diff --git a/Intersect.Client/Interface/Game/EscapeMenu.cs b/Intersect.Client/Interface/Game/EscapeMenu.cs index d0aaa82ec..749aa77e7 100644 --- a/Intersect.Client/Interface/Game/EscapeMenu.cs +++ b/Intersect.Client/Interface/Game/EscapeMenu.cs @@ -9,82 +9,69 @@ namespace Intersect.Client.Interface.Game; - public partial class EscapeMenu : ImagePanel { + private readonly SettingsWindow _settingsWindow; + private readonly Button _buttonCharacterSelect; - private readonly Button mClose; - - private readonly ImagePanel mContainer; - - private readonly Button mExitToDesktop; - - private readonly Button mGoToCharacterSelect; - - private readonly Button mLogout; - - private readonly Button mSettings; - - private readonly SettingsWindow mSettingsWindow; - - private readonly Label mTitle; - - public EscapeMenu(Canvas gameCanvas) : base(gameCanvas, "EscapeMenu") + public EscapeMenu(Canvas gameCanvas) : base(gameCanvas, nameof(EscapeMenu)) { Interface.InputBlockingElements?.Add(this); Width = gameCanvas.Width; Height = gameCanvas.Height; - mContainer = new ImagePanel(this, "EscapeMenu"); + // Create the container + var container = new ImagePanel(this, nameof(EscapeMenu)); - mTitle = new Label(mContainer, "TitleLabel") + // Title Label + _ = new Label(container, "TitleLabel") { Text = Strings.EscapeMenu.Title, }; - mSettingsWindow = new SettingsWindow(gameCanvas, null, this); + // Settings Window and Button + _settingsWindow = new SettingsWindow(gameCanvas, null, this); - mSettings = new Button(mContainer, "SettingsButton") + var buttonSettings = new Button(container, "SettingsButton") { - Text = Strings.EscapeMenu.Settings + Text = Strings.EscapeMenu.Settings, }; + buttonSettings.Clicked += (s, e) => OpenSettingsWindow(true); - mSettings.Clicked += Settings_Clicked; - - mGoToCharacterSelect = new Button(mContainer, "CharacterSelectButton") + // Character Select Button + _buttonCharacterSelect = new Button(container, "CharacterSelectButton") { - Text = Strings.EscapeMenu.CharacterSelect + Text = Strings.EscapeMenu.CharacterSelect, }; + _buttonCharacterSelect.Clicked += _buttonCharacterSelect_Clicked; - mGoToCharacterSelect.Clicked += GoToCharacterSelect_Clicked; - - mLogout = new Button(mContainer, "LogoutButton") + // Logout Button + var buttonLogout = new Button(container, "LogoutButton") { - Text = Strings.EscapeMenu.Logout + Text = Strings.EscapeMenu.Logout, }; + buttonLogout.Clicked += buttonLogout_Clicked; - mLogout.Clicked += Logout_Clicked; - - mExitToDesktop = new Button(mContainer, "ExitToDesktopButton") + // Exit to Desktop Button + var buttonQuit = new Button(container, "ExitToDesktopButton") { - Text = Strings.EscapeMenu.ExitToDesktop + Text = Strings.EscapeMenu.ExitToDesktop, }; + buttonQuit.Clicked += buttonQuit_Clicked; - mExitToDesktop.Clicked += ExitToDesktop_Clicked; - - mClose = new Button(mContainer, "CloseButton") + // Close Button + var buttonContinue = new Button(container, "CloseButton") { - Text = Strings.EscapeMenu.Close + Text = Strings.EscapeMenu.Close, }; + buttonContinue.Clicked += (s, e) => Hide(); - mClose.Clicked += Close_Clicked; - - mContainer.LoadJsonUi(GameContentManager.UI.InGame, Graphics.Renderer.GetResolutionString()); + container.LoadJsonUi(GameContentManager.UI.InGame, Graphics.Renderer?.GetResolutionString()); if (Options.Player.MaxCharacters <= 1) { - mGoToCharacterSelect.IsDisabled = true; + _buttonCharacterSelect.IsDisabled = true; } } @@ -100,39 +87,16 @@ public override void Invalidate() } base.Invalidate(); - if (Interface.GameUi != null && Interface.GameUi.GameCanvas != null) + if (Interface.GameUi?.GameCanvas != null) { - Interface.GameUi.GameCanvas.MouseInputEnabled = false; Interface.GameUi.GameCanvas.MouseInputEnabled = true; } } - public void Update() - { - if (!IsHidden) - { - BringToFront(); - } - - mGoToCharacterSelect.IsDisabled = Globals.Me?.CombatTimer > Timing.Global.Milliseconds; - } - - private void Settings_Clicked(Base sender, ClickedEventArgs arguments) - { - mSettingsWindow.Show(true); - Interface.GameUi?.EscapeMenu?.Hide(); - } - - public void OpenSettingsWindow() - { - mSettingsWindow.Show(); - Interface.GameUi?.EscapeMenu?.Hide(); - } - /// public override void ToggleHidden() { - if (!mSettingsWindow.IsHidden) + if (!_settingsWindow.IsHidden) { return; } @@ -140,40 +104,26 @@ public override void ToggleHidden() base.ToggleHidden(); } - private void LogoutToCharacterSelect(object? sender, EventArgs? e) - { - if (Globals.Me != null) - { - Globals.Me.CombatTimer = 0; - } - - Main.Logout(true); - } - - private void LogoutToMainMenu(object? sender, EventArgs? e) + public void Update() { - if (Globals.Me != null) + if (!IsHidden) { - Globals.Me.CombatTimer = 0; + BringToFront(); } - Main.Logout(false); + _buttonCharacterSelect.IsDisabled = Globals.Me?.CombatTimer > Timing.Global.Milliseconds; } - private void ExitToDesktop(object? sender, EventArgs? e) + public void OpenSettingsWindow(bool returnToMenu = false) { - if (Globals.Me != null) - { - Globals.Me.CombatTimer = 0; - } - - Globals.IsRunning = false; + _settingsWindow.Show(returnToMenu); + Interface.GameUi?.EscapeMenu?.Hide(); } - private void GoToCharacterSelect_Clicked(Base sender, ClickedEventArgs arguments) + private void _buttonCharacterSelect_Clicked(Base sender, ClickedEventArgs arguments) { ToggleHidden(); - if (Globals.Me.CombatTimer > Timing.Global.Milliseconds) + if (Globals.Me?.CombatTimer > Timing.Global.Milliseconds) { //Show Logout in Combat Warning _ = new InputBox( @@ -189,10 +139,20 @@ private void GoToCharacterSelect_Clicked(Base sender, ClickedEventArgs arguments } } - private void Logout_Clicked(Base sender, ClickedEventArgs arguments) + private void LogoutToCharacterSelect(object? sender, EventArgs? e) + { + if (Globals.Me != null) + { + Globals.Me.CombatTimer = 0; + } + + Main.Logout(true); + } + + private void buttonLogout_Clicked(Base sender, ClickedEventArgs arguments) { ToggleHidden(); - if (Globals.Me.CombatTimer > Timing.Global.Milliseconds) + if (Globals.Me?.CombatTimer > Timing.Global.Milliseconds) { //Show Logout in Combat Warning _ = new InputBox( @@ -208,10 +168,20 @@ private void Logout_Clicked(Base sender, ClickedEventArgs arguments) } } - private void ExitToDesktop_Clicked(Base sender, ClickedEventArgs arguments) + private void LogoutToMainMenu(object? sender, EventArgs? e) + { + if (Globals.Me != null) + { + Globals.Me.CombatTimer = 0; + } + + Main.Logout(false); + } + + private void buttonQuit_Clicked(Base sender, ClickedEventArgs arguments) { ToggleHidden(); - if (Globals.Me.CombatTimer > Timing.Global.Milliseconds) + if (Globals.Me?.CombatTimer > Timing.Global.Milliseconds) { //Show Logout in Combat Warning _ = new InputBox( @@ -227,9 +197,13 @@ private void ExitToDesktop_Clicked(Base sender, ClickedEventArgs arguments) } } - private void Close_Clicked(Base sender, ClickedEventArgs arguments) + private void ExitToDesktop(object? sender, EventArgs? e) { - Hide(); - } + if (Globals.Me != null) + { + Globals.Me.CombatTimer = 0; + } + Globals.IsRunning = false; + } }