Skip to content

Commit

Permalink
Merge branch 'master' into Blueprints
Browse files Browse the repository at this point in the history
  • Loading branch information
blackknight954 authored Dec 11, 2024
2 parents 7d4c957 + 2fd8cc6 commit 4af0b99
Show file tree
Hide file tree
Showing 237 changed files with 11,512 additions and 2,895 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<Button Name="BanButton" Text="{Loc player-panel-ban}" Disabled="True"/>
<controls:ConfirmButton Name="RejuvenateButton" Text="{Loc player-panel-rejuvenate}" Disabled="True"/>
</GridContainer>
<Button Name="JobWhitelistsButton" Text="{Loc player-panel-job-whitelists}" SetWidth="136" SetHeight="27" Disabled="True"/> <!-- DeltaV: Job whitelists -->
</BoxContainer>
</BoxContainer>
</ui:FancyWindow>
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public sealed partial class PlayerPanel : FancyWindow
public event Action? OnLogs;
public event Action? OnDelete;
public event Action? OnRejuvenate;
public event Action<NetUserId?>? OnOpenJobWhitelists; // DeltaV

public NetUserId? TargetPlayer;
public string? TargetUsername;
Expand All @@ -52,6 +53,8 @@ public PlayerPanel(IClientAdminManager adminManager)
LogsButton.OnPressed += _ => OnLogs?.Invoke();
DeleteButton.OnPressed += _ => OnDelete?.Invoke();
RejuvenateButton.OnPressed += _ => OnRejuvenate?.Invoke();

JobWhitelistsButton.OnPressed += _ => OnOpenJobWhitelists?.Invoke(TargetPlayer); // DeltaV: Job whitelists
}

public void SetUsername(string player)
Expand Down Expand Up @@ -128,5 +131,6 @@ public void SetButtons()
LogsButton.Disabled = !_adminManager.CanCommand("adminlogs");
RejuvenateButton.Disabled = !_adminManager.HasFlag(AdminFlags.Debug);
DeleteButton.Disabled = !_adminManager.HasFlag(AdminFlags.Debug);
JobWhitelistsButton.Disabled = !_adminManager.HasFlag(AdminFlags.Whitelist); // DeltaV
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public PlayerPanelEui()
PlayerPanel.OnLogs += () => SendMessage(new PlayerPanelLogsMessage());
PlayerPanel.OnRejuvenate += () => SendMessage(new PlayerPanelRejuvenationMessage());
PlayerPanel.OnDelete+= () => SendMessage(new PlayerPanelDeleteMessage());
PlayerPanel.OnOpenJobWhitelists += id => _console.ExecuteCommand($"jobwhitelists \"{id}\""); // DeltaV

PlayerPanel.OnClose += () => SendMessage(new CloseEuiMessage());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<PanelContainer
xmlns="https://spacestation14.io"
xmlns:cc="clr-namespace:Content.Client.DeltaV.Administration.UI"
StyleClasses="BackgroundDark"
HorizontalExpand="True"
Margin="4">
<BoxContainer Orientation="Vertical">
<CheckBox Name="Department"/> <!-- Toggles all jobs in the department at once -->
<GridContainer Name="JobsContainer" Columns="4"/> <!-- Populated with each job to toggle individually-->
</BoxContainer>
</PanelContainer>
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using Content.Shared.Roles;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Prototypes;

namespace Content.Client.DeltaV.Administration.UI;

[GenerateTypedNameReferences]
public sealed partial class DepartmentWhitelistPanel : PanelContainer
{
public Action<ProtoId<JobPrototype>, bool>? OnSetJob;

public DepartmentWhitelistPanel(DepartmentPrototype department, IPrototypeManager proto, HashSet<ProtoId<JobPrototype>> whitelists, bool globalWhitelist) // Frontier: add globalWhitelist
{
RobustXamlLoader.Load(this);

var anyValid = false;//
var allWhitelisted = true;
var grey = Color.FromHex("#ccc");
foreach (var id in department.Roles)
{
var thisJob = id; // closure capturing funny

// Frontier: skip non-whitelisted roles, cache prototype
var jobProto = proto.Index(id);
if (!jobProto.Whitelisted)
continue;
else
anyValid = true;
// End Frontier

var button = new CheckBox();
button.Text = jobProto.LocalizedName;
if (!jobProto.Whitelisted)
button.Modulate = grey; // Let admins know whitelisting this job is only for futureproofing.
button.Pressed = whitelists.Contains(id) || globalWhitelist;
button.OnPressed += _ => OnButtonPressed(thisJob, button, globalWhitelist); // Frontier: check global whitelist
JobsContainer.AddChild(button);

allWhitelisted &= button.Pressed;
}

if (!anyValid) // Frontier: hide checkbox set if no valid events
Visible = false; // Frontier

Department.Text = Loc.GetString(department.Name);
Department.Modulate = department.Color;
Department.Pressed = allWhitelisted;
Department.OnPressed += args => OnDepartmentPressed(department, proto, whitelists, globalWhitelist); // Frontier: check global whitelist
}

// Frontier: global whitelist handling
private void OnButtonPressed(ProtoId<JobPrototype> thisJob, CheckBox button, bool globalWhitelist)
{
if (globalWhitelist)
button.Pressed = true; // Force the button on.
else
OnSetJob?.Invoke(thisJob, button.Pressed);
}

private void OnDepartmentPressed(DepartmentPrototype department, IPrototypeManager proto, HashSet<ProtoId<JobPrototype>> whitelists, bool globalWhitelist)
{
// Frontier: global override
if (globalWhitelist)
{
Department.Pressed = true;
return;
}
// End Frontier: global override

foreach (var id in department.Roles)
{
// only request to whitelist roles that aren't already whitelisted, and vice versa - Frontier: roles must be whitelisted
if (whitelists.Contains(id) != Department.Pressed && proto.Index(id).Whitelisted)
OnSetJob?.Invoke(id, Department.Pressed);
}
}
// End Frontier
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<PanelContainer
xmlns="https://spacestation14.io"
xmlns:cc="clr-namespace:Content.Client.DeltaV.Administration.UI"
StyleClasses="BackgroundDark"
HorizontalExpand="True"
Margin="4"> <!-- Frontier: ghost role set whitelist -->
<BoxContainer Orientation="Vertical">
<CheckBox Name="GhostRoleSet"/> <!-- Toggles all jobs in the department at once -->
<GridContainer Name="RolesContainer" Columns="4"/> <!-- Populated with each job to toggle individually-->
</BoxContainer>
</PanelContainer>
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using Content.Shared.Ghost.Roles;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Prototypes;

namespace Content.Client.DeltaV.Administration.UI;

// Frontier: ghost role whitelist set
[GenerateTypedNameReferences]
public sealed partial class GhostRoleSetWhitelistPanel : PanelContainer
{
public Action<ProtoId<GhostRolePrototype>, bool>? OnSetGhostRole;

public GhostRoleSetWhitelistPanel(List<ProtoId<GhostRolePrototype>> ghostRoleList, string ghostRoleSetName, Color ghostRoleSetColor, IPrototypeManager proto, HashSet<ProtoId<GhostRolePrototype>> whitelists, bool globalWhitelist)
{
RobustXamlLoader.Load(this);

var allWhitelisted = true;
foreach (var id in ghostRoleList)
{
var thisRole = id; // closure capturing funny
var button = new CheckBox();
button.Text = Loc.GetString(proto.Index(id).Name);
button.Pressed = whitelists.Contains(id) || globalWhitelist;
button.OnPressed += _ => OnButtonPressed(thisRole, button, globalWhitelist);
RolesContainer.AddChild(button);

allWhitelisted &= button.Pressed;
}

GhostRoleSet.Text = Loc.GetString(ghostRoleSetName);
GhostRoleSet.Modulate = ghostRoleSetColor;
GhostRoleSet.Pressed = allWhitelisted;
GhostRoleSet.OnPressed += args => OnDepartmentPressed(ghostRoleList, whitelists, globalWhitelist);
}

// Frontier: global whitelist
private void OnButtonPressed(ProtoId<GhostRolePrototype> thisRole, CheckBox button, bool globalWhitelist)
{
if (globalWhitelist)
button.Pressed = true; // Force the button on.
else
OnSetGhostRole?.Invoke(thisRole, button.Pressed);
}

private void OnDepartmentPressed(List<ProtoId<GhostRolePrototype>> ghostRoleList, HashSet<ProtoId<GhostRolePrototype>> whitelists, bool globalWhitelist)
{
// Frontier: global override
if (globalWhitelist)
{
GhostRoleSet.Pressed = true;
return;
}
// End Frontier: global override

foreach (var id in ghostRoleList)
{
// only request to whitelist roles that aren't already whitelisted, and vice versa
if (whitelists.Contains(id) != GhostRoleSet.Pressed)
OnSetGhostRole?.Invoke(id, GhostRoleSet.Pressed);
}
}
// End Frontier

}
// End Frontier
42 changes: 42 additions & 0 deletions Content.Client/DeltaV/Administration/UI/JobWhitelistsEui.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Content.Client.Eui;
using Content.Shared.DeltaV.Administration;
using Content.Shared.Eui;

namespace Content.Client.DeltaV.Administration.UI;

public sealed class JobWhitelistsEui : BaseEui
{
private JobWhitelistsWindow Window;

public JobWhitelistsEui()
{
Window = new JobWhitelistsWindow();
Window.OnClose += () => SendMessage(new CloseEuiMessage());
Window.OnSetJob += (id, whitelisted) => SendMessage(new SetJobWhitelistedMessage(id, whitelisted));
Window.OnSetGhostRole += (id, whitelisted) => SendMessage(new SetGhostRoleWhitelistedMessage(id, whitelisted)); // Frontier
Window.OnSetGlobal += (whitelisted) => SendMessage(new SetGlobalWhitelistMessage(whitelisted)); // Frontier
}

public override void HandleState(EuiStateBase state)
{
if (state is not JobWhitelistsEuiState cast)
return;

Window.HandleState(cast);
}

public override void Opened()
{
base.Opened();

Window.OpenCentered();
}

public override void Closed()
{
base.Closed();

Window.Close();
Window.Dispose();
}
}
20 changes: 20 additions & 0 deletions Content.Client/DeltaV/Administration/UI/JobWhitelistsWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<controls:FancyWindow
xmlns="https://spacestation14.io"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
Title="{Loc player-panel-job-whitelists}" MinSize="750 600">
<BoxContainer Orientation="Vertical">
<Label Name="PlayerName" Margin="4"/>
<BoxContainer Orientation="Horizontal" Margin="4">
<BoxContainer Name="TierButtons" Orientation="Horizontal"/>
</BoxContainer>
<ScrollContainer VerticalExpand="True">
<!-- Frontier: global checkbox -->
<BoxContainer Orientation="Vertical">
<CheckBox Name="Global" Margin="4"/>
<BoxContainer Name="Departments" Orientation="Vertical"/>
<BoxContainer Name="GhostRoles" Orientation="Vertical"/> <!-- Frontier: ghost roles -->
</BoxContainer>
<!-- End Frontier: global checkbox -->
</ScrollContainer>
</BoxContainer>
</controls:FancyWindow>
108 changes: 108 additions & 0 deletions Content.Client/DeltaV/Administration/UI/JobWhitelistsWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
using Content.Client.UserInterface.Controls;
using Content.Shared.Database;
using Content.Shared.DeltaV.Administration;
using Content.Shared.Roles;
using Content.Shared.DeltaV.Whitelist;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Prototypes;
using Content.Shared.Ghost.Roles;

namespace Content.Client.DeltaV.Administration.UI;

/// <summary>
/// An admin panel to toggle whitelists for individual jobs or entire departments.
/// This should generally be preferred to a blanket whitelist (Whitelisted: True) since
/// being good with a batong doesn't mean you know engineering and vice versa.
/// </summary>
[GenerateTypedNameReferences]
public sealed partial class JobWhitelistsWindow : FancyWindow
{
[Dependency] private readonly IPrototypeManager _proto = default!;

public Action<ProtoId<JobPrototype>, bool>? OnSetJob;
public Action<ProtoId<GhostRolePrototype>, bool>? OnSetGhostRole; // Frontier
public Action<bool>? OnSetGlobal; // Frontier

public JobWhitelistsWindow()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);

PlayerName.Text = "???";
InitializeTierButtons();

// Frontier: global whitelist button
Global.Text = Loc.GetString("player-panel-global-whitelist");
Global.OnPressed += _ => OnSetGlobal?.Invoke(Global.Pressed);
Global.Modulate = Color.FromHex("#f0c65d");
// End Frontier
}

private void InitializeTierButtons()
{
foreach (var tier in _proto.EnumeratePrototypes<WhitelistTierPrototype>())
{
var button = new Button
{
Text = Loc.GetString(tier.Name),
Modulate = tier.Color
};

button.OnPressed += _ => ApplyWhitelistTier(tier);
TierButtons.AddChild(button);
}
}

private void ApplyWhitelistTier(WhitelistTierPrototype tier)
{
foreach (var jobId in tier.Jobs)
{
OnSetJob?.Invoke(jobId, true);
}

// Frontier: ghost role prototypes
foreach (var ghostRoleId in tier.GhostRoles)
{
OnSetGhostRole?.Invoke(ghostRoleId, true);
}
// End Frontier
}

public void HandleState(JobWhitelistsEuiState state)
{
PlayerName.Text = state.PlayerName;

// Frontier: global whitelist
Global.Pressed = state.GlobalWhitelist;
// End Frontier

Departments.RemoveAllChildren();
foreach (var proto in _proto.EnumeratePrototypes<DepartmentPrototype>())
{
// Frontier: skip empty departments
if (proto.Roles.Count <= 0)
continue;
// End Frontier

var panel = new DepartmentWhitelistPanel(proto, _proto, state.Whitelists, state.GlobalWhitelist);
panel.OnSetJob += (id, whitelisting) => OnSetJob?.Invoke(id, whitelisting);
Departments.AddChild(panel);
}
// Frontier: ghost role prototypes
GhostRoles.RemoveAllChildren();
List<ProtoId<GhostRolePrototype>> ghostRoles = new();
foreach (var proto in _proto.EnumeratePrototypes<GhostRolePrototype>())
{
if (proto.Whitelisted)
ghostRoles.Add(proto.ID);
}
var ghostRolePanel = new GhostRoleSetWhitelistPanel(ghostRoles, Loc.GetString("player-panel-ghost-role-whitelists"), Color.FromHex("#71f0ca"), _proto, state.GhostRoleWhitelists, state.GlobalWhitelist);
ghostRolePanel.OnSetGhostRole += (id, whitelisting) => OnSetGhostRole?.Invoke(id, whitelisting);
GhostRoles.AddChild(ghostRolePanel);
// End Frontier
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ public bool CheckWhitelist(JobPrototype job, [NotNullWhen(false)] out FormattedM
if (!_cfg.GetCVar(CCVars.GameRoleWhitelist))
return true;

// DeltaV - blanket whitelist check in client
//if (_whitelisted)
// return true;

if (job.Whitelisted && !_jobWhitelists.Contains(job.ID) && !_whitelisted) // Frontier: add _whitelisted
{
reason = FormattedMessage.FromUnformatted(Loc.GetString("role-not-whitelisted"));
Expand Down
Loading

0 comments on commit 4af0b99

Please sign in to comment.