Replace frame limit text field with a slider.
This commit is contained in:
@@ -137,6 +137,17 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
ss.OnChange += x => field.SetValue(group, x);
|
ss.OnChange += x => field.SetValue(group, x);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void BindIntSliderPref(Widget parent, string id, object group, string pref)
|
||||||
|
{
|
||||||
|
var field = group.GetType().GetField(pref);
|
||||||
|
if (field == null)
|
||||||
|
throw new InvalidOperationException("{0} does not contain a preference type {1}".F(group.GetType().Name, pref));
|
||||||
|
|
||||||
|
var ss = parent.Get<SliderWidget>(id);
|
||||||
|
ss.Value = (float)(int)field.GetValue(group);
|
||||||
|
ss.OnChange += x => field.SetValue(group, (int)x);
|
||||||
|
}
|
||||||
|
|
||||||
void BindHotkeyPref(HotkeyDefinition hd, Widget template, Widget parent)
|
void BindHotkeyPref(HotkeyDefinition hd, Widget template, Widget parent)
|
||||||
{
|
{
|
||||||
var key = template.Clone() as Widget;
|
var key = template.Clone() as Widget;
|
||||||
@@ -207,6 +218,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
BindCheckboxPref(panel, "CURSORDOUBLE_CHECKBOX", ds, "CursorDouble");
|
BindCheckboxPref(panel, "CURSORDOUBLE_CHECKBOX", ds, "CursorDouble");
|
||||||
BindCheckboxPref(panel, "VSYNC_CHECKBOX", ds, "VSync");
|
BindCheckboxPref(panel, "VSYNC_CHECKBOX", ds, "VSync");
|
||||||
BindCheckboxPref(panel, "FRAME_LIMIT_CHECKBOX", ds, "CapFramerate");
|
BindCheckboxPref(panel, "FRAME_LIMIT_CHECKBOX", ds, "CapFramerate");
|
||||||
|
BindIntSliderPref(panel, "FRAME_LIMIT_SLIDER", ds, "MaxFramerate");
|
||||||
BindCheckboxPref(panel, "PLAYER_STANCE_COLORS_CHECKBOX", gs, "UsePlayerStanceColors");
|
BindCheckboxPref(panel, "PLAYER_STANCE_COLORS_CHECKBOX", gs, "UsePlayerStanceColors");
|
||||||
|
|
||||||
var languageDropDownButton = panel.Get<DropDownButtonWidget>("LANGUAGE_DROPDOWNBUTTON");
|
var languageDropDownButton = panel.Get<DropDownButtonWidget>("LANGUAGE_DROPDOWNBUTTON");
|
||||||
@@ -249,37 +261,15 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
var windowHeight = panel.Get<TextFieldWidget>("WINDOW_HEIGHT");
|
var windowHeight = panel.Get<TextFieldWidget>("WINDOW_HEIGHT");
|
||||||
windowHeight.Text = ds.WindowedSize.Y.ToString();
|
windowHeight.Text = ds.WindowedSize.Y.ToString();
|
||||||
|
|
||||||
var frameLimitTextfield = panel.Get<TextFieldWidget>("FRAME_LIMIT_TEXTFIELD");
|
var frameLimitCheckbox = panel.Get<CheckboxWidget>("FRAME_LIMIT_CHECKBOX");
|
||||||
frameLimitTextfield.Text = ds.MaxFramerate.ToString();
|
var frameLimitOrigLabel = frameLimitCheckbox.Text;
|
||||||
var escPressed = false;
|
var frameLimitLabel = new CachedTransform<int, string>(fps => frameLimitOrigLabel + " ({0} FPS)".F(fps));
|
||||||
frameLimitTextfield.OnLoseFocus = () =>
|
frameLimitCheckbox.GetText = () => frameLimitLabel.Update(ds.MaxFramerate);
|
||||||
{
|
|
||||||
if (escPressed)
|
|
||||||
{
|
|
||||||
escPressed = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int fps;
|
|
||||||
Exts.TryParseIntegerInvariant(frameLimitTextfield.Text, out fps);
|
|
||||||
ds.MaxFramerate = fps.Clamp(1, 1000);
|
|
||||||
frameLimitTextfield.Text = ds.MaxFramerate.ToString();
|
|
||||||
};
|
|
||||||
|
|
||||||
frameLimitTextfield.OnEnterKey = () => { frameLimitTextfield.YieldKeyboardFocus(); return true; };
|
|
||||||
frameLimitTextfield.OnEscKey = () =>
|
|
||||||
{
|
|
||||||
frameLimitTextfield.Text = ds.MaxFramerate.ToString();
|
|
||||||
escPressed = true;
|
|
||||||
frameLimitTextfield.YieldKeyboardFocus();
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
|
|
||||||
frameLimitTextfield.IsDisabled = () => !ds.CapFramerate;
|
|
||||||
|
|
||||||
// Player profile
|
// Player profile
|
||||||
var ps = Game.Settings.Player;
|
var ps = Game.Settings.Player;
|
||||||
|
|
||||||
|
var escPressed = false;
|
||||||
var nameTextfield = panel.Get<TextFieldWidget>("PLAYERNAME");
|
var nameTextfield = panel.Get<TextFieldWidget>("PLAYERNAME");
|
||||||
nameTextfield.IsDisabled = () => worldRenderer.World.Type != WorldType.Shellmap;
|
nameTextfield.IsDisabled = () => worldRenderer.World.Type != WorldType.Shellmap;
|
||||||
nameTextfield.Text = Settings.SanitizedPlayerName(ps.Name);
|
nameTextfield.Text = Settings.SanitizedPlayerName(ps.Name);
|
||||||
@@ -324,7 +314,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
Exts.TryParseIntegerInvariant(windowWidth.Text, out x);
|
Exts.TryParseIntegerInvariant(windowWidth.Text, out x);
|
||||||
Exts.TryParseIntegerInvariant(windowHeight.Text, out y);
|
Exts.TryParseIntegerInvariant(windowHeight.Text, out y);
|
||||||
ds.WindowedSize = new int2(x, y);
|
ds.WindowedSize = new int2(x, y);
|
||||||
frameLimitTextfield.YieldKeyboardFocus();
|
|
||||||
nameTextfield.YieldKeyboardFocus();
|
nameTextfield.YieldKeyboardFocus();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -159,25 +159,14 @@ Container@SETTINGS_PANEL:
|
|||||||
Height: 20
|
Height: 20
|
||||||
Font: Regular
|
Font: Regular
|
||||||
Text: Enable Frame Limiter
|
Text: Enable Frame Limiter
|
||||||
Label@FRAME_LIMIT_DESC_A:
|
Slider@FRAME_LIMIT_SLIDER:
|
||||||
X: 340
|
X: 340
|
||||||
Y: 153
|
Y: 150
|
||||||
Width: 50
|
Width: 200
|
||||||
Height: 25
|
Height: 20
|
||||||
Text: Limit to
|
Ticks: 20
|
||||||
Align: Right
|
MinimumValue: 50
|
||||||
TextField@FRAME_LIMIT_TEXTFIELD:
|
MaximumValue: 240
|
||||||
X: 395
|
|
||||||
Y: 153
|
|
||||||
Width: 45
|
|
||||||
Height: 25
|
|
||||||
MaxLength: 3
|
|
||||||
Type: Integer
|
|
||||||
Label@FRAME_LIMIT_DESC_B:
|
|
||||||
X: 445
|
|
||||||
Y: 153
|
|
||||||
Height: 25
|
|
||||||
Text: FPS
|
|
||||||
Checkbox@PLAYER_STANCE_COLORS_CHECKBOX:
|
Checkbox@PLAYER_STANCE_COLORS_CHECKBOX:
|
||||||
X: 310
|
X: 310
|
||||||
Y: 185
|
Y: 185
|
||||||
|
|||||||
@@ -173,25 +173,14 @@ Background@SETTINGS_PANEL:
|
|||||||
Height: 20
|
Height: 20
|
||||||
Font: Regular
|
Font: Regular
|
||||||
Text: Enable Frame Limiter
|
Text: Enable Frame Limiter
|
||||||
Label@FRAME_LIMIT_DESC_A:
|
Slider@FRAME_LIMIT_SLIDER:
|
||||||
X: 340
|
X: 330
|
||||||
Y: 159
|
Y: 150
|
||||||
Width: 50
|
Width: 200
|
||||||
Height: 25
|
Height: 20
|
||||||
Text: Limit to
|
Ticks: 20
|
||||||
Align: Right
|
MinimumValue: 50
|
||||||
TextField@FRAME_LIMIT_TEXTFIELD:
|
MaximumValue: 240
|
||||||
X: 395
|
|
||||||
Y: 158
|
|
||||||
Width: 45
|
|
||||||
Height: 25
|
|
||||||
MaxLength: 3
|
|
||||||
Type: Integer
|
|
||||||
Label@FRAME_LIMIT_DESC_B:
|
|
||||||
X: 445
|
|
||||||
Y: 159
|
|
||||||
Height: 25
|
|
||||||
Text: FPS
|
|
||||||
Checkbox@PLAYER_STANCE_COLORS_CHECKBOX:
|
Checkbox@PLAYER_STANCE_COLORS_CHECKBOX:
|
||||||
X: 310
|
X: 310
|
||||||
Y: 195
|
Y: 195
|
||||||
|
|||||||
Reference in New Issue
Block a user