Cleaner BoundUserInterfaces (#17736)
This commit is contained in:
@@ -2,29 +2,28 @@
|
||||
using Content.Shared.APC;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Client.Power.APC
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public sealed class ApcBoundUserInterface : BoundUserInterface
|
||||
{
|
||||
[ViewVariables] private ApcMenu? _menu;
|
||||
[ViewVariables]
|
||||
private ApcMenu? _menu;
|
||||
|
||||
public ApcBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void Open()
|
||||
{
|
||||
base.Open();
|
||||
|
||||
_menu = new ApcMenu(this,Owner);
|
||||
_menu = new ApcMenu(this);
|
||||
_menu.OnClose += Close;
|
||||
_menu.OpenCentered();
|
||||
}
|
||||
|
||||
public ApcBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void UpdateState(BoundUserInterfaceState state)
|
||||
{
|
||||
base.UpdateState(state);
|
||||
|
||||
@@ -18,12 +18,12 @@ namespace Content.Client.Power.APC.UI
|
||||
public sealed partial class ApcMenu : FancyWindow
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
public ApcMenu(ApcBoundUserInterface owner, ClientUserInterfaceComponent component)
|
||||
public ApcMenu(ApcBoundUserInterface owner)
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
RobustXamlLoader.Load(this);
|
||||
|
||||
EntityView.Sprite = _entityManager.GetComponent<SpriteComponent>(component.Owner);
|
||||
EntityView.SetEntity(owner.Owner);
|
||||
BreakerButton.OnPressed += _ => owner.BreakerPressed();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,22 +1,14 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using Content.Client.Computer;
|
||||
using Content.Client.IoC;
|
||||
using Content.Shared.Power;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Client.Power;
|
||||
@@ -25,12 +17,14 @@ namespace Content.Client.Power;
|
||||
public sealed partial class PowerMonitoringWindow : DefaultWindow, IComputerWindow<PowerMonitoringConsoleBoundInterfaceState>
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
private readonly SpriteSystem _spriteSystem = default!;
|
||||
|
||||
public PowerMonitoringWindow()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
SetSize = MinSize = new Vector2(300, 450);
|
||||
IoCManager.InjectDependencies(this);
|
||||
_spriteSystem = IoCManager.Resolve<IEntityManager>().System<SpriteSystem>();
|
||||
MasterTabContainer.SetTabTitle(0, Loc.GetString("power-monitoring-window-tab-sources"));
|
||||
MasterTabContainer.SetTabTitle(1, Loc.GetString("power-monitoring-window-tab-loads"));
|
||||
}
|
||||
@@ -45,7 +39,7 @@ public sealed partial class PowerMonitoringWindow : DefaultWindow, IComputerWind
|
||||
// This means filtering out loads that are not either:
|
||||
// + Batteries (always important)
|
||||
// + Meaningful (size above 0)
|
||||
loads = loads.Where(a => a.IsBattery || (a.Size > 0.0f)).ToArray();
|
||||
loads = loads.Where(a => a.IsBattery || a.Size > 0.0f).ToArray();
|
||||
}
|
||||
UpdateList(TotalLoadsNum, scc.TotalLoads, LoadsList, loads);
|
||||
}
|
||||
@@ -69,7 +63,7 @@ public sealed partial class PowerMonitoringWindow : DefaultWindow, IComputerWind
|
||||
_prototypeManager.TryIndex(ent.IconEntityPrototypeId, out EntityPrototype? entityPrototype);
|
||||
IRsiStateLike? iconState = null;
|
||||
if (entityPrototype != null)
|
||||
iconState = SpriteComponent.GetPrototypeIcon(entityPrototype, StaticIoC.ResC);
|
||||
iconState = _spriteSystem.GetPrototypeIcon(entityPrototype);
|
||||
var icon = iconState?.GetFrame(RSI.State.Direction.South, 0);
|
||||
var item = list[i];
|
||||
item.Text = $"{ent.NameLocalized} {Loc.GetString("power-monitoring-window-value", ("value", ent.Size))}";
|
||||
@@ -81,6 +75,8 @@ public sealed partial class PowerMonitoringWindow : DefaultWindow, IComputerWind
|
||||
[UsedImplicitly]
|
||||
public sealed class PowerMonitoringConsoleBoundUserInterface : ComputerBoundUserInterface<PowerMonitoringWindow, PowerMonitoringConsoleBoundInterfaceState>
|
||||
{
|
||||
public PowerMonitoringConsoleBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) {}
|
||||
public PowerMonitoringConsoleBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,14 +4,11 @@ using Content.Client.Computer;
|
||||
using Content.Shared.Solar;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Client.Power
|
||||
@@ -19,6 +16,7 @@ namespace Content.Client.Power
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class SolarControlWindow : DefaultWindow, IComputerWindow<SolarControlConsoleBoundInterfaceState>
|
||||
{
|
||||
[ViewVariables]
|
||||
private SolarControlConsoleBoundInterfaceState _lastState = new(0, 0, 0, 0);
|
||||
|
||||
public SolarControlWindow()
|
||||
@@ -28,9 +26,10 @@ namespace Content.Client.Power
|
||||
|
||||
public void SetupComputerWindow(ComputerBoundUserInterfaceBase cb)
|
||||
{
|
||||
PanelRotation.OnTextEntered += text => {
|
||||
double value;
|
||||
if (!double.TryParse((string?) text.Text, out value)) return;
|
||||
PanelRotation.OnTextEntered += text =>
|
||||
{
|
||||
if (!double.TryParse((string?) text.Text, out var value))
|
||||
return;
|
||||
|
||||
SolarControlConsoleAdjustMessage msg = new()
|
||||
{
|
||||
@@ -43,9 +42,11 @@ namespace Content.Client.Power
|
||||
_lastState.Rotation = msg.Rotation;
|
||||
NotARadar.UpdateState(_lastState);
|
||||
};
|
||||
PanelVelocity.OnTextEntered += text => {
|
||||
double value;
|
||||
if (!double.TryParse((string?) text.Text, out value)) return;
|
||||
|
||||
PanelVelocity.OnTextEntered += text =>
|
||||
{
|
||||
if (!double.TryParse((string?) text.Text, out var value))
|
||||
return;
|
||||
|
||||
SolarControlConsoleAdjustMessage msg = new()
|
||||
{
|
||||
@@ -61,14 +62,14 @@ namespace Content.Client.Power
|
||||
};
|
||||
}
|
||||
|
||||
private string FormatAngle(Angle d)
|
||||
private static string FormatAngle(Angle d)
|
||||
{
|
||||
return d.Degrees.ToString("F1");
|
||||
}
|
||||
|
||||
// The idea behind this is to prevent every update from the server
|
||||
// breaking the textfield.
|
||||
private void UpdateField(LineEdit field, string newValue)
|
||||
private static void UpdateField(LineEdit field, string newValue)
|
||||
{
|
||||
if (!field.HasKeyboardFocus())
|
||||
{
|
||||
@@ -92,7 +93,7 @@ namespace Content.Client.Power
|
||||
{
|
||||
// This is used for client-side prediction of the panel rotation.
|
||||
// This makes the display feel a lot smoother.
|
||||
private IGameTiming _gameTiming = IoCManager.Resolve<IGameTiming>();
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
|
||||
private SolarControlConsoleBoundInterfaceState _lastState = new(0, 0, 0, 0);
|
||||
|
||||
@@ -105,6 +106,7 @@ namespace Content.Client.Power
|
||||
|
||||
public SolarControlNotARadar()
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
MinSize = new Vector2(SizeFull, SizeFull);
|
||||
}
|
||||
|
||||
@@ -114,7 +116,7 @@ namespace Content.Client.Power
|
||||
_lastStateTime = _gameTiming.CurTime;
|
||||
}
|
||||
|
||||
public Angle PredictedPanelRotation => _lastState.Rotation + (_lastState.AngularVelocity * ((_gameTiming.CurTime - _lastStateTime).TotalSeconds));
|
||||
public Angle PredictedPanelRotation => _lastState.Rotation + _lastState.AngularVelocity * (_gameTiming.CurTime - _lastStateTime).TotalSeconds;
|
||||
|
||||
protected override void Draw(DrawingHandleScreen handle)
|
||||
{
|
||||
@@ -137,7 +139,7 @@ namespace Content.Client.Power
|
||||
|
||||
for (var i = 0; i < gridLinesRadial; i++)
|
||||
{
|
||||
Angle angle = (Math.PI / gridLinesRadial) * i;
|
||||
Angle angle = Math.PI / gridLinesRadial * i;
|
||||
var aExtent = angle.ToVec() * RadiusCircle;
|
||||
handle.DrawLine(new Vector2(point, point) - aExtent, new Vector2(point, point) + aExtent, gridLines);
|
||||
}
|
||||
@@ -162,6 +164,8 @@ namespace Content.Client.Power
|
||||
[UsedImplicitly]
|
||||
public sealed class SolarControlConsoleBoundUserInterface : ComputerBoundUserInterface<SolarControlWindow, SolarControlConsoleBoundInterfaceState>
|
||||
{
|
||||
public SolarControlConsoleBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) {}
|
||||
public SolarControlConsoleBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user