示例#1
0
        protected override void LoadContent()
        {
            _spriteBatch = new SpriteBatch(GraphicsDevice);

            var tex                  = Content.Load <Texture2D>("TestTextures/Test");
            var fengPortrait         = new TextureRegion(Content.Load <Texture2D>("Portraits/framedFeng"));
            var knightPortrait       = new TextureRegion(Content.Load <Texture2D>("Portraits/framedKnight"));
            var fengPortraitGolden   = new TextureRegion(Content.Load <Texture2D>("Portraits/framedFengGolden"));
            var knightPortraitGolden = new TextureRegion(Content.Load <Texture2D>("Portraits/framedKnightGolden"));

            var titleStyle = new UntexturedStyle(_spriteBatch)
            {
                Font          = new GenericSpriteFont(Content.Load <SpriteFont>("Fonts/alagard")),
                TextScale     = 8.0f,
                PanelTexture  = new NinePatch(new TextureRegion(tex, 0, 8, 24, 24), 8),
                ButtonTexture = new NinePatch(new TextureRegion(tex, 24, 8, 16, 16), 4),
            };

            var style = new UntexturedStyle(_spriteBatch)
            {
                Font                     = new GenericSpriteFont(Content.Load <SpriteFont>("Fonts/alagard")),
                TextScale                = 2.25f,
                TextFieldTexture         = new NinePatch(new TextureRegion(tex, 24, 8, 16, 16), 4),
                PanelTexture             = new NinePatch(new TextureRegion(tex, 0, 8, 24, 24), 8),
                ButtonTexture            = new NinePatch(new TextureRegion(tex, 24, 8, 16, 16), 4),
                ScrollBarBackground      = new NinePatch(new TextureRegion(tex, 12, 0, 4, 8), 1, 1, 2, 2),
                ScrollBarScrollerTexture = new NinePatch(new TextureRegion(tex, 8, 0, 4, 8), 1, 1, 2, 2)
            };

            UiSystem = new UiSystem(Window, GraphicsDevice, style);
            titleUi  = new UiSystem(Window, GraphicsDevice, titleStyle);

            var prgTitle = new Paragraph(Anchor.TopCenter, 1, "Way of The", true)
            {
                PositionOffset = new Vector2(0, 20)
            };
            var prgSubTitle = new Paragraph(Anchor.TopCenter, 1, "Sword", true)
            {
                PositionOffset = new Vector2(0, 140)
            };

            titleUi.Add("title", prgTitle);
            titleUi.Add("subTitle", prgSubTitle);

            var panel   = new Panel(Anchor.Center, new Vector2(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height), positionOffset: Vector2.Zero);
            var imgFeng = new Image(Anchor.Center, new Vector2(200, 200), fengPortrait)
            {
                IsHidden = true, PositionOffset = new Vector2(-150, 20)
            };
            var btnFeng = new Button(Anchor.Center, imgFeng.Size, "")
            {
                HoveredColor   = Color.Transparent,
                NormalColor    = Color.Transparent,
                PositionOffset = new Vector2(-150, 20),
                IsHidden       = true
            };
            var imgKnight = new Image(Anchor.Center, new Vector2(235, 235), knightPortrait)
            {
                IsHidden = true, PositionOffset = new Vector2(150, 32)
            };;
            var btnKnight = new Button(Anchor.Center, imgKnight.Size, "")
            {
                HoveredColor   = Color.Transparent,
                NormalColor    = Color.Transparent,
                PositionOffset = new Vector2(150, 32),
                IsHidden       = true
            };
            var prgAuthor = new Paragraph(Anchor.Center, 1, "By Ethan Eshed", true)
            {
                PositionOffset = new Vector2(0, 80)
            };
            var btnPlay = new Button(Anchor.BottomCenter, new Vector2(200, 50), "Play")
            {
                PositionOffset = new Vector2(0, 35)
            };
            var btnFight = new Button(Anchor.BottomCenter, new Vector2(200, 50), "Fight!")
            {
                IsHidden       = true,
                PositionOffset = new Vector2(0, 35)
            };
            var prgPlayers = new Paragraph(Anchor.Center, 1, "Select your Champion", true)
            {
                PositionOffset = new Vector2(0, -120), IsHidden = true
            };
            var btnProceed = new Button(Anchor.BottomCenter, new Vector2(200, 50), "Proceed")
            {
                IsHidden = true, PositionOffset = new Vector2(0, 35)
            };
            var prgNickName = new Paragraph(Anchor.Center, 1, "Enter your Name", true)
            {
                PositionOffset = new Vector2(-19, -80), IsHidden = true
            };
            var txtBoxNickName = new TextField(Anchor.Center, new Vector2(400, 50))
            {
                IsHidden = true, PositionOffset = new Vector2(0, 30)
            };

            var btnBack = new Button(Anchor.TopRight, new Vector2(200, 50), "Back")
            {
                IsHidden       = true,
                PositionOffset = new Vector2(15, 15),
                OnPressed      = e =>
                {
                    if (!btnFight.IsHidden) // champion select screen
                    {
                        btnProceed.IsHidden     = false;
                        txtBoxNickName.IsHidden = false;
                        prgNickName.IsHidden    = false;
                        e.IsHidden = false;

                        prgPlayers.IsHidden = true;
                        imgFeng.IsHidden    = true;
                        imgKnight.IsHidden  = true;
                        btnFight.IsHidden   = true;
                        btnFeng.IsHidden    = true;
                        btnKnight.IsHidden  = true;
                    }
                    else
                    {
                        prgTitle.IsHidden       = false;
                        prgSubTitle.IsHidden    = false;
                        prgAuthor.IsHidden      = false;
                        btnPlay.IsHidden        = false;
                        btnProceed.IsHidden     = true;
                        txtBoxNickName.IsHidden = true;
                        prgNickName.IsHidden    = true;
                        e.IsHidden = true;
                    }
                }
            };

            btnPlay.OnPressed = e =>
            {
                prgTitle.IsHidden       = true;
                prgSubTitle.IsHidden    = true;
                prgAuthor.IsHidden      = true;
                e.IsHidden              = true;
                btnBack.IsHidden        = false;
                btnProceed.IsHidden     = false;
                txtBoxNickName.IsHidden = false;
                prgNickName.IsHidden    = false;
            };

            btnProceed.OnPressed = e =>
            {
                if (!txtBoxNickName.Text.Equals(""))
                {
                    prgPlayers.IsHidden     = false;
                    imgFeng.IsHidden        = false;
                    imgKnight.IsHidden      = false;
                    btnFight.IsHidden       = false;
                    btnFeng.IsHidden        = false;
                    btnKnight.IsHidden      = false;
                    btnProceed.IsHidden     = true;
                    txtBoxNickName.IsHidden = true;
                    prgNickName.IsHidden    = true;
                    nickName = txtBoxNickName.Text;
                }
            };

            btnFeng.OnPressed = e =>
            {
                imgKnight.Texture = knightPortrait;
                imgFeng.Texture   = fengPortraitGolden;
                champion          = "feng";
            };
            btnFeng.OnMouseEnter = e =>
            {
                imgFeng.Texture = fengPortraitGolden;
            };
            btnFeng.OnMouseExit = e =>
            {
                if (champion != "feng")
                {
                    imgFeng.Texture = fengPortrait;
                }
            };

            btnKnight.OnPressed = e =>
            {
                imgFeng.Texture   = fengPortrait;
                imgKnight.Texture = knightPortraitGolden;
                champion          = "knight";
            };
            btnKnight.OnMouseEnter = e =>
            {
                imgKnight.Texture = knightPortraitGolden;
            };
            btnKnight.OnMouseExit = e =>
            {
                if (champion != "knight")
                {
                    imgKnight.Texture = knightPortrait;
                }
            };

            btnFight.OnPressed = e =>
            {
                if (champion != "none")
                {
                    UiSystem.Dispose();
                    titleUi.Dispose();
                    Exit();
                    Communicator.Setup(champion, nickName);
                }
            };

            panel.AddChild(prgPlayers);
            panel.AddChild(prgAuthor);
            panel.AddChild(btnPlay);
            panel.AddChild(btnBack);
            panel.AddChild(imgFeng);
            panel.AddChild(imgKnight);
            panel.AddChild(btnFight);
            panel.AddChild(btnFeng);
            panel.AddChild(btnKnight);
            panel.AddChild(btnPlay);
            panel.AddChild(txtBoxNickName);
            panel.AddChild(btnProceed);
            panel.AddChild(prgNickName);

            UiSystem.Add("StartMenu", panel);
        }