105 lines
3.2 KiB
C#
105 lines
3.2 KiB
C#
using Content.Shared.Administration;
|
|
using Content.Shared.Roles;
|
|
using JetBrains.Annotations;
|
|
using Robust.Client.AutoGenerated;
|
|
using Robust.Client.Console;
|
|
using Robust.Client.UserInterface.CustomControls;
|
|
using Robust.Client.UserInterface.XAML;
|
|
using Robust.Shared.Prototypes;
|
|
using static Robust.Client.UserInterface.Controls.LineEdit;
|
|
|
|
namespace Content.Client._White.Administration;
|
|
|
|
[GenerateTypedNameReferences]
|
|
[UsedImplicitly]
|
|
public sealed partial class HoursPanel : DefaultWindow
|
|
{
|
|
public HoursPanel()
|
|
{
|
|
RobustXamlLoader.Load(this);
|
|
var roles = new Dictionary<int, string>();
|
|
PlayerNameLine.OnTextChanged += _ => OnNamesChanged();
|
|
PlayerList.OnSelectionChanged += OnPlayerSelectionChanged;
|
|
HourButton.OnPressed += _ => AddMinutes(60);
|
|
MinutesLine.OnTextChanged += UpdateButtonsText;
|
|
RoleOption.OnItemSelected += args => RoleOption.SelectId(args.Id);
|
|
SubmitButton.OnPressed += _ => OnSubmitButtonOnPressed(roles);
|
|
SaveButton.OnPressed += _ => OnSaveButtonOnPressed();
|
|
OnNamesChanged();
|
|
InitRoleList(roles);
|
|
|
|
}
|
|
private void InitRoleList(Dictionary<int, string> roles)
|
|
{
|
|
var roleInd = 0;
|
|
RoleOption.AddItem("общее", roleInd);
|
|
roles.Add(roleInd, "Overall");
|
|
roleInd++;
|
|
foreach (var dep in IoCManager.Resolve<IPrototypeManager>().EnumeratePrototypes<DepartmentPrototype>())
|
|
{
|
|
foreach (var role in dep.Roles)
|
|
{
|
|
RoleOption.AddItem(Loc.GetString($"Job{role.Id}"), roleInd);
|
|
roles.Add(roleInd, $"Job{role.Id}");
|
|
roleInd++;
|
|
}
|
|
}
|
|
RoleOption.SelectId(0);
|
|
}
|
|
|
|
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))
|
|
minutes = 0;
|
|
|
|
MinutesLine.Text = $"{minutes + add}";
|
|
UpdateButtons(minutes + add);
|
|
OnNamesChanged();
|
|
}
|
|
|
|
private void UpdateButtonsText(LineEditEventArgs obj)
|
|
{
|
|
if (!TryGetMinutes(obj.Text, out var minutes))
|
|
return;
|
|
|
|
UpdateButtons(minutes);
|
|
OnNamesChanged();
|
|
}
|
|
|
|
private void UpdateButtons(uint minutes)
|
|
{
|
|
HourButton.Text = $"+1h ({minutes / 60})";
|
|
}
|
|
|
|
private void OnNamesChanged()
|
|
{
|
|
SubmitButton.Disabled = string.IsNullOrEmpty(PlayerNameLine.Text) || !TryGetMinutes(MinutesLine.Text, out _);
|
|
}
|
|
|
|
private void OnPlayerSelectionChanged(PlayerInfo? player)
|
|
{
|
|
PlayerNameLine.Text = player?.Username ?? string.Empty;
|
|
OnNamesChanged();
|
|
}
|
|
|
|
private void OnSubmitButtonOnPressed(Dictionary<int, string> roles)
|
|
{
|
|
IoCManager.Resolve<IClientConsoleHost>().ExecuteCommand(
|
|
$"playtime_addrole {PlayerNameLine.Text} {roles[RoleOption.SelectedId]} {MinutesLine.Text}");
|
|
SaveButton.Disabled = false;
|
|
}
|
|
|
|
private void OnSaveButtonOnPressed()
|
|
{
|
|
IoCManager.Resolve<IClientConsoleHost>().ExecuteCommand(
|
|
$"playtime_save {PlayerNameLine.Text}");
|
|
SaveButton.Disabled = true;
|
|
}
|
|
}
|