OpenTTD

goal_gui.cpp
Go to the documentation of this file.
1 /* $Id: goal_gui.cpp 26509 2014-04-25 15:40:32Z rubidium $ */
2
3 /*
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/>.
8 */
9
12 #include "stdafx.h"
13 #include "industry.h"
14 #include "town.h"
15 #include "window_gui.h"
16 #include "strings_func.h"
17 #include "date_func.h"
18 #include "viewport_func.h"
19 #include "gui.h"
20 #include "goal_base.h"
21 #include "core/geometry_func.hpp"
22 #include "company_func.h"
23 #include "company_base.h"
24 #include "story_base.h"
25 #include "command_func.h"
26 #include "string_func.h"
27
28 #include "widgets/goal_widget.h"
29
30 #include "table/strings.h"
31
32 #include "safeguards.h"
33
35 enum GoalColumn {
36 GC_GOAL = 0,
37 GC_PROGRESS,
38 };
39
41 struct GoalListWindow : public Window {
42 Scrollbar *vscroll;
43
44 GoalListWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc)
45 {
46 this->CreateNestedTree();
47 this->vscroll = this->GetScrollbar(WID_GOAL_SCROLLBAR);
48 this->FinishInitNested(window_number);
49 this->owner = (Owner)this->window_number;
50 this->OnInvalidateData(0);
51 }
52
53 /* virtual */ void SetStringParameters(int widget) const
54 {
55 if (widget != WID_GOAL_CAPTION) return;
56
57 if (this->window_number == INVALID_COMPANY) {
58 SetDParam(0, STR_GOALS_SPECTATOR_CAPTION);
59 } else {
60 SetDParam(0, STR_GOALS_CAPTION);
61 SetDParam(1, this->window_number);
62 }
63 }
64
65 /* virtual */ void OnClick(Point pt, int widget, int click_count)
66 {
67 if (widget != WID_GOAL_LIST) return;
68
69 int y = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_GOAL_LIST, WD_FRAMERECT_TOP);
70 int num = 0;
71 const Goal *s;
72 FOR_ALL_GOALS(s) {
73 if (s->company == INVALID_COMPANY) {
74 y--;
75 if (y == 0) {
76 this->HandleClick(s);
77 return;
78 }
79 num++;
80 }
81 }
82
83 if (num == 0) {
84 y--; // "None" line.
85 if (y < 0) return;
86 }
87
88 y -= 2; // "Company specific goals:" line.
89 if (y < 0) return;
90
91 FOR_ALL_GOALS(s) {
92 if (s->company == this->window_number) {
93 y--;
94 if (y == 0) {
95 this->HandleClick(s);
96 return;
97 }
98 }
99 }
100 }
101
106 void HandleClick(const Goal *s)
107 {
108 /* Determine dst coordinate for goal and try to scroll to it. */
109 TileIndex xy;
110 switch (s->type) {
111 case GT_NONE: return;
112 case GT_COMPANY: return;
113
114 case GT_TILE:
115 if (!IsValidTile(s->dst)) return;
116 xy = s->dst;
117 break;
118
119 case GT_INDUSTRY:
120 if (!Industry::IsValidID(s->dst)) return;
121 xy = Industry::Get(s->dst)->location.tile;
122 break;
123
124 case GT_TOWN:
125 if (!Town::IsValidID(s->dst)) return;
126 xy = Town::Get(s->dst)->xy;
127 break;
128
129 case GT_STORY_PAGE: {
130 if (!StoryPage::IsValidID(s->dst)) return;
131
132 /* Verify that:
133 * - if global goal: story page must be global.
134 * - if company goal: story page must be global or of the same company.
135 */
136 CompanyID goal_company = s->company;
137 CompanyID story_company = StoryPage::Get(s->dst)->company;
138 if (goal_company == INVALID_COMPANY ? story_company != INVALID_COMPANY : story_company != INVALID_COMPANY && story_company != goal_company) return;
139
140 ShowStoryBook((CompanyID)this->window_number, s->dst);
141 return;
142 }
143
144 default: NOT_REACHED();
145 }
146
147 if (_ctrl_pressed) {
148 ShowExtraViewPortWindow(xy);
149 } else {
150 ScrollMainWindowToTile(xy);
151 }
152 }
153
158 uint CountLines()
159 {
160 /* Count number of (non) awarded goals. */
161 uint num_global = 0;
162 uint num_company = 0;
163 const Goal *s;
164 FOR_ALL_GOALS(s) {
165 if (s->company == INVALID_COMPANY) {
166 num_global++;
167 } else if (s->company == this->window_number) {
168 num_company++;
169 }
170 }
171
172 /* Count the 'none' lines. */
173 if (num_global == 0) num_global = 1;
174 if (num_company == 0) num_company = 1;
175
176 /* Global, company and an empty line before the accepted ones. */
177 return 3 + num_global + num_company;
178 }
179
180 /* virtual */ void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
181 {
182 if (widget != WID_GOAL_LIST) return;
183 Dimension d = maxdim(GetStringBoundingBox(STR_GOALS_GLOBAL_TITLE), GetStringBoundingBox(STR_GOALS_COMPANY_TITLE));
184
185 resize->height = d.height;
186
187 d.height *= 5;
188 d.width += padding.width + WD_FRAMERECT_RIGHT + WD_FRAMERECT_LEFT;
189 d.height += padding.height + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
190 *size = maxdim(*size, d);
191 }
192
204 void DrawPartialGoalList(int &pos, const int cap, int x, int y, int right, uint progress_col_width, bool global_section, GoalColumn column) const
205 {
206 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);
207 pos++;
208
209 bool rtl = _current_text_dir == TD_RTL;
210
211 uint num = 0;
212 const Goal *s;
213 FOR_ALL_GOALS(s) {
214 if (global_section ? s->company == INVALID_COMPANY : (s->company == this->window_number && s->company != INVALID_COMPANY)) {
215 if (IsInsideMM(pos, 0, cap)) {
216 switch (column) {
217 case GC_GOAL: {
218 /* Display the goal. */
219 SetDParamStr(0, s->text);
220 uint width_reduction = progress_col_width > 0 ? progress_col_width + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT : 0;
221 DrawString(x + (rtl ? width_reduction : 0), right - (rtl ? 0 : width_reduction), y + pos * FONT_HEIGHT_NORMAL, STR_GOALS_TEXT);
222 break;
223 }
224
225 case GC_PROGRESS:
226 if (s->progress != NULL) {
227 SetDParamStr(0, s->progress);
228 StringID str = s->completed ? STR_GOALS_PROGRESS_COMPLETE : STR_GOALS_PROGRESS;
229 int progress_x = x;
230 int progress_right = rtl ? x + progress_col_width : right;
231 DrawString(progress_x, progress_right, y + pos * FONT_HEIGHT_NORMAL, str, TC_FROMSTRING, SA_RIGHT | SA_FORCE);
232 }
233 break;
234 }
235 }
236 pos++;
237 num++;
238 }
239 }
240
241 if (num == 0) {
242 if (column == GC_GOAL && IsInsideMM(pos, 0, cap)) {
243 StringID str = !global_section && this->window_number == INVALID_COMPANY ? STR_GOALS_SPECTATOR_NONE : STR_GOALS_NONE;
244 DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, str);
245 }
246 pos++;
247 }
248 }
249
257 void DrawListColumn(GoalColumn column, NWidgetBase *wid, uint progress_col_width) const
258 {
259 /* Get column draw area. */
260 int y = wid->pos_y + WD_FRAMERECT_TOP;
261 int x = wid->pos_x + WD_FRAMERECT_LEFT;
262 int right = x + wid->current_x - WD_FRAMERECT_RIGHT;
263
264 int pos = -this->vscroll->GetPosition();
265 const int cap = this->vscroll->GetCapacity();
266
267 /* Draw partial list with global goals. */
268 DrawPartialGoalList(pos, cap, x, y, right, progress_col_width, true, column);
269
270 /* Draw partial list with company goals. */
271 pos++;
272 DrawPartialGoalList(pos, cap, x, y, right, progress_col_width, false, column);
273 }
274
275 /* virtual */ void OnPaint()
276 {
277 this->DrawWidgets();
278
279 if (this->IsShaded()) return; // Don't draw anything when the window is shaded.
280
281 /* Calculate progress column width. */
282 uint max_width = 0;
283 Goal *s;
284 FOR_ALL_GOALS(s) {
285 if (s->progress != NULL) {
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 = 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 /* virtual */ void OnResize()
303 {
304 this->vscroll->SetCapacityFromWidget(this, WID_GOAL_LIST);
305 }
306
312 /* virtual */ void OnInvalidateData(int data = 0, bool gui_scope = true)
313 {
314 if (!gui_scope) return;
315 this->vscroll->SetCount(this->CountLines());
316 this->SetWidgetDirty(WID_GOAL_LIST);
317 }
318 };
319
321 static const NWidgetPart _nested_goals_list_widgets[] = {
322 NWidget(NWID_HORIZONTAL),
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(),
329 NWidget(NWID_HORIZONTAL),
330 NWidget(WWT_PANEL, COLOUR_BROWN), SetDataTip(0x0, STR_GOALS_TOOLTIP_CLICK_ON_SERVICE_TO_CENTER), SetScrollbar(WID_GOAL_SCROLLBAR),
331 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),
332 EndContainer(),
333 NWidget(NWID_VERTICAL),
334 NWidget(NWID_VSCROLLBAR, COLOUR_BROWN, WID_GOAL_SCROLLBAR),
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,
342 WC_GOALS_LIST, WC_NONE,
343 0,
344 _nested_goals_list_widgets, lengthof(_nested_goals_list_widgets)
345 );
346
351 void ShowGoalsList(CompanyID company)
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];
363 byte type;
364
365 GoalQuestionWindow(WindowDesc *desc, WindowNumber window_number, byte type, uint32 button_mask, const char *question) : Window(desc), type(type)
366 {
367 assert(type < GOAL_QUESTION_TYPE_COUNT);
368 this->question = stredup(question);
369
370 /* Figure out which buttons we have to enable. */
371 uint bit;
372 int n = 0;
373 FOR_EACH_SET_BIT(bit, button_mask) {
374 if (bit >= GOAL_QUESTION_BUTTON_COUNT) break;
375 this->button[n++] = bit;
376 if (n == 3) break;
377 }
378 this->buttons = n;
379 assert(this->buttons > 0 && this->buttons < 4);
380
381 this->CreateNestedTree();
382 this->GetWidget<NWidgetStacked>(WID_GQ_BUTTONS)->SetDisplayedPlane(this->buttons - 1);
383 this->FinishInitNested(window_number);
384 }
385
386 ~GoalQuestionWindow()
387 {
388 free(this->question);
389 }
390
391 /* virtual */ void SetStringParameters(int widget) const
392 {
393 switch (widget) {
394 case WID_GQ_CAPTION:
395 SetDParam(0, STR_GOAL_QUESTION_CAPTION_QUESTION + this->type);
396 break;
397
398 case WID_GQ_BUTTON_1:
399 SetDParam(0, STR_GOAL_QUESTION_BUTTON_CANCEL + this->button[0]);
400 break;
401
402 case WID_GQ_BUTTON_2:
403 SetDParam(0, STR_GOAL_QUESTION_BUTTON_CANCEL + this->button[1]);
404 break;
405
406 case WID_GQ_BUTTON_3:
407 SetDParam(0, STR_GOAL_QUESTION_BUTTON_CANCEL + this->button[2]);
408 break;
409 }
410 }
411
412 /* virtual */ void OnClick(Point pt, int widget, int click_count)
413 {
414 switch (widget) {
415 case WID_GQ_BUTTON_1:
416 DoCommandP(0, this->window_number, this->button[0], CMD_GOAL_QUESTION_ANSWER);
417 delete this;
418 break;
419
420 case WID_GQ_BUTTON_2:
421 DoCommandP(0, this->window_number, this->button[1], CMD_GOAL_QUESTION_ANSWER);
422 delete this;
423 break;
424
425 case WID_GQ_BUTTON_3:
426 DoCommandP(0, this->window_number, this->button[2], CMD_GOAL_QUESTION_ANSWER);
427 delete this;
428 break;
429 }
430 }
431
432 /* virtual */ void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
433 {
434 if (widget != WID_GQ_QUESTION) return;
435
436 SetDParamStr(0, this->question);
437 size->height = GetStringHeight(STR_JUST_RAW_STRING, size->width) + WD_PAR_VSEP_WIDE;
438 }
439
440 /* virtual */ void DrawWidget(const Rect &r, int widget) const
441 {
442 if (widget != WID_GQ_QUESTION) return;
443
444 SetDParamStr(0, this->question);
445 DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, STR_JUST_RAW_STRING, TC_BLACK, SA_TOP | SA_HOR_CENTER);
446 }
447 };
448
450 static const NWidgetPart _nested_goal_question_widgets[] = {
451 NWidget(NWID_HORIZONTAL),
452 NWidget(WWT_CLOSEBOX, COLOUR_LIGHT_BLUE),
453 NWidget(WWT_CAPTION, COLOUR_LIGHT_BLUE, WID_GQ_CAPTION), SetDataTip(STR_WHITE_STRING, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
454 EndContainer(),
455 NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE),
456 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GQ_QUESTION), SetMinimalSize(300, 0), SetPadding(8, 8, 8, 8), SetFill(1, 0),
457 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GQ_BUTTONS),
458 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(85, 10, 85),
459 NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
460 EndContainer(),
461 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(65, 10, 65),
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 EndContainer(),
465 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(25, 10, 25),
466 NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
467 NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_2), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
468 NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_3), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
469 EndContainer(),
470 EndContainer(),
471 NWidget(NWID_SPACER), SetMinimalSize(0, 8),
472 EndContainer(),
473 };
474
475 static WindowDesc _goal_question_list_desc(
476 WDP_CENTER, NULL, 0, 0,
477 WC_GOAL_QUESTION, WC_NONE,
478 WDF_CONSTRUCTION,
479 _nested_goal_question_widgets, lengthof(_nested_goal_question_widgets)
480 );
481
489 void ShowGoalQuestion(uint16 id, byte type, uint32 button_mask, const char *question)
490 {
491 new GoalQuestionWindow(&_goal_question_list_desc, id, type, button_mask, question);
492 }
strings_func.h
Functions related to OTTD&#39;s strings.
WWT_EMPTY
Empty widget, place holder to reserve space in widget array.
Definition: widget_type.h:48
company_base.h
Definition of stuff that is very close to a company, like the company struct itself.
SA_HOR_CENTER
Horizontally center the text.
Definition: gfx_func.h:99
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:317
SetResize
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:930
WID_GOAL_CAPTION
Caption of the window.
Definition: goal_widget.h:18
WID_GQ_BUTTONS
Buttons selection (between 1, 2 or 3).
Definition: goal_widget.h:27
GT_STORY_PAGE
Destination is a story page.
Definition: goal_type.h:27
WindowDesc
High level window description.
Definition: window_gui.h:168
GC_PROGRESS
Goal progress column.
Definition: goal_gui.cpp:37
_nested_goal_question_widgets
static const NWidgetPart _nested_goal_question_widgets[]
Widgets of the goal question window.
Definition: goal_gui.cpp:450
GoalListWindow::SetStringParameters
void SetStringParameters(int widget) const
Initialize string parameters for a widget.
Definition: goal_gui.cpp:53
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:604
Pool::PoolItem<&_industry_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:246
GT_COMPANY
Destination is a company.
Definition: goal_type.h:26
date_func.h
Functions related to dates.
IsInsideMM
static bool IsInsideMM(const T x, const uint min, const uint max)
Checks if a value is in an interval.
Definition: math_func.hpp:266
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:589
Window::SetWidgetDirty
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:577
WD_FRAMERECT_TOP
Offset at top to draw the frame rectangular area.
Definition: window_gui.h:64
NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:75
WC_GOAL_QUESTION
Popup with a set of buttons, designed to ask the user a question from a GameScript.
Definition: window_type.h:132
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:204
GT_TOWN
Destination is a town.
Definition: goal_type.h:25
GoalQuestionWindow::question
char * question
Question to ask (private copy).
Definition: goal_gui.cpp:360
GoalListWindow
Window for displaying goals.
Definition: goal_gui.cpp:41
GT_NONE
Destination is not linked.
Definition: goal_type.h:22
WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:68
Goal
Struct about goals, current and completed.
Definition: goal_base.h:23
WC_GOALS_LIST
Goals list; Window numbers:
Definition: window_type.h:285
ShowGoalsList
void ShowGoalsList(CompanyID company)
Open a goal list window.
Definition: goal_gui.cpp:351
WID_GQ_BUTTON_3
Third button.
Definition: goal_widget.h:30
GetStringHeight
int GetStringHeight(const char *str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
Definition: gfx.cpp:547
WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:69
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:965
GoalQuestionWindow
Ask a question about a goal.
Definition: goal_gui.cpp:359
WID_GQ_BUTTON_1
First button.
Definition: goal_widget.h:28
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
GoalListWindow::OnPaint
void OnPaint()
The window must be repainted.
Definition: goal_gui.cpp:275
GoalQuestionWindow::type
byte type
Type of question.
Definition: goal_gui.cpp:363
Window::CreateNestedTree
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1804
WD_PAR_VSEP_WIDE
Large amount of vertical space between two paragraphs of text.
Definition: window_gui.h:140
window_gui.h
Functions, definitions and such used only by the GUI.
WID_GQ_CAPTION
Caption of the window.
Definition: goal_widget.h:25
Scrollbar::SetCount
void SetCount(int num)
Sets the number of elements in the list.
Definition: widget_type.h:670
SA_FORCE
Force the alignment, i.e. don&#39;t swap for RTL languages.
Definition: gfx_func.h:110
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:910
viewport_func.h
Functions related to (drawing on) viewports.
Goal::dst
GoalTypeID dst
Index of type.
Definition: goal_base.h:26
Window
Data structure for an opened window.
Definition: window_gui.h:271
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:36
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1820
IsValidTile
static bool IsValidTile(TileIndex tile)
Checks if a tile is valid.
Definition: tile_map.h:154
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:1046
WD_FRAMETEXT_BOTTOM
Bottom offset of the text of the frame.
Definition: window_gui.h:75
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:279
string_func.h
Functions related to low-level strings.
NWID_SPACER
Invisible widget that takes some space.
Definition: widget_type.h:79
WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX) ...
Definition: widget_type.h:65
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:1959
NWidgetBase::pos_y
uint pos_y
Vertical position of top-left corner of the widget in the window.
Definition: widget_type.h:178
WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
Definition: window_gui.h:210
GoalListWindow::OnClick
void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
Definition: goal_gui.cpp:65
GT_INDUSTRY
Destination is an industry.
Definition: goal_type.h:24
FONT_HEIGHT_NORMAL
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:180
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1014
SetMinimalSize
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:947
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
SA_TOP
Top align the text.
Definition: gfx_func.h:103
_nested_goals_list_widgets
static const NWidgetPart _nested_goals_list_widgets[]
Widgets of the GoalListWindow.
Definition: goal_gui.cpp:321
safeguards.h
A number of safeguards to prevent using unsafe methods.
WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:104
geometry_func.hpp
Geometry functions.
WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:50
Window::GetScrollbar
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:307
stredup
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
Definition: string.cpp:126
WID_GOAL_LIST
Goal list.
Definition: goal_widget.h:19
WDP_CENTER
Center the window.
Definition: window_gui.h:157
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new &#39;real&#39; widget.
Definition: widget_type.h:1114
WD_FRAMERECT_BOTTOM
Offset at bottom to draw the frame rectangular area.
Definition: window_gui.h:65
NWidgetBase
Baseclass for nested widgets.
Definition: widget_type.h:126
GoalQuestionWindow::SetStringParameters
void SetStringParameters(int widget) const
Initialize string parameters for a widget.
Definition: goal_gui.cpp:391
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:499
DoCommandP
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
Definition: command.cpp:527
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: depend.cpp:42
GT_TILE
Destination is a tile.
Definition: goal_type.h:23
min
static T min(const T a, const T b)
Returns the minimum of two values.
Definition: math_func.hpp:42
NWidgetBase::pos_x
uint pos_x
Horizontal position of top-left corner of the widget in the window.
Definition: widget_type.h:177
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:18
GoalQuestionWindow::OnClick
void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
Definition: goal_gui.cpp:412
Goal::type
GoalTypeByte type
Type of the goal.
Definition: goal_base.h:25
ShowExtraViewPortWindow
void ShowExtraViewPortWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
Definition: viewport_gui.cpp:170
GetStringBoundingBox
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:699
GoalListWindow::vscroll
Scrollbar * vscroll
Reference to the scrollbar widget.
Definition: goal_gui.cpp:42
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition: geometry_func.cpp:24
WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:40
company_func.h
Functions related to companies.
WID_GOAL_SCROLLBAR
Scrollbar of the goal list.
Definition: goal_widget.h:20
GoalQuestionWindow::UpdateWidgetSize
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
Update size and resize step of a widget in the window.
Definition: goal_gui.cpp:432
Goal::company
CompanyByte company
Goal is for a specific company; INVALID_COMPANY if it is global.
Definition: goal_base.h:24
Goal::progress
char * progress
Progress text of the goal.
Definition: goal_base.h:28
WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:61
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
goal_widget.h
Types related to the goal widgets.
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:52
Goal::completed
bool completed
Is the goal completed or not?
Definition: goal_base.h:29
NWID_VERTICAL
Vertical container.
Definition: widget_type.h:77
ShowGoalQuestion
void ShowGoalQuestion(uint16 id, byte type, uint32 button_mask, const char *question)
Display a goal question.
Definition: goal_gui.cpp:489
EndContainer
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME, WWT_INSET, or WWT_PANEL).
Definition: widget_type.h:999
WID_GQ_BUTTON_2
Second button.
Definition: goal_widget.h:29
NWidgetBase::current_x
uint current_x
Current horizontal size (after resizing).
Definition: widget_type.h:174
goal_base.h
Goal base class.
ScrollMainWindowToTile
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Definition: viewport.cpp:2268
command_func.h
Functions related to commands.
GoalListWindow::UpdateWidgetSize
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
Update size and resize step of a widget in the window.
Definition: goal_gui.cpp:180
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:766
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:28
Pool::PoolItem<&_industry_pool >::IsValidID
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-NULL) Titem.
Definition: pool_type.hpp:235
Scrollbar::GetCapacity
uint16 GetCapacity() const
Gets the number of visible elements of the scrollbar.
Definition: widget_type.h:622
GoalListWindow::CountLines
uint CountLines()
Count the number of lines in this window.
Definition: goal_gui.cpp:158
GC_GOAL
Goal text column.
Definition: goal_gui.cpp:36
GoalListWindow::HandleClick
void HandleClick(const Goal *s)
Handle clicking at a goal.
Definition: goal_gui.cpp:106
Window::owner
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable...
Definition: window_gui.h:319
story_base.h
StoryPage base class.
industry.h
Base of all industries.
free
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: depend.cpp:114
WD_FRAMERECT_RIGHT
Offset at right to draw the frame rectangular area.
Definition: window_gui.h:63
WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:66
SetFill
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:983
GOAL_QUESTION_BUTTON_COUNT
static const uint32 GOAL_QUESTION_BUTTON_COUNT
Amount of buttons available.
Definition: goal_type.h:17
GoalColumn
GoalColumn
Goal list columns.
Definition: goal_gui.cpp:35
town.h
Base of the town class.
CMD_GOAL_QUESTION_ANSWER
answer(s) to CMD_GOAL_QUESTION
Definition: command_type.h:287
WindowNumber
int32 WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:695
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:1973
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:40
NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:84
Window::IsShaded
bool IsShaded() const
Is window shaded currently?
Definition: window_gui.h:519
TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:26
SA_RIGHT
Right align the text (must be a single bit).
Definition: gfx_func.h:100
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:307
Goal::text
char * text
Text of the goal.
Definition: goal_base.h:27
GOAL_QUESTION_TYPE_COUNT
static const byte GOAL_QUESTION_TYPE_COUNT
Amount of question types.
Definition: goal_type.h:18
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:20
GoalQuestionWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
Definition: goal_gui.cpp:440
WDP_AUTO
Find a place automatically.
Definition: window_gui.h:156
NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition: widget_type.h:80
gui.h
GUI functions that shouldn&#39;t be here.
GoalQuestionWindow::buttons
int buttons
Number of valid buttons in button.
Definition: goal_gui.cpp:361
GoalListWindow::OnResize
void OnResize()
Called after the window got resized.
Definition: goal_gui.cpp:302
GoalListWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true)
Some data on this window has become invalid.
Definition: goal_gui.cpp:312
INVALID_COMPANY
An invalid company.
Definition: company_type.h:32
SetScrollbar
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1095
WID_GQ_QUESTION
Question text.
Definition: goal_widget.h:26
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:34
NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:429
WD_FRAMERECT_LEFT
Offset at left to draw the frame rectangular area.
Definition: window_gui.h:62
WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:64
SetPIP
static NWidgetPart SetPIP(uint8 pre, uint8 inter, uint8 post)
Widget part function for setting a pre/inter/post spaces.
Definition: widget_type.h:1076
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:620
Scrollbar::GetPosition
uint16 GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:631
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:201
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:257