(svn r5282) -Backport: r5226 0.4
authortron
Thu, 15 Jun 2006 15:25:18 +0000
branch0.4
changeset 10036 1b119438cefb
parent 10035 23985f53225c
child 10037 bda27ca67908
(svn r5282) -Backport: r5226
-Fix: It was possible to rename signs or waypoints with the chat box
gui.h
main_gui.c
network_gui.c
--- a/gui.h	Thu Jun 15 14:45:03 2006 +0000
+++ b/gui.h	Thu Jun 15 15:25:18 2006 +0000
@@ -123,7 +123,6 @@
 
 /* network gui */
 void ShowNetworkGameWindow(void);
-void ShowChatWindow(void);
 
 /* bridge_gui.c */
 void ShowBuildBridgeWindow(uint start, uint end, byte type);
--- a/main_gui.c	Thu Jun 15 14:45:03 2006 +0000
+++ b/main_gui.c	Thu Jun 15 15:25:18 2006 +0000
@@ -76,12 +76,6 @@
 		DoCommandP(0, id, 0, NULL, CMD_RENAME_WAYPOINT | CMD_MSG(STR_CANT_CHANGE_WAYPOINT_NAME));
 		break;
 #ifdef ENABLE_NETWORK
-	case 2: /* Speak to.. */
-		if (!_network_server)
-			SEND_COMMAND(PACKET_CLIENT_CHAT)(NETWORK_ACTION_CHAT + (id & 0xFF), id & 0xFF, (id >> 8) & 0xFF, e->edittext.str);
-		else
-			NetworkServer_HandleChat(NETWORK_ACTION_CHAT + (id & 0xFF), id & 0xFF, (id >> 8) & 0xFF, e->edittext.str, NETWORK_SERVER_INDEX);
-		break;
 	case 3: { /* Give money, you can only give money in excess of loan */
 		const Player *p = GetPlayer(_current_player);
 		int32 money = min(p->money64 - p->current_loan, atoi(e->edittext.str) / _currency->rate);
@@ -327,13 +321,6 @@
 
 #ifdef ENABLE_NETWORK
 
-void ShowNetworkChatQueryWindow(byte desttype, byte dest)
-{
-	_rename_id = desttype + (dest << 8);
-	_rename_what = 2;
-	ShowChatWindow();
-}
-
 void ShowNetworkGiveMoneyWindow(byte player)
 {
 	_rename_id = player;
--- a/network_gui.c	Thu Jun 15 14:45:03 2006 +0000
+++ b/network_gui.c	Thu Jun 15 15:25:18 2006 +0000
@@ -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 @@
 }
 
 
+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 @@
 
 	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 @@
 	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';