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); }
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 = mainScreneImages[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 = mainScreneImages["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 lockIconImage = mainScreneImages["lock_icon"]; var lockIconElement = new ImageElement { Source = lockIconImage, StretchType = StretchType.Fill, }; lockIconElement.SetPanelZIndex(1); buttonGrid.Children.Add(lockIconElement); } return buttonGrid; }
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 } }; }