예제 #1
0
        protected override void LoadScene()
        {
            mainScreneImages = LoadAsset <SpriteSheet>("MainSceneImages");
            westernFont      = LoadAsset <SpriteFont>("WesternFont");
            popupWindowImage = mainScreneImages["popup_window"];

            // Preload stars
            starSprites.Add(mainScreneImages["star0"]);
            starSprites.Add(mainScreneImages["star1"]);
            starSprites.Add(mainScreneImages["star2"]);
            starSprites.Add(mainScreneImages["star3"]);
            borderStarImages.Add(mainScreneImages["bstar0"]);
            borderStarImages.Add(mainScreneImages["bstar1"]);
            borderStarImages.Add(mainScreneImages["bstar2"]);
            borderStarImages.Add(mainScreneImages["bstar3"]);

            // Create space ships
            var random = new Random();

            for (var i = 0; i < ShipNameList.Count; i++)
            {
                shipList.Add(new SpaceShip
                {
                    Name     = ShipNameList[i],
                    Power    = random.Next(4),
                    Control  = random.Next(4),
                    Speed    = random.Next(4),
                    IsLocked = (i % 3) == 2,
                });
            }

            var mainStackPanel = CreateMainScene();

            CreateWelcomePopup();
            CreateShipSelectionPopup();

            // Create the background
            var background = new ImageElement {
                Source = mainScreneImages["background_uiimage"], StretchType = StretchType.Fill
            };

            background.SetPanelZIndex(-1);

            // Overlay pop-ups and the main screen
            var overlay = new UniformGrid();

            overlay.Children.Add(background);
            overlay.Children.Add(mainStackPanel);
            overlay.Children.Add(welcomePopup);
            overlay.Children.Add(shipSelectPopup);

            // Set the root element to the overall overlay
            var uiComponent = Entity.Get <UIComponent>();

            uiComponent.RootElement = overlay;

            Script.AddTask(FillLifeBar);
        }
예제 #2
0
        protected override void LoadScene()
        {
            // Allow user to resize the window with the mouse.
            Game.Window.AllowUserResizing = true;

            // Create and initialize "Stride Samples" Text
            var strideSampleTextBlock = new ContentDecorator
            {
                BackgroundImage = SpriteFromSheet.Create(SplashScreenImages, "stride_sample_text_bg"),
                Content         = new TextBlock
                {
                    Font      = WesternFont,
                    TextSize  = 60,
                    Text      = "Stride UI Particles",
                    TextColor = Color.White,
                },
                Padding             = new Thickness(35, 15, 35, 25),
                HorizontalAlignment = HorizontalAlignment.Center
            };

            strideSampleTextBlock.SetPanelZIndex(1);


            //*********************************
            // Confetti button
            var buttonImage = SpriteFromSheet.Create(SplashScreenImages, "button_long");

            var strideButtonConfetti = new Button
            {
                NotPressedImage = buttonImage,
                PressedImage    = buttonImage,
                MouseOverImage  = buttonImage,

                Content = new TextBlock
                {
                    Font      = WesternFont,
                    TextColor = Color.White,
                    Text      = "Click here to start the game over",
                    TextSize  = 24
                },

                HorizontalAlignment = HorizontalAlignment.Right,
                Padding             = new Thickness(90, 22, 25, 35),
//                BackgroundColor = Color.DarkOrchid
            };

            strideButtonConfetti.SetPanelZIndex(1);
            strideButtonConfetti.SetGridRow(1);

            strideButtonConfetti.Click += delegate
            {
                fusePercentage = 1f;
                desiredState   = GameState.NewGame;
                var effectOffset = new Vector3(45 - strideButtonConfetti.RenderSize.X / 2, -5, 0);
                SpawnParticles(strideButtonConfetti.WorldMatrix.TranslationVector + effectOffset, Prefab, 2f);
            };
            //*********************************

            //*********************************
            // Stars button
            var buttonStars = SpriteFromSheet.Create(SplashScreenImages, "button_short");

            var strideButtonStars = new Button
            {
                NotPressedImage = buttonStars,
                PressedImage    = buttonStars,
                MouseOverImage  = buttonStars,

                Content = new TextBlock
                {
                    Font      = WesternFont,
                    TextColor = Color.White,
                    Text      = "Congratulations",
                    TextSize  = 24
                },

                HorizontalAlignment = HorizontalAlignment.Right,
                Padding             = new Thickness(90, 22, 25, 35),
//                BackgroundColor = Color.DarkOrchid
            };

            strideButtonStars.SetPanelZIndex(1);
            strideButtonStars.SetGridRow(4);

            strideButtonStars.Click += delegate
            {
                desiredState = GameState.EndGame;
                var effectOffset = new Vector3(45 - strideButtonStars.RenderSize.X / 2, -5, 0);
                SpawnParticles(strideButtonStars.WorldMatrix.TranslationVector + effectOffset, Prefab, 2f);
            };
            //*********************************

            var bottomBar = CreateBottomBar();

            bottomBar.SetPanelZIndex(1);
            bottomBar.SetGridRow(6);

            var grid = new Grid
            {
                MaximumWidth        = virtualWidth,
                MaximumHeight       = virtualHeight,
                VerticalAlignment   = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center,
            };

            grid.RowDefinitions.Add(new StripDefinition(StripType.Auto));       // 0
            grid.RowDefinitions.Add(new StripDefinition(StripType.Auto));       // 1
            grid.RowDefinitions.Add(new StripDefinition(StripType.Auto));       // 2
            grid.RowDefinitions.Add(new StripDefinition(StripType.Auto));       // 3
            grid.RowDefinitions.Add(new StripDefinition(StripType.Auto));       // 4
            grid.RowDefinitions.Add(new StripDefinition(StripType.Fixed, 100)); // 5
            grid.RowDefinitions.Add(new StripDefinition(StripType.Fixed, 50));  // 5
            grid.ColumnDefinitions.Add(new StripDefinition());
            grid.LayerDefinitions.Add(new StripDefinition());

            grid.Children.Add(strideSampleTextBlock);
            grid.Children.Add(strideButtonConfetti);
            grid.Children.Add(strideButtonStars);
            grid.Children.Add(bottomBar);

            // Add the background
            var background = new ImageElement {
                Source = SpriteFromSheet.Create(SplashScreenImages, "background_uiimage"), StretchType = StretchType.Fill
            };

            background.SetPanelZIndex(-1);

            Entity.Get <UIComponent>().Page = new UIPage {
                RootElement = new UniformGrid {
                    Children = { background, grid }
                }
            };
        }
예제 #3
0
        private UniformGrid CreateShipButtonElement(SpaceShip spaceShip)
        {
            // Put the stat text block in a vertical uniform grid
            var statusTextGrid = new UniformGrid {
                Rows = 3, Margin = new Thickness(5f, -6f, 0, 0)
            };

            statusTextGrid.Children.Add(CreateShipStatusTextBlock("Power", 0));
            statusTextGrid.Children.Add(CreateShipStatusTextBlock("Control", 1));
            statusTextGrid.Children.Add(CreateShipStatusTextBlock("Speed", 2));

            // Put the stat stars in a vertical uniform grid
            spaceShip.PowerImageElement   = CreateShipStatusStar(0);
            spaceShip.ControlImageElement = CreateShipStatusStar(1);
            spaceShip.SpeedImageElement   = CreateShipStatusStar(2);

            var starGrid = new UniformGrid {
                Rows = 3
            };

            starGrid.Children.Add(spaceShip.PowerImageElement);
            starGrid.Children.Add(spaceShip.ControlImageElement);
            starGrid.Children.Add(spaceShip.SpeedImageElement);
            starGrid.SetGridColumn(2);

            // Ship image
            var shipSprite       = SpriteFromSheet.Create(MainSceneImages, spaceShip.Name);
            var shipImageElement = new ImageElement {
                Source = shipSprite
            };

            shipImageElement.SetGridColumn(4);

            // Create the horizontal grid with two blank stretchable columns and add the text blocks, the starts and the ship image
            var shipContent = new Grid();

            shipContent.ColumnDefinitions.Add(new StripDefinition(StripType.Auto));
            shipContent.ColumnDefinitions.Add(new StripDefinition(StripType.Star));
            shipContent.ColumnDefinitions.Add(new StripDefinition(StripType.Auto));
            shipContent.ColumnDefinitions.Add(new StripDefinition(StripType.Star));
            shipContent.ColumnDefinitions.Add(new StripDefinition(StripType.Auto));
            shipContent.RowDefinitions.Add(new StripDefinition());
            shipContent.LayerDefinitions.Add(new StripDefinition());

            shipContent.Children.Add(statusTextGrid);
            shipContent.Children.Add(starGrid);
            shipContent.Children.Add(shipImageElement);

            //
            var shipSelectFrameSprite = SpriteFromSheet.Create(MainSceneImages, "weapon_select_frame");

            var shipButton = new Button
            {
                Name            = spaceShip.Name,
                Content         = shipContent,
                PressedImage    = shipSelectFrameSprite,
                NotPressedImage = shipSelectFrameSprite,
                MouseOverImage  = shipSelectFrameSprite,
                Padding         = new Thickness(60, 20, 20, 20)
            };

            shipButton.Click += delegate
            {
                currentShipImage.Source = shipSprite;

                activeShipIndex = shipList.FindIndex(w => w.Name == spaceShip.Name);

                PowerStatus   = spaceShip.Power;
                ControlStatus = spaceShip.Control;
                SpeedStatus   = spaceShip.Speed;

                CloseShipSelectPopup();
            };

            shipButton.IsEnabled = !spaceShip.IsLocked;
            shipButton.SetCanvasRelativeSize(new Vector3(1f, 1f, 1f));

            var buttonGrid = new UniformGrid {
                MaximumHeight = 100
            };

            buttonGrid.Children.Add(shipButton);

            if (spaceShip.IsLocked)
            {
                var lockIconElement = new ImageElement {
                    Source = SpriteFromSheet.Create(MainSceneImages, "lock_icon"), StretchType = StretchType.Fill,
                };
                lockIconElement.SetPanelZIndex(1);
                buttonGrid.Children.Add(lockIconElement);
            }

            return(buttonGrid);
        }
예제 #4
0
        protected Entity GetUIEntity(SpriteFont font, bool fixedSize, Vector3 position)
        {
            // Create and initialize "Touch Screen to Start"
            var touchStartLabel = new ContentDecorator
            {
                Content = new TextBlock
                {
                    Font      = font,
                    TextSize  = 32,
                    Text      = (fixedSize) ? "Fixed Size UI" : "Regular UI",
                    TextColor = Color.White
                },
                Padding             = new Thickness(30, 20, 30, 25),
                HorizontalAlignment = HorizontalAlignment.Center
            };

            //touchStartLabel.SetPanelZIndex(1);

            var grid = new Grid
            {
                BackgroundColor     = (fixedSize) ? new Color(255, 0, 255) : new Color(255, 255, 0),
                MaximumWidth        = 100,
                MaximumHeight       = 100,
                MinimumWidth        = 100,
                MinimumHeight       = 100,
                VerticalAlignment   = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center,
            };

            grid.RowDefinitions.Add(new StripDefinition(StripType.Auto));
            grid.ColumnDefinitions.Add(new StripDefinition());
            grid.LayerDefinitions.Add(new StripDefinition());

            grid.Children.Add(touchStartLabel);

            // Add the background
            var background = new ImageElement {
                StretchType = StretchType.Fill
            };

            background.SetPanelZIndex(-1);

            var uiEntity = new Entity();

            // Create a procedural model with a diffuse material
            var uiComponent = new UIComponent
            {
                Page = new UIPage
                {
                    RootElement = new UniformGrid {
                        Children = { background, grid }
                    }
                },
                //IsBillboard = true,
                IsFixedSize  = fixedSize,
                IsFullScreen = false,
                Resolution   = new Vector3(100, 100, 100), // Same size as the inner grid
                Size         = new Vector3(0.1f),          // 10% of the vertical resolution
            };

            uiEntity.Add(uiComponent);

            uiEntity.Transform.Position = position;

            return(uiEntity);
        }
예제 #5
0
        protected override void LoadScene()
        {
            // Allow user to resize the window with the mouse.
            Game.Window.AllowUserResizing = true;

            // Create and initialize "Xenko Samples" Text
            var xenkoSampleTextBlock = new ContentDecorator
            {
                BackgroundImage = SpriteFromSheet.Create(SplashScreenImages, "xenko_sample_text_bg"),
                Content         = new TextBlock
                {
                    Font      = WesternFont,
                    TextSize  = 60,
                    Text      = "Xenko Samples",
                    TextColor = Color.White,
                },
                Padding             = new Thickness(35, 15, 35, 25),
                HorizontalAlignment = HorizontalAlignment.Center
            };

            xenkoSampleTextBlock.SetPanelZIndex(1);

            // Create and initialize "UI" Text
            var uiTextBlock = new ContentDecorator
            {
                BackgroundImage = SpriteFromSheet.Create(SplashScreenImages, "ui_text_bg"),
                Content         = new TextBlock
                {
                    Font      = WesternFont,
                    TextSize  = 60,
                    Text      = "UI",
                    TextColor = Color.White,
                },
                Padding             = new Thickness(15, 4, 15, 7),
                HorizontalAlignment = HorizontalAlignment.Center
            };

            uiTextBlock.SetPanelZIndex(1);
            uiTextBlock.SetGridRow(1);

            // Create and initialize Xenko Logo
            var xenkoLogoImageElement = new ImageElement
            {
                Source = SpriteFromSheet.Create(SplashScreenImages, "Logo"),
                HorizontalAlignment = HorizontalAlignment.Center
            };

            xenkoLogoImageElement.SetPanelZIndex(1);
            xenkoLogoImageElement.SetGridRow(3);

            // Create and initialize "Touch Screen to Start"
            var touchStartLabel = new ContentDecorator
            {
                BackgroundImage = SpriteFromSheet.Create(SplashScreenImages, "touch_start_frame"),
                Content         = new TextBlock
                {
                    Font      = WesternFont,
                    TextSize  = 42,
                    Text      = "Touch Screen to Start",
                    TextColor = Color.White
                },
                Padding             = new Thickness(30, 20, 30, 25),
                HorizontalAlignment = HorizontalAlignment.Center
            };

            touchStartLabel.SetPanelZIndex(1);
            touchStartLabel.SetGridRow(5);

            var grid = new Grid
            {
                MaximumWidth        = 600,
                MaximumHeight       = 900,
                VerticalAlignment   = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center,
            };

            grid.RowDefinitions.Add(new StripDefinition(StripType.Auto));
            grid.RowDefinitions.Add(new StripDefinition(StripType.Auto));
            grid.RowDefinitions.Add(new StripDefinition(StripType.Star, 2));
            grid.RowDefinitions.Add(new StripDefinition(StripType.Star, 2f));
            grid.RowDefinitions.Add(new StripDefinition(StripType.Star, 2));
            grid.RowDefinitions.Add(new StripDefinition(StripType.Auto));
            grid.ColumnDefinitions.Add(new StripDefinition());
            grid.LayerDefinitions.Add(new StripDefinition());

            grid.Children.Add(xenkoSampleTextBlock);
            grid.Children.Add(uiTextBlock);
            grid.Children.Add(xenkoLogoImageElement);
            grid.Children.Add(touchStartLabel);

            // Add the background
            var background = new ImageElement {
                Source = SpriteFromSheet.Create(SplashScreenImages, "background_uiimage"), StretchType = StretchType.Fill
            };

            background.SetPanelZIndex(-1);

            Entity.Get <UIComponent>().RootElement = new UniformGrid {
                Children = { background, grid }
            };
        }