summaryrefslogtreecommitdiff
path: root/network_gui.c
diff options
context:
space:
mode:
authortron <tron@openttd.org>2006-06-11 16:00:56 +0000
committertron <tron@openttd.org>2006-06-11 16:00:56 +0000
commit260012382d07ef38bcc8f58bb4c8f6aadbf6d371 (patch)
tree8231e06357f55a4c8d55761c3c11601f2b1d7285 /network_gui.c
parent88f9473c85661a3ca7a53d2d3d71efd2dc0b242b (diff)
downloadopenttd-260012382d07ef38bcc8f58bb4c8f6aadbf6d371.tar.xz
(svn r5226) Reduce the mess that sending chat messages is
This also fixes a bug: -Fix: It was possible to rename a signs or waypoints with the chat box
Diffstat (limited to 'network_gui.c')
-rw-r--r--network_gui.c65
1 files changed, 29 insertions, 36 deletions
diff --git a/network_gui.c b/network_gui.c
index a1ed5c386..79136f8dd 100644
--- a/network_gui.c
+++ b/network_gui.c
@@ -14,6 +14,7 @@
#include "table/strings.h"
#include "functions.h"
#include "network_data.h"
+#include "network_client.h"
#include "network_gamelist.h"
#include "window.h"
#include "gui.h"
@@ -1464,6 +1465,21 @@ void ShowJoinStatusWindowAfterJoin(void)
}
+static byte _chat_type;
+static byte _chat_dest;
+
+
+static void SendChat(const char* buf)
+{
+ if (buf[0] == '\0') return;
+ if (!_network_server) {
+ SEND_COMMAND(PACKET_CLIENT_CHAT)(NETWORK_ACTION_CHAT + _chat_type, _chat_type, _chat_dest, buf);
+ } else {
+ NetworkServer_HandleChat(NETWORK_ACTION_CHAT + _chat_type, _chat_type, _chat_dest, buf, NETWORK_SERVER_INDEX);
+ }
+}
+
+
/* uses querystr_d WP macro */
static void ChatWindowWndProc(Window *w, WindowEvent *e)
{
@@ -1480,48 +1496,21 @@ static void ChatWindowWndProc(Window *w, WindowEvent *e)
case WE_CLICK:
switch (e->click.widget) {
- case 3: DeleteWindow(w); break; // Cancel
- case 2: // Send
-press_ok:;
- if (WP(w, querystr_d).text.buf[0] == '\0') {
- DeleteWindow(w);
- } else {
- char *buf = WP(w, querystr_d).text.buf;
- WindowClass wnd_class = WP(w, querystr_d).wnd_class;
- WindowNumber wnd_num = WP(w, querystr_d).wnd_num;
- Window *parent;
-
- DeleteWindow(w);
-
- parent = FindWindowById(wnd_class, wnd_num);
- if (parent != NULL) {
- WindowEvent e;
- e.event = WE_ON_EDIT_TEXT;
- e.edittext.str = buf;
- parent->wndproc(parent, &e);
- }
- }
- break;
+ case 2: /* Send */ SendChat(WP(w, querystr_d).text.buf); /* FALLTHROUGH */
+ case 3: /* Cancel */ DeleteWindow(w); break;
}
break;
- case WE_MOUSELOOP: {
- if (!FindWindowById(WP(w,querystr_d).wnd_class, WP(w,querystr_d).wnd_num)) {
- DeleteWindow(w);
- return;
- }
+ case WE_MOUSELOOP:
HandleEditBox(w, &WP(w, querystr_d), 1);
- } break;
+ break;
- case WE_KEYPRESS: {
+ case WE_KEYPRESS:
switch (HandleEditBoxKey(w, &WP(w, querystr_d), 1, e)) {
- case 1: // Return
- goto press_ok;
- case 2: // Escape
- DeleteWindow(w);
- break;
+ case 1: /* Return */ SendChat(WP(w, querystr_d).text.buf); /* FALLTHROUGH */
+ case 2: /* Escape */ DeleteWindow(w); break;
}
- } break;
+ break;
case WE_DESTROY:
SendWindowMessage(WC_NEWS_WINDOW, 0, WE_DESTROY, 0, 0);
@@ -1546,10 +1535,14 @@ static const WindowDesc _chat_window_desc = {
ChatWindowWndProc
};
-void ShowChatWindow(void)
+
+void ShowNetworkChatQueryWindow(byte desttype, byte dest)
{
Window *w;
+ _chat_type = desttype;
+ _chat_dest = dest;
+
DeleteWindowById(WC_SEND_NETWORK_MSG, 0);
_edit_str_buf[0] = '\0';