35 #include "table/strings.h"
63 Debug(misc, 3,
"Building sign list");
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);
215 for (
auto it = first; it != last; ++it) {
216 const Sign *si = *it;
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;
274 size.height += padding.height;
275 size.width += padding.width;
295 void OnEditboxChanged(
WidgetID widget)
override
300 void BuildSortSignList()
303 this->BuildSignsList();
304 this->vscroll->
SetCount(this->signs.size());
307 this->SortSignsList();
312 this->BuildSortSignList();
321 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
326 if (data == 0 || data == -1 || !this->string_filter.
IsEmpty()) {
347 static inline HotkeyList hotkeys{
"signlist", {
352 static constexpr
NWidgetPart _nested_sign_list_widgets[] = {
366 NWidget(
WWT_EDITBOX, COLOUR_BROWN,
WID_SIL_FILTER_TEXT),
SetMinimalSize(80, 0),
SetResize(1, 0),
SetFill(1, 0),
SetPadding(2, 2, 2, 2),
367 SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
383 _nested_sign_list_widgets,
384 &SignListWindow::hotkeys
394 return AllocateWindowDescFront<SignListWindow>(_sign_list_desc, 0);
417 this->name_editbox.caption = STR_EDIT_SIGN_CAPTION;
423 UpdateSignEditWindow(si);
427 void UpdateSignEditWindow(
const Sign *si)
430 if (!si->name.empty()) {
432 this->name_editbox.text.
Assign(STR_SIGN_NAME);
437 this->cur_sign = si->
index;
453 this->BuildSignsList();
454 this->SortSignsList();
459 size_t end = this->signs.size() - (next ? 1 : 0);
460 for (uint i = next ? 0 : 1; i < end; i++) {
461 if (this->cur_sign == this->signs[i]->index) {
463 return this->signs[i + (next ? 1 : -1)];
467 return next ? this->signs.front() : this->signs.back();
470 void SetStringParameters(
WidgetID widget)
const override
474 SetDParam(0, this->name_editbox.caption);
479 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
500 this->BuildSignsList();
501 this->SortSignsList();
505 UpdateSignEditWindow(si);
516 if (
RenameSign(this->cur_sign, this->name_editbox.text.
buf))
break;
526 static constexpr
NWidgetPart _nested_query_sign_edit_widgets[] = {
533 NWidget(
WWT_EDITBOX, COLOUR_GREY,
WID_QES_TEXT),
SetMinimalSize(256, 0),
SetDataTip(STR_EDIT_SIGN_SIGN_OSKTITLE, STR_NULL),
SetPadding(2, 2, 2, 2),
549 _nested_query_sign_edit_widgets
589 if (w !=
nullptr && w->cur_sign == sign) w->
Close();
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
bool Filter(FilterFunction *decide, F filter_data)
Filter the list.
void RebuildDone()
Notify the sortlist that the rebuild is done.
void SetFilterState(bool state)
Enable or disable the filter.
bool NeedRebuild() const
Check if a rebuild is needed.
void ForceRebuild()
Force that a rebuild is needed.
bool Sort(Comp compare)
Sort the list.
void ForceResort()
Force a resort next Sort call Reset the resort timer if used too.
bool NeedResort()
Check if a resort is needed next loop If used the resort timer will decrease every call till 0.
Functions related to commands.
void DrawCompanyIcon(CompanyID c, int x, int y)
Draw the icon of a company.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Functions related to companies.
GUI Functions related to companies.
@ OWNER_DEITY
The object is owned by a superuser / goal script.
@ OWNER_NONE
The tile has no ownership.
Functions related to debugging.
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
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.
bool _ctrl_pressed
Is Ctrl pressed?
@ FS_NORMAL
Index of the normal font in the font tables.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
GUI functions that shouldn't be here.
void ShowExtraViewportWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
Hotkey related functions.
Functions related to maps.
static debug_inline TileIndex TileVirtXY(uint x, uint y)
Get a tile from the virtual XY-coordinate.
@ DO_SHOW_COMPETITOR_SIGNS
Display signs, station names and waypoint names of opponent companies. Buoys and oilrig-stations are ...
Base for the GUIs that have an edit box in them.
A number of safeguards to prevent using unsafe methods.
bool CompanyCanRenameSign(const Sign *si)
Check if the current company can rename a given sign.
Command definitions related to signs.
Functions related to signs.
Window * ShowSignList()
Open the sign list window.
void HandleClickOnSign(const Sign *si)
Handle clicking on a sign.
void DeleteRenameSignWindow(SignID sign)
Close the sign window associated with the given sign.
SignListHotkeys
Enum referring to the Hotkeys in the sign list window.
@ SLHK_FOCUS_FILTER_BOX
Focus the edit box for editing the filter string.
static bool RenameSign(SignID index, const char *text)
Actually rename the sign.
void ShowRenameSignWindow(const Sign *si)
Show the window to change the text of a sign.
uint16_t SignID
The type of the IDs of signs.
static const uint MAX_LENGTH_SIGN_NAME_CHARS
The maximum length of a sign name in characters including '\0'.
Base types for having sorted lists in GUIs.
This file contains all sprite-related enums and defines.
Definition of base types and functions in a cross-platform compatible way.
int StrNaturalCompare(std::string_view s1, std::string_view s2, bool ignore_garbage_at_front)
Compares two strings using case insensitive natural sort.
Functions related to low-level strings.
bool StrEmpty(const char *s)
Check if a string buffer is empty.
Searching and filtering using a stringterm.
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.
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with all the associated DParam lookups and formatting.
TextDirection _current_text_dir
Text direction of the currently selected language.
Functions related to OTTD's strings.
@ TD_RTL
Text is written right-to-left by default.
static const int MAX_CHAR_LENGTH
Max. length of UTF-8 encoded unicode character.
Dimensions (a width and height) of a rectangle in 2D.
List of hotkeys for a window.
All data for a single hotkey.
Coordinates of a point in 2D.
static size_t GetPoolSize()
Returns first unused index.
Tindex index
Index of this pool item.
static Titem * Get(size_t index)
Returns Titem with given index.
static size_t GetNumItems()
Returns number of valid items in the pool.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Data stored about a string that can be modified in the GUI.
int ok_button
Widget button of parent window to simulate when pressing OK in OSK.
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
static const int ACTION_CLEAR
Clear editbox.
Specification of a rectangle with absolute coordinates of all edges.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
uint step_height
Step-size of height resize changes.
IntervalTimer< TimerWindow > rebuild_interval
Resort the sign listing on a regular interval.
void SetFilterString(const char *new_filter_string)
This function sets the filter string of the sign list.
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.
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
QueryString filter_editbox
Filter editbox;.
void OnPaint() override
The window must be repainted.
void OnInit() override
Notification that the nested widget tree gets initialized.
static EventState SignListGlobalHotkeys(int hotkey)
Handler for global hotkeys of the SignListWindow.
void OnResize() override
Called after the window got resized.
static bool OwnerDeityFilter(const Sign *const *a, StringFilter &)
Filter sign list excluding OWNER_DEITY.
GUIList< const Sign *, std::nullptr_t, StringFilter & > GUISignList
A GUIList contains signs and uses a StringFilter for filtering.
static bool OwnerVisibilityFilter(const Sign *const *a, StringFilter &)
Filter sign list by owner.
static bool SignNameSorter(const Sign *const &a, const Sign *const &b)
Sort signs by their name.
SignList()
Creates a SignList with filtering disabled by default.
void FilterSignList()
Filter out signs from the sign list that does not match the name filter.
static bool match_case
Should case sensitive matching be used?
static std::string default_name
Default sign name, used if Sign::name is nullptr.
static bool SignNameFilter(const Sign *const *a, StringFilter &filter)
Filter sign list by sign name.
StringFilter string_filter
The match string to be used when the GUIList is (re)-sorted.
const Sign * PrevNextSign(bool next)
Returns a pointer to the (alphabetically) previous or next sign of the current sign.
bool IsEmpty() const
Check whether any filter words were entered.
void SetFilterTerm(const char *str)
Set the term to filter on.
void ResetState()
Reset the matching state to process a new item.
void AddLine(const char *str)
Pass another text line from the current item to the filter.
bool GetState() const
Get the matching state of the current item.
void DeleteAll()
Delete every character in the textbuffer.
void Assign(StringID string)
Render a string into the textbuffer.
char *const buf
buffer in which text is saved
High level window description.
Data structure for an opened window.
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
std::map< WidgetID, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
void DrawWidgets() const
Paint all widgets of a window.
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
ResizeInfo resize
Resize information.
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
bool SetFocusedWidget(WidgetID widget_index)
Set focus within this window to the given widget.
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
bool IsShaded() const
Is window shaded currently?
Window(WindowDesc &desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
WindowNumber window_number
Window number within the window class.
Definition of Interval and OneShot timers.
Definition of the Window system.
Functions related to transparency.
uint8_t _display_opt
What do we want to draw/do?
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Functions related to (drawing on) viewports.
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
void SetFocusedWindow(Window *w)
Set the window that has the focus.
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
Window functions not directly related to making/drawing windows.
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
@ WDP_CENTER
Center the window.
@ WDP_AUTO
Find a place automatically.
@ WN_QUERY_STRING_SIGN
Query string for signs.
int32_t WindowNumber
Number to differentiate different windows of the same class.
EventState
State of handling an event.
@ ES_HANDLED
The passed event is handled.
@ ES_NOT_HANDLED
The passed event is not handled.
@ WC_SIGN_LIST
Sign list; Window numbers:
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
@ WC_QUERY_STRING
Query string window; Window numbers: