mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-16 07:12:27 +02:00
62 lines
2.1 KiB
C#
62 lines
2.1 KiB
C#
using System.Linq;
|
|
using Robust.Client.UserInterface;
|
|
using Robust.Client.UserInterface.Controls;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.ViewVariables;
|
|
|
|
namespace Robust.Client.ViewVariables.Editors
|
|
{
|
|
public class ViewVariablesPropertyEditorKeyValuePair : ViewVariablesPropertyEditor
|
|
{
|
|
[Dependency] private readonly IViewVariablesManagerInternal _viewVariables = default!;
|
|
|
|
private ViewVariablesPropertyEditor? _propertyEditorK;
|
|
private ViewVariablesPropertyEditor? _propertyEditorV;
|
|
|
|
public ViewVariablesPropertyEditorKeyValuePair()
|
|
{
|
|
IoCManager.InjectDependencies(this);
|
|
}
|
|
|
|
protected override Control MakeUI(object? value)
|
|
{
|
|
var hBox = new HBoxContainer();
|
|
|
|
dynamic d = value!;
|
|
|
|
// NOTE: value can be both a KeyValuePair<,> here OR as a ServerKeyValuePairToken.
|
|
|
|
object? valueK = d.Key;
|
|
object? valueV = d.Value;
|
|
|
|
// ReSharper disable ConstantConditionalAccessQualifier
|
|
var typeK = valueK?.GetType();
|
|
var typeV = valueV?.GetType();
|
|
// ReSharper restore ConstantConditionalAccessQualifier
|
|
|
|
_propertyEditorK = _viewVariables.PropertyFor(typeK);
|
|
_propertyEditorV = _viewVariables.PropertyFor(typeV);
|
|
|
|
var controlK = _propertyEditorK.Initialize(valueK, true);
|
|
var controlV = _propertyEditorV.Initialize(valueV, true);
|
|
|
|
hBox.AddChild(controlK);
|
|
hBox.AddChild(controlV);
|
|
|
|
return hBox;
|
|
}
|
|
|
|
public override void WireNetworkSelector(uint sessionId, object[] selectorChain)
|
|
{
|
|
var keySelector = new ViewVariablesSelectorKeyValuePair {Key = true};
|
|
var valueSelector = new ViewVariablesSelectorKeyValuePair {Key = false};
|
|
|
|
var keyChain = selectorChain.Append(keySelector).ToArray();
|
|
var valueChain = selectorChain.Append(valueSelector).ToArray();
|
|
|
|
_propertyEditorK!.WireNetworkSelector(sessionId, keyChain);
|
|
_propertyEditorV!.WireNetworkSelector(sessionId, valueChain);
|
|
}
|
|
}
|
|
}
|