protected override async Task LoadContent() { await base.LoadContent(); var sprites = Asset.Load<SpriteSheet>("RotatedImages"); var img1 = new ImageElement { Source = sprites["NRNR"], StretchType = StretchType.Fill }; var img2 = new ImageElement { Source = sprites["RNR"], StretchType = StretchType.Fill }; var img3 = new ImageElement { Source = sprites["NRR"], StretchType = StretchType.Fill }; var img4 = new ImageElement { Source = sprites["RR"], StretchType = StretchType.Fill }; img1.SetGridColumnSpan(2); img2.SetGridColumnSpan(2); img2.SetGridRow(1); img3.SetGridRowSpan(2); img3.SetGridColumn(2); img4.SetGridRowSpan(2); img4.SetGridColumn(3); var grid = new UniformGrid { Rows = 2, Columns = 4, Children = { img1, img2, img3, img4 } }; UIComponent.RootElement = grid; }
private UIElement CreateMainSceneShipStatusPanel() { // Status star bars {Power, Life, Speed} var powerStatusDecorator = CreateMainSceneShipStatusStars("power", powerStatusStar, 0); var controlStatusDecorator = CreateMainSceneShipStatusStars("control", controlStatusStar, 1); var speedStatusDecorator = CreateMainSceneShipStatusStars("speed", speedStatusStar, 2); PowerStatus = shipList[activeShipIndex].Power; ControlStatus = shipList[activeShipIndex].Control; SpeedStatus = shipList[activeShipIndex].Speed; // Put the stats (Stars) in 3x1 uniform grid var statusPanel = new UniformGrid { Rows = 3 }; statusPanel.Children.Add(powerStatusDecorator); statusPanel.Children.Add(controlStatusDecorator); statusPanel.Children.Add(speedStatusDecorator); statusPanel.SetGridColumn(1); // SpaceShip Button currentShipImage = new ImageElement { Source = mainScreneImages[shipList[activeShipIndex].Name], }; currentShipImage.SetGridRow(1); var shipImageSpacerGrid = new Grid { HorizontalAlignment = HorizontalAlignment.Center }; shipImageSpacerGrid.Children.Add(currentShipImage); shipImageSpacerGrid.RowDefinitions.Add(new StripDefinition(StripType.Star, 2)); shipImageSpacerGrid.RowDefinitions.Add(new StripDefinition(StripType.Star, 6)); shipImageSpacerGrid.RowDefinitions.Add(new StripDefinition(StripType.Star, 2)); shipImageSpacerGrid.ColumnDefinitions.Add(new StripDefinition()); shipImageSpacerGrid.LayerDefinitions.Add(new StripDefinition()); var shipButtonDesign = mainScreneImages["display_element"]; var currentShipButton = new Button { NotPressedImage = shipButtonDesign, PressedImage = shipButtonDesign, MouseOverImage = shipButtonDesign, Content = shipImageSpacerGrid, Padding = new Thickness(45, 20, 10, 25), VerticalAlignment = VerticalAlignment.Center }; currentShipButton.Click += delegate { // Once click, update the SpaceShip status pop-up and show it. UpdateShipStatus(); ShowShipSelectionPopup(); }; currentShipButton.SetGridColumn(3); // Status upgrade buttons var powerUpgradeButton = CreateIncreaseStatusButton("P", 0, 0, 2, 0, () => PowerStatus, () => PowerStatus++); var controlUpgradeButton = CreateIncreaseStatusButton("C", 0, 1, 2, 0, () => ControlStatus, () => ControlStatus++); var speedUpgradeButton = CreateIncreaseStatusButton("S", 1, 0, 2, 0, () => SpeedStatus, () => SpeedStatus++); var lifeUpgradeButton = CreateIncreaseStatusButton("L", 1, 1, 1, 1, () => 0, () => LifeStatus++); // Arrange the status up buttons in a 2x2 Uniform grid. var statusUpgradeGridPanel = new UniformGrid { Rows = 2, Columns = 2, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center }; statusUpgradeGridPanel.Children.Add(powerUpgradeButton); statusUpgradeGridPanel.Children.Add(controlUpgradeButton); statusUpgradeGridPanel.Children.Add(speedUpgradeButton); statusUpgradeGridPanel.Children.Add(lifeUpgradeButton); statusUpgradeGridPanel.SetGridColumn(5); // Put together bottom region in horizontal Stack panel, arranging it from left to right var mainPanel = new Grid(); mainPanel.RowDefinitions.Add(new StripDefinition()); mainPanel.ColumnDefinitions.Add(new StripDefinition(StripType.Fixed, 10)); // space mainPanel.ColumnDefinitions.Add(new StripDefinition(StripType.Star, 4)); mainPanel.ColumnDefinitions.Add(new StripDefinition(StripType.Fixed, 25)); // space mainPanel.ColumnDefinitions.Add(new StripDefinition(StripType.Star, 4)); mainPanel.ColumnDefinitions.Add(new StripDefinition(StripType.Fixed, 25)); // space mainPanel.ColumnDefinitions.Add(new StripDefinition(StripType.Star, 3)); mainPanel.ColumnDefinitions.Add(new StripDefinition(StripType.Fixed, 10)); // space mainPanel.LayerDefinitions.Add(new StripDefinition()); mainPanel.Children.Add(statusPanel); mainPanel.Children.Add(currentShipButton); mainPanel.Children.Add(statusUpgradeGridPanel); return mainPanel; }
private UIElement CreateMainScene() { // the top life bar var topBar = CreateMainScreneTopBar(); // Create Name label nameTextBlock = new TextBlock { Font = westernFont, TextSize = 52, TextColor = Color.LightGreen, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(50, 0, 50, 0) }; var nameLabel = new ContentDecorator { BackgroundImage = mainScreneImages["tex_edit_inactivated_background"], Content = nameTextBlock, Padding = new Thickness(20, 15, 20, 20), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center }; nameLabel.SetGridRow(1); // Create Character image var characterImage = new ImageElement { Name = "HeroImage", Source = mainScreneImages["character"], HorizontalAlignment = HorizontalAlignment.Center, }; characterImage.SetGridRow(2); // Create Explanation TextBlock var explanationLabel = new ContentDecorator { BackgroundImage = mainScreneImages["description_frame"], HorizontalAlignment = HorizontalAlignment.Center, Content = new TextBlock { Font = LoadAsset<SpriteFont>("JapaneseFont"), TextSize = 34, TextColor = Color.White, Text = "Pictogram-based alphabets are easily supported.\n日本語も簡単に入れることが出来ます。", HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, WrapText = true }, Padding = new Thickness(50, 30, 50, 40), }; explanationLabel.SetGridRow(3); // The ship status panel var shipStatusPanel = CreateMainSceneShipStatusPanel(); shipStatusPanel.SetGridRow(4); // Create quit button (Last element) var quitButton = CreateTextButton("Quit Sample"); quitButton.HorizontalAlignment = HorizontalAlignment.Center; quitButton.VerticalAlignment = VerticalAlignment.Center; quitButton.Click += delegate { UIGame.Exit(); }; quitButton.SetGridRow(5); // Put region together in the main grid var mainLayout = new Grid(); mainLayout.ColumnDefinitions.Add(new StripDefinition()); mainLayout.RowDefinitions.Add(new StripDefinition(StripType.Star, 15)); mainLayout.RowDefinitions.Add(new StripDefinition(StripType.Star, 10)); mainLayout.RowDefinitions.Add(new StripDefinition(StripType.Star, 20)); mainLayout.RowDefinitions.Add(new StripDefinition(StripType.Star, 20)); mainLayout.RowDefinitions.Add(new StripDefinition(StripType.Star, 25)); mainLayout.RowDefinitions.Add(new StripDefinition(StripType.Star, 10)); mainLayout.LayerDefinitions.Add(new StripDefinition()); // set minimal and maximal size of rows mainLayout.RowDefinitions[0].MaximumSize = topBar.MaximumHeight; mainLayout.RowDefinitions[1].MinimumSize = 100; mainLayout.RowDefinitions[3].MinimumSize = 120; mainLayout.RowDefinitions[5].MinimumSize = 90; mainLayout.Children.Add(topBar); mainLayout.Children.Add(nameLabel); mainLayout.Children.Add(characterImage); mainLayout.Children.Add(explanationLabel); mainLayout.Children.Add(shipStatusPanel); mainLayout.Children.Add(quitButton); return mainLayout; }
private ImageElement CreateShipStatusStar(int elementIndex) { var starImage = new ImageElement { VerticalAlignment = VerticalAlignment.Center }; starImage.SetGridRow(elementIndex); return starImage; }
protected override void LoadScene() { // Allow user to resize the window with the mouse. Game.Window.AllowUserResizing = true; var arial = LoadAsset<SpriteFont>("WesternFont"); var uiImages = LoadAsset<SpriteSheet>("SplashScreenImages"); // Create and initialize "Paradox Samples" Text var paradoxSampleTextBlock = new ContentDecorator { BackgroundImage = uiImages["paradox_sample_text_bg"], Content = new TextBlock { Font = arial, TextSize = 60, Text = "Paradox Samples", TextColor = Color.White, }, Padding = new Thickness(35, 15, 35, 25), HorizontalAlignment = HorizontalAlignment.Center }; paradoxSampleTextBlock.SetPanelZIndex(1); // Create and initialize "UI" Text var uiTextBlock = new ContentDecorator { BackgroundImage = uiImages["ui_text_bg"], Content = new TextBlock { Font = arial, 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 Paradox Logo var paradoxLogoImageElement = new ImageElement { Source = uiImages["Logo"], HorizontalAlignment = HorizontalAlignment.Center }; paradoxLogoImageElement.SetPanelZIndex(1); paradoxLogoImageElement.SetGridRow(3); // Create and initialize "Touch Screen to Start" var touchStartLabel = new ContentDecorator { BackgroundImage = uiImages["touch_start_frame"], Content = new TextBlock { Font = arial, 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, 5)); 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(paradoxSampleTextBlock); grid.Children.Add(uiTextBlock); grid.Children.Add(paradoxLogoImageElement); grid.Children.Add(touchStartLabel); // Add the background var background = new ImageElement { Source = uiImages["background_uiimage"], StretchType = StretchType.Fill }; background.SetPanelZIndex(-1); Entity.Get<UIComponent>().RootElement = new UniformGrid { Children = { background, grid } }; }