コード例 #1
0
        public LibraryState()
            : base("Library")
        {
            Util.Assert(CoM.AllDataLoaded, "Data must be loaded before LibraryState can be created.");

            MainWindow.Width  = 600;
            MainWindow.Height = 480;

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

            ItemsWindow    = new LibraryItemsView();
            MonstersWindow = new LibraryMonstersView();
            RecordsWindow  = new LibraryRecordsView();

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

            var buttonGroup = new GuiRadioButtonGroup();

            buttonGroup.EnableBackground = true;

            buttonGroup.OnValueChanged += delegate {
                ItemsWindow.Visible    = buttonGroup.SelectedIndex == 0;
                MonstersWindow.Visible = buttonGroup.SelectedIndex == 1;
                RecordsWindow.Visible  = buttonGroup.SelectedIndex == 2;
            };

            buttonGroup.AddItem("Items");
            buttonGroup.AddItem("Monsters");
            buttonGroup.AddItem("Records");
            buttonGroup.ButtonSize = new Vector2(120, 28);
            buttonGroup.Height     = 45;
            buttonGroup.Style      = Engine.GetStyleCopy("Solid");
            buttonGroup.Color      = Color.black.Faded(0.5f);
            buttonGroup.Width      = MainWindow.Width;
            buttonGroup.Height     = 45;
            MainWindow.Add(buttonGroup);

            buttonGroup.SelectedIndex = 0;

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

            var BodySection = new GuiContainer(MainWindow.Width, MainWindow.Height - buttonGroup.Height)
            {
                Y = buttonGroup.Height
            };

            MainWindow.Add(BodySection);

            BodySection.Add(ItemsWindow);
            BodySection.Add(MonstersWindow);
            BodySection.Add(RecordsWindow);

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

            RepositionControls();

            MainWindow.Background.Sprite = ResourceManager.GetSprite("Gui/InnerWindow");
            MainWindow.Background.Color  = new Color(0.4f, 0.42f, 0.62f);
        }
コード例 #2
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();
        }
コード例 #3
0
        public SettingsMenuState() : base("Settings Menu")
        {
            TransparentDraw = true;

            MainWindow = new GuiWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Settings");
            Add(MainWindow, 0, 0);

            var buttonsGroup = new GuiRadioButtonGroup();

            buttonsGroup.AddItem("General");
            if (Settings.Advanced.PowerMode)
            {
                buttonsGroup.AddItem("Advanced");
            }
            if (Settings.Advanced.PowerMode)
            {
                buttonsGroup.AddItem("Information");
            }
            buttonsGroup.OnValueChanged += delegate {
                switch (buttonsGroup.SelectedIndex)
                {
                case 0:
                    setSettingsGroup(generalGroup);
                    break;

                case 1:
                    setSettingsGroup(advancedGroup);
                    break;

                case 2:
                    setSettingsGroup(informationGroup);
                    break;
                }
            };
            buttonsGroup.EnableBackground = false;
            buttonsGroup.Align            = GuiAlignment.Top;
            MainWindow.Add(buttonsGroup);

            var closeButton = new GuiButton("Close");

            MainWindow.Add(closeButton, -10, -10);

            var resetButton = new GuiButton("Reset");

            MainWindow.Add(resetButton, 10, -10);

            CreateSettingsControls();

            previousSoundFXLevel = Settings.General.SoundFXVolume;

            closeButton.OnMouseClicked += delegate {
                Engine.PopState();
            };
            resetButton.OnMouseClicked += delegate {
                Engine.ConfirmAction(Settings.ResetSettings, "Are you sure you want to reset the settings?");
            };

            Settings.Advanced.OnValueChanged += UpdateControls;
            Settings.General.OnValueChanged  += UpdateControls;

            setSettingsGroup(generalGroup);
        }
コード例 #4
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);
        }