From 1143f496db08c7d2822475531d7ba746f688a948 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Mon, 23 Aug 2010 23:20:27 +1200 Subject: [PATCH] Part 2 of 3: Split Settings into logical units. Syntax for command line overrides is now
.= eg `General.InitialMods=cnc' --- OpenRA.Game/Game.cs | 12 +- OpenRA.Game/GameRules/Settings.cs | 129 ++++++++++++------ OpenRA.Game/Graphics/Renderer.cs | 2 +- OpenRA.Game/Network/Session.cs | 2 +- OpenRA.Game/Network/SyncReport.cs | 2 +- OpenRA.Game/Server/Server.cs | 16 +-- OpenRA.Game/Sound.cs | 12 +- OpenRA.Game/Traits/Player/DeveloperMode.cs | 2 +- OpenRA.Game/UiOverlay.cs | 2 +- .../Delegates/CreateServerMenuDelegate.cs | 22 +-- .../Delegates/DeveloperModeDelegate.cs | 2 +- .../Widgets/Delegates/LobbyDelegate.cs | 23 ++-- .../Widgets/Delegates/PerfDebugDelegate.cs | 2 +- .../Delegates/ServerBrowserDelegate.cs | 8 +- .../Widgets/Delegates/SettingsMenuDelegate.cs | 58 ++++---- OpenRA.Game/Widgets/TimerWidget.cs | 2 +- .../Widgets/ViewportScrollControllerWidget.cs | 6 +- 17 files changed, 174 insertions(+), 128 deletions(-) diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index e9a20cb092..9cf4b9e959 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -115,11 +115,11 @@ namespace OpenRA int t = Environment.TickCount; int dt = t - lastTime; - if (dt >= Settings.Timestep) + if (dt >= Settings.General.Timestep) { using (new PerfSample("tick_time")) { - lastTime += Settings.Timestep; + lastTime += Settings.General.Timestep; Widget.DoTick(world); orderManager.TickImmediate(world); @@ -261,12 +261,12 @@ namespace OpenRA Log.AddChannel("debug", "debug.log"); Log.AddChannel("sync", "syncreport.log"); - LobbyInfo.GlobalSettings.Mods = Settings.InitialMods; + LobbyInfo.GlobalSettings.Mods = Settings.General.InitialMods; modData = new ModData( LobbyInfo.GlobalSettings.Mods ); - Renderer.SheetSize = Settings.SheetSize; + Renderer.SheetSize = Settings.General.SheetSize; - Renderer.Initialize( Game.Settings.WindowMode ); + Renderer.Initialize( Game.Settings.Graphics.WindowMode ); Sound.Initialize(); PerfHistory.items["render"].hasNormalTick = false; @@ -307,7 +307,7 @@ namespace OpenRA orderManager.Dispose(); var shellmap = modData.Manifest.ShellmapUid; LobbyInfo = new Session(); - LobbyInfo.GlobalSettings.Mods = Settings.InitialMods; + LobbyInfo.GlobalSettings.Mods = Settings.General.InitialMods; JoinLocal(); StartGame(shellmap); diff --git a/OpenRA.Game/GameRules/Settings.cs b/OpenRA.Game/GameRules/Settings.cs index 9f01ae8e83..37639a481c 100755 --- a/OpenRA.Game/GameRules/Settings.cs +++ b/OpenRA.Game/GameRules/Settings.cs @@ -14,32 +14,56 @@ using System.IO; using System.Windows.Forms; using OpenRA.FileFormats; using OpenRA.FileFormats.Graphics; +using System; namespace OpenRA.GameRules { - public class Settings + public class ServerSettings + { + public string LastServerTitle = "OpenRA Game"; + public int ListenPort = 1234; + public int ExternalPort = 1234; + public bool AdvertiseOnline = true; + public string MasterServer = "http://open-ra.org/master/"; + public bool AllowCheats = false; + } + + public class DebugSettings { - // Behaviour settings - public bool ViewportEdgeScroll = true; - public bool InverseDragScroll = false; - - // Debug settings public bool PerfDebug = false; - public bool RecordSyncReports = true; - public bool ShowGameTimer = true; + public bool RecordSyncReports = true; + public bool ShowGameTimer = true; public bool UnitDebug = false; - - // Window settings + } + + public class GraphicSettings + { public WindowMode WindowMode = WindowMode.PseudoFullscreen; public int2 FullscreenSize = new int2(Screen.PrimaryScreen.Bounds.Width,Screen.PrimaryScreen.Bounds.Height); public int2 WindowedSize = new int2(1024,768); public readonly int2 MinResolution = new int2(800, 600); - - //Sound Settings + } + + public class SoundSettings + { public float SoundVolume = 0.5f; public float MusicVolume = 0.5f; public float VideoVolume = 0.5f; public bool MusicPlayer = false; + } + + public class PlayerSettings + { + public string PlayerName = "Newbie"; + public Color PlayerColor1 = Color.FromArgb(255,160,238); + public Color PlayerColor2 = Color.FromArgb(68,0,56); + } + + public class GeneralSettings + { + // Behaviour settings + public bool ViewportEdgeScroll = true; + public bool InverseDragScroll = false; // Internal game settings public int Timestep = 40; @@ -47,40 +71,39 @@ namespace OpenRA.GameRules // External game settings public string LastServer = "localhost:1234"; - public string PlayerName = "Newbie"; - public Color PlayerColor1 = Color.FromArgb(255,160,238); - public Color PlayerColor2 = Color.FromArgb(68,0,56); public string[] InitialMods = { "ra" }; - - // Server settings - public string LastServerTitle = "OpenRA Game"; - public int ListenPort = 1234; - public int ExternalPort = 1234; - public bool AdvertiseOnline = true; - public string MasterServer = "http://open-ra.org/master/"; - public bool AllowCheats = false; - + } + + public class Settings + { string SettingsFile; - Settings defaults; - public Settings() {} + public PlayerSettings Player = new PlayerSettings(); + public GeneralSettings General = new GeneralSettings(); + public SoundSettings Sound = new SoundSettings(); + public GraphicSettings Graphics = new GraphicSettings(); + public ServerSettings Server = new ServerSettings(); + public DebugSettings Debug = new DebugSettings(); + + Dictionary Sections; public Settings(Arguments args) { - defaults = new Settings(); SettingsFile = Game.SupportDir + "settings.yaml"; - - // Override settings loading to not crash + Sections = new Dictionary() + { + {"Player", Player}, + {"General", General}, + {"Sound", Sound}, + {"Graphics", Graphics}, + {"Server", Server}, + {"Debug", Debug} + }; + + // Override fieldloader to ignore invalid entries var err1 = FieldLoader.UnknownFieldAction; var err2 = FieldLoader.InvalidValueAction; - FieldLoader.InvalidValueAction = (s,t,f) => - { - object ret = defaults.GetType().GetField(f).GetValue(defaults); - System.Console.WriteLine("FieldLoader: Cannot parse `{0}` into `{2}:{1}`; substituting default `{3}`".F(s,t.Name,f,ret) ); - return ret; - }; - FieldLoader.UnknownFieldAction = (s,f) => { System.Console.WriteLine( "Ignoring unknown field `{0}` on `{1}`".F( s, f.Name ) ); @@ -90,12 +113,16 @@ namespace OpenRA.GameRules { System.Console.WriteLine("Loading settings file {0}",SettingsFile); var yaml = MiniYaml.FromFile(SettingsFile); - FieldLoader.Load(this, yaml["Settings"]); + + foreach (var kv in Sections) + LoadSectionYaml(yaml[kv.Key], kv.Value); } - foreach (var f in this.GetType().GetFields()) - if (args.Contains(f.Name)) - OpenRA.FileFormats.FieldLoader.LoadField( this, f.Name, args.GetValue(f.Name, "") ); + // Override with commandline args + foreach (var kv in Sections) + foreach (var f in kv.Value.GetType().GetFields()) + if (args.Contains(kv.Key+"."+f.Name)) + OpenRA.FileFormats.FieldLoader.LoadField( kv.Value, f.Name, args.GetValue(kv.Key+"."+f.Name, "") ); FieldLoader.UnknownFieldAction = err1; FieldLoader.InvalidValueAction = err2; @@ -104,8 +131,28 @@ namespace OpenRA.GameRules public void Save() { Dictionary root = new Dictionary(); - root.Add("Settings", FieldSaver.SaveDifferences(this, defaults)); + foreach (var kv in Sections) + root.Add(kv.Key, SectionYaml(kv.Value)); + root.WriteToFile(SettingsFile); } + + MiniYaml SectionYaml(object section) + { + return FieldSaver.SaveDifferences(section, Activator.CreateInstance(section.GetType())); + } + + void LoadSectionYaml(MiniYaml yaml, object section) + { + object defaults = Activator.CreateInstance(section.GetType()); + FieldLoader.InvalidValueAction = (s,t,f) => + { + object ret = defaults.GetType().GetField(f).GetValue(defaults); + System.Console.WriteLine("FieldLoader: Cannot parse `{0}` into `{2}:{1}`; substituting default `{3}`".F(s,t.Name,f,ret) ); + return ret; + }; + + FieldLoader.Load(section, yaml); + } } } diff --git a/OpenRA.Game/Graphics/Renderer.cs b/OpenRA.Game/Graphics/Renderer.cs index 58d92f8c1a..fde69be2c5 100644 --- a/OpenRA.Game/Graphics/Renderer.cs +++ b/OpenRA.Game/Graphics/Renderer.cs @@ -130,7 +130,7 @@ namespace OpenRA.Graphics static Size GetResolution(WindowMode windowmode) { var desktopResolution = Screen.PrimaryScreen.Bounds.Size; - var customSize = (windowmode == WindowMode.Windowed) ? Game.Settings.WindowedSize : Game.Settings.FullscreenSize; + var customSize = (windowmode == WindowMode.Windowed) ? Game.Settings.Graphics.WindowedSize : Game.Settings.Graphics.FullscreenSize; if (customSize.X > 0 && customSize.Y > 0) { diff --git a/OpenRA.Game/Network/Session.cs b/OpenRA.Game/Network/Session.cs index 7c0c970e68..760cd87579 100644 --- a/OpenRA.Game/Network/Session.cs +++ b/OpenRA.Game/Network/Session.cs @@ -75,7 +75,7 @@ namespace OpenRA.Network public static Session Deserialize(string data) { var session = new Session(); - session.GlobalSettings.Mods = Game.Settings.InitialMods; + session.GlobalSettings.Mods = Game.Settings.General.InitialMods; var ys = MiniYaml.FromString(data); foreach (var y in ys) diff --git a/OpenRA.Game/Network/SyncReport.cs b/OpenRA.Game/Network/SyncReport.cs index c8c1c3387f..2a748831df 100755 --- a/OpenRA.Game/Network/SyncReport.cs +++ b/OpenRA.Game/Network/SyncReport.cs @@ -13,7 +13,7 @@ namespace OpenRA.Network internal void UpdateSyncReport() { - if (!Game.Settings.RecordSyncReports) + if (!Game.Settings.Debug.RecordSyncReports) return; while (syncReports.Count >= numSyncReports) syncReports.Dequeue(); diff --git a/OpenRA.Game/Server/Server.cs b/OpenRA.Game/Server/Server.cs index a8af167be1..6249b8a33c 100644 --- a/OpenRA.Game/Server/Server.cs +++ b/OpenRA.Game/Server/Server.cs @@ -53,19 +53,19 @@ namespace OpenRA.Server Log.AddChannel("server", "server.log"); isInitialPing = true; - Server.masterServerUrl = settings.MasterServer; - isInternetServer = settings.AdvertiseOnline; - listener = new TcpListener(IPAddress.Any, settings.ListenPort); - Name = settings.LastServerTitle; - ExternalPort = settings.ExternalPort; + Server.masterServerUrl = settings.Server.MasterServer; + isInternetServer = settings.Server.AdvertiseOnline; + listener = new TcpListener(IPAddress.Any, settings.Server.ListenPort); + Name = settings.Server.LastServerTitle; + ExternalPort = settings.Server.ExternalPort; randomSeed = (int)DateTime.Now.ToBinary(); ModData = modData; lobbyInfo = new Session(); - lobbyInfo.GlobalSettings.Mods = settings.InitialMods; + lobbyInfo.GlobalSettings.Mods = settings.General.InitialMods; lobbyInfo.GlobalSettings.RandomSeed = randomSeed; lobbyInfo.GlobalSettings.Map = map; - lobbyInfo.GlobalSettings.AllowCheats = settings.AllowCheats; + lobbyInfo.GlobalSettings.AllowCheats = settings.Server.AllowCheats; LoadMap(); // populates the Session's slots, too. @@ -151,7 +151,7 @@ namespace OpenRA.Server newConn.socket.Send(BitConverter.GetBytes(newConn.PlayerIndex)); conns.Add(newConn); - var defaults = new GameRules.Settings(); + var defaults = new GameRules.PlayerSettings(); lobbyInfo.Clients.Add( new Session.Client() { diff --git a/OpenRA.Game/Sound.cs b/OpenRA.Game/Sound.cs index f47bb8e49e..bc8c871669 100644 --- a/OpenRA.Game/Sound.cs +++ b/OpenRA.Game/Sound.cs @@ -141,20 +141,20 @@ namespace OpenRA public static float SoundVolume { - get { return Game.Settings.SoundVolume; } + get { return Game.Settings.Sound.SoundVolume; } set { - Game.Settings.SoundVolume = value; + Game.Settings.Sound.SoundVolume = value; soundEngine.SetSoundVolume(value, music, video); } } public static float MusicVolume { - get { return Game.Settings.MusicVolume; } + get { return Game.Settings.Sound.MusicVolume; } set { - Game.Settings.MusicVolume = value; + Game.Settings.Sound.MusicVolume = value; if (music != null) music.Volume = value; } @@ -162,10 +162,10 @@ namespace OpenRA public static float VideoVolume { - get { return Game.Settings.VideoVolume; } + get { return Game.Settings.Sound.VideoVolume; } set { - Game.Settings.VideoVolume = value; + Game.Settings.Sound.VideoVolume = value; if (video != null) video.Volume = value; } diff --git a/OpenRA.Game/Traits/Player/DeveloperMode.cs b/OpenRA.Game/Traits/Player/DeveloperMode.cs index 77817e53fd..cbbad53970 100644 --- a/OpenRA.Game/Traits/Player/DeveloperMode.cs +++ b/OpenRA.Game/Traits/Player/DeveloperMode.cs @@ -79,7 +79,7 @@ namespace OpenRA.Traits case "DevUnitDebug": { if (self.World.LocalPlayer == self.Owner) - Game.Settings.UnitDebug ^= true; + Game.Settings.Debug.UnitDebug ^= true; break; } } diff --git a/OpenRA.Game/UiOverlay.cs b/OpenRA.Game/UiOverlay.cs index 2aa003bca3..3b32b116d0 100644 --- a/OpenRA.Game/UiOverlay.cs +++ b/OpenRA.Game/UiOverlay.cs @@ -42,7 +42,7 @@ namespace OpenRA public void Draw( World world ) { - if (Game.Settings.UnitDebug) + if (Game.Settings.Debug.UnitDebug) { var uim = world.WorldActor.Trait(); diff --git a/OpenRA.Game/Widgets/Delegates/CreateServerMenuDelegate.cs b/OpenRA.Game/Widgets/Delegates/CreateServerMenuDelegate.cs index c347450445..785990d673 100644 --- a/OpenRA.Game/Widgets/Delegates/CreateServerMenuDelegate.cs +++ b/OpenRA.Game/Widgets/Delegates/CreateServerMenuDelegate.cs @@ -36,29 +36,29 @@ namespace OpenRA.Widgets.Delegates var map = Game.modData.AvailableMaps.Keys.FirstOrDefault(); - settings.LastServerTitle = cs.GetWidget("GAME_TITLE").Text; - settings.ListenPort = int.Parse(cs.GetWidget("LISTEN_PORT").Text); - settings.ExternalPort = int.Parse(cs.GetWidget("EXTERNAL_PORT").Text); + settings.Server.LastServerTitle = cs.GetWidget("GAME_TITLE").Text; + settings.Server.ListenPort = int.Parse(cs.GetWidget("LISTEN_PORT").Text); + settings.Server.ExternalPort = int.Parse(cs.GetWidget("EXTERNAL_PORT").Text); settings.Save(); Server.Server.ServerMain(Game.modData, settings, map); - Game.JoinServer(IPAddress.Loopback.ToString(), settings.ListenPort); + Game.JoinServer(IPAddress.Loopback.ToString(), settings.Server.ListenPort); return true; }; - cs.GetWidget("GAME_TITLE").Text = settings.LastServerTitle; - cs.GetWidget("LISTEN_PORT").Text = settings.ListenPort.ToString(); - cs.GetWidget("EXTERNAL_PORT").Text = settings.ExternalPort.ToString(); - cs.GetWidget("CHECKBOX_ONLINE").Checked = () => settings.AdvertiseOnline; + cs.GetWidget("GAME_TITLE").Text = settings.Server.LastServerTitle; + cs.GetWidget("LISTEN_PORT").Text = settings.Server.ListenPort.ToString(); + cs.GetWidget("EXTERNAL_PORT").Text = settings.Server.ExternalPort.ToString(); + cs.GetWidget("CHECKBOX_ONLINE").Checked = () => settings.Server.AdvertiseOnline; cs.GetWidget("CHECKBOX_ONLINE").OnMouseDown = mi => { - settings.AdvertiseOnline ^= true; + settings.Server.AdvertiseOnline ^= true; settings.Save(); return true; }; - cs.GetWidget("CHECKBOX_CHEATS").Checked = () => settings.AllowCheats; + cs.GetWidget("CHECKBOX_CHEATS").Checked = () => settings.Server.AllowCheats; cs.GetWidget("CHECKBOX_CHEATS").OnMouseDown = mi => { - settings.AllowCheats ^=true; + settings.Server.AllowCheats ^=true; settings.Save(); return true; }; diff --git a/OpenRA.Game/Widgets/Delegates/DeveloperModeDelegate.cs b/OpenRA.Game/Widgets/Delegates/DeveloperModeDelegate.cs index 36c0d22931..ea086a4042 100644 --- a/OpenRA.Game/Widgets/Delegates/DeveloperModeDelegate.cs +++ b/OpenRA.Game/Widgets/Delegates/DeveloperModeDelegate.cs @@ -49,7 +49,7 @@ namespace OpenRA.Widgets.Delegates }; devmodeBG.GetWidget("SETTINGS_CHECKBOX_UNITDEBUG").Checked = - () => Game.Settings.UnitDebug; + () => Game.Settings.Debug.UnitDebug; devmodeBG.GetWidget("SETTINGS_CHECKBOX_UNITDEBUG").OnMouseDown = mi => { Game.IssueOrder(new Order("DevUnitDebug", Game.world.LocalPlayer.PlayerActor)); diff --git a/OpenRA.Game/Widgets/Delegates/LobbyDelegate.cs b/OpenRA.Game/Widgets/Delegates/LobbyDelegate.cs index be04fd0aa4..127e3b4ab8 100644 --- a/OpenRA.Game/Widgets/Delegates/LobbyDelegate.cs +++ b/OpenRA.Game/Widgets/Delegates/LobbyDelegate.cs @@ -33,8 +33,8 @@ namespace OpenRA.Widgets.Delegates Game.LobbyInfoChanged += UpdateCurrentMap; UpdateCurrentMap(); - CurrentColorPreview1 = Game.Settings.PlayerColor1; - CurrentColorPreview2 = Game.Settings.PlayerColor2; + CurrentColorPreview1 = Game.Settings.Player.PlayerColor1; + CurrentColorPreview2 = Game.Settings.Player.PlayerColor2; var r = Widget.RootWidget; var lobby = r.GetWidget("SERVER_LOBBY"); @@ -162,8 +162,8 @@ namespace OpenRA.Widgets.Delegates var c1 = ColorFromHSL(hf, sf, lf); var c2 = ColorFromHSL(hf, sf, r*lf); - Game.Settings.PlayerColor1 = c1; - Game.Settings.PlayerColor2 = c2; + Game.Settings.Player.PlayerColor1 = c1; + Game.Settings.Player.PlayerColor2 = c2; Game.Settings.Save(); Game.IssueOrder(Order.Command("color {0},{1},{2},{3},{4},{5}".F(c1.R,c1.G,c1.B,c2.R,c2.G,c2.B))); } @@ -220,15 +220,14 @@ namespace OpenRA.Widgets.Delegates return; hasJoined = true; - if (Game.LocalClient.Name != Game.Settings.PlayerName) - Game.IssueOrder(Order.Command("name " + Game.Settings.PlayerName)); + if (Game.LocalClient.Name != Game.Settings.Player.PlayerName) + Game.IssueOrder(Order.Command("name " + Game.Settings.Player.PlayerName)); + + var c1 = Game.Settings.Player.PlayerColor1; + var c2 = Game.Settings.Player.PlayerColor2; - if (Game.LocalClient.Color1 != Game.Settings.PlayerColor1 || Game.LocalClient.Color2 != Game.Settings.PlayerColor2) - { - var c1 = Game.Settings.PlayerColor1; - var c2 = Game.Settings.PlayerColor2; + if (Game.LocalClient.Color1 != c1 || Game.LocalClient.Color2 != c2) Game.IssueOrder(Order.Command("color {0},{1},{2},{3},{4},{5}".F(c1.R,c1.G,c1.B,c2.R,c2.G,c2.B))); - } } void ResetConnectionState() @@ -265,7 +264,7 @@ namespace OpenRA.Widgets.Delegates return true; Game.IssueOrder(Order.Command("name " + name.Text)); - Game.Settings.PlayerName = name.Text; + Game.Settings.Player.PlayerName = name.Text; Game.Settings.Save(); return true; }; diff --git a/OpenRA.Game/Widgets/Delegates/PerfDebugDelegate.cs b/OpenRA.Game/Widgets/Delegates/PerfDebugDelegate.cs index faa4810298..bfa5852a84 100644 --- a/OpenRA.Game/Widgets/Delegates/PerfDebugDelegate.cs +++ b/OpenRA.Game/Widgets/Delegates/PerfDebugDelegate.cs @@ -18,7 +18,7 @@ namespace OpenRA.Widgets.Delegates { var r = Widget.RootWidget; var perfRoot = r.GetWidget("PERF_BG"); - perfRoot.IsVisible = () => perfRoot.Visible && Game.Settings.PerfDebug; + perfRoot.IsVisible = () => perfRoot.Visible && Game.Settings.Debug.PerfDebug; // Perf text var perfText = perfRoot.GetWidget("TEXT"); diff --git a/OpenRA.Game/Widgets/Delegates/ServerBrowserDelegate.cs b/OpenRA.Game/Widgets/Delegates/ServerBrowserDelegate.cs index 9cd0531492..ec3eb07700 100644 --- a/OpenRA.Game/Widgets/Delegates/ServerBrowserDelegate.cs +++ b/OpenRA.Game/Widgets/Delegates/ServerBrowserDelegate.cs @@ -41,7 +41,7 @@ namespace OpenRA.Widgets.Delegates bg.Children.RemoveAll(a => GameButtons.Contains(a)); GameButtons.Clear(); - MasterServerQuery.Refresh(Game.Settings.MasterServer); + MasterServerQuery.Refresh(Game.Settings.Server.MasterServer); return true; }; @@ -76,7 +76,7 @@ namespace OpenRA.Widgets.Delegates bg.Children.RemoveAll(a => GameButtons.Contains(a)); GameButtons.Clear(); - MasterServerQuery.Refresh(Game.Settings.MasterServer); + MasterServerQuery.Refresh(Game.Settings.Server.MasterServer); return true; }; @@ -91,7 +91,7 @@ namespace OpenRA.Widgets.Delegates { r.CloseWindow(); - dc.GetWidget("SERVER_ADDRESS").Text = Game.Settings.LastServer; + dc.GetWidget("SERVER_ADDRESS").Text = Game.Settings.General.LastServer; r.OpenWindow("DIRECTCONNECT_BG"); return true; }; @@ -133,7 +133,7 @@ namespace OpenRA.Widgets.Delegates if (cpts.Length != 2) return true; - Game.Settings.LastServer = address; + Game.Settings.General.LastServer = address; Game.Settings.Save(); r.CloseWindow(); diff --git a/OpenRA.Game/Widgets/Delegates/SettingsMenuDelegate.cs b/OpenRA.Game/Widgets/Delegates/SettingsMenuDelegate.cs index c25fc291b4..c3aeb3b98a 100755 --- a/OpenRA.Game/Widgets/Delegates/SettingsMenuDelegate.cs +++ b/OpenRA.Game/Widgets/Delegates/SettingsMenuDelegate.cs @@ -34,31 +34,31 @@ namespace OpenRA.Widgets.Delegates var general = bg.GetWidget("GENERAL_PANE"); var name = general.GetWidget("NAME"); - name.Text = Game.Settings.PlayerName; + name.Text = Game.Settings.Player.PlayerName; name.OnLoseFocus = () => { name.Text = name.Text.Trim(); if (name.Text.Length == 0) - name.Text = Game.Settings.PlayerName; + name.Text = Game.Settings.Player.PlayerName; else - Game.Settings.PlayerName = name.Text; + Game.Settings.Player.PlayerName = name.Text; }; name.OnEnterKey = () => { name.LoseFocus(); return true; }; var edgeScroll = general.GetWidget("EDGE_SCROLL"); - edgeScroll.Checked = () => Game.Settings.ViewportEdgeScroll; + edgeScroll.Checked = () => Game.Settings.General.ViewportEdgeScroll; edgeScroll.OnMouseDown = mi => { - Game.Settings.ViewportEdgeScroll ^= true; + Game.Settings.General.ViewportEdgeScroll ^= true; return true; }; var inverseScroll = general.GetWidget("INVERSE_SCROLL"); - inverseScroll.Checked = () => Game.Settings.InverseDragScroll; + inverseScroll.Checked = () => Game.Settings.General.InverseDragScroll; inverseScroll.OnMouseDown = mi => { - Game.Settings.InverseDragScroll ^= true; + Game.Settings.General.InverseDragScroll ^= true; return true; }; @@ -77,47 +77,47 @@ namespace OpenRA.Widgets.Delegates // Display var display = bg.GetWidget("DISPLAY_PANE"); var fullscreen = display.GetWidget("FULLSCREEN_CHECKBOX"); - fullscreen.Checked = () => {return Game.Settings.WindowMode != WindowMode.Windowed;}; + fullscreen.Checked = () => {return Game.Settings.Graphics.WindowMode != WindowMode.Windowed;}; fullscreen.OnMouseDown = mi => { - Game.Settings.WindowMode = (Game.Settings.WindowMode == WindowMode.Windowed) ? WindowMode.PseudoFullscreen : WindowMode.Windowed; + Game.Settings.Graphics.WindowMode = (Game.Settings.Graphics.WindowMode == WindowMode.Windowed) ? WindowMode.PseudoFullscreen : WindowMode.Windowed; return true; }; var width = display.GetWidget("SCREEN_WIDTH"); - Game.Settings.WindowedSize.X = (Game.Settings.WindowedSize.X < Game.Settings.MinResolution.X)? - Game.Settings.MinResolution.X : Game.Settings.WindowedSize.X; - width.Text = Game.Settings.WindowedSize.X.ToString(); + Game.Settings.Graphics.WindowedSize.X = (Game.Settings.Graphics.WindowedSize.X < Game.Settings.Graphics.MinResolution.X)? + Game.Settings.Graphics.MinResolution.X : Game.Settings.Graphics.WindowedSize.X; + width.Text = Game.Settings.Graphics.WindowedSize.X.ToString(); width.OnLoseFocus = () => { try { var w = int.Parse(width.Text); - if (w > Game.Settings.MinResolution.X && w <= Screen.PrimaryScreen.Bounds.Size.Width) - Game.Settings.WindowedSize = new int2(w, Game.Settings.WindowedSize.Y); + if (w > Game.Settings.Graphics.MinResolution.X && w <= Screen.PrimaryScreen.Bounds.Size.Width) + Game.Settings.Graphics.WindowedSize = new int2(w, Game.Settings.Graphics.WindowedSize.Y); else - width.Text = Game.Settings.WindowedSize.X.ToString(); + width.Text = Game.Settings.Graphics.WindowedSize.X.ToString(); } catch (FormatException) { - width.Text = Game.Settings.WindowedSize.X.ToString(); + width.Text = Game.Settings.Graphics.WindowedSize.X.ToString(); } }; width.OnEnterKey = () => { width.LoseFocus(); return true; }; var height = display.GetWidget("SCREEN_HEIGHT"); - Game.Settings.WindowedSize.Y = (Game.Settings.WindowedSize.Y < Game.Settings.MinResolution.Y)? - Game.Settings.MinResolution.Y : Game.Settings.WindowedSize.Y; - height.Text = Game.Settings.WindowedSize.Y.ToString(); + Game.Settings.Graphics.WindowedSize.Y = (Game.Settings.Graphics.WindowedSize.Y < Game.Settings.Graphics.MinResolution.Y)? + Game.Settings.Graphics.MinResolution.Y : Game.Settings.Graphics.WindowedSize.Y; + height.Text = Game.Settings.Graphics.WindowedSize.Y.ToString(); height.OnLoseFocus = () => { try { var h = int.Parse(height.Text); - if (h > Game.Settings.MinResolution.Y && h <= Screen.PrimaryScreen.Bounds.Size.Height) - Game.Settings.WindowedSize = new int2(Game.Settings.WindowedSize.X, h); + if (h > Game.Settings.Graphics.MinResolution.Y && h <= Screen.PrimaryScreen.Bounds.Size.Height) + Game.Settings.Graphics.WindowedSize = new int2(Game.Settings.Graphics.WindowedSize.X, h); else - height.Text = Game.Settings.WindowedSize.Y.ToString(); + height.Text = Game.Settings.Graphics.WindowedSize.Y.ToString(); } catch (FormatException) { - height.Text = Game.Settings.WindowedSize.Y.ToString(); + height.Text = Game.Settings.Graphics.WindowedSize.Y.ToString(); } }; height.OnEnterKey = () => { height.LoseFocus(); return true; }; @@ -125,26 +125,26 @@ namespace OpenRA.Widgets.Delegates // Debug var debug = bg.GetWidget("DEBUG_PANE"); var perfdebug = debug.GetWidget("PERFDEBUG_CHECKBOX"); - perfdebug.Checked = () => {return Game.Settings.PerfDebug;}; + perfdebug.Checked = () => {return Game.Settings.Debug.PerfDebug;}; perfdebug.OnMouseDown = mi => { - Game.Settings.PerfDebug ^= true; + Game.Settings.Debug.PerfDebug ^= true; return true; }; var syncreports = debug.GetWidget("SYNCREPORTS_CHECKBOX"); - syncreports.Checked = () => { return Game.Settings.RecordSyncReports; }; + syncreports.Checked = () => { return Game.Settings.Debug.RecordSyncReports; }; syncreports.OnMouseDown = mi => { - Game.Settings.RecordSyncReports ^= true; + Game.Settings.Debug.RecordSyncReports ^= true; return true; }; var timedebug = debug.GetWidget("GAMETIME_CHECKBOX"); - timedebug.Checked = () => {return Game.Settings.ShowGameTimer;}; + timedebug.Checked = () => {return Game.Settings.Debug.ShowGameTimer;}; timedebug.OnMouseDown = mi => { - Game.Settings.ShowGameTimer ^= true; + Game.Settings.Debug.ShowGameTimer ^= true; return true; }; diff --git a/OpenRA.Game/Widgets/TimerWidget.cs b/OpenRA.Game/Widgets/TimerWidget.cs index d2c441b9be..10e6280c39 100644 --- a/OpenRA.Game/Widgets/TimerWidget.cs +++ b/OpenRA.Game/Widgets/TimerWidget.cs @@ -19,7 +19,7 @@ namespace OpenRA.Widgets public TimerWidget () { - IsVisible = () => Game.Settings.ShowGameTimer; + IsVisible = () => Game.Settings.Debug.ShowGameTimer; } public override void DrawInner(World world) diff --git a/OpenRA.Game/Widgets/ViewportScrollControllerWidget.cs b/OpenRA.Game/Widgets/ViewportScrollControllerWidget.cs index 253ed378fe..81686c64e0 100755 --- a/OpenRA.Game/Widgets/ViewportScrollControllerWidget.cs +++ b/OpenRA.Game/Widgets/ViewportScrollControllerWidget.cs @@ -39,7 +39,7 @@ namespace OpenRA.Widgets if (mi.Event == MouseInputEvent.Move && (mi.Button == MouseButton.Middle || mi.Button == (MouseButton.Left | MouseButton.Right))) { - int InverseScroll = Game.Settings.InverseDragScroll ? -1 : 1; + int InverseScroll = Game.Settings.General.InverseDragScroll ? -1 : 1; Game.viewport.Scroll((Viewport.LastMousePos - mi.Location) * InverseScroll); return true; } @@ -48,7 +48,7 @@ namespace OpenRA.Widgets public override string GetCursor(int2 pos) { - if (!Game.Settings.ViewportEdgeScroll) + if (!Game.Settings.General.ViewportEdgeScroll) return null; if (Edge.Includes(ScrollDirection.Up) && Edge.Includes(ScrollDirection.Left)) @@ -93,7 +93,7 @@ namespace OpenRA.Widgets public override void Tick(World world) { Edge = ScrollDirection.None; - if (Game.Settings.ViewportEdgeScroll) + if (Game.Settings.General.ViewportEdgeScroll) { // Check for edge-scroll if (Viewport.LastMousePos.X < EdgeScrollThreshold)