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