mirror of
https://github.com/wega-team/ss14-wega.git
synced 2026-02-14 19:30:01 +01:00
* Merge IFF controls into one control. * Implement logic to hide IFF of sydicate IFF console on map load. Add hideOnInit property to IFFConsoleComponent * DataField --------- Co-authored-by: ScarKy0 <106310278+ScarKy0@users.noreply.github.com>
125 lines
3.9 KiB
C#
125 lines
3.9 KiB
C#
using Content.Server.Shuttles.Components;
|
|
using Content.Shared.CCVar;
|
|
using Content.Shared.Shuttles.BUIStates;
|
|
using Content.Shared.Shuttles.Components;
|
|
using Content.Shared.Shuttles.Events;
|
|
|
|
namespace Content.Server.Shuttles.Systems;
|
|
|
|
public sealed partial class ShuttleSystem
|
|
{
|
|
private void InitializeIFF()
|
|
{
|
|
SubscribeLocalEvent<IFFConsoleComponent, AnchorStateChangedEvent>(OnIFFConsoleAnchor);
|
|
SubscribeLocalEvent<IFFConsoleComponent, IFFShowIFFMessage>(OnIFFShow);
|
|
SubscribeLocalEvent<IFFConsoleComponent, MapInitEvent>(OnInitIFFConsole);
|
|
SubscribeLocalEvent<GridSplitEvent>(OnGridSplit);
|
|
}
|
|
|
|
private void OnGridSplit(ref GridSplitEvent ev)
|
|
{
|
|
var splitMass = _cfg.GetCVar(CCVars.HideSplitGridsUnder);
|
|
|
|
if (splitMass < 0)
|
|
return;
|
|
|
|
foreach (var grid in ev.NewGrids)
|
|
{
|
|
if (!_physicsQuery.TryGetComponent(grid, out var physics) ||
|
|
physics.Mass > splitMass)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
AddIFFFlag(grid, IFFFlags.HideLabel);
|
|
}
|
|
}
|
|
|
|
private void OnIFFShow(EntityUid uid, IFFConsoleComponent component, IFFShowIFFMessage args)
|
|
{
|
|
if (!TryComp(uid, out TransformComponent? xform) || xform.GridUid == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
// Merged toggle controls both HideLabel and Hide flags
|
|
if (!args.Show)
|
|
{
|
|
if ((component.AllowedFlags & IFFFlags.HideLabel) != 0x0)
|
|
{
|
|
AddIFFFlag(xform.GridUid.Value, IFFFlags.HideLabel);
|
|
}
|
|
if ((component.AllowedFlags & IFFFlags.Hide) != 0x0)
|
|
{
|
|
AddIFFFlag(xform.GridUid.Value, IFFFlags.Hide);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if ((component.AllowedFlags & IFFFlags.HideLabel) != 0x0)
|
|
{
|
|
RemoveIFFFlag(xform.GridUid.Value, IFFFlags.HideLabel);
|
|
}
|
|
if ((component.AllowedFlags & IFFFlags.Hide) != 0x0)
|
|
{
|
|
RemoveIFFFlag(xform.GridUid.Value, IFFFlags.Hide);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnInitIFFConsole(EntityUid uid, IFFConsoleComponent component, MapInitEvent args)
|
|
{
|
|
if (!TryComp(uid, out TransformComponent? xform) || xform.GridUid == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (component.HideOnInit)
|
|
{
|
|
AddIFFFlag(xform.GridUid.Value, IFFFlags.HideLabel);
|
|
AddIFFFlag(xform.GridUid.Value, IFFFlags.Hide);
|
|
}
|
|
}
|
|
|
|
private void OnIFFConsoleAnchor(EntityUid uid, IFFConsoleComponent component, ref AnchorStateChangedEvent args)
|
|
{
|
|
// If we anchor / re-anchor then make sure flags up to date.
|
|
if (!args.Anchored ||
|
|
!TryComp(uid, out TransformComponent? xform) ||
|
|
!TryComp<IFFComponent>(xform.GridUid, out var iff))
|
|
{
|
|
_uiSystem.SetUiState(uid, IFFConsoleUiKey.Key, new IFFConsoleBoundUserInterfaceState()
|
|
{
|
|
AllowedFlags = component.AllowedFlags,
|
|
Flags = IFFFlags.None,
|
|
});
|
|
}
|
|
else
|
|
{
|
|
_uiSystem.SetUiState(uid, IFFConsoleUiKey.Key, new IFFConsoleBoundUserInterfaceState()
|
|
{
|
|
AllowedFlags = component.AllowedFlags,
|
|
Flags = iff.Flags,
|
|
});
|
|
}
|
|
}
|
|
|
|
protected override void UpdateIFFInterfaces(EntityUid gridUid, IFFComponent component)
|
|
{
|
|
base.UpdateIFFInterfaces(gridUid, component);
|
|
|
|
var query = AllEntityQuery<IFFConsoleComponent, TransformComponent>();
|
|
while (query.MoveNext(out var uid, out var comp, out var xform))
|
|
{
|
|
if (xform.GridUid != gridUid)
|
|
continue;
|
|
|
|
_uiSystem.SetUiState(uid, IFFConsoleUiKey.Key, new IFFConsoleBoundUserInterfaceState()
|
|
{
|
|
AllowedFlags = comp.AllowedFlags,
|
|
Flags = component.Flags,
|
|
});
|
|
}
|
|
}
|
|
}
|