Clamp, scroll, scrollspeed, sliders

Reduced clamp duplication
Fixed scrolling speed issue
Modified scrollspeed slider to use a range
Fixed scrollspeed, volume, and sound sliders not showing current setting.
This commit is contained in:
Caleb Anderson
2010-10-06 02:37:20 -05:00
committed by Chris Forbes
parent ab431fe9ee
commit c85503811c
7 changed files with 21 additions and 31 deletions

View File

@@ -67,15 +67,5 @@ namespace OpenRA
Log.Write("perf", text, x, dt * 1000, Game.LocalTick);
});
}
public static T Clamp<T>(this T val, T min, T max) where T : IComparable<T>
{
if (val.CompareTo(min) < 0)
return min;
else if (val.CompareTo(max) > 0)
return max;
else
return val;
}
}
}

View File

@@ -33,15 +33,5 @@ namespace OpenRA.Server
{
return ts.Except( new[] { t } );
}
public static T Clamp<T>(this T val, T min, T max) where T : IComparable<T>
{
if (val.CompareTo(min) < 0)
return min;
else if (val.CompareTo(max) > 0)
return max;
else
return val;
}
}
}

View File

@@ -57,9 +57,10 @@ namespace OpenRA.Widgets.Delegates
// Added scroll sensitivity - Gecko
var edgeScrollSlider = general.GetWidget<SliderWidget>("EDGE_SCROLL_AMOUNT");
if (edgeScrollSlider != null) // Backwards compatible - Gecko
{
edgeScrollSlider.OnChange += x => { x += 0.1f; Game.Settings.Game.ViewportEdgeScrollStep = x; };
edgeScrollSlider.GetOffset = () => { return Game.Settings.Game.ViewportEdgeScrollStep - 0.1f; };
{
edgeScrollSlider.SetOffset(Game.Settings.Game.ViewportEdgeScrollStep);
edgeScrollSlider.OnChange += _ => { Game.Settings.Game.ViewportEdgeScrollStep = edgeScrollSlider.GetOffset(); };
Game.Settings.Game.ViewportEdgeScrollStep = edgeScrollSlider.GetOffset();
}
var inverseScroll = general.GetWidget<CheckboxWidget>("INVERSE_SCROLL");
@@ -76,10 +77,12 @@ namespace OpenRA.Widgets.Delegates
var soundslider = audio.GetWidget<SliderWidget>("SOUND_VOLUME");
soundslider.OnChange += x => { Sound.SoundVolume = x; };
soundslider.GetOffset = () => { return Sound.SoundVolume; };
soundslider.SetOffset(Sound.SoundVolume);
var musicslider = audio.GetWidget<SliderWidget>("MUSIC_VOLUME");
musicslider.OnChange += x => { Sound.MusicVolume = x; };
musicslider.GetOffset = () => { return Sound.MusicVolume; };
musicslider.SetOffset(Sound.MusicVolume);
// Display

View File

@@ -37,7 +37,7 @@ namespace OpenRA.Widgets
return Spread * Offset + Little;
};
OnChange = x => Offset = x;
OnChange = x => Offset = x.Clamp(0f, 1f);
}
public SliderWidget(SliderWidget other)
@@ -45,8 +45,9 @@ namespace OpenRA.Widgets
{
OnChange = other.OnChange;
GetOffset = other.GetOffset;
Offset = other.Offset;
Ticks = other.Ticks;
Range = other.Range;
Offset = GetOffset();
TrackHeight = other.TrackHeight;
lastMouseLocation = other.lastMouseLocation;
isMoving = other.isMoving;
@@ -58,7 +59,7 @@ namespace OpenRA.Widgets
var Little = Math.Min(Range.X, Range.Y);
var Spread = Big - Little;
Offset = (newOffset - Little) / Spread;
Offset = ((newOffset - Little) / Spread).Clamp(0f, 1f);
}
public override bool HandleInputInner(MouseInput mi)

View File

@@ -144,14 +144,18 @@ namespace OpenRA.Widgets
// Modified to use the ViewportEdgeScrollStep setting - Gecko
if (Keyboard.Includes(ScrollDirection.Up) || Edge.Includes(ScrollDirection.Up))
scroll += new float2(0, -(Game.Settings.Game.ViewportEdgeScrollStep * 100));
scroll += new float2(0, -1);
if (Keyboard.Includes(ScrollDirection.Right) || Edge.Includes(ScrollDirection.Right))
scroll += new float2((Game.Settings.Game.ViewportEdgeScrollStep * 100), 0);
scroll += new float2(1, 0);
if (Keyboard.Includes(ScrollDirection.Down) || Edge.Includes(ScrollDirection.Down))
scroll += new float2(0, (Game.Settings.Game.ViewportEdgeScrollStep * 100));
scroll += new float2(0, 1);
if (Keyboard.Includes(ScrollDirection.Left) || Edge.Includes(ScrollDirection.Left))
scroll += new float2(-(Game.Settings.Game.ViewportEdgeScrollStep * 100), 0);
scroll += new float2(-1, 0);
float length = scroll.Length;
scroll.X = (scroll.X / length) * Game.Settings.Game.ViewportEdgeScrollStep;
scroll.Y = (scroll.Y / length) * Game.Settings.Game.ViewportEdgeScrollStep;
Game.viewport.Scroll(scroll);
}
}

View File

@@ -102,6 +102,7 @@ Background@SETTINGS_MENU:
Width:250
Height:20
Ticks:5
Range:10,50
Checkbox@INVERSE_SCROLL:
Id:INVERSE_SCROLL
X:0

View File

@@ -103,6 +103,7 @@ Background@SETTINGS_MENU:
Width:250
Height:20
Ticks:5
Range:10,50
Checkbox@INVERSE_SCROLL:
Id:INVERSE_SCROLL
X:0