示例#1
0
        private void InitializeWelcomePopup()
        {
            welcomePopup = UILibrary.InstantiateElement <ModalElement>("WelcomePopup");
            welcomePopup.SetPanelZIndex(1);

            // FIXME: UI asset should support multiline text
            var welcomeText = welcomePopup.FindVisualChildOfType <TextBlock>("welcomeText");

            welcomeText.Text = "Welcome to stride UI sample.\nPlease name your character";

            var cancelButton = welcomePopup.FindVisualChildOfType <Button>("cancelButton");

            cancelButton.Click += delegate
            {
                nameTextBlock.Text = DefaultName;
                CloseWelcomePopup();
            };

            var nameEditText = welcomePopup.FindVisualChildOfType <EditText>("nameEditText");

            nameEditText.Text = DefaultName;
            var validateButton = welcomePopup.FindVisualChildOfType <Button>("validateButton");

            validateButton.Click += delegate
            {
                nameTextBlock.Text = nameEditText.Text.Trim();
                CloseWelcomePopup();
            };
        }
示例#2
0
        private void InitializeShipSelectionPopup()
        {
            shipSelectPopup = UILibrary.InstantiateElement <ModalElement>("ShipSelectPopup");
            shipSelectPopup.SetPanelZIndex(1);

            // Layout elements in vertical StackPanel
            var contentStackpanel = shipSelectPopup.FindVisualChildOfType <StackPanel>("contentStackPanel");

            // Create and Add SpaceShip to the stack layout
            foreach (var ship in shipList)
            {
                contentStackpanel.Children.Add(CreateShipSelectionItem(ship));
            }

            // Uncomment those lines to have an example of stack panel item virtualization
            //var shipInitialCount = shipList.Count;
            //contentStackpanel.ItemVirtualizationEnabled = true;
            //for (var i = 0; i < 200; i++)
            //{
            //    shipList.Add(new SpaceShip { Name = shipList[i % shipInitialCount].Name });
            //    contentStackpanel.Children.Add(CreateShipSelectionItem(shipList[shipList.Count - 1]));
            //}

            UpdateShipStatus();
            CloseShipSelectPopup();
        }
示例#3
0
        private void CreateWelcomePopup()
        {
            // Create welcome text
            var welcomeText = new TextBlock
            {
                Font                = WesternFont,
                TextSize            = 42,
                TextColor           = Color.White,
                Text                = "Welcome to xenko UI sample.\n" + "Please name your character",
                TextAlignment       = TextAlignment.Center,
                WrapText            = true,
                Margin              = new Thickness(20, 0, 20, 0),
                HorizontalAlignment = HorizontalAlignment.Center
            };

            // Create Edit text
            var nameEditText = new EditText()
            {
                Font                = WesternFont,
                TextSize            = 32,
                TextColor           = Color.White,
                Text                = DefaultName,
                MaxLength           = 15,
                TextAlignment       = TextAlignment.Center,
                ActiveImage         = SpriteFromSheet.Create(MainSceneImages, "tex_edit_activated_background"),
                InactiveImage       = SpriteFromSheet.Create(MainSceneImages, "tex_edit_inactivated_background"),
                MouseOverImage      = SpriteFromSheet.Create(MainSceneImages, "tex_edit_inactivated_background"),
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment   = VerticalAlignment.Center,
                MinimumWidth        = 340,
                Padding             = new Thickness(30, 30, 30, 40), // Pad text (Content inside),
                Margin              = new Thickness(0, 80, 0, 80),   // Space around the edit
            };

            nameEditText.SetGridRow(1);

            // Create cancel and validate button
            var cancelButton = CreateTextButton("Cancel");

            cancelButton.SetGridColumn(1);

            cancelButton.Click += delegate
            {
                nameTextBlock.Text      = DefaultName;
                welcomePopup.Visibility = Visibility.Collapsed;
            };

            var validateButton = CreateTextButton("Validate");

            validateButton.SetGridColumn(3);

            validateButton.Click += delegate
            {
                nameTextBlock.Text      = nameEditText.Text.Trim();
                welcomePopup.Visibility = Visibility.Collapsed;
            };

            // Put cancel and validate buttons in stack panel (Left-right orientation placement)
            var buttonPanel = new Grid();

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

            buttonPanel.Children.Add(cancelButton);
            buttonPanel.Children.Add(validateButton);
            buttonPanel.SetGridRow(2);

            // Create a stack panel to store items (Top-down orientation placement)
            var popupContentPanel = new Grid
            {
                MaximumWidth        = 580,
                MaximumHeight       = 900,
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment   = VerticalAlignment.Center,
            };

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

            popupContentPanel.Children.Add(welcomeText);
            popupContentPanel.Children.Add(nameEditText);
            popupContentPanel.Children.Add(buttonPanel);

            var welcomePopupContent = new ContentDecorator
            {
                BackgroundImage = popupWindowImage,
                Content         = popupContentPanel,
                Padding         = new Thickness(85, 130, 85, 110)
            };

            welcomePopup = new ModalElement
            {
                Visibility = Visibility.Collapsed,
                Content    = welcomePopupContent,
            };
            welcomePopup.SetPanelZIndex(1);
        }
示例#4
0
        private void CreateShipSelectionPopup()
        {
            // Create "Please select your SpaceShip" text
            var pleaseSelectText = new TextBlock
            {
                Font          = WesternFont,
                TextSize      = 48,
                TextColor     = Color.White,
                Text          = "Please select your ship",
                TextAlignment = TextAlignment.Center,
                WrapText      = true
            };

            // Layout elements in vertical StackPanel
            var contentStackpanel = new StackPanel {
                Orientation = Orientation.Vertical
            };

            // Create and Add SpaceShip to the stack layout
            foreach (var ship in shipList)
            {
                contentStackpanel.Children.Add(CreateShipButtonElement(ship));
            }

            // Uncomment those lines to have an example of stack panel item virtualization
            //var shipInitialCount = shipList.Count;
            //contentStackpanel.ItemVirtualizationEnabled = true;
            //for (int i = 0; i < 200; i++)
            //{
            //    shipList.Add(new SpaceShip { Name = shipList[i % shipInitialCount].Name });
            //    contentStackpanel.Children.Add(CreateShipButtonElement(shipList[shipList.Count - 1]));
            //}

            UpdateShipStatus();

            var contentScrollView = new ScrollViewer
            {
                MaximumHeight  = 425,
                Content        = contentStackpanel,
                ScrollMode     = ScrollingMode.Vertical,
                Margin         = new Thickness(12, 10, 7, 10),
                Padding        = new Thickness(0, 0, 6, 0),
                ScrollBarColor = Color.Orange
            };

            var scrollViewerDecorator = new ContentDecorator {
                BackgroundImage = SpriteFromSheet.Create(MainSceneImages, "scroll_background"), Content = contentScrollView,
            };

            scrollViewerDecorator.SetGridRow(2);

            var layoutGrid = new Grid();

            layoutGrid.ColumnDefinitions.Add(new StripDefinition());
            layoutGrid.RowDefinitions.Add(new StripDefinition(StripType.Auto));
            layoutGrid.RowDefinitions.Add(new StripDefinition(StripType.Fixed, 10)); // white space
            layoutGrid.RowDefinitions.Add(new StripDefinition(StripType.Star));
            layoutGrid.LayerDefinitions.Add(new StripDefinition());
            layoutGrid.Children.Add(pleaseSelectText);
            layoutGrid.Children.Add(scrollViewerDecorator);

            var shipSelectPopupContent = new ContentDecorator
            {
                BackgroundImage = popupWindowImage,
                Content         = layoutGrid,
                Padding         = new Thickness(110, 120, 100, 140)
            };

            // Create SpaceShip selection popup
            shipSelectPopup = new ModalElement
            {
                Visibility = Visibility.Collapsed,
                Content    = shipSelectPopupContent
            };

            shipSelectPopup.SetPanelZIndex(1);
        }