41 #include "network_client.h" |
41 #include "network_client.h" |
42 #include "network_server.h" |
42 #include "network_server.h" |
43 #include "network_gui.h" |
43 #include "network_gui.h" |
44 #include "industry.h" |
44 #include "industry.h" |
45 |
45 |
46 static int _rename_id; |
46 static int _rename_id = 1; |
47 static int _rename_what; |
47 static int _rename_what = -1; |
48 |
48 |
49 static byte _terraform_size = 1; |
49 static byte _terraform_size = 1; |
50 RailType _last_built_railtype; |
50 RailType _last_built_railtype; |
51 static int _scengen_town_size = 2; // depress medium-sized towns per default |
51 static int _scengen_town_size = 2; // depress medium-sized towns per default |
52 |
52 |
53 extern void GenerateIndustries(void); |
53 extern void GenerateIndustries(void); |
54 extern bool GenerateTowns(void); |
54 extern bool GenerateTowns(void); |
55 |
55 |
56 |
56 |
57 void HandleOnEditText(WindowEvent *e) |
57 void HandleOnEditText(const char *str) |
58 { |
58 { |
59 const char *b = e->we.edittext.str; |
59 int id = _rename_id; |
60 int id; |
60 _cmd_text = str; |
61 |
|
62 _cmd_text = b; |
|
63 |
|
64 id = _rename_id; |
|
65 |
61 |
66 switch (_rename_what) { |
62 switch (_rename_what) { |
67 case 0: /* Rename a s sign, if string is empty, delete sign */ |
63 case 0: /* Rename a s sign, if string is empty, delete sign */ |
68 DoCommandP(0, id, 0, NULL, CMD_RENAME_SIGN | CMD_MSG(STR_280C_CAN_T_CHANGE_SIGN_NAME)); |
64 DoCommandP(0, id, 0, NULL, CMD_RENAME_SIGN | CMD_MSG(STR_280C_CAN_T_CHANGE_SIGN_NAME)); |
69 break; |
65 break; |
70 case 1: /* Rename a waypoint */ |
66 case 1: /* Rename a waypoint */ |
71 if (*b == '\0') return; |
67 if (*str == '\0') return; |
72 DoCommandP(0, id, 0, NULL, CMD_RENAME_WAYPOINT | CMD_MSG(STR_CANT_CHANGE_WAYPOINT_NAME)); |
68 DoCommandP(0, id, 0, NULL, CMD_RENAME_WAYPOINT | CMD_MSG(STR_CANT_CHANGE_WAYPOINT_NAME)); |
73 break; |
69 break; |
74 #ifdef ENABLE_NETWORK |
70 #ifdef ENABLE_NETWORK |
75 case 3: { /* Give money, you can only give money in excess of loan */ |
71 case 3: { /* Give money, you can only give money in excess of loan */ |
76 const Player *p = GetPlayer(_current_player); |
72 const Player *p = GetPlayer(_current_player); |
77 int32 money = min(p->money64 - p->current_loan, atoi(e->we.edittext.str) / _currency->rate); |
73 int32 money = min(p->money64 - p->current_loan, atoi(str) / _currency->rate); |
78 char msg[20]; |
74 char msg[20]; |
79 |
75 |
80 money = clamp(money, 0, 20000000); // Clamp between 20 million and 0 |
76 money = clamp(money, 0, 20000000); // Clamp between 20 million and 0 |
81 |
77 |
82 // Give 'id' the money, and substract it from ourself |
78 // Give 'id' the money, and substract it from ourself |
88 if (!_network_server) { |
84 if (!_network_server) { |
89 SEND_COMMAND(PACKET_CLIENT_CHAT)(NETWORK_ACTION_GIVE_MONEY, DESTTYPE_TEAM, id, msg); |
85 SEND_COMMAND(PACKET_CLIENT_CHAT)(NETWORK_ACTION_GIVE_MONEY, DESTTYPE_TEAM, id, msg); |
90 } else { |
86 } else { |
91 NetworkServer_HandleChat(NETWORK_ACTION_GIVE_MONEY, DESTTYPE_TEAM, id, msg, NETWORK_SERVER_INDEX); |
87 NetworkServer_HandleChat(NETWORK_ACTION_GIVE_MONEY, DESTTYPE_TEAM, id, msg, NETWORK_SERVER_INDEX); |
92 } |
88 } |
93 break; |
89 } break; |
94 } |
|
95 #endif /* ENABLE_NETWORK */ |
90 #endif /* ENABLE_NETWORK */ |
96 } |
91 default: NOT_REACHED(); |
|
92 } |
|
93 |
|
94 _rename_id = _rename_what = -1; |
97 } |
95 } |
98 |
96 |
99 /** |
97 /** |
100 * This code is shared for the majority of the pushbuttons. |
98 * This code is shared for the majority of the pushbuttons. |
101 * Handles e.g. the pressing of a button (to build things), playing of click sound and sets certain parameters |
99 * Handles e.g. the pressing of a button (to build things), playing of click sound and sets certain parameters |
307 #ifdef ENABLE_NETWORK |
305 #ifdef ENABLE_NETWORK |
308 void ShowNetworkGiveMoneyWindow(PlayerID player) |
306 void ShowNetworkGiveMoneyWindow(PlayerID player) |
309 { |
307 { |
310 _rename_id = player; |
308 _rename_id = player; |
311 _rename_what = 3; |
309 _rename_what = 3; |
312 ShowQueryString(STR_EMPTY, STR_NETWORK_GIVE_MONEY_CAPTION, 30, 180, 1, 0, CS_NUMERAL); |
310 ShowQueryString(STR_EMPTY, STR_NETWORK_GIVE_MONEY_CAPTION, 30, 180, NULL, CS_NUMERAL); |
313 } |
311 } |
314 #endif /* ENABLE_NETWORK */ |
312 #endif /* ENABLE_NETWORK */ |
315 |
313 |
316 void ShowRenameSignWindow(const Sign *si) |
314 void ShowRenameSignWindow(const Sign *si) |
317 { |
315 { |
318 _rename_id = si->index; |
316 _rename_id = si->index; |
319 _rename_what = 0; |
317 _rename_what = 0; |
320 ShowQueryString(si->str, STR_280B_EDIT_SIGN_TEXT, 30, 180, 1, 0, CS_ALPHANUMERAL); |
318 ShowQueryString(si->str, STR_280B_EDIT_SIGN_TEXT, 30, 180, NULL, CS_ALPHANUMERAL); |
321 } |
319 } |
322 |
320 |
323 void ShowRenameWaypointWindow(const Waypoint *wp) |
321 void ShowRenameWaypointWindow(const Waypoint *wp) |
324 { |
322 { |
325 int id = wp->index; |
323 int id = wp->index; |
1833 case WE_ABORT_PLACE_OBJ: { |
1831 case WE_ABORT_PLACE_OBJ: { |
1834 RaiseWindowWidget(w, 25); |
1832 RaiseWindowWidget(w, 25); |
1835 SetWindowDirty(w); |
1833 SetWindowDirty(w); |
1836 } break; |
1834 } break; |
1837 |
1835 |
1838 case WE_ON_EDIT_TEXT: HandleOnEditText(e); break; |
|
1839 |
|
1840 case WE_MOUSELOOP: |
1836 case WE_MOUSELOOP: |
1841 if (IsWindowWidgetLowered(w, 0) != !!_pause) { |
1837 if (IsWindowWidgetLowered(w, 0) != !!_pause) { |
1842 ToggleWidgetLoweredState(w, 0); |
1838 ToggleWidgetLoweredState(w, 0); |
1843 SetWindowDirty(w); |
1839 InvalidateWidget(w, 0); |
1844 } |
1840 } |
1845 |
1841 |
1846 if (IsWindowWidgetLowered(w, 1) != !!_fast_forward) { |
1842 if (IsWindowWidgetLowered(w, 1) != !!_fast_forward) { |
1847 ToggleWidgetLoweredState(w, 1); |
1843 ToggleWidgetLoweredState(w, 1); |
1848 SetWindowDirty(w); |
1844 InvalidateWidget(w, 1); |
1849 } |
1845 } |
1850 break; |
1846 break; |
1851 |
1847 |
1852 case WE_TIMEOUT: { |
1848 case WE_TIMEOUT: { |
1853 uint i; |
1849 uint i; |
2381 } |
2374 } |
2382 |
2375 |
2383 width = _screen.width; |
2376 width = _screen.width; |
2384 height = _screen.height; |
2377 height = _screen.height; |
2385 |
2378 |
|
2379 w = AllocateWindow(0, 0, width, height, MainWindowWndProc, WC_MAIN_WINDOW, NULL); |
|
2380 AssignWindowViewport(w, 0, 0, width, height, TileXY(32, 32), 0); |
|
2381 |
2386 // XXX: these are not done |
2382 // XXX: these are not done |
2387 switch (_game_mode) { |
2383 switch (_game_mode) { |
2388 case GM_MENU: |
2384 default: NOT_REACHED(); |
2389 w = AllocateWindow(0, 0, width, height, MainWindowWndProc, WC_MAIN_WINDOW, NULL); |
2385 case GM_MENU: |
2390 AssignWindowViewport(w, 0, 0, width, height, TileXY(32, 32), 0); |
2386 ShowSelectGameWindow(); |
2391 ShowSelectGameWindow(); |
2387 break; |
2392 break; |
2388 |
2393 case GM_NORMAL: |
2389 case GM_NORMAL: |
2394 w = AllocateWindow(0, 0, width, height, MainWindowWndProc, WC_MAIN_WINDOW, NULL); |
2390 case GM_EDITOR: |
2395 AssignWindowViewport(w, 0, 0, width, height, TileXY(32, 32), 0); |
2391 ShowVitalWindows(); |
2396 |
2392 break; |
2397 ShowVitalWindows(); |
|
2398 |
|
2399 /* Bring joining GUI to front till the client is really joined */ |
|
2400 if (_networking && !_network_server) |
|
2401 ShowJoinStatusWindowAfterJoin(); |
|
2402 |
|
2403 break; |
|
2404 case GM_EDITOR: |
|
2405 w = AllocateWindow(0, 0, width, height, MainWindowWndProc, WC_MAIN_WINDOW, NULL); |
|
2406 AssignWindowViewport(w, 0, 0, width, height, 0, 0); |
|
2407 |
|
2408 ShowVitalWindows(); |
|
2409 break; |
|
2410 default: |
|
2411 NOT_REACHED(); |
|
2412 } |
2393 } |
2413 } |
2394 } |
2414 |
2395 |
2415 void ShowVitalWindows(void) |
2396 void ShowVitalWindows(void) |
2416 { |
2397 { |