OpenTTD Source  12.0-beta2
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 "network.h"
21 #include "network_client.h"
22 #include "network_base.h"
23 
24 #include "../widgets/network_chat_widget.h"
25 
26 #include "table/strings.h"
27 
28 #include <stdarg.h> /* va_list */
29 #include <deque>
30 
31 #include "../safeguards.h"
32 
35 static_assert((int)DRAW_STRING_BUFFER >= (int)NETWORK_CHAT_LENGTH + NETWORK_NAME_LENGTH + 40);
36 
38 static const uint NETWORK_CHAT_LINE_SPACING = 3;
39 
41 struct ChatMessage {
42  std::string message;
44  std::chrono::steady_clock::time_point remove_time;
45 };
46 
47 /* used for chat window */
48 static std::deque<ChatMessage> _chatmsg_list;
49 static bool _chatmessage_dirty = false;
50 static bool _chatmessage_visible = false;
52 static uint MAX_CHAT_MESSAGES = 0;
53 
58 static std::chrono::steady_clock::time_point _chatmessage_dirty_time;
59 
65 static uint8 *_chatmessage_backup = nullptr;
66 
72 static inline bool HaveChatMessages(bool show_all)
73 {
74  if (show_all) return _chatmsg_list.size() != 0;
75 
76  auto now = std::chrono::steady_clock::now();
77  for (auto &cmsg : _chatmsg_list) {
78  if (cmsg.remove_time >= now) return true;
79  }
80 
81  return false;
82 }
83 
90 void CDECL NetworkAddChatMessage(TextColour colour, uint duration, const std::string &message)
91 {
92  if (_chatmsg_list.size() == MAX_CHAT_MESSAGES) {
93  _chatmsg_list.pop_back();
94  }
95 
96  ChatMessage *cmsg = &_chatmsg_list.emplace_front();
97  cmsg->message = message;
98  cmsg->colour = (colour & TC_IS_PALETTE_COLOUR) ? colour : TC_WHITE;
99  cmsg->remove_time = std::chrono::steady_clock::now() + std::chrono::seconds(duration);
100 
101  _chatmessage_dirty_time = std::chrono::steady_clock::now();
102  _chatmessage_dirty = true;
103 }
104 
107 {
111 }
112 
115 {
117 
118  _chatmsg_list.clear();
119  _chatmsg_box.x = 10;
120  _chatmsg_box.width = _settings_client.gui.network_chat_box_width_pct * _screen.width / 100;
122  _chatmessage_visible = false;
123 }
124 
127 {
128  /* Sometimes we also need to hide the cursor
129  * This is because both textmessage and the cursor take a shot of the
130  * screen before drawing.
131  * Now the textmessage takes its shot and paints its data before the cursor
132  * does, so in the shot of the cursor is the screen-data of the textmessage
133  * included when the cursor hangs somewhere over the textmessage. To
134  * avoid wrong repaints, we undraw the cursor in that case, and everything
135  * looks nicely ;)
136  * (and now hope this story above makes sense to you ;))
137  */
138  if (_cursor.visible &&
139  _cursor.draw_pos.x + _cursor.draw_size.x >= _chatmsg_box.x &&
140  _cursor.draw_pos.x <= _chatmsg_box.x + _chatmsg_box.width &&
141  _cursor.draw_pos.y + _cursor.draw_size.y >= _screen.height - _chatmsg_box.y - _chatmsg_box.height &&
142  _cursor.draw_pos.y <= _screen.height - _chatmsg_box.y) {
143  UndrawMouseCursor();
144  }
145 
146  if (_chatmessage_visible) {
148  int x = _chatmsg_box.x;
149  int y = _screen.height - _chatmsg_box.y - _chatmsg_box.height;
150  int width = _chatmsg_box.width;
151  int height = _chatmsg_box.height;
152  if (y < 0) {
153  height = std::max(height + y, std::min(_chatmsg_box.height, _screen.height));
154  y = 0;
155  }
156  if (x + width >= _screen.width) {
157  width = _screen.width - x;
158  }
159  if (width <= 0 || height <= 0) return;
160 
161  _chatmessage_visible = false;
162  /* Put our 'shot' back to the screen */
163  blitter->CopyFromBuffer(blitter->MoveTo(_screen.dst_ptr, x, y), _chatmessage_backup, width, height);
164  /* And make sure it is updated next time */
165  VideoDriver::GetInstance()->MakeDirty(x, y, width, height);
166 
167  _chatmessage_dirty_time = std::chrono::steady_clock::now();
168  _chatmessage_dirty = true;
169  }
170 }
171 
174 {
175  auto now = std::chrono::steady_clock::now();
176  for (auto &cmsg : _chatmsg_list) {
177  /* Message has expired, remove from the list */
178  if (now > cmsg.remove_time && _chatmessage_dirty_time < cmsg.remove_time) {
180  _chatmessage_dirty = true;
181  break;
182  }
183  }
184 }
185 
188 {
190  if (!_chatmessage_dirty) return;
191 
193  bool show_all = (w != nullptr);
194 
195  /* First undraw if needed */
197 
198  if (_iconsole_mode == ICONSOLE_FULL) return;
199 
200  /* Check if we have anything to draw at all */
201  if (!HaveChatMessages(show_all)) return;
202 
203  int x = _chatmsg_box.x;
204  int y = _screen.height - _chatmsg_box.y - _chatmsg_box.height;
205  int width = _chatmsg_box.width;
206  int height = _chatmsg_box.height;
207  if (y < 0) {
208  height = std::max(height + y, std::min(_chatmsg_box.height, _screen.height));
209  y = 0;
210  }
211  if (x + width >= _screen.width) {
212  width = _screen.width - x;
213  }
214  if (width <= 0 || height <= 0) return;
215 
216  assert(blitter->BufferSize(width, height) <= (int)(_chatmsg_box.width * _chatmsg_box.height * blitter->GetBytesPerPixel()));
217 
218  /* Make a copy of the screen as it is before painting (for undraw) */
219  blitter->CopyToBuffer(blitter->MoveTo(_screen.dst_ptr, x, y), _chatmessage_backup, width, height);
220 
221  _cur_dpi = &_screen; // switch to _screen painting
222 
223  auto now = std::chrono::steady_clock::now();
224  int string_height = 0;
225  for (auto &cmsg : _chatmsg_list) {
226  if (!show_all && cmsg.remove_time < now) continue;
227  SetDParamStr(0, cmsg.message);
228  string_height += GetStringLineCount(STR_JUST_RAW_STRING, width - 1) * FONT_HEIGHT_NORMAL + NETWORK_CHAT_LINE_SPACING;
229  }
230 
231  string_height = std::min<uint>(string_height, MAX_CHAT_MESSAGES * (FONT_HEIGHT_NORMAL + NETWORK_CHAT_LINE_SPACING));
232 
233  int top = _screen.height - _chatmsg_box.y - string_height - 2;
234  int bottom = _screen.height - _chatmsg_box.y - 2;
235  /* Paint a half-transparent box behind the chat messages */
236  GfxFillRect(_chatmsg_box.x, top - 2, _chatmsg_box.x + _chatmsg_box.width - 1, bottom,
237  PALETTE_TO_TRANSPARENT, FILLRECT_RECOLOUR // black, but with some alpha for background
238  );
239 
240  /* Paint the chat messages starting with the lowest at the bottom */
241  int ypos = bottom - 2;
242 
243  for (auto &cmsg : _chatmsg_list) {
244  if (!show_all && cmsg.remove_time < now) continue;
245  ypos = DrawStringMultiLine(_chatmsg_box.x + 3, _chatmsg_box.x + _chatmsg_box.width - 1, top, ypos, cmsg.message, cmsg.colour, SA_LEFT | SA_BOTTOM | SA_FORCE) - NETWORK_CHAT_LINE_SPACING;
246  if (ypos < top) break;
247  }
248 
249  /* Make sure the data is updated next flush */
250  VideoDriver::GetInstance()->MakeDirty(x, y, width, height);
251 
252  _chatmessage_visible = true;
253  _chatmessage_dirty = false;
254 }
255 
262 static void SendChat(const std::string &buf, DestType type, int dest)
263 {
264  if (buf.empty()) return;
265  if (!_network_server) {
266  MyClient::SendChat((NetworkAction)(NETWORK_ACTION_CHAT + type), type, dest, buf, 0);
267  } else {
268  NetworkServerSendChat((NetworkAction)(NETWORK_ACTION_CHAT + type), type, dest, buf, CLIENT_ID_SERVER);
269  }
270 }
271 
273 struct NetworkChatWindow : public Window {
275  int dest;
277 
285  {
286  this->dtype = type;
287  this->dest = dest;
289  this->message_editbox.cancel_button = WID_NC_CLOSE;
290  this->message_editbox.ok_button = WID_NC_SENDBUTTON;
291 
292  static const StringID chat_captions[] = {
293  STR_NETWORK_CHAT_ALL_CAPTION,
294  STR_NETWORK_CHAT_COMPANY_CAPTION,
295  STR_NETWORK_CHAT_CLIENT_CAPTION
296  };
297  assert((uint)this->dtype < lengthof(chat_captions));
298 
299  this->CreateNestedTree();
300  this->GetWidget<NWidgetCore>(WID_NC_DESTINATION)->widget_data = chat_captions[this->dtype];
301  this->FinishInitNested(type);
302 
305  _chat_tab_completion_active = false;
306 
308  }
309 
310  void Close() override
311  {
313  this->Window::Close();
314  }
315 
316  void FindWindowPlacementAndResize(int def_width, int def_height) override
317  {
319  }
320 
327  const char *ChatTabCompletionNextItem(uint *item)
328  {
329  static char chat_tab_temp_buffer[64];
330 
331  /* First, try clients */
332  if (*item < MAX_CLIENT_SLOTS) {
333  /* Skip inactive clients */
334  for (NetworkClientInfo *ci : NetworkClientInfo::Iterate(*item)) {
335  *item = ci->index;
336  return ci->client_name.c_str();
337  }
338  *item = MAX_CLIENT_SLOTS;
339  }
340 
341  /* Then, try townnames
342  * Not that the following assumes all town indices are adjacent, ie no
343  * towns have been deleted. */
344  if (*item < (uint)MAX_CLIENT_SLOTS + Town::GetPoolSize()) {
345  for (const Town *t : Town::Iterate(*item - MAX_CLIENT_SLOTS)) {
346  /* Get the town-name via the string-system */
347  SetDParam(0, t->index);
348  GetString(chat_tab_temp_buffer, STR_TOWN_NAME, lastof(chat_tab_temp_buffer));
349  return &chat_tab_temp_buffer[0];
350  }
351  }
352 
353  return nullptr;
354  }
355 
361  static char *ChatTabCompletionFindText(char *buf)
362  {
363  char *p = strrchr(buf, ' ');
364  if (p == nullptr) return buf;
365 
366  *p = '\0';
367  return p + 1;
368  }
369 
374  {
375  static char _chat_tab_completion_buf[NETWORK_CHAT_LENGTH];
376  assert(this->message_editbox.text.max_bytes == lengthof(_chat_tab_completion_buf));
377 
378  Textbuf *tb = &this->message_editbox.text;
379  size_t len, tb_len;
380  uint item;
381  char *tb_buf, *pre_buf;
382  const char *cur_name;
383  bool second_scan = false;
384 
385  item = 0;
386 
387  /* Copy the buffer so we can modify it without damaging the real data */
388  pre_buf = (_chat_tab_completion_active) ? stredup(_chat_tab_completion_buf) : stredup(tb->buf);
389 
390  tb_buf = ChatTabCompletionFindText(pre_buf);
391  tb_len = strlen(tb_buf);
392 
393  while ((cur_name = ChatTabCompletionNextItem(&item)) != nullptr) {
394  item++;
395 
397  /* We are pressing TAB again on the same name, is there another name
398  * that starts with this? */
399  if (!second_scan) {
400  size_t offset;
401  size_t length;
402 
403  /* If we are completing at the begin of the line, skip the ': ' we added */
404  if (tb_buf == pre_buf) {
405  offset = 0;
406  length = (tb->bytes - 1) - 2;
407  } else {
408  /* Else, find the place we are completing at */
409  offset = strlen(pre_buf) + 1;
410  length = (tb->bytes - 1) - offset;
411  }
412 
413  /* Compare if we have a match */
414  if (strlen(cur_name) == length && strncmp(cur_name, tb->buf + offset, length) == 0) second_scan = true;
415 
416  continue;
417  }
418 
419  /* Now any match we make on _chat_tab_completion_buf after this, is perfect */
420  }
421 
422  len = strlen(cur_name);
423  if (tb_len < len && strncasecmp(cur_name, tb_buf, tb_len) == 0) {
424  /* Save the data it was before completion */
425  if (!second_scan) seprintf(_chat_tab_completion_buf, lastof(_chat_tab_completion_buf), "%s", tb->buf);
427 
428  /* Change to the found name. Add ': ' if we are at the start of the line (pretty) */
429  if (pre_buf == tb_buf) {
430  this->message_editbox.text.Print("%s: ", cur_name);
431  } else {
432  this->message_editbox.text.Print("%s %s", pre_buf, cur_name);
433  }
434 
435  this->SetDirty();
436  free(pre_buf);
437  return;
438  }
439  }
440 
441  if (second_scan) {
442  /* We walked all possibilities, and the user presses tab again.. revert to original text */
443  this->message_editbox.text.Assign(_chat_tab_completion_buf);
445 
446  this->SetDirty();
447  }
448  free(pre_buf);
449  }
450 
451  Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number) override
452  {
453  Point pt = { 0, _screen.height - sm_height - FindWindowById(WC_STATUS_BAR, 0)->height };
454  return pt;
455  }
456 
457  void SetStringParameters(int widget) const override
458  {
459  if (widget != WID_NC_DESTINATION) return;
460 
461  if (this->dtype == DESTTYPE_CLIENT) {
462  SetDParamStr(0, NetworkClientInfo::GetByClientID((ClientID)this->dest)->client_name);
463  }
464  }
465 
466  void OnClick(Point pt, int widget, int click_count) override
467  {
468  switch (widget) {
469  case WID_NC_SENDBUTTON: /* Send */
470  SendChat(this->message_editbox.text.buf, this->dtype, this->dest);
471  FALLTHROUGH;
472 
473  case WID_NC_CLOSE: /* Cancel */
474  this->Close();
475  break;
476  }
477  }
478 
479  EventState OnKeyPress(WChar key, uint16 keycode) override
480  {
481  EventState state = ES_NOT_HANDLED;
482  if (keycode == WKC_TAB) {
484  state = ES_HANDLED;
485  }
486  return state;
487  }
488 
489  void OnEditboxChanged(int wid) override
490  {
492  }
493 
499  void OnInvalidateData(int data = 0, bool gui_scope = true) override
500  {
501  if (data == this->dest) this->Close();
502  }
503 };
504 
508  NWidget(WWT_CLOSEBOX, COLOUR_GREY, WID_NC_CLOSE),
509  NWidget(WWT_PANEL, COLOUR_GREY, WID_NC_BACKGROUND),
511  NWidget(WWT_TEXT, COLOUR_GREY, WID_NC_DESTINATION), SetMinimalSize(62, 12), SetPadding(1, 0, 1, 0), SetTextColour(TC_BLACK), SetAlignment(SA_TOP | SA_RIGHT), SetDataTip(STR_NULL, STR_NULL),
512  NWidget(WWT_EDITBOX, COLOUR_GREY, WID_NC_TEXTBOX), SetMinimalSize(100, 12), SetPadding(1, 0, 1, 0), SetResize(1, 0),
513  SetDataTip(STR_NETWORK_CHAT_OSKTITLE, STR_NULL),
514  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_NC_SENDBUTTON), SetMinimalSize(62, 12), SetPadding(1, 0, 1, 0), SetDataTip(STR_NETWORK_CHAT_SEND, STR_NULL),
515  EndContainer(),
516  EndContainer(),
517  EndContainer(),
518 };
519 
522  WDP_MANUAL, nullptr, 0, 0,
524  0,
526 );
527 
528 
535 {
537  new NetworkChatWindow(&_chat_window_desc, type, dest);
538 }
ES_HANDLED
@ ES_HANDLED
The passed event is handled.
Definition: window_type.h:718
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:3218
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:35
NetworkChatWindow
Window to enter the chat message in.
Definition: network_chat_gui.cpp:273
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:275
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:1139
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:1153
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:57
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:289
_chatmessage_backup
static uint8 * _chatmessage_backup
Backup in case text is moved.
Definition: network_chat_gui.cpp:65
Window::CreateNestedTree
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1760
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:114
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:1146
PALETTE_TO_TRANSPARENT
static const PaletteID PALETTE_TO_TRANSPARENT
This sets the sprite to transparent.
Definition: sprites.h:1597
NetworkChatWindow::dtype
DestType dtype
The type of destination.
Definition: network_chat_gui.cpp:274
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:250
SetResize
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:993
SA_BOTTOM
@ SA_BOTTOM
Bottom align the text.
Definition: gfx_type.h:335
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:52
ChatMessage
Container for a message.
Definition: network_chat_gui.cpp:41
NetworkChatWindow::NetworkChatWindow
NetworkChatWindow(WindowDesc *desc, DestType type, int dest)
Create a chat input window.
Definition: network_chat_gui.cpp:284
SA_RIGHT
@ SA_RIGHT
Right align the text (must be a single bit).
Definition: gfx_type.h:330
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:971
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1107
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:738
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:323
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:787
NetworkReInitChatBoxSize
void NetworkReInitChatBoxSize()
Initialize all font-dependent chat box sizes.
Definition: network_chat_gui.cpp:106
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:436
ICONSOLE_FULL
@ ICONSOLE_FULL
In-game console is closed.
Definition: console_type.h:17
NetworkChatWindow::OnKeyPress
EventState OnKeyPress(WChar key, uint16 keycode) override
A key has been pressed.
Definition: network_chat_gui.cpp:479
WindowDesc
High level window description.
Definition: window_gui.h:168
ChatMessage::message
std::string message
The action message.
Definition: network_chat_gui.cpp:42
NetworkClientInfo::GetByClientID
static NetworkClientInfo * GetByClientID(ClientID client_id)
Return the CI given it's client-identifier.
Definition: network.cpp:112
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:43
_chatmessage_visible
static bool _chatmessage_visible
Is a chat message visible.
Definition: network_chat_gui.cpp:50
DRAW_STRING_BUFFER
static const int DRAW_STRING_BUFFER
Size of the buffer used for drawing strings.
Definition: gfx_func.h:85
NetworkChatWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: network_chat_gui.cpp:457
SA_TOP
@ SA_TOP
Top align the text.
Definition: gfx_type.h:333
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:315
_toolbar_width
uint _toolbar_width
Width of the toolbar, shared by statusbar.
Definition: toolbar_gui.cpp:63
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:451
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:993
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:719
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:187
TC_IS_PALETTE_COLOUR
@ TC_IS_PALETTE_COLOUR
Colour value is already a real palette colour index, not an index of a StringColour.
Definition: gfx_type.h:273
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:340
_chat_tab_completion_active
static bool _chat_tab_completion_active
Whether tab completion is active.
Definition: network_chat_gui.cpp:51
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:262
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:126
Window::SetFocusedWidget
bool SetFocusedWidget(int widget_index)
Set focus within this window to the given widget.
Definition: window.cpp:506
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:307
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:199
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:37
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:1092
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:38
_chatmessage_dirty
static bool _chatmessage_dirty
Does the chat message need repainting?
Definition: network_chat_gui.cpp: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...
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:499
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:90
FONT_HEIGHT_NORMAL
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:165
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1207
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:327
CloseWindowByClass
void CloseWindowByClass(WindowClass cls)
Close all windows of a given class.
Definition: window.cpp:1188
_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:58
SetMinimalSize
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1010
_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:489
NetworkChatWindow::FindWindowPlacementAndResize
void FindWindowPlacementAndResize(int def_width, int def_height) override
Resize window towards the default size.
Definition: network_chat_gui.cpp:316
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:310
EventState
EventState
State of handling an event.
Definition: window_type.h:717
MAX_CHAT_MESSAGES
static uint MAX_CHAT_MESSAGES
The limit of chat messages to show.
Definition: network_chat_gui.cpp:52
FindWindowByClass
Window * FindWindowByClass(WindowClass cls)
Find any window by its class.
Definition: window.cpp:1161
NetworkChatMessageLoop
void NetworkChatMessageLoop()
Check if a message is expired.
Definition: network_chat_gui.cpp:173
seprintf
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
Definition: string.cpp:535
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1776
HaveChatMessages
static bool HaveChatMessages(bool show_all)
Test if there are any chat messages to display.
Definition: network_chat_gui.cpp:72
SetAlignment
static NWidgetPart SetAlignment(StringAlignment align)
Widget part function for setting the alignment of text/images.
Definition: widget_type.h:1060
NetworkChatWindow::ChatTabCompletion
void ChatTabCompletion()
See if we can auto-complete the current text of the user.
Definition: network_chat_gui.cpp:373
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:466
stredup
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
Definition: string.cpp:137
ShowNetworkChatQueryWindow
void ShowNetworkChatQueryWindow(DestType type, int dest)
Show the chat window.
Definition: network_chat_gui.cpp:534
SA_LEFT
@ SA_LEFT
Left align the text.
Definition: gfx_type.h:328
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:180
WC_SEND_NETWORK_MSG
@ WC_SEND_NETWORK_MSG
Chatbox; Window numbers:
Definition: window_type.h:489
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:361
Town
Town data structure.
Definition: town.h:50
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:378
WDP_MANUAL
@ WDP_MANUAL
Manually align the window (so no automatic location finding)
Definition: window_gui.h:155
_chatmsg_list
static std::deque< ChatMessage > _chatmsg_list
The actual chat message list.
Definition: network_chat_gui.cpp:48
NetworkChatWindow::message_editbox
QueryString message_editbox
Message editbox.
Definition: network_chat_gui.cpp:276
PointDimension
Specification of a rectangle with an absolute top-left coordinate and a (relative) width/height.
Definition: geometry_type.hpp:58
_nested_chat_window_widgets
static const NWidgetPart _nested_chat_window_widgets[]
The widgets of the chat window.
Definition: network_chat_gui.cpp:506
PositionNetworkChatWindow
int PositionNetworkChatWindow(Window *w)
(Re)position network chat window at the screen.
Definition: window.cpp:3415
DESTTYPE_CLIENT
@ DESTTYPE_CLIENT
Send message/notice to only a certain client (Private)
Definition: network_type.h:92
SetTextColour
static NWidgetPart SetTextColour(TextColour colour)
Widget part function for setting the text colour.
Definition: widget_type.h:1045
Window
Data structure for an opened window.
Definition: window_gui.h:279
WC_STATUS_BAR
@ WC_STATUS_BAR
Statusbar (at the bottom of your screen); Window numbers:
Definition: window_type.h:56
WC_NEWS_WINDOW
@ WC_NEWS_WINDOW
News window; Window numbers:
Definition: window_type.h:240
free
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: stdafx.h:460
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:64
lastof
#define lastof(x)
Get the last element of an fixed size array.
Definition: stdafx.h:394
GUISettings::network_chat_box_height
uint8 network_chat_box_height
height of the chat box in lines
Definition: settings_type.h:181
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:296
ChatMessage::remove_time
std::chrono::steady_clock::time_point remove_time
The time to remove the message.
Definition: network_chat_gui.cpp:44
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:593
Window::FindWindowPlacementAndResize
virtual void FindWindowPlacementAndResize(int def_width, int def_height)
Resize window towards the default size.
Definition: window.cpp:1457
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:1092
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.