#region Copyright & License Information /* * Copyright 2007-2010 The OpenRA Developers (see AUTHORS) * This file is part of OpenRA, which is free software. It is made * available to you under the terms of the GNU General Public License * as published by the Free Software Foundation. For more information, * see LICENSE. */ #endregion using System; using System.Windows.Forms; using OpenRA.FileFormats.Graphics; using OpenRA.GameRules; namespace OpenRA.Widgets.Delegates { public class SettingsMenuDelegate : IWidgetDelegate { Widget bg; public SettingsMenuDelegate() { bg = Widget.RootWidget.GetWidget("SETTINGS_MENU"); var tabs = bg.GetWidget("TAB_CONTAINER"); //Tabs tabs.GetWidget("GENERAL").OnMouseUp = mi => FlipToTab("GENERAL_PANE"); tabs.GetWidget("AUDIO").OnMouseUp = mi => FlipToTab("AUDIO_PANE"); tabs.GetWidget("DISPLAY").OnMouseUp = mi => FlipToTab("DISPLAY_PANE"); tabs.GetWidget("DEBUG").OnMouseUp = mi => FlipToTab("DEBUG_PANE"); FlipToTab("GENERAL_PANE"); //General var general = bg.GetWidget("GENERAL_PANE"); var name = general.GetWidget("NAME"); name.Text = Game.Settings.PlayerName; name.OnLoseFocus = () => { name.Text = name.Text.Trim(); if (name.Text.Length == 0) name.Text = Game.Settings.PlayerName; else Game.Settings.PlayerName = name.Text; }; name.OnEnterKey = () => { name.LoseFocus(); return true; }; var edgeScroll = general.GetWidget("EDGE_SCROLL"); edgeScroll.Checked = () => Game.Settings.ViewportEdgeScroll; edgeScroll.OnMouseDown = mi => { Game.Settings.ViewportEdgeScroll ^= true; return true; }; var inverseScroll = general.GetWidget("INVERSE_SCROLL"); inverseScroll.Checked = () => Game.Settings.InverseDragScroll; inverseScroll.OnMouseDown = mi => { Game.Settings.InverseDragScroll ^= true; return true; }; // Audio var audio = bg.GetWidget("AUDIO_PANE"); var soundslider = audio.GetWidget("SOUND_VOLUME"); soundslider.OnChange += x => { Sound.SoundVolume = x; }; soundslider.GetOffset = () => { return Sound.SoundVolume; }; var musicslider = audio.GetWidget("MUSIC_VOLUME"); musicslider.OnChange += x => { Sound.MusicVolume = x; }; musicslider.GetOffset = () => { return Sound.MusicVolume; }; // Display var display = bg.GetWidget("DISPLAY_PANE"); var fullscreen = display.GetWidget("FULLSCREEN_CHECKBOX"); fullscreen.Checked = () => {return Game.Settings.WindowMode != WindowMode.Windowed;}; fullscreen.OnMouseDown = mi => { Game.Settings.WindowMode = (Game.Settings.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(); 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); else width.Text = Game.Settings.WindowedSize.X.ToString(); } catch (FormatException) { width.Text = Game.Settings.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(); 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); else height.Text = Game.Settings.WindowedSize.Y.ToString(); } catch (FormatException) { height.Text = Game.Settings.WindowedSize.Y.ToString(); } }; height.OnEnterKey = () => { height.LoseFocus(); return true; }; // Debug var debug = bg.GetWidget("DEBUG_PANE"); var perfdebug = debug.GetWidget("PERFDEBUG_CHECKBOX"); perfdebug.Checked = () => {return Game.Settings.PerfDebug;}; perfdebug.OnMouseDown = mi => { Game.Settings.PerfDebug ^= true; return true; }; var syncreports = debug.GetWidget("SYNCREPORTS_CHECKBOX"); syncreports.Checked = () => { return Game.Settings.RecordSyncReports; }; syncreports.OnMouseDown = mi => { Game.Settings.RecordSyncReports ^= true; return true; }; var timedebug = debug.GetWidget("GAMETIME_CHECKBOX"); timedebug.Checked = () => {return Game.Settings.ShowGameTimer;}; timedebug.OnMouseDown = mi => { Game.Settings.ShowGameTimer ^= true; return true; }; bg.GetWidget("BUTTON_CLOSE").OnMouseUp = mi => { Game.Settings.Save(); Widget.RootWidget.CloseWindow(); return true; }; // Menu Buttons Widget.RootWidget.GetWidget("MAINMENU_BUTTON_SETTINGS").OnMouseUp = mi => { Widget.RootWidget.OpenWindow("SETTINGS_MENU"); return true; }; } string open = null; bool FlipToTab(string id) { if (open != null) bg.GetWidget(open).Visible = false; open = id; bg.GetWidget(open).Visible = true; return true; } } }