Removes hacky behavior from DeviceListSystem (#11255)
This commit is contained in:
@@ -55,20 +55,7 @@ public sealed class NetworkConfiguratorBoundUserInterface : BoundUserInterface
|
||||
|
||||
private void OnShowPressed(BaseButton.ButtonEventArgs args)
|
||||
{
|
||||
if (!args.Button.Pressed)
|
||||
{
|
||||
_netConfig.ToggleVisualization(Owner.Owner, false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (_entityManager.GetComponent<MetaDataComponent>(Owner.Owner).EntityLifeStage == EntityLifeStage.Initialized)
|
||||
{
|
||||
// We're in mapping mode. Do something hacky.
|
||||
SendMessage(new ManualDeviceListSyncMessage(null, null));
|
||||
return;
|
||||
}
|
||||
|
||||
_netConfig.ToggleVisualization(Owner.Owner, true);
|
||||
_netConfig.ToggleVisualization(Owner.Owner, args.Button.Pressed);
|
||||
}
|
||||
|
||||
protected override void UpdateState(BoundUserInterfaceState state)
|
||||
@@ -86,25 +73,6 @@ public sealed class NetworkConfiguratorBoundUserInterface : BoundUserInterface
|
||||
}
|
||||
}
|
||||
|
||||
protected override void ReceiveMessage(BoundUserInterfaceMessage message)
|
||||
{
|
||||
base.ReceiveMessage(message);
|
||||
|
||||
if (_configurationMenu == null
|
||||
|| _entityManager.GetComponent<MetaDataComponent>(Owner.Owner).EntityLifeStage > EntityLifeStage.Initialized
|
||||
|| message is not ManualDeviceListSyncMessage cast
|
||||
|| cast.Device == null
|
||||
|| cast.Devices == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_netConfig.SetActiveDeviceList(Owner.Owner, cast.Device.Value);
|
||||
_deviceList.UpdateDeviceList(cast.Device.Value, cast.Devices);
|
||||
_netConfig.ToggleVisualization(Owner.Owner, true);
|
||||
_configurationMenu.Show.Pressed = true;
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
|
||||
@@ -12,10 +12,16 @@ public sealed class DeviceListSystem : SharedDeviceListSystem
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<DeviceListComponent, ComponentInit>(OnInit);
|
||||
SubscribeLocalEvent<DeviceListComponent, BeforeBroadcastAttemptEvent>(OnBeforeBroadcast);
|
||||
SubscribeLocalEvent<DeviceListComponent, BeforePacketSentEvent>(OnBeforePacketSent);
|
||||
}
|
||||
|
||||
public void OnInit(EntityUid uid, DeviceListComponent component, ComponentInit args)
|
||||
{
|
||||
Dirty(component);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the given device list as a dictionary
|
||||
/// </summary>
|
||||
|
||||
@@ -46,7 +46,6 @@ public sealed class NetworkConfiguratorSystem : SharedNetworkConfiguratorSystem
|
||||
SubscribeLocalEvent<NetworkConfiguratorComponent, NetworkConfiguratorRemoveDeviceMessage>(OnRemoveDevice);
|
||||
SubscribeLocalEvent<NetworkConfiguratorComponent, NetworkConfiguratorClearDevicesMessage>(OnClearDevice);
|
||||
SubscribeLocalEvent<NetworkConfiguratorComponent, NetworkConfiguratorButtonPressedMessage>(OnConfigButtonPressed);
|
||||
SubscribeLocalEvent<NetworkConfiguratorComponent, ManualDeviceListSyncMessage>(ManualDeviceListSync);
|
||||
|
||||
SubscribeLocalEvent<DeviceListComponent, ComponentRemove>(OnComponentRemoved);
|
||||
}
|
||||
@@ -330,20 +329,5 @@ public sealed class NetworkConfiguratorSystem : SharedNetworkConfiguratorSystem
|
||||
_deviceListSystem.GetDeviceList(component.ActiveDeviceList.Value)
|
||||
.Select(v => (v.Key, MetaData(v.Value).EntityName)).ToHashSet()));
|
||||
}
|
||||
|
||||
// hacky solution related to mapping
|
||||
private void ManualDeviceListSync(EntityUid uid, NetworkConfiguratorComponent comp,
|
||||
ManualDeviceListSyncMessage args)
|
||||
{
|
||||
if (comp.ActiveDeviceList == null || args.Session is not IPlayerSession player)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var devices = _deviceListSystem.GetAllDevices(comp.ActiveDeviceList.Value).ToHashSet();
|
||||
|
||||
_uiSystem.TrySendUiMessage(uid, NetworkConfiguratorUiKey.Configure, new ManualDeviceListSyncMessage(comp.ActiveDeviceList.Value, devices), player);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ public abstract class SharedDeviceListSystem : EntitySystem
|
||||
/// <param name="uid">The entity to update.</param>
|
||||
/// <param name="devices">The devices to store.</param>
|
||||
/// <param name="merge">Whether to merge or replace the devices stored.</param>
|
||||
/// <param name="dirty">If the component should be dirtied upon this call.</param>
|
||||
/// <param name="deviceList">Device list component</param>
|
||||
public DeviceListUpdateResult UpdateDeviceList(EntityUid uid, IEnumerable<EntityUid> devices, bool merge = false, DeviceListComponent? deviceList = null)
|
||||
{
|
||||
|
||||
@@ -14,8 +14,6 @@ public abstract class SharedNetworkConfiguratorSystem : EntitySystem
|
||||
SubscribeLocalEvent<NetworkConfiguratorComponent, ComponentHandleState>(HandleNetworkConfiguratorState);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void GetNetworkConfiguratorState(EntityUid uid, NetworkConfiguratorComponent comp,
|
||||
ref ComponentGetState args)
|
||||
{
|
||||
@@ -34,19 +32,6 @@ public abstract class SharedNetworkConfiguratorSystem : EntitySystem
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class ManualDeviceListSyncMessage : BoundUserInterfaceMessage
|
||||
{
|
||||
public ManualDeviceListSyncMessage(EntityUid? device, HashSet<EntityUid>? devices)
|
||||
{
|
||||
Device = device;
|
||||
Devices = devices;
|
||||
}
|
||||
|
||||
public EntityUid? Device { get; }
|
||||
public HashSet<EntityUid>? Devices { get; }
|
||||
}
|
||||
|
||||
public sealed class ClearAllOverlaysEvent : InstantActionEvent
|
||||
{
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user