[feat] RoleBan UI
# Conflicts: # Content.Client/Administration/UI/Tabs/AdminTab/AdminTab.xaml
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
<GridContainer Columns="3">
|
||||
<cc:UICommandButton Command="kick" Text="{Loc admin-player-actions-window-title}" WindowType="{x:Type at:PlayerActionsWindow}" />
|
||||
<cc:CommandButton Command="banpanel" Text="{Loc admin-player-actions-window-ban}" />
|
||||
<cc:UICommandButton Command="ban" Text="{Loc admin-player-actions-window-roleban}" WindowType="{x:Type at:RoleBanWindow}" />
|
||||
<cc:CommandButton Command="aghost" Text="{Loc admin-player-actions-window-admin-ghost}" />
|
||||
<cc:UICommandButton Command="tpto" Text="{Loc admin-player-actions-window-teleport}" WindowType="{x:Type at:TeleportWindow}" />
|
||||
<cc:CommandButton Command="permissions" Text="{Loc admin-player-actions-window-permissions}" />
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
<DefaultWindow
|
||||
xmlns="https://spacestation14.io"
|
||||
xmlns:cc="clr-namespace:Content.Client.Administration.UI.CustomControls"
|
||||
Title="{Loc admin-job-ban-window-title}" MinSize="425 325">
|
||||
<BoxContainer Orientation="Vertical">
|
||||
<!-- Name -->
|
||||
<BoxContainer Orientation="Horizontal">
|
||||
<Label Text="{Loc admin-job-ban-window-player}" MinWidth="100" />
|
||||
<Control MinWidth="50" />
|
||||
<LineEdit Name="PlayerNameLine" MinWidth="100" HorizontalExpand="True" />
|
||||
</BoxContainer>
|
||||
<!-- Reason -->
|
||||
<BoxContainer Orientation="Horizontal">
|
||||
<Label Text="{Loc admin-job-ban-window-reason}" MinSize="100 0" />
|
||||
<Control MinSize="50 0" />
|
||||
<LineEdit Name="ReasonLine" Text="..." MinSize="100 0" HorizontalExpand="True" />
|
||||
</BoxContainer>
|
||||
<!-- Time -->
|
||||
<BoxContainer Orientation="Horizontal">
|
||||
<Label Text="{Loc admin-job-ban-window-minutes}" MinWidth="100" />
|
||||
<Control MinWidth="50" />
|
||||
<LineEdit Name="MinutesLine" Text="0" MinWidth="100" HorizontalExpand="True" PlaceHolder="{Loc admin-job-ban-window-minutes-amount}" />
|
||||
<Button Name="HourButton" Text="+1ч (0)"/>
|
||||
<Button Name="DayButton" Text="+1д (0)"/>
|
||||
<Button Name="WeekButton" Text="+1н (0)"/>
|
||||
<Button Name="MonthButton" Text="+1М (0)"/>
|
||||
</BoxContainer>
|
||||
<!-- Role -->
|
||||
<BoxContainer Orientation="Horizontal">
|
||||
<Label Text="{Loc admin-job-ban-window-role}" MinWidth="100" />
|
||||
<Control MinWidth="50" />
|
||||
<LineEdit Name="RoleNameLine" MinWidth="100" HorizontalExpand="True" />
|
||||
<Button Name="SubmitByNameButton" Text="{Loc admin-job-ban-window-button-ban-by-name}" />
|
||||
</BoxContainer>
|
||||
<CheckBox Name="GlobalBan" Text="{Loc admin-job-ban-window-global-ban}"/>
|
||||
<BoxContainer Orientation="Horizontal">
|
||||
<cc:PlayerListControl Name="PlayerList" VerticalExpand="True" HorizontalExpand="True"/>
|
||||
<BoxContainer Orientation="Vertical">
|
||||
<BoxContainer Orientation="Horizontal">
|
||||
<BoxContainer Orientation="Vertical">
|
||||
<Label Text="{Loc department-Command}" FontColorOverride="Yellow"/>
|
||||
<CheckBox Name="Captain" Text="{Loc job-name-captain}"/>
|
||||
<CheckBox Name="HeadOfPersonnel" Text="{Loc job-name-hop}"/>
|
||||
<CheckBox Name="HeadOfSecurity" Text="{Loc job-name-hos}"/>
|
||||
<CheckBox Name="ChiefMedicalOfficer" Text="{Loc job-name-cmo}"/>
|
||||
<CheckBox Name="ChiefEngineer" Text="{Loc job-name-ce}"/>
|
||||
<CheckBox Name="Quartermaster" Text="{Loc job-name-qm}"/>
|
||||
<CheckBox Name="ResearchDirector" Text="{Loc job-name-rd}"/>
|
||||
<Label Text="{Loc department-Security}" FontColorOverride="Red"/>
|
||||
<CheckBox Name="Warden" Text="{Loc job-name-warden}"/>
|
||||
<CheckBox Name="SecurityOfficer" Text="{Loc job-name-security}"/>
|
||||
<CheckBox Name="Detective" Text="{Loc job-name-detective}"/>
|
||||
<CheckBox Name="SecurityCadet" Text="{Loc job-name-cadet}"/>
|
||||
<CheckBox Name="Brigmedic" Text="{Loc job-name-brigmedic}"/>
|
||||
<Label Text="{Loc department-Medical}" FontColorOverride="DeepSkyBlue"/>
|
||||
<CheckBox Name="Chemist" Text="{Loc job-name-chemist}"/>
|
||||
<CheckBox Name="MedicalDoctor" Text="{Loc job-name-doctor}"/>
|
||||
<CheckBox Name="Psychologist" Text="{Loc job-name-psychologist}"/>
|
||||
<CheckBox Name="MedicalIntern" Text="{Loc job-name-intern}"/>
|
||||
<Label Text="{Loc department-Engineering}" FontColorOverride="Orange"/>
|
||||
<CheckBox Name="AtmosphericTechnician" Text="{Loc job-name-atmostech}"/>
|
||||
<CheckBox Name="StationEngineer" Text="{Loc job-name-engineer}"/>
|
||||
<CheckBox Name="TechnicalAssistant" Text="{Loc job-name-technical-assistant}"/>
|
||||
</BoxContainer>
|
||||
<Control MinWidth="30" />
|
||||
<BoxContainer Orientation="Vertical">
|
||||
<Label Text="{Loc department-Cargo}" FontColorOverride="Chocolate"/>
|
||||
<CheckBox Name="CargoTechnician" Text="{Loc job-name-cargotech}"/>
|
||||
<CheckBox Name="SalvageSpecialist" Text="{Loc job-name-salvagespec}"/>
|
||||
<Label Text="{Loc department-Science}" FontColorOverride="MediumOrchid"/>
|
||||
<CheckBox Name="Scientist" Text="{Loc job-name-scientist}"/>
|
||||
<Label Text="{Loc department-Civilian}" FontColorOverride="Lime"/>
|
||||
<CheckBox Name="ServiceWorker" Text="{Loc job-name-serviceworker}"/>
|
||||
<CheckBox Name="Bartender" Text="{Loc job-name-bartender}"/>
|
||||
<CheckBox Name="Chef" Text="{Loc job-name-chef}"/>
|
||||
<CheckBox Name="Botanist" Text="{Loc job-name-botanist}"/>
|
||||
<CheckBox Name="Clown" Text="{Loc job-name-clown}"/>
|
||||
<CheckBox Name="Mime" Text="{Loc job-name-mime}"/>
|
||||
<CheckBox Name="Chaplain" Text="{Loc job-name-chaplain}"/>
|
||||
<CheckBox Name="Librarian" Text="{Loc job-name-librarian}"/>
|
||||
<CheckBox Name="Lawyer" Text="{Loc job-name-lawyer}"/>
|
||||
<CheckBox Name="Janitor" Text="{Loc job-name-janitor}"/>
|
||||
<CheckBox Name="Musician" Text="{Loc job-name-musician}"/>
|
||||
<CheckBox Name="Reporter" Text="{Loc job-name-reporter}"/>
|
||||
<CheckBox Name="Zookeeper" Text="{Loc job-name-zookeeper}"/>
|
||||
<!--<Label Text="{Loc department-Silicon}" FontColorOverride="LightGray"/>
|
||||
<CheckBox Name="Cyborg" Text="{Loc job-name-cyborg}"/>
|
||||
<CheckBox Name="MedicalCyborg" Text="{Loc job-name-medical-cyborg}"/>
|
||||
<CheckBox Name="EngCyborg" Text="Инженерный борг"/>
|
||||
<CheckBox Name="SecCyborg" Text="Охранный борг"/>-->
|
||||
</BoxContainer>
|
||||
</BoxContainer>
|
||||
<Button Name="SubmitListButton" Text="{Loc admin-job-ban-window-button-ban}"/>
|
||||
</BoxContainer>
|
||||
</BoxContainer>
|
||||
</BoxContainer>
|
||||
</DefaultWindow>
|
||||
@@ -0,0 +1,123 @@
|
||||
using System.Linq;
|
||||
using Content.Shared.Administration;
|
||||
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.IoC;
|
||||
using Robust.Shared.Utility;
|
||||
using static Robust.Client.UserInterface.Controls.LineEdit;
|
||||
using Content.Shared.Roles;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Client.Administration.UI.Tabs.AdminTab
|
||||
{
|
||||
[GenerateTypedNameReferences]
|
||||
[UsedImplicitly]
|
||||
public sealed partial class RoleBanWindow : DefaultWindow
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = IoCManager.Resolve<IPrototypeManager>();
|
||||
private List<CheckBox> CheckBoxes = new();
|
||||
private readonly IClientConsoleHost _clientConsoleHost = IoCManager.Resolve<IClientConsoleHost>();
|
||||
public RoleBanWindow()
|
||||
{
|
||||
RobustXamlLoader.Load(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);
|
||||
CacheJobs();
|
||||
}
|
||||
private void CacheJobs()
|
||||
{
|
||||
var nameScope = FindNameScope();
|
||||
var jobs = _prototypeManager.EnumeratePrototypes<JobPrototype>();
|
||||
if (nameScope == null)
|
||||
return;
|
||||
foreach (var job in jobs)
|
||||
{
|
||||
if (!job.SetPreference)
|
||||
continue;
|
||||
var control = nameScope.Find(job.ID);
|
||||
if (control is CheckBox)
|
||||
CheckBoxes.Add(FindControl<CheckBox>(job.ID));
|
||||
}
|
||||
}
|
||||
|
||||
private bool TryGetMinutes(string str, out uint minutes)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(str))
|
||||
{
|
||||
minutes = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
return 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}\" \"{GlobalBan.Pressed}\"");
|
||||
}
|
||||
private void SubmitListButtonOnPressed(BaseButton.ButtonEventArgs obj)
|
||||
{
|
||||
var pressedCheckBoxes = CheckBoxes.Where(checkbox => checkbox.Pressed);
|
||||
foreach (var checkbox in pressedCheckBoxes)
|
||||
{
|
||||
_clientConsoleHost.ExecuteCommand($"roleban \"{PlayerNameLine.Text}\" \"{checkbox.Name}\" \"{CommandParsing.Escape(ReasonLine.Text)}\" \"{MinutesLine.Text}\" \"{GlobalBan.Pressed}\"");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user