mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-01-22 23:26:34 +00:00
(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
This commit is contained in:
parent
88f9473c85
commit
260012382d
1
gui.h
1
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);
|
||||
|
13
main_gui.c
13
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;
|
||||
|
@ -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';
|
||||
|
Loading…
Reference in New Issue
Block a user