From 51eaa17b1e454b858353cdcd64d6528db5be7605 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 8 Dec 2019 22:02:24 +0000 Subject: [PATCH] Replace frame limit text field with a slider. --- .../Widgets/Logic/SettingsLogic.cs | 45 +++++++------------ mods/cnc/chrome/settings.yaml | 25 +++-------- mods/common/chrome/settings.yaml | 27 ++++------- 3 files changed, 32 insertions(+), 65 deletions(-) diff --git a/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs index 7e75f9b437..10ba7eddd6 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs @@ -137,6 +137,17 @@ namespace OpenRA.Mods.Common.Widgets.Logic 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(id); + ss.Value = (float)(int)field.GetValue(group); + ss.OnChange += x => field.SetValue(group, (int)x); + } + void BindHotkeyPref(HotkeyDefinition hd, Widget template, Widget parent) { var key = template.Clone() as Widget; @@ -207,6 +218,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic BindCheckboxPref(panel, "CURSORDOUBLE_CHECKBOX", ds, "CursorDouble"); BindCheckboxPref(panel, "VSYNC_CHECKBOX", ds, "VSync"); BindCheckboxPref(panel, "FRAME_LIMIT_CHECKBOX", ds, "CapFramerate"); + BindIntSliderPref(panel, "FRAME_LIMIT_SLIDER", ds, "MaxFramerate"); BindCheckboxPref(panel, "PLAYER_STANCE_COLORS_CHECKBOX", gs, "UsePlayerStanceColors"); var languageDropDownButton = panel.Get("LANGUAGE_DROPDOWNBUTTON"); @@ -249,37 +261,15 @@ namespace OpenRA.Mods.Common.Widgets.Logic var windowHeight = panel.Get("WINDOW_HEIGHT"); windowHeight.Text = ds.WindowedSize.Y.ToString(); - var frameLimitTextfield = panel.Get("FRAME_LIMIT_TEXTFIELD"); - frameLimitTextfield.Text = ds.MaxFramerate.ToString(); - var escPressed = false; - frameLimitTextfield.OnLoseFocus = () => - { - 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; + var frameLimitCheckbox = panel.Get("FRAME_LIMIT_CHECKBOX"); + var frameLimitOrigLabel = frameLimitCheckbox.Text; + var frameLimitLabel = new CachedTransform(fps => frameLimitOrigLabel + " ({0} FPS)".F(fps)); + frameLimitCheckbox.GetText = () => frameLimitLabel.Update(ds.MaxFramerate); // Player profile var ps = Game.Settings.Player; + var escPressed = false; var nameTextfield = panel.Get("PLAYERNAME"); nameTextfield.IsDisabled = () => worldRenderer.World.Type != WorldType.Shellmap; nameTextfield.Text = Settings.SanitizedPlayerName(ps.Name); @@ -324,7 +314,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic Exts.TryParseIntegerInvariant(windowWidth.Text, out x); Exts.TryParseIntegerInvariant(windowHeight.Text, out y); ds.WindowedSize = new int2(x, y); - frameLimitTextfield.YieldKeyboardFocus(); nameTextfield.YieldKeyboardFocus(); }; } diff --git a/mods/cnc/chrome/settings.yaml b/mods/cnc/chrome/settings.yaml index 66dcdd867f..471fcdd103 100644 --- a/mods/cnc/chrome/settings.yaml +++ b/mods/cnc/chrome/settings.yaml @@ -159,25 +159,14 @@ Container@SETTINGS_PANEL: Height: 20 Font: Regular Text: Enable Frame Limiter - Label@FRAME_LIMIT_DESC_A: + Slider@FRAME_LIMIT_SLIDER: X: 340 - Y: 153 - Width: 50 - Height: 25 - Text: Limit to - Align: Right - TextField@FRAME_LIMIT_TEXTFIELD: - 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 + Y: 150 + Width: 200 + Height: 20 + Ticks: 20 + MinimumValue: 50 + MaximumValue: 240 Checkbox@PLAYER_STANCE_COLORS_CHECKBOX: X: 310 Y: 185 diff --git a/mods/common/chrome/settings.yaml b/mods/common/chrome/settings.yaml index bddd79d518..e426069f78 100644 --- a/mods/common/chrome/settings.yaml +++ b/mods/common/chrome/settings.yaml @@ -173,25 +173,14 @@ Background@SETTINGS_PANEL: Height: 20 Font: Regular Text: Enable Frame Limiter - Label@FRAME_LIMIT_DESC_A: - X: 340 - Y: 159 - Width: 50 - Height: 25 - Text: Limit to - Align: Right - TextField@FRAME_LIMIT_TEXTFIELD: - 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 + Slider@FRAME_LIMIT_SLIDER: + X: 330 + Y: 150 + Width: 200 + Height: 20 + Ticks: 20 + MinimumValue: 50 + MaximumValue: 240 Checkbox@PLAYER_STANCE_COLORS_CHECKBOX: X: 310 Y: 195