Exemple #1
0
        protected override bool PopulateDropDown()
        {
            availablePillars = PillarCustomizer.instance.GetAvailablePillars(SelectedPrefab, PillarType);

            if (SelectedPrefab != null && availablePillars != null)
            {
                var defaultPillar = PillarCustomizer.instance.GetDefaultPillar(SelectedPrefab, PillarType);
                var activePillar  = PillarCustomizer.instance.GetActivePillar(SelectedPrefab, PillarType);

                DropDown.items = new string[0];

                foreach (var pillar in availablePillars)
                {
                    var itemName = UIUtil.GenerateBeautifiedPrefabName(pillar);
                    itemName = BeautifyNameEvenMore(itemName);
                    if (pillar == defaultPillar)
                    {
                        itemName += " (Default)";
                    }
                    DropDown.AddItem(itemName);

                    if (pillar == activePillar)
                    {
                        DropDown.selectedIndex = DropDown.items.Length - 1;
                    }
                }

                if (availablePillars.Count >= 2)
                {
                    return(true);
                }
            }
            return(false);
        }
Exemple #2
0
        private void InitializeMenu(ContentManager content)
        {
            UserInterface.Initialize(content, BuiltinThemes.hd);

            _filterPanel       = new Panel(new Vector2(400, 300), PanelSkin.Default, Anchor.TopLeft);
            _antiAliasingPanel = new Panel(new Vector2(400, 300), PanelSkin.Default, Anchor.TopLeft);
            _resolutionPanel   = new Panel(new Vector2(400, 300), PanelSkin.Default, Anchor.TopLeft);

            UserInterface.Active.AddEntity(_filterPanel);
            UserInterface.Active.AddEntity(_antiAliasingPanel);
            UserInterface.Active.AddEntity(_resolutionPanel);

            _filterLinearMagnify    = new CheckBox("Magnifier linear filter");
            _filterMinmap           = new CheckBox("Mipmap filter");
            _filterMinmapBias       = new Slider(0, 100);
            _filterMinmapBias.Value = 0;

            _filterPanel.AddChild(new Header("Filters"));
            _filterPanel.AddChild(new HorizontalLine());
            _filterPanel.AddChild(_filterLinearMagnify);
            _filterPanel.AddChild(_filterMinmap);
            _filterPanel.AddChild(new Label("Level of details bias"));
            _filterPanel.AddChild(_filterMinmapBias);

            _antiAliasingMsaa         = new CheckBox("MSAA");
            _antiAliasingMsaa.Checked = true;

            _antiAliasingPanel.AddChild(new Header("Anti aliasing"));
            _antiAliasingPanel.AddChild(new HorizontalLine());
            _antiAliasingPanel.AddChild(_antiAliasingMsaa);

            _resolution = new DropDown();
            _resolution.AddItem("1440x900");
            _resolution.AddItem("1900x1080");
            _resolution.AddItem("1600x960");

            _resolutionPanel.AddChild(new Header("Resolution"));
            _resolutionPanel.AddChild(new HorizontalLine());
            _resolutionPanel.AddChild(_resolution);

            _filterLinearMagnify.OnValueChange = (Entity e) => UpdateOptions();
            _filterMinmap.OnValueChange        = (Entity e) => UpdateOptions();
            _filterMinmapBias.OnValueChange    = (Entity e) => UpdateOptions();
            _resolution.OnValueChange          = (Entity e) => UpdateOptions();
            _antiAliasingMsaa.OnValueChange    = (Entity e) => UpdateOptions();
            UpdateOptions();
        }
Exemple #3
0
        public OptionsMenu() : base("Options")
        {
            Skin = PanelSkin.Default;

            PlayerName.PlaceholderText = "Enter your Name";

            Resolution = new DropDown(new Vector2(0, 280));
            var resolutions = Ballz.The().GetResolutions();

            foreach (var resolution in resolutions)
            {
                Resolution.AddItem($"{resolution.Width}x{resolution.Height}");
            }

            LoadSettings();

            AddItem(new Label("Player Name:"));
            AddItem(PlayerName);

            AddItem(EnableFullscreen);

            AddItem(new Label("Screen Resolution:"));
            AddItem(Resolution);

            AddItem(new Label("Sound Volume:"));
            AddItem(MasterVolume);

            AddItem(new Label("Music Volume:"));
            AddItem(MusicVolume);

            var backButton = new MenuButton(
                "Back",
                size: new Vector2(0.5f, -1.0f),
                skin: ButtonSkin.Alternative,
                anchor: Anchor.BottomLeft,
                click: () => Ballz.The().Logic.MenuGoBack()
                );

            AddItem(backButton);
            var saveButton = new MenuButton(
                "OK",
                size: new Vector2(0.5f, -1.0f),
                skin: ButtonSkin.Alternative,
                anchor: Anchor.BottomRight,
                click: SaveSettings
                );

            AddItem(saveButton);
        }
Exemple #4
0
        protected override bool PopulateDropDown()
        {
            _availableStreetLights = PropCustomizer.Instance.GetAvailableStreetLights(SelectedPrefab);

            if (SelectedPrefab != null && _availableStreetLights != null && PropCustomizer.Instance.HasStreetLights(SelectedPrefab))
            {
                var defaultProp = PropCustomizer.Instance.GetDefaultStreetLight(SelectedPrefab);
                var activeProp  = PropCustomizer.Instance.GetActiveStreetLight(SelectedPrefab);

                DropDown.items = new string[0];

                foreach (var prop in _availableStreetLights)
                {
                    var itemName = UIUtil.GenerateBeautifiedPrefabName(prop);
                    itemName = BeautifyNameEvenMore(itemName);
                    if (prop == defaultProp)
                    {
                        itemName += " (Default)";
                    }

                    DropDown.AddItem(itemName);

                    if (prop == activeProp)
                    {
                        DropDown.selectedIndex = DropDown.items.Length - 1;
                    }
                }

                var defaultDistance = PropCustomizer.Instance.GetDefaultStreetLightDistance(SelectedPrefab);
                var activeDistance  = PropCustomizer.Instance.GetActiveStreetLightDistance(SelectedPrefab);
                TextField.text    = activeDistance.ToString(CultureInfo.InvariantCulture);
                TextField.tooltip = $"Distance between street lights in m (default {defaultDistance})\nValue must be between 1 and 100!";

                if (_availableStreetLights.Count >= 2)
                {
                    DropDown.Enable();
                }
                else
                {
                    DropDown.Disable();
                }
                return(true);
            }
            return(false);
        }
Exemple #5
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);
        }
Exemple #6
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!");
            }
        }
Exemple #7
0
        public void Activate()
        {
            Window window = NUIApplication.GetDefaultWindow();

            root = new View()
            {
                Size2D          = new Size2D(1920, 1080),
                BackgroundColor = Color.White,
            };
            window.Add(root);

            ///////////////////////////////////////////////Create by Property//////////////////////////////////////////////////////////
            createText[0]            = new TextLabel();
            createText[0].Text       = "Create DropDown just by properties";
            createText[0].Size2D     = new Size2D(450, 100);
            createText[0].Position2D = new Position2D(200, 100);
            createText[0].MultiLine  = true;
            root.Add(createText[0]);

            #region CreateByProperty
            dropDown                                       = new DropDown();
            dropDown.Size2D                                = new Size2D(900, 108);
            dropDown.Position2D                            = new Position2D(50, 300);
            dropDown.Style.HeaderText.Text                 = "TitleArea";
            dropDown.Style.HeaderText.TextColor            = new Color(0, 0, 0, 1);
            dropDown.Style.HeaderText.PointSize            = 28;
            dropDown.Style.HeaderText.FontFamily           = "SamsungOneUI 500C";
            dropDown.Style.Button.Text.Text                = "DropDown Text";
            dropDown.Style.Button.Text.TextColor           = new Color(0, 0, 0, 1);
            dropDown.Style.Button.Text.PointSize           = 20;
            dropDown.Style.Button.Text.FontFamily          = "SamsungOneUI 500";
            dropDown.Style.Button.Icon.ResourceUrl         = CommonResource.GetFHResourcePath() + "6. List/list_ic_dropdown.png";
            dropDown.Style.Button.Icon.Size                = new Size(48, 48);
            dropDown.Style.Button.IconRelativeOrientation  = Button.IconOrientation.Right;
            dropDown.Style.Button.PositionX                = 56;
            dropDown.SpaceBetweenButtonTextAndIcon         = 8;
            dropDown.Style.ListBackgroundImage.ResourceUrl = CommonResource.GetFHResourcePath() + "10. Drop Down/dropdown_bg.png";
            dropDown.Style.ListBackgroundImage.Border      = new Rectangle(51, 51, 51, 51);
            dropDown.Style.ListBackgroundImage.Size        = new Size(360, 500);
            dropDown.ListMargin.Start                      = 20;
            dropDown.ListMargin.Top                        = 20;
            dropDown.ListPadding                           = new Extents(4, 4, 4, 4);
            root.Add(dropDown);

            for (int i = 0; i < 8; i++)
            {
                DropDown.DropDownDataItem item = new DropDown.DropDownDataItem();
                item.Size            = new Size(360, 96);
                item.BackgroundColor = new Selector <Color>
                {
                    Pressed = new Color(0, 0, 0, 0.4f),
                    Other   = new Color(1, 1, 1, 0),
                };
                item.Text                    = "Normal list " + i;
                item.PointSize               = 18;
                item.FontFamily              = "SamsungOne 500";
                item.TextPosition            = new Position(28, 0);
                item.CheckImageSize          = new Size(40, 40);
                item.CheckImageResourceUrl   = CommonResource.GetFHResourcePath() + "10. Drop Down/dropdown_checkbox_on.png";
                item.CheckImageGapToBoundary = 16;
                dropDown.AddItem(item);
            }

            dropDown.SelectedItemIndex = 3;
            //dropDown.DeleteItem(1);

            //DropDown.DropDownItemData insertItem = new DropDown.DropDownItemData();
            //insertItem.Size2D = new Size2D(360, 96);
            //insertItem.BackgroundColorSelector = new Selector<Color>
            //{
            //    Pressed = new Color(0, 0, 0, 0.4f),
            //    Other = new Color(1, 1, 1, 0),
            //};
            //insertItem.Text = "Insert Normal list ";
            //insertItem.PointSize = 18;
            //insertItem.FontFamily = "SamsungOne 500";
            //insertItem.TextPosition2D = new Position2D(28, 0);
            //insertItem.CheckImageSize = new Size2D(40, 40);
            //insertItem.CheckImageResourceUrl = CommonReosurce.GetFHResourcePath() + "10. Drop Down/dropdown_checkbox_on.png";
            //insertItem.CheckImageRightSpace = 16;
            //dropDown.InsertItem(insertItem, 1);
            ////////Attach scrollbar///////////
            scrollBar            = new ScrollBar();
            scrollBar.Direction  = ScrollBar.DirectionType.Vertical;
            scrollBar.Position2D = new Position2D(394, 2);
            scrollBar.Size2D     = new Size2D(4, 446);
            scrollBar.Style.Track.BackgroundColor = Color.Green;
            scrollBar.Style.Thumb.Size            = new Size(4, 30);
            scrollBar.Style.Thumb.BackgroundColor = Color.Yellow;
            scrollBar.Style.Track.ResourceUrl     = CommonResource.GetTVResourcePath() + "component/c_progressbar/c_progressbar_white_buffering.png";
            dropDown.AttachScrollBar(scrollBar);

            #endregion
            ///////////////////////////////////////////////Create by Attributes//////////////////////////////////////////////////////////
            createText[1]            = new TextLabel();
            createText[1].Text       = "Create DropDown just by Attributes";
            createText[1].Size2D     = new Size2D(450, 100);
            createText[1].Position2D = new Position2D(1000, 100);
            createText[1].MultiLine  = true;
            root.Add(createText[1]);

            #region CreateByAttributes

            DropDownStyle attrs = new DropDownStyle
            {
                HeaderText = new TextLabelStyle
                {
                    Text = new Selector <string> {
                        All = "TitleArea"
                    },
                    PointSize = new Selector <float?> {
                        All = 28
                    },
                    TextColor = new Selector <Color> {
                        All = new Color(0, 0, 0, 1)
                    },
                    FontFamily = "SamsungOneUI 500C",
                },

                Button = new ButtonStyle
                {
                    Text = new TextLabelStyle
                    {
                        Text = new Selector <string> {
                            All = "DropDown Text"
                        },
                        PointSize = new Selector <float?> {
                            All = 20
                        },
                        TextColor = new Selector <Color> {
                            All = new Color(0, 0, 0, 1)
                        },
                        FontFamily = "SamsungOneUI 500",
                    },
                    Icon = new ImageViewStyle
                    {
                        Size        = new Size(48, 48),
                        ResourceUrl = new Selector <string> {
                            All = CommonResource.GetFHResourcePath() + "6. List/list_ic_dropdown.png"
                        },
                    },
                    IconRelativeOrientation = Button.IconOrientation.Right,
                    PositionX = 56,
                },
                ListBackgroundImage = new ImageViewStyle
                {
                    ResourceUrl = new Selector <string> {
                        All = CommonResource.GetFHResourcePath() + "10. Drop Down/dropdown_bg.png"
                    },
                    Border = new Selector <Rectangle> {
                        All = new Rectangle(51, 51, 51, 51)
                    },
                    Size = new Size(360, 500),
                },
                SpaceBetweenButtonTextAndIcon = 8,
                ListMargin      = new Extents(20, 0, 20, 0),
                BackgroundColor = new Selector <Color> {
                    All = new Color(1, 1, 1, 1)
                },
                ListPadding = new Extents(4, 4, 4, 4),
            };

            dropDown2            = new DropDown(attrs);
            dropDown2.Size2D     = new Size2D(900, 108);
            dropDown2.Position2D = new Position2D(1000, 300);
            root.Add(dropDown2);

            DropDownItemStyle itemAttrs = new DropDownItemStyle
            {
                BackgroundColor = new Selector <Color>
                {
                    Pressed = new Color(0, 0, 0, 0.4f),
                    Other   = new Color(1, 1, 1, 0),
                },
                Text = new TextLabelStyle
                {
                    PointSize = new Selector <float?> {
                        All = 18
                    },
                    FontFamily = "SamsungOne 500",
                    Position   = new Position(28, 0),
                },
                CheckImage = new ImageViewStyle
                {
                    Size        = new Size(40, 40),
                    ResourceUrl = new Selector <string> {
                        All = CommonResource.GetFHResourcePath() + "10. Drop Down/dropdown_checkbox_on.png"
                    },
                },
                CheckImageGapToBoundary = 16,
            };

            for (int i = 0; i < 8; i++)
            {
                DropDown.DropDownDataItem item = new DropDown.DropDownDataItem(itemAttrs);
                item.Size = new Size(360, 96);
                item.Text = "Normal list " + i;
                dropDown2.AddItem(item);
            }
            dropDown2.SelectedItemIndex = 0;

            ////////Attach scrollbar///////////
            scrollBar2            = new ScrollBar();
            scrollBar2.Direction  = ScrollBar.DirectionType.Vertical;
            scrollBar2.Position2D = new Position2D(394, 2);
            scrollBar2.Size2D     = new Size2D(4, 446);
            scrollBar2.Style.Track.BackgroundColor = Color.Green;
            scrollBar2.Style.Thumb.Size            = new Size(4, 30);
            scrollBar2.Style.Thumb.BackgroundColor = Color.Yellow;
            scrollBar2.Style.Track.ResourceUrl     = CommonResource.GetTVResourcePath() + "component/c_progressbar/c_progressbar_white_buffering.png";
            dropDown2.AttachScrollBar(scrollBar2);

            #endregion
        }
Exemple #8
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();
        }
Exemple #9
0
        public MultiplayerScene()
        {
            this.SetDesignResolution(1200, 600, SceneResolutionPolicy.None);
            Core.Instance.Screen.SetSize(1200, 600);

            this.AddRenderer(new DefaultRenderer());

            this.AddEntitySystem(new FieldMeshGeneratorSystem());
            this.AddEntitySystem(new FieldClickUpdateSystem(this));
            this.AddEntitySystem(new ApplyTurnUpdateSystem(this));
            this.AddEntitySystem(new CounterToTextUpdateSystem());
            this.AddEntitySystem(new MultiplayerGameOverUpdateSystem(this));
            this.AddEntitySystem(new TextUIUpdateSystem());
            this.AddEntitySystem(new AIUpdateSystem());
            this.AddEntitySystem(new UIUpdateSystem(Core.Instance.Content));
            this.AddEntitySystem(new TurnSelectorUpdateSystem());
            this.AddEntitySystem(new ColorSelectorGrayingUpdateSystem(this));

            this.AddEntitySystemExecutionOrder <AIUpdateSystem, TurnSelectorUpdateSystem>();
            this.AddEntitySystemExecutionOrder <FieldClickUpdateSystem, TurnSelectorUpdateSystem>();
            this.AddEntitySystemExecutionOrder <TurnSelectorUpdateSystem, ApplyTurnUpdateSystem>();
            this.AddEntitySystemExecutionOrder <ApplyTurnUpdateSystem, FieldMeshGeneratorSystem>();
            this.AddEntitySystemExecutionOrder <ApplyTurnUpdateSystem, MultiplayerGameOverUpdateSystem>();
            this.AddEntitySystemExecutionOrder <ApplyTurnUpdateSystem, CounterToTextUpdateSystem>();
            this.AddEntitySystemExecutionOrder <ApplyTurnUpdateSystem, ColorSelectorGrayingUpdateSystem>();
            this.AddEntitySystemExecutionOrder <ColorSelectorGrayingUpdateSystem, FieldMeshGeneratorSystem>();
            this.AddEntitySystemExecutionOrder <CounterToTextUpdateSystem, MultiplayerGameOverUpdateSystem>();
            this.AddEntitySystemExecutionOrder <CounterToTextUpdateSystem, TextUIUpdateSystem>();
            this.AddEntitySystemExecutionOrder <UIUpdateSystem, TextUIUpdateSystem>();

            var moonTex = Core.Instance.Content.Load <Texture2D>(ContentPaths.moon);

            var common = this.CreateEntity("Common");

            common.AddComponent(new CameraShakeComponent(this.Camera));

            var fieldEntity = this.CreateEntity("Field");

            fieldEntity.AddComponent <PositionComponent>().Position = new Vector2(285, 5);
            fieldEntity.AddComponent <TurnMadeComponent>();
            var field = fieldEntity.AddComponent <FieldComponent>();

            field.BlockSize = 600 / SharedData.MapSize;
            field.Map       = new int[SharedData.MapSize, SharedData.MapSize];
            field.Texture   = moonTex;

            var colorSelector         = this.CreateEntity("ColorSelector");
            var colorSelectorPosition = colorSelector.AddComponent <PositionComponent>();
            var colorSelectionField   = colorSelector.AddComponent <FieldComponent>();

            colorSelectorPosition.Position    = new Vector2(1000, Core.Instance.Screen.Center.Y - (400 / SharedData.ColorsCount) * SharedData.ColorsCount / 2f);
            colorSelectionField.Map           = new int[1, SharedData.ColorsCount];
            colorSelectionField.Texture       = moonTex;
            colorSelectionField.BlockSize     = 400 / SharedData.ColorsCount - 10;
            colorSelectionField.BlockInterval = 10;

            var player1     = this.CreateEntity("Player1");
            var player1Turn = player1.AddComponent <TurnMadeComponent>();

            player1Turn.PlayerX  = 0;
            player1Turn.PlayerY  = 0;
            player1Turn.TurnMade = false;

            var player2     = this.CreateEntity("Player2");
            var player2Turn = player2.AddComponent <TurnMadeComponent>();

            player2Turn.PlayerX  = SharedData.MapSize - 1;
            player2Turn.PlayerY  = SharedData.MapSize - 1;
            player2Turn.TurnMade = true;

            var switcher = fieldEntity.AddComponent(
                new PlayerSwitcherComponent {
                Players = new List <TurnMadeComponent> {
                    player1Turn, player2Turn
                }
            });

            var counterEntity = this.CreateEntity("Counter");
            var counter       = counterEntity.AddComponent <CounterComponent>();

            counter.Players.Add(new CounterComponent.PlayerData());
            counter.Players.Add(new CounterComponent.PlayerData());
            counterEntity.AddComponent <TextComponent>().Text         = "Test text;";
            counterEntity.AddComponent <ColorComponent>().Color       = Color.Gray;
            counterEntity.AddComponent <RenderOrderComponent>().Order = -1;

            var uiEntity = this.CreateEntity("UI");
            var ui       = uiEntity.AddComponent <UIComponent>();

            ui.UserInterface.ShowCursor = false;
            var panel = ui.UserInterface.AddEntity(new Panel(new Vector2(250, 250), PanelSkin.None, Anchor.CenterLeft));

            var player1Label    = new Label("Player 1", Anchor.TopLeft, null, new Vector2(0, 60));
            var player1DropDown = new DropDown(new Vector2(250, -1), Anchor.TopLeft, new Vector2(0, 90));

            player1DropDown.AddItem("User");
            player1DropDown.AddItem("Easy");
            player1DropDown.AddItem("Med.");
            player1DropDown.AddItem("Hard");
            player1DropDown.SelectedValue = "User";

            var player2Label    = new Label("Player 2", Anchor.TopLeft, null, new Vector2(300, 60));
            var player2DropDown = new DropDown(new Vector2(250, -1), Anchor.TopLeft, new Vector2(300, 90));

            player2DropDown.AddItem("User");
            player2DropDown.AddItem("Easy");
            player2DropDown.AddItem("Med.");
            player2DropDown.AddItem("Hard");
            player2DropDown.SelectedValue = "Hard";

            var colorsCountLabel    = new Label("Colors count", Anchor.TopLeft, null, new Vector2(0, 180));
            var colorsCountDropDown = new DropDown(new Vector2(250, -1), Anchor.TopLeft, new Vector2(0, 210));

            colorsCountDropDown.AddItem("4");
            colorsCountDropDown.AddItem("5");
            colorsCountDropDown.AddItem("6");
            colorsCountDropDown.AddItem("7");
            colorsCountDropDown.SelectedValue = SharedData.ColorsCount.ToString();

            var fieldSizeLabel    = new Label("Field size", Anchor.TopLeft, null, new Vector2(300, 180));
            var fieldSizeDropDown = new DropDown(new Vector2(250, -1), Anchor.TopLeft, new Vector2(300, 210));

            fieldSizeDropDown.AddItem("7");
            fieldSizeDropDown.AddItem("11");
            fieldSizeDropDown.AddItem("15");
            fieldSizeDropDown.AddItem("19");
            fieldSizeDropDown.SelectedValue = SharedData.MapSize.ToString();

            var settingsMessageBox = MessageBox.BuildMessageBox(
                "Settings",
                "",
                "Set",
                new Vector2(600, 450),
                new Entity[]
            {
                player1Label, player1DropDown, player2Label, player2DropDown, colorsCountLabel,
                colorsCountDropDown, fieldSizeLabel, fieldSizeDropDown
            });

            settingsMessageBox.OnDone = (b) =>
            {
                player1.Enabled                   = true;
                player2.Enabled                   = true;
                counter.Players[0].Name           = player1DropDown.SelectedValue;
                counter.Players[1].Name           = player2DropDown.SelectedValue;
                SharedData.ColorsCount            = int.Parse(colorsCountDropDown.SelectedValue);
                colorSelectorPosition.Position    = new Vector2(1000, Core.Instance.Screen.Center.Y - (400 / SharedData.ColorsCount) * SharedData.ColorsCount / 2f);
                colorSelectionField.Map           = new int[1, SharedData.ColorsCount];
                colorSelectionField.Texture       = moonTex;
                colorSelectionField.BlockSize     = 400 / SharedData.ColorsCount - 10;
                colorSelectionField.BlockInterval = 10;

                SharedData.MapSize  = int.Parse(fieldSizeDropDown.SelectedValue);
                field.BlockSize     = 600 / SharedData.MapSize;
                field.Map           = new int[SharedData.MapSize, SharedData.MapSize];
                field.Texture       = moonTex;
                player2Turn.PlayerX = SharedData.MapSize - 1;
                player2Turn.PlayerY = SharedData.MapSize - 1;

                this.InitPlayer(player1, player1Turn, switcher, player1DropDown.SelectedValue, field.Map);
                this.InitPlayer(player2, player2Turn, switcher, player2DropDown.SelectedValue, field.Map);
                this.Restart(field, counter);
            };

            panel.AddChild(
                new Button("Settings")
            {
                OnClick = (b) =>
                {
                    settingsMessageBox.Show();
                    player1.Enabled = false;
                    player2.Enabled = false;
                }
            });

            panel.AddChild(
                new Button("Back")
            {
                OnClick = (b) => { Core.Instance.SwitchScene(new GameChooseScene()); }
            });

            counter.Players[0].Name = player1DropDown.SelectedValue;
            counter.Players[1].Name = player2DropDown.SelectedValue;
            this.InitPlayer(player1, player1Turn, switcher, player1DropDown.SelectedValue, field.Map);
            this.InitPlayer(player2, player2Turn, switcher, player2DropDown.SelectedValue, field.Map);
            this.Restart(field, counter);

            UserInterface.Active = ui.UserInterface;
        }
Exemple #10
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();
        }
Exemple #11
0
        public HostGameMenu(bool isMultiplayer) : base(isMultiplayer ? "Host Game" : "Singleplayer Game")
        {
            Skin = PanelSkin.Default;

            if (isMultiplayer)
            {
                //AddItem(new Gui.InputBox("Public Name", true));
            }


            AddItem(new Label("Game Name:"));

            GameName.Value = Ballz.The().Settings.HostGameName;
            AddItem(GameName);

            AddItem(new Label("Map:"));
            // TODO: Map Select
            ModeSelect.AddItem("TestWorld2");
            ModeSelect.AddItem("Procedural");
            ModeSelect.AddItem("Desert");
            ModeSelect.SelectedIndex = 0;
            AddItem(ModeSelect);
            AddItem(TurnBased);

            ErrorLabel.SetStyleProperty("FillColor", new StyleProperty(Color.Red));
            AddItem(ErrorLabel);

            if (isMultiplayer)
            {
                var startGameButton = new MenuButton("Open Game", () =>
                {
                    var name = GameName.Value;
                    Ballz.The().Settings.HostGameName = name;
                    if (String.IsNullOrWhiteSpace(name))
                    {
                        ErrorLabel.Text = "Invalid Game Name!";
                        return;
                    }

                    var mapName        = ModeSelect.SelectedValue;
                    var usePlayerTurns = TurnBased.Checked;

                    var settings = new MatchSettings
                    {
                        GameName       = name,
                        IsPrivate      = false,
                        GameMode       = SessionFactory.SessionFactory.AvailableFactories.First(), // Todo: Select game modes
                        UsePlayerTurns = usePlayerTurns,
                        MapName        = mapName,
                        Teams          = new List <Team>()
                    };

                    Ballz.The().Logic.OpenMenu(new LobbyMenu(true, settings));
                });

                AddItem(startGameButton);
            }
            else
            {
                AddItem(new Label("Start Game"));
            }
            AddItem(new Gui.BackButton());
        }
Exemple #12
0
        public void Window_Jatek_Beallitasok_Grafika()
        {
            Panel  panel          = new Panel(new Vector2(800, 500));
            Button grafika_button = new Button("Grafika");

            //grafika_button.Locked=true;
            grafika_button.Locked = true;


            grafika_button.SetPosition(Anchor.TopLeft, new Vector2(0, -40));
            grafika_button.Size = new Vector2(190, 40);
            //grafika_button.
            grafika_button.FillColor = new Color(150, 150, 150);
            Header fent_kozep      = new Header("Beallitasok", Anchor.TopCenter);
            Label  felbontas_label = new Label("Felbontas:", Anchor.CenterLeft, new Vector2(230, 70), new Vector2(50));

            felbontas_label.SetPosition(Anchor.AutoInline, new Vector2(10, 95));
            felbontas_label.Scale = 1.5f;
            //felbontas_label.Size = new Vector2(40);
            DropDown felbontas = new DropDown(new Vector2(300, 200));

            felbontas.Anchor = Anchor.CenterRight;
            string[] felbontasok = new string[4];
            felbontasok[0] = "800x600";
            felbontasok[1] = "1240x640";
            felbontasok[2] = "1366x720";
            felbontasok[3] = "1920x1080";
            for (int i = 0; i < felbontasok.Length; i++)
            {
                string[] adatok = felbontasok[i].Split('x');
                if (int.Parse(adatok[0]) <= GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width &&
                    int.Parse(adatok[1]) <= GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height
                    )
                {
                    felbontas.AddItem(felbontasok[i]);
                }
            }

            felbontas.SelectedIndex = Game1.kijelolt_felbontas;
            CheckBox full_screen_check_box = new CheckBox("Teljes kepernyo");

            full_screen_check_box.Checked = true;
            Button Ment   = new Button("Alkalmaz");
            Button Vissza = new Button("Vissza");

            Game1.felbontas = felbontas.SelectedValue;

            UserInterface.Active.AddEntity(panel);



            panel.AddChild(grafika_button);
            panel.AddChild(fent_kozep);

            panel.AddChild(felbontas_label);

            panel.AddChild(felbontas);
            panel.AddChild(full_screen_check_box);
            panel.AddChild(Ment);
            panel.AddChild(Vissza);


            Ment.OnClick += (Entity entity) => {
                string   sor    = felbontas.SelectedValue;
                string[] adatok = sor.Split('x');
                Game1.x_felbontas = int.Parse(adatok[0]);
                Game1.y_felbontas = int.Parse(adatok[1]);
                Game1.ment        = true;
                Game1.felbontas   = felbontas.SelectedValue;
                if (full_screen_check_box.Checked)
                {
                    Game1.full_screen = true;
                }
                else
                {
                    Game1.full_screen = false;
                }
            };

            Vissza.OnClick += (Entity vissza) =>
            {
                Menu_Manager.Jatek_Menu_Eltuntet(Menu_Manager.Menu.Jatek_Beallitasok);
            };


            Window_Keszites(panel);
        }
Exemple #13
0
        internal void GenerateUserInterface(GameState tempGameState)
        {
            switch (tempGameState)
            {
            case GameState.MainGame:
                UserInterface.SetCursor(_game1.transparent);
                _game1.shopHUDButton = new Button("Shop (G)", anchor: Anchor.BottomRight, size: new Vector2(150, 50), skin: ButtonSkin.Alternative);
                _game1.shopHUDButton.ButtonParagraph.Scale     = 0.5f;
                _game1.shopHUDButton.ButtonParagraph.WrapWords = false;
                _game1.shopHUDButton.OnClick = (Entity btn) =>
                {
                    if (_game1.gameState == GameState.MainGame)
                    {
                        _game1.ChangeState(GameState.ShopMenu);
                    }
                    else if (_game1.gameState == GameState.ShopMenu)
                    {
                        _game1.ChangeState(GameState.MainGame);
                    }
                };
                UserInterface.AddEntity(_game1.shopHUDButton);
                break;

            case GameState.EndScreen:
                UserInterface.SetCursor(CursorType.Default);
                break;

            case GameState.MainMenu:
                _game1.mainMenuPanel = new Panel(new Vector2(300, 500));
                UserInterface.AddEntity(_game1.mainMenuPanel);
                mainMenuPlayButton = new Button("Play");
                mainMenuPlayButton.ButtonParagraph.Scale = 0.5f;
                var mainMenuControlsButton = new Button("Controls");
                mainMenuControlsButton.ButtonParagraph.Scale = 0.5f;
                mainMenuSettingsButton = new Button("Settings");
                mainMenuSettingsButton.ButtonParagraph.Scale = 0.5f;
                mainMenuExitButton = new Button("Quit");
                mainMenuExitButton.ButtonParagraph.Scale = 0.5f;

                //var LoadButton = new Button("Load names");
                //LoadButton.ButtonParagraph.Scale = 0.5f;

                _game1.mainMenuPanel.AddChild(mainMenuPlayButton);
                _game1.mainMenuPanel.AddChild(mainMenuControlsButton);
                _game1.mainMenuPanel.AddChild(mainMenuSettingsButton);
                _game1.mainMenuPanel.AddChild(mainMenuExitButton);

                //_game1.mainMenuPanel.AddChild(LoadButton);
                //LoadButton.OnClick = (Entity btn) =>
                //{
                //    _game1.LoadNames();
                //};

                mainMenuControlsButton.OnClick = (Entity btn) =>
                {
                    _game1.ChangeState(GameState.ControlsMenu);
                };
                mainMenuPlayButton.OnClick = (Entity btn) =>
                {
                    _game1.ResetGame();
                    _game1.ChangeState(GameState.MainGame);
                };
                mainMenuSettingsButton.OnClick = (Entity btn) =>
                {
                    _game1.ChangeState(GameState.SettingsMenu);
                };
                mainMenuExitButton.OnClick = (Entity btn) =>
                {
                    _game1.Exit();
                };
                break;

            case GameState.ControlsMenu:
                _game1.controlsMenuPanel = new Panel(new Vector2(700, 500));
                UserInterface.AddEntity(_game1.controlsMenuPanel);

                var backButton2 = new Button("Back");
                backButton2.ButtonParagraph.Scale = 0.5f;
                backButton2.OnClick = (Entity btn) =>
                {
                    _game1.ChangeState(GameState.MainMenu);
                };
                _game1.controlsMenuPanel.AddChild(backButton2);

                var forwardKeyButton = new Button(_game1.forwardKey.ToString(), size: new Vector2(75, 75), anchor: Anchor.TopLeft, offset: new Vector2(0, 75 + 30));
                forwardKeyButton.ButtonParagraph.Scale = 1.0f;
                forwardKeyButton.ButtonParagraph.SetAnchor(Anchor.BottomCenter);
                forwardKeyButton.ButtonParagraph.SetOffset(new Vector2(0, -27));

                var forwardKeyButton2 = new Button(_game1.forwardKey2.ToString(), size: new Vector2(75, 75), anchor: Anchor.TopLeft, offset: new Vector2(75 + 30, 75 + 30));
                forwardKeyButton2.ButtonParagraph.Scale = 1.0f;
                forwardKeyButton2.ButtonParagraph.SetAnchor(Anchor.BottomCenter);
                forwardKeyButton2.ButtonParagraph.SetOffset(new Vector2(0, -27));

                var forwardKeyParagraph = new Paragraph(" - Forward", anchor: Anchor.TopLeft, offset: new Vector2(150 + 30, 75 + 30 + 5));
                forwardKeyParagraph.Scale = 1.0f;
                _game1.controlsMenuPanel.AddChild(forwardKeyParagraph);
                _game1.controlsMenuPanel.AddChild(forwardKeyButton);
                _game1.controlsMenuPanel.AddChild(forwardKeyButton2);

                break;

            case GameState.SettingsMenu:
                UserInterface.SetCursor(CursorType.Default);

                _game1.settingsMenuPanel = new Panel(new Vector2(700, 500));
                UserInterface.AddEntity(_game1.settingsMenuPanel);

                var backButton = new Button("Back");
                backButton.ButtonParagraph.Scale = 0.5f;
                backButton.OnClick = btn =>
                {
                    _game1.ChangeState(_game1.oldGameState);
                };
                _game1.settingsMenuPanel.AddChild(backButton);

                var fullscreenCheckbox = new CheckBox("Fullscreen");
                fullscreenCheckbox.Checked             = _game1.Graphics.IsFullScreen;
                fullscreenCheckbox.TextParagraph.Scale = 0.5f;
                fullscreenCheckbox.OnValueChange       = box =>
                {
                    _game1.Graphics.IsFullScreen = fullscreenCheckbox.Checked;
                    _game1.Graphics.ApplyChanges();
                };
                _game1.settingsMenuPanel.AddChild(fullscreenCheckbox);

                var dropDown2 = new DropDown(new Vector2(0, 0));
                dropDown2.SelectedTextPanelParagraph.Text = CurrentScreenWidth + "x" + CurrentScreenHeight;
                dropDown2.AddItem("2560x1080");
                dropDown2.AddItem("1920x1080");
                dropDown2.AddItem("1680x1050");
                dropDown2.AddItem("1440x900");
                dropDown2.AddItem("1336x768");
                dropDown2.AddItem("1280x800");
                dropDown2.AddItem("1240x720");

                dropDown2.OnValueChange = (Entity drop) =>
                {
                    string selected = dropDown2.SelectedValue;
                    var    index    = selected.IndexOf('x');

                    var widthRes  = selected.Substring(0, index);
                    var heightRes = selected.Substring(index + 1);

                    CurrentScreenWidth  = Convert.ToInt16(widthRes);
                    CurrentScreenHeight = Convert.ToInt16(heightRes);
                    _game1.halfScreen   = new Vector2(CurrentScreenWidth / 2f, CurrentScreenHeight / 2f);
                    _game1.Graphics.ApplyChanges();
                };

                _game1.settingsMenuPanel.AddChild(dropDown2);

                break;

            case GameState.ShopMenu:
                UserInterface.SetCursor(CursorType.Default);
                _game1.shopPanel = new Panel(new Vector2(500, 300), anchor: Anchor.TopLeft, offset: new Vector2(0, 70));
                UserInterface.AddEntity(_game1.shopPanel);
                tabs = new PanelTabs();
                tab0 = tabs.AddTab("Warp");
                tab0.button.ButtonParagraph.Scale = 0.5f;

                tab1 = tabs.AddTab("Shop");
                tab1.button.ButtonParagraph.Scale = 0.5f;

                tab2 = tabs.AddTab("Upgrades");
                tab2.button.ButtonParagraph.Scale     = 0.5f;
                tab2.button.ButtonParagraph.WrapWords = false;

                tab3 = tabs.AddTab("Refitting");
                tab3.button.ButtonParagraph.Scale     = 0.5f;
                tab3.button.ButtonParagraph.WrapWords = false;

                //first tab

                var para = new Paragraph("Current sector: " + _game1.currentSector.Name);
                para.Scale     = 0.7f;
                para.WrapWords = false;
                tab0.panel.AddChild(para);

                warpButton = new Button("Warp to new sector");
                warpButton.ButtonParagraph.Scale = 0.5f;
                warpButton.OnClick = (Entity btn) =>
                {
                    ChangeSector(_game1.GenerateSector());
                    _game1.ChangeState(GameState.MainGame);
                };

                tab0.panel.AddChild(warpButton);
                tab0.panel.AddChild(new HorizontalLine());

                var dropDown = new DropDown(new Vector2(0, 0));
                dropDown.SelectedTextPanelParagraph.Scale = 0.5f;
                dropDown.SelectList.ItemsScale            = 0.5f;
                dropDown.SelectedTextPanelParagraph.Text  = "Warp to an old sector";
                for (int i = 0; i < _game1.sectors.Count; i++)
                {
                    if (_game1.sectors[i].Name == _game1.currentSector.Name)
                    {
                        continue;
                    }
                    dropDown.AddItem(_game1.sectors[i].Name);
                }
                dropDown.AttachedData  = dropDown.SelectedValue;
                dropDown.OnValueChange = (Entity drop) =>
                {
                    var dropDownSector = _game1.sectors.FirstOrDefault(x => x.Name == dropDown.SelectedValue);
                    ChangeSector(dropDownSector);
                };
                tab0.panel.AddChild(dropDown);

                //for (int i = 0; i < sectors.Count; i++)
                //{
                //    var button = new Button("Sector: " + sectors[i].Name);
                //    button.Identifier = i.ToString();
                //    button.OnClick = (Entity btn) => {
                //        currentSector = sectors[Convert.ToInt16(btn.Identifier)];
                //        ChangeState(GameState.MainGame);
                //    };
                //    tab0.panel.AddChild(button);
                //    tab0.panel.AddChild(new HorizontalLine());
                //}

                //second tab

                int height = 200;
                //TODO: offset = text width, measurestring
                for (int i = 0; i < _game1.availableShips.Count; i++)
                {
                    CreateShopSection(tab1, height, i);
                }

                tab1.panel.PanelOverflowBehavior = PanelOverflowBehavior.VerticalScroll;
                tab1.panel.Scrollbar.Max         = Convert.ToUInt16((int)((_game1.availableShips.Count * (height + 20)) - _game1.shopPanel.Size.Y));
                tab1.panel.Scrollbar.StepsCount  = (uint)_game1.availableShips.Count * 5;

                //third tab

                int height2 = 200;
                //TODO: offset = text width, measurestring
                for (int i = 0; i < _game1.availableUpgrades.Count; i++)     //TODO change max to randomly generated upgrades
                {
                    CreateUpgradeShopSection(tab2, height2, i);
                }

                tab2.panel.PanelOverflowBehavior = PanelOverflowBehavior.VerticalScroll;
                tab2.panel.Scrollbar.Max         = Convert.ToUInt16((int)((_game1.availableShips.Count * (height + 20)) - _game1.shopPanel.Size.Y));
                tab2.panel.Scrollbar.StepsCount  = (uint)_game1.availableShips.Count * 5;

                //fourth tab



                //last tab end

                _game1.shopPanel.AddChild(tabs);
                break;

            case GameState.PauseMenu:
                UserInterface.SetCursor(CursorType.Default);
                //panel
                _game1.pauseMenuPanel = new Panel(new Vector2(300, 520));
                UserInterface.AddEntity(_game1.pauseMenuPanel);
                //resumebutton
                var resumeButton = new Button("Resume");
                resumeButton.ButtonParagraph.Scale = 0.5f;
                resumeButton.OnClick = (Entity btn) =>
                {
                    _game1.ChangeState(GameState.MainGame);
                };
                _game1.pauseMenuPanel.AddChild(resumeButton);
                //save button
                var saveButton = new Button("Save game");
                saveButton.ButtonParagraph.Scale = 0.5f;
                saveButton.OnClick = (Entity btn) =>
                {
                    SaveGame();
                };
                _game1.pauseMenuPanel.AddChild(saveButton);
                //load button
                var loadButton = new Button("Load game");
                loadButton.ButtonParagraph.Scale = 0.5f;
                loadButton.OnClick = (Entity btn) =>
                {
                    LoadGame();
                };
                _game1.pauseMenuPanel.AddChild(loadButton);
                //settings button
                var settingsMenuButton = new Button("Settings");
                settingsMenuButton.ButtonParagraph.Scale = 0.5f;
                settingsMenuButton.OnClick = (Entity btn) =>
                {
                    _game1.ChangeState(GameState.SettingsMenu);
                };
                _game1.pauseMenuPanel.AddChild(settingsMenuButton);
                //main menu button
                var mainMenuButton = new Button("Main Menu");
                mainMenuButton.ButtonParagraph.Scale = 0.5f;
                mainMenuButton.OnClick = (Entity btn) =>
                {
                    _game1.ChangeState(GameState.MainMenu);
                };
                _game1.pauseMenuPanel.AddChild(mainMenuButton);
                //exit button
                var exitButton = new Button("Exit");
                exitButton.ButtonParagraph.Scale = 0.5f;
                exitButton.OnClick = (Entity btn) =>
                {
                    _game1.Exit();
                };
                _game1.pauseMenuPanel.AddChild(exitButton);

                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(tempGameState), tempGameState, null);
            }
        }
        void Initialize()
        {
            Window.Instance.BackgroundColor = Color.White;
            Size tenthOfWindowSize = new Size(Window.Instance.WindowSize.Width * .1f, Window.Instance.WindowSize.Height * .1f);

            LinearLayout linearLayout = new LinearLayout();

            linearLayout.LinearOrientation = LinearLayout.Orientation.Vertical;
            View root = new View()
            {
                Name = "example-root",
                WidthSpecification  = LayoutParamPolicies.MatchParent,
                HeightSpecification = LayoutParamPolicies.WrapContent,
                Padding             = new Extents((ushort)tenthOfWindowSize.Width, (ushort)tenthOfWindowSize.Width, (ushort)(tenthOfWindowSize.Height), 0),
                //Layout = linearLayout,
            };

            // Don't use root whilst testing DropDown style refactor, add to Window instead.
            //Window.Instance.Add(root);

            TextLabel text = new TextLabel()
            {
                Text                = "DropDown Clicked item string is ",
                PointSize           = 18,
                HeightSpecification = 80,
                WidthSpecification  = LayoutParamPolicies.MatchParent,
                HorizontalAlignment = HorizontalAlignment.Center,
                MultiLine           = true,
                BackgroundColor     = new Color(0.8f, 0.8f, 0.8f, 1.0f),
            };

            // Don't use root whilst testing DropDown style refactor, add to Window instead.
            //            root.Add(text);
            Window.Instance.Add(text);

            DropDown dropDown = new DropDown();

            dropDown.Size2D                                    = new Size2D(900, 108);
            dropDown.Position2D                                = new Position2D(50, 300);
            dropDown.Style.HeaderText.Text                     = "TitleArea";
            dropDown.Style.HeaderText.TextColor                = new Color(0, 0, 0, 1);
            dropDown.Style.HeaderText.PointSize                = 28;
            dropDown.Style.HeaderText.FontFamily               = "SamsungOneUI 500C";
            dropDown.Style.Button.Text.Text                    = "DropDown Text";
            dropDown.Style.Button.Text.TextColor               = new Color(0, 0, 0, 1);
            dropDown.Style.Button.Text.PointSize               = 20;
            dropDown.Style.Button.Text.FontFamily              = "SamsungOneUI 500";
            dropDown.Style.Button.Icon.ResourceUrl             = this.DirectoryInfo.Resource + TestImages.images[2];
            dropDown.Style.Button.Icon.Size                    = new Size(48, 48);
            dropDown.Style.Button.BackgroundColor.Pressed      = new Color(0, 1, 0, 0.4f);
            dropDown.Style.Button.BackgroundColor.Normal       = new Color(0, 0, 1, 0.4f);
            dropDown.Style.Button.Size                         = new Size(300, 60);
            dropDown.Space.Start                               = 56;
            dropDown.SpaceBetweenButtonTextAndIcon             = 8;
            dropDown.Style.ListBackgroundImage.ResourceUrl     = this.DirectoryInfo.Resource + TestImages.images[0];
            dropDown.Style.ListBackgroundImage.Border          = new Rectangle(51, 51, 51, 51);
            dropDown.Style.ListBackgroundImage.BackgroundColor = new Color(1, 1, 1, 1f);
            dropDown.ListMargin.Start                          = 20;
            dropDown.ListMargin.Top                            = 20;
            dropDown.BackgroundColor                           = new Color(1, 1, 1, 1);
            dropDown.ListSize                                  = new Size(360, 500);
            dropDown.ListPadding                               = new Extents(4, 4, 4, 4);

            // Don't use root whilst testing DropDown style refactor, add to Window instead.
            //root.Add(dropDown);
            Window.Instance.Add(dropDown);

            for (int i = 0; i < 8; i++)
            {
                DropDown.DropDownDataItem item = new DropDown.DropDownDataItem();
                item.Size = new Size(360, 96);
                item.BackgroundColorSelector = new Selector <Color>
                {
                    Pressed = new Color(0, 0, 0, 0.4f),
                    Other   = new Color(1, 1, 1, 0),
                };
                item.Text                    = "Normal list " + i;
                item.PointSize               = 18;
                item.FontFamily              = "SamsungOne 500";
                item.TextPosition            = new Position(28, 0);
                item.CheckImageSize          = new Size(40, 40);
                item.CheckImageResourceUrl   = this.DirectoryInfo.Resource + TestImages.images[1];
                item.CheckImageGapToBoundary = 16;
                dropDown.AddItem(item);
            }

            dropDown.SelectedItemIndex = 2;

            dropDown.RaiseToTop();
            Window.Instance.KeyEvent += OnKeyEvent;
        }
Exemple #15
0
        public override void CreateControls(GUI gui)
        {
            listsPanel         = new FloatPanel(new Vector2(300, 200), "ENTITIES", false, false);
            listsPanel.Pos.X   = 0;
            listsPanel.Pos.Y   = 22;
            listsPanel.Visible = false;
            gui.AddChild(listsPanel);

            groupsList       = new ListBox(new Vector2(120, listsPanel.Size.Y - 24), 1, groupItemSelected);
            groupsList.Pos.X = 2;
            groupsList.Pos.Y = 2;
            listsPanel.AddChild(groupsList);

            entitiesList       = new ListBox(new Vector2(174, listsPanel.Size.Y - 24), 1, entityItemSelected);
            entitiesList.Pos.X = 124;
            entitiesList.Pos.Y = 2;
            listsPanel.AddChild(entitiesList);

            newEntityDropDown       = new DropDown(addEntityDropDownItemSelected);
            newEntityDropDown.Pos.X = listsPanel.Size.X - 20;
            listsPanel.AddChild(newEntityDropDown);

            newEntityDropDown.AddItem("New Checkpoint", 1);
            newEntityDropDown.AddItem("New Trigger", 1);
            newEntityDropDown.AddItem("New Recovery Truck", 1);
            newEntityDropDown.AddItem("New Cone", 1);
            newEntityDropDown.AddItem("New Explosion", 1);
            newEntityDropDown.AddItem("New Steam", 1);
            newEntityDropDown.AddItem("New Fuel Item", 1);
            newEntityDropDown.AddItem("New Shield Item", 1);
            newEntityDropDown.AddItem("New Ammo Item", 1);
            newEntityDropDown.AddItem("New Minigun Item", 1);
            newEntityDropDown.AddItem("New Missile Item", 1);
            newEntityDropDown.AddItem("New Booster Item", 1);

            layout();
        }
Exemple #16
0
        public void Activate()
        {
            Window window = NUIApplication.GetDefaultWindow();

            //Create root view with linear layout.
            root = new View()
            {
                Size            = new Size(1920, 1080),
                BackgroundColor = new Color(0.7f, 0.9f, 0.8f, 1.0f),
                Layout          = new LinearLayout()
                {
                    LinearOrientation = LinearLayout.Orientation.Horizontal,
                    CellPadding       = new Size(50, 50),
                    LinearAlignment   = LinearLayout.Alignment.Center,
                }
            };
            window.Add(root);

            ///////////////////////////////////////////////Create by Property//////////////////////////////////////////////////////////
            parent1 = new View()
            {
                Size   = new Size(900, 800),
                Layout = new LinearLayout()
                {
                    LinearOrientation = LinearLayout.Orientation.Vertical,
                    CellPadding       = new Size(50, 50),
                    LinearAlignment   = LinearLayout.Alignment.Top,
                }
            };

            root.Add(parent1);
            // Create a description text.
            createText[0]           = new TextLabel();
            createText[0].Text      = "Create DropDown just by properties";
            createText[0].Size      = new Size(800, 100);
            createText[0].MultiLine = true;
            parent1.Add(createText[0]);

            //Create a dropdown by property.
            #region CreateByProperty
            dropDown = new DropDown();
            var style = dropDown.Style;
            style.Button.BackgroundImage  = "";
            style.Button.Icon.ResourceUrl = CommonResource.GetFHResourcePath() + "6. List/list_ic_dropdown.png";
            style.Button.Text.PointSize   = 20;
            style.Button.Text.FontFamily  = "SamsungOneUI 500";
            style.Button.Text.TextColor   = new Color(0, 0, 0, 1);
            dropDown.ApplyStyle(style);
            dropDown.Size                            = new Size(900, 108);
            dropDown.HeaderText.Text                 = "TitleArea";
            dropDown.HeaderText.TextColor            = new Color(0, 0, 0, 1);
            dropDown.HeaderText.PointSize            = 28;
            dropDown.HeaderText.FontFamily           = "SamsungOneUI 500C";
            dropDown.HeaderText.PositionX            = 50;
            dropDown.Button.TextLabel.Text           = "DropDown Text";
            dropDown.Button.Icon.Size                = new Size(48, 48);
            dropDown.Button.IconRelativeOrientation  = Button.IconOrientation.Right;
            dropDown.Button.ParentOrigin             = ParentOrigin.CenterLeft;
            dropDown.Button.PivotPoint               = PivotPoint.CenterLeft;
            dropDown.Button.PositionX                = 56;
            dropDown.SpaceBetweenButtonTextAndIcon   = 8;
            dropDown.ListBackgroundImage.ResourceUrl = CommonResource.GetFHResourcePath() + "10. Drop Down/dropdown_bg.png";
            dropDown.ListBackgroundImage.Border      = new Rectangle(51, 51, 51, 51);
            dropDown.ListBackgroundImage.Size        = new Size(360, 500);
            dropDown.ListMargin.Start                = 20;
            dropDown.ListMargin.Top                  = 20;
            dropDown.ListPadding                     = new Extents(4, 4, 4, 4);
            dropDown.BackgroundColor                 = new Color(1, 1, 1, 1);
            parent1.Add(dropDown);
            for (int i = 0; i < 8; i++)
            {
                DropDown.DropDownDataItem item = new DropDown.DropDownDataItem();
                item.Size            = new Size(360, 96);
                item.BackgroundColor = new Selector <Color>
                {
                    Pressed = new Color(0, 0, 0, 0.4f),
                    Other   = new Color(1, 1, 1, 0),
                };
                item.Text                    = "Normal list " + i;
                item.PointSize               = 18;
                item.FontFamily              = "SamsungOne 500";
                item.TextPosition            = new Position(28, 0);
                item.CheckImageSize          = new Size(40, 40);
                item.CheckImageResourceUrl   = CommonResource.GetFHResourcePath() + "10. Drop Down/dropdown_checkbox_on.png";
                item.CheckImageGapToBoundary = 16;
                dropDown.AddItem(item);
            }

            dropDown.SelectedItemIndex = 3;

            ////////Attach scrollbar///////////
            scrollBar               = new ScrollBar();
            scrollBar.Direction     = ScrollBar.DirectionType.Vertical;
            scrollBar.Size          = new Size(4, 446);
            scrollBar.TrackColor    = Color.Green;
            scrollBar.ThumbSize     = new Size(4, 30);
            scrollBar.ThumbColor    = Color.Yellow;
            scrollBar.TrackImageURL = CommonResource.GetTVResourcePath() + "component/c_progressbar/c_progressbar_white_buffering.png";
            dropDown.AttachScrollBar(scrollBar);

            #endregion
            ///////////////////////////////////////////////Create by Attributes//////////////////////////////////////////////////////////
            parent2 = new View()
            {
                Size   = new Size(900, 800),
                Layout = new LinearLayout()
                {
                    LinearOrientation = LinearLayout.Orientation.Vertical,
                    CellPadding       = new Size(50, 50),
                    LinearAlignment   = LinearLayout.Alignment.Top,
                }
            };
            root.Add(parent2);

            // Create a description text.
            createText[1]           = new TextLabel();
            createText[1].Text      = "Create DropDown just by Attributes";
            createText[1].Size      = new Size(800, 100);
            createText[1].MultiLine = true;
            parent2.Add(createText[1]);

            //Create a dropdown by style.
            #region CreateByStyle

            DropDownStyle dropDownStyle = new DropDownStyle
            {
                HeaderText = new TextLabelStyle
                {
                    Text = new Selector <string> {
                        All = "TitleArea"
                    },
                    PointSize = new Selector <float?> {
                        All = 28
                    },
                    TextColor = new Selector <Color> {
                        All = new Color(0, 0, 0, 1)
                    },
                    FontFamily = "SamsungOneUI 500C",
                    PositionX  = 50,
                },

                Button = new ButtonStyle
                {
                    Text = new TextLabelStyle
                    {
                        Text = new Selector <string> {
                            All = "DropDown Text"
                        },
                        PointSize = new Selector <float?> {
                            All = 20
                        },
                        TextColor = new Selector <Color> {
                            All = new Color(0, 0, 0, 1)
                        },
                        FontFamily = "SamsungOneUI 500",
                    },
                    Icon = new ImageViewStyle
                    {
                        Size        = new Size(48, 48),
                        ResourceUrl = new Selector <string> {
                            All = CommonResource.GetFHResourcePath() + "6. List/list_ic_dropdown.png"
                        },
                    },
                    IconRelativeOrientation = Button.IconOrientation.Right,
                    PositionX       = 56,
                    BackgroundImage = "",
                },
                ListBackgroundImage = new ImageViewStyle
                {
                    ResourceUrl = new Selector <string> {
                        All = CommonResource.GetFHResourcePath() + "10. Drop Down/dropdown_bg.png"
                    },
                    Border = new Selector <Rectangle> {
                        All = new Rectangle(51, 51, 51, 51)
                    },
                    Size = new Size(360, 500),
                },
                SpaceBetweenButtonTextAndIcon = 8,
                ListMargin      = new Extents(20, 0, 20, 0),
                BackgroundColor = new Selector <Color> {
                    All = new Color(1, 1, 1, 1)
                },
                ListPadding = new Extents(4, 4, 4, 4),
            };

            dropDown2      = new DropDown(dropDownStyle);
            dropDown2.Size = new Size(900, 108);
            parent2.Add(dropDown2);

            DropDownItemStyle itemStyle = new DropDownItemStyle
            {
                BackgroundColor = new Selector <Color>
                {
                    Pressed = new Color(0, 0, 0, 0.4f),
                    Other   = new Color(1, 1, 1, 0),
                },
                Text = new TextLabelStyle
                {
                    PointSize = new Selector <float?> {
                        All = 18
                    },
                    FontFamily = "SamsungOne 500",
                    Position   = new Position(28, 0),
                },
                CheckImage = new ImageViewStyle
                {
                    Size        = new Size(40, 40),
                    ResourceUrl = new Selector <string> {
                        All = CommonResource.GetFHResourcePath() + "10. Drop Down/dropdown_checkbox_on.png"
                    },
                },
                CheckImageGapToBoundary = 16,
            };

            for (int i = 0; i < 8; i++)
            {
                DropDown.DropDownDataItem item = new DropDown.DropDownDataItem(itemStyle);
                item.Size = new Size(360, 96);
                item.Text = "Normal list " + i;
                dropDown2.AddItem(item);
            }
            dropDown2.SelectedItemIndex = 0;

            ////////Attach scrollbar///////////
            scrollBar2               = new ScrollBar();
            scrollBar2.Direction     = ScrollBar.DirectionType.Vertical;
            scrollBar2.Size          = new Size(4, 446);
            scrollBar2.TrackColor    = Color.Green;
            scrollBar2.ThumbSize     = new Size(4, 30);
            scrollBar2.ThumbColor    = Color.Yellow;
            scrollBar2.TrackImageURL = CommonResource.GetTVResourcePath() + "component/c_progressbar/c_progressbar_white_buffering.png";
            dropDown2.AttachScrollBar(scrollBar2);

            #endregion
            //Add all views into root view.
            root.Add(parent1);
            root.Add(parent2);
        }