Beispiel #1
0
        private GUIComponent CreateStringField(ISerializableEntity entity, SerializableProperty property, string value, int yPos, GUIComponent parent)
        {
            int boxHeight = 18;
            var editable  = property.GetAttribute <Editable>();

            boxHeight = (int)(Math.Ceiling(editable.MaxLength / 40.0f) * boxHeight);

            var label = new GUITextBlock(new Rectangle(0, yPos, 0, 18), property.Name, "", Alignment.TopLeft, Alignment.Left, parent, false, GUI.SmallFont);

            label.ToolTip = property.GetAttribute <Editable>().ToolTip;
            GUITextBox propertyBox = new GUITextBox(new Rectangle(0, yPos, 250, boxHeight), Alignment.Right, "", parent);

            propertyBox.ToolTip = editable.ToolTip;
            propertyBox.Font    = GUI.SmallFont;

            propertyBox.Text           = value;
            propertyBox.OnEnterPressed = (textBox, text) =>
            {
                if (property.TrySetValue(text))
                {
                    TrySendNetworkUpdate(entity, property);
                    textBox.Text = (string)property.GetValue();
                    textBox.Deselect();
                }
                return(true);
            };

            return(propertyBox);
        }
Beispiel #2
0
        private GUIComponent CreateEnumField(ISerializableEntity entity, SerializableProperty property, object value, int yPos, GUIComponent parent)
        {
            var label = new GUITextBlock(new Rectangle(0, yPos, 0, 18), property.Name, "", Alignment.TopLeft, Alignment.Left, parent, false, GUI.SmallFont);

            label.ToolTip = property.GetAttribute <Editable>().ToolTip;
            GUIDropDown enumDropDown = new GUIDropDown(new Rectangle(180, yPos, 0, 18), "", "", Alignment.TopLeft, parent);

            enumDropDown.ToolTip = property.GetAttribute <Editable>().ToolTip;

            foreach (object enumValue in Enum.GetValues(value.GetType()))
            {
                var enumTextBlock = new GUITextBlock(new Rectangle(0, 0, 200, 25), enumValue.ToString(), "", enumDropDown);
                enumTextBlock.UserData = enumValue;
            }

            enumDropDown.OnSelected += (selected, val) =>
            {
                if (property.TrySetValue(val))
                {
                    TrySendNetworkUpdate(entity, property);
                }
                return(true);
            };

            enumDropDown.SelectItem(value);

            return(enumDropDown);
        }
Beispiel #3
0
        private GUIComponent CreateFloatField(ISerializableEntity entity, SerializableProperty property, float value, int yPos, GUIComponent parent)
        {
            var label = new GUITextBlock(new Rectangle(0, yPos, 0, 18), property.Name, "", Alignment.TopLeft, Alignment.Left, parent, false, GUI.SmallFont);

            label.ToolTip = property.GetAttribute <Editable>().ToolTip;
            GUINumberInput numberInput = new GUINumberInput(new Rectangle(180, yPos, 0, 18), "", GUINumberInput.NumberType.Float, Alignment.Left, parent);

            numberInput.ToolTip = property.GetAttribute <Editable>().ToolTip;
            numberInput.Font    = GUI.SmallFont;

            var editableAttribute = property.GetAttribute <Editable>();

            numberInput.MinValueFloat = editableAttribute.MinValueFloat;
            numberInput.MaxValueFloat = editableAttribute.MaxValueFloat;

            numberInput.FloatValue = value;

            numberInput.OnValueChanged += (numInput) =>
            {
                if (property.TrySetValue(numInput.FloatValue))
                {
                    TrySendNetworkUpdate(entity, property);
                }
            };

            return(numberInput);
        }
Beispiel #4
0
        private GUIComponent CreateRectangleField(ISerializableEntity entity, SerializableProperty property, Rectangle value, int yPos, GUIComponent parent)
        {
            var label = new GUITextBlock(new Rectangle(0, yPos, 0, 18), property.Name, "", Alignment.TopLeft, Alignment.Left, parent, false, GUI.SmallFont);

            label.ToolTip = property.GetAttribute <Editable>().ToolTip;
            for (int i = 0; i < 4; i++)
            {
                new GUITextBlock(new Rectangle(140 + i * 70, yPos, 100, 18), rectComponentLabels[i], "", Alignment.TopLeft, Alignment.CenterLeft, parent, false, GUI.SmallFont);
                GUINumberInput numberInput = new GUINumberInput(new Rectangle(160 + i * 70, yPos, 45, 18), "", GUINumberInput.NumberType.Int, Alignment.Left, parent);
                numberInput.Font = GUI.SmallFont;

                if (i == 0)
                {
                    numberInput.IntValue = value.X;
                }
                else if (i == 1)
                {
                    numberInput.IntValue = value.Y;
                }
                else if (i == 2)
                {
                    numberInput.IntValue = value.Width;
                }
                else
                {
                    numberInput.IntValue = value.Height;
                }

                int comp = i;
                numberInput.OnValueChanged += (numInput) =>
                {
                    Rectangle newVal = (Rectangle)property.GetValue();
                    if (comp == 0)
                    {
                        newVal.X = numInput.IntValue;
                    }
                    else if (comp == 1)
                    {
                        newVal.Y = numInput.IntValue;
                    }
                    else if (comp == 2)
                    {
                        newVal.Width = numInput.IntValue;
                    }
                    else
                    {
                        newVal.Height = numInput.IntValue;
                    }

                    if (property.TrySetValue(newVal))
                    {
                        TrySendNetworkUpdate(entity, property);
                    }
                };
            }

            return(label);
        }
Beispiel #5
0
        private GUIComponent CreateBoolField(ISerializableEntity entity, SerializableProperty property, bool value, int yPos, GUIComponent parent)
        {
            GUITickBox propertyTickBox = new GUITickBox(new Rectangle(10, yPos, 18, 18), property.Name, Alignment.Left, parent);

            propertyTickBox.Font     = GUI.SmallFont;
            propertyTickBox.Selected = value;
            propertyTickBox.ToolTip  = property.GetAttribute <Editable>().ToolTip;

            propertyTickBox.OnSelected = (tickBox) =>
            {
                if (property.TrySetValue(tickBox.Selected))
                {
                    TrySendNetworkUpdate(entity, property);
                }
                return(true);
            };

            return(propertyTickBox);
        }
Beispiel #6
0
        private GUIComponent CreateColorField(ISerializableEntity entity, SerializableProperty property, Color value, int yPos, GUIComponent parent)
        {
            var label = new GUITextBlock(new Rectangle(0, yPos, 0, 18), property.Name, "", Alignment.TopLeft, Alignment.Left, parent, false, GUI.SmallFont);

            label.ToolTip = property.GetAttribute <Editable>().ToolTip;

            var colorBoxBack = new GUIFrame(new Rectangle(110 - 1, yPos - 1, 25 + 2, 18 + 2), Color.Black, Alignment.TopLeft, null, parent);
            var colorBox     = new GUIFrame(new Rectangle(110, yPos, 25, 18), value, Alignment.TopLeft, null, parent);

            for (int i = 0; i < 4; i++)
            {
                new GUITextBlock(new Rectangle(140 + i * 70, yPos, 100, 18), colorComponentLabels[i], "", Alignment.TopLeft, Alignment.CenterLeft, parent, false, GUI.SmallFont);
                GUINumberInput numberInput = new GUINumberInput(new Rectangle(160 + i * 70, yPos, 45, 18), "", GUINumberInput.NumberType.Int, Alignment.Left, parent);
                numberInput.MinValueInt = 0;
                numberInput.MaxValueInt = 255;

                if (i == 0)
                {
                    numberInput.IntValue = value.R;
                }
                else if (i == 1)
                {
                    numberInput.IntValue = value.G;
                }
                else if (i == 2)
                {
                    numberInput.IntValue = value.B;
                }
                else
                {
                    numberInput.IntValue = value.A;
                }

                numberInput.Font = GUI.SmallFont;

                int comp = i;
                numberInput.OnValueChanged += (numInput) =>
                {
                    Color newVal = (Color)property.GetValue();
                    if (comp == 0)
                    {
                        newVal.R = (byte)(numInput.IntValue);
                    }
                    else if (comp == 1)
                    {
                        newVal.G = (byte)(numInput.IntValue);
                    }
                    else if (comp == 2)
                    {
                        newVal.B = (byte)(numInput.IntValue);
                    }
                    else
                    {
                        newVal.A = (byte)(numInput.IntValue);
                    }

                    if (property.TrySetValue(newVal))
                    {
                        TrySendNetworkUpdate(entity, property);
                        colorBox.Color = newVal;
                    }
                };
            }

            return(label);
        }