Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Admin "Add objective" button fix #568

Merged
merged 6 commits into from
Dec 10, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ public sealed class UICommandButton : CommandButton
public Type? WindowType { get; set; }
private DefaultWindow? _window;

public event Action<DefaultWindow>? OnWindowCreated;

protected override void Execute(ButtonEventArgs obj)
{
if (WindowType == null)
return;
_window = (DefaultWindow) IoCManager.Resolve<IDynamicTypeFactory>().CreateInstance(WindowType);
if (_window is not null)
OnWindowCreated?.Invoke(_window);
_window?.OpenCentered();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
<DefaultWindow
xmlns="https://spacestation14.io"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cc="clr-namespace:Content.Client.Administration.UI.CustomControls"
xmlns:ss220a="clr-namespace:Content.Client.SS220.Administration"
Title="{Loc admin-player-actions-window-antagonists}" MinSize="425 272">
<BoxContainer Orientation="Vertical">
<cc:AntagonistsListControl Name="AntagonistsList" VerticalExpand="True" />
<BoxContainer Orientation="Horizontal">
<Button Name="ListOfTargetsButton" Text="{Loc admin-antagonists-list-of-targets}" Disabled="True"/>
<Button Name="AddTargetButton" Text="{Loc admin-antagonists-add-target}" Disabled="True"/>
<!-- SS220-antag-add-objective -->
<cc:UICommandButton Name="AddTargetButton" Text="{Loc admin-antagonists-add-target}" Disabled="True" WindowType="{x:Type ss220a:AddObjectiveWindow}"/>
</BoxContainer>
</BoxContainer>
</DefaultWindow>
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using Content.Client.SS220.Administration;
using Content.Shared.Administration;
using JetBrains.Annotations;
using Robust.Client.AutoGenerated;
using Robust.Client.Console;
using Robust.Client.Player;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;

Expand All @@ -19,15 +21,18 @@ protected override void EnteredTree()
{
AntagonistsList.OnSelectionChanged += OnListOnOnSelectionChanged;
ListOfTargetsButton.OnPressed += ListOfTargetsButtonOnPressed;
AddTargetButton.OnPressed += AddTargetButtonOnPressed;
//SS220-antag-add-objective begin
TheArturZh marked this conversation as resolved.
Show resolved Hide resolved
//AddTargetButton.OnPressed += AddTargetButtonOnPressed;
AddTargetButton.OnWindowCreated += AddTargetButtonOnWindowCreated;
//SS220-antag-add-objective end
}

private void OnListOnOnSelectionChanged(PlayerInfo? obj)
{
_selectedAntagonist = obj;
var disableButtons = _selectedAntagonist == null;
ListOfTargetsButton.Disabled = disableButtons;
//AddTargetButton.Disabled = disableButtons;
AddTargetButton.Disabled = disableButtons; //SS220-antag-add-objective
}

private void ListOfTargetsButtonOnPressed(BaseButton.ButtonEventArgs obj)
Expand All @@ -39,6 +44,18 @@ private void ListOfTargetsButtonOnPressed(BaseButton.ButtonEventArgs obj)
$"openobjectives {_selectedAntagonist.SessionId}");
}

//SS220-antag-add-objective begin
private void AddTargetButtonOnWindowCreated(DefaultWindow window)
{
// This is dumb.
if (_selectedAntagonist is null)
return;
var addObjectiveWindow = (AddObjectiveWindow) window;
var antagSession = IoCManager.Resolve<IPlayerManager>().GetSessionById(_selectedAntagonist.SessionId);
addObjectiveWindow.SetAntagonist(antagSession);
}
//SS220-antag-add-objective end

private void AddTargetButtonOnPressed(BaseButton.ButtonEventArgs obj)
{
if (_selectedAntagonist == null)
Expand Down
12 changes: 12 additions & 0 deletions Content.Client/SS220/Administration/AddObjectiveWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!-- © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt -->

<DefaultWindow xmlns="https://spacestation14.io"
Title="{Loc 'ui-add-objective-title'}"
Resizable="False">
<BoxContainer Orientation="Vertical" SeparationOverride="4" MinSize="240 60">
<BoxContainer Orientation="Horizontal">
<LineEdit Name="ObjectiveLineEdit" Access="Public" HorizontalExpand="True" PlaceHolder="{Loc 'ui-add-objective-line-edit-placeholder'}"/>
</BoxContainer>
<Button Name="ApplyButton" Access="Public" Text="{Loc 'ui-add-objective-apply'}"/>
</BoxContainer>
</DefaultWindow>
46 changes: 46 additions & 0 deletions Content.Client/SS220/Administration/AddObjectiveWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt

using Robust.Client.AutoGenerated;
using Robust.Client.Console;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Player;

namespace Content.Client.SS220.Administration;

[GenerateTypedNameReferences]
public partial class AddObjectiveWindow : DefaultWindow
{
private ICommonSession? _selectedAntagonist;
private string _input = "";

public AddObjectiveWindow()
{
RobustXamlLoader.Load(this);
}

protected override void EnteredTree()
{
ApplyButton.OnPressed += OnApplyButtonPressed;
ObjectiveLineEdit.OnTextChanged += OnObjectiveLineEditChanged;
}

public void SetAntagonist(ICommonSession antagonistPlayerName)
{
_selectedAntagonist = antagonistPlayerName;
}

private void OnObjectiveLineEditChanged(LineEdit.LineEditEventArgs args)
{
_input = args.Text;
}

private void OnApplyButtonPressed(BaseButton.ButtonEventArgs args)
{
if (_input.Length == 0)
return;

IoCManager.Resolve<IClientConsoleHost>().ExecuteCommand($"addobjective {_selectedAntagonist} {_input}");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ui-add-objective-title = Add objective
ui-add-objective-line-edit-placeholder = Objective prototype ID
ui-add-objective-apply = Confirm
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ui-add-objective-title = Добавить цель
ui-add-objective-line-edit-placeholder = ID прототипа цели
ui-add-objective-apply = Добавить
Loading