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 event preference panel #480

Merged
2 changes: 1 addition & 1 deletion .run/Content Server+Client.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
<toRun name="Content.Server" type="DotNetProject" />
<method v="2" />
</configuration>
</component>
dffdff2423 marked this conversation as resolved.
Show resolved Hide resolved
</component>
34 changes: 34 additions & 0 deletions Content.Client/_CD/Admin/UI/EventPreferencePanelEui.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Content.Client.Eui;
using Content.Shared._CD.Admin;
using Content.Shared.Eui;

namespace Content.Client._CD.Admin.UI;

public sealed class EventPreferencesPanelEui : BaseEui
{
private EventPreferencesPanel EventPreferencesPanel { get; }

public EventPreferencesPanelEui()
{
EventPreferencesPanel = new EventPreferencesPanel();
}

public override void Opened()
{
EventPreferencesPanel.OpenCentered();
}

public override void Closed()
{
EventPreferencesPanel.Close();
}

public override void HandleState(EuiStateBase state)
{
if (state is not EventPreferencePanelEuiState s)
return;

EventPreferencesPanel.SetDetails(s.Username, s.Preferences, s.VisibleAntagPrototypes);
}

}
5 changes: 5 additions & 0 deletions Content.Client/_CD/Admin/UI/EventPreferences.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<cdadmin:EventPreferences xmlns="https://spacestation14.io"
xmlns:cdadmin="clr-namespace:Content.Client._CD.Admin.UI"
MinSize="100 200">
<BoxContainer Name="EventPrefContainer" Orientation="Vertical" HorizontalExpand="True" VerticalExpand="True"/>
</cdadmin:EventPreferences>
44 changes: 44 additions & 0 deletions Content.Client/_CD/Admin/UI/EventPreferences.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using Content.Shared.Preferences;
using Content.Shared.Roles;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;

namespace Content.Client._CD.Admin.UI;

[GenerateTypedNameReferences]
public sealed partial class EventPreferences : Control
{
public EventPreferences()
{
RobustXamlLoader.Load(this);
}

/// <summary>
/// Fills the BoxContainer with all the AntagPrototypes that we want to show, and colours them based on whether
/// the passed in preference profile has these preferences set to yes or no.
/// </summary>
/// <param name="userPreferences">The profile of preferences that we want to check for.</param>
/// <param name="listablePreferences">The preferences that we want to list and compare with userPreferences.</param>
public void SetPreferenceList(HumanoidCharacterProfile userPreferences, IEnumerable<AntagPrototype> listablePreferences)
{
var labelList = new List<Label>();

// representing whether a player has a preference with red and green colors
foreach (var listablePreference in listablePreferences)
{
var label = new Label();

var color = Color.Red;
if (userPreferences.AntagPreferences.Contains(listablePreference))
color = Color.Green;

label.Text = Loc.GetString(listablePreference.Name);
label.Modulate = color;
label.HorizontalAlignment = HAlignment.Center;

EventPrefContainer.AddChild(label);
}
}
}
14 changes: 14 additions & 0 deletions Content.Client/_CD/Admin/UI/EventPreferencesPanel.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<DefaultWindow xmlns="https://spacestation14.io"
xmlns:cdadmin="clr-namespace:Content.Client._CD.Admin.UI"
xmlns:cc="clr-namespace:Content.Client.Administration.UI.CustomControls"
Title="{Loc cd-eventpreferencepanel-title}"
Resizable="False"
>
<BoxContainer Orientation="Vertical" HorizontalAlignment="Center">
<Label Name="PlayerLabel"/>
<Label Name="CharacterLabel"/>
<cc:HSeparator Margin="12"/>
<cdadmin:EventPreferences Name="EventPreferenceControl"/>
<Control Margin="12"/>
</BoxContainer>
</DefaultWindow>
31 changes: 31 additions & 0 deletions Content.Client/_CD/Admin/UI/EventPreferencesPanel.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Content.Shared.Preferences;
using Content.Shared.Roles;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
namespace Content.Client._CD.Admin.UI;

[GenerateTypedNameReferences]
public sealed partial class EventPreferencesPanel : DefaultWindow
{
public EventPreferencesPanel()
{
RobustXamlLoader.Load(this);
}

/// <summary>
/// Sets the displayed username of the current player alongside their current selected character's name
/// </summary>
/// <param name="username">Player's username</param>
/// <param name="currentPreferences">Profile preference to fetch the character name from</param>
public void SetDetails(string username, HumanoidCharacterProfile currentPreferences, IEnumerable<AntagPrototype> listablePreferences)
{
PlayerLabel.Text = Loc.GetString("cd-eventpreferencepanel-player", ("player", username));
CharacterLabel.Text = Loc.GetString(
"cd-eventpreferencepanel-character",
("characterName", currentPreferences.Name)
);

EventPreferenceControl.SetPreferenceList(currentPreferences, listablePreferences);
}
}
61 changes: 61 additions & 0 deletions Content.Server/_CD/Admin/Commands/EventPreferencesCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System.Linq;
using Content.Server.Administration;
using Content.Server.EUI;
using Content.Server.Preferences.Managers;
using Content.Shared.Administration;
using Content.Shared.Preferences;
using Robust.Server.Player;
using Robust.Shared.Console;

namespace Content.Server._CD.Admin.Commands;

[AdminCommand(AdminFlags.Admin)]
public sealed class EventPreferencesCommand : LocalizedCommands
lunarcomets marked this conversation as resolved.
Show resolved Hide resolved
{
[Dependency] private readonly IPlayerLocator _locator = default!;
[Dependency] private readonly IServerPreferencesManager _pref = default!;
[Dependency] private readonly EuiManager _eui = default!;
[Dependency] private readonly IPlayerManager _players = default!;
public override string Command => "eventpreferences";

public override async void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (shell.Player is not { } admin)
{
shell.WriteError(Loc.GetString("cmd-playerpanel-server"));
return;
}

if (args.Length != 1)
{
shell.WriteError(Loc.GetString("cmd-playerpanel-invalid-arguments"));
return;
}

var queriedPlayer = await _locator.LookupIdByNameAsync(args[0]);

if (queriedPlayer == null)
{
shell.WriteError(Loc.GetString("cmd-playerpanel-invalid-player"));
return;
}

var pref = (HumanoidCharacterProfile)_pref.GetPreferences(queriedPlayer.UserId).SelectedCharacter;

var ui = new EventPreferencesPanelEui(queriedPlayer, pref);
_eui.OpenEui(ui, admin);
ui.StateDirty();
}

public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
{
if (args.Length == 1)
{
var options = _players.Sessions.OrderBy(c => c.Name).Select(c => c.Name).ToArray();

return CompletionResult.FromHintOptions(options, LocalizationManager.GetString("cmd-playerpanel-completion"));
}

return CompletionResult.Empty;
}
}
23 changes: 23 additions & 0 deletions Content.Server/_CD/Admin/EventPreferenceEui.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Content.Server.Administration;
using Content.Server.EUI;
using Content.Shared.Preferences;

namespace Content.Server._CD.Admin;

public sealed class EventPreferenceEui : BaseEui
{
private readonly HumanoidCharacterProfile _playerPref;
private readonly LocatedPlayerData _targetPlayer;

public EventPreferenceEui(LocatedPlayerData player, HumanoidCharacterProfile pref)
{
IoCManager.InjectDependencies(this);
_targetPlayer = player;
_playerPref = pref;
}

public async void SetState()
{
StateDirty();
}
}
43 changes: 43 additions & 0 deletions Content.Server/_CD/Admin/EventPreferencePanelEui.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using Content.Server.Administration;
using Content.Server.EUI;
using Content.Shared._CD.Admin;
using Content.Shared.Eui;
using Content.Shared.Preferences;
using Content.Shared.Roles;
using Robust.Shared.Prototypes;

namespace Content.Server._CD.Admin;

public sealed class EventPreferencesPanelEui : BaseEui
{
[Dependency] private readonly IPrototypeManager _proto = default!;

private readonly HumanoidCharacterProfile _playerPref;
private readonly LocatedPlayerData _targetPlayer;
private List<AntagPrototype> _visibleAntagPrototypes = new List<AntagPrototype>();

public EventPreferencesPanelEui(LocatedPlayerData player, HumanoidCharacterProfile pref)
{
IoCManager.InjectDependencies(this);
_targetPlayer = player;
_playerPref = pref;

var visibleAntagPrototypes = new List<AntagPrototype>();
foreach (var antagPrototype in _proto.EnumeratePrototypes<AntagPrototype>())
{
if(antagPrototype.VisiblePreference)
visibleAntagPrototypes.Add(antagPrototype);
}

_visibleAntagPrototypes = visibleAntagPrototypes;
}

public override EuiStateBase GetNewState()
{
return new EventPreferencePanelEuiState(
_targetPlayer.Username,
_playerPref,
_visibleAntagPrototypes
);
}
}
17 changes: 17 additions & 0 deletions Content.Shared/_CD/Admin/EventPreferencePanelEuiState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Content.Shared.Eui;
using Content.Shared.Preferences;
using Content.Shared.Roles;
using Robust.Shared.Serialization;

namespace Content.Shared._CD.Admin;

[Serializable, NetSerializable]
public sealed class EventPreferencePanelEuiState(
string username,
HumanoidCharacterProfile preferences,
List<AntagPrototype> visibleAntagPrototypes) : EuiStateBase
{
public readonly string Username = username;
public readonly HumanoidCharacterProfile Preferences = preferences;
public readonly List<AntagPrototype> VisibleAntagPrototypes = visibleAntagPrototypes;
}
7 changes: 7 additions & 0 deletions Resources/Locale/en-US/_CD/admin/admin.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,10 @@ admin-player-actions-window-cd-record-purge = Modify Character Records
cd-actions-admin-modify-records = Modify Character Records
cd-actions-admin-modify-reset = Reset Records
cd-actions-admin-modify-del-entry = Delete Entry

cd-eventpreferencepanel-title = Event Preference View
cd-eventpreferencepanel-player = Player: {$player}
cd-eventpreferencepanel-character = Character: {$characterName}

cmd-eventpreferences-help = Usage: eventpreferences <name>
cmd-eventpreferences-desc = Displays a player's current character's event preferences (i.e. antags)
dffdff2423 marked this conversation as resolved.
Show resolved Hide resolved
Loading