summaryrefslogtreecommitdiff
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
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
-rw-r--r--gui.h1
-rw-r--r--main_gui.c13
-rw-r--r--network_gui.c65
3 files changed, 29 insertions, 50 deletions
diff --git a/gui.h b/gui.h
index b291effc7..c6102a673 100644
--- a/gui.h
+++ b/gui.h
@@ -124,7 +124,6 @@ extern const byte _fios_colors[];
/* network gui */
void ShowNetworkGameWindow(void);
-void ShowChatWindow(void);
/* bridge_gui.c */
void ShowBuildBridgeWindow(uint start, uint end, byte type);
diff --git a/main_gui.c b/main_gui.c
index 71c77d001..d2389ec8b 100644
--- a/main_gui.c
+++ b/main_gui.c
@@ -77,12 +77,6 @@ void HandleOnEditText(WindowEvent *e)
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);
@@ -328,13 +322,6 @@ static void MenuClickBuildAir(int index)
#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;
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';