Network interfacedata (#5399)

If UIs are dynamically changed this fixes it.
This commit is contained in:
metalgearsloth
2024-08-26 18:48:15 +10:00
committed by GitHub
parent 57f133b742
commit e3819f8245
2 changed files with 22 additions and 3 deletions

View File

@@ -34,16 +34,19 @@ namespace Robust.Shared.GameObjects
[Serializable, NetSerializable]
internal sealed class UserInterfaceComponentState(
Dictionary<Enum, List<NetEntity>> actors,
Dictionary<Enum, BoundUserInterfaceState> states)
Dictionary<Enum, BoundUserInterfaceState> states,
Dictionary<Enum, InterfaceData> data)
: IComponentState
{
public Dictionary<Enum, List<NetEntity>> Actors = actors;
public Dictionary<Enum, BoundUserInterfaceState> States = states;
public Dictionary<Enum, InterfaceData> Data = data;
}
}
[DataDefinition]
[DataDefinition, Serializable, NetSerializable]
public sealed partial class InterfaceData
{
[DataField("type", required: true)]
@@ -65,6 +68,11 @@ namespace Robust.Shared.GameObjects
/// </remarks>
[DataField]
public bool RequireInputValidation = true;
public InterfaceData(string type)
{
ClientType = type;
}
}
/// <summary>

View File

@@ -300,7 +300,7 @@ public abstract class SharedUserInterfaceSystem : EntitySystem
// I.e., don't resend the whole BUI state just because a new user opened it.
var actors = new Dictionary<Enum, List<NetEntity>>();
args.State = new UserInterfaceComponent.UserInterfaceComponentState(actors, ent.Comp.States);
args.State = new UserInterfaceComponent.UserInterfaceComponentState(actors, ent.Comp.States, ent.Comp.Interfaces);
// Ensure that only the player that currently has the UI open gets to know what they have it open.
if (args.ReplayState)
@@ -326,6 +326,17 @@ public abstract class SharedUserInterfaceSystem : EntitySystem
if (args.Current is not UserInterfaceComponent.UserInterfaceComponentState state)
return;
ent.Comp.Interfaces.Clear();
foreach (var data in state.Data)
{
ent.Comp.Interfaces[data.Key] = new(data.Value.ClientType)
{
InteractionRange = data.Value.InteractionRange,
RequireInputValidation = data.Value.RequireInputValidation,
};
}
foreach (var key in ent.Comp.Actors.Keys)
{
if (!state.Actors.ContainsKey(key))