4 * This file is part of OpenTTD.
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
10 /** @file town_gui.cpp GUI for towns. */
18 #include "map/zoneheight.h"
19 #include "map/slope.h"
20 #include "map/bridge.h"
21 #include "viewport_func.h"
24 #include "command_func.h"
25 #include "company_func.h"
26 #include "company_base.h"
27 #include "company_gui.h"
28 #include "network/network.h"
30 #include "strings_func.h"
31 #include "sound_func.h"
32 #include "tilehighlight_func.h"
33 #include "sortlist_type.h"
35 #include "landscape.h"
36 #include "querystring_gui.h"
37 #include "window_func.h"
38 #include "townname_func.h"
39 #include "core/geometry_func.hpp"
40 #include "core/random_func.hpp"
41 #include "core/smallvec_type.hpp"
43 #include "widgets/dropdown_func.h"
44 #include "economy_func.h"
45 #include "newgrf_config.h"
46 #include "newgrf_house.h"
47 #include "newgrf_cargo.h"
48 #include "date_func.h"
49 #include "zoom_func.h"
50 #include "slope_func.h"
52 #include "widgets/town_widget.h"
54 #include "table/strings.h"
56 typedef GUIList
<const Town
*> GUITownList
;
58 static const NWidgetPart _nested_town_authority_widgets
[] = {
59 NWidget(NWID_HORIZONTAL
),
60 NWidget(WWT_CLOSEBOX
, COLOUR_BROWN
),
61 NWidget(WWT_CAPTION
, COLOUR_BROWN
, WID_TA_CAPTION
), SetDataTip(STR_LOCAL_AUTHORITY_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
62 NWidget(WWT_SHADEBOX
, COLOUR_BROWN
),
63 NWidget(WWT_DEFSIZEBOX
, COLOUR_BROWN
),
64 NWidget(WWT_STICKYBOX
, COLOUR_BROWN
),
66 NWidget(WWT_PANEL
, COLOUR_BROWN
, WID_TA_RATING_INFO
), SetMinimalSize(317, 92), SetResize(1, 1), EndContainer(),
67 NWidget(NWID_HORIZONTAL
),
68 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(),
69 NWidget(NWID_VSCROLLBAR
, COLOUR_BROWN
, WID_TA_SCROLLBAR
),
71 NWidget(WWT_PANEL
, COLOUR_BROWN
, WID_TA_ACTION_INFO
), SetMinimalSize(317, 52), SetResize(1, 0), EndContainer(),
72 NWidget(NWID_HORIZONTAL
),
73 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
),
74 NWidget(WWT_RESIZEBOX
, COLOUR_BROWN
),
78 /** Town authority window. */
79 struct TownAuthorityWindow
: Window
{
81 Town
*town
; ///< Town being displayed.
82 int sel_index
; ///< Currently selected town action, \c 0 to \c TACT_COUNT-1, \c -1 means no action selected.
84 uint displayed_actions_on_previous_painting
; ///< Actions that were available on the previous call to OnPaint()
87 * Get the position of the Nth set bit.
89 * If there is no Nth bit set return -1
91 * @param bits The value to search in
92 * @param n The Nth set bit from which we want to know the position
93 * @return The position of the Nth set bit
95 static int GetNthSetBit(uint32 bits
, int n
)
99 FOR_EACH_SET_BIT(i
, bits
) {
108 TownAuthorityWindow (const WindowDesc
*desc
, WindowNumber window_number
) :
109 Window (desc
), town (NULL
), sel_index(-1), vscroll (NULL
),
110 displayed_actions_on_previous_painting (0)
112 this->town
= Town::Get(window_number
);
113 this->InitNested(window_number
);
114 this->vscroll
= this->GetScrollbar(WID_TA_SCROLLBAR
);
115 this->vscroll
->SetCapacity((this->GetWidget
<NWidgetBase
>(WID_TA_COMMAND_LIST
)->current_y
- WD_FRAMERECT_TOP
- WD_FRAMERECT_BOTTOM
) / FONT_HEIGHT_NORMAL
);
118 void OnPaint (BlitArea
*dpi
) OVERRIDE
121 uint buttons
= GetMaskOfTownActions(&numact
, _local_company
, this->town
);
122 if (buttons
!= displayed_actions_on_previous_painting
) this->SetDirty();
123 displayed_actions_on_previous_painting
= buttons
;
125 this->vscroll
->SetCount(numact
+ 1);
127 if (this->sel_index
!= -1 && !HasBit(buttons
, this->sel_index
)) {
128 this->sel_index
= -1;
131 this->SetWidgetDisabledState(WID_TA_EXECUTE
, this->sel_index
== -1);
133 this->DrawWidgets (dpi
);
134 if (!this->IsShaded()) this->DrawRatings (dpi
);
137 /** Draw the contents of the ratings panel. May request a resize of the window if the contents does not fit. */
138 void DrawRatings (BlitArea
*dpi
)
140 NWidgetBase
*nwid
= this->GetWidget
<NWidgetBase
>(WID_TA_RATING_INFO
);
141 uint left
= nwid
->pos_x
+ WD_FRAMERECT_LEFT
;
142 uint right
= nwid
->pos_x
+ nwid
->current_x
- 1 - WD_FRAMERECT_RIGHT
;
144 uint y
= nwid
->pos_y
+ WD_FRAMERECT_TOP
;
146 DrawString (dpi
, left
, right
, y
, STR_LOCAL_AUTHORITY_COMPANY_RATINGS
);
147 y
+= FONT_HEIGHT_NORMAL
;
149 Dimension icon_size
= GetSpriteSize(SPR_COMPANY_ICON
);
150 int icon_width
= icon_size
.width
;
151 int icon_y_offset
= (FONT_HEIGHT_NORMAL
- icon_size
.height
) / 2;
153 Dimension exclusive_size
= GetSpriteSize(SPR_EXCLUSIVE_TRANSPORT
);
154 int exclusive_width
= exclusive_size
.width
;
155 int exclusive_y_offset
= (FONT_HEIGHT_NORMAL
- exclusive_size
.height
) / 2;
157 bool rtl
= _current_text_dir
== TD_RTL
;
158 uint text_left
= left
+ (rtl
? 0 : icon_width
+ exclusive_width
+ 4);
159 uint text_right
= right
- (rtl
? icon_width
+ exclusive_width
+ 4 : 0);
160 uint icon_left
= rtl
? right
- icon_width
: left
;
161 uint exclusive_left
= rtl
? right
- icon_width
- exclusive_width
- 2 : left
+ icon_width
+ 2;
163 /* Draw list of companies */
165 FOR_ALL_COMPANIES(c
) {
166 if ((HasBit(this->town
->have_ratings
, c
->index
) || this->town
->exclusivity
== c
->index
)) {
167 DrawCompanyIcon (dpi
, c
->index
, icon_left
, y
+ icon_y_offset
);
169 SetDParam(0, c
->index
);
170 SetDParam(1, c
->index
);
172 int r
= this->town
->ratings
[c
->index
];
174 (str
= STR_CARGO_RATING_APPALLING
, r
<= RATING_APPALLING
) || // Apalling
175 (str
++, r
<= RATING_VERYPOOR
) || // Very Poor
176 (str
++, r
<= RATING_POOR
) || // Poor
177 (str
++, r
<= RATING_MEDIOCRE
) || // Mediocore
178 (str
++, r
<= RATING_GOOD
) || // Good
179 (str
++, r
<= RATING_VERYGOOD
) || // Very Good
180 (str
++, r
<= RATING_EXCELLENT
) || // Excellent
181 (str
++, true); // Outstanding
184 if (this->town
->exclusivity
== c
->index
) {
185 DrawSprite (dpi
, SPR_EXCLUSIVE_TRANSPORT
, COMPANY_SPRITE_COLOUR(c
->index
), exclusive_left
, y
+ exclusive_y_offset
);
188 DrawString (dpi
, text_left
, text_right
, y
, STR_LOCAL_AUTHORITY_COMPANY_RATING
);
189 y
+= FONT_HEIGHT_NORMAL
;
193 y
= y
+ WD_FRAMERECT_BOTTOM
- nwid
->pos_y
; // Compute needed size of the widget.
194 if (y
> nwid
->current_y
) {
195 /* If the company list is too big to fit, mark ourself dirty and draw again. */
196 ResizeWindow(this, 0, y
- nwid
->current_y
, false);
200 virtual void SetStringParameters(int widget
) const
202 if (widget
== WID_TA_CAPTION
) SetDParam(0, this->window_number
);
205 void DrawWidget (BlitArea
*dpi
, const Rect
&r
, int widget
) const OVERRIDE
208 case WID_TA_ACTION_INFO
:
209 if (this->sel_index
!= -1) {
210 SetDParam(0, _price
[PR_TOWN_ACTION
] * _town_action_costs
[this->sel_index
] >> 8);
211 DrawStringMultiLine (dpi
, r
.left
+ WD_FRAMERECT_LEFT
, r
.right
- WD_FRAMERECT_RIGHT
, r
.top
+ WD_FRAMERECT_TOP
, r
.bottom
- WD_FRAMERECT_BOTTOM
,
212 STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_SMALL_ADVERTISING
+ this->sel_index
);
215 case WID_TA_COMMAND_LIST
: {
217 uint buttons
= GetMaskOfTownActions(&numact
, _local_company
, this->town
);
218 int y
= r
.top
+ WD_FRAMERECT_TOP
;
219 int pos
= this->vscroll
->GetPosition();
222 DrawString (dpi
, r
.left
+ WD_FRAMERECT_LEFT
, r
.right
- WD_FRAMERECT_RIGHT
, y
, STR_LOCAL_AUTHORITY_ACTIONS_TITLE
);
223 y
+= FONT_HEIGHT_NORMAL
;
226 for (int i
= 0; buttons
; i
++, buttons
>>= 1) {
227 if (pos
<= -5) break; ///< Draw only the 5 fitting lines
229 if ((buttons
& 1) && --pos
< 0) {
230 DrawString (dpi
, r
.left
+ WD_FRAMERECT_LEFT
, r
.right
- WD_FRAMERECT_RIGHT
, y
,
231 STR_LOCAL_AUTHORITY_ACTION_SMALL_ADVERTISING_CAMPAIGN
+ i
, this->sel_index
== i
? TC_WHITE
: TC_ORANGE
);
232 y
+= FONT_HEIGHT_NORMAL
;
240 virtual void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
)
243 case WID_TA_ACTION_INFO
: {
244 assert(size
->width
> padding
.width
&& size
->height
> padding
.height
);
245 const uint width
= size
->width
- (WD_FRAMERECT_LEFT
+ WD_FRAMERECT_RIGHT
);
247 for (int i
= 0; i
< TACT_COUNT
; i
++) {
248 SetDParam(0, _price
[PR_TOWN_ACTION
] * _town_action_costs
[i
] >> 8);
249 uint h
= GetStringHeight (STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_SMALL_ADVERTISING
+ i
, width
);
250 hmax
= max (hmax
, h
);
252 size
->height
= max (size
->height
, hmax
+ WD_FRAMERECT_TOP
+ WD_FRAMERECT_BOTTOM
);
256 case WID_TA_COMMAND_LIST
:
257 size
->height
= WD_FRAMERECT_TOP
+ 5 * FONT_HEIGHT_NORMAL
+ WD_FRAMERECT_BOTTOM
;
258 size
->width
= GetStringBoundingBox(STR_LOCAL_AUTHORITY_ACTIONS_TITLE
).width
;
259 for (uint i
= 0; i
< TACT_COUNT
; i
++ ) {
260 size
->width
= max(size
->width
, GetStringBoundingBox(STR_LOCAL_AUTHORITY_ACTION_SMALL_ADVERTISING_CAMPAIGN
+ i
).width
);
262 size
->width
+= WD_FRAMERECT_LEFT
+ WD_FRAMERECT_RIGHT
;
265 case WID_TA_RATING_INFO
:
266 resize
->height
= FONT_HEIGHT_NORMAL
;
267 size
->height
= WD_FRAMERECT_TOP
+ 9 * FONT_HEIGHT_NORMAL
+ WD_FRAMERECT_BOTTOM
;
272 virtual void OnClick(Point pt
, int widget
, int click_count
)
275 case WID_TA_COMMAND_LIST
: {
276 int y
= this->GetRowFromWidget(pt
.y
, WID_TA_COMMAND_LIST
, 1, FONT_HEIGHT_NORMAL
);
277 if (!IsInsideMM(y
, 0, 5)) return;
279 y
= GetNthSetBit(GetMaskOfTownActions(NULL
, _local_company
, this->town
), y
+ this->vscroll
->GetPosition() - 1);
284 /* When double-clicking, continue */
285 if (click_count
== 1 || y
< 0) break;
290 DoCommandP(this->town
->xy
, this->window_number
, this->sel_index
, CMD_DO_TOWN_ACTION
);
295 virtual void OnHundredthTick()
301 static WindowDesc::Prefs
_town_authority_prefs ("view_town_authority");
303 static const WindowDesc
_town_authority_desc(
305 WC_TOWN_AUTHORITY
, WC_NONE
,
307 _nested_town_authority_widgets
, lengthof(_nested_town_authority_widgets
),
308 &_town_authority_prefs
311 static void ShowTownAuthorityWindow(uint town
)
313 AllocateWindowDescFront
<TownAuthorityWindow
>(&_town_authority_desc
, town
);
317 /* Town view window. */
318 struct TownViewWindow
: Window
{
320 Town
*town
; ///< Town displayed by the window.
323 static const int WID_TV_HEIGHT_NORMAL
= 162;
325 TownViewWindow (const WindowDesc
*desc
, WindowNumber window_number
) :
326 Window (desc
), town (NULL
)
328 this->CreateNestedTree();
330 this->town
= Town::Get(window_number
);
331 if (this->town
->larger_town
) this->GetWidget
<NWidgetCore
>(WID_TV_CAPTION
)->widget_data
= STR_TOWN_VIEW_CITY_CAPTION
;
333 this->InitNested(window_number
);
335 this->flags
|= WF_DISABLE_VP_SCROLL
;
336 NWidgetViewport
*nvp
= this->GetWidget
<NWidgetViewport
>(WID_TV_VIEWPORT
);
337 nvp
->InitializeViewport(this, this->town
->xy
, ZOOM_LVL_NEWS
);
339 /* disable renaming town in network games if you are not the server */
340 this->SetWidgetDisabledState(WID_TV_CHANGE_NAME
, _networking
&& !_network_server
);
343 void OnPaint (BlitArea
*dpi
) OVERRIDE
345 if (_game_mode
!= GM_EDITOR
) {
346 this->SetWidgetLoweredState (WID_TV_SHOW_AREA
, _thd
.town
== this->town
->index
);
349 this->DrawWidgets (dpi
);
352 virtual void SetStringParameters(int widget
) const
354 if (widget
== WID_TV_CAPTION
) SetDParam(0, this->town
->index
);
357 void DrawWidget (BlitArea
*dpi
, const Rect
&r
, int widget
) const OVERRIDE
359 if (widget
!= WID_TV_INFO
) return;
361 uint y
= r
.top
+ WD_FRAMERECT_TOP
;
363 SetDParam(0, this->town
->cache
.population
);
364 SetDParam(1, this->town
->cache
.num_houses
);
365 DrawString (dpi
, r
.left
+ WD_FRAMERECT_LEFT
, r
.right
- WD_FRAMERECT_LEFT
, y
, STR_TOWN_VIEW_POPULATION_HOUSES
);
367 SetDParam(0, this->town
->supplied
[CT_PASSENGERS
].old_act
);
368 SetDParam(1, this->town
->supplied
[CT_PASSENGERS
].old_max
);
369 DrawString (dpi
, r
.left
+ WD_FRAMERECT_LEFT
, r
.right
- WD_FRAMERECT_LEFT
, y
+= FONT_HEIGHT_NORMAL
, STR_TOWN_VIEW_PASSENGERS_LAST_MONTH_MAX
);
371 SetDParam(0, this->town
->supplied
[CT_MAIL
].old_act
);
372 SetDParam(1, this->town
->supplied
[CT_MAIL
].old_max
);
373 DrawString (dpi
, r
.left
+ WD_FRAMERECT_LEFT
, r
.right
- WD_FRAMERECT_LEFT
, y
+= FONT_HEIGHT_NORMAL
, STR_TOWN_VIEW_MAIL_LAST_MONTH_MAX
);
376 for (int i
= TE_BEGIN
; i
< TE_END
; i
++) {
377 if (this->town
->goal
[i
] == 0) continue;
378 if (this->town
->goal
[i
] == TOWN_GROWTH_WINTER
&& (TileHeight(this->town
->xy
) < LowestSnowLine() || this->town
->cache
.population
<= 90)) continue;
379 if (this->town
->goal
[i
] == TOWN_GROWTH_DESERT
&& (GetTropicZone(this->town
->xy
) != TROPICZONE_DESERT
|| this->town
->cache
.population
<= 60)) continue;
382 DrawString (dpi
, r
.left
+ WD_FRAMERECT_LEFT
, r
.right
- WD_FRAMERECT_LEFT
, y
+= FONT_HEIGHT_NORMAL
, STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH
);
386 bool rtl
= _current_text_dir
== TD_RTL
;
387 uint cargo_text_left
= r
.left
+ WD_FRAMERECT_LEFT
+ (rtl
? 0 : 20);
388 uint cargo_text_right
= r
.right
- WD_FRAMERECT_RIGHT
- (rtl
? 20 : 0);
390 const CargoSpec
*cargo
= FindFirstCargoWithTownEffect((TownEffect
)i
);
391 assert(cargo
!= NULL
);
395 if (this->town
->goal
[i
] == TOWN_GROWTH_DESERT
|| this->town
->goal
[i
] == TOWN_GROWTH_WINTER
) {
396 /* For 'original' gameplay, don't show the amount required (you need 1 or more ..) */
397 string
= STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_DELIVERED_GENERAL
;
398 if (this->town
->received
[i
].old_act
== 0) {
399 string
= STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_REQUIRED_GENERAL
;
401 if (this->town
->goal
[i
] == TOWN_GROWTH_WINTER
&& TileHeight(this->town
->xy
) < GetSnowLine()) {
402 string
= STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_REQUIRED_WINTER
;
406 SetDParam(0, cargo
->name
);
408 string
= STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_DELIVERED
;
409 if (this->town
->received
[i
].old_act
< this->town
->goal
[i
]) {
410 string
= STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_REQUIRED
;
413 SetDParam(0, cargo
->Index());
414 SetDParam(1, this->town
->received
[i
].old_act
);
415 SetDParam(2, cargo
->Index());
416 SetDParam(3, this->town
->goal
[i
]);
418 DrawString (dpi
, cargo_text_left
, cargo_text_right
, y
+= FONT_HEIGHT_NORMAL
, string
);
421 if (HasBit(this->town
->flags
, TOWN_IS_GROWING
)) {
422 SetDParam(0, ((this->town
->growth_rate
& (~TOWN_GROW_RATE_CUSTOM
)) * TOWN_GROWTH_TICKS
+ DAY_TICKS
) / DAY_TICKS
);
423 DrawString (dpi
, r
.left
+ WD_FRAMERECT_LEFT
, r
.right
- WD_FRAMERECT_LEFT
, y
+= FONT_HEIGHT_NORMAL
, this->town
->fund_buildings_months
== 0 ? STR_TOWN_VIEW_TOWN_GROWS_EVERY
: STR_TOWN_VIEW_TOWN_GROWS_EVERY_FUNDED
);
425 DrawString (dpi
, r
.left
+ WD_FRAMERECT_LEFT
, r
.right
- WD_FRAMERECT_LEFT
, y
+= FONT_HEIGHT_NORMAL
, STR_TOWN_VIEW_TOWN_GROW_STOPPED
);
428 /* only show the town noise, if the noise option is activated. */
429 if (_settings_game
.economy
.station_noise_level
) {
430 SetDParam(0, this->town
->noise_reached
);
431 SetDParam(1, this->town
->MaxTownNoise());
432 DrawString (dpi
, r
.left
+ WD_FRAMERECT_LEFT
, r
.right
- WD_FRAMERECT_LEFT
, y
+= FONT_HEIGHT_NORMAL
, STR_TOWN_VIEW_NOISE_IN_TOWN
);
435 if (this->town
->text
!= NULL
) {
436 SetDParamStr(0, this->town
->text
);
437 DrawStringMultiLine (dpi
, r
.left
+ WD_FRAMERECT_LEFT
, r
.right
- WD_FRAMERECT_RIGHT
, y
+= FONT_HEIGHT_NORMAL
, UINT16_MAX
, STR_JUST_RAW_STRING
, TC_BLACK
);
441 virtual void OnClick(Point pt
, int widget
, int click_count
)
444 case WID_TV_CENTER_VIEW
: // scroll to location
446 ShowExtraViewPortWindow(this->town
->xy
);
448 ScrollMainWindowToTile(this->town
->xy
);
452 case WID_TV_SHOW_AUTHORITY
: // town authority
453 ShowTownAuthorityWindow(this->window_number
);
456 case WID_TV_CHANGE_NAME
: // rename
457 SetDParam(0, this->window_number
);
458 ShowQueryString(STR_TOWN_NAME
, STR_TOWN_VIEW_RENAME_TOWN_BUTTON
, MAX_LENGTH_TOWN_NAME_CHARS
, this, CS_ALPHANUMERAL
, QSF_ENABLE_DEFAULT
| QSF_LEN_IN_CHARS
);
461 case WID_TV_EXPAND
: { // expand town - only available on Scenario editor
462 /* Warn the user if towns are not allowed to build roads, but do this only once per OpenTTD run. */
463 static bool _warn_town_no_roads
= false;
465 if (!_settings_game
.economy
.allow_town_roads
&& !_warn_town_no_roads
) {
466 ShowErrorMessage(STR_ERROR_TOWN_EXPAND_WARN_NO_ROADS
, INVALID_STRING_ID
, WL_WARNING
);
467 _warn_town_no_roads
= true;
470 DoCommandP(0, this->window_number
, 0, CMD_EXPAND_TOWN
);
474 case WID_TV_DELETE
: // delete town - only available on Scenario editor
475 DoCommandP(0, this->window_number
, 0, CMD_DELETE_TOWN
);
478 case WID_TV_SHOW_AREA
: // show town area
479 if (_thd
.town
== this->town
->index
) {
480 _thd
.town
= INVALID_TOWN
;
482 if (_thd
.town
!= INVALID_TOWN
) {
483 SetWindowWidgetDirty (WC_TOWN_VIEW
, _thd
.town
, WID_TV_SHOW_AREA
);
484 MarkTownAreaDirty (_thd
.town
);
486 _thd
.town
= this->town
->index
;
488 SetWidgetDirty (WID_TV_SHOW_AREA
);
489 MarkTownAreaDirty (this->town
->index
);
494 virtual void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
)
498 size
->height
= GetDesiredInfoHeight(size
->width
);
504 * Gets the desired height for the information panel.
505 * @return the desired height in pixels.
507 uint
GetDesiredInfoHeight(int width
) const
509 uint aimed_height
= 3 * FONT_HEIGHT_NORMAL
+ WD_FRAMERECT_TOP
+ WD_FRAMERECT_BOTTOM
;
512 for (int i
= TE_BEGIN
; i
< TE_END
; i
++) {
513 if (this->town
->goal
[i
] == 0) continue;
514 if (this->town
->goal
[i
] == TOWN_GROWTH_WINTER
&& (TileHeight(this->town
->xy
) < LowestSnowLine() || this->town
->cache
.population
<= 90)) continue;
515 if (this->town
->goal
[i
] == TOWN_GROWTH_DESERT
&& (GetTropicZone(this->town
->xy
) != TROPICZONE_DESERT
|| this->town
->cache
.population
<= 60)) continue;
518 aimed_height
+= FONT_HEIGHT_NORMAL
;
521 aimed_height
+= FONT_HEIGHT_NORMAL
;
523 aimed_height
+= FONT_HEIGHT_NORMAL
;
525 if (_settings_game
.economy
.station_noise_level
) aimed_height
+= FONT_HEIGHT_NORMAL
;
527 if (this->town
->text
!= NULL
) {
528 SetDParamStr(0, this->town
->text
);
529 aimed_height
+= GetStringHeight(STR_JUST_RAW_STRING
, width
- WD_FRAMERECT_LEFT
- WD_FRAMERECT_RIGHT
);
535 void ResizeWindowAsNeeded()
537 const NWidgetBase
*nwid_info
= this->GetWidget
<NWidgetBase
>(WID_TV_INFO
);
538 uint aimed_height
= GetDesiredInfoHeight(nwid_info
->current_x
);
539 if (aimed_height
> nwid_info
->current_y
|| (aimed_height
< nwid_info
->current_y
&& nwid_info
->current_y
> nwid_info
->smallest_y
)) {
544 virtual void OnResize()
546 if (this->viewport
!= NULL
) {
547 NWidgetViewport
*nvp
= this->GetWidget
<NWidgetViewport
>(WID_TV_VIEWPORT
);
548 nvp
->UpdateViewportCoordinates(this);
550 ScrollWindowToTile(this->town
->xy
, this, true); // Re-center viewport.
555 * Some data on this window has become invalid.
556 * @param data Information about the changed data.
557 * @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
559 virtual void OnInvalidateData(int data
= 0, bool gui_scope
= true)
561 if (!gui_scope
) return;
562 /* Called when setting station noise or required cargoes have changed, in order to resize the window */
563 this->SetDirty(); // refresh display for current size. This will allow to avoid glitches when downgrading
564 this->ResizeWindowAsNeeded();
567 virtual void OnQueryTextFinished(char *str
)
569 if (str
== NULL
) return;
571 DoCommandP(0, this->window_number
, 0, CMD_RENAME_TOWN
, str
);
575 static const NWidgetPart _nested_town_game_view_widgets
[] = {
576 NWidget(NWID_HORIZONTAL
),
577 NWidget(WWT_CLOSEBOX
, COLOUR_BROWN
),
578 NWidget(WWT_CAPTION
, COLOUR_BROWN
, WID_TV_CAPTION
), SetDataTip(STR_TOWN_VIEW_TOWN_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
579 NWidget(WWT_SHADEBOX
, COLOUR_BROWN
),
580 NWidget(WWT_DEFSIZEBOX
, COLOUR_BROWN
),
581 NWidget(WWT_STICKYBOX
, COLOUR_BROWN
),
583 NWidget(WWT_PANEL
, COLOUR_BROWN
),
584 NWidget(WWT_INSET
, COLOUR_BROWN
), SetPadding(2, 2, 2, 2),
585 NWidget(NWID_VIEWPORT
, INVALID_COLOUR
, WID_TV_VIEWPORT
), SetMinimalSize(254, 86), SetFill(1, 0), SetResize(1, 1), SetPadding(1, 1, 1, 1),
588 NWidget(WWT_PANEL
, COLOUR_BROWN
, WID_TV_INFO
), SetMinimalSize(260, 32), SetResize(1, 0), SetFill(1, 0), EndContainer(),
589 NWidget(NWID_HORIZONTAL
),
590 NWidget(NWID_VERTICAL
, NC_EQUALSIZE
),
591 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
592 NWidget(WWT_PUSHTXTBTN
, COLOUR_BROWN
, WID_TV_SHOW_AUTHORITY
), SetMinimalSize(130, 12), SetFill(1, 1), SetResize(1, 0), SetDataTip(STR_TOWN_VIEW_LOCAL_AUTHORITY_BUTTON
, STR_TOWN_VIEW_LOCAL_AUTHORITY_TOOLTIP
),
593 NWidget(WWT_PUSHTXTBTN
, COLOUR_BROWN
, WID_TV_SHOW_AREA
), SetMinimalSize(130, 12), SetFill(1, 1), SetResize(1, 0), SetDataTip(STR_SHOW_TOWN_AREA
, STR_SHOW_TOWN_AREA_TOOLTIP
),
595 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
596 NWidget(WWT_PUSHTXTBTN
, COLOUR_BROWN
, WID_TV_CENTER_VIEW
), SetMinimalSize(130, 12), SetFill(1, 1), SetResize(1, 0), SetDataTip(STR_BUTTON_LOCATION
, STR_TOWN_VIEW_CENTER_TOOLTIP
),
597 NWidget(WWT_PUSHTXTBTN
, COLOUR_BROWN
, WID_TV_CHANGE_NAME
), SetMinimalSize(130, 12), SetFill(1, 1), SetResize(1, 0), SetDataTip(STR_BUTTON_RENAME
, STR_TOWN_VIEW_RENAME_TOOLTIP
),
600 NWidget(WWT_RESIZEBOX
, COLOUR_BROWN
),
604 static WindowDesc::Prefs
_town_game_view_prefs ("view_town");
606 static const WindowDesc
_town_game_view_desc(
607 WDP_AUTO
, 260, TownViewWindow::WID_TV_HEIGHT_NORMAL
,
608 WC_TOWN_VIEW
, WC_NONE
,
610 _nested_town_game_view_widgets
, lengthof(_nested_town_game_view_widgets
),
611 &_town_game_view_prefs
614 static const NWidgetPart _nested_town_editor_view_widgets
[] = {
615 NWidget(NWID_HORIZONTAL
),
616 NWidget(WWT_CLOSEBOX
, COLOUR_BROWN
),
617 NWidget(WWT_CAPTION
, COLOUR_BROWN
, WID_TV_CAPTION
), SetDataTip(STR_TOWN_VIEW_TOWN_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
618 NWidget(WWT_SHADEBOX
, COLOUR_BROWN
),
619 NWidget(WWT_DEFSIZEBOX
, COLOUR_BROWN
),
620 NWidget(WWT_STICKYBOX
, COLOUR_BROWN
),
622 NWidget(WWT_PANEL
, COLOUR_BROWN
),
623 NWidget(WWT_INSET
, COLOUR_BROWN
), SetPadding(2, 2, 2, 2),
624 NWidget(NWID_VIEWPORT
, INVALID_COLOUR
, WID_TV_VIEWPORT
), SetMinimalSize(254, 86), SetFill(1, 1), SetResize(1, 1), SetPadding(1, 1, 1, 1),
627 NWidget(WWT_PANEL
, COLOUR_BROWN
, WID_TV_INFO
), SetMinimalSize(260, 32), SetResize(1, 0), SetFill(1, 0), EndContainer(),
628 NWidget(NWID_HORIZONTAL
),
629 NWidget(NWID_VERTICAL
, NC_EQUALSIZE
),
630 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
631 NWidget(WWT_PUSHTXTBTN
, COLOUR_BROWN
, WID_TV_EXPAND
), SetMinimalSize(130, 12), SetFill(1, 1), SetResize(1, 0), SetDataTip(STR_TOWN_VIEW_EXPAND_BUTTON
, STR_TOWN_VIEW_EXPAND_TOOLTIP
),
632 NWidget(WWT_PUSHTXTBTN
, COLOUR_BROWN
, WID_TV_DELETE
), SetMinimalSize(130, 12), SetFill(1, 1), SetResize(1, 0), SetDataTip(STR_TOWN_VIEW_DELETE_BUTTON
, STR_TOWN_VIEW_DELETE_TOOLTIP
),
634 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
635 NWidget(WWT_PUSHTXTBTN
, COLOUR_BROWN
, WID_TV_CENTER_VIEW
), SetMinimalSize(130, 12), SetFill(1, 1), SetResize(1, 0), SetDataTip(STR_BUTTON_LOCATION
, STR_TOWN_VIEW_CENTER_TOOLTIP
),
636 NWidget(WWT_PUSHTXTBTN
, COLOUR_BROWN
, WID_TV_CHANGE_NAME
), SetMinimalSize(130, 12), SetFill(1, 1), SetResize(1, 0), SetDataTip(STR_BUTTON_RENAME
, STR_TOWN_VIEW_RENAME_TOOLTIP
),
639 NWidget(WWT_RESIZEBOX
, COLOUR_BROWN
),
643 static WindowDesc::Prefs
_town_editor_view_prefs ("view_town_scen");
645 static const WindowDesc
_town_editor_view_desc(
646 WDP_AUTO
, 260, TownViewWindow::WID_TV_HEIGHT_NORMAL
,
647 WC_TOWN_VIEW
, WC_NONE
,
649 _nested_town_editor_view_widgets
, lengthof(_nested_town_editor_view_widgets
),
650 &_town_editor_view_prefs
653 void ShowTownViewWindow(TownID town
)
655 if (_game_mode
== GM_EDITOR
) {
656 AllocateWindowDescFront
<TownViewWindow
>(&_town_editor_view_desc
, town
);
658 AllocateWindowDescFront
<TownViewWindow
>(&_town_game_view_desc
, town
);
662 static const NWidgetPart _nested_town_directory_widgets
[] = {
663 NWidget(NWID_HORIZONTAL
),
664 NWidget(WWT_CLOSEBOX
, COLOUR_BROWN
),
665 NWidget(WWT_CAPTION
, COLOUR_BROWN
), SetDataTip(STR_TOWN_DIRECTORY_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
666 NWidget(WWT_SHADEBOX
, COLOUR_BROWN
),
667 NWidget(WWT_DEFSIZEBOX
, COLOUR_BROWN
),
668 NWidget(WWT_STICKYBOX
, COLOUR_BROWN
),
670 NWidget(NWID_HORIZONTAL
),
671 NWidget(NWID_VERTICAL
),
672 NWidget(NWID_HORIZONTAL
),
673 NWidget(WWT_TEXTBTN
, COLOUR_BROWN
, WID_TD_SORT_ORDER
), SetDataTip(STR_BUTTON_SORT_BY
, STR_TOOLTIP_SORT_ORDER
),
674 NWidget(WWT_DROPDOWN
, COLOUR_BROWN
, WID_TD_SORT_CRITERIA
), SetDataTip(STR_JUST_STRING
, STR_TOOLTIP_SORT_CRITERIA
),
675 NWidget(WWT_PANEL
, COLOUR_BROWN
), SetResize(1, 0), EndContainer(),
677 NWidget(WWT_PANEL
, COLOUR_BROWN
, WID_TD_LIST
), SetMinimalSize(196, 0), SetDataTip(0x0, STR_TOWN_DIRECTORY_LIST_TOOLTIP
),
678 SetFill(1, 0), SetResize(0, 10), SetScrollbar(WID_TD_SCROLLBAR
), EndContainer(),
679 NWidget(WWT_PANEL
, COLOUR_BROWN
),
680 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
),
683 NWidget(NWID_VERTICAL
),
684 NWidget(NWID_VSCROLLBAR
, COLOUR_BROWN
, WID_TD_SCROLLBAR
),
685 NWidget(WWT_RESIZEBOX
, COLOUR_BROWN
),
690 /** Town directory window class. */
691 struct TownDirectoryWindow
: public Window
{
693 /* Runtime saved values */
694 static Listing last_sorting
;
695 static const Town
*last_town
;
697 /* Constants for sorting towns */
698 static const StringID sorter_names
[];
699 static GUITownList::SortFunction
* const sorter_funcs
[];
705 void BuildSortTownList()
707 if (this->towns
.NeedRebuild()) {
712 *this->towns
.Append() = t
;
715 this->towns
.Compact();
716 this->towns
.RebuildDone();
717 this->vscroll
->SetCount(this->towns
.Length()); // Update scrollbar as well.
719 /* Always sort the towns. */
720 this->last_town
= NULL
;
722 this->SetWidgetDirty(WID_TD_LIST
); // Force repaint of the displayed towns.
725 /** Sort by town name */
726 static int CDECL
TownNameSorter(const Town
* const *a
, const Town
* const *b
)
728 static char buf_cache
[64];
733 SetDParam(0, ta
->index
);
734 GetString (buf
, STR_TOWN_NAME
);
736 /* If 'b' is the same town as in the last round, use the cached value
737 * We do this to speed stuff up ('b' is called with the same value a lot of
738 * times after each other) */
739 if (tb
!= last_town
) {
741 SetDParam(0, tb
->index
);
742 GetString (buf_cache
, STR_TOWN_NAME
);
745 return strnatcmp(buf
, buf_cache
); // Sort by name (natural sorting).
748 /** Sort by population (default descending, as big towns are of the most interest). */
749 static int CDECL
TownPopulationSorter(const Town
* const *a
, const Town
* const *b
)
751 uint32 a_population
= (*a
)->cache
.population
;
752 uint32 b_population
= (*b
)->cache
.population
;
753 if (a_population
== b_population
) return TownDirectoryWindow::TownNameSorter(a
, b
);
754 return (a_population
< b_population
) ? -1 : 1;
757 /** Sort by town rating */
758 static int CDECL
TownRatingSorter(const Town
* const *a
, const Town
* const *b
)
760 int before
= TownDirectoryWindow::last_sorting
.order
? 1 : -1; // Value to get 'a' before 'b'.
762 /* Towns without rating are always after towns with rating. */
763 if (HasBit((*a
)->have_ratings
, _local_company
)) {
764 if (HasBit((*b
)->have_ratings
, _local_company
)) {
765 int16 a_rating
= (*a
)->ratings
[_local_company
];
766 int16 b_rating
= (*b
)->ratings
[_local_company
];
767 if (a_rating
== b_rating
) return TownDirectoryWindow::TownNameSorter(a
, b
);
768 return (a_rating
< b_rating
) ? -1 : 1;
772 if (HasBit((*b
)->have_ratings
, _local_company
)) return -before
;
773 return -before
* TownDirectoryWindow::TownNameSorter(a
, b
); // Sort unrated towns always on ascending town name.
777 TownDirectoryWindow (const WindowDesc
*desc
) :
778 Window (desc
), towns(), vscroll (NULL
)
780 this->CreateNestedTree();
782 this->vscroll
= this->GetScrollbar(WID_TD_SCROLLBAR
);
784 this->towns
.SetListing(this->last_sorting
);
785 this->towns
.SetSortFuncs(TownDirectoryWindow::sorter_funcs
);
786 this->towns
.ForceRebuild();
787 this->BuildSortTownList();
792 virtual void SetStringParameters(int widget
) const
795 case WID_TD_WORLD_POPULATION
:
796 SetDParam(0, GetWorldPopulation());
799 case WID_TD_SORT_CRITERIA
:
800 SetDParam(0, TownDirectoryWindow::sorter_names
[this->towns
.SortType()]);
805 void DrawWidget (BlitArea
*dpi
, const Rect
&r
, int widget
) const OVERRIDE
808 case WID_TD_SORT_ORDER
:
809 this->DrawSortButtonState (dpi
, widget
, this->towns
.IsDescSortOrder() ? SBS_DOWN
: SBS_UP
);
814 int y
= r
.top
+ WD_FRAMERECT_TOP
;
815 if (this->towns
.Length() == 0) { // No towns available.
816 DrawString (dpi
, r
.left
+ WD_FRAMERECT_LEFT
, r
.right
, y
, STR_TOWN_DIRECTORY_NONE
);
820 /* At least one town available. */
821 bool rtl
= _current_text_dir
== TD_RTL
;
822 Dimension icon_size
= GetSpriteSize(SPR_TOWN_RATING_GOOD
);
823 int text_left
= r
.left
+ WD_FRAMERECT_LEFT
+ (rtl
? 0 : icon_size
.width
+ 2);
824 int text_right
= r
.right
- WD_FRAMERECT_RIGHT
- (rtl
? icon_size
.width
+ 2 : 0);
825 int icon_x
= rtl
? r
.right
- WD_FRAMERECT_RIGHT
- icon_size
.width
: r
.left
+ WD_FRAMERECT_LEFT
;
827 for (uint i
= this->vscroll
->GetPosition(); i
< this->towns
.Length(); i
++) {
828 const Town
*t
= this->towns
[i
];
829 assert(t
->xy
!= INVALID_TILE
);
831 /* Draw rating icon. */
832 if (_game_mode
== GM_EDITOR
|| !HasBit(t
->have_ratings
, _local_company
)) {
833 DrawSprite (dpi
, SPR_TOWN_RATING_NA
, PAL_NONE
, icon_x
, y
+ (this->resize
.step_height
- icon_size
.height
) / 2);
835 SpriteID icon
= SPR_TOWN_RATING_APALLING
;
836 if (t
->ratings
[_local_company
] > RATING_VERYPOOR
) icon
= SPR_TOWN_RATING_MEDIOCRE
;
837 if (t
->ratings
[_local_company
] > RATING_GOOD
) icon
= SPR_TOWN_RATING_GOOD
;
838 DrawSprite (dpi
, icon
, PAL_NONE
, icon_x
, y
+ (this->resize
.step_height
- icon_size
.height
) / 2);
841 SetDParam(0, t
->index
);
842 SetDParam(1, t
->cache
.population
);
843 DrawString (dpi
, text_left
, text_right
, y
+ (this->resize
.step_height
- FONT_HEIGHT_NORMAL
) / 2, STR_TOWN_DIRECTORY_TOWN
);
845 y
+= this->resize
.step_height
;
846 if (++n
== this->vscroll
->GetCapacity()) break; // max number of towns in 1 window
853 virtual void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
)
856 case WID_TD_SORT_ORDER
: {
857 Dimension d
= GetStringBoundingBox(this->GetWidget
<NWidgetCore
>(widget
)->widget_data
);
858 d
.width
+= padding
.width
+ Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better.
859 d
.height
+= padding
.height
;
860 *size
= maxdim(*size
, d
);
863 case WID_TD_SORT_CRITERIA
: {
864 Dimension d
= {0, 0};
865 for (uint i
= 0; TownDirectoryWindow::sorter_names
[i
] != INVALID_STRING_ID
; i
++) {
866 d
= maxdim(d
, GetStringBoundingBox(TownDirectoryWindow::sorter_names
[i
]));
868 d
.width
+= padding
.width
;
869 d
.height
+= padding
.height
;
870 *size
= maxdim(*size
, d
);
874 Dimension d
= GetStringBoundingBox(STR_TOWN_DIRECTORY_NONE
);
875 for (uint i
= 0; i
< this->towns
.Length(); i
++) {
876 const Town
*t
= this->towns
[i
];
880 SetDParam(0, t
->index
);
881 SetDParamMaxDigits(1, 8);
882 d
= maxdim(d
, GetStringBoundingBox(STR_TOWN_DIRECTORY_TOWN
));
884 Dimension icon_size
= GetSpriteSize(SPR_TOWN_RATING_GOOD
);
885 d
.width
+= icon_size
.width
+ 2;
886 d
.height
= max(d
.height
, icon_size
.height
);
887 resize
->height
= d
.height
;
889 d
.width
+= padding
.width
+ WD_FRAMERECT_LEFT
+ WD_FRAMERECT_RIGHT
;
890 d
.height
+= padding
.height
+ WD_FRAMERECT_TOP
+ WD_FRAMERECT_BOTTOM
;
891 *size
= maxdim(*size
, d
);
894 case WID_TD_WORLD_POPULATION
: {
895 SetDParamMaxDigits(0, 10);
896 Dimension d
= GetStringBoundingBox(STR_TOWN_POPULATION
);
897 d
.width
+= padding
.width
;
898 d
.height
+= padding
.height
;
899 *size
= maxdim(*size
, d
);
905 virtual void OnClick(Point pt
, int widget
, int click_count
)
908 case WID_TD_SORT_ORDER
: // Click on sort order button
909 if (this->towns
.SortType() != 2) { // A different sort than by rating.
910 this->towns
.ToggleSortOrder();
911 this->last_sorting
= this->towns
.GetListing(); // Store new sorting order.
913 /* Some parts are always sorted ascending on name. */
914 this->last_sorting
.order
= !this->last_sorting
.order
;
915 this->towns
.SetListing(this->last_sorting
);
916 this->towns
.ForceResort();
922 case WID_TD_SORT_CRITERIA
: // Click on sort criteria dropdown
923 ShowDropDownMenu(this, TownDirectoryWindow::sorter_names
, this->towns
.SortType(), WID_TD_SORT_CRITERIA
, 0, 0);
926 case WID_TD_LIST
: { // Click on Town Matrix
927 uint id_v
= this->vscroll
->GetScrolledRowFromWidget(pt
.y
, this, WID_TD_LIST
, WD_FRAMERECT_TOP
);
928 if (id_v
>= this->towns
.Length()) return; // click out of town bounds
930 const Town
*t
= this->towns
[id_v
];
933 ShowExtraViewPortWindow(t
->xy
);
935 ScrollMainWindowToTile(t
->xy
);
942 virtual void OnDropdownSelect(int widget
, int index
)
944 if (widget
!= WID_TD_SORT_CRITERIA
) return;
946 if (this->towns
.SortType() != index
) {
947 this->towns
.SetSortType(index
);
948 this->last_sorting
= this->towns
.GetListing(); // Store new sorting order.
949 this->BuildSortTownList();
953 void OnPaint (BlitArea
*dpi
) OVERRIDE
955 if (this->towns
.NeedRebuild()) this->BuildSortTownList();
956 this->DrawWidgets (dpi
);
959 virtual void OnHundredthTick()
961 this->BuildSortTownList();
965 virtual void OnResize()
967 this->vscroll
->SetCapacityFromWidget(this, WID_TD_LIST
);
971 * Some data on this window has become invalid.
972 * @param data Information about the changed data.
973 * @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
975 virtual void OnInvalidateData(int data
= 0, bool gui_scope
= true)
978 /* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
979 this->towns
.ForceRebuild();
981 this->towns
.ForceResort();
986 Listing
TownDirectoryWindow::last_sorting
= {false, 0};
987 const Town
*TownDirectoryWindow::last_town
= NULL
;
989 /** Names of the sorting functions. */
990 const StringID
TownDirectoryWindow::sorter_names
[] = {
992 STR_SORT_BY_POPULATION
,
997 /** Available town directory sorting functions. */
998 GUITownList::SortFunction
* const TownDirectoryWindow::sorter_funcs
[] = {
1000 &TownPopulationSorter
,
1004 static WindowDesc::Prefs
_town_directory_prefs ("list_towns");
1006 static const WindowDesc
_town_directory_desc(
1008 WC_TOWN_DIRECTORY
, WC_NONE
,
1010 _nested_town_directory_widgets
, lengthof(_nested_town_directory_widgets
),
1011 &_town_directory_prefs
1014 void ShowTownDirectory()
1016 if (BringWindowToFrontById(WC_TOWN_DIRECTORY
, 0)) return;
1017 new TownDirectoryWindow(&_town_directory_desc
);
1020 void CcFoundTown(const CommandCost
&result
, TileIndex tile
, uint32 p1
, uint32 p2
)
1022 if (result
.Failed()) return;
1024 if (HasBit(p1
, 6)) {
1025 ScrollMainWindowToTile(Town::Get(_new_town_id
)->xy
);
1027 if (_settings_client
.sound
.confirm
) SndPlayTileFx(SND_1F_SPLAT_OTHER
, tile
);
1028 if (!_settings_client
.gui
.persistent_buildingtools
) ResetPointerMode();
1032 StringID
GetErrFoundTown (TileIndex tile
, uint32 p1
, uint32 p2
, const char *text
)
1034 return HasBit(p1
, 6) ? STR_ERROR_CAN_T_GENERATE_TOWN
: STR_ERROR_CAN_T_FOUND_TOWN_HERE
;
1037 static const NWidgetPart _nested_found_town_widgets
[] = {
1038 NWidget(NWID_HORIZONTAL
),
1039 NWidget(WWT_CLOSEBOX
, COLOUR_DARK_GREEN
),
1040 NWidget(WWT_CAPTION
, COLOUR_DARK_GREEN
), SetDataTip(STR_FOUND_TOWN_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
1041 NWidget(WWT_SHADEBOX
, COLOUR_DARK_GREEN
),
1042 NWidget(WWT_STICKYBOX
, COLOUR_DARK_GREEN
),
1044 /* Construct new town(s) buttons. */
1045 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
),
1046 NWidget(NWID_SPACER
), SetMinimalSize(0, 2),
1047 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_TF_NEW_TOWN
), SetMinimalSize(156, 12), SetFill(1, 0),
1048 SetDataTip(STR_FOUND_TOWN_NEW_TOWN_BUTTON
, STR_FOUND_TOWN_NEW_TOWN_TOOLTIP
), SetPadding(0, 2, 1, 2),
1049 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_TF_RANDOM_TOWN
), SetMinimalSize(156, 12), SetFill(1, 0),
1050 SetDataTip(STR_FOUND_TOWN_RANDOM_TOWN_BUTTON
, STR_FOUND_TOWN_RANDOM_TOWN_TOOLTIP
), SetPadding(0, 2, 1, 2),
1051 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_TF_MANY_RANDOM_TOWNS
), SetMinimalSize(156, 12), SetFill(1, 0),
1052 SetDataTip(STR_FOUND_TOWN_MANY_RANDOM_TOWNS
, STR_FOUND_TOWN_RANDOM_TOWNS_TOOLTIP
), SetPadding(0, 2, 0, 2),
1053 /* Town name selection. */
1054 NWidget(WWT_LABEL
, COLOUR_DARK_GREEN
), SetMinimalSize(156, 14), SetPadding(0, 2, 0, 2), SetDataTip(STR_FOUND_TOWN_NAME_TITLE
, STR_NULL
),
1055 NWidget(WWT_EDITBOX
, COLOUR_GREY
, WID_TF_TOWN_NAME_EDITBOX
), SetMinimalSize(156, 12), SetPadding(0, 2, 3, 2),
1056 SetDataTip(STR_FOUND_TOWN_NAME_EDITOR_TITLE
, STR_FOUND_TOWN_NAME_EDITOR_HELP
),
1057 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_TF_TOWN_NAME_RANDOM
), SetMinimalSize(78, 12), SetPadding(0, 2, 0, 2), SetFill(1, 0),
1058 SetDataTip(STR_FOUND_TOWN_NAME_RANDOM_BUTTON
, STR_FOUND_TOWN_NAME_RANDOM_TOOLTIP
),
1059 /* Town size selection. */
1060 NWidget(NWID_HORIZONTAL
), SetPIP(2, 0, 2),
1061 NWidget(NWID_SPACER
), SetFill(1, 0),
1062 NWidget(WWT_LABEL
, COLOUR_DARK_GREEN
), SetMinimalSize(148, 14), SetDataTip(STR_FOUND_TOWN_INITIAL_SIZE_TITLE
, STR_NULL
),
1063 NWidget(NWID_SPACER
), SetFill(1, 0),
1065 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
), SetPIP(2, 0, 2),
1066 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_TF_SIZE_SMALL
), SetMinimalSize(78, 12), SetFill(1, 0),
1067 SetDataTip(STR_FOUND_TOWN_INITIAL_SIZE_SMALL_BUTTON
, STR_FOUND_TOWN_INITIAL_SIZE_TOOLTIP
),
1068 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_TF_SIZE_MEDIUM
), SetMinimalSize(78, 12), SetFill(1, 0),
1069 SetDataTip(STR_FOUND_TOWN_INITIAL_SIZE_MEDIUM_BUTTON
, STR_FOUND_TOWN_INITIAL_SIZE_TOOLTIP
),
1071 NWidget(NWID_SPACER
), SetMinimalSize(0, 1),
1072 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
), SetPIP(2, 0, 2),
1073 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_TF_SIZE_LARGE
), SetMinimalSize(78, 12), SetFill(1, 0),
1074 SetDataTip(STR_FOUND_TOWN_INITIAL_SIZE_LARGE_BUTTON
, STR_FOUND_TOWN_INITIAL_SIZE_TOOLTIP
),
1075 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_TF_SIZE_RANDOM
), SetMinimalSize(78, 12), SetFill(1, 0),
1076 SetDataTip(STR_FOUND_TOWN_SIZE_RANDOM
, STR_FOUND_TOWN_INITIAL_SIZE_TOOLTIP
),
1078 NWidget(NWID_SPACER
), SetMinimalSize(0, 3),
1079 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_TF_CITY
), SetPadding(0, 2, 0, 2), SetMinimalSize(156, 12), SetFill(1, 0),
1080 SetDataTip(STR_FOUND_TOWN_CITY
, STR_FOUND_TOWN_CITY_TOOLTIP
), SetFill(1, 0),
1081 /* Town roads selection. */
1082 NWidget(NWID_HORIZONTAL
), SetPIP(2, 0, 2),
1083 NWidget(NWID_SPACER
), SetFill(1, 0),
1084 NWidget(WWT_LABEL
, COLOUR_DARK_GREEN
), SetMinimalSize(148, 14), SetDataTip(STR_FOUND_TOWN_ROAD_LAYOUT
, STR_NULL
),
1085 NWidget(NWID_SPACER
), SetFill(1, 0),
1087 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
), SetPIP(2, 0, 2),
1088 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_TF_LAYOUT_ORIGINAL
), SetMinimalSize(78, 12), SetFill(1, 0), SetDataTip(STR_FOUND_TOWN_SELECT_LAYOUT_ORIGINAL
, STR_FOUND_TOWN_SELECT_TOWN_ROAD_LAYOUT
),
1089 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_TF_LAYOUT_BETTER
), SetMinimalSize(78, 12), SetFill(1, 0), SetDataTip(STR_FOUND_TOWN_SELECT_LAYOUT_BETTER_ROADS
, STR_FOUND_TOWN_SELECT_TOWN_ROAD_LAYOUT
),
1091 NWidget(NWID_SPACER
), SetMinimalSize(0, 1),
1092 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
), SetPIP(2, 0, 2),
1093 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_TF_LAYOUT_GRID2
), SetMinimalSize(78, 12), SetFill(1, 0), SetDataTip(STR_FOUND_TOWN_SELECT_LAYOUT_2X2_GRID
, STR_FOUND_TOWN_SELECT_TOWN_ROAD_LAYOUT
),
1094 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_TF_LAYOUT_GRID3
), SetMinimalSize(78, 12), SetFill(1, 0), SetDataTip(STR_FOUND_TOWN_SELECT_LAYOUT_3X3_GRID
, STR_FOUND_TOWN_SELECT_TOWN_ROAD_LAYOUT
),
1096 NWidget(NWID_SPACER
), SetMinimalSize(0, 1),
1097 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_TF_LAYOUT_RANDOM
), SetPadding(0, 2, 0, 2), SetMinimalSize(0, 12), SetFill(1, 0),
1098 SetDataTip(STR_FOUND_TOWN_SELECT_LAYOUT_RANDOM
, STR_FOUND_TOWN_SELECT_TOWN_ROAD_LAYOUT
), SetFill(1, 0),
1099 NWidget(NWID_SPACER
), SetMinimalSize(0, 2),
1103 /** Found a town window class. */
1104 struct FoundTownWindow
: Window
{
1106 TownSize town_size
; ///< Selected town size
1107 TownLayout town_layout
; ///< Selected town layout
1108 bool city
; ///< Are we building a city?
1109 QueryStringC
<MAX_LENGTH_TOWN_NAME_CHARS
> townname_editbox
; ///< Townname editbox
1110 bool townnamevalid
; ///< Is generated town name valid?
1111 uint32 townnameparts
; ///< Generated town name
1112 TownNameParams params
; ///< Town name parameters
1115 FoundTownWindow (const WindowDesc
*desc
, WindowNumber window_number
) :
1117 town_size(TSZ_MEDIUM
),
1118 town_layout(_settings_game
.economy
.town_layout
),
1121 townnamevalid(false),
1123 params(_settings_game
.game_creation
.town_name
)
1125 this->InitNested(window_number
);
1126 this->querystrings
[WID_TF_TOWN_NAME_EDITBOX
] = &this->townname_editbox
;
1127 this->RandomTownName();
1128 this->UpdateButtons(true);
1131 void RandomTownName()
1133 this->townnamevalid
= GenerateTownName(&this->townnameparts
);
1135 if (!this->townnamevalid
) {
1136 this->townname_editbox
.DeleteAll();
1138 this->townname_editbox
.clear();
1139 AppendTownName (&this->townname_editbox
, &this->params
, this->townnameparts
);
1140 this->townname_editbox
.UpdateSize();
1142 UpdateOSKOriginalText(this, WID_TF_TOWN_NAME_EDITBOX
);
1144 this->SetWidgetDirty(WID_TF_TOWN_NAME_EDITBOX
);
1147 void UpdateButtons(bool check_availability
)
1149 if (check_availability
&& _game_mode
!= GM_EDITOR
) {
1150 this->SetWidgetsDisabledState(true, WID_TF_RANDOM_TOWN
, WID_TF_MANY_RANDOM_TOWNS
, WID_TF_SIZE_LARGE
, WIDGET_LIST_END
);
1151 this->SetWidgetsDisabledState(_settings_game
.economy
.found_town
!= TF_CUSTOM_LAYOUT
,
1152 WID_TF_LAYOUT_ORIGINAL
, WID_TF_LAYOUT_BETTER
, WID_TF_LAYOUT_GRID2
, WID_TF_LAYOUT_GRID3
, WID_TF_LAYOUT_RANDOM
, WIDGET_LIST_END
);
1153 if (_settings_game
.economy
.found_town
!= TF_CUSTOM_LAYOUT
) town_layout
= _settings_game
.economy
.town_layout
;
1156 for (int i
= WID_TF_SIZE_SMALL
; i
<= WID_TF_SIZE_RANDOM
; i
++) {
1157 this->SetWidgetLoweredState(i
, i
== WID_TF_SIZE_SMALL
+ this->town_size
);
1160 this->SetWidgetLoweredState(WID_TF_CITY
, this->city
);
1162 for (int i
= WID_TF_LAYOUT_ORIGINAL
; i
<= WID_TF_LAYOUT_RANDOM
; i
++) {
1163 this->SetWidgetLoweredState(i
, i
== WID_TF_LAYOUT_ORIGINAL
+ this->town_layout
);
1169 void ExecuteFoundTownCommand(TileIndex tile
, bool random
)
1171 const char *name
= NULL
;
1173 if (!this->townnamevalid
) {
1174 name
= this->townname_editbox
.GetText();
1176 /* If user changed the name, send it */
1177 sstring
<MAX_LENGTH_TOWN_NAME_CHARS
* MAX_CHAR_LENGTH
> buf
;
1178 AppendTownName (&buf
, &this->params
, this->townnameparts
);
1179 if (strcmp (buf
.c_str(), this->townname_editbox
.GetText()) != 0) name
= this->townname_editbox
.GetText();
1182 bool success
= DoCommandP(tile
, this->town_size
| this->city
<< 2 | this->town_layout
<< 3 | random
<< 6,
1183 townnameparts
, CMD_FOUND_TOWN
, name
);
1185 /* Rerandomise name, if success and no cost-estimation. */
1186 if (success
&& !_shift_pressed
) this->RandomTownName();
1189 virtual void OnClick(Point pt
, int widget
, int click_count
)
1192 case WID_TF_NEW_TOWN
:
1193 HandlePlacePushButton (this, WID_TF_NEW_TOWN
, SPR_CURSOR_TOWN
, POINTER_TILE
);
1196 case WID_TF_RANDOM_TOWN
:
1197 this->ExecuteFoundTownCommand(0, true);
1200 case WID_TF_TOWN_NAME_RANDOM
:
1201 this->RandomTownName();
1202 this->SetFocusedWidget(WID_TF_TOWN_NAME_EDITBOX
);
1205 case WID_TF_MANY_RANDOM_TOWNS
:
1206 _generating_world
= true;
1207 UpdateNearestTownForRoadTiles(true);
1208 if (!GenerateTowns(this->town_layout
)) {
1209 ShowErrorMessage(STR_ERROR_CAN_T_GENERATE_TOWN
, STR_ERROR_NO_SPACE_FOR_TOWN
, WL_INFO
);
1211 UpdateNearestTownForRoadTiles(false);
1212 _generating_world
= false;
1215 case WID_TF_SIZE_SMALL
: case WID_TF_SIZE_MEDIUM
: case WID_TF_SIZE_LARGE
: case WID_TF_SIZE_RANDOM
:
1216 this->town_size
= (TownSize
)(widget
- WID_TF_SIZE_SMALL
);
1217 this->UpdateButtons(false);
1222 this->SetWidgetLoweredState(WID_TF_CITY
, this->city
);
1226 case WID_TF_LAYOUT_ORIGINAL
: case WID_TF_LAYOUT_BETTER
: case WID_TF_LAYOUT_GRID2
:
1227 case WID_TF_LAYOUT_GRID3
: case WID_TF_LAYOUT_RANDOM
:
1228 this->town_layout
= (TownLayout
)(widget
- WID_TF_LAYOUT_ORIGINAL
);
1229 this->UpdateButtons(false);
1234 virtual void OnPlaceObject(Point pt
, TileIndex tile
)
1236 this->ExecuteFoundTownCommand(tile
, false);
1239 virtual void OnPlaceObjectAbort()
1241 this->RaiseButtons();
1242 this->UpdateButtons(false);
1246 * Some data on this window has become invalid.
1247 * @param data Information about the changed data.
1248 * @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
1250 virtual void OnInvalidateData(int data
= 0, bool gui_scope
= true)
1252 if (!gui_scope
) return;
1253 this->UpdateButtons(true);
1257 static WindowDesc::Prefs
_found_town_prefs ("build_town");
1259 static const WindowDesc
_found_town_desc(
1261 WC_FOUND_TOWN
, WC_NONE
,
1263 _nested_found_town_widgets
, lengthof(_nested_found_town_widgets
),
1267 void ShowFoundTownWindow()
1269 if (_game_mode
!= GM_EDITOR
&& !Company::IsValidID(_local_company
)) return;
1270 AllocateWindowDescFront
<FoundTownWindow
>(&_found_town_desc
, 0);
1275 * Window for selecting towns to build a house in.
1277 struct SelectTownWindow
: Window
{
1278 const TileIndex tile
; ///< tile where to build the house
1279 const HouseID house
; ///< house to build
1280 std::vector
<Town
*> towns
; ///< sorted vector of towns
1281 Scrollbar
*vscroll
; ///< scrollbar for the town list
1282 bool rebuild
; ///< town vector must be rebuilt
1284 void RebuildTownList (void);
1286 SelectTownWindow (const WindowDesc
*desc
, TileIndex tile
, HouseID house
)
1287 : Window(desc
), tile(tile
), house(house
), towns(),
1288 vscroll(NULL
), rebuild(false)
1290 this->CreateNestedTree();
1291 this->vscroll
= this->GetScrollbar(WID_ST_SCROLLBAR
);
1292 this->RebuildTownList();
1296 virtual void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
)
1298 if (widget
!= WID_ST_PANEL
) return;
1300 /* Determine the widest string */
1301 Dimension d
= { 0, 0 };
1302 for (uint i
= 0; i
< Town::pool
.items
; i
++) {
1304 d
= maxdim(d
, GetStringBoundingBox(STR_SELECT_TOWN_LIST_ITEM
));
1307 resize
->height
= d
.height
;
1309 d
.width
+= WD_FRAMERECT_RIGHT
+ WD_FRAMERECT_LEFT
;
1310 d
.height
+= WD_FRAMERECT_TOP
+ WD_FRAMERECT_BOTTOM
;
1314 void DrawWidget (BlitArea
*dpi
, const Rect
&r
, int widget
) const OVERRIDE
1316 if (widget
!= WID_ST_PANEL
) return;
1318 uint y
= r
.top
+ WD_FRAMERECT_TOP
;
1319 uint end
= min(this->vscroll
->GetCount(), this->vscroll
->GetPosition() + this->vscroll
->GetCapacity());
1320 for (uint i
= this->vscroll
->GetPosition(); i
< end
; i
++) {
1321 SetDParam(0, this->towns
[i
]->index
);
1322 DrawString (dpi
, r
.left
+ WD_FRAMERECT_LEFT
, r
.right
- WD_FRAMERECT_RIGHT
, y
, STR_SELECT_TOWN_LIST_ITEM
);
1323 y
+= this->resize
.step_height
;
1327 virtual void OnClick(Point pt
, int widget
, int click_count
)
1329 if (widget
!= WID_ST_PANEL
) return;
1331 uint pos
= this->vscroll
->GetScrolledRowFromWidget(pt
.y
, this, WID_ST_PANEL
, WD_FRAMERECT_TOP
);
1332 if (pos
>= this->towns
.size()) return;
1334 Town
*town
= this->towns
[pos
];
1336 StringID err
= IsNewTownHouseAllowed (town
, this->house
);
1337 if (err
!= STR_NULL
) {
1338 ShowErrorMessage (STR_ERROR_CAN_T_BUILD_HOUSE_HERE
,
1339 err
, WL_INFO
, pt
.x
, pt
.y
);
1344 DoBuildHouse (town
, this->tile
, this->house
, InteractiveRandom());
1346 /* Close the window */
1350 void OnPaint (BlitArea
*dpi
) OVERRIDE
1352 if (this->rebuild
) this->RebuildTownList();
1353 this->DrawWidgets (dpi
);
1356 virtual void OnResize()
1358 this->vscroll
->SetCapacityFromWidget(this, WID_ST_PANEL
, WD_FRAMERECT_TOP
+ WD_FRAMERECT_BOTTOM
);
1361 virtual void OnInvalidateData(int data
= 0, bool gui_scope
= true)
1363 this->rebuild
= true;
1367 struct TownDistanceSorter
{
1368 const TileIndex tile
;
1370 TownDistanceSorter (TileIndex tile
) : tile (tile
)
1374 bool operator() (const Town
*t1
, const Town
*t2
)
1376 return DistanceSquare (tile
, t1
->xy
) < DistanceSquare (tile
, t2
->xy
);
1380 void SelectTownWindow::RebuildTownList (void)
1382 this->towns
.clear();
1386 this->towns
.push_back (t
);
1389 TownDistanceSorter
sorter (this->tile
);
1390 std::stable_sort (this->towns
.begin(), this->towns
.end(), sorter
);
1392 this->rebuild
= false;
1393 this->vscroll
->SetCount (this->towns
.size());
1396 static const NWidgetPart _nested_select_town_widgets
[] = {
1397 NWidget(NWID_HORIZONTAL
),
1398 NWidget(WWT_CLOSEBOX
, COLOUR_DARK_GREEN
),
1399 NWidget(WWT_CAPTION
, COLOUR_DARK_GREEN
, WID_ST_CAPTION
), SetDataTip(STR_SELECT_TOWN_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
1400 NWidget(WWT_DEFSIZEBOX
, COLOUR_DARK_GREEN
),
1402 NWidget(NWID_HORIZONTAL
),
1403 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_ST_PANEL
), SetResize(1, 0), SetScrollbar(WID_ST_SCROLLBAR
), EndContainer(),
1404 NWidget(NWID_VERTICAL
),
1405 NWidget(NWID_VSCROLLBAR
, COLOUR_DARK_GREEN
, WID_ST_SCROLLBAR
),
1406 NWidget(WWT_RESIZEBOX
, COLOUR_DARK_GREEN
),
1411 static WindowDesc::Prefs
_select_town_prefs ("select_town");
1413 static const WindowDesc
_select_town_desc(
1415 WC_SELECT_TOWN
, WC_NONE
,
1417 _nested_select_town_widgets
, lengthof(_nested_select_town_widgets
),
1422 /** The window used for building houses. */
1423 class HousePickerWindow
: public Window
{
1424 std::vector
<HouseID
> houses
; ///< List of available houses.
1425 std::vector
<uint16
> sets
; ///< List of house sets, each item points the first house of the set in the houses array.
1426 uint sel_set
; ///< Index of the selected house set.
1427 uint sel_offset
; ///< Index of the selected house.
1428 StringID name
; ///< Name of the selected house.
1429 uint32 supply
; ///< Cargo mask of produced cargo.
1430 char acceptance
[DRAW_STRING_BUFFER
]; ///< String representation of accepted cargo.
1431 uint line_height
; ///< Height of a single line in the list of house sets.
1433 static HouseID cur_house
; ///< House selected in the house picker window.
1435 uint
GetSetSize (uint set
) const
1437 assert (set
< this->sets
.size());
1438 uint next
= set
+ 1;
1439 return ((next
== this->sets
.size()) ? this->houses
.size() : this->sets
[next
])
1440 - this->sets
[this->sel_set
];
1443 static void GetAcceptedCargo (CargoArray
*acceptance
, HouseID house
)
1445 const HouseSpec
*hs
= HouseSpec::Get (house
);
1448 /* Set the initial accepted cargo types. */
1449 for (uint i
= 0; i
< lengthof(accepts
); i
++) {
1450 accepts
[i
] = hs
->accepts_cargo
[i
];
1453 /* Check for custom accepted cargo types. */
1454 if (HasBit(hs
->callback_mask
, CBM_HOUSE_ACCEPT_CARGO
)) {
1455 uint16 callback
= GetHouseCallback (CBID_HOUSE_ACCEPT_CARGO
, 0, 0, house
);
1456 if (callback
!= CALLBACK_FAILED
) {
1457 /* Replace accepted cargo types with translated values from callback. */
1458 accepts
[0] = GetCargoTranslation (GB(callback
, 0, 5), hs
->grf_prop
.grffile
);
1459 accepts
[1] = GetCargoTranslation (GB(callback
, 5, 5), hs
->grf_prop
.grffile
);
1460 accepts
[2] = GetCargoTranslation (GB(callback
, 10, 5), hs
->grf_prop
.grffile
);
1464 /* Check for custom cargo acceptance */
1465 if (HasBit(hs
->callback_mask
, CBM_HOUSE_CARGO_ACCEPTANCE
)) {
1466 uint16 callback
= GetHouseCallback (CBID_HOUSE_CARGO_ACCEPTANCE
, 0, 0, house
);
1467 if (callback
!= CALLBACK_FAILED
) {
1468 if (accepts
[0] != CT_INVALID
) (*acceptance
)[accepts
[0]] += GB(callback
, 0, 4);
1469 if (accepts
[1] != CT_INVALID
) (*acceptance
)[accepts
[1]] += GB(callback
, 4, 4);
1470 if (_settings_game
.game_creation
.landscape
!= LT_TEMPERATE
&& HasBit(callback
, 12)) {
1471 /* The 'S' bit indicates food instead of goods. */
1472 (*acceptance
)[CT_FOOD
] += GB(callback
, 8, 4);
1473 } else if (accepts
[2] != CT_INVALID
) {
1474 (*acceptance
)[accepts
[2]] += GB(callback
, 8, 4);
1480 /* No custom acceptance, so fill in with the default values. */
1481 for (uint i
= 0; i
< lengthof(accepts
); i
++) {
1482 if (accepts
[i
] != CT_INVALID
) (*acceptance
)[accepts
[i
]] += hs
->cargo_acceptance
[i
];
1486 void BuildSetList (void)
1488 /* Try to reselect the previous selection. */
1490 this->sel_offset
= 0;
1492 const GRFFile
*cur_grffile
= (cur_house
!= INVALID_HOUSE_ID
) ?
1493 HouseSpec::Get (cur_house
)->grf_prop
.grffile
: NULL
;
1495 assert (!this->houses
.empty());
1499 HouseID house
= this->houses
[i
];
1500 const HouseSpec
*hs
= HouseSpec::Get (house
);
1501 const GRFFile
*grffile
= hs
->grf_prop
.grffile
;
1502 if (grffile
== cur_grffile
) {
1503 this->sel_set
= this->sets
.size();
1505 this->sets
.push_back (i
);
1507 if (house
== cur_house
) {
1508 this->sel_offset
= i
;
1511 if (i
== this->houses
.size()) return;
1512 house
= this->houses
[i
];
1513 if (HouseSpec::Get(house
)->grf_prop
.grffile
!= grffile
) break;
1518 void SetObjectToPlace (void)
1520 SetPointerMode (POINTER_TILE
, this, SPR_CURSOR_TOWN
);
1523 void UpdateCache (void)
1525 if (cur_house
== INVALID_HOUSE_ID
) {
1526 SetTileSelectSize (1, 1);
1527 this->name
= STR_EMPTY
;
1529 this->acceptance
[0] = '\0';
1533 const HouseSpec
*hs
= HouseSpec::Get (cur_house
);
1535 SetTileSelectSize ((hs
->building_flags
& BUILDING_2_TILES_X
) ? 2 : 1,
1536 (hs
->building_flags
& BUILDING_2_TILES_Y
) ? 2 : 1);
1538 /* Cache house name. */
1539 this->name
= hs
->building_name
;
1540 uint16 callback_res
= GetHouseCallback (CBID_HOUSE_CUSTOM_NAME
, 1, 0, cur_house
);
1541 if (callback_res
!= CALLBACK_FAILED
&& callback_res
!= 0x400) {
1542 uint32 grfid
= hs
->grf_prop
.grffile
->grfid
;
1543 if (callback_res
> 0x400) {
1544 ErrorUnknownCallbackResult (grfid
, CBID_HOUSE_CUSTOM_NAME
, callback_res
);
1546 StringID ret
= GetGRFStringID (grfid
, 0xD000 + callback_res
);
1547 if (ret
!= STR_NULL
&& ret
!= STR_UNDEFINED
) this->name
= ret
;
1551 /* Cache house production. */
1552 if (HasBit(hs
->callback_mask
, CBM_HOUSE_PRODUCE_CARGO
)) {
1553 CargoArray production
;
1554 for (uint i
= 0; i
< 256; i
++) {
1555 uint16 callback
= GetHouseCallback (CBID_HOUSE_PRODUCE_CARGO
, i
, 0, cur_house
);
1556 if (callback
== CALLBACK_FAILED
|| callback
== CALLBACK_HOUSEPRODCARGO_END
) break;
1557 CargoID c
= GetCargoTranslation (GB(callback
, 8, 7), hs
->grf_prop
.grffile
);
1558 if (c
!= CT_INVALID
) production
[c
]++;
1561 for (CargoID i
= 0; i
< NUM_CARGO
; i
++) if (production
[i
] != 0) SetBit (mask
, i
);
1562 this->supply
= mask
;
1565 if (hs
->population
> 0) mask
|= (1 << CT_PASSENGERS
);
1566 if (hs
->mail_generation
> 0) mask
|= (1 << CT_MAIL
);
1567 this->supply
= mask
;
1570 /* Cache house acceptance. */
1572 GetAcceptedCargo (&cargo
, cur_house
);
1574 stringb
buf (this->acceptance
);
1576 for (CargoID i
= 0; i
< NUM_CARGO
; ++i
) {
1577 if (cargo
[i
] == 0) continue;
1579 /* Add a comma between each item. */
1580 if (!buf
.empty()) buf
.append (", ");
1582 /* If the accepted value is less than 8, show it in 1/8s. */
1584 SetDParam (0, cargo
[i
]);
1585 SetDParam (1, CargoSpec::Get(i
)->name
);
1586 AppendString (&buf
, STR_LAND_AREA_INFORMATION_CARGO_EIGHTS
);
1588 AppendString (&buf
, CargoSpec::Get(i
)->name
);
1592 if (buf
.empty()) AppendString (&buf
, STR_JUST_NOTHING
);
1596 HousePickerWindow (const WindowDesc
*desc
, WindowNumber number
) :
1597 Window (desc
), houses(), sets(), sel_set (0), sel_offset (0),
1598 name (STR_NULL
), supply (0), line_height (0)
1600 memset (this->acceptance
, 0, sizeof(this->acceptance
));
1602 this->CreateNestedTree();
1603 /* there is no shade box but we will shade the window if there is no house to show */
1604 this->shade_select
= this->GetWidget
<NWidgetStacked
> (WID_HP_MAIN_PANEL_SEL
);
1605 NWidgetMatrix
*matrix
= this->GetWidget
<NWidgetMatrix
> (WID_HP_HOUSE_SELECT_MATRIX
);
1606 matrix
->SetScrollbar (this->GetScrollbar (WID_HP_HOUSE_SELECT_SCROLL
));
1607 this->InitNested (number
);
1609 if (cur_house
!= INVALID_HOUSE_ID
) {
1610 matrix
->SetClicked (this->sel_offset
); // set clicked item again to make it visible
1611 this->SetObjectToPlace();
1617 void OnInit() OVERRIDE
1619 /* Rebuild house list. */
1621 this->houses
.clear();
1623 /* Collect houses. */
1624 for (HouseID house
= 0; house
< NUM_HOUSES
; house
++) {
1625 const HouseSpec
*hs
= HouseSpec::Get(house
);
1627 if (!hs
->enabled
) continue;
1628 if (hs
->grf_prop
.override
!= INVALID_HOUSE_ID
) continue;
1630 uint landscape
= _settings_game
.game_creation
.landscape
;
1631 uint mask
= (landscape
!= LT_ARCTIC
) ? (HZ_TEMP
<< landscape
) :
1632 (HZ_SUBARTC_ABOVE
| HZ_SUBARTC_BELOW
);
1633 HouseZones availability
= hs
->building_availability
;
1634 if ((availability
& mask
) == 0) continue;
1635 if ((availability
& HZ_ZONALL
) == 0) continue;
1637 this->houses
.push_back (house
);
1640 if (this->houses
.empty()) {
1641 cur_house
= INVALID_HOUSE_ID
;
1642 /* Hide widgets if we have no houses to show. */
1643 this->SetShaded (true);
1645 std::sort (this->houses
.begin(), this->houses
.end());
1647 this->BuildSetList();
1649 this->SetShaded (false);
1651 /* Show the list of house sets if we have at least 2 items to show. */
1652 this->GetWidget
<NWidgetStacked
> (WID_HP_HOUSE_SETS_SEL
)->SetDisplayedPlane (this->sets
.size() > 1 ? 0 : SZSP_NONE
);
1653 /* Set the number of items in the list of house sets. */
1654 this->GetWidget
<NWidgetCore
> (WID_HP_HOUSE_SETS
)->widget_data
= (this->sets
.size() << MAT_ROW_START
) | (1 << MAT_COL_START
);
1655 /* Show the landscape info only in arctic climate (above/below snowline). */
1656 this->GetWidget
<NWidgetStacked
> (WID_HP_HOUSE_LANDSCAPE_SEL
)->SetDisplayedPlane (_settings_game
.game_creation
.landscape
== LT_ARCTIC
? 0 : SZSP_NONE
);
1657 /* Update the matrix of houses. */
1658 NWidgetMatrix
*matrix
= this->GetWidget
<NWidgetMatrix
> (WID_HP_HOUSE_SELECT_MATRIX
);
1659 matrix
->SetCount (GetSetSize (this->sel_set
));
1660 matrix
->SetClicked (this->sel_offset
);
1661 cur_house
= this->houses
[this->sets
[this->sel_set
] + this->sel_offset
];
1664 this->UpdateCache();
1666 /* If we have exactly one set of houses and it is not the default one then display its name in the title bar. */
1667 this->GetWidget
<NWidgetCore
> (WID_HP_CAPTION
)->widget_data
=
1668 (this->sets
.size() == 1 && HouseSpec::Get (this->houses
[0])->grf_prop
.grffile
!= NULL
) ?
1669 STR_BUILD_HOUSE_CUSTOM_CAPTION
: STR_BUILD_HOUSE_CAPTION
;
1672 const GRFFile
*GetGRFFileOfSet (uint set
) const
1674 assert (set
< this->sets
.size());
1675 return HouseSpec::Get (this->houses
[this->sets
[set
]])->grf_prop
.grffile
;
1678 static const char *GetNameOfSet (const GRFFile
*grffile
)
1680 return GetGRFConfig (grffile
->grfid
)->GetName();
1683 void SetStringParameters (int widget
) const OVERRIDE
1686 case WID_HP_CAPTION
:
1687 if (this->sets
.size() == 1) {
1688 const GRFFile
*grffile
= GetGRFFileOfSet (0);
1689 if (grffile
!= NULL
) {
1690 SetDParamStr (0, GetNameOfSet (grffile
));
1695 case WID_HP_HOUSE_NAME
: {
1696 SetDParam (0, this->name
);
1700 case WID_HP_HISTORICAL_BUILDING
:
1701 SetDParam (0, ((cur_house
!= INVALID_HOUSE_ID
) && (HouseSpec::Get (cur_house
)->extra_flags
& BUILDING_IS_HISTORICAL
) != 0) ? STR_BUILD_HOUSE_HISTORICAL_BUILDING
: STR_EMPTY
);
1704 case WID_HP_HOUSE_POPULATION
:
1705 SetDParam (0, (cur_house
!= INVALID_HOUSE_ID
) ? HouseSpec::Get (cur_house
)->population
: 0);
1708 case WID_HP_HOUSE_ZONES
: {
1709 HouseZones zones
= (cur_house
!= INVALID_HOUSE_ID
) ? HouseSpec::Get(cur_house
)->building_availability
: HZ_NOZNS
;
1710 for (int i
= 0; i
< HZB_END
; i
++) {
1711 SetDParam (i
, HasBit (zones
, HZB_END
- 1 - i
) ? STR_BUILD_HOUSE_ZONE_ENABLED
: STR_BUILD_HOUSE_ZONE_DISABLED
);
1716 case WID_HP_HOUSE_LANDSCAPE
: {
1718 if (cur_house
!= INVALID_HOUSE_ID
) {
1719 switch (HouseSpec::Get(cur_house
)->building_availability
& (HZ_SUBARTC_ABOVE
| HZ_SUBARTC_BELOW
)) {
1720 case HZ_SUBARTC_ABOVE
: info
= STR_BUILD_HOUSE_ABOVE_SNOWLINE
; break;
1721 case HZ_SUBARTC_BELOW
: info
= STR_BUILD_HOUSE_BELOW_SNOWLINE
; break;
1722 default: info
= STR_BUILD_HOUSE_ABOVE_OR_BELOW_SNOWLINE
; break;
1727 SetDParam (0, info
);
1731 case WID_HP_HOUSE_YEARS
: {
1732 if (cur_house
!= INVALID_HOUSE_ID
) {
1733 const HouseSpec
*hs
= HouseSpec::Get (cur_house
);
1734 SetDParam (0, hs
->min_year
<= _cur_year
? STR_BUILD_HOUSE_GOOD_YEAR
: STR_BUILD_HOUSE_BAD_YEAR
);
1735 SetDParam (1, hs
->min_year
);
1736 SetDParam (2, hs
->max_year
>= _cur_year
? STR_BUILD_HOUSE_GOOD_YEAR
: STR_BUILD_HOUSE_BAD_YEAR
);
1737 SetDParam (3, hs
->max_year
);
1739 SetDParam (0, STR_EMPTY
);
1741 SetDParam (2, STR_EMPTY
);
1747 case WID_HP_HOUSE_ACCEPTANCE
:
1748 SetDParamStr (0, this->acceptance
);
1751 case WID_HP_HOUSE_SUPPLY
:
1752 SetDParam (0, this->supply
);
1759 void UpdateWidgetSize (int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
) OVERRIDE
1762 case WID_HP_HOUSE_SETS
: {
1764 for (uint i
= 0; i
< this->sets
.size(); i
++) {
1765 const GRFFile
*grffile
= this->GetGRFFileOfSet (i
);
1766 uint w
= (grffile
!= NULL
) ?
1767 GetStringBoundingBox (GetNameOfSet (grffile
)).width
:
1768 GetStringBoundingBox (STR_BUILD_HOUSE_ORIGINAL_SET_NAME
).width
;
1769 max_w
= max (max_w
, w
);
1771 size
->width
= max (size
->width
, max_w
+ padding
.width
);
1772 this->line_height
= FONT_HEIGHT_NORMAL
+ WD_MATRIX_TOP
+ WD_MATRIX_BOTTOM
;
1773 size
->height
= this->sets
.size() * this->line_height
;
1777 case WID_HP_HOUSE_PREVIEW
:
1778 size
->width
= ScaleGUITrad (2 * TILE_PIXELS
);
1779 size
->height
= ScaleGUITrad (142);
1782 case WID_HP_HOUSE_NAME
:
1783 size
->width
= 120; // we do not want this window to get too wide, better clip
1786 case WID_HP_HISTORICAL_BUILDING
:
1787 size
->width
= max (size
->width
, GetStringBoundingBox (STR_BUILD_HOUSE_HISTORICAL_BUILDING
).width
+ padding
.width
);
1790 case WID_HP_HOUSE_POPULATION
:
1791 /* Max popultion is 255 - 3 digits */
1792 SetDParamMaxDigits (0, 3);
1793 size
->width
= max (size
->width
, GetStringBoundingBox (STR_BUILD_HOUSE_POPULATION
).width
+ padding
.width
);
1796 case WID_HP_HOUSE_ZONES
: {
1797 for (int i
= 0; i
< HZB_END
; i
++) {
1798 SetDParam (2 * i
, STR_BUILD_HOUSE_ZONE_ENABLED
); // colour
1799 SetDParam (2 * i
+ 1, i
+ 1); // digit: 1(center)/2/3/4/5(edge)
1801 size
->width
= max (size
->width
, GetStringBoundingBox (STR_BUILD_HOUSE_ZONES
).width
+ padding
.width
);
1805 case WID_HP_HOUSE_LANDSCAPE
: {
1806 SetDParam (0, STR_BUILD_HOUSE_ABOVE_OR_BELOW_SNOWLINE
);
1807 Dimension dim
= GetStringBoundingBox (STR_BUILD_HOUSE_LANDSCAPE
);
1808 SetDParam (0, STR_BUILD_HOUSE_ABOVE_SNOWLINE
);
1809 dim
= maxdim (dim
, GetStringBoundingBox (STR_BUILD_HOUSE_LANDSCAPE
));
1810 SetDParam (0, STR_BUILD_HOUSE_BELOW_SNOWLINE
);
1811 dim
= maxdim (dim
, GetStringBoundingBox (STR_BUILD_HOUSE_LANDSCAPE
));
1812 dim
.width
+= padding
.width
;
1813 dim
.height
+= padding
.height
;
1814 *size
= maxdim (*size
, dim
);
1818 case WID_HP_HOUSE_YEARS
: {
1819 SetDParam (0, STR_BUILD_HOUSE_GOOD_YEAR
);
1820 SetDParamMaxDigits (1, 8);
1821 SetDParam (2, STR_BUILD_HOUSE_GOOD_YEAR
);
1822 SetDParamMaxDigits (3, 8);
1823 Dimension dim
= GetStringBoundingBox (STR_BUILD_HOUSE_YEARS
);
1824 dim
.width
+= padding
.width
;
1825 dim
.height
+= padding
.height
;
1826 *size
= maxdim (*size
, dim
);
1830 case WID_HP_HOUSE_SELECT_MATRIX
:
1831 resize
->height
= 1; // don't snap to rows of this matrix
1834 case WID_HP_HOUSE_SELECT
:
1835 size
->width
= ScaleGUITrad(64) + 2;
1836 size
->height
= ScaleGUITrad(58) + 2;
1839 /* these texts can be long, better clip */
1840 case WID_HP_HOUSE_ACCEPTANCE
:
1841 case WID_HP_HOUSE_SUPPLY
:
1849 void DrawWidget (BlitArea
*dpi
, const Rect
&r
, int widget
) const OVERRIDE
1851 switch (GB(widget
, 0, 16)) {
1852 case WID_HP_HOUSE_SETS
: {
1853 int y
= r
.top
+ WD_MATRIX_TOP
;
1854 for (uint i
= 0; i
< this->sets
.size(); i
++) {
1855 const GRFFile
*grffile
= this->GetGRFFileOfSet (i
);
1857 if (grffile
!= NULL
) {
1858 SetDParamStr (0, GetNameOfSet (grffile
));
1859 str
= STR_JUST_RAW_STRING
;
1861 str
= STR_BUILD_HOUSE_ORIGINAL_SET_NAME
;
1863 DrawString (dpi
, r
.left
+ WD_MATRIX_LEFT
, r
.right
- WD_MATRIX_RIGHT
, y
, str
, i
== this->sel_set
? TC_WHITE
: TC_BLACK
);
1864 y
+= this->line_height
;
1869 case WID_HP_HOUSE_PREVIEW
:
1870 if (cur_house
!= INVALID_HOUSE_ID
) {
1871 DrawHouseImage (cur_house
, dpi
, r
.left
, r
.top
, r
.right
, r
.bottom
);
1875 case WID_HP_HOUSE_SELECT
: {
1876 HouseID house
= this->houses
[this->sets
[this->sel_set
] + GB(widget
, 16, 16)];
1877 DrawHouseImage (house
, dpi
,
1878 r
.left
+ WD_MATRIX_LEFT
, r
.top
+ WD_MATRIX_TOP
,
1879 r
.right
- WD_MATRIX_RIGHT
, r
.bottom
- WD_MATRIX_BOTTOM
);
1885 void OnClick (Point pt
, int widget
, int click_count
) OVERRIDE
1887 switch (GB(widget
, 0, 16)) {
1888 case WID_HP_HOUSE_SETS
: {
1889 uint index
= (uint
)(pt
.y
- this->GetWidget
<NWidgetBase
>(widget
)->pos_y
) / this->line_height
;
1890 if (index
< this->sets
.size() && index
!= this->sel_set
) {
1891 this->SetObjectToPlace();
1892 cur_house
= this->houses
[this->sets
[index
]];
1893 this->sel_set
= index
;
1894 this->sel_offset
= 0;
1896 NWidgetMatrix
*matrix
= this->GetWidget
<NWidgetMatrix
>(WID_HP_HOUSE_SELECT_MATRIX
);
1897 matrix
->SetCount (GetSetSize (index
));
1898 matrix
->SetClicked (0);
1899 this->UpdateCache();
1905 case WID_HP_HOUSE_SELECT
: {
1906 uint index
= GB(widget
, 16, 16);
1907 if (index
!= this->sel_offset
) {
1908 this->SetObjectToPlace();
1909 cur_house
= this->houses
[this->sets
[this->sel_set
] + index
];
1910 this->sel_offset
= index
;
1912 NWidgetMatrix
*matrix
= this->GetWidget
<NWidgetMatrix
>(WID_HP_HOUSE_SELECT_MATRIX
);
1913 matrix
->SetClicked (index
);
1914 this->UpdateCache();
1922 void OnPlaceObject (Point pt
, TileIndex tile
) OVERRIDE
;
1924 void OnPlaceObjectAbort (void) OVERRIDE
1926 this->sel_offset
= -1;
1927 this->GetWidget
<NWidgetMatrix
>(WID_HP_HOUSE_SELECT_MATRIX
)->SetClicked (-1);
1932 static StringID
CheckPlaceHouse (TileIndex tile
, HouseID house
, Town
*town
)
1934 const HouseSpec
*hs
= HouseSpec::Get (house
);
1936 int z
= GetTileMaxZ (tile
);
1938 if (_settings_game
.game_creation
.landscape
== LT_ARCTIC
) {
1939 bool above_snowline
= z
> HighestSnowLine();
1940 HouseZones mask
= above_snowline
? HZ_SUBARTC_ABOVE
: HZ_SUBARTC_BELOW
;
1941 if ((hs
->building_availability
& mask
) == 0) {
1942 return above_snowline
?
1943 STR_ERROR_BUILDING_NOT_ALLOWED_ABOVE_SNOW_LINE
:
1944 STR_ERROR_BUILDING_NOT_ALLOWED_BELOW_SNOW_LINE
;
1949 StringID err
= IsNewTownHouseAllowed (town
, house
);
1950 if (err
!= STR_NULL
) return err
;
1954 if (hs
->building_flags
& BUILDING_2_TILES_X
) ta
.w
++;
1955 if (hs
->building_flags
& BUILDING_2_TILES_Y
) ta
.h
++;
1957 bool noslope
= (hs
->building_flags
& TILE_NOT_SLOPED
) != 0;
1959 TILE_AREA_LOOP(test
, ta
) {
1961 if (!IsTileFlat (test
)) {
1962 return STR_ERROR_FLAT_LAND_REQUIRED
;
1965 if (IsSteepSlope (GetTileSlope (test
)) || (GetTileMaxZ (test
) != z
)) {
1966 return STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION
;
1970 if (HasBridgeAbove (test
)) {
1971 return STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST
;
1974 CommandCost clear
= DoCommand (test
, 0, 0, DC_AUTO
| DC_NO_WATER
, CMD_LANDSCAPE_CLEAR
);
1975 if (clear
.Failed()) return clear
.GetErrorMessage();
1981 void HousePickerWindow::OnPlaceObject (Point pt
, TileIndex tile
)
1983 HouseID house
= cur_house
;
1984 if (house
== INVALID_HOUSE_ID
) return;
1987 if (!_ctrl_pressed
) {
1988 /* Add the house to the closest town. */
1989 Town
*town
= CalcClosestTownFromTile (tile
);
1991 err
= STR_ERROR_MUST_FOUND_TOWN_FIRST
;
1993 err
= CheckPlaceHouse (tile
, house
, town
);
1994 if (err
== STR_NULL
) {
1995 DoBuildHouse (town
, tile
, house
, InteractiveRandom());
2000 /* Show a list of towns to join. */
2001 if (Town::pool
.items
== 0) {
2002 err
= STR_ERROR_MUST_FOUND_TOWN_FIRST
;
2004 err
= CheckPlaceHouse (tile
, house
, NULL
);
2005 if (err
== STR_NULL
) {
2006 DeleteWindowByClass (WC_SELECT_TOWN
);
2007 new SelectTownWindow (&_select_town_desc
, tile
, house
);
2013 ShowErrorMessage (STR_ERROR_CAN_T_BUILD_HOUSE_HERE
, err
,
2014 WL_INFO
, pt
.x
, pt
.y
);
2017 static const NWidgetPart _nested_house_picker_widgets
[] = {
2018 NWidget(NWID_HORIZONTAL
),
2019 NWidget(WWT_CLOSEBOX
, COLOUR_DARK_GREEN
),
2020 NWidget(WWT_CAPTION
, COLOUR_DARK_GREEN
, WID_HP_CAPTION
), SetDataTip(STR_BUILD_HOUSE_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
2021 NWidget(WWT_DEFSIZEBOX
, COLOUR_DARK_GREEN
),
2023 NWidget(NWID_SELECTION
, COLOUR_DARK_GREEN
, WID_HP_MAIN_PANEL_SEL
),
2024 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
), SetScrollbar(WID_HP_HOUSE_SELECT_SCROLL
),
2025 NWidget(NWID_HORIZONTAL
), SetPIP(5, 0, 0),
2026 NWidget(NWID_VERTICAL
), SetPIP(5, 2, 2),
2027 /* List of house sets */
2028 NWidget(NWID_SELECTION
, COLOUR_DARK_GREEN
, WID_HP_HOUSE_SETS_SEL
),
2029 NWidget(NWID_HORIZONTAL
),
2030 NWidget(WWT_MATRIX
, COLOUR_GREY
, WID_HP_HOUSE_SETS
), SetMinimalSize(0, 60), SetFill(1, 0), SetResize(0, 0),
2031 SetMatrixDataTip(1, 1, STR_BUILD_HOUSE_HOUSESET_LIST_TOOLTIP
),
2034 /* House picture and label */
2035 NWidget(WWT_TEXT
, COLOUR_DARK_GREEN
, WID_HP_HOUSE_PREVIEW
), SetFill(1, 1), SetResize(0, 1), SetMinimalSize(2 * TILE_PIXELS
, 142), SetPadding(5, 0, 5, 0),
2036 NWidget(WWT_LABEL
, COLOUR_DARK_GREEN
, WID_HP_HOUSE_NAME
), SetDataTip(STR_BUILD_HOUSE_NAME
, STR_NULL
), SetMinimalSize(120, 0),
2037 NWidget(WWT_LABEL
, COLOUR_DARK_GREEN
, WID_HP_HISTORICAL_BUILDING
), SetDataTip(STR_JUST_STRING
, STR_NULL
),
2038 /* House info (short) */
2039 NWidget(WWT_TEXT
, COLOUR_DARK_GREEN
, WID_HP_HOUSE_POPULATION
), SetDataTip(STR_BUILD_HOUSE_POPULATION
, STR_NULL
), SetPadding(5, 0, 0, 0),
2040 NWidget(WWT_TEXT
, COLOUR_DARK_GREEN
, WID_HP_HOUSE_ZONES
), SetDataTip(STR_BUILD_HOUSE_ZONES
, STR_NULL
),
2041 NWidget(NWID_SELECTION
, COLOUR_DARK_GREEN
, WID_HP_HOUSE_LANDSCAPE_SEL
),
2042 NWidget(WWT_TEXT
, COLOUR_DARK_GREEN
, WID_HP_HOUSE_LANDSCAPE
), SetDataTip(STR_BUILD_HOUSE_LANDSCAPE
, STR_NULL
),
2044 NWidget(WWT_TEXT
, COLOUR_DARK_GREEN
, WID_HP_HOUSE_YEARS
), SetDataTip(STR_BUILD_HOUSE_YEARS
, STR_NULL
),
2047 NWidget(NWID_MATRIX
, COLOUR_DARK_GREEN
, WID_HP_HOUSE_SELECT_MATRIX
), SetPIP(0, 2, 0), SetPadding(2, 2, 2, 2), SetScrollbar(WID_HP_HOUSE_SELECT_SCROLL
),
2048 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_HP_HOUSE_SELECT
), SetMinimalSize(64, 64), SetFill(0, 0), SetResize(0, 0),
2049 SetDataTip(0x0, STR_BUILD_HOUSE_SELECT_HOUSE_TOOLTIP
), SetScrollbar(WID_HP_HOUSE_SELECT_SCROLL
),
2052 NWidget(NWID_VSCROLLBAR
, COLOUR_DARK_GREEN
, WID_HP_HOUSE_SELECT_SCROLL
),
2054 NWidget(NWID_HORIZONTAL
), SetPIP(5, 2, 0),
2055 /* House info (long) */
2056 NWidget(NWID_VERTICAL
), SetPIP(0, 2, 5),
2057 NWidget(WWT_TEXT
, COLOUR_DARK_GREEN
, WID_HP_HOUSE_ACCEPTANCE
), SetDataTip(STR_BUILD_HOUSE_ACCEPTED_CARGO
, STR_NULL
), SetFill(1, 0), SetResize(1, 0),
2058 NWidget(WWT_TEXT
, COLOUR_DARK_GREEN
, WID_HP_HOUSE_SUPPLY
), SetDataTip(STR_BUILD_HOUSE_SUPPLIED_CARGO
, STR_NULL
), SetFill(1, 0), SetResize(1, 0),
2061 NWidget(NWID_VERTICAL
),
2062 NWidget(NWID_SPACER
), SetFill(0, 1),
2063 NWidget(WWT_RESIZEBOX
, COLOUR_DARK_GREEN
),
2070 static WindowDesc::Prefs
_house_picker_prefs ("build_house");
2072 static const WindowDesc
_house_picker_desc(
2074 WC_BUILD_HOUSE
, WC_BUILD_TOOLBAR
,
2076 _nested_house_picker_widgets
, lengthof(_nested_house_picker_widgets
),
2077 &_house_picker_prefs
2080 HouseID
HousePickerWindow::cur_house
= INVALID_HOUSE_ID
;
2083 * Show our house picker.
2084 * @param parent The toolbar window we're associated with.
2086 void ShowBuildHousePicker (void)
2088 AllocateWindowDescFront
<HousePickerWindow
> (&_house_picker_desc
, 0);