示例#1
0
		void CreateGUI()
		{
			var cache = ResourceCache;
			UI ui = UI;

			UIElement root = ui.Root;
			// Load the style sheet from xml
			root.SetDefaultStyle(cache.GetXmlFile("UI/DefaultStyle.xml"));

			for (int i = 0; i < 10; i++)
			{
				Button b = new Button();
				root.AddChild(b);
				// Reference a style from the style sheet loaded earlier:
				b.SetStyle("Button", null);
				b.SetSize(300, 100);
				b.Position = new IntVector2(50 * i, 50 * i);

				b.SubscribeToDragMove(HandleDragMove);
				b.SubscribeToDragBegin(HandleDragBegin);
				b.SubscribeToDragCancel(HandleDragCancel);
				b.SubscribeToDragEnd(HandleDragEnd);

				{
					var t = new Text();
					b.AddChild(t);
					t.SetStyle("Text", null);
					t.HorizontalAlignment = HorizontalAlignment.Center;
					t.VerticalAlignment = VerticalAlignment.Center;
					t.Name = ("Text");
				}

				{
					var t = new Text();
					b.AddChild(t);
					t.SetStyle("Text", null);
					t.Name=("Event Touch");
					t.HorizontalAlignment=HorizontalAlignment.Center;
					t.VerticalAlignment=VerticalAlignment.Bottom;
				}

				{
					var t = new Text();
					b.AddChild(t);
					t.SetStyle("Text", null);
					t.Name=("Num Touch");
					t.HorizontalAlignment=HorizontalAlignment.Center;
					t.VerticalAlignment=VerticalAlignment.Top;
				}
			}

			for (int i = 0; i< 10; i++)
			{
				var t = new Text();
				root.AddChild(t);
				t.SetStyle("Text", null);
				t.Name=("Touch "+ i);
				t.Visible = false;
			}
		}
        public void MakeRebindActionButton(Container parentContainer, InputEvent inputAction)
        {
            Button button = new Button();

            if (inputAction != null)
            {
                //Keyboard
                if (inputAction is InputEventKey inputKey)
                {
                    KeyList key = (KeyList)inputKey.Scancode;
                    button.Text = key.ToString();
                }

                //Mouse
                if (inputAction is InputEventMouseButton inputMouseButton)
                {
                    button.Text = "Controls.Mouse." + inputMouseButton.ButtonIndex;
                    button.AddChild(new Translator());
                }

                //Controller
                if (inputAction is InputEventJoypadButton inputJoypadButton)
                {
                    button.Text = "Controls.Mouse." + inputJoypadButton.ButtonIndex;
                    button.AddChild(new Translator());
                }
            }
            else
            {
                button.Text = "Controls.RebindThis";
                button.AddChild(new Translator());
            }

            parentContainer.AddChild(button);
        }
示例#3
0
            public NumberInput(int x, int y, int value = 0)
            {
                Value = value;

                text = new TextBlock(Value.ToString(), 2, x + 22, y + 3);
                add  = new Button(x, y, 20, 20);
                sub  = new Button(x + 72, y, 20, 20);

                text.Color = Color.White;
                add.AddChild(new TextBlock("+", 2f, 5, 3));
                sub.AddChild(new TextBlock("-", 2f, 5, 3));

                MaxValue = 9999;
                MinValue = -999;

                add.OnLeftClick += (sender) =>
                {
                    if (add.ui.Input.KeyDown(OpenTK.Input.Key.LControl) ||
                        add.ui.Input.KeyDown(OpenTK.Input.Key.RControl))
                    {
                        Value += 10;
                    }
                    else if (add.ui.Input.KeyDown(OpenTK.Input.Key.LShift) ||
                             add.ui.Input.KeyDown(OpenTK.Input.Key.RShift))
                    {
                        Value += 5;
                    }
                    else
                    {
                        Value += 1;
                    }

                    Value = Value.Clamp(MinValue, MaxValue);

                    text.Text = Value.ToString();
                    ValueChanged?.Invoke(Value);
                };
                sub.OnLeftClick += (sender) =>
                {
                    if (add.ui.Input.KeyDown(OpenTK.Input.Key.LControl) ||
                        add.ui.Input.KeyDown(OpenTK.Input.Key.RControl))
                    {
                        Value -= 10;
                    }
                    else if (add.ui.Input.KeyDown(OpenTK.Input.Key.LShift) ||
                             add.ui.Input.KeyDown(OpenTK.Input.Key.RShift))
                    {
                        Value -= 5;
                    }
                    else
                    {
                        Value -= 1;
                    }

                    Value = Value.Clamp(MinValue, MaxValue);

                    text.Text = Value.ToString();
                    ValueChanged?.Invoke(Value);
                };
            }
示例#4
0
        private void UpdateWorlds()
        {
            worldFrame.ClearChildren();

            const int ButtonHeight = 60;
            const int Margin       = 10;

            int i = 0;

            foreach (var world in worlds)
            {
                Button button = new Button(0, i * (ButtonHeight + Margin), 0, ButtonHeight);
                button.Constraints.width = new RelativeConstraint(1, RelativeTo.Parent);
                button.OnLeftClick      += (sender) =>
                {
                    Game game = new Game(world);
                    game.OnExit += () => { SceneManager.LoadScene(new Transition(this, 10)); };
                    SceneManager.LoadScene(new Transition(game, 10));
                };

                TextBlock text = new TextBlock($"{world.Title}: {world.Levels.Count} Level", 3, 10, 10);
                text.Constraints.x = new CenterConstraint();
                text.Constraints.y = new CenterConstraint();
                text.Color         = Color.Black;
                button.AddChild(text);

                worldFrame.AddChild(button);
                i++;
            }
        }
示例#5
0
        private void InitUI()
        {
            ui = new UI.UI
            {
                Input = new Input(SceneManager.Window)
            };

            TextBlock title = new TextBlock("Welten", 4, 0, 50)
            {
                Color = Color.White
            };

            title.Constraints.x = new CenterConstraint();
            ui.Add(title);


            Button exitButton = new Button(40, 40, 40, 40)
            {
                Shortcut = Key.Escape
            };

            exitButton.OnLeftClick += (sender) =>
            {
                SceneManager.LoadScene(new Transition(new MainMenu(), 10));
            };
            UI.Image exitImage = new UI.Image(Textures.Get("Icons"), new RectangleF(0, 10, 10, 10), Color.Black)
            {
                Constraints = new UIConstraints(10, 10, 20, 20)
            };

            exitButton.AddChild(exitImage);
            ui.Add(exitButton);

            InitWorlds();
        }
示例#6
0
        void CreateDraggableFish()
        {
            var cache    = ResourceCache;
            var graphics = Graphics;

            // Create a draggable Fish button
            draggableFish           = new Button();
            draggableFish.Texture   = cache.GetTexture2D("Textures/UrhoDecal.dds");           // Set texture
            draggableFish.BlendMode = BlendMode.Add;
            draggableFish.SetSize(128, 128);
            draggableFish.SetPosition((graphics.Width - draggableFish.Width) / 2, 200);
            draggableFish.Name = "Fish";
            uiRoot.AddChild(draggableFish);

            // Add a tooltip to Fish button
            ToolTip toolTip = new ToolTip();

            draggableFish.AddChild(toolTip);
            toolTip.Position = new IntVector2(draggableFish.Width + 5, draggableFish.Width / 2);
            // slightly offset from close button
            BorderImage textHolder = new BorderImage();

            toolTip.AddChild(textHolder);
            textHolder.SetStyle("ToolTipBorderImage", null);
            var toolTipText = new Text();

            textHolder.AddChild(toolTipText);
            toolTipText.SetStyle("ToolTipText", null);
            toolTipText.Value = "Please drag me!";

            // Subscribe draggableFish to Drag Events (in order to make it draggable)
            draggableFish.SubscribeToDragBegin(HandleDragBegin);
            draggableFish.SubscribeToDragMove(HandleDragMove);
            draggableFish.SubscribeToDragEnd(HandleDragEnd);
        }
示例#7
0
文件: Bug219.cs 项目: wqg2016/urho
        void Reload()
        {
            // clear UI.Root
            UI.Root.RemoveAllChildren();

            const int count = 8;

            for (int i = 0; i < count; i++)
            {
                for (int j = 0; j < count; j++)
                {
                    var w = Graphics.Width / count;
                    var h = Graphics.Height / count;

                    var button = new Button();
                    UI.Root.AddChild(button);
                    button.SetStyle("Button");
                    button.SetSize(w, h);
                    button.Position = new IntVector2(w * i, h * j);

                    var label = new Text();
                    button.AddChild(label);
                    label.SetStyle("Text");
                    label.HorizontalAlignment = HorizontalAlignment.Center;
                    label.VerticalAlignment   = VerticalAlignment.Center;
                    label.Value = $"{i};{j}";

                    //button.Pressed += Button_Pressed;
                    button.Pressed += args => label.Value += "!";
                }
            }
        }
示例#8
0
        private void InitUI()
        {
            const int ButtonSize = 28;

            ui       = new UI.UI();
            ui.Input = SceneManager.Input;

            Button exitButton = new Button(20, 20, 40, 40)
            {
                Shortcut = Key.Escape
            };

            exitButton.OnLeftClick += (sender) => SceneManager.LoadScene(new Transition(new MainMenu(), 10));

            UI.Image exitImage = new UI.Image(Textures.Get("Icons"), new RectangleF(0, 10, 10, 10), Color.Black);
            exitImage.SetConstraints(new UIConstraints(10, 10, 20, 20));

            exitButton.AddChild(exitImage);
            ui.Add(exitButton);

            Frame buttonFrame = new Frame
            {
                Color       = Color.Transparent,
                Constraints = new UIConstraints(new CenterConstraint(), new CenterConstraint(), new PixelConstraint(ButtonSize * width), new PixelConstraint(ButtonSize * height))
            };

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    Button button = new Button(x * ButtonSize, y * ButtonSize, ButtonSize, ButtonSize)
                    {
                        Style = 1
                    };

                    int copyX = x;
                    int copyY = y;

                    button.OnLeftClick += (sender) =>
                    {
                        if (firstClick)
                        {
                            InitTiles(copyX, copyY);
                            firstClick = false;
                        }

                        RevealTile(copyX, copyY);
                    };
                    button.OnRightClick += (sender) => MarkTile(copyX, copyY);

                    tiles[x, y].Button = button;

                    buttonFrame.AddChild(button);
                }
            }

            ui.Add(buttonFrame);
        }
示例#9
0
        private void InitUI()
        {
            ui = new UI.UI
            {
                Input = new Input(SceneManager.Window)
            };

            TextBlock title = new TextBlock("Level", 4, 0, 50)
            {
                Color = Color.White
            };

            title.Constraints.x = new CenterConstraint();
            ui.Add(title);


            Button exitButton = new Button(20, 20, 40, 40)
            {
                Shortcut = Key.Escape
            };

            exitButton.OnLeftClick += (sender) => SceneManager.LoadScene(new Transition(new WorldMenu(), 10));

            UI.Image exitImage = new UI.Image(Textures.Get("Icons"), new RectangleF(0, 10, 10, 10), Color.Black)
            {
                Constraints = new UIConstraints(10, 10, 20, 20)
            };

            exitButton.AddChild(exitImage);
            ui.Add(exitButton);

            Button modeButton = new Button();

            modeButton.Shortcut = Key.Tab;
            modeButton.Color    = Color.FromArgb(100, 255, 100);
            modeButton.SetConstraints(new PixelConstraint(40, RelativeTo.Window, Direction.Left),
                                      new PixelConstraint(40, RelativeTo.Window, Direction.Bottom),
                                      new PixelConstraint(300),
                                      new PixelConstraint(60));

            TextBlock modeText = new TextBlock("Normal", 3);

            modeText.SetConstraints(new CenterConstraint(), new CenterConstraint(), new PixelConstraint((int)modeText.TextWidth), new PixelConstraint((int)modeText.TextHeight));
            modeButton.AddChild(modeText);

            modeButton.OnLeftClick += (sender) =>
            {
                normalMode = !normalMode;

                modeText.Text    = normalMode ? "Normal" : "Perfekt";
                modeButton.Color = normalMode ? Color.FromArgb(100, 255, 100) : Color.FromArgb(255, 100, 100);
                modeText.SetConstraints(new CenterConstraint(), new CenterConstraint(), new PixelConstraint((int)modeText.TextWidth), new PixelConstraint((int)modeText.TextHeight));
            };
            ui.Add(modeButton);
        }
示例#10
0
        public static void Main()
        {
            UserInterfaceControl button = new Button();
            UserInterfaceControl border = new Border();
            UserInterfaceControl text   = new Text();

            button.AddChild(text);
            border.AddChild(button);

            border.ShowOnDisplay(0);
        }
示例#11
0
        private void InitUI()
        {
            ui = new UI.UI
            {
                Input = SceneManager.Input
            };

            Button exitButton = new Button(40, 40, 40, 40)
            {
                Shortcut = Key.Escape
            };

            exitButton.OnLeftClick += (sender) =>
            {
                SceneManager.LoadScene(new Transition(new MainMenu(), 10));
            };
            UI.Image exitImage = new UI.Image(Textures.Get("Icons"), new RectangleF(0, 10, 10, 10), Color.Black);
            exitImage.SetConstraints(new UIConstraints(10, 10, 20, 20));

            exitButton.AddChild(exitImage);
            ui.Add(exitButton);

            Button weeklyButton = new Button(200, 40, 40, 40);

            weeklyButton.OnLeftClick += (sender) =>
            {
                if (!weekly.HasValue)
                {
                    Notification.Show("Wöchentliche Welt ist nicht verfügbar");
                    return;
                }

                Game game = new Game(weekly.Value);
                game.OnExit += () => { SceneManager.LoadScene(new Transition(this, 10)); };
                SceneManager.LoadScene(new Transition(game, 10));
            };

            ui.Add(weeklyButton);

            worldFrame = new Frame
            {
                Color       = Color.Transparent,
                Constraints = new UIConstraints(new CenterConstraint(),
                                                new PixelConstraint(100),
                                                new RelativeConstraint(0.8f, RelativeTo.Window),
                                                new PixelConstraint(200))
            };

            ui.Add(worldFrame);
        }
示例#12
0
        Button CreateButton(int x, int y, int xSize, int ySize, string text)
        {
            // Create the button and center the text onto it
            Button button = new Button();

            this.AddChild(button);
            button.SetStyleAuto(null);
            button.SetPosition(x, y);
            button.SetSize(xSize, ySize);

            Text buttonText = new Text();

            button.AddChild(buttonText);
            buttonText.SetAlignment(HorizontalAlignment.Center, VerticalAlignment.Center);
            buttonText.SetFontSize(20);
            buttonText.Value = text;

            return(button);
        }
示例#13
0
        Button CreateButton(string text, HorizontalAlignment align = HorizontalAlignment.Left)
        {
            var Button = new Button();

            // Create the button and center the text onto it
            Button.SetFixedSize(36, 36);
            Label = new Text()
            {
                Value = text,
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment   = VerticalAlignment.Center
            };
            Label.SetFont(Font, 20);

            Button.AddChild(Label);

            Button.SetFixedWidth(Button.GetChild(0).Width + 16);
            Button.SetStyleAuto(null);
            Button.HorizontalAlignment = align;
            return(Button);
        }
示例#14
0
		Button CreateButton(int x, int y, int xSize, int ySize, string text)
		{
			UIElement root = UI.Root;
			var cache = ResourceCache;
			Font font = cache.GetFont("Fonts/Anonymous Pro.ttf");

			// Create the button and center the text onto it
			Button button = new Button();
			root.AddChild(button);
			button.SetStyleAuto(null);
			button.SetPosition(x, y);
			button.SetSize(xSize, ySize);

			Text buttonText = new Text();
			button.AddChild(buttonText);
			buttonText.SetAlignment(HorizontalAlignment.Center, VerticalAlignment.Center);
			buttonText.SetFont(font, 12);
			buttonText.Value = text;

			return button;
		}
示例#15
0
        Button CreateButton(string text, int width)
        {
            var  cache = ResourceCache;
            Font font  = cache.GetFont("Fonts/Anonymous Pro.ttf");

            Button button = new Button();

            buttonContainer.AddChild(button);
            button.SetStyleAuto(null);
            button.SetFixedWidth(width);

            var buttonText = new Text();

            button.AddChild(buttonText);
            buttonText.SetFont(font, 12);
            buttonText.SetAlignment(HorizontalAlignment.Center, VerticalAlignment.Center);

            buttonText.Value = text;

            return(button);
        }
示例#16
0
        private void InitMenu(ResourceCache cache)
        {
            windowMenu = new Window();
            windowMenu.SetMinSize(Application.Graphics.Width / 2, Application.Graphics.Height / 4);
            windowMenu.SetLayout(LayoutMode.Vertical, 6, new IntRect(6, 6, 6, 6));
            windowMenu.SetAlignment(HorizontalAlignment.Center, VerticalAlignment.Bottom);
            XmlFile defaultUIStyle = cache.GetXmlFile(Assets.UI.DefaultStyle);

            windowMenu.SetStyleAuto(null);
            // Set the loaded style as default style
            windowMenu.SetDefaultStyle(defaultUIStyle);

            var buttonStart = new Button();

            textBlock       = new Text();
            textBlock.Value = "Start";
            textBlock.SetFont(cache.GetFont(Assets.Fonts.Font), Application.Graphics.Width / 15);

            textBlock.HorizontalAlignment = HorizontalAlignment.Center;
            textBlock.VerticalAlignment   = VerticalAlignment.Center;
            buttonStart.AddChild(textBlock);
            buttonStart.SubscribeToReleased(_ => Start());

            //settings
            var buttonSettings    = new Button();
            var textBlockSettings = new Text();

            textBlockSettings.Value = "Settings";
            textBlockSettings.SetFont(cache.GetFont(Assets.Fonts.Font), Application.Graphics.Width / 15);
            textBlockSettings.HorizontalAlignment = HorizontalAlignment.Center;
            textBlockSettings.VerticalAlignment   = VerticalAlignment.Center;
            buttonSettings.AddChild(textBlockSettings);
            buttonSettings.SubscribeToReleased(_ => ShowSettings());

            windowMenu.AddChild(buttonStart);
            windowMenu.AddChild(buttonSettings);
            buttonStart.SetStyleAuto(null);
            buttonSettings.SetStyleAuto(null);
            Application.UI.Root.AddChild(windowMenu);
        }
示例#17
0
        public static void Initialize(Urho.Application app, List <DebugAction> handlers)
        {
            app.UI.Root.SetDefaultStyle(CoreAssets.UIs.DefaultStyle);

            buttons = new List <Button>(handlers.Count);
            for (int j = 0; j < handlers.Count + 1; j++)
            {
                var w = app.Graphics.Width / (handlers.Count + 1);
                var h = app.Graphics.Height / 25;

                var button = new Button();
                app.UI.Root.AddChild(button);
                button.SetStyle("Button");
                button.SetSize(w, h);
                button.Position = new IntVector2(w * j, 0);
                button.Visible  = false;

                var label = new Text();
                button.AddChild(label);
                label.SetStyle("Text");
                label.SetFontSize((int)(label.FontSize / 1f));
                label.HorizontalAlignment = HorizontalAlignment.Center;
                label.VerticalAlignment   = VerticalAlignment.Center;

                int index = j;
                if (j == handlers.Count)
                {
                    label.Value     = "debug menu";
                    button.Visible  = true;
                    button.Pressed += args => buttons.ForEach(b => b.Visible = !b.Visible);
                }
                else
                {
                    label.Value     = handlers[j].Name;
                    button.Pressed += args => handlers[index].Action();
                    buttons.Add(button);
                }
            }
        }
示例#18
0
        Button CreateButton(int x, int y, int xSize, int ySize, string text)
        {
            UIElement root  = UI.Root;
            var       cache = ResourceCache;
            Font      font  = cache.GetFont("Fonts/Anonymous Pro.ttf");

            // Create the button and center the text onto it
            Button button = new Button();

            root.AddChild(button);
            button.SetStyleAuto(null);
            button.SetPosition(x, y);
            button.SetSize(xSize, ySize);

            Text buttonText = new Text();

            button.AddChild(buttonText);
            buttonText.SetAlignment(HorizontalAlignment.Center, VerticalAlignment.Center);
            buttonText.SetFont(font, 12);
            buttonText.Value = text;

            return(button);
        }
示例#19
0
        private void PopulateClientComponents()
        {
            _clientComponents.DisposeAllChildren();

            _clientComponents.AddChild(_clientComponentsSearchBar = new LineEdit
            {
                PlaceHolder         = Loc.GetString("Search"),
                SizeFlagsHorizontal = SizeFlags.FillExpand
            });

            _clientComponents.AddChild(_clientComponentsAddButton = new Button()
            {
                Text = Loc.GetString("Add Component"),
                SizeFlagsHorizontal = SizeFlags.FillExpand
            });

            _clientComponentsAddButton.OnPressed     += OnClientComponentsAddButtonPressed;
            _clientComponentsSearchBar.OnTextChanged += OnClientComponentsSearchBarChanged;

            var componentList = _entity.GetAllComponents().OrderBy(c => c.GetType().ToString());

            foreach (var component in componentList)
            {
                var button = new Button {
                    Text = TypeAbbreviation.Abbreviate(component.GetType()), TextAlign = Label.AlignMode.Left
                };
                var removeButton = new TextureButton()
                {
                    StyleClasses        = { SS14Window.StyleClassWindowCloseButton },
                    SizeFlagsHorizontal = SizeFlags.ShrinkEnd
                };
                button.OnPressed       += _ => ViewVariablesManager.OpenVV(component);
                removeButton.OnPressed += _ => RemoveClientComponent(component);
                button.AddChild(removeButton);
                _clientComponents.AddChild(button);
            }
        }
示例#20
0
        void CreateGUI()
        {
            var cache = ResourceCache;
            UI  ui    = UI;

            UIElement root = ui.Root;

            // Load the style sheet from xml
            root.SetDefaultStyle(cache.GetXmlFile("UI/DefaultStyle.xml"));

            for (int i = 0; i < 10; i++)
            {
                Button b = new Button();
                root.AddChild(b);
                // Reference a style from the style sheet loaded earlier:
                b.SetStyle("Button", null);
                b.SetSize(300, 100);
                b.Position = new IntVector2(50 * i, 50 * i);

                b.SubscribeToDragMove(HandleDragMove);
                b.SubscribeToDragBegin(HandleDragBegin);
                b.SubscribeToDragCancel(HandleDragCancel);
                b.SubscribeToDragEnd(HandleDragEnd);

                {
                    var t = new Text();
                    b.AddChild(t);
                    t.SetStyle("Text", null);
                    t.HorizontalAlignment = HorizontalAlignment.Center;
                    t.VerticalAlignment   = VerticalAlignment.Center;
                    t.Name = ("Text");
                }

                {
                    var t = new Text();
                    b.AddChild(t);
                    t.SetStyle("Text", null);
                    t.Name = ("Event Touch");
                    t.HorizontalAlignment = HorizontalAlignment.Center;
                    t.VerticalAlignment   = VerticalAlignment.Bottom;
                }

                {
                    var t = new Text();
                    b.AddChild(t);
                    t.SetStyle("Text", null);
                    t.Name = ("Num Touch");
                    t.HorizontalAlignment = HorizontalAlignment.Center;
                    t.VerticalAlignment   = VerticalAlignment.Top;
                }
            }

            for (int i = 0; i < 10; i++)
            {
                var t = new Text();
                root.AddChild(t);
                t.SetStyle("Text", null);
                t.Name    = ("Touch " + i);
                t.Visible = false;
            }
        }
示例#21
0
        void InitControls()
        {
            var cache = application.ResourceCache;
            // Create a Button
            Button button = new Button();

            button.Name      = "Button";
            button.MinHeight = 24;



            Text text = new Text();

            text.Value = "Save";
            text.SetFont(cache.GetFont(Assets.Fonts.Font), application.Graphics.Width / 30);
            text.HorizontalAlignment = HorizontalAlignment.Center;
            text.VerticalAlignment   = VerticalAlignment.Center;
            button.AddChild(text);

            var textPrivateKey = new Text();

            textPrivateKey.Value = "Private Key";

            textPrivateKey.HorizontalAlignment = HorizontalAlignment.Center;
            textPrivateKey.VerticalAlignment   = VerticalAlignment.Center;

            var textUrl = new Text();

            textUrl.Value = "Url";

            textUrl.HorizontalAlignment = HorizontalAlignment.Center;
            textUrl.VerticalAlignment   = VerticalAlignment.Center;

            // Create a LineEdit
            lineEditPrivateKey                               = new LineEdit();
            lineEditPrivateKey.Name                          = "lineEditprivateKey";
            lineEditPrivateKey.TextCopyable                  = true;
            lineEditPrivateKey.Cursor.VerticalAlignment      = VerticalAlignment.Center;
            lineEditPrivateKey.TextElement.VerticalAlignment = VerticalAlignment.Center;
            lineEditPrivateKey.Text                          = Ethereum.GameScoreService.PRIVATE_KEY;


            lineEditUrl      = new LineEdit();
            lineEditUrl.Name = "lineEditUrl";
            lineEditUrl.Cursor.VerticalAlignment      = VerticalAlignment.Center;
            lineEditUrl.TextElement.VerticalAlignment = VerticalAlignment.Center;
            lineEditUrl.TextCopyable = true;
            lineEditUrl.Text         = Ethereum.GameScoreService.DEFAULT_MORDEN;

            // Add controls to Window


            window.AddChild(textPrivateKey);
            window.AddChild(lineEditPrivateKey);
            window.AddChild(textUrl);
            window.AddChild(lineEditUrl);
            window.AddChild(button);
            // Apply previously set default style

            button.SetStyleAuto(null);
            lineEditPrivateKey.SetStyleAuto(null);
            lineEditUrl.SetStyleAuto(null);

            textPrivateKey.SetFont(cache.GetFont(Assets.Fonts.Font), application.Graphics.Width / 30);
            textUrl.SetFont(cache.GetFont(Assets.Fonts.Font), application.Graphics.Width / 30);
            lineEditPrivateKey.TextElement.SetFontSize(application.Graphics.Width / 20);
            lineEditUrl.TextElement.SetFontSize(application.Graphics.Width / 20);
            lineEditUrl.CursorPosition        = 0;
            lineEditPrivateKey.CursorPosition = 0;

            button.SubscribeToReleased(_ => Save());
        }
        void CreateScreenBody()
        {
            _container           = root.CreateSprite();
            _container.Texture   = GameInstance.ResourceCache.GetTexture2D(AssetsCoordinates.Generic.Boxes.ResourcePath);
            _container.ImageRect = AssetsCoordinates.Generic.Boxes.ContainerTrasparent;
            _container.SetSize((int)(dim.XScreenRatio * 1200), (int)(dim.YScreenRatio * 1400));
            _container.SetPosition(GameInstance.ScreenInfo.SetX(0), GameInstance.ScreenInfo.SetY(240));

            // No track window
            _noTrackWindow = new Window();
            _container.AddChild(_noTrackWindow);
            _noTrackWindow.SetPosition(GameInstance.ScreenInfo.SetY(1180), GameInstance.ScreenInfo.SetY(200));
            _noTrackWindow.SetSize(GameInstance.ScreenInfo.SetX(650), GameInstance.ScreenInfo.SetY(450));
            _noTrackWindow.Texture   = GameInstance.ResourceCache.GetTexture2D(AssetsCoordinates.Generic.Boxes.ResourcePath);
            _noTrackWindow.ImageRect = AssetsCoordinates.Generic.Boxes.PauseMenuBox;
            _noTrackWindow.Opacity   = 0.5f;
            //_noTrackWindow.SetColor(Color.Black);

            var noTrackText = new Text();

            _noTrackWindow.AddChild(noTrackText);
            noTrackText.SetPosition(GameInstance.ScreenInfo.SetX(20), GameInstance.ScreenInfo.SetY(15));
            noTrackText.SetSize((int)(dim.XScreenRatio * 610), (int)(dim.YScreenRatio * 370));
            noTrackText.UseDerivedOpacity = false;
            noTrackText.Value             = "Use SmartRoadSense to collect at least 15 minutes of road data and unlock new levels!";
            noTrackText.Wordwrap          = true;
            noTrackText.SetColor(Color.White);
            noTrackText.SetFont(font, 20);

            /*
             * ScrollBar scrollBar = new ScrollBar();
             * container.AddChild(scrollBar);
             *
             * scrollBar.SetPosition(GameInstance.ScreenInfo.SetX(10), GameInstance.ScreenInfo.SetY(10));
             * scrollBar.SetSize(GameInstance.ScreenInfo.SetX(1800), GameInstance.ScreenInfo.SetY(20));
             * scrollBar.SetColor(Color.Cyan);
             * scrollBar.Range = TrackManager.Instance.TrackCount;
             *
             * var slider = scrollBar.Slider;
             * slider.Range = TrackManager.Instance.TrackCount;
             * slider.SetColor(Color.Blue);
             *
             * slider.DragEnd += (DragEndEventArgs args) => {
             *  Debug.WriteLine("Scrollbar Value: " + scrollBar.Value);
             *  Debug.WriteLine("Slider: " + slider.Value);
             * };
             */
            _prevLevel = new Button();
            _container.AddChild(_prevLevel);
            _prevLevel.SetStyleAuto(null);
            _prevLevel.Opacity = 0.5f;
            _prevLevel.SetPosition(GameInstance.ScreenInfo.SetX(250), GameInstance.ScreenInfo.SetY(250));
            _prevLevel.SetSize((int)(dim.YScreenRatio * 400), (int)(dim.YScreenRatio * 400));
            _prevLevel.Texture = GameInstance.ResourceCache.GetTexture2D(AssetsCoordinates.Generic.Boxes.ResourcePath);
            //prev_level.ImageRect = AssetsCoordinates.Generic.Boxes.LevelBeach;
            _prevLevel.Pressed += (PressedEventArgs args) => {
                PreviousRace();
            };

            Text prevLevel = new Text();

            _prevLevel.AddChild(prevLevel);
            prevLevel.SetAlignment(HorizontalAlignment.Center, VerticalAlignment.Center);
            prevLevel.SetPosition(0, GameInstance.ScreenInfo.SetY(30));
            prevLevel.Opacity = 0.5f;
            prevLevel.SetFont(font, dim.XScreenRatio * 30);
            prevLevel.SetColor(Color.Black);
            prevLevel.Value = "TRACK";

            prevLevelN = new Text();
            _prevLevel.AddChild(prevLevelN);
            prevLevelN.SetAlignment(HorizontalAlignment.Center, VerticalAlignment.Center);
            prevLevelN.SetPosition(0, GameInstance.ScreenInfo.SetY(120));
            prevLevelN.Opacity = 0.5f;
            prevLevelN.SetFont(font, dim.XScreenRatio * 70);
            prevLevelN.SetColor(Color.Black);
            prevLevelN.Value = "1";

            /* SELECTED */
            _selLevel = new Button();
            _container.AddChild(_selLevel);
            _selLevel.SetStyleAuto(null);
            _selLevel.SetPosition(GameInstance.ScreenInfo.SetY(700), GameInstance.ScreenInfo.SetY(200));
            _selLevel.SetSize((int)(dim.XScreenRatio * 450), (int)(dim.YScreenRatio * 450));
            _selLevel.Texture = GameInstance.ResourceCache.GetTexture2D(AssetsCoordinates.Generic.Boxes.ResourcePath);

            Text selLevel = new Text();

            _selLevel.AddChild(selLevel);
            selLevel.SetAlignment(HorizontalAlignment.Center, VerticalAlignment.Center);
            selLevel.SetPosition(GameInstance.ScreenInfo.SetX(-40), GameInstance.ScreenInfo.SetY(40));
            selLevel.SetFont(font, dim.XScreenRatio * 50);
            selLevel.SetColor(Color.Black);
            selLevel.Value = "TRACK";

            selLevelN = new Text();
            _selLevel.AddChild(selLevelN);
            selLevelN.SetAlignment(HorizontalAlignment.Center, VerticalAlignment.Center);
            selLevelN.SetPosition(GameInstance.ScreenInfo.SetX(100), GameInstance.ScreenInfo.SetY(40));
            selLevelN.SetFont(font, dim.XScreenRatio * 50);
            selLevelN.SetColor(Color.Black);
            selLevelN.Value = "";

            Text difficulty = new Text();

            _selLevel.AddChild(difficulty);
            difficulty.SetAlignment(HorizontalAlignment.Left, VerticalAlignment.Center);
            difficulty.SetPosition(GameInstance.ScreenInfo.SetX(20), GameInstance.ScreenInfo.SetY(120));
            difficulty.SetFont(font, dim.XScreenRatio * 30);
            difficulty.SetColor(Color.Black);
            difficulty.Value = "Difficulty:";

            difficultyN = new Text();
            _selLevel.AddChild(difficultyN);
            difficultyN.SetAlignment(HorizontalAlignment.Right, VerticalAlignment.Center);
            difficultyN.SetPosition(GameInstance.ScreenInfo.SetX(-20), GameInstance.ScreenInfo.SetY(120));
            difficultyN.SetFont(font, dim.XScreenRatio * 30);
            difficultyN.SetColor(Color.Gray);
            difficultyN.Value = "N/A";

            Text BestTime = new Text();

            _selLevel.AddChild(BestTime);
            BestTime.SetAlignment(HorizontalAlignment.Left, VerticalAlignment.Center);
            BestTime.SetPosition(GameInstance.ScreenInfo.SetX(20), GameInstance.ScreenInfo.SetY(180));
            BestTime.SetFont(font, dim.XScreenRatio * 30);
            BestTime.SetColor(Color.Black);
            BestTime.Value = "Best Time:";

            BestTimeN = new Text();
            _selLevel.AddChild(BestTimeN);
            BestTimeN.SetAlignment(HorizontalAlignment.Right, VerticalAlignment.Center);
            BestTimeN.SetPosition(GameInstance.ScreenInfo.SetX(-20), GameInstance.ScreenInfo.SetY(180));
            BestTimeN.SetFont(font, dim.XScreenRatio * 30);
            BestTimeN.SetColor(Color.Gray);
            BestTimeN.Value = "00:00:0";

            /*END SELECTED */

            _nextLevel = new Button();
            _container.AddChild(_nextLevel);
            _nextLevel.Opacity = 0.5f;
            _nextLevel.SetStyleAuto(null);
            _nextLevel.SetPosition(GameInstance.ScreenInfo.SetX(1280), GameInstance.ScreenInfo.SetY(250));
            _nextLevel.SetSize((int)(dim.XScreenRatio * 400), (int)(dim.YScreenRatio * 400));
            _nextLevel.Texture  = GameInstance.ResourceCache.GetTexture2D(AssetsCoordinates.Generic.Boxes.ResourcePath);
            _nextLevel.Pressed += (PressedEventArgs args) => {
                NextRace();
            };

            Text nextLevel = new Text();

            _nextLevel.AddChild(nextLevel);
            nextLevel.SetAlignment(HorizontalAlignment.Center, VerticalAlignment.Center);
            nextLevel.SetPosition(0, GameInstance.ScreenInfo.SetY(30));
            nextLevel.Opacity = 0.5f;
            nextLevel.SetFont(font, dim.XScreenRatio * 30);
            nextLevel.SetColor(Color.Black);
            nextLevel.Value = "TRACK";

            nextLevelN = new Text();
            _nextLevel.AddChild(nextLevelN);
            nextLevelN.SetAlignment(HorizontalAlignment.Center, VerticalAlignment.Center);
            nextLevelN.SetPosition(0, GameInstance.ScreenInfo.SetY(120));
            nextLevelN.Opacity = 0.5f;
            nextLevelN.SetFont(font, dim.XScreenRatio * 70);
            nextLevelN.SetColor(Color.Black);
            nextLevelN.Value = "3";

            UpdateActiveLevels();

            /*START BUTTONS - random & selected level*/

            Button StartRandom = new Button();

            _container.AddChild(StartRandom);
            StartRandom.SetStyleAuto(null);
            //StartRandom.Opacity = 0.25f;
            StartRandom.SetPosition(GameInstance.ScreenInfo.SetX(100), GameInstance.ScreenInfo.SetY(700));
            StartRandom.SetSize((int)(dim.XScreenRatio * 700), (int)(dim.YScreenRatio * 100));
            StartRandom.Texture   = GameInstance.ResourceCache.GetTexture2D(AssetsCoordinates.Generic.Boxes.ResourcePath);
            StartRandom.ImageRect = AssetsCoordinates.Generic.Boxes.RankIncreaseBar;
            StartRandom.Pressed  += (PressedEventArgs args) => {
                //SessionManager.Instance.SelectedLevelId = "smoothed-averaged-20.csv";
                TrackManager.Instance.SelectedTrackId = 0;
                Launcher(true);
            };

            Text level = new Text();

            StartRandom.AddChild(level);
            level.SetAlignment(HorizontalAlignment.Center, VerticalAlignment.Center);
            level.SetPosition(0, 0);
            level.SetFont(font, dim.SetX(40));
            level.SetColor(Color.White);
            level.Value = "RANDOM TRACK";

            Button StartGame = new Button();

            _container.AddChild(StartGame);
            StartGame.SetStyleAuto(null);
            StartGame.SetPosition(GameInstance.ScreenInfo.SetX(1150), GameInstance.ScreenInfo.SetY(700));
            StartGame.SetSize((int)(dim.XScreenRatio * 700), (int)(dim.YScreenRatio * 100));
            StartGame.Texture   = GameInstance.ResourceCache.GetTexture2D(AssetsCoordinates.Generic.Boxes.ResourcePath);
            StartGame.ImageRect = AssetsCoordinates.Generic.Boxes.RaceCompleted;
            StartGame.Pressed  += (PressedEventArgs args) => {
                if (_counter >= 1)
                {
                    Launcher();
                }
            };

            Text go = new Text();

            StartGame.AddChild(go);
            go.SetAlignment(HorizontalAlignment.Center, VerticalAlignment.Center);
            go.SetPosition(0, 0);
            go.SetFont(font, dim.SetX(40));
            go.SetColor(Color.White);
            go.Value = "GO!";

            /* END START BUTTONS */
        }
示例#23
0
        Button CreateButton(int x, int y, int xSize, int ySize, int lr, int tr, int rr, int br, string text, int action)
        {
            Font font = GameInstance.ResourceCache.GetFont("Fonts/OpenSans-Bold.ttf");
            // Create the button and center the text onto it
            Button button = new Button();

            GameInstance.UI.Root.AddChild(button);
            button.SetStyleAuto(null);
            button.SetPosition((int)(dim.XScreenRatio * x), (int)(dim.YScreenRatio * y));
            button.SetSize((int)(dim.XScreenRatio * xSize), (int)(dim.YScreenRatio * ySize));

            var btn1Texture = GameInstance.ResourceCache.GetTexture2D("Textures/menutmp.png");

            button.Texture   = btn1Texture;
            button.ImageRect = new IntRect(lr, tr, rr, br);
            Text buttonText = new Text();

            button.AddChild(buttonText);
            //button.SetAlignment(HorizontalAlignment.Center, VerticalAlignment.Top);
            buttonText.SetAlignment(HorizontalAlignment.Center, VerticalAlignment.Center);
            buttonText.SetPosition(GameInstance.ScreenInfo.SetX(40), 0);
            buttonText.SetFont(font, dim.XScreenRatio * 25);
            buttonText.Value = text;

            button.Pressed += args => {
                switch (action)
                {
                case 2:

                    Plugin.Settings.CrossSettings.Current.AddOrUpdateValue("EXIT_FLAG", 1);
                    GameInstance.LaunchScene(GameScenesEnumeration.LEVEL_SELECT);
                    break;

                case 3:

                    Plugin.Settings.CrossSettings.Current.AddOrUpdateValue("EXIT_FLAG", 1);
                    GameInstance.LaunchScene(GameScenesEnumeration.GARAGE);
                    break;

                case 7:

                    Plugin.Settings.CrossSettings.Current.AddOrUpdateValue("EXIT_FLAG", 1);
                    GameInstance.LaunchScene(GameScenesEnumeration.PROFILE);
                    break;

                case 9:

                    Plugin.Settings.CrossSettings.Current.AddOrUpdateValue("EXIT_FLAG", 1);
                    GameInstance.LaunchScene(GameScenesEnumeration.SETTINGS);
                    break;

                case 10:

                    Plugin.Settings.CrossSettings.Current.AddOrUpdateValue("EXIT_FLAG", 1);
                    GameInstance.LaunchScene(GameScenesEnumeration.USER_PROFILE);
                    break;

                case 11:
                    ComingSoon();
                    break;
                }
            };

            return(button);
        }
示例#24
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();
        }
示例#25
0
        /// <summary>
        /// Returns the name of the UI Element
        /// </summary>
        /// <returns>Splash screen.</returns>
        /// <param name="GameInstance">Game instance.</param>
        public static string CreateSplashScreen(Game GameInstance, Node parent, bool randomLevel = false)
        {
            // Get data
            var data    = TrackManager.Instance.LoadingScreenFacts;
            var rnd     = new Random();
            var argIdx  = rnd.Next(0, data.LoadingScreens.Count);
            var arg     = data.LoadingScreens[argIdx];
            var factIdx = rnd.Next(0, arg.Facts.Count);
            var fact    = arg.Facts[factIdx];

            // get poster asset
            IntRect poster;

            switch (arg.Type)
            {
            case LoadingScreenType.CLI:
                poster = AssetsCoordinates.Backgrounds.LoadingScreen.Posters.Climate;
                break;

            case LoadingScreenType.ENV:
                poster = AssetsCoordinates.Backgrounds.LoadingScreen.Posters.Environment;
                break;

            case LoadingScreenType.RES:
                poster = AssetsCoordinates.Backgrounds.LoadingScreen.Posters.Resources;
                break;

            case LoadingScreenType.WASTE:
                poster = AssetsCoordinates.Backgrounds.LoadingScreen.Posters.Waste;
                break;

            case LoadingScreenType.WILD:
                poster = AssetsCoordinates.Backgrounds.LoadingScreen.Posters.Wild;
                break;

            default:
                poster = AssetsCoordinates.Backgrounds.LoadingScreen.Posters.Environment;
                break;
            }

            var splashscreen = new Window {
                Name                = "SplashUI",
                Position            = new IntVector2(GameInstance.ScreenInfo.SetX(0), GameInstance.ScreenInfo.SetY(0)),
                Size                = new IntVector2(GameInstance.ScreenInfo.SetX(1920), GameInstance.ScreenInfo.SetY(1080)),
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Top,
                Texture             = GameInstance.ResourceCache.GetTexture2D(AssetsCoordinates.Backgrounds.FixedBackground.ResourcePath),
                ImageRect           = AssetsCoordinates.Backgrounds.FixedBackground.ImageRect,
                Priority            = 999
            };

            GameInstance.UI.Root.AddChild(splashscreen);

            // TOP BAR
            var topBar = new Sprite();

            splashscreen.AddChild(topBar);
            topBar.Texture   = GameInstance.ResourceCache.GetTexture2D(AssetsCoordinates.Generic.TopBar.ResourcePath);
            topBar.ImageRect = AssetsCoordinates.Generic.TopBar.Rectangle;
            topBar.Opacity   = 0.5f;
            topBar.SetPosition(GameInstance.ScreenInfo.SetX(0), GameInstance.ScreenInfo.SetY(30));
            topBar.SetSize(GameInstance.ScreenInfo.SetX(2000), GameInstance.ScreenInfo.SetY(120));

            Button screenTitle = new Button();

            //screenTitle.SetStyleAuto(null);
            screenTitle.HorizontalAlignment = HorizontalAlignment.Right;
            screenTitle.VerticalAlignment   = VerticalAlignment.Center;
            screenTitle.SetPosition(GameInstance.ScreenInfo.SetX(-150), GameInstance.ScreenInfo.SetY(0));
            screenTitle.SetSize(GameInstance.ScreenInfo.SetX(400), GameInstance.ScreenInfo.SetY(95));
            screenTitle.Texture           = GameInstance.ResourceCache.GetTexture2D(AssetsCoordinates.Generic.Boxes.ResourcePath);
            screenTitle.ImageRect         = AssetsCoordinates.Generic.Boxes.BoxTitle;
            screenTitle.Enabled           = false;
            screenTitle.UseDerivedOpacity = false;
            topBar.AddChild(screenTitle);

            Text buttonTitleText = new Text();

            screenTitle.AddChild(buttonTitleText);
            buttonTitleText.SetAlignment(HorizontalAlignment.Left, VerticalAlignment.Center);
            buttonTitleText.SetPosition(GameInstance.ScreenInfo.SetX(20), GameInstance.ScreenInfo.SetY(0));
            buttonTitleText.SetFont(GameInstance.ResourceCache.GetFont(GameInstance.defaultFont), GameInstance.ScreenInfo.SetX(35));
            buttonTitleText.Value             = "LOADING";
            buttonTitleText.UseDerivedOpacity = false;

            BorderImage wheel = new BorderImage();

            screenTitle.AddChild(wheel);
            wheel.SetAlignment(HorizontalAlignment.Right, VerticalAlignment.Center);
            wheel.SetPosition(GameInstance.ScreenInfo.SetX(-15), GameInstance.ScreenInfo.SetY(0));
            wheel.SetSize(100, 100);
            wheel.Texture           = GameInstance.ResourceCache.GetTexture2D(AssetsCoordinates.Generic.Icons.ResourcePath);
            wheel.ImageRect         = AssetsCoordinates.Generic.Icons.LoadingWheel;
            wheel.UseDerivedOpacity = false;

            /*
             * ValueAnimation textAnimation = new ValueAnimation();
             * textAnimation.SetKeyFrame(0.0f, Color.Blue);
             * textAnimation.SetKeyFrame(1.0f, Color.Red);
             * textAnimation.SetKeyFrame(2.0f, Color.Green);
             *
             * Debug.WriteLine($"Name: {nameof(UIElement.Position)}");
             * buttonTitleText.SetAttributeAnimation(nameof(Color), textAnimation, WrapMode.Loop);
             *
             * ValueAnimation positionAnimation = new ValueAnimation {
             *  InterpolationMethod = InterpMethod.Spline
             * };
             * positionAnimation.SetKeyFrame(0.0f, new IntVector2(-25,0));
             * positionAnimation.SetKeyFrame(1.0f, new IntVector2(-35, 0));
             * positionAnimation.SetKeyFrame(2.0f, new IntVector2(-45, 0));
             * positionAnimation.SetKeyFrame(3.0f, new IntVector2(-55, 0));
             * positionAnimation.SetKeyFrame(4.0f, new IntVector2(-65, 0));
             *
             * wheel.SetAttributeAnimation(nameof(UIElement.Position), positionAnimation);
             * wheel.AnimationEnabled = true;
             * wheel.ApplyAttributes();
             */

            // BODY
            if (randomLevel)
            {
                var text = new Text();
                text.SetFont(GameInstance.ResourceCache.GetFont(GameInstance.defaultFont), 17);
                text.SetPosition(GameInstance.ScreenInfo.SetX(20), GameInstance.ScreenInfo.SetY(172));
                text.Value             = "*Coins and items collected in the random level are not saved.";
                text.UseDerivedOpacity = false;
                splashscreen.AddChild(text);
            }

            var posterImage = new Window {
                Name                = "PosterUI",
                Position            = new IntVector2(GameInstance.ScreenInfo.SetX(200), GameInstance.ScreenInfo.SetY(50)),
                Size                = new IntVector2(GameInstance.ScreenInfo.SetX(500), GameInstance.ScreenInfo.SetY(636)),
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Center,
                Texture             = GameInstance.ResourceCache.GetTexture2D(AssetsCoordinates.Backgrounds.LoadingScreen.Posters.Path),
                ImageRect           = poster
            };

            splashscreen.AddChild(posterImage);

            var textWindow = new Window {
                Name                = "splashScreenTextWindow",
                Position            = new IntVector2(GameInstance.ScreenInfo.SetX(750), GameInstance.ScreenInfo.SetY(50)),
                Size                = new IntVector2(GameInstance.ScreenInfo.SetX(1000), GameInstance.ScreenInfo.SetY(636)),
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Center
            };

            textWindow.SetColor(Color.Transparent);
            splashscreen.AddChild(textWindow);

            var titleBox = new Text {
                Name                = "splashScreenTitle",
                Position            = new IntVector2(GameInstance.ScreenInfo.SetX(10), GameInstance.ScreenInfo.SetY(-20)),
                Size                = new IntVector2(GameInstance.ScreenInfo.SetX(1000), GameInstance.ScreenInfo.SetY(60)),
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Top,
                Wordwrap            = true
            };

            titleBox.SetFont(GameInstance.ResourceCache.GetFont(GameInstance.defaultFont), GameInstance.ScreenInfo.SetX(50));
            titleBox.Value = arg.Title;
            textWindow.AddChild(titleBox);

            var textBox = new Text {
                Name                = "splashScreenText",
                Position            = new IntVector2(GameInstance.ScreenInfo.SetX(10), GameInstance.ScreenInfo.SetY(75)),
                Size                = new IntVector2(GameInstance.ScreenInfo.SetX(1000), GameInstance.ScreenInfo.SetY(350)),
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Top,
                Wordwrap            = true
            };

            textBox.SetFont(GameInstance.ResourceCache.GetFont(GameInstance.defaultFont), GameInstance.ScreenInfo.SetX(30));
            textBox.Value = fact.Message;
            textWindow.AddChild(textBox);

            var btnContinue = new Button {
                Texture             = GameInstance.ResourceCache.GetTexture2D(AssetsCoordinates.Generic.Boxes.ResourcePath),
                ImageRect           = AssetsCoordinates.Generic.Boxes.GroupSelected,
                Name                = "ButtonContinue",
                Position            = new IntVector2(GameInstance.ScreenInfo.SetX(0), GameInstance.ScreenInfo.SetY(0)),
                Size                = new IntVector2(GameInstance.ScreenInfo.SetX(400), GameInstance.ScreenInfo.SetY(95)),
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment   = VerticalAlignment.Bottom
            };

            btnContinue.Visible = false;
            textWindow.AddChild(btnContinue);

            Text btnContinueText = new Text();

            btnContinueText.SetAlignment(HorizontalAlignment.Center, VerticalAlignment.Center);
            btnContinueText.SetPosition(GameInstance.ScreenInfo.SetX(-10), GameInstance.ScreenInfo.SetY(0));
            btnContinueText.SetFont(GameInstance.ResourceCache.GetFont(GameInstance.defaultFont), GameInstance.ScreenInfo.SetX(35));
            btnContinueText.Value = "CONTINUE";
            btnContinue.AddChild(btnContinueText);

            return(splashscreen.Name);
        }
示例#26
0
        Button CreateButton(string text, int width)
        {
            var cache = ResourceCache;
            Font font = cache.GetFont("Fonts/Anonymous Pro.ttf");

            Button button = new Button();
            buttonContainer.AddChild(button);
            button.SetStyleAuto(null);
            button.SetFixedWidth(width);

            var buttonText = new Text();
            button.AddChild(buttonText);
            buttonText.SetFont(font, 12);
            buttonText.SetAlignment(HorizontalAlignment.Center, VerticalAlignment.Center);

            buttonText.Value = text;

            return button;
        }
示例#27
0
        private void InitUI()
        {
            ui       = new UI.UI();
            ui.Input = SceneManager.Input;

            TextBlock title = new TextBlock("Einstellungen", 4);

            title.Color = Color.White;
            title.SetConstraints(new CenterConstraint(), new PixelConstraint(50), new PixelConstraint((int)title.TextWidth), new PixelConstraint((int)title.TextHeight));
            ui.Add(title);

            {
                Button button = new Button(40, 40, 40, 40);
                button.Shortcut     = OpenTK.Input.Key.Escape;
                button.OnLeftClick += (sender) =>
                {
                    SceneManager.LoadScene(new Transition(new MainMenu(), 10));
                };
                UI.Image exitImage = new UI.Image(Textures.Get("Icons"), new RectangleF(0, 10, 10, 10), Color.Black);
                exitImage.SetConstraints(new UIConstraints(10, 10, 20, 20));

                button.AddChild(exitImage);
                ui.Add(button);
            }

            void AddCheckBox(string s, int y, bool state, CheckEvent clickEvent)
            {
                Frame frame = new Frame();

                frame.Color = Color.Transparent;

                CheckBox box = new CheckBox(0, 0, 36, 36);

                box.Checked    = state;
                box.OnChecked += clickEvent;
                frame.AddChild(box);

                TextBlock text = new TextBlock(s, 3, 45, 0);

                text.Constraints.y = new CenterConstraint();
                text.Color         = Color.White;
                frame.AddChild(text);

                frame.SetConstraints(new CenterConstraint(), new PixelConstraint(y), new PixelConstraint(45 + (int)text.TextWidth), new PixelConstraint(36));
                ui.Add(frame);
            }

            void AddText(string s, int y)
            {
                TextBlock text = new TextBlock(s, 3);

                text.Color = Color.White;
                text.SetConstraints(new CenterConstraint(), new PixelConstraint(y), new PixelConstraint((int)text.TextWidth), new PixelConstraint((int)text.TextHeight));
                ui.Add(text);
            }

            AddCheckBox("Vollbild", 100, Settings.Current.Fullscreen, (b) =>
            {
                Settings.Current.Fullscreen     = b;
                SceneManager.Window.WindowState = b ? WindowState.Fullscreen : WindowState.Normal;
            });
            AddCheckBox("Züge anzeigen", 150, Settings.Current.ShowMoves, (b) =>
            {
                Settings.Current.ShowMoves = b;
            });
            AddCheckBox("FPS/UPS anzeigen", 200, Settings.Current.ShowFps, (b) =>
            {
                Settings.Current.ShowFps = b;
            });
            AddCheckBox("Animationen anzeigen", 250, Settings.Current.ShowAnimations, (b) =>
            {
                Settings.Current.ShowAnimations = b;
            });

            TextBox textBox = new TextBox
            {
                Constraints = new UIConstraints(new CenterConstraint(), new PixelConstraint(310), new PixelConstraint(180), new PixelConstraint(34)),
                Enabled     = !Settings.Current.LoggedIn,
                TextColor   = Color.Black,
                MaxTextSize = 15,
                Text        = Settings.Current.UserName ?? ""
            };

            ui.Add(textBox);

            Button sendButton = new Button();

            sendButton.SetConstraints(new CenterConstraint(), new PixelConstraint(350), new PixelConstraint(120), new PixelConstraint(34));
            sendButton.Enabled      = !Settings.Current.LoggedIn;
            sendButton.OnLeftClick += (sender) => SignUp(textBox);

            TextBlock sendText = new TextBlock("Anmelden", 2, 10, 10);

            sendButton.AddChild(sendText);
            ui.Add(sendButton);

            AddText($"ID: {Settings.Current.UserID.ToID()}", 400);
            AddText($"LoginInfo: {Settings.Current.LoginInfo.ToID()}", 440);
        }
        void CreateDraggableFish()
        {
            var cache = ResourceCache;
            var graphics = Graphics;

            // Create a draggable Fish button
            draggableFish = new Button();
            draggableFish.Texture = cache.GetTexture2D("Textures/UrhoDecal.dds"); // Set texture
            draggableFish.BlendMode = BlendMode.Add;
            draggableFish.SetSize(128, 128);
            draggableFish.SetPosition((graphics.Width - draggableFish.Width)/2, 200);
            draggableFish.Name = "Fish";
            uiRoot.AddChild(draggableFish);

            // Add a tooltip to Fish button
            ToolTip toolTip = new ToolTip();
            draggableFish.AddChild(toolTip);
            toolTip.Position = new IntVector2(draggableFish.Width + 5, draggableFish.Width/2);
            // slightly offset from close button
            BorderImage textHolder = new BorderImage();
            toolTip.AddChild(textHolder);
            textHolder.SetStyle("ToolTipBorderImage", null);
            var toolTipText = new Text();
            textHolder.AddChild(toolTipText);
            toolTipText.SetStyle("ToolTipText", null);
            toolTipText.Value = "Please drag me!";

            // Subscribe draggableFish to Drag Events (in order to make it draggable)
            draggableFish.SubscribeToDragBegin(HandleDragBegin);
            draggableFish.SubscribeToDragMove(HandleDragMove);
            draggableFish.SubscribeToDragEnd(HandleDragEnd);
        }
示例#29
0
        private void InitUI()
        {
            ui = new UI.UI
            {
                Input = new Input(SceneManager.Window)
            };

            void AddText(string s, string value, int y)
            {
                TextBlock text1 = new TextBlock(s, 3, 0, y)
                {
                    Color = Color.White
                };

                text1.Constraints.x = new CenterConstraint(-text1.TextWidth / 2f);
                ui.Add(text1);

                TextBlock text2 = new TextBlock(value, 3, 0, y)
                {
                    Color = Color.White
                };

                text2.Constraints.x = new CenterConstraint(text2.TextWidth / 2f);
                ui.Add(text2);
            }

            TextBlock title = new TextBlock("Statistik", 4, 0, 50)
            {
                Color = Color.White
            };

            title.Constraints.x = new CenterConstraint();
            ui.Add(title);

            Button button = new Button(40, 40, 40, 40)
            {
                Shortcut = OpenTK.Input.Key.Escape
            };

            button.OnLeftClick += (sender) =>
            {
                SceneManager.LoadScene(new Transition(new MainMenu(), 10));
            };
            UI.Image exitImage = new UI.Image(Textures.Get("Icons"), new RectangleF(0, 10, 10, 10), Color.Black);
            exitImage.SetConstraints(new UIConstraints(10, 10, 20, 20));

            button.AddChild(exitImage);
            ui.Add(button);

            int y = 100;

            AddText("Züge: ", Stats.Current.TotalMoves.ToString(), y += 30);
            AddText("Level geschafft: ", Stats.Current.LevelsCompleted.ToString(), y += 30);
            AddText("Level perfekt geschafft: ", Stats.Current.LevelsCompletedPerfect.ToString(), y += 30);
            AddText("Erstes Spiel: ", Stats.Current.FirstStart.ToString("dd.MM.yy"), y += 30);
            AddText("Spielzeit: ", $"{(int)Stats.Current.TimePlaying.TotalHours}:{Stats.Current.TimePlaying.Minutes:00}:{Stats.Current.TimePlaying.Seconds:00}", y += 30);
            AddText("Tode: ", Stats.Current.Fails.ToString(), y += 30);
            if (Stats.Current.TetrisHighScore > 0)
            {
                AddText("Tetris höchste Punktzahl: ", Stats.Current.TetrisHighScore.ToString(), y += 30);
                AddText("Tetris meiste Linien: ", Stats.Current.TetrisMostLines.ToString(), y     += 30);
                AddText("Tetris höchstes Level: ", Stats.Current.TetrisHighLevel.ToString(), y    += 30);
            }
            if (Stats.Current.MinesweeperWon > 0 || Stats.Current.MinesweeperLost > 0)
            {
                AddText("Minesweeper geschafft: ", Stats.Current.MinesweeperWon.ToString(), y    += 30);
                AddText("Minesweeper gescheitert: ", Stats.Current.MinesweeperLost.ToString(), y += 30);
            }
        }