Go to the documentation of this file.
33 #include "table/strings.h"
61 Debug(misc, 3,
"Building sign list");
69 this->signs.shrink_to_fit();
160 this->BuildSortSignList();
168 this->SortSignsList();
200 if (this->vscroll->
GetCount() == 0) {
201 DrawString(tr.left, tr.right, tr.top + text_offset_y, STR_STATION_LIST_NONE);
208 uint icon_left = rtl ? tr.right - this->
text_offset : tr.left;
209 tr = tr.
Indent(this->text_offset, rtl);
214 const Sign *si = this->signs[i];
219 DrawString(tr.left, tr.right, tr.top + text_offset_y, STR_SIGN_NAME, TC_YELLOW);
237 if (id_v == INT_MAX)
return;
239 const Sign *si = this->signs[id_v];
245 if (this->signs.size() >= 1) {
246 const Sign *si = this->signs[0];
279 size->height += padding.height;
280 size->width += padding.width;
305 void BuildSortSignList()
308 this->BuildSignsList();
309 this->vscroll->
SetCount((uint)this->signs.size());
312 this->SortSignsList();
317 this->BuildSortSignList();
331 if (data == 0 || data == -1 || !this->string_filter.
IsEmpty()) {
355 static Hotkey signlist_hotkeys[] = {
361 static const NWidgetPart _nested_sign_list_widgets[] = {
375 NWidget(
WWT_EDITBOX, COLOUR_BROWN,
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),
394 _nested_sign_list_widgets,
lengthof(_nested_sign_list_widgets),
395 &SignListWindow::hotkeys
405 return AllocateWindowDescFront<SignListWindow>(&_sign_list_desc, 0);
428 this->name_editbox.caption = STR_EDIT_SIGN_CAPTION;
434 UpdateSignEditWindow(si);
438 void UpdateSignEditWindow(
const Sign *si)
441 if (!si->name.empty()) {
443 this->name_editbox.text.
Assign(STR_SIGN_NAME);
448 this->cur_sign = si->
index;
464 this->BuildSignsList();
465 this->SortSignsList();
470 size_t end = this->signs.size() - (next ? 1 : 0);
471 for (uint i = next ? 0 : 1; i < end; i++) {
472 if (this->cur_sign == this->signs[i]->index) {
474 return this->signs[i + (next ? 1 : -1)];
478 return next ? this->signs.front() : this->signs.back();
485 SetDParam(0, this->name_editbox.caption);
511 this->BuildSignsList();
512 this->SortSignsList();
516 UpdateSignEditWindow(si);
527 if (
RenameSign(this->cur_sign, this->name_editbox.text.
buf))
break;
537 static const NWidgetPart _nested_query_sign_edit_widgets[] = {
544 NWidget(
WWT_EDITBOX, COLOUR_GREY,
WID_QES_TEXT),
SetMinimalSize(256, 12),
SetDataTip(STR_EDIT_SIGN_SIGN_OSKTITLE, STR_NULL),
SetPadding(2, 2, 2, 2),
560 _nested_query_sign_edit_widgets,
lengthof(_nested_query_sign_edit_widgets)
600 if (w !=
nullptr && w->cur_sign == sign) w->
Close();
@ DO_SHOW_COMPETITOR_SIGNS
Display signs, station names and waypoint names of opponent companies. Buoys and oilrig-stations are ...
@ ES_HANDLED
The passed event is handled.
void OnResize() override
Called after the window got resized.
void OnPaint() override
The window must be repainted.
static Titem * Get(size_t index)
Returns Titem with given index.
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
int ok_button
Widget button of parent window to simulate when pressing OK in OSK.
void ShowExtraViewportWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
List of hotkeys for a window.
void SetFocusedWindow(Window *w)
Set the window that has the focus.
Dimensions (a width and height) of a rectangle in 2D.
bool Sort(Comp compare)
Sort the list.
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
bool IsEmpty() const
Check whether any filter words were entered.
QueryString filter_editbox
Filter editbox;.
void SetFilterTerm(const char *str)
Set the term to filter on.
SignList()
Creates a SignList with filtering disabled by default.
static char default_name[64]
Default sign name, used if Sign::name is nullptr.
void Assign(StringID string)
Render a string into the textbuffer.
void DeleteRenameSignWindow(SignID sign)
Close the sign window associated with the given sign.
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
Tindex index
Index of this pool item.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
void FilterSignList()
Filter out signs from the sign list that does not match the name filter.
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
static const uint MAX_LENGTH_SIGN_NAME_CHARS
The maximum length of a sign name in characters including '\0'.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
@ WC_SIGN_LIST
Sign list; Window numbers:
bool _ctrl_pressed
Is Ctrl pressed?
SignListHotkeys
Enum referring to the Hotkeys in the sign list window.
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.
void AddLine(const char *str)
Pass another text line from the current item to the filter.
int32 WindowNumber
Number to differentiate different windows of the same class.
byte _display_opt
What do we want to draw/do?
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
Window(WindowDesc *desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Data stored about a string that can be modified in the GUI.
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
char *const buf
buffer in which text is saved
SmallMap< int, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
static const int MAX_CHAR_LENGTH
Max. length of UTF-8 encoded unicode character.
const Sign * PrevNextSign(bool next)
Returns a pointer to the (alphabetically) previous or next sign of the current sign.
High level window description.
static size_t GetPoolSize()
Returns first unused index.
@ WC_QUERY_STRING
Query string window; Window numbers:
StringFilter string_filter
The match string to be used when the GUIList is (re)-sorted.
@ WDP_AUTO
Find a place automatically.
void SetFilterState(bool state)
Enable or disable the filter.
ResizeInfo resize
Resize information.
static bool CDECL OwnerVisibilityFilter(const Sign *const *a, StringFilter &filter)
Filter sign list by owner.
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
void ShowRenameSignWindow(const Sign *si)
Show the window to change the text of a sign.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
@ ES_NOT_HANDLED
The passed event is not handled.
void HandleClickOnSign(const Sign *si)
Handle clicking on a sign.
static EventState SignListGlobalHotkeys(int hotkey)
Handler for global hotkeys of the SignListWindow.
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
void OnInit() override
Notification that the nested widget tree gets initialized.
Coordinates of a point in 2D.
bool CompanyCanRenameSign(const Sign *si)
Check if the current company can rename a given sign.
void OnHundredthTick() override
Called once every 100 (game) ticks, or once every 3s, whichever comes last.
bool SetFocusedWidget(int widget_index)
Set focus within this window to the given widget.
WindowNumber window_number
Window number within the window class.
uint step_height
Step-size of height resize changes.
bool NeedResort()
Check if a resort is needed next loop If used the resort timer will decrease every call till 0.
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
GUIList< const Sign *, StringFilter & > GUISignList
A GUIList contains signs and uses a StringFilter for filtering.
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
void DrawCompanyIcon(CompanyID c, int x, int y)
Draw the icon of a company.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
bool NeedRebuild() const
Check if a rebuild is needed.
@ WN_QUERY_STRING_SIGN
Query string for signs.
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
static bool match_case
Should case sensitive matching be used?
bool IsShaded() const
Is window shaded currently?
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
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.
void CloseWindowByClass(WindowClass cls)
Close all windows of a given class.
Window * ShowSignList()
Open the sign list window.
void ResetState()
Reset the matching state to process a new item.
@ OWNER_NONE
The tile has no ownership.
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
EventState
State of handling an event.
void OnEditboxChanged(int widget) override
The text in an editbox has been edited.
bool GetState() const
Get the matching state of the current item.
static bool CDECL SignNameFilter(const Sign *const *a, StringFilter &filter)
Filter sign list by sign name.
@ OWNER_DEITY
The object is owned by a superuser / goal script.
bool Filter(FilterFunction *decide, F filter_data)
Filter the list.
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
static const int ACTION_CLEAR
Clear editbox.
void ForceResort()
Force a resort next Sort call Reset the resort timer if used too.
void ForceRebuild()
Force that a rebuild is needed.
#define Debug(name, level, format_string,...)
Ouptut a line of debugging information.
#define lengthof(x)
Return the length of an fixed size array.
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
int text_offset
Offset of the sign text relative to the left edge of the WID_SIL_LIST widget.
static bool CDECL OwnerDeityFilter(const Sign *const *a, StringFilter &filter)
Filter sign list excluding OWNER_DEITY.
int strnatcmp(const char *s1, const char *s2, bool ignore_garbage_at_front)
Compares two strings using case insensitive natural sort.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Data structure for an opened window.
void RebuildDone()
Notify the sortlist that the rebuild is done.
@ SLHK_FOCUS_FILTER_BOX
Focus the edit box for editing the filter string.
void DrawWidgets() const
Paint all widgets of a window.
void SetFilterString(const char *new_filter_string)
This function sets the filter string of the sign list.
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Specification of a rectangle with absolute coordinates of all edges.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
#define lastof(x)
Get the last element of an fixed size array.
@ WDP_CENTER
Center the window.
void SetWidgetLoweredState(byte widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
void CDECL void DeleteAll()
Delete every character in the textbuffer.
@ TD_RTL
Text is written right-to-left by default.
TextDirection _current_text_dir
Text direction of the currently selected language.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
static bool SignNameSorter(const Sign *const &a, const Sign *const &b)
Sort signs by their name.
uint16 SignID
The type of the IDs of signs.
static bool RenameSign(SignID index, const char *text)
Actually rename the sign.
static TileIndex TileVirtXY(uint x, uint y)
Get a tile from the virtual XY-coordinate.
All data for a single hotkey.
virtual void Close()
Hide the window and all its child windows, and mark them for a later deletion.