Character menu asks if you want to save your character on exit (#29875)

* 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>
This commit is contained in:
Winkarst-cpu
2024-07-11 03:24:37 +03:00
committed by GitHub
parent 2df65f10f5
commit adcbe8d0be
5 changed files with 86 additions and 7 deletions

View 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;