Skip to content

Commit

Permalink
Character menu asks if you want to save your character on exit (space…
Browse files Browse the repository at this point in the history
…-wizards#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>
  • Loading branch information
2 people authored and Baa14453 committed Oct 19, 2024
1 parent d719027 commit de65f6a
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 7 deletions.
55 changes: 49 additions & 6 deletions Content.Client/Lobby/LobbyUIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -214,6 +215,46 @@ private void SaveProfile()
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)
Expand All @@ -240,14 +281,16 @@ private void SaveProfile()

_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;
Expand Down
10 changes: 10 additions & 0 deletions Content.Client/Lobby/UI/CharacterSetupGuiSavePanel.xaml
Original file line number Diff line number Diff line change
@@ -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>
21 changes: 21 additions & 0 deletions Content.Client/Lobby/UI/CharacterSetupGuiSavePanel.xaml.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
2 changes: 1 addition & 1 deletion Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1190,7 +1190,7 @@ private void SetSpawnPriority(SpawnPriorityPreference newSpawnPriority)
SetDirty();
}

private bool IsDirty
public bool IsDirty
{
get => _isDirty;
set
Expand Down
5 changes: 5 additions & 0 deletions Resources/Locale/en-US/preferences/ui/character-setup-gui.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit de65f6a

Please sign in to comment.