Skip to content

Commit

Permalink
Feature: Button to expand all towns in the scenario editor
Browse files Browse the repository at this point in the history
  • Loading branch information
perezdidac committed Dec 24, 2022
1 parent 04ee86d commit 856f9b0
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/lang/english.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2851,6 +2851,8 @@ STR_FOUND_TOWN_RANDOM_TOWN_BUTTON :{BLACK}Random T
STR_FOUND_TOWN_RANDOM_TOWN_TOOLTIP :{BLACK}Found town in random location
STR_FOUND_TOWN_MANY_RANDOM_TOWNS :{BLACK}Many random towns
STR_FOUND_TOWN_RANDOM_TOWNS_TOOLTIP :{BLACK}Cover the map with randomly placed towns
STR_FOUND_TOWN_EXPAND_ALL_TOWNS :{BLACK}Expand all towns
STR_FOUND_TOWN_EXPAND_ALL_TOWNS_TOOLTIP :{BLACK}Make all towns grow slightly

STR_FOUND_TOWN_NAME_TITLE :{YELLOW}Town name:
STR_FOUND_TOWN_NAME_EDITOR_TITLE :{BLACK}Enter town name
Expand Down
1 change: 1 addition & 0 deletions src/town.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ HouseZonesBits GetTownRadiusGroup(const Town *t, TileIndex tile);
void SetTownRatingTestMode(bool mode);
TownActions GetMaskOfTownActions(CompanyID cid, const Town *t);
bool GenerateTowns(TownLayout layout);
void ExpandTowns();
const CargoSpec *FindFirstCargoWithTownEffect(TownEffect effect);

extern const byte _town_action_costs[TACT_COUNT];
Expand Down
8 changes: 8 additions & 0 deletions src/town_cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2272,6 +2272,14 @@ bool GenerateTowns(TownLayout layout)
return false; // we are still without a town? we failed, simply
}

void ExpandTowns()
{
for (Town *t : Town::Iterate()) {
Command<CMD_EXPAND_TOWN>::Do(DC_EXEC, t->index, 0);
}

UpdateAirportsNoise();
}

/**
* Returns the bit corresponding to the town zone of the specified tile
Expand Down
10 changes: 8 additions & 2 deletions src/town_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,9 @@ static const NWidgetPart _nested_found_town_widgets[] = {
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_TF_RANDOM_TOWN), SetMinimalSize(156, 12), SetFill(1, 0),
SetDataTip(STR_FOUND_TOWN_RANDOM_TOWN_BUTTON, STR_FOUND_TOWN_RANDOM_TOWN_TOOLTIP), SetPadding(0, 2, 1, 2),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_TF_MANY_RANDOM_TOWNS), SetMinimalSize(156, 12), SetFill(1, 0),
SetDataTip(STR_FOUND_TOWN_MANY_RANDOM_TOWNS, STR_FOUND_TOWN_RANDOM_TOWNS_TOOLTIP), SetPadding(0, 2, 0, 2),
SetDataTip(STR_FOUND_TOWN_MANY_RANDOM_TOWNS, STR_FOUND_TOWN_RANDOM_TOWNS_TOOLTIP), SetPadding(0, 2, 1, 2),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_TF_EXPAND_ALL_TOWNS), SetMinimalSize(156, 12), SetFill(1, 0),
SetDataTip(STR_FOUND_TOWN_EXPAND_ALL_TOWNS, STR_FOUND_TOWN_EXPAND_ALL_TOWNS_TOOLTIP), SetPadding(0, 2, 0, 2),
/* Town name selection. */
NWidget(WWT_LABEL, COLOUR_DARK_GREEN), SetMinimalSize(156, 14), SetPadding(0, 2, 0, 2), SetDataTip(STR_FOUND_TOWN_NAME_TITLE, STR_NULL),
NWidget(WWT_EDITBOX, COLOUR_GREY, WID_TF_TOWN_NAME_EDITBOX), SetMinimalSize(156, 12), SetPadding(0, 2, 3, 2),
Expand Down Expand Up @@ -1155,7 +1157,7 @@ struct FoundTownWindow : Window {
void UpdateButtons(bool check_availability)
{
if (check_availability && _game_mode != GM_EDITOR) {
this->SetWidgetsDisabledState(true, WID_TF_RANDOM_TOWN, WID_TF_MANY_RANDOM_TOWNS, WID_TF_SIZE_LARGE, WIDGET_LIST_END);
this->SetWidgetsDisabledState(true, WID_TF_RANDOM_TOWN, WID_TF_MANY_RANDOM_TOWNS, WID_TF_EXPAND_ALL_TOWNS, WID_TF_SIZE_LARGE, WIDGET_LIST_END);
this->SetWidgetsDisabledState(_settings_game.economy.found_town != TF_CUSTOM_LAYOUT,
WID_TF_LAYOUT_ORIGINAL, WID_TF_LAYOUT_BETTER, WID_TF_LAYOUT_GRID2, WID_TF_LAYOUT_GRID3, WID_TF_LAYOUT_RANDOM, WIDGET_LIST_END);
if (_settings_game.economy.found_town != TF_CUSTOM_LAYOUT) town_layout = _settings_game.economy.town_layout;
Expand Down Expand Up @@ -1222,6 +1224,10 @@ struct FoundTownWindow : Window {
break;
}

case WID_TF_EXPAND_ALL_TOWNS:
ExpandTowns();
break;

case WID_TF_SIZE_SMALL: case WID_TF_SIZE_MEDIUM: case WID_TF_SIZE_LARGE: case WID_TF_SIZE_RANDOM:
this->town_size = (TownSize)(widget - WID_TF_SIZE_SMALL);
this->UpdateButtons(false);
Expand Down
1 change: 1 addition & 0 deletions src/widgets/town_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ enum TownFoundingWidgets {
WID_TF_NEW_TOWN, ///< Create a new town.
WID_TF_RANDOM_TOWN, ///< Randomly place a town.
WID_TF_MANY_RANDOM_TOWNS, ///< Randomly place many towns.
WID_TF_EXPAND_ALL_TOWNS, ///< Make all towns grow slightly.
WID_TF_TOWN_NAME_EDITBOX, ///< Editor for the town name.
WID_TF_TOWN_NAME_RANDOM, ///< Generate a random town name.
WID_TF_SIZE_SMALL, ///< Selection for a small town.
Expand Down

0 comments on commit 856f9b0

Please sign in to comment.