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);
        }
        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);
        }
Beispiel #3
0
        public ViewVariablesPropertyEditor SetProperty(ViewVariablesBlobMembers.MemberData member)
        {
            NameLabel.Text = member.Name;
            var type = Type.GetType(member.Type);

            _bottomLabel.Text = $"Type: {member.TypePretty}";
            ViewVariablesPropertyEditor editor;

            if (type == null)
            {
                // Type is server-side only.
                // Info whether it's reference or value type can be figured out from the sent value.
                if (member.Value is ViewVariablesBlobMembers.ServerValueTypeToken)
                {
                    // Value type, just display it stringified read-only.
                    editor = new ViewVariablesPropertyEditorDummy();
                }
                else
                {
                    // Has to be a reference type at this point.
                    DebugTools.Assert(member.Value is ViewVariablesBlobMembers.ReferenceToken || member.Value == null);
                    editor = _viewVariablesManager.PropertyFor(typeof(object));
                }
            }
            else
            {
                editor = _viewVariablesManager.PropertyFor(type);
            }

            var view = editor.Initialize(member.Value, !member.Editable);

            if (view.SizeFlagsHorizontal != SizeFlags.FillExpand)
            {
                NameLabel.SizeFlagsHorizontal = SizeFlags.FillExpand;
            }

            NameLabel.CustomMinimumSize = new Vector2(150, 0);
            TopContainer.AddChild(view);

            /*
             * _beingEdited = obj;
             * _editedProperty = propertyInfo;
             * DebugTools.Assert(propertyInfo.DeclaringType != null);
             * DebugTools.Assert(propertyInfo.DeclaringType.IsInstanceOfType(obj));
             *
             * var attr = propertyInfo.GetCustomAttribute<ViewVariablesAttribute>();
             * DebugTools.Assert(attr != null);
             * NameLabel.Text = propertyInfo.Name;
             *
             * _bottomLabel.Text = $"Type: {propertyInfo.PropertyType.FullName}";
             *
             * var editor = vvm.PropertyFor(propertyInfo.PropertyType);
             * var value = propertyInfo.GetValue(obj);
             *
             * var view = editor.Initialize(value, attr.Access != VVAccess.ReadWrite);
             * if (view.SizeFlagsHorizontal != SizeFlags.FillExpand)
             * {
             *  NameLabel.SizeFlagsHorizontal = SizeFlags.FillExpand;
             * }
             * NameLabel.CustomMinimumSize = new Vector2(150, 0);
             * TopContainer.AddChild(view);
             * editor.OnValueChanged += v => { propertyInfo.SetValue(obj, v); };
             */
            return(editor);
        }