Exemple #1
0
        public TempleState()
            : base("Temple")
        {
            MainWindow.Width  = 650;
            MainWindow.Height = 400;

            // Background:
            MainWindow.InnerShadow       = true;
            MainWindow.Background.Align  = GuiAlignment.None;
            MainWindow.Background.Sprite = ResourceManager.GetSprite("Backgrounds/TownTemple");
            MainWindow.Background.Color  = Color.white;
            MainWindow.Background.BestFit(MainWindow.ContentsFrame, true);
            MainWindow.PositionComponent(MainWindow.Background, 0, 0);

            // Bodies list:
            deadCharactersList = new GuiListBox <MDRCharacter>(0, 0, 250, 200);
            var deadCharactersListFrame = GuiWindow.CreateFrame(deadCharactersList, "Characters");

            deadCharactersListFrame.Style            = Engine.GetStyleCopy("Box50");
            deadCharactersListFrame.Background.Color = Colors.BackgroundYellow.Faded(0.75f);
            MainWindow.Add(deadCharactersListFrame, 10, 0);

            noDeadCharacters            = new GuiLabel("There are no dead\ncharacters here.", 250);
            noDeadCharacters.TextAlign  = TextAnchor.MiddleCenter;
            noDeadCharacters.DropShadow = true;
            MainWindow.Add(noDeadCharacters, 10, 150);

            // Info:
            raiseInfo               = new GuiLabel(0, 0, "", 300, 200);
            raiseInfo.WordWrap      = true;
            raiseInfo.Color         = new Color(0.9f, 0.9f, 0.9f, 0.9f);
            raiseInfo.Style.padding = new RectOffset(10, 10, 10, 4);
            var raiseInfoFrame = GuiWindow.CreateFrame(raiseInfo, "Details");

            raiseInfoFrame.Style            = Engine.GetStyleCopy("Box50");
            raiseInfoFrame.Background.Color = Color.white.Faded(0.75f);
            MainWindow.Add(raiseInfoFrame, (int)deadCharactersList.Bounds.xMax + 40, (int)deadCharactersList.Bounds.yMin);

            // Buttons:
            raiseCharacterButton = new GuiButton("Raise", 120);
            MainWindow.Add(raiseCharacterButton, raiseInfoFrame.X + 70, (int)raiseInfoFrame.Bounds.yMax + 5);

            costLabel = new GuiCoinAmount();

            MainWindow.Add(costLabel, (int)raiseCharacterButton.Bounds.xMax + 20, raiseCharacterButton.Y + 3);

            // Triggers
            deadCharactersList.OnSelectedChanged += delegate {
                doUpdateRaiseInfo();
            };
            PopulateDeadCharacterList();

            raiseCharacterButton.OnMouseClicked += delegate {
                if (deadCharactersList.Selected != null)
                {
                    doRaiseCharacter(deadCharactersList.Selected);
                }
            };

            RepositionControls();
        }
Exemple #2
0
        /**
         * Creates ui elements to configure each settings in given group.
         *
         * Returns a GuiComponent containing the controls.
         */
        private GuiComponent CreateUIFromSettingsGroup(SettingsGroup group)
        {
            GuiContainer result = new GuiScrollableArea(WINDOW_WIDTH - 50, WINDOW_HEIGHT - 150)
            {
                Y = 50
            };

            result.Name = group.Name;

            int atY = 10;

            var binding = (BindingFlags.Public |
                           BindingFlags.NonPublic |
                           BindingFlags.Instance |
                           BindingFlags.DeclaredOnly);

            foreach (var property in group.GetType().GetProperties(binding))
            {
                var attribute = getAttribute <SettingAttribute>(property, SettingAttribute.Default);
                var divider   = getAttribute <SettingDivider>(property);

                // filter out some properties
                if (property.Name == "Item")
                {
                    continue;
                }
                if (!property.CanRead)
                {
                    continue;
                }
                if (attribute.Ignore)
                {
                    continue;
                }

                GuiLabeledComponent control = CreateControl(group, property);
                if (control == null)
                {
                    Trace.Log("No suitable control found for property " + property.Name + " of type " + property.PropertyType);
                    continue;
                }

                if (group.isDisabled(property.Name))
                {
                    if (control is GuiToggleButton)
                    {
                        (control as GuiToggleButton).Value = false;
                    }
                    control.SelfEnabled = false;
                }

                if (divider != null)
                {
                    string dividerText    = divider.Name;
                    var    dividerControl = new GuiLabel(dividerText);
                    dividerControl.TextAlign = TextAnchor.MiddleLeft;
                    dividerControl.FontColor = new Color(0.75f, 0.75f, 0.75f);
                    result.Add(dividerControl, 20, atY + 3);
                    atY += (dividerText == "") ? 5 : 30;
                }

                // apply attributes
                if (control.Enabled)
                {
                    control.LabelColor = attribute.Color;
                }
                else
                {
                    control.LabelColor = Color.Lerp(attribute.Color, Color.gray, 0.75f);
                }

                control.LabelText = attribute.DisplayName ?? property.Name;

                result.Add(control, 200, atY);

                int spacing = Util.ClampInt(control.Height + 10, 30, 999);
                atY += spacing;
            }

            result.FitToChildren();

            result = GuiWindow.CreateFrame(result);
            (result as GuiWindow).WindowStyle = GuiWindowStyle.Transparent;
            result.Color = new Color(0.25f, 0.25f, 0.25f, 0.5f);
            result.FitToChildren();
            result.Width = WINDOW_WIDTH - 40;

            return(result);
        }