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;
 
  287   WDP_AUTO, 
"view_town_authority", 317, 222,
 
  290   _nested_town_authority_widgets, 
lengthof(_nested_town_authority_widgets)
 
  293 static void ShowTownAuthorityWindow(uint town)
 
  295   AllocateWindowDescFront<TownAuthorityWindow>(&_town_authority_desc, town);
 
  305   static const int WID_TV_HEIGHT_NORMAL = 150;
 
  348     for (
int i = TE_BEGIN; i < 
TE_END; i++) {
 
  349       if (this->
town->
goal[i] == 0) 
continue;
 
  363       assert(cargo != NULL);
 
  369         string = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_DELIVERED_GENERAL;
 
  371           string = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_REQUIRED_GENERAL;
 
  374             string = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_REQUIRED_WINTER;
 
  380         string = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_DELIVERED;
 
  382           string = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_REQUIRED;
 
  425         ShowTownAuthorityWindow(this->window_number);
 
  435         static bool _warn_town_no_roads = 
false;
 
  439           _warn_town_no_roads = 
true;
 
  470     for (
int i = TE_BEGIN; i < 
TE_END; i++) {
 
  471       if (this->
town->
goal[i] == 0) 
continue;
 
  493   void ResizeWindowAsNeeded()
 
  519     if (!gui_scope) 
return;
 
  522     this->ResizeWindowAsNeeded();
 
  527     if (str == NULL) 
return;
 
  533 static const NWidgetPart _nested_town_game_view_widgets[] = {
 
  543       NWidget(
NWID_VIEWPORT, INVALID_COLOUR, 
WID_TV_VIEWPORT), 
SetMinimalSize(254, 86), 
SetFill(1, 0), 
SetResize(1, 1), 
SetPadding(1, 1, 1, 1),
 
  546   NWidget(
WWT_PANEL, COLOUR_BROWN, 
WID_TV_INFO), 
SetMinimalSize(260, 32), 
SetResize(1, 0), 
SetFill(1, 0), 
EndContainer(),
 
  549       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),
 
  550       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),
 
  551       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),
 
  558   WDP_AUTO, 
"view_town", 260, TownViewWindow::WID_TV_HEIGHT_NORMAL,
 
  561   _nested_town_game_view_widgets, 
lengthof(_nested_town_game_view_widgets)
 
  564 static const NWidgetPart _nested_town_editor_view_widgets[] = {
 
  575       NWidget(
NWID_VIEWPORT, INVALID_COLOUR, 
WID_TV_VIEWPORT), 
SetMinimalSize(254, 86), 
SetFill(1, 1), 
SetResize(1, 1), 
SetPadding(1, 1, 1, 1),
 
  578   NWidget(
WWT_PANEL, COLOUR_BROWN, 
WID_TV_INFO), 
SetMinimalSize(260, 32), 
SetResize(1, 0), 
SetFill(1, 0), 
EndContainer(),
 
  581       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),
 
  582       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),
 
  583       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),
 
  590   WDP_AUTO, 
"view_town_scen", 260, TownViewWindow::WID_TV_HEIGHT_NORMAL,
 
  593   _nested_town_editor_view_widgets, 
lengthof(_nested_town_editor_view_widgets)
 
  596 void ShowTownViewWindow(TownID town)
 
  598   if (_game_mode == GM_EDITOR) {
 
  599     AllocateWindowDescFront<TownViewWindow>(&_town_editor_view_desc, town);
 
  601     AllocateWindowDescFront<TownViewWindow>(&_town_game_view_desc, town);
 
  605 static const NWidgetPart _nested_town_directory_widgets[] = {
 
  623         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),
 
  638   static const Town *last_town;
 
  648   void BuildSortTownList()
 
  655         *this->towns.
Append() = t;
 
  663     this->last_town = NULL;
 
  671     static char buf_cache[64];
 
  677     GetString(buf, STR_TOWN_NAME, 
lastof(buf));
 
  682     if (tb != last_town) {
 
  685       GetString(buf_cache, STR_TOWN_NAME, 
lastof(buf_cache));
 
  694     uint32 a_population = (*a)->cache.population;
 
  695     uint32 b_population = (*b)->cache.population;
 
  697     return (a_population < b_population) ? -1 : 1;
 
  703     int before = TownDirectoryWindow::last_sorting.
order ? 1 : -1; 
 
  711         return (a_rating < b_rating) ? -1 : 1;
 
  729     this->BuildSortTownList();
 
  757         if (this->towns.
Length() == 0) { 
 
  770           const Town *t = this->towns[i];
 
  777             SpriteID icon = SPR_TOWN_RATING_APALLING;
 
  801         d.height += padding.height;
 
  810         d.width += padding.width;
 
  811         d.height += padding.height;
 
  817         for (uint i = 0; i < this->towns.
Length(); i++) {
 
  818           const Town *t = this->towns[i];
 
  827         d.width += icon_size.width + 2;
 
  828         d.height = 
max(d.height, icon_size.height);
 
  829         resize->height = d.height;
 
  839         d.width += padding.width;
 
  840         d.height += padding.height;
 
  853           this->last_sorting = this->towns.
GetListing(); 
 
  856           this->last_sorting.
order = !this->last_sorting.
order;
 
  870         if (id_v >= this->towns.
Length()) 
return; 
 
  872         const Town *t = this->towns[id_v];
 
  888     if (this->towns.
SortType() != index) {
 
  890       this->last_sorting = this->towns.
GetListing(); 
 
  891       this->BuildSortTownList();
 
  897     if (this->towns.
NeedRebuild()) this->BuildSortTownList();
 
  903     this->BuildSortTownList();
 
  928 Listing TownDirectoryWindow::last_sorting = {
false, 0};
 
  929 const Town *TownDirectoryWindow::last_town = NULL;
 
  934   STR_SORT_BY_POPULATION,
 
  942   &TownPopulationSorter,
 
  950   _nested_town_directory_widgets, 
lengthof(_nested_town_directory_widgets)
 
  953 void ShowTownDirectory()
 
  961   if (result.
Failed()) 
return;
 
  972 static const NWidgetPart _nested_found_town_widgets[] = {
 
  983                     SetDataTip(STR_FOUND_TOWN_NEW_TOWN_BUTTON, STR_FOUND_TOWN_NEW_TOWN_TOOLTIP), 
SetPadding(0, 2, 1, 2),
 
  985                     SetDataTip(STR_FOUND_TOWN_RANDOM_TOWN_BUTTON, STR_FOUND_TOWN_RANDOM_TOWN_TOOLTIP), 
SetPadding(0, 2, 1, 2),
 
  987                     SetDataTip(STR_FOUND_TOWN_MANY_RANDOM_TOWNS, STR_FOUND_TOWN_RANDOM_TOWNS_TOOLTIP), 
SetPadding(0, 2, 0, 2),
 
  989     NWidget(
WWT_LABEL, COLOUR_DARK_GREEN), 
SetMinimalSize(156, 14), 
SetPadding(0, 2, 0, 2), 
SetDataTip(STR_FOUND_TOWN_NAME_TITLE, STR_NULL),
 
  991                     SetDataTip(STR_FOUND_TOWN_NAME_EDITOR_TITLE, STR_FOUND_TOWN_NAME_EDITOR_HELP),
 
  992     NWidget(
WWT_PUSHTXTBTN, COLOUR_GREY, 
WID_TF_TOWN_NAME_RANDOM), 
SetMinimalSize(78, 12), 
SetPadding(0, 2, 0, 2), 
SetFill(1, 0),
 
  993                     SetDataTip(STR_FOUND_TOWN_NAME_RANDOM_BUTTON, STR_FOUND_TOWN_NAME_RANDOM_TOOLTIP),
 
 1002                     SetDataTip(STR_FOUND_TOWN_INITIAL_SIZE_SMALL_BUTTON, STR_FOUND_TOWN_INITIAL_SIZE_TOOLTIP),
 
 1004                     SetDataTip(STR_FOUND_TOWN_INITIAL_SIZE_MEDIUM_BUTTON, STR_FOUND_TOWN_INITIAL_SIZE_TOOLTIP),
 
 1009                     SetDataTip(STR_FOUND_TOWN_INITIAL_SIZE_LARGE_BUTTON, STR_FOUND_TOWN_INITIAL_SIZE_TOOLTIP),
 
 1011                     SetDataTip(STR_FOUND_TOWN_SIZE_RANDOM, STR_FOUND_TOWN_INITIAL_SIZE_TOOLTIP),
 
 1014     NWidget(
WWT_TEXTBTN, COLOUR_GREY, 
WID_TF_CITY), 
SetPadding(0, 2, 0, 2), 
SetMinimalSize(156, 12), 
SetFill(1, 0),
 
 1032     NWidget(
WWT_TEXTBTN, COLOUR_GREY, 
WID_TF_LAYOUT_RANDOM), 
SetPadding(0, 2, 0, 2), 
SetMinimalSize(0, 12), 
SetFill(1, 0),
 
 1033                     SetDataTip(STR_FOUND_TOWN_SELECT_LAYOUT_RANDOM, STR_FOUND_TOWN_SELECT_TOWN_ROAD_LAYOUT), 
SetFill(1, 0),
 
 1059     this->RandomTownName();
 
 1060     this->UpdateButtons(
true);
 
 1063   void RandomTownName()
 
 1070       GetTownName(this->
townname_editbox.text.
buf, &this->params, this->townnameparts, &this->townname_editbox.text.buf[this->townname_editbox.text.max_bytes - 1]);
 
 1078   void UpdateButtons(
bool check_availability)
 
 1080     if (check_availability && _game_mode != GM_EDITOR) {
 
 1102     const char *name = NULL;
 
 1128         this->ExecuteFoundTownCommand(0, 
true, STR_ERROR_CAN_T_GENERATE_TOWN, CcFoundRandomTown);
 
 1132         this->RandomTownName();
 
 1148         this->UpdateButtons(
false);
 
 1160         this->UpdateButtons(
false);
 
 1167     this->ExecuteFoundTownCommand(tile, 
false, STR_ERROR_CAN_T_FOUND_TOWN_HERE, CcFoundTown);
 
 1173     this->UpdateButtons(
false);
 
 1183     if (!gui_scope) 
return;
 
 1184     this->UpdateButtons(
true);
 
 1192   _nested_found_town_widgets, 
lengthof(_nested_found_town_widgets)
 
 1195 void ShowFoundTownWindow()
 
 1198   AllocateWindowDescFront<FoundTownWindow>(&_found_town_desc, 0);