38 #include "table/strings.h"
44 static const NWidgetPart _nested_town_authority_widgets[] = {
54 NWidget(
WWT_PANEL, COLOUR_BROWN,
WID_TA_COMMAND_LIST),
SetMinimalSize(305, 52),
SetResize(1, 0),
SetDataTip(0x0, STR_LOCAL_AUTHORITY_ACTIONS_TOOLTIP),
SetScrollbar(
WID_TA_SCROLLBAR),
EndContainer(),
59 NWidget(
WWT_PUSHTXTBTN, COLOUR_BROWN,
WID_TA_EXECUTE),
SetMinimalSize(317, 12),
SetResize(1, 0),
SetFill(1, 0),
SetDataTip(STR_LOCAL_AUTHORITY_DO_IT_BUTTON, STR_LOCAL_AUTHORITY_DO_IT_TOOLTIP),
109 this->vscroll->
SetCount(numact + 1);
130 DrawString(left, right, y, STR_LOCAL_AUTHORITY_COMPANY_RATINGS);
134 int icon_width = icon_size.width;
138 int exclusive_width = exclusive_size.width;
142 uint text_left = left + (rtl ? 0 : icon_width + exclusive_width + 4);
143 uint text_right = right - (rtl ? icon_width + exclusive_width + 4 : 0);
144 uint icon_left = rtl ? right - icon_width :
left;
145 uint exclusive_left = rtl ? right - icon_width - exclusive_width - 2 : left + icon_width + 2;
149 FOR_ALL_COMPANIES(c) {
158 (str = STR_CARGO_RATING_APPALLING, r <= RATING_APPALLING) ||
159 (str++, r <= RATING_VERYPOOR) ||
160 (str++, r <= RATING_POOR) ||
161 (str++, r <= RATING_MEDIOCRE) ||
162 (str++, r <= RATING_GOOD) ||
163 (str++, r <= RATING_VERYGOOD) ||
164 (str++, r <= RATING_EXCELLENT) ||
169 DrawSprite(SPR_EXCLUSIVE_TRANSPORT, COMPANY_SPRITE_COLOUR(c->
index), exclusive_left, y + exclusive_y_offset);
172 DrawString(text_left, text_right, y, STR_LOCAL_AUTHORITY_COMPANY_RATING);
196 STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_SMALL_ADVERTISING + this->sel_index);
210 for (
int i = 0; buttons; i++, buttons >>= 1) {
211 if (pos <= -5)
break;
213 if ((buttons & 1) && --pos < 0) {
215 STR_LOCAL_AUTHORITY_ACTION_SMALL_ADVERTISING_CAMPAIGN + i, this->sel_index == i ? TC_WHITE : TC_ORANGE);
228 assert(size->width > padding.width && size->height > padding.height);
271 if (click_count == 1 || y < 0)
break;
288 WDP_AUTO,
"view_town_authority", 317, 222,
291 _nested_town_authority_widgets,
lengthof(_nested_town_authority_widgets)
294 static void ShowTownAuthorityWindow(uint town)
296 AllocateWindowDescFront<TownAuthorityWindow>(&_town_authority_desc, town);
306 static const int WID_TV_HEIGHT_NORMAL = 150;
349 for (
int i = TE_BEGIN; i <
TE_END; i++) {
350 if (this->
town->
goal[i] == 0)
continue;
364 assert(cargo != NULL);
370 string = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_DELIVERED_GENERAL;
372 string = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_REQUIRED_GENERAL;
375 string = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_REQUIRED_WINTER;
381 string = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_DELIVERED;
383 string = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_REQUIRED;
426 ShowTownAuthorityWindow(this->window_number);
436 static bool _warn_town_no_roads =
false;
440 _warn_town_no_roads =
true;
471 for (
int i = TE_BEGIN; i <
TE_END; i++) {
472 if (this->
town->
goal[i] == 0)
continue;
494 void ResizeWindowAsNeeded()
520 if (!gui_scope)
return;
523 this->ResizeWindowAsNeeded();
528 if (str == NULL)
return;
534 static const NWidgetPart _nested_town_game_view_widgets[] = {
544 NWidget(
NWID_VIEWPORT, INVALID_COLOUR,
WID_TV_VIEWPORT),
SetMinimalSize(254, 86),
SetFill(1, 0),
SetResize(1, 1),
SetPadding(1, 1, 1, 1),
547 NWidget(
WWT_PANEL, COLOUR_BROWN,
WID_TV_INFO),
SetMinimalSize(260, 32),
SetResize(1, 0),
SetFill(1, 0),
EndContainer(),
550 NWidget(
WWT_PUSHTXTBTN, COLOUR_BROWN,
WID_TV_CENTER_VIEW),
SetMinimalSize(80, 12),
SetFill(1, 1),
SetResize(1, 0),
SetDataTip(STR_BUTTON_LOCATION, STR_TOWN_VIEW_CENTER_TOOLTIP),
551 NWidget(
WWT_PUSHTXTBTN, COLOUR_BROWN,
WID_TV_SHOW_AUTHORITY),
SetMinimalSize(80, 12),
SetFill(1, 1),
SetResize(1, 0),
SetDataTip(STR_TOWN_VIEW_LOCAL_AUTHORITY_BUTTON, STR_TOWN_VIEW_LOCAL_AUTHORITY_TOOLTIP),
552 NWidget(
WWT_PUSHTXTBTN, COLOUR_BROWN,
WID_TV_CHANGE_NAME),
SetMinimalSize(80, 12),
SetFill(1, 1),
SetResize(1, 0),
SetDataTip(STR_BUTTON_RENAME, STR_TOWN_VIEW_RENAME_TOOLTIP),
559 WDP_AUTO,
"view_town", 260, TownViewWindow::WID_TV_HEIGHT_NORMAL,
562 _nested_town_game_view_widgets,
lengthof(_nested_town_game_view_widgets)
565 static const NWidgetPart _nested_town_editor_view_widgets[] = {
576 NWidget(
NWID_VIEWPORT, INVALID_COLOUR,
WID_TV_VIEWPORT),
SetMinimalSize(254, 86),
SetFill(1, 1),
SetResize(1, 1),
SetPadding(1, 1, 1, 1),
579 NWidget(
WWT_PANEL, COLOUR_BROWN,
WID_TV_INFO),
SetMinimalSize(260, 32),
SetResize(1, 0),
SetFill(1, 0),
EndContainer(),
582 NWidget(
WWT_PUSHTXTBTN, COLOUR_BROWN,
WID_TV_CENTER_VIEW),
SetMinimalSize(80, 12),
SetFill(1, 1),
SetResize(1, 0),
SetDataTip(STR_BUTTON_LOCATION, STR_TOWN_VIEW_CENTER_TOOLTIP),
583 NWidget(
WWT_PUSHTXTBTN, COLOUR_BROWN,
WID_TV_EXPAND),
SetMinimalSize(80, 12),
SetFill(1, 1),
SetResize(1, 0),
SetDataTip(STR_TOWN_VIEW_EXPAND_BUTTON, STR_TOWN_VIEW_EXPAND_TOOLTIP),
584 NWidget(
WWT_PUSHTXTBTN, COLOUR_BROWN,
WID_TV_DELETE),
SetMinimalSize(80, 12),
SetFill(1, 1),
SetResize(1, 0),
SetDataTip(STR_TOWN_VIEW_DELETE_BUTTON, STR_TOWN_VIEW_DELETE_TOOLTIP),
591 WDP_AUTO,
"view_town_scen", 260, TownViewWindow::WID_TV_HEIGHT_NORMAL,
594 _nested_town_editor_view_widgets,
lengthof(_nested_town_editor_view_widgets)
597 void ShowTownViewWindow(TownID town)
599 if (_game_mode == GM_EDITOR) {
600 AllocateWindowDescFront<TownViewWindow>(&_town_editor_view_desc, town);
602 AllocateWindowDescFront<TownViewWindow>(&_town_game_view_desc, town);
606 static const NWidgetPart _nested_town_directory_widgets[] = {
624 NWidget(
WWT_TEXT, COLOUR_BROWN,
WID_TD_WORLD_POPULATION),
SetPadding(2, 0, 0, 2),
SetMinimalSize(196, 12),
SetFill(1, 0),
SetDataTip(STR_TOWN_POPULATION, STR_NULL),
639 static const Town *last_town;
649 void BuildSortTownList()
656 *this->towns.
Append() = t;
664 this->last_town = NULL;
672 static char buf_cache[64];
678 GetString(buf, STR_TOWN_NAME,
lastof(buf));
683 if (tb != last_town) {
686 GetString(buf_cache, STR_TOWN_NAME,
lastof(buf_cache));
695 uint32 a_population = (*a)->cache.population;
696 uint32 b_population = (*b)->cache.population;
698 return (a_population < b_population) ? -1 : 1;
704 int before = TownDirectoryWindow::last_sorting.
order ? 1 : -1;
712 return (a_rating < b_rating) ? -1 : 1;
730 this->BuildSortTownList();
758 if (this->towns.
Length() == 0) {
771 const Town *t = this->towns[i];
778 SpriteID icon = SPR_TOWN_RATING_APALLING;
802 d.height += padding.height;
811 d.width += padding.width;
812 d.height += padding.height;
818 for (uint i = 0; i < this->towns.
Length(); i++) {
819 const Town *t = this->towns[i];
828 d.width += icon_size.width + 2;
829 d.height =
max(d.height, icon_size.height);
830 resize->height = d.height;
840 d.width += padding.width;
841 d.height += padding.height;
854 this->last_sorting = this->towns.
GetListing();
857 this->last_sorting.
order = !this->last_sorting.
order;
871 if (id_v >= this->towns.
Length())
return;
873 const Town *t = this->towns[id_v];
889 if (this->towns.
SortType() != index) {
891 this->last_sorting = this->towns.
GetListing();
892 this->BuildSortTownList();
898 if (this->towns.
NeedRebuild()) this->BuildSortTownList();
904 this->BuildSortTownList();
929 Listing TownDirectoryWindow::last_sorting = {
false, 0};
930 const Town *TownDirectoryWindow::last_town = NULL;
935 STR_SORT_BY_POPULATION,
943 &TownPopulationSorter,
951 _nested_town_directory_widgets,
lengthof(_nested_town_directory_widgets)
954 void ShowTownDirectory()
962 if (result.
Failed())
return;
973 static const NWidgetPart _nested_found_town_widgets[] = {
984 SetDataTip(STR_FOUND_TOWN_NEW_TOWN_BUTTON, STR_FOUND_TOWN_NEW_TOWN_TOOLTIP),
SetPadding(0, 2, 1, 2),
986 SetDataTip(STR_FOUND_TOWN_RANDOM_TOWN_BUTTON, STR_FOUND_TOWN_RANDOM_TOWN_TOOLTIP),
SetPadding(0, 2, 1, 2),
988 SetDataTip(STR_FOUND_TOWN_MANY_RANDOM_TOWNS, STR_FOUND_TOWN_RANDOM_TOWNS_TOOLTIP),
SetPadding(0, 2, 0, 2),
990 NWidget(
WWT_LABEL, COLOUR_DARK_GREEN),
SetMinimalSize(156, 14),
SetPadding(0, 2, 0, 2),
SetDataTip(STR_FOUND_TOWN_NAME_TITLE, STR_NULL),
992 SetDataTip(STR_FOUND_TOWN_NAME_EDITOR_TITLE, STR_FOUND_TOWN_NAME_EDITOR_HELP),
993 NWidget(
WWT_PUSHTXTBTN, COLOUR_GREY,
WID_TF_TOWN_NAME_RANDOM),
SetMinimalSize(78, 12),
SetPadding(0, 2, 0, 2),
SetFill(1, 0),
994 SetDataTip(STR_FOUND_TOWN_NAME_RANDOM_BUTTON, STR_FOUND_TOWN_NAME_RANDOM_TOOLTIP),
1003 SetDataTip(STR_FOUND_TOWN_INITIAL_SIZE_SMALL_BUTTON, STR_FOUND_TOWN_INITIAL_SIZE_TOOLTIP),
1005 SetDataTip(STR_FOUND_TOWN_INITIAL_SIZE_MEDIUM_BUTTON, STR_FOUND_TOWN_INITIAL_SIZE_TOOLTIP),
1010 SetDataTip(STR_FOUND_TOWN_INITIAL_SIZE_LARGE_BUTTON, STR_FOUND_TOWN_INITIAL_SIZE_TOOLTIP),
1012 SetDataTip(STR_FOUND_TOWN_SIZE_RANDOM, STR_FOUND_TOWN_INITIAL_SIZE_TOOLTIP),
1015 NWidget(
WWT_TEXTBTN, COLOUR_GREY,
WID_TF_CITY),
SetPadding(0, 2, 0, 2),
SetMinimalSize(156, 12),
SetFill(1, 0),
1033 NWidget(
WWT_TEXTBTN, COLOUR_GREY,
WID_TF_LAYOUT_RANDOM),
SetPadding(0, 2, 0, 2),
SetMinimalSize(0, 12),
SetFill(1, 0),
1034 SetDataTip(STR_FOUND_TOWN_SELECT_LAYOUT_RANDOM, STR_FOUND_TOWN_SELECT_TOWN_ROAD_LAYOUT),
SetFill(1, 0),
1060 this->RandomTownName();
1061 this->UpdateButtons(
true);
1064 void RandomTownName()
1071 GetTownName(this->
townname_editbox.text.
buf, &this->params, this->townnameparts, &this->townname_editbox.text.buf[this->townname_editbox.text.max_bytes - 1]);
1079 void UpdateButtons(
bool check_availability)
1081 if (check_availability && _game_mode != GM_EDITOR) {
1103 const char *name = NULL;
1129 this->ExecuteFoundTownCommand(0,
true, STR_ERROR_CAN_T_GENERATE_TOWN, CcFoundRandomTown);
1133 this->RandomTownName();
1149 this->UpdateButtons(
false);
1161 this->UpdateButtons(
false);
1168 this->ExecuteFoundTownCommand(tile,
false, STR_ERROR_CAN_T_FOUND_TOWN_HERE, CcFoundTown);
1174 this->UpdateButtons(
false);
1184 if (!gui_scope)
return;
1185 this->UpdateButtons(
true);
1193 _nested_found_town_widgets,
lengthof(_nested_found_town_widgets)
1196 void ShowFoundTownWindow()
1199 AllocateWindowDescFront<FoundTownWindow>(&_found_town_desc, 0);