Example #1
0
        public void UpdateSelectList(SelectList list, PublicGameInfo[] games)
        {
            var selection  = list.SelectedValue;
            var scrollPos  = list.ScrollPosition;
            var isFocussed = list.IsFocused;

            list.ClearItems();
            if (games.Length == 0)
            {
                list.AddItem("[No games found]");
            }
            else
            {
                foreach (PublicGameInfo g in games)
                {
                    list.AddItem(g.Name);
                }
            }

            try
            {
                list.ScrollPosition = scrollPos;
                if (isFocussed)
                {
                    GeonBit.UI.UserInterface.ActiveEntity = list;
                }
                list.SelectedValue = selection;
            }
            catch (System.Exception e)
            {
                list.SelectedIndex = 0;
            }
        }
Example #2
0
        protected override void Initialize()
        {
            base.Initialize();

            UserInterface.Initialize(Content, BuiltinThemes.editor);
            //UserInterface.Active.UseRenderTarget = true;
            //Panel panel = new Panel(new Vector2(graphics.PreferredBackBufferHeight, graphics.PreferredBackBufferHeight), anchor: Anchor.CenterRight);
            //panel.PanelOverflowBehavior = PanelOverflowBehavior.VerticalScroll;
            //UserInterface.Active.AddEntity(panel);
            SelectList list = new SelectList(new Vector2(graphics.PreferredBackBufferHeight, graphics.PreferredBackBufferHeight), anchor: Anchor.CenterRight);

            UserInterface.Active.AddEntity(list);

            var directory = new DirectoryInfo($"{Content.RootDirectory}/roms/");

            foreach (var file in directory.GetFiles("*.*"))
            {
                list.AddItem(file.Name);
            }
            list.SelectedIndex  = 0;
            list.OnValueChange += e => StartRom(list.SelectedValue);

            chip = new Chip8();
            chip.LoadGame(program);
            chipSound    = new ChipSound();
            chipInput    = new ChipInput();
            chipRenderer = new ChipRenderer(Chip8.ScreenWidth, Chip8.ScreenHeight, 512, 256, GraphicsDevice);
        }
Example #3
0
        public LoadFilePopUp(string directory, string extension = "*", Action <string> load = null) : base("Load Map")
        {
            Extension       = extension;
            SearchDirectory = directory;
            _loadListBox    = new SelectList(new Vector2(-1, -1), Anchor.AutoCenter, null, PanelSkin.Simple);
            foreach (var mapFile in Directory.GetFiles(directory, extension))
            {
                _loadListBox.AddItem(Path.GetFileNameWithoutExtension(mapFile));
            }
            if (!_loadListBox.Empty)
            {
                _loadListBox.SelectedIndex = 0;
            }
            Panel.AddChild(_loadListBox);

            var cancelButton = new Button("Cancel", ButtonSkin.Default, Anchor.BottomLeft, new Vector2(0.5f, -1));

            cancelButton.OnClick += entity => {
                Hide();
                Parent?.Show();
            };
            Panel.AddChild(cancelButton);
            var loadButton = new Button("Load", ButtonSkin.Default, Anchor.BottomRight, new Vector2(0.5f, -1));

            loadButton.OnClick += entity => {
                Task.Run(
                    () => {
                    load?.Invoke(_loadListBox.SelectedValue);
                    MessageBox.ShowMsgBox("Map Loaded", $"Map \"{_loadListBox.SelectedValue}\" Loaded", new[] { new MessageBox.MsgBoxOption("OK", () => true) }, null, null, () => Hide());
                });
            };
            Panel.AddChild(loadButton);
        }
Example #4
0
 public void UpdatePlayerList(object sender, LobbyPlayerList list)
 {
     PlayerList.ClearItems();
     foreach (var name in list.PlayerNames)
     {
         PlayerList.AddItem(name);
     }
 }
Example #5
0
 public override void Show()
 {
     _saveListbox.ClearItems();
     foreach (var mapFile in Directory.GetFiles(SearchDirectory, Extension))
     {
         _saveListbox.AddItem(Path.GetFileNameWithoutExtension(mapFile));
     }
     _saveInput.IsFocused = true;
     base.Show();
 }
Example #6
0
        private void AddLevelsList(Panel levelPanel, KeyValuePair <string, List <string> > serie)
        {
            SelectList levelsList = new SelectList(new Vector2(0, 300));

            foreach (var level in serie.Value)
            {
                levelsList.AddItem(level);
            }

            levelsList.OnValueChange = (Entity entity) =>
            {
                var loader    = new LevelLoader();
                var serieName = serie.Key;
                var levelName = levelsList.SelectedValue;
                loader.Load(new Level(serieName, levelName));
                var data = new HashSet <GameObject>();
                data.UnionWith(loader.Walls);
                data.UnionWith(loader.Boxes);
                data.UnionWith(loader.CellsForBoxes);
                data.Add(loader.Storekeeper);

                previewLevel = new Field(data, loader.Size, content.BlocksTextures);
                var startPoint  = new Point(graphics.PreferredBackBufferWidth / 2 - 100, graphics.PreferredBackBufferHeight / 4);
                var sizeOfField = new Point(graphics.PreferredBackBufferWidth / 2, graphics.PreferredBackBufferHeight / 2);
                previewLevel.Init(startPoint, sizeOfField);
            };
            levelPanel.AddChild(levelsList);
            AddButton(levelPanel, "Start",
                      (Entity btn) =>
            {
                if (levelsList.SelectedValue == null)
                {
                    return;
                }
                seriesPanel.Visible = false;
                levelPanel.Visible  = false;
                var serieName       = serie.Key;
                var levelName       = levelsList.SelectedValue;
                gameModel.LoadLevel(new Level(serieName, levelName));
                GameStart?.Invoke();
                previewLevel = null;
            });
            levelPanel.AddChild(new HorizontalLine());
            AddButton(levelPanel, "Back",
                      (Entity btn) =>
            {
                seriesPanel.Visible = true;
                levelPanel.Visible  = false;
                previewLevel        = null;
            });
        }
Example #7
0
 public override void Show()
 {
     _loadListBox.ClearItems();
     foreach (var mapFile in Directory.GetFiles(SearchDirectory, Extension))
     {
         _loadListBox.AddItem(Path.GetFileNameWithoutExtension(mapFile));
     }
     _loadListBox.IsFocused = true;
     if (_loadListBox.Count > 0)
     {
         _loadListBox.SelectedIndex = 0;
     }
     base.Show();
 }
Example #8
0
        private void SetUpUI()
        {
            this.currentUI = null;
            if (this.mainMenu != null)
            {
                UserInterface.Active.RemoveEntity(this.mainMenu);
            }
            if (this.contextMenu != null)
            {
                UserInterface.Active.RemoveEntity(this.contextMenu);
            }
            this.mainMenu = new PanelTabs();
            this.mainMenu.SetAnchor(Anchor.Center);
            this.mainMenu.Size    = new Vector2(1400, 1000);
            this.mainMenu.Visible = false;

            // file menu
            var fileMenu    = (this.mainMenu as PanelTabs).AddTab("File", PanelSkin.Default);
            var newMapPanel = new Panel(new Vector2(800, 120), skin: PanelSkin.Simple, anchor: Anchor.AutoCenter);
            var newMapWidth = new TextInput(false, anchor: Anchor.CenterLeft, size: new Vector2(200, 100));

            newMapWidth.Value = $"{this.Context.Map.Width}";
            newMapPanel.AddChild(newMapWidth);
            var newMapHeight = new TextInput(false, anchor: Anchor.Center, size: new Vector2(200, 100));

            newMapHeight.Value = $"{this.Context.Map.Height}";
            newMapPanel.AddChild(newMapHeight);
            var newMapButton = new Button("New", anchor: Anchor.CenterRight, size: new Vector2(200, 100));

            newMapButton.OnClick += (e) =>
            {
                int width;
                int height;
                if (!int.TryParse(newMapWidth.Value, out width))
                {
                    return;
                }
                if (!int.TryParse(newMapHeight.Value, out height))
                {
                    return;
                }
                this.Context.Reset();
                this.Context.Map = new TileMap(width, height);
            };
            newMapPanel.AddChild(newMapButton);
            fileMenu.panel.AddChild(newMapPanel);

            var processButton = new Button("Process", anchor: Anchor.AutoCenter, size: new Vector2(400, 100));

            processButton.OnClick += (b) =>
            {
                var processor = new PFPTMapProcessor();
                processor.Process(this.Context.Map);
            };
            fileMenu.panel.AddChild(processButton);

            /*var saveBlockStoreButton = new Button("Save BlockStore", anchor: Anchor.AutoCenter, size: new Vector2(400, 100));
             * saveBlockStoreButton.OnClick += (b) =>
             * {
             *  this.SaveBlockStore();
             * };
             * fileMenu.panel.AddChild(saveBlockStoreButton);*/

            /*var saveContextButton = new Button("Save context", anchor: Anchor.AutoCenter, size: new Vector2(400, 100));
             * saveContextButton.OnClick += (b) =>
             * {
             *  BinPlatformContextSerializer.Save("default.ctx", this.Context);
             * };
             * fileMenu.panel.AddChild(saveContextButton);*/

            // 'save map' area
            var savePanel = new Panel(new Vector2(600, 100), skin: PanelSkin.Simple, anchor: Anchor.BottomLeft);

            var filenameInput = new TextInput(false, anchor: Anchor.CenterLeft, size: new Vector2(300, 0));

            filenameInput.Value = DefaultContext;
            savePanel.AddChild(filenameInput);

            var saveButton = new Button("Save", anchor: Anchor.CenterRight, size: new Vector2(200, 0));

            saveButton.OnClick += (b) =>
            {
                var filename = filenameInput.Value.Trim();
                if (string.IsNullOrEmpty(filename))
                {
                    return;
                }
                if (!filename.EndsWith(".ctx", StringComparison.InvariantCultureIgnoreCase))
                {
                    filename           += ".ctx";
                    filenameInput.Value = filename;
                }
                BinPlatformContextSerializer.Save(filenameInput.TextParagraph.Text, this.Context);
            };
            savePanel.AddChild(saveButton);
            fileMenu.panel.AddChild(savePanel);

            // quit button
            var quitButton = new Button("Quit", anchor: Anchor.BottomRight, size: new Vector2(400, 100));

            quitButton.OnClick += (b) =>
            {
                this.SceneEnded = true;
            };
            fileMenu.panel.AddChild(quitButton);

            // tiles menu
            var tilesMenu  = (this.mainMenu as PanelTabs).AddTab("Tiles", PanelSkin.Default);
            var tilePicker = new TilePicker(
                this.Context.BlockStore,
                this.Context.BlockStore.Tiles.Select((s, i) => new Tile(i)),
                anchor: Anchor.CenterLeft,
                size: new Vector2(1000, 0));

            tilesMenu.panel.AddChild(tilePicker);
            var tileSettingsPanel = new Panel(new Vector2(300, 0), skin: PanelSkin.Simple, anchor: Anchor.CenterRight);

            tilesMenu.panel.AddChild(tileSettingsPanel);
            tilePicker.OnItemClick += (e, tile) =>
            {
                var curr = new TileStencil();
                curr[0, 0] = tile;
                this.mode  = new TilePlacement(curr, this.lastLayer);
                tileSettingsPanel.ClearChildren();
                var asTile = tile as Tile;
                if (asTile != null)
                {
                    var flagsLabel = new Label("Flags:", anchor: Anchor.AutoInline);
                    tileSettingsPanel.AddChild(flagsLabel);
                    foreach (var flag in EnumHelper.GetValues <TileFlags>())
                    {
                        if (flag == TileFlags.None)
                        {
                            continue;
                        }
                        var checkBox = new CheckBox($"{flag}", anchor: Anchor.AutoCenter);
                        checkBox.Checked        = this.Context.BlockStore[asTile.Id].HasFlag(flag);
                        checkBox.OnValueChange += (entity) =>
                        {
                            var currState = this.Context.BlockStore[asTile.Id];
                            if (checkBox.Checked)
                            {
                                currState |= flag;
                            }
                            else
                            {
                                currState &= ~flag;
                            }
                            this.Context.BlockStore[asTile.Id] = currState;
                        };
                        tileSettingsPanel.AddChild(checkBox);
                    }
                }
            };
            tilePicker.Scrollbar.Max = (uint)(this.mainMenu.Size.Y * 4); // we have to guess at the maximum height...

            // stencil menu
            var stencilMenu   = (this.mainMenu as PanelTabs).AddTab("Stencils", PanelSkin.Default);
            var stencilPicker = new StencilPicker(this.Context.BlockStore, this.stencils);

            stencilPicker.OnStencilClick += (e, stencil) =>
            {
                this.mode = new TilePlacement(stencil, this.lastLayer);
            };
            stencilPicker.Scrollbar.Max = (uint)(this.mainMenu.Size.Y * 4); // we have to guess at the maximum height...
            stencilMenu.panel.AddChild(stencilPicker);

            // materials menu
            var materialsMenu = (this.mainMenu as PanelTabs).AddTab("Materials", PanelSkin.Default);
            var materialList  = new SelectList(new Vector2(400, 300), anchor: Anchor.TopLeft);
            var settingsPanel = new Panel(new Vector2(600, 0), anchor: Anchor.CenterRight, skin: PanelSkin.Simple);

            materialsMenu.panel.AddChild(settingsPanel);

            foreach (var material in EnumHelper.GetValues <MaterialType>())
            {
                if (material != MaterialType.None)
                {
                    materialList.AddItem($"{material}");
                }
            }
            materialList.OnValueChange += (e) =>
            {
                var material = (MaterialType)(materialList.SelectedIndex + 1);
                settingsPanel.ClearChildren();
                var materialTilePicker = new TilePicker(
                    this.Context.BlockStore,
                    this.Context.BlockStore.Materials[material].Select(id => new Tile(id)),
                    size: new Vector2(0, 700),
                    anchor: Anchor.AutoCenter);
                settingsPanel.AddChild(materialTilePicker);
                var deleteTile = new Button("Delete tile", anchor: Anchor.AutoCenter);
                deleteTile.OnClick += (entity) =>
                {
                    var asTile = materialTilePicker.SelectedItem as Tile;
                    if (asTile != null)
                    {
                        materialTilePicker.RemoveSelected();
                        this.Context.BlockStore.Materials[material].Remove(asTile.Id);
                    }
                };
                settingsPanel.AddChild(deleteTile);
                var addTile = new Button("Add tile", anchor: Anchor.AutoCenter);
                addTile.OnClick += (entity) =>
                {
                    var materialNewTilePicker = new TilePicker(
                        this.Context.BlockStore,
                        this.Context.BlockStore.Tiles.Select((s, i) => new Tile(i)),
                        size: new Vector2(1000, 900),
                        anchor: Anchor.TopCenter);
                    materialNewTilePicker.OnItemClick += (picker, tile) =>
                    {
                        var asTile = tile as Tile;
                        if (asTile != null)
                        {
                            this.Context.BlockStore.Materials[material].Add(asTile.Id);
                            materialTilePicker.AddItem(tile);
                        }
                        UserInterface.Active.RemoveEntity(materialNewTilePicker);
                    };
                    UserInterface.Active.AddEntity(materialNewTilePicker);
                };
                settingsPanel.AddChild(addTile);
            };
            materialsMenu.panel.AddChild(materialList);

            // lights menu
            var lightsMenu  = (this.mainMenu as PanelTabs).AddTab("Lights", PanelSkin.Default);
            var colourPanel = new Panel(new Vector2(0, 250), skin: PanelSkin.Simple, anchor: Anchor.AutoCenter);
            var redLabel    = new Label("Red", anchor: Anchor.AutoCenter);
            var redSlider   = new Slider(min: 0, max: 255, skin: SliderSkin.Default, anchor: Anchor.AutoCenter);

            redSlider.Value = 255;
            var greenLabel  = new Label("Green", anchor: Anchor.AutoCenter);
            var greenSlider = new Slider(min: 0, max: 255, skin: SliderSkin.Default, anchor: Anchor.AutoCenter);

            greenSlider.Value = 255;
            var blueLabel  = new Label("Blue", anchor: Anchor.AutoCenter);
            var blueSlider = new Slider(min: 0, max: 255, skin: SliderSkin.Default, anchor: Anchor.AutoCenter);

            blueSlider.Value = 255;
            colourPanel.AddChild(redLabel);
            colourPanel.AddChild(redSlider);
            colourPanel.AddChild(greenLabel);
            colourPanel.AddChild(greenSlider);
            colourPanel.AddChild(blueLabel);
            colourPanel.AddChild(blueSlider);
            lightsMenu.panel.AddChild(colourPanel);
            var animationPanel    = new Panel(new Vector2(0, 150), skin: PanelSkin.Simple, anchor: Anchor.AutoCenter);
            var animationLabel    = new Label("Animation", anchor: Anchor.AutoCenter);
            var animationDropdown = new DropDown(Vector2.Zero, anchor: Anchor.AutoCenter);

            animationDropdown.AddItem("None");
            animationDropdown.AddItem("Candle");
            animationDropdown.SelectedIndex = 0;
            animationPanel.AddChild(animationLabel);
            animationPanel.AddChild(animationDropdown);
            lightsMenu.panel.AddChild(animationPanel);
            var lightTypeDropdown = new DropDown(new Vector2(0, 100), anchor: Anchor.AutoCenter);

            lightTypeDropdown.AddItem("Ambient");
            lightTypeDropdown.AddItem("Specular");
            lightTypeDropdown.SelectedIndex = 0;
            lightsMenu.panel.AddChild(lightTypeDropdown);

            var updateButton = new Button("Set Light", anchor: Anchor.BottomCenter);

            updateButton.OnClick += (e) =>
            {
                var light = new Light();
                switch (animationDropdown.SelectedIndex)
                {
                case 0:
                    light.animation = null;
                    break;

                case 1:
                    light.animation = Light.Candle;
                    break;

                default:
                    light.animation = null;
                    break;
                }
                light.LightType = (Light.Type)lightTypeDropdown.SelectedIndex;
                light.Colour    = new Color(redSlider.Value, greenSlider.Value, blueSlider.Value);
                this.mode       = new LightPlacement(light);
            };
            lightsMenu.panel.AddChild(updateButton);

            // other placeable items
            var otherMenu      = (this.mainMenu as PanelTabs).AddTab("Other", PanelSkin.Default);
            var setSpawnButton = new Button("Set Spawn Locations", anchor: Anchor.AutoCenter);

            setSpawnButton.OnClick += (e) =>
            {
                this.mode = new SpawnPlacement(new Spawn());
            };
            otherMenu.panel.AddChild(setSpawnButton);

            UserInterface.Active.AddEntity(this.mainMenu);
        }
Example #9
0
        // onPurchaseCallback name, amount, total
        public void ShowUpfrontStore(string title,
                                     List <string> items,
                                     List <string> classes,
                                     List <int> prices,
                                     Action onInteractionEnd,
                                     Func <List <string>, List <int>, int, string> onPurchaseCallback)
        {
            _isDisplayingMenu = true;

            if (_textPanel != null)
            {
                UserInterface.Active.RemoveEntity(_textPanel);
                _textPanel = null;
            }

            _selectedIndex  = 1;
            _selectedAmount = 0;
            _selectedTotal  = 0;

            _items   = items;
            _classes = classes;
            _prices  = prices;
            _amounts = new List <int>();

            _storeOnAfterConfirmCallback = onInteractionEnd;

            _onPurchaseCallback = null;
            _onPurchaseCallback = onPurchaseCallback;


            float scaleY = HarvestMoon.Instance.Graphics.GraphicsDevice.Viewport.Height / 480.0f;

            // create panel and add to list of panels and manager
            Panel panel = new Panel(new Vector2(620 * scaleY, -1));

            _textPanel = panel;
            _textPanel.SetCustomSkin(_window_11Texture);

            UserInterface.Active.AddEntity(panel);

            // list title
            panel.AddChild(new Header(title));
            panel.AddChild(new HorizontalLine());

            _gParagraph     = new Paragraph("Current G: " + HarvestMoon.Instance.Gold.ToString());
            _totalParagraph = new Paragraph("Total: " + "0G");

            panel.AddChild(_gParagraph);
            panel.AddChild(_totalParagraph);

            // create the list
            _upfrontStoreList = new SelectList(new Vector2(0, 280));

            // lock and create title
            _upfrontStoreList.LockedItems[0] = true;
            _upfrontStoreList.AddItem(System.String.Format("{0}{1,-8} {2,-8} {3, -10} {4, -10}", "{{RED}}", "Name", "Class", "Price", "Amount"));


            for (int i = 0; i < items.Count; ++i)
            {
                // add items as formatted table
                _amounts.Add(0);
                _upfrontStoreList.AddItem(System.String.Format("{0,-8} {1,-8} {2,-10} {3, -10}", items[i], classes[i], prices[i].ToString(), _amounts[i].ToString()));
            }

            if (_upfrontStoreList.Items.Length >= 2)
            {
                _upfrontStoreList.SelectedIndex = _selectedIndex;
            }
            else
            {
                _selectedIndex = 0;
            }

            panel.AddChild(_upfrontStoreList);

            _npcMenu = NPCMenu.UpfrontStore;
        }
Example #10
0
        public void ShowBookshelf(string title,
                                  List <string> items,
                                  List <string> text,
                                  Action onInteractionEnd)
        {
            _isDisplayingMenu = true;
            Bookshelf.Reading = false;

            if (_textPanel != null)
            {
                UserInterface.Active.RemoveEntity(_textPanel);
                _textPanel = null;
            }

            _selectedIndex = 1;

            _title = title;
            _items = items;
            _text  = text;

            _bookshelfOnAfterConfirmCallback = onInteractionEnd;


            float scaleY = HarvestMoon.Instance.Graphics.GraphicsDevice.Viewport.Height / 480.0f;

            // create panel and add to list of panels and manager
            Panel panel = new Panel(new Vector2(620 * scaleY, -1));

            _textPanel = panel;
            _textPanel.SetCustomSkin(_window_11Texture);

            UserInterface.Active.AddEntity(panel);

            // list title
            panel.AddChild(new Header(title));
            panel.AddChild(new HorizontalLine());

            // create the list
            _bookshelfList = new SelectList(new Vector2(0, 280));

            // lock and create title
            _bookshelfList.LockedItems[0] = true;
            _bookshelfList.AddItem(System.String.Format("{0}{1,-8}", "{{RED}}", "Selection"));


            for (int i = 0; i < items.Count; ++i)
            {
                // add items as formatted table
                _bookshelfList.AddItem(System.String.Format("{0,-8}", items[i]));
            }

            if (_bookshelfList.Items.Length >= 2)
            {
                _bookshelfList.SelectedIndex = _selectedIndex;
            }
            else
            {
                _selectedIndex = 0;
            }

            panel.AddChild(_bookshelfList);

            _npcMenu = NPCMenu.Bookshelf;
        }
Example #11
0
        public void Update(GameTime gameTime)
        {
            _dayToolSprite.Update(gameTime);
            _goldSprite.Update(gameTime);

            foreach (var staminaSprite in _staminaSprites)
            {
                staminaSprite.Update(gameTime);
            }

            // GeonBit.UIL update UI manager
            UserInterface.Active.Update(gameTime);
            var deltaSeconds = (float)gameTime.ElapsedGameTime.TotalSeconds;

            if (_npcCoolDown)
            {
                _coolingTimer += deltaSeconds;

                if (_coolingTimer >= _npcCoolingDelay)
                {
                    _coolingTimer = 0.0f;
                    _npcCoolDown  = false;
                    _busy         = false;
                }
            }

            var keyboardState = HarvestMoon.Instance.Input;

            if (keyboardState.IsKeyUp(InputDevice.Keys.A))
            {
                _isActionButtonDown = false;
            }

            if (keyboardState.IsKeyUp(InputDevice.Keys.B))
            {
                _isCancelButtonDown = false;
            }

            if (keyboardState.IsKeyUp(InputDevice.Keys.Up))
            {
                _isUpButtonDown = false;
            }

            if (keyboardState.IsKeyUp(InputDevice.Keys.Down))
            {
                _isDownButtonDown = false;
            }

            if (keyboardState.IsKeyUp(InputDevice.Keys.Left))
            {
                _isLeftButtonDown = false;
            }

            if (keyboardState.IsKeyUp(InputDevice.Keys.Right))
            {
                _isRightButtonDown = false;
            }

            if ((keyboardState.IsKeyDown(InputDevice.Keys.Left) && !_isLeftButtonDown))
            {
                _isLeftButtonDown = true;

                if (_isDisplayingMenu)
                {
                    switch (_npcMenu)
                    {
                    case NPCMenu.UpfrontStore:
                        if (!UpfrontStore.ConfirmPurchase)
                        {
                            _upfrontStoreList.ClearItems();

                            _upfrontStoreList.LockedItems[0] = true;
                            _upfrontStoreList.AddItem(System.String.Format("{0}{1,-8} {2,-8} {3, -10} {4, -10}", "{{RED}}", "Name", "Class", "Price", "Amount"));

                            _amounts[_selectedIndex - 1] = _amounts[_selectedIndex - 1] - 1;

                            if (_amounts[_selectedIndex - 1] < 0)
                            {
                                _amounts[_selectedIndex - 1] = 0;
                            }

                            for (int i = 0; i < _items.Count; ++i)
                            {
                                // add items as formatted table
                                _upfrontStoreList.AddItem(System.String.Format("{0,-8} {1,-8} {2,-10} {3, -10}", _items[i], _classes[i], _prices[i].ToString(), _amounts[i].ToString()));
                            }

                            UpdateTotal();
                        }
                        break;
                    }
                }
            }

            if ((keyboardState.IsKeyDown(InputDevice.Keys.Right) && !_isRightButtonDown))
            {
                _isRightButtonDown = true;


                if (_isDisplayingMenu)
                {
                    switch (_npcMenu)
                    {
                    case NPCMenu.UpfrontStore:
                        if (!UpfrontStore.ConfirmPurchase)
                        {
                            _upfrontStoreList.ClearItems();

                            _upfrontStoreList.LockedItems[0] = true;
                            _upfrontStoreList.AddItem(System.String.Format("{0}{1,-8} {2,-8} {3, -10} {4, -10}", "{{RED}}", "Name", "Class", "Price", "Amount"));

                            _amounts[_selectedIndex - 1] = _amounts[_selectedIndex - 1] + 1;

                            if (_amounts[_selectedIndex - 1] > 10)
                            {
                                _amounts[_selectedIndex - 1] = 10;
                            }

                            for (int i = 0; i < _items.Count; ++i)
                            {
                                // add items as formatted table
                                _upfrontStoreList.AddItem(System.String.Format("{0,-8} {1,-8} {2,-10} {3, -10}", _items[i], _classes[i], _prices[i].ToString(), _amounts[i].ToString()));
                            }

                            UpdateTotal();
                        }
                        break;
                    }
                }
            }

            if ((keyboardState.IsKeyDown(InputDevice.Keys.Up) && !_isUpButtonDown) || (keyboardState.IsKeyDown(InputDevice.Keys.Down) && !_isDownButtonDown))
            {
                if (keyboardState.IsKeyDown(InputDevice.Keys.Up))
                {
                    _isUpButtonDown = true;
                }

                if (keyboardState.IsKeyDown(InputDevice.Keys.Down))
                {
                    _isDownButtonDown = true;
                }

                if (_isDisplayingMenu)
                {
                    switch (_npcMenu)
                    {
                    case NPCMenu.YesNo:
                        if (_textParagraph.Text == "> " + _menuStrings.First() + "\n" + "  " + _menuStrings.Last())
                        {
                            _textParagraph.Text = "  " + _menuStrings.First() + "\n" + "> " + _menuStrings.Last();
                        }
                        else
                        {
                            _textParagraph.Text = "> " + _menuStrings.First() + "\n" + "  " + _menuStrings.Last();
                        }

                        break;

                    case NPCMenu.UpfrontStore:
                        if (!UpfrontStore.ConfirmPurchase)
                        {
                            if (_isDownButtonDown)
                            {
                                _selectedIndex++;

                                if (_selectedIndex == _upfrontStoreList.Items.Length)
                                {
                                    _selectedIndex = 1;
                                }
                            }

                            if (_isUpButtonDown)
                            {
                                _selectedIndex--;

                                if (_selectedIndex == 0)
                                {
                                    _selectedIndex = _upfrontStoreList.Items.Length - 1;
                                }
                            }
                        }
                        break;

                    case NPCMenu.Bookshelf:
                        if (!Bookshelf.Reading)
                        {
                            if (_isDownButtonDown)
                            {
                                _selectedIndex++;

                                if (_selectedIndex == _bookshelfList.Items.Length)
                                {
                                    _selectedIndex = 1;
                                }
                            }

                            if (_isUpButtonDown)
                            {
                                _selectedIndex--;

                                if (_selectedIndex == 0)
                                {
                                    _selectedIndex = _bookshelfList.Items.Length - 1;
                                }
                            }
                        }
                        break;
                    }
                }
            }

            if (_isDisplayingMenu)
            {
                if (_npcMenu == NPCMenu.UpfrontStore)
                {
                    _gParagraph.Text = "Current G: " + HarvestMoon.Instance.Gold.ToString() + "G";

                    if (_upfrontStoreList.SelectedIndex != _selectedIndex)
                    {
                        _upfrontStoreList.SelectedIndex = _selectedIndex;
                        _selectedAmount = 0;
                        _selectedTotal  = 0;
                    }
                }
                else if (_npcMenu == NPCMenu.Bookshelf)
                {
                    if (_bookshelfList.SelectedIndex != _selectedIndex)
                    {
                        _bookshelfList.SelectedIndex  = _selectedIndex;
                        _bookshelfList.ScrollPosition = _selectedIndex - 1;
                    }
                }
            }

            if (keyboardState.IsKeyDown(InputDevice.Keys.B) && !_isCancelButtonDown)
            {
                _isCancelButtonDown = true;

                if (_textPanel != null)
                {
                    if (_isDisplayingMenu)
                    {
                        if (_npcMenu == NPCMenu.UpfrontStore)
                        {
                            if (UpfrontStore.ConfirmPurchase)
                            {
                                UpdateTotal();
                                UpfrontStore.ConfirmPurchase = false;
                            }
                            else
                            {
                                UserInterface.Active.RemoveEntity(_textPanel);
                                _textPanel        = null;
                                _npcCoolDown      = true;
                                _busy             = true;
                                _isDisplayingMenu = false;

                                _storeOnAfterConfirmCallback?.Invoke();
                                _storeOnAfterConfirmCallback = null;
                            }
                        }
                        else if (_npcMenu == NPCMenu.Bookshelf)
                        {
                            if (!Bookshelf.Reading)
                            {
                                UserInterface.Active.RemoveEntity(_textPanel);
                                _textPanel        = null;
                                _npcCoolDown      = true;
                                _busy             = true;
                                _isDisplayingMenu = false;

                                _bookshelfOnAfterConfirmCallback?.Invoke();
                                _bookshelfOnAfterConfirmCallback = null;
                            }
                        }
                    }
                }
            }

            if (keyboardState.IsKeyDown(InputDevice.Keys.A) && !_isActionButtonDown)
            {
                _isActionButtonDown = true;
                if (_textPanel != null)
                {
                    if (_isDisplayingMenu)
                    {
                        switch (_npcMenu)
                        {
                        case NPCMenu.YesNo:
                            if (_textParagraph.Text == "> " + _menuStrings.First() + "\n" + "  " + _menuStrings.Last())
                            {
                                UserInterface.Active.RemoveEntity(_textPanel);
                                _textPanel        = null;
                                _npcCoolDown      = true;
                                _busy             = true;
                                _isDisplayingMenu = false;
                                _menuCallbacks[0]();
                            }
                            else
                            {
                                UserInterface.Active.RemoveEntity(_textPanel);
                                _textPanel        = null;
                                _npcCoolDown      = true;
                                _busy             = true;
                                _isDisplayingMenu = false;
                                _menuCallbacks[1]();
                            }

                            break;

                        case NPCMenu.UpfrontStore:
                            _npcCoolDown = true;
                            _busy        = true;

                            List <string> items   = new List <string>();
                            List <int>    amounts = new List <int>();

                            for (int i = 0; i < _items.Count; ++i)
                            {
                                if (_amounts[i] > 0)
                                {
                                    items.Add(_items[i]);
                                    amounts.Add(_amounts[i]);
                                }
                            }

                            UpdateTotal();

                            var result = _onPurchaseCallback?.Invoke(items, amounts, _selectedTotal);

                            if (!UpfrontStore.ConfirmPurchase)
                            {
                                for (int i = 0; i < _amounts.Count; ++i)
                                {
                                    _amounts[i] = 0;
                                }

                                UpdateTotal(result);

                                _upfrontStoreList.ClearItems();

                                _upfrontStoreList.LockedItems[0] = true;
                                _upfrontStoreList.AddItem(System.String.Format("{0}{1,-8} {2,-8} {3, -10} {4, -10}", "{{RED}}", "Name", "Class", "Price", "Amount"));

                                for (int i = 0; i < _items.Count; ++i)
                                {
                                    // add items as formatted table
                                    _upfrontStoreList.AddItem(System.String.Format("{0,-8} {1,-8} {2,-10} {3, -10}", _items[i], _classes[i], _prices[i].ToString(), _amounts[i].ToString()));
                                }
                            }
                            else
                            {
                                UpdateTotal(result);
                            }
                            break;

                        case NPCMenu.Bookshelf:
                        {
                            _npcCoolDown = true;
                            _busy        = true;
                            if (_textAnimator != null)
                            {
                                if (_textAnimator.IsDone)
                                {
                                    if (_bufferedStrings.Count > 0)
                                    {
                                        _textAnimator.TextToType = _bufferedStrings.First();
                                        _bufferedStrings.Remove(_bufferedStrings.First());
                                    }
                                    else
                                    {
                                        ShowBookshelf(_title, _items, _text, _bookshelfOnAfterConfirmCallback);
                                        _textAnimator = null;
                                    }
                                }
                            }
                            else
                            {
                                Bookshelf.Reading = true;
                                _bufferedStrings  = SplitByLength(_text[_selectedIndex - 1], 300);

                                _textAnimator = new TypeWriterAnimator();

                                _textAnimator.TextToType = _bufferedStrings.First();
                                _bufferedStrings.Remove(_bufferedStrings.First());

                                _textPanel.RemoveChild(_bookshelfList);

                                var paragraph = new Paragraph("");
                                paragraph.AttachAnimator(_textAnimator);
                                float scaleY = HarvestMoon.Instance.Graphics.GraphicsDevice.Viewport.Height / 480.0f;

                                Panel panel = new Panel(new Vector2(0, 280 * scaleY));

                                panel.AddChild(paragraph);

                                _textPanel.AddChild(panel);
                                _textPanel.Opacity = 0;
                                //_textPanel.Visible = false;
                            }
                        }

                        break;
                        }
                    }
                    else
                    {
                        if (_textAnimator != null)
                        {
                            if (_textAnimator.IsDone)
                            {
                                if (_bufferedStrings.Count > 0)
                                {
                                    _textAnimator.TextToType = _bufferedStrings.First();
                                    _bufferedStrings.Remove(_bufferedStrings.First());
                                    _npcCoolDown = true;
                                    _busy        = true;
                                }
                                else
                                {
                                    UserInterface.Active.RemoveEntity(_textPanel);
                                    _textPanel    = null;
                                    _npcCoolDown  = true;
                                    _busy         = true;
                                    _textAnimator = null;

                                    _onAfterConfirmCallback?.Invoke();
                                }
                            }
                        }
                    }
                }
            }
        }
Example #12
0
        /// <summary>
        /// Create the top bar with next / prev buttons etc, and init all UI example panels.
        /// </summary>
        protected void InitExamplesAndUI()
        {
            // create top panel
            int   topPanelHeight = 65;
            Panel topPanel       = new Panel(new Vector2(0, topPanelHeight + 2), PanelSkin.Simple, Anchor.TopCenter);

            topPanel.Padding = Vector2.Zero;
            UIManager.AddEntity(topPanel);

            // add previous example button
            previousExampleButton         = new Button("<- Back", ButtonSkin.Default, Anchor.TopLeft, new Vector2(300, topPanelHeight));
            previousExampleButton.OnClick = (Entity btn) => { this.PreviousExample(); };
            topPanel.AddChild(previousExampleButton);

            // add next example button
            nextExampleButton         = new Button("Next ->", ButtonSkin.Default, Anchor.TopRight, new Vector2(300, topPanelHeight));
            nextExampleButton.OnClick = (Entity btn) => { this.NextExample(); };
            topPanel.AddChild(nextExampleButton);

            // add show-get button
            Button showGitButton = new Button("Git Repo", ButtonSkin.Fancy, Anchor.TopCenter, new Vector2(280, topPanelHeight));

            showGitButton.OnClick = (Entity btn) => { System.Diagnostics.Process.Start("https://github.com/RonenNess/GeonBit.UI"); };
            topPanel.AddChild(showGitButton);

            // add exit button
            Button exitBtn = new Button("Exit", anchor: Anchor.BottomRight, size: new Vector2(200, -1));

            exitBtn.OnClick = (Entity entity) =>
            {
                System.Environment.Exit(1);
            };
            UIManager.AddEntity(exitBtn);

            // events panel for debug
            Panel eventsPanel = new Panel(new Vector2(400, 500), PanelSkin.Simple, Anchor.CenterLeft, new Vector2(-10, 0));

            eventsPanel.Visible = false;

            // events log (single-time events)
            eventsPanel.AddChild(new Label("Events Log:"));
            SelectList eventsLog = new SelectList(size: new Vector2(-1, 280));

            eventsLog.ExtraSpaceBetweenLines = -8;
            eventsLog.ItemsScale             = 0.5f;
            eventsLog.Locked = true;
            eventsPanel.AddChild(eventsLog);

            // current events (events that happen while something is true)
            eventsPanel.AddChild(new Label("Current Events:"));
            SelectList eventsNow = new SelectList(size: new Vector2(-1, 100));

            eventsNow.ExtraSpaceBetweenLines = -8;
            eventsNow.ItemsScale             = 0.5f;
            eventsNow.Locked = true;
            eventsPanel.AddChild(eventsNow);

            // add the events panel
            UIManager.AddEntity(eventsPanel);

            // whenever events log list size changes, make sure its not too long. if it is, trim it.
            eventsLog.OnListChange = (Entity entity) =>
            {
                SelectList list = (SelectList)entity;
                if (list.Count > 100)
                {
                    list.RemoveItem(0);
                }
            };

            // listen to all global events - one timers
            UserInterface.OnClick            = (Entity entity) => { eventsLog.AddItem("Click: " + entity.GetType().Name); eventsLog.scrollToEnd(); };
            UserInterface.OnMouseDown        = (Entity entity) => { eventsLog.AddItem("MouseDown: " + entity.GetType().Name); eventsLog.scrollToEnd(); };
            UserInterface.OnMouseEnter       = (Entity entity) => { eventsLog.AddItem("MouseEnter: " + entity.GetType().Name); eventsLog.scrollToEnd(); };
            UserInterface.OnMouseLeave       = (Entity entity) => { eventsLog.AddItem("MouseLeave: " + entity.GetType().Name); eventsLog.scrollToEnd(); };
            UserInterface.OnMouseReleased    = (Entity entity) => { eventsLog.AddItem("MouseReleased: " + entity.GetType().Name); eventsLog.scrollToEnd(); };
            UserInterface.OnMouseWheelScroll = (Entity entity) => { eventsLog.AddItem("Scroll: " + entity.GetType().Name); eventsLog.scrollToEnd(); };
            UserInterface.OnStartDrag        = (Entity entity) => { eventsLog.AddItem("StartDrag: " + entity.GetType().Name); eventsLog.scrollToEnd(); };
            UserInterface.OnStopDrag         = (Entity entity) => { eventsLog.AddItem("StopDrag: " + entity.GetType().Name); eventsLog.scrollToEnd(); };
            UserInterface.OnValueChange      = (Entity entity) => { if (entity.Parent == eventsLog)
                                                                    {
                                                                        return;
                                                                    }
                                                                    eventsLog.AddItem("ValueChanged: " + entity.GetType().Name); eventsLog.scrollToEnd(); };

            // clear the current events after every frame they were drawn
            eventsNow.AfterDraw = (Entity entity) => { eventsNow.ClearItems(); };

            // listen to all global events - happening now
            UserInterface.WhileDragging   = (Entity entity) => { eventsNow.AddItem("Dragging: " + entity.GetType().Name); eventsNow.scrollToEnd(); };
            UserInterface.WhileMouseDown  = (Entity entity) => { eventsNow.AddItem("MouseDown: " + entity.GetType().Name); eventsNow.scrollToEnd(); };
            UserInterface.WhileMouseHover = (Entity entity) => { eventsNow.AddItem("MouseHover: " + entity.GetType().Name); eventsNow.scrollToEnd(); };

            // add extra info button
            Button infoBtn = new Button("  Events", anchor: Anchor.BottomLeft, size: new Vector2(280, -1), offset: new Vector2(140, 0));

            infoBtn.AddChild(new Icon(IconType.Scroll, Anchor.CenterLeft), true);
            infoBtn.OnClick = (Entity entity) =>
            {
                eventsPanel.Visible = !eventsPanel.Visible;
            };
            UIManager.AddEntity(infoBtn);

            // zoom in / out factor
            float zoominFactor = 0.05f;

            // scale show
            Paragraph scaleShow = new Paragraph("100%", Anchor.BottomLeft, offset: new Vector2(10, 70));

            UIManager.AddEntity(scaleShow);

            // init zoom-out button
            Button zoomout     = new Button("", ButtonSkin.Default, Anchor.BottomLeft, new Vector2(70, 70));
            Icon   zoomoutIcon = new Icon(IconType.ZoomOut, Anchor.Center, 0.75f);

            zoomout.AddChild(zoomoutIcon, true);
            zoomout.OnClick = (Entity btn) =>
            {
                if (UserInterface.SCALE > 0.5f)
                {
                    UserInterface.SCALE -= zoominFactor;
                }
                scaleShow.Text = ((int)System.Math.Round(UserInterface.SCALE * 100f)).ToString() + "%";
            };
            UIManager.AddEntity(zoomout);

            // init zoom-in button
            Button zoomin     = new Button("", ButtonSkin.Default, Anchor.BottomLeft, new Vector2(70, 70), new Vector2(70, 0));
            Icon   zoominIcon = new Icon(IconType.ZoomIn, Anchor.Center, 0.75f);

            zoomin.AddChild(zoominIcon, true);
            zoomin.OnClick = (Entity btn) =>
            {
                if (UserInterface.SCALE < 1.45f)
                {
                    UserInterface.SCALE += zoominFactor;
                }
                scaleShow.Text = ((int)System.Math.Round(UserInterface.SCALE * 100f)).ToString() + "%";
            };
            UIManager.AddEntity(zoomin);

            // init all examples

            // example: welcome message
            {
                // create panel and add to list of panels and manager
                Panel panel = new Panel(new Vector2(500, 650));
                panels.Add(panel);
                UIManager.AddEntity(panel);

                // add title and text
                Image title = new Image(Content.Load <Texture2D>("example/GeonBitUI-sm"), new Vector2(400, 240), anchor: Anchor.TopCenter, offset: new Vector2(0, -20));
                title.ShadowColor  = Color.Black;
                title.ShadowOffset = Vector2.One * -3;
                panel.AddChild(title);
                panel.AddChild(new Paragraph(@"Welcome to GeonBit UI!

This UI is part of the GeonBit project.
It provide a simple yet extensive UI for MonoGame based projects.

To start the demo, please click the 'Next' button on the top navbar."));
            }

            // example: featues list
            {
                // create panel and add to list of panels and manager
                Panel panel = new Panel(new Vector2(500, 640));
                panels.Add(panel);
                UIManager.AddEntity(panel);

                // add title and text
                panel.AddChild(new Header("Widgets Types"));
                panel.AddChild(new HorizontalLine());
                panel.AddChild(new Paragraph(@"GeonBit.UI implements the following widgets:

- Paragraphs
- Headers
- Buttons
- Panels
- CheckBox
- Radio buttons
- Rectangles
- Images & Icons
- Select List
- Dropdown
- Panel Tabs
- Sliders & Progressbars
- Text input
- And more...
"));
            }

            // example: basic concepts
            {
                // create panel and add to list of panels and manager
                Panel panel = new Panel(new Vector2(740, 680));
                panels.Add(panel);
                UIManager.AddEntity(panel);

                // add title and text
                panel.AddChild(new Header("Basic Concepts"));
                panel.AddChild(new HorizontalLine());
                panel.AddChild(new Paragraph(@"Panels are the basic containers of GeonBit.UI. They are like window forms.

To position elements inside panels or other widgets, you set an anchor and offset. An anchor is a pre-defined position in parent element, like top-left corner, center, etc. and offset is just the distance from that point.

Another thing to keep in mind is size; Most widgets come with a default size, but for those you need to set size for remember that setting size 0 will take full width / height. For example, size of X = 0, Y = 100 means the widget will be 100 pixels height and the width of its parent (minus the parent padding)."));
            }

            // example: anchors
            {
                // create panel and add to list of panels and manager
                Panel panel = new Panel(new Vector2(800, 650));
                panels.Add(panel);
                UIManager.AddEntity(panel);

                // add title and text
                panel.AddChild(new Paragraph(@"Anchors help position elements. For example, this paragraph anchor is 'center'.

The most common anchors are 'Auto' and 'AutoInline', which will place entities one after another automatically.",
                                             Anchor.Center, Color.White, 0.8f, new Vector2(320, 0)));

                panel.AddChild(new Header("Anchors", Anchor.TopCenter, new Vector2(0, 100)));
                panel.AddChild(new Paragraph("top-left", Anchor.TopLeft, Color.Yellow, 0.8f));
                panel.AddChild(new Paragraph("top-center", Anchor.TopCenter, Color.Yellow, 0.8f));
                panel.AddChild(new Paragraph("top-right", Anchor.TopRight, Color.Yellow, 0.8f));
                panel.AddChild(new Paragraph("bottom-left", Anchor.BottomLeft, Color.Yellow, 0.8f));
                panel.AddChild(new Paragraph("bottom-center", Anchor.BottomCenter, Color.Yellow, 0.8f));
                panel.AddChild(new Paragraph("bottom-right", Anchor.BottomRight, Color.Yellow, 0.8f));
                panel.AddChild(new Paragraph("center-left", Anchor.CenterLeft, Color.Yellow, 0.8f));
                panel.AddChild(new Paragraph("center-right", Anchor.CenterRight, Color.Yellow, 0.8f));
            }

            // example: buttons
            {
                // create panel and add to list of panels and manager
                Panel panel = new Panel(new Vector2(450, 700));
                panels.Add(panel);
                UIManager.AddEntity(panel);

                // add title and text
                panel.AddChild(new Header("Buttons"));
                panel.AddChild(new HorizontalLine());
                panel.AddChild(new Paragraph("GeonBit.UI comes with 3 button skins:"));

                // add default buttons
                panel.AddChild(new Button("Default", ButtonSkin.Default));
                panel.AddChild(new Button("Alternative", ButtonSkin.Alternative));
                panel.AddChild(new Button("Fancy", ButtonSkin.Fancy));

                // custom button
                Button custom = new Button("Custom Skin", ButtonSkin.Default, size: new Vector2(0, 80));
                custom.SetCustomSkin(
                    Content.Load <Texture2D>("example/btn_default"),
                    Content.Load <Texture2D>("example/btn_hover"),
                    Content.Load <Texture2D>("example/btn_down"));
                panel.AddChild(custom);

                // toggle button
                panel.AddChild(new LineSpace());
                panel.AddChild(new HorizontalLine());
                panel.AddChild(new LineSpace());
                panel.AddChild(new Paragraph("Note: buttons can also work in toggle mode:"));
                Button btn = new Button("Toggle Me!", ButtonSkin.Default);
                btn.ToggleMode = true;
                panel.AddChild(btn);
            }

            // example: checkboxes and radio buttons
            {
                // create panel and add to list of panels and manager
                Panel panel = new Panel(new Vector2(450, 570));
                panels.Add(panel);
                UIManager.AddEntity(panel);

                // checkboxes example
                panel.AddChild(new Header("CheckBox"));
                panel.AddChild(new HorizontalLine());
                panel.AddChild(new Paragraph("CheckBoxes example:"));

                panel.AddChild(new CheckBox("CheckBox 1"));
                panel.AddChild(new CheckBox("CheckBox 2"));

                // radio example
                panel.AddChild(new LineSpace(3));
                panel.AddChild(new Header("Radio buttons"));
                panel.AddChild(new HorizontalLine());
                panel.AddChild(new Paragraph("Radio buttons example:"));

                panel.AddChild(new RadioButton("Option 1"));
                panel.AddChild(new RadioButton("Option 2"));
                panel.AddChild(new RadioButton("Option 3"));
            }

            // example: panels
            {
                // create panel and add to list of panels and manager
                Panel panel = new Panel(new Vector2(450, 660));
                panels.Add(panel);
                UIManager.AddEntity(panel);

                // title and text
                panel.AddChild(new Header("Panels"));
                panel.AddChild(new HorizontalLine());
                panel.AddChild(new Paragraph("GeonBit.UI comes with 4 alternative panel skins:"));
                int panelHeight = 110;
                {
                    Panel intPanel = new Panel(new Vector2(0, panelHeight), PanelSkin.Fancy, Anchor.Auto);
                    intPanel.AddChild(new Paragraph("Fancy Panel", Anchor.Center));
                    panel.AddChild(intPanel);
                }
                {
                    Panel intPanel = new Panel(new Vector2(0, panelHeight), PanelSkin.Golden, Anchor.Auto);
                    intPanel.AddChild(new Paragraph("Golden Panel", Anchor.Center));
                    panel.AddChild(intPanel);
                }
                {
                    Panel intPanel = new Panel(new Vector2(0, panelHeight), PanelSkin.Simple, Anchor.Auto);
                    intPanel.AddChild(new Paragraph("Simple Panel", Anchor.Center));
                    panel.AddChild(intPanel);
                }
                {
                    Panel intPanel = new Panel(new Vector2(0, panelHeight), PanelSkin.ListBackground, Anchor.Auto);
                    intPanel.AddChild(new Paragraph("List Background", Anchor.Center));
                    panel.AddChild(intPanel);
                }
            }

            // example: draggable
            {
                // create panel and add to list of panels and manager
                Panel panel = new Panel(new Vector2(450, 690));
                panel.Draggable = true;
                panels.Add(panel);
                UIManager.AddEntity(panel);

                // title and text
                panel.AddChild(new Header("Draggable"));
                panel.AddChild(new HorizontalLine());
                panel.AddChild(new Paragraph("This panel can be dragged, try it out!"));
                panel.AddChild(new LineSpace());
                panel.AddChild(new HorizontalLine());
                panel.AddChild(new LineSpace());
                Paragraph paragraph = new Paragraph("Note that any type of entity can become draggable. For example, try to drag this paragraph!");
                paragraph.SetStyleProperty("FillColor", new StyleProperty(Color.Yellow));
                paragraph.SetStyleProperty("FillColor", new StyleProperty(Color.Purple), EntityState.MouseHover);
                paragraph.Draggable = true;
                paragraph.LimitDraggingToParentBoundaries = false;
                panel.AddChild(paragraph);

                // internal panel with internal draggable
                Panel panelInt = new Panel(new Vector2(250, 250), PanelSkin.Golden, Anchor.AutoCenter);
                panelInt.Draggable = true;
                panelInt.AddChild(new Paragraph("This panel is draggable too, but limited to its parent boundaries.", Anchor.Center, Color.White, 0.85f));
                panel.AddChild(panelInt);
            }

            // example: sliders
            {
                // create panel and add to list of panels and manager
                Panel panel = new Panel(new Vector2(450, 600));
                panels.Add(panel);
                UIManager.AddEntity(panel);

                // sliders title
                panel.AddChild(new Header("Sliders"));
                panel.AddChild(new HorizontalLine());
                panel.AddChild(new Paragraph("Sliders help pick numeric value in range:"));

                panel.AddChild(new Paragraph("\nDefault slider"));
                panel.AddChild(new Slider(0, 10, SliderSkin.Default));

                panel.AddChild(new Paragraph("\nFancy slider"));
                panel.AddChild(new Slider(0, 10, SliderSkin.Fancy));

                // progressbar title
                panel.AddChild(new LineSpace(3));
                panel.AddChild(new Header("Progress bar"));
                panel.AddChild(new HorizontalLine());
                panel.AddChild(new Paragraph("Works just like sliders:"));
                panel.AddChild(new ProgressBar(0, 10));
            }

            // example: lists
            {
                // create panel and add to list of panels and manager
                Panel panel = new Panel(new Vector2(450, 480));
                panels.Add(panel);
                UIManager.AddEntity(panel);

                // list title
                panel.AddChild(new Header("SelectList"));
                panel.AddChild(new HorizontalLine());
                panel.AddChild(new Paragraph("SelectLists let you pick a value from a list of items:"));

                SelectList list = new SelectList(new Vector2(0, 250));
                list.AddItem("Warrior");
                list.AddItem("Mage");
                list.AddItem("Ranger");
                list.AddItem("Rogue");
                list.AddItem("Paladin");
                list.AddItem("Cleric");
                list.AddItem("Warlock");
                list.AddItem("Barbarian");
                list.AddItem("Monk");
                list.AddItem("Ranger");
                panel.AddChild(list);
            }

            // example: lists skins
            {
                // create panel and add to list of panels and manager
                Panel panel = new Panel(new Vector2(450, 480));
                panels.Add(panel);
                UIManager.AddEntity(panel);

                // list title
                panel.AddChild(new Header("SelectList - Skin"));
                panel.AddChild(new HorizontalLine());
                panel.AddChild(new Paragraph("Just like panels, SelectList can also use alternative skins:"));

                SelectList list = new SelectList(new Vector2(0, 250), skin: PanelSkin.Golden);
                list.AddItem("Warrior");
                list.AddItem("Mage");
                list.AddItem("Ranger");
                list.AddItem("Rogue");
                list.AddItem("Paladin");
                list.AddItem("Cleric");
                list.AddItem("Warlock");
                list.AddItem("Barbarian");
                list.AddItem("Monk");
                list.AddItem("Ranger");
                panel.AddChild(list);
            }

            // example: dropdown
            {
                // create panel and add to list of panels and manager
                Panel panel = new Panel(new Vector2(450, 480));
                panels.Add(panel);
                UIManager.AddEntity(panel);

                // dropdown title
                panel.AddChild(new Header("DropDown"));
                panel.AddChild(new HorizontalLine());
                panel.AddChild(new Paragraph("DropDown is just like a list, but take less space since it hide the list when not used:"));

                DropDown drop = new DropDown(new Vector2(0, 280));
                drop.AddItem("Warrior");
                drop.AddItem("Mage");
                drop.AddItem("Ranger");
                drop.AddItem("Rogue");
                drop.AddItem("Paladin");
                drop.AddItem("Cleric");
                drop.AddItem("Warlock");
                drop.AddItem("Barbarian");
                drop.AddItem("Monk");
                drop.AddItem("Ranger");
                panel.AddChild(drop);

                panel.AddChild(new Paragraph("And like list, we can set different skins:"));
                drop = new DropDown(new Vector2(0, 240), skin: PanelSkin.Golden);
                drop.AddItem("Warrior");
                drop.AddItem("Mage");
                drop.AddItem("Ranger");
                panel.AddChild(drop);
            }

            // example: icons
            {
                // create panel and add to list of panels and manager
                Panel panel = new Panel(new Vector2(460, 670));
                panels.Add(panel);
                UIManager.AddEntity(panel);

                // icons title
                panel.AddChild(new Header("Icons"));
                panel.AddChild(new HorizontalLine());
                panel.AddChild(new Paragraph("GeonBit.UI comes with some built-in icons:"));

                foreach (IconType icon in System.Enum.GetValues(typeof(IconType)))
                {
                    if (icon == IconType.None)
                    {
                        continue;
                    }
                    panel.AddChild(new Icon(icon, Anchor.AutoInline));
                }

                panel.AddChild(new Paragraph("And you can also add an inventory-like frame:"));

                for (int i = 0; i < 6; ++i)
                {
                    panel.AddChild(new Icon((IconType)i, Anchor.AutoInline, 1, true));
                }
            }

            // example: text input
            {
                // create panel and add to list of panels and manager
                Panel panel = new Panel(new Vector2(450, 590));
                panels.Add(panel);
                UIManager.AddEntity(panel);

                // text input example
                panel.AddChild(new Header("Text Input"));
                panel.AddChild(new HorizontalLine());

                // inliner
                panel.AddChild(new Paragraph("Text input let you get free text from the user:"******"Insert text..";
                panel.AddChild(text);

                // multiline
                panel.AddChild(new Paragraph("Text input can also be multiline, and use different panel skins:"));
                TextInput textMulti = new TextInput(true, new Vector2(0, 220), skin: PanelSkin.Golden);
                textMulti.PlaceholderText = @"Insert multiline text..";
                panel.AddChild(textMulti);
            }

            // example: locked text input
            {
                // create panel and add to list of panels and manager
                Panel panel = new Panel(new Vector2(500, 590));
                panels.Add(panel);
                UIManager.AddEntity(panel);

                // text input example
                panel.AddChild(new Header("Locked Text Input"));
                panel.AddChild(new HorizontalLine());

                // inliner
                panel.AddChild(new Paragraph("A locked multiline text is a cool trick to create long, scrollable text:"));
                TextInput textMulti = new TextInput(true, new Vector2(0, 370));
                textMulti.Locked = true;
                textMulti.TextParagraph.Scale = 0.6f;
                textMulti.Value = @"The Cleric, Priest, or Bishop is a character class in Dungeons & Dragons and other fantasy role-playing games. 

The cleric is a healer, usually a priest and a holy warrior, originally modeled on or inspired by the Military Orders. 
Clerics are usually members of religious orders, with the original intent being to portray soldiers of sacred orders who have magical abilities, although this role was later taken more clearly by the paladin. 

Most clerics have powers to heal wounds, protect their allies and sometimes resurrect the dead, as well as summon, manipulate and banish undead.

A description of Priests and Priestesses from the Nethack guidebook: Priests and Priestesses are clerics militant, crusaders advancing the cause of righteousness with arms, armor, and arts thaumaturgic. Their ability to commune with deities via prayer occasionally extricates them from peril, but can also put them in it.[1]

A common feature of clerics across many games is that they may not equip pointed weapons such as swords or daggers, and must use blunt weapons such as maces, war-hammers, shields or wand instead. This is based on a popular, but erroneous, interpretation of the depiction of Odo of Bayeux and accompanying text. They are also often limited in what types of armor they can wear, though usually not as restricted as mages.

Related to the cleric is the paladin, who is typically a Lawful Good[citation needed] warrior often aligned with a religious order, and who uses their martial skills to advance its holy cause.";
                panel.AddChild(textMulti);
            }

            // example: panel tabs
            {
                // create panel and add to list of panels and manager
                Panel panel = new Panel(new Vector2(540, 480));
                panels.Add(panel);
                UIManager.AddEntity(panel);

                // create panel tabs
                PanelTabs tabs = new PanelTabs();
                panel.AddChild(tabs);

                // add first panel
                {
                    PanelTabs.TabData tab = tabs.AddTab("Tab 1");
                    tab.panel.AddChild(new Header("PanelTabs"));
                    tab.panel.AddChild(new HorizontalLine());
                    tab.panel.AddChild(new Paragraph(@"PanelTab creates a group of internal panels with toggle buttons to switch between them.

Choose a tab in the buttons above for more info..."));
                }

                // add second panel
                {
                    PanelTabs.TabData tab = tabs.AddTab("Tab 2");
                    tab.panel.AddChild(new Header("Tab 2"));
                    tab.panel.AddChild(new HorizontalLine());
                    tab.panel.AddChild(new Paragraph(@"Awesome, you got to tab2!

Maybe something interesting in tab3?"));
                }

                // add third panel
                {
                    PanelTabs.TabData tab = tabs.AddTab("Tab 3");
                    tab.panel.AddChild(new Header("Nope."));
                    tab.panel.AddChild(new HorizontalLine());
                    tab.panel.AddChild(new Paragraph("Nothing to see here."));
                }
            }

            // example: disabled
            {
                // create panel and add to list of panels and manager
                Panel panel = new Panel(new Vector2(480, 650));
                panel.Disabled = true;
                panels.Add(panel);
                UIManager.AddEntity(panel);

                // disabled title
                panel.AddChild(new Header("Disabled"));
                panel.AddChild(new HorizontalLine());
                panel.AddChild(new Paragraph("Entities can be disabled:"));

                // internal panel
                Panel panel2 = new Panel(Vector2.Zero, PanelSkin.None, Anchor.Auto);
                panel2.Padding = Vector2.Zero;
                panel.AddChild(panel2);
                panel2.AddChild(new Button("button"));

                for (int i = 0; i < 6; ++i)
                {
                    panel2.AddChild(new Icon((IconType)i, Anchor.AutoInline, 1, true, new Vector2(12, 6)));
                }
                panel2.AddChild(new Paragraph("\nDisabled entities are drawn in black & white, and you cannot interact with them.."));

                SelectList list = new SelectList(new Vector2(0, 130));
                list.AddItem("Warrior");
                list.AddItem("Mage");
                panel2.AddChild(list);
                panel2.AddChild(new CheckBox("disabled.."));
            }

            // example: Locked
            {
                // create panel and add to list of panels and manager
                Panel panel = new Panel(new Vector2(520, 680));
                panels.Add(panel);
                UIManager.AddEntity(panel);

                // locked title
                panel.AddChild(new Header("Locked"));
                panel.AddChild(new HorizontalLine());
                panel.AddChild(new Paragraph("Entities can also be locked:",
                                             Anchor.Auto));

                Panel panel2 = new Panel(Vector2.Zero, PanelSkin.None, Anchor.Auto);
                panel2.Padding = Vector2.Zero;
                panel2.Locked  = true;

                panel.AddChild(panel2);
                panel2.AddChild(new Button("button"));

                for (int i = 0; i < 6; ++i)
                {
                    panel2.AddChild(new Icon((IconType)i, Anchor.AutoInline, 1, true, new Vector2(12, 6)));
                }
                panel2.AddChild(new Paragraph("\nLocked entities will not respond to input, but unlike disabled entities they are drawn normally, eg with colors:"));

                SelectList list = new SelectList(new Vector2(0, 130));
                list.AddItem("Warrior");
                list.AddItem("Mage");
                panel2.AddChild(list);
                panel2.AddChild(new CheckBox("locked.."));
            }

            // example: Misc
            {
                // create panel and add to list of panels and manager
                Panel panel = new Panel(new Vector2(530, 650));
                panels.Add(panel);
                UIManager.AddEntity(panel);

                // misc title
                panel.AddChild(new Header("Miscellaneous"));
                panel.AddChild(new HorizontalLine());
                panel.AddChild(new Paragraph("Some cool tricks you can do:"));

                // button with icon
                Button btn = new Button("Button With Icon");
                btn.ButtonParagraph.SetPosition(Anchor.CenterLeft, new Vector2(60, 0));
                btn.AddChild(new Icon(IconType.Book, Anchor.CenterLeft), true);
                panel.AddChild(btn);

                // change progressbar color
                panel.AddChild(new Paragraph("Different PrograssBar colors:"));
                ProgressBar pb = new ProgressBar();
                pb.ProgressFill.FillColor = Color.Red;
                panel.AddChild(pb);

                // paragraph style with mouse
                panel.AddChild(new LineSpace());
                panel.AddChild(new HorizontalLine());
                Paragraph paragraph = new Paragraph("Hover / click styling..");
                paragraph.SetStyleProperty("FillColor", new StyleProperty(Color.Purple), EntityState.MouseDown);
                paragraph.SetStyleProperty("FillColor", new StyleProperty(Color.Red), EntityState.MouseHover);
                panel.AddChild(paragraph);
                panel.AddChild(new HorizontalLine());

                // colored rectangle
                panel.AddChild(new Paragraph("Colored rectangle:"));
                ColoredRectangle rect = new ColoredRectangle(Color.Blue, Color.Red, 4, new Vector2(0, 40));
                panel.AddChild(rect);
                panel.AddChild(new HorizontalLine());

                // custom icons
                panel.AddChild(new Paragraph("Custom icons / images:"));
                Icon icon = new Icon(IconType.None, Anchor.AutoInline, 1, true, new Vector2(12, 10));
                icon.Texture = Content.Load <Texture2D>("example/warrior");
                panel.AddChild(icon);
                icon         = new Icon(IconType.None, Anchor.AutoInline, 1, true, new Vector2(12, 10));
                icon.Texture = Content.Load <Texture2D>("example/monk");
                panel.AddChild(icon);
                icon         = new Icon(IconType.None, Anchor.AutoInline, 1, true, new Vector2(12, 10));
                icon.Texture = Content.Load <Texture2D>("example/mage");
                panel.AddChild(icon);
            }

            // example: character build page - intro
            {
                // create panel and add to list of panels and manager
                Panel panel = new Panel(new Vector2(500, 380));
                panels.Add(panel);
                UIManager.AddEntity(panel);

                // add title and text
                panel.AddChild(new Header("Final Example"));
                panel.AddChild(new HorizontalLine());
                panel.AddChild(new Paragraph(@"The next example will show a fully-functional character creation page, that use different entities, events, etc.

Click on 'Next' to see the character creation demo."));
            }

            // example: character build page - final
            {
                int panelWidth = 730;

                // create panel and add to list of panels and manager
                Panel panel = new Panel(new Vector2(panelWidth, 570));
                panels.Add(panel);
                UIManager.AddEntity(panel);

                // add title and text
                panel.AddChild(new Header("Create New Character"));
                panel.AddChild(new HorizontalLine());

                // create an internal panel to align components better - a row that covers the entire width split into 3 columns (left, center, right)
                // first the container panel
                Panel entitiesGroup = new Panel(new Vector2(0, 240), PanelSkin.None, Anchor.AutoCenter);
                entitiesGroup.Padding = Vector2.Zero;
                panel.AddChild(entitiesGroup);

                // now left side
                Panel leftPanel = new Panel(new Vector2(0.33f, 0), PanelSkin.None, Anchor.TopLeft);
                leftPanel.Padding = Vector2.Zero;
                entitiesGroup.AddChild(leftPanel);

                // right side
                Panel rightPanel = new Panel(new Vector2(0.33f, 0), PanelSkin.None, Anchor.TopRight);
                rightPanel.Padding = Vector2.Zero;
                entitiesGroup.AddChild(rightPanel);

                // center
                Panel centerPanel = new Panel(new Vector2(0.33f, 0), PanelSkin.None, Anchor.TopCenter);
                centerPanel.Padding = Vector2.Zero;
                entitiesGroup.AddChild(centerPanel);

                // create a character preview panel
                centerPanel.AddChild(new Label(@"Preview", Anchor.AutoCenter));
                Panel charPreviewPanel = new Panel(new Vector2(180, 180), PanelSkin.Simple, Anchor.AutoCenter);
                charPreviewPanel.Padding = Vector2.Zero;
                centerPanel.AddChild(charPreviewPanel);

                // create preview pics of character
                Image previewImage      = new Image(Content.Load <Texture2D>("example/warrior"), Vector2.Zero, anchor: Anchor.Center);
                Image previewImageColor = new Image(Content.Load <Texture2D>("example/warrior_color"), Vector2.Zero, anchor: Anchor.Center);
                Image previewImageSkin  = new Image(Content.Load <Texture2D>("example/warrior_skin"), Vector2.Zero, anchor: Anchor.Center);
                charPreviewPanel.AddChild(previewImage);
                charPreviewPanel.AddChild(previewImageColor);
                charPreviewPanel.AddChild(previewImageSkin);

                // add skin tone slider
                Slider skin = new Slider(0, 10, new Vector2(0, -1), SliderSkin.Default, Anchor.Auto);
                skin.OnValueChange = (Entity entity) =>
                {
                    Slider slider = (Slider)entity;
                    int    alpha  = (int)(slider.GetValueAsPercent() * 255);
                    previewImageSkin.FillColor = new Color(60, 32, 25, alpha);
                };
                skin.Value = 5;
                charPreviewPanel.AddChild(skin);

                // create the class selection list
                leftPanel.AddChild(new Label(@"Class", Anchor.AutoCenter));
                SelectList classTypes = new SelectList(new Vector2(0, 208), Anchor.Auto);
                classTypes.AddItem("Warrior");
                classTypes.AddItem("Mage");
                classTypes.AddItem("Ranger");
                classTypes.AddItem("Monk");
                classTypes.SelectedIndex = 0;
                leftPanel.AddChild(classTypes);
                classTypes.OnValueChange = (Entity entity) =>
                {
                    string texture = ((SelectList)(entity)).SelectedValue.ToLower();
                    previewImage.Texture      = Content.Load <Texture2D>("example/" + texture);
                    previewImageColor.Texture = Content.Load <Texture2D>("example/" + texture + "_color");
                    previewImageSkin.Texture  = Content.Load <Texture2D>("example/" + texture + "_skin");
                };

                // create color selection buttons
                rightPanel.AddChild(new Label(@"Color", Anchor.AutoCenter));
                Color[] colors        = { Color.White, Color.Red, Color.Green, Color.Blue, Color.Yellow, Color.Purple, Color.Cyan, Color.Brown };
                int     colorPickSize = 24;
                foreach (Color baseColor in colors)
                {
                    rightPanel.AddChild(new LineSpace());
                    for (int i = 0; i < 8; ++i)
                    {
                        Color            color           = baseColor * (1.0f - (i * 2 / 16.0f)); color.A = 255;
                        ColoredRectangle currColorButton = new ColoredRectangle(color, Vector2.One * colorPickSize, Anchor.AutoInline);
                        currColorButton.SpaceAfter = currColorButton.SpaceBefore = Vector2.Zero;
                        currColorButton.OnClick    = (Entity entity) =>
                        {
                            previewImageColor.FillColor = entity.FillColor;
                        };
                        rightPanel.AddChild(currColorButton);
                    }
                }

                // gender selection (radio buttons)
                entitiesGroup.AddChild(new LineSpace());
                entitiesGroup.AddChild(new RadioButton("Male", Anchor.Auto, new Vector2(180, 60), isChecked: true));
                entitiesGroup.AddChild(new RadioButton("Female", Anchor.AutoInline, new Vector2(240, 60)));

                // hardcore mode
                Button hardcore = new Button("Hardcore", ButtonSkin.Fancy, Anchor.AutoInline, new Vector2(220, 60));
                hardcore.ButtonParagraph.Scale = 0.8f;
                hardcore.ToggleMode            = true;
                entitiesGroup.AddChild(hardcore);
                entitiesGroup.AddChild(new HorizontalLine());

                // add character name, last name, and age
                // first add the labels
                entitiesGroup.AddChild(new Label(@"First Name: ", Anchor.AutoInline, size: new Vector2(0.4f, -1)));
                entitiesGroup.AddChild(new Label(@"Last Name: ", Anchor.AutoInline, size: new Vector2(0.4f, -1)));
                entitiesGroup.AddChild(new Label(@"Age: ", Anchor.AutoInline, size: new Vector2(0.2f, -1)));

                // now add the text inputs

                // first name
                TextInput firstName = new TextInput(false, new Vector2(0.4f, -1), anchor: Anchor.Auto);
                firstName.PlaceholderText = "Name";
                firstName.Validators.Add(new TextValidatorEnglishCharsOnly());
                firstName.Validators.Add(new TextValidatorMakeTitle());
                entitiesGroup.AddChild(firstName);

                // last name
                TextInput lastName = new TextInput(false, new Vector2(0.4f, -1), anchor: Anchor.AutoInline);
                lastName.PlaceholderText = "Surname";
                lastName.Validators.Add(new TextValidatorEnglishCharsOnly());
                lastName.Validators.Add(new TextValidatorMakeTitle());
                entitiesGroup.AddChild(lastName);

                // age
                TextInput age = new TextInput(false, new Vector2(0.2f, -1), anchor: Anchor.AutoInline);
                age.Validators.Add(new TextValidatorNumbersOnly(false, 0, 80));
                age.Value = "20";
                entitiesGroup.AddChild(age);
            }

            // example: epilogue
            {
                // create panel and add to list of panels and manager
                Panel panel = new Panel(new Vector2(500, 560));
                panels.Add(panel);
                UIManager.AddEntity(panel);

                // add title and text
                panel.AddChild(new Header("End Of Examples"));
                panel.AddChild(new HorizontalLine());
                panel.AddChild(new Paragraph(@"That's it for now! There is still much to learn about GeonBit.UI, but these examples were enough to get you going.

To learn more, please visit the git repo, read the docs, or go through some source code.

If you liked GeonBit.UI feel free to star the repo on GitHub. :)"));
            }

            // init panels and buttons
            UpdateAfterExapmleChange();

            // once done init, clear events log
            eventsLog.ClearItems();

            // call base initialize
            base.Initialize();
        }
Example #13
0
        void addSelectorUI()
        {
            Panel panel = new Panel(new Vector2(1200, 450), PanelSkin.Default, Anchor.BottomCenter);

            this.UserInterface.AddEntity(panel);

            panel.AddChild(new Header("CAR BUILDER"));


            SelectList bodySelect = new SelectList(new Vector2(350, 150), Anchor.Center, new Vector2(0, 0));

            //bodyDrop.DefaultText = ("Choose a Body");
            foreach (string text in gameState.carState.getBodyStrings())
            {
                bodySelect.AddItem(text);
            }

            bodySelect.ToolTipText = ("Choose a Body");

            bodySelect.OnValueChange = (Entity e) =>
            {
                gameState.carState.updateSelectedBody(bodySelect.SelectedIndex);
                addCarModelAndCamera();
                updateStatDisplay();
            };


            SelectList frontWheelSelect = new SelectList(new Vector2(300, 150), Anchor.CenterLeft, new Vector2(0, 0));

            //frontWheelDrop.DefaultText = ("Choose Front Wheels");
            foreach (string text in gameState.carState.getWheelStrings())
            {
                frontWheelSelect.AddItem(text);
            }
            frontWheelSelect.ToolTipText = ("Choose Front Wheels");

            frontWheelSelect.OnValueChange = (Entity e) =>
            {
                gameState.carState.updateSelectedWheel(frontWheelSelect.SelectedIndex, true);
                addCarModelAndCamera();
                updateStatDisplay();
            };

            SelectList backWheelSelect = new SelectList(new Vector2(300, 150), Anchor.CenterRight, new Vector2(0, 0));

            //backWheelDrop.DefaultText = ("Choose Back Wheels");
            foreach (string text in gameState.carState.getWheelStrings())
            {
                backWheelSelect.AddItem(text);
            }
            backWheelSelect.ToolTipText = ("Choose Back Wheels");

            backWheelSelect.OnValueChange = (Entity e) =>
            {
                gameState.carState.updateSelectedWheel(backWheelSelect.SelectedIndex, false);
                addCarModelAndCamera();
                updateStatDisplay();
            };

            int       labelOffsetY = -100;
            int       labelOffsetX = 70;
            Color     labelColor   = Color.Plum;
            Paragraph bodyLabel    = new Paragraph("Body", Anchor.Center, new Vector2(80, 20), new Vector2(0, labelOffsetY));

            bodyLabel.FillColor = labelColor;

            Paragraph fwLabel = new Paragraph("Front Wheels", Anchor.CenterLeft, new Vector2(200, 20), new Vector2(labelOffsetX, labelOffsetY));

            fwLabel.FillColor = labelColor;

            Paragraph bwLabel = new Paragraph("Back Wheels", Anchor.CenterRight, new Vector2(200, 20), new Vector2(labelOffsetX, labelOffsetY));

            bwLabel.FillColor = labelColor;

            panel.AddChild(bodyLabel);
            panel.AddChild(fwLabel);
            panel.AddChild(bwLabel);

            panel.AddChild(bodySelect);
            panel.AddChild(frontWheelSelect);
            panel.AddChild(backWheelSelect);

            Button closeTut = new Button("Click to play!", ButtonSkin.Fancy, Anchor.BottomCenter);

            closeTut.OnClick = (Entity btn) =>
            {
                btn.Parent.Visible = false;
                gameState.changeScene(State.GAME);
            };
            panel.AddChild(closeTut);
            Button randomButton = new Button("Random Car", ButtonSkin.Fancy, Anchor.TopLeft, new Vector2(350, 50));

            randomButton.OnClick = (Entity btn) =>
            {
                gameState.carState.buildRandomCar();
                bodySelect.SelectedIndex       = (int)gameState.carState.body;
                frontWheelSelect.SelectedIndex = (int)gameState.carState.frontWheels;
                backWheelSelect.SelectedIndex  = (int)gameState.carState.backWheels;
                addCarModelAndCamera();
                updateStatDisplay();
            };
            panel.AddChild(randomButton);

            //Panel wip = new Panel(new Vector2(700, 450),PanelSkin.Default, Anchor.CenterLeft,new Vector2(0,-100));

            //wip.AddChild(new Header("--Woah slow down there!--"));
            //panel.AddChild(new HorizontalLine());
            //var tutorialText = new Paragraph("This feature isn't quite ready yet!\n\n Here you would build your car from various parts.\n\nEach part affects how your car handles and how much damage it takes.\n\n For now go ahead and click play, we'll make you a random car.");
            //wip.AddChild(tutorialText);
            //UserInterface.AddEntity(wip);
        }
Example #14
0
        private void InitUI()
        {
            UserInterface.Initialize(XNAContent, BuiltinThemes.editor);
            UserInterface.Active.ShowCursor = false;

            return;

            var realPanel = new Panel(new Vector2(500, 650));

            realPanel.Draggable = true;
            var tabs = new PanelTabs();

            realPanel.AddChild(tabs);
            var MainPanel = tabs.AddTab("Some Tab").panel;
            var tab2      = tabs.AddTab("Some Other Tab");

            //tab2.button.Enabled = false;
            tab2.button.ToolTipText = "This is tab 2.";
            tab2.panel.AddChild(new TextInput()
            {
                CharactersLimit = 16
            });

            UserInterface.Active.AddEntity(realPanel);

            MainPanel.AddChild(new Header("Some Header Text"));
            MainPanel.AddChild(new HorizontalLine());
            MainPanel.AddChild(new Paragraph("This is a UI test."));
            var b = new Button("This is a button!");

            b.ToolTipText = "Some tooltip!";
            MainPanel.AddChild(b);
            MainPanel.AddChild(new Slider(0, 100, SliderSkin.Default)
            {
                Enabled = false
            });
            var toggle = new GeonBit.UI.Entities.CheckBox("Some Check", Anchor.Auto);

            MainPanel.AddChild(toggle);

            var test = new Panel(new Vector2(300, 140), PanelSkin.Fancy, Anchor.AutoInline);

            test.AddChild(new Label("I am a label"));
            test.AddChild(new CheckBox("I'm a box"));
            test.AdjustHeightAutomatically = true;
            MainPanel.AddChild(test);

            var list = new SelectList();

            list.AddItem("Option A");
            list.AddItem("Option B");
            list.AddItem("Option C");
            list.SetHeightBasedOnChildren();
            var drop = new DropDown();

            drop.AddItem("Something A");
            drop.AddItem("Something B");
            drop.AddItem("Something C");
            MainPanel.AddChild(drop);

            var pan2 = new Panel();

            pan2.AddChild(new Header("Some sub-panel"));
            pan2.AddChild(new CheckBox("Cool?")
            {
                OnValueChange = (e) => { Debug.Log((e as CheckBox).Checked.ToString()); }
            });
            tab2.panel.AddChild(pan2, true);
            //pan2.Anchor = Anchor.AutoInline;
            Debug.Log(MainPanel.Padding.ToString());

            MainPanel.AddChild(list);

            MainPanel.Padding = new Vector2(10, 5);
            MainPanel.SetHeightBasedOnChildren();
        }
Example #15
0
        protected void InitExamplesAndUI()
        {
            bool initExamples = true;

            // add previous example button
            previousExampleButton         = new Button("Back", ButtonSkin.Default, Anchor.BottomCenter, new Vector2(300, 50));
            previousExampleButton.OnClick = (Entity btn) => { this.PreviousExample(); };
            UserInterface.Active.AddEntity(previousExampleButton);

            // add new scenario button
            nextExampleButton         = new Button("New Scenario", ButtonSkin.Default, Anchor.TopCenter, new Vector2(300, 50));
            nextExampleButton.OnClick = (Entity btn) => { this.NextExample(); };

            // add new hero button
            nextExampleButton1         = new Button("Embark", ButtonSkin.Default, Anchor.BottomCenter, new Vector2(300, 50));
            nextExampleButton1.OnClick = (Entity btn) => { this.NextExample(); };
            spriteBatch.Begin();
            foreach (Tile t in tileset)
            {
                t.Draw(spriteBatch);
            }
            spriteBatch.End();

            // add exit button
            Button exitBtn = new Button("Exit", anchor: Anchor.BottomCenter, size: new Vector2(300, 50));

            exitBtn.OnClick = (Entity entity) => { Exit(); };


            if (initExamples)
            {
                {
                    int   PanelHeight = 400;
                    Panel Panel       = new Panel(new Vector2(500, PanelHeight + 2), PanelSkin.Simple, Anchor.Center);
                    panels.Add(Panel);
                    UserInterface.Active.AddEntity(Panel);

                    Panel.AddChild(nextExampleButton);
                    Panel.AddChild(exitBtn);
                    {
                        var btn = new Button("Credits", ButtonSkin.Default, Anchor.Center, new Vector2(300, 50));
                        btn.OnClick += (GeonBit.UI.Entities.Entity entity) =>
                        {
                            GeonBit.UI.Utils.MessageBox.ShowMsgBox("Hello World!", "This is a simple message box. It doesn't say much, really.");
                        };
                        Panel.AddChild(btn);
                    }
                }

                {
                    int panelWidth = 730;

                    // create panel and add to list of panels and manager
                    Panel panel = new Panel(new Vector2(panelWidth, 550));
                    panels.Add(panel);

                    UserInterface.Active.AddEntity(panel);

                    // add title and text
                    panel.AddChild(new Header("Create New Character"));
                    panel.AddChild(new HorizontalLine());

                    // create an internal panel to align components better - a row that covers the entire width split into 3 columns (left, center, right)
                    // first the container panel
                    Panel entitiesGroup = new Panel(new Vector2(0, 240), PanelSkin.None, Anchor.AutoCenter);
                    entitiesGroup.Padding = Vector2.Zero;
                    panel.AddChild(entitiesGroup);

                    // now left side
                    Panel leftPanel = new Panel(new Vector2(0.33f, 0), PanelSkin.None, Anchor.TopLeft);
                    leftPanel.Padding = Vector2.Zero;
                    entitiesGroup.AddChild(leftPanel);

                    // right side
                    Panel rightPanel = new Panel(new Vector2(0.33f, 0), PanelSkin.None, Anchor.TopRight);
                    rightPanel.Padding = Vector2.Zero;
                    entitiesGroup.AddChild(rightPanel);

                    // center
                    Panel centerPanel = new Panel(new Vector2(0.33f, 0), PanelSkin.None, Anchor.TopCenter);
                    centerPanel.Padding = Vector2.Zero;
                    entitiesGroup.AddChild(centerPanel);

                    // create a character preview panel
                    centerPanel.AddChild(new Label(@"Preview", Anchor.AutoCenter));
                    Panel charPreviewPanel = new Panel(new Vector2(180, 180), PanelSkin.Simple, Anchor.AutoCenter);
                    charPreviewPanel.Padding = Vector2.Zero;
                    centerPanel.AddChild(charPreviewPanel);

                    // create preview pics of character
                    Image previewImage      = new Image(Content.Load <Texture2D>("example/warrior"), Vector2.Zero, anchor: Anchor.Center);
                    Image previewImageColor = new Image(Content.Load <Texture2D>("example/warrior_color"), Vector2.Zero, anchor: Anchor.Center);
                    Image previewImageSkin  = new Image(Content.Load <Texture2D>("example/warrior_skin"), Vector2.Zero, anchor: Anchor.Center);
                    charPreviewPanel.AddChild(previewImage);
                    charPreviewPanel.AddChild(previewImageColor);
                    charPreviewPanel.AddChild(previewImageSkin);

                    // add skin tone slider
                    Slider skin = new Slider(0, 10, new Vector2(0, -1), SliderSkin.Default, Anchor.Auto);
                    skin.OnValueChange = (Entity entity) =>
                    {
                        Slider slider = (Slider)entity;
                        int    alpha  = (int)(slider.GetValueAsPercent() * 255);
                        previewImageSkin.FillColor = new Color(60, 32, 25, alpha);
                    };
                    skin.Value = 5;
                    charPreviewPanel.AddChild(skin);

                    // create the class selection list
                    leftPanel.AddChild(new Label(@"Class", Anchor.AutoCenter));
                    SelectList classTypes = new SelectList(new Vector2(0, 208), Anchor.Auto);
                    classTypes.AddItem("Warrior");
                    classTypes.AddItem("Mage");
                    classTypes.AddItem("Ranger");
                    classTypes.AddItem("Monk");
                    classTypes.SelectedIndex = 0;
                    leftPanel.AddChild(classTypes);
                    classTypes.OnValueChange = (Entity entity) =>
                    {
                        string texture = ((SelectList)(entity)).SelectedValue.ToLower();
                        previewImage.Texture      = Content.Load <Texture2D>("example/" + texture);
                        previewImageColor.Texture = Content.Load <Texture2D>("example/" + texture + "_color");
                        previewImageSkin.Texture  = Content.Load <Texture2D>("example/" + texture + "_skin");
                    };

                    // create color selection buttons
                    rightPanel.AddChild(new Label(@"Color", Anchor.AutoCenter));
                    Color[] colors        = { Color.White, Color.Red, Color.Green, Color.Blue, Color.Yellow, Color.Purple, Color.Cyan, Color.Brown };
                    int     colorPickSize = 24;
                    foreach (Color baseColor in colors)
                    {
                        rightPanel.AddChild(new LineSpace(0));
                        for (int i = 0; i < 8; ++i)
                        {
                            Color            color           = baseColor * (1.0f - (i * 2 / 16.0f)); color.A = 255;
                            ColoredRectangle currColorButton = new ColoredRectangle(color, Vector2.One * colorPickSize, Anchor.AutoInline);
                            currColorButton.Padding = currColorButton.SpaceAfter = currColorButton.SpaceBefore = Vector2.Zero;
                            currColorButton.OnClick = (Entity entity) =>
                            {
                                previewImageColor.FillColor = entity.FillColor;
                            };
                            rightPanel.AddChild(currColorButton);
                        }
                    }
                    panel.AddChild(nextExampleButton1);

                    // add character name, last name, and age
                    // first add the labels
                    entitiesGroup.AddChild(new Label(@"Name: ", Anchor.AutoInline, size: new Vector2(0.4f, -1)));
                    // now add the text inputs

                    // first name
                    TextInput firstName = new TextInput(false, new Vector2(0.4f, -1), anchor: Anchor.Auto);
                    firstName.PlaceholderText = "Name";
                    firstName.Validators.Add(new TextValidatorEnglishCharsOnly(true));
                    firstName.Validators.Add(new OnlySingleSpaces());
                    firstName.Validators.Add(new TextValidatorMakeTitle());
                    entitiesGroup.AddChild(firstName);
                }
                {
                    int   PanelHeight = 400;
                    Panel Panel       = new Panel(new Vector2(500, PanelHeight + 2), PanelSkin.Simple, Anchor.BottomRight);
                    panels.Add(Panel);
                    UserInterface.Active.AddEntity(Panel);
                }
                // init panels and buttons
                UpdateAfterExapmleChange();
            }
            // call base initialize
            base.Initialize();
        }
Example #16
0
        void LoadCharSelection(Zombicide game)
        {
            //Setup Last Panel to hold skills and confirm button
            Panel     skillPanel = new Panel(new Vector2(400, 600), PanelSkin.Default, Anchor.AutoInline);
            Paragraph bs         = new Paragraph("Blue Skill", Anchor.Auto, Color.DeepSkyBlue);
            Paragraph ys         = new Paragraph("Yellow Skill", Anchor.Auto, Color.Yellow);
            Paragraph os1        = new Paragraph("Orange Skill", Anchor.Auto, Color.Orange);
            Paragraph os2        = new Paragraph("Orange Skill", Anchor.Auto, Color.Orange);
            Paragraph rs1        = new Paragraph("Red Skill", Anchor.Auto, Color.Red);
            Paragraph rs2        = new Paragraph("Red Skill", Anchor.Auto, Color.Red);
            Paragraph rs3        = new Paragraph("Red Skill", Anchor.Auto, Color.Red);
            Paragraph ArmAlt     = new Paragraph("Item", Anchor.Auto, Color.White);
            Button    ConfirmBut = new Button("CONFIRM", ButtonSkin.Default, Anchor.BottomCenter);

            ConfirmBut.Enabled = false;

            skillPanel.AddChild(new Header("Skills"));
            skillPanel.AddChild(new HorizontalLine());
            skillPanel.AddChild(bs);
            skillPanel.AddChild(ys);
            skillPanel.AddChild(os1);
            skillPanel.AddChild(os2);
            skillPanel.AddChild(rs1);
            skillPanel.AddChild(rs2);
            skillPanel.AddChild(rs3);
            skillPanel.AddChild(new LineSpace(5));
            skillPanel.AddChild(new Header("Armor Alternative"));
            skillPanel.AddChild(new HorizontalLine());
            skillPanel.AddChild(ArmAlt);
            skillPanel.AddChild(ConfirmBut);


            //Setup First Panel to hold character list
            Panel Charpanel = new Panel(new Vector2(400, 600), PanelSkin.Default, Anchor.AutoInline, new Vector2((game.GraphicsDevice.Viewport.Width / 2) - 700, 100));

            Charpanel.AddChild(new Header("Select Character"));
            Charpanel.AddChild(new HorizontalLine());
            SelectList list         = new SelectList(new Vector2(0, 500));
            var        CharDocument = PopulateCharacters();

            foreach (XmlNode node in CharDocument.DocumentElement.ChildNodes)
            {
                list.AddItem(node.FirstChild.InnerText);
            }
            Charpanel.AddChild(list);

            //Setup middle panel to hold character image
            Panel picpanel = new Panel(new Vector2(600, 600), PanelSkin.Default, Anchor.AutoInline);
            Image img      = new Image(new Texture2D(game.GraphicsDevice, 400, 400));

            picpanel.AddChild(img);

            //Add Panels to UI
            UserInterface.Active.AddEntity(Charpanel);
            UserInterface.Active.AddEntity(picpanel);
            UserInterface.Active.AddEntity(skillPanel);

            //Set events
            ConfirmBut.OnClick = (Entity btn) =>
            {
                Character.Initialize(game, list.SelectedValue.First());
                SelectedCharacter = new Character(list.SelectedValue, bs.Text, ys.Text, os1.Text, os2.Text, rs1.Text, rs2.Text, rs3.Text, ArmAlt.Text);
                StarterPopup(game);
            };

            list.OnValueChange = (Entity lst) =>
            {
                ConfirmBut.Enabled = true;
                var     name         = list.SelectedValue;
                XmlNode selectedNode = null;
                foreach (XmlNode node in CharDocument.DocumentElement.ChildNodes)
                {
                    if (node.FirstChild.InnerText == name)
                    {
                        selectedNode = node;
                    }
                }
                string blueSkill        = selectedNode.ChildNodes.Item(1).InnerText;
                string yellowSkill      = selectedNode.ChildNodes.Item(2).InnerText;
                string orangeSkill1     = selectedNode.ChildNodes.Item(3).InnerText;
                string OrangeSkill2     = selectedNode.ChildNodes.Item(4).InnerText;
                string RedSkill1        = selectedNode.ChildNodes.Item(5).InnerText;
                string RedSkill2        = selectedNode.ChildNodes.Item(6).InnerText;
                string RedSkill3        = selectedNode.ChildNodes.Item(7).InnerText;
                string ArmorAlternative = selectedNode.ChildNodes.Item(8).InnerText;

                bs.Text     = blueSkill;
                ys.Text     = yellowSkill;
                os1.Text    = orangeSkill1;
                os2.Text    = OrangeSkill2;
                rs1.Text    = RedSkill1;
                rs2.Text    = RedSkill2;
                rs3.Text    = RedSkill3;
                ArmAlt.Text = ArmorAlternative;

                string     baseDir  = Directory.GetCurrentDirectory();
                string     fileName = name + ".jpg";
                var        imgPath  = Path.Combine(baseDir, @"Data\", fileName);
                FileStream imgFile  = File.OpenRead(imgPath);
                img.Texture = Texture2D.FromStream(game.GraphicsDevice, imgFile);
            };
        }
Example #17
0
        /// <summary>
        /// Create and return an entity for a field type.
        /// </summary>
        /// <param name="fieldData">Field data to generate entity for.</param>
        /// <param name="needLabel">Will set if need to generate a label for this entity or not.</param>
        /// <returns></returns>
        protected virtual Entity CreateEntityForField(FormFieldData fieldData, ref bool needLabel)
        {
            // by default need label
            needLabel = !string.IsNullOrEmpty(fieldData.FieldLabel);

            // create entity based on type
            switch (fieldData.Type)
            {
            // create checkbox
            case FormFieldType.Checkbox:
                needLabel = false;
                return(new CheckBox(fieldData.FieldLabel, isChecked: fieldData.DefaultValue != null && (bool)(fieldData.DefaultValue)));

            // create dropdown
            case FormFieldType.DropDown:

                // create entity and set choices
                var dropdown = new DropDown(new Vector2(0, -1));
                foreach (var choice in fieldData.Choices)
                {
                    dropdown.AddItem(choice);
                }

                // if got few items adjust height automatically
                if (dropdown.SelectList.Items.Length < 10)
                {
                    dropdown.SelectList.AdjustHeightAutomatically = true;
                }

                // set default value and return
                if (fieldData.DefaultValue is string)
                {
                    dropdown.SelectedValue = fieldData.DefaultValue as string;
                }
                else if (fieldData.DefaultValue is int)
                {
                    dropdown.SelectedIndex = (int)fieldData.DefaultValue;
                }
                return(dropdown);

            // create multi-line text input
            case FormFieldType.MultilineTextInput:
                var multiText = new TextInput(true);
                multiText.Value = fieldData.DefaultValue as string;
                return(multiText);

            // create single-line text input
            case FormFieldType.TextInput:
                var text = new TextInput(false);
                if (fieldData.DefaultValue != null)
                {
                    text.Value = fieldData.DefaultValue as string;
                }
                return(text);

            // create slider input
            case FormFieldType.Slider:
                var slider = new Slider((uint)fieldData.Min, (uint)fieldData.Max);
                if (fieldData.DefaultValue is int)
                {
                    slider.Value = (int)fieldData.DefaultValue;
                }
                return(slider);

            // create select list input
            case FormFieldType.SelectList:

                // create the entity itself
                var selectlist = new SelectList(new Vector2(0, -1));
                foreach (var choice in fieldData.Choices)
                {
                    selectlist.AddItem(choice);
                }

                // if got few items set height automatically
                if (selectlist.Items.Length < 10)
                {
                    selectlist.AdjustHeightAutomatically = true;
                }

                // set default value and return
                if (fieldData.DefaultValue is string)
                {
                    selectlist.SelectedValue = fieldData.DefaultValue as string;
                }
                else if (fieldData.DefaultValue is int)
                {
                    selectlist.SelectedIndex = (int)fieldData.DefaultValue;
                }
                return(selectlist);

            // create radio buttons
            case FormFieldType.RadioButtons:
                var radiosPanel = new Panel(new Vector2(0, -1), PanelSkin.None, Anchor.Auto);
                radiosPanel.Padding = Vector2.Zero;
                foreach (var choice in fieldData.Choices)
                {
                    var radio = new RadioButton(choice, isChecked: (fieldData.DefaultValue as string) == choice);
                    radiosPanel.AddChild(radio);
                }
                return(radiosPanel);

            // create a new secion
            case FormFieldType.Section:
                var containerPanel = new Panel(new Vector2(0, -1), PanelSkin.None, Anchor.Auto);
                containerPanel.Padding = Vector2.Zero;
                if (needLabel)
                {
                    containerPanel.AddChild(new Paragraph(fieldData.FieldLabel));
                }
                containerPanel.AddChild(new HorizontalLine());
                needLabel = false;
                return(containerPanel);

            // unknown type!
            default:
                throw new Exceptions.InvalidStateException("Unknown field type!");
            }
        }