/// <summary> /// Creates a new element with a label and a button, allowing a player to build a building using a builder. /// </summary> /// <param name="startPos">The starting position of this element on the screen.</param> /// <param name="unitNameWithCount">The string in the label.</param> /// <param name="addSelectionHandler">The click handler for the button.</param> /// <returns>The element with the label and the button.</returns> public static ElementArmySelection CreateBuildButton(Point startPos, string unitNameWithCount, GuiButton.OnClickHandler addSelectionHandler, GuiButton.OnClickHandler removeSelectionHandler) { // Create the new element using the starting position, and add the click handler Rectangle rect = new Rectangle(startPos, new Point(0)); ElementArmySelection retVal = new ElementArmySelection(startPos, unitNameWithCount, " - ", " + "); retVal.buttonRemoveSelection.ClickHandler = removeSelectionHandler; retVal.buttonAddSelection.ClickHandler = addSelectionHandler; // Calculate the location and size of this object Point location = new Point(retVal.labelUnitSelection.Bounds.Left, retVal.buttonRemoveSelection.Bounds.Top); Point size = new Point(retVal.buttonRemoveSelection.Bounds.Right - location.X, retVal.buttonRemoveSelection.Bounds.Bottom - location.Y + 5); retVal.Bounds = new Rectangle(location, size); // Return the newly generated object return(retVal); }
/// <summary> /// Creates a new element with a label and a button, allowing a player to build a building using a builder. /// </summary> /// <param name="startPos">The starting position of this element on the screen.</param> /// <param name="buildingString">The string in the label.</param> /// <param name="clickHandler">The click handler for the button.</param> /// <returns>The element with the label and the button.</returns> public static ElementBuildButton CreateBuildButton(Point startPos, string buildingString, GuiButton.OnClickHandler clickHandler, string buttonText = "Build") { // Create the new element using the starting position, and add the click handler Rectangle rect = new Rectangle(startPos, new Point(0)); ElementBuildButton retVal = new ElementBuildButton(startPos, buildingString, buttonText); retVal.buttonBuildBuilding.ClickHandler = clickHandler; // Calculate the location and size of this object Point location = new Point(retVal.labelBuildingNameAndCost.Bounds.Left, retVal.buttonBuildBuilding.Bounds.Top); Point size = new Point(retVal.buttonBuildBuilding.Bounds.Right - location.X, retVal.buttonBuildBuilding.Bounds.Bottom - location.Y + 5); retVal.Bounds = new Rectangle(location, size); // Return the newly generated object return(retVal); }