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; }
public void TestComputeAvailableSize() { var child = new Button(); child.SetCanvasPinOrigin(new Vector3(0, 0.5f, 1)); // tests in the cases position is absolute var availableSize = new Vector3(100, 150, 200); child.SetCanvasAbsolutePosition(new Vector3(-1, -2, -3)); Utilities.AreExactlyEqual(new Vector3(0), ComputeAvailableSize(child, availableSize, false)); child.SetCanvasAbsolutePosition(new Vector3(0, 0, 0)); Utilities.AreExactlyEqual(new Vector3(100, 0, 0), ComputeAvailableSize(child, availableSize, false)); child.SetCanvasAbsolutePosition(new Vector3(1, 2, 3)); Utilities.AreExactlyEqual(new Vector3(99, 4, 3), ComputeAvailableSize(child, availableSize, false)); child.SetCanvasAbsolutePosition(availableSize); Utilities.AreExactlyEqual(new Vector3(0, 0, 200), ComputeAvailableSize(child, availableSize, false)); child.SetCanvasAbsolutePosition(availableSize + new Vector3(1, 2, 3)); Utilities.AreExactlyEqual(new Vector3(0), ComputeAvailableSize(child, availableSize, false)); // tests in the cases position is relative child.SetCanvasRelativePosition(new Vector3(-1, -2, -3)); Utilities.AreExactlyEqual(new Vector3(0), ComputeAvailableSize(child, availableSize, false)); child.SetCanvasRelativePosition(new Vector3(0, 0, 0)); Utilities.AreExactlyEqual(new Vector3(100, 0, 0), ComputeAvailableSize(child, availableSize, false)); child.SetCanvasRelativePosition(new Vector3(0.1f, 0.2f, 0.4f)); Utilities.AreExactlyEqual(new Vector3(90, 60, 80), ComputeAvailableSize(child, availableSize, false)); child.SetCanvasRelativePosition(new Vector3(1f)); Utilities.AreExactlyEqual(new Vector3(0, 0, 200), ComputeAvailableSize(child, availableSize, false)); child.SetCanvasRelativePosition(new Vector3(1.1f, 2f, 3f)); Utilities.AreExactlyEqual(new Vector3(0), ComputeAvailableSize(child, availableSize, false)); // tests in the case available size are infinite availableSize = new Vector3(float.PositiveInfinity); child.SetCanvasAbsolutePosition(new Vector3(-1, -2, -3)); Utilities.AreExactlyEqual(new Vector3(0), ComputeAvailableSize(child, availableSize, false)); child.SetCanvasAbsolutePosition(new Vector3(1, 2, 3)); Utilities.AreExactlyEqual(new Vector3(float.PositiveInfinity, 4, 3), ComputeAvailableSize(child, availableSize, false)); child.SetCanvasRelativePosition(new Vector3(-1f, -2f, -3f)); Utilities.AreExactlyEqual(new Vector3(0), ComputeAvailableSize(child, availableSize, false)); child.SetCanvasRelativePosition(new Vector3(1f, 2f, 3f)); Utilities.AreExactlyEqual(new Vector3(float.PositiveInfinity), ComputeAvailableSize(child, availableSize, false)); child.SetCanvasRelativeSize(new Vector3(0, 0.5f, 1.5f)); Utilities.AreExactlyEqual(new Vector3(0, float.PositiveInfinity, float.PositiveInfinity), ComputeAvailableSize(child, availableSize, false)); }