Fix #8316: Make sort industries by production and transported with a cargo filter...
[openttd-github.git] / src / goal_gui.cpp
blob65ed9003b09dea0200306d0f87ddc4699b0920d1
1 /*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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/>.
6 */
8 /** @file goal_gui.cpp GUI for goals. */
10 #include "stdafx.h"
11 #include "industry.h"
12 #include "town.h"
13 #include "window_gui.h"
14 #include "strings_func.h"
15 #include "date_func.h"
16 #include "viewport_func.h"
17 #include "gui.h"
18 #include "goal_base.h"
19 #include "core/geometry_func.hpp"
20 #include "company_func.h"
21 #include "company_base.h"
22 #include "company_gui.h"
23 #include "story_base.h"
24 #include "command_func.h"
25 #include "string_func.h"
27 #include "widgets/goal_widget.h"
29 #include "table/strings.h"
31 #include "safeguards.h"
33 /** Goal list columns. */
34 enum GoalColumn {
35 GC_GOAL = 0, ///< Goal text column.
36 GC_PROGRESS, ///< Goal progress column.
39 /** Window for displaying goals. */
40 struct GoalListWindow : public Window {
41 Scrollbar *vscroll; ///< Reference to the scrollbar widget.
43 GoalListWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc)
45 this->CreateNestedTree();
46 this->vscroll = this->GetScrollbar(WID_GOAL_SCROLLBAR);
47 this->FinishInitNested(window_number);
48 this->owner = (Owner)this->window_number;
49 NWidgetStacked *wi = this->GetWidget<NWidgetStacked>(WID_GOAL_SELECT_BUTTONS);
50 wi->SetDisplayedPlane(window_number == INVALID_COMPANY ? 1 : 0);
51 this->OnInvalidateData(0);
54 void SetStringParameters(int widget) const override
56 if (widget != WID_GOAL_CAPTION) return;
58 if (this->window_number == INVALID_COMPANY) {
59 SetDParam(0, STR_GOALS_SPECTATOR_CAPTION);
60 } else {
61 SetDParam(0, STR_GOALS_CAPTION);
62 SetDParam(1, this->window_number);
66 void OnClick(Point pt, int widget, int click_count) override
68 switch (widget) {
69 case WID_GOAL_GLOBAL_BUTTON:
70 ShowGoalsList(INVALID_COMPANY);
71 break;
73 case WID_GOAL_COMPANY_BUTTON:
74 ShowGoalsList(_local_company);
75 break;
77 case WID_GOAL_LIST: {
78 int y = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_GOAL_LIST, WD_FRAMERECT_TOP);
79 for (const Goal *s : Goal::Iterate()) {
80 if (s->company == this->window_number) {
81 if (y == 0) {
82 this->HandleClick(s);
83 return;
85 y--;
88 break;
91 default:
92 break;
96 /**
97 * Handle clicking at a goal.
98 * @param s #Goal clicked at.
100 void HandleClick(const Goal *s)
102 /* Determine dst coordinate for goal and try to scroll to it. */
103 TileIndex xy;
104 switch (s->type) {
105 case GT_NONE: return;
107 case GT_COMPANY:
108 /* s->dst here is not a tile, but a CompanyID.
109 * Show the window with the overview of the company instead. */
110 ShowCompany((CompanyID)s->dst);
111 return;
113 case GT_TILE:
114 if (!IsValidTile(s->dst)) return;
115 xy = s->dst;
116 break;
118 case GT_INDUSTRY:
119 if (!Industry::IsValidID(s->dst)) return;
120 xy = Industry::Get(s->dst)->location.tile;
121 break;
123 case GT_TOWN:
124 if (!Town::IsValidID(s->dst)) return;
125 xy = Town::Get(s->dst)->xy;
126 break;
128 case GT_STORY_PAGE: {
129 if (!StoryPage::IsValidID(s->dst)) return;
131 /* Verify that:
132 * - if global goal: story page must be global.
133 * - if company goal: story page must be global or of the same company.
135 CompanyID goal_company = s->company;
136 CompanyID story_company = StoryPage::Get(s->dst)->company;
137 if (goal_company == INVALID_COMPANY ? story_company != INVALID_COMPANY : story_company != INVALID_COMPANY && story_company != goal_company) return;
139 ShowStoryBook((CompanyID)this->window_number, s->dst);
140 return;
143 default: NOT_REACHED();
146 if (_ctrl_pressed) {
147 ShowExtraViewportWindow(xy);
148 } else {
149 ScrollMainWindowToTile(xy);
154 * Count the number of lines in this window.
155 * @return the number of lines.
157 uint CountLines()
159 /* Count number of (non) awarded goals. */
160 uint num = 0;
161 for (const Goal *s : Goal::Iterate()) {
162 if (s->company == this->window_number) num++;
165 /* Count the 'none' lines. */
166 if (num == 0) num = 1;
168 return num;
171 void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
173 if (widget != WID_GOAL_LIST) return;
174 Dimension d = GetStringBoundingBox(STR_GOALS_NONE);
176 resize->height = d.height;
178 d.height *= 5;
179 d.width += padding.width + WD_FRAMERECT_RIGHT + WD_FRAMERECT_LEFT;
180 d.height += padding.height + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
181 *size = maxdim(*size, d);
185 * Draws a given column of the goal list.
186 * @param column Which column to draw.
187 * @param wid Pointer to the goal list widget.
188 * @param progress_col_width Width of the progress column.
189 * @return max width of drawn text
191 void DrawListColumn(GoalColumn column, NWidgetBase *wid, uint progress_col_width) const
193 /* Get column draw area. */
194 int y = wid->pos_y + WD_FRAMERECT_TOP;
195 int x = wid->pos_x + WD_FRAMERECT_LEFT;
196 int right = x + wid->current_x - WD_FRAMERECT_RIGHT;
197 bool rtl = _current_text_dir == TD_RTL;
199 int pos = -this->vscroll->GetPosition();
200 const int cap = this->vscroll->GetCapacity();
202 uint num = 0;
203 for (const Goal *s : Goal::Iterate()) {
204 if (s->company == this->window_number) {
205 if (IsInsideMM(pos, 0, cap)) {
206 switch (column) {
207 case GC_GOAL: {
208 /* Display the goal. */
209 SetDParamStr(0, s->text);
210 uint width_reduction = progress_col_width > 0 ? progress_col_width + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT : 0;
211 DrawString(x + (rtl ? width_reduction : 0), right - (rtl ? 0 : width_reduction), y + pos * FONT_HEIGHT_NORMAL, STR_GOALS_TEXT);
212 break;
215 case GC_PROGRESS:
216 if (s->progress != nullptr) {
217 SetDParamStr(0, s->progress);
218 StringID str = s->completed ? STR_GOALS_PROGRESS_COMPLETE : STR_GOALS_PROGRESS;
219 int progress_x = x;
220 int progress_right = rtl ? x + progress_col_width : right;
221 DrawString(progress_x, progress_right, y + pos * FONT_HEIGHT_NORMAL, str, TC_FROMSTRING, SA_RIGHT | SA_FORCE);
223 break;
226 pos++;
227 num++;
231 if (num == 0) {
232 if (column == GC_GOAL && IsInsideMM(pos, 0, cap)) {
233 DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, STR_GOALS_NONE);
235 pos++;
239 void OnPaint() override
241 this->DrawWidgets();
243 if (this->IsShaded()) return; // Don't draw anything when the window is shaded.
245 /* Calculate progress column width. */
246 uint max_width = 0;
247 for (const Goal *s : Goal::Iterate()) {
248 if (s->progress != nullptr) {
249 SetDParamStr(0, s->progress);
250 StringID str = s->completed ? STR_GOALS_PROGRESS_COMPLETE : STR_GOALS_PROGRESS;
251 uint str_width = GetStringBoundingBox(str).width;
252 if (str_width > max_width) max_width = str_width;
256 NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_GOAL_LIST);
257 uint progress_col_width = std::min(max_width, wid->current_x);
259 /* Draw goal list. */
260 this->DrawListColumn(GC_PROGRESS, wid, progress_col_width);
261 this->DrawListColumn(GC_GOAL, wid, progress_col_width);
265 void OnResize() override
267 this->vscroll->SetCapacityFromWidget(this, WID_GOAL_LIST);
271 * Some data on this window has become invalid.
272 * @param data Information about the changed data.
273 * @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.
275 void OnInvalidateData(int data = 0, bool gui_scope = true) override
277 if (!gui_scope) return;
278 this->vscroll->SetCount(this->CountLines());
279 this->SetWidgetDisabledState(WID_GOAL_COMPANY_BUTTON, _local_company == COMPANY_SPECTATOR);
280 this->SetWidgetDirty(WID_GOAL_COMPANY_BUTTON);
281 this->SetWidgetDirty(WID_GOAL_LIST);
285 /** Widgets of the #GoalListWindow. */
286 static const NWidgetPart _nested_goals_list_widgets[] = {
287 NWidget(NWID_HORIZONTAL),
288 NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
289 NWidget(WWT_CAPTION, COLOUR_BROWN, WID_GOAL_CAPTION), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
290 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GOAL_SELECT_BUTTONS),
291 NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_GOAL_GLOBAL_BUTTON), SetMinimalSize(50, 0), SetMinimalTextLines(1, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + 2), SetDataTip(STR_GOALS_GLOBAL_BUTTON, STR_GOALS_GLOBAL_BUTTON_HELPTEXT),
292 NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_GOAL_COMPANY_BUTTON), SetMinimalSize(50, 0), SetMinimalTextLines(1, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + 2), SetDataTip(STR_GOALS_COMPANY_BUTTON, STR_GOALS_COMPANY_BUTTON_HELPTEXT),
293 EndContainer(),
294 NWidget(WWT_SHADEBOX, COLOUR_BROWN),
295 NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
296 NWidget(WWT_STICKYBOX, COLOUR_BROWN),
297 EndContainer(),
298 NWidget(NWID_HORIZONTAL),
299 NWidget(WWT_PANEL, COLOUR_BROWN), SetDataTip(0x0, STR_GOALS_TOOLTIP_CLICK_ON_SERVICE_TO_CENTER), SetScrollbar(WID_GOAL_SCROLLBAR),
300 NWidget(WWT_EMPTY, COLOUR_GREY, WID_GOAL_LIST), SetResize(1, 1), SetMinimalTextLines(2, 0), SetFill(1, 1), SetPadding(WD_FRAMERECT_TOP, 2, WD_FRAMETEXT_BOTTOM, 2),
301 EndContainer(),
302 NWidget(NWID_VERTICAL),
303 NWidget(NWID_VSCROLLBAR, COLOUR_BROWN, WID_GOAL_SCROLLBAR),
304 NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
305 EndContainer(),
306 EndContainer(),
309 static WindowDesc _goals_list_desc(
310 WDP_AUTO, "list_goals", 500, 127,
311 WC_GOALS_LIST, WC_NONE,
313 _nested_goals_list_widgets, lengthof(_nested_goals_list_widgets)
317 * Open a goal list window.
318 * @param company %Company to display the goals for, use #INVALID_COMPANY to display global goals.
320 void ShowGoalsList(CompanyID company)
322 if (!Company::IsValidID(company)) company = (CompanyID)INVALID_COMPANY;
324 AllocateWindowDescFront<GoalListWindow>(&_goals_list_desc, company);
327 /** Ask a question about a goal. */
328 struct GoalQuestionWindow : public Window {
329 char *question; ///< Question to ask (private copy).
330 int buttons; ///< Number of valid buttons in #button.
331 int button[3]; ///< Buttons to display.
332 TextColour colour; ///< Colour of the question text.
334 GoalQuestionWindow(WindowDesc *desc, WindowNumber window_number, TextColour colour, uint32 button_mask, const char *question) : Window(desc), colour(colour)
336 this->question = stredup(question);
338 /* Figure out which buttons we have to enable. */
339 int n = 0;
340 for (uint bit : SetBitIterator(button_mask)) {
341 if (bit >= GOAL_QUESTION_BUTTON_COUNT) break;
342 this->button[n++] = bit;
343 if (n == 3) break;
345 this->buttons = n;
346 assert(this->buttons < 4);
348 this->CreateNestedTree();
349 if (this->buttons == 0) {
350 this->GetWidget<NWidgetStacked>(WID_GQ_BUTTONS)->SetDisplayedPlane(SZSP_HORIZONTAL);
351 this->GetWidget<NWidgetStacked>(WID_GQ_BUTTON_SPACER)->SetDisplayedPlane(SZSP_HORIZONTAL);
352 } else {
353 this->GetWidget<NWidgetStacked>(WID_GQ_BUTTONS)->SetDisplayedPlane(this->buttons - 1);
354 this->GetWidget<NWidgetStacked>(WID_GQ_BUTTON_SPACER)->SetDisplayedPlane(0);
356 this->FinishInitNested(window_number);
359 ~GoalQuestionWindow()
361 free(this->question);
364 void SetStringParameters(int widget) const override
366 switch (widget) {
367 case WID_GQ_BUTTON_1:
368 SetDParam(0, STR_GOAL_QUESTION_BUTTON_CANCEL + this->button[0]);
369 break;
371 case WID_GQ_BUTTON_2:
372 SetDParam(0, STR_GOAL_QUESTION_BUTTON_CANCEL + this->button[1]);
373 break;
375 case WID_GQ_BUTTON_3:
376 SetDParam(0, STR_GOAL_QUESTION_BUTTON_CANCEL + this->button[2]);
377 break;
381 void OnClick(Point pt, int widget, int click_count) override
383 switch (widget) {
384 case WID_GQ_BUTTON_1:
385 DoCommandP(0, this->window_number, this->button[0], CMD_GOAL_QUESTION_ANSWER);
386 this->Close();
387 break;
389 case WID_GQ_BUTTON_2:
390 DoCommandP(0, this->window_number, this->button[1], CMD_GOAL_QUESTION_ANSWER);
391 this->Close();
392 break;
394 case WID_GQ_BUTTON_3:
395 DoCommandP(0, this->window_number, this->button[2], CMD_GOAL_QUESTION_ANSWER);
396 this->Close();
397 break;
401 void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
403 if (widget != WID_GQ_QUESTION) return;
405 SetDParamStr(0, this->question);
406 size->height = GetStringHeight(STR_JUST_RAW_STRING, size->width) + WD_PAR_VSEP_WIDE;
409 void DrawWidget(const Rect &r, int widget) const override
411 if (widget != WID_GQ_QUESTION) return;
413 SetDParamStr(0, this->question);
414 DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, STR_JUST_RAW_STRING, this->colour, SA_TOP | SA_HOR_CENTER);
418 /** Widgets of the goal question window. */
419 static const NWidgetPart _nested_goal_question_widgets_question[] = {
420 NWidget(NWID_HORIZONTAL),
421 NWidget(WWT_CLOSEBOX, COLOUR_LIGHT_BLUE),
422 NWidget(WWT_CAPTION, COLOUR_LIGHT_BLUE, WID_GQ_CAPTION), SetDataTip(STR_GOAL_QUESTION_CAPTION_QUESTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
423 EndContainer(),
424 NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE),
425 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GQ_QUESTION), SetMinimalSize(300, 0), SetPadding(8, 8, 8, 8), SetFill(1, 0),
426 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GQ_BUTTONS),
427 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(85, 10, 85),
428 NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
429 EndContainer(),
430 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(65, 10, 65),
431 NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
432 NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_2), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
433 EndContainer(),
434 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(25, 10, 25),
435 NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
436 NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_2), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
437 NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_3), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
438 EndContainer(),
439 EndContainer(),
440 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GQ_BUTTON_SPACER),
441 NWidget(NWID_SPACER), SetMinimalSize(0, 8),
442 EndContainer(),
443 EndContainer(),
446 static const NWidgetPart _nested_goal_question_widgets_info[] = {
447 NWidget(NWID_HORIZONTAL),
448 NWidget(WWT_CLOSEBOX, COLOUR_LIGHT_BLUE),
449 NWidget(WWT_CAPTION, COLOUR_LIGHT_BLUE, WID_GQ_CAPTION), SetDataTip(STR_GOAL_QUESTION_CAPTION_INFORMATION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
450 EndContainer(),
451 NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE),
452 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GQ_QUESTION), SetMinimalSize(300, 0), SetPadding(8, 8, 8, 8), SetFill(1, 0),
453 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GQ_BUTTONS),
454 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(85, 10, 85),
455 NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
456 EndContainer(),
457 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(65, 10, 65),
458 NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
459 NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_2), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
460 EndContainer(),
461 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(25, 10, 25),
462 NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
463 NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_2), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
464 NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_3), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
465 EndContainer(),
466 EndContainer(),
467 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GQ_BUTTON_SPACER),
468 NWidget(NWID_SPACER), SetMinimalSize(0, 8),
469 EndContainer(),
470 EndContainer(),
473 static const NWidgetPart _nested_goal_question_widgets_warning[] = {
474 NWidget(NWID_HORIZONTAL),
475 NWidget(WWT_CLOSEBOX, COLOUR_YELLOW),
476 NWidget(WWT_CAPTION, COLOUR_YELLOW, WID_GQ_CAPTION), SetDataTip(STR_GOAL_QUESTION_CAPTION_WARNING, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
477 EndContainer(),
478 NWidget(WWT_PANEL, COLOUR_YELLOW),
479 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GQ_QUESTION), SetMinimalSize(300, 0), SetPadding(8, 8, 8, 8), SetFill(1, 0),
480 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GQ_BUTTONS),
481 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(85, 10, 85),
482 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
483 EndContainer(),
484 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(65, 10, 65),
485 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
486 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_2), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
487 EndContainer(),
488 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(25, 10, 25),
489 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
490 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_2), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
491 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_3), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
492 EndContainer(),
493 EndContainer(),
494 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GQ_BUTTON_SPACER),
495 NWidget(NWID_SPACER), SetMinimalSize(0, 8),
496 EndContainer(),
497 EndContainer(),
500 static const NWidgetPart _nested_goal_question_widgets_error[] = {
501 NWidget(NWID_HORIZONTAL),
502 NWidget(WWT_CLOSEBOX, COLOUR_RED),
503 NWidget(WWT_CAPTION, COLOUR_RED, WID_GQ_CAPTION), SetDataTip(STR_GOAL_QUESTION_CAPTION_ERROR, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
504 EndContainer(),
505 NWidget(WWT_PANEL, COLOUR_RED),
506 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GQ_QUESTION), SetMinimalSize(300, 0), SetPadding(8, 8, 8, 8), SetFill(1, 0),
507 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GQ_BUTTONS),
508 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(85, 10, 85),
509 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
510 EndContainer(),
511 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(65, 10, 65),
512 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
513 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_2), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
514 EndContainer(),
515 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(25, 10, 25),
516 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
517 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_2), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
518 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_3), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
519 EndContainer(),
520 EndContainer(),
521 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GQ_BUTTON_SPACER),
522 NWidget(NWID_SPACER), SetMinimalSize(0, 8),
523 EndContainer(),
524 EndContainer(),
527 static WindowDesc _goal_question_list_desc[] = {
529 WDP_CENTER, nullptr, 0, 0,
530 WC_GOAL_QUESTION, WC_NONE,
531 WDF_CONSTRUCTION,
532 _nested_goal_question_widgets_question, lengthof(_nested_goal_question_widgets_question),
535 WDP_CENTER, nullptr, 0, 0,
536 WC_GOAL_QUESTION, WC_NONE,
537 WDF_CONSTRUCTION,
538 _nested_goal_question_widgets_info, lengthof(_nested_goal_question_widgets_info),
541 WDP_CENTER, nullptr, 0, 0,
542 WC_GOAL_QUESTION, WC_NONE,
543 WDF_CONSTRUCTION,
544 _nested_goal_question_widgets_warning, lengthof(_nested_goal_question_widgets_warning),
547 WDP_CENTER, nullptr, 0, 0,
548 WC_GOAL_QUESTION, WC_NONE,
549 WDF_CONSTRUCTION,
550 _nested_goal_question_widgets_error, lengthof(_nested_goal_question_widgets_error),
555 * Display a goal question.
556 * @param id Window number to use.
557 * @param type Type of question.
558 * @param button_mask Buttons to display.
559 * @param question Question to ask.
561 void ShowGoalQuestion(uint16 id, byte type, uint32 button_mask, const char *question)
563 assert(type < GQT_END);
564 new GoalQuestionWindow(&_goal_question_list_desc[type], id, type == 3 ? TC_WHITE : TC_BLACK, button_mask, question);