public void AddEditorUI(string id, ITreeNodeView view, IProperty property)
        {
            _property = property;
            _nullBox  = BoolPropertyEditor.CreateCheckbox(view.TreeItem, _factory, id + "_NullBox");
            refreshChecked();

            _nullBox.OnCheckChanged.Subscribe(args =>
            {
                Type underlying = Nullable.GetUnderlyingType(property.PropertyType) ??
                                  throw new Exception($"Underlying type for {property.PropertyType.Name} returned null");
                object val = args.Checked ? Activator.CreateInstance(underlying) : null;

                if (args.UserInitiated)
                {
                    _actions.RecordAction(new PropertyAction(property, val, _model));
                }
                else
                {
                    property.Value = new ValueModel(val, type: property.PropertyType);
                }

                _editor.OnNullChanged(!_nullBox.Checked);
            });

            _editor.AddEditorUI(id, view, property);
            _editor.OnNullChanged(!_nullBox.Checked);
        }
Example #2
0
        private void addTargetUIForCreate(IPanel panel, Target target)
        {
            if (target == Target.Area)
            {
                return;
            }

            var factory      = _editor.Editor.Factory;
            var buttonsPanel = factory.UI.GetPanel("MethodWizardTargetPanel", 100f, 45f, MethodWizard.MARGIN_HORIZONTAL, 50f, panel);

            buttonsPanel.Tint = Colors.Transparent;

            var font        = _editor.Editor.Settings.Defaults.Fonts.Text;
            var labelConfig = factory.Fonts.GetTextConfig(font: factory.Fonts.LoadFont(font.FontFamily, font.SizeInPoints, FontStyle.Underline));

            factory.UI.GetLabel("AddToLabel", "Add To:", 50f, 20f, 0f, 0f, buttonsPanel, labelConfig);

            const float buttonY    = -40f;
            var         roomButton = BoolPropertyEditor.CreateRadioButton(buttonsPanel, factory, "AddToRoomRadioButton", 10f, buttonY, "Room");
            var         guiButton  = BoolPropertyEditor.CreateRadioButton(buttonsPanel, factory, "AddToGUIRadioButton", 130f, buttonY, "GUI");

            _guiButton            = guiButton.GetComponent <ICheckboxComponent>();
            _targetRadioGroup     = new AGSRadioGroup();
            roomButton.RadioGroup = _targetRadioGroup;
            guiButton.RadioGroup  = _targetRadioGroup;
            if (_potentialParent != null)
            {
                var parentButton = BoolPropertyEditor.CreateRadioButton(buttonsPanel, factory, "AddToParentRadioButton", 250f, buttonY, _potentialParent.GetFriendlyName());
                parentButton.RadioGroup = _targetRadioGroup;
                _parentButton           = parentButton.GetComponent <ICheckboxComponent>();
                parentButton.MouseClicked.Subscribe(() =>
                {
                    resetNumberEditor(panel, "x");
                    resetNumberEditor(panel, "y");
                });
            }
            _targetRadioGroup.SelectedButton = target == Target.UI ? _guiButton : roomButton;
        }
Example #3
0
        private ITreeStringNode addToTree(InspectorProperty property, ITreeStringNode parent)
        {
            if (property.IsReadonly)
            {
                return(addReadonlyNodeToTree(property, parent));
            }
            IInspectorPropertyEditor editor;

            var propType = property.Prop.PropertyType;

            if (propType == typeof(bool))
            {
                editor = new BoolPropertyEditor(_factory, _actions);
            }
            else if (propType == typeof(Color))
            {
                editor = new ColorPropertyEditor(_factory, _actions);
            }
            else if (propType == typeof(int))
            {
                editor = new NumberPropertyEditor(_actions, _state, _factory, true, false);
            }
            else if (propType == typeof(float))
            {
                editor = new NumberPropertyEditor(_actions, _state, _factory, false, false);
            }
            else if (propType == typeof(SizeF))
            {
                editor = new SizeFPropertyEditor(_actions, _state, _factory, false);
            }
            else if (propType == typeof(Size))
            {
                editor = new SizePropertyEditor(_actions, _state, _factory, false);
            }
            else if (propType == typeof(PointF))
            {
                editor = new PointFPropertyEditor(_actions, _state, _factory, false);
            }
            else if (propType == typeof(Point))
            {
                editor = new PointPropertyEditor(_actions, _state, _factory, false);
            }
            else if (propType == typeof(Vector2))
            {
                editor = new Vector2PropertyEditor(_actions, _state, _factory, false);
            }
            else if (propType == typeof(Vector3))
            {
                editor = new Vector3PropertyEditor(_actions, _state, _factory, false);
            }
            else if (propType == typeof(Vector4))
            {
                editor = new Vector4PropertyEditor(_actions, _state, _factory, false);
            }
            else if (propType == typeof(ILocation))
            {
                var entity   = _currentEntity;
                var drawable = entity == null ? null : entity.GetComponent <IDrawableInfoComponent>();
                editor = new LocationPropertyEditor(_actions, _state, _factory, false, _settings, drawable);
            }
            else if (propType == typeof(RectangleF))
            {
                editor = new RectangleFPropertyEditor(_actions, _state, _factory, false);
            }
            else if (propType == typeof(Rectangle))
            {
                editor = new RectanglePropertyEditor(_actions, _state, _factory, false);
            }
            else if (propType == typeof(int?))
            {
                editor = new NumberPropertyEditor(_actions, _state, _factory, true, true);
            }
            else if (propType == typeof(float?))
            {
                editor = new NumberPropertyEditor(_actions, _state, _factory, false, true);
            }
            else if (propType == typeof(SizeF?))
            {
                editor = new SizeFPropertyEditor(_actions, _state, _factory, true);
            }
            else if (propType == typeof(Size?))
            {
                editor = new SizePropertyEditor(_actions, _state, _factory, true);
            }
            else if (propType == typeof(PointF?))
            {
                editor = new PointFPropertyEditor(_actions, _state, _factory, true);
            }
            else if (propType == typeof(Point?))
            {
                editor = new PointPropertyEditor(_actions, _state, _factory, true);
            }
            else if (propType == typeof(Vector2?))
            {
                editor = new Vector2PropertyEditor(_actions, _state, _factory, true);
            }
            else if (propType == typeof(Vector3?))
            {
                editor = new Vector3PropertyEditor(_actions, _state, _factory, true);
            }
            else if (propType == typeof(Vector4?))
            {
                editor = new Vector4PropertyEditor(_actions, _state, _factory, true);
            }
            else if (propType == typeof(RectangleF?))
            {
                editor = new RectangleFPropertyEditor(_actions, _state, _factory, true);
            }
            else if (propType == typeof(Rectangle?))
            {
                editor = new RectanglePropertyEditor(_actions, _state, _factory, true);
            }
            else
            {
                var typeInfo = propType.GetTypeInfo();
                if (typeInfo.IsEnum)
                {
                    editor = new EnumPropertyEditor(_factory.UI, _actions);
                }
                else
                {
                    editor = new StringPropertyEditor(_factory, propType == typeof(string), _actions);
                }
            }

            ITreeStringNode node = new InspectorTreeNode(property, editor);

            return(addToTree(node, parent));
        }