コード例 #1
0
        private Button CreateButton(string text, int textSize, int columnId, Scene targetScene)
        {
            var button = new Button
            {
                Name = text,
                HorizontalAlignment = HorizontalAlignment.Center,
                Content = new TextBlock { Text = text, Font = Font, TextSize = textSize, TextColor = new Color(200, 200, 200, 255), VerticalAlignment = VerticalAlignment.Center },
                BackgroundColor = new Color(new Vector4(0.2f, 0.2f, 0.2f, 0.2f)),
            };

            button.SetGridColumn(columnId);

            button.Click += (sender, args) =>
            {
                SceneSystem.SceneInstance.Scene = targetScene;
                Cancel();
            };

            return button;
        }
コード例 #2
0
ファイル: SensorGameTest.cs プロジェクト: cg123/xenko
        private void BuildUI()
        {
            var width = 400;
            var bufferRatio = GraphicsDevice.Presenter.BackBuffer.Width / (float)GraphicsDevice.Presenter.BackBuffer.Height;
            var ui = new UIComponent { Resolution = new Vector3(width, width / bufferRatio, 500) };
            SceneSystem.SceneInstance.Scene.Entities.Add(new Entity { ui });

            currentText = new TextBlock { Font = font, TextColor = Color.White, VerticalAlignment = VerticalAlignment.Bottom, HorizontalAlignment = HorizontalAlignment.Center };

            var buttonBack = new Button { Content = new TextBlock { Font = font, Text = "Previous" }, VerticalAlignment = VerticalAlignment.Bottom, HorizontalAlignment = HorizontalAlignment.Left };
            var buttonNext = new Button { Content = new TextBlock { Font = font, Text = "Next" }, VerticalAlignment = VerticalAlignment.Bottom, HorizontalAlignment = HorizontalAlignment.Right };

            currentText.SetGridColumn(1);
            buttonNext.SetGridColumn(2);

            buttonBack.Click += (o, _) => ChangeScene(-1);
            buttonNext.Click += (o, _) => ChangeScene(+1);

            ui.RootElement = new UniformGrid { Columns = 3, Children = { buttonBack, currentText, buttonNext } };
        }
コード例 #3
0
ファイル: TerrainScript.cs プロジェクト: cg123/xenko
        /// <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;
        }