Skip to content

Commit

Permalink
Добавляет в панель админа кнопку выдачи времени.
Browse files Browse the repository at this point in the history
  • Loading branch information
CrimeMoot authored Jul 19, 2024
1 parent 7e3f3fa commit 0445655
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<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}" />
<cc:UICommandButton Command="timeto" Text="{Loc admin-player-actions-window-timeto}" WindowType="{x:Type at:TimePanelWindow}" />
<cc:CommandButton Command="announceui" Text="{Loc admin-player-actions-window-announce}"/>
<cc:UICommandButton Command="callshuttle" Text="{Loc admin-player-actions-window-shuttle}" WindowType="{x:Type at:AdminShuttleWindow}"/>
<cc:CommandButton Command="adminlogs" Text="{Loc admin-player-actions-window-admin-logs}"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<DefaultWindow
xmlns="https://spacestation14.io"
xmlns:cc="clr-namespace:Content.Client.Administration.UI.CustomControls"
Title="{Loc admin-player-actions-window-timeto}" MinSize="425 325">
<BoxContainer Orientation="Vertical">
<BoxContainer Orientation="Horizontal">
<Label Text="{Loc admin-time-panel-window-player}" MinWidth="100" />
<Control MinWidth="50" />
<LineEdit Name="PlayerNameLine" MinWidth="100" HorizontalExpand="True" />
</BoxContainer>
<BoxContainer Orientation="Horizontal">
<Label Text="{Loc admin-time-panel-window-role}" MinSize="100 0" />
<Control MinSize="50 0" />
<OptionButton Name="RoleOption" MinSize="250 0" HorizontalExpand="false" />
</BoxContainer>
<BoxContainer Orientation="Horizontal">
<Label Text="{Loc admin-time-panel-window-minutes}" MinWidth="100" />
<Control MinWidth="50" />
<LineEdit Name="MinutesLine" MinWidth="100" HorizontalExpand="True"/>
<Button Name="HourButton" Text="+1h (0)"/>
<Button Name="DayButton" Text="+1d (0)"/>
<Button Name="WeekButton" Text="+1w (0)"/>
<Button Name="MonthButton" Text="+1M (0)"/>
</BoxContainer>
<cc:PlayerListControl Name="PlayerList" VerticalExpand="True" />
<BoxContainer MinWidth="250" Orientation="Horizontal">
<Button Name="SubmitButton" Text="{Loc admin-time-panel-window-add-to-role}" HorizontalExpand="True"/>
<Button Name="SubmitOverallButton" Text="{Loc admin-time-panel-window-add-to-overall}" HorizontalExpand="True"/>
</BoxContainer>
</BoxContainer>
</DefaultWindow>
120 changes: 120 additions & 0 deletions Content.Client/Administration/UI/Tabs/AdminTab/TimePanelWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
using System.Linq;
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.IoC;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
using static Robust.Client.UserInterface.Controls.LineEdit;

namespace Content.Client.Administration.UI.Tabs.AdminTab
{
[GenerateTypedNameReferences]
[UsedImplicitly]
public sealed partial class TimePanelWindow : DefaultWindow
{
[Dependency]
private readonly IPrototypeManager _prototypeManager = default!;
public TimePanelWindow()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);

PopulateJobs();

PlayerNameLine.OnTextChanged += _ => OnFieldChanged();
PlayerList.OnSelectionChanged += OnPlayerSelectionChanged;
SubmitButton.OnPressed += SubmitButtonOnOnPressed;
SubmitButton.Disabled = SubmitOverallButton.Disabled = true;
SubmitOverallButton.OnPressed += SubmitOverallButtonOnOnPressed;
MinutesLine.OnTextChanged += UpdateButtonsText;
MinutesLine.OnTextChanged += _ => OnFieldChanged();
RoleOption.OnItemSelected += args => RoleOption.SelectId(args.Id);
HourButton.OnPressed += _ => AddMinutes(60);
DayButton.OnPressed += _ => AddMinutes(1440);
WeekButton.OnPressed += _ => AddMinutes(10080);
MonthButton.OnPressed += _ => AddMinutes(43200);
}

private void PopulateJobs()
{
var jobs = _prototypeManager.EnumeratePrototypes<JobPrototype>().ToList();
var i = 0;
foreach (var job in jobs)
{
RoleOption.AddItem(job.LocalizedName);
RoleOption.SetItemMetadata(i++, job.PlayTimeTracker);
}
}

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}";
OnFieldChanged();
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 OnFieldChanged()
{
var state = string.IsNullOrEmpty(PlayerNameLine.Text) || string.IsNullOrEmpty(MinutesLine.Text);
SubmitButton.Disabled = state;
SubmitOverallButton.Disabled = state;
}

public void OnPlayerSelectionChanged(PlayerInfo? player)
{
PlayerNameLine.Text = player?.Username ?? string.Empty;
OnFieldChanged();
}

private void SubmitButtonOnOnPressed(BaseButton.ButtonEventArgs obj)
{
var selectedRole = (string?) RoleOption.SelectedMetadata;
if (string.IsNullOrWhiteSpace(selectedRole))
return;

IoCManager.Resolve<IClientConsoleHost>().ExecuteCommand(
$"playtime_addrole \"{PlayerNameLine.Text}\" \"{CommandParsing.Escape(selectedRole)}\" {MinutesLine.Text}");
}

private void SubmitOverallButtonOnOnPressed(BaseButton.ButtonEventArgs obj)
{
IoCManager.Resolve<IClientConsoleHost>().ExecuteCommand(
$"playtime_addoverall \"{PlayerNameLine.Text}\" {MinutesLine.Text}");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ admin-player-actions-window-title = Player Actions Panel
admin-player-actions-window-ban = Banning panel
admin-player-actions-window-admin-ghost = Admin Ghost
admin-player-actions-window-teleport = Teleport
admin-player-actions-window-timeto = Time Panel
admin-player-actions-window-permissions = Permissions Panel
admin-player-actions-window-announce = Announce
admin-player-actions-window-shuttle = (Re)call Shuttle
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
admin-time-panel-window-player = Player
admin-time-panel-window-role = Role
admin-time-panel-window-add-to-role = Add to role
admin-time-panel-window-add-to-overall = Add to overall
admin-time-panel-window-minutes = Minutes
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ admin-player-actions-window-title = Действия с игроками
admin-player-actions-window-ban = Панель банов
admin-player-actions-window-admin-ghost = Админ призрак
admin-player-actions-window-teleport = Телепорт
admin-player-actions-window-timeto = Панель времени
admin-player-actions-window-permissions = Панель доступов
admin-player-actions-window-announce = Сделать объявление
admin-player-actions-window-shuttle = Вызвать/отозвать шаттл
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
admin-time-panel-window-player = Игрок
admin-time-panel-window-role = Роль
admin-time-panel-window-add-to-role = Добавить к роли
admin-time-panel-window-add-to-overall = Добавить к общему
admin-time-panel-window-minutes = Минут

0 comments on commit 0445655

Please sign in to comment.