OpenTTD

network_chat_gui.cpp
Go to the documentation of this file.
1 /* $Id: network_chat_gui.cpp 27893 2017-08-13 18:38:42Z frosch $ */
2
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
8 */
9
12 #include <stdarg.h> /* va_list */
13
14 #ifdef ENABLE_NETWORK
15
16 #include "../stdafx.h"
17 #include "../strings_func.h"
18 #include "../blitter/factory.hpp"
19 #include "../console_func.h"
20 #include "../video/video_driver.hpp"
21 #include "../querystring_gui.h"
22 #include "../town.h"
23 #include "../window_func.h"
24 #include "../toolbar_gui.h"
25 #include "../core/geometry_func.hpp"
26 #include "network.h"
27 #include "network_client.h"
28 #include "network_base.h"
29
30 #include "../widgets/network_chat_widget.h"
31
32 #include "table/strings.h"
33
34 #include "../safeguards.h"
35
38 assert_compile((int)DRAW_STRING_BUFFER >= (int)NETWORK_CHAT_LENGTH + NETWORK_NAME_LENGTH + 40);
39
41 static const uint NETWORK_CHAT_LINE_SPACING = 3;
42
44 struct ChatMessage {
45 char message[DRAW_STRING_BUFFER];
46 TextColour colour;
47 uint32 remove_time;
48 };
49
50 /* used for chat window */
51 static ChatMessage *_chatmsg_list = NULL;
52 static bool _chatmessage_dirty = false;
53 static bool _chatmessage_visible = false;
54 static bool _chat_tab_completion_active;
55 static uint MAX_CHAT_MESSAGES = 0;
56
61 static PointDimension _chatmsg_box;
62 static uint8 *_chatmessage_backup = NULL;
63
68 static inline uint GetChatMessageCount()
69 {
70 uint i = 0;
71 for (; i < MAX_CHAT_MESSAGES; i++) {
72 if (_chatmsg_list[i].message[0] == '\0') break;
73 }
74
75 return i;
76 }
77
84 void CDECL NetworkAddChatMessage(TextColour colour, uint duration, const char *message, ...)
85 {
86 char buf[DRAW_STRING_BUFFER];
87 va_list va;
88
89 va_start(va, message);
90 vseprintf(buf, lastof(buf), message, va);
91 va_end(va);
92
93 Utf8TrimString(buf, DRAW_STRING_BUFFER);
94
95 uint msg_count = GetChatMessageCount();
96 if (MAX_CHAT_MESSAGES == msg_count) {
97 memmove(&_chatmsg_list[0], &_chatmsg_list[1], sizeof(_chatmsg_list[0]) * (msg_count - 1));
98 msg_count = MAX_CHAT_MESSAGES - 1;
99 }
100
101 ChatMessage *cmsg = &_chatmsg_list[msg_count++];
102 strecpy(cmsg->message, buf, lastof(cmsg->message));
103 cmsg->colour = (colour & TC_IS_PALETTE_COLOUR) ? colour : TC_WHITE;
104 cmsg->remove_time = _realtime_tick + duration * 1000;
105
106 _chatmessage_dirty = true;
107 }
108
110 void NetworkReInitChatBoxSize()
111 {
112 _chatmsg_box.y = 3 * FONT_HEIGHT_NORMAL;
113 _chatmsg_box.height = MAX_CHAT_MESSAGES * (FONT_HEIGHT_NORMAL + NETWORK_CHAT_LINE_SPACING) + 4;
114 _chatmessage_backup = ReallocT(_chatmessage_backup, _chatmsg_box.width * _chatmsg_box.height * BlitterFactory::GetCurrentBlitter()->GetBytesPerPixel());
115 }
116
118 void NetworkInitChatMessage()
119 {
120 MAX_CHAT_MESSAGES = _settings_client.gui.network_chat_box_height;
121
122 _chatmsg_list = ReallocT(_chatmsg_list, _settings_client.gui.network_chat_box_height);
123 _chatmsg_box.x = 10;
124 _chatmsg_box.width = _settings_client.gui.network_chat_box_width_pct * _screen.width / 100;
125 NetworkReInitChatBoxSize();
126 _chatmessage_visible = false;
127
128 for (uint i = 0; i < MAX_CHAT_MESSAGES; i++) {
129 _chatmsg_list[i].message[0] = '\0';
130 }
131 }
132
134 void NetworkUndrawChatMessage()
135 {
136 /* Sometimes we also need to hide the cursor
137 * This is because both textmessage and the cursor take a shot of the
138 * screen before drawing.
139 * Now the textmessage takes his shot and paints his data before the cursor
140 * does, so in the shot of the cursor is the screen-data of the textmessage
141 * included when the cursor hangs somewhere over the textmessage. To
142 * avoid wrong repaints, we undraw the cursor in that case, and everything
143 * looks nicely ;)
144 * (and now hope this story above makes sense to you ;))
145 */
146 if (_cursor.visible &&
147 _cursor.draw_pos.x + _cursor.draw_size.x >= _chatmsg_box.x &&
148 _cursor.draw_pos.x <= _chatmsg_box.x + _chatmsg_box.width &&
149 _cursor.draw_pos.y + _cursor.draw_size.y >= _screen.height - _chatmsg_box.y - _chatmsg_box.height &&
150 _cursor.draw_pos.y <= _screen.height - _chatmsg_box.y) {
151 UndrawMouseCursor();
152 }
153
154 if (_chatmessage_visible) {
155 Blitter *blitter = BlitterFactory::GetCurrentBlitter();
156 int x = _chatmsg_box.x;
157 int y = _screen.height - _chatmsg_box.y - _chatmsg_box.height;
158 int width = _chatmsg_box.width;
159 int height = _chatmsg_box.height;
160 if (y < 0) {
161 height = max(height + y, min(_chatmsg_box.height, _screen.height));
162 y = 0;
163 }
164 if (x + width >= _screen.width) {
165 width = _screen.width - x;
166 }
167 if (width <= 0 || height <= 0) return;
168
169 _chatmessage_visible = false;
170 /* Put our 'shot' back to the screen */
171 blitter->CopyFromBuffer(blitter->MoveTo(_screen.dst_ptr, x, y), _chatmessage_backup, width, height);
172 /* And make sure it is updated next time */
173 VideoDriver::GetInstance()->MakeDirty(x, y, width, height);
174
175 _chatmessage_dirty = true;
176 }
177 }
178
180 void NetworkChatMessageLoop()
181 {
182 for (uint i = 0; i < MAX_CHAT_MESSAGES; i++) {
183 ChatMessage *cmsg = &_chatmsg_list[i];
184 if (cmsg->message[0] == '\0') continue;
185
186 /* Message has expired, remove from the list */
187 if (cmsg->remove_time < _realtime_tick) {
188 /* Move the remaining messages over the current message */
189 if (i != MAX_CHAT_MESSAGES - 1) memmove(cmsg, cmsg + 1, sizeof(*cmsg) * (MAX_CHAT_MESSAGES - i - 1));
190
191 /* Mark the last item as empty */
192 _chatmsg_list[MAX_CHAT_MESSAGES - 1].message[0] = '\0';
193 _chatmessage_dirty = true;
194
195 /* Go one item back, because we moved the array 1 to the left */
196 i--;
197 }
198 }
199 }
200
202 void NetworkDrawChatMessage()
203 {
204 Blitter *blitter = BlitterFactory::GetCurrentBlitter();
205 if (!_chatmessage_dirty) return;
206
207 /* First undraw if needed */
208 NetworkUndrawChatMessage();
209
210 if (_iconsole_mode == ICONSOLE_FULL) return;
211
212 /* Check if we have anything to draw at all */
213 uint count = GetChatMessageCount();
214 if (count == 0) return;
215
216 int x = _chatmsg_box.x;
217 int y = _screen.height - _chatmsg_box.y - _chatmsg_box.height;
218 int width = _chatmsg_box.width;
219 int height = _chatmsg_box.height;
220 if (y < 0) {
221 height = max(height + y, min(_chatmsg_box.height, _screen.height));
222 y = 0;
223 }
224 if (x + width >= _screen.width) {
225 width = _screen.width - x;
226 }
227 if (width <= 0 || height <= 0) return;
228
229 assert(blitter->BufferSize(width, height) <= (int)(_chatmsg_box.width * _chatmsg_box.height * blitter->GetBytesPerPixel()));
230
231 /* Make a copy of the screen as it is before painting (for undraw) */
232 blitter->CopyToBuffer(blitter->MoveTo(_screen.dst_ptr, x, y), _chatmessage_backup, width, height);
233
234 _cur_dpi = &_screen; // switch to _screen painting
235
236 int string_height = 0;
237 for (uint i = 0; i < count; i++) {
238 SetDParamStr(0, _chatmsg_list[i].message);
239 string_height += GetStringLineCount(STR_JUST_RAW_STRING, width - 1) * FONT_HEIGHT_NORMAL + NETWORK_CHAT_LINE_SPACING;
240 }
241
242 string_height = min(string_height, MAX_CHAT_MESSAGES * (FONT_HEIGHT_NORMAL + NETWORK_CHAT_LINE_SPACING));
243
244 int top = _screen.height - _chatmsg_box.y - string_height - 2;
245 int bottom = _screen.height - _chatmsg_box.y - 2;
246 /* Paint a half-transparent box behind the chat messages */
247 GfxFillRect(_chatmsg_box.x, top - 2, _chatmsg_box.x + _chatmsg_box.width - 1, bottom,
248 PALETTE_TO_TRANSPARENT, FILLRECT_RECOLOUR // black, but with some alpha for background
249 );
250
251 /* Paint the chat messages starting with the lowest at the bottom */
252 int ypos = bottom - 2;
253
254 for (int i = count - 1; i >= 0; i--) {
255 ypos = DrawStringMultiLine(_chatmsg_box.x + 3, _chatmsg_box.x + _chatmsg_box.width - 1, top, ypos, _chatmsg_list[i].message, _chatmsg_list[i].colour, SA_LEFT | SA_BOTTOM | SA_FORCE) - NETWORK_CHAT_LINE_SPACING;
256 if (ypos < top) break;
257 }
258
259 /* Make sure the data is updated next flush */
260 VideoDriver::GetInstance()->MakeDirty(x, y, width, height);
261
262 _chatmessage_visible = true;
263 _chatmessage_dirty = false;
264 }
265
272 static void SendChat(const char *buf, DestType type, int dest)
273 {
274 if (StrEmpty(buf)) return;
275 if (!_network_server) {
276 MyClient::SendChat((NetworkAction)(NETWORK_ACTION_CHAT + type), type, dest, buf, 0);
277 } else {
278 NetworkServerSendChat((NetworkAction)(NETWORK_ACTION_CHAT + type), type, dest, buf, CLIENT_ID_SERVER);
279 }
280 }
281
283 struct NetworkChatWindow : public Window {
284 DestType dtype;
285 StringID dest_string;
286 int dest;
287 QueryString message_editbox;
288
295 NetworkChatWindow(WindowDesc *desc, DestType type, int dest) : Window(desc), message_editbox(NETWORK_CHAT_LENGTH)
296 {
297 this->dtype = type;
298 this->dest = dest;
299 this->querystrings[WID_NC_TEXTBOX] = &this->message_editbox;
300 this->message_editbox.cancel_button = WID_NC_CLOSE;
301 this->message_editbox.ok_button = WID_NC_SENDBUTTON;
302
303 static const StringID chat_captions[] = {
304 STR_NETWORK_CHAT_ALL_CAPTION,
305 STR_NETWORK_CHAT_COMPANY_CAPTION,
306 STR_NETWORK_CHAT_CLIENT_CAPTION
307 };
308 assert((uint)this->dtype < lengthof(chat_captions));
309 this->dest_string = chat_captions[this->dtype];
310
311 this->InitNested(type);
312
313 this->SetFocusedWidget(WID_NC_TEXTBOX);
314 InvalidateWindowData(WC_NEWS_WINDOW, 0, this->height);
315 _chat_tab_completion_active = false;
316
317 PositionNetworkChatWindow(this);
318 }
319
320 ~NetworkChatWindow()
321 {
322 InvalidateWindowData(WC_NEWS_WINDOW, 0, 0);
323 }
324
325 virtual void FindWindowPlacementAndResize(int def_width, int def_height)
326 {
327 Window::FindWindowPlacementAndResize(_toolbar_width, def_height);
328 }
329
336 const char *ChatTabCompletionNextItem(uint *item)
337 {
338 static char chat_tab_temp_buffer[64];
339
340 /* First, try clients */
341 if (*item < MAX_CLIENT_SLOTS) {
342 /* Skip inactive clients */
343 NetworkClientInfo *ci;
344 FOR_ALL_CLIENT_INFOS_FROM(ci, *item) {
345 *item = ci->index;
346 return ci->client_name;
347 }
348 *item = MAX_CLIENT_SLOTS;
349 }
350
351 /* Then, try townnames
352 * Not that the following assumes all town indices are adjacent, ie no
353 * towns have been deleted. */
354 if (*item < (uint)MAX_CLIENT_SLOTS + Town::GetPoolSize()) {
355 const Town *t;
356
357 FOR_ALL_TOWNS_FROM(t, *item - MAX_CLIENT_SLOTS) {
358 /* Get the town-name via the string-system */
359 SetDParam(0, t->index);
360 GetString(chat_tab_temp_buffer, STR_TOWN_NAME, lastof(chat_tab_temp_buffer));
361 return &chat_tab_temp_buffer[0];
362 }
363 }
364
365 return NULL;
366 }
367
373 static char *ChatTabCompletionFindText(char *buf)
374 {
375 char *p = strrchr(buf, ' ');
376 if (p == NULL) return buf;
377
378 *p = '\0';
379 return p + 1;
380 }
381
385 void ChatTabCompletion()
386 {
387 static char _chat_tab_completion_buf[NETWORK_CHAT_LENGTH];
388 assert(this->message_editbox.text.max_bytes == lengthof(_chat_tab_completion_buf));
389
390 Textbuf *tb = &this->message_editbox.text;
391 size_t len, tb_len;
392 uint item;
393 char *tb_buf, *pre_buf;
394 const char *cur_name;
395 bool second_scan = false;
396
397 item = 0;
398
399 /* Copy the buffer so we can modify it without damaging the real data */
400 pre_buf = (_chat_tab_completion_active) ? stredup(_chat_tab_completion_buf) : stredup(tb->buf);
401
402 tb_buf = ChatTabCompletionFindText(pre_buf);
403 tb_len = strlen(tb_buf);
404
405 while ((cur_name = ChatTabCompletionNextItem(&item)) != NULL) {
406 item++;
407
408 if (_chat_tab_completion_active) {
409 /* We are pressing TAB again on the same name, is there another name
410 * that starts with this? */
411 if (!second_scan) {
412 size_t offset;
413 size_t length;
414
415 /* If we are completing at the begin of the line, skip the ': ' we added */
416 if (tb_buf == pre_buf) {
417 offset = 0;
418 length = (tb->bytes - 1) - 2;
419 } else {
420 /* Else, find the place we are completing at */
421 offset = strlen(pre_buf) + 1;
422 length = (tb->bytes - 1) - offset;
423 }
424
425 /* Compare if we have a match */
426 if (strlen(cur_name) == length && strncmp(cur_name, tb->buf + offset, length) == 0) second_scan = true;
427
428 continue;
429 }
430
431 /* Now any match we make on _chat_tab_completion_buf after this, is perfect */
432 }
433
434 len = strlen(cur_name);
435 if (tb_len < len && strncasecmp(cur_name, tb_buf, tb_len) == 0) {
436 /* Save the data it was before completion */
437 if (!second_scan) seprintf(_chat_tab_completion_buf, lastof(_chat_tab_completion_buf), "%s", tb->buf);
438 _chat_tab_completion_active = true;
439
440 /* Change to the found name. Add ': ' if we are at the start of the line (pretty) */
441 if (pre_buf == tb_buf) {
442 this->message_editbox.text.Print("%s: ", cur_name);
443 } else {
444 this->message_editbox.text.Print("%s %s", pre_buf, cur_name);
445 }
446
447 this->SetDirty();
448 free(pre_buf);
449 return;
450 }
451 }
452
453 if (second_scan) {
454 /* We walked all possibilities, and the user presses tab again.. revert to original text */
455 this->message_editbox.text.Assign(_chat_tab_completion_buf);
456 _chat_tab_completion_active = false;
457
458 this->SetDirty();
459 }
460 free(pre_buf);
461 }
462
463 virtual Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number)
464 {
465 Point pt = { 0, _screen.height - sm_height - FindWindowById(WC_STATUS_BAR, 0)->height };
466 return pt;
467 }
468
469 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
470 {
471 if (widget != WID_NC_DESTINATION) return;
472
473 if (this->dtype == DESTTYPE_CLIENT) {
474 SetDParamStr(0, NetworkClientInfo::GetByClientID((ClientID)this->dest)->client_name);
475 }
476 Dimension d = GetStringBoundingBox(this->dest_string);
477 d.width += WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
478 d.height += WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
479 *size = maxdim(*size, d);
480 }
481
482 virtual void DrawWidget(const Rect &r, int widget) const
483 {
484 if (widget != WID_NC_DESTINATION) return;
485
486 if (this->dtype == DESTTYPE_CLIENT) {
487 SetDParamStr(0, NetworkClientInfo::GetByClientID((ClientID)this->dest)->client_name);
488 }
489 DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, this->dest_string, TC_BLACK, SA_RIGHT);
490 }
491
492 virtual void OnClick(Point pt, int widget, int click_count)
493 {
494 switch (widget) {
495 case WID_NC_SENDBUTTON: /* Send */
496 SendChat(this->message_editbox.text.buf, this->dtype, this->dest);
497 FALLTHROUGH;
498
499 case WID_NC_CLOSE: /* Cancel */
500 delete this;
501 break;
502 }
503 }
504
505 virtual EventState OnKeyPress(WChar key, uint16 keycode)
506 {
507 EventState state = ES_NOT_HANDLED;
508 if (keycode == WKC_TAB) {
509 ChatTabCompletion();
510 state = ES_HANDLED;
511 }
512 return state;
513 }
514
515 virtual void OnEditboxChanged(int wid)
516 {
517 _chat_tab_completion_active = false;
518 }
519
525 virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
526 {
527 if (data == this->dest) delete this;
528 }
529 };
530
532 static const NWidgetPart _nested_chat_window_widgets[] = {
533 NWidget(NWID_HORIZONTAL),
534 NWidget(WWT_CLOSEBOX, COLOUR_GREY, WID_NC_CLOSE),
535 NWidget(WWT_PANEL, COLOUR_GREY, WID_NC_BACKGROUND),
536 NWidget(NWID_HORIZONTAL),
537 NWidget(WWT_TEXT, COLOUR_GREY, WID_NC_DESTINATION), SetMinimalSize(62, 12), SetPadding(1, 0, 1, 0), SetDataTip(STR_NULL, STR_NULL),
538 NWidget(WWT_EDITBOX, COLOUR_GREY, WID_NC_TEXTBOX), SetMinimalSize(100, 12), SetPadding(1, 0, 1, 0), SetResize(1, 0),
539 SetDataTip(STR_NETWORK_CHAT_OSKTITLE, STR_NULL),
540 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_NC_SENDBUTTON), SetMinimalSize(62, 12), SetPadding(1, 0, 1, 0), SetDataTip(STR_NETWORK_CHAT_SEND, STR_NULL),
541 EndContainer(),
542 EndContainer(),
543 EndContainer(),
544 };
545
547 static WindowDesc _chat_window_desc(
548 WDP_MANUAL, NULL, 0, 0,
549 WC_SEND_NETWORK_MSG, WC_NONE,
550 0,
551 _nested_chat_window_widgets, lengthof(_nested_chat_window_widgets)
552 );
553
554
560 void ShowNetworkChatQueryWindow(DestType type, int dest)
561 {
562 DeleteWindowByClass(WC_SEND_NETWORK_MSG);
563 new NetworkChatWindow(&_chat_window_desc, type, dest);
564 }
565
566 #endif /* ENABLE_NETWORK */
EventState
EventState
State of handling an event.
Definition: window_type.h:701
VideoDriver::MakeDirty
virtual void MakeDirty(int left, int top, int width, int height)=0
Mark a particular area dirty.
ChatMessage
Container for a message.
Definition: network_chat_gui.cpp:44
WID_NC_DESTINATION
Destination.
Definition: network_chat_widget.h:19
NetworkChatWindow
Window to enter the chat message in.
Definition: network_chat_gui.cpp:283
PALETTE_TO_TRANSPARENT
static const PaletteID PALETTE_TO_TRANSPARENT
This sets the sprite to transparent.
Definition: sprites.h:1566
NetworkClientInfo
Container for all information known about a client.
Definition: network_base.h:27
SetResize
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:930
_realtime_tick
uint32 _realtime_tick
The real time in the game.
Definition: debug.cpp:48
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:112
WindowDesc
High level window description.
Definition: window_gui.h:168
ChatMessage::colour
TextColour colour
The colour of the message.
Definition: network_chat_gui.cpp:46
GUISettings::network_chat_box_width_pct
uint16 network_chat_box_width_pct
width of the chat box in percent
Definition: settings_type.h:148
seprintf
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
Definition: string.cpp:398
WID_NC_CLOSE
Close button.
Definition: network_chat_widget.h:17
WD_FRAMERECT_TOP
Offset at top to draw the frame rectangular area.
Definition: window_gui.h:64
NetworkReInitChatBoxSize
void NetworkReInitChatBoxSize()
Initialize all font-dependent chat box sizes.
Definition: network_chat_gui.cpp:110
NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:75
FindWindowById
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition: window.cpp:1105
ES_NOT_HANDLED
The passed event is not handled.
Definition: window_type.h:703
NetworkChatWindow::OnClick
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
Definition: network_chat_gui.cpp:492
vseprintf
int CDECL vseprintf(char *str, const char *last, const char *format, va_list ap)
Safer implementation of vsnprintf; same as vsnprintf except:
Definition: string.cpp:50
WWT_EDITBOX
a textbox for typing
Definition: widget_type.h:71
NetworkChatWindow::OnInitialPosition
virtual Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number)
Compute the initial position of the window.
Definition: network_chat_gui.cpp:463
network_client.h
Client part of the network protocol.
NetworkChatWindow::OnEditboxChanged
virtual void OnEditboxChanged(int wid)
The text in an editbox has been edited.
Definition: network_chat_gui.cpp:515
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:147
Textbuf::Print
void CDECL Print(const char *format,...) WARN_FORMAT(2
Print a formatted string into the textbuffer.
Definition: textbuf.cpp:418
WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:69
DRAW_STRING_BUFFER
static const int DRAW_STRING_BUFFER
Size of the buffer used for drawing strings.
Definition: gfx_func.h:87
DESTTYPE_CLIENT
Send message/notice to only a certain client (Private)
Definition: network_type.h:85
NetworkChatWindow::ChatTabCompletion
void ChatTabCompletion()
See if we can auto-complete the current text of the user.
Definition: network_chat_gui.cpp:385
lastof
#define lastof(x)
Get the last element of an fixed size array.
Definition: depend.cpp:50
Textbuf
Helper/buffer for input fields.
Definition: textbuf_type.h:32
network_base.h
Base core network types and some helper functions to access them.
Blitter
How all blitters should look like.
Definition: base.hpp:30
Textbuf::bytes
uint16 bytes
the current size of the string in bytes (including terminating &#39;\0&#39;)
Definition: textbuf_type.h:37
max
static T max(const T a, const T b)
Returns the maximum of two values.
Definition: math_func.hpp:26
CursorVars::visible
bool visible
cursor is visible
Definition: gfx_type.h:141
Blitter::GetBytesPerPixel
virtual int GetBytesPerPixel()=0
Get how many bytes are needed to store a pixel.
WWT_TEXT
Pure simple text.
Definition: widget_type.h:58
CLIENT_ID_SERVER
Servers always have this ID.
Definition: network_type.h:45
NetworkChatWindow::NetworkChatWindow
NetworkChatWindow(WindowDesc *desc, DestType type, int dest)
Create a chat input window.
Definition: network_chat_gui.cpp:295
ICONSOLE_FULL
In-game console is closed.
Definition: console_type.h:19
SA_FORCE
Force the alignment, i.e. don&#39;t swap for RTL languages.
Definition: gfx_func.h:110
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:910
Window
Data structure for an opened window.
Definition: window_gui.h:271
CursorVars::draw_size
Point draw_size
position and size bounding-box for drawing
Definition: gfx_type.h:135
SetPadding
static NWidgetPart SetPadding(uint8 top, uint8 right, uint8 bottom, uint8 left)
Widget part function for setting additional space around a widget.
Definition: widget_type.h:1046
SetDParamStr
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Definition: strings.cpp:279
NetworkChatMessageLoop
void NetworkChatMessageLoop()
Check if a message is expired.
Definition: network_chat_gui.cpp:180
NetworkDrawChatMessage
void NetworkDrawChatMessage()
Draw the chat message-box.
Definition: network_chat_gui.cpp:202
GUISettings::network_chat_box_height
uint8 network_chat_box_height
height of the chat box in lines
Definition: settings_type.h:149
Pool::PoolItem<&_town_pool >::GetPoolSize
static size_t GetPoolSize()
Returns first unused index.
Definition: pool_type.hpp:267
NetworkClientInfo::client_name
char client_name[NETWORK_CLIENT_NAME_LENGTH]
Name of the client.
Definition: network_base.h:29
WC_SEND_NETWORK_MSG
Chatbox; Window numbers:
Definition: window_type.h:493
NetworkChatWindow::DrawWidget
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
Definition: network_chat_gui.cpp:482
QueryString::ok_button
int ok_button
Widget button of parent window to simulate when pressing OK in OSK.
Definition: querystring_gui.h:29
GetChatMessageCount
static uint GetChatMessageCount()
Count the chat messages.
Definition: network_chat_gui.cpp:68
WID_NC_TEXTBOX
Textbox.
Definition: network_chat_widget.h:20
Utf8TrimString
size_t Utf8TrimString(char *s, size_t maxlen)
Properly terminate an UTF8 string to some maximum length.
Definition: string.cpp:511
NetworkChatWindow::ChatTabCompletionFindText
static char * ChatTabCompletionFindText(char *buf)
Find what text to complete.
Definition: network_chat_gui.cpp:373
FONT_HEIGHT_NORMAL
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:180
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1014
QueryString
Data stored about a string that can be modified in the GUI.
Definition: querystring_gui.h:22
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:76
FILLRECT_RECOLOUR
Apply a recolour sprite to the screen content.
Definition: gfx_type.h:285
SetMinimalSize
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:947
_chatmessage_dirty
static bool _chatmessage_dirty
Does the chat message need repainting?
Definition: network_chat_gui.cpp:52
SA_BOTTOM
Bottom align the text.
Definition: gfx_func.h:105
FOR_ALL_CLIENT_INFOS_FROM
#define FOR_ALL_CLIENT_INFOS_FROM(var, start)
Iterate over all the clients from a given index.
Definition: network_base.h:49
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:247
WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:104
WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:50
PositionNetworkChatWindow
int PositionNetworkChatWindow(Window *w)
(Re)position network chat window at the screen.
Definition: window.cpp:3429
NetworkChatWindow::dest
int dest
The identifier of the destination.
Definition: network_chat_gui.cpp:286
stredup
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
Definition: string.cpp:126
ReallocT
static T * ReallocT(T *t_ptr, size_t num_elements)
Simplified reallocation function that allocates the specified number of elements of the given type...
Definition: alloc_func.hpp:113
_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:61
NETWORK_CHAT_LENGTH
static const uint NETWORK_CHAT_LENGTH
The maximum length of a chat message, in bytes including &#39;\0&#39;.
Definition: config.h:52
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new &#39;real&#39; widget.
Definition: widget_type.h:1114
WD_FRAMERECT_BOTTOM
Offset at bottom to draw the frame rectangular area.
Definition: window_gui.h:65
_chat_tab_completion_active
static bool _chat_tab_completion_active
Whether tab completion is active.
Definition: network_chat_gui.cpp:54
DrawString
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.
Definition: gfx.cpp:499
NetworkChatWindow::ChatTabCompletionNextItem
const char * ChatTabCompletionNextItem(uint *item)
Find the next item of the list of things that can be auto-completed.
Definition: network_chat_gui.cpp:336
network.h
Basic functions/variables used all over the place.
_chatmsg_list
static ChatMessage * _chatmsg_list
The actual chat message list.
Definition: network_chat_gui.cpp:51
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: depend.cpp:42
BlitterFactory::GetCurrentBlitter
static Blitter * GetCurrentBlitter()
Get the current active blitter (always set by calling SelectBlitter).
Definition: factory.hpp:147
min
static T min(const T a, const T b)
Returns the minimum of two values.
Definition: math_func.hpp:42
NetworkChatWindow::OnInvalidateData
virtual void OnInvalidateData(int data=0, bool gui_scope=true)
Some data on this window has become invalid.
Definition: network_chat_gui.cpp:525
QueryString::cancel_button
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
Definition: querystring_gui.h:30
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:18
DeleteWindowByClass
void DeleteWindowByClass(WindowClass cls)
Delete all windows of a given class.
Definition: window.cpp:1150
Blitter::CopyToBuffer
virtual void CopyToBuffer(const void *video, void *dst, int width, int height)=0
Copy from the screen to a buffer.
Textbuf::Assign
void Assign(StringID string)
Render a string into the textbuffer.
Definition: textbuf.cpp:399
NetworkUndrawChatMessage
void NetworkUndrawChatMessage()
Hide the chatbox.
Definition: network_chat_gui.cpp:134
GetStringBoundingBox
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:699
ChatMessage::remove_time
uint32 remove_time
The time to remove the message.
Definition: network_chat_gui.cpp:47
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition: geometry_func.cpp:24
WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:40
NetworkInitChatMessage
void NetworkInitChatMessage()
Initialize all buffers of the chat visualisation.
Definition: network_chat_gui.cpp:118
Blitter::BufferSize
virtual int BufferSize(int width, int height)=0
Calculate how much memory there is needed for an image of this size in the video-buffer.
Textbuf::buf
char *const buf
buffer in which text is saved
Definition: textbuf_type.h:34
WID_NC_BACKGROUND
Background of the window.
Definition: network_chat_widget.h:18
NetworkServerSendChat
void NetworkServerSendChat(NetworkAction action, DestType type, int dest, const char *msg, ClientID from_id, int64 data=0, bool from_admin=false)
Send an actual chat message.
Definition: network_server.cpp:1268
NetworkChatWindow::dest_string
StringID dest_string
String representation of the destination.
Definition: network_chat_gui.cpp:285
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:561
Textbuf::max_bytes
uint16 max_bytes
the maximum size of the buffer in bytes (including terminating &#39;\0&#39;)
Definition: textbuf_type.h:35
StrEmpty
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:59
GetStringLineCount
int GetStringLineCount(StringID str, int maxw)
Calculates number of lines of string.
Definition: gfx.cpp:572
PointDimension
Specification of a rectangle with an absolute top-left coordinate and a (relative) width/height...
Definition: geometry_type.hpp:51
_toolbar_width
uint _toolbar_width
Width of the toolbar, shared by statusbar.
Definition: toolbar_gui.cpp:61
VideoDriver::GetInstance
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
Definition: video_driver.hpp:98
Blitter::CopyFromBuffer
virtual void CopyFromBuffer(void *video, const void *src, int width, int height)=0
Copy from a buffer to the screen.
_chatmessage_backup
static uint8 * _chatmessage_backup
Backup in case text is moved.
Definition: network_chat_gui.cpp:62
ClientID
ClientID
&#39;Unique&#39; identifier to be given to clients
Definition: network_type.h:43
EndContainer
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME, WWT_INSET, or WWT_PANEL).
Definition: widget_type.h:999
NetworkChatWindow::message_editbox
QueryString message_editbox
Message editbox.
Definition: network_chat_gui.cpp:287
strecpy
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
Definition: depend.cpp:68
Town
Town data structure.
Definition: town.h:55
NetworkAddChatMessage
void CDECL NetworkAddChatMessage(TextColour colour, uint duration, const char *message,...)
Add a text message to the &#39;chat window&#39; to be shown.
Definition: network_chat_gui.cpp:84
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...
WC_STATUS_BAR
Statusbar (at the bottom of your screen); Window numbers:
Definition: window_type.h:59
_network_server
bool _network_server
network-server is active
Definition: network.cpp:57
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:28
NetworkChatWindow::OnKeyPress
virtual EventState OnKeyPress(WChar key, uint16 keycode)
A key has been pressed.
Definition: network_chat_gui.cpp:505
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:27
SendChat
static void SendChat(const char *buf, DestType type, int dest)
Send an actual chat message.
Definition: network_chat_gui.cpp:272
TC_IS_PALETTE_COLOUR
Colour value is already a real palette colour index, not an index of a StringColour.
Definition: gfx_type.h:270
free
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: depend.cpp:114
Window::FindWindowPlacementAndResize
virtual void FindWindowPlacementAndResize(int def_width, int def_height)
Resize window towards the default size.
Definition: window.cpp:1498
WD_FRAMERECT_RIGHT
Offset at right to draw the frame rectangular area.
Definition: window_gui.h:63
NETWORK_NAME_LENGTH
static const uint NETWORK_NAME_LENGTH
The maximum length of the server name and map name, in bytes including &#39;\0&#39;.
Definition: config.h:42
NetworkChatWindow::UpdateWidgetSize
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
Update size and resize step of a widget in the window.
Definition: network_chat_gui.cpp:469
_nested_chat_window_widgets
static const NWidgetPart _nested_chat_window_widgets[]
The widgets of the chat window.
Definition: network_chat_gui.cpp:532
MAX_CHAT_MESSAGES
static uint MAX_CHAT_MESSAGES
The limit of chat messages to show.
Definition: network_chat_gui.cpp:55
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:40
ES_HANDLED
The passed event is handled.
Definition: window_type.h:702
ChatMessage::message
char message[DRAW_STRING_BUFFER]
The action message.
Definition: network_chat_gui.cpp:45
SA_RIGHT
Right align the text (must be a single bit).
Definition: gfx_func.h:100
SA_LEFT
Left align the text.
Definition: gfx_func.h:98
_chat_window_desc
static WindowDesc _chat_window_desc(WDP_MANUAL, NULL, 0, 0, WC_SEND_NETWORK_MSG, WC_NONE, 0, _nested_chat_window_widgets, lengthof(_nested_chat_window_widgets))
The description of the chat window.
NETWORK_CHAT_LINE_SPACING
static const uint NETWORK_CHAT_LINE_SPACING
Spacing between chat lines.
Definition: network_chat_gui.cpp:41
NetworkClientInfo::GetByClientID
static NetworkClientInfo * GetByClientID(ClientID client_id)
Return the CI given it&#39;s client-identifier.
Definition: network.cpp:126
_chatmessage_visible
static bool _chatmessage_visible
Is a chat message visible.
Definition: network_chat_gui.cpp:53
NetworkChatWindow::FindWindowPlacementAndResize
virtual void FindWindowPlacementAndResize(int def_width, int def_height)
Resize window towards the default size.
Definition: network_chat_gui.cpp:325
WDP_MANUAL
Manually align the window (so no automatic location finding)
Definition: window_gui.h:155
ClientNetworkGameSocketHandler::SendChat
static NetworkRecvStatus SendChat(NetworkAction action, DestType type, int dest, const char *msg, int64 data)
Send a chat-packet over the network.
Definition: network_client.cpp:419
WChar
uint32 WChar
Type for wide characters, i.e.
Definition: string_type.h:35
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:34
WD_FRAMERECT_LEFT
Offset at left to draw the frame rectangular area.
Definition: window_gui.h:62
NetworkChatWindow::dtype
DestType dtype
The type of destination.
Definition: network_chat_gui.cpp:284
DestType
DestType
Destination of our chat messages.
Definition: network_type.h:82
NetworkAction
NetworkAction
Actions that can be used for NetworkTextMessage.
Definition: network_type.h:89
ShowNetworkChatQueryWindow
void ShowNetworkChatQueryWindow(DestType type, int dest)
Show the chat window.
Definition: network_chat_gui.cpp:560
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:3220
assert_compile
assert_compile((int) DRAW_STRING_BUFFER >=(int) NETWORK_CHAT_LENGTH+NETWORK_NAME_LENGTH+40)
The draw buffer must be able to contain the chat message, client name and the "[All]" message...
Window::height
int height
Height of the window (number of pixels down in y direction)
Definition: window_gui.h:315
WC_NEWS_WINDOW
News window; Window numbers:
Definition: window_type.h:243
DrawStringMultiLine
int DrawStringMultiLine(int left, int right, int top, int bottom, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Definition: gfx.cpp:620
WID_NC_SENDBUTTON
Send button.
Definition: network_chat_widget.h:21
SetDParam
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:201