diff --git a/OpenRA.Game/GameRules/Settings.cs b/OpenRA.Game/GameRules/Settings.cs index 625d382e4d..ab385b6d5b 100755 --- a/OpenRA.Game/GameRules/Settings.cs +++ b/OpenRA.Game/GameRules/Settings.cs @@ -58,7 +58,6 @@ namespace OpenRA.GameRules public WindowMode Mode = WindowMode.PseudoFullscreen; public int2 FullscreenSize = new int2(0,0); public int2 WindowedSize = new int2(1024, 768); - public readonly int2 MinResolution = new int2(800, 600); public int BatchSize = 8192; public int NumTempBuffers = 8; diff --git a/OpenRA.Mods.RA/Widgets/Logic/SettingsMenuLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/SettingsMenuLogic.cs index bc77ab1b4e..97c0d8a480 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/SettingsMenuLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/SettingsMenuLogic.cs @@ -9,6 +9,8 @@ #endregion using System; +using System.Collections.Generic; +using System.Linq; using OpenRA.FileFormats.Graphics; using OpenRA.GameRules; using OpenRA.Widgets; @@ -76,45 +78,19 @@ namespace OpenRA.Mods.RA.Widgets.Logic // Display var display = bg.GetWidget("DISPLAY_PANE"); var gs = Game.Settings.Graphics; + + var windowModeDropdown = display.GetWidget("MODE_DROPDOWN"); + windowModeDropdown.OnMouseDown = _ => ShowWindowModeDropdown(windowModeDropdown, gs); + windowModeDropdown.GetText = () => gs.Mode == WindowMode.Windowed ? + "Windowed" : gs.Mode == WindowMode.Fullscreen ? "Fullscreen" : "Pseudo-Fullscreen"; - var fullscreen = display.GetWidget("FULLSCREEN_CHECKBOX"); - fullscreen.IsChecked = () => gs.Mode != WindowMode.Windowed; - fullscreen.OnClick = () => gs.Mode = (gs.Mode == WindowMode.Windowed) ? WindowMode.PseudoFullscreen : WindowMode.Windowed; - - var width = display.GetWidget("SCREEN_WIDTH"); - gs.WindowedSize.X = Math.Max(gs.WindowedSize.X, gs.MinResolution.X); - width.Text = gs.WindowedSize.X.ToString(); - width.OnLoseFocus = () => - { - try { - var w = int.Parse(width.Text); - if (w > gs.MinResolution.X) - gs.WindowedSize = new int2(w, gs.WindowedSize.Y); - } - catch (FormatException) { - width.Text = gs.WindowedSize.X.ToString(); - } - }; - width.OnEnterKey = () => { width.LoseFocus(); return true; }; - - var height = display.GetWidget("SCREEN_HEIGHT"); - gs.WindowedSize.Y = Math.Max(gs.WindowedSize.Y, gs.MinResolution.Y); - height.Text = gs.WindowedSize.Y.ToString(); - height.OnLoseFocus = () => - { - try { - var h = int.Parse(height.Text); - if (h > gs.MinResolution.Y) - gs.WindowedSize = new int2(gs.WindowedSize.X, h); - else - height.Text = gs.WindowedSize.Y.ToString(); - } - catch (FormatException) { - height.Text = gs.WindowedSize.Y.ToString(); - } - }; - height.OnEnterKey = () => { height.LoseFocus(); return true; }; + display.GetWidget("WINDOW_RESOLUTION").IsVisible = () => gs.Mode == WindowMode.Windowed; + var windowWidth = display.GetWidget("WINDOW_WIDTH"); + windowWidth.Text = gs.WindowedSize.X.ToString(); + var windowHeight = display.GetWidget("WINDOW_HEIGHT"); + windowHeight.Text = gs.WindowedSize.Y.ToString(); + // Debug var debug = bg.GetWidget("DEBUG_PANE"); @@ -128,7 +104,12 @@ namespace OpenRA.Mods.RA.Widgets.Logic checkunsyncedCheckbox.IsChecked = () => Game.Settings.Debug.SanityCheckUnsyncedCode; checkunsyncedCheckbox.OnClick = () => Game.Settings.Debug.SanityCheckUnsyncedCode ^= true; - bg.GetWidget("BUTTON_CLOSE").OnClick = () => { + bg.GetWidget("BUTTON_CLOSE").OnClick = () => + { + int x = gs.WindowedSize.X, y = gs.WindowedSize.Y; + int.TryParse(windowWidth.Text, out x); + int.TryParse(windowHeight.Text, out y); + gs.WindowedSize = new int2(x,y); Game.Settings.Save(); Widget.CloseWindow(); }; @@ -144,5 +125,27 @@ namespace OpenRA.Mods.RA.Widgets.Logic bg.GetWidget(open).Visible = true; return true; } + + bool ShowWindowModeDropdown(DropDownButtonWidget dropdown, GraphicSettings s) + { + var options = new Dictionary() + { + { "Pseudo-Fullscreen", WindowMode.PseudoFullscreen }, + { "Fullscreen", WindowMode.Fullscreen }, + { "Windowed", WindowMode.Windowed }, + }; + + Func setupItem = (o, itemTemplate) => + { + var item = ScrollItemWidget.Setup(itemTemplate, + () => s.Mode == options[o], + () => s.Mode = options[o]); + item.GetWidget("LABEL").GetText = () => o; + return item; + }; + + dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 500, options.Keys.ToList(), setupItem); + return true; + } } } diff --git a/mods/ra/chrome/settings.yaml b/mods/ra/chrome/settings.yaml index 7609f9dbc8..4bb8fd805d 100644 --- a/mods/ra/chrome/settings.yaml +++ b/mods/ra/chrome/settings.yaml @@ -159,44 +159,59 @@ Background@SETTINGS_MENU: Height:PARENT_BOTTOM - 100 Visible: false Children: - Checkbox@FULLSCREEN_CHECKBOX: - Id:FULLSCREEN_CHECKBOX + Label@MODE_LABEL: X:0 Y:0 - Width:300 - Height:20 - Text:Fullscreen - Label@RESOLUTION_LABEL: - Id:RESOLUTION_LABEL - X:0 - Y:50 - Text: Window Resolution: - TextField@SCREEN_WIDTH: - Id:SCREEN_WIDTH - Text:Width - Width:50 + Width:45 Height:25 - X:130 - Y:40 - MaxLength:5 - Label@X: - Id:X - Text:x - X:185 - Y:50 - TextField@SCREEN_HEIGHT: - Id:SCREEN_HEIGHT - Text:Height - Width:50 + Text:Mode: + DropDownButton@MODE_DROPDOWN: + Id:MODE_DROPDOWN + X:50 + Y:1 + Width:170 Height:25 - X:195 - Y:40 - MaxLength:5 - Label@RESTART: - Id:RESTART - Text: Restart Game To Apply Changes - X:0 - Y:PARENT_BOTTOM - 30 + Font:Regular + Text:Windowed + Container@WINDOWRES: + Id:WINDOW_RESOLUTION + X:220 + Y:0 + Children: + Label@At: + Text:@ + Font:Bold + Y:0-1 + Height:25 + Width:25 + Align:Center + TextField@SCREEN_WIDTH: + Id:WINDOW_WIDTH + X:25 + Width:45 + Height:25 + MaxLength:5 + Label@X: + Text:x + Font:Bold + X:70 + Y:0-1 + Height:25 + Width:15 + Align:Center + TextField@SCREEN_HEIGHT: + Id:WINDOW_HEIGHT + X:85 + Width:45 + Height:25 + MaxLength:5 + Label@VIDEO_DESC: + Y:25 + Width:PARENT_RIGHT + Height:25 + Font:Tiny + Align:Center + Text:Video changes will be applied after the game is restarted Container@DEBUG_PANE: Id:DEBUG_PANE X:37