141 lines
4.7 KiB
C#
141 lines
4.7 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;
|
|
using Content.Shared._White.Administration;
|
|
using Robust.Client.UserInterface.Controls;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
using Robust.Client.Graphics.Clyde;
|
|
|
|
namespace Content.Client._White.Administration.HoursPanelSystems;
|
|
|
|
[GenerateTypedNameReferences]
|
|
[UsedImplicitly]
|
|
public sealed partial class HoursPanel : DefaultWindow
|
|
{
|
|
public HoursPanel()
|
|
{
|
|
RobustXamlLoader.Load(this);
|
|
|
|
var entityManager = IoCManager.Resolve<IEntityManager>();
|
|
var hoursPanelSystem = entityManager.System<HoursPanelSystem>();
|
|
hoursPanelSystem.Panel = this;
|
|
var roles = new Dictionary<int, string>();
|
|
PlayerNameLine.OnTextChanged += _ => OnNamesChanged();
|
|
PlayerNameLine.OnTextEntered += _ => OnNameSubmited(hoursPanelSystem, roles);
|
|
PlayerList.OnSelectionChanged += OnPlayerSelectionChanged;
|
|
HourButton.OnPressed += _ => AddMinutes(60);
|
|
MinutesLine.OnTextChanged += UpdateButtonsText;
|
|
RoleOption.OnItemSelected += args => OnItemSelected(args, hoursPanelSystem, roles);
|
|
SubmitButton.OnPressed += _ => OnSubmitButtonOnPressed(roles, hoursPanelSystem);
|
|
SaveButton.OnPressed += _ => OnSaveButtonOnPressed();
|
|
OnNamesChanged();
|
|
InitRoleList(roles);
|
|
|
|
}
|
|
public void UpdateTime(TimeSpan? time)
|
|
{
|
|
if (time != null)
|
|
{
|
|
var t = (TimeSpan) time;
|
|
TimeDisplayer.Text = $"Время игры: {Math.Floor(t.TotalHours) + string.Format(" ч {0:%m} м", t)}";
|
|
}
|
|
else
|
|
TimeDisplayer.Text = $"Время игры: нет данных";
|
|
}
|
|
|
|
private void OnItemSelected(OptionButton.ItemSelectedEventArgs args, HoursPanelSystem owner, Dictionary<int, string> roles)
|
|
{
|
|
RoleOption.SelectId(args.Id);
|
|
OnNameSubmited(owner, roles);
|
|
}
|
|
|
|
private void OnNameSubmited(HoursPanelSystem owner, Dictionary<int, string> roles)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(PlayerNameLine.Text))
|
|
return;
|
|
|
|
owner.SendPlayerTimeRequest(new HoursPanelMessageToServer(PlayerNameLine.Text, roles[RoleOption.SelectedId]));
|
|
}
|
|
|
|
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, HoursPanelSystem owner)
|
|
{
|
|
IoCManager.Resolve<IClientConsoleHost>().ExecuteCommand(
|
|
$"playtime_addrole {PlayerNameLine.Text} {roles[RoleOption.SelectedId]} {MinutesLine.Text}");
|
|
SaveButton.Disabled = false;
|
|
|
|
owner.SendPlayerTimeRequest(new HoursPanelMessageToServer(PlayerNameLine.Text, roles[RoleOption.SelectedId]));
|
|
}
|
|
|
|
private void OnSaveButtonOnPressed()
|
|
{
|
|
IoCManager.Resolve<IClientConsoleHost>().ExecuteCommand(
|
|
$"playtime_save {PlayerNameLine.Text}");
|
|
SaveButton.Disabled = true;
|
|
}
|
|
}
|