Files
tbd-station-14/Content.Shared/Power/SharedPowerMonitoringConsoleComponent.cs
chromiumboy 1de682e23f Power monitoring console overhaul (#20927)
* Prototyping whole station wire map

* More prototyping

* Added icons for the different power distributors and toggleable cable displays

* Power cable layouts are now only sent to the client when the power monitor is open

* UI prototyping

* Power monitors can now see the sprites of distant entities, long entity names are truncated

* Updated how network devices are added to the player's PVS

* More feature prototypes

* Added source / load symbols

* Final prototype! Time to actually code it properly...

* Start of code clean up

* Continuing code clean up

* Fixed UI appearance

* Code clean up complete

* Removed unnecessary changes

* Updated how power values are calculated, added UI warnings for power sinks and power net checks

* Updated how power values are calculated again, added support for portable generators

* Removed unnecessary files

* Map beacons start toggled off, console map now works outside the station, fixed substation icon

* Made some of Sloth's requested changes. Power distributors don't blink anymore, unless selected

* Moved a number of static variables in PowerMonitoringHelper to sensible places in the main files. Added a NavMapTrackableComponent so that you can specify how individual entities appear on the navmap

* Updated the colors/positions of HV cables and SMESes to improve contrast

* Fixed SMES color in map legend

* Partially fixed auto-scrolling on device selection, made sublists alphabetical

* Changed how auto-scroll is handled

* Changed the font color of the console warning messages

* Reduced the font size of beacon labels

* Added the station name to the console

* Organized references

* Removed unwanted changes to RobustToolbox

* Fix merge conflict

* Fix merge conflict, maybe

* Fix merge conflict

* Updated outdated reference

* Fixed portable_generator.yml

* Implemented a number of requested changes, move bit masks to a shared component

* Navigate listings via the navmap

* First attempt at improving efficiency

* Second attempt at optimization, entity grouping added for solar panels

* Finished solar panel entity joining

* Finished major revisions, code clean up needed

* Finializing optimizations

* Made requested changes

* Bug fix, removed obsolete code

* Bug fixes

* Bug fixes

* STarted revisions

* Further revisions

* More revision

* Finalizing revisions. Need to make RT PR

* Code tidying

* More code tidying

* Trying to avoid merge conflicts

* Trying to avoid merge conflicts

* Removed use of PVS

* Improving efficiency

* Addressed a bunch of outstanding issues

* Clear old data on console refresh

* UI adjustments

* Made node comparison more robust. More devices can be combined into one entry

* Added missing component 'dirty'
2023-12-24 17:07:41 +11:00

160 lines
4.7 KiB
C#

using Robust.Shared.GameStates;
using Robust.Shared.Map;
using Robust.Shared.Serialization;
namespace Content.Shared.Power;
/// <summary>
/// Flags an entity as being a power monitoring console
/// </summary>
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
[Access(typeof(SharedPowerMonitoringConsoleSystem), Other = AccessPermissions.ReadExecute)]
public sealed partial class PowerMonitoringConsoleComponent : Component
{
/// <summary>
/// The EntityUid of the device that is the console's current focus
/// </summary>
/// <remarks>
/// Not-networked - set by the console UI
/// </remarks>
[ViewVariables]
public EntityUid? Focus;
/// <summary>
/// The group that the device that is the console's current focus belongs to
/// </summary>
/// /// <remarks>
/// Not-networked - set by the console UI
/// </remarks>
[ViewVariables]
public PowerMonitoringConsoleGroup FocusGroup = PowerMonitoringConsoleGroup.Generator;
/// <summary>
/// A list of flags relating to currently active events of interest to the console.
/// E.g., power sinks, power net anomalies
/// </summary>
[ViewVariables, AutoNetworkedField]
public PowerMonitoringFlags Flags = PowerMonitoringFlags.None;
/// <summary>
/// A dictionary containing all the meta data for tracked power monitoring devices
/// </summary>
[ViewVariables, AutoNetworkedField]
public Dictionary<NetEntity, PowerMonitoringDeviceMetaData> PowerMonitoringDeviceMetaData = new();
}
[Serializable, NetSerializable]
public struct PowerMonitoringDeviceMetaData
{
public string EntityName;
public NetCoordinates Coordinates;
public PowerMonitoringConsoleGroup Group;
public string SpritePath;
public string SpriteState;
public NetEntity? CollectionMaster;
public PowerMonitoringDeviceMetaData(string name, NetCoordinates coordinates, PowerMonitoringConsoleGroup group, string spritePath, string spriteState)
{
EntityName = name;
Coordinates = coordinates;
Group = group;
SpritePath = spritePath;
SpriteState = spriteState;
}
}
/// <summary>
/// Data from by the server to the client for the power monitoring console UI
/// </summary>
[Serializable, NetSerializable]
public sealed class PowerMonitoringConsoleBoundInterfaceState : BoundUserInterfaceState
{
public double TotalSources;
public double TotalBatteryUsage;
public double TotalLoads;
public PowerMonitoringConsoleEntry[] AllEntries;
public PowerMonitoringConsoleEntry[] FocusSources;
public PowerMonitoringConsoleEntry[] FocusLoads;
public PowerMonitoringConsoleBoundInterfaceState
(double totalSources,
double totalBatteryUsage,
double totalLoads,
PowerMonitoringConsoleEntry[] allEntries,
PowerMonitoringConsoleEntry[] focusSources,
PowerMonitoringConsoleEntry[] focusLoads)
{
TotalSources = totalSources;
TotalBatteryUsage = totalBatteryUsage;
TotalLoads = totalLoads;
AllEntries = allEntries;
FocusSources = focusSources;
FocusLoads = focusLoads;
}
}
/// <summary>
/// Contains all the data needed to update a single device on the power monitoring UI
/// </summary>
[Serializable, NetSerializable]
public struct PowerMonitoringConsoleEntry
{
public NetEntity NetEntity;
public PowerMonitoringConsoleGroup Group;
public double PowerValue;
[NonSerialized] public PowerMonitoringDeviceMetaData? MetaData = null;
public PowerMonitoringConsoleEntry(NetEntity netEntity, PowerMonitoringConsoleGroup group, double powerValue = 0d)
{
NetEntity = netEntity;
Group = group;
PowerValue = powerValue;
}
}
/// <summary>
/// Triggers the server to send updated power monitoring console data to the client for the single player session
/// </summary>
[Serializable, NetSerializable]
public sealed class PowerMonitoringConsoleMessage : BoundUserInterfaceMessage
{
public NetEntity? FocusDevice;
public PowerMonitoringConsoleGroup FocusGroup;
public PowerMonitoringConsoleMessage(NetEntity? focusDevice, PowerMonitoringConsoleGroup focusGroup)
{
FocusDevice = focusDevice;
FocusGroup = focusGroup;
}
}
/// <summary>
/// Determines how entities are grouped and color coded on the power monitor
/// </summary>
public enum PowerMonitoringConsoleGroup : byte
{
Generator,
SMES,
Substation,
APC,
Consumer,
}
[Flags]
public enum PowerMonitoringFlags : byte
{
None = 0,
RoguePowerConsumer = 1,
PowerNetAbnormalities = 2,
}
/// <summary>
/// UI key associated with the power monitoring console
/// </summary>
[Serializable, NetSerializable]
public enum PowerMonitoringConsoleUiKey
{
Key
}