OpenTTD Source  13.2.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 "network.h"
22 #include "network_client.h"
23 #include "network_base.h"
24 
25 #include "../widgets/network_chat_widget.h"
26 
27 #include "table/strings.h"
28 
29 #include <stdarg.h> /* va_list */
30 #include <deque>
31 
32 #include "../safeguards.h"
33 
36 static_assert((int)DRAW_STRING_BUFFER >= (int)NETWORK_CHAT_LENGTH + NETWORK_NAME_LENGTH + 40);
37 
39 static const uint NETWORK_CHAT_LINE_SPACING = 3;
40 
42 struct ChatMessage {
43  std::string message;
45  std::chrono::steady_clock::time_point remove_time;
46 };
47 
48 /* used for chat window */
49 static std::deque<ChatMessage> _chatmsg_list;
50 static bool _chatmessage_dirty = false;
51 static bool _chatmessage_visible = false;
53 static uint MAX_CHAT_MESSAGES = 0;
54 
59 static std::chrono::steady_clock::time_point _chatmessage_dirty_time;
60 
66 static uint8 *_chatmessage_backup = nullptr;
67 
73 static inline bool HaveChatMessages(bool show_all)
74 {
75  if (show_all) return _chatmsg_list.size() != 0;
76 
77  auto now = std::chrono::steady_clock::now();
78  for (auto &cmsg : _chatmsg_list) {
79  if (cmsg.remove_time >= now) return true;
80  }
81 
82  return false;
83 }
84 
91 void CDECL NetworkAddChatMessage(TextColour colour, uint duration, const std::string &message)
92 {
93  if (_chatmsg_list.size() == MAX_CHAT_MESSAGES) {
94  _chatmsg_list.pop_back();
95  }
96 
97  ChatMessage *cmsg = &_chatmsg_list.emplace_front();
98  cmsg->message = message;
99  cmsg->colour = colour;
100  cmsg->remove_time = std::chrono::steady_clock::now() + std::chrono::seconds(duration);
101 
102  _chatmessage_dirty_time = std::chrono::steady_clock::now();
103  _chatmessage_dirty = true;
104 }
105 
108 {
112 }
113 
116 {
118 
119  _chatmsg_list.clear();
120  _chatmsg_box.x = ScaleGUITrad(10);
121  _chatmsg_box.width = _settings_client.gui.network_chat_box_width_pct * _screen.width / 100;
123  _chatmessage_visible = false;
124 }
125 
128 {
129  /* Sometimes we also need to hide the cursor
130  * This is because both textmessage and the cursor take a shot of the
131  * screen before drawing.
132  * Now the textmessage takes its shot and paints its data before the cursor
133  * does, so in the shot of the cursor is the screen-data of the textmessage
134  * included when the cursor hangs somewhere over the textmessage. To
135  * avoid wrong repaints, we undraw the cursor in that case, and everything
136  * looks nicely ;)
137  * (and now hope this story above makes sense to you ;))
138  */
139  if (_cursor.visible &&
140  _cursor.draw_pos.x + _cursor.draw_size.x >= _chatmsg_box.x &&
141  _cursor.draw_pos.x <= _chatmsg_box.x + _chatmsg_box.width &&
142  _cursor.draw_pos.y + _cursor.draw_size.y >= _screen.height - _chatmsg_box.y - _chatmsg_box.height &&
143  _cursor.draw_pos.y <= _screen.height - _chatmsg_box.y) {
144  UndrawMouseCursor();
145  }
146 
147  if (_chatmessage_visible) {
149  int x = _chatmsg_box.x;
150  int y = _screen.height - _chatmsg_box.y - _chatmsg_box.height;
151  int width = _chatmsg_box.width;
152  int height = _chatmsg_box.height;
153  if (y < 0) {
154  height = std::max(height + y, std::min(_chatmsg_box.height, _screen.height));
155  y = 0;
156  }
157  if (x + width >= _screen.width) {
158  width = _screen.width - x;
159  }
160  if (width <= 0 || height <= 0) return;
161 
162  _chatmessage_visible = false;
163  /* Put our 'shot' back to the screen */
164  blitter->CopyFromBuffer(blitter->MoveTo(_screen.dst_ptr, x, y), _chatmessage_backup, width, height);
165  /* And make sure it is updated next time */
166  VideoDriver::GetInstance()->MakeDirty(x, y, width, height);
167 
168  _chatmessage_dirty_time = std::chrono::steady_clock::now();
169  _chatmessage_dirty = true;
170  }
171 }
172 
175 {
176  auto now = std::chrono::steady_clock::now();
177  for (auto &cmsg : _chatmsg_list) {
178  /* Message has expired, remove from the list */
179  if (now > cmsg.remove_time && _chatmessage_dirty_time < cmsg.remove_time) {
181  _chatmessage_dirty = true;
182  break;
183  }
184  }
185 }
186 
189 {
191  if (!_chatmessage_dirty) return;
192 
194  bool show_all = (w != nullptr);
195 
196  /* First undraw if needed */
198 
199  if (_iconsole_mode == ICONSOLE_FULL) return;
200 
201  /* Check if we have anything to draw at all */
202  if (!HaveChatMessages(show_all)) return;
203 
204  int x = _chatmsg_box.x;
205  int y = _screen.height - _chatmsg_box.y - _chatmsg_box.height;
206  int width = _chatmsg_box.width;
207  int height = _chatmsg_box.height;
208  if (y < 0) {
209  height = std::max(height + y, std::min(_chatmsg_box.height, _screen.height));
210  y = 0;
211  }
212  if (x + width >= _screen.width) {
213  width = _screen.width - x;
214  }
215  if (width <= 0 || height <= 0) return;
216 
217  assert(blitter->BufferSize(width, height) <= (int)(_chatmsg_box.width * _chatmsg_box.height * blitter->GetBytesPerPixel()));
218 
219  /* Make a copy of the screen as it is before painting (for undraw) */
220  blitter->CopyToBuffer(blitter->MoveTo(_screen.dst_ptr, x, y), _chatmessage_backup, width, height);
221 
222  _cur_dpi = &_screen; // switch to _screen painting
223 
224  auto now = std::chrono::steady_clock::now();
225  int string_height = 0;
226  for (auto &cmsg : _chatmsg_list) {
227  if (!show_all && cmsg.remove_time < now) continue;
228  SetDParamStr(0, cmsg.message);
229  string_height += GetStringLineCount(STR_JUST_RAW_STRING, width - 1) * FONT_HEIGHT_NORMAL + NETWORK_CHAT_LINE_SPACING;
230  }
231 
232  string_height = std::min<uint>(string_height, MAX_CHAT_MESSAGES * (FONT_HEIGHT_NORMAL + NETWORK_CHAT_LINE_SPACING));
233 
234  int top = _screen.height - _chatmsg_box.y - string_height - 2;
235  int bottom = _screen.height - _chatmsg_box.y - 2;
236  /* Paint a half-transparent box behind the chat messages */
237  GfxFillRect(_chatmsg_box.x, top - 2, _chatmsg_box.x + _chatmsg_box.width - 1, bottom,
238  PALETTE_TO_TRANSPARENT, FILLRECT_RECOLOUR // black, but with some alpha for background
239  );
240 
241  /* Paint the chat messages starting with the lowest at the bottom */
242  int ypos = bottom - 2;
243 
244  for (auto &cmsg : _chatmsg_list) {
245  if (!show_all && cmsg.remove_time < now) continue;
246  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;
247  if (ypos < top) break;
248  }
249 
250  /* Make sure the data is updated next flush */
251  VideoDriver::GetInstance()->MakeDirty(x, y, width, height);
252 
253  _chatmessage_visible = true;
254  _chatmessage_dirty = false;
255 }
256 
263 static void SendChat(const std::string &buf, DestType type, int dest)
264 {
265  if (buf.empty()) return;
266  if (!_network_server) {
267  MyClient::SendChat((NetworkAction)(NETWORK_ACTION_CHAT + type), type, dest, buf, 0);
268  } else {
269  NetworkServerSendChat((NetworkAction)(NETWORK_ACTION_CHAT + type), type, dest, buf, CLIENT_ID_SERVER);
270  }
271 }
272 
274 struct NetworkChatWindow : public Window {
276  int dest;
278 
286  {
287  this->dtype = type;
288  this->dest = dest;
290  this->message_editbox.cancel_button = WID_NC_CLOSE;
291  this->message_editbox.ok_button = WID_NC_SENDBUTTON;
292 
293  static const StringID chat_captions[] = {
294  STR_NETWORK_CHAT_ALL_CAPTION,
295  STR_NETWORK_CHAT_COMPANY_CAPTION,
296  STR_NETWORK_CHAT_CLIENT_CAPTION
297  };
298  assert((uint)this->dtype < lengthof(chat_captions));
299 
300  this->CreateNestedTree();
301  this->GetWidget<NWidgetCore>(WID_NC_DESTINATION)->widget_data = chat_captions[this->dtype];
302  this->FinishInitNested(type);
303 
306  _chat_tab_completion_active = false;
307 
309  }
310 
311  void Close() override
312  {
314  this->Window::Close();
315  }
316 
317  void FindWindowPlacementAndResize(int def_width, int def_height) override
318  {
320  }
321 
328  const char *ChatTabCompletionNextItem(uint *item)
329  {
330  static char chat_tab_temp_buffer[64];
331 
332  /* First, try clients */
333  if (*item < MAX_CLIENT_SLOTS) {
334  /* Skip inactive clients */
335  for (NetworkClientInfo *ci : NetworkClientInfo::Iterate(*item)) {
336  *item = ci->index;
337  return ci->client_name.c_str();
338  }
339  *item = MAX_CLIENT_SLOTS;
340  }
341 
342  /* Then, try townnames
343  * Not that the following assumes all town indices are adjacent, ie no
344  * towns have been deleted. */
345  if (*item < (uint)MAX_CLIENT_SLOTS + Town::GetPoolSize()) {
346  for (const Town *t : Town::Iterate(*item - MAX_CLIENT_SLOTS)) {
347  /* Get the town-name via the string-system */
348  SetDParam(0, t->index);
349  GetString(chat_tab_temp_buffer, STR_TOWN_NAME, lastof(chat_tab_temp_buffer));
350  return &chat_tab_temp_buffer[0];
351  }
352  }
353 
354  return nullptr;
355  }
356 
362  static char *ChatTabCompletionFindText(char *buf)
363  {
364  char *p = strrchr(buf, ' ');
365  if (p == nullptr) return buf;
366 
367  *p = '\0';
368  return p + 1;
369  }
370 
375  {
376  static char _chat_tab_completion_buf[NETWORK_CHAT_LENGTH];
377  assert(this->message_editbox.text.max_bytes == lengthof(_chat_tab_completion_buf));
378 
379  Textbuf *tb = &this->message_editbox.text;
380  size_t len, tb_len;
381  uint item;
382  char *tb_buf, *pre_buf;
383  const char *cur_name;
384  bool second_scan = false;
385 
386  item = 0;
387 
388  /* Copy the buffer so we can modify it without damaging the real data */
389  pre_buf = (_chat_tab_completion_active) ? stredup(_chat_tab_completion_buf) : stredup(tb->buf);
390 
391  tb_buf = ChatTabCompletionFindText(pre_buf);
392  tb_len = strlen(tb_buf);
393 
394  while ((cur_name = ChatTabCompletionNextItem(&item)) != nullptr) {
395  item++;
396 
398  /* We are pressing TAB again on the same name, is there another name
399  * that starts with this? */
400  if (!second_scan) {
401  size_t offset;
402  size_t length;
403 
404  /* If we are completing at the begin of the line, skip the ': ' we added */
405  if (tb_buf == pre_buf) {
406  offset = 0;
407  length = (tb->bytes - 1) - 2;
408  } else {
409  /* Else, find the place we are completing at */
410  offset = strlen(pre_buf) + 1;
411  length = (tb->bytes - 1) - offset;
412  }
413 
414  /* Compare if we have a match */
415  if (strlen(cur_name) == length && strncmp(cur_name, tb->buf + offset, length) == 0) second_scan = true;
416 
417  continue;
418  }
419 
420  /* Now any match we make on _chat_tab_completion_buf after this, is perfect */
421  }
422 
423  len = strlen(cur_name);
424  if (tb_len < len && strncasecmp(cur_name, tb_buf, tb_len) == 0) {
425  /* Save the data it was before completion */
426  if (!second_scan) seprintf(_chat_tab_completion_buf, lastof(_chat_tab_completion_buf), "%s", tb->buf);
428 
429  /* Change to the found name. Add ': ' if we are at the start of the line (pretty) */
430  if (pre_buf == tb_buf) {
431  this->message_editbox.text.Print("%s: ", cur_name);
432  } else {
433  this->message_editbox.text.Print("%s %s", pre_buf, cur_name);
434  }
435 
436  this->SetDirty();
437  free(pre_buf);
438  return;
439  }
440  }
441 
442  if (second_scan) {
443  /* We walked all possibilities, and the user presses tab again.. revert to original text */
444  this->message_editbox.text.Assign(_chat_tab_completion_buf);
446 
447  this->SetDirty();
448  }
449  free(pre_buf);
450  }
451 
452  Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number) override
453  {
454  Point pt = { 0, _screen.height - sm_height - FindWindowById(WC_STATUS_BAR, 0)->height };
455  return pt;
456  }
457 
458  void SetStringParameters(int widget) const override
459  {
460  if (widget != WID_NC_DESTINATION) return;
461 
462  if (this->dtype == DESTTYPE_CLIENT) {
463  SetDParamStr(0, NetworkClientInfo::GetByClientID((ClientID)this->dest)->client_name);
464  }
465  }
466 
467  void OnClick(Point pt, int widget, int click_count) override
468  {
469  switch (widget) {
470  case WID_NC_SENDBUTTON: /* Send */
471  SendChat(this->message_editbox.text.buf, this->dtype, this->dest);
472  FALLTHROUGH;
473 
474  case WID_NC_CLOSE: /* Cancel */
475  this->Close();
476  break;
477  }
478  }
479 
480  EventState OnKeyPress(WChar key, uint16 keycode) override
481  {
482  EventState state = ES_NOT_HANDLED;
483  if (keycode == WKC_TAB) {
485  state = ES_HANDLED;
486  }
487  return state;
488  }
489 
490  void OnEditboxChanged(int wid) override
491  {
493  }
494 
500  void OnInvalidateData(int data = 0, bool gui_scope = true) override
501  {
502  if (data == this->dest) this->Close();
503  }
504 };
505 
509  NWidget(WWT_CLOSEBOX, COLOUR_GREY, WID_NC_CLOSE),
510  NWidget(WWT_PANEL, COLOUR_GREY, WID_NC_BACKGROUND),
512  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),
513  NWidget(WWT_EDITBOX, COLOUR_GREY, WID_NC_TEXTBOX), SetMinimalSize(100, 12), SetPadding(1, 0, 1, 0), SetResize(1, 0),
514  SetDataTip(STR_NETWORK_CHAT_OSKTITLE, STR_NULL),
515  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_NC_SENDBUTTON), SetMinimalSize(62, 12), SetPadding(1, 0, 1, 0), SetDataTip(STR_NETWORK_CHAT_SEND, STR_NULL),
516  EndContainer(),
517  EndContainer(),
518  EndContainer(),
519 };
520 
523  WDP_MANUAL, nullptr, 0, 0,
525  0,
527 );
528 
529 
536 {
538  new NetworkChatWindow(&_chat_window_desc, type, dest);
539 }
ES_HANDLED
@ ES_HANDLED
The passed event is handled.
Definition: window_type.h:720
WID_NC_SENDBUTTON
@ WID_NC_SENDBUTTON
Send button.
Definition: network_chat_widget.h:19
DestType
DestType
Destination of our chat messages.
Definition: network_type.h:89
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:3254
QueryString::ok_button
int ok_button
Widget button of parent window to simulate when pressing OK in OSK.
Definition: querystring_gui.h:27
WChar
char32_t WChar
Type for wide characters, i.e.
Definition: string_type.h:36
NetworkChatWindow
Window to enter the chat message in.
Definition: network_chat_gui.cpp:274
Textbuf::max_bytes
uint16 max_bytes
the maximum size of the buffer in bytes (including terminating '\0')
Definition: textbuf_type.h:33
Textbuf::Print
void CDECL Print(const char *format,...) WARN_FORMAT(2
Print a formatted string into the textbuffer.
Definition: textbuf.cpp:415
WID_NC_DESTINATION
@ WID_NC_DESTINATION
Destination.
Definition: network_chat_widget.h:17
NetworkChatWindow::dest
int dest
The identifier of the destination.
Definition: network_chat_gui.cpp:276
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:1143
NetworkServerSendChat
void NetworkServerSendChat(NetworkAction action, DestType type, int dest, const std::string &msg, ClientID from_id, int64 data=0, bool from_admin=false)
Send an actual chat message.
Definition: network_server.cpp:1185
NETWORK_NAME_LENGTH
static const uint NETWORK_NAME_LENGTH
The maximum length of the server name and map name, in bytes including '\0'.
Definition: config.h:55
Blitter
How all blitters should look like.
Definition: base.hpp:28
WID_NC_CLOSE
@ WID_NC_CLOSE
Close button.
Definition: network_chat_widget.h:15
CursorVars::visible
bool visible
cursor is visible
Definition: gfx_type.h:139
Textbuf::Assign
void Assign(StringID string)
Render a string into the textbuffer.
Definition: textbuf.cpp:396
_network_server
bool _network_server
network-server is active
Definition: network.cpp:59
NetworkAction
NetworkAction
Actions that can be used for NetworkTextMessage.
Definition: network_type.h:99
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
_chatmessage_backup
static uint8 * _chatmessage_backup
Backup in case text is moved.
Definition: network_chat_gui.cpp:66
Window::CreateNestedTree
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1775
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:73
NetworkInitChatMessage
void NetworkInitChatMessage()
Initialize all buffers of the chat visualisation.
Definition: network_chat_gui.cpp:115
NETWORK_CHAT_LENGTH
static const uint NETWORK_CHAT_LENGTH
The maximum length of a chat message, in bytes including '\0'.
Definition: config.h:66
FindWindowById
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition: window.cpp:1161
PALETTE_TO_TRANSPARENT
static const PaletteID PALETTE_TO_TRANSPARENT
This sets the sprite to transparent.
Definition: sprites.h:1595
NetworkChatWindow::dtype
DestType dtype
The type of destination.
Definition: network_chat_gui.cpp:275
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:253
SetResize
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:997
SA_BOTTOM
@ SA_BOTTOM
Bottom align the text.
Definition: gfx_type.h:341
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:53
ChatMessage
Container for a message.
Definition: network_chat_gui.cpp:42
NetworkChatWindow::NetworkChatWindow
NetworkChatWindow(WindowDesc *desc, DestType type, int dest)
Create a chat input window.
Definition: network_chat_gui.cpp:285
SA_RIGHT
@ SA_RIGHT
Right align the text (must be a single bit).
Definition: gfx_type.h:336
SA_VERT_CENTER
@ SA_VERT_CENTER
Vertically center the text.
Definition: gfx_type.h:340
CursorVars::draw_size
Point draw_size
position and size bounding-box for drawing
Definition: gfx_type.h:133
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:196
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:975
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1111
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:740
Textbuf::buf
char *const buf
buffer in which text is saved
Definition: textbuf_type.h:32
Window::querystrings
SmallMap< int, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
Definition: window_gui.h:257
network_base.h
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:789
NetworkReInitChatBoxSize
void NetworkReInitChatBoxSize()
Initialize all font-dependent chat box sizes.
Definition: network_chat_gui.cpp:107
ClientNetworkGameSocketHandler::SendChat
static NetworkRecvStatus SendChat(NetworkAction action, DestType type, int dest, const std::string &msg, int64 data)
Send a chat-packet over the network.
Definition: network_client.cpp:427
ICONSOLE_FULL
@ ICONSOLE_FULL
In-game console is opened, whole screen.
Definition: console_type.h:17
NetworkChatWindow::OnKeyPress
EventState OnKeyPress(WChar key, uint16 keycode) override
A key has been pressed.
Definition: network_chat_gui.cpp:480
WindowDesc
High level window description.
Definition: window_gui.h:102
ChatMessage::message
std::string message
The action message.
Definition: network_chat_gui.cpp:43
NetworkClientInfo::GetByClientID
static NetworkClientInfo * GetByClientID(ClientID client_id)
Return the CI given it's client-identifier.
Definition: network.cpp:114
Pool::PoolItem<&_town_pool >::GetPoolSize
static size_t GetPoolSize()
Returns first unused index.
Definition: pool_type.hpp:358
ChatMessage::colour
TextColour colour
The colour of the message.
Definition: network_chat_gui.cpp:44
_chatmessage_visible
static bool _chatmessage_visible
Is a chat message visible.
Definition: network_chat_gui.cpp:51
DRAW_STRING_BUFFER
static const int DRAW_STRING_BUFFER
Size of the buffer used for drawing strings.
Definition: gfx_func.h:86
NetworkChatWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: network_chat_gui.cpp:458
WWT_EDITBOX
@ WWT_EDITBOX
a textbox for typing
Definition: widget_type.h:69
Window::height
int height
Height of the window (number of pixels down in y direction)
Definition: window_gui.h:249
_toolbar_width
uint _toolbar_width
Width of the toolbar, shared by statusbar.
Definition: toolbar_gui.cpp:67
NetworkChatWindow::OnInitialPosition
Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number) override
Compute the initial position of the window.
Definition: network_chat_gui.cpp:452
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:1008
ClientID
ClientID
'Unique' identifier to be given to clients
Definition: network_type.h:47
ES_NOT_HANDLED
@ ES_NOT_HANDLED
The passed event is not handled.
Definition: window_type.h:721
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:104
NetworkDrawChatMessage
void NetworkDrawChatMessage()
Draw the chat message-box.
Definition: network_chat_gui.cpp:188
BlitterFactory::GetCurrentBlitter
static Blitter * GetCurrentBlitter()
Get the current active blitter (always set by calling SelectBlitter).
Definition: factory.hpp:141
SA_FORCE
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
Definition: gfx_type.h:346
_chat_tab_completion_active
static bool _chat_tab_completion_active
Whether tab completion is active.
Definition: network_chat_gui.cpp:52
CLIENT_ID_SERVER
@ CLIENT_ID_SERVER
Servers always have this ID.
Definition: network_type.h:49
SendChat
static void SendChat(const std::string &buf, DestType type, int dest)
Send an actual chat message.
Definition: network_chat_gui.cpp:263
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:127
Window::SetFocusedWidget
bool SetFocusedWidget(int widget_index)
Set focus within this window to the given widget.
Definition: window.cpp:519
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:241
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:116
VideoDriver::GetInstance
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
Definition: video_driver.hpp:202
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:38
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:67
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
Textbuf::bytes
uint16 bytes
the current size of the string in bytes (including terminating '\0')
Definition: textbuf_type.h:35
QueryString::cancel_button
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
Definition: querystring_gui.h:28
EndContainer
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1096
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:386
NETWORK_CHAT_LINE_SPACING
static const uint NETWORK_CHAT_LINE_SPACING
The draw buffer must be able to contain the chat message, client name and the "[All]" message,...
Definition: network_chat_gui.cpp:39
_chatmessage_dirty
static bool _chatmessage_dirty
Does the chat message need repainting?
Definition: network_chat_gui.cpp:50
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...
NetworkChatWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: network_chat_gui.cpp:500
WWT_TEXT
@ WWT_TEXT
Pure simple text.
Definition: widget_type.h:56
WID_NC_TEXTBOX
@ WID_NC_TEXTBOX
Textbox.
Definition: network_chat_widget.h:18
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:91
FONT_HEIGHT_NORMAL
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:206
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1229
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:328
CloseWindowByClass
void CloseWindowByClass(WindowClass cls)
Close all windows of a given class.
Definition: window.cpp:1203
_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:59
SetMinimalSize
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1014
_chat_window_desc
static WindowDesc _chat_window_desc(WDP_MANUAL, nullptr, 0, 0, WC_SEND_NETWORK_MSG, WC_NONE, 0, _nested_chat_window_widgets, lengthof(_nested_chat_window_widgets))
The description of the chat window.
NetworkChatWindow::OnEditboxChanged
void OnEditboxChanged(int wid) override
The text in an editbox has been edited.
Definition: network_chat_gui.cpp:490
NetworkChatWindow::FindWindowPlacementAndResize
void FindWindowPlacementAndResize(int def_width, int def_height) override
Resize window towards the default size.
Definition: network_chat_gui.cpp:317
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:48
NetworkChatWindow::Close
void Close() override
Hide the window and all its child windows, and mark them for a later deletion.
Definition: network_chat_gui.cpp:311
EventState
EventState
State of handling an event.
Definition: window_type.h:719
MAX_CHAT_MESSAGES
static uint MAX_CHAT_MESSAGES
The limit of chat messages to show.
Definition: network_chat_gui.cpp:53
FindWindowByClass
Window * FindWindowByClass(WindowClass cls)
Find any window by its class.
Definition: window.cpp:1176
NetworkChatMessageLoop
void NetworkChatMessageLoop()
Check if a message is expired.
Definition: network_chat_gui.cpp:174
seprintf
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
Definition: string.cpp:554
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1791
HaveChatMessages
static bool HaveChatMessages(bool show_all)
Test if there are any chat messages to display.
Definition: network_chat_gui.cpp:73
SetAlignment
static NWidgetPart SetAlignment(StringAlignment align)
Widget part function for setting the alignment of text/images.
Definition: widget_type.h:1064
NetworkChatWindow::ChatTabCompletion
void ChatTabCompletion()
See if we can auto-complete the current text of the user.
Definition: network_chat_gui.cpp:374
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:111
NetworkChatWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: network_chat_gui.cpp:467
stredup
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
Definition: string.cpp:138
ShowNetworkChatQueryWindow
void ShowNetworkChatQueryWindow(DestType type, int dest)
Show the chat window.
Definition: network_chat_gui.cpp:535
SA_LEFT
@ SA_LEFT
Left align the text.
Definition: gfx_type.h:334
network.h
GUISettings::network_chat_box_width_pct
uint16 network_chat_box_width_pct
width of the chat box in percent
Definition: settings_type.h:186
WC_SEND_NETWORK_MSG
@ WC_SEND_NETWORK_MSG
Chatbox; Window numbers:
Definition: window_type.h:490
Blitter::CopyFromBuffer
virtual void CopyFromBuffer(void *video, const void *src, int width, int height)=0
Copy from a buffer to the screen.
NetworkChatWindow::ChatTabCompletionFindText
static char * ChatTabCompletionFindText(char *buf)
Find what text to complete.
Definition: network_chat_gui.cpp:362
Town
Town data structure.
Definition: town.h:50
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:386
WDP_MANUAL
@ WDP_MANUAL
Manually align the window (so no automatic location finding)
Definition: window_gui.h:89
_chatmsg_list
static std::deque< ChatMessage > _chatmsg_list
The actual chat message list.
Definition: network_chat_gui.cpp:49
NetworkChatWindow::message_editbox
QueryString message_editbox
Message editbox.
Definition: network_chat_gui.cpp:277
PointDimension
Specification of a rectangle with an absolute top-left coordinate and a (relative) width/height.
Definition: geometry_type.hpp:228
_nested_chat_window_widgets
static const NWidgetPart _nested_chat_window_widgets[]
The widgets of the chat window.
Definition: network_chat_gui.cpp:507
PositionNetworkChatWindow
int PositionNetworkChatWindow(Window *w)
(Re)position network chat window at the screen.
Definition: window.cpp:3466
DESTTYPE_CLIENT
@ DESTTYPE_CLIENT
Send message/notice to only a certain client (Private)
Definition: network_type.h:92
Window
Data structure for an opened window.
Definition: window_gui.h:213
WC_STATUS_BAR
@ WC_STATUS_BAR
Statusbar (at the bottom of your screen); Window numbers:
Definition: window_type.h:57
WC_NEWS_WINDOW
@ WC_NEWS_WINDOW
News window; Window numbers:
Definition: window_type.h:241
free
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: stdafx.h:470
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:21
WID_NC_BACKGROUND
@ WID_NC_BACKGROUND
Background of the window.
Definition: network_chat_widget.h:16
_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:65
lastof
#define lastof(x)
Get the last element of an fixed size array.
Definition: stdafx.h:402
GUISettings::network_chat_box_height
uint8 network_chat_box_height
height of the chat box in lines
Definition: settings_type.h:187
Blitter::GetBytesPerPixel
virtual int GetBytesPerPixel()=0
Get how many bytes are needed to store a pixel.
NetworkClientInfo
Container for all information known about a client.
Definition: network_base.h:24
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:297
ChatMessage::remove_time
std::chrono::steady_clock::time_point remove_time
The time to remove the message.
Definition: network_chat_gui.cpp:45
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:604
ScaleGUITrad
static RectPadding ScaleGUITrad(const RectPadding &r)
Scale a RectPadding to GUI zoom level.
Definition: widget.cpp:168
Window::FindWindowPlacementAndResize
virtual void FindWindowPlacementAndResize(int def_width, int def_height)
Resize window towards the default size.
Definition: window.cpp:1472
Textbuf
Helper/buffer for input fields.
Definition: textbuf_type.h:30
Window::Close
virtual void Close()
Hide the window and all its child windows, and mark them for a later deletion.
Definition: window.cpp:1107
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.