Wires! (#315)
* Wires! * Use state instead of messages * cleanup * Update submodule * actually fix conflict * Maybe fix conflicts? * Localized strings, removed hardcoded sprite path * cleanup * More localization and sounds
This commit is contained in:
committed by
Pieter-Jan Briers
parent
70e3cffa90
commit
264a63b7f6
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using Robust.Client.GameObjects.Components.UserInterface;
|
||||
using Robust.Shared.GameObjects.Components.UserInterface;
|
||||
using static Content.Shared.GameObjects.Components.SharedWiresComponent;
|
||||
|
||||
namespace Content.Client.GameObjects.Components.Wires
|
||||
{
|
||||
public class WiresBoundUserInterface : BoundUserInterface
|
||||
{
|
||||
public WiresBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey)
|
||||
{
|
||||
}
|
||||
|
||||
private WiresMenu _menu;
|
||||
|
||||
protected override void Open()
|
||||
{
|
||||
base.Open();
|
||||
_menu = new WiresMenu() {Owner = this};
|
||||
|
||||
_menu.OnClose += Close;
|
||||
_menu.OpenCentered();
|
||||
}
|
||||
|
||||
protected override void UpdateState(BoundUserInterfaceState state)
|
||||
{
|
||||
base.UpdateState(state);
|
||||
var castState = (WiresBoundUserInterfaceState) state;
|
||||
_menu.Populate(castState.WiresList);
|
||||
}
|
||||
|
||||
public void PerformAction(Guid guid, WiresAction action)
|
||||
{
|
||||
SendMessage(new WiresActionMessage(guid, action));
|
||||
}
|
||||
}
|
||||
}
|
||||
60
Content.Client/GameObjects/Components/Wires/WiresMenu.cs
Normal file
60
Content.Client/GameObjects/Components/Wires/WiresMenu.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using System.Collections.Generic;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Maths;
|
||||
using static Content.Shared.GameObjects.Components.SharedWiresComponent;
|
||||
|
||||
namespace Content.Client.GameObjects.Components.Wires
|
||||
{
|
||||
public class WiresMenu : SS14Window
|
||||
{
|
||||
#pragma warning disable 649
|
||||
[Dependency] private readonly ILocalizationManager _localizationManager;
|
||||
#pragma warning restore 649
|
||||
protected override Vector2? CustomSize => (300, 450);
|
||||
public WiresBoundUserInterface Owner { get; set; }
|
||||
|
||||
private readonly VBoxContainer _rows;
|
||||
|
||||
public WiresMenu()
|
||||
{
|
||||
IoCManager.InjectDependencies(this); // TODO: Remove this and use DynamicTypeFactory?
|
||||
Title = _localizationManager.GetString("Wires");
|
||||
_rows = new VBoxContainer();
|
||||
Contents.AddChild(_rows);
|
||||
}
|
||||
|
||||
public void Populate(List<ClientWire> wiresList)
|
||||
{
|
||||
_rows.RemoveAllChildren();
|
||||
foreach (var entry in wiresList)
|
||||
{
|
||||
var container = new HBoxContainer();
|
||||
var newLabel = new Label()
|
||||
{
|
||||
Text = $"{_localizationManager.GetString(entry.Color.Name())}: ",
|
||||
FontColorOverride = entry.Color,
|
||||
};
|
||||
container.AddChild(newLabel);
|
||||
|
||||
var newButton = new Button()
|
||||
{
|
||||
Text = _localizationManager.GetString("Pulse"),
|
||||
};
|
||||
newButton.OnPressed += _ => Owner.PerformAction(entry.Guid, WiresAction.Pulse);
|
||||
container.AddChild(newButton);
|
||||
|
||||
newButton = new Button()
|
||||
{
|
||||
Text = entry.IsCut ? _localizationManager.GetString("Mend") : _localizationManager.GetString("Cut"),
|
||||
};
|
||||
newButton.OnPressed += _ => Owner.PerformAction(entry.Guid, entry.IsCut ? WiresAction.Mend : WiresAction.Cut);
|
||||
container.AddChild(newButton);
|
||||
_rows.AddChild(container);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Interfaces.GameObjects.Components;
|
||||
using static Content.Shared.GameObjects.Components.SharedWiresComponent;
|
||||
|
||||
namespace Content.Client.GameObjects.Components.Wires
|
||||
{
|
||||
public class WiresVisualizer2D : AppearanceVisualizer
|
||||
{
|
||||
public override void OnChangeData(AppearanceComponent component)
|
||||
{
|
||||
base.OnChangeData(component);
|
||||
|
||||
var sprite = component.Owner.GetComponent<ISpriteComponent>();
|
||||
if (component.TryGetData<bool>(WiresVisuals.MaintenancePanelState, out var state))
|
||||
{
|
||||
sprite.LayerSetVisible(WiresVisualLayers.MaintenancePanel, state);
|
||||
}
|
||||
}
|
||||
|
||||
public enum WiresVisualLayers
|
||||
{
|
||||
MaintenancePanel,
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user