KVPair<K, V> now shows in VV. Client only.

This commit is contained in:
Pieter-Jan Briers
2019-12-22 21:38:21 +01:00
parent 21b29e26e2
commit 531cfeb9e6
2 changed files with 67 additions and 0 deletions

View File

@@ -0,0 +1,57 @@
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.IoC;
namespace Robust.Client.ViewVariables.Editors
{
public class ViewVariablesPropertyEditorKeyValuePair : ViewVariablesPropertyEditor
{
#pragma warning disable 649
[Dependency] private readonly IViewVariablesManagerInternal _viewVariables;
#pragma warning restore 649
public ViewVariablesPropertyEditorKeyValuePair()
{
IoCManager.InjectDependencies(this);
}
protected override Control MakeUI(object value)
{
var hBox = new HBoxContainer();
var propK = value.GetType().GetProperty("Key");
var propV = value.GetType().GetProperty("Value");
var valueK = propK.GetValue(value);
var valueV = propV.GetValue(value);
var typeK = valueK?.GetType();
var typeV = valueV?.GetType();
var propertyEditorK = _viewVariables.PropertyFor(typeK);
var propertyEditorV = _viewVariables.PropertyFor(typeV);
WireReference(propertyEditorK, valueK);
WireReference(propertyEditorV, valueV);
var controlK = propertyEditorK.Initialize(valueK, true);
var controlV = propertyEditorV.Initialize(valueV, true);
hBox.AddChild(controlK);
hBox.AddChild(controlV);
return hBox;
}
private void WireReference(ViewVariablesPropertyEditor prop, object value)
{
if (!(prop is ViewVariablesPropertyEditorReference reference))
{
return;
}
// TODO: Won't work when networked, fix this.
reference.OnPressed += () => _viewVariables.OpenVV(value);
}
}
}

View File

@@ -58,6 +58,11 @@ namespace Robust.Client.ViewVariables
public ViewVariablesPropertyEditor PropertyFor(Type type)
{
// TODO: make this more flexible.
if (type == null)
{
return new ViewVariablesPropertyEditorDummy();
}
if (type == typeof(sbyte))
{
return new ViewVariablesPropertyEditorNumeric(NumberType.SByte);
@@ -178,6 +183,11 @@ namespace Robust.Client.ViewVariables
return new ViewVariablesPropertyEditorReference();
}
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(KeyValuePair<,>))
{
return new ViewVariablesPropertyEditorKeyValuePair();
}
return new ViewVariablesPropertyEditorDummy();
}