public MultiplayerAddEditServerState(string serverType, string name, string address,
                                             Action <AddOrEditCallback> callbackAction,
                                             GuiPanoramaSkyBox skyBox) :
            base(callbackAction)
        {
            _serverTypeManager = GetService <ServerTypeManager>();
            _skyBox            = skyBox;

            Title = "Add Server";
            TitleTranslationKey = "addServer.title";

            base.HeaderTitle.Anchor    = Alignment.MiddleCenter;
            base.HeaderTitle.FontStyle = FontStyle.Bold | FontStyle.DropShadow;
            Body.BackgroundOverlay     = new Color(Color.Black, 0.5f);

            Body.ChildAnchor = Alignment.MiddleCenter;

            var usernameRow = AddGuiRow(new GuiTextElement()
            {
                Text           = "Server Name:",
                TranslationKey = "addServer.enterName",
                Margin         = new Thickness(0, 0, 5, 0)
            }, _nameInput = new GuiTextInput()
            {
                TabIndex = 1,

                Width = 200,

                PlaceHolder = "Name of the server",
                Margin      = new Thickness(23, 5, 5, 5),
            });

            usernameRow.ChildAnchor = Alignment.MiddleCenter;
            usernameRow.Orientation = Orientation.Horizontal;

            var hostnameRow = AddGuiRow(new GuiTextElement()
            {
                Text           = "Server Address:",
                TranslationKey = "addServer.enterIp",
                Margin         = new Thickness(0, 0, 5, 0)
            }, _hostnameInput = new GuiTextInput()
            {
                TabIndex = 2,

                Width = 200,

                PlaceHolder = "Hostname or IP",
                Margin      = new Thickness(5),
            });

            hostnameRow.ChildAnchor = Alignment.MiddleCenter;
            hostnameRow.Orientation = Orientation.Horizontal;

            var typeLabelRow = AddGuiRow(_serverTypeLabel = new GuiTextElement()
            {
                Text   = "Server Type:",
                Margin = new Thickness(0, 0, 5, 0)
            });

            typeLabelRow.ChildAnchor = Alignment.MiddleCenter;
            typeLabelRow.Orientation = Orientation.Horizontal;

            AddGuiRow(_serverTypeGroup = new GuiButtonGroup()
            {
                Orientation = Orientation.Horizontal,
                ChildAnchor = Alignment.MiddleCenter
            });

            int tabIndex = 3;

            foreach (var type in _serverTypeManager.GetAll())
            {
                if (_selectedImplementation == null)
                {
                    _selectedImplementation = type;
                }

                GuiToggleButton element;
                _serverTypeGroup.AddChild(
                    element = new GuiToggleButton(type.DisplayName)
                {
                    Margin  = new Thickness(5),
                    Modern  = true,
                    Width   = 50,
                    Checked = serverType == type.Id,
                    CheckedOutlineThickness = new Thickness(1),
                    DisplayFormat           = new ValueFormatter <bool>((val) => $"{type.DisplayName} {(val ? "[Active]" : "")}"),
                    TabIndex = tabIndex++
                });

                element.ValueChanged += (sender, value) =>
                {
                    if (value)
                    {
                        _selectedImplementation = type;
                    }
                };
            }

            var buttonRow = AddGuiRow(_saveButton = new GuiButton(OnSaveButtonPressed)
            {
                AccessKey = Keys.Enter,

                TranslationKey = "addServer.add",
                Margin         = new Thickness(5),
                Modern         = false,
                Width          = 100,
                TabIndex       = 5
            }, new GuiButton(OnCancelButtonPressed)
            {
                AccessKey = Keys.Escape,

                TranslationKey = "gui.cancel",
                Margin         = new Thickness(5),
                Modern         = false,
                Width          = 100,
                TabIndex       = 6
            });

            buttonRow.ChildAnchor = Alignment.MiddleCenter;


            AddGuiElement(_errorMessage = new GuiTextElement()
            {
                TextColor = TextColor.Red
            });

            if (!string.IsNullOrWhiteSpace(name))
            {
                _nameInput.Value = name;
            }

            if (!string.IsNullOrWhiteSpace(address))
            {
                _hostnameInput.Value = address;
            }

            if (_entry != null)
            {
                //EnableButtonsFor(_entry.ServerType);
            }

            Background = new GuiTexture2D(_skyBox, TextureRepeatMode.Stretch);
        }
Example #2
0
        /** Creates the UI componenets required to display the gui */
        private void CreateUIComponents()
        {
            var window = new GuiWindow(800, 560);

            window.Background.Sprite = ResourceManager.GetSprite("Gui/InnerWindow");
            window.Background.Color  = new Color(0.5f, 0.5f, 0.5f);
            PositionComponent(window, 0, 0);
            Add(window);

            // ------------------

            nameInput               = new GuiTextField(0, 0, 200);
            nameInput.Value         = CharacterNameGenerator.GenerateName();
            nameInput.LabelText     = "Name";
            nameInput.LabelPosition = LabelPosition.Left;
            window.Add(nameInput, 0, 20);

            var randomButton = new GuiButton("random", -1, 20);

            window.Add(randomButton, (int)nameInput.Bounds.xMax + 10, 25);

            // ------------------

            var genderListFrame = new FramedListBox <MDRGender>(200, 100, "Gender");

            window.Add(genderListFrame, 260, 100);

            portraitSelector          = new GuiPictureSeletor();
            portraitSelector.Pictures = CoM.Instance.Portraits.GetEntries().ToArray();
            window.Add(portraitSelector, 460, 70 + 18 + 20);

            allRacesToggle                 = new GuiToggleButton();
            allRacesToggle.LabelText       = "Show All";
            allRacesToggle.LabelPosition   = LabelPosition.Right;
            allRacesToggle.X               = (int)portraitSelector.Bounds.xMax + 10;
            allRacesToggle.Y               = (int)portraitSelector.Bounds.y + 30;
            allRacesToggle.Value           = false;
            allRacesToggle.OnValueChanged += delegate {
                updatePortraits();
            };
            window.Add(allRacesToggle);

            // ------------------

            var raceListFrame = new FramedListBox <MDRRace>(200, 240, "Race");

            window.Add(raceListFrame, 20, 240);

            statList = new GuiStatList(new MDRStats());
            window.Add(statList, 220 + 20, 240);

            var characterInfo = new GuiWindow(250, 240, "Info");

            window.Add(characterInfo, 470 + 40, 240);

            characterInfoText          = new GuiLabel(0, 0, "");
            characterInfoText.Align    = GuiAlignment.Full;
            characterInfoText.WordWrap = true;
            characterInfo.Add(characterInfoText);

            // ------------------

            // ------------------

            GuiButton cancelButton = new GuiButton("Cancel", 100);

            window.Add(cancelButton, 20, -20);

            GuiButton doneButton = new GuiButton("Save", 100);

            window.Add(doneButton, -20, -20);


            raceList = raceListFrame.ListBox;
            foreach (MDRRace race in CoM.Races)
            {
                raceList.Add(race);
            }

            genderList = genderListFrame.ListBox;
            genderList.Add(MDRGender.Male);
            genderList.Add(MDRGender.Female);

            genderList.OnSelectedChanged += delegate {
                updateGender();
            };
            raceList.OnSelectedChanged += delegate {
                updateRace();
            };

            doneButton.OnMouseClicked += delegate {
                if (statList.FreePoints != 0)
                {
                    Engine.ConfirmAction(saveAndClose, "This character still has " + Util.Colorise(statList.FreePoints, Color.green) + " stat points left to spend.\nAre you sure you want to save the character without spending them?");
                }
                else
                {
                    saveAndClose();
                }
            };

            cancelButton.OnMouseClicked += delegate {
                Engine.PopState();
            };
            randomButton.OnMouseClicked += delegate {
                nameInput.Value = CharacterNameGenerator.GenerateName();
            };

            updateRace();
            updateGender();
        }
Example #3
0
        public CustomFormDialog(uint formId, BedrockFormManager parent, CustomForm form, InputManager inputManager) : base(formId, parent, inputManager)
        {
            Container.AddChild(new GuiTextElement()
            {
                Anchor    = Alignment.TopCenter,
                Text      = form.Title,
                FontStyle = FontStyle.Bold,
                Scale     = 2f,
                TextColor = TextColor.White
            });

            Form = form;

            GuiScrollableStackContainer stackContainer = new GuiScrollableStackContainer();

            stackContainer.Orientation = Orientation.Vertical;
            stackContainer.Anchor      = Alignment.Fill;
            stackContainer.ChildAnchor = Alignment.MiddleFill;

            var margin = new Thickness(5, 5);

            foreach (var element in form.Content)
            {
                switch (element)
                {
                case Label label:
                {
                    stackContainer.AddChild(new GuiTextElement()
                        {
                            Text   = label.Text,
                            Margin = margin
                        });
                }
                break;

                case Input input:
                {
                    GuiTextInput guiInput = new GuiTextInput()
                    {
                        Value       = input.Value,
                        PlaceHolder = input.Placeholder,
                        Margin      = margin
                    };

                    guiInput.ValueChanged += (sender, s) => { input.Value = s; };

                    stackContainer.AddChild(guiInput);
                }
                break;

                case Toggle toggle:
                {
                    GuiToggleButton guiToggle;
                    stackContainer.AddChild(guiToggle = new GuiToggleButton(toggle.Text)
                        {
                            Margin = margin,
                            Value  = !toggle.Value
                        });

                    guiToggle.DisplayFormat = new ValueFormatter <bool>((val) =>
                        {
                            return($"{toggle.Text}: {val.ToString()}");
                        });

                    guiToggle.Value = toggle.Value;

                    guiToggle.ValueChanged += (sender, b) => { toggle.Value = b; };
                }
                break;

                case Slider slider:
                {
                    GuiSlider guiSlider;
                    stackContainer.AddChild(guiSlider = new GuiSlider()
                        {
                            Label        = { Text = slider.Text },
                            Value        = slider.Value,
                            MaxValue     = slider.Max,
                            MinValue     = slider.Min,
                            StepInterval = slider.Step,
                            Margin       = margin
                        });

                    guiSlider.ValueChanged += (sender, d) => { slider.Value = (float)d; };
                }
                break;

                case StepSlider stepSlider:
                {
                    stackContainer.AddChild(new GuiTextElement()
                        {
                            Text      = "Unsupported stepslider",
                            TextColor = TextColor.Red,
                            Margin    = margin
                        });
                }
                break;

                case Dropdown dropdown:
                {
                    stackContainer.AddChild(new GuiTextElement()
                        {
                            Text      = "Unsupported dropdown",
                            TextColor = TextColor.Red,
                            Margin    = margin
                        });
                }
                break;
                }
            }

            SubmitButton = new GuiButton("Submit", SubmitPressed);

            stackContainer.AddChild(SubmitButton);

            Container.AddChild(stackContainer);
        }
Example #4
0
        /** Create the store ui */
        //todo: remove sizes
        public GuiStore(MDRStore store, int width = 800, int height = 600)
            : base(width, height)
        {
            int splitWidth = (width / 2) + 50;

            const int HEADER_HEIGHT = 50;

            WindowStyle         = GuiWindowStyle.ThinTransparent;
            StoreSelectedItemID = -1;
            Store           = store;
            CanReceiveFocus = true;
            DragDropEnabled = true;

            // -----------------------------------------
            // Main areas

            var mainArea = new GuiContainer(0, (int)ContentsBounds.height - HEADER_HEIGHT);

            mainArea.Align = GuiAlignment.Bottom;

            // -----------------------------------------
            // Header

            var headerArea = new GuiContainer((int)ContentsBounds.width, HEADER_HEIGHT);

            headerArea.EnableBackground = true;
            headerArea.Style            = Engine.GetStyleCopy("Frame");
            headerArea.Y     -= 4;
            headerArea.X     -= 4;
            headerArea.Width += 8;

            modeButtons = new GuiRadioButtonGroup();
            modeButtons.AddItem("Buy");
            modeButtons.AddItem("Sell");
            modeButtons.ButtonSize       = new Vector2(120, 30);
            modeButtons.ButtonSpacing    = 50;
            modeButtons.EnableBackground = false;
            headerArea.Add(modeButtons, 0, 0, true);

            modeButtons.OnValueChanged += delegate {
                _mode = (StoreMode)modeButtons.SelectedIndex;
                updateStoreMode();
            };

            Add(headerArea);
            Add(mainArea);

            // -----------------------------------------
            // Item Info Area

            GuiPanel itemInfoPanel = new GuiPanel((int)ContentsBounds.width - splitWidth);

            itemInfoPanel.Align            = GuiAlignment.Right;
            itemInfoPanel.EnableBackground = false;
            mainArea.Add(itemInfoPanel, -1, 1, true);

            itemInfoBackground       = new GuiImage(0, 0, ResourceManager.GetSprite("Gui/InnerWindow"));
            itemInfoBackground.Align = GuiAlignment.Full;
            itemInfoBackground.Color = Colors.StoreItemInfoBackgroundColor;
            itemInfoPanel.Add(itemInfoBackground);

            SelectedItemInfo = new GuiItemToolTip();
            SelectedItemInfo.EnableBackground = false;
            SelectedItemInfo.Align            = GuiAlignment.Full;
            SelectedItemInfo.ShowAllInfo      = true;
            itemInfoPanel.Add(SelectedItemInfo);

            // -----------------------------------------
            // Item Buy Area

            buyItemArea       = new GuiContainer(splitWidth, (int)ContentsBounds.height);
            buyItemArea.Align = GuiAlignment.Left;
            mainArea.Add(buyItemArea);

            itemListingScrollArea = new GuiScrollableArea(buyItemArea.Width, buyItemArea.Height, ScrollMode.VerticalOnly);
            buyItemArea.Add(itemListingScrollArea);

            filterItemsToggle = new GuiToggleButton();
            filterItemsToggle.OnValueChanged += delegate {
                ShowOnlyUsableItems = filterItemsToggle.Value;
            };
            mainArea.Add(filterItemsToggle, -10, -10);
            filterItemsToggle.Visible = false;

            buyButton = new GuiButton("Buy");
            buyButton.OnMouseClicked += DoBuy;
            itemInfoPanel.Add(buyButton, 0, -30);

            notEnoughGold           = new GuiLabel("No enough coins");
            notEnoughGold.FontColor = new Color(0.5f, 0.5f, 0.5f, 0.9f);
            notEnoughGold.Visible   = false;
            itemInfoPanel.Add(notEnoughGold, 0, -56);

            // -----------------------------------------
            // item Sell area

            sellItemArea         = new GuiSellItemArea((int)mainArea.ContentsBounds.width - splitWidth, (int)mainArea.ContentsBounds.height, store);
            sellItemArea.Align   = GuiAlignment.Right;
            sellItemArea.OnSell += delegate {
                Mode = StoreMode.Buy;
            };
            mainArea.Add(sellItemArea);

            // -----------------------------------------

            CoM.Party.OnSelectedChanged += createStoreListings;
            store.OnInventoryChanged    += createStoreListings;

            updateStoreMode();
            createStoreListings();
        }
        public MultiplayerAddEditServerState(ServerType serverType, string name, string address,
                                             Action <SavedServerEntry> callbackAction,
                                             GuiPanoramaSkyBox skyBox) :
            base(callbackAction)
        {
            _savedServersStorage = GetService <IListStorageProvider <SavedServerEntry> >();
            _skyBox = skyBox;

            Title = "Add Server";
            TitleTranslationKey = "addServer.title";

            base.HeaderTitle.Anchor    = Alignment.MiddleCenter;
            base.HeaderTitle.FontStyle = FontStyle.Bold | FontStyle.DropShadow;
            Body.BackgroundOverlay     = new Color(Color.Black, 0.5f);

            Body.ChildAnchor = Alignment.MiddleCenter;

            var usernameRow = AddGuiRow(new GuiTextElement()
            {
                Text           = "Server Name:",
                TranslationKey = "addServer.enterName",
                Margin         = new Thickness(0, 0, 5, 0)
            }, _nameInput = new GuiTextInput()
            {
                TabIndex = 1,

                Width = 200,

                PlaceHolder = "Name of the server",
                Margin      = new Thickness(23, 5, 5, 5),
            });

            usernameRow.ChildAnchor = Alignment.MiddleCenter;
            usernameRow.Orientation = Orientation.Horizontal;

            var hostnameRow = AddGuiRow(new GuiTextElement()
            {
                Text           = "Server Address:",
                TranslationKey = "addServer.enterIp",
                Margin         = new Thickness(0, 0, 5, 0)
            }, _hostnameInput = new GuiTextInput()
            {
                TabIndex = 2,

                Width = 200,

                PlaceHolder = "Hostname or IP",
                Margin      = new Thickness(5),
            });

            hostnameRow.ChildAnchor = Alignment.MiddleCenter;
            hostnameRow.Orientation = Orientation.Horizontal;

            var typeLabelRow = AddGuiRow(_serverTypeLabel = new GuiTextElement()
            {
                Text   = "Server Type:",
                Margin = new Thickness(0, 0, 5, 0)
            });

            typeLabelRow.ChildAnchor = Alignment.MiddleCenter;
            typeLabelRow.Orientation = Orientation.Horizontal;

            AddGuiRow(_serverTypeGroup = new GuiButtonGroup()
            {
                Orientation = Orientation.Horizontal,
                ChildAnchor = Alignment.MiddleCenter
            });
            _serverTypeGroup.AddChild(_javaEditionButton = new GuiToggleButton("Java")
            {
                Margin  = new Thickness(5),
                Modern  = true,
                Width   = 50,
                Checked = serverType == ServerType.Java,
                CheckedOutlineThickness = new Thickness(1),
                DisplayFormat           = new ValueFormatter <bool>((val) => $"Java {(val ? "[Active]" : "")}"),
                TabIndex = 3
            });
            _serverTypeGroup.AddChild(_bedrockEditionButton = new GuiToggleButton("Bedrock")
            {
                Margin  = new Thickness(5),
                Modern  = true,
                Width   = 50,
                Checked = serverType == ServerType.Bedrock,
                CheckedOutlineThickness = new Thickness(1),
                DisplayFormat           = new ValueFormatter <bool>((val) => $"Bedrock {(val ? "[Active]" : "")}"),
                TabIndex = 4
            });

            //	var portRow = AddGuiRow();
            //  portRow.ChildAnchor = Alignment.MiddleCenter;

            var buttonRow = AddGuiRow(_saveButton = new GuiButton(OnSaveButtonPressed)
            {
                AccessKey = Keys.Enter,

                TranslationKey = "addServer.add",
                Margin         = new Thickness(5),
                Modern         = false,
                Width          = 100,
                TabIndex       = 5
            }, new GuiButton(OnCancelButtonPressed)
            {
                AccessKey = Keys.Escape,

                TranslationKey = "gui.cancel",
                Margin         = new Thickness(5),
                Modern         = false,
                Width          = 100,
                TabIndex       = 6
            });

            buttonRow.ChildAnchor = Alignment.MiddleCenter;


            AddGuiElement(_errorMessage = new GuiTextElement()
            {
                TextColor = TextColor.Red
            });

            if (!string.IsNullOrWhiteSpace(name))
            {
                _nameInput.Value = name;
            }

            if (!string.IsNullOrWhiteSpace(address))
            {
                _hostnameInput.Value = address;
            }

            if (_entry != null)
            {
                //EnableButtonsFor(_entry.ServerType);
            }

            Background = new GuiTexture2D(_skyBox, TextureRepeatMode.Stretch);
        }
Example #6
0
        public CustomFormDialog(uint formId, BedrockFormManager parent, CustomForm form, InputManager inputManager) : base(formId, parent, inputManager)
        {
            Form = form;

            GuiScrollableStackContainer stackContainer = new GuiScrollableStackContainer();

            stackContainer.Orientation = Orientation.Vertical;
            stackContainer.Anchor      = Alignment.Fill;
            stackContainer.ChildAnchor = Alignment.MiddleFill;
            stackContainer.Background  = Color.Black * 0.35f;
            var margin = new Thickness(5, 5);

            foreach (var element in form.Content)
            {
                switch (element)
                {
                case Label label:
                {
                    stackContainer.AddChild(new GuiTextElement()
                        {
                            Text   = label.Text,
                            Margin = margin
                        });
                }
                break;

                case Input input:
                {
                    GuiTextInput guiInput = new GuiTextInput()
                    {
                        Value       = input.Value,
                        PlaceHolder = !string.IsNullOrWhiteSpace(input.Placeholder) ? input.Placeholder : input.Text,
                        Margin      = margin
                    };

                    guiInput.ValueChanged += (sender, s) => { input.Value = s; };

                    stackContainer.AddChild(guiInput);
                }
                break;

                case Toggle toggle:
                {
                    GuiToggleButton guiToggle;
                    stackContainer.AddChild(guiToggle = new GuiToggleButton(toggle.Text)
                        {
                            Margin = margin,
                            Value  = !toggle.Value
                        });

                    guiToggle.DisplayFormat = new ValueFormatter <bool>((val) =>
                        {
                            return($"{toggle.Text}: {val.ToString()}");
                        });

                    guiToggle.Value = toggle.Value;

                    guiToggle.ValueChanged += (sender, b) => { toggle.Value = b; };
                }
                break;

                case Slider slider:
                {
                    GuiSlider guiSlider;
                    stackContainer.AddChild(guiSlider = new GuiSlider()
                        {
                            Label        = { Text = slider.Text },
                            Value        = slider.Value,
                            MaxValue     = slider.Max,
                            MinValue     = slider.Min,
                            StepInterval = slider.Step,
                            Margin       = margin
                        });

                    guiSlider.ValueChanged += (sender, d) => { slider.Value = (float)d; };
                }
                break;

                case StepSlider stepSlider:
                {
                    stackContainer.AddChild(new GuiTextElement()
                        {
                            Text      = "Unsupported stepslider",
                            TextColor = TextColor.Red,
                            Margin    = margin
                        });
                }
                break;

                case Dropdown dropdown:
                {
                    stackContainer.AddChild(new GuiTextElement()
                        {
                            Text      = "Unsupported dropdown",
                            TextColor = TextColor.Red,
                            Margin    = margin
                        });
                }
                break;
                }
            }

            SubmitButton = new GuiButton("Submit", SubmitPressed);

            stackContainer.AddChild(SubmitButton);

            Background = Color.Transparent;

            var width  = 356;
            var height = width;

            ContentContainer.Width  = ContentContainer.MinWidth = ContentContainer.MaxWidth = width;
            ContentContainer.Height = ContentContainer.MinHeight = ContentContainer.MaxHeight = height;

            SetFixedSize(width, height);

            ContentContainer.AutoSizeMode = AutoSizeMode.None;

            Container.Anchor = Alignment.MiddleCenter;

            var bodyWrapper = new GuiContainer();

            bodyWrapper.Anchor  = Alignment.Fill;
            bodyWrapper.Padding = new Thickness(5, 0);
            bodyWrapper.AddChild(stackContainer);

            Container.AddChild(bodyWrapper);

            Container.AddChild(Header = new GuiStackContainer()
            {
                Anchor      = Alignment.TopFill,
                ChildAnchor = Alignment.BottomCenter,
                Height      = 32,
                Padding     = new Thickness(3),
                Background  = Color.Black * 0.5f
            });

            Header.AddChild(new GuiTextElement()
            {
                Text      = FixContrast(form.Title),
                TextColor = TextColor.White,
                Scale     = 2f,
                FontStyle = FontStyle.DropShadow,

                Anchor = Alignment.BottomCenter,
            });

            stackContainer.Margin = new Thickness(0, Header.Height, 0, 0);
        }
Example #7
0
        /**
         * Creates a control for given property.
         *
         * ToggleButtons will be used for boolean properties.
         * For the moment other types of properties are not supported.
         *
         * @param source The source object this property belongs to.
         * @param property The property to create a control for.
         */
        private GuiLabeledComponent CreateControl(object source, PropertyInfo property)
        {
            GuiLabeledComponent result = null;

            var rangeAttribute = getAttribute <SettingRange>(property);

            if (property.PropertyType == typeof(System.Boolean))
            {
                var toggleButton = new GuiToggleButton();
                toggleButton.Value = (bool)property.GetValue(source, null);
                if (property.CanWrite)
                {
                    toggleButton.OnValueChanged += delegate {
                        property.SetValue(source, toggleButton.Value, null);
                    }
                }
                ;
                result = toggleButton;
            }
            else if (property.PropertyType.IsEnum)
            {
                var radioGroup = new GuiRadioButtonGroup();

                radioGroup.EnableBackground = false;
                radioGroup.ButtonSpacing    = 2;
                radioGroup.ButtonSize       = new Vector2(80, 32);

                var enumNames = Enum.GetNames(property.PropertyType);
                foreach (string enumValueName in enumNames)
                {
                    if (!enumValueName.StartsWith("_"))
                    {
                        radioGroup.AddItem(enumValueName);
                    }
                }

                radioGroup.SelectedIndex = (int)property.GetValue(source, null);

                if (property.CanWrite)
                {
                    radioGroup.OnValueChanged += delegate {
                        property.SetValue(source, radioGroup.SelectedIndex, null);
                    };
                }

                result = radioGroup;
            }
            else if (property.PropertyType == typeof(System.Single) && (rangeAttribute != null))
            {
                var slider = new GuiSlider();
                slider.Min   = rangeAttribute.Min;
                slider.Max   = rangeAttribute.Max;
                slider.Value = (float)property.GetValue(source, null);
                if (property.CanWrite)
                {
                    slider.OnValueChanged += delegate {
                        property.SetValue(source, slider.Value, null);
                    }
                }
                ;
                result = slider;
            }
            else if (
                // fallback to edit box
                (property.PropertyType == typeof(int)) ||
                (property.PropertyType == typeof(float)) ||
                (property.PropertyType == typeof(string)))
            {
                int editWidth = (property.PropertyType == typeof(string)) ? 325 : 60;

                var editBox = new GuiTextField(0, 0, editWidth);

                object propertyValue = property.GetValue(source, null);
                if (propertyValue != null)
                {
                    editBox.Value = propertyValue.ToString();
                    if (editBox.Value.Length > 35)
                    {
                        editBox.FontSize = 12;
                    }
                    if (editBox.Value.Length > 55)
                    {
                        editBox.FontSize = 10;
                    }
                    if (editBox.Value.Length > 75)
                    {
                        editBox.FontSize = 8;
                    }
                }

                if (property.CanWrite)
                {
                    editBox.OnValueChanged += delegate {
                        if (property.PropertyType == typeof(int))
                        {
                            property.SetValue(source, Util.ParseIntDefault(editBox.Value, 0), null);
                        }
                        else if (property.PropertyType == typeof(float))
                        {
                            property.SetValue(source, Util.ParseFloatDefault(editBox.Value, 0), null);
                        }
                        else if (property.PropertyType == typeof(string))
                        {
                            property.SetValue(source, editBox.Value, null);
                        }
                    }
                }
                ;

                result = editBox;
            }

            if (result != null)
            {
                if (!property.CanWrite)
                {
                    result.SelfEnabled = false;
                }
                result.LabelText     = property.Name;
                result.LabelPosition = LabelPosition.Left;
                result.Name          = property.Name;
            }


            return(result);
        }