33 #include "table/strings.h" 44 static const Sign *last_sign;
61 DEBUG(misc, 3,
"Building sign list");
66 FOR_ALL_SIGNS(si) *this->signs.
Append() = si;
77 static char buf_cache[64];
81 GetString(buf, STR_SIGN_NAME,
lastof(buf));
83 if (*b != last_sign) {
86 GetString(buf_cache, STR_SIGN_NAME,
lastof(buf_cache));
91 return r != 0 ? r : ((*a)->index - (*b)->index);
99 this->last_sign = NULL;
108 GetString(buf1, STR_SIGN_NAME,
lastof(buf1));
141 const Sign *SignList::last_sign = NULL;
156 this->CreateNestedTree();
158 this->FinishInitNested(window_number);
166 this->SetFilterString(
"");
169 this->signs.ForceRebuild();
170 this->signs.ForceResort();
171 this->BuildSortSignList();
186 this->InvalidateData();
191 if (this->signs.NeedRebuild()) this->BuildSortSignList();
201 if (this->vscroll->
GetCount() == 0) {
208 uint icon_left = 4 + (rtl ? r.right - this->text_offset : r.left);
214 const Sign *si = this->signs[i];
219 DrawString(text_left, text_right, y, STR_SIGN_NAME, TC_YELLOW);
220 y += this->resize.step_height;
237 if (id_v == INT_MAX)
return;
239 const Sign *si = this->signs[id_v];
245 if (this->signs.Length() >= 1) {
246 const Sign *si = this->signs[0];
254 this->InvalidateData();
279 size->height += padding.height;
280 size->width += padding.width;
305 void BuildSortSignList()
307 if (this->signs.NeedRebuild()) {
308 this->BuildSignsList();
309 this->vscroll->
SetCount(this->signs.Length());
312 this->SortSignsList();
317 this->BuildSortSignList();
333 this->signs.ForceRebuild();
335 this->signs.ForceResort();
355 static Hotkey signlist_hotkeys[] = {
361 static const NWidgetPart _nested_sign_list_widgets[] = {
375 NWidget(
WWT_EDITBOX, COLOUR_GREY,
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 != NULL) {
443 this->name_editbox.text.
Assign(STR_SIGN_NAME);
448 this->cur_sign = si->
index;
462 this->signs.ForceRebuild();
463 this->signs.NeedResort();
464 this->BuildSignsList();
465 this->SortSignsList();
470 uint end = this->signs.Length() - (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 this->signs[next ? 0 : this->signs.Length() - 1];
485 SetDParam(0, this->name_editbox.caption);
498 this->signs.ForceRebuild();
499 this->signs.NeedResort();
500 this->BuildSignsList();
501 this->SortSignsList();
505 UpdateSignEditWindow(si);
516 if (
RenameSign(this->cur_sign, this->name_editbox.text.
buf))
break;
526 static const NWidgetPart _nested_query_sign_edit_widgets[] = {
532 NWidget(
WWT_EDITBOX, COLOUR_GREY,
WID_QES_TEXT),
SetMinimalSize(256, 12),
SetDataTip(STR_EDIT_SIGN_SIGN_OSKTITLE, STR_NULL),
SetPadding(2, 2, 2, 2),
548 _nested_query_sign_edit_widgets,
lengthof(_nested_query_sign_edit_widgets)
584 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.
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.
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.