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 "../core/geometry_func.hpp"
29 #include "../widgets/network_chat_widget.h"
31 #include "table/strings.h"
33 #include "../safeguards.h"
71 if (_chatmsg_list[i].message[0] ==
'\0')
break;
88 va_start(va, message);
95 if (MAX_CHAT_MESSAGES == msg_count) {
96 memmove(&_chatmsg_list[0], &_chatmsg_list[1],
sizeof(_chatmsg_list[0]) * (msg_count - 1));
97 msg_count = MAX_CHAT_MESSAGES - 1;
105 _chatmessage_dirty =
true;
125 _chatmessage_visible =
false;
128 _chatmsg_list[i].
message[0] =
'\0';
146 _cursor.draw_pos.x + _cursor.
draw_size.x >= _chatmsg_box.x &&
147 _cursor.draw_pos.x <= _chatmsg_box.x + _chatmsg_box.width &&
148 _cursor.draw_pos.y + _cursor.
draw_size.y >= _screen.height - _chatmsg_box.y - _chatmsg_box.height &&
149 _cursor.draw_pos.y <= _screen.height - _chatmsg_box.y) {
153 if (_chatmessage_visible) {
155 int x = _chatmsg_box.x;
156 int y = _screen.height - _chatmsg_box.y - _chatmsg_box.height;
157 int width = _chatmsg_box.width;
158 int height = _chatmsg_box.height;
160 height =
max(height + y,
min(_chatmsg_box.height, _screen.height));
163 if (x + width >= _screen.width) {
164 width = _screen.width - x;
166 if (width <= 0 || height <= 0)
return;
168 _chatmessage_visible =
false;
174 _chatmessage_dirty =
true;
183 if (cmsg->
message[0] ==
'\0')
continue;
188 if (i != MAX_CHAT_MESSAGES - 1) memmove(cmsg, cmsg + 1,
sizeof(*cmsg) * (MAX_CHAT_MESSAGES - i - 1));
191 _chatmsg_list[MAX_CHAT_MESSAGES - 1].
message[0] =
'\0';
192 _chatmessage_dirty =
true;
204 if (!_chatmessage_dirty)
return;
213 if (count == 0)
return;
215 int x = _chatmsg_box.x;
216 int y = _screen.height - _chatmsg_box.y - _chatmsg_box.height;
217 int width = _chatmsg_box.width;
218 int height = _chatmsg_box.height;
220 height =
max(height + y,
min(_chatmsg_box.height, _screen.height));
223 if (x + width >= _screen.width) {
224 width = _screen.width - x;
226 if (width <= 0 || height <= 0)
return;
235 int string_height = 0;
236 for (uint i = 0; i < count; i++) {
241 string_height =
min(string_height, MAX_CHAT_MESSAGES * (
FONT_HEIGHT_NORMAL + NETWORK_CHAT_LINE_SPACING));
243 int top = _screen.height - _chatmsg_box.y - string_height - 2;
244 int bottom = _screen.height - _chatmsg_box.y - 2;
246 GfxFillRect(_chatmsg_box.x, top - 2, _chatmsg_box.x + _chatmsg_box.width - 1, bottom,
251 int ypos = bottom - 2;
253 for (
int i = count - 1; i >= 0; i--) {
255 if (ypos < top)
break;
261 _chatmessage_visible =
true;
262 _chatmessage_dirty =
false;
302 static const StringID chat_captions[] = {
303 STR_NETWORK_CHAT_ALL_CAPTION,
304 STR_NETWORK_CHAT_COMPANY_CAPTION,
305 STR_NETWORK_CHAT_CLIENT_CAPTION
314 _chat_tab_completion_active =
false;
332 static char chat_tab_temp_buffer[64];
354 GetString(chat_tab_temp_buffer, STR_TOWN_NAME,
lastof(chat_tab_temp_buffer));
355 return &chat_tab_temp_buffer[0];
369 char *p = strrchr(buf,
' ');
370 if (p == NULL)
return buf;
387 char *tb_buf, *pre_buf;
388 const char *cur_name;
389 bool second_scan =
false;
397 tb_len = strlen(tb_buf);
402 if (_chat_tab_completion_active) {
410 if (tb_buf == pre_buf) {
412 length = (tb->
bytes - 1) - 2;
415 offset = strlen(pre_buf) + 1;
416 length = (tb->
bytes - 1) - offset;
420 if (strlen(cur_name) == length && strncmp(cur_name, tb->
buf + offset, length) == 0) second_scan =
true;
428 len = strlen(cur_name);
429 if (tb_len < len && strncasecmp(cur_name, tb_buf, tb_len) == 0) {
431 if (!second_scan)
seprintf(_chat_tab_completion_buf,
lastof(_chat_tab_completion_buf),
"%s", tb->
buf);
432 _chat_tab_completion_active =
true;
435 if (pre_buf == tb_buf) {
450 _chat_tab_completion_active =
false;
499 if (keycode == WKC_TAB) {
508 _chat_tab_completion_active =
false;
518 if (data == this->
dest)
delete this;
528 NWidget(
WWT_TEXT, COLOUR_GREY,
WID_NC_DESTINATION),
SetMinimalSize(62, 12),
SetPadding(1, 0, 1, 0),
SetDataTip(STR_NULL, STR_NULL),
529 NWidget(
WWT_EDITBOX, COLOUR_GREY,
WID_NC_TEXTBOX),
SetMinimalSize(100, 12),
SetPadding(1, 0, 1, 0),
SetResize(1, 0),
530 SetDataTip(STR_NETWORK_CHAT_OSKTITLE, STR_NULL),
531 NWidget(
WWT_PUSHTXTBTN, COLOUR_GREY,
WID_NC_SENDBUTTON),
SetMinimalSize(62, 12),
SetPadding(1, 0, 1, 0),
SetDataTip(STR_NETWORK_CHAT_SEND, STR_NULL),
542 _nested_chat_window_widgets,
lengthof(_nested_chat_window_widgets)