]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Character menu asks if you want to save your character on exit (#29875)
authorWinkarst-cpu <74284083+Winkarst-cpu@users.noreply.github.com>
Thu, 11 Jul 2024 00:24:37 +0000 (03:24 +0300)
committerGitHub <noreply@github.com>
Thu, 11 Jul 2024 00:24:37 +0000 (10:24 +1000)
* Character menu asks if you want to save your character on exit

* Fix

* Another fix, little mistake by me

* Update Content.Client/Lobby/UI/CharacterSetupGuiSavePanel.xaml.cs

---------

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Content.Client/Lobby/LobbyUIController.cs
Content.Client/Lobby/UI/CharacterSetupGuiSavePanel.xaml [new file with mode: 0644]
Content.Client/Lobby/UI/CharacterSetupGuiSavePanel.xaml.cs [new file with mode: 0644]
Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs
Resources/Locale/en-US/preferences/ui/character-setup-gui.ftl

index e4a13ed8c6b7e85d3c85ff09cfa3f61a524bc8d2..824a842d560744cc3cebae71ee029c21e54c9a56 100644 (file)
@@ -46,6 +46,7 @@ public sealed class LobbyUIController : UIController, IOnStateEntered<LobbyState
 
     private CharacterSetupGui? _characterSetup;
     private HumanoidProfileEditor? _profileEditor;
+    private CharacterSetupGuiSavePanel? _savePanel;
 
     /// <summary>
     /// This is the characher preview panel in the chat. This should only update if their character updates.
@@ -214,6 +215,46 @@ public sealed class LobbyUIController : UIController, IOnStateEntered<LobbyState
         ReloadCharacterSetup();
     }
 
+    private void CloseProfileEditor()
+    {
+        if (_profileEditor == null)
+            return;
+
+        _profileEditor.SetProfile(null, null);
+        _profileEditor.Visible = false;
+
+        if (_stateManager.CurrentState is LobbyState lobbyGui)
+        {
+            lobbyGui.SwitchState(LobbyGui.LobbyGuiState.Default);
+        }
+    }
+
+    private void OpenSavePanel()
+    {
+        if (_savePanel is { IsOpen: true })
+            return;
+
+        _savePanel = new CharacterSetupGuiSavePanel();
+
+        _savePanel.SaveButton.OnPressed += _ =>
+        {
+            SaveProfile();
+
+            _savePanel.Close();
+
+            CloseProfileEditor();
+        };
+
+        _savePanel.NoSaveButton.OnPressed += _ =>
+        {
+            _savePanel.Close();
+
+            CloseProfileEditor();
+        };
+
+        _savePanel.OpenCentered();
+    }
+
     private (CharacterSetupGui, HumanoidProfileEditor) EnsureGui()
     {
         if (_characterSetup != null && _profileEditor != null)
@@ -240,14 +281,16 @@ public sealed class LobbyUIController : UIController, IOnStateEntered<LobbyState
 
         _characterSetup.CloseButton.OnPressed += _ =>
         {
-            // Reset sliders etc.
-            _profileEditor.SetProfile(null, null);
-            _profileEditor.Visible = false;
-
-            if (_stateManager.CurrentState is LobbyState lobbyGui)
+            // Open the save panel if we have unsaved changes.
+            if (_profileEditor.Profile != null && _profileEditor.IsDirty)
             {
-                lobbyGui.SwitchState(LobbyGui.LobbyGuiState.Default);
+                OpenSavePanel();
+
+                return;
             }
+
+            // Reset sliders etc.
+            CloseProfileEditor();
         };
 
         _profileEditor.Save += SaveProfile;
diff --git a/Content.Client/Lobby/UI/CharacterSetupGuiSavePanel.xaml b/Content.Client/Lobby/UI/CharacterSetupGuiSavePanel.xaml
new file mode 100644 (file)
index 0000000..2dcf914
--- /dev/null
@@ -0,0 +1,10 @@
+<DefaultWindow xmlns="https://spacestation14.io"
+            Title="{Loc 'character-setup-gui-save-panel-title'}"
+            Resizable="False">
+
+    <BoxContainer Orientation="Horizontal" SeparationOverride="4" MinSize="200 40">
+        <Button Name="SaveButton" Access="Public" Text="{Loc 'character-setup-gui-save-panel-save'}" StyleClasses="ButtonBig"/>
+        <Button Name="NoSaveButton" Access="Public" Text="{Loc 'character-setup-gui-save-panel-nosave'}" StyleClasses="ButtonBig"/>
+        <Button Name="CancelButton" Access="Public" Text="{Loc 'character-setup-gui-save-panel-cancel'}" StyleClasses="ButtonBig"/>
+    </BoxContainer>
+</DefaultWindow>
diff --git a/Content.Client/Lobby/UI/CharacterSetupGuiSavePanel.xaml.cs b/Content.Client/Lobby/UI/CharacterSetupGuiSavePanel.xaml.cs
new file mode 100644 (file)
index 0000000..5f2690b
--- /dev/null
@@ -0,0 +1,21 @@
+using Robust.Client.AutoGenerated;
+using Robust.Client.UserInterface.CustomControls;
+using Robust.Client.UserInterface.XAML;
+
+namespace Content.Client.Lobby.UI;
+
+[GenerateTypedNameReferences]
+public sealed partial class CharacterSetupGuiSavePanel : DefaultWindow
+{
+    public CharacterSetupGuiSavePanel()
+    {
+        RobustXamlLoader.Load(this);
+
+        CancelButton.OnPressed += _ =>
+        {
+            Close();
+        };
+
+        CloseButton.Visible = false;
+    }
+}
index b3bc0cafe741397fff6a42d4f4bad9092334ec5e..87ef41c0b738beea6fa37d1f10405ffa69de3f8e 100644 (file)
@@ -1190,7 +1190,7 @@ namespace Content.Client.Lobby.UI
             SetDirty();
         }
 
-        private bool IsDirty
+        public bool IsDirty
         {
             get => _isDirty;
             set
index b85d7be38ed1b28d65d6594d3c378e0787d3c4b8..325d7cb538dbcd033ca071f17b3fb6aa33806c14 100644 (file)
@@ -6,3 +6,8 @@ character-setup-gui-create-new-character-button = Create new slot...
 character-setup-gui-create-new-character-button-tooltip = A maximum of {$maxCharacters} characters are allowed.
 character-setup-gui-character-picker-button-delete-button = Delete
 character-setup-gui-character-picker-button-confirm-delete-button = Confirm
+
+character-setup-gui-save-panel-title = Unsaved character changes
+character-setup-gui-save-panel-save = Save
+character-setup-gui-save-panel-nosave = Don't save
+character-setup-gui-save-panel-cancel = Cancel
\ No newline at end of file