OpenTTD Source  1.11.0-beta2
goal_gui.cpp
Go to the documentation of this file.
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  */
7 
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"
26 
27 #include "widgets/goal_widget.h"
28 
29 #include "table/strings.h"
30 
31 #include "safeguards.h"
32 
34 enum GoalColumn {
35  GC_GOAL = 0,
37 };
38 
40 struct GoalListWindow : public Window {
42 
44  {
45  this->CreateNestedTree();
46  this->vscroll = this->GetScrollbar(WID_GOAL_SCROLLBAR);
47  this->FinishInitNested(window_number);
48  this->owner = (Owner)this->window_number;
49  this->OnInvalidateData(0);
50  }
51 
52  void SetStringParameters(int widget) const override
53  {
54  if (widget != WID_GOAL_CAPTION) return;
55 
56  if (this->window_number == INVALID_COMPANY) {
57  SetDParam(0, STR_GOALS_SPECTATOR_CAPTION);
58  } else {
59  SetDParam(0, STR_GOALS_CAPTION);
60  SetDParam(1, this->window_number);
61  }
62  }
63 
64  void OnClick(Point pt, int widget, int click_count) override
65  {
66  if (widget != WID_GOAL_LIST) return;
67 
68  int y = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_GOAL_LIST, WD_FRAMERECT_TOP);
69  int num = 0;
70  for (const Goal *s : Goal::Iterate()) {
71  if (s->company == INVALID_COMPANY) {
72  y--;
73  if (y == 0) {
74  this->HandleClick(s);
75  return;
76  }
77  num++;
78  }
79  }
80 
81  if (num == 0) {
82  y--; // "None" line.
83  if (y < 0) return;
84  }
85 
86  y -= 2; // "Company specific goals:" line.
87  if (y < 0) return;
88 
89  for (const Goal *s : Goal::Iterate()) {
90  if (s->company == this->window_number && s->company != INVALID_COMPANY) {
91  y--;
92  if (y == 0) {
93  this->HandleClick(s);
94  return;
95  }
96  }
97  }
98  }
99 
104  void HandleClick(const Goal *s)
105  {
106  /* Determine dst coordinate for goal and try to scroll to it. */
107  TileIndex xy;
108  switch (s->type) {
109  case GT_NONE: return;
110 
111  case GT_COMPANY:
112  /* s->dst here is not a tile, but a CompanyID.
113  * Show the window with the overview of the company instead. */
115  return;
116 
117  case GT_TILE:
118  if (!IsValidTile(s->dst)) return;
119  xy = s->dst;
120  break;
121 
122  case GT_INDUSTRY:
123  if (!Industry::IsValidID(s->dst)) return;
124  xy = Industry::Get(s->dst)->location.tile;
125  break;
126 
127  case GT_TOWN:
128  if (!Town::IsValidID(s->dst)) return;
129  xy = Town::Get(s->dst)->xy;
130  break;
131 
132  case GT_STORY_PAGE: {
133  if (!StoryPage::IsValidID(s->dst)) return;
134 
135  /* Verify that:
136  * - if global goal: story page must be global.
137  * - if company goal: story page must be global or of the same company.
138  */
139  CompanyID goal_company = s->company;
140  CompanyID story_company = StoryPage::Get(s->dst)->company;
141  if (goal_company == INVALID_COMPANY ? story_company != INVALID_COMPANY : story_company != INVALID_COMPANY && story_company != goal_company) return;
142 
144  return;
145  }
146 
147  default: NOT_REACHED();
148  }
149 
150  if (_ctrl_pressed) {
152  } else {
154  }
155  }
156 
161  uint CountLines()
162  {
163  /* Count number of (non) awarded goals. */
164  uint num_global = 0;
165  uint num_company = 0;
166  for (const Goal *s : Goal::Iterate()) {
167  if (s->company == INVALID_COMPANY) {
168  num_global++;
169  } else if (s->company == this->window_number) {
170  num_company++;
171  }
172  }
173 
174  /* Count the 'none' lines. */
175  if (num_global == 0) num_global = 1;
176  if (num_company == 0) num_company = 1;
177 
178  /* Global, company and an empty line before the accepted ones. */
179  return 3 + num_global + num_company;
180  }
181 
182  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
183  {
184  if (widget != WID_GOAL_LIST) return;
185  Dimension d = maxdim(GetStringBoundingBox(STR_GOALS_GLOBAL_TITLE), GetStringBoundingBox(STR_GOALS_COMPANY_TITLE));
186 
187  resize->height = d.height;
188 
189  d.height *= 5;
190  d.width += padding.width + WD_FRAMERECT_RIGHT + WD_FRAMERECT_LEFT;
191  d.height += padding.height + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
192  *size = maxdim(*size, d);
193  }
194 
206  void DrawPartialGoalList(int &pos, const int cap, int x, int y, int right, uint progress_col_width, bool global_section, GoalColumn column) const
207  {
208  if (column == GC_GOAL && IsInsideMM(pos, 0, cap)) DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, global_section ? STR_GOALS_GLOBAL_TITLE : STR_GOALS_COMPANY_TITLE);
209  pos++;
210 
211  bool rtl = _current_text_dir == TD_RTL;
212 
213  uint num = 0;
214  for (const Goal *s : Goal::Iterate()) {
215  if (global_section ? s->company == INVALID_COMPANY : (s->company == this->window_number && s->company != INVALID_COMPANY)) {
216  if (IsInsideMM(pos, 0, cap)) {
217  switch (column) {
218  case GC_GOAL: {
219  /* Display the goal. */
220  SetDParamStr(0, s->text);
221  uint width_reduction = progress_col_width > 0 ? progress_col_width + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT : 0;
222  DrawString(x + (rtl ? width_reduction : 0), right - (rtl ? 0 : width_reduction), y + pos * FONT_HEIGHT_NORMAL, STR_GOALS_TEXT);
223  break;
224  }
225 
226  case GC_PROGRESS:
227  if (s->progress != nullptr) {
228  SetDParamStr(0, s->progress);
229  StringID str = s->completed ? STR_GOALS_PROGRESS_COMPLETE : STR_GOALS_PROGRESS;
230  int progress_x = x;
231  int progress_right = rtl ? x + progress_col_width : right;
232  DrawString(progress_x, progress_right, y + pos * FONT_HEIGHT_NORMAL, str, TC_FROMSTRING, SA_RIGHT | SA_FORCE);
233  }
234  break;
235  }
236  }
237  pos++;
238  num++;
239  }
240  }
241 
242  if (num == 0) {
243  if (column == GC_GOAL && IsInsideMM(pos, 0, cap)) {
244  StringID str = !global_section && this->window_number == INVALID_COMPANY ? STR_GOALS_SPECTATOR_NONE : STR_GOALS_NONE;
245  DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, str);
246  }
247  pos++;
248  }
249  }
250 
258  void DrawListColumn(GoalColumn column, NWidgetBase *wid, uint progress_col_width) const
259  {
260  /* Get column draw area. */
261  int y = wid->pos_y + WD_FRAMERECT_TOP;
262  int x = wid->pos_x + WD_FRAMERECT_LEFT;
263  int right = x + wid->current_x - WD_FRAMERECT_RIGHT;
264 
265  int pos = -this->vscroll->GetPosition();
266  const int cap = this->vscroll->GetCapacity();
267 
268  /* Draw partial list with global goals. */
269  DrawPartialGoalList(pos, cap, x, y, right, progress_col_width, true, column);
270 
271  /* Draw partial list with company goals. */
272  pos++;
273  DrawPartialGoalList(pos, cap, x, y, right, progress_col_width, false, column);
274  }
275 
276  void OnPaint() override
277  {
278  this->DrawWidgets();
279 
280  if (this->IsShaded()) return; // Don't draw anything when the window is shaded.
281 
282  /* Calculate progress column width. */
283  uint max_width = 0;
284  for (const Goal *s : Goal::Iterate()) {
285  if (s->progress != nullptr) {
286  SetDParamStr(0, s->progress);
287  StringID str = s->completed ? STR_GOALS_PROGRESS_COMPLETE : STR_GOALS_PROGRESS;
288  uint str_width = GetStringBoundingBox(str).width;
289  if (str_width > max_width) max_width = str_width;
290  }
291  }
292 
293  NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_GOAL_LIST);
294  uint progress_col_width = std::min(max_width, wid->current_x);
295 
296  /* Draw goal list. */
297  this->DrawListColumn(GC_PROGRESS, wid, progress_col_width);
298  this->DrawListColumn(GC_GOAL, wid, progress_col_width);
299 
300  }
301 
302  void OnResize() override
303  {
304  this->vscroll->SetCapacityFromWidget(this, WID_GOAL_LIST);
305  }
306 
312  void OnInvalidateData(int data = 0, bool gui_scope = true) override
313  {
314  if (!gui_scope) return;
315  this->vscroll->SetCount(this->CountLines());
317  }
318 };
319 
323  NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
324  NWidget(WWT_CAPTION, COLOUR_BROWN, WID_GOAL_CAPTION), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
325  NWidget(WWT_SHADEBOX, COLOUR_BROWN),
326  NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
327  NWidget(WWT_STICKYBOX, COLOUR_BROWN),
328  EndContainer(),
330  NWidget(WWT_PANEL, COLOUR_BROWN), SetDataTip(0x0, STR_GOALS_TOOLTIP_CLICK_ON_SERVICE_TO_CENTER), SetScrollbar(WID_GOAL_SCROLLBAR),
332  EndContainer(),
335  NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
336  EndContainer(),
337  EndContainer(),
338 };
339 
340 static WindowDesc _goals_list_desc(
341  WDP_AUTO, "list_goals", 500, 127,
343  0,
345 );
346 
352 {
353  if (!Company::IsValidID(company)) company = (CompanyID)INVALID_COMPANY;
354 
355  AllocateWindowDescFront<GoalListWindow>(&_goals_list_desc, company);
356 }
357 
359 struct GoalQuestionWindow : public Window {
360  char *question;
361  int buttons;
362  int button[3];
364 
365  GoalQuestionWindow(WindowDesc *desc, WindowNumber window_number, TextColour colour, uint32 button_mask, const char *question) : Window(desc), colour(colour)
366  {
367  this->question = stredup(question);
368 
369  /* Figure out which buttons we have to enable. */
370  uint bit;
371  int n = 0;
372  FOR_EACH_SET_BIT(bit, button_mask) {
373  if (bit >= GOAL_QUESTION_BUTTON_COUNT) break;
374  this->button[n++] = bit;
375  if (n == 3) break;
376  }
377  this->buttons = n;
378  assert(this->buttons < 4);
379 
380  this->CreateNestedTree();
381  if (this->buttons == 0) {
382  this->GetWidget<NWidgetStacked>(WID_GQ_BUTTONS)->SetDisplayedPlane(SZSP_HORIZONTAL);
383  this->GetWidget<NWidgetStacked>(WID_GQ_BUTTON_SPACER)->SetDisplayedPlane(SZSP_HORIZONTAL);
384  } else {
385  this->GetWidget<NWidgetStacked>(WID_GQ_BUTTONS)->SetDisplayedPlane(this->buttons - 1);
386  this->GetWidget<NWidgetStacked>(WID_GQ_BUTTON_SPACER)->SetDisplayedPlane(0);
387  }
388  this->FinishInitNested(window_number);
389  }
390 
392  {
393  free(this->question);
394  }
395 
396  void SetStringParameters(int widget) const override
397  {
398  switch (widget) {
399  case WID_GQ_BUTTON_1:
400  SetDParam(0, STR_GOAL_QUESTION_BUTTON_CANCEL + this->button[0]);
401  break;
402 
403  case WID_GQ_BUTTON_2:
404  SetDParam(0, STR_GOAL_QUESTION_BUTTON_CANCEL + this->button[1]);
405  break;
406 
407  case WID_GQ_BUTTON_3:
408  SetDParam(0, STR_GOAL_QUESTION_BUTTON_CANCEL + this->button[2]);
409  break;
410  }
411  }
412 
413  void OnClick(Point pt, int widget, int click_count) override
414  {
415  switch (widget) {
416  case WID_GQ_BUTTON_1:
417  DoCommandP(0, this->window_number, this->button[0], CMD_GOAL_QUESTION_ANSWER);
418  delete this;
419  break;
420 
421  case WID_GQ_BUTTON_2:
422  DoCommandP(0, this->window_number, this->button[1], CMD_GOAL_QUESTION_ANSWER);
423  delete this;
424  break;
425 
426  case WID_GQ_BUTTON_3:
427  DoCommandP(0, this->window_number, this->button[2], CMD_GOAL_QUESTION_ANSWER);
428  delete this;
429  break;
430  }
431  }
432 
433  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
434  {
435  if (widget != WID_GQ_QUESTION) return;
436 
437  SetDParamStr(0, this->question);
438  size->height = GetStringHeight(STR_JUST_RAW_STRING, size->width) + WD_PAR_VSEP_WIDE;
439  }
440 
441  void DrawWidget(const Rect &r, int widget) const override
442  {
443  if (widget != WID_GQ_QUESTION) return;
444 
445  SetDParamStr(0, this->question);
446  DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, STR_JUST_RAW_STRING, this->colour, SA_TOP | SA_HOR_CENTER);
447  }
448 };
449 
453  NWidget(WWT_CLOSEBOX, COLOUR_LIGHT_BLUE),
454  NWidget(WWT_CAPTION, COLOUR_LIGHT_BLUE, WID_GQ_CAPTION), SetDataTip(STR_GOAL_QUESTION_CAPTION_QUESTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
455  EndContainer(),
456  NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE),
457  NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GQ_QUESTION), SetMinimalSize(300, 0), SetPadding(8, 8, 8, 8), SetFill(1, 0),
458  NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GQ_BUTTONS),
460  NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
461  EndContainer(),
463  NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
464  NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_2), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
465  EndContainer(),
467  NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
468  NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_2), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
469  NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_3), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
470  EndContainer(),
471  EndContainer(),
472  NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GQ_BUTTON_SPACER),
474  EndContainer(),
475  EndContainer(),
476 };
477 
478 static const NWidgetPart _nested_goal_question_widgets_info[] = {
480  NWidget(WWT_CLOSEBOX, COLOUR_LIGHT_BLUE),
481  NWidget(WWT_CAPTION, COLOUR_LIGHT_BLUE, WID_GQ_CAPTION), SetDataTip(STR_GOAL_QUESTION_CAPTION_INFORMATION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
482  EndContainer(),
483  NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE),
484  NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GQ_QUESTION), SetMinimalSize(300, 0), SetPadding(8, 8, 8, 8), SetFill(1, 0),
485  NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GQ_BUTTONS),
487  NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
488  EndContainer(),
490  NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
491  NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_2), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
492  EndContainer(),
494  NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
495  NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_2), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
496  NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_3), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
497  EndContainer(),
498  EndContainer(),
499  NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GQ_BUTTON_SPACER),
501  EndContainer(),
502  EndContainer(),
503 };
504 
505 static const NWidgetPart _nested_goal_question_widgets_warning[] = {
507  NWidget(WWT_CLOSEBOX, COLOUR_YELLOW),
508  NWidget(WWT_CAPTION, COLOUR_YELLOW, WID_GQ_CAPTION), SetDataTip(STR_GOAL_QUESTION_CAPTION_WARNING, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
509  EndContainer(),
510  NWidget(WWT_PANEL, COLOUR_YELLOW),
511  NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GQ_QUESTION), SetMinimalSize(300, 0), SetPadding(8, 8, 8, 8), SetFill(1, 0),
512  NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GQ_BUTTONS),
514  NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
515  EndContainer(),
517  NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
518  NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_2), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
519  EndContainer(),
521  NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
522  NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_2), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
523  NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_3), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
524  EndContainer(),
525  EndContainer(),
526  NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GQ_BUTTON_SPACER),
528  EndContainer(),
529  EndContainer(),
530 };
531 
532 static const NWidgetPart _nested_goal_question_widgets_error[] = {
534  NWidget(WWT_CLOSEBOX, COLOUR_RED),
535  NWidget(WWT_CAPTION, COLOUR_RED, WID_GQ_CAPTION), SetDataTip(STR_GOAL_QUESTION_CAPTION_ERROR, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
536  EndContainer(),
537  NWidget(WWT_PANEL, COLOUR_RED),
538  NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GQ_QUESTION), SetMinimalSize(300, 0), SetPadding(8, 8, 8, 8), SetFill(1, 0),
539  NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GQ_BUTTONS),
541  NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
542  EndContainer(),
544  NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
545  NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_2), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
546  EndContainer(),
548  NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
549  NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_2), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
550  NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_3), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
551  EndContainer(),
552  EndContainer(),
553  NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GQ_BUTTON_SPACER),
555  EndContainer(),
556  EndContainer(),
557 };
558 
559 static WindowDesc _goal_question_list_desc[] = {
560  {
561  WDP_CENTER, nullptr, 0, 0,
565  },
566  {
567  WDP_CENTER, nullptr, 0, 0,
570  _nested_goal_question_widgets_info, lengthof(_nested_goal_question_widgets_info),
571  },
572  {
573  WDP_CENTER, nullptr, 0, 0,
576  _nested_goal_question_widgets_warning, lengthof(_nested_goal_question_widgets_warning),
577  },
578  {
579  WDP_CENTER, nullptr, 0, 0,
582  _nested_goal_question_widgets_error, lengthof(_nested_goal_question_widgets_error),
583  },
584 };
585 
593 void ShowGoalQuestion(uint16 id, byte type, uint32 button_mask, const char *question)
594 {
595  assert(type < GQT_END);
596  new GoalQuestionWindow(&_goal_question_list_desc[type], id, type == 3 ? TC_WHITE : TC_BLACK, button_mask, question);
597 }
GoalListWindow
Window for displaying goals.
Definition: goal_gui.cpp:40
GoalListWindow::UpdateWidgetSize
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Definition: goal_gui.cpp:182
WD_FRAMERECT_TOP
@ WD_FRAMERECT_TOP
Offset at top to draw the frame rectangular area.
Definition: window_gui.h:62
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:78
Goal
Struct about goals, current and completed.
Definition: goal_base.h:21
Pool::PoolItem<&_industry_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:329
ScrollMainWindowToTile
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Definition: viewport.cpp:2443
GoalListWindow::DrawPartialGoalList
void DrawPartialGoalList(int &pos, const int cap, int x, int y, int right, uint progress_col_width, bool global_section, GoalColumn column) const
Draws either the global goals or the company goal section.
Definition: goal_gui.cpp:206
ShowGoalsList
void ShowGoalsList(CompanyID company)
Open a goal list window.
Definition: goal_gui.cpp:351
SetScrollbar
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1094
ShowExtraViewportWindow
void ShowExtraViewportWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
Definition: viewport_gui.cpp:168
GoalColumn
GoalColumn
Goal list columns.
Definition: goal_gui.cpp:34
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:27
Scrollbar::GetCapacity
uint16 GetCapacity() const
Gets the number of visible elements of the scrollbar.
Definition: widget_type.h:621
command_func.h
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:64
SetPadding
static NWidgetPart SetPadding(uint8 top, uint8 right, uint8 bottom, uint8 left)
Widget part function for setting additional space around a widget.
Definition: widget_type.h:1045
Window::GetScrollbar
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:309
WDF_CONSTRUCTION
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
Definition: window_gui.h:208
ShowStoryBook
void ShowStoryBook(CompanyID company, uint16 page_id=INVALID_STORY_PAGE)
Raise or create the story book window for company, at page page_id.
Definition: story_gui.cpp:1062
GT_INDUSTRY
@ GT_INDUSTRY
Destination is an industry.
Definition: goal_type.h:29
company_base.h
WID_GQ_BUTTONS
@ WID_GQ_BUTTONS
Buttons selection (between 1, 2 or 3).
Definition: goal_widget.h:25
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:59
GoalListWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: goal_gui.cpp:312
company_gui.h
GoalListWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: goal_gui.cpp:276
Scrollbar::GetScrolledRowFromWidget
int GetScrolledRowFromWidget(int clickpos, const Window *const w, int widget, int padding=0, int line_height=-1) const
Compute the row of a scrolled widget that a user clicked in.
Definition: widget.cpp:1966
SA_RIGHT
@ SA_RIGHT
Right align the text (must be a single bit).
Definition: gfx_func.h:98
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition: widget_type.h:63
Window::CreateNestedTree
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1832
WID_GQ_CAPTION
@ WID_GQ_CAPTION
Caption of the window.
Definition: goal_widget.h:23
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:73
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition: geometry_func.cpp:22
GT_TILE
@ GT_TILE
Destination is a tile.
Definition: goal_type.h:28
GoalListWindow::HandleClick
void HandleClick(const Goal *s)
Handle clicking at a goal.
Definition: goal_gui.cpp:104
_nested_goal_question_widgets_question
static const NWidgetPart _nested_goal_question_widgets_question[]
Widgets of the goal question window.
Definition: goal_gui.cpp:451
Scrollbar::SetCount
void SetCount(int num)
Sets the number of elements in the list.
Definition: widget_type.h:669
WID_GOAL_SCROLLBAR
@ WID_GOAL_SCROLLBAR
Scrollbar of the goal list.
Definition: goal_widget.h:18
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:35
GC_PROGRESS
@ GC_PROGRESS
Goal progress column.
Definition: goal_gui.cpp:36
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:250
SetResize
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:929
goal_base.h
DrawString
int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition: gfx.cpp:640
SZSP_HORIZONTAL
@ SZSP_HORIZONTAL
Display plane with zero size vertically, and filling and resizing horizontally.
Definition: widget_type.h:388
WWT_EMPTY
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget array.
Definition: widget_type.h:46
town.h
Window::owner
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
Definition: window_gui.h:324
WindowNumber
int32 WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:711
Goal::dst
GoalTypeID dst
Index of type.
Definition: goal_base.h:24
WC_GOALS_LIST
@ WC_GOALS_LIST
Goals list; Window numbers:
Definition: window_type.h:283
SA_FORCE
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
Definition: gfx_func.h:108
SA_HOR_CENTER
@ SA_HOR_CENTER
Horizontally center the text.
Definition: gfx_func.h:97
WID_GQ_BUTTON_3
@ WID_GQ_BUTTON_3
Third button.
Definition: goal_widget.h:28
GoalQuestionWindow
Ask a question about a goal.
Definition: goal_gui.cpp:359
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:588
SetDParam
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:199
WID_GQ_QUESTION
@ WID_GQ_QUESTION
Question text.
Definition: goal_widget.h:24
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:909
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1013
WID_GQ_BUTTON_2
@ WID_GQ_BUTTON_2
Second button.
Definition: goal_widget.h:27
GetStringBoundingBox
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:842
DrawStringMultiLine
int DrawStringMultiLine(int left, int right, int top, int bottom, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Definition: gfx.cpp:763
IsInsideMM
static bool IsInsideMM(const T x, const size_t min, const size_t max)
Checks if a value is in an interval.
Definition: math_func.hpp:204
GT_TOWN
@ GT_TOWN
Destination is a town.
Definition: goal_type.h:30
WindowDesc
High level window description.
Definition: window_gui.h:166
SA_TOP
@ SA_TOP
Top align the text.
Definition: gfx_func.h:101
window_gui.h
goal_widget.h
GoalQuestionWindow::button
int button[3]
Buttons to display.
Definition: goal_gui.cpp:362
NC_EQUALSIZE
@ NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:428
GC_GOAL
@ GC_GOAL
Goal text column.
Definition: goal_gui.cpp:35
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:154
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:322
DoCommandP
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
Definition: command.cpp:541
GoalQuestionWindow::UpdateWidgetSize
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Definition: goal_gui.cpp:433
WD_FRAMERECT_LEFT
@ WD_FRAMERECT_LEFT
Offset at left to draw the frame rectangular area.
Definition: window_gui.h:60
GoalListWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: goal_gui.cpp:52
WD_FRAMERECT_RIGHT
@ WD_FRAMERECT_RIGHT
Offset at right to draw the frame rectangular area.
Definition: window_gui.h:61
WD_FRAMERECT_BOTTOM
@ WD_FRAMERECT_BOTTOM
Offset at bottom to draw the frame rectangular area.
Definition: window_gui.h:63
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:102
NWidgetBase
Baseclass for nested widgets.
Definition: widget_type.h:124
WD_FRAMETEXT_BOTTOM
@ WD_FRAMETEXT_BOTTOM
Bottom offset of the text of the frame.
Definition: window_gui.h:73
WID_GQ_BUTTON_SPACER
@ WID_GQ_BUTTON_SPACER
Selection to hide extra padding if there are no buttons.
Definition: goal_widget.h:29
CMD_GOAL_QUESTION_ANSWER
@ CMD_GOAL_QUESTION_ANSWER
answer(s) to CMD_GOAL_QUESTION
Definition: command_type.h:289
industry.h
safeguards.h
IsValidTile
static bool IsValidTile(TileIndex tile)
Checks if a tile is valid.
Definition: tile_map.h:161
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
GoalListWindow::vscroll
Scrollbar * vscroll
Reference to the scrollbar widget.
Definition: goal_gui.cpp:41
GoalListWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: goal_gui.cpp:64
date_func.h
stdafx.h
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:312
GoalListWindow::CountLines
uint CountLines()
Count the number of lines in this window.
Definition: goal_gui.cpp:161
viewport_func.h
GT_NONE
@ GT_NONE
Destination is not linked.
Definition: goal_type.h:27
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:38
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:75
GetStringHeight
int GetStringHeight(const char *str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
Definition: gfx.cpp:689
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:67
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:66
string_func.h
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
WID_GOAL_LIST
@ WID_GOAL_LIST
Goal list.
Definition: goal_widget.h:17
EndContainer
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:998
GoalQuestionWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: goal_gui.cpp:413
Pool::PoolItem<&_goal_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:378
strings_func.h
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:82
Window::IsShaded
bool IsShaded() const
Is window shaded currently?
Definition: window_gui.h:524
GoalListWindow::DrawListColumn
void DrawListColumn(GoalColumn column, NWidgetBase *wid, uint progress_col_width) const
Draws a given column of the goal list.
Definition: goal_gui.cpp:258
NWidgetBase::pos_x
int pos_x
Horizontal position of top-left corner of the widget in the window.
Definition: widget_type.h:175
GOAL_QUESTION_BUTTON_COUNT
static const uint32 GOAL_QUESTION_BUTTON_COUNT
Amount of buttons available.
Definition: goal_type.h:15
GT_COMPANY
@ GT_COMPANY
Destination is a company.
Definition: goal_type.h:31
FONT_HEIGHT_NORMAL
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:179
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1113
geometry_func.hpp
GoalQuestionWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: goal_gui.cpp:396
SetMinimalSize
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:946
Goal::company
CompanyID company
Goal is for a specific company; INVALID_COMPANY if it is global.
Definition: goal_base.h:22
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:48
WID_GQ_BUTTON_1
@ WID_GQ_BUTTON_1
First button.
Definition: goal_widget.h:26
GoalQuestionWindow::buttons
int buttons
Number of valid buttons in button.
Definition: goal_gui.cpp:361
WC_GOAL_QUESTION
@ WC_GOAL_QUESTION
Popup with a set of buttons, designed to ask the user a question from a GameScript.
Definition: window_type.h:130
Scrollbar::GetPosition
uint16 GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:630
GT_STORY_PAGE
@ GT_STORY_PAGE
Destination is a story page.
Definition: goal_type.h:32
GoalQuestionWindow::question
char * question
Question to ask (private copy).
Definition: goal_gui.cpp:360
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1848
NWID_SPACER
@ NWID_SPACER
Invisible widget that takes some space.
Definition: widget_type.h:77
company_func.h
GoalListWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: goal_gui.cpp:302
stredup
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
Definition: string.cpp:137
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:367
Scrollbar::SetCapacityFromWidget
void SetCapacityFromWidget(Window *w, int widget, int padding=0)
Set capacity of visible elements from the size and resize properties of a widget.
Definition: widget.cpp:1980
WID_GOAL_CAPTION
@ WID_GOAL_CAPTION
Caption of the window.
Definition: goal_widget.h:16
SetPIP
static NWidgetPart SetPIP(uint8 pre, uint8 inter, uint8 post)
Widget part function for setting a pre/inter/post spaces.
Definition: widget_type.h:1075
NWidgetBase::pos_y
int pos_y
Vertical position of top-left corner of the widget in the window.
Definition: widget_type.h:176
INVALID_COMPANY
@ INVALID_COMPANY
An invalid company.
Definition: company_type.h:30
SetFill
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:982
gui.h
Window
Data structure for an opened window.
Definition: window_gui.h:276
Pool::PoolItem<&_industry_pool >::IsValidID
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:318
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:602
GoalQuestionWindow::colour
TextColour colour
Colour of the question text.
Definition: goal_gui.cpp:363
NWID_SELECTION
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition: widget_type.h:78
free
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: stdafx.h:454
story_base.h
Window::SetWidgetDirty
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:597
ShowCompany
void ShowCompany(CompanyID company)
Show the window with the overview of the company.
Definition: company_gui.cpp:2751
GoalQuestionWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: goal_gui.cpp:441
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:47
_nested_goals_list_widgets
static const NWidgetPart _nested_goals_list_widgets[]
Widgets of the GoalListWindow.
Definition: goal_gui.cpp:321
NWidgetBase::current_x
uint current_x
Current horizontal size (after resizing).
Definition: widget_type.h:172
WD_PAR_VSEP_WIDE
@ WD_PAR_VSEP_WIDE
Large amount of vertical space between two paragraphs of text.
Definition: window_gui.h:138
Goal::type
GoalType type
Type of the goal.
Definition: goal_base.h:23
WDP_CENTER
@ WDP_CENTER
Center the window.
Definition: window_gui.h:155
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:24
FOR_EACH_SET_BIT
#define FOR_EACH_SET_BIT(bitpos_var, bitset_value)
Do an operation for each set set bit in a value.
Definition: bitmath_func.hpp:361
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:48
SetDParamStr
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Definition: strings.cpp:286
ShowGoalQuestion
void ShowGoalQuestion(uint16 id, byte type, uint32 button_mask, const char *question)
Display a goal question.
Definition: goal_gui.cpp:593
SetMinimalTextLines
static NWidgetPart SetMinimalTextLines(uint8 lines, uint8 spacing, FontSize size=FS_NORMAL)
Widget part function for setting the minimal text lines.
Definition: widget_type.h:964
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:62