Exemplo n.º 1
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 UI Particles",
                    TextColor = Color.White,
                },
                Padding = new Thickness(35, 15, 35, 25),
                HorizontalAlignment = HorizontalAlignment.Center
            };

            xenkoSampleTextBlock.SetPanelZIndex(1);
            

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

            var xenkoButtonConfetti = 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
            };

            xenkoButtonConfetti.SetPanelZIndex(1);
            xenkoButtonConfetti.SetGridRow(1);

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

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

            var xenkoButtonStars = 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

            };

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

            xenkoButtonStars.Click += delegate
            {
                desiredState = GameState.EndGame;
                var effectOffset = new Vector3(45 - xenkoButtonStars.RenderSize.X / 2, -5, 0);
                SpawnParticles(xenkoButtonStars.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(xenkoSampleTextBlock);
            grid.Children.Add(xenkoButtonConfetti);
            grid.Children.Add(xenkoButtonStars);
            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 } } };
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates UI showing parameters of Fault formation algorithm
        /// </summary>
        private void CreateUI()
        {
            var virtualResolution = new Vector3(GraphicsDevice.Presenter.BackBuffer.Width, GraphicsDevice.Presenter.BackBuffer.Height, 1);

            loadingModal = new ModalElement { Visibility = Visibility.Collapsed };

            loadingTextBlock = new TextBlock { Font = Font, Text = "Loading a model...", Visibility = Visibility.Collapsed, TextColor = Color.White, TextSize = 22 };

            loadingTextBlock.SetCanvasPinOrigin(new Vector3(0.5f, 0.5f, 1f));
            loadingTextBlock.SetCanvasRelativePosition(new Vector3(0.5f, 0.5f, 0));

            // Parameters Grid
            var parametersGrid = new Grid();
            parametersGrid.LayerDefinitions.Add(new StripDefinition(StripType.Auto));
            parametersGrid.RowDefinitions.Add(new StripDefinition(StripType.Auto));
            parametersGrid.RowDefinitions.Add(new StripDefinition(StripType.Auto));
            parametersGrid.RowDefinitions.Add(new StripDefinition(StripType.Auto));
            parametersGrid.RowDefinitions.Add(new StripDefinition(StripType.Auto));
            parametersGrid.RowDefinitions.Add(new StripDefinition(StripType.Auto));
            parametersGrid.ColumnDefinitions.Add(new StripDefinition(StripType.Auto));
            parametersGrid.ColumnDefinitions.Add(new StripDefinition(StripType.Star));
            parametersGrid.ColumnDefinitions.Add(new StripDefinition(StripType.Fixed, 30));
            parametersGrid.ColumnDefinitions.Add(new StripDefinition(StripType.Fixed, 30));

            // Terrain Size
            var terrainSizeText = new TextBlock
            {
                Font = Font,
                Text = "" + (int)Math.Pow(2, terrainSizePowerFactor),
                TextAlignment = TextAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center,
                MinimumWidth = 60
            };
            terrainSizeText.SetGridRow(0);
            terrainSizeText.SetGridColumn(1);

            var terrainSizeIncButton = new Button { Content = new TextBlock { Text = "+", Font = Font, TextAlignment = TextAlignment.Center } };
            terrainSizeIncButton.SetGridRow(0);
            terrainSizeIncButton.SetGridColumn(3);

            var terrainSizeDecButton = new Button { Content = new TextBlock { Text = "-", Font = Font, TextAlignment = TextAlignment.Center } };
            terrainSizeDecButton.SetGridRow(0);
            terrainSizeDecButton.SetGridColumn(2);

            terrainSizeIncButton.Click += (s, e) =>
            {
                TerrainSizePowerFactor++;
                terrainSizeText.Text = "" + (int)Math.Pow(2, TerrainSizePowerFactor);
            };

            terrainSizeDecButton.Click += (s, e) =>
            {
                TerrainSizePowerFactor--;
                terrainSizeText.Text = "" + (int)Math.Pow(2, TerrainSizePowerFactor);
            };

            var terrainSizeDescription = new TextBlock
            {
                Font = Font,
                Text = "Terrain Size:",
                TextAlignment = TextAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Left
            };

            terrainSizeDescription.SetGridRow(0);
            terrainSizeDescription.SetGridColumn(0);

            parametersGrid.Children.Add(terrainSizeDescription);
            parametersGrid.Children.Add(terrainSizeText);
            parametersGrid.Children.Add(terrainSizeDecButton);
            parametersGrid.Children.Add(terrainSizeIncButton);

            // Iteration
            var iterationText = new TextBlock
            {
                Font = Font,
                Text = "" + (int)Math.Pow(2, IterationPowerFactor),
                TextAlignment = TextAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center
            };

            iterationText.SetGridRow(1);
            iterationText.SetGridColumn(1);

            var iterationIncButton = new Button { Content = new TextBlock { Text = "+", Font = Font, TextAlignment = TextAlignment.Center } };
            iterationIncButton.SetGridRow(1);
            iterationIncButton.SetGridColumn(3);

            var iterationDecButton = new Button { Content = new TextBlock { Text = "-", Font = Font, TextAlignment = TextAlignment.Center } };
            iterationDecButton.SetGridRow(1);
            iterationDecButton.SetGridColumn(2);

            iterationIncButton.Click += (s, e) =>
            {
                IterationPowerFactor++;
                iterationText.Text = "" + (int)Math.Pow(2, IterationPowerFactor);
            };

            iterationDecButton.Click += (s, e) =>
            {
                IterationPowerFactor--;
                iterationText.Text = "" + (int)Math.Pow(2, IterationPowerFactor);
            };

            var iterationDescription = new TextBlock
            {
                Font = Font,
                Text = "Iteration:",
                TextAlignment = TextAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Left
            };

            iterationDescription.SetGridRow(1);
            iterationDescription.SetGridColumn(0);

            parametersGrid.Children.Add(iterationDescription);
            parametersGrid.Children.Add(iterationText);
            parametersGrid.Children.Add(iterationDecButton);
            parametersGrid.Children.Add(iterationIncButton);

            // Filter Intensity
            var filterIntensityText = new TextBlock
            {
                Font = Font,
                Text = "" + FilterHeightBandStrength,
                TextAlignment = TextAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center
            };

            filterIntensityText.SetGridRow(2);
            filterIntensityText.SetGridColumn(1);

            var filterIncButton = new Button { Content = new TextBlock { Text = "+", Font = Font, TextAlignment = TextAlignment.Center } };
            filterIncButton.SetGridRow(2);
            filterIncButton.SetGridColumn(3);

            var filterDecButton = new Button { Content = new TextBlock { Text = "-", Font = Font, TextAlignment = TextAlignment.Center } };
            filterDecButton.SetGridRow(2);
            filterDecButton.SetGridColumn(2);

            filterIncButton.Click += (s, e) =>
            {
                FilterHeightBandStrength += 0.1f;
                filterIntensityText.Text = "" + FilterHeightBandStrength;
            };

            filterDecButton.Click += (s, e) =>
            {
                FilterHeightBandStrength -= 0.1f;
                filterIntensityText.Text = "" + FilterHeightBandStrength;
            };

            var filterIntensityDescription = new TextBlock
            {
                Font = Font,
                Text = "Filter Intensity:",
                TextAlignment = TextAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Left
            };

            filterIntensityDescription.SetGridRow(2);
            filterIntensityDescription.SetGridColumn(0);

            parametersGrid.Children.Add(filterIntensityDescription);
            parametersGrid.Children.Add(filterIntensityText);
            parametersGrid.Children.Add(filterDecButton);
            parametersGrid.Children.Add(filterIncButton);

            // Height Scale
            var heightScaleText = new TextBlock
            {
                Font = Font,
                Text = "" + TerrainHeightScale,
                TextAlignment = TextAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center
            };

            heightScaleText.SetGridRow(3);
            heightScaleText.SetGridColumn(1);

            var heightScaleIncButton = new Button { Content = new TextBlock { Text = "+", Font = Font, TextAlignment = TextAlignment.Center } };
            heightScaleIncButton.SetGridRow(3);
            heightScaleIncButton.SetGridColumn(3);

            var heightScaleDecButton = new Button { Content = new TextBlock { Text = "-", Font = Font, TextAlignment = TextAlignment.Center } };
            heightScaleDecButton.SetGridRow(3);
            heightScaleDecButton.SetGridColumn(2);

            heightScaleIncButton.Click += (s, e) =>
            {
                TerrainHeightScale++;
                heightScaleText.Text = "" + TerrainHeightScale;
            };

            heightScaleDecButton.Click += (s, e) =>
            {
                TerrainHeightScale--;
                heightScaleText.Text = "" + TerrainHeightScale;
            };

            var heightScaleDescription = new TextBlock
            {
                Font = Font,
                Text = "Height Scale:",
                TextAlignment = TextAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Left
            };

            heightScaleDescription.SetGridRow(3);
            heightScaleDescription.SetGridColumn(0);

            parametersGrid.Children.Add(heightScaleDescription);
            parametersGrid.Children.Add(heightScaleText);
            parametersGrid.Children.Add(heightScaleDecButton);
            parametersGrid.Children.Add(heightScaleIncButton);

            // Zoom
            var zoomFactorIncButton = new Button { Content = new TextBlock { Text = "+", Font = Font, TextAlignment = TextAlignment.Center } };
            zoomFactorIncButton.SetGridRow(4);
            zoomFactorIncButton.SetGridColumn(3);

            var zoomFactorDecButton = new Button { Content = new TextBlock { Text = "-", Font = Font, TextAlignment = TextAlignment.Center } };
            zoomFactorDecButton.SetGridRow(4);
            zoomFactorDecButton.SetGridColumn(2);

            zoomFactorIncButton.Click += (s, e) =>
            {
                zoomFactor -= 0.1f;
                UpdateCamera();
            };

            zoomFactorDecButton.Click += (s, e) =>
            {
                zoomFactor += 0.1f;
                UpdateCamera();
            };

            var zoomDescription = new TextBlock
            {
                Font = Font,
                Text = "Zoom",
                TextAlignment = TextAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Right
            };

            zoomDescription.SetGridRow(4);
            zoomDescription.SetGridColumn(0);

            parametersGrid.Children.Add(zoomDescription);
            parametersGrid.Children.Add(zoomFactorDecButton);
            parametersGrid.Children.Add(zoomFactorIncButton);

            // Light toggle button
            var lightToggleButton = new Button { Content = new TextBlock { Text = "Directional Light Off", Font = Font }, HorizontalAlignment = HorizontalAlignment.Left };

            lightToggleButton.Click += (s, e) =>
            {
                var ligh0 = DirectionalLight0.Get<LightComponent>();
                var ligh1 = DirectionalLight1.Get<LightComponent>();

                ligh0.Enabled = !ligh0.Enabled;
                ligh1.Enabled = !ligh1.Enabled;
                ((TextBlock)lightToggleButton.Content).Text = ligh0.Enabled ? "Directional Light Off" : "Directional Light On";
            };

            // Re-create terrain
            var reCreateTerrainButton = new Button { Content = new TextBlock { Text = "Recreate terrain", Font = Font }, HorizontalAlignment = HorizontalAlignment.Left };

            reCreateTerrainButton.Click += (s, e) => GenerateTerrain();

            var descriptionCanvas = new StackPanel
            {
                Children =
                {
                    new TextBlock { Font = Font, Text = "Fault formation parameters", TextSize = 19},
                    parametersGrid,
                    lightToggleButton,
                    reCreateTerrainButton
                }
            };

            var activeButton = new Button
            {
                Content = new TextBlock { Text = "Description Off", Font = Font },
                Padding = new Thickness(10, 10, 10, 10),
                Margin = new Thickness(0, 0, 0, 20),
                HorizontalAlignment = HorizontalAlignment.Left
            };

            var isDescriptionOn = true;

            activeButton.Click += (s, e) =>
            {
                isDescriptionOn = !isDescriptionOn;
                ((TextBlock)activeButton.Content).Text = isDescriptionOn ? "Description Off" : "Description On";
                descriptionCanvas.Visibility = isDescriptionOn ? Visibility.Visible : Visibility.Collapsed;
            };

            var buttonDescription = new StackPanel { Orientation = Orientation.Vertical, Children = { activeButton, descriptionCanvas } };

            var uiComponent = UIEntity.Get<UIComponent>();
            uiComponent.RootElement = new Canvas { Children = { buttonDescription, loadingModal, loadingTextBlock } };
            uiComponent.Resolution = virtualResolution;
        }