forked from space-wizards/space-station-14
-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #444 from TGRCdev/spelf-mood-admin-verb
Admins can now view and edit spelf moods
- Loading branch information
Showing
13 changed files
with
381 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<BoxContainer | ||
xmlns="https://spacestation14.io" | ||
xmlns:graphics="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client" | ||
xmlns:customControls="clr-namespace:Content.Client.Administration.UI.CustomControls" | ||
HorizontalExpand="True" | ||
Orientation="Vertical" | ||
> | ||
<customControls:HSeparator></customControls:HSeparator> | ||
<BoxContainer Orientation="Vertical"> | ||
<LineEdit Name="SpelfMoodTitle" Access="Public" Margin="5 0 0 0" /> | ||
<PanelContainer | ||
Margin="20 10 0 0" | ||
MinHeight="128" | ||
> | ||
<PanelContainer.PanelOverride> | ||
<graphics:StyleBoxFlat BackgroundColor="#1B1B1B"></graphics:StyleBoxFlat> | ||
</PanelContainer.PanelOverride> | ||
<BoxContainer Orientation="Horizontal" SeparationOverride="5"> | ||
<TextEdit Name="SpelfMoodContent" Access="Public" HorizontalExpand="True" Editable="True" MinWidth="500" MinHeight="80"></TextEdit> | ||
</BoxContainer> | ||
</PanelContainer> | ||
</BoxContainer> | ||
<BoxContainer Orientation="Horizontal" Margin="0 5 0 0" MaxHeight="64" Align="Begin"> | ||
<Button Name="MoveUp" Access="Public" Text="{Loc spelf-mood-admin-ui-move-up}" StyleClasses="OpenRight"></Button> | ||
<Button Name="MoveDown" Access="Public" Text="{Loc spelf-mood-admin-ui-move-down}" StyleClasses="OpenLeft"></Button> | ||
</BoxContainer> | ||
<BoxContainer Orientation="Horizontal" Align="End" Margin="0 10 5 10"> | ||
<Button Name="Delete" Access="Public" Text="{Loc spelf-mood-admin-ui-delete}" ModulateSelfOverride="Red"></Button> | ||
</BoxContainer> | ||
</BoxContainer> |
22 changes: 22 additions & 0 deletions
22
Content.Client/Impstation/Spelfs/Eui/MoodContainer.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using Content.Shared.Impstation.Spelfs; | ||
using Robust.Client.AutoGenerated; | ||
using Robust.Client.UserInterface.Controls; | ||
using Robust.Client.UserInterface.XAML; | ||
using Robust.Shared.Utility; | ||
|
||
namespace Content.Client.Impstation.Spelfs.Eui; | ||
|
||
[GenerateTypedNameReferences] | ||
public sealed partial class MoodContainer : BoxContainer | ||
{ | ||
public MoodContainer(SpelfMood? mood = null) | ||
{ | ||
RobustXamlLoader.Load(this); | ||
|
||
if (mood != null) | ||
{ | ||
SpelfMoodTitle.Text = mood.GetLocName(); | ||
SpelfMoodContent.TextRope = new Rope.Leaf(mood.GetLocDesc()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<controls:FancyWindow | ||
xmlns="https://spacestation14.io" | ||
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls" | ||
Title="{Loc spelf-moods-admin-ui-title}" | ||
MinSize="560 400" | ||
> | ||
<!--> | ||
this shit does not layout properly unless I put the horizontal boxcontainer inside of a vertical one | ||
???? | ||
<!--> | ||
<BoxContainer Orientation="Vertical"> | ||
<BoxContainer Orientation="Horizontal" Align="End"> | ||
<Button Name="NewMoodButton" Text="{Loc spelf-moods-admin-ui-new-mood}" MaxSize="256 64" StyleClasses="OpenRight"></Button> | ||
<Button Name="SaveButton" Text="{Loc spelf-moods-admin-ui-save}" MaxSize="256 64" Access="Public" StyleClasses="OpenLeft"></Button> | ||
</BoxContainer> | ||
</BoxContainer> | ||
<BoxContainer Orientation="Vertical" Margin="4 60 0 0"> | ||
<ScrollContainer VerticalExpand="True" HorizontalExpand="True" HScrollEnabled="False"> | ||
<BoxContainer Orientation="Vertical" Name="MoodContainer" Access="Public" VerticalExpand="True" /> | ||
</ScrollContainer> | ||
</BoxContainer> | ||
</controls:FancyWindow> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
using Content.Client.UserInterface.Controls; | ||
using Content.Shared.Impstation.Spelfs; | ||
using Robust.Client.AutoGenerated; | ||
using Robust.Client.UserInterface.XAML; | ||
using Robust.Shared.Utility; | ||
|
||
namespace Content.Client.Impstation.Spelfs.Eui; | ||
|
||
[GenerateTypedNameReferences] | ||
public sealed partial class SpelfMoodUi : FancyWindow | ||
{ | ||
private List<SpelfMood> _moods = new(); | ||
|
||
public SpelfMoodUi() | ||
{ | ||
RobustXamlLoader.Load(this); | ||
NewMoodButton.OnPressed += _ => AddNewMood(); | ||
} | ||
|
||
private void AddNewMood() | ||
{ | ||
MoodContainer.AddChild(new MoodContainer()); | ||
} | ||
|
||
public List<SpelfMood> GetMoods() | ||
{ | ||
var newMoods = new List<SpelfMood>(); | ||
|
||
foreach (var control in MoodContainer.Children) | ||
{ | ||
if (control is not MoodContainer moodControl) | ||
continue; | ||
|
||
if (string.IsNullOrWhiteSpace(moodControl.SpelfMoodTitle.Text)) | ||
continue; | ||
|
||
var moodText = Rope.Collapse(moodControl.SpelfMoodContent.TextRope).Trim(); | ||
|
||
if (string.IsNullOrWhiteSpace(moodText)) | ||
continue; | ||
|
||
var mood = new SpelfMood() | ||
{ | ||
MoodName = moodControl.SpelfMoodTitle.Text, | ||
MoodDesc = moodText, | ||
}; | ||
|
||
newMoods.Add(mood); | ||
} | ||
|
||
return newMoods; | ||
} | ||
|
||
private void MoveUp(int index) | ||
{ | ||
if (index <= 0) | ||
return; | ||
|
||
(_moods[index], _moods[index - 1]) = (_moods[index - 1], _moods[index]); | ||
SetMoods(_moods); | ||
} | ||
|
||
private void MoveDown(int index) | ||
{ | ||
if (index >= _moods.Count - 1) | ||
return; | ||
|
||
(_moods[index], _moods[index + 1]) = (_moods[index + 1], _moods[index]); | ||
SetMoods(_moods); | ||
} | ||
|
||
private void Delete(int index) | ||
{ | ||
_moods.RemoveAt(index); | ||
|
||
SetMoods(_moods); | ||
} | ||
|
||
public void SetMoods(List<SpelfMood> moods) | ||
{ | ||
_moods = moods; | ||
MoodContainer.RemoveAllChildren(); | ||
for (var i = 0; i < moods.Count; i++) | ||
{ | ||
var index = i; // Copy for the closure | ||
var mood = moods[i]; | ||
var moodControl = new MoodContainer(mood); | ||
moodControl.MoveUp.OnPressed += _ => MoveUp(index); | ||
moodControl.MoveDown.OnPressed += _ => MoveDown(index); | ||
moodControl.Delete.OnPressed += _ => Delete(index); | ||
MoodContainer.AddChild(moodControl); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using Content.Client.Eui; | ||
using Content.Shared.Eui; | ||
using Content.Shared.Impstation.Spelfs; | ||
|
||
namespace Content.Client.Impstation.Spelfs.Eui; | ||
|
||
public sealed class SpelfMoodsEui : BaseEui | ||
{ | ||
private readonly EntityManager _entityManager; | ||
|
||
private SpelfMoodUi _spelfMoodUi; | ||
private NetEntity _target; | ||
|
||
public SpelfMoodsEui() | ||
{ | ||
_entityManager = IoCManager.Resolve<EntityManager>(); | ||
|
||
_spelfMoodUi = new SpelfMoodUi(); | ||
_spelfMoodUi.SaveButton.OnPressed += _ => SaveMoods(); | ||
} | ||
|
||
private void SaveMoods() | ||
{ | ||
var newMoods = _spelfMoodUi.GetMoods(); | ||
SendMessage(new SpelfMoodsSaveMessage(newMoods, _target)); | ||
_spelfMoodUi.SetMoods(newMoods); | ||
} | ||
|
||
public override void Opened() | ||
{ | ||
_spelfMoodUi.OpenCentered(); | ||
} | ||
|
||
public override void HandleState(EuiStateBase state) | ||
{ | ||
if (state is not SpelfMoodsEuiState s) | ||
return; | ||
|
||
_target = s.Target; | ||
_spelfMoodUi.SetMoods(s.Moods); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.