diff --git a/Intersect.Client/Interface/Game/EscapeMenu.cs b/Intersect.Client/Interface/Game/EscapeMenu.cs index 00b4a9ef2..834759b0e 100644 --- a/Intersect.Client/Interface/Game/EscapeMenu.cs +++ b/Intersect.Client/Interface/Game/EscapeMenu.cs @@ -132,7 +132,7 @@ public void OpenSettingsWindow() /// public override void ToggleHidden() { - if (mSettingsWindow.IsVisible) + if (!mSettingsWindow.IsHidden) { return; } diff --git a/Intersect.Client/Interface/Shared/SettingsWindow.cs b/Intersect.Client/Interface/Shared/SettingsWindow.cs index 2e4901450..7fcc0c02d 100644 --- a/Intersect.Client/Interface/Shared/SettingsWindow.cs +++ b/Intersect.Client/Interface/Shared/SettingsWindow.cs @@ -15,176 +15,134 @@ namespace Intersect.Client.Interface.Shared; -public partial class SettingsWindow +public partial class SettingsWindow : ImagePanel { // Parent Window. - private readonly MainMenu mMainMenu; - - private readonly EscapeMenu mEscapeMenu; + private readonly MainMenu _mainMenu; + private readonly EscapeMenu _escapeMenu; // Settings Window. - private readonly Label mSettingsHeader; - - private readonly ImagePanel mSettingsPanel; - - private readonly Button mSettingsApplyBtn; - - private readonly Button mSettingsCancelBtn; + private readonly Label _settingsHeader; + private readonly Button _settingsApplyBtn; + private readonly Button _settingsCancelBtn; // Settings Containers. - private readonly ScrollControl mGameSettingsContainer; - - private readonly ScrollControl mVideoSettingsContainer; - - private readonly ScrollControl mAudioSettingsContainer; - - private readonly ScrollControl mKeybindingSettingsContainer; + private readonly ScrollControl _gameSettingsContainer; + private readonly ScrollControl _videoSettingsContainer; + private readonly ScrollControl _audioSettingsContainer; + private readonly ScrollControl _keybindingSettingsContainer; // Tabs. - private readonly Button mGameSettingsTab; - - private readonly Button mVideoSettingsTab; - - private readonly Button mAudioSettingsTab; - - private readonly Button mKeybindingSettingsTab; + private readonly Button _gameSettingsTab; + private readonly Button _videoSettingsTab; + private readonly Button _audioSettingsTab; + private readonly Button _keybindingSettingsTab; // Game Settings - Interface. - private readonly ScrollControl mInterfaceSettings; - - private readonly LabeledCheckBox mAutoCloseWindowsCheckbox; - - private readonly LabeledCheckBox mAutoToggleChatLogCheckbox; - - private readonly LabeledCheckBox mShowExperienceAsPercentageCheckbox; - - private readonly LabeledCheckBox mShowHealthAsPercentageCheckbox; - - private readonly LabeledCheckBox mShowManaAsPercentageCheckbox; + private readonly ScrollControl _interfaceSettings; + private readonly LabeledCheckBox _autoCloseWindowsCheckbox; + private readonly LabeledCheckBox _autoToggleChatLogCheckbox; + private readonly LabeledCheckBox _showExperienceAsPercentageCheckbox; + private readonly LabeledCheckBox _showHealthAsPercentageCheckbox; + private readonly LabeledCheckBox _showManaAsPercentageCheckbox; // Game Settings - Information. - private readonly ScrollControl mInformationSettings; - - private readonly LabeledCheckBox mFriendOverheadInfoCheckbox; - - private readonly LabeledCheckBox mGuildMemberOverheadInfoCheckbox; - - private readonly LabeledCheckBox mMyOverheadInfoCheckbox; - - private readonly LabeledCheckBox mNpcOverheadInfoCheckbox; - - private readonly LabeledCheckBox mPartyMemberOverheadInfoCheckbox; - - private readonly LabeledCheckBox mPlayerOverheadInfoCheckbox; - - private readonly LabeledCheckBox mFriendOverheadHpBarCheckbox; - - private readonly LabeledCheckBox mGuildMemberOverheadHpBarCheckbox; - - private readonly LabeledCheckBox mMyOverheadHpBarCheckbox; - - private readonly LabeledCheckBox mNpcOverheadHpBarCheckbox; - - private readonly LabeledCheckBox mPartyMemberOverheadHpBarCheckbox; - - private readonly LabeledCheckBox mPlayerOverheadHpBarCheckbox; - - private readonly LabeledCheckBox mTypewriterCheckbox; + private readonly ScrollControl _informationSettings; + private readonly LabeledCheckBox _friendOverheadInfoCheckbox; + private readonly LabeledCheckBox _guildMemberOverheadInfoCheckbox; + private readonly LabeledCheckBox _myOverheadInfoCheckbox; + private readonly LabeledCheckBox _npcOverheadInfoCheckbox; + private readonly LabeledCheckBox _partyMemberOverheadInfoCheckbox; + private readonly LabeledCheckBox _playerOverheadInfoCheckbox; + private readonly LabeledCheckBox _friendOverheadHpBarCheckbox; + private readonly LabeledCheckBox _guildMemberOverheadHpBarCheckbox; + private readonly LabeledCheckBox _myOverheadHpBarCheckbox; + private readonly LabeledCheckBox _mpcOverheadHpBarCheckbox; + private readonly LabeledCheckBox _partyMemberOverheadHpBarCheckbox; + private readonly LabeledCheckBox _playerOverheadHpBarCheckbox; + private readonly LabeledCheckBox _typewriterCheckbox; // Game Settings - Targeting. - private readonly ScrollControl mTargetingSettings; - - private readonly LabeledCheckBox mStickyTarget; - - private readonly LabeledCheckBox mAutoTurnToTarget; + private readonly ScrollControl _targetingSettings; + private readonly LabeledCheckBox _stickyTarget; + private readonly LabeledCheckBox _autoTurnToTarget; // Video Settings. - private readonly ComboBox mResolutionList; - - private MenuItem mCustomResolutionMenuItem; - - private readonly ComboBox mFpsList; - + private readonly ComboBox _resolutionList; + private MenuItem? _customResolutionMenuItem; + private readonly ComboBox _fpsList; private readonly LabeledHorizontalSlider _worldScale; - - private readonly LabeledHorizontalSlider _uiScale; - - private readonly LabeledCheckBox mFullscreenCheckbox; - - private readonly LabeledCheckBox mLightingEnabledCheckbox; + private readonly LabeledCheckBox _fullscreenCheckbox; + private readonly LabeledCheckBox _lightingEnabledCheckbox; // Audio Settings. - private readonly HorizontalSlider mMusicSlider; - - private int mPreviousMusicVolume; - - private readonly Label mMusicLabel; - - private readonly HorizontalSlider mSoundSlider; - - private int mPreviousSoundVolume; - - private readonly Label mSoundLabel; + private readonly HorizontalSlider _musicSlider; + private int _previousMusicVolume; + private readonly Label _musicLabel; + private readonly HorizontalSlider _soundSlider; + private int _previousSoundVolume; + private readonly Label _soundLabel; // Keybinding Settings. - private Control mKeybindingEditControl; - - private Controls mKeybindingEditControls; - - private Button? mKeybindingEditBtn; - - private readonly Button mKeybindingRestoreBtn; - - private long mKeybindingListeningTimer; - - private int mKeyEdit = -1; - - private readonly Dictionary mKeybindingBtns = new Dictionary(); + private Control _keybindingEditControl; + private Controls _keybindingEditControls = default!; + private Button? _keybindingEditBtn; + private readonly Button _keybindingRestoreBtn; + private long _keybindingListeningTimer; + private int _keyEdit = -1; + private readonly Dictionary mKeybindingBtns = []; // Open Settings. - private bool mReturnToMenu; + private bool _returnToMenu; // Initialize. - public SettingsWindow(Base parent, MainMenu mainMenu, EscapeMenu escapeMenu) + public SettingsWindow(Base parent, MainMenu mainMenu, EscapeMenu escapeMenu) : base(parent, "SettingsWindow") { // Assign References. - mMainMenu = mainMenu; - mEscapeMenu = escapeMenu; + _mainMenu = mainMenu; + _escapeMenu = escapeMenu; // Main Menu Window. - mSettingsPanel = new ImagePanel(parent, "SettingsWindow") { IsHidden = true }; - Interface.InputBlockingElements.Add(mSettingsPanel); + Interface.InputBlockingElements.Add(this); // Menu Header. - mSettingsHeader = new Label(mSettingsPanel, "SettingsHeader"); - mSettingsHeader.SetText(Strings.Settings.Title); + _settingsHeader = new Label(this, "SettingsHeader") + { + Text = Strings.Settings.Title + }; // Apply Button. - mSettingsApplyBtn = new Button(mSettingsPanel, "SettingsApplyBtn"); - mSettingsApplyBtn.SetText(Strings.Settings.Apply); - mSettingsApplyBtn.Clicked += SettingsApplyBtn_Clicked; + _settingsApplyBtn = new Button(this, "SettingsApplyBtn") + { + Text = Strings.Settings.Apply + }; + _settingsApplyBtn.Clicked += SettingsApplyBtn_Clicked; // Cancel Button. - mSettingsCancelBtn = new Button(mSettingsPanel, "SettingsCancelBtn"); - mSettingsCancelBtn.SetText(Strings.Settings.Cancel); - mSettingsCancelBtn.Clicked += SettingsCancelBtn_Clicked; + _settingsCancelBtn = new Button(this, "SettingsCancelBtn") + { + Text = Strings.Settings.Cancel + }; + _settingsCancelBtn.Clicked += SettingsCancelBtn_Clicked; #region InitGameSettings // Init GameSettings Tab. - mGameSettingsTab = new Button(mSettingsPanel, "GameSettingsTab"); - mGameSettingsTab.Text = Strings.Settings.GameSettingsTab; - mGameSettingsTab.Clicked += GameSettingsTab_Clicked; + _gameSettingsTab = new Button(this, "GameSettingsTab") + { + Text = Strings.Settings.GameSettingsTab + }; + _gameSettingsTab.Clicked += GameSettingsTab_Clicked; // Game Settings are stored in the GameSettings Scroll Control. - mGameSettingsContainer = new ScrollControl(mSettingsPanel, "GameSettingsContainer"); - mGameSettingsContainer.EnableScroll(false, false); + _gameSettingsContainer = new ScrollControl(this, "GameSettingsContainer"); + _gameSettingsContainer.EnableScroll(false, false); // Game Settings subcategories are stored in the GameSettings List. - var gameSettingsList = new ListBox(mGameSettingsContainer, "GameSettingsList"); - gameSettingsList.AddRow(Strings.Settings.InterfaceSettings); - gameSettingsList.AddRow(Strings.Settings.InformationSettings); - gameSettingsList.AddRow(Strings.Settings.TargetingSettings); + var gameSettingsList = new ListBox(_gameSettingsContainer, "GameSettingsList"); + _ = gameSettingsList.AddRow(Strings.Settings.InterfaceSettings); + _ = gameSettingsList.AddRow(Strings.Settings.InformationSettings); + _ = gameSettingsList.AddRow(Strings.Settings.TargetingSettings); gameSettingsList.EnableScroll(false, true); gameSettingsList.SelectedRowIndex = 0; gameSettingsList[0].Clicked += InterfaceSettings_Clicked; @@ -192,131 +150,166 @@ public SettingsWindow(Base parent, MainMenu mainMenu, EscapeMenu escapeMenu) gameSettingsList[2].Clicked += TargetingSettings_Clicked; // Game Settings - Interface. - mInterfaceSettings = new ScrollControl(mGameSettingsContainer, "InterfaceSettings"); - mInterfaceSettings.EnableScroll(false, true); + _interfaceSettings = new ScrollControl(_gameSettingsContainer, "InterfaceSettings"); + _interfaceSettings.EnableScroll(false, true); // Game Settings - Interface: Auto-close Windows. - mAutoCloseWindowsCheckbox = new LabeledCheckBox(mInterfaceSettings, "AutoCloseWindowsCheckbox"); - mAutoCloseWindowsCheckbox.Text = Strings.Settings.AutoCloseWindows; + _autoCloseWindowsCheckbox = new LabeledCheckBox(_interfaceSettings, "AutoCloseWindowsCheckbox") + { + Text = Strings.Settings.AutoCloseWindows + }; // Game Settings - Interface: Auto-toggle chat log visibility. - mAutoToggleChatLogCheckbox = new LabeledCheckBox(mInterfaceSettings, "AutoToggleChatLogCheckbox"); - mAutoToggleChatLogCheckbox.Text = Strings.Settings.AutoToggleChatLog; + _autoToggleChatLogCheckbox = new LabeledCheckBox(_interfaceSettings, "AutoToggleChatLogCheckbox") + { + Text = Strings.Settings.AutoToggleChatLog + }; // Game Settings - Interface: Show EXP/HP/MP as Percentage. - mShowExperienceAsPercentageCheckbox = - new LabeledCheckBox(mInterfaceSettings, "ShowExperienceAsPercentageCheckbox"); - mShowExperienceAsPercentageCheckbox.Text = Strings.Settings.ShowExperienceAsPercentage; - mShowHealthAsPercentageCheckbox = new LabeledCheckBox(mInterfaceSettings, "ShowHealthAsPercentageCheckbox"); - mShowHealthAsPercentageCheckbox.Text = Strings.Settings.ShowHealthAsPercentage; - mShowManaAsPercentageCheckbox = new LabeledCheckBox(mInterfaceSettings, "ShowManaAsPercentageCheckbox"); - mShowManaAsPercentageCheckbox.Text = Strings.Settings.ShowManaAsPercentage; + _showExperienceAsPercentageCheckbox = new LabeledCheckBox(_interfaceSettings, "ShowExperienceAsPercentageCheckbox") + { + Text = Strings.Settings.ShowExperienceAsPercentage + }; + + _showHealthAsPercentageCheckbox = new LabeledCheckBox(_interfaceSettings, "ShowHealthAsPercentageCheckbox") + { + Text = Strings.Settings.ShowHealthAsPercentage + }; + + _showManaAsPercentageCheckbox = new LabeledCheckBox(_interfaceSettings, "ShowManaAsPercentageCheckbox") + { + Text = Strings.Settings.ShowManaAsPercentage + }; // Game Settings - Information. - mInformationSettings = new ScrollControl(mGameSettingsContainer, "InformationSettings"); - mInformationSettings.EnableScroll(false, true); + _informationSettings = new ScrollControl(_gameSettingsContainer, "InformationSettings"); + _informationSettings.EnableScroll(false, true); // Game Settings - Information: Friends. - mFriendOverheadInfoCheckbox = - new LabeledCheckBox(mInformationSettings, "FriendOverheadInfoCheckbox"); - mFriendOverheadInfoCheckbox.Text = Strings.Settings.ShowFriendOverheadInformation; + _friendOverheadInfoCheckbox = new LabeledCheckBox(_informationSettings, "FriendOverheadInfoCheckbox") + { + Text = Strings.Settings.ShowFriendOverheadInformation + }; // Game Settings - Information: Guild Members. - mGuildMemberOverheadInfoCheckbox = - new LabeledCheckBox(mInformationSettings, "GuildMemberOverheadInfoCheckbox"); - mGuildMemberOverheadInfoCheckbox.Text = Strings.Settings.ShowGuildOverheadInformation; + _guildMemberOverheadInfoCheckbox = new LabeledCheckBox(_informationSettings, "GuildMemberOverheadInfoCheckbox") + { + Text = Strings.Settings.ShowGuildOverheadInformation + }; // Game Settings - Information: Myself. - mMyOverheadInfoCheckbox = new LabeledCheckBox(mInformationSettings, "MyOverheadInfoCheckbox"); - mMyOverheadInfoCheckbox.Text = Strings.Settings.ShowMyOverheadInformation; + _myOverheadInfoCheckbox = new LabeledCheckBox(_informationSettings, "MyOverheadInfoCheckbox") + { + Text = Strings.Settings.ShowMyOverheadInformation + }; // Game Settings - Information: NPCs. - mNpcOverheadInfoCheckbox = new LabeledCheckBox(mInformationSettings, "NpcOverheadInfoCheckbox"); - mNpcOverheadInfoCheckbox.Text = Strings.Settings.ShowNpcOverheadInformation; + _npcOverheadInfoCheckbox = new LabeledCheckBox(_informationSettings, "NpcOverheadInfoCheckbox") + { + Text = Strings.Settings.ShowNpcOverheadInformation + }; // Game Settings - Information: Party Members. - mPartyMemberOverheadInfoCheckbox = - new LabeledCheckBox(mInformationSettings, "PartyMemberOverheadInfoCheckbox"); - mPartyMemberOverheadInfoCheckbox.Text = Strings.Settings.ShowPartyOverheadInformation; + _partyMemberOverheadInfoCheckbox = new LabeledCheckBox(_informationSettings, "PartyMemberOverheadInfoCheckbox") + { + Text = Strings.Settings.ShowPartyOverheadInformation + }; // Game Settings - Information: Players. - mPlayerOverheadInfoCheckbox = - new LabeledCheckBox(mInformationSettings, "PlayerOverheadInfoCheckbox"); - mPlayerOverheadInfoCheckbox.Text = Strings.Settings.ShowPlayerOverheadInformation; + _playerOverheadInfoCheckbox = new LabeledCheckBox(_informationSettings, "PlayerOverheadInfoCheckbox") + { + Text = Strings.Settings.ShowPlayerOverheadInformation + }; // Game Settings - Information: friends overhead hp bar. - mFriendOverheadHpBarCheckbox = - new LabeledCheckBox(mInformationSettings, "FriendOverheadHpBarCheckbox"); - mFriendOverheadHpBarCheckbox.Text = Strings.Settings.ShowFriendOverheadHpBar; + _friendOverheadHpBarCheckbox = new LabeledCheckBox(_informationSettings, "FriendOverheadHpBarCheckbox") + { + Text = Strings.Settings.ShowFriendOverheadHpBar + }; // Game Settings - Information: guild members overhead hp bar. - mGuildMemberOverheadHpBarCheckbox = - new LabeledCheckBox(mInformationSettings, "GuildMemberOverheadHpBarCheckbox"); - mGuildMemberOverheadHpBarCheckbox.Text = Strings.Settings.ShowGuildOverheadHpBar; + _guildMemberOverheadHpBarCheckbox = new LabeledCheckBox(_informationSettings, "GuildMemberOverheadHpBarCheckbox") + { + Text = Strings.Settings.ShowGuildOverheadHpBar + }; // Game Settings - Information: my overhead hp bar. - mMyOverheadHpBarCheckbox = - new LabeledCheckBox(mInformationSettings, "MyOverheadHpBarCheckbox"); - mMyOverheadHpBarCheckbox.Text = Strings.Settings.ShowMyOverheadHpBar; + _myOverheadHpBarCheckbox = new LabeledCheckBox(_informationSettings, "MyOverheadHpBarCheckbox") + { + Text = Strings.Settings.ShowMyOverheadHpBar + }; // Game Settings - Information: NPC overhead hp bar. - mNpcOverheadHpBarCheckbox = - new LabeledCheckBox(mInformationSettings, "NpcOverheadHpBarCheckbox"); - mNpcOverheadHpBarCheckbox.Text = Strings.Settings.ShowNpcOverheadHpBar; + _mpcOverheadHpBarCheckbox = new LabeledCheckBox(_informationSettings, "NpcOverheadHpBarCheckbox") + { + Text = Strings.Settings.ShowNpcOverheadHpBar + }; // Game Settings - Information: party members overhead hp bar. - mPartyMemberOverheadHpBarCheckbox = - new LabeledCheckBox(mInformationSettings, "PartyMemberOverheadHpBarCheckbox"); - mPartyMemberOverheadHpBarCheckbox.Text = Strings.Settings.ShowPartyOverheadHpBar; + _partyMemberOverheadHpBarCheckbox = new LabeledCheckBox(_informationSettings, "PartyMemberOverheadHpBarCheckbox") + { + Text = Strings.Settings.ShowPartyOverheadHpBar + }; // Game Settings - Information: players overhead hp bar. - mPlayerOverheadHpBarCheckbox = - new LabeledCheckBox(mInformationSettings, "PlayerOverheadHpBarCheckbox"); - mPlayerOverheadHpBarCheckbox.Text = Strings.Settings.ShowPlayerOverheadHpBar; + _playerOverheadHpBarCheckbox = new LabeledCheckBox(_informationSettings, "PlayerOverheadHpBarCheckbox") + { + Text = Strings.Settings.ShowPlayerOverheadHpBar + }; // Game Settings - Targeting. - mTargetingSettings = new ScrollControl(mGameSettingsContainer, "TargetingSettings"); - mTargetingSettings.EnableScroll(false, false); + _targetingSettings = new ScrollControl(_gameSettingsContainer, "TargetingSettings"); + _targetingSettings.EnableScroll(false, false); // Game Settings - Targeting: Sticky Target. - mStickyTarget = new LabeledCheckBox(mTargetingSettings, "StickyTargetCheckbox"); - mStickyTarget.Text = Strings.Settings.StickyTarget; + _stickyTarget = new LabeledCheckBox(_targetingSettings, "StickyTargetCheckbox") + { + Text = Strings.Settings.StickyTarget + }; // Game Settings - Targeting: Auto-turn to Target. - mAutoTurnToTarget = new LabeledCheckBox(mTargetingSettings, "AutoTurnToTargetCheckbox"); - mAutoTurnToTarget.Text = Strings.Settings.AutoTurnToTarget; + _autoTurnToTarget = new LabeledCheckBox(_targetingSettings, "AutoTurnToTargetCheckbox") + { + Text = Strings.Settings.AutoTurnToTarget + }; // Game Settings - Typewriter Text - mTypewriterCheckbox = new LabeledCheckBox(mInterfaceSettings, "TypewriterCheckbox"); - mTypewriterCheckbox.Text = Strings.Settings.TypewriterText; + _typewriterCheckbox = new LabeledCheckBox(_interfaceSettings, "TypewriterCheckbox") + { + Text = Strings.Settings.TypewriterText + }; #endregion #region InitVideoSettings // Init VideoSettings Tab. - mVideoSettingsTab = new Button(mSettingsPanel, "VideoSettingsTab"); - mVideoSettingsTab.Text = Strings.Settings.VideoSettingsTab; - mVideoSettingsTab.Clicked += VideoSettingsTab_Clicked; + _videoSettingsTab = new Button(this, "VideoSettingsTab") + { + Text = Strings.Settings.VideoSettingsTab + }; + _videoSettingsTab.Clicked += VideoSettingsTab_Clicked; // Video Settings Get Stored in the VideoSettings Scroll Control. - mVideoSettingsContainer = new ScrollControl(mSettingsPanel, "VideoSettingsContainer"); - mVideoSettingsContainer.EnableScroll(false, false); + _videoSettingsContainer = new ScrollControl(this, "VideoSettingsContainer"); + _videoSettingsContainer.EnableScroll(false, false); // Video Settings - Resolution Background. - var resolutionBackground = new ImagePanel(mVideoSettingsContainer, "ResolutionPanel"); + var resolutionBackground = new ImagePanel(_videoSettingsContainer, "ResolutionPanel"); // Video Settings - Resolution Label. - var resolutionLabel = new Label(resolutionBackground, "ResolutionLabel"); - resolutionLabel.SetText(Strings.Settings.Resolution); + var resolutionLabel = new Label(resolutionBackground, "ResolutionLabel") + { + Text = Strings.Settings.Resolution + }; // Video Settings - Resolution List. - mResolutionList = new ComboBox(resolutionBackground, "ResolutionCombobox"); - var myModes = Graphics.Renderer.GetValidVideoModes(); + _resolutionList = new ComboBox(resolutionBackground, "ResolutionCombobox"); + var myModes = Graphics.Renderer?.GetValidVideoModes(); myModes?.ForEach( t => { - var item = mResolutionList.AddItem(t); + var item = _resolutionList.AddItem(t); item.Alignment = Pos.Left; } ); @@ -324,7 +317,7 @@ public SettingsWindow(Base parent, MainMenu mainMenu, EscapeMenu escapeMenu) Globals.Database.WorldZoom = MathHelper.Clamp(Globals.Database.WorldZoom, 1, 4); var worldScaleNotches = new double[] { 1, 2, 4 }.Select(n => n * Graphics.BaseWorldScale).ToArray(); - _worldScale = new LabeledHorizontalSlider(mVideoSettingsContainer, "WorldScale") + _worldScale = new LabeledHorizontalSlider(_videoSettingsContainer, "WorldScale") { Label = Strings.Settings.WorldScale, Min = worldScaleNotches.Min(), @@ -334,40 +327,32 @@ public SettingsWindow(Base parent, MainMenu mainMenu, EscapeMenu escapeMenu) Value = Globals.Database.WorldZoom, }; - // _uiScale = new LabeledHorizontalSlider(mVideoSettingsContainer, "UIScale") - // { - // Label = Strings.Settings.UIScale, - // Min = 0.5f, - // Max = 4f, - // Notches = new double[] { 0.5, 1, 2, 4 }, - // SnapToNotches = true, - // Value = 1f, - // }; - // Video Settings - FPS Background. - var fpsBackground = new ImagePanel(mVideoSettingsContainer, "FPSPanel"); + var fpsBackground = new ImagePanel(_videoSettingsContainer, "FPSPanel"); // Video Settings - FPS Label. - var fpsLabel = new Label(fpsBackground, "FPSLabel"); - fpsLabel.SetText(Strings.Settings.TargetFps); - + var fpsLabel = new Label(fpsBackground, "FPSLabel") + { + Text = Strings.Settings.TargetFps + }; + // Video Settings - FPS List. - mFpsList = new ComboBox(fpsBackground, "FPSCombobox"); - mFpsList.AddItem(Strings.Settings.Vsync); - mFpsList.AddItem(Strings.Settings.Fps30); - mFpsList.AddItem(Strings.Settings.Fps60); - mFpsList.AddItem(Strings.Settings.Fps90); - mFpsList.AddItem(Strings.Settings.Fps120); - mFpsList.AddItem(Strings.Settings.UnlimitedFps); + _fpsList = new ComboBox(fpsBackground, "FPSCombobox"); + _ = _fpsList.AddItem(Strings.Settings.Vsync); + _ = _fpsList.AddItem(Strings.Settings.Fps30); + _ = _fpsList.AddItem(Strings.Settings.Fps60); + _ = _fpsList.AddItem(Strings.Settings.Fps90); + _ = _fpsList.AddItem(Strings.Settings.Fps120); + _ = _fpsList.AddItem(Strings.Settings.UnlimitedFps); // Video Settings - Fullscreen Checkbox. - mFullscreenCheckbox = new LabeledCheckBox(mVideoSettingsContainer, "FullscreenCheckbox") + _fullscreenCheckbox = new LabeledCheckBox(_videoSettingsContainer, "FullscreenCheckbox") { Text = Strings.Settings.Fullscreen }; // Video Settings - Enable Lighting Checkbox - mLightingEnabledCheckbox = new LabeledCheckBox(mVideoSettingsContainer, "EnableLightingCheckbox") + _lightingEnabledCheckbox = new LabeledCheckBox(_videoSettingsContainer, "EnableLightingCheckbox") { Text = Strings.Settings.EnableLighting }; @@ -377,51 +362,65 @@ public SettingsWindow(Base parent, MainMenu mainMenu, EscapeMenu escapeMenu) #region InitAudioSettings // Init AudioSettingsTab. - mAudioSettingsTab = new Button(mSettingsPanel, "AudioSettingsTab"); - mAudioSettingsTab.Text = Strings.Settings.AudioSettingsTab; - mAudioSettingsTab.Clicked += AudioSettingsTab_Clicked; + _audioSettingsTab = new Button(this, "AudioSettingsTab") + { + Text = Strings.Settings.AudioSettingsTab + }; + _audioSettingsTab.Clicked += AudioSettingsTab_Clicked; // Audio Settings Get Stored in the AudioSettings Scroll Control. - mAudioSettingsContainer = new ScrollControl(mSettingsPanel, "AudioSettingsContainer"); - mAudioSettingsContainer.EnableScroll(false, false); + _audioSettingsContainer = new ScrollControl(this, "AudioSettingsContainer"); + _audioSettingsContainer.EnableScroll(false, false); // Audio Settings - Sound Label - mSoundLabel = new Label(mAudioSettingsContainer, "SoundLabel"); - mSoundLabel.SetText(Strings.Settings.SoundVolume.ToString(100)); + _soundLabel = new Label(_audioSettingsContainer, "SoundLabel") + { + Text = Strings.Settings.SoundVolume.ToString(100) + }; // Audio Settings - Sound Slider - mSoundSlider = new HorizontalSlider(mAudioSettingsContainer, "SoundSlider"); - mSoundSlider.Min = 0; - mSoundSlider.Max = 100; - mSoundSlider.ValueChanged += SoundSlider_ValueChanged; + _soundSlider = new HorizontalSlider(_audioSettingsContainer, "SoundSlider") + { + Min = 0, + Max = 100 + }; + _soundSlider.ValueChanged += SoundSlider_ValueChanged; // Audio Settings - Music Label - mMusicLabel = new Label(mAudioSettingsContainer, "MusicLabel"); - mMusicLabel.SetText(Strings.Settings.MusicVolume.ToString(100)); + _musicLabel = new Label(_audioSettingsContainer, "MusicLabel") + { + Text = Strings.Settings.MusicVolume.ToString(100) + }; // Audio Settings - Music Slider - mMusicSlider = new HorizontalSlider(mAudioSettingsContainer, "MusicSlider"); - mMusicSlider.Min = 0; - mMusicSlider.Max = 100; - mMusicSlider.ValueChanged += MusicSlider_ValueChanged; + _musicSlider = new HorizontalSlider(_audioSettingsContainer, "MusicSlider") + { + Min = 0, + Max = 100 + }; + _musicSlider.ValueChanged += MusicSlider_ValueChanged; #endregion #region InitKeybindingSettings // Init KeybindingsSettings Tab. - mKeybindingSettingsTab = new Button(mSettingsPanel, "KeybindingSettingsTab"); - mKeybindingSettingsTab.Text = Strings.Settings.KeyBindingSettingsTab; - mKeybindingSettingsTab.Clicked += KeybindingSettingsTab_Clicked; + _keybindingSettingsTab = new Button(this, "KeybindingSettingsTab") + { + Text = Strings.Settings.KeyBindingSettingsTab + }; + _keybindingSettingsTab.Clicked += KeybindingSettingsTab_Clicked; // KeybindingSettings Get Stored in the KeybindingSettings Scroll Control - mKeybindingSettingsContainer = new ScrollControl(mSettingsPanel, "KeybindingSettingsContainer"); - mKeybindingSettingsContainer.EnableScroll(false, true); + _keybindingSettingsContainer = new ScrollControl(this, "KeybindingSettingsContainer"); + _keybindingSettingsContainer.EnableScroll(false, true); // Keybinding Settings - Restore Default Keys Button. - mKeybindingRestoreBtn = new Button(mSettingsPanel, "KeybindingsRestoreBtn"); - mKeybindingRestoreBtn.Text = Strings.Settings.Restore; - mKeybindingRestoreBtn.Clicked += KeybindingsRestoreBtn_Clicked; + _keybindingRestoreBtn = new Button(this, "KeybindingsRestoreBtn") + { + Text = Strings.Settings.Restore + }; + _keybindingRestoreBtn.Clicked += KeybindingsRestoreBtn_Clicked; // Keybinding Settings - Controls var row = 0; @@ -429,19 +428,19 @@ public SettingsWindow(Base parent, MainMenu mainMenu, EscapeMenu escapeMenu) foreach (Control control in Enum.GetValues(typeof(Control))) { var offset = row++ * 32; - var name = Enum.GetName(typeof(Control), control)?.ToLower(); + var name = Enum.GetName(typeof(Control), control)?.ToLower() ?? string.Empty; var prefix = $"Control{Enum.GetName(typeof(Control), control)}"; - var label = new Label(mKeybindingSettingsContainer, $"{prefix}Label") + var label = new Label(_keybindingSettingsContainer, $"{prefix}Label") { Text = Strings.Controls.KeyDictionary[name], AutoSizeToContents = true, Font = defaultFont, }; - label.SetBounds(14, 11 + offset, 21, 16); + _ = label.SetBounds(14, 11 + offset, 21, 16); label.SetTextColor(new Color(255, 255, 255, 255), Label.ControlState.Normal); - var key1 = new Button(mKeybindingSettingsContainer, $"{prefix}Button1") + var key1 = new Button(_keybindingSettingsContainer, $"{prefix}Button1") { AutoSizeToContents = false, Font = defaultFont, @@ -454,10 +453,10 @@ public SettingsWindow(Base parent, MainMenu mainMenu, EscapeMenu escapeMenu) key1.SetImage("control_button_clicked.png", Button.ControlState.Clicked); key1.SetHoverSound("octave-tap-resonant.wav"); key1.SetMouseDownSound("octave-tap-warm.wav"); - key1.SetBounds(181, 6 + offset, 120, 28); + _ = key1.SetBounds(181, 6 + offset, 120, 28); key1.Clicked += Key_Clicked; - var key2 = new Button(mKeybindingSettingsContainer, $"{prefix}Button2") + var key2 = new Button(_keybindingSettingsContainer, $"{prefix}Button2") { AutoSizeToContents = false, Font = defaultFont, @@ -470,10 +469,10 @@ public SettingsWindow(Base parent, MainMenu mainMenu, EscapeMenu escapeMenu) key2.SetImage("control_button_clicked.png", Button.ControlState.Clicked); key2.SetHoverSound("octave-tap-resonant.wav"); key2.SetMouseDownSound("octave-tap-warm.wav"); - key2.SetBounds(309, 6 + offset, 120, 28); + _ = key2.SetBounds(309, 6 + offset, 120, 28); key2.Clicked += Key_Clicked; - mKeybindingBtns.Add(control, new[] { key1, key2 }); + mKeybindingBtns.Add(control, [key1, key2]); } Input.KeyDown += OnKeyDown; @@ -483,121 +482,122 @@ public SettingsWindow(Base parent, MainMenu mainMenu, EscapeMenu escapeMenu) #endregion - mSettingsPanel.LoadJsonUi(UI.Shared, Graphics.Renderer.GetResolutionString()); + LoadJsonUi(UI.Shared, Graphics.Renderer?.GetResolutionString()); + IsHidden = true; } private void GameSettingsTab_Clicked(Base sender, ClickedEventArgs arguments) { // Determine if GameSettingsContainer is currently being shown or not. - if (!mGameSettingsContainer.IsVisible) + if (!_gameSettingsContainer.IsVisible) { // Disable the GameSettingsTab to fake it being selected visually. - mGameSettingsTab.Disable(); - mVideoSettingsTab.Enable(); - mAudioSettingsTab.Enable(); - mKeybindingSettingsTab.Enable(); + _gameSettingsTab.Disable(); + _videoSettingsTab.Enable(); + _audioSettingsTab.Enable(); + _keybindingSettingsTab.Enable(); // Containers. - mGameSettingsContainer.Show(); - mVideoSettingsContainer.Hide(); - mAudioSettingsContainer.Hide(); - mKeybindingSettingsContainer.Hide(); + _gameSettingsContainer.Show(); + _videoSettingsContainer.Hide(); + _audioSettingsContainer.Hide(); + _keybindingSettingsContainer.Hide(); // Restore Default KeybindingSettings Button. - mKeybindingRestoreBtn.Hide(); + _keybindingRestoreBtn.Hide(); } } void InterfaceSettings_Clicked(Base sender, ClickedEventArgs arguments) { - mInterfaceSettings.Show(); - mInformationSettings.Hide(); - mTargetingSettings.Hide(); + _interfaceSettings.Show(); + _informationSettings.Hide(); + _targetingSettings.Hide(); } void InformationSettings_Clicked(Base sender, ClickedEventArgs arguments) { - mInterfaceSettings.Hide(); - mInformationSettings.Show(); - mTargetingSettings.Hide(); + _interfaceSettings.Hide(); + _informationSettings.Show(); + _targetingSettings.Hide(); } void TargetingSettings_Clicked(Base sender, ClickedEventArgs arguments) { - mInterfaceSettings.Hide(); - mInformationSettings.Hide(); - mTargetingSettings.Show(); - mAutoTurnToTarget.IsDisabled = !(Options.Instance?.PlayerOpts?.EnableAutoTurnToTarget ?? false); + _interfaceSettings.Hide(); + _informationSettings.Hide(); + _targetingSettings.Show(); + _autoTurnToTarget.IsDisabled = !(Options.Instance?.PlayerOpts?.EnableAutoTurnToTarget ?? false); } private void VideoSettingsTab_Clicked(Base sender, ClickedEventArgs arguments) { // Determine if VideoSettingsContainer is currently being shown or not. - if (!mVideoSettingsContainer.IsVisible) + if (!_videoSettingsContainer.IsVisible) { // Disable the VideoSettingsTab to fake it being selected visually. - mGameSettingsTab.Enable(); - mVideoSettingsTab.Disable(); - mAudioSettingsTab.Enable(); - mKeybindingSettingsTab.Enable(); + _gameSettingsTab.Enable(); + _videoSettingsTab.Disable(); + _audioSettingsTab.Enable(); + _keybindingSettingsTab.Enable(); // Containers. - mGameSettingsContainer.Hide(); - mVideoSettingsContainer.Show(); - mAudioSettingsContainer.Hide(); - mKeybindingSettingsContainer.Hide(); + _gameSettingsContainer.Hide(); + _videoSettingsContainer.Show(); + _audioSettingsContainer.Hide(); + _keybindingSettingsContainer.Hide(); // Restore Default KeybindingSettings Button. - mKeybindingRestoreBtn.Hide(); + _keybindingRestoreBtn.Hide(); } } private void AudioSettingsTab_Clicked(Base sender, ClickedEventArgs arguments) { // Determine if AudioSettingsContainer is currently being shown or not. - if (!mAudioSettingsContainer.IsVisible) + if (!_audioSettingsContainer.IsVisible) { // Disable the AudioSettingsTab to fake it being selected visually. - mGameSettingsTab.Enable(); - mVideoSettingsTab.Enable(); - mAudioSettingsTab.Disable(); - mKeybindingSettingsTab.Enable(); + _gameSettingsTab.Enable(); + _videoSettingsTab.Enable(); + _audioSettingsTab.Disable(); + _keybindingSettingsTab.Enable(); // Containers. - mGameSettingsContainer.Hide(); - mVideoSettingsContainer.Hide(); - mAudioSettingsContainer.Show(); - mKeybindingSettingsContainer.Hide(); + _gameSettingsContainer.Hide(); + _videoSettingsContainer.Hide(); + _audioSettingsContainer.Show(); + _keybindingSettingsContainer.Hide(); // Restore Default KeybindingSettings Button. - mKeybindingRestoreBtn.Hide(); + _keybindingRestoreBtn.Hide(); } } private void KeybindingSettingsTab_Clicked(Base sender, ClickedEventArgs arguments) { // Determine if controls are currently being shown or not. - if (!mKeybindingSettingsContainer.IsVisible) + if (!_keybindingSettingsContainer.IsVisible) { // Disable the KeybindingSettingsTab to fake it being selected visually. - mGameSettingsTab.Enable(); - mVideoSettingsTab.Enable(); - mAudioSettingsTab.Enable(); - mKeybindingSettingsTab.Disable(); + _gameSettingsTab.Enable(); + _videoSettingsTab.Enable(); + _audioSettingsTab.Enable(); + _keybindingSettingsTab.Disable(); // Containers. - mGameSettingsContainer.Hide(); - mVideoSettingsContainer.Hide(); - mAudioSettingsContainer.Hide(); - mKeybindingSettingsContainer.Show(); + _gameSettingsContainer.Hide(); + _videoSettingsContainer.Hide(); + _audioSettingsContainer.Hide(); + _keybindingSettingsContainer.Show(); // Restore Default KeybindingSettings Button. - mKeybindingRestoreBtn.Show(); + _keybindingRestoreBtn.Show(); // KeybindingBtns. foreach (Control control in Enum.GetValues(typeof(Control))) { - var controlMapping = mKeybindingEditControls.ControlMapping[control]; + var controlMapping = _keybindingEditControls.ControlMapping[control]; for (var bindingIndex = 0; bindingIndex < controlMapping.Bindings.Count; bindingIndex++) { var binding = controlMapping.Bindings[bindingIndex]; @@ -610,30 +610,30 @@ private void KeybindingSettingsTab_Clicked(Base sender, ClickedEventArgs argumen private void LoadSettingsWindow() { // Settings Window Title. - mSettingsHeader.SetText(Strings.Settings.Title); + _settingsHeader.SetText(Strings.Settings.Title); // Containers. - mGameSettingsContainer.Show(); - mVideoSettingsContainer.Hide(); - mAudioSettingsContainer.Hide(); - mKeybindingSettingsContainer.Hide(); + _gameSettingsContainer.Show(); + _videoSettingsContainer.Hide(); + _audioSettingsContainer.Hide(); + _keybindingSettingsContainer.Hide(); // Tabs. - mGameSettingsTab.Show(); - mVideoSettingsTab.Show(); - mAudioSettingsTab.Show(); - mKeybindingSettingsTab.Show(); + _gameSettingsTab.Show(); + _videoSettingsTab.Show(); + _audioSettingsTab.Show(); + _keybindingSettingsTab.Show(); // Disable the GameSettingsTab to fake it being selected visually by default. - mGameSettingsTab.Disable(); - mVideoSettingsTab.Enable(); - mAudioSettingsTab.Enable(); - mKeybindingSettingsTab.Enable(); + _gameSettingsTab.Disable(); + _videoSettingsTab.Enable(); + _audioSettingsTab.Enable(); + _keybindingSettingsTab.Enable(); // Buttons. - mSettingsApplyBtn.Show(); - mSettingsCancelBtn.Show(); - mKeybindingRestoreBtn.Hide(); + _settingsApplyBtn.Show(); + _settingsCancelBtn.Show(); + _keybindingRestoreBtn.Hide(); var worldScaleNotches = new double[] { 1, 2, 4 }.Select(n => n * Graphics.BaseWorldScale).ToArray(); @@ -647,11 +647,11 @@ private void LoadSettingsWindow() _worldScale.Value = Globals.Database.WorldZoom; } - private readonly HashSet _keysDown = new HashSet(); + private readonly HashSet _keysDown = []; private void OnKeyDown(Keys modifier, Keys key) { - if (mKeybindingEditBtn != default) + if (_keybindingEditBtn != default) { _ = _keysDown.Add(key); } @@ -659,7 +659,7 @@ private void OnKeyDown(Keys modifier, Keys key) private void OnKeyUp(Keys modifier, Keys key) { - if (mKeybindingEditBtn == null) + if (_keybindingEditBtn == null) { return; } @@ -669,14 +669,14 @@ private void OnKeyUp(Keys modifier, Keys key) return; } - mKeybindingEditControls.UpdateControl(mKeybindingEditControl, mKeyEdit, modifier, key); - mKeybindingEditBtn.Text = Strings.Keys.FormatKeyName(modifier, key); + _keybindingEditControls.UpdateControl(_keybindingEditControl, _keyEdit, modifier, key); + _keybindingEditBtn.Text = Strings.Keys.FormatKeyName(modifier, key); if (key != Keys.None) { - foreach (var control in mKeybindingEditControls.ControlMapping) + foreach (var control in _keybindingEditControls.ControlMapping) { - if (control.Key == mKeybindingEditControl) + if (control.Key == _keybindingEditControl) { continue; } @@ -689,18 +689,18 @@ private void OnKeyUp(Keys modifier, Keys key) if (binding.Modifier == modifier && binding.Key == key) { // Remove this mapping. - mKeybindingEditControls.UpdateControl(control.Key, bindingIndex, Keys.None, Keys.None); + _keybindingEditControls.UpdateControl(control.Key, bindingIndex, Keys.None, Keys.None); // Update UI. - mKeybindingBtns[control.Key][bindingIndex].Text = Strings.Keys.KeyDictionary[Enum.GetName(typeof(Keys), Keys.None).ToLower()]; + mKeybindingBtns[control.Key][bindingIndex].Text = Strings.Keys.KeyDictionary[Enum.GetName(typeof(Keys), Keys.None)?.ToLower() ?? string.Empty]; } } } - mKeybindingEditBtn.PlayHoverSound(); + _keybindingEditBtn.PlayHoverSound(); } - mKeybindingEditBtn = null; + _keybindingEditBtn = null; _keysDown.Clear(); Interface.GwenInput.HandleInput = true; } @@ -708,9 +708,9 @@ private void OnKeyUp(Keys modifier, Keys key) // Methods. public void Update() { - if (IsVisible && - mKeybindingEditBtn != null && - mKeybindingListeningTimer < Timing.Global.MillisecondsUtc) + if (!IsHidden && + _keybindingEditBtn != null && + _keybindingListeningTimer < Timing.Global.MillisecondsUtc) { OnKeyUp(Keys.None, Keys.None); } @@ -721,51 +721,47 @@ public void Show(bool returnToMenu = false) // Take over all input when we're in-game. if (Globals.GameState == GameStates.InGame) { - mSettingsPanel.MakeModal(true); + MakeModal(true); } // Game Settings. - mAutoCloseWindowsCheckbox.IsChecked = Globals.Database.HideOthersOnWindowOpen; - mAutoToggleChatLogCheckbox.IsChecked = Globals.Database.AutoToggleChatLog; - mShowHealthAsPercentageCheckbox.IsChecked = Globals.Database.ShowHealthAsPercentage; - mShowManaAsPercentageCheckbox.IsChecked = Globals.Database.ShowManaAsPercentage; - mShowExperienceAsPercentageCheckbox.IsChecked = Globals.Database.ShowExperienceAsPercentage; - mFriendOverheadInfoCheckbox.IsChecked = Globals.Database.FriendOverheadInfo; - mGuildMemberOverheadInfoCheckbox.IsChecked = Globals.Database.GuildMemberOverheadInfo; - mMyOverheadInfoCheckbox.IsChecked = Globals.Database.MyOverheadInfo; - mNpcOverheadInfoCheckbox.IsChecked = Globals.Database.NpcOverheadInfo; - mPartyMemberOverheadInfoCheckbox.IsChecked = Globals.Database.PartyMemberOverheadInfo; - mPlayerOverheadInfoCheckbox.IsChecked = Globals.Database.PlayerOverheadInfo; - mFriendOverheadHpBarCheckbox.IsChecked = Globals.Database.FriendOverheadHpBar; - mGuildMemberOverheadHpBarCheckbox.IsChecked = Globals.Database.GuildMemberOverheadHpBar; - mMyOverheadHpBarCheckbox.IsChecked = Globals.Database.MyOverheadHpBar; - mNpcOverheadHpBarCheckbox.IsChecked = Globals.Database.NpcOverheadHpBar; - mPartyMemberOverheadHpBarCheckbox.IsChecked = Globals.Database.PartyMemberOverheadHpBar; - mPlayerOverheadHpBarCheckbox.IsChecked = Globals.Database.PlayerOverheadHpBar; - mStickyTarget.IsChecked = Globals.Database.StickyTarget; - mAutoTurnToTarget.IsChecked = Globals.Database.AutoTurnToTarget; - mTypewriterCheckbox.IsChecked = Globals.Database.TypewriterBehavior == Enums.TypewriterBehavior.Word; + _autoCloseWindowsCheckbox.IsChecked = Globals.Database.HideOthersOnWindowOpen; + _autoToggleChatLogCheckbox.IsChecked = Globals.Database.AutoToggleChatLog; + _showHealthAsPercentageCheckbox.IsChecked = Globals.Database.ShowHealthAsPercentage; + _showManaAsPercentageCheckbox.IsChecked = Globals.Database.ShowManaAsPercentage; + _showExperienceAsPercentageCheckbox.IsChecked = Globals.Database.ShowExperienceAsPercentage; + _friendOverheadInfoCheckbox.IsChecked = Globals.Database.FriendOverheadInfo; + _guildMemberOverheadInfoCheckbox.IsChecked = Globals.Database.GuildMemberOverheadInfo; + _myOverheadInfoCheckbox.IsChecked = Globals.Database.MyOverheadInfo; + _npcOverheadInfoCheckbox.IsChecked = Globals.Database.NpcOverheadInfo; + _partyMemberOverheadInfoCheckbox.IsChecked = Globals.Database.PartyMemberOverheadInfo; + _playerOverheadInfoCheckbox.IsChecked = Globals.Database.PlayerOverheadInfo; + _friendOverheadHpBarCheckbox.IsChecked = Globals.Database.FriendOverheadHpBar; + _guildMemberOverheadHpBarCheckbox.IsChecked = Globals.Database.GuildMemberOverheadHpBar; + _myOverheadHpBarCheckbox.IsChecked = Globals.Database.MyOverheadHpBar; + _mpcOverheadHpBarCheckbox.IsChecked = Globals.Database.NpcOverheadHpBar; + _partyMemberOverheadHpBarCheckbox.IsChecked = Globals.Database.PartyMemberOverheadHpBar; + _playerOverheadHpBarCheckbox.IsChecked = Globals.Database.PlayerOverheadHpBar; + _stickyTarget.IsChecked = Globals.Database.StickyTarget; + _autoTurnToTarget.IsChecked = Globals.Database.AutoTurnToTarget; + _typewriterCheckbox.IsChecked = Globals.Database.TypewriterBehavior == Enums.TypewriterBehavior.Word; // Video Settings. - mFullscreenCheckbox.IsChecked = Globals.Database.FullScreen; - mLightingEnabledCheckbox.IsChecked = Globals.Database.EnableLighting; + _fullscreenCheckbox.IsChecked = Globals.Database.FullScreen; + _lightingEnabledCheckbox.IsChecked = Globals.Database.EnableLighting; // _uiScale.Value = Globals.Database.UIScale; _worldScale.Value = Globals.Database.WorldZoom; - if (Graphics.Renderer.GetValidVideoModes().Count > 0) + if (Graphics.Renderer?.GetValidVideoModes().Count > 0) { string resolutionLabel; if (Graphics.Renderer.HasOverrideResolution) { resolutionLabel = Strings.Settings.ResolutionCustom; - if (mCustomResolutionMenuItem == null) - { - mCustomResolutionMenuItem = mResolutionList.AddItem(Strings.Settings.ResolutionCustom); - } - - mCustomResolutionMenuItem.Show(); + _customResolutionMenuItem ??= _resolutionList.AddItem(Strings.Settings.ResolutionCustom); + _customResolutionMenuItem.Show(); } else { @@ -774,103 +770,101 @@ public void Show(bool returnToMenu = false) resolutionLabel = targetResolution < 0 || validVideoModes.Count <= targetResolution ? Strings.Settings.ResolutionCustom : validVideoModes[Globals.Database.TargetResolution]; } - mResolutionList.SelectByText(resolutionLabel); + _resolutionList.SelectByText(resolutionLabel); } switch (Globals.Database.TargetFps) { case -1: // Unlimited. - mFpsList.SelectByText(Strings.Settings.UnlimitedFps); + _fpsList.SelectByText(Strings.Settings.UnlimitedFps); break; case 0: // Vertical Sync. - mFpsList.SelectByText(Strings.Settings.Vsync); + _fpsList.SelectByText(Strings.Settings.Vsync); break; case 1: // 30 Frames per second. - mFpsList.SelectByText(Strings.Settings.Fps30); + _fpsList.SelectByText(Strings.Settings.Fps30); break; case 2: // 60 Frames per second. - mFpsList.SelectByText(Strings.Settings.Fps60); + _fpsList.SelectByText(Strings.Settings.Fps60); break; case 3: // 90 Frames per second. - mFpsList.SelectByText(Strings.Settings.Fps90); + _fpsList.SelectByText(Strings.Settings.Fps90); break; case 4: // 120 Frames per second. - mFpsList.SelectByText(Strings.Settings.Fps120); + _fpsList.SelectByText(Strings.Settings.Fps120); break; default: - mFpsList.SelectByText(Strings.Settings.Vsync); + _fpsList.SelectByText(Strings.Settings.Vsync); break; } // Audio Settings. - mPreviousMusicVolume = Globals.Database.MusicVolume; - mPreviousSoundVolume = Globals.Database.SoundVolume; - mMusicSlider.Value = Globals.Database.MusicVolume; - mSoundSlider.Value = Globals.Database.SoundVolume; - mMusicLabel.Text = Strings.Settings.MusicVolume.ToString((int)mMusicSlider.Value); - mSoundLabel.Text = Strings.Settings.SoundVolume.ToString((int)mSoundSlider.Value); + _previousMusicVolume = Globals.Database.MusicVolume; + _previousSoundVolume = Globals.Database.SoundVolume; + _musicSlider.Value = Globals.Database.MusicVolume; + _soundSlider.Value = Globals.Database.SoundVolume; + _musicLabel.Text = Strings.Settings.MusicVolume.ToString((int)_musicSlider.Value); + _soundLabel.Text = Strings.Settings.SoundVolume.ToString((int)_soundSlider.Value); // Control Settings. - mKeybindingEditControls = new Controls(Controls.ActiveControls); + _keybindingEditControls = new Controls(Controls.ActiveControls); // Settings Window is not hidden anymore. - mSettingsPanel.Show(); + base.Show(); // Load every GUI element to their default state when showing up the settings window (pressed tabs, containers, etc.) LoadSettingsWindow(); // Set up whether we're supposed to return to the previous menu. - mReturnToMenu = returnToMenu; + _returnToMenu = returnToMenu; } - public bool IsVisible => !mSettingsPanel.IsHidden; - - public void Hide() + public override void Hide() { // Hide the current window. - mSettingsPanel.Hide(); - mSettingsPanel.RemoveModal(); + base.Hide(); + RemoveModal(); // Return to our previous menus (or not) depending on gamestate and the method we'd been opened. - if (mReturnToMenu) + if (_returnToMenu) { switch (Globals.GameState) { case GameStates.Menu: - mMainMenu?.Show(); + _mainMenu?.Show(); break; case GameStates.InGame: - mEscapeMenu?.Show(); + _escapeMenu?.Show(); break; default: throw new NotImplementedException(); } - mReturnToMenu = false; + _returnToMenu = false; } } // Input Handlers private void MusicSlider_ValueChanged(Base sender, EventArgs arguments) { - mMusicLabel.Text = Strings.Settings.MusicVolume.ToString((int)mMusicSlider.Value); - Globals.Database.MusicVolume = (int)mMusicSlider.Value; + _musicLabel.Text = Strings.Settings.MusicVolume.ToString((int)_musicSlider.Value); + Globals.Database.MusicVolume = (int)_musicSlider.Value; Audio.UpdateGlobalVolume(); } private void SoundSlider_ValueChanged(Base sender, EventArgs arguments) { - mSoundLabel.Text = Strings.Settings.SoundVolume.ToString((int)mSoundSlider.Value); - Globals.Database.SoundVolume = (int)mSoundSlider.Value; + _soundLabel.Text = Strings.Settings.SoundVolume.ToString((int)_soundSlider.Value); + Globals.Database.SoundVolume = (int)_soundSlider.Value; Audio.UpdateGlobalVolume(); } @@ -881,23 +875,23 @@ private void Key_Clicked(Base sender, ClickedEventArgs arguments) private void EditKeyPressed(Button sender) { - if (mKeybindingEditBtn == null) + if (_keybindingEditBtn == null) { sender.Text = Strings.Controls.Listening; - mKeyEdit = ((KeyValuePair)sender.UserData).Value; - mKeybindingEditControl = ((KeyValuePair)sender.UserData).Key; - mKeybindingEditBtn = sender; + _keyEdit = ((KeyValuePair)sender.UserData).Value; + _keybindingEditControl = ((KeyValuePair)sender.UserData).Key; + _keybindingEditBtn = sender; Interface.GwenInput.HandleInput = false; - mKeybindingListeningTimer = Timing.Global.MillisecondsUtc + 3000; + _keybindingListeningTimer = Timing.Global.MillisecondsUtc + 3000; } } private void KeybindingsRestoreBtn_Clicked(Base sender, ClickedEventArgs arguments) { - mKeybindingEditControls.ResetDefaults(); + _keybindingEditControls.ResetDefaults(); foreach (Control control in Enum.GetValues(typeof(Control))) { - var controlMapping = mKeybindingEditControls.ControlMapping[control]; + var controlMapping = _keybindingEditControls.ControlMapping[control]; for (var bindingIndex = 0; bindingIndex < controlMapping.Bindings.Count; bindingIndex++) { var binding = controlMapping.Bindings[bindingIndex]; @@ -911,70 +905,68 @@ private void SettingsApplyBtn_Clicked(Base sender, ClickedEventArgs arguments) var shouldReset = false; // Game Settings. - Globals.Database.HideOthersOnWindowOpen = mAutoCloseWindowsCheckbox.IsChecked; - Globals.Database.AutoToggleChatLog = mAutoToggleChatLogCheckbox.IsChecked; - Globals.Database.ShowExperienceAsPercentage = mShowExperienceAsPercentageCheckbox.IsChecked; - Globals.Database.ShowHealthAsPercentage = mShowHealthAsPercentageCheckbox.IsChecked; - Globals.Database.ShowManaAsPercentage = mShowManaAsPercentageCheckbox.IsChecked; - Globals.Database.FriendOverheadInfo = mFriendOverheadInfoCheckbox.IsChecked; - Globals.Database.GuildMemberOverheadInfo = mGuildMemberOverheadInfoCheckbox.IsChecked; - Globals.Database.MyOverheadInfo = mMyOverheadInfoCheckbox.IsChecked; - Globals.Database.NpcOverheadInfo = mNpcOverheadInfoCheckbox.IsChecked; - Globals.Database.PartyMemberOverheadInfo = mPartyMemberOverheadInfoCheckbox.IsChecked; - Globals.Database.PlayerOverheadInfo = mPlayerOverheadInfoCheckbox.IsChecked; - Globals.Database.FriendOverheadHpBar = mFriendOverheadHpBarCheckbox.IsChecked; - Globals.Database.GuildMemberOverheadHpBar = mGuildMemberOverheadHpBarCheckbox.IsChecked; - Globals.Database.MyOverheadHpBar= mMyOverheadHpBarCheckbox.IsChecked; - Globals.Database.NpcOverheadHpBar= mNpcOverheadHpBarCheckbox.IsChecked; - Globals.Database.PartyMemberOverheadHpBar = mPartyMemberOverheadHpBarCheckbox.IsChecked; - Globals.Database.PlayerOverheadHpBar = mPlayerOverheadHpBarCheckbox.IsChecked; - Globals.Database.StickyTarget = mStickyTarget.IsChecked; - Globals.Database.AutoTurnToTarget = mAutoTurnToTarget.IsChecked; - Globals.Database.TypewriterBehavior = mTypewriterCheckbox.IsChecked ? Enums.TypewriterBehavior.Word : Enums.TypewriterBehavior.Off; + Globals.Database.HideOthersOnWindowOpen = _autoCloseWindowsCheckbox.IsChecked; + Globals.Database.AutoToggleChatLog = _autoToggleChatLogCheckbox.IsChecked; + Globals.Database.ShowExperienceAsPercentage = _showExperienceAsPercentageCheckbox.IsChecked; + Globals.Database.ShowHealthAsPercentage = _showHealthAsPercentageCheckbox.IsChecked; + Globals.Database.ShowManaAsPercentage = _showManaAsPercentageCheckbox.IsChecked; + Globals.Database.FriendOverheadInfo = _friendOverheadInfoCheckbox.IsChecked; + Globals.Database.GuildMemberOverheadInfo = _guildMemberOverheadInfoCheckbox.IsChecked; + Globals.Database.MyOverheadInfo = _myOverheadInfoCheckbox.IsChecked; + Globals.Database.NpcOverheadInfo = _npcOverheadInfoCheckbox.IsChecked; + Globals.Database.PartyMemberOverheadInfo = _partyMemberOverheadInfoCheckbox.IsChecked; + Globals.Database.PlayerOverheadInfo = _playerOverheadInfoCheckbox.IsChecked; + Globals.Database.FriendOverheadHpBar = _friendOverheadHpBarCheckbox.IsChecked; + Globals.Database.GuildMemberOverheadHpBar = _guildMemberOverheadHpBarCheckbox.IsChecked; + Globals.Database.MyOverheadHpBar = _myOverheadHpBarCheckbox.IsChecked; + Globals.Database.NpcOverheadHpBar = _mpcOverheadHpBarCheckbox.IsChecked; + Globals.Database.PartyMemberOverheadHpBar = _partyMemberOverheadHpBarCheckbox.IsChecked; + Globals.Database.PlayerOverheadHpBar = _playerOverheadHpBarCheckbox.IsChecked; + Globals.Database.StickyTarget = _stickyTarget.IsChecked; + Globals.Database.AutoTurnToTarget = _autoTurnToTarget.IsChecked; + Globals.Database.TypewriterBehavior = _typewriterCheckbox.IsChecked ? Enums.TypewriterBehavior.Word : Enums.TypewriterBehavior.Off; // Video Settings. // Globals.Database.UIScale = (float)_uiScale.Value; Globals.Database.WorldZoom = (float)_worldScale.Value; - var resolution = mResolutionList.SelectedItem; - var validVideoModes = Graphics.Renderer.GetValidVideoModes(); - var targetResolution = validVideoModes?.FindIndex(videoMode => - string.Equals(videoMode, resolution.Text)) ?? -1; + var resolution = _resolutionList.SelectedItem; + var validVideoModes = Graphics.Renderer?.GetValidVideoModes(); + var targetResolution = validVideoModes?.FindIndex(videoMode => string.Equals(videoMode, resolution.Text)) ?? -1; var newFps = 0; - Globals.Database.EnableLighting = mLightingEnabledCheckbox.IsChecked; + Globals.Database.EnableLighting = _lightingEnabledCheckbox.IsChecked; if (targetResolution > -1) { - shouldReset = Globals.Database.TargetResolution != targetResolution || - Graphics.Renderer.HasOverrideResolution; + shouldReset = Globals.Database.TargetResolution != targetResolution || Graphics.Renderer?.HasOverrideResolution == true; Globals.Database.TargetResolution = targetResolution; } - if (Globals.Database.FullScreen != mFullscreenCheckbox.IsChecked) + if (Globals.Database.FullScreen != _fullscreenCheckbox.IsChecked) { - Globals.Database.FullScreen = mFullscreenCheckbox.IsChecked; + Globals.Database.FullScreen = _fullscreenCheckbox.IsChecked; shouldReset = true; } - if (mFpsList.SelectedItem.Text == Strings.Settings.UnlimitedFps) + if (_fpsList.SelectedItem.Text == Strings.Settings.UnlimitedFps) { newFps = -1; } - else if (mFpsList.SelectedItem.Text == Strings.Settings.Fps30) + else if (_fpsList.SelectedItem.Text == Strings.Settings.Fps30) { newFps = 1; } - else if (mFpsList.SelectedItem.Text == Strings.Settings.Fps60) + else if (_fpsList.SelectedItem.Text == Strings.Settings.Fps60) { newFps = 2; } - else if (mFpsList.SelectedItem.Text == Strings.Settings.Fps90) + else if (_fpsList.SelectedItem.Text == Strings.Settings.Fps90) { newFps = 3; } - else if (mFpsList.SelectedItem.Text == Strings.Settings.Fps120) + else if (_fpsList.SelectedItem.Text == Strings.Settings.Fps120) { newFps = 4; } @@ -986,20 +978,20 @@ private void SettingsApplyBtn_Clicked(Base sender, ClickedEventArgs arguments) } // Audio Settings. - Globals.Database.MusicVolume = (int)mMusicSlider.Value; - Globals.Database.SoundVolume = (int)mSoundSlider.Value; + Globals.Database.MusicVolume = (int)_musicSlider.Value; + Globals.Database.SoundVolume = (int)_soundSlider.Value; Audio.UpdateGlobalVolume(); // Control Settings. - Controls.ActiveControls = mKeybindingEditControls; + Controls.ActiveControls = _keybindingEditControls; Controls.ActiveControls.Save(); // Save Preferences. Globals.Database.SavePreferences(); - if (shouldReset) + if (shouldReset && Graphics.Renderer != default) { - mCustomResolutionMenuItem?.Hide(); + _customResolutionMenuItem?.Hide(); Graphics.Renderer.OverrideResolution = Resolution.Empty; Graphics.Renderer.Init(); } @@ -1011,10 +1003,10 @@ private void SettingsApplyBtn_Clicked(Base sender, ClickedEventArgs arguments) private void SettingsCancelBtn_Clicked(Base sender, ClickedEventArgs arguments) { // Update previously saved values in order to discard changes. - Globals.Database.MusicVolume = mPreviousMusicVolume; - Globals.Database.SoundVolume = mPreviousSoundVolume; + Globals.Database.MusicVolume = _previousMusicVolume; + Globals.Database.SoundVolume = _previousSoundVolume; Audio.UpdateGlobalVolume(); - mKeybindingEditControls = new Controls(Controls.ActiveControls); + _keybindingEditControls = new Controls(Controls.ActiveControls); // Hide our current window. Hide();