diff options
Diffstat (limited to 'src/network/network_gui.cpp')
-rw-r--r-- | src/network/network_gui.cpp | 248 |
1 files changed, 0 insertions, 248 deletions
diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index 70ddccd92..d8ebfffea 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -15,11 +15,9 @@ #include "network_gamelist.h" #include "../gui.h" #include "../window_gui.h" -#include "../textbuf_gui.h" #include "../variables.h" #include "network_server.h" #include "network_udp.h" -#include "../town.h" #include "../newgrf.h" #include "../functions.h" #include "../window_func.h" @@ -37,8 +35,6 @@ #include "../table/sprites.h" -static bool _chat_tab_completion_active; - static void ShowNetworkStartServerWindow(); static void ShowNetworkLobbyWindow(NetworkGameList *ngl); extern void SwitchMode(int new_mode); @@ -1732,250 +1728,6 @@ void ShowJoinStatusWindow() new NetworkJoinStatusWindow(&_network_join_status_window_desc); } -static void SendChat(const char *buf, DestType type, int dest) -{ - if (StrEmpty(buf)) return; - if (!_network_server) { - SEND_COMMAND(PACKET_CLIENT_CHAT)((NetworkAction)(NETWORK_ACTION_CHAT + type), type, dest, buf); - } else { - NetworkServerSendChat((NetworkAction)(NETWORK_ACTION_CHAT + type), type, dest, buf, NETWORK_SERVER_INDEX); - } -} - - -struct NetworkChatWindow : public QueryStringBaseWindow { - DestType dtype; - int dest; - - NetworkChatWindow (const WindowDesc *desc, DestType type, int dest) : QueryStringBaseWindow(NETWORK_CHAT_LENGTH, desc) - { - this->LowerWidget(2); - this->dtype = type; - this->dest = dest; - this->afilter = CS_ALPHANUMERAL; - InitializeTextBuffer(&this->text, this->edit_str_buf, this->edit_str_size, 0); - - InvalidateWindowData(WC_NEWS_WINDOW, 0, this->height); - SetBit(_no_scroll, SCROLL_CHAT); // do not scroll the game with the arrow-keys - - _chat_tab_completion_active = false; - - this->FindWindowPlacementAndResize(desc); - } - - ~NetworkChatWindow () - { - InvalidateWindowData(WC_NEWS_WINDOW, 0, 0); - ClrBit(_no_scroll, SCROLL_CHAT); - } - - /** - * Find the next item of the list of things that can be auto-completed. - * @param item The current indexed item to return. This function can, and most - * likely will, alter item, to skip empty items in the arrays. - * @return Returns the char that matched to the index. - */ - const char *ChatTabCompletionNextItem(uint *item) - { - static char chat_tab_temp_buffer[64]; - - /* First, try clients */ - if (*item < MAX_CLIENT_INFO) { - /* Skip inactive clients */ - while (_network_client_info[*item].client_index == NETWORK_EMPTY_INDEX && *item < MAX_CLIENT_INFO) (*item)++; - if (*item < MAX_CLIENT_INFO) return _network_client_info[*item].client_name; - } - - /* Then, try townnames */ - /* Not that the following assumes all town indices are adjacent, ie no - * towns have been deleted. */ - if (*item <= (uint)MAX_CLIENT_INFO + GetMaxTownIndex()) { - const Town *t; - - FOR_ALL_TOWNS_FROM(t, *item - MAX_CLIENT_INFO) { - /* Get the town-name via the string-system */ - SetDParam(0, t->index); - GetString(chat_tab_temp_buffer, STR_TOWN, lastof(chat_tab_temp_buffer)); - return &chat_tab_temp_buffer[0]; - } - } - - return NULL; - } - - /** - * Find what text to complete. It scans for a space from the left and marks - * the word right from that as to complete. It also writes a \0 at the - * position of the space (if any). If nothing found, buf is returned. - */ - static char *ChatTabCompletionFindText(char *buf) - { - char *p = strrchr(buf, ' '); - if (p == NULL) return buf; - - *p = '\0'; - return p + 1; - } - - /** - * See if we can auto-complete the current text of the user. - */ - void ChatTabCompletion() - { - static char _chat_tab_completion_buf[NETWORK_CHAT_LENGTH]; - assert(this->edit_str_size == lengthof(_chat_tab_completion_buf)); - - Textbuf *tb = &this->text; - size_t len, tb_len; - uint item; - char *tb_buf, *pre_buf; - const char *cur_name; - bool second_scan = false; - - item = 0; - - /* Copy the buffer so we can modify it without damaging the real data */ - pre_buf = (_chat_tab_completion_active) ? strdup(_chat_tab_completion_buf) : strdup(tb->buf); - - tb_buf = ChatTabCompletionFindText(pre_buf); - tb_len = strlen(tb_buf); - - while ((cur_name = ChatTabCompletionNextItem(&item)) != NULL) { - item++; - - if (_chat_tab_completion_active) { - /* We are pressing TAB again on the same name, is there an other name - * that starts with this? */ - if (!second_scan) { - size_t offset; - size_t length; - - /* If we are completing at the begin of the line, skip the ': ' we added */ - if (tb_buf == pre_buf) { - offset = 0; - length = tb->length - 2; - } else { - /* Else, find the place we are completing at */ - offset = strlen(pre_buf) + 1; - length = tb->length - offset; - } - - /* Compare if we have a match */ - if (strlen(cur_name) == length && strncmp(cur_name, tb->buf + offset, length) == 0) second_scan = true; - - continue; - } - - /* Now any match we make on _chat_tab_completion_buf after this, is perfect */ - } - - len = strlen(cur_name); - if (tb_len < len && strncasecmp(cur_name, tb_buf, tb_len) == 0) { - /* Save the data it was before completion */ - if (!second_scan) snprintf(_chat_tab_completion_buf, lengthof(_chat_tab_completion_buf), "%s", tb->buf); - _chat_tab_completion_active = true; - - /* Change to the found name. Add ': ' if we are at the start of the line (pretty) */ - if (pre_buf == tb_buf) { - snprintf(tb->buf, this->edit_str_size, "%s: ", cur_name); - } else { - snprintf(tb->buf, this->edit_str_size, "%s %s", pre_buf, cur_name); - } - - /* Update the textbuffer */ - UpdateTextBufferSize(&this->text); - - this->SetDirty(); - free(pre_buf); - return; - } - } - - if (second_scan) { - /* We walked all posibilities, and the user presses tab again.. revert to original text */ - strcpy(tb->buf, _chat_tab_completion_buf); - _chat_tab_completion_active = false; - - /* Update the textbuffer */ - UpdateTextBufferSize(&this->text); - - this->SetDirty(); - } - free(pre_buf); - } - - virtual void OnPaint() - { - static const StringID chat_captions[] = { - STR_NETWORK_CHAT_ALL_CAPTION, - STR_NETWORK_CHAT_COMPANY_CAPTION, - STR_NETWORK_CHAT_CLIENT_CAPTION - }; - - this->DrawWidgets(); - - assert((uint)this->dtype < lengthof(chat_captions)); - DrawStringRightAligned(this->widget[2].left - 2, this->widget[2].top + 1, chat_captions[this->dtype], TC_BLACK); - this->DrawEditBox(2); - } - - virtual void OnClick(Point pt, int widget) - { - switch (widget) { - case 2: - ShowOnScreenKeyboard(this, 2, 0, 3); - break; - - case 3: /* Send */ - SendChat(this->text.buf, this->dtype, this->dest); - /* FALLTHROUGH */ - case 0: /* Cancel */ delete this; break; - } - } - - virtual void OnMouseLoop() - { - this->HandleEditBox(2); - } - - virtual EventState OnKeyPress(uint16 key, uint16 keycode) - { - EventState state = ES_NOT_HANDLED; - if (keycode == WKC_TAB) { - ChatTabCompletion(); - } else { - _chat_tab_completion_active = false; - switch (this->HandleEditBoxKey(2, key, keycode, state)) { - case 1: /* Return */ - SendChat(this->text.buf, this->dtype, this->dest); - /* FALLTHROUGH */ - case 2: /* Escape */ delete this; break; - } - } - return state; - } -}; - -static const Widget _chat_window_widgets[] = { -{ WWT_CLOSEBOX, RESIZE_NONE, COLOUR_GREY, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, -{ WWT_PANEL, RESIZE_RIGHT, COLOUR_GREY, 11, 319, 0, 13, 0x0, STR_NULL}, // background -{ WWT_EDITBOX, RESIZE_RIGHT, COLOUR_GREY, 75, 257, 1, 12, STR_NETWORK_CHAT_OSKTITLE, STR_NULL}, // text box -{ WWT_PUSHTXTBTN, RESIZE_LR, COLOUR_GREY, 258, 319, 1, 12, STR_NETWORK_SEND, STR_NULL}, // send button -{ WIDGETS_END}, -}; - -static const WindowDesc _chat_window_desc = { - WDP_CENTER, -26, 320, 14, 640, 14, // x, y, width, height - WC_SEND_NETWORK_MSG, WC_NONE, - WDF_STD_TOOLTIPS | WDF_DEF_WIDGET, - _chat_window_widgets, -}; - -void ShowNetworkChatQueryWindow(DestType type, int dest) -{ - DeleteWindowById(WC_SEND_NETWORK_MSG, 0); - new NetworkChatWindow (&_chat_window_desc, type, dest); -} /** Enum for NetworkGameWindow, referring to _network_game_window_widgets */ enum NetworkCompanyPasswordWindowWidgets { |