OpenTTD Source: src/signs_gui.cpp Source File

OpenTTD Source 14.1

signs_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 "company_gui.h"
12 #include "company_func.h"
13 #include "signs_base.h"
14 #include "signs_func.h"
15 #include "debug.h"
16 #include "command_func.h"
17 #include "strings_func.h"
18 #include "window_func.h"
19 #include "map_func.h"
20 #include "viewport_func.h"
21 #include "querystring_gui.h"
22 #include "sortlist_type.h"
23 #include "stringfilter_type.h"
24 #include "string_func.h"
25 #include "core/geometry_func.hpp"
26 #include "hotkeys.h"
27 #include "transparency.h"
28 #include "gui.h"
29 #include "signs_cmd.h"
30 #include "timer/timer.h"
31 #include "timer/timer_window.h"
32
33 #include "widgets/sign_widget.h"
34
35 #include "table/strings.h"
36 #include "table/sprites.h"
37
38 #include "safeguards.h"
39
40 struct SignList {
44 typedef GUIList<const Sign *, std::nullptr_t, StringFilter &> GUISignList;
45
46 GUISignList signs;
47
48 StringFilter string_filter;
49 static bool match_case;
50 static std::string default_name;
51
55 SignList() : string_filter(&match_case)
56 {
57 }
58
59 void BuildSignsList()
60 {
61 if (!this->signs.NeedRebuild()) return;
62
63 Debug(misc, 3, "Building sign list");
64
65 this->signs.clear();
66
67 for (const Sign *si : Sign::Iterate()) this->signs.push_back(si);
68
69 this->signs.SetFilterState(true);
70 this->FilterSignList();
71 this->signs.shrink_to_fit();
72 this->signs.RebuildDone();
73 }
74
76 static bool SignNameSorter(const Sign * const &a, const Sign * const &b)
77 {
78 /* Signs are very very rarely using the default text, but there can also be
79 * a lot of them. Therefore a worthwhile performance gain can be made by
80 * directly comparing Sign::name instead of going through the string
81 * system for each comparison. */
82 const std::string &a_name = a->name.empty() ? SignList::default_name : a->name;
83 const std::string &b_name = b->name.empty() ? SignList::default_name : b->name;
84
85 int r = StrNaturalCompare(a_name, b_name); // Sort by name (natural sorting).
86
87 return r != 0 ? r < 0 : (a->index < b->index);
88 }
89
90 void SortSignsList()
91 {
92 if (!this->signs.Sort(&SignNameSorter)) return;
93 }
94
96 static bool CDECL SignNameFilter(const Sign * const *a, StringFilter &filter)
97 {
98 /* Same performance benefit as above for sorting. */
99 const std::string &a_name = (*a)->name.empty() ? SignList::default_name : (*a)->name;
100
101 filter.ResetState();
102 filter.AddLine(a_name);
103 return filter.GetState();
104 }
105
107 static bool CDECL OwnerDeityFilter(const Sign * const *a, StringFilter &)
108 {
109 /* You should never be able to edit signs of owner DEITY */
110 return (*a)->owner != OWNER_DEITY;
111 }
112
114 static bool CDECL OwnerVisibilityFilter(const Sign * const *a, StringFilter &)
115 {
116 assert(!HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS));
117 /* Hide sign if non-own signs are hidden in the viewport */
118 return (*a)->owner == _local_company || (*a)->owner == OWNER_DEITY;
119 }
120
122 void FilterSignList()
123 {
124 this->signs.Filter(&SignNameFilter, this->string_filter);
125 if (_game_mode != GM_EDITOR) this->signs.Filter(&OwnerDeityFilter, this->string_filter);
126 if (!HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS)) {
127 this->signs.Filter(&OwnerVisibilityFilter, this->string_filter);
128 }
129 }
130 };
131
132 bool SignList::match_case = false;
133 std::string SignList::default_name;
134
136 enum SignListHotkeys {
137 SLHK_FOCUS_FILTER_BOX,
138 };
139
140 struct SignListWindow : Window, SignList {
141 QueryString filter_editbox;
142 int text_offset;
143 Scrollbar *vscroll;
144
145 SignListWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc), filter_editbox(MAX_LENGTH_SIGN_NAME_CHARS * MAX_CHAR_LENGTH, MAX_LENGTH_SIGN_NAME_CHARS)
146 {
147 this->CreateNestedTree();
148 this->vscroll = this->GetScrollbar(WID_SIL_SCROLLBAR);
149 this->FinishInitNested(window_number);
150 this->SetWidgetLoweredState(WID_SIL_FILTER_MATCH_CASE_BTN, SignList::match_case);
151
152 /* Initialize the text edit widget */
153 this->querystrings[WID_SIL_FILTER_TEXT] = &this->filter_editbox;
154 this->filter_editbox.cancel_button = QueryString::ACTION_CLEAR;
155
156 /* Initialize the filtering variables */
157 this->SetFilterString("");
158
159 /* Create initial list. */
160 this->signs.ForceRebuild();
161 this->signs.ForceResort();
162 this->BuildSortSignList();
163 }
164
165 void OnInit() override
166 {
167 /* Default sign name, used if Sign::name is nullptr. */
168 SignList::default_name = GetString(STR_DEFAULT_SIGN_NAME);
169 this->signs.ForceResort();
170 this->SortSignsList();
171 this->SetDirty();
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 void OnPaint() override
190 {
191 if (!this->IsShaded() && this->signs.NeedRebuild()) this->BuildSortSignList();
192 this->DrawWidgets();
193 }
194
195 void DrawWidget(const Rect &r, WidgetID widget) const override
196 {
197 switch (widget) {
198 case WID_SIL_LIST: {
199 Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
200 uint text_offset_y = (this->resize.step_height - GetCharacterHeight(FS_NORMAL) + 1) / 2;
201 /* No signs? */
202 if (this->vscroll->GetCount() == 0) {
203 DrawString(tr.left, tr.right, tr.top + text_offset_y, STR_STATION_LIST_NONE);
204 return;
205 }
206
207 Dimension d = GetSpriteSize(SPR_COMPANY_ICON);
208 bool rtl = _current_text_dir == TD_RTL;
209 int sprite_offset_y = (this->resize.step_height - d.height + 1) / 2;
210 uint icon_left = rtl ? tr.right - this->text_offset : tr.left;
211 tr = tr.Indent(this->text_offset, rtl);
212
213 /* At least one sign available. */
214 for (uint16_t i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < this->vscroll->GetCount(); i++)
215 {
216 const Sign *si = this->signs[i];
217
218 if (si->owner != OWNER_NONE) DrawCompanyIcon(si->owner, icon_left, tr.top + sprite_offset_y);
219
220 SetDParam(0, si->index);
221 DrawString(tr.left, tr.right, tr.top + text_offset_y, STR_SIGN_NAME, TC_YELLOW);
222 tr.top += this->resize.step_height;
223 }
224 break;
225 }
226 }
227 }
228
229 void SetStringParameters(WidgetID widget) const override
230 {
231 if (widget == WID_SIL_CAPTION) SetDParam(0, this->vscroll->GetCount());
232 }
233
234 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
235 {
236 switch (widget) {
237 case WID_SIL_LIST: {
238 auto it = this->vscroll->GetScrolledItemFromWidget(this->signs, pt.y, this, WID_SIL_LIST, WidgetDimensions::scaled.framerect.top);
239 if (it == this->signs.end()) return;
240
241 const Sign *si = *it;
242 ScrollMainWindowToTile(TileVirtXY(si->x, si->y));
243 break;
244 }
245
246 case WID_SIL_FILTER_ENTER_BTN:
247 if (this->signs.size() >= 1) {
248 const Sign *si = this->signs[0];
249 ScrollMainWindowToTile(TileVirtXY(si->x, si->y));
250 }
251 break;
252
253 case WID_SIL_FILTER_MATCH_CASE_BTN:
254 SignList::match_case = !SignList::match_case; // Toggle match case
255 this->SetWidgetLoweredState(WID_SIL_FILTER_MATCH_CASE_BTN, SignList::match_case); // Toggle button pushed state
256 this->InvalidateData(); // Rebuild the list of signs
257 break;
258 }
259 }
260
261 void OnResize() override
262 {
263 this->vscroll->SetCapacityFromWidget(this, WID_SIL_LIST, WidgetDimensions::scaled.framerect.Vertical());
264 }
265
266 void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
267 {
268 switch (widget) {
269 case WID_SIL_LIST: {
270 Dimension spr_dim = GetSpriteSize(SPR_COMPANY_ICON);
271 this->text_offset = WidgetDimensions::scaled.frametext.left + spr_dim.width + 2; // 2 pixels space between icon and the sign text.
272 resize->height = std::max<uint>(GetCharacterHeight(FS_NORMAL), spr_dim.height + 2);
273 Dimension d = {(uint)(this->text_offset + WidgetDimensions::scaled.frametext.right), padding.height + 5 * resize->height};
274 *size = maxdim(*size, d);
275 break;
276 }
277
278 case WID_SIL_CAPTION:
279 SetDParamMaxValue(0, Sign::GetPoolSize(), 3);
280 *size = GetStringBoundingBox(STR_SIGN_LIST_CAPTION);
281 size->height += padding.height;
282 size->width += padding.width;
283 break;
284 }
285 }
286
287 EventState OnHotkey(int hotkey) override
288 {
289 switch (hotkey) {
290 case SLHK_FOCUS_FILTER_BOX:
291 this->SetFocusedWidget(WID_SIL_FILTER_TEXT);
292 SetFocusedWindow(this); // The user has asked to give focus to the text box, so make sure this window is focused.
293 break;
294
295 default:
296 return ES_NOT_HANDLED;
297 }
298
299 return ES_HANDLED;
300 }
301
302 void OnEditboxChanged(WidgetID widget) override
303 {
304 if (widget == WID_SIL_FILTER_TEXT) this->SetFilterString(this->filter_editbox.text.buf);
305 }
306
307 void BuildSortSignList()
308 {
309 if (this->signs.NeedRebuild()) {
310 this->BuildSignsList();
311 this->vscroll->SetCount(this->signs.size());
312 this->SetWidgetDirty(WID_SIL_CAPTION);
313 }
314 this->SortSignsList();
315 }
316
318 IntervalTimer<TimerWindow> rebuild_interval = {std::chrono::seconds(3), [this](auto) {
319 this->BuildSortSignList();
320 this->SetDirty();
321 }};
322
328 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
329 {
330 /* When there is a filter string, we always need to rebuild the list even if
331 * the amount of signs in total is unchanged, as the subset of signs that is
332 * accepted by the filter might has changed. */
333 if (data == 0 || data == -1 || !this->string_filter.IsEmpty()) { // New or deleted sign, changed visibility setting or there is a filter string
334 /* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
335 this->signs.ForceRebuild();
336 } else { // Change of sign contents while there is no filter string
337 this->signs.ForceResort();
338 }
339 }
340
346 static EventState SignListGlobalHotkeys(int hotkey)
347 {
348 if (_game_mode == GM_MENU) return ES_NOT_HANDLED;
349 Window *w = ShowSignList();
350 if (w == nullptr) return ES_NOT_HANDLED;
351 return w->OnHotkey(hotkey);
352 }
353
354 static inline HotkeyList hotkeys{"signlist", {
355 Hotkey('F', "focus_filter_box", SLHK_FOCUS_FILTER_BOX),
356 }, SignListGlobalHotkeys};
357 };
358
359 static constexpr NWidgetPart _nested_sign_list_widgets[] = {
360 NWidget(NWID_HORIZONTAL),
361 NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
362 NWidget(WWT_CAPTION, COLOUR_BROWN, WID_SIL_CAPTION), SetDataTip(STR_SIGN_LIST_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
363 NWidget(WWT_SHADEBOX, COLOUR_BROWN),
364 NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
365 NWidget(WWT_STICKYBOX, COLOUR_BROWN),
366 EndContainer(),
367 NWidget(NWID_HORIZONTAL),
368 NWidget(NWID_VERTICAL),
369 NWidget(WWT_PANEL, COLOUR_BROWN, WID_SIL_LIST), SetMinimalSize(WidgetDimensions::unscaled.frametext.Horizontal() + 16 + 255, 0),
370 SetResize(1, 1), SetFill(1, 0), SetScrollbar(WID_SIL_SCROLLBAR), EndContainer(),
371 NWidget(NWID_HORIZONTAL),
372 NWidget(WWT_PANEL, COLOUR_BROWN), SetFill(1, 1),
373 NWidget(WWT_EDITBOX, COLOUR_BROWN, WID_SIL_FILTER_TEXT), SetMinimalSize(80, 12), SetResize(1, 0), SetFill(1, 0), SetPadding(2, 2, 2, 2),
374 SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
375 EndContainer(),
376 NWidget(WWT_TEXTBTN, COLOUR_BROWN, WID_SIL_FILTER_MATCH_CASE_BTN), SetDataTip(STR_SIGN_LIST_MATCH_CASE, STR_SIGN_LIST_MATCH_CASE_TOOLTIP),
377 EndContainer(),
378 EndContainer(),
379 NWidget(NWID_VERTICAL),
380 NWidget(NWID_VSCROLLBAR, COLOUR_BROWN, WID_SIL_SCROLLBAR),
381 NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
382 EndContainer(),
383 EndContainer(),
384 };
385
386 static WindowDesc _sign_list_desc(__FILE__, __LINE__,
387 WDP_AUTO, "list_signs", 358, 138,
388 WC_SIGN_LIST, WC_NONE,
389 0,
390 std::begin(_nested_sign_list_widgets), std::end(_nested_sign_list_widgets),
391 &SignListWindow::hotkeys
392 );
393
399 Window *ShowSignList()
400 {
401 return AllocateWindowDescFront<SignListWindow>(&_sign_list_desc, 0);
402 }
403
410 static bool RenameSign(SignID index, const char *text)
411 {
412 bool remove = StrEmpty(text);
413 Command<CMD_RENAME_SIGN>::Post(StrEmpty(text) ? STR_ERROR_CAN_T_DELETE_SIGN : STR_ERROR_CAN_T_CHANGE_SIGN_NAME, index, text);
414 return remove;
415 }
416
417 struct SignWindow : Window, SignList {
418 QueryString name_editbox;
419 SignID cur_sign;
420
421 SignWindow(WindowDesc *desc, const Sign *si) : Window(desc), name_editbox(MAX_LENGTH_SIGN_NAME_CHARS * MAX_CHAR_LENGTH, MAX_LENGTH_SIGN_NAME_CHARS)
422 {
423 this->querystrings[WID_QES_TEXT] = &this->name_editbox;
424 this->name_editbox.caption = STR_EDIT_SIGN_CAPTION;
425 this->name_editbox.cancel_button = WID_QES_CANCEL;
426 this->name_editbox.ok_button = WID_QES_OK;
427
428 this->InitNested(WN_QUERY_STRING_SIGN);
429
430 UpdateSignEditWindow(si);
431 this->SetFocusedWidget(WID_QES_TEXT);
432 }
433
434 void UpdateSignEditWindow(const Sign *si)
435 {
436 /* Display an empty string when the sign hasn't been edited yet */
437 if (!si->name.empty()) {
438 SetDParam(0, si->index);
439 this->name_editbox.text.Assign(STR_SIGN_NAME);
440 } else {
441 this->name_editbox.text.DeleteAll();
442 }
443
444 this->cur_sign = si->index;
445
446 this->SetWidgetDirty(WID_QES_TEXT);
447 this->SetFocusedWidget(WID_QES_TEXT);
448 }
449
455 const Sign *PrevNextSign(bool next)
456 {
457 /* Rebuild the sign list */
458 this->signs.ForceRebuild();
459 this->signs.NeedResort();
460 this->BuildSignsList();
461 this->SortSignsList();
462
463 /* Search through the list for the current sign, excluding
464 * - the first sign if we want the previous sign or
465 * - the last sign if we want the next sign */
466 size_t end = this->signs.size() - (next ? 1 : 0);
467 for (uint i = next ? 0 : 1; i < end; i++) {
468 if (this->cur_sign == this->signs[i]->index) {
469 /* We've found the current sign, so return the sign before/after it */
470 return this->signs[i + (next ? 1 : -1)];
471 }
472 }
473 /* If we haven't found the current sign by now, return the last/first sign */
474 return next ? this->signs.front() : this->signs.back();
475 }
476
477 void SetStringParameters(WidgetID widget) const override
478 {
479 switch (widget) {
480 case WID_QES_CAPTION:
481 SetDParam(0, this->name_editbox.caption);
482 break;
483 }
484 }
485
486 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
487 {
488 switch (widget) {
489 case WID_QES_LOCATION: {
490 const Sign *si = Sign::Get(this->cur_sign);
491 TileIndex tile = TileVirtXY(si->x, si->y);
492 if (_ctrl_pressed) {
493 ShowExtraViewportWindow(tile);
494 } else {
495 ScrollMainWindowToTile(tile);
496 }
497 break;
498 }
499
500 case WID_QES_PREVIOUS:
501 case WID_QES_NEXT: {
502 const Sign *si = this->PrevNextSign(widget == WID_QES_NEXT);
503
504 /* Rebuild the sign list */
505 this->signs.ForceRebuild();
506 this->signs.NeedResort();
507 this->BuildSignsList();
508 this->SortSignsList();
509
510 /* Scroll to sign and reopen window */
511 ScrollMainWindowToTile(TileVirtXY(si->x, si->y));
512 UpdateSignEditWindow(si);
513 break;
514 }
515
516 case WID_QES_DELETE:
517 /* Only need to set the buffer to null, the rest is handled as the OK button */
518 RenameSign(this->cur_sign, "");
519 /* don't delete this, we are deleted in Sign::~Sign() -> DeleteRenameSignWindow() */
520 break;
521
522 case WID_QES_OK:
523 if (RenameSign(this->cur_sign, this->name_editbox.text.buf)) break;
524 [[fallthrough]];
525
526 case WID_QES_CANCEL:
527 this->Close();
528 break;
529 }
530 }
531 };
532
533 static constexpr NWidgetPart _nested_query_sign_edit_widgets[] = {
534 NWidget(NWID_HORIZONTAL),
535 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
536 NWidget(WWT_CAPTION, COLOUR_GREY, WID_QES_CAPTION), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS), SetTextStyle(TC_WHITE),
537 NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_QES_LOCATION), SetMinimalSize(12, 14), SetDataTip(SPR_GOTO_LOCATION, STR_EDIT_SIGN_LOCATION_TOOLTIP),
538 EndContainer(),
539 NWidget(WWT_PANEL, COLOUR_GREY),
540 NWidget(WWT_EDITBOX, COLOUR_GREY, WID_QES_TEXT), SetMinimalSize(256, 12), SetDataTip(STR_EDIT_SIGN_SIGN_OSKTITLE, STR_NULL), SetPadding(2, 2, 2, 2),
541 EndContainer(),
542 NWidget(NWID_HORIZONTAL),
543 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_QES_OK), SetMinimalSize(61, 12), SetDataTip(STR_BUTTON_OK, STR_NULL),
544 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_QES_CANCEL), SetMinimalSize(60, 12), SetDataTip(STR_BUTTON_CANCEL, STR_NULL),
545 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_QES_DELETE), SetMinimalSize(60, 12), SetDataTip(STR_TOWN_VIEW_DELETE_BUTTON, STR_NULL),
546 NWidget(WWT_PANEL, COLOUR_GREY), SetFill(1, 1), EndContainer(),
547 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_QES_PREVIOUS), SetMinimalSize(11, 12), SetDataTip(AWV_DECREASE, STR_EDIT_SIGN_PREVIOUS_SIGN_TOOLTIP),
548 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_QES_NEXT), SetMinimalSize(11, 12), SetDataTip(AWV_INCREASE, STR_EDIT_SIGN_NEXT_SIGN_TOOLTIP),
549 EndContainer(),
550 };
551
552 static WindowDesc _query_sign_edit_desc(__FILE__, __LINE__,
553 WDP_CENTER, nullptr, 0, 0,
554 WC_QUERY_STRING, WC_NONE,
555 WDF_CONSTRUCTION,
556 std::begin(_nested_query_sign_edit_widgets), std::end(_nested_query_sign_edit_widgets)
557 );
558
563 void HandleClickOnSign(const Sign *si)
564 {
565 /* If we can't rename the sign, don't even open the rename GUI. */
566 if (!CompanyCanRenameSign(si)) return;
567
568 if (_ctrl_pressed && (si->owner == _local_company || (si->owner == OWNER_DEITY && _game_mode == GM_EDITOR))) {
569 RenameSign(si->index, "");
570 return;
571 }
572
573 ShowRenameSignWindow(si);
574 }
575
580 void ShowRenameSignWindow(const Sign *si)
581 {
582 /* Delete all other edit windows */
583 CloseWindowByClass(WC_QUERY_STRING);
584
585 new SignWindow(&_query_sign_edit_desc, si);
586 }
587
592 void DeleteRenameSignWindow(SignID sign)
593 {
594 SignWindow *w = dynamic_cast<SignWindow *>(FindWindowById(WC_QUERY_STRING, WN_QUERY_STRING_SIGN));
595
596 if (w != nullptr && w->cur_sign == sign) w->Close();
597 }
DO_SHOW_COMPETITOR_SIGNS
@ DO_SHOW_COMPETITOR_SIGNS
Display signs, station names and waypoint names of opponent companies. Buoys and oilrig-stations are ...
Definition: openttd.h:52
ES_HANDLED
@ ES_HANDLED
The passed event is handled.
Definition: window_type.h:739
SignListWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: signs_gui.cpp:261
SetFill
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1143
SignListWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: signs_gui.cpp:189
CloseWindowByClass
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
Definition: window.cpp:1153
Pool::PoolItem<&_sign_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:339
ScrollMainWindowToTile
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Definition: viewport.cpp:2509
QueryString::ok_button
int ok_button
Widget button of parent window to simulate when pressing OK in OSK.
Definition: querystring_gui.h:27
querystring_gui.h
ShowExtraViewportWindow
void ShowExtraViewportWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
Definition: viewport_gui.cpp:156
HotkeyList
List of hotkeys for a window.
Definition: hotkeys.h:37
SetFocusedWindow
void SetFocusedWindow(Window *w)
Set the window that has the focus.
Definition: window.cpp:423
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:30
command_func.h
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition: window_gui.h:68
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:68
WDF_CONSTRUCTION
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
Definition: window_gui.h:197
GUIList::SetFilterState
void SetFilterState(bool state)
Enable or disable the filter.
Definition: sortlist_type.h:327
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition: geometry_type.hpp:98
StringFilter::IsEmpty
bool IsEmpty() const
Check whether any filter words were entered.
Definition: stringfilter_type.h:60
SignListWindow::filter_editbox
QueryString filter_editbox
Filter editbox;.
Definition: signs_gui.cpp:141
StringFilter::SetFilterTerm
void SetFilterTerm(const char *str)
Set the term to filter on.
Definition: stringfilter.cpp:28
SignList::SignList
SignList()
Creates a SignList with filtering disabled by default.
Definition: signs_gui.cpp:55
SignList
Definition: signs_gui.cpp:40
signs_func.h
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:63
company_gui.h
Window::SetWidgetDirty
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:552
GUIList< const Sign *, std::nullptr_t, StringFilter & >
Textbuf::Assign
void Assign(StringID string)
Render a string into the textbuffer.
Definition: textbuf.cpp:405
SignWindow
Definition: signs_gui.cpp:417
DeleteRenameSignWindow
void DeleteRenameSignWindow(SignID sign)
Close the sign window associated with the given sign.
Definition: signs_gui.cpp:592
WID_QES_TEXT
@ WID_QES_TEXT
Text of the query.
Definition: sign_widget.h:28
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition: widget_type.h:67
IntervalTimer< TimerWindow >
map_func.h
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:238
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:77
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition: geometry_func.cpp:22
SignList::FilterSignList
void FilterSignList()
Filter out signs from the sign list that does not match the name filter.
Definition: signs_gui.cpp:122
Window::Close
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Definition: window.cpp:1048
FindWindowById
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition: window.cpp:1099
MAX_LENGTH_SIGN_NAME_CHARS
static const uint MAX_LENGTH_SIGN_NAME_CHARS
The maximum length of a sign name in characters including '\0'.
Definition: signs_type.h:19
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1153
sign_widget.h
WC_SIGN_LIST
@ WC_SIGN_LIST
Sign list; Window numbers:
Definition: window_type.h:278
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:37
Scrollbar::SetCapacityFromWidget
void SetCapacityFromWidget(Window *w, WidgetID widget, int padding=0)
Set capacity of visible elements from the size and resize properties of a widget.
Definition: widget.cpp:2341
WID_SIL_LIST
@ WID_SIL_LIST
List of signs.
Definition: sign_widget.h:17
StrNaturalCompare
int StrNaturalCompare(std::string_view s1, std::string_view s2, bool ignore_garbage_at_front)
Compares two strings using case insensitive natural sort.
Definition: string.cpp:585
SignListHotkeys
SignListHotkeys
Enum referring to the Hotkeys in the sign list window.
Definition: signs_gui.cpp:136
WWT_PUSHARROWBTN
@ WWT_PUSHARROWBTN
Normal push-button (no toggle button) with arrow caption.
Definition: widget_type.h:112
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
StringFilter::AddLine
void AddLine(const char *str)
Pass another text line from the current item to the filter.
Definition: stringfilter.cpp:114
_display_opt
byte _display_opt
What do we want to draw/do?
Definition: transparency_gui.cpp:26
SignListWindow::SignListGlobalHotkeys
static EventState SignListGlobalHotkeys(int hotkey)
Handler for global hotkeys of the SignListWindow.
Definition: signs_gui.cpp:346
SignID
uint16_t SignID
The type of the IDs of signs.
Definition: signs_type.h:14
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:680
Window::GetScrollbar
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:315
StrEmpty
bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:56
Window::OnHotkey
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
Definition: window.cpp:566
Window::Window
Window(WindowDesc *desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition: window.cpp:1757
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:1040
GUIList::NeedRebuild
bool NeedRebuild() const
Check if a rebuild is needed.
Definition: sortlist_type.h:387
Scrollbar::GetPosition
uint16_t GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:722
QueryString
Data stored about a string that can be modified in the GUI.
Definition: querystring_gui.h:20
Debug
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
Definition: debug.h:37
Textbuf::buf
char *const buf
buffer in which text is saved
Definition: textbuf_type.h:32
WID_SIL_FILTER_TEXT
@ WID_SIL_FILTER_TEXT
Text box for typing a filter string.
Definition: sign_widget.h:19
Scrollbar::GetCount
uint16_t GetCount() const
Gets the number of elements in the list.
Definition: widget_type.h:704
MAX_CHAR_LENGTH
static const int MAX_CHAR_LENGTH
Max. length of UTF-8 encoded unicode character.
Definition: strings_type.h:18
SignList::OwnerDeityFilter
static bool CDECL OwnerDeityFilter(const Sign *const *a, StringFilter &)
Filter sign list excluding OWNER_DEITY.
Definition: signs_gui.cpp:107
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:455
WindowDesc
High level window description.
Definition: window_gui.h:153
WidgetID
int WidgetID
Widget ID.
Definition: window_type.h:18
Pool::PoolItem<&_sign_pool >::GetPoolSize
static size_t GetPoolSize()
Returns first unused index.
Definition: pool_type.hpp:360
SetPadding
constexpr NWidgetPart SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
Widget part function for setting additional space around a widget.
Definition: widget_type.h:1190
WC_QUERY_STRING
@ WC_QUERY_STRING
Query string window; Window numbers:
Definition: window_type.h:123
SignList::string_filter
StringFilter string_filter
The match string to be used when the GUIList is (re)-sorted.
Definition: signs_gui.cpp:48
SetResize
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition: widget_type.h:1088
signs_cmd.h
GUIList::NeedResort
bool NeedResort()
Check if a resort is needed next loop If used the resort timer will decrease every call till 0.
Definition: sortlist_type.h:220
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:141
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:308
WindowNumber
int32_t WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:732
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition: gfx_type.h:203
Window::InitNested
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition: window.cpp:1747
SetScrollbar
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1246
GUIList::Filter
bool Filter(FilterFunction *decide, F filter_data)
Filter the list.
Definition: sortlist_type.h:343
WWT_EDITBOX
@ WWT_EDITBOX
a textbox for typing
Definition: widget_type.h:73
WID_QES_DELETE
@ WID_QES_DELETE
Delete button.
Definition: sign_widget.h:31
ShowRenameSignWindow
void ShowRenameSignWindow(const Sign *si)
Show the window to change the text of a sign.
Definition: signs_gui.cpp:580
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:941
WID_QES_LOCATION
@ WID_QES_LOCATION
Scroll to sign location.
Definition: sign_widget.h:27
GUIList::ForceResort
void ForceResort()
Force a resort next Sort call Reset the resort timer if used too.
Definition: sortlist_type.h:234
ES_NOT_HANDLED
@ ES_NOT_HANDLED
The passed event is not handled.
Definition: window_type.h:740
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:110
HandleClickOnSign
void HandleClickOnSign(const Sign *si)
Handle clicking on a sign.
Definition: signs_gui.cpp:563
WID_SIL_FILTER_MATCH_CASE_BTN
@ WID_SIL_FILTER_MATCH_CASE_BTN
Button to toggle if case sensitive filtering should be used.
Definition: sign_widget.h:20
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1260
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:50
safeguards.h
sortlist_type.h
timer.h
WID_SIL_CAPTION
@ WID_SIL_CAPTION
Caption of the window.
Definition: sign_widget.h:16
WID_SIL_FILTER_ENTER_BTN
@ WID_SIL_FILTER_ENTER_BTN
Scroll to first sign.
Definition: sign_widget.h:21
Rect::Indent
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Definition: geometry_type.hpp:198
SignListWindow::OnInit
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition: signs_gui.cpp:165
sprites.h
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
CompanyCanRenameSign
bool CompanyCanRenameSign(const Sign *si)
Check if the current company can rename a given sign.
Definition: signs.cpp:71
Scrollbar::GetScrolledItemFromWidget
Tcontainer::iterator GetScrolledItemFromWidget(Tcontainer &container, int clickpos, const Window *const w, WidgetID widget, int padding=0, int line_height=-1) const
Return an iterator pointing to the element of a scrolled widget that a user clicked in.
Definition: widget_type.h:847
WID_QES_OK
@ WID_QES_OK
OK button.
Definition: sign_widget.h:29
stdafx.h
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:296
Window::SetFocusedWidget
bool SetFocusedWidget(WidgetID widget_index)
Set focus within this window to the given widget.
Definition: window.cpp:487
SignListWindow::OnInvalidateData
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
Definition: signs_gui.cpp:328
ResizeInfo::step_height
uint step_height
Step-size of height resize changes.
Definition: window_gui.h:208
Window::InvalidateData
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
Definition: window.cpp:3144
viewport_func.h
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:45
Window::SetWidgetLoweredState
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition: window_gui.h:441
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:79
DrawCompanyIcon
void DrawCompanyIcon(CompanyID c, int x, int y)
Draw the icon of a company.
Definition: company_cmd.cpp:159
WidgetDimensions::unscaled
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition: window_gui.h:67
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:937
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:71
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:70
GUIList::ForceRebuild
void ForceRebuild()
Force that a rebuild is needed.
Definition: sortlist_type.h:395
string_func.h
WN_QUERY_STRING_SIGN
@ WN_QUERY_STRING_SIGN
Query string for signs.
Definition: window_type.h:30
WWT_PUSHIMGBTN
@ WWT_PUSHIMGBTN
Normal push-button (no toggle button) with image caption.
Definition: widget_type.h:111
Window::querystrings
std::map< WidgetID, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
Definition: window_gui.h:314
QueryString::cancel_button
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
Definition: querystring_gui.h:28
Pool::PoolItem<&_sign_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:388
SignList::OwnerVisibilityFilter
static bool CDECL OwnerVisibilityFilter(const Sign *const *a, StringFilter &)
Filter sign list by owner.
Definition: signs_gui.cpp:114
Window::CreateNestedTree
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1724
strings_func.h
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:86
SignList::match_case
static bool match_case
Should case sensitive matching be used?
Definition: signs_gui.cpp:49
WID_QES_CANCEL
@ WID_QES_CANCEL
Cancel button.
Definition: sign_widget.h:30
Window::IsShaded
bool IsShaded() const
Is window shaded currently?
Definition: window_gui.h:557
Scrollbar::IsVisible
bool IsVisible(uint16_t item) const
Checks whether given current item is visible in the list.
Definition: widget_type.h:732
SetDParamMaxValue
void SetDParamMaxValue(size_t n, uint64_t max_value, uint min_count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
Definition: strings.cpp:127
SignList::default_name
static std::string default_name
Default sign name, used if Sign::name is nullptr.
Definition: signs_gui.cpp:50
SignListWindow
Definition: signs_gui.cpp:140
SetDParam
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings.cpp:104
geometry_func.hpp
ShowSignList
Window * ShowSignList()
Open the sign list window.
Definition: signs_gui.cpp:399
transparency.h
StringFilter::ResetState
void ResetState()
Reset the matching state to process a new item.
Definition: stringfilter.cpp:98
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:52
OWNER_NONE
@ OWNER_NONE
The tile has no ownership.
Definition: company_type.h:25
Scrollbar::SetCount
void SetCount(size_t num)
Sets the number of elements in the list.
Definition: widget_type.h:762
GetString
std::string GetString(StringID string)
Resolve the given StringID into a std::string with all the associated DParam lookups and formatting.
Definition: strings.cpp:327
EventState
EventState
State of handling an event.
Definition: window_type.h:738
Sign
Definition: signs_base.h:21
WID_QES_NEXT
@ WID_QES_NEXT
Next button.
Definition: sign_widget.h:33
StringFilter::GetState
bool GetState() const
Get the matching state of the current item.
Definition: stringfilter_type.h:71
SignList::SignNameFilter
static bool CDECL SignNameFilter(const Sign *const *a, StringFilter &filter)
Filter sign list by sign name.
Definition: signs_gui.cpp:96
OWNER_DEITY
@ OWNER_DEITY
The object is owned by a superuser / goal script.
Definition: company_type.h:27
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1734
company_func.h
QueryString::ACTION_CLEAR
static const int ACTION_CLEAR
Clear editbox.
Definition: querystring_gui.h:24
WID_QES_CAPTION
@ WID_QES_CAPTION
Caption of the window.
Definition: sign_widget.h:26
CommandHelper
Definition: command_func.h:93
window_func.h
GetCharacterHeight
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition: fontcache.cpp:78
stringfilter_type.h
SetMinimalSize
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1099
GUIList::RebuildDone
void RebuildDone()
Notify the sortlist that the rebuild is done.
Definition: sortlist_type.h:405
SignListWindow::OnHotkey
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
Definition: signs_gui.cpp:287
DrawString
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition: gfx.cpp:654
timer_window.h
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:142
TileVirtXY
static debug_inline TileIndex TileVirtXY(uint x, uint y)
Get a tile from the virtual XY-coordinate.
Definition: map_func.h:416
gui.h
WidgetDimensions::frametext
RectPadding frametext
Padding inside frame with text.
Definition: window_gui.h:43
Window
Data structure for an opened window.
Definition: window_gui.h:267
SLHK_FOCUS_FILTER_BOX
@ SLHK_FOCUS_FILTER_BOX
Focus the edit box for editing the filter string.
Definition: signs_gui.cpp:137
SignListWindow::rebuild_interval
IntervalTimer< TimerWindow > rebuild_interval
Resort the sign listing on a regular interval.
Definition: signs_gui.cpp:318
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:731
WID_QES_PREVIOUS
@ WID_QES_PREVIOUS
Previous button.
Definition: sign_widget.h:32
SetDataTip
constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1164
SignListWindow::SetFilterString
void SetFilterString(const char *new_filter_string)
This function sets the filter string of the sign list.
Definition: signs_gui.cpp:180
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:75
SignList::GUISignList
GUIList< const Sign *, std::nullptr_t, StringFilter & > GUISignList
A GUIList contains signs and uses a StringFilter for filtering.
Definition: signs_gui.cpp:44
GUIList::Sort
bool Sort(Comp compare)
Sort the list.
Definition: sortlist_type.h:268
AWV_INCREASE
@ AWV_INCREASE
Arrow to the right or in case of RTL to the left.
Definition: widget_type.h:34
WidgetDimensions::framerect
RectPadding framerect
Standard padding inside many panels.
Definition: window_gui.h:42
WDP_CENTER
@ WDP_CENTER
Center the window.
Definition: window_gui.h:142
Textbuf::DeleteAll
void DeleteAll()
Delete every character in the textbuffer.
Definition: textbuf.cpp:113
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:24
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:56
SetTextStyle
constexpr NWidgetPart SetTextStyle(TextColour colour, FontSize size=FS_NORMAL)
Widget part function for setting the text style.
Definition: widget_type.h:1122
WID_SIL_SCROLLBAR
@ WID_SIL_SCROLLBAR
Scrollbar of list.
Definition: sign_widget.h:18
signs_base.h
GetStringBoundingBox
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:848
StringFilter
String filter and state.
Definition: stringfilter_type.h:30
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition: widget_type.h:57
SignList::SignNameSorter
static bool SignNameSorter(const Sign *const &a, const Sign *const &b)
Sort signs by their name.
Definition: signs_gui.cpp:76
debug.h
AWV_DECREASE
@ AWV_DECREASE
Arrow to the left or in case of RTL to the right.
Definition: widget_type.h:33
RenameSign
static bool RenameSign(SignID index, const char *text)
Actually rename the sign.
Definition: signs_gui.cpp:410
Hotkey
All data for a single hotkey.
Definition: hotkeys.h:21
hotkeys.h
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:66
HasBit
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103