forked from Rxup/space-station-14
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Добавляет в панель админа кнопку выдачи времени.
- Loading branch information
Showing
7 changed files
with
164 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
Content.Client/Administration/UI/Tabs/AdminTab/TimePanelWindow.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
120
Content.Client/Administration/UI/Tabs/AdminTab/TimePanelWindow.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
Resources/Locale/en-US/administration/ui/tabs/admin-tab/time-panel-window.ftl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
Resources/Locale/ru-RU/administration/ui/tabs/admin-tab/time-panel-window.ftl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = Минут |