|
OpenTTD Source
14.0-beta3
|
Go to the documentation of this file.
35 #include "table/strings.h"
63 Debug(misc, 3,
"Building sign list");
71 this->signs.shrink_to_fit();
162 this->BuildSortSignList();
170 this->SortSignsList();
195 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
202 if (this->vscroll->
GetCount() == 0) {
203 DrawString(tr.left, tr.right, tr.top + text_offset_y, STR_STATION_LIST_NONE);
210 uint icon_left = rtl ? tr.right - this->
text_offset : tr.left;
211 tr = tr.
Indent(this->text_offset, rtl);
216 const Sign *si = this->signs[i];
221 DrawString(tr.left, tr.right, tr.top + text_offset_y, STR_SIGN_NAME, TC_YELLOW);
229 void SetStringParameters(
WidgetID widget)
const override
234 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
239 if (it == this->signs.end())
return;
241 const Sign *si = *it;
247 if (this->signs.size() >= 1) {
248 const Sign *si = this->signs[0];
281 size->height += padding.height;
282 size->width += padding.width;
302 void OnEditboxChanged(
WidgetID widget)
override
307 void BuildSortSignList()
310 this->BuildSignsList();
311 this->vscroll->
SetCount(this->signs.size());
314 this->SortSignsList();
319 this->BuildSortSignList();
328 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
333 if (data == 0 || data == -1 || !this->string_filter.
IsEmpty()) {
354 static inline HotkeyList hotkeys{
"signlist", {
359 static constexpr
NWidgetPart _nested_sign_list_widgets[] = {
373 NWidget(
WWT_EDITBOX, COLOUR_BROWN,
WID_SIL_FILTER_TEXT),
SetMinimalSize(80, 12),
SetResize(1, 0),
SetFill(1, 0),
SetPadding(2, 2, 2, 2),
374 SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
386 static WindowDesc _sign_list_desc(__FILE__, __LINE__,
390 std::begin(_nested_sign_list_widgets), std::end(_nested_sign_list_widgets),
391 &SignListWindow::hotkeys
401 return AllocateWindowDescFront<SignListWindow>(&_sign_list_desc, 0);
424 this->name_editbox.caption = STR_EDIT_SIGN_CAPTION;
430 UpdateSignEditWindow(si);
434 void UpdateSignEditWindow(
const Sign *si)
437 if (!si->name.empty()) {
439 this->name_editbox.text.
Assign(STR_SIGN_NAME);
444 this->cur_sign = si->
index;
460 this->BuildSignsList();
461 this->SortSignsList();
466 size_t end = this->signs.size() - (next ? 1 : 0);
467 for (uint i = next ? 0 : 1; i < end; i++) {
468 if (this->cur_sign == this->signs[i]->index) {
470 return this->signs[i + (next ? 1 : -1)];
474 return next ? this->signs.front() : this->signs.back();
477 void SetStringParameters(
WidgetID widget)
const override
481 SetDParam(0, this->name_editbox.caption);
486 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
507 this->BuildSignsList();
508 this->SortSignsList();
512 UpdateSignEditWindow(si);
523 if (
RenameSign(this->cur_sign, this->name_editbox.text.
buf))
break;
533 static constexpr
NWidgetPart _nested_query_sign_edit_widgets[] = {
540 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 static WindowDesc _query_sign_edit_desc(__FILE__, __LINE__,
556 std::begin(_nested_query_sign_edit_widgets), std::end(_nested_query_sign_edit_widgets)
596 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.
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
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.
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
void SetFilterState(bool state)
Enable or disable the filter.
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.
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
void Assign(StringID string)
Render a string into the textbuffer.
void DeleteRenameSignWindow(SignID sign)
Close the sign window associated with the given sign.
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.
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
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'.
@ WC_SIGN_LIST
Sign list; Window numbers:
bool _ctrl_pressed
Is Ctrl pressed?
int StrNaturalCompare(std::string_view s1, std::string_view s2, bool ignore_garbage_at_front)
Compares two strings using case insensitive natural sort.
SignListHotkeys
Enum referring to the Hotkeys in the sign list window.
void AddLine(const char *str)
Pass another text line from the current item to the filter.
byte _display_opt
What do we want to draw/do?
static EventState SignListGlobalHotkeys(int hotkey)
Handler for global hotkeys of the SignListWindow.
uint16_t SignID
The type of the IDs of signs.
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
bool StrEmpty(const char *s)
Check if a string buffer is empty.
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...
bool NeedRebuild() const
Check if a rebuild is needed.
Data stored about a string that can be modified in the GUI.
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
char *const buf
buffer in which text is saved
static const int MAX_CHAR_LENGTH
Max. length of UTF-8 encoded unicode character.
static bool CDECL OwnerDeityFilter(const Sign *const *a, StringFilter &)
Filter sign list excluding OWNER_DEITY.
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.
bool NeedResort()
Check if a resort is needed next loop If used the resort timer will decrease every call till 0.
@ WDP_AUTO
Find a place automatically.
ResizeInfo resize
Resize information.
int32_t WindowNumber
Number to differentiate different windows of the same class.
@ FS_NORMAL
Index of the normal font in the font tables.
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
bool Filter(FilterFunction *decide, F filter_data)
Filter the list.
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)
void ForceResort()
Force a resort next Sort call Reset the resort timer if used too.
@ ES_NOT_HANDLED
The passed event is not handled.
void HandleClickOnSign(const Sign *si)
Handle clicking on a sign.
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.
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.
WindowNumber window_number
Window number within the window class.
bool SetFocusedWidget(WidgetID widget_index)
Set focus within this window to the given widget.
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
uint step_height
Step-size of height resize changes.
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
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.
void ForceRebuild()
Force that a rebuild is needed.
@ WN_QUERY_STRING_SIGN
Query string for signs.
std::map< WidgetID, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
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 CDECL OwnerVisibilityFilter(const Sign *const *a, StringFilter &)
Filter sign list by owner.
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
static bool match_case
Should case sensitive matching be used?
bool IsShaded() const
Is window shaded currently?
void SetDParamMaxValue(size_t n, uint64_t max_value, uint min_count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
static std::string default_name
Default sign name, used if Sign::name is nullptr.
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
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.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with all the associated DParam lookups and formatting.
EventState
State of handling an event.
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.
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.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
void RebuildDone()
Notify the sortlist that the rebuild is done.
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
int text_offset
Offset of the sign text relative to the left edge of the WID_SIL_LIST widget.
static debug_inline TileIndex TileVirtXY(uint x, uint y)
Get a tile from the virtual XY-coordinate.
Data structure for an opened window.
@ SLHK_FOCUS_FILTER_BOX
Focus the edit box for editing the filter string.
IntervalTimer< TimerWindow > rebuild_interval
Resort the sign listing on a regular interval.
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.
Specification of a rectangle with absolute coordinates of all edges.
GUIList< const Sign *, std::nullptr_t, StringFilter & > GUISignList
A GUIList contains signs and uses a StringFilter for filtering.
bool Sort(Comp compare)
Sort the list.
@ WDP_CENTER
Center the window.
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.
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
static bool SignNameSorter(const Sign *const &a, const Sign *const &b)
Sort signs by their name.
static bool RenameSign(SignID index, const char *text)
Actually rename the sign.
All data for a single hotkey.
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.