* Added atmos sprites from CEV-Eris * Moved canister sprites to appropriate dir * Removed unnecessary sprites, edited canisters prototype * Created Gas Canister UI and release pressure buttons * Changed GasMixture's pressure calculation (convert liters to cube meters) * Added relabeling Canisters * Reverted changes on GasMixture * Changed my name in the credits * Added valve opening on canisters * Change canister visual state when connected to a port * Added nullable to SharedGasCanisterComponent * Replaced nullable contexts * Changed again nullable annotation context * Moved name in the credits to correct alphabetical order * Canisters: Fix the most blatant issues with this PR (the added project interdependencies for no reason whatsoever) * Canisters: Stop crashes when canisters leave atmosphere * Canisters: Gas released into no atmosphere gets transferred "into space" (deleted) * Atmos: Nullability annotations on TileAtmosphere, explaination of the states of TileAtmosphere.Air * Canisters: If in an airblocked tile, do NOT release gas * Scrubbers: Fix typo leading to them not connecting properly. * Revert manual changes to credits file (sorry!) (1/2) This reverts commit 94f3b0e5df8d9c2fa189866a17a231920f99bdaf. * Revert manual changes to credits file (sorry!) (2/2) This reverts commit 1986fb094dfaa44060f08d280f36b755258d17a6. * Canisters: Apply @Zumorica 's reviews * Canisters: Add missing localization as suggested by PJB Co-authored-by: Pieter-Jan Briers <pieterjan.briers@gmail.com> * Canisters: Pressure lights! * Canisters: Light is now unshaded. * Canisters: Now using IActivate * Gas canisters (& air canister), now with their numbers properly calibrated (hopefully) * Canisters: Refactor how their layers are added to be more like ApcVisualizer * Canisters: Clean up of the tile invalidation/air release logic * Canisters: Some gas canister window improvements * Canisters: Clean up release pressure change button label code Co-authored-by: Clement-O <topy72.mine@gmail.com> Co-authored-by: Clément <clement.orlandini@gmail.com> Co-authored-by: Pieter-Jan Briers <pieterjan.briers@gmail.com>
This commit is contained in:
@@ -0,0 +1,115 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects.Components.UserInterface;
|
||||
using Robust.Shared.GameObjects.Components.UserInterface;
|
||||
using Content.Client.GameObjects.Components.Atmos;
|
||||
using Content.Shared.GameObjects.Components.Atmos;
|
||||
using Robust.Shared.Localization;
|
||||
|
||||
namespace Content.Client.GameObjects.Components.Atmos
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a <see cref="GasCanisterWindow"/> and updates it when new server messages are received.
|
||||
/// </summary>
|
||||
[UsedImplicitly]
|
||||
public class GasCanisterBoundUserInterface : BoundUserInterface
|
||||
{
|
||||
|
||||
private GasCanisterWindow? _window;
|
||||
|
||||
public GasCanisterBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// When a button is pressed, send a network message to the server
|
||||
/// </summary>
|
||||
/// <param name="button">Which button has been pressed, as an enum item</param>
|
||||
private void ButtonPressed(UiButton button)
|
||||
{
|
||||
SendMessage(new UiButtonPressedMessage(button));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// When the release pressure is changed
|
||||
/// </summary>
|
||||
/// <param name="value">The pressure value</param>
|
||||
private void ReleasePressureButtonPressed(float value)
|
||||
{
|
||||
SendMessage(new ReleasePressureButtonPressedMessage(value));
|
||||
}
|
||||
|
||||
|
||||
protected override void Open()
|
||||
{
|
||||
base.Open();
|
||||
|
||||
_window = new GasCanisterWindow();
|
||||
_window.Title = Loc.GetString("Gas Canister");
|
||||
|
||||
_window.OpenCentered();
|
||||
_window.OnClose += Close;
|
||||
|
||||
// Bind buttons OnPressed event
|
||||
foreach (ReleasePressureButton btn in _window.ReleasePressureButtons)
|
||||
{
|
||||
btn.OnPressed += _ => ReleasePressureButtonPressed(btn.PressureChange);
|
||||
}
|
||||
|
||||
// Bind events
|
||||
_window.EditLabelBtn.OnPressed += _ => EditLabel();
|
||||
_window.ToggleValve.OnPressed += _ => ToggleValve();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Called when the edit label button is pressed
|
||||
/// </summary>
|
||||
private void EditLabel()
|
||||
{
|
||||
// Obligatory check because bool isn't nullable
|
||||
if (_window == null) return;
|
||||
|
||||
if (_window.LabelInputEditable)
|
||||
{
|
||||
if (_window.LabelInput.Text != _window.OldLabel)
|
||||
SendMessage(new CanisterLabelChangedMessage(_window.LabelInput.Text));
|
||||
|
||||
_window.LabelInputEditable = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
_window.LabelInputEditable = true;
|
||||
_window.LabelInput.HasKeyboardFocus();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void ToggleValve()
|
||||
{
|
||||
SendMessage(new UiButtonPressedMessage(UiButton.ValveToggle));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Update the UI state based on server-sent info
|
||||
/// </summary>
|
||||
/// <param name="state"></param>
|
||||
protected override void UpdateState(BoundUserInterfaceState state)
|
||||
{
|
||||
base.UpdateState(state);
|
||||
|
||||
if (!(state is GasCanisterBoundUserInterfaceState cast))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_window?.UpdateState(cast);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
using Content.Shared.GameObjects.Components.Atmos;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.Interfaces.GameObjects.Components;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Utility;
|
||||
using YamlDotNet.RepresentationModel;
|
||||
|
||||
namespace Content.Client.GameObjects.Components.Atmos
|
||||
{
|
||||
public class GasCanisterVisualizer : AppearanceVisualizer
|
||||
{
|
||||
private string _stateConnected;
|
||||
private string[] _statePressure = new string[] {"", "", "", ""};
|
||||
|
||||
public override void LoadData(YamlMappingNode node)
|
||||
{
|
||||
base.LoadData(node);
|
||||
|
||||
_stateConnected = node.GetNode("stateConnected").AsString();
|
||||
for (int i = 0; i < _statePressure.Length; i++)
|
||||
_statePressure[i] = node.GetNode("stateO" + i).AsString();
|
||||
}
|
||||
|
||||
public override void InitializeEntity(IEntity entity)
|
||||
{
|
||||
base.InitializeEntity(entity);
|
||||
|
||||
var sprite = entity.GetComponent<ISpriteComponent>();
|
||||
|
||||
sprite.LayerMapSet(Layers.ConnectedToPort, sprite.AddLayerState(_stateConnected));
|
||||
sprite.LayerSetVisible(Layers.ConnectedToPort, false);
|
||||
|
||||
sprite.LayerMapSet(Layers.PressureLight, sprite.AddLayerState(_stateConnected));
|
||||
sprite.LayerSetShader(Layers.PressureLight, "unshaded");
|
||||
}
|
||||
|
||||
public override void OnChangeData(AppearanceComponent component)
|
||||
{
|
||||
base.OnChangeData(component);
|
||||
|
||||
if (component.Deleted)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!component.Owner.TryGetComponent(out ISpriteComponent sprite))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Update the visuals : Is the canister connected to a port or not
|
||||
if (component.TryGetData(GasCanisterVisuals.ConnectedState, out bool isConnected))
|
||||
{
|
||||
sprite.LayerSetVisible(Layers.ConnectedToPort, isConnected);
|
||||
}
|
||||
|
||||
// Update the visuals : Canister lights
|
||||
if (component.TryGetData(GasCanisterVisuals.PressureState, out int pressureState))
|
||||
if ((pressureState >= 0) && (pressureState < _statePressure.Length))
|
||||
sprite.LayerSetState(Layers.PressureLight, _statePressure[pressureState]);
|
||||
}
|
||||
|
||||
enum Layers
|
||||
{
|
||||
ConnectedToPort,
|
||||
PressureLight
|
||||
}
|
||||
}
|
||||
}
|
||||
166
Content.Client/GameObjects/Components/Atmos/GasCanisterWindow.cs
Normal file
166
Content.Client/GameObjects/Components/Atmos/GasCanisterWindow.cs
Normal file
@@ -0,0 +1,166 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Shared.GameObjects.Components.Disposal;
|
||||
using Robust.Client.Graphics.Drawing;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Maths;
|
||||
using Content.Client.GameObjects.Components.Atmos;
|
||||
using Content.Shared.GameObjects.Components.Atmos;
|
||||
|
||||
namespace Content.Client.GameObjects.Components.Atmos
|
||||
{
|
||||
/// <summary>
|
||||
/// Client-side UI used to control a <see cref="SharedGasCanisterComponent"/>
|
||||
/// </summary>
|
||||
public class GasCanisterWindow : SS14Window
|
||||
{
|
||||
private readonly Label _pressure;
|
||||
private readonly Label _releasePressure;
|
||||
|
||||
public readonly CheckButton ToggleValve;
|
||||
public readonly LineEdit LabelInput;
|
||||
public readonly Button EditLabelBtn;
|
||||
public string OldLabel { get; set; } = "";
|
||||
|
||||
public bool LabelInputEditable {
|
||||
get => LabelInput.Editable;
|
||||
set {
|
||||
LabelInput.Editable = value;
|
||||
EditLabelBtn.Text = value ? Loc.GetString("OK") : Loc.GetString("Edit");
|
||||
}
|
||||
}
|
||||
|
||||
public List<ReleasePressureButton> ReleasePressureButtons { get; private set; }
|
||||
|
||||
protected override Vector2? CustomSize => (300, 200);
|
||||
|
||||
public GasCanisterWindow()
|
||||
{
|
||||
HBoxContainer releasePressureButtons;
|
||||
|
||||
Contents.AddChild(new VBoxContainer
|
||||
{
|
||||
Children =
|
||||
{
|
||||
new VBoxContainer
|
||||
{
|
||||
Children =
|
||||
{
|
||||
new HBoxContainer()
|
||||
{
|
||||
Children =
|
||||
{
|
||||
new Label(){ Text = Loc.GetString("Label") },
|
||||
(LabelInput = new LineEdit() { Text = Name, Editable = false,
|
||||
CustomMinimumSize = new Vector2(200, 30)}),
|
||||
(EditLabelBtn = new Button()),
|
||||
}
|
||||
},
|
||||
new HBoxContainer
|
||||
{
|
||||
Children =
|
||||
{
|
||||
new Label {Text = Loc.GetString("Pressure:")},
|
||||
(_pressure = new Label())
|
||||
}
|
||||
},
|
||||
new VBoxContainer()
|
||||
{
|
||||
Children =
|
||||
{
|
||||
new HBoxContainer()
|
||||
{
|
||||
Children =
|
||||
{
|
||||
new Label() {Text = Loc.GetString("Release pressure:")},
|
||||
(_releasePressure = new Label())
|
||||
}
|
||||
},
|
||||
(releasePressureButtons = new HBoxContainer()
|
||||
{
|
||||
Children =
|
||||
{
|
||||
new ReleasePressureButton() {PressureChange = -50},
|
||||
new ReleasePressureButton() {PressureChange = -10},
|
||||
new ReleasePressureButton() {PressureChange = -1},
|
||||
new ReleasePressureButton() {PressureChange = -0.1f},
|
||||
new ReleasePressureButton() {PressureChange = 0.1f},
|
||||
new ReleasePressureButton() {PressureChange = 1},
|
||||
new ReleasePressureButton() {PressureChange = 10},
|
||||
new ReleasePressureButton() {PressureChange = 50}
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
new HBoxContainer()
|
||||
{
|
||||
Children =
|
||||
{
|
||||
new Label { Text = Loc.GetString("Valve") },
|
||||
(ToggleValve = new CheckButton() { Text = Loc.GetString("Open") })
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Create the release pressure buttons list
|
||||
ReleasePressureButtons = new List<ReleasePressureButton>();
|
||||
foreach (var control in releasePressureButtons.Children.ToList())
|
||||
{
|
||||
var btn = (ReleasePressureButton) control;
|
||||
ReleasePressureButtons.Add(btn);
|
||||
}
|
||||
|
||||
// Reset the editable label
|
||||
LabelInputEditable = false;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Update the UI based on <see cref="GasCanisterBoundUserInterfaceState"/>
|
||||
/// </summary>
|
||||
/// <param name="state">The state the UI should reflect</param>
|
||||
public void UpdateState(GasCanisterBoundUserInterfaceState state)
|
||||
{
|
||||
_pressure.Text = Loc.GetString("{0}kPa", state.Volume);
|
||||
_releasePressure.Text = Loc.GetString("{0}kPa", state.ReleasePressure);
|
||||
|
||||
// Update the canister label
|
||||
OldLabel = LabelInput.Text;
|
||||
LabelInput.Text = state.Label;
|
||||
Title = state.Label;
|
||||
|
||||
// Reset the editable label
|
||||
LabelInputEditable = false;
|
||||
|
||||
ToggleValve.Pressed = state.ValveOpened;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Special button class which stores a numerical value and has it as a label
|
||||
/// </summary>
|
||||
public class ReleasePressureButton : Button
|
||||
{
|
||||
public float PressureChange
|
||||
{
|
||||
get { return _pressureChange; }
|
||||
set
|
||||
{
|
||||
_pressureChange = value;
|
||||
Text = (value >= 0) ? ("+" + value) : value.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
private float _pressureChange;
|
||||
|
||||
public ReleasePressureButton() : base() {}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user