* JobRequirement refactor (#30347) * refactor JobRequirements * add profile support * fix * Update quartermaster.yml * sloth fixes * inport 30208 * Update DepartmentPrototype.cs * species restriction * left tweak stick * stringbuilder is cool! * Add JobRequirementOverride prototypes (#28607) * Add JobRequirementOverride prototypes * a * invert if * Add override that takes in prototypes directly * - fix: Errors. * - add: Add stuff. * - fix: Formatted message fix. * - add: Another requirement. --------- Co-authored-by: Ed <96445749+TheShuEd@users.noreply.github.com> Co-authored-by: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com>
197 lines
6.4 KiB
C#
197 lines
6.4 KiB
C#
using System.Linq;
|
|
using Content.Client.Administration.UI.CustomControls;
|
|
using Content.Shared.Administration;
|
|
using Content.Shared.Roles;
|
|
using JetBrains.Annotations;
|
|
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.Utility;
|
|
using Robust.Client.Graphics;
|
|
using Robust.Client.UserInterface;
|
|
using Robust.Shared.Prototypes;
|
|
using static Robust.Client.UserInterface.Controls.LineEdit;
|
|
|
|
namespace Content.Client.Administration.UI.Tabs.AdminTab;
|
|
|
|
[GenerateTypedNameReferences, UsedImplicitly]
|
|
public sealed partial class RoleBanWindow : DefaultWindow
|
|
{
|
|
private readonly IClientConsoleHost _clientConsoleHost = IoCManager.Resolve<IClientConsoleHost>();
|
|
private readonly List<CheckBox> _roleCheckboxes = new();
|
|
|
|
public RoleBanWindow()
|
|
{
|
|
RobustXamlLoader.Load(this);
|
|
IoCManager.InjectDependencies(this);
|
|
OnNamesChanged();
|
|
PlayerNameLine.OnTextChanged += _ => OnNamesChanged();
|
|
MinutesLine.OnTextChanged += UpdateButtonsText;
|
|
RoleNameLine.OnTextChanged += _ => OnNamesChanged();
|
|
PlayerList.OnSelectionChanged += OnPlayerSelectionChanged;
|
|
SubmitByNameButton.OnPressed += SubmitByNameButtonOnPressed;
|
|
SubmitListButton.OnPressed += SubmitListButtonOnPressed;
|
|
MinutesLine.OnTextChanged += UpdateButtonsText;
|
|
HourButton.OnPressed += _ => AddMinutes(60);
|
|
DayButton.OnPressed += _ => AddMinutes(1440);
|
|
WeekButton.OnPressed += _ => AddMinutes(10080);
|
|
MonthButton.OnPressed += _ => AddMinutes(43200);
|
|
|
|
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
|
|
foreach (var proto in prototypeManager.EnumeratePrototypes<DepartmentPrototype>())
|
|
{
|
|
CreateRoleGroup(proto.ID, proto.Roles.Select(x => x.Id), proto.Color);
|
|
}
|
|
|
|
CreateRoleGroup("Antagonist", prototypeManager.EnumeratePrototypes<AntagPrototype>().Select(p => p.ID),
|
|
Color.Red);
|
|
}
|
|
|
|
private void CreateRoleGroup(string roleName, IEnumerable<string> roleList, Color color)
|
|
{
|
|
var outerContainer = new BoxContainer
|
|
{
|
|
Name = $"{roleName}GroupOuterBox",
|
|
HorizontalExpand = true,
|
|
VerticalExpand = true,
|
|
Orientation = BoxContainer.LayoutOrientation.Vertical,
|
|
Margin = new Thickness(4)
|
|
};
|
|
|
|
var departmentCheckbox = new CheckBox
|
|
{
|
|
Name = $"{roleName}GroupCheckbox",
|
|
Text = roleName,
|
|
Modulate = color,
|
|
HorizontalAlignment = HAlignment.Left
|
|
};
|
|
|
|
outerContainer.AddChild(departmentCheckbox);
|
|
var innerContainer = new BoxContainer
|
|
{
|
|
Name = $"{roleName}GroupInnerBox",
|
|
HorizontalExpand = true,
|
|
Orientation = BoxContainer.LayoutOrientation.Horizontal
|
|
};
|
|
|
|
departmentCheckbox.OnToggled += args =>
|
|
{
|
|
foreach (var child in innerContainer.Children)
|
|
{
|
|
if (child is CheckBox c)
|
|
{
|
|
c.Pressed = args.Pressed;
|
|
}
|
|
}
|
|
};
|
|
|
|
outerContainer.AddChild(innerContainer);
|
|
foreach (var role in roleList)
|
|
{
|
|
AddRoleCheckbox(role, innerContainer, departmentCheckbox);
|
|
}
|
|
|
|
RolesContainer.AddChild(new PanelContainer
|
|
{
|
|
PanelOverride = new StyleBoxFlat
|
|
{
|
|
BackgroundColor = color
|
|
}
|
|
});
|
|
|
|
RolesContainer.AddChild(outerContainer);
|
|
RolesContainer.AddChild(new HSeparator());
|
|
}
|
|
|
|
private void AddRoleCheckbox(string role, Control container, CheckBox header)
|
|
{
|
|
var roleCheckbox = new CheckBox
|
|
{
|
|
Name = $"{role}RoleCheckbox",
|
|
Text = role
|
|
};
|
|
|
|
roleCheckbox.OnToggled += args =>
|
|
{
|
|
if (args is { Pressed: true, Button.Parent: { } } && args.Button.Parent.Children
|
|
.Where(e => e is CheckBox).All(e => ((CheckBox) e).Pressed))
|
|
header.Pressed = args.Pressed;
|
|
else
|
|
header.Pressed = false;
|
|
};
|
|
|
|
container.AddChild(roleCheckbox);
|
|
_roleCheckboxes.Add(roleCheckbox);
|
|
}
|
|
|
|
private bool TryGetMinutes(string str, out uint minutes)
|
|
{
|
|
minutes = 0;
|
|
return string.IsNullOrWhiteSpace(str) || uint.TryParse(str, out minutes);
|
|
}
|
|
|
|
private void AddMinutes(uint add)
|
|
{
|
|
if (!TryGetMinutes(MinutesLine.Text, out var minutes))
|
|
return;
|
|
|
|
MinutesLine.Text = $"{minutes + add}";
|
|
UpdateButtons(minutes + add);
|
|
}
|
|
|
|
private void UpdateButtonsText(LineEditEventArgs obj)
|
|
{
|
|
if (!TryGetMinutes(obj.Text, out var minutes))
|
|
return;
|
|
|
|
UpdateButtons(minutes);
|
|
}
|
|
|
|
private void UpdateButtons(uint minutes)
|
|
{
|
|
HourButton.Text = $"+1h ({minutes / 60})";
|
|
DayButton.Text = $"+1d ({minutes / 1440})";
|
|
WeekButton.Text = $"+1w ({minutes / 10080})";
|
|
MonthButton.Text = $"+1M ({minutes / 43200})";
|
|
}
|
|
|
|
private void OnNamesChanged()
|
|
{
|
|
if (!string.IsNullOrEmpty(PlayerNameLine.Text) && !string.IsNullOrEmpty(RoleNameLine.Text))
|
|
{
|
|
SubmitByNameButton.Disabled = false;
|
|
}
|
|
else
|
|
{
|
|
SubmitByNameButton.Disabled = true;
|
|
}
|
|
|
|
SubmitListButton.Disabled = string.IsNullOrEmpty(PlayerNameLine.Text);
|
|
}
|
|
|
|
private void OnPlayerSelectionChanged(PlayerInfo? player)
|
|
{
|
|
PlayerNameLine.Text = player?.Username ?? string.Empty;
|
|
OnNamesChanged();
|
|
}
|
|
|
|
private void SubmitByNameButtonOnPressed(BaseButton.ButtonEventArgs obj)
|
|
{
|
|
_clientConsoleHost.ExecuteCommand(
|
|
$"roleban \"{PlayerNameLine.Text}\" \"{RoleNameLine.Text}\" \"{CommandParsing.Escape(ReasonLine.Text)}\" \"{MinutesLine.Text}\" \"medium\" \"{GlobalBan.Pressed}\"");
|
|
}
|
|
|
|
private void SubmitListButtonOnPressed(BaseButton.ButtonEventArgs obj)
|
|
{
|
|
var pressedCheckBoxes = _roleCheckboxes.Where(checkbox => checkbox.Pressed);
|
|
|
|
foreach (var checkbox in pressedCheckBoxes)
|
|
{
|
|
_clientConsoleHost.ExecuteCommand(
|
|
$"roleban \"{PlayerNameLine.Text}\" \"{checkbox.Text}\" \"{CommandParsing.Escape(ReasonLine.Text)}\" \"{MinutesLine.Text}\" \"medium\" \"{GlobalBan.Pressed}\"");
|
|
}
|
|
}
|
|
}
|