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" 
   23 #include "../window_func.h" 
   24 #include "../toolbar_gui.h" 
   25 #include "../core/geometry_func.hpp" 
   30 #include "../widgets/network_chat_widget.h" 
   32 #include "table/strings.h" 
   34 #include "../safeguards.h" 
   72     if (_chatmsg_list[i].message[0] == 
'\0') 
break;
 
   89   va_start(va, message);
 
   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;
 
  106   _chatmessage_dirty = 
true;
 
  126   _chatmessage_visible = 
false;
 
  129     _chatmsg_list[i].
message[0] = 
'\0';
 
  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) {
 
  154   if (_chatmessage_visible) {
 
  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;
 
  161       height = 
max(height + y, 
min(_chatmsg_box.height, _screen.height));
 
  164     if (x + width >= _screen.width) {
 
  165       width = _screen.width - x;
 
  167     if (width <= 0 || height <= 0) 
return;
 
  169     _chatmessage_visible = 
false;
 
  175     _chatmessage_dirty = 
true;
 
  184     if (cmsg->
message[0] == 
'\0') 
continue;
 
  189       if (i != MAX_CHAT_MESSAGES - 1) memmove(cmsg, cmsg + 1, 
sizeof(*cmsg) * (MAX_CHAT_MESSAGES - i - 1));
 
  192       _chatmsg_list[MAX_CHAT_MESSAGES - 1].
message[0] = 
'\0';
 
  193       _chatmessage_dirty = 
true;
 
  205   if (!_chatmessage_dirty) 
return;
 
  214   if (count == 0) 
return;
 
  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;
 
  221     height = 
max(height + y, 
min(_chatmsg_box.height, _screen.height));
 
  224   if (x + width >= _screen.width) {
 
  225     width = _screen.width - x;
 
  227   if (width <= 0 || height <= 0) 
return;
 
  236   int string_height = 0;
 
  237   for (uint i = 0; i < count; i++) {
 
  242   string_height = 
min(string_height, MAX_CHAT_MESSAGES * (
FONT_HEIGHT_NORMAL + NETWORK_CHAT_LINE_SPACING));
 
  244   int top = _screen.height - _chatmsg_box.y - string_height - 2;
 
  245   int bottom = _screen.height - _chatmsg_box.y - 2;
 
  247   GfxFillRect(_chatmsg_box.x, top - 2, _chatmsg_box.x + _chatmsg_box.width - 1, bottom,
 
  252   int ypos = bottom - 2;
 
  254   for (
int i = count - 1; i >= 0; i--) {
 
  256     if (ypos < top) 
break;
 
  262   _chatmessage_visible = 
true;
 
  263   _chatmessage_dirty = 
false;
 
  303     static const StringID chat_captions[] = {
 
  304       STR_NETWORK_CHAT_ALL_CAPTION,
 
  305       STR_NETWORK_CHAT_COMPANY_CAPTION,
 
  306       STR_NETWORK_CHAT_CLIENT_CAPTION
 
  315     _chat_tab_completion_active = 
false;
 
  338     static char chat_tab_temp_buffer[64];
 
  360         GetString(chat_tab_temp_buffer, STR_TOWN_NAME, 
lastof(chat_tab_temp_buffer));
 
  361         return &chat_tab_temp_buffer[0];
 
  375     char *p = strrchr(buf, 
' ');
 
  376     if (p == NULL) 
return buf;
 
  393     char *tb_buf, *pre_buf;
 
  394     const char *cur_name;
 
  395     bool second_scan = 
false;
 
  403     tb_len  = strlen(tb_buf);
 
  408       if (_chat_tab_completion_active) {
 
  416           if (tb_buf == pre_buf) {
 
  418             length = (tb->
bytes - 1) - 2;
 
  421             offset = strlen(pre_buf) + 1;
 
  422             length = (tb->
bytes - 1) - offset;
 
  426           if (strlen(cur_name) == length && strncmp(cur_name, tb->
buf + offset, length) == 0) second_scan = 
true;
 
  434       len = strlen(cur_name);
 
  435       if (tb_len < len && strncasecmp(cur_name, tb_buf, tb_len) == 0) {
 
  437         if (!second_scan) 
seprintf(_chat_tab_completion_buf, 
lastof(_chat_tab_completion_buf), 
"%s", tb->
buf);
 
  438         _chat_tab_completion_active = 
true;
 
  441         if (pre_buf == tb_buf) {
 
  456       _chat_tab_completion_active = 
false;
 
  505     if (keycode == WKC_TAB) {
 
  514     _chat_tab_completion_active = 
false;
 
  524     if (data == this->
dest) 
delete this;
 
  534         NWidget(
WWT_TEXT, COLOUR_GREY, 
WID_NC_DESTINATION), 
SetMinimalSize(62, 12), 
SetPadding(1, 0, 1, 0), 
SetDataTip(STR_NULL, STR_NULL),
 
  535         NWidget(
WWT_EDITBOX, COLOUR_GREY, 
WID_NC_TEXTBOX), 
SetMinimalSize(100, 12), 
SetPadding(1, 0, 1, 0), 
SetResize(1, 0),
 
  536                                   SetDataTip(STR_NETWORK_CHAT_OSKTITLE, STR_NULL),
 
  537         NWidget(
WWT_PUSHTXTBTN, COLOUR_GREY, 
WID_NC_SENDBUTTON), 
SetMinimalSize(62, 12), 
SetPadding(1, 0, 1, 0), 
SetDataTip(STR_NETWORK_CHAT_SEND, STR_NULL),
 
  548   _nested_chat_window_widgets, 
lengthof(_nested_chat_window_widgets)