private void AddBuilderButton(EconomyGrid grid, GuiList listBuilderActions, string buildingName, Type buildingType)
        {
            // Create the label for the element
            StringBuilder label = new StringBuilder();

            label.Append(Translations.GetTranslation(buildingName)).Append(" (");
            label.Append(BuildingRegistry.GetCost(buildingName)).Append("G): ");

            // Create the element using the label, and add a BuildBuilding clickhandler
            listBuilderActions.addElement(ElementBuildButton.CreateBuildButton(listBuilderActions.Bounds.Location, label.ToString(), BuildBuilding(grid, buildingName, buildingType)));

            // Also add this buildingID-Type pair to the BuildingRegistry
            BuildingRegistry.buildingTypeById[buildingName] = buildingType;
        }
Пример #2
0
        /// <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);
        }