OpenTTD

signs_gui.cpp
Go to the documentation of this file.
1 /* $Id: signs_gui.cpp 27893 2017-08-13 18:38:42Z frosch $ */
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 "company_gui.h"
14 #include "company_func.h"
15 #include "signs_base.h"
16 #include "signs_func.h"
17 #include "debug.h"
18 #include "command_func.h"
19 #include "strings_func.h"
20 #include "window_func.h"
21 #include "map_func.h"
22 #include "viewport_func.h"
23 #include "querystring_gui.h"
24 #include "sortlist_type.h"
25 #include "stringfilter_type.h"
26 #include "string_func.h"
27 #include "core/geometry_func.hpp"
28 #include "hotkeys.h"
29 #include "transparency.h"
30
31 #include "widgets/sign_widget.h"
32
33 #include "table/strings.h"
34 #include "table/sprites.h"
35
36 #include "safeguards.h"
37
38 struct SignList {
42 typedef GUIList<const Sign *, StringFilter &> GUISignList;
43
44 static const Sign *last_sign;
45 GUISignList signs;
46
47 StringFilter string_filter;
48 static bool match_case;
49
53 SignList() : string_filter(&match_case)
54 {
55 }
56
57 void BuildSignsList()
58 {
59 if (!this->signs.NeedRebuild()) return;
60
61 DEBUG(misc, 3, "Building sign list");
62
63 this->signs.Clear();
64
65 const Sign *si;
66 FOR_ALL_SIGNS(si) *this->signs.Append() = si;
67
68 this->signs.SetFilterState(true);
69 this->FilterSignList();
70 this->signs.Compact();
71 this->signs.RebuildDone();
72 }
73
75 static int CDECL SignNameSorter(const Sign * const *a, const Sign * const *b)
76 {
77 static char buf_cache[64];
78 char buf[64];
79
80 SetDParam(0, (*a)->index);
81 GetString(buf, STR_SIGN_NAME, lastof(buf));
82
83 if (*b != last_sign) {
84 last_sign = *b;
85 SetDParam(0, (*b)->index);
86 GetString(buf_cache, STR_SIGN_NAME, lastof(buf_cache));
87 }
88
89 int r = strnatcmp(buf, buf_cache); // Sort by name (natural sorting).
90
91 return r != 0 ? r : ((*a)->index - (*b)->index);
92 }
93
94 void SortSignsList()
95 {
96 if (!this->signs.Sort(&SignNameSorter)) return;
97
98 /* Reset the name sorter sort cache */
99 this->last_sign = NULL;
100 }
101
103 static bool CDECL SignNameFilter(const Sign * const *a, StringFilter &filter)
104 {
105 /* Get sign string */
106 char buf1[MAX_LENGTH_SIGN_NAME_CHARS * MAX_CHAR_LENGTH];
107 SetDParam(0, (*a)->index);
108 GetString(buf1, STR_SIGN_NAME, lastof(buf1));
109
110 filter.ResetState();
111 filter.AddLine(buf1);
112 return filter.GetState();
113 }
114
116 static bool CDECL OwnerDeityFilter(const Sign * const *a, StringFilter &filter)
117 {
118 /* You should never be able to edit signs of owner DEITY */
119 return (*a)->owner != OWNER_DEITY;
120 }
121
123 static bool CDECL OwnerVisibilityFilter(const Sign * const *a, StringFilter &filter)
124 {
125 assert(!HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS));
126 /* Hide sign if non-own signs are hidden in the viewport */
127 return (*a)->owner == _local_company || (*a)->owner == OWNER_DEITY;
128 }
129
131 void FilterSignList()
132 {
133 this->signs.Filter(&SignNameFilter, this->string_filter);
134 if (_game_mode != GM_EDITOR) this->signs.Filter(&OwnerDeityFilter, this->string_filter);
135 if (!HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS)) {
136 this->signs.Filter(&OwnerVisibilityFilter, this->string_filter);
137 }
138 }
139 };
140
141 const Sign *SignList::last_sign = NULL;
142 bool SignList::match_case = false;
143
145 enum SignListHotkeys {
146 SLHK_FOCUS_FILTER_BOX,
147 };
148
149 struct SignListWindow : Window, SignList {
150 QueryString filter_editbox;
151 int text_offset;
152 Scrollbar *vscroll;
153
154 SignListWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc), filter_editbox(MAX_LENGTH_SIGN_NAME_CHARS * MAX_CHAR_LENGTH, MAX_LENGTH_SIGN_NAME_CHARS)
155 {
156 this->CreateNestedTree();
157 this->vscroll = this->GetScrollbar(WID_SIL_SCROLLBAR);
158 this->FinishInitNested(window_number);
159 this->SetWidgetLoweredState(WID_SIL_FILTER_MATCH_CASE_BTN, SignList::match_case);
160
161 /* Initialize the text edit widget */
162 this->querystrings[WID_SIL_FILTER_TEXT] = &this->filter_editbox;
163 this->filter_editbox.cancel_button = QueryString::ACTION_CLEAR;
164
165 /* Initialize the filtering variables */
166 this->SetFilterString("");
167
168 /* Create initial list. */
169 this->signs.ForceRebuild();
170 this->signs.ForceResort();
171 this->BuildSortSignList();
172 }
173
180 void SetFilterString(const char *new_filter_string)
181 {
182 /* check if there is a new filter string */
183 this->string_filter.SetFilterTerm(new_filter_string);
184
185 /* Rebuild the list of signs */
186 this->InvalidateData();
187 }
188
189 virtual void OnPaint()
190 {
191 if (this->signs.NeedRebuild()) this->BuildSortSignList();
192 this->DrawWidgets();
193 }
194
195 virtual void DrawWidget(const Rect &r, int widget) const
196 {
197 switch (widget) {
198 case WID_SIL_LIST: {
199 uint y = r.top + WD_FRAMERECT_TOP; // Offset from top of widget.
200 /* No signs? */
201 if (this->vscroll->GetCount() == 0) {
202 DrawString(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, y, STR_STATION_LIST_NONE);
203 return;
204 }
205
206 bool rtl = _current_text_dir == TD_RTL;
207 int sprite_offset_y = (FONT_HEIGHT_NORMAL - 10) / 2 + 1;
208 uint icon_left = 4 + (rtl ? r.right - this->text_offset : r.left);
209 uint text_left = r.left + (rtl ? WD_FRAMERECT_LEFT : this->text_offset);
210 uint text_right = r.right - (rtl ? this->text_offset : WD_FRAMERECT_RIGHT);
211
212 /* At least one sign available. */
213 for (uint16 i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < this->vscroll->GetCount(); i++) {
214 const Sign *si = this->signs[i];
215
216 if (si->owner != OWNER_NONE) DrawCompanyIcon(si->owner, icon_left, y + sprite_offset_y);
217
218 SetDParam(0, si->index);
219 DrawString(text_left, text_right, y, STR_SIGN_NAME, TC_YELLOW);
220 y += this->resize.step_height;
221 }
222 break;
223 }
224 }
225 }
226
227 virtual void SetStringParameters(int widget) const
228 {
229 if (widget == WID_SIL_CAPTION) SetDParam(0, this->vscroll->GetCount());
230 }
231
232 virtual void OnClick(Point pt, int widget, int click_count)
233 {
234 switch (widget) {
235 case WID_SIL_LIST: {
236 uint id_v = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_SIL_LIST, WD_FRAMERECT_TOP);
237 if (id_v == INT_MAX) return;
238
239 const Sign *si = this->signs[id_v];
240 ScrollMainWindowToTile(TileVirtXY(si->x, si->y));
241 break;
242 }
243
244 case WID_SIL_FILTER_ENTER_BTN:
245 if (this->signs.Length() >= 1) {
246 const Sign *si = this->signs[0];
247 ScrollMainWindowToTile(TileVirtXY(si->x, si->y));
248 }
249 break;
250
251 case WID_SIL_FILTER_MATCH_CASE_BTN:
252 SignList::match_case = !SignList::match_case; // Toggle match case
253 this->SetWidgetLoweredState(WID_SIL_FILTER_MATCH_CASE_BTN, SignList::match_case); // Toggle button pushed state
254 this->InvalidateData(); // Rebuild the list of signs
255 break;
256 }
257 }
258
259 virtual void OnResize()
260 {
261 this->vscroll->SetCapacityFromWidget(this, WID_SIL_LIST, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM);
262 }
263
264 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
265 {
266 switch (widget) {
267 case WID_SIL_LIST: {
268 Dimension spr_dim = GetSpriteSize(SPR_COMPANY_ICON);
269 this->text_offset = WD_FRAMETEXT_LEFT + spr_dim.width + 2; // 2 pixels space between icon and the sign text.
270 resize->height = max<uint>(FONT_HEIGHT_NORMAL, spr_dim.height);
271 Dimension d = {(uint)(this->text_offset + WD_FRAMETEXT_RIGHT), WD_FRAMERECT_TOP + 5 * resize->height + WD_FRAMERECT_BOTTOM};
272 *size = maxdim(*size, d);
273 break;
274 }
275
276 case WID_SIL_CAPTION:
277 SetDParamMaxValue(0, Sign::GetPoolSize(), 3);
278 *size = GetStringBoundingBox(STR_SIGN_LIST_CAPTION);
279 size->height += padding.height;
280 size->width += padding.width;
281 break;
282 }
283 }
284
285 virtual EventState OnHotkey(int hotkey)
286 {
287 switch (hotkey) {
288 case SLHK_FOCUS_FILTER_BOX:
289 this->SetFocusedWidget(WID_SIL_FILTER_TEXT);
290 SetFocusedWindow(this); // The user has asked to give focus to the text box, so make sure this window is focused.
291 break;
292
293 default:
294 return ES_NOT_HANDLED;
295 }
296
297 return ES_HANDLED;
298 }
299
300 virtual void OnEditboxChanged(int widget)
301 {
302 if (widget == WID_SIL_FILTER_TEXT) this->SetFilterString(this->filter_editbox.text.buf);
303 }
304
305 void BuildSortSignList()
306 {
307 if (this->signs.NeedRebuild()) {
308 this->BuildSignsList();
309 this->vscroll->SetCount(this->signs.Length());
310 this->SetWidgetDirty(WID_SIL_CAPTION);
311 }
312 this->SortSignsList();
313 }
314
315 virtual void OnHundredthTick()
316 {
317 this->BuildSortSignList();
318 this->SetDirty();
319 }
320
326 virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
327 {
328 /* When there is a filter string, we always need to rebuild the list even if
329 * the amount of signs in total is unchanged, as the subset of signs that is
330 * accepted by the filter might has changed. */
331 if (data == 0 || data == -1 || !this->string_filter.IsEmpty()) { // New or deleted sign, changed visibility setting or there is a filter string
332 /* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
333 this->signs.ForceRebuild();
334 } else { // Change of sign contents while there is no filter string
335 this->signs.ForceResort();
336 }
337 }
338
339 static HotkeyList hotkeys;
340 };
341
347 static EventState SignListGlobalHotkeys(int hotkey)
348 {
349 if (_game_mode == GM_MENU) return ES_NOT_HANDLED;
350 Window *w = ShowSignList();
351 if (w == NULL) return ES_NOT_HANDLED;
352 return w->OnHotkey(hotkey);
353 }
354
355 static Hotkey signlist_hotkeys[] = {
356 Hotkey('F', "focus_filter_box", SLHK_FOCUS_FILTER_BOX),
357 HOTKEY_LIST_END
358 };
359 HotkeyList SignListWindow::hotkeys("signlist", signlist_hotkeys, SignListGlobalHotkeys);
360
361 static const NWidgetPart _nested_sign_list_widgets[] = {
362 NWidget(NWID_HORIZONTAL),
363 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
364 NWidget(WWT_CAPTION, COLOUR_GREY, WID_SIL_CAPTION), SetDataTip(STR_SIGN_LIST_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
365 NWidget(WWT_SHADEBOX, COLOUR_GREY),
366 NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
367 NWidget(WWT_STICKYBOX, COLOUR_GREY),
368 EndContainer(),
369 NWidget(NWID_HORIZONTAL),
370 NWidget(NWID_VERTICAL),
371 NWidget(WWT_PANEL, COLOUR_GREY, WID_SIL_LIST), SetMinimalSize(WD_FRAMETEXT_LEFT + 16 + 255 + WD_FRAMETEXT_RIGHT, 50),
372 SetResize(1, 10), SetFill(1, 0), SetScrollbar(WID_SIL_SCROLLBAR), EndContainer(),
373 NWidget(NWID_HORIZONTAL),
374 NWidget(WWT_PANEL, COLOUR_GREY), SetFill(1, 1),
375 NWidget(WWT_EDITBOX, COLOUR_GREY, WID_SIL_FILTER_TEXT), SetMinimalSize(80, 12), SetResize(1, 0), SetFill(1, 0), SetPadding(2, 2, 2, 2),
376 SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
377 EndContainer(),
378 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SIL_FILTER_MATCH_CASE_BTN), SetDataTip(STR_SIGN_LIST_MATCH_CASE, STR_SIGN_LIST_MATCH_CASE_TOOLTIP),
379 EndContainer(),
380 EndContainer(),
381 NWidget(NWID_VERTICAL),
382 NWidget(NWID_VERTICAL), SetFill(0, 1),
383 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_SIL_SCROLLBAR),
384 EndContainer(),
385 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
386 EndContainer(),
387 EndContainer(),
388 };
389
390 static WindowDesc _sign_list_desc(
391 WDP_AUTO, "list_signs", 358, 138,
392 WC_SIGN_LIST, WC_NONE,
393 0,
394 _nested_sign_list_widgets, lengthof(_nested_sign_list_widgets),
395 &SignListWindow::hotkeys
396 );
397
403 Window *ShowSignList()
404 {
405 return AllocateWindowDescFront<SignListWindow>(&_sign_list_desc, 0);
406 }
407
414 static bool RenameSign(SignID index, const char *text)
415 {
416 bool remove = StrEmpty(text);
417 DoCommandP(0, index, 0, CMD_RENAME_SIGN | (StrEmpty(text) ? CMD_MSG(STR_ERROR_CAN_T_DELETE_SIGN) : CMD_MSG(STR_ERROR_CAN_T_CHANGE_SIGN_NAME)), NULL, text);
418 return remove;
419 }
420
421 struct SignWindow : Window, SignList {
422 QueryString name_editbox;
423 SignID cur_sign;
424
425 SignWindow(WindowDesc *desc, const Sign *si) : Window(desc), name_editbox(MAX_LENGTH_SIGN_NAME_CHARS * MAX_CHAR_LENGTH, MAX_LENGTH_SIGN_NAME_CHARS)
426 {
427 this->querystrings[WID_QES_TEXT] = &this->name_editbox;
428 this->name_editbox.caption = STR_EDIT_SIGN_CAPTION;
429 this->name_editbox.cancel_button = WID_QES_CANCEL;
430 this->name_editbox.ok_button = WID_QES_OK;
431
432 this->InitNested(WN_QUERY_STRING_SIGN);
433
434 UpdateSignEditWindow(si);
435 this->SetFocusedWidget(WID_QES_TEXT);
436 }
437
438 void UpdateSignEditWindow(const Sign *si)
439 {
440 /* Display an empty string when the sign hasn't been edited yet */
441 if (si->name != NULL) {
442 SetDParam(0, si->index);
443 this->name_editbox.text.Assign(STR_SIGN_NAME);
444 } else {
445 this->name_editbox.text.DeleteAll();
446 }
447
448 this->cur_sign = si->index;
449
450 this->SetWidgetDirty(WID_QES_TEXT);
451 this->SetFocusedWidget(WID_QES_TEXT);
452 }
453
459 const Sign *PrevNextSign(bool next)
460 {
461 /* Rebuild the sign list */
462 this->signs.ForceRebuild();
463 this->signs.NeedResort();
464 this->BuildSignsList();
465 this->SortSignsList();
466
467 /* Search through the list for the current sign, excluding
468 * - the first sign if we want the previous sign or
469 * - the last sign if we want the next sign */
470 uint end = this->signs.Length() - (next ? 1 : 0);
471 for (uint i = next ? 0 : 1; i < end; i++) {
472 if (this->cur_sign == this->signs[i]->index) {
473 /* We've found the current sign, so return the sign before/after it */
474 return this->signs[i + (next ? 1 : -1)];
475 }
476 }
477 /* If we haven't found the current sign by now, return the last/first sign */
478 return this->signs[next ? 0 : this->signs.Length() - 1];
479 }
480
481 virtual void SetStringParameters(int widget) const
482 {
483 switch (widget) {
484 case WID_QES_CAPTION:
485 SetDParam(0, this->name_editbox.caption);
486 break;
487 }
488 }
489
490 virtual void OnClick(Point pt, int widget, int click_count)
491 {
492 switch (widget) {
493 case WID_QES_PREVIOUS:
494 case WID_QES_NEXT: {
495 const Sign *si = this->PrevNextSign(widget == WID_QES_NEXT);
496
497 /* Rebuild the sign list */
498 this->signs.ForceRebuild();
499 this->signs.NeedResort();
500 this->BuildSignsList();
501 this->SortSignsList();
502
503 /* Scroll to sign and reopen window */
504 ScrollMainWindowToTile(TileVirtXY(si->x, si->y));
505 UpdateSignEditWindow(si);
506 break;
507 }
508
509 case WID_QES_DELETE:
510 /* Only need to set the buffer to null, the rest is handled as the OK button */
511 RenameSign(this->cur_sign, "");
512 /* don't delete this, we are deleted in Sign::~Sign() -> DeleteRenameSignWindow() */
513 break;
514
515 case WID_QES_OK:
516 if (RenameSign(this->cur_sign, this->name_editbox.text.buf)) break;
517 FALLTHROUGH;
518
519 case WID_QES_CANCEL:
520 delete this;
521 break;
522 }
523 }
524 };
525
526 static const NWidgetPart _nested_query_sign_edit_widgets[] = {
527 NWidget(NWID_HORIZONTAL),
528 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
529 NWidget(WWT_CAPTION, COLOUR_GREY, WID_QES_CAPTION), SetDataTip(STR_WHITE_STRING, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
530 EndContainer(),
531 NWidget(WWT_PANEL, COLOUR_GREY),
532 NWidget(WWT_EDITBOX, COLOUR_GREY, WID_QES_TEXT), SetMinimalSize(256, 12), SetDataTip(STR_EDIT_SIGN_SIGN_OSKTITLE, STR_NULL), SetPadding(2, 2, 2, 2),
533 EndContainer(),
534 NWidget(NWID_HORIZONTAL),
535 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_QES_OK), SetMinimalSize(61, 12), SetDataTip(STR_BUTTON_OK, STR_NULL),
536 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_QES_CANCEL), SetMinimalSize(60, 12), SetDataTip(STR_BUTTON_CANCEL, STR_NULL),
537 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_QES_DELETE), SetMinimalSize(60, 12), SetDataTip(STR_TOWN_VIEW_DELETE_BUTTON, STR_NULL),
538 NWidget(WWT_PANEL, COLOUR_GREY), SetFill(1, 1), EndContainer(),
539 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_QES_PREVIOUS), SetMinimalSize(11, 12), SetDataTip(AWV_DECREASE, STR_EDIT_SIGN_PREVIOUS_SIGN_TOOLTIP),
540 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_QES_NEXT), SetMinimalSize(11, 12), SetDataTip(AWV_INCREASE, STR_EDIT_SIGN_NEXT_SIGN_TOOLTIP),
541 EndContainer(),
542 };
543
544 static WindowDesc _query_sign_edit_desc(
545 WDP_CENTER, "query_sign", 0, 0,
546 WC_QUERY_STRING, WC_NONE,
547 WDF_CONSTRUCTION,
548 _nested_query_sign_edit_widgets, lengthof(_nested_query_sign_edit_widgets)
549 );
550
555 void HandleClickOnSign(const Sign *si)
556 {
557 if (_ctrl_pressed && (si->owner == _local_company || (si->owner == OWNER_DEITY && _game_mode == GM_EDITOR))) {
558 RenameSign(si->index, NULL);
559 return;
560 }
561 ShowRenameSignWindow(si);
562 }
563
568 void ShowRenameSignWindow(const Sign *si)
569 {
570 /* Delete all other edit windows */
571 DeleteWindowByClass(WC_QUERY_STRING);
572
573 new SignWindow(&_query_sign_edit_desc, si);
574 }
575
580 void DeleteRenameSignWindow(SignID sign)
581 {
582 SignWindow *w = dynamic_cast<SignWindow *>(FindWindowById(WC_QUERY_STRING, WN_QUERY_STRING_SIGN));
583
584 if (w != NULL && w->cur_sign == sign) delete w;
585 }
EventState
EventState
State of handling an event.
Definition: window_type.h:701
strings_func.h
Functions related to OTTD&#39;s strings.
sortlist_type.h
Base types for having sorted lists in GUIs.
GUIList< const Sign *, StringFilter & >
GUIList::RebuildDone
void RebuildDone()
Notify the sortlist that the rebuild is done.
Definition: sortlist_type.h:397
WN_QUERY_STRING_SIGN
Query string for signs.
Definition: window_type.h:24
MAX_LENGTH_SIGN_NAME_CHARS
static const uint MAX_LENGTH_SIGN_NAME_CHARS
The maximum length of a sign name in characters including &#39;\0&#39;.
Definition: signs_type.h:21
Window::OnHotkey
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
Definition: window.cpp:590
SetResize
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:930
CMD_RENAME_SIGN
rename a sign
Definition: command_type.h:251
SignListWindow::OnPaint
virtual void OnPaint()
The window must be repainted.
Definition: signs_gui.cpp:189
SignListWindow::OnEditboxChanged
virtual void OnEditboxChanged(int widget)
The text in an editbox has been edited.
Definition: signs_gui.cpp:300
SetFocusedWindow
void SetFocusedWindow(Window *w)
Set the window that has the focus.
Definition: window.cpp:432
SignListHotkeys
SignListHotkeys
Enum referring to the Hotkeys in the sign list window.
Definition: signs_gui.cpp:145
Hotkey
All data for a single hotkey.
Definition: hotkeys.h:24
WindowDesc
High level window description.
Definition: window_gui.h:168
SignList
Definition: signs_gui.cpp:38
_display_opt
byte _display_opt
What do we want to draw/do?
Definition: transparency_gui.cpp:28
GUIList::Filter
bool Filter(FilterFunction *decide, F filter_data)
Filter the list.
Definition: sortlist_type.h:334
SignList::GUISignList
GUIList< const Sign *, StringFilter & > GUISignList
A GUIList contains signs and uses a StringFilter for filtering.
Definition: signs_gui.cpp:42
hotkeys.h
Hotkey related functions.
DeleteRenameSignWindow
void DeleteRenameSignWindow(SignID sign)
Close the sign window associated with the given sign.
Definition: signs_gui.cpp:580
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:589
SignList::match_case
static bool match_case
Should case sensitive matching be used?
Definition: signs_gui.cpp:48
WD_FRAMERECT_TOP
Offset at top to draw the frame rectangular area.
Definition: window_gui.h:64
debug.h
Functions related to debugging.
NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:75
FindWindowById
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition: window.cpp:1105
StringFilter::ResetState
void ResetState()
Reset the matching state to process a new item.
Definition: stringfilter.cpp:91
ES_NOT_HANDLED
The passed event is not handled.
Definition: window_type.h:703
AWV_INCREASE
Arrow to the right or in case of RTL to the left.
Definition: widget_type.h:38
AWV_DECREASE
Arrow to the left or in case of RTL to the right.
Definition: widget_type.h:37
StringFilter::GetState
bool GetState() const
Get the matching state of the current item.
Definition: stringfilter_type.h:71
SignWindow::PrevNextSign
const Sign * PrevNextSign(bool next)
Returns a pointer to the (alphabetically) previous or next sign of the current sign.
Definition: signs_gui.cpp:459
SignListWindow::text_offset
int text_offset
Offset of the sign text relative to the left edge of the WID_SIL_LIST widget.
Definition: signs_gui.cpp:151
WC_SIGN_LIST
Sign list; Window numbers:
Definition: window_type.h:273
Textbuf::DeleteAll
void CDECL void DeleteAll()
Delete every character in the textbuffer.
Definition: textbuf.cpp:118
WWT_EDITBOX
a textbox for typing
Definition: widget_type.h:71
WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:68
DrawCompanyIcon
void DrawCompanyIcon(CompanyID c, int x, int y)
Draw the icon of a company.
Definition: company_cmd.cpp:141
QueryString::ACTION_CLEAR
static const int ACTION_CLEAR
Clear editbox.
Definition: querystring_gui.h:26
SignListWindow::OnClick
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
Definition: signs_gui.cpp:232
SmallVector::Clear
void Clear()
Remove all items from the list.
Definition: smallvec_type.hpp:98
SmallVector::Compact
void Compact()
Compact the list down to the smallest block size boundary.
Definition: smallvec_type.hpp:120
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:147
WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:69
DO_SHOW_COMPETITOR_SIGNS
Display signs, station names and waypoint names of opponent companies. Buoys and oilrig-stations are ...
Definition: openttd.h:49
StringFilter
String filter and state.
Definition: stringfilter_type.h:33
lastof
#define lastof(x)
Get the last element of an fixed size array.
Definition: depend.cpp:50
signs_func.h
Functions related to signs.
map_func.h
Functions related to maps.
GUIList::NeedRebuild
bool NeedRebuild() const
Check if a rebuild is needed.
Definition: sortlist_type.h:379
SmallVector::Append
T * Append(uint to_add=1)
Append an item and return it.
Definition: smallvec_type.hpp:134
Scrollbar::SetCount
void SetCount(int num)
Sets the number of elements in the list.
Definition: widget_type.h:670
_local_company
CompanyByte _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:46
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.
OWNER_DEITY
The object is owned by a superuser / goal script.
Definition: company_type.h:29
querystring_gui.h
Base for the GUIs that have an edit box in them.
Window
Data structure for an opened window.
Definition: window_gui.h:271
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:36
StringFilter::SetFilterTerm
void SetFilterTerm(const char *str)
Set the term to filter on.
Definition: stringfilter.cpp:29
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
SignWindow::SetStringParameters
virtual void SetStringParameters(int widget) const
Initialize string parameters for a widget.
Definition: signs_gui.cpp:481
string_func.h
Functions related to low-level strings.
MAX_CHAR_LENGTH
static const int MAX_CHAR_LENGTH
Max. length of UTF-8 encoded unicode character.
Definition: strings_type.h:20
WID_SIL_LIST
List of signs.
Definition: sign_widget.h:19
WID_SIL_SCROLLBAR
Scrollbar of list.
Definition: sign_widget.h:20
SignWindow
Definition: signs_gui.cpp:421
WID_QES_TEXT
Text of the query.
Definition: sign_widget.h:29
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
WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
Definition: window_gui.h:210
Pool::PoolItem<&_sign_pool >::GetPoolSize
static size_t GetPoolSize()
Returns first unused index.
Definition: pool_type.hpp:267
QueryString::ok_button
int ok_button
Widget button of parent window to simulate when pressing OK in OSK.
Definition: querystring_gui.h:29
ShowRenameSignWindow
void ShowRenameSignWindow(const Sign *si)
Show the window to change the text of a sign.
Definition: signs_gui.cpp:568
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
QueryString
Data stored about a string that can be modified in the GUI.
Definition: querystring_gui.h:22
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.
WID_SIL_FILTER_TEXT
Text box for typing a filter string.
Definition: sign_widget.h:21
safeguards.h
A number of safeguards to prevent using unsafe methods.
WID_QES_DELETE
Delete button.
Definition: sign_widget.h:32
HotkeyList
List of hotkeys for a window.
Definition: hotkeys.h:42
WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:104
SignListWindow::OnResize
virtual void OnResize()
Called after the window got resized.
Definition: signs_gui.cpp:259
WID_SIL_FILTER_ENTER_BTN
Scroll to first sign.
Definition: sign_widget.h:23
geometry_func.hpp
Geometry functions.
WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:50
SignList::SignNameFilter
static bool CDECL SignNameFilter(const Sign *const *a, StringFilter &filter)
Filter sign list by sign name.
Definition: signs_gui.cpp:103
SignListWindow::SetStringParameters
virtual void SetStringParameters(int widget) const
Initialize string parameters for a widget.
Definition: signs_gui.cpp:227
company_gui.h
GUI Functions related to companies.
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
OWNER_NONE
The tile has no ownership.
Definition: company_type.h:27
WD_FRAMERECT_BOTTOM
Offset at bottom to draw the frame rectangular area.
Definition: window_gui.h:65
WID_QES_OK
OK button.
Definition: sign_widget.h:30
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
WD_FRAMETEXT_RIGHT
Right offset of the text of the frame.
Definition: window_gui.h:73
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
WD_FRAMETEXT_LEFT
Left offset of the text of the frame.
Definition: window_gui.h:72
QueryString::cancel_button
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
Definition: querystring_gui.h:30
GUIList::Sort
bool Sort(SortFunction *compare)
Sort the list.
Definition: sortlist_type.h:256
DeleteWindowByClass
void DeleteWindowByClass(WindowClass cls)
Delete all windows of a given class.
Definition: window.cpp:1150
Scrollbar::IsVisible
bool IsVisible(uint16 item) const
Checks whether given current item is visible in the list.
Definition: widget_type.h:641
Textbuf::Assign
void Assign(StringID string)
Render a string into the textbuffer.
Definition: textbuf.cpp:399
DEBUG
#define DEBUG(name, level,...)
Output a line of debugging information.
Definition: debug.h:39
GetStringBoundingBox
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:699
SignListGlobalHotkeys
static EventState SignListGlobalHotkeys(int hotkey)
Handler for global hotkeys of the SignListWindow.
Definition: signs_gui.cpp:347
StringFilter::AddLine
void AddLine(const char *str)
Pass another text line from the current item to the filter.
Definition: stringfilter.cpp:108
Scrollbar::GetCount
uint16 GetCount() const
Gets the number of elements in the list.
Definition: widget_type.h:613
SLHK_FOCUS_FILTER_BOX
Focus the edit box for editing the filter string.
Definition: signs_gui.cpp:146
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
SignList::string_filter
StringFilter string_filter
The match string to be used when the GUIList is (re)-sorted.
Definition: signs_gui.cpp:47
company_func.h
Functions related to companies.
TileVirtXY
static TileIndex TileVirtXY(uint x, uint y)
Get a tile from the virtual XY-coordinate.
Definition: map_func.h:196
sign_widget.h
Types related to the sign widgets.
Textbuf::buf
char *const buf
buffer in which text is saved
Definition: textbuf_type.h:34
SignListWindow::filter_editbox
QueryString filter_editbox
Filter editbox;.
Definition: signs_gui.cpp:150
SignList::SignNameSorter
static int CDECL SignNameSorter(const Sign *const *a, const Sign *const *b)
Sort signs by their name.
Definition: signs_gui.cpp:75
WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:61
strnatcmp
int strnatcmp(const char *s1, const char *s2, bool ignore_garbage_at_front)
Compares two strings using case insensitive natural sort.
Definition: string.cpp:569
HandleClickOnSign
void HandleClickOnSign(const Sign *si)
Handle clicking on a sign.
Definition: signs_gui.cpp:555
StrEmpty
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:59
GUIList::SetFilterState
void SetFilterState(bool state)
Enable or disable the filter.
Definition: sortlist_type.h:318
WID_QES_CAPTION
Caption of the window.
Definition: sign_widget.h:28
Sign
Definition: signs_base.h:23
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:52
transparency.h
Functions related to transparency.
stringfilter_type.h
Searching and filtering using a stringterm.
SetDParamMaxValue
void SetDParamMaxValue(uint n, uint64 max_value, uint min_count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
Definition: strings.cpp:105
ShowSignList
Window * ShowSignList()
Open the sign list window.
Definition: signs_gui.cpp:403
NWID_VERTICAL
Vertical container.
Definition: widget_type.h:77
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
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.
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:28
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:768
WID_QES_CANCEL
Cancel button.
Definition: sign_widget.h:31
SignID
uint16 SignID
The type of the IDs of signs.
Definition: signs_type.h:16
WWT_PUSHARROWBTN
Normal push-button (no toggle button) with arrow caption.
Definition: widget_type.h:106
SignListWindow
Definition: signs_gui.cpp:149
SignListWindow::OnHundredthTick
virtual void OnHundredthTick()
Called once every 100 (game) ticks.
Definition: signs_gui.cpp:315
SignListWindow::SetFilterString
void SetFilterString(const char *new_filter_string)
This function sets the filter string of the sign list.
Definition: signs_gui.cpp:180
WD_FRAMERECT_RIGHT
Offset at right to draw the frame rectangular area.
Definition: window_gui.h:63
SignList::OwnerDeityFilter
static bool CDECL OwnerDeityFilter(const Sign *const *a, StringFilter &filter)
Filter sign list excluding OWNER_DEITY.
Definition: signs_gui.cpp:116
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
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:105
SignList::SignList
SignList()
Creates a SignList with filtering disabled by default.
Definition: signs_gui.cpp:53
CMD_MSG
#define CMD_MSG(x)
Used to combine a StringID with the command.
Definition: command_type.h:366
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
ES_HANDLED
The passed event is handled.
Definition: window_type.h:702
TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:26
window_func.h
Window functions not directly related to making/drawing windows.
WDP_AUTO
Find a place automatically.
Definition: window_gui.h:156
SignListWindow::OnHotkey
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
Definition: signs_gui.cpp:285
RenameSign
static bool RenameSign(SignID index, const char *text)
Actually rename the sign.
Definition: signs_gui.cpp:414
WID_QES_NEXT
Next button.
Definition: sign_widget.h:34
WID_SIL_FILTER_MATCH_CASE_BTN
Button to toggle if case sensitive filtering should be used.
Definition: sign_widget.h:22
SignListWindow::DrawWidget
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
Definition: signs_gui.cpp:195
SignList::OwnerVisibilityFilter
static bool CDECL OwnerVisibilityFilter(const Sign *const *a, StringFilter &filter)
Filter sign list by owner.
Definition: signs_gui.cpp:123
SetScrollbar
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1095
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:34
WC_QUERY_STRING
Query string window; Window numbers:
Definition: window_type.h:118
StringFilter::IsEmpty
bool IsEmpty() const
Check whether any filter words were entered.
Definition: stringfilter_type.h:61
WD_FRAMERECT_LEFT
Offset at left to draw the frame rectangular area.
Definition: window_gui.h:62
sprites.h
This file contains all sprite-related enums and defines.
WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:64
WID_SIL_CAPTION
Caption of the window.
Definition: sign_widget.h:18
SignWindow::OnClick
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
Definition: signs_gui.cpp:490
WID_QES_PREVIOUS
Previous button.
Definition: sign_widget.h:33
SignListWindow::OnInvalidateData
virtual void OnInvalidateData(int data=0, bool gui_scope=true)
Some data on this window has become invalid.
Definition: signs_gui.cpp:326
WWT_TEXTBTN
(Toggle) Button with text
Definition: widget_type.h:55
signs_base.h
Base class for signs.
Scrollbar::GetPosition
uint16 GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:631
SignListWindow::UpdateWidgetSize
virtual 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: signs_gui.cpp:264
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
SignList::FilterSignList
void FilterSignList()
Filter out signs from the sign list that does not match the name filter.
Definition: signs_gui.cpp:131