OpenTTD Source: src/network/network_chat_gui.cpp Source File

OpenTTD Source 14.1

network_chat_gui.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10 #include "../stdafx.h"
11 #include "../strings_func.h"
12 #include "../blitter/factory.hpp"
13 #include "../console_func.h"
14 #include "../video/video_driver.hpp"
15 #include "../querystring_gui.h"
16 #include "../town.h"
17 #include "../window_func.h"
18 #include "../toolbar_gui.h"
19 #include "../core/geometry_func.hpp"
20 #include "../zoom_func.h"
21 #include "../timer/timer.h"
22 #include "../timer/timer_window.h"
23 #include "network.h"
24 #include "network_client.h"
25 #include "network_base.h"
26
27 #include "../widgets/network_chat_widget.h"
28
29 #include "table/strings.h"
30
31 #include "../safeguards.h"
32
34 static const uint NETWORK_CHAT_LINE_SPACING = 3;
35
37 struct ChatMessage {
38 std::string message;
39 TextColour colour;
40 std::chrono::steady_clock::time_point remove_time;
41 };
42
43 /* used for chat window */
44 static std::deque<ChatMessage> _chatmsg_list;
45 static bool _chatmessage_dirty = false;
46 static bool _chatmessage_visible = false;
47 static bool _chat_tab_completion_active;
48 static uint MAX_CHAT_MESSAGES = 0;
49
54 static std::chrono::steady_clock::time_point _chatmessage_dirty_time;
55
60 static PointDimension _chatmsg_box;
61 static ReusableBuffer<uint8_t> _chatmessage_backup;
62
68 static inline bool HaveChatMessages(bool show_all)
69 {
70 if (show_all) return !_chatmsg_list.empty();
71
72 auto now = std::chrono::steady_clock::now();
73 for (auto &cmsg : _chatmsg_list) {
74 if (cmsg.remove_time >= now) return true;
75 }
76
77 return false;
78 }
79
86 void CDECL NetworkAddChatMessage(TextColour colour, uint duration, const std::string &message)
87 {
88 if (_chatmsg_list.size() == MAX_CHAT_MESSAGES) {
89 _chatmsg_list.pop_back();
90 }
91
92 ChatMessage *cmsg = &_chatmsg_list.emplace_front();
93 cmsg->message = message;
94 cmsg->colour = colour;
95 cmsg->remove_time = std::chrono::steady_clock::now() + std::chrono::seconds(duration);
96
97 _chatmessage_dirty_time = std::chrono::steady_clock::now();
98 _chatmessage_dirty = true;
99 }
100
102 void NetworkReInitChatBoxSize()
103 {
104 _chatmsg_box.y = 3 * GetCharacterHeight(FS_NORMAL);
105 _chatmsg_box.height = MAX_CHAT_MESSAGES * (GetCharacterHeight(FS_NORMAL) + ScaleGUITrad(NETWORK_CHAT_LINE_SPACING)) + ScaleGUITrad(4);
106 }
107
109 void NetworkInitChatMessage()
110 {
111 MAX_CHAT_MESSAGES = _settings_client.gui.network_chat_box_height;
112
113 _chatmsg_list.clear();
114 _chatmsg_box.x = ScaleGUITrad(10);
115 _chatmsg_box.width = _settings_client.gui.network_chat_box_width_pct * _screen.width / 100;
116 NetworkReInitChatBoxSize();
117 _chatmessage_visible = false;
118 }
119
121 void NetworkUndrawChatMessage()
122 {
123 /* Sometimes we also need to hide the cursor
124 * This is because both textmessage and the cursor take a shot of the
125 * screen before drawing.
126 * Now the textmessage takes its shot and paints its data before the cursor
127 * does, so in the shot of the cursor is the screen-data of the textmessage
128 * included when the cursor hangs somewhere over the textmessage. To
129 * avoid wrong repaints, we undraw the cursor in that case, and everything
130 * looks nicely ;)
131 * (and now hope this story above makes sense to you ;))
132 */
133 if (_cursor.visible &&
134 _cursor.draw_pos.x + _cursor.draw_size.x >= _chatmsg_box.x &&
135 _cursor.draw_pos.x <= _chatmsg_box.x + _chatmsg_box.width &&
136 _cursor.draw_pos.y + _cursor.draw_size.y >= _screen.height - _chatmsg_box.y - _chatmsg_box.height &&
137 _cursor.draw_pos.y <= _screen.height - _chatmsg_box.y) {
138 UndrawMouseCursor();
139 }
140
141 if (_chatmessage_visible) {
142 Blitter *blitter = BlitterFactory::GetCurrentBlitter();
143 int x = _chatmsg_box.x;
144 int y = _screen.height - _chatmsg_box.y - _chatmsg_box.height;
145 int width = _chatmsg_box.width;
146 int height = _chatmsg_box.height;
147 if (y < 0) {
148 height = std::max(height + y, std::min(_chatmsg_box.height, _screen.height));
149 y = 0;
150 }
151 if (x + width >= _screen.width) {
152 width = _screen.width - x;
153 }
154 if (width <= 0 || height <= 0) return;
155
156 _chatmessage_visible = false;
157 /* Put our 'shot' back to the screen */
158 blitter->CopyFromBuffer(blitter->MoveTo(_screen.dst_ptr, x, y), _chatmessage_backup.GetBuffer(), width, height);
159 /* And make sure it is updated next time */
160 VideoDriver::GetInstance()->MakeDirty(x, y, width, height);
161
162 _chatmessage_dirty_time = std::chrono::steady_clock::now();
163 _chatmessage_dirty = true;
164 }
165 }
166
168 static IntervalTimer<TimerWindow> network_message_expired_interval(std::chrono::seconds(1), [](auto) {
169 auto now = std::chrono::steady_clock::now();
170 for (auto &cmsg : _chatmsg_list) {
171 /* Message has expired, remove from the list */
172 if (now > cmsg.remove_time && _chatmessage_dirty_time < cmsg.remove_time) {
173 _chatmessage_dirty_time = now;
174 _chatmessage_dirty = true;
175 break;
176 }
177 }
178 });
179
181 void NetworkDrawChatMessage()
182 {
183 Blitter *blitter = BlitterFactory::GetCurrentBlitter();
184 if (!_chatmessage_dirty) return;
185
186 const Window *w = FindWindowByClass(WC_SEND_NETWORK_MSG);
187 bool show_all = (w != nullptr);
188
189 /* First undraw if needed */
190 NetworkUndrawChatMessage();
191
192 if (_iconsole_mode == ICONSOLE_FULL) return;
193
194 /* Check if we have anything to draw at all */
195 if (!HaveChatMessages(show_all)) return;
196
197 int x = _chatmsg_box.x;
198 int y = _screen.height - _chatmsg_box.y - _chatmsg_box.height;
199 int width = _chatmsg_box.width;
200 int height = _chatmsg_box.height;
201 if (y < 0) {
202 height = std::max(height + y, std::min(_chatmsg_box.height, _screen.height));
203 y = 0;
204 }
205 if (x + width >= _screen.width) {
206 width = _screen.width - x;
207 }
208 if (width <= 0 || height <= 0) return;
209
210 /* Make a copy of the screen as it is before painting (for undraw) */
211 uint8_t *buffer = _chatmessage_backup.Allocate(BlitterFactory::GetCurrentBlitter()->BufferSize(width, height));
212 blitter->CopyToBuffer(blitter->MoveTo(_screen.dst_ptr, x, y), buffer, width, height);
213
214 _cur_dpi = &_screen; // switch to _screen painting
215
216 auto now = std::chrono::steady_clock::now();
217 int string_height = 0;
218 for (auto &cmsg : _chatmsg_list) {
219 if (!show_all && cmsg.remove_time < now) continue;
220 SetDParamStr(0, cmsg.message);
221 string_height += GetStringLineCount(STR_JUST_RAW_STRING, width - 1) * GetCharacterHeight(FS_NORMAL) + NETWORK_CHAT_LINE_SPACING;
222 }
223
224 string_height = std::min<uint>(string_height, MAX_CHAT_MESSAGES * (GetCharacterHeight(FS_NORMAL) + NETWORK_CHAT_LINE_SPACING));
225
226 int top = _screen.height - _chatmsg_box.y - string_height - 2;
227 int bottom = _screen.height - _chatmsg_box.y - 2;
228 /* Paint a half-transparent box behind the chat messages */
229 GfxFillRect(_chatmsg_box.x, top - 2, _chatmsg_box.x + _chatmsg_box.width - 1, bottom,
230 PALETTE_TO_TRANSPARENT, FILLRECT_RECOLOUR // black, but with some alpha for background
231 );
232
233 /* Paint the chat messages starting with the lowest at the bottom */
234 int ypos = bottom - 2;
235
236 for (auto &cmsg : _chatmsg_list) {
237 if (!show_all && cmsg.remove_time < now) continue;
238 ypos = DrawStringMultiLine(_chatmsg_box.x + ScaleGUITrad(3), _chatmsg_box.x + _chatmsg_box.width - 1, top, ypos, cmsg.message, cmsg.colour, SA_LEFT | SA_BOTTOM | SA_FORCE) - NETWORK_CHAT_LINE_SPACING;
239 if (ypos < top) break;
240 }
241
242 /* Make sure the data is updated next flush */
243 VideoDriver::GetInstance()->MakeDirty(x, y, width, height);
244
245 _chatmessage_visible = true;
246 _chatmessage_dirty = false;
247 }
248
255 static void SendChat(const std::string &buf, DestType type, int dest)
256 {
257 if (buf.empty()) return;
258 if (!_network_server) {
259 MyClient::SendChat((NetworkAction)(NETWORK_ACTION_CHAT + type), type, dest, buf, 0);
260 } else {
261 NetworkServerSendChat((NetworkAction)(NETWORK_ACTION_CHAT + type), type, dest, buf, CLIENT_ID_SERVER);
262 }
263 }
264
266 struct NetworkChatWindow : public Window {
267 DestType dtype;
268 int dest;
269 QueryString message_editbox;
270
277 NetworkChatWindow(WindowDesc *desc, DestType type, int dest) : Window(desc), message_editbox(NETWORK_CHAT_LENGTH)
278 {
279 this->dtype = type;
280 this->dest = dest;
281 this->querystrings[WID_NC_TEXTBOX] = &this->message_editbox;
282 this->message_editbox.cancel_button = WID_NC_CLOSE;
283 this->message_editbox.ok_button = WID_NC_SENDBUTTON;
284
285 static const StringID chat_captions[] = {
286 STR_NETWORK_CHAT_ALL_CAPTION,
287 STR_NETWORK_CHAT_COMPANY_CAPTION,
288 STR_NETWORK_CHAT_CLIENT_CAPTION
289 };
290 assert((uint)this->dtype < lengthof(chat_captions));
291
292 this->CreateNestedTree();
293 this->GetWidget<NWidgetCore>(WID_NC_DESTINATION)->widget_data = chat_captions[this->dtype];
294 this->FinishInitNested(type);
295
296 this->SetFocusedWidget(WID_NC_TEXTBOX);
297 InvalidateWindowData(WC_NEWS_WINDOW, 0, this->height);
298 _chat_tab_completion_active = false;
299
300 PositionNetworkChatWindow(this);
301 }
302
303 void Close([[maybe_unused]] int data = 0) override
304 {
305 InvalidateWindowData(WC_NEWS_WINDOW, 0, 0);
306 this->Window::Close();
307 }
308
309 void FindWindowPlacementAndResize([[maybe_unused]] int def_width, [[maybe_unused]] int def_height) override
310 {
311 Window::FindWindowPlacementAndResize(_toolbar_width, def_height);
312 }
313
320 std::optional<std::string> ChatTabCompletionNextItem(uint *item)
321 {
322 /* First, try clients */
323 if (*item < MAX_CLIENT_SLOTS) {
324 /* Skip inactive clients */
325 for (NetworkClientInfo *ci : NetworkClientInfo::Iterate(*item)) {
326 *item = ci->index;
327 return ci->client_name;
328 }
329 *item = MAX_CLIENT_SLOTS;
330 }
331
332 /* Then, try townnames
333 * Not that the following assumes all town indices are adjacent, ie no
334 * towns have been deleted. */
335 if (*item < (uint)MAX_CLIENT_SLOTS + Town::GetPoolSize()) {
336 for (const Town *t : Town::Iterate(*item - MAX_CLIENT_SLOTS)) {
337 /* Get the town-name via the string-system */
338 SetDParam(0, t->index);
339 return GetString(STR_TOWN_NAME);
340 }
341 }
342
343 return std::nullopt;
344 }
345
351 static std::string_view ChatTabCompletionFindText(std::string_view &buf)
352 {
353 auto it = buf.find_last_of(' ');
354 if (it == std::string_view::npos) return buf;
355
356 std::string_view res = buf.substr(it + 1);
357 buf.remove_suffix(res.size() + 1);
358 return res;
359 }
360
364 void ChatTabCompletion()
365 {
366 static std::string _chat_tab_completion_buf;
367
368 Textbuf *tb = &this->message_editbox.text;
369 uint item = 0;
370 bool second_scan = false;
371
372 /* Create views, so we do not need to copy the data for now. */
373 std::string_view pre_buf = _chat_tab_completion_active ? std::string_view(_chat_tab_completion_buf) : std::string_view(tb->buf);
374 std::string_view tb_buf = ChatTabCompletionFindText(pre_buf);
375
376 /*
377 * Comparing pointers of the data, as both "Hi:<tab>" and "Hi: Hi:<tab>" will result in
378 * tb_buf and pre_buf being "Hi:", which would be equal in content but not in context.
379 */
380 bool begin_of_line = tb_buf.data() == pre_buf.data();
381
382 std::optional<std::string> cur_item;
383 while ((cur_item = ChatTabCompletionNextItem(&item)).has_value()) {
384 std::string_view cur_name = cur_item.value();
385 item++;
386
387 if (_chat_tab_completion_active) {
388 /* We are pressing TAB again on the same name, is there another name
389 * that starts with this? */
390 if (!second_scan) {
391 std::string_view view;
392
393 /* If we are completing at the begin of the line, skip the ': ' we added */
394 if (begin_of_line) {
395 view = std::string_view(tb->buf, (tb->bytes - 1) - 2);
396 } else {
397 /* Else, find the place we are completing at */
398 size_t offset = pre_buf.size() + 1;
399 view = std::string_view(tb->buf + offset, (tb->bytes - 1) - offset);
400 }
401
402 /* Compare if we have a match */
403 if (cur_name == view) second_scan = true;
404
405 continue;
406 }
407
408 /* Now any match we make on _chat_tab_completion_buf after this, is perfect */
409 }
410
411 if (tb_buf.size() < cur_name.size() && cur_name.starts_with(tb_buf)) {
412 /* Save the data it was before completion */
413 if (!second_scan) _chat_tab_completion_buf = tb->buf;
414 _chat_tab_completion_active = true;
415
416 /* Change to the found name. Add ': ' if we are at the start of the line (pretty) */
417 if (begin_of_line) {
418 this->message_editbox.text.Assign(fmt::format("{}: ", cur_name));
419 } else {
420 this->message_editbox.text.Assign(fmt::format("{} {}", pre_buf, cur_name));
421 }
422
423 this->SetDirty();
424 return;
425 }
426 }
427
428 if (second_scan) {
429 /* We walked all possibilities, and the user presses tab again.. revert to original text */
430 this->message_editbox.text.Assign(_chat_tab_completion_buf);
431 _chat_tab_completion_active = false;
432
433 this->SetDirty();
434 }
435 }
436
437 Point OnInitialPosition([[maybe_unused]] int16_t sm_width, [[maybe_unused]] int16_t sm_height, [[maybe_unused]] int window_number) override
438 {
439 Point pt = { 0, _screen.height - sm_height - FindWindowById(WC_STATUS_BAR, 0)->height };
440 return pt;
441 }
442
443 void SetStringParameters(WidgetID widget) const override
444 {
445 if (widget != WID_NC_DESTINATION) return;
446
447 if (this->dtype == DESTTYPE_CLIENT) {
448 SetDParamStr(0, NetworkClientInfo::GetByClientID((ClientID)this->dest)->client_name);
449 }
450 }
451
452 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
453 {
454 switch (widget) {
455 case WID_NC_SENDBUTTON: /* Send */
456 SendChat(this->message_editbox.text.buf, this->dtype, this->dest);
457 [[fallthrough]];
458
459 case WID_NC_CLOSE: /* Cancel */
460 this->Close();
461 break;
462 }
463 }
464
465 EventState OnKeyPress([[maybe_unused]] char32_t key, uint16_t keycode) override
466 {
467 EventState state = ES_NOT_HANDLED;
468 if (keycode == WKC_TAB) {
469 ChatTabCompletion();
470 state = ES_HANDLED;
471 }
472 return state;
473 }
474
475 void OnEditboxChanged(WidgetID widget) override
476 {
477 if (widget == WID_NC_TEXTBOX) {
478 _chat_tab_completion_active = false;
479 }
480 }
481
487 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
488 {
489 if (data == this->dest) this->Close();
490 }
491 };
492
494 static constexpr NWidgetPart _nested_chat_window_widgets[] = {
495 NWidget(NWID_HORIZONTAL),
496 NWidget(WWT_CLOSEBOX, COLOUR_GREY, WID_NC_CLOSE),
497 NWidget(WWT_PANEL, COLOUR_GREY, WID_NC_BACKGROUND),
498 NWidget(NWID_HORIZONTAL),
499 NWidget(WWT_TEXT, COLOUR_GREY, WID_NC_DESTINATION), SetMinimalSize(62, 12), SetPadding(1, 0, 1, 0), SetAlignment(SA_VERT_CENTER | SA_RIGHT), SetDataTip(STR_NULL, STR_NULL),
500 NWidget(WWT_EDITBOX, COLOUR_GREY, WID_NC_TEXTBOX), SetMinimalSize(100, 12), SetPadding(1, 0, 1, 0), SetResize(1, 0),
501 SetDataTip(STR_NETWORK_CHAT_OSKTITLE, STR_NULL),
502 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_NC_SENDBUTTON), SetMinimalSize(62, 12), SetPadding(1, 0, 1, 0), SetDataTip(STR_NETWORK_CHAT_SEND, STR_NULL),
503 EndContainer(),
504 EndContainer(),
505 EndContainer(),
506 };
507
509 static WindowDesc _chat_window_desc(__FILE__, __LINE__,
510 WDP_MANUAL, nullptr, 0, 0,
511 WC_SEND_NETWORK_MSG, WC_NONE,
512 0,
513 std::begin(_nested_chat_window_widgets), std::end(_nested_chat_window_widgets)
514 );
515
516
522 void ShowNetworkChatQueryWindow(DestType type, int dest)
523 {
524 CloseWindowByClass(WC_SEND_NETWORK_MSG);
525 new NetworkChatWindow(&_chat_window_desc, type, dest);
526 }
ES_HANDLED
@ ES_HANDLED
The passed event is handled.
Definition: window_type.h:739
InvalidateWindowData
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-...
Definition: window.cpp:3204
CloseWindowByClass
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
Definition: window.cpp:1153
QueryString::ok_button
int ok_button
Widget button of parent window to simulate when pressing OK in OSK.
Definition: querystring_gui.h:27
NetworkChatWindow
Window to enter the chat message in.
Definition: network_chat_gui.cpp:266
ReusableBuffer
A reusable buffer that can be used for places that temporary allocate a bit of memory and do that ver...
Definition: alloc_type.hpp:24
NetworkChatWindow::dest
int dest
The identifier of the destination.
Definition: network_chat_gui.cpp:268
NetworkChatWindow::ChatTabCompletionFindText
static std::string_view ChatTabCompletionFindText(std::string_view &buf)
Find what text to complete.
Definition: network_chat_gui.cpp:351
Blitter
How all blitters should look like.
Definition: base.hpp:29
CursorVars::visible
bool visible
cursor is visible
Definition: gfx_type.h:139
SetAlignment
constexpr NWidgetPart SetAlignment(StringAlignment align)
Widget part function for setting the alignment of text/images.
Definition: widget_type.h:1132
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
Textbuf::Assign
void Assign(StringID string)
Render a string into the textbuffer.
Definition: textbuf.cpp:405
_network_server
bool _network_server
network-server is active
Definition: network.cpp:66
NetworkAction
NetworkAction
Actions that can be used for NetworkTextMessage.
Definition: network_type.h:102
Blitter::CopyToBuffer
virtual void CopyToBuffer(const void *video, void *dst, int width, int height)=0
Copy from the screen to a buffer.
FILLRECT_RECOLOUR
@ FILLRECT_RECOLOUR
Apply a recolour sprite to the screen content.
Definition: gfx_type.h:295
IntervalTimer< TimerWindow >
VideoDriver::MakeDirty
virtual void MakeDirty(int left, int top, int width, int height)=0
Mark a particular area dirty.
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:77
NetworkInitChatMessage
void NetworkInitChatMessage()
Initialize all buffers of the chat visualisation.
Definition: network_chat_gui.cpp:109
Window::Close
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Definition: window.cpp:1048
NETWORK_CHAT_LENGTH
static const uint NETWORK_CHAT_LENGTH
The maximum length of a chat message, in bytes including '\0'.
Definition: config.h:63
ClientNetworkGameSocketHandler::SendChat
static NetworkRecvStatus SendChat(NetworkAction action, DestType type, int dest, const std::string &msg, int64_t data)
Send a chat-packet over the network.
Definition: network_client.cpp:450
FindWindowById
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition: window.cpp:1099
NetworkChatWindow::ChatTabCompletionNextItem
std::optional< std::string > ChatTabCompletionNextItem(uint *item)
Find the next item of the list of things that can be auto-completed.
Definition: network_chat_gui.cpp:320
PALETTE_TO_TRANSPARENT
static const PaletteID PALETTE_TO_TRANSPARENT
This sets the sprite to transparent.
Definition: sprites.h:1599
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1153
NetworkChatWindow::dtype
DestType dtype
The type of destination.
Definition: network_chat_gui.cpp:267
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:253
SA_BOTTOM
@ SA_BOTTOM
Bottom align the text.
Definition: gfx_type.h:345
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:54
ChatMessage
Container for a message.
Definition: network_chat_gui.cpp:37
NetworkChatWindow::NetworkChatWindow
NetworkChatWindow(WindowDesc *desc, DestType type, int dest)
Create a chat input window.
Definition: network_chat_gui.cpp:277
SA_RIGHT
@ SA_RIGHT
Right align the text (must be a single bit).
Definition: gfx_type.h:340
SA_VERT_CENTER
@ SA_VERT_CENTER
Vertically center the text.
Definition: gfx_type.h:344
NetworkServerSendChat
void NetworkServerSendChat(NetworkAction action, DestType type, int dest, const std::string &msg, ClientID from_id, int64_t data=0, bool from_admin=false)
Send an actual chat message.
Definition: network_server.cpp:1235
CursorVars::draw_size
Point draw_size
position and size bounding-box for drawing
Definition: gfx_type.h:133
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:1040
NetworkChatWindow::OnInvalidateData
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
Definition: network_chat_gui.cpp:487
QueryString
Data stored about a string that can be modified in the GUI.
Definition: querystring_gui.h:20
GetStringLineCount
int GetStringLineCount(StringID str, int maxw)
Calculates number of lines of string.
Definition: gfx.cpp:725
Textbuf::buf
char *const buf
buffer in which text is saved
Definition: textbuf_type.h:32
network_base.h
WID_NC_TEXTBOX
@ WID_NC_TEXTBOX
Textbox.
Definition: network_chat_widget.h:18
NetworkReInitChatBoxSize
void NetworkReInitChatBoxSize()
Initialize all font-dependent chat box sizes.
Definition: network_chat_gui.cpp:102
ICONSOLE_FULL
@ ICONSOLE_FULL
In-game console is opened, whole screen.
Definition: console_type.h:17
WindowDesc
High level window description.
Definition: window_gui.h:153
WidgetID
int WidgetID
Widget ID.
Definition: window_type.h:18
ChatMessage::message
std::string message
The action message.
Definition: network_chat_gui.cpp:38
ScaleGUITrad
int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
Definition: zoom_func.h:117
NetworkClientInfo::GetByClientID
static NetworkClientInfo * GetByClientID(ClientID client_id)
Return the CI given it's client-identifier.
Definition: network.cpp:120
Pool::PoolItem<&_town_pool >::GetPoolSize
static size_t GetPoolSize()
Returns first unused index.
Definition: pool_type.hpp:360
SetPadding
constexpr NWidgetPart SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
Widget part function for setting additional space around a widget.
Definition: widget_type.h:1190
ChatMessage::colour
TextColour colour
The colour of the message.
Definition: network_chat_gui.cpp:39
_chatmessage_visible
static bool _chatmessage_visible
Is a chat message visible.
Definition: network_chat_gui.cpp:46
SetResize
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition: widget_type.h:1088
WID_NC_CLOSE
@ WID_NC_CLOSE
Close button.
Definition: network_chat_widget.h:15
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition: gfx_type.h:203
WWT_EDITBOX
@ WWT_EDITBOX
a textbox for typing
Definition: widget_type.h:73
Window::height
int height
Height of the window (number of pixels down in y direction)
Definition: window_gui.h:306
WID_NC_BACKGROUND
@ WID_NC_BACKGROUND
Background of the window.
Definition: network_chat_widget.h:16
_toolbar_width
uint _toolbar_width
Width of the toolbar, shared by statusbar.
Definition: toolbar_gui.cpp:70
_chat_window_desc
static WindowDesc _chat_window_desc(__FILE__, __LINE__, WDP_MANUAL, nullptr, 0, 0, WC_SEND_NETWORK_MSG, WC_NONE, 0, std::begin(_nested_chat_window_widgets), std::end(_nested_chat_window_widgets))
The description of the chat window.
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:941
Textbuf::bytes
uint16_t bytes
the current size of the string in bytes (including terminating '\0')
Definition: textbuf_type.h:35
ES_NOT_HANDLED
@ ES_NOT_HANDLED
The passed event is not handled.
Definition: window_type.h:740
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:110
_chatmessage_backup
static ReusableBuffer< uint8_t > _chatmessage_backup
Backup in case text is moved.
Definition: network_chat_gui.cpp:61
NetworkDrawChatMessage
void NetworkDrawChatMessage()
Draw the chat message-box.
Definition: network_chat_gui.cpp:181
BlitterFactory::GetCurrentBlitter
static Blitter * GetCurrentBlitter()
Get the current active blitter (always set by calling SelectBlitter).
Definition: factory.hpp:138
SA_FORCE
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
Definition: gfx_type.h:350
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1260
lengthof
#define lengthof(array)
Return the length of an fixed size array.
Definition: stdafx.h:303
_chat_tab_completion_active
static bool _chat_tab_completion_active
Whether tab completion is active.
Definition: network_chat_gui.cpp:47
GUISettings::network_chat_box_height
uint8_t network_chat_box_height
height of the chat box in lines
Definition: settings_type.h:211
SendChat
static void SendChat(const std::string &buf, DestType type, int dest)
Send an actual chat message.
Definition: network_chat_gui.cpp:255
network_client.h
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
NetworkUndrawChatMessage
void NetworkUndrawChatMessage()
Hide the chatbox.
Definition: network_chat_gui.cpp:121
network_message_expired_interval
static 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.
WID_NC_SENDBUTTON
@ WID_NC_SENDBUTTON
Send button.
Definition: network_chat_widget.h:19
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:296
Window::SetFocusedWidget
bool SetFocusedWidget(WidgetID widget_index)
Set focus within this window to the given widget.
Definition: window.cpp:487
GfxFillRect
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
Definition: gfx.cpp:113
VideoDriver::GetInstance
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
Definition: video_driver.hpp:201
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:45
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:71
Window::querystrings
std::map< WidgetID, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
Definition: window_gui.h:314
QueryString::cancel_button
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
Definition: querystring_gui.h:28
DrawStringMultiLine
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.
Definition: gfx.cpp:771
Pool::PoolItem<&_networkclientinfo_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:388
WID_NC_DESTINATION
@ WID_NC_DESTINATION
Destination.
Definition: network_chat_widget.h:17
Window::CreateNestedTree
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1724
NETWORK_CHAT_LINE_SPACING
static const uint NETWORK_CHAT_LINE_SPACING
Spacing between chat lines.
Definition: network_chat_gui.cpp:34
_chatmessage_dirty
static bool _chatmessage_dirty
Does the chat message need repainting?
Definition: network_chat_gui.cpp:45
ClientID
ClientID
'Unique' identifier to be given to clients
Definition: network_type.h:49
Blitter::MoveTo
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...
WWT_TEXT
@ WWT_TEXT
Pure simple text.
Definition: widget_type.h:60
NetworkAddChatMessage
void CDECL NetworkAddChatMessage(TextColour colour, uint duration, const std::string &message)
Add a text message to the 'chat window' to be shown.
Definition: network_chat_gui.cpp:86
DestType
DestType
Destination of our chat messages.
Definition: network_type.h:91
SetDParam
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings.cpp:104
_chatmessage_dirty_time
static std::chrono::steady_clock::time_point _chatmessage_dirty_time
Time the chat history was marked dirty.
Definition: network_chat_gui.cpp:54
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:52
_nested_chat_window_widgets
static constexpr NWidgetPart _nested_chat_window_widgets[]
The widgets of the chat window.
Definition: network_chat_gui.cpp:494
GetString
std::string GetString(StringID string)
Resolve the given StringID into a std::string with all the associated DParam lookups and formatting.
Definition: strings.cpp:327
EventState
EventState
State of handling an event.
Definition: window_type.h:738
MAX_CHAT_MESSAGES
static uint MAX_CHAT_MESSAGES
The limit of chat messages to show.
Definition: network_chat_gui.cpp:48
FindWindowByClass
Window * FindWindowByClass(WindowClass cls)
Find any window by its class.
Definition: window.cpp:1114
DESTTYPE_CLIENT
@ DESTTYPE_CLIENT
Send message/notice to only a certain client (Private)
Definition: network_type.h:94
SetDParamStr
void SetDParamStr(size_t n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Definition: strings.cpp:352
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1734
HaveChatMessages
static bool HaveChatMessages(bool show_all)
Test if there are any chat messages to display.
Definition: network_chat_gui.cpp:68
NetworkChatWindow::ChatTabCompletion
void ChatTabCompletion()
See if we can auto-complete the current text of the user.
Definition: network_chat_gui.cpp:364
ShowNetworkChatQueryWindow
void ShowNetworkChatQueryWindow(DestType type, int dest)
Show the chat window.
Definition: network_chat_gui.cpp:522
SA_LEFT
@ SA_LEFT
Left align the text.
Definition: gfx_type.h:338
network.h
WC_SEND_NETWORK_MSG
@ WC_SEND_NETWORK_MSG
Chatbox; Window numbers:
Definition: window_type.h:503
Blitter::CopyFromBuffer
virtual void CopyFromBuffer(void *video, const void *src, int width, int height)=0
Copy from a buffer to the screen.
GetCharacterHeight
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition: fontcache.cpp:78
Town
Town data structure.
Definition: town.h:50
SetMinimalSize
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1099
WDP_MANUAL
@ WDP_MANUAL
Manually align the window (so no automatic location finding)
Definition: window_gui.h:140
_chatmsg_list
static std::deque< ChatMessage > _chatmsg_list
The actual chat message list.
Definition: network_chat_gui.cpp:44
NetworkChatWindow::message_editbox
QueryString message_editbox
Message editbox.
Definition: network_chat_gui.cpp:269
PointDimension
Specification of a rectangle with an absolute top-left coordinate and a (relative) width/height.
Definition: geometry_type.hpp:234
PositionNetworkChatWindow
int PositionNetworkChatWindow(Window *w)
(Re)position network chat window at the screen.
Definition: window.cpp:3407
Window
Data structure for an opened window.
Definition: window_gui.h:267
WC_STATUS_BAR
@ WC_STATUS_BAR
Statusbar (at the bottom of your screen); Window numbers:
Definition: window_type.h:64
WC_NEWS_WINDOW
@ WC_NEWS_WINDOW
News window; Window numbers:
Definition: window_type.h:248
SetDataTip
constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1164
MAX_CLIENT_SLOTS
static const uint MAX_CLIENT_SLOTS
The number of slots; must be at least 1 more than MAX_CLIENTS.
Definition: network_type.h:23
_chatmsg_box
static PointDimension _chatmsg_box
The chatbox grows from the bottom so the coordinates are pixels from the left and pixels from the bot...
Definition: network_chat_gui.cpp:60
CLIENT_ID_SERVER
@ CLIENT_ID_SERVER
Servers always have this ID.
Definition: network_type.h:51
NetworkClientInfo
Container for all information known about a client.
Definition: network_base.h:24
ChatMessage::remove_time
std::chrono::steady_clock::time_point remove_time
The time to remove the message.
Definition: network_chat_gui.cpp:40
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:635
GUISettings::network_chat_box_width_pct
uint16_t network_chat_box_width_pct
width of the chat box in percent
Definition: settings_type.h:210
Window::FindWindowPlacementAndResize
virtual void FindWindowPlacementAndResize(int def_width, int def_height)
Resize window towards the default size.
Definition: window.cpp:1421
Textbuf
Helper/buffer for input fields.
Definition: textbuf_type.h:30