Cleaner BoundUserInterfaces (#17736)

This commit is contained in:
TemporalOroboros
2023-07-08 09:02:17 -07:00
committed by GitHub
parent 55b4fb1649
commit 3ac4cf85db
137 changed files with 1069 additions and 972 deletions

View File

@@ -68,15 +68,13 @@ public sealed class NetworkConfiguratorSystem : SharedNetworkConfiguratorSystem
{
base.Update(frameTime);
foreach (var component in EntityManager.EntityQuery<NetworkConfiguratorComponent>())
var query = EntityQueryEnumerator<NetworkConfiguratorComponent>();
while (query.MoveNext(out var uid, out var component))
{
var uid = component.Owner;
if (component.ActiveDeviceList != null && EntityManager.EntityExists(component.ActiveDeviceList.Value) &&
_interactionSystem.InRangeUnobstructed(uid, component.ActiveDeviceList.Value))
{
if (component.ActiveDeviceList != null
&& EntityManager.EntityExists(component.ActiveDeviceList.Value)
&& _interactionSystem.InRangeUnobstructed(uid, component.ActiveDeviceList.Value))
continue;
}
//The network configurator is a handheld device. There can only ever be an ui session open for the player holding the device.
_uiSystem.TryCloseAll(uid, NetworkConfiguratorUiKey.Configure);
@@ -95,10 +93,10 @@ public sealed class NetworkConfiguratorSystem : SharedNetworkConfiguratorSystem
if (!Resolve(configuratorUid, ref configurator))
return;
TryAddNetworkDevice(targetUid, userUid, configurator);
TryAddNetworkDevice(configuratorUid, targetUid, userUid, configurator);
}
private void TryAddNetworkDevice(EntityUid? targetUid, EntityUid userUid, NetworkConfiguratorComponent configurator, DeviceNetworkComponent? device = null)
private void TryAddNetworkDevice(EntityUid configuratorUid, EntityUid? targetUid, EntityUid userUid, NetworkConfiguratorComponent configurator, DeviceNetworkComponent? device = null)
{
if (!targetUid.HasValue || !Resolve(targetUid.Value, ref device, false))
return;
@@ -122,7 +120,7 @@ public sealed class NetworkConfiguratorSystem : SharedNetworkConfiguratorSystem
return;
}
address = $"UID: {targetUid.Value.ToString()}";
address = $"UID: {targetUid.Value}";
}
if (configurator.Devices.ContainsValue(targetUid.Value))
@@ -135,7 +133,6 @@ public sealed class NetworkConfiguratorSystem : SharedNetworkConfiguratorSystem
_popupSystem.PopupCursor(Loc.GetString("network-configurator-device-saved", ("address", device.Address), ("device", targetUid)),
userUid, PopupType.Medium);
var configuratorUid = configurator.Owner;
_adminLogger.Add(LogType.DeviceLinking, LogImpact.Low, $"{ToPrettyString(userUid):actor} saved {ToPrettyString(targetUid.Value):subject} to {ToPrettyString(configuratorUid):tool}");
UpdateListUiState(configuratorUid, configurator);
@@ -167,11 +164,11 @@ public sealed class NetworkConfiguratorSystem : SharedNetworkConfiguratorSystem
|| HasComp<DeviceLinkSinkComponent>(target) && HasComp<DeviceLinkSinkComponent>(configurator.ActiveDeviceLink))
return;
_popupSystem.PopupEntity(Loc.GetString("network-configurator-link-mode-started", ("device", Name(target.Value))), target.Value, user);
_popupSystem.PopupEntity(Loc.GetString("network-configurator-link-mode-started", ("device", Name(target.Value))), target.Value, user);
configurator.ActiveDeviceLink = target;
}
private void TryLinkDefaults(EntityUid uid, NetworkConfiguratorComponent configurator, EntityUid? targetUid, EntityUid user)
private void TryLinkDefaults(EntityUid _, NetworkConfiguratorComponent configurator, EntityUid? targetUid, EntityUid user)
{
if (!configurator.LinkModeActive || !configurator.ActiveDeviceLink.HasValue
|| !targetUid.HasValue || configurator.ActiveDeviceLink == targetUid)
@@ -297,11 +294,11 @@ public sealed class NetworkConfiguratorSystem : SharedNetworkConfiguratorSystem
if (!HasComp<DeviceListComponent>(target))
{
TryAddNetworkDevice(target, user, configurator);
TryAddNetworkDevice(uid, target, user, configurator);
return;
}
OpenDeviceListUi(target, user, configurator);
OpenDeviceListUi(uid, target, user, configurator);
}
private void DetermineMode(EntityUid configuratorUid, NetworkConfiguratorComponent configurator, EntityUid? target, EntityUid userUid)
@@ -382,7 +379,8 @@ public sealed class NetworkConfiguratorSystem : SharedNetworkConfiguratorSystem
return;
}
if (configurator is {LinkModeActive: true, ActiveDeviceLink: { }} && (HasComp<DeviceLinkSinkComponent>(args.Target) || HasComp<DeviceLinkSourceComponent>(args.Target)))
if (configurator is { LinkModeActive: true, ActiveDeviceLink: { } }
&& (HasComp<DeviceLinkSinkComponent>(args.Target) || HasComp<DeviceLinkSourceComponent>(args.Target)))
{
AlternativeVerb verb = new()
{
@@ -460,7 +458,7 @@ public sealed class NetworkConfiguratorSystem : SharedNetworkConfiguratorSystem
/// <summary>
/// Opens the config ui. It can be used to modify the devices in the targets device list.
/// </summary>
private void OpenDeviceListUi(EntityUid? targetUid, EntityUid userUid, NetworkConfiguratorComponent configurator)
private void OpenDeviceListUi(EntityUid configuratorUid, EntityUid? targetUid, EntityUid userUid, NetworkConfiguratorComponent configurator)
{
if (Delay(configurator))
return;
@@ -470,13 +468,15 @@ public sealed class NetworkConfiguratorSystem : SharedNetworkConfiguratorSystem
configurator.ActiveDeviceList = targetUid;
Dirty(configurator);
_uiSystem.GetUiOrNull(configurator.Owner, NetworkConfiguratorUiKey.Configure)?.Open(actor.PlayerSession);
_uiSystem.TrySetUiState(
configurator.Owner,
NetworkConfiguratorUiKey.Configure,
new DeviceListUserInterfaceState(
if (!_uiSystem.TryGetUi(configuratorUid, NetworkConfiguratorUiKey.Configure, out var bui))
return;
if (_uiSystem.OpenUi(bui, actor.PlayerSession))
UserInterfaceSystem.SetUiState(bui, new DeviceListUserInterfaceState(
_deviceListSystem.GetDeviceList(configurator.ActiveDeviceList.Value)
.Select(v => (v.Key, MetaData(v.Value).EntityName)).ToHashSet()));
.Select(v => (v.Key, MetaData(v.Value).EntityName)).ToHashSet()
));
}
/// <summary>
@@ -504,7 +504,8 @@ public sealed class NetworkConfiguratorSystem : SharedNetworkConfiguratorSystem
component.Devices.Remove(invalidDevice);
}
_uiSystem.GetUiOrNull(uid, NetworkConfiguratorUiKey.List)?.SetState(new NetworkConfiguratorUserInterfaceState(devices));
if (_uiSystem.TryGetUi(uid, NetworkConfiguratorUiKey.List, out var bui))
UserInterfaceSystem.SetUiState(bui, new NetworkConfiguratorUserInterfaceState(devices));
}
/// <summary>