Esempio n. 1
0
        protected override UIElement InitializeUI(Loader loader, DrawingContext context, int screenWidth, int screenHeight)
        {
            context.NewNinePartsBitmap("glowingBorder", loader.LoadBitmapFromFile(@"Textures\GlowingBorder.png"), 21, 29, 21, 29);
            context.NewBitmap("bulletsTexture", loader.LoadBitmapFromFile(@"Textures\Bullets.png"));
            context.NewSolidBrush("neonBrush", new RawColor4(144f / 255f, 238f / 255f, 233f / 255f, 1f));
            context.NewTextFormat("ammoFormat",
                                  fontWeight: SharpDX.DirectWrite.FontWeight.Black,
                                  textAlignment: SharpDX.DirectWrite.TextAlignment.Center,
                                  paragraphAlignment: SharpDX.DirectWrite.ParagraphAlignment.Center);

            var ui = new UISequentialContainer(Vector2.Zero, new Vector2(screenWidth, screenHeight))
            {
                MainAxis  = UISequentialContainer.Alignment.End,
                CrossAxis = UISequentialContainer.Alignment.Start
            };

            _healthBar   = new UIProgressBar(Vector2.Zero, new Vector2(100, 20), "neonBrush");
            _ammoCounter = new UIText("0", new Vector2(48, 10), "ammoFormat", "neonBrush");
            var ammoImage = new UIPanel(Vector2.Zero, new Vector2(40, 36))
            {
                Background = new TextureBackground("bulletsTexture")
            };

            var ammoContainer = new UISequentialContainer(Vector2.Zero, new Vector2(100, 36), false)
            {
                MainAxis  = UISequentialContainer.Alignment.Start,
                CrossAxis = UISequentialContainer.Alignment.Center
            };
            var healthContainer = new UIMarginContainer(_healthBar, 15)
            {
                Background = new NinePartsTextureBackground("glowingBorder")
            };

            ammoContainer.Add(new UIMarginContainer(ammoImage, 6, 0));
            ammoContainer.Add(_ammoCounter);

            ui.Add(ammoContainer);
            ui.Add(healthContainer);

            return(ui);
        }
        protected override UIElement InitializeUI(Loader loader, DrawingContext context, int screenWidth, int screenHeight)
        {
            string textFormat      = "testSceneTextFormat";
            string whiteBrush      = "testSceneWhiteBrush";
            string text1background = "testSceneText1background";
            string text2background = "testSceneText2background";
            string text3background = "testSceneText3background";
            string panelBitmap     = "testScenePanelBitmap";

            //string buttonlBitmap = "panelBitmap";

            //context.NewBitmap(buttonlBitmap, loader.LoadBitmapFromFile(@"Textures\button.png"));
            context.NewNinePartsBitmap(panelBitmap, loader.LoadBitmapFromFile(@"Textures\button.png"), 15, 121, 15, 46);
            context.NewSolidBrush(whiteBrush, new RawColor4(1f, 1f, 1f, 1f));
            context.NewSolidBrush(text1background, new RawColor4(0.6f, 0.1f, 0.2f, 1f));
            context.NewSolidBrush(text2background, new RawColor4(0.2f, 0.4f, 0.8f, 1f));
            context.NewSolidBrush(text3background, new RawColor4(0.5f, 0.4f, 0.3f, 1f));
            context.NewTextFormat(textFormat);

            _ui = new UIMultiElementsContainer(Vector2.Zero, new Vector2(screenWidth, screenHeight));

            _panel = new UISequentialContainer(Vector2.Zero, new Vector2(200, 200))
            {
                MainAxis  = UISequentialContainer.Alignment.Center,
                CrossAxis = UISequentialContainer.Alignment.Center,
                //Background = new TextureBackground(panelBitmap)
                Background = new NinePartsTextureBackground(panelBitmap)
            };
            _ui.Add(_panel);

            _text1 = new UIText("X", new Vector2(120, 16), textFormat, whiteBrush)
            {
                Background = new ColorBackground(text1background)
            };
            _text2 = new UIText("Y", new Vector2(120, 16), textFormat, whiteBrush)
            {
                Background = new ColorBackground(text2background)
            };
            _text3 = new UIText("Z", new Vector2(120, 16), textFormat, whiteBrush)
            {
                Background = new ColorBackground(text3background)
            };
            UIElement text4 = new UIText("Click Me!", new Vector2(120, 16), textFormat, whiteBrush);
            UIElement m     = new UIMarginContainer(_text1, 2f);

            UIButton button = new UIButton(text4)
            {
                ReleasedBackground = new ColorBackground(text1background), PressedBackground = new ColorBackground(text2background)
            };

            button.OnClicked += () =>
            {
                MainMenuScene menu = new MainMenuScene();
                Game.ChangeScene(menu);
            };

            _panel.Add(m);
            _panel.Add(_text2);
            _panel.Add(_text3);
            _panel.Add(button);

            _text1.OnClicked += () =>
            {
                Transition transition = new SmoothTransition(_go.Rotation.X, _go.Rotation.X + MathUtil.TwoPi, 2);
                transition.Process += value => _go.SetRotationX(value);
                transition.Process += value => _go.SetRotationY(value);
                transition.Process += value => _go.SetRotationZ(value);
            };
            _text2.OnClicked += () =>
            {
                Transition transition = new SmoothTransition(_go.Rotation.Y, _go.Rotation.Y + MathUtil.TwoPi, 2);
                transition.Process += value => _go.SetRotationY(value);

                //_voice.Stop();
                //_voice.Play();

                _voice2.Stop();
                _voice2.Play();
            };
            _text3.OnClicked += () =>
            {
                Transition transition = new SmoothTransition(_go.Rotation.Z, _go.Rotation.Z + MathUtil.TwoPi, 2);
                transition.Process += value => _go.SetRotationZ(value);

                _voice.Play();
                //_voice2.Play();
            };
            _text1.IsClickable = true;
            _text2.IsClickable = true;
            _text3.IsClickable = true;

            return(_ui);
        }