diff --git a/.github/workflows/build-map-renderer.yml b/.github/workflows/build-map-renderer.yml index 35aed1a7f7f500..398baddd843f26 100644 --- a/.github/workflows/build-map-renderer.yml +++ b/.github/workflows/build-map-renderer.yml @@ -2,11 +2,11 @@ on: push: - branches: [ master, staging, trying ] + branches: [ master, staging, stable ] merge_group: pull_request: types: [ opened, reopened, synchronize, ready_for_review ] - branches: [ master ] + branches: [ master, staging, stable ] jobs: build: diff --git a/.github/workflows/build-test-debug.yml b/.github/workflows/build-test-debug.yml index 47f9fd1a514e62..8f50c621d82ad8 100644 --- a/.github/workflows/build-test-debug.yml +++ b/.github/workflows/build-test-debug.yml @@ -2,11 +2,11 @@ name: Build & Test Debug on: push: - branches: [ master, staging, trying ] + branches: [ master, staging, stable ] merge_group: pull_request: types: [ opened, reopened, synchronize, ready_for_review ] - branches: [ master ] + branches: [ master, staging, stable ] jobs: build: diff --git a/.github/workflows/labeler-size.yml b/.github/workflows/labeler-size.yml index ad6e35c829291a..50f89c9bc870f0 100644 --- a/.github/workflows/labeler-size.yml +++ b/.github/workflows/labeler-size.yml @@ -14,7 +14,7 @@ jobs: { "0": "XS", "10": "S", - "30": "M", - "100": "L", - "1000": "XL" + "100": "M", + "1000": "L", + "5000": "XL" } diff --git a/.github/workflows/test-packaging.yml b/.github/workflows/test-packaging.yml index 2d002f869a169d..bddacb9fa4e5d3 100644 --- a/.github/workflows/test-packaging.yml +++ b/.github/workflows/test-packaging.yml @@ -2,7 +2,7 @@ on: push: - branches: [ master, staging, trying ] + branches: [ master, staging, stable ] paths: - '**.cs' - '**.csproj' @@ -16,7 +16,7 @@ on: merge_group: pull_request: types: [ opened, reopened, synchronize, ready_for_review ] - branches: [ master ] + branches: [ master, staging, stable ] paths: - '**.cs' - '**.csproj' diff --git a/.github/workflows/validate-rgas.yml b/.github/workflows/validate-rgas.yml index 2c4bb40fdf35e0..25191958a8c3ac 100644 --- a/.github/workflows/validate-rgas.yml +++ b/.github/workflows/validate-rgas.yml @@ -1,7 +1,7 @@ name: RGA schema validator on: push: - branches: [ master, staging, trying ] + branches: [ master, staging, stable ] merge_group: pull_request: types: [ opened, reopened, synchronize, ready_for_review ] diff --git a/.github/workflows/validate-rsis.yml b/.github/workflows/validate-rsis.yml index b76df28e6afff0..5d30944c73f6eb 100644 --- a/.github/workflows/validate-rsis.yml +++ b/.github/workflows/validate-rsis.yml @@ -2,7 +2,7 @@ name: RSI Validator on: push: - branches: [ staging, trying ] + branches: [ master, staging, stable ] merge_group: pull_request: paths: diff --git a/.github/workflows/validate_mapfiles.yml b/.github/workflows/validate_mapfiles.yml index fb11e1a4697d88..aaf1edcc289572 100644 --- a/.github/workflows/validate_mapfiles.yml +++ b/.github/workflows/validate_mapfiles.yml @@ -1,7 +1,7 @@ name: Map file schema validator on: push: - branches: [ master, staging, trying ] + branches: [ master, staging, stable ] merge_group: pull_request: types: [ opened, reopened, synchronize, ready_for_review ] diff --git a/.github/workflows/yaml-linter.yml b/.github/workflows/yaml-linter.yml index 691eb29f1de426..0b6e934cb594fd 100644 --- a/.github/workflows/yaml-linter.yml +++ b/.github/workflows/yaml-linter.yml @@ -2,7 +2,7 @@ name: YAML Linter on: push: - branches: [ master, staging, trying ] + branches: [ master, staging, stable ] merge_group: pull_request: types: [ opened, reopened, synchronize, ready_for_review ] diff --git a/Content.Client/Atmos/Consoles/AtmosAlarmEntryContainer.xaml.cs b/Content.Client/Atmos/Consoles/AtmosAlarmEntryContainer.xaml.cs index e533ef2dce0a2a..f0e4b13356c352 100644 --- a/Content.Client/Atmos/Consoles/AtmosAlarmEntryContainer.xaml.cs +++ b/Content.Client/Atmos/Consoles/AtmosAlarmEntryContainer.xaml.cs @@ -31,19 +31,6 @@ public sealed partial class AtmosAlarmEntryContainer : BoxContainer [AtmosAlarmType.Danger] = "atmos-alerts-window-danger-state", }; - private Dictionary _gasShorthands = new Dictionary() - { - [Gas.Ammonia] = "NH₃", - [Gas.CarbonDioxide] = "CO₂", - [Gas.Frezon] = "F", - [Gas.Nitrogen] = "N₂", - [Gas.NitrousOxide] = "N₂O", - [Gas.Oxygen] = "O₂", - [Gas.Plasma] = "P", - [Gas.Tritium] = "T", - [Gas.WaterVapor] = "H₂O", - }; - public AtmosAlarmEntryContainer(NetEntity uid, EntityCoordinates? coordinates) { RobustXamlLoader.Load(this); @@ -162,12 +149,11 @@ public void UpdateEntry(AtmosAlertsComputerEntry entry, bool isFocus, AtmosAlert foreach ((var gas, (var mol, var percent, var alert)) in keyValuePairs) { FixedPoint2 gasPercent = percent * 100f; - - var gasShorthand = _gasShorthands.GetValueOrDefault(gas, "X"); + var gasAbbreviation = Atmospherics.GasAbbreviations.GetValueOrDefault(gas, Loc.GetString("gas-unknown-abbreviation")); var gasLabel = new Label() { - Text = Loc.GetString("atmos-alerts-window-other-gases-value", ("shorthand", gasShorthand), ("value", gasPercent)), + Text = Loc.GetString("atmos-alerts-window-other-gases-value", ("shorthand", gasAbbreviation), ("value", gasPercent)), FontOverride = normalFont, FontColorOverride = GetAlarmStateColor(alert), HorizontalAlignment = HAlignment.Center, diff --git a/Content.Client/Atmos/Consoles/AtmosMonitoringConsoleBoundUserInterface.cs b/Content.Client/Atmos/Consoles/AtmosMonitoringConsoleBoundUserInterface.cs new file mode 100644 index 00000000000000..563122f962c6d0 --- /dev/null +++ b/Content.Client/Atmos/Consoles/AtmosMonitoringConsoleBoundUserInterface.cs @@ -0,0 +1,40 @@ +using Content.Shared.Atmos.Components; + +namespace Content.Client.Atmos.Consoles; + +public sealed class AtmosMonitoringConsoleBoundUserInterface : BoundUserInterface +{ + [ViewVariables] + private AtmosMonitoringConsoleWindow? _menu; + + public AtmosMonitoringConsoleBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { } + + protected override void Open() + { + base.Open(); + + _menu = new AtmosMonitoringConsoleWindow(this, Owner); + _menu.OpenCentered(); + _menu.OnClose += Close; + } + + protected override void UpdateState(BoundUserInterfaceState state) + { + base.UpdateState(state); + + if (state is not AtmosMonitoringConsoleBoundInterfaceState castState) + return; + + EntMan.TryGetComponent(Owner, out var xform); + _menu?.UpdateUI(xform?.Coordinates, castState.AtmosNetworks); + } + + protected override void Dispose(bool disposing) + { + base.Dispose(disposing); + if (!disposing) + return; + + _menu?.Dispose(); + } +} diff --git a/Content.Client/Atmos/Consoles/AtmosMonitoringConsoleNavMapControl.cs b/Content.Client/Atmos/Consoles/AtmosMonitoringConsoleNavMapControl.cs new file mode 100644 index 00000000000000..c23ebb64355874 --- /dev/null +++ b/Content.Client/Atmos/Consoles/AtmosMonitoringConsoleNavMapControl.cs @@ -0,0 +1,295 @@ +using Content.Client.Pinpointer.UI; +using Content.Shared.Atmos.Components; +using Content.Shared.Pinpointer; +using Robust.Client.Graphics; +using Robust.Shared.Collections; +using Robust.Shared.Map.Components; +using System.Linq; +using System.Numerics; + +namespace Content.Client.Atmos.Consoles; + +public sealed partial class AtmosMonitoringConsoleNavMapControl : NavMapControl +{ + [Dependency] private readonly IEntityManager _entManager = default!; + + public bool ShowPipeNetwork = true; + public int? FocusNetId = null; + + private const int ChunkSize = 4; + + private readonly Color _basePipeNetColor = Color.LightGray; + private readonly Color _unfocusedPipeNetColor = Color.DimGray; + + private List _atmosPipeNetwork = new(); + private Dictionary _sRGBLookUp = new Dictionary(); + + // Look up tables for merging continuous lines. Indexed by line color + private Dictionary> _horizLines = new(); + private Dictionary> _horizLinesReversed = new(); + private Dictionary> _vertLines = new(); + private Dictionary> _vertLinesReversed = new(); + + public AtmosMonitoringConsoleNavMapControl() : base() + { + PostWallDrawingAction += DrawAllPipeNetworks; + } + + protected override void UpdateNavMap() + { + base.UpdateNavMap(); + + if (!_entManager.TryGetComponent(Owner, out var console)) + return; + + if (!_entManager.TryGetComponent(MapUid, out var grid)) + return; + + _atmosPipeNetwork = GetDecodedAtmosPipeChunks(console.AtmosPipeChunks, grid); + } + + private void DrawAllPipeNetworks(DrawingHandleScreen handle) + { + if (!ShowPipeNetwork) + return; + + // Draw networks + if (_atmosPipeNetwork != null && _atmosPipeNetwork.Any()) + DrawPipeNetwork(handle, _atmosPipeNetwork); + } + + private void DrawPipeNetwork(DrawingHandleScreen handle, List atmosPipeNetwork) + { + var offset = GetOffset(); + offset = offset with { Y = -offset.Y }; + + if (WorldRange / WorldMaxRange > 0.5f) + { + var pipeNetworks = new Dictionary>(); + + foreach (var chunkedLine in atmosPipeNetwork) + { + var start = ScalePosition(chunkedLine.Origin - offset); + var end = ScalePosition(chunkedLine.Terminus - offset); + + if (!pipeNetworks.TryGetValue(chunkedLine.Color, out var subNetwork)) + subNetwork = new ValueList(); + + subNetwork.Add(start); + subNetwork.Add(end); + + pipeNetworks[chunkedLine.Color] = subNetwork; + } + + foreach ((var color, var subNetwork) in pipeNetworks) + { + if (subNetwork.Count > 0) + handle.DrawPrimitives(DrawPrimitiveTopology.LineList, subNetwork.Span, color); + } + } + + else + { + var pipeVertexUVs = new Dictionary>(); + + foreach (var chunkedLine in atmosPipeNetwork) + { + var leftTop = ScalePosition(new Vector2 + (Math.Min(chunkedLine.Origin.X, chunkedLine.Terminus.X) - 0.1f, + Math.Min(chunkedLine.Origin.Y, chunkedLine.Terminus.Y) - 0.1f) + - offset); + + var rightTop = ScalePosition(new Vector2 + (Math.Max(chunkedLine.Origin.X, chunkedLine.Terminus.X) + 0.1f, + Math.Min(chunkedLine.Origin.Y, chunkedLine.Terminus.Y) - 0.1f) + - offset); + + var leftBottom = ScalePosition(new Vector2 + (Math.Min(chunkedLine.Origin.X, chunkedLine.Terminus.X) - 0.1f, + Math.Max(chunkedLine.Origin.Y, chunkedLine.Terminus.Y) + 0.1f) + - offset); + + var rightBottom = ScalePosition(new Vector2 + (Math.Max(chunkedLine.Origin.X, chunkedLine.Terminus.X) + 0.1f, + Math.Max(chunkedLine.Origin.Y, chunkedLine.Terminus.Y) + 0.1f) + - offset); + + if (!pipeVertexUVs.TryGetValue(chunkedLine.Color, out var pipeVertexUV)) + pipeVertexUV = new ValueList(); + + pipeVertexUV.Add(leftBottom); + pipeVertexUV.Add(leftTop); + pipeVertexUV.Add(rightBottom); + pipeVertexUV.Add(leftTop); + pipeVertexUV.Add(rightBottom); + pipeVertexUV.Add(rightTop); + + pipeVertexUVs[chunkedLine.Color] = pipeVertexUV; + } + + foreach ((var color, var pipeVertexUV) in pipeVertexUVs) + { + if (pipeVertexUV.Count > 0) + handle.DrawPrimitives(DrawPrimitiveTopology.TriangleList, pipeVertexUV.Span, color); + } + } + } + + private List GetDecodedAtmosPipeChunks(Dictionary? chunks, MapGridComponent? grid) + { + var decodedOutput = new List(); + + if (chunks == null || grid == null) + return decodedOutput; + + // Clear stale look up table values + _horizLines.Clear(); + _horizLinesReversed.Clear(); + _vertLines.Clear(); + _vertLinesReversed.Clear(); + + // Generate masks + var northMask = (ulong)1 << 0; + var southMask = (ulong)1 << 1; + var westMask = (ulong)1 << 2; + var eastMask = (ulong)1 << 3; + + foreach ((var chunkOrigin, var chunk) in chunks) + { + var list = new List(); + + foreach (var ((netId, hexColor), atmosPipeData) in chunk.AtmosPipeData) + { + // Determine the correct coloration for the pipe + var color = Color.FromHex(hexColor) * _basePipeNetColor; + + if (FocusNetId != null && FocusNetId != netId) + color *= _unfocusedPipeNetColor; + + // Get the associated line look up tables + if (!_horizLines.TryGetValue(color, out var horizLines)) + { + horizLines = new(); + _horizLines[color] = horizLines; + } + + if (!_horizLinesReversed.TryGetValue(color, out var horizLinesReversed)) + { + horizLinesReversed = new(); + _horizLinesReversed[color] = horizLinesReversed; + } + + if (!_vertLines.TryGetValue(color, out var vertLines)) + { + vertLines = new(); + _vertLines[color] = vertLines; + } + + if (!_vertLinesReversed.TryGetValue(color, out var vertLinesReversed)) + { + vertLinesReversed = new(); + _vertLinesReversed[color] = vertLinesReversed; + } + + // Loop over the chunk + for (var tileIdx = 0; tileIdx < ChunkSize * ChunkSize; tileIdx++) + { + if (atmosPipeData == 0) + continue; + + var mask = (ulong)SharedNavMapSystem.AllDirMask << tileIdx * SharedNavMapSystem.Directions; + + if ((atmosPipeData & mask) == 0) + continue; + + var relativeTile = GetTileFromIndex(tileIdx); + var tile = (chunk.Origin * ChunkSize + relativeTile) * grid.TileSize; + tile = tile with { Y = -tile.Y }; + + // Calculate the draw point offsets + var vertLineOrigin = (atmosPipeData & northMask << tileIdx * SharedNavMapSystem.Directions) > 0 ? + new Vector2(grid.TileSize * 0.5f, -grid.TileSize * 1f) : new Vector2(grid.TileSize * 0.5f, -grid.TileSize * 0.5f); + + var vertLineTerminus = (atmosPipeData & southMask << tileIdx * SharedNavMapSystem.Directions) > 0 ? + new Vector2(grid.TileSize * 0.5f, -grid.TileSize * 0f) : new Vector2(grid.TileSize * 0.5f, -grid.TileSize * 0.5f); + + var horizLineOrigin = (atmosPipeData & eastMask << tileIdx * SharedNavMapSystem.Directions) > 0 ? + new Vector2(grid.TileSize * 1f, -grid.TileSize * 0.5f) : new Vector2(grid.TileSize * 0.5f, -grid.TileSize * 0.5f); + + var horizLineTerminus = (atmosPipeData & westMask << tileIdx * SharedNavMapSystem.Directions) > 0 ? + new Vector2(grid.TileSize * 0f, -grid.TileSize * 0.5f) : new Vector2(grid.TileSize * 0.5f, -grid.TileSize * 0.5f); + + // Since we can have pipe lines that have a length of a half tile, + // double the vectors and convert to vector2i so we can merge them + AddOrUpdateNavMapLine(ConvertVector2ToVector2i(tile + horizLineOrigin, 2), ConvertVector2ToVector2i(tile + horizLineTerminus, 2), horizLines, horizLinesReversed); + AddOrUpdateNavMapLine(ConvertVector2ToVector2i(tile + vertLineOrigin, 2), ConvertVector2ToVector2i(tile + vertLineTerminus, 2), vertLines, vertLinesReversed); + } + } + } + + // Scale the vector2is back down and convert to vector2 + foreach (var (color, horizLines) in _horizLines) + { + // Get the corresponding sRBG color + var sRGB = GetsRGBColor(color); + + foreach (var (origin, terminal) in horizLines) + decodedOutput.Add(new AtmosMonitoringConsoleLine + (ConvertVector2iToVector2(origin, 0.5f), ConvertVector2iToVector2(terminal, 0.5f), sRGB)); + } + + foreach (var (color, vertLines) in _vertLines) + { + // Get the corresponding sRBG color + var sRGB = GetsRGBColor(color); + + foreach (var (origin, terminal) in vertLines) + decodedOutput.Add(new AtmosMonitoringConsoleLine + (ConvertVector2iToVector2(origin, 0.5f), ConvertVector2iToVector2(terminal, 0.5f), sRGB)); + } + + return decodedOutput; + } + + private Vector2 ConvertVector2iToVector2(Vector2i vector, float scale = 1f) + { + return new Vector2(vector.X * scale, vector.Y * scale); + } + + private Vector2i ConvertVector2ToVector2i(Vector2 vector, float scale = 1f) + { + return new Vector2i((int)MathF.Round(vector.X * scale), (int)MathF.Round(vector.Y * scale)); + } + + private Vector2i GetTileFromIndex(int index) + { + var x = index / ChunkSize; + var y = index % ChunkSize; + return new Vector2i(x, y); + } + + private Color GetsRGBColor(Color color) + { + if (!_sRGBLookUp.TryGetValue(color, out var sRGB)) + { + sRGB = Color.ToSrgb(color); + _sRGBLookUp[color] = sRGB; + } + + return sRGB; + } +} + +public struct AtmosMonitoringConsoleLine +{ + public readonly Vector2 Origin; + public readonly Vector2 Terminus; + public readonly Color Color; + + public AtmosMonitoringConsoleLine(Vector2 origin, Vector2 terminus, Color color) + { + Origin = origin; + Terminus = terminus; + Color = color; + } +} diff --git a/Content.Client/Atmos/Consoles/AtmosMonitoringConsoleSystem.cs b/Content.Client/Atmos/Consoles/AtmosMonitoringConsoleSystem.cs new file mode 100644 index 00000000000000..bfbb05d2ab150e --- /dev/null +++ b/Content.Client/Atmos/Consoles/AtmosMonitoringConsoleSystem.cs @@ -0,0 +1,69 @@ +using Content.Shared.Atmos.Components; +using Content.Shared.Atmos.Consoles; +using Robust.Shared.GameStates; + +namespace Content.Client.Atmos.Consoles; + +public sealed class AtmosMonitoringConsoleSystem : SharedAtmosMonitoringConsoleSystem +{ + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent(OnHandleState); + } + + private void OnHandleState(EntityUid uid, AtmosMonitoringConsoleComponent component, ref ComponentHandleState args) + { + Dictionary> modifiedChunks; + Dictionary atmosDevices; + + switch (args.Current) + { + case AtmosMonitoringConsoleDeltaState delta: + { + modifiedChunks = delta.ModifiedChunks; + atmosDevices = delta.AtmosDevices; + + foreach (var index in component.AtmosPipeChunks.Keys) + { + if (!delta.AllChunks!.Contains(index)) + component.AtmosPipeChunks.Remove(index); + } + + break; + } + + case AtmosMonitoringConsoleState state: + { + modifiedChunks = state.Chunks; + atmosDevices = state.AtmosDevices; + + foreach (var index in component.AtmosPipeChunks.Keys) + { + if (!state.Chunks.ContainsKey(index)) + component.AtmosPipeChunks.Remove(index); + } + + break; + } + default: + return; + } + + foreach (var (origin, chunk) in modifiedChunks) + { + var newChunk = new AtmosPipeChunk(origin); + newChunk.AtmosPipeData = new Dictionary<(int, string), ulong>(chunk); + + component.AtmosPipeChunks[origin] = newChunk; + } + + component.AtmosDevices.Clear(); + + foreach (var (nuid, atmosDevice) in atmosDevices) + { + component.AtmosDevices[nuid] = atmosDevice; + } + } +} diff --git a/Content.Client/Atmos/Consoles/AtmosMonitoringConsoleWindow.xaml b/Content.Client/Atmos/Consoles/AtmosMonitoringConsoleWindow.xaml new file mode 100644 index 00000000000000..b6fde7592fd6ea --- /dev/null +++ b/Content.Client/Atmos/Consoles/AtmosMonitoringConsoleWindow.xaml @@ -0,0 +1,99 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Content.Client/Atmos/Consoles/AtmosMonitoringConsoleWindow.xaml.cs b/Content.Client/Atmos/Consoles/AtmosMonitoringConsoleWindow.xaml.cs new file mode 100644 index 00000000000000..515f91790f493e --- /dev/null +++ b/Content.Client/Atmos/Consoles/AtmosMonitoringConsoleWindow.xaml.cs @@ -0,0 +1,455 @@ +using Content.Client.Pinpointer.UI; +using Content.Client.UserInterface.Controls; +using Content.Shared.Atmos.Components; +using Content.Shared.Prototypes; +using Robust.Client.AutoGenerated; +using Robust.Client.GameObjects; +using Robust.Client.UserInterface; +using Robust.Client.UserInterface.Controls; +using Robust.Client.UserInterface.XAML; +using Robust.Shared.Map; +using Robust.Shared.Prototypes; +using Robust.Shared.Timing; +using Robust.Shared.Utility; +using System.Diagnostics.CodeAnalysis; +using System.Linq; + +namespace Content.Client.Atmos.Consoles; + +[GenerateTypedNameReferences] +public sealed partial class AtmosMonitoringConsoleWindow : FancyWindow +{ + private readonly IEntityManager _entManager; + private readonly IPrototypeManager _protoManager; + private readonly SpriteSystem _spriteSystem; + + private EntityUid? _owner; + private NetEntity? _focusEntity; + private int? _focusNetId; + + private bool _autoScrollActive = false; + + private readonly Color _unfocusedDeviceColor = Color.DimGray; + private ProtoId _navMapConsoleProtoId = "NavMapConsole"; + private ProtoId _gasPipeSensorProtoId = "GasPipeSensor"; + + public AtmosMonitoringConsoleWindow(AtmosMonitoringConsoleBoundUserInterface userInterface, EntityUid? owner) + { + RobustXamlLoader.Load(this); + _entManager = IoCManager.Resolve(); + _protoManager = IoCManager.Resolve(); + _spriteSystem = _entManager.System(); + + // Pass the owner to nav map + _owner = owner; + NavMap.Owner = _owner; + + // Set nav map grid uid + var stationName = Loc.GetString("atmos-monitoring-window-unknown-location"); + EntityCoordinates? consoleCoords = null; + + if (_entManager.TryGetComponent(owner, out var xform)) + { + consoleCoords = xform.Coordinates; + NavMap.MapUid = xform.GridUid; + + // Assign station name + if (_entManager.TryGetComponent(xform.GridUid, out var stationMetaData)) + stationName = stationMetaData.EntityName; + + var msg = new FormattedMessage(); + msg.TryAddMarkup(Loc.GetString("atmos-monitoring-window-station-name", ("stationName", stationName)), out _); + + StationName.SetMessage(msg); + } + + else + { + StationName.SetMessage(stationName); + NavMap.Visible = false; + } + + // Set trackable entity selected action + NavMap.TrackedEntitySelectedAction += SetTrackedEntityFromNavMap; + + // Update nav map + NavMap.ForceNavMapUpdate(); + + // Set tab container headers + MasterTabContainer.SetTabTitle(0, Loc.GetString("atmos-monitoring-window-tab-networks")); + + // Set UI toggles + ShowPipeNetwork.OnToggled += _ => OnShowPipeNetworkToggled(); + ShowGasPipeSensors.OnToggled += _ => OnShowGasPipeSensors(); + + // Set nav map colors + if (!_entManager.TryGetComponent(_owner, out var console)) + return; + + NavMap.TileColor = console.NavMapTileColor; + NavMap.WallColor = console.NavMapWallColor; + + // Initalize + UpdateUI(consoleCoords, Array.Empty()); + } + + #region Toggle handling + + private void OnShowPipeNetworkToggled() + { + if (_owner == null) + return; + + if (!_entManager.TryGetComponent(_owner.Value, out var console)) + return; + + NavMap.ShowPipeNetwork = ShowPipeNetwork.Pressed; + + foreach (var (netEnt, device) in console.AtmosDevices) + { + if (device.NavMapBlip == _gasPipeSensorProtoId) + continue; + + if (ShowPipeNetwork.Pressed) + AddTrackedEntityToNavMap(device); + + else + NavMap.TrackedEntities.Remove(netEnt); + } + } + + private void OnShowGasPipeSensors() + { + if (_owner == null) + return; + + if (!_entManager.TryGetComponent(_owner.Value, out var console)) + return; + + foreach (var (netEnt, device) in console.AtmosDevices) + { + if (device.NavMapBlip != _gasPipeSensorProtoId) + continue; + + if (ShowGasPipeSensors.Pressed) + AddTrackedEntityToNavMap(device, true); + + else + NavMap.TrackedEntities.Remove(netEnt); + } + } + + #endregion + + public void UpdateUI + (EntityCoordinates? consoleCoords, + AtmosMonitoringConsoleEntry[] atmosNetworks) + { + if (_owner == null) + return; + + if (!_entManager.TryGetComponent(_owner.Value, out var console)) + return; + + // Reset nav map values + NavMap.TrackedCoordinates.Clear(); + NavMap.TrackedEntities.Clear(); + + if (_focusEntity != null && !console.AtmosDevices.Any(x => x.Key == _focusEntity)) + ClearFocus(); + + // Add tracked entities to the nav map + UpdateNavMapBlips(); + + // Show the monitor location + var consoleNetEnt = _entManager.GetNetEntity(_owner); + + if (consoleCoords != null && consoleNetEnt != null) + { + var proto = _protoManager.Index(_navMapConsoleProtoId); + + if (proto.TexturePaths != null && proto.TexturePaths.Length != 0) + { + var texture = _spriteSystem.Frame0(new SpriteSpecifier.Texture(proto.TexturePaths[0])); + var blip = new NavMapBlip(consoleCoords.Value, texture, proto.Color, proto.Blinks, proto.Selectable); + NavMap.TrackedEntities[consoleNetEnt.Value] = blip; + } + } + + // Update the nav map + NavMap.ForceNavMapUpdate(); + + // Clear excess children from the tables + while (AtmosNetworksTable.ChildCount > atmosNetworks.Length) + AtmosNetworksTable.RemoveChild(AtmosNetworksTable.GetChild(AtmosNetworksTable.ChildCount - 1)); + + // Update all entries in each table + for (int index = 0; index < atmosNetworks.Length; index++) + { + var entry = atmosNetworks.ElementAt(index); + UpdateUIEntry(entry, index, AtmosNetworksTable, console); + } + } + + private void UpdateNavMapBlips() + { + if (_owner == null || !_entManager.TryGetComponent(_owner.Value, out var console)) + return; + + if (NavMap.Visible) + { + foreach (var (netEnt, device) in console.AtmosDevices) + { + // Update the focus network ID, incase it has changed + if (_focusEntity == netEnt) + { + _focusNetId = device.NetId; + NavMap.FocusNetId = _focusNetId; + } + + var isSensor = device.NavMapBlip == _gasPipeSensorProtoId; + + // Skip network devices if the toggled is off + if (!ShowPipeNetwork.Pressed && !isSensor) + continue; + + // Skip gas pipe sensors if the toggle is off + if (!ShowGasPipeSensors.Pressed && isSensor) + continue; + + AddTrackedEntityToNavMap(device, isSensor); + } + } + } + + private void AddTrackedEntityToNavMap(AtmosDeviceNavMapData metaData, bool isSensor = false) + { + var proto = _protoManager.Index(metaData.NavMapBlip); + + if (proto.TexturePaths == null || proto.TexturePaths.Length == 0) + return; + + var idx = Math.Clamp((int)metaData.Direction / 2, 0, proto.TexturePaths.Length - 1); + var texture = proto.TexturePaths.Length > 0 ? proto.TexturePaths[idx] : proto.TexturePaths[0]; + var color = isSensor ? proto.Color : proto.Color * metaData.PipeColor; + + if (_focusNetId != null && metaData.NetId != _focusNetId) + color *= _unfocusedDeviceColor; + + var blinks = proto.Blinks || _focusEntity == metaData.NetEntity; + var coords = _entManager.GetCoordinates(metaData.NetCoordinates); + var blip = new NavMapBlip(coords, _spriteSystem.Frame0(new SpriteSpecifier.Texture(texture)), color, blinks, proto.Selectable, proto.Scale); + NavMap.TrackedEntities[metaData.NetEntity] = blip; + } + + private void UpdateUIEntry(AtmosMonitoringConsoleEntry data, int index, Control table, AtmosMonitoringConsoleComponent console) + { + // Make new UI entry if required + if (index >= table.ChildCount) + { + var newEntryContainer = new AtmosMonitoringEntryContainer(data); + + // On click + newEntryContainer.FocusButton.OnButtonUp += args => + { + if (_focusEntity == newEntryContainer.Data.NetEntity) + { + ClearFocus(); + } + + else + { + SetFocus(newEntryContainer.Data.NetEntity, newEntryContainer.Data.NetId); + + var coords = _entManager.GetCoordinates(newEntryContainer.Data.Coordinates); + NavMap.CenterToCoordinates(coords); + } + + // Update affected UI elements across all tables + UpdateConsoleTable(console, AtmosNetworksTable, _focusEntity); + }; + + // Add the entry to the current table + table.AddChild(newEntryContainer); + } + + // Update values and UI elements + var tableChild = table.GetChild(index); + + if (tableChild is not AtmosMonitoringEntryContainer) + { + table.RemoveChild(tableChild); + UpdateUIEntry(data, index, table, console); + + return; + } + + var entryContainer = (AtmosMonitoringEntryContainer)tableChild; + entryContainer.UpdateEntry(data, data.NetEntity == _focusEntity); + } + + private void UpdateConsoleTable(AtmosMonitoringConsoleComponent console, Control table, NetEntity? currTrackedEntity) + { + foreach (var tableChild in table.Children) + { + if (tableChild is not AtmosAlarmEntryContainer) + continue; + + var entryContainer = (AtmosAlarmEntryContainer)tableChild; + + if (entryContainer.NetEntity != currTrackedEntity) + entryContainer.RemoveAsFocus(); + + else if (entryContainer.NetEntity == currTrackedEntity) + entryContainer.SetAsFocus(); + } + } + + private void SetTrackedEntityFromNavMap(NetEntity? focusEntity) + { + if (focusEntity == null) + return; + + if (!_entManager.TryGetComponent(_owner, out var console)) + return; + + foreach (var (netEnt, device) in console.AtmosDevices) + { + if (netEnt != focusEntity) + continue; + + if (device.NavMapBlip != _gasPipeSensorProtoId) + return; + + // Set new focus + SetFocus(focusEntity.Value, device.NetId); + + // Get the scroll position of the selected entity on the selected button the UI + ActivateAutoScrollToFocus(); + + break; + } + } + + protected override void FrameUpdate(FrameEventArgs args) + { + AutoScrollToFocus(); + } + + private void ActivateAutoScrollToFocus() + { + _autoScrollActive = true; + } + + private void AutoScrollToFocus() + { + if (!_autoScrollActive) + return; + + var scroll = AtmosNetworksTable.Parent as ScrollContainer; + if (scroll == null) + return; + + if (!TryGetVerticalScrollbar(scroll, out var vScrollbar)) + return; + + if (!TryGetNextScrollPosition(out float? nextScrollPosition)) + return; + + vScrollbar.ValueTarget = nextScrollPosition.Value; + + if (MathHelper.CloseToPercent(vScrollbar.Value, vScrollbar.ValueTarget)) + _autoScrollActive = false; + } + + private bool TryGetVerticalScrollbar(ScrollContainer scroll, [NotNullWhen(true)] out VScrollBar? vScrollBar) + { + vScrollBar = null; + + foreach (var control in scroll.Children) + { + if (control is not VScrollBar) + continue; + + vScrollBar = (VScrollBar)control; + + return true; + } + + return false; + } + + private bool TryGetNextScrollPosition([NotNullWhen(true)] out float? nextScrollPosition) + { + nextScrollPosition = null; + + var scroll = AtmosNetworksTable.Parent as ScrollContainer; + if (scroll == null) + return false; + + var container = scroll.Children.ElementAt(0) as BoxContainer; + if (container == null || container.Children.Count() == 0) + return false; + + // Exit if the heights of the children haven't been initialized yet + if (!container.Children.Any(x => x.Height > 0)) + return false; + + nextScrollPosition = 0; + + foreach (var control in container.Children) + { + if (control is not AtmosMonitoringEntryContainer) + continue; + + var entry = (AtmosMonitoringEntryContainer)control; + + if (entry.Data.NetEntity == _focusEntity) + return true; + + nextScrollPosition += control.Height; + } + + // Failed to find control + nextScrollPosition = null; + + return false; + } + + private void SetFocus(NetEntity focusEntity, int focusNetId) + { + _focusEntity = focusEntity; + _focusNetId = focusNetId; + NavMap.FocusNetId = focusNetId; + + OnFocusChanged(); + } + + private void ClearFocus() + { + _focusEntity = null; + _focusNetId = null; + NavMap.FocusNetId = null; + + OnFocusChanged(); + } + + private void OnFocusChanged() + { + UpdateNavMapBlips(); + NavMap.ForceNavMapUpdate(); + + if (!_entManager.TryGetComponent(_owner, out var console)) + return; + + for (int index = 0; index < AtmosNetworksTable.ChildCount; index++) + { + var entry = (AtmosMonitoringEntryContainer)AtmosNetworksTable.GetChild(index); + + if (entry == null) + continue; + + UpdateUIEntry(entry.Data, index, AtmosNetworksTable, console); + } + } +} diff --git a/Content.Client/Atmos/Consoles/AtmosMonitoringEntryContainer.xaml b/Content.Client/Atmos/Consoles/AtmosMonitoringEntryContainer.xaml new file mode 100644 index 00000000000000..6a19f0775f96e5 --- /dev/null +++ b/Content.Client/Atmos/Consoles/AtmosMonitoringEntryContainer.xaml @@ -0,0 +1,74 @@ + + + + + diff --git a/Content.Client/Atmos/Consoles/AtmosMonitoringEntryContainer.xaml.cs b/Content.Client/Atmos/Consoles/AtmosMonitoringEntryContainer.xaml.cs new file mode 100644 index 00000000000000..0ce0c9c880a623 --- /dev/null +++ b/Content.Client/Atmos/Consoles/AtmosMonitoringEntryContainer.xaml.cs @@ -0,0 +1,166 @@ +using Content.Client.Stylesheets; +using Content.Shared.Atmos; +using Content.Shared.Atmos.Components; +using Content.Shared.FixedPoint; +using Content.Shared.Temperature; +using Robust.Client.AutoGenerated; +using Robust.Client.Graphics; +using Robust.Client.ResourceManagement; +using Robust.Client.UserInterface.Controls; +using Robust.Client.UserInterface.XAML; +using System.Linq; + +namespace Content.Client.Atmos.Consoles; + +[GenerateTypedNameReferences] +public sealed partial class AtmosMonitoringEntryContainer : BoxContainer +{ + public AtmosMonitoringConsoleEntry Data; + + private readonly IEntityManager _entManager; + private readonly IResourceCache _cache; + + public AtmosMonitoringEntryContainer(AtmosMonitoringConsoleEntry data) + { + RobustXamlLoader.Load(this); + _entManager = IoCManager.Resolve(); + _cache = IoCManager.Resolve(); + + Data = data; + + // Modulate colored stripe + NetworkColorStripe.Modulate = data.Color; + + // Load fonts + var headerFont = new VectorFont(_cache.GetResource("/Fonts/NotoSans/NotoSans-Bold.ttf"), 11); + var normalFont = new VectorFont(_cache.GetResource("/Fonts/NotoSansDisplay/NotoSansDisplay-Regular.ttf"), 11); + + // Set fonts + TemperatureHeaderLabel.FontOverride = headerFont; + PressureHeaderLabel.FontOverride = headerFont; + TotalMolHeaderLabel.FontOverride = headerFont; + GasesHeaderLabel.FontOverride = headerFont; + + TemperatureLabel.FontOverride = normalFont; + PressureLabel.FontOverride = normalFont; + TotalMolLabel.FontOverride = normalFont; + + NoDataLabel.FontOverride = headerFont; + } + + public void UpdateEntry(AtmosMonitoringConsoleEntry updatedData, bool isFocus) + { + // Load fonts + var normalFont = new VectorFont(_cache.GetResource("/Fonts/NotoSansDisplay/NotoSansDisplay-Regular.ttf"), 11); + + // Update name and values + if (!string.IsNullOrEmpty(updatedData.Address)) + NetworkNameLabel.Text = Loc.GetString("atmos-alerts-window-alarm-label", ("name", updatedData.EntityName), ("address", updatedData.Address)); + + else + NetworkNameLabel.Text = Loc.GetString(updatedData.EntityName); + + Data = updatedData; + + // Modulate colored stripe + NetworkColorStripe.Modulate = Data.Color; + + // Focus updates + if (isFocus) + SetAsFocus(); + else + RemoveAsFocus(); + + // Check if powered + if (!updatedData.IsPowered) + { + MainDataContainer.Visible = false; + NoDataLabel.Visible = true; + + return; + } + + // Set container visibility + MainDataContainer.Visible = true; + NoDataLabel.Visible = false; + + // Update temperature + var isNotVacuum = updatedData.TotalMolData > 1e-6f; + var tempK = (FixedPoint2)updatedData.TemperatureData; + var tempC = (FixedPoint2)TemperatureHelpers.KelvinToCelsius(tempK.Float()); + + TemperatureLabel.Text = isNotVacuum ? + Loc.GetString("atmos-alerts-window-temperature-value", ("valueInC", tempC), ("valueInK", tempK)) : + Loc.GetString("atmos-alerts-window-invalid-value"); + + TemperatureLabel.FontColorOverride = isNotVacuum ? Color.DarkGray : StyleNano.DisabledFore; + + // Update pressure + PressureLabel.Text = Loc.GetString("atmos-alerts-window-pressure-value", ("value", (FixedPoint2)updatedData.PressureData)); + PressureLabel.FontColorOverride = isNotVacuum ? Color.DarkGray : StyleNano.DisabledFore; + + // Update total mol + TotalMolLabel.Text = Loc.GetString("atmos-alerts-window-total-mol-value", ("value", (FixedPoint2)updatedData.TotalMolData)); + TotalMolLabel.FontColorOverride = isNotVacuum ? Color.DarkGray : StyleNano.DisabledFore; + + // Update other present gases + GasGridContainer.RemoveAllChildren(); + + if (updatedData.GasData.Count() == 0) + { + // No gases + var gasLabel = new Label() + { + Text = Loc.GetString("atmos-alerts-window-other-gases-value-nil"), + FontOverride = normalFont, + FontColorOverride = StyleNano.DisabledFore, + HorizontalAlignment = HAlignment.Center, + VerticalAlignment = VAlignment.Center, + HorizontalExpand = true, + Margin = new Thickness(0, 2, 0, 0), + SetHeight = 24f, + }; + + GasGridContainer.AddChild(gasLabel); + } + + else + { + // Add an entry for each gas + foreach (var (gas, percent) in updatedData.GasData) + { + var gasPercent = (FixedPoint2)0f; + gasPercent = percent * 100f; + + var gasAbbreviation = Atmospherics.GasAbbreviations.GetValueOrDefault(gas, Loc.GetString("gas-unknown-abbreviation")); + + var gasLabel = new Label() + { + Text = Loc.GetString("atmos-alerts-window-other-gases-value", ("shorthand", gasAbbreviation), ("value", gasPercent)), + FontOverride = normalFont, + HorizontalAlignment = HAlignment.Center, + VerticalAlignment = VAlignment.Center, + HorizontalExpand = true, + Margin = new Thickness(0, 2, 0, 0), + SetHeight = 24f, + }; + + GasGridContainer.AddChild(gasLabel); + } + } + } + + public void SetAsFocus() + { + FocusButton.AddStyleClass(StyleNano.StyleClassButtonColorGreen); + ArrowTexture.TexturePath = "/Textures/Interface/Nano/inverted_triangle.svg.png"; + FocusContainer.Visible = true; + } + + public void RemoveAsFocus() + { + FocusButton.RemoveStyleClass(StyleNano.StyleClassButtonColorGreen); + ArrowTexture.TexturePath = "/Textures/Interface/Nano/triangle_right.png"; + FocusContainer.Visible = false; + } +} diff --git a/Content.Client/Chat/UI/SpeechBubble.cs b/Content.Client/Chat/UI/SpeechBubble.cs index 32e9f4ae9be530..aa61e73e31c85a 100644 --- a/Content.Client/Chat/UI/SpeechBubble.cs +++ b/Content.Client/Chat/UI/SpeechBubble.cs @@ -2,6 +2,7 @@ using Content.Client.Chat.Managers; using Content.Shared.CCVar; using Content.Shared.Chat; +using Content.Shared.Speech; using Robust.Client.Graphics; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; @@ -141,7 +142,12 @@ protected override void FrameUpdate(FrameEventArgs args) Modulate = Color.White; } - var offset = (-_eyeManager.CurrentEye.Rotation).ToWorldVec() * -EntityVerticalOffset; + var baseOffset = 0f; + + if (_entityManager.TryGetComponent(_senderEntity, out var speech)) + baseOffset = speech.SpeechBubbleOffset; + + var offset = (-_eyeManager.CurrentEye.Rotation).ToWorldVec() * -(EntityVerticalOffset + baseOffset); var worldPos = _transformSystem.GetWorldPosition(xform) + offset; var lowerCenter = _eyeManager.WorldToScreen(worldPos) / UIScale; diff --git a/Content.Client/Chemistry/UI/ChemMasterWindow.xaml.cs b/Content.Client/Chemistry/UI/ChemMasterWindow.xaml.cs index 5eace08a7fdb28..20c61f10cb821a 100644 --- a/Content.Client/Chemistry/UI/ChemMasterWindow.xaml.cs +++ b/Content.Client/Chemistry/UI/ChemMasterWindow.xaml.cs @@ -12,6 +12,7 @@ using System.Linq; using System.Numerics; using Content.Shared.FixedPoint; +using Robust.Client.Graphics; using static Robust.Client.UserInterface.Controls.BoxContainer; namespace Content.Client.Chemistry.UI @@ -90,10 +91,40 @@ public ChemMasterWindow() private ReagentButton MakeReagentButton(string text, ChemMasterReagentAmount amount, ReagentId id, bool isBuffer, string styleClass) { - var button = new ReagentButton(text, amount, id, isBuffer, styleClass); - button.OnPressed += args - => OnReagentButtonPressed?.Invoke(args, button); - return button; + var reagentTransferButton = new ReagentButton(text, amount, id, isBuffer, styleClass); + reagentTransferButton.OnPressed += args + => OnReagentButtonPressed?.Invoke(args, reagentTransferButton); + return reagentTransferButton; + } + /// + /// Conditionally generates a set of reagent buttons based on the supplied boolean argument. + /// This was moved outside of BuildReagentRow to facilitate conditional logic, stops indentation depth getting out of hand as well. + /// + private List CreateReagentTransferButtons(ReagentId reagent, bool isBuffer, bool addReagentButtons) + { + if (!addReagentButtons) + return new List(); // Return an empty list if reagentTransferButton creation is disabled. + + var buttonConfigs = new (string text, ChemMasterReagentAmount amount, string styleClass)[] + { + ("1", ChemMasterReagentAmount.U1, StyleBase.ButtonOpenBoth), + ("5", ChemMasterReagentAmount.U5, StyleBase.ButtonOpenBoth), + ("10", ChemMasterReagentAmount.U10, StyleBase.ButtonOpenBoth), + ("25", ChemMasterReagentAmount.U25, StyleBase.ButtonOpenBoth), + ("50", ChemMasterReagentAmount.U50, StyleBase.ButtonOpenBoth), + ("100", ChemMasterReagentAmount.U100, StyleBase.ButtonOpenBoth), + (Loc.GetString("chem-master-window-buffer-all-amount"), ChemMasterReagentAmount.All, StyleBase.ButtonOpenLeft), + }; + + var buttons = new List(); + + foreach (var (text, amount, styleClass) in buttonConfigs) + { + var reagentTransferButton = MakeReagentButton(text, amount, reagent, isBuffer, styleClass); + buttons.Add(reagentTransferButton); + } + + return buttons; } /// @@ -102,25 +133,36 @@ private ReagentButton MakeReagentButton(string text, ChemMasterReagentAmount amo /// State data sent by the server. public void UpdateState(BoundUserInterfaceState state) { - var castState = (ChemMasterBoundUserInterfaceState) state; + var castState = (ChemMasterBoundUserInterfaceState)state; + if (castState.UpdateLabel) LabelLine = GenerateLabel(castState); - UpdatePanelInfo(castState); - - var output = castState.OutputContainerInfo; + // Ensure the Panel Info is updated, including UI elements for Buffer Volume, Output Container and so on + UpdatePanelInfo(castState); + BufferCurrentVolume.Text = $" {castState.BufferCurrentVolume?.Int() ?? 0}u"; - + InputEjectButton.Disabled = castState.InputContainerInfo is null; - OutputEjectButton.Disabled = output is null; - CreateBottleButton.Disabled = output?.Reagents == null; - CreatePillButton.Disabled = output?.Entities == null; - + OutputEjectButton.Disabled = castState.OutputContainerInfo is null; + CreateBottleButton.Disabled = castState.OutputContainerInfo?.Reagents == null; + CreatePillButton.Disabled = castState.OutputContainerInfo?.Entities == null; + + UpdateDosageFields(castState); + } + + //assign default values for pill and bottle fields. + private void UpdateDosageFields(ChemMasterBoundUserInterfaceState castState) + { + var output = castState.OutputContainerInfo; var remainingCapacity = output is null ? 0 : (output.MaxVolume - output.CurrentVolume).Int(); var holdsReagents = output?.Reagents != null; var pillNumberMax = holdsReagents ? 0 : remainingCapacity; var bottleAmountMax = holdsReagents ? remainingCapacity : 0; + var bufferVolume = castState.BufferCurrentVolume?.Int() ?? 0; + PillDosage.Value = (int)Math.Min(bufferVolume, castState.PillDosageLimit); + PillTypeButtons[castState.SelectedPillType].Pressed = true; PillNumber.IsValid = x => x >= 0 && x <= pillNumberMax; PillDosage.IsValid = x => x > 0 && x <= castState.PillDosageLimit; @@ -130,8 +172,19 @@ public void UpdateState(BoundUserInterfaceState state) PillNumber.Value = pillNumberMax; if (BottleDosage.Value > bottleAmountMax) BottleDosage.Value = bottleAmountMax; - } + // Avoid division by zero + if (PillDosage.Value > 0) + { + PillNumber.Value = Math.Min(bufferVolume / PillDosage.Value, pillNumberMax); + } + else + { + PillNumber.Value = 0; + } + + BottleDosage.Value = Math.Min(bottleAmountMax, bufferVolume); + } /// /// Generate a product label based on reagents in the buffer. /// @@ -178,46 +231,23 @@ private void UpdatePanelInfo(ChemMasterBoundUserInterfaceState state) var bufferVol = new Label { Text = $"{state.BufferCurrentVolume}u", - StyleClasses = {StyleNano.StyleClassLabelSecondaryColor} + StyleClasses = { StyleNano.StyleClassLabelSecondaryColor } }; bufferHBox.AddChild(bufferVol); + // initialises rowCount to allow for striped rows + + var rowCount = 0; foreach (var (reagent, quantity) in state.BufferReagents) { - // Try to get the prototype for the given reagent. This gives us its name. - _prototypeManager.TryIndex(reagent.Prototype, out ReagentPrototype? proto); + var reagentId = reagent; + _prototypeManager.TryIndex(reagentId.Prototype, out ReagentPrototype? proto); var name = proto?.LocalizedName ?? Loc.GetString("chem-master-window-unknown-reagent-text"); - - if (proto != null) - { - BufferInfo.Children.Add(new BoxContainer - { - Orientation = LayoutOrientation.Horizontal, - Children = - { - new Label {Text = $"{name}: "}, - new Label - { - Text = $"{quantity}u", - StyleClasses = {StyleNano.StyleClassLabelSecondaryColor} - }, - - // Padding - new Control {HorizontalExpand = true}, - - MakeReagentButton("1", ChemMasterReagentAmount.U1, reagent, true, StyleBase.ButtonOpenRight), - MakeReagentButton("5", ChemMasterReagentAmount.U5, reagent, true, StyleBase.ButtonOpenBoth), - MakeReagentButton("10", ChemMasterReagentAmount.U10, reagent, true, StyleBase.ButtonOpenBoth), - MakeReagentButton("25", ChemMasterReagentAmount.U25, reagent, true, StyleBase.ButtonOpenBoth), - MakeReagentButton("50", ChemMasterReagentAmount.U50, reagent, true, StyleBase.ButtonOpenBoth), - MakeReagentButton("100", ChemMasterReagentAmount.U100, reagent, true, StyleBase.ButtonOpenBoth), - MakeReagentButton(Loc.GetString("chem-master-window-buffer-all-amount"), ChemMasterReagentAmount.All, reagent, true, StyleBase.ButtonOpenLeft), - } - }); - } + var reagentColor = proto?.SubstanceColor ?? default(Color); + BufferInfo.Children.Add(BuildReagentRow(reagentColor, rowCount++, name, reagentId, quantity, true, true)); } } - + private void BuildContainerUI(Control control, ContainerInfo? info, bool addReagentButtons) { control.Children.Clear(); @@ -228,104 +258,111 @@ private void BuildContainerUI(Control control, ContainerInfo? info, bool addReag { Text = Loc.GetString("chem-master-window-no-container-loaded-text") }); + return; } - else + + // Name of the container and its fill status (Ex: 44/100u) + control.Children.Add(new BoxContainer { - // Name of the container and its fill status (Ex: 44/100u) - control.Children.Add(new BoxContainer + Orientation = LayoutOrientation.Horizontal, + Children = { - Orientation = LayoutOrientation.Horizontal, - Children = + new Label { Text = $"{info.DisplayName}: " }, + new Label { - new Label {Text = $"{info.DisplayName}: "}, - new Label - { - Text = $"{info.CurrentVolume}/{info.MaxVolume}", - StyleClasses = {StyleNano.StyleClassLabelSecondaryColor} - } + Text = $"{info.CurrentVolume}/{info.MaxVolume}", + StyleClasses = { StyleNano.StyleClassLabelSecondaryColor } } - }); - - IEnumerable<(string Name, ReagentId Id, FixedPoint2 Quantity)> contents; + } + }); + // Initialises rowCount to allow for striped rows + var rowCount = 0; - if (info.Entities != null) + // Handle entities if they are not null + if (info.Entities != null) + { + foreach (var (id, quantity) in info.Entities.Select(x => (x.Id, x.Quantity))) { - contents = info.Entities.Select(x => (x.Id, default(ReagentId), x.Quantity)); + control.Children.Add(BuildReagentRow(default(Color), rowCount++, id, default(ReagentId), quantity, false, addReagentButtons)); } - else if (info.Reagents != null) - { - contents = info.Reagents.Select(x => - { - _prototypeManager.TryIndex(x.Reagent.Prototype, out ReagentPrototype? proto); - var name = proto?.LocalizedName - ?? Loc.GetString("chem-master-window-unknown-reagent-text"); + } - return (name, Id: x.Reagent, x.Quantity); - }) - .OrderBy(r => r.Item1); - } - else + // Handle reagents if they are not null + if (info.Reagents != null) + { + foreach (var reagent in info.Reagents) { - return; + _prototypeManager.TryIndex(reagent.Reagent.Prototype, out ReagentPrototype? proto); + var name = proto?.LocalizedName ?? Loc.GetString("chem-master-window-unknown-reagent-text"); + var reagentColor = proto?.SubstanceColor ?? default(Color); + + control.Children.Add(BuildReagentRow(reagentColor, rowCount++, name, reagent.Reagent, reagent.Quantity, false, addReagentButtons)); } - - - foreach (var (name, id, quantity) in contents) + } + } + /// + /// Take reagent/entity data and present rows, labels, and buttons appropriately. todo sprites? + /// + private Control BuildReagentRow(Color reagentColor, int rowCount, string name, ReagentId reagent, FixedPoint2 quantity, bool isBuffer, bool addReagentButtons) + { + //Colors rows and sets fallback for reagentcolor to the same as background, this will hide colorPanel for entities hopefully + var rowColor1 = Color.FromHex("#1B1B1E"); + var rowColor2 = Color.FromHex("#202025"); + var currentRowColor = (rowCount % 2 == 1) ? rowColor1 : rowColor2; + if ((reagentColor == default(Color))|(!addReagentButtons)) + { + reagentColor = currentRowColor; + } + //this calls the separated button builder, and stores the return to render after labels + var reagentButtonConstructors = CreateReagentTransferButtons(reagent, isBuffer, addReagentButtons); + + // Create the row layout with the color panel + var rowContainer = new BoxContainer + { + Orientation = LayoutOrientation.Horizontal, + Children = { - var inner = new BoxContainer + new Label { Text = $"{name}: " }, + new Label { - Orientation = LayoutOrientation.Horizontal, - Children = - { - new Label { Text = $"{name}: " }, - new Label - { - Text = $"{quantity}u", - StyleClasses = { StyleNano.StyleClassLabelSecondaryColor }, - } - } - }; - - if (addReagentButtons) + Text = $"{quantity}u", + StyleClasses = { StyleNano.StyleClassLabelSecondaryColor } + }, + + // Padding + new Control { HorizontalExpand = true }, + // Colored panels for reagents + new PanelContainer { - var cs = inner.Children; - - // Padding - cs.Add(new Control { HorizontalExpand = true }); - - cs.Add(MakeReagentButton( - "1", ChemMasterReagentAmount.U1, id, false, StyleBase.ButtonOpenRight)); - cs.Add(MakeReagentButton( - "5", ChemMasterReagentAmount.U5, id, false, StyleBase.ButtonOpenBoth)); - cs.Add(MakeReagentButton( - "10", ChemMasterReagentAmount.U10, id, false, StyleBase.ButtonOpenBoth)); - cs.Add(MakeReagentButton( - "25", ChemMasterReagentAmount.U25, id, false, StyleBase.ButtonOpenBoth)); - cs.Add(MakeReagentButton( - "50", ChemMasterReagentAmount.U50, id, false, StyleBase.ButtonOpenBoth)); - cs.Add(MakeReagentButton( - "100", ChemMasterReagentAmount.U100, id, false, StyleBase.ButtonOpenBoth)); - cs.Add(MakeReagentButton( - Loc.GetString("chem-master-window-buffer-all-amount"), - ChemMasterReagentAmount.All, id, false, StyleBase.ButtonOpenLeft)); + Name = "colorPanel", + VerticalExpand = true, + MinWidth = 4, + PanelOverride = new StyleBoxFlat + { + BackgroundColor = reagentColor + }, + Margin = new Thickness(0, 1) } - - control.Children.Add(inner); } + }; - } - } - - public String LabelLine - { - get + // Add the reagent buttons after the color panel + foreach (var reagentTransferButton in reagentButtonConstructors) { - return LabelLineEdit.Text; + rowContainer.AddChild(reagentTransferButton); } - set + //Apply panencontainer to allow for striped rows + return new PanelContainer { - LabelLineEdit.Text = value; - } + PanelOverride = new StyleBoxFlat(currentRowColor), + Children = { rowContainer } + }; + } + + public string LabelLine + { + get => LabelLineEdit.Text; + set => LabelLineEdit.Text = value; } } diff --git a/Content.Client/Explosion/ScatteringGrenadeSystem.cs b/Content.Client/Explosion/ScatteringGrenadeSystem.cs new file mode 100644 index 00000000000000..28976779153d93 --- /dev/null +++ b/Content.Client/Explosion/ScatteringGrenadeSystem.cs @@ -0,0 +1,8 @@ +using Content.Shared.Explosion.EntitySystems; + +namespace Content.Client.Explosion; + +public sealed class ScatteringGrenadeSystem : SharedScatteringGrenadeSystem +{ + +} diff --git a/Content.Client/Holopad/HolopadBoundUserInterface.cs b/Content.Client/Holopad/HolopadBoundUserInterface.cs new file mode 100644 index 00000000000000..20b55ea8c76d88 --- /dev/null +++ b/Content.Client/Holopad/HolopadBoundUserInterface.cs @@ -0,0 +1,101 @@ +using Content.Shared.Holopad; +using Content.Shared.Silicons.StationAi; +using Robust.Client.Graphics; +using Robust.Client.UserInterface; +using Robust.Shared.Player; +using System.Numerics; + +namespace Content.Client.Holopad; + +public sealed class HolopadBoundUserInterface : BoundUserInterface +{ + [Dependency] private readonly ISharedPlayerManager _playerManager = default!; + [Dependency] private readonly IClyde _displayManager = default!; + + [ViewVariables] + private HolopadWindow? _window; + + public HolopadBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) + { + IoCManager.InjectDependencies(this); + } + + protected override void Open() + { + base.Open(); + + _window = this.CreateWindow(); + _window.Title = Loc.GetString("holopad-window-title", ("title", EntMan.GetComponent(Owner).EntityName)); + + if (this.UiKey is not HolopadUiKey) + { + Close(); + return; + } + + var uiKey = (HolopadUiKey)this.UiKey; + + // AIs will see a different holopad interface to crew when interacting with them in the world + if (uiKey == HolopadUiKey.InteractionWindow && EntMan.HasComponent(_playerManager.LocalEntity)) + uiKey = HolopadUiKey.InteractionWindowForAi; + + _window.SetState(Owner, uiKey); + _window.UpdateState(new Dictionary()); + + // Set message actions + _window.SendHolopadStartNewCallMessageAction += SendHolopadStartNewCallMessage; + _window.SendHolopadAnswerCallMessageAction += SendHolopadAnswerCallMessage; + _window.SendHolopadEndCallMessageAction += SendHolopadEndCallMessage; + _window.SendHolopadStartBroadcastMessageAction += SendHolopadStartBroadcastMessage; + _window.SendHolopadActivateProjectorMessageAction += SendHolopadActivateProjectorMessage; + _window.SendHolopadRequestStationAiMessageAction += SendHolopadRequestStationAiMessage; + + // If this call is addressed to an AI, open the window in the bottom right hand corner of the screen + if (uiKey == HolopadUiKey.AiRequestWindow) + _window.OpenCenteredAt(new Vector2(1f, 1f)); + + // Otherwise offset to the left so the holopad can still be seen + else + _window.OpenCenteredAt(new Vector2(0.3333f, 0.50f)); + } + + protected override void UpdateState(BoundUserInterfaceState state) + { + base.UpdateState(state); + + var castState = (HolopadBoundInterfaceState)state; + EntMan.TryGetComponent(Owner, out var xform); + + _window?.UpdateState(castState.Holopads); + } + + public void SendHolopadStartNewCallMessage(NetEntity receiver) + { + SendMessage(new HolopadStartNewCallMessage(receiver)); + } + + public void SendHolopadAnswerCallMessage() + { + SendMessage(new HolopadAnswerCallMessage()); + } + + public void SendHolopadEndCallMessage() + { + SendMessage(new HolopadEndCallMessage()); + } + + public void SendHolopadStartBroadcastMessage() + { + SendMessage(new HolopadStartBroadcastMessage()); + } + + public void SendHolopadActivateProjectorMessage() + { + SendMessage(new HolopadActivateProjectorMessage()); + } + + public void SendHolopadRequestStationAiMessage() + { + SendMessage(new HolopadStationAiRequestMessage()); + } +} diff --git a/Content.Client/Holopad/HolopadSystem.cs b/Content.Client/Holopad/HolopadSystem.cs new file mode 100644 index 00000000000000..3bd556f1fc2329 --- /dev/null +++ b/Content.Client/Holopad/HolopadSystem.cs @@ -0,0 +1,172 @@ +using Content.Shared.Chat.TypingIndicator; +using Content.Shared.Holopad; +using Robust.Client.GameObjects; +using Robust.Client.Graphics; +using Robust.Client.Player; +using Robust.Shared.Prototypes; +using Robust.Shared.Timing; +using System.Linq; + +namespace Content.Client.Holopad; + +public sealed class HolopadSystem : SharedHolopadSystem +{ + [Dependency] private readonly IPrototypeManager _prototypeManager = default!; + [Dependency] private readonly IPlayerManager _playerManager = default!; + [Dependency] private readonly IGameTiming _timing = default!; + + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent(OnComponentInit); + SubscribeLocalEvent(OnShaderRender); + SubscribeAllEvent(OnTypingChanged); + + SubscribeNetworkEvent(OnPlayerSpriteStateRequest); + SubscribeNetworkEvent(OnPlayerSpriteStateMessage); + } + + private void OnComponentInit(EntityUid uid, HolopadHologramComponent component, ComponentInit ev) + { + if (!TryComp(uid, out var sprite)) + return; + + UpdateHologramSprite(uid); + } + + private void OnShaderRender(EntityUid uid, HolopadHologramComponent component, BeforePostShaderRenderEvent ev) + { + if (ev.Sprite.PostShader == null) + return; + + ev.Sprite.PostShader.SetParameter("t", (float)_timing.CurTime.TotalSeconds * component.ScrollRate); + } + + private void OnTypingChanged(TypingChangedEvent ev, EntitySessionEventArgs args) + { + var uid = args.SenderSession.AttachedEntity; + + if (!Exists(uid)) + return; + + if (!HasComp(uid)) + return; + + var netEv = new HolopadUserTypingChangedEvent(GetNetEntity(uid.Value), ev.IsTyping); + RaiseNetworkEvent(netEv); + } + + private void OnPlayerSpriteStateRequest(PlayerSpriteStateRequest ev) + { + var targetPlayer = GetEntity(ev.TargetPlayer); + var player = _playerManager.LocalSession?.AttachedEntity; + + // Ignore the request if received by a player who isn't the target + if (targetPlayer != player) + return; + + if (!TryComp(player, out var playerSprite)) + return; + + var spriteLayerData = new List(); + + if (playerSprite.Visible) + { + // Record the RSI paths, state names and shader paramaters of all visible layers + for (int i = 0; i < playerSprite.AllLayers.Count(); i++) + { + if (!playerSprite.TryGetLayer(i, out var layer)) + continue; + + if (!layer.Visible || + string.IsNullOrEmpty(layer.ActualRsi?.Path.ToString()) || + string.IsNullOrEmpty(layer.State.Name)) + continue; + + var layerDatum = new PrototypeLayerData(); + layerDatum.RsiPath = layer.ActualRsi.Path.ToString(); + layerDatum.State = layer.State.Name; + + if (layer.CopyToShaderParameters != null) + { + var key = (string)layer.CopyToShaderParameters.LayerKey; + + if (playerSprite.LayerMapTryGet(key, out var otherLayerIdx) && + playerSprite.TryGetLayer(otherLayerIdx, out var otherLayer) && + otherLayer.Visible) + { + layerDatum.MapKeys = new() { key }; + + layerDatum.CopyToShaderParameters = new PrototypeCopyToShaderParameters() + { + LayerKey = key, + ParameterTexture = layer.CopyToShaderParameters.ParameterTexture, + ParameterUV = layer.CopyToShaderParameters.ParameterUV + }; + } + } + + spriteLayerData.Add(layerDatum); + } + } + + // Return the recorded data to the server + var evResponse = new PlayerSpriteStateMessage(ev.TargetPlayer, spriteLayerData.ToArray()); + RaiseNetworkEvent(evResponse); + } + + private void OnPlayerSpriteStateMessage(PlayerSpriteStateMessage ev) + { + UpdateHologramSprite(GetEntity(ev.SpriteEntity), ev.SpriteLayerData); + } + + private void UpdateHologramSprite(EntityUid uid, PrototypeLayerData[]? layerData = null) + { + if (!TryComp(uid, out var hologramSprite)) + return; + + if (!TryComp(uid, out var holopadhologram)) + return; + + for (int i = hologramSprite.AllLayers.Count() - 1; i >= 0; i--) + hologramSprite.RemoveLayer(i); + + if (layerData == null || layerData.Length == 0) + { + layerData = new PrototypeLayerData[1]; + layerData[0] = new PrototypeLayerData() + { + RsiPath = holopadhologram.RsiPath, + State = holopadhologram.RsiState + }; + } + + for (int i = 0; i < layerData.Length; i++) + { + var layer = layerData[i]; + layer.Shader = "unshaded"; + + hologramSprite.AddLayer(layerData[i], i); + } + + UpdateHologramShader(uid, hologramSprite, holopadhologram); + } + + private void UpdateHologramShader(EntityUid uid, SpriteComponent sprite, HolopadHologramComponent holopadHologram) + { + // Find the texture height of the largest layer + float texHeight = sprite.AllLayers.Max(x => x.PixelSize.Y); + + var instance = _prototypeManager.Index(holopadHologram.ShaderName).InstanceUnique(); + instance.SetParameter("color1", new Vector3(holopadHologram.Color1.R, holopadHologram.Color1.G, holopadHologram.Color1.B)); + instance.SetParameter("color2", new Vector3(holopadHologram.Color2.R, holopadHologram.Color2.G, holopadHologram.Color2.B)); + instance.SetParameter("alpha", holopadHologram.Alpha); + instance.SetParameter("intensity", holopadHologram.Intensity); + instance.SetParameter("texHeight", texHeight); + instance.SetParameter("t", (float)_timing.CurTime.TotalSeconds * holopadHologram.ScrollRate); + + sprite.PostShader = instance; + sprite.RaiseShaderEvent = true; + } +} diff --git a/Content.Client/Holopad/HolopadWindow.xaml b/Content.Client/Holopad/HolopadWindow.xaml new file mode 100644 index 00000000000000..9c3dfab1ea67aa --- /dev/null +++ b/Content.Client/Holopad/HolopadWindow.xaml @@ -0,0 +1,107 @@ + + + + + + + + + + + + + + + + + + + + + + + + + +