summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortron <tron@openttd.org>2006-09-01 13:35:43 +0000
committertron <tron@openttd.org>2006-09-01 13:35:43 +0000
commit8ef52bc43c3afe9139aed61a64b023f5ca49101d (patch)
tree8390bc18a0b9bc901d95d47c600997066ebe0508
parent47b0d41d63b5e835d528f82a232d75a995e31fda (diff)
downloadopenttd-8ef52bc43c3afe9139aed61a64b023f5ca49101d.tar.xz
(svn r6297) -Codechange: Disentangle the query window mess a bit: Move the network game password handling somewhere were it belongs to
-rw-r--r--functions.h2
-rw-r--r--intro_gui.c2
-rw-r--r--main_gui.c27
-rw-r--r--network_client.c19
-rw-r--r--network_gui.c26
-rw-r--r--network_gui.h8
6 files changed, 43 insertions, 41 deletions
diff --git a/functions.h b/functions.h
index 5d81e8e51..2969fb2e1 100644
--- a/functions.h
+++ b/functions.h
@@ -196,8 +196,6 @@ void ChangeTownRating(Town *t, int add, int max);
uint GetTownRadiusGroup(const Town* t, TileIndex tile);
void ShowNetworkChatQueryWindow(byte desttype, byte dest);
void ShowNetworkGiveMoneyWindow(byte player);
-void ShowNetworkNeedGamePassword(void);
-void ShowNetworkNeedCompanyPassword(void);
int FindFirstBit(uint32 x);
void ShowHighscoreTable(int difficulty, int8 rank);
TileIndex AdjustTileCoordRandomly(TileIndex a, byte rng);
diff --git a/intro_gui.c b/intro_gui.c
index 0b4c81743..c10a3bc80 100644
--- a/intro_gui.c
+++ b/intro_gui.c
@@ -37,7 +37,6 @@ static const Widget _select_game_widgets[] = {
};
extern void HandleOnEditText(WindowEvent *e);
-extern void HandleOnEditTextCancel(void);
static inline void SetNewLandscapeType(byte landscape)
{
@@ -83,7 +82,6 @@ static void SelectGameWndProc(Window *w, WindowEvent *e)
break;
case WE_ON_EDIT_TEXT: HandleOnEditText(e); break;
- case WE_ON_EDIT_TEXT_CANCEL: HandleOnEditTextCancel(); break;
}
}
diff --git a/main_gui.c b/main_gui.c
index de3c9ec85..b0b8a93e2 100644
--- a/main_gui.c
+++ b/main_gui.c
@@ -47,17 +47,6 @@ static RailType _last_built_railtype;
extern void GenerateIndustries(void);
extern bool GenerateTowns(void);
-void HandleOnEditTextCancel(void)
-{
- switch (_rename_what) {
-#ifdef ENABLE_NETWORK
- case 4:
- NetworkDisconnect();
- ShowNetworkGameWindow();
- break;
-#endif /* ENABLE_NETWORK */
- }
-}
void HandleOnEditText(WindowEvent *e)
{
@@ -97,9 +86,6 @@ void HandleOnEditText(WindowEvent *e)
}
break;
}
- case 4: /* Game-Password and Company-Password */
- SEND_COMMAND(PACKET_CLIENT_PASSWORD)(id, e->edittext.str);
- break;
#endif /* ENABLE_NETWORK */
}
}
@@ -330,19 +316,6 @@ void ShowNetworkGiveMoneyWindow(byte player)
ShowQueryString(STR_EMPTY, STR_NETWORK_GIVE_MONEY_CAPTION, 30, 180, 1, 0, CS_NUMERAL);
}
-void ShowNetworkNeedGamePassword(void)
-{
- _rename_id = NETWORK_GAME_PASSWORD;
- _rename_what = 4;
- ShowQueryString(STR_EMPTY, STR_NETWORK_NEED_GAME_PASSWORD_CAPTION, 20, 180, WC_SELECT_GAME, 0, CS_ALPHANUMERAL);
-}
-
-void ShowNetworkNeedCompanyPassword(void)
-{
- _rename_id = NETWORK_COMPANY_PASSWORD;
- _rename_what = 4;
- ShowQueryString(STR_EMPTY, STR_NETWORK_NEED_COMPANY_PASSWORD_CAPTION, 20, 180, WC_SELECT_GAME, 0, CS_ALPHANUMERAL);
-}
#endif /* ENABLE_NETWORK */
diff --git a/network_client.c b/network_client.c
index d804715a8..db78632e3 100644
--- a/network_client.c
+++ b/network_client.c
@@ -13,6 +13,7 @@
#include "functions.h"
#include "network_client.h"
#include "network_gamelist.h"
+#include "network_gui.h"
#include "saveload.h"
#include "command.h"
#include "window.h"
@@ -423,18 +424,16 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_ERROR)
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_NEED_PASSWORD)
{
- NetworkPasswordType type;
- type = NetworkRecv_uint8(MY_CLIENT, p);
+ NetworkPasswordType type = NetworkRecv_uint8(MY_CLIENT, p);
- if (type == NETWORK_GAME_PASSWORD) {
- ShowNetworkNeedGamePassword();
- return NETWORK_RECV_STATUS_OKAY;
- } else if (type == NETWORK_COMPANY_PASSWORD) {
- ShowNetworkNeedCompanyPassword();
- return NETWORK_RECV_STATUS_OKAY;
- }
+ switch (type) {
+ case NETWORK_GAME_PASSWORD:
+ case NETWORK_COMPANY_PASSWORD:
+ ShowNetworkNeedPassword(type);
+ return NETWORK_RECV_STATUS_OKAY;
- return NETWORK_RECV_STATUS_MALFORMED_PACKET;
+ default: return NETWORK_RECV_STATUS_MALFORMED_PACKET;
+ }
}
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_WELCOME)
diff --git a/network_gui.c b/network_gui.c
index 95d9d5213..0d951afb1 100644
--- a/network_gui.c
+++ b/network_gui.c
@@ -1395,6 +1395,24 @@ void ShowClientList(void)
AllocateWindowDescFront(&_client_list_desc, 0);
}
+
+static NetworkPasswordType pw_type;
+
+
+void ShowNetworkNeedPassword(NetworkPasswordType npt)
+{
+ StringID caption;
+
+ pw_type = npt;
+ switch (npt) {
+ default: NOT_REACHED();
+ case NETWORK_GAME_PASSWORD: caption = STR_NETWORK_NEED_GAME_PASSWORD_CAPTION;
+ case NETWORK_COMPANY_PASSWORD: caption = STR_NETWORK_NEED_COMPANY_PASSWORD_CAPTION;
+ }
+ ShowQueryString(STR_EMPTY, caption, 20, 180, WC_NETWORK_STATUS_WINDOW, 0, CS_ALPHANUMERAL);
+}
+
+
static void NetworkJoinStatusWindowWndProc(Window *w, WindowEvent *e)
{
switch (e->event) {
@@ -1438,6 +1456,14 @@ static void NetworkJoinStatusWindowWndProc(Window *w, WindowEvent *e)
}
break;
+ case WE_ON_EDIT_TEXT_CANCEL:
+ NetworkDisconnect();
+ ShowNetworkGameWindow();
+ break;
+
+ case WE_ON_EDIT_TEXT:
+ SEND_COMMAND(PACKET_CLIENT_PASSWORD)(pw_type, e->edittext.str);
+ break;
}
}
diff --git a/network_gui.h b/network_gui.h
new file mode 100644
index 000000000..521ebc524
--- /dev/null
+++ b/network_gui.h
@@ -0,0 +1,8 @@
+/* $Id$ */
+
+#ifndef NETWORK_GUI_H
+#define NETWORK_GUI_H
+
+void ShowNetworkNeedPassword(NetworkPasswordType npt);
+
+#endif