Exemple #1
0
        protected override UIElement InitializeUI(Loader loader, DrawingContext context, int screenWidth, int screenHeight)
        {
            context.NewBitmap("Background", loader.LoadBitmapFromFile(@"Resources\UI\menu.png"));
            context.NewNinePartsBitmap("Panel", loader.LoadBitmapFromFile(@"Resources\UI\panel.png"), 25, 103, 25, 103);
            context.NewNinePartsBitmap("ButtonPressed", loader.LoadBitmapFromFile(@"Resources\UI\buttonPressed.png"), 30, 98, 30, 98);
            context.NewNinePartsBitmap("ButtonRealesed", loader.LoadBitmapFromFile(@"Resources\UI\buttonRealesed.png"), 30, 98, 30, 98);

            context.NewSolidBrush("TextLight", new RawColor4(238.0f / 255.0f, 201.0f / 255.0f, 159.0f / 255.0f, 1.0f));
            context.NewSolidBrush("TextDark", new RawColor4(120.0f / 255.0f, 58.0f / 255.0f, 41.0f / 255.0f, 1.0f));
            context.NewTextFormat("Text", fontSize: 35.0f, textAlignment: SharpDX.DirectWrite.TextAlignment.Center,
                                  paragraphAlignment: SharpDX.DirectWrite.ParagraphAlignment.Center);

            var ui = new UIMultiElementsContainer(Vector2.Zero, new Vector2(screenWidth, screenHeight))
            {
                Background = new TextureBackground("Background")
            };

            DrawMenu(screenWidth, screenHeight);
            DrawEndPanel(screenWidth, screenHeight);

            ui.OnResized += () => _menu.Size = ui.Size;
            ui.OnResized += () => _endGamePanel.Size = ui.Size;

            ui.Add(_menu);
            ui.Add(_endGamePanel);

            return(ui);
        }
        protected override UIElement InitializeUI(Loader loader, DrawingContext context, int screenWidth, int screenHeight)
        {
            var ui = new UIMultiElementsContainer(Vector2.Zero, new Vector2(screenWidth, screenHeight));

            // Create ui and gui
            context.NewSolidBrush("ProgressBarBrush", new RawColor4(30f / 255f, 144f / 255f, 255f / 255f, 0.6f));
            _healthBar          = new UIProgressBar(Vector2.Zero, new Vector2(100, 20), "ProgressBarBrush");
            _healthBar.MaxValue = 100;
            _healthBar.Value    = 100;
            var gui = new UISequentialContainer(Vector2.Zero, new Vector2(screenWidth, screenHeight))
            {
                MainAxis  = UISequentialContainer.Alignment.Start,
                CrossAxis = UISequentialContainer.Alignment.Center,
            };

            ui.OnResized += () => gui.Size = ui.Size;
            ui.Add(gui);
            gui.Add(new UIMarginContainer(_healthBar, 15));
            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);
        }
Exemple #4
0
        protected override UIElement InitializeUI(Loader loader, DrawingContext context, int screenWidth, int screenHeight)
        {
            Cursor.Hide();
            context.NewNinePartsBitmap("Panel", loader.LoadBitmapFromFile(@"Resources\UI\panel.png"), 30, 98, 30, 98);
            context.NewBitmap("Heart", loader.LoadBitmapFromFile(@"Resources\UI\heart.png"));
            context.NewBitmap("ArrowStandart", loader.LoadBitmapFromFile(@"Resources\UI\arrowStandart.png"));
            context.NewBitmap("ArrowPoison", loader.LoadBitmapFromFile(@"Resources\UI\arrowPoison.png"));
            context.NewBitmap("WolfIcon", loader.LoadBitmapFromFile(@"Resources\UI\wolfIcon.png"));

            var header1 = new UISequentialContainer(new Vector2(0.0f, 0.0f), new Vector2(screenWidth, 100.0f), false);
            // здоровье
            var counter = new UISequentialContainer(Vector2.Zero, new Vector2(300.0f, 100.0f), false)
            {
                Background = new NinePartsTextureBackground("Panel"),
                MainAxis   = UISequentialContainer.Alignment.Center,
                CrossAxis  = UISequentialContainer.Alignment.Center
            };
            var image = new UIPanel(Vector2.Zero, new Vector2(80.0f, 80.0f))
            {
                Background = new TextureBackground("Heart")
            };

            context.NewSolidBrush("HealthBarBack", new RawColor4(144.0f / 255.0f, 31.0f / 255.0f, 61.0f / 255.0f, 1.0f));
            context.NewSolidBrush("HealthBar", new RawColor4(187.0f / 255.0f, 48.0f / 255.0f, 48.0f / 255.0f, 1.0f));
            _healthProgressBar = new UIProgressBar(Vector2.Zero, new Vector2(180.0f, 20.0f), "HealthBar")
            {
                Background = new ColorBackground("HealthBarBack"),
                MaxValue   = 100.0f,
                Value      = 50.0f
            };

            counter.Add(image);
            counter.Add(_healthProgressBar);
            header1.Add(new UIMarginContainer(counter, 5.0f, 0.0f));

            // обычные стрелы
            counter = new UISequentialContainer(Vector2.Zero, new Vector2(200.0f, 100.0f), false)
            {
                Background = new NinePartsTextureBackground("Panel"),
                MainAxis   = UISequentialContainer.Alignment.Center,
                CrossAxis  = UISequentialContainer.Alignment.Center
            };
            image = new UIPanel(Vector2.Zero, new Vector2(80.0f, 80.0f))
            {
                Background = new TextureBackground("ArrowStandart")
            };
            context.NewSolidBrush("Text", new RawColor4(1.0f, 1.0f, 1.0f, 1.0f));
            context.NewTextFormat("Text", fontSize: 40.0f,
                                  textAlignment: SharpDX.DirectWrite.TextAlignment.Center);
            _arrowStandartText = new UIText("0", new Vector2(50.0f, 50.0f), "Text", "Text");

            counter.Add(image);
            counter.Add(_arrowStandartText);
            header1.Add(new UIMarginContainer(counter, 5.0f, 0.0f));

            // стрелы яда
            counter = new UISequentialContainer(Vector2.Zero, new Vector2(200.0f, 100.0f), false)
            {
                Background = new NinePartsTextureBackground("Panel"),
                MainAxis   = UISequentialContainer.Alignment.Center,
                CrossAxis  = UISequentialContainer.Alignment.Center
            };
            image = new UIPanel(Vector2.Zero, new Vector2(80.0f, 80.0f))
            {
                Background = new TextureBackground("ArrowPoison")
            };
            _arrowPoisonText = new UIText("0", new Vector2(50.0f, 50.0f), "Text", "Text");

            counter.Add(image);
            counter.Add(_arrowPoisonText);
            header1.Add(new UIMarginContainer(counter, 5.0f, 0.0f));

            var header2 = new UISequentialContainer(new Vector2(5.0f, 110.0f), new Vector2(screenWidth, 100.0f), false);

            // счет врагов
            counter = new UISequentialContainer(Vector2.Zero, new Vector2(200.0f, 100.0f), false)
            {
                Background = new NinePartsTextureBackground("Panel"),
                MainAxis   = UISequentialContainer.Alignment.Center,
                CrossAxis  = UISequentialContainer.Alignment.Center
            };
            image = new UIPanel(Vector2.Zero, new Vector2(80.0f, 80.0f))
            {
                Background = new TextureBackground("WolfIcon")
            };
            _wolfCounter = new UIText("0", new Vector2(100.0f, 50.0f), "Text", "Text");
            counter.Add(image);
            counter.Add(_wolfCounter);
            header2.Add(counter);

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

            ui.OnResized += () => header1.Size = ui.Size;
            ui.OnResized += () => header2.Size = ui.Size;
            ui.Add(header1);
            ui.Add(header2);
            return(ui);
        }