31 #include "table/strings.h" 59 DEBUG(misc, 3,
"Building sign list");
67 this->signs.shrink_to_fit();
78 const char *a_name = a->name;
79 const char *b_name = b->name;
98 const char *a_name = (*a)->name;
148 this->CreateNestedTree();
150 this->FinishInitNested(window_number);
158 this->SetFilterString(
"");
161 this->signs.ForceRebuild();
162 this->signs.ForceResort();
163 this->BuildSortSignList();
170 this->signs.ForceResort();
171 this->SortSignsList();
187 this->InvalidateData();
192 if (!this->IsShaded() && this->signs.NeedRebuild()) this->BuildSortSignList();
202 if (this->vscroll->
GetCount() == 0) {
209 uint icon_left = 4 + (rtl ? r.right - this->text_offset : r.left);
215 const Sign *si = this->signs[i];
220 DrawString(text_left, text_right, y, STR_SIGN_NAME, TC_YELLOW);
221 y += this->resize.step_height;
238 if (id_v == INT_MAX)
return;
240 const Sign *si = this->signs[id_v];
246 if (this->signs.size() >= 1) {
247 const Sign *si = this->signs[0];
255 this->InvalidateData();
280 size->height += padding.height;
281 size->width += padding.width;
306 void BuildSortSignList()
308 if (this->signs.NeedRebuild()) {
309 this->BuildSignsList();
310 this->vscroll->
SetCount((uint)this->signs.size());
313 this->SortSignsList();
318 this->BuildSortSignList();
334 this->signs.ForceRebuild();
336 this->signs.ForceResort();
356 static Hotkey signlist_hotkeys[] = {
362 static const NWidgetPart _nested_sign_list_widgets[] = {
376 NWidget(
WWT_EDITBOX, COLOUR_GREY,
WID_SIL_FILTER_TEXT),
SetMinimalSize(80, 12),
SetResize(1, 0),
SetFill(1, 0),
SetPadding(2, 2, 2, 2),
377 SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
395 _nested_sign_list_widgets,
lengthof(_nested_sign_list_widgets),
396 &SignListWindow::hotkeys
406 return AllocateWindowDescFront<SignListWindow>(&_sign_list_desc, 0);
429 this->name_editbox.caption = STR_EDIT_SIGN_CAPTION;
435 UpdateSignEditWindow(si);
439 void UpdateSignEditWindow(
const Sign *si)
442 if (si->name !=
nullptr) {
444 this->name_editbox.text.
Assign(STR_SIGN_NAME);
449 this->cur_sign = si->
index;
463 this->signs.ForceRebuild();
464 this->signs.NeedResort();
465 this->BuildSignsList();
466 this->SortSignsList();
471 size_t end = this->signs.size() - (next ? 1 : 0);
472 for (uint i = next ? 0 : 1; i < end; i++) {
473 if (this->cur_sign == this->signs[i]->index) {
475 return this->signs[i + (next ? 1 : -1)];
479 return next ? this->signs.front() : this->signs.back();
486 SetDParam(0, this->name_editbox.caption);
499 this->signs.ForceRebuild();
500 this->signs.NeedResort();
501 this->BuildSignsList();
502 this->SortSignsList();
506 UpdateSignEditWindow(si);
517 if (
RenameSign(this->cur_sign, this->name_editbox.text.
buf))
break;
527 static const NWidgetPart _nested_query_sign_edit_widgets[] = {
533 NWidget(
WWT_EDITBOX, COLOUR_GREY,
WID_QES_TEXT),
SetMinimalSize(256, 12),
SetDataTip(STR_EDIT_SIGN_SIGN_OSKTITLE, STR_NULL),
SetPadding(2, 2, 2, 2),
549 _nested_query_sign_edit_widgets,
lengthof(_nested_query_sign_edit_widgets)
585 if (w !=
nullptr && w->cur_sign == sign)
delete w;
EventState
State of handling an event.
Functions related to OTTD's strings.
Base types for having sorted lists in GUIs.
void RebuildDone()
Notify the sortlist that the rebuild is done.
static const uint MAX_LENGTH_SIGN_NAME_CHARS
The maximum length of a sign name in characters including '\0'.
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
void SetFocusedWindow(Window *w)
Set the window that has the focus.
SignListHotkeys
Enum referring to the Hotkeys in the sign list window.
All data for a single hotkey.
High level window description.
byte _display_opt
What do we want to draw/do?
bool Filter(FilterFunction *decide, F filter_data)
Filter the list.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
GUIList< const Sign *, StringFilter & > GUISignList
A GUIList contains signs and uses a StringFilter for filtering.
Hotkey related functions.
void DeleteRenameSignWindow(SignID sign)
Close the sign window associated with the given sign.
static bool match_case
Should case sensitive matching be used?
Offset at top to draw the frame rectangular area.
Functions related to debugging.
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
void ResetState()
Reset the matching state to process a new item.
The passed event is not handled.
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.
int text_offset
Offset of the sign text relative to the left edge of the WID_SIL_LIST widget.
Sign list; Window numbers:
void CDECL void DeleteAll()
Delete every character in the textbuffer.
void DrawCompanyIcon(CompanyID c, int x, int y)
Draw the icon of a company.
static const int ACTION_CLEAR
Clear editbox.
void OnResize() override
Called after the window got resized.
Tindex index
Index of this pool item.
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Display signs, station names and waypoint names of opponent companies. Buoys and oilrig-stations are ...
#define lastof(x)
Get the last element of an fixed size array.
Functions related to signs.
void OnPaint() override
The window must be repainted.
Functions related to maps.
bool NeedRebuild() const
Check if a rebuild is needed.
Functions related to (drawing on) viewports.
Base for the GUIs that have an edit box in them.
Data structure for an opened window.
bool _ctrl_pressed
Is Ctrl pressed?
void SetFilterTerm(const char *str)
Set the term to filter on.
Functions related to low-level strings.
static const int MAX_CHAR_LENGTH
Max. length of UTF-8 encoded unicode character.
The tile has no ownership.
This window is used for construction; close it whenever changing company.
static size_t GetPoolSize()
Returns first unused index.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
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.
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Data stored about a string that can be modified in the GUI.
Definition of base types and functions in a cross-platform compatible way.
A number of safeguards to prevent using unsafe methods.
List of hotkeys for a window.
static bool CDECL SignNameFilter(const Sign *const *a, StringFilter &filter)
Filter sign list by sign name.
GUI Functions related to companies.
Offset at bottom to draw the frame rectangular area.
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.
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.
Right offset of the text of the frame.
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
#define lengthof(x)
Return the length of an fixed size array.
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
Left offset of the text of the frame.
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.
void Assign(StringID string)
Render a string into the textbuffer.
#define DEBUG(name, level,...)
Output a line of debugging information.
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
static EventState SignListGlobalHotkeys(int hotkey)
Handler for global hotkeys of the SignListWindow.
void AddLine(const char *str)
Pass another text line from the current item to the filter.
Focus the edit box for editing the filter string.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
No window, redirects to WC_MAIN_WINDOW.
StringFilter string_filter
The match string to be used when the GUIList is (re)-sorted.
static char default_name[64]
Default sign name, used if Sign::name is nullptr.
Functions related to companies.
static TileIndex TileVirtXY(uint x, uint y)
Get a tile from the virtual XY-coordinate.
char *const buf
buffer in which text is saved
static bool SignNameSorter(const Sign *const &a, const Sign *const &b)
Sort signs by their name.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
QueryString filter_editbox
Filter editbox;.
int strnatcmp(const char *s1, const char *s2, bool ignore_garbage_at_front)
Compares two strings using case insensitive natural sort.
void HandleClickOnSign(const Sign *si)
Handle clicking on a sign.
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
void SetFilterState(bool state)
Enable or disable the filter.
TextDirection _current_text_dir
Text direction of the currently selected language.
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.
void OnInit() override
Notification that the nested widget tree gets initialized.
Window * ShowSignList()
Open the sign list window.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Functions related to commands.
Coordinates of a point in 2D.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
uint16 SignID
The type of the IDs of signs.
void SetFilterString(const char *new_filter_string)
This function sets the filter string of the sign list.
Offset at right to draw the frame rectangular area.
static bool CDECL OwnerDeityFilter(const Sign *const *a, StringFilter &filter)
Filter sign list excluding OWNER_DEITY.
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.
#define CMD_MSG(x)
Used to combine a StringID with the command.
int32 WindowNumber
Number to differentiate different windows of the same class.
Specification of a rectangle with absolute coordinates of all edges.
The passed event is handled.
Text is written right-to-left by default.
Window functions not directly related to making/drawing windows.
Find a place automatically.
static bool RenameSign(SignID index, const char *text)
Actually rename the sign.
static bool CDECL OwnerVisibilityFilter(const Sign *const *a, StringFilter &filter)
Filter sign list by owner.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
The object is owned by a superuser / goal script.
Dimensions (a width and height) of a rectangle in 2D.
Query string window; Window numbers:
bool IsEmpty() const
Check whether any filter words were entered.
Offset at left to draw the frame rectangular area.
This file contains all sprite-related enums and defines.
void OnEditboxChanged(int widget) override
The text in an editbox has been edited.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
void OnHundredthTick() override
Called once every 100 (game) ticks.
void FilterSignList()
Filter out signs from the sign list that does not match the name filter.