OpenTTD Source
12.0-beta2
|
Go to the documentation of this file.
32 #include "table/strings.h"
60 Debug(misc, 3,
"Building sign list");
68 this->signs.shrink_to_fit();
159 this->BuildSortSignList();
167 this->SortSignsList();
199 if (this->vscroll->
GetCount() == 0) {
207 uint icon_left = 4 + (rtl ? r.right - this->
text_offset : r.left);
213 const Sign *si = this->signs[i];
218 DrawString(text_left, text_right, y + text_offset_y, STR_SIGN_NAME, TC_YELLOW);
236 if (id_v == INT_MAX)
return;
238 const Sign *si = this->signs[id_v];
244 if (this->signs.size() >= 1) {
245 const Sign *si = this->signs[0];
278 size->height += padding.height;
279 size->width += padding.width;
304 void BuildSortSignList()
307 this->BuildSignsList();
308 this->vscroll->
SetCount((uint)this->signs.size());
311 this->SortSignsList();
316 this->BuildSortSignList();
330 if (data == 0 || data == -1 || !this->string_filter.
IsEmpty()) {
354 static Hotkey signlist_hotkeys[] = {
360 static const NWidgetPart _nested_sign_list_widgets[] = {
374 NWidget(
WWT_EDITBOX, COLOUR_BROWN,
WID_SIL_FILTER_TEXT),
SetMinimalSize(80, 12),
SetResize(1, 0),
SetFill(1, 0),
SetPadding(2, 2, 2, 2),
375 SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
393 _nested_sign_list_widgets,
lengthof(_nested_sign_list_widgets),
394 &SignListWindow::hotkeys
404 return AllocateWindowDescFront<SignListWindow>(&_sign_list_desc, 0);
427 this->name_editbox.caption = STR_EDIT_SIGN_CAPTION;
433 UpdateSignEditWindow(si);
437 void UpdateSignEditWindow(
const Sign *si)
440 if (!si->name.empty()) {
442 this->name_editbox.text.
Assign(STR_SIGN_NAME);
447 this->cur_sign = si->
index;
463 this->BuildSignsList();
464 this->SortSignsList();
469 size_t end = this->signs.size() - (next ? 1 : 0);
470 for (uint i = next ? 0 : 1; i < end; i++) {
471 if (this->cur_sign == this->signs[i]->index) {
473 return this->signs[i + (next ? 1 : -1)];
477 return next ? this->signs.front() : this->signs.back();
484 SetDParam(0, this->name_editbox.caption);
510 this->BuildSignsList();
511 this->SortSignsList();
515 UpdateSignEditWindow(si);
526 if (
RenameSign(this->cur_sign, this->name_editbox.text.
buf))
break;
536 static const NWidgetPart _nested_query_sign_edit_widgets[] = {
543 NWidget(
WWT_EDITBOX, COLOUR_GREY,
WID_QES_TEXT),
SetMinimalSize(256, 12),
SetDataTip(STR_EDIT_SIGN_SIGN_OSKTITLE, STR_NULL),
SetPadding(2, 2, 2, 2),
559 _nested_query_sign_edit_widgets,
lengthof(_nested_query_sign_edit_widgets)
595 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.
@ WD_FRAMERECT_TOP
Offset at top to draw the frame rectangular area.
#define CMD_MSG(x)
Used to combine a StringID with the command.
uint32 TileIndex
The index/ID of a Tile.
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.
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.
@ WD_FRAMETEXT_LEFT
Left offset of the text of the frame.
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.
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
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)
@ WD_FRAMERECT_LEFT
Offset at left to draw the frame rectangular area.
@ WD_FRAMERECT_RIGHT
Offset at right to draw the frame rectangular area.
@ ES_NOT_HANDLED
The passed event is not handled.
@ WD_FRAMERECT_BOTTOM
Offset at bottom to draw the frame rectangular area.
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.
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.
void OnHundredthTick() override
Called once every 100 (game) ticks, or once every 3s, whichever comes last.
@ WD_FRAMETEXT_RIGHT
Right offset of the text of the frame.
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.
@ CMD_RENAME_SIGN
rename a sign
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.