Debian Codegraph @

netgames/dmfc/dmfcui.cpp

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 --- HISTORICAL COMMENTS FOLLOW ---
19
20 * $Logfile: /DescentIII/Main/Dmfc/dmfcui.cpp $
21 * $Revision: 1.1.1.1 $
22 * $Date: 2003/08/26 03:57:21 $
23 * $Author: kevinb $
24 *
25 * UI Code for DMFC dialogs
26 *
27 * $Log: dmfcui.cpp,v $
28 * Revision 1.1.1.1 2003/08/26 03:57:21 kevinb
29 * initial 1.5 import
30 *
31 *
32 * 26 7/09/99 2:54p Jeff
33 * handle gametime better (pause it when needed) if the server is 'waiting
34 * for players'
35 *
36 * 25 5/19/99 2:40a Jeff
37 * use correct calls of NewUIGameWindow
38 *
39 * 24 5/18/99 7:14p Jeff
40 * error checking
41 *
42 * 23 4/27/99 12:36p Jeff
43 * fixed dialog due to new art
44 *
45 * 22 4/24/99 11:13p Jeff
46 * added flags for creating a newui window for a title bar
47 *
48 * 21 4/09/99 3:28p Jeff
49 * fixed some bugs in wait for players dlg
50 *
51 * 20 4/03/99 9:26p Jeff
52 * changed dialogs that weren't using UID_OK and UID_CANCEL to use and
53 * handle them properly
54 *
55 * 19 3/17/99 12:25p Jeff
56 * converted DMFC to be COM interface
57 *
58 * 18 2/11/99 12:51a Jeff
59 * changed names of exported variables
60 *
61 * 17 2/09/99 3:32p Jeff
62 * table file parser takes quotes strings for force keywords
63 *
64 * 16 2/07/99 1:18a Jeff
65 * peppered UI dialogs that were missing NEWUIRES_FORCEQUIT to handle it
66 *
67 * 15 2/05/99 8:24p Jeff
68 * added table file parser macros
69 *
70 * 14 1/19/99 3:55a Jeff
71 * all strings localized out
72 *
73 * 13 1/14/99 7:55p Jeff
74 * changed icons for team selection dialog, added real powerball
75 *
76 * 12 1/12/99 2:55p Jeff
77 * added/finished the waiting for player's to join dialog
78 *
79 * 11 1/11/99 6:54p Jeff
80 * fixed bug with wait4player dialog
81 *
82 * 10 1/10/99 7:41p Jeff
83 * added initial version of waitforplayers dialog
84 *
85 * 9 12/08/98 3:29p Jeff
86 * updated the team control dialog so the server can determine if they
87 * want to make the clients wait
88 *
89 * 8 12/08/98 12:17p Jeff
90 * various changes that include an improved Team Control dialog (doesn't
91 * switch teams until exit..) and spew/respawn players that change teams
92 *
93 * 7 11/19/98 5:56p Jeff
94 * added slider exported and improved Hoard
95 *
96 * 6 11/17/98 6:29p Jeff
97 * mod can specify whether or not to display the team setup dialog on team
98 * game start. Added a menu item to display team setup dialog in mid-game
99 *
100 * 5 11/17/98 12:35p Jeff
101 * fixed bug where team placement window didn't update second time
102 * displayed
103 *
104 * 4 11/16/98 5:35p Jeff
105 * removed log functions, added support for changing team names, fixed ctf
106 * to work better with different team names
107 *
108 * 3 11/11/98 7:19p Jeff
109 * changes made so that a dedicated server's team is always -1 (team game
110 * or not)
111 *
112 * 2 10/29/98 7:01p Jeff
113 * creation of team placement dialog. Moved TranslateEvent into DMFC
114 *
115 * $NoKeywords: $
116 */
117
118 #include "gamedll_header.h"
119 #include "DMFC.h"
120 #include "dmfcinternal.h"
121
122 extern DMFCBase *basethis;
123
124 struct tTeamPlacementDialogInfo {
125 void *lb[DLLMAX_TEAMS];
126 void *text[DLLMAX_PLAYERS];
127 int trans[DLLMAX_TEAMS][DLLMAX_PLAYERS];
128 void (*old_callback)();
129 };
130 tTeamPlacementDialogInfo tpdi;
131
132 #define TS_NOTINGAME -2
133 int8_t TeamDlgInitialTeamSettings[DLLMAX_PLAYERS];
134 int8_t TeamDlgFinalTeamSettings[DLLMAX_PLAYERS];
135
136 // UpdateTeamPlacementDialog
137 //
138 // Call to update the listboxes, etc in the team placement
139 void UpdateTeamPlacementDialog(void) {
140 int selected_num[DLLMAX_TEAMS];
141 int i;
142
143 for (i = 0; i < DLLMAX_TEAMS; i++) {
144 selected_num[i] = -1;
145
146 // remove everything from the listboxes
147 // save the selected names, and reselect them if they are on the same listbox
148 if (tpdi.lb[i]) {
149 int sel = DLLListGetSelectedIndex(tpdi.lb[i]);
150
151 if (sel >= 0 && sel < DLLMAX_PLAYERS)
152 selected_num[i] = tpdi.trans[i][sel];
153
154 DLLListRemoveAll(tpdi.lb[i]);
155 }
156 }
157
158 int curr_lb_count[DLLMAX_TEAMS];
159 for (i = 0; i < DLLMAX_TEAMS; i++) {
160 curr_lb_count[i] = 0;
161 for (int p = 0; p < DLLMAX_PLAYERS; p++) {
162 tpdi.trans[i][p] = -1;
163 }
164 }
165
166 // now rebuild the listboxes with correct placement
167 for (i = 0; i < DLLMAX_PLAYERS; i++) {
168
169 if (tpdi.text[i]) {
170 DLLRemoveUITextItem(tpdi.text[i]);
171 tpdi.text[i] = NULL;
172 }
173
174 // as we go through all the players, we need to update the trans[][]
175 if (basethis->CheckPlayerNum(i)) {
176 // the player is in the game, get their team
177 int team;
178
179 if (TeamDlgFinalTeamSettings[i] != TS_NOTINGAME) {
180 // ok this guy was in the game when the dialog first got displayed, so
181 // use his current status, and not his real team
182 team = TeamDlgFinalTeamSettings[i];
183 } else {
184 // he wasn't in the game to start and his team hasn't changed yet
185 team = basethis->GetPlayerTeam(i);
186 }
187
188 // add them to a team
189 if (tpdi.lb[team]) {
190 tpdi.text[i] = DLLCreateNewUITextItem(basethis->Players[i].callsign, basethis->GetTeamColor(team), -1);
191 if (tpdi.text[i]) {
192 DLLListAddItem(tpdi.lb[team], tpdi.text[i]);
193 tpdi.trans[team][curr_lb_count[team]] = i; // update the translator
194 curr_lb_count[team]++;
195 } else
196 mprintf(0, "Couldn't create text item\n");
197 } else {
198 mprintf(0, "Listbox not valid!\n");
199 }
200 } else {
201 TeamDlgInitialTeamSettings[i] = TeamDlgFinalTeamSettings[i] = TS_NOTINGAME;
202 }
203 }
204
205 // go through all the listboxes, and reselect previously selected
206 for (i = 0; i < DLLMAX_TEAMS; i++) {
207 if (selected_num[i] != -1 && basethis->CheckPlayerNum(selected_num[i])) {
208
209 if (((TeamDlgFinalTeamSettings[selected_num[i]] == TS_NOTINGAME) &&
210 (basethis->GetPlayerTeam(selected_num[i]) == i)) ||
211 (TeamDlgFinalTeamSettings[selected_num[i]] == i)) {
212 // this player was on this team last update, is still on the team, is a valid player in the game and was
213 // selected so select them again
214 for (int j = 0; j < DLLMAX_PLAYERS; j++) {
215 if (tpdi.trans[i][j] == selected_num[i]) {
216 // we found em, reselect
217 if (tpdi.lb[i]) {
218 DLLListSetSelectedIndex(tpdi.lb[i], j);
219 }
220 break;
221 }
222 }
223 }
224 }
225 }
226 }
227
228 static float Team_placement_lastcall = 0;
229 void TeamPlacementCallback(void) {
230 float time = *basethis->Gametime;
231
232 if (time > Team_placement_lastcall + 0.5f) {
233 UpdateTeamPlacementDialog();
234 Team_placement_lastcall = time;
235 }
236
237 if (tpdi.old_callback)
238 (*tpdi.old_callback)();
239 }
240
241 void TeamPlacementChangeTeam(int old_team, int new_team) {
242 int sel = DLLListGetSelectedIndex(tpdi.lb[old_team]);
243 if (sel < 0)
244 return;
245
246 int pnum = tpdi.trans[old_team][sel];
247 if (!basethis->CheckPlayerNum(pnum)) {
248 TeamDlgInitialTeamSettings[pnum] = TeamDlgFinalTeamSettings[pnum] = TS_NOTINGAME;
249 return;
250 }
251
252 TeamDlgFinalTeamSettings[pnum] = new_team;
253 }
254
255 #define REDTOBLUE 0xC0
256 #define REDTOGREEN 0xC1
257 #define REDTOYELLOW 0xC2
258 #define BLUETORED 0xC3
259 #define BLUETOGREEN 0xC4
260 #define BLUETOYELLOW 0xC5
261 #define GREENTORED 0xC6
262 #define GREENTOBLUE 0xC7
263 #define GREENTOYELLOW 0xC8
264 #define YELLOWTORED 0xC9
265 #define YELLOWTOBLUE 0xCA
266 #define YELLOWTOGREEN 0xCB
267
268 // DMFCBase::DoDMFCUITeamPlacement
269 //
270 // Displays the dialog for doing team placement in DMFC
271 void DMFCBase::DoDMFCUITeamPlacement(bool clients_wait, bool called_by_level_start) {
272 if (GetLocalRole() != LR_SERVER)
273 return;
274
275 if (IAmDedicatedServer())
276 return;
277
278 Team_placement_lastcall = 0;
279
280 // turn on client waiting
281 if (clients_wait) {
282 // Pause realgametime,
283 ENABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_PAUSETIME);
284 SendControlMessageToPlayer(SP_ALL, CM_PAUSETIME);
285 MakeClientsWait(true);
286 }
287
288 int i;
289
290 // build the initial team list, so we know what players changed teams in the process
291 for (i = 0; i < DLLMAX_PLAYERS; i++) {
292 if (CheckPlayerNum(i)) {
293 TeamDlgFinalTeamSettings[i] = TeamDlgInitialTeamSettings[i] = Players[i].team;
294 } else {
295 TeamDlgFinalTeamSettings[i] = TeamDlgInitialTeamSettings[i] = TS_NOTINGAME;
296 }
297 }
298
299 bool exit_menu = false;
300 void *list_red = NULL, *list_blue = NULL, *list_green = NULL, *list_yellow = NULL;
301 void *icon_b_hs[DLLMAX_TEAMS][DLLMAX_TEAMS - 1];
302 void *icon_hs[DLLMAX_TEAMS][DLLMAX_TEAMS - 1];
303 void *team_text[DLLMAX_TEAMS];
304
305 int count;
306 int id_list[DLLMAX_TEAMS * (DLLMAX_TEAMS - 1)];
307
308 int team_icons[DLLMAX_TEAMS];
309 const char *team_icon_names[DLLMAX_TEAMS] = {"toredteamicon.ogf", "toblueteamicon.ogf", "togreenteamicon.ogf", "toyellowteamicon.ogf"};
310 /*
311 $$TABLE_GAMEFILE "toredteamicon.ogf"
312 $$TABLE_GAMEFILE "toblueteamicon.ogf"
313 $$TABLE_GAMEFILE "togreenteamicon.ogf"
314 $$TABLE_GAMEFILE "toyellowteamicon.ogf"
315 */
316 for (i = 0; i < DLLMAX_TEAMS; i++) {
317 team_icons[i] = DLLbm_AllocLoadFileBitmap(IGNORE_TABLE(team_icon_names[i]), 0, BITMAP_FORMAT_1555);
318 if (team_icons[i] <= BAD_BITMAP_HANDLE)
319 team_icons[i] = BAD_BITMAP_HANDLE;
320 }
321
322 for (i = 0; i < DLLMAX_TEAMS; i++) {
323 count = 0;
324 for (int j = 0; j < DLLMAX_TEAMS; j++) {
325 if (i != j) {
326 icon_b_hs[i][count] = DLLCreateNewUIBmpItem(team_icons[j], 255);
327 icon_hs[i][count] = NULL;
328 count++;
329 }
330 }
331 }
332
333 for (i = 0; i < DLLMAX_TEAMS * (DLLMAX_TEAMS - 1); i++) {
334 id_list[i] = 0xC0 + i;
335 }
336
337 for (i = 0; i < DLLMAX_TEAMS; i++) {
338 team_text[i] = NULL;
339 }
340
341 //////////////////////////////////////////////////
342 // Text Items
343 void *start_game_text_off =
344 DLLCreateNewUITextItem((called_by_level_start) ? DTXT_UI_STARTGAME : DTXT_UI_RETURNTOGAME, UICOL_HOTSPOT_LO, -1);
345 void *start_game_text_on =
346 DLLCreateNewUITextItem((called_by_level_start) ? DTXT_UI_STARTGAME : DTXT_UI_RETURNTOGAME, UICOL_HOTSPOT_HI, -1);
347 void *client_wait_txt = DLLCreateNewUITextItem(DTXT_UI_CLIENTSWAIT, UICOL_HOTSPOT_LO, -1);
348 void *window_title = DLLCreateNewUITextItem(DTXT_UI_TEAMSETUP, UICOL_WINDOW_TITLE, -1);
349
350 ///////////////////////////////////////////////////
351 // Main Window
352 void *main_wnd = DLLNewUIGameWindowCreate(0, 0, 512, 384, UIF_PROCESS_ALL | UIF_CENTER | NUWF_TITLEMED);
353
354 ///////////////////////////////////////////////////
355 // Item placement
356 int cury;
357 count = GetNumTeams();
358
359 void *start_game_hs = DLLHotSpotCreate(main_wnd, UID_OK, K_ENTER, start_game_text_off, start_game_text_on, 40,
360 384 - OKCANCEL_YOFFSET, 130, 15, UIF_CENTER);
361 void *window_title_text = DLLTextCreate(main_wnd, window_title, 0, 7, UIF_CENTER | UIF_FIT);
362 void *client_wait_cb;
363
364 if (count > 2) {
365 client_wait_cb = DLLCheckBoxCreate(main_wnd, 128, client_wait_txt, 256 - (DLLGetUIItemWidth(client_wait_txt) / 2),
366 192 - (DLLGetUIItemHeight(client_wait_txt) / 2), 130, 15, UIF_FIT);
367 cury = 60;
368 } else {
369 client_wait_cb = DLLCheckBoxCreate(main_wnd, 128, client_wait_txt, 30, 384 - OKCANCEL_YOFFSET, 130, 15, UIF_FIT);
370 cury = 80;
371 }
372
373 DLLCheckBoxSetCheck(client_wait_cb, clients_wait);
374
375 int left_x, right_x;
376 int top_y, bottom_y;
377 int icon_width = DLLbm_w(team_icons[0], 0);
378 int icon_height = DLLbm_h(team_icons[0], 0);
379 int curr_y;
380 int *id_list_ptr;
381
382 left_x = 168 + 10;
383 right_x = 512 - 178 - icon_width;
384
385 int total_height = (count - 1) * (icon_height + 3);
386 top_y = cury + (64 - (total_height / 2));
387 bottom_y = cury + 163 + (64 - (total_height / 2));
388
389 switch (count) {
390 case 4:
391 list_yellow = DLLListCreate(main_wnd, 1, 512 - 168, cury + 163, 128, 128, 0);
392 team_text[YELLOW_TEAM] = DLLEditCreate(main_wnd, -1, 512 - 168, cury + 131, 128, 32, 0);
393
394 // put in the hotspots for yellow
395 curr_y = bottom_y;
396 id_list_ptr = &id_list[YELLOW_TEAM * (DLLMAX_TEAMS - 1)];
397 for (i = 0; i < count - 1; i++) {
398 icon_hs[YELLOW_TEAM][i] =
399 DLLHotSpotCreate(main_wnd, id_list_ptr[i], -1, icon_b_hs[YELLOW_TEAM][i], icon_b_hs[YELLOW_TEAM][i], right_x,
400 curr_y, icon_width, icon_height, 0);
401 curr_y += icon_height + 3;
402 }
403 case 3:
404 list_green = DLLListCreate(main_wnd, 1, 40, cury + 163, 128, 128, 0);
405 team_text[GREEN_TEAM] = DLLEditCreate(main_wnd, -1, 40, cury + 131, 128, 32, 0);
406
407 list_red = DLLListCreate(main_wnd, 0, 40, cury, 128, 128, 0);
408 team_text[RED_TEAM] = DLLEditCreate(main_wnd, -1, 40, cury - 32, 128, 32, 0);
409
410 list_blue = DLLListCreate(main_wnd, 1, 512 - 168, cury, 128, 128, 0);
411 team_text[BLUE_TEAM] = DLLEditCreate(main_wnd, -1, 512 - 168, cury - 32, 128, 32, 0);
412
413 // put in the hotspots for green
414 curr_y = bottom_y;
415 id_list_ptr = &id_list[GREEN_TEAM * (DLLMAX_TEAMS - 1)];
416 for (i = 0; i < count - 1; i++) {
417 icon_hs[GREEN_TEAM][i] = DLLHotSpotCreate(main_wnd, id_list_ptr[i], -1, icon_b_hs[GREEN_TEAM][i],
418 icon_b_hs[GREEN_TEAM][i], left_x, curr_y, icon_width, icon_height, 0);
419 curr_y += icon_height + 3;
420 }
421
422 // put in the hotspots for blue
423 curr_y = top_y;
424 id_list_ptr = &id_list[BLUE_TEAM * (DLLMAX_TEAMS - 1)];
425 for (i = 0; i < count - 1; i++) {
426 icon_hs[BLUE_TEAM][i] = DLLHotSpotCreate(main_wnd, id_list_ptr[i], -1, icon_b_hs[BLUE_TEAM][i],
427 icon_b_hs[BLUE_TEAM][i], right_x, curr_y, icon_width, icon_height, 0);
428 curr_y += icon_height + 3;
429 }
430
431 // put in the hotspots for red
432 curr_y = top_y;
433 id_list_ptr = &id_list[RED_TEAM * (DLLMAX_TEAMS - 1)];
434 for (i = 0; i < count - 1; i++) {
435 icon_hs[RED_TEAM][i] = DLLHotSpotCreate(main_wnd, id_list_ptr[i], -1, icon_b_hs[RED_TEAM][i],
436 icon_b_hs[RED_TEAM][i], left_x, curr_y, icon_width, icon_height, 0);
437 curr_y += icon_height + 3;
438 }
439
440 break;
441 case 2:
442 list_red = DLLListCreate(main_wnd, 0, 40, cury, 128, 224, 0);
443 team_text[RED_TEAM] = DLLEditCreate(main_wnd, -1, 40, cury - 32, 128, 32, 0);
444
445 list_blue = DLLListCreate(main_wnd, 1, 512 - 168, cury, 128, 224, 0);
446 team_text[BLUE_TEAM] = DLLEditCreate(main_wnd, -1, 512 - 168, cury - 32, 128, 32, 0);
447
448 // recalc the top y value
449 top_y = cury + (118 - (total_height / 2));
450
451 // put in the hotspots for blue
452 curr_y = top_y;
453 id_list_ptr = &id_list[BLUE_TEAM * (DLLMAX_TEAMS - 1)];
454 for (i = 0; i < count - 1; i++) {
455 icon_hs[BLUE_TEAM][i] = DLLHotSpotCreate(main_wnd, id_list_ptr[i], -1, icon_b_hs[BLUE_TEAM][i],
456 icon_b_hs[BLUE_TEAM][i], right_x, curr_y, icon_width, icon_height, 0);
457 curr_y += icon_height + 3;
458 }
459
460 // put in the hotspots for red
461 curr_y = top_y;
462 id_list_ptr = &id_list[RED_TEAM * (DLLMAX_TEAMS - 1)];
463 for (i = 0; i < count - 1; i++) {
464 icon_hs[RED_TEAM][i] = DLLHotSpotCreate(main_wnd, id_list_ptr[i], -1, icon_b_hs[RED_TEAM][i],
465 icon_b_hs[RED_TEAM][i], left_x, curr_y, icon_width, icon_height, 0);
466 curr_y += icon_height + 3;
467 }
468
469 break;
470 case 0:
471 case 1:
472 // the wait is over, let them in
473 if (clients_wait) {
474 // UnPause realgametime,
475 DISABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_PAUSETIME);
476 SendControlMessageToPlayer(SP_ALL, CM_UNPAUSETIME);
477 MakeClientsWait(false);
478 }
479
480 // Unpause realgametime,
481 DISABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_PAUSETIME);
482 SendControlMessageToPlayer(SP_ALL, CM_UNPAUSETIME);
483 return;
484 break;
485 }
486
487 // Set information for the team name edit boxes
488 for (i = 0; i < DLLMAX_TEAMS; i++) {
489 if (team_text[i]) {
490 DLLSetOldEditBufferLen(team_text[i], MAX_TEAMNAME_LEN - 1);
491 DLLEditSetText(team_text[i], DMFC_team_names[i]);
492 }
493 }
494
495 tpdi.lb[RED_TEAM] = list_red;
496 tpdi.lb[BLUE_TEAM] = list_blue;
497 tpdi.lb[GREEN_TEAM] = list_green;
498 tpdi.lb[YELLOW_TEAM] = list_yellow;
499 for (i = 0; i < DLLMAX_PLAYERS; i++) {
500 tpdi.text[i] = NULL;
501 for (int t = 0; t < DLLMAX_TEAMS; t++) {
502 tpdi.trans[t][i] = -1;
503 }
504 }
505 DLLGetUICallback((void **)&tpdi.old_callback);
506 DLLSetUICallback(TeamPlacementCallback);
507
508 //////////////////////////////////////////////////
509 // Process all
510 DLLNewUIGameWindowOpen(main_wnd);
511
512 UpdateTeamPlacementDialog();
513
514 bool canceled = false;
515
516 while (!exit_menu) {
517 int res;
518 res = DLLPollUI();
519
520 if (res == -1)
521 continue;
522
523 // handle all UI results.
524 switch (res) {
525 case REDTOBLUE:
526 TeamPlacementChangeTeam(RED_TEAM, BLUE_TEAM);
527 UpdateTeamPlacementDialog();
528 break;
529 case REDTOGREEN:
530 TeamPlacementChangeTeam(RED_TEAM, GREEN_TEAM);
531 UpdateTeamPlacementDialog();
532 break;
533 case REDTOYELLOW:
534 TeamPlacementChangeTeam(RED_TEAM, YELLOW_TEAM);
535 UpdateTeamPlacementDialog();
536 break;
537 case BLUETORED:
538 TeamPlacementChangeTeam(BLUE_TEAM, RED_TEAM);
539 UpdateTeamPlacementDialog();
540 break;
541 case BLUETOGREEN:
542 TeamPlacementChangeTeam(BLUE_TEAM, GREEN_TEAM);
543 UpdateTeamPlacementDialog();
544 break;
545 case BLUETOYELLOW:
546 TeamPlacementChangeTeam(BLUE_TEAM, YELLOW_TEAM);
547 UpdateTeamPlacementDialog();
548 break;
549 case GREENTORED:
550 TeamPlacementChangeTeam(GREEN_TEAM, RED_TEAM);
551 UpdateTeamPlacementDialog();
552 break;
553 case GREENTOBLUE:
554 TeamPlacementChangeTeam(GREEN_TEAM, BLUE_TEAM);
555 UpdateTeamPlacementDialog();
556 break;
557 case GREENTOYELLOW:
558 TeamPlacementChangeTeam(GREEN_TEAM, YELLOW_TEAM);
559 UpdateTeamPlacementDialog();
560 break;
561 case YELLOWTORED:
562 TeamPlacementChangeTeam(YELLOW_TEAM, RED_TEAM);
563 UpdateTeamPlacementDialog();
564 break;
565 case YELLOWTOBLUE:
566 TeamPlacementChangeTeam(YELLOW_TEAM, BLUE_TEAM);
567 UpdateTeamPlacementDialog();
568 break;
569 case YELLOWTOGREEN:
570 TeamPlacementChangeTeam(YELLOW_TEAM, GREEN_TEAM);
571 UpdateTeamPlacementDialog();
572 break;
573 case UID_OK: // start game
574 // get the team names and save them
575 for (i = 0; i < DLLMAX_TEAMS; i++) {
576 if (team_text[i]) {
577 char buff[MAX_TEAMNAME_LEN + 1];
578 DLLEditGetText(team_text[i], buff, MAX_TEAMNAME_LEN);
579 SetTeamName(i, buff, true);
580 }
581 }
582
583 exit_menu = true;
584 break;
585 case NEWUIRES_FORCEQUIT:
586 exit_menu = true;
587 canceled = true;
588 break;
589 case 128: // make clients wait on/off
590 {
591 if (DLLCheckBoxIsChecked(client_wait_cb)) {
592 // make the clients wait
593 clients_wait = true;
594
595 // Pause realgametime,
596 ENABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_PAUSETIME);
597 SendControlMessageToPlayer(SP_ALL, CM_PAUSETIME);
598 } else {
599 // they no longer have to wait
600 clients_wait = false;
601
602 // UnPause realgametime,
603 DISABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_PAUSETIME);
604 SendControlMessageToPlayer(SP_ALL, CM_UNPAUSETIME);
605 }
606
607 MakeClientsWait(clients_wait);
608 } break;
609 };
610 }
611
612 // Place all changed players!!!
613 if (!canceled) {
614 for (i = 0; i < DLLMAX_PLAYERS; i++) {
615 if (CheckPlayerNum(i)) {
616 // the player is in the game, update his team if needed
617 if (TeamDlgInitialTeamSettings[i] == TS_NOTINGAME) {
618 // this player was NOT in the game when we brought up the dialog
619
620 if (TeamDlgFinalTeamSettings[i] != TS_NOTINGAME) {
621 // we've changed his team though
622 int new_team;
623 new_team = TeamDlgFinalTeamSettings[i];
624 RequestTeamChange(new_team, i, false); // no need to spew his stuff
625 } else {
626 // we haven't changed his team, so he's ok on the team he's on
627 }
628 } else {
629 // this player was in the game when we brought up the dialog
630 if (TeamDlgInitialTeamSettings[i] != TeamDlgFinalTeamSettings[i]) {
631 // he has changed teams!!
632 int new_team;
633 if (TeamDlgFinalTeamSettings[i] != TS_NOTINGAME) {
634 new_team = TeamDlgFinalTeamSettings[i];
635 } else {
636 // weird...they are out of sync?
637 FatalError("Team Dialog Out Of Sync"); // remove later
638 }
639 RequestTeamChange(new_team, i, true); // spew his stuff also
640 }
641 }
642 }
643 }
644 }
645
646 // the wait is over, let them in
647 if (clients_wait) {
648 // UnPause realgametime,
649 DISABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_PAUSETIME);
650 SendControlMessageToPlayer(SP_ALL, CM_UNPAUSETIME);
651 MakeClientsWait(false);
652 }
653
654 DLLNewUIGameWindowClose(main_wnd);
655 DLLNewUIGameWindowDestroy(main_wnd);
656
657 ////////////////////////////////////////////
658 // Remove text items
659 DLLRemoveUITextItem(start_game_text_on);
660 DLLRemoveUITextItem(start_game_text_off);
661 DLLRemoveUITextItem(window_title);
662 DLLRemoveUITextItem(client_wait_txt);
663 for (i = 0; i < DLLMAX_PLAYERS; i++) {
664 if (tpdi.text[i]) {
665 DLLRemoveUITextItem(tpdi.text[i]);
666 tpdi.text[i] = NULL;
667 }
668 }
669 for (i = 0; i < DLLMAX_TEAMS; i++) {
670 for (int j = 0; j < DLLMAX_TEAMS - 1; j++) {
671 if (icon_b_hs[i][j])
672 DLLRemoveUIBmpItem(icon_b_hs[i][j]);
673 if (icon_hs[i][j])
674 DLLDeleteUIItem(icon_hs[i][j]);
675 }
676 }
677
678 ////////////////////////////////////////////
679 // Remove all items
680 if (list_red)
681 DLLDeleteUIItem(list_red);
682 if (list_blue)
683 DLLDeleteUIItem(list_blue);
684 if (list_green)
685 DLLDeleteUIItem(list_green);
686 if (list_yellow)
687 DLLDeleteUIItem(list_yellow);
688 DLLDeleteUIItem(main_wnd);
689 DLLDeleteUIItem(start_game_hs);
690 DLLDeleteUIItem(window_title_text);
691 DLLDeleteUIItem(client_wait_cb);
692
693 for (i = 0; i < DLLMAX_TEAMS; i++) {
694 if (team_icons[i] > BAD_BITMAP_HANDLE)
695 DLLbm_FreeBitmap(team_icons[i]);
696 }
697
698 for (i = 0; i < DLLMAX_TEAMS; i++) {
699 if (team_text[i])
700 DLLDeleteUIItem(team_text[i]);
701 }
702
703 DLLSetUICallback(tpdi.old_callback);
704 }
705
706 //============================================================================
707 // Wait for Players Dialog
708 //============================================================================
709 struct tWaitForPlayers {
710 float last_update;
711 void (*old_callback)(void);
712 void *listbox;
713 void *text[DLLMAX_PLAYERS];
714 int indexmap[DLLMAX_PLAYERS];
715 };
716 tWaitForPlayers wfpi;
717
718 void UpdateWaitForPlayersDialog(void) {
719 int pnum = -1;
720
721 int sel = DLLListGetSelectedIndex(wfpi.listbox);
722 if (sel >= 0) {
723 pnum = wfpi.indexmap[sel];
724 }
725
726 int index = 0;
727 DLLListRemoveAll(wfpi.listbox);
728 for (int i = 0; i < DLLMAX_PLAYERS; i++) {
729 if (wfpi.text[i]) {
730 DLLRemoveUITextItem(wfpi.text[i]);
731 wfpi.text[i] = NULL;
732 }
733
734 if (basethis->CheckPlayerNum(i)) {
735 wfpi.indexmap[index] = i;
736 index++;
737 wfpi.text[i] = DLLCreateNewUITextItem(basethis->Players[i].callsign, basethis->Player_colors[i], -1);
738 DLLListAddItem(wfpi.listbox, wfpi.text[i]);
739 if (pnum == i) {
740 DLLListSetSelectedIndex(wfpi.listbox, i);
741 }
742 }
743 }
744 }
745 void WaitForPlayersCallback(void) {
746 float time = *basethis->Gametime;
747
748 if (time > wfpi.last_update + 0.5f) {
749 UpdateWaitForPlayersDialog();
750 wfpi.last_update = time;
751 }
752
753 if (wfpi.old_callback)
754 (*wfpi.old_callback)();
755 }
756
757 // DMFCBase::DoDMFCUIWaitForPlayers
758 //
759 // Displays the dialog for in the beginning of the level, waiting for all the players
760 void DMFCBase::DoDMFCUIWaitForPlayers(bool clients_wait) {
761 if (GetLocalRole() != LR_SERVER)
762 return;
763
764 if (IAmDedicatedServer())
765 return;
766
767 wfpi.last_update = 0;
768 int i;
769 for (i = 0; i < DLLMAX_PLAYERS; i++)
770 wfpi.text[i] = NULL;
771
772 // turn on client waiting
773 if (clients_wait) {
774 // Pause realgametime,
775 ENABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_PAUSETIME);
776 SendControlMessageToPlayer(SP_ALL, CM_PAUSETIME);
777 MakeClientsWait(true);
778 }
779
780 for (i = 0; i < DLLMAX_PLAYERS; i++)
781 wfpi.indexmap[i] = 0;
782
783 ///////////////////////////////////////////////////
784 // Text Items
785 void *start_game_text_off = DLLCreateNewUITextItem(DTXT_UI_STARTGAME, UICOL_HOTSPOT_LO, -1);
786 void *start_game_text_on = DLLCreateNewUITextItem(DTXT_UI_STARTGAME, UICOL_HOTSPOT_HI, -1);
787 void *client_wait_txt = DLLCreateNewUITextItem(DTXT_UI_CLIENTSWAIT, UICOL_HOTSPOT_LO, -1);
788 void *window_title = DLLCreateNewUITextItem(DTXT_UI_WAITFORPLAYERS, UICOL_WINDOW_TITLE, -1);
789 void *kick_text_off = DLLCreateNewUITextItem(DTXT_UI_KICKPLAYER, UICOL_HOTSPOT_LO, -1);
790 void *kick_text_on = DLLCreateNewUITextItem(DTXT_UI_KICKPLAYER, UICOL_HOTSPOT_HI, -1);
791 void *ban_text_off = DLLCreateNewUITextItem(DTXT_UI_BANPLAYER, UICOL_HOTSPOT_LO, -1);
792 void *ban_text_on = DLLCreateNewUITextItem(DTXT_UI_BANPLAYER, UICOL_HOTSPOT_HI, -1);
793
794 ///////////////////////////////////////////////////
795 // Main Window
796 void *main_wnd = DLLNewUIGameWindowCreate(0, 0, 512, 384, UIF_PROCESS_ALL | UIF_CENTER | NUWF_TITLEMED);
797
798 ///////////////////////////////////////////////////
799 // Item placement
800 int cury = 30;
801 bool exit_menu = false;
802
803 void *start_game_hs = DLLHotSpotCreate(main_wnd, UID_OK, K_ENTER, start_game_text_off, start_game_text_on, 40,
804 384 - OKCANCEL_YOFFSET, 130, 15, UIF_CENTER);
805 void *window_title_text = DLLTextCreate(main_wnd, window_title, 0, 7, UIF_CENTER | UIF_FIT);
806 void *client_wait_cb =
807 DLLCheckBoxCreate(main_wnd, 128, client_wait_txt, 30, 369 - OKCANCEL_YOFFSET, 130, 15, UIF_FIT | UIF_CENTER);
808 wfpi.listbox = DLLListCreate(main_wnd, -1, 40, cury, 256, 288, UIF_CENTER);
809 DLLCheckBoxSetCheck(client_wait_cb, clients_wait);
810
811 int l_x, l_y, l_w, l_h;
812 DLLGetUIItemPosition(wfpi.listbox, &l_x, &l_y, &l_w, &l_h);
813 l_x = l_x + l_w + 10;
814 l_y = (l_y + (l_h / 2)) - 15;
815 void *kick_hs = DLLHotSpotCreate(main_wnd, 10, -1, kick_text_off, kick_text_on, l_x, l_y, 130, 15, UIF_FIT);
816 l_y += 15;
817 void *ban_hs = DLLHotSpotCreate(main_wnd, 20, -1, ban_text_off, ban_text_on, l_x, l_y, 130, 15, UIF_FIT);
818
819 //////////////////////////////////////////////////
820 // Process all
821 DLLGetUICallback((void **)&wfpi.old_callback);
822 DLLSetUICallback(WaitForPlayersCallback);
823
824 DLLNewUIGameWindowOpen(main_wnd);
825
826 UpdateWaitForPlayersDialog();
827
828 mprintf(0, "1:Entering UI Loop\n");
829
830 while (!exit_menu) {
831 int res;
832 res = DLLPollUI();
833
834 if (res == -1) {
835 continue;
836 }
837 switch (res) {
838 case NEWUIRES_FORCEQUIT:
839 mprintf(0, "1:Got a force quit\n");
840 exit_menu = true;
841 break;
842 case UID_OK: // exit menu
843 mprintf(0, "1:Got a regular quit\n");
844 exit_menu = true;
845 break;
846 case 10: // kick player
847 {
848 int cursel = DLLListGetSelectedIndex(wfpi.listbox);
849 int pnum = wfpi.indexmap[cursel];
850 KickPlayer(pnum);
851 } break;
852 case 20: // ban player
853 {
854 int cursel = DLLListGetSelectedIndex(wfpi.listbox);
855 int pnum = wfpi.indexmap[cursel];
856 BanPlayer(pnum);
857 } break;
858 case 128: // make clients wait on/off
859 {
860 if (DLLCheckBoxIsChecked(client_wait_cb)) {
861 // make the clients wait
862 clients_wait = true;
863 // Pause realgametime,
864 ENABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_PAUSETIME);
865 SendControlMessageToPlayer(SP_ALL, CM_PAUSETIME);
866 } else {
867 // they no longer have to wait
868 clients_wait = false;
869 // UnPause realgametime,
870 DISABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_PAUSETIME);
871 SendControlMessageToPlayer(SP_ALL, CM_UNPAUSETIME);
872 }
873 MakeClientsWait(clients_wait);
874 } break;
875 };
876 }
877
878 mprintf(0, "1:Out of UI Loop\n");
879
880 // the wait is over, let them in
881 if (clients_wait) {
882 // Unpause realgametime,
883 DISABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_PAUSETIME);
884 SendControlMessageToPlayer(SP_ALL, CM_UNPAUSETIME);
885 MakeClientsWait(false);
886 }
887
888 DLLNewUIGameWindowClose(main_wnd);
889 DLLNewUIGameWindowDestroy(main_wnd);
890
891 DLLRemoveUITextItem(start_game_text_on);
892 DLLRemoveUITextItem(start_game_text_off);
893 DLLRemoveUITextItem(kick_text_off);
894 DLLRemoveUITextItem(kick_text_on);
895 DLLRemoveUITextItem(ban_text_off);
896 DLLRemoveUITextItem(ban_text_on);
897 DLLRemoveUITextItem(window_title);
898 DLLRemoveUITextItem(client_wait_txt);
899 for (i = 0; i < DLLMAX_PLAYERS; i++) {
900 if (wfpi.text[i]) {
901 DLLRemoveUITextItem(wfpi.text[i]);
902 wfpi.text[i] = NULL;
903 }
904 }
905
906 DLLDeleteUIItem(main_wnd);
907 DLLDeleteUIItem(start_game_hs);
908 DLLDeleteUIItem(window_title_text);
909 DLLDeleteUIItem(client_wait_cb);
910 DLLDeleteUIItem(wfpi.listbox);
911 DLLDeleteUIItem(kick_hs);
912 DLLDeleteUIItem(ban_hs);
913
914 DLLSetUICallback(wfpi.old_callback);
915 }