29#include "table/strings.h"
71 auto now = std::chrono::steady_clock::now();
73 if (cmsg.remove_time >= now)
return true;
94 cmsg->
remove_time = std::chrono::steady_clock::now() + std::chrono::seconds(duration);
132 if (_cursor.visible &&
133 _cursor.draw_pos.x + _cursor.draw_size.x >=
_chatmsg_box.x &&
136 _cursor.draw_pos.y <= _screen.height -
_chatmsg_box.y) {
147 height = std::max(height + y, std::min(
_chatmsg_box.height, _screen.height));
150 if (x + width >= _screen.width) {
151 width = _screen.width - x;
153 if (width <= 0 || height <= 0)
return;
168 auto now = std::chrono::steady_clock::now();
186 bool show_all = (w !=
nullptr);
201 height = std::max(height + y, std::min(
_chatmsg_box.height, _screen.height));
204 if (x + width >= _screen.width) {
205 width = _screen.width - x;
207 if (width <= 0 || height <= 0)
return;
215 auto now = std::chrono::steady_clock::now();
216 int string_height = 0;
218 if (!show_all && cmsg.remove_time < now)
continue;
224 int top = _screen.height -
_chatmsg_box.y - string_height - 2;
232 int ypos = bottom - 2;
235 if (!show_all && cmsg.remove_time < now)
continue;
237 if (ypos < top)
break;
255 if (buf.empty())
return;
262 default: NOT_REACHED();
275 using AutoCompletion::AutoCompletion;
280 std::vector<std::string> suggestions;
282 if (ci->client_name.starts_with(
query)) {
283 suggestions.push_back(ci->client_name);
288 std::string town_name =
GetString(STR_TOWN_NAME, t->index);
289 if (town_name.starts_with(
query)) {
290 suggestions.push_back(std::move(town_name));
300 this->textbuf->Assign(fmt::format(
"{}: ", suggestion));
302 this->textbuf->Assign(fmt::format(
"{}{} ",
prefix, suggestion));
336 void Close([[maybe_unused]]
int data = 0)
override
378 SendChat(this->message_editbox.text.
GetText(), this->dtype, this->dest);
390 if (keycode == WKC_TAB) {
400 this->chat_tab_completion.Reset();
409 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
411 if (data == this->dest) this->
Close();
421 NWidget(
WWT_TEXT,
Colours::Invalid,
WID_NC_DESTINATION),
SetMinimalSize(62, 12),
SetPadding(1, 0, 1, 0),
SetAlignment(
SA_VERT_CENTER |
SA_RIGHT),
422 NWidget(
WWT_EDITBOX,
Colours::Grey,
WID_NC_TEXTBOX),
SetMinimalSize(100, 0),
SetPadding(1, 0, 1, 0),
SetResize(1, 0),
424 NWidget(
WWT_PUSHTXTBTN,
Colours::Grey,
WID_NC_SENDBUTTON),
SetMinimalSize(62, 12),
SetPadding(1, 0, 1, 0),
SetStringTip(STR_NETWORK_CHAT_SEND),
Generic auto-completion engine.
std::string_view query
Last token of the text. This is used to based the suggestions on.
std::string_view prefix
Prefix of the text before the last space.
static Blitter * GetCurrentBlitter()
Get the current active blitter (always set by calling SelectBlitter).
How all blitters should look like.
virtual void * MoveTo(void *video, int x, int y)=0
Move the destination pointer the requested amount x and y, keeping in mind any pitch and bpp of the r...
virtual void CopyToBuffer(const void *video, void *dst, int width, int height)=0
Copy from the screen to a buffer.
virtual void CopyFromBuffer(void *video, const void *src, int width, int height)=0
Copy from a buffer to the screen.
static NetworkRecvStatus SendChat(NetworkAction action, NetworkChatDestinationType type, int dest, std::string_view msg, int64_t data)
Send a chat-packet over the network.
An interval timer will fire every interval, and will continue to fire until it is deleted.
Implementation of AutoCompletion for nicknames and town names in the chat.
std::vector< std::string > GetSuggestions(std::string_view prefix, std::string_view query) override
Get suggestions for auto completion with the given 'query' input text.
void ApplySuggestion(std::string_view prefix, std::string_view suggestion) override
Format the given suggestion after the given prefix, and write that to the buffer.
A reusable buffer that can be used for places that temporary allocate a bit of memory and do that ver...
virtual void MakeDirty(int left, int top, int width, int height)=0
Mark a particular area dirty.
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
static const uint NETWORK_CHAT_LENGTH
The maximum length of a chat message, in bytes including '\0'.
Console functions used outside of the console code.
IConsoleModes _iconsole_mode
Console modes.
@ ICONSOLE_FULL
In-game console is opened, whole screen.
Factory to 'query' all available blitters.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
int GetStringLineCount(std::string_view str, int maxw)
Calculates number of lines of string.
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
void GfxFillRect(int left, int top, int right, int bottom, const std::variant< PixelColour, PaletteID > &colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
@ Normal
Index of the normal font in the font tables.
@ SA_LEFT
Left align the text.
@ SA_RIGHT
Right align the text (must be a single bit).
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
@ SA_BOTTOM
Bottom align the text.
@ SA_VERT_CENTER
Vertically center the text.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
@ FILLRECT_RECOLOUR
Apply a recolour sprite to the screen content.
void SetDirty() const
Mark entire window as dirty (in need of re-paint).
#define Point
Macro that prevents name conflicts between included headers.
bool _network_server
network-server is active
Basic functions/variables used all over the place.
Base core network types and some helper functions to access them.
static void SendChat(std::string_view buf, NetworkChatDestinationType type, int dest)
Send an actual chat message.
static uint MAX_CHAT_MESSAGES
The limit of chat messages to show.
void NetworkDrawChatMessage()
Draw the chat message-box.
static ReusableBuffer< uint8_t > _chatmessage_backup
Backup in case text is moved.
static bool HaveChatMessages(bool show_all)
Test if there are any chat messages to display.
static constexpr std::initializer_list< NWidgetPart > _nested_chat_window_widgets
The widgets of the chat window.
void NetworkAddChatMessage(TextColour colour, uint duration, const std::string &message)
Add a text message to the 'chat window' to be shown.
static std::chrono::steady_clock::time_point _chatmessage_dirty_time
Time the chat history was marked dirty.
void NetworkReInitChatBoxSize()
Initialize all font-dependent chat box sizes.
void ShowNetworkChatQueryWindow(NetworkChatDestinationType type, int dest)
Show the chat window.
static const uint NETWORK_CHAT_LINE_SPACING
Spacing between chat lines.
static WindowDesc _chat_window_desc(WDP_MANUAL, {}, 0, 0, WC_SEND_NETWORK_MSG, WC_NONE, {}, _nested_chat_window_widgets)
The description of the chat window.
void NetworkInitChatMessage()
Initialize all buffers of the chat visualisation.
static const IntervalTimer< TimerWindow > network_message_expired_interval(std::chrono::seconds(1), [](auto) { auto now=std::chrono::steady_clock::now();for(auto &cmsg :_chatmsg_list) { if(now > cmsg.remove_time &&_chatmessage_dirty_time< cmsg.remove_time) { _chatmessage_dirty_time=now;_chatmessage_dirty=true;break;} } })
Check if a message is expired on a regular interval.
void NetworkUndrawChatMessage()
Hide the chatbox.
static PointDimension _chatmsg_box
The chatbox grows from the bottom so the coordinates are pixels from the left and pixels from the bot...
static bool _chatmessage_dirty
Does the chat message need repainting?
static bool _chatmessage_visible
Is a chat message visible.
static std::deque< ChatMessage > _chatmsg_list
The actual chat message list.
Client part of the network protocol.
void NetworkServerSendChat(NetworkAction action, NetworkChatDestinationType type, int dest, std::string_view msg, ClientID from_id, int64_t data=0, bool from_admin=false)
Send an actual chat message.
NetworkAction
Actions that can be used for NetworkTextMessage.
@ ChatTeam
A chat sent to all clients of a team/company.
@ ChatClient
A chat sent to a specific client.
@ ChatBroadcast
A chat broadcast to all clients.
NetworkChatDestinationType
Destination of our chat messages.
@ Client
Send message/notice to only a certain client (Private).
@ Team
Send message/notice to everyone playing the same company (Team).
@ Broadcast
Send message/notice to all clients (All).
ClientID
'Unique' identifier to be given to clients
@ CLIENT_ID_SERVER
Servers always have this ID.
Base for the GUIs that have an edit box in them.
A number of safeguards to prevent using unsafe methods.
ClientSettings _settings_client
The current settings for this game.
static const PaletteID PALETTE_TO_TRANSPARENT
This sets the sprite to transparent.
Definition of base types and functions in a cross-platform compatible way.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Functions related to OTTD's strings.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
TextColour colour
The colour of the message.
std::chrono::steady_clock::time_point remove_time
The time to remove the message.
std::string message
The action message.
Window to enter the chat message in.
void FindWindowPlacementAndResize(int, int def_height, bool allow_resize) override
Resize window towards the default size.
NetworkChatAutoCompletion chat_tab_completion
Holds the state and logic of auto-completion of player names and towns on Tab press.
EventState OnKeyPress(char32_t key, uint16_t keycode) override
A key has been pressed.
void OnEditboxChanged(WidgetID widget) override
The text in an editbox has been edited.
NetworkChatWindow(WindowDesc &desc, NetworkChatDestinationType type, int dest)
Create a chat input window.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void ChatTabCompletion()
See if we can auto-complete the current text of the user.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
int dest
The identifier of the destination.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
QueryString message_editbox
Message editbox.
NetworkChatDestinationType dtype
The type of destination.
Point OnInitialPosition(int16_t sm_width, int16_t sm_height, int window_number) override
Compute the initial position of the window.
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
Container for all information known about a client.
static NetworkClientInfo * GetByClientID(ClientID client_id)
Return the CI given it's client-identifier.
Specification of a rectangle with an absolute top-left coordinate and a (relative) width/height.
static Pool::IterateWrapper< NetworkClientInfo > Iterate(size_t from=0)
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.
std::string_view GetText() const
Get the current text.
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.
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
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.
virtual void FindWindowPlacementAndResize(int def_width, int def_height, bool allow_resize)
Resize window towards the default size.
Window(WindowDesc &desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
int height
Height of the window (number of pixels down in y direction).
WindowNumber window_number
Window number within the window class.
Definition of Interval and OneShot timers.
Definition of the Window system.
Base of all video drivers.
int PositionNetworkChatWindow(Window *w)
(Re)position network chat window at the screen.
Window * FindWindowByClass(WindowClass cls)
Find any window by its class.
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Window functions not directly related to making/drawing windows.
@ WDP_MANUAL
Manually align the window (so no automatic location finding).
EventState
State of handling an event.
@ ES_HANDLED
The passed event is handled.
@ ES_NOT_HANDLED
The passed event is not handled.
@ WC_NEWS_WINDOW
News window; Window numbers:
@ WC_STATUS_BAR
Statusbar (at the bottom of your screen); Window numbers:
@ WC_SEND_NETWORK_MSG
Chatbox; Window numbers:
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Functions related to zooming.