33 #include "table/strings.h" 61 DEBUG(misc, 3,
"Building sign list");
66 FOR_ALL_SIGNS(si) *this->signs.
Append() = si;
81 const char *a_name = (*a)->name;
82 const char *b_name = (*b)->name;
89 return r != 0 ? r : ((*a)->index - (*b)->index);
101 const char *a_name = (*a)->name;
151 this->CreateNestedTree();
153 this->FinishInitNested(window_number);
161 this->SetFilterString(
"");
164 this->signs.ForceRebuild();
165 this->signs.ForceResort();
166 this->BuildSortSignList();
173 this->signs.ForceResort();
174 this->SortSignsList();
190 this->InvalidateData();
195 if (!this->IsShaded() && this->signs.NeedRebuild()) this->BuildSortSignList();
205 if (this->vscroll->
GetCount() == 0) {
212 uint icon_left = 4 + (rtl ? r.right - this->text_offset : r.left);
218 const Sign *si = this->signs[i];
223 DrawString(text_left, text_right, y, STR_SIGN_NAME, TC_YELLOW);
224 y += this->resize.step_height;
241 if (id_v == INT_MAX)
return;
243 const Sign *si = this->signs[id_v];
249 if (this->signs.Length() >= 1) {
250 const Sign *si = this->signs[0];
258 this->InvalidateData();
283 size->height += padding.height;
284 size->width += padding.width;
309 void BuildSortSignList()
311 if (this->signs.NeedRebuild()) {
312 this->BuildSignsList();
313 this->vscroll->
SetCount(this->signs.Length());
316 this->SortSignsList();
321 this->BuildSortSignList();
337 this->signs.ForceRebuild();
339 this->signs.ForceResort();
359 static Hotkey signlist_hotkeys[] = {
365 static const NWidgetPart _nested_sign_list_widgets[] = {
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),
398 _nested_sign_list_widgets,
lengthof(_nested_sign_list_widgets),
399 &SignListWindow::hotkeys
409 return AllocateWindowDescFront<SignListWindow>(&_sign_list_desc, 0);
432 this->name_editbox.caption = STR_EDIT_SIGN_CAPTION;
438 UpdateSignEditWindow(si);
442 void UpdateSignEditWindow(
const Sign *si)
445 if (si->name != NULL) {
447 this->name_editbox.text.
Assign(STR_SIGN_NAME);
452 this->cur_sign = si->
index;
466 this->signs.ForceRebuild();
467 this->signs.NeedResort();
468 this->BuildSignsList();
469 this->SortSignsList();
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) {
478 return this->signs[i + (next ? 1 : -1)];
482 return this->signs[next ? 0 : this->signs.Length() - 1];
489 SetDParam(0, this->name_editbox.caption);
502 this->signs.ForceRebuild();
503 this->signs.NeedResort();
504 this->BuildSignsList();
505 this->SortSignsList();
509 UpdateSignEditWindow(si);
520 if (
RenameSign(this->cur_sign, this->name_editbox.text.
buf))
break;
530 static const NWidgetPart _nested_query_sign_edit_widgets[] = {
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),
552 _nested_query_sign_edit_widgets,
lengthof(_nested_query_sign_edit_widgets)
588 if (w != NULL && 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.
virtual void OnPaint()
The window must be repainted.
virtual void OnEditboxChanged(int widget)
The text in an editbox has been edited.
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.
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.
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
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.
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.
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.
CompanyByte _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Functions related to (drawing on) viewports.
The object is owned by a superuser / goal script.
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.
virtual void SetStringParameters(int widget) const
Initialize string parameters for a widget.
Functions related to low-level strings.
static const int MAX_CHAR_LENGTH
Max. length of UTF-8 encoded unicode character.
This window is used for construction; close it whenever changing company.
static size_t GetPoolSize()
Returns first unused index.
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.
virtual void OnResize()
Called after the window got resized.
static bool CDECL SignNameFilter(const Sign *const *a, StringFilter &filter)
Filter sign list by sign name.
virtual void SetStringParameters(int widget) const
Initialize string parameters for a widget.
GUI Functions related to companies.
virtual void OnInit()
Notification that the nested widget tree gets initialized.
The tile has no ownership.
Offset at bottom to draw the frame rectangular area.
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.
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 NULL.
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
QueryString filter_editbox
Filter editbox;.
static int CDECL SignNameSorter(const Sign *const *a, const Sign *const *b)
Sort signs by their name.
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.
Window * ShowSignList()
Open the sign list 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.
virtual void OnHundredthTick()
Called once every 100 (game) ticks.
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.
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
static bool RenameSign(SignID index, const char *text)
Actually rename the sign.
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
static bool CDECL OwnerVisibilityFilter(const Sign *const *a, StringFilter &filter)
Filter sign list by owner.
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.
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
virtual void OnInvalidateData(int data=0, bool gui_scope=true)
Some data on this window has become invalid.
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.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
void FilterSignList()
Filter out signs from the sign list that does not match the name filter.