Hours panel2 (#886)
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:cc="clr-namespace:Content.Client.Administration.UI.CustomControls"
|
||||
xmlns:at="clr-namespace:Content.Client.Administration.UI.Tabs.AdminTab"
|
||||
xmlns:wd="clr-namespace:Content.Client._White.Administration"
|
||||
xmlns:wd="clr-namespace:Content.Client._White.Administration.HoursPanelSystems"
|
||||
Margin="4"
|
||||
MinSize="50 50">
|
||||
<BoxContainer Orientation="Vertical">
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
<LineEdit Name="MinutesLine" MinWidth="100" HorizontalExpand="True" PlaceHolder="минуты" />
|
||||
<Button Name="HourButton" Text="+1h (0)"/>
|
||||
</BoxContainer>
|
||||
<Label Name="TimeDisplayer" Text="Время игры: " />
|
||||
<OptionButton Name="RoleOption" />
|
||||
<cc:PlayerListControl Name="PlayerList" VerticalExpand="True" MinWidth="200"/>
|
||||
<Button Name="SubmitButton" Text="Добавить время" />
|
||||
@@ -7,8 +7,12 @@ 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;
|
||||
namespace Content.Client._White.Administration.HoursPanelSystems;
|
||||
|
||||
[GenerateTypedNameReferences]
|
||||
[UsedImplicitly]
|
||||
@@ -17,18 +21,48 @@ 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 => RoleOption.SelectId(args.Id);
|
||||
SubmitButton.OnPressed += _ => OnSubmitButtonOnPressed(roles);
|
||||
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;
|
||||
@@ -88,11 +122,13 @@ public sealed partial class HoursPanel : DefaultWindow
|
||||
OnNamesChanged();
|
||||
}
|
||||
|
||||
private void OnSubmitButtonOnPressed(Dictionary<int, string> roles)
|
||||
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()
|
||||
@@ -0,0 +1,25 @@
|
||||
using Content.Shared._White.Administration;
|
||||
|
||||
namespace Content.Client._White.Administration.HoursPanelSystems;
|
||||
|
||||
public sealed class HoursPanelSystem : EntitySystem
|
||||
{
|
||||
public HoursPanel? Panel;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeNetworkEvent<HoursPanelMessageToClient>(OnHoursPanelMessage);
|
||||
}
|
||||
|
||||
private void OnHoursPanelMessage(HoursPanelMessageToClient message, EntitySessionEventArgs eventArgs)
|
||||
{
|
||||
Panel?.UpdateTime(message.Time);
|
||||
}
|
||||
|
||||
public void SendPlayerTimeRequest(HoursPanelMessageToServer message)
|
||||
{
|
||||
RaiseNetworkEvent(message);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user