Files
ss14-wega/Content.Client/_Wega/Mining/MiningServerControl.xaml.cs
Zekins 91f919dec0 Майнинг сервера #147
Майнинг сервера
2025-08-27 22:28:36 +03:00

88 lines
2.8 KiB
C#

using Content.Shared.Mining;
using Robust.Client.AutoGenerated;
using Robust.Client.Graphics;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.XAML;
namespace Content.Client._Wega.Mining;
[GenerateTypedNameReferences]
public sealed partial class MiningServerControl : Control
{
public event Action<NetEntity, int>? OnStageChange;
public event Action<NetEntity>? OnTogglePower;
private readonly NetEntity _serverEntity;
private bool _isBroken;
public MiningServerControl(MiningServerData data)
{
RobustXamlLoader.Load(this);
_serverEntity = data.Uid;
if (StatusIndicator.PanelOverride is StyleBoxFlat statusBox)
statusBox.BackgroundColor = Color.Gray;
if (TemperatureBar.ForegroundStyleBoxOverride is StyleBoxFlat tempBox)
tempBox.BackgroundColor = Color.Orange;
UpdateData(data);
StageUp.OnPressed += _ => OnStageChange?.Invoke(_serverEntity, 1);
StageDown.OnPressed += _ => OnStageChange?.Invoke(_serverEntity, -1);
TogglePower.OnPressed += _ => OnTogglePower?.Invoke(_serverEntity);
}
public void UpdateData(MiningServerData data)
{
_isBroken = data.IsBroken;
ServerIdLabel.Text = Loc.GetString("mining-server-id", ("id", data.Uid));
StageLabel.Text = data.Stage.ToString();
TemperatureBar.Value = data.Temperature;
var tempColor = data.Temperature switch
{
> 330 => Color.Red,
> 310 => Color.Orange,
_ => Color.Yellow
};
if (TemperatureBar.ForegroundStyleBoxOverride is StyleBoxFlat tempBox)
tempBox.BackgroundColor = tempColor;
if (_isBroken)
{
StatusLabel.Text = Loc.GetString("mining-server-status-broken");
if (StatusIndicator.PanelOverride is StyleBoxFlat statusBox)
statusBox.BackgroundColor = Color.Red;
TogglePower.Disabled = true;
}
else
{
var statusText = data.IsActive
? Loc.GetString("mining-server-status-active")
: Loc.GetString("mining-server-status-inactive");
StatusLabel.Text = statusText;
if (StatusIndicator.PanelOverride is StyleBoxFlat statusBox)
statusBox.BackgroundColor = data.IsActive ? Color.Green : Color.Yellow;
TogglePower.Disabled = false;
}
TogglePower.Text = data.IsActive
? Loc.GetString("mining-server-power-off")
: Loc.GetString("mining-server-power-on");
}
public void SetDisabled(bool disabled)
{
StageUp.Disabled = disabled || _isBroken;
StageDown.Disabled = disabled || _isBroken;
TogglePower.Disabled = disabled || _isBroken;
}
}