Debian Codegraph @

netgames/dmfc/dmfcmenu.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/dmfcmenu.cpp $
21 * $Revision: 1.1.1.1 $
22 * $Date: 2003/08/26 03:57:21 $
23 * $Author: kevinb $
24 *
25 * DMFC in-game Graphical menu functions
26 *
27 * $Log: dmfcmenu.cpp,v $
28 * Revision 1.1.1.1 2003/08/26 03:57:21 kevinb
29 * initial 1.5 import
30 *
31 *
32 * 42 3/20/00 12:25p Matt
33 * Merge of Duane's post-1.3 changes.
34 * Initialize m_cPtrs in altenate menuItem constructor.
35 *
36 * 41 10/26/99 10:32a Jeff
37 * fixed COM interface bug
38 *
39 * 40 7/07/99 5:00p Jeff
40 * removed vararg functions from interface functions, just made different
41 * versions of them
42 *
43 * 39 5/13/99 4:55p Ardussi
44 * changes for compiling on the Mac
45 *
46 * 38 5/09/99 6:20a Jeff
47 * improved Entropy (added sounds, max virii per room). Fixed rendering
48 * bugs for other multiplayer dlls.
49 *
50 * 37 4/03/99 4:06p Jeff
51 * added loss/ping gauge
52 *
53 * 36 3/22/99 6:21p Jeff
54 * added 2 more audio taunts. a mulitplayer event when someone plays an
55 * audio taunt. option to disable audio taunts.
56 *
57 * 35 3/17/99 12:24p Jeff
58 * converted DMFC to be COM interface
59 *
60 * 34 3/05/99 1:30p Jeff
61 * fixed 99% of the high res issues
62 *
63 * 33 2/11/99 12:51a Jeff
64 * changed names of exported variables
65 *
66 * 32 1/31/99 7:26p Matt
67 * Renamed a bunch of functions to have HUD capitalized
68 *
69 * 31 1/19/99 3:55a Jeff
70 * all strings localized out
71 *
72 * 30 1/04/99 12:21p Jeff
73 * added support for hosts.allow/deny and updates stats manager a little
74 *
75 * 29 12/13/98 5:32p Jeff
76 * fixed ugly crash due to freeing memory allocated in another heap
77 *
78 * 28 12/08/98 12:17p Jeff
79 * various changes that include an improved Team Control dialog (doesn't
80 * switch teams until exit..) and spew/respawn players that change teams
81 *
82 * 27 11/19/98 5:56p Jeff
83 * added slider exported and improved Hoard
84 *
85 * 26 11/17/98 6:29p Jeff
86 * mod can specify whether or not to display the team setup dialog on team
87 * game start. Added a menu item to display team setup dialog in mid-game
88 *
89 * 25 11/17/98 12:36p Jeff
90 * remove onscreen menu when endlevel selected
91 *
92 * 24 11/13/98 6:36p Jeff
93 * created dmfc_dll (a DLL version of DMFC) and converted current mods to
94 * use it
95 *
96 * 23 11/11/98 7:19p Jeff
97 * changes made so that a dedicated server's team is always -1 (team game
98 * or not)
99 *
100 * 22 10/20/98 5:39p Jeff
101 * fixed MIF_INCLUDEONE bug with team games
102 *
103 * 21 10/20/98 4:35p Jeff
104 * added a flag for menu to add a <None> to MIT_PLIST...
105 *
106 * 20 10/20/98 12:16p Jeff
107 * added death message filter, hud callsign filter
108 *
109 * 19 10/15/98 1:34p Jeff
110 * added scrollable onscreen menu. Remove ban in dmfc. prejoin event
111 *
112 * 18 10/14/98 11:26p Jeff
113 * added scrollable menus
114 *
115 * 17 10/05/98 2:50p Jeff
116 *
117 * 16 9/30/98 3:50p Jeff
118 * general improvements (many)
119 *
120 * 15 9/29/98 3:04p Jeff
121 * added time in game and start_time support
122 *
123 * 14 9/28/98 5:05p Jeff
124 * made the statisitical death messages an option in the menu
125 *
126 * 13 9/21/98 7:11p Jeff
127 * made InputCommand interface API and moved existing input commands to
128 * the interface. Changed mprintf/ASSERT so they are valid in DMFC
129 *
130 * $NoKeywords: $
131 */
132
133 #include "DMFC.h"
134 #include "gamedll_header.h"
135 #include "dmfcinternal.h"
136
137
138 #include <algorithm>
139
140 extern DMFCBase *basethis;
141
142 MenuItem::MenuItem() {
143 m_cPtrs = 0;
144 m_bMoreToScroll = false;
145 m_bAtBottom = false;
146 m_iTopIndex = 0;
147 SubMenuCount = 0;
148 CurrSubMenu = -1;
149 m_iState = 0;
150 SubMenus = NULL;
151 func = NULL;
152 HasInputFocus = false;
153 m_cType = MIT_NORMAL;
154
155 m_Alpha = 0;
156 m_AlphaDir = true;
157
158 memset(&m_cmInfo, 0, sizeof(tCustomMenu));
159
160 strcpy(m_sTitle, " ");
161 }
162
163 MenuItem::MenuItem(const char *title, char type, uint8_t flags, void (*fp)(int), ...) {
164 m_bMoreToScroll = false;
165 m_bAtBottom = false;
166 m_iTopIndex = 0;
167 SubMenuCount = 0;
168 CurrSubMenu = -1;
169 m_iState = 0;
170 SubMenus = NULL;
171 func = fp;
172 HasInputFocus = false;
173 m_cType = type;
174 m_Alpha = 0;
175 m_AlphaDir = true;
176 m_iFlags = flags;
177 m_cPtrs = 0; // DAJ Do this or fail the second netgame start
178
179 memset(&m_cmInfo, 0, sizeof(tCustomMenu));
180
181 if (title) {
182 strncpy(m_sTitle, title, MAX_STRING_LEN - 1);
183 m_sTitle[MAX_STRING_LEN - 1] = '\0';
184 } else {
185 strcpy(m_sTitle, " ");
186 }
187
188 // if the type is MIT_PLIST than add a dummy submenu so it will register
189 if (type == MIT_PLIST) {
190 SubMenuCount = 1;
191 SubMenus = (IMenuItem **)malloc(sizeof(IMenuItem *) * 1);
192 SubMenus[0] = new MenuItem("Pfuncer", MIT_STATEITEM, 0, fp);
193 }
194
195 // if the type is MIT_CUSTOM than add a dummy submenu so it will register
196 // the only variable parameter should be a pointer to a tCustomMenu struct that
197 // contains the needed callbacks
198 if (type == MIT_CUSTOM) {
199 SubMenuCount = 1;
200 SubMenus = (IMenuItem **)malloc(sizeof(IMenuItem *) * 1);
201 SubMenus[0] = new MenuItem("Pfuncer", MIT_STATEITEM, 0, fp);
202
203 va_list marker;
204 va_start(marker, fp);
205 memcpy(&m_cmInfo, va_arg(marker, tCustomMenu *), sizeof(tCustomMenu));
206 va_end(marker);
207 }
208
209 // if the type is MIT_STATE than we need to pull off the extra parameters for the states
210 if (type == MIT_STATE) {
211 va_list marker;
212 va_start(marker, fp);
213 SubMenuCount = va_arg(marker, int);
214 m_iState = va_arg(marker, int);
215 if ((SubMenuCount > 0) && (SubMenuCount < MAX_STATE_SUBMENUS)) {
216 SubMenus = (IMenuItem **)malloc(sizeof(IMenuItem *) * SubMenuCount);
217 if (!SubMenus)
218 return;
219 char *string;
220 for (int i = 0; i < SubMenuCount; i++) {
221 string = va_arg(marker, char *);
222 SubMenus[i] = new MenuItem(string, MIT_STATEITEM, 0, fp);
223 }
224 } else
225 SubMenuCount = 0;
226 va_end(marker);
227 }
228 }
229
230 MenuItem::~MenuItem() {
231 MenuItem *p;
232
233 if (SubMenus) {
234 if ((m_cType == MIT_PLIST) || (m_cType == MIT_CUSTOM)) {
235 p = (MenuItem *)SubMenus[0];
236 if (p) {
237 SubMenus[0] = NULL;
238 delete p;
239 }
240 } else {
241 for (int i = 0; i < SubMenuCount; i++) {
242 p = (MenuItem *)SubMenus[i];
243 if (p) {
244 SubMenus[i] = NULL;
245 delete p;
246 }
247 }
248 }
249
250 free(SubMenus);
251 SubMenus = NULL;
252 }
253
254 SubMenuCount = 0;
255 }
256
257 bool MenuItem::AddSubMenu(IMenuItem *p) {
258 // No submenus for a Player list submenu or custom or if we are working with a stateitem submenu item
259 if ((m_cType == MIT_PLIST) || (m_cType == MIT_STATEITEM) || (m_cType == MIT_STATE) || (m_cType == MIT_CUSTOM))
260 return false;
261
262 MenuItem **temp;
263 temp = (MenuItem **)SubMenus;
264
265 // create a new array of submenus and copy the old to it
266 SubMenus = (IMenuItem **)malloc(sizeof(IMenuItem *) * (SubMenuCount + 1));
267 for (int i = 0; i < SubMenuCount; i++) {
268 SubMenus[i] = temp[i];
269 }
270
271 if (temp)
272 free(temp);
273
274 // Put the new submenu item at the end of this one
275 SubMenus[SubMenuCount] = p;
276 SubMenuCount++;
277 return true;
278 }
279
280 bool MenuItem::DetachSubMenu(IMenuItem *p) {
281 // No submenus for a Player list submenu or custom or if we are working with a stateitem submenu item
282 if ((m_cType == MIT_PLIST) || (m_cType == MIT_STATEITEM) || (m_cType == MIT_STATE) || (m_cType == MIT_CUSTOM))
283 return false;
284
285 if (SubMenuCount < 1)
286 return false;
287
288 int i;
289 bool found = false;
290
291 // make sure there is this menu somewhere in our list
292 for (i = 0; i < SubMenuCount; i++) {
293 if (SubMenus[i] == p) {
294 found = true;
295 break;
296 }
297 }
298 if (!found) {
299 // doesn't exist
300 return false;
301 }
302
303 MenuItem **temp;
304 temp = (MenuItem **)SubMenus;
305
306 if (SubMenuCount > 1) {
307 // we need to resize our list
308 // create a new array of submenus and copy the old to it
309 int c;
310
311 SubMenus = (IMenuItem **)malloc(sizeof(IMenuItem *) * (SubMenuCount - 1));
312 for (i = 0, c = 0; i < SubMenuCount; i++) {
313 // make sure it isn't the one we are trying to detach
314 if (temp[i] != p) {
315 ASSERT((c < (SubMenuCount - 1)));
316 SubMenus[c] = temp[i];
317 c++;
318 }
319 }
320
321 if (temp)
322 free(temp);
323
324 SubMenuCount--;
325 } else {
326 // this is the only remaining submenu
327 SubMenuCount = 0;
328
329 if (temp)
330 free(temp);
331 SubMenus = NULL;
332 }
333
334 return true;
335 }
336
337 bool MenuItem::Forward(void) {
338 if ((m_cType == MIT_PLIST) || (m_cType == MIT_STATE) || (m_cType == MIT_CUSTOM))
339 return false; // short circuit on a plist and state since it has no submenus in reality
340
341 char type = SubMenus[CurrSubMenu]->GetType();
342
343 // We can only move forward if there is a submenu
344 if ((type == MIT_CUSTOM && SubMenus[CurrSubMenu]->GetCustomSubMenuCount() > 0) ||
345 (type != MIT_CUSTOM && (SubMenuCount > 0))) {
346 // If this submenu has input focus, than we need to check the currently selected submenu
347 // and set that as the new item with focus, and remove focus from this one
348 if (HasInputFocus) {
349 if ((CurrSubMenu != -1) && (SubMenus[CurrSubMenu]->HasSubMenus())) {
350 SubMenus[CurrSubMenu]->SetInputFocus();
351 HasInputFocus = false;
352 }
353 return true;
354 }
355 // This submenu doesn't have input focus, so move to it's currently selected submenu and
356 // Tell it to go forward if it can
357 if (CurrSubMenu != -1)
358 return SubMenus[CurrSubMenu]->Forward();
359 }
360 return false;
361 }
362 bool MenuItem::Back(void) {
363 // We need to look ahead and see if the next submenu has input focus
364 // if it does have focus, than we need to make it lose focus, and make this one have focus
365 if (SubMenuCount > 0) {
366 if (CurrSubMenu != -1) {
367 if (SubMenus[CurrSubMenu]->GetFocus()) {
368 // The next submenu has focus so we can remove it and set this guy to have focus
369 SubMenus[CurrSubMenu]->LoseInputFocus();
370 HasInputFocus = true;
371 return true;
372 }
373 // The next submenu doesn't have focus, but one of it's submenus might (they better),
374 // so move on to the next submenu and call Back()
375 return SubMenus[CurrSubMenu]->Back();
376 }
377 }
378 return false;
379 }
380 bool MenuItem::Up(void) {
381 // See if this MenuItem has focus, if it does, and we can move up, then move up
382 if (HasInputFocus) {
383 if (CurrSubMenu > 0)
384 CurrSubMenu--;
385 if (m_iTopIndex > 0 && m_iTopIndex >= CurrSubMenu) {
386 // move the top and index's up
387 m_iTopIndex--;
388 }
389
390 return true;
391 }
392 // Ok, one of the submenus better have focus, so move on to the next submenu and call Up()
393 if (CurrSubMenu != -1)
394 return SubMenus[CurrSubMenu]->Up();
395 return false;
396 }
397 bool MenuItem::Down(void) {
398 // See if this MenuItem has focus, if it does, and we can move down, then move down
399 if (HasInputFocus) {
400 if (CurrSubMenu < SubMenuCount - 1)
401 CurrSubMenu++;
402 if (m_bMoreToScroll && m_bAtBottom) {
403 m_iTopIndex++;
404 }
405 return true;
406 }
407 // Ok, one of the submenus better have focus, so move on to the next submenu and call Down()
408 if (CurrSubMenu != -1)
409 return SubMenus[CurrSubMenu]->Down();
410 return false;
411 }
412 void MenuItem::Execute(void) {
413 switch (m_cType) {
414 case MIT_NORMAL: {
415 // We need to go through the Submenus and check to see if the submenu has focus
416 // if it does, than we need to execute it's function
417 if (SubMenuCount > 0) {
418 if (CurrSubMenu != -1) {
419 if (HasInputFocus) {
420 // The submenu has focus, so call it's handler as long as it's not a plist type
421 char type = SubMenus[CurrSubMenu]->GetType();
422 if ((type != MIT_PLIST) && (type != MIT_STATE) && (type != MIT_CUSTOM))
423 SubMenus[CurrSubMenu]->CallFunc(CurrSubMenu);
424 return;
425 }
426 // The next submenu doesn't have focus, so move on and check it's submenu to see if we
427 // can Execute() that
428 SubMenus[CurrSubMenu]->Execute();
429 }
430 } else {
431 // We don't have any SubMenus so try and call our handler
432 CallFunc(0);
433 }
434 } break;
435 case MIT_PLIST: {
436 // We need to go through the Submenus and check to see if the submenu has focus
437 // if it does, than we need to execute it's function
438 if ((SubMenuCount > 0) && (CurrSubMenu != -1) && (HasInputFocus)) {
439 if (m_iFlags & MIF_INCLUDENONE) {
440 // there is a <None> so take that into consideration
441 if (CurrSubMenu == 0) {
442 //<None> is selected
443 CallFunc(-1);
444 return;
445 }
446
447 if (basethis->CheckPlayerNum(Pnums[CurrSubMenu - 1])) {
448 // The submenu has focus, so call it's handler
449 CallFunc(Pnums[CurrSubMenu - 1]);
450 return;
451 }
452 } else {
453 // a regular plist
454 if (basethis->CheckPlayerNum(Pnums[CurrSubMenu])) {
455 // The submenu has focus, so call it's handler
456 CallFunc(Pnums[CurrSubMenu]);
457 return;
458 }
459 }
460 }
461 } break;
462 case MIT_CUSTOM: {
463 // We need to go through the Submenus and check to see if the submenu has focus
464 // if it does, than we need to execute it's function
465 int count = (m_cmInfo.GetListCount) ? (*m_cmInfo.GetListCount)() : 0;
466 if (count > 0) {
467 if (CurrSubMenu != -1) {
468 if (HasInputFocus) {
469 // The submenu has focus, so call it's handler
470 CallFunc(CurrSubMenu);
471 return;
472 }
473 }
474 }
475 }
476 case MIT_STATE: {
477 // We need to go through the Submenus and check to see if the submenu has focus
478 // if it does, than we need to execute it's function
479 if (SubMenuCount > 0) {
480 if (CurrSubMenu != -1) {
481 if (HasInputFocus) {
482 // The submenu has focus, so call it's handler
483 CallFunc(CurrSubMenu);
484 m_iState = CurrSubMenu;
485 return;
486 }
487 }
488 }
489 } break;
490 }
491 }
492 void MenuItem::Draw(int x, int y, int height, int bmp, float *not_used) {
493 int old_font = DLLgrtext_GetFont();
494 DLLgrtext_SetFont(basethis->Game_fonts[HUD_FONT_INDEX]);
495
496 /*
497 static float aspratio;
498 if(!ratio){
499 //we need to calculate a ratio
500 aspratio = DEFAULT_HUD_WIDTH / ((float)*base->Game_window_w);
501 }
502
503 float useratio;
504 if(!ratio) useratio = aspratio; else useratio = *ratio;
505 */
506
507 uint8_t alpha_to_use = 255;
508
509 #define FLASHRATE 700.0 // alphas per second
510
511 int16_t a = m_Alpha;
512 int units = (int)FLASHRATE * (*basethis->Frametime);
513
514 // do alphaing effect
515 while (units > 0) {
516 if (m_AlphaDir) {
517 // find the amount to adjust
518 uint8_t amount = std::min<int>(255 - a, units);
519 units -= amount;
520 a += amount;
521 if (a >= 255) {
522 a = 255;
523 m_AlphaDir = false;
524 }
525 } else {
526 // find the amount to adjust
527 uint8_t amount = std::min<int>(a, units);
528 units -= amount;
529 a -= amount;
530 if (a <= 0) {
531 a = 0;
532 m_AlphaDir = true;
533 }
534 }
535 }
536
537 m_Alpha = alpha_to_use = (uint8_t)a;
538
539 ddgr_color color;
540 int temp, maxx;
541 temp = maxx = 0;
542 char buff[256];
543 char checked[3];
544 char buffer[100];
545
546 if (SubMenuCount <= 0) {
547 DLLgrtext_SetFont(old_font);
548 return;
549 }
550
551 bool nodisp_custom = false;
552
553 // First find the max width of the submenu items
554 switch (m_cType) {
555 case MIT_NORMAL:
556 case MIT_STATE: {
557 for (int i = 0; i < SubMenuCount; i++) {
558 // temp = DLLRenderHUDGetTextLineWidth(SubMenus[i]->GetTitle());
559 temp = DLLgrtext_GetTextLineWidth(SubMenus[i]->GetTitle());
560 if (temp > maxx)
561 maxx = temp;
562 }
563 if (m_cType == MIT_NORMAL) {
564 maxx += (x + 10);
565 } else {
566 snprintf(checked, sizeof(checked), "%c ", CHAR_RIGHT_ARROW);
567 // maxx += (x + 10 + (useratio * ((float)DLLRenderHUDGetTextLineWidth(checked))));
568 // maxx += (x + 10 + DLLRenderHUDGetTextLineWidth(checked));
569 maxx += (x + 10 + DLLgrtext_GetTextLineWidth(checked));
570 }
571 } break;
572 case MIT_PLIST: {
573 // First create/update the playerlist
574 SubMenuCount = 0;
575 int i;
576 for (i = 0; i < DLLMAX_PLAYERS; i++) {
577 if (basethis->CheckPlayerNum(i)) {
578 // we have a valid pnum, fill it in
579 Pnums[SubMenuCount] = i;
580 SubMenuCount++;
581 }
582 }
583
584 if (m_iFlags & MIF_INCLUDENONE)
585 SubMenuCount++; // account for <None>
586
587 // Do some error checking and make sure values for the currsub are ok
588 if (CurrSubMenu >= SubMenuCount)
589 CurrSubMenu = SubMenuCount - 1;
590
591 if (CurrSubMenu < m_iTopIndex)
592 m_iTopIndex = (CurrSubMenu >= 0) ? CurrSubMenu : 0;
593
594 int end_i = SubMenuCount;
595
596 // Now we have a list of pnums, so draw them
597 if (m_iFlags & MIF_INCLUDENONE) {
598 // temp = useratio * ((float)DLLRenderHUDGetTextLineWidth(DTXT_NONE));
599 // temp = DLLRenderHUDGetTextLineWidth(DTXT_NONE);
600 temp = DLLgrtext_GetTextLineWidth(DTXT_NONE);
601 end_i = SubMenuCount - 1;
602 }
603
604 // go through all the names and get the longest name
605 for (i = 0; i < end_i; i++) {
606 // temp = useratio * ((float)DLLRenderHUDGetTextLineWidth(base->Players[Pnums[i]].callsign));
607 // temp = DLLRenderHUDGetTextLineWidth(base->Players[Pnums[i]].callsign);
608 temp = DLLgrtext_GetTextLineWidth(basethis->Players[Pnums[i]].callsign);
609 if (temp > maxx)
610 maxx = temp;
611 }
612 // maxx += (x + 10 + (useratio * ((float)DLLRenderHUDGetTextLineWidth("[33]"))));
613 // maxx += (x + 10 + DLLRenderHUDGetTextLineWidth("[33]"));
614 maxx += (x + 10 + DLLgrtext_GetTextLineWidth("[33]"));
615 } break;
616 case MIT_CUSTOM: {
617 // First find out how many submenus there are going to be
618 SubMenuCount = (m_cmInfo.GetListCount) ? (*m_cmInfo.GetListCount)() : 0;
619
620 // Do some error checking and make sure values are ok
621 if (CurrSubMenu >= SubMenuCount)
622 CurrSubMenu = SubMenuCount - 1;
623 if (CurrSubMenu < m_iTopIndex)
624 m_iTopIndex = (CurrSubMenu >= 0) ? CurrSubMenu : 0;
625
626 if (SubMenuCount <= 0) {
627 nodisp_custom = true;
628 }
629
630 // now find out the biggest string
631 if (m_cmInfo.GetItem) {
632 for (int i = 0; i < SubMenuCount; i++) {
633 char *ptr = (*m_cmInfo.GetItem)(i);
634 if (ptr) {
635 // temp = useratio * ((float)DLLRenderHUDGetTextLineWidth(ptr));
636 // temp = DLLRenderHUDGetTextLineWidth(ptr);
637 temp = DLLgrtext_GetTextLineWidth(ptr);
638 if (temp > maxx)
639 maxx = temp;
640 }
641 }
642 }
643 maxx += (x + 10);
644 } break;
645 }
646
647 int end_index = std::min(SubMenuCount, m_iTopIndex + ((400 - y) / height));
648 int num_teams = basethis->GetNumTeams();
649
650 if (SubMenuCount && bmp > BAD_BITMAP_HANDLE) {
651 DLLrend_SetAlphaValue(210);
652 DLLrend_SetZBufferState(0);
653 DLLrend_SetTextureType(TT_LINEAR);
654 DLLrend_SetLighting(LS_NONE);
655 DLLrend_SetAlphaType(AT_CONSTANT_TEXTURE);
656 DLLrend_DrawScaledBitmap(x, y, maxx, y + (height * (end_index - m_iTopIndex + 1)), bmp, 0, 0, 1, 1, 1.0, 1, NULL);
657 DLLrend_SetZBufferState(1);
658 }
659
660 x += 5;
661
662 uint8_t al;
663
664 m_bMoreToScroll = (end_index < SubMenuCount) ? true : false;
665 // m_bAtBottom = (m_bMoreToScroll)?((CurrSubMenu<end_index-1)?false:true):((CurrSubMenu<end_index)?false:true);
666 m_bAtBottom =
667 (m_bMoreToScroll) ? ((CurrSubMenu < end_index - 2) ? false : true) : ((CurrSubMenu < end_index) ? false : true);
668
669 // we have something to draw
670 for (int i = m_iTopIndex; i < end_index; i++) {
671 switch (m_cType) {
672 case MIT_PLIST: {
673 if (num_teams <= 1) {
674 if ((i == CurrSubMenu) && (HasInputFocus)) {
675 al = alpha_to_use;
676 color = GR_RGB(180, 255, 180);
677 } else {
678 al = 255;
679 color = GR_RGB(0, 180, 0);
680 }
681 } else {
682 if ((i == CurrSubMenu) && (HasInputFocus)) {
683 al = alpha_to_use;
684 color = GR_RGB(180, 255, 180);
685 } else {
686 al = 255;
687 if (m_iFlags & MIF_INCLUDENONE) {
688 if (i == 0)
689 color = GR_RGB(0, 180, 0);
690 else
691 color = basethis->GetTeamColor(basethis->Players[Pnums[i - 1]].team);
692 } else {
693 color = basethis->GetTeamColor(basethis->Players[Pnums[i]].team);
694 }
695 }
696 }
697 } break;
698 case MIT_CUSTOM:
699 case MIT_NORMAL:
700 case MIT_STATE: {
701 if ((i == CurrSubMenu) && (HasInputFocus)) {
702 al = alpha_to_use;
703 color = GR_RGB(180, 255, 180);
704 } else {
705 al = 255;
706 color = GR_RGB(0, 180, 0);
707 }
708 } break;
709 }
710
711 bool draw_text = true;
712 if (i == m_iTopIndex && m_iTopIndex > 0) {
713 // we need to draw the UP arrow
714 char b[2];
715 snprintf(b, sizeof(b), "%c", CHAR_UP_ARROW);
716 // DLLRenderHUDText(color,al,0,(maxx-x)/2+x,y,b);
717 DLLgrtext_SetColor(color);
718 DLLgrtext_SetAlpha(al);
719 DLLgrtext_Printf((maxx - x) / 2 + x, y, b);
720 draw_text = false;
721 }
722
723 if (m_bMoreToScroll && i == (end_index - 1)) {
724 // we need to draw the DOWN arrow
725 char b[2];
726 snprintf(b, sizeof(b), "%c", CHAR_DOWN_ARROW);
727 // DLLRenderHUDText(color,al,0,(maxx-x)/2+x,y,b);
728 DLLgrtext_SetColor(color);
729 DLLgrtext_SetAlpha(al);
730 DLLgrtext_Printf((maxx - x) / 2 + x, y, b);
731 draw_text = false;
732 }
733
734 if (draw_text) {
735 switch (m_cType) {
736 case MIT_NORMAL: {
737 // DLLRenderHUDText(color,al,0,x,y,SubMenus[i]->GetTitle());
738 DLLgrtext_SetColor(color);
739 DLLgrtext_SetAlpha(al);
740 DLLgrtext_Printf(x, y, SubMenus[i]->GetTitle());
741
742 if (i == CurrSubMenu) { // go through the submenus
743 // if(ratio){
744 SubMenus[i]->Draw(maxx, y, height, bmp, not_used);
745 //}else{
746 // SubMenus[i]->Draw(maxx,y,height,base,bmp,&aspratio);
747 //}
748 }
749 } break;
750 case MIT_PLIST: {
751 if (m_iFlags & MIF_INCLUDENONE) {
752
753 if (i == 0) {
754 // include the <None> if index is 0
755 strcpy(buffer, DTXT_NONE);
756 } else {
757 // do the regular
758 snprintf(buffer, sizeof(buffer), "%s[%d]", basethis->Players[Pnums[i - 1]].callsign, Pnums[i - 1]);
759 }
760 } else {
761 // do the regular
762 snprintf(buffer, sizeof(buffer), "%s[%d]", basethis->Players[Pnums[i]].callsign, Pnums[i]);
763 }
764
765 // DLLRenderHUDText(color,al,0,x,y,buffer);
766 DLLgrtext_SetColor(color);
767 DLLgrtext_SetAlpha(al);
768 DLLgrtext_Printf(x, y, buffer);
769
770 } break;
771 case MIT_CUSTOM: {
772 if (m_cmInfo.GetItem) {
773 char *ptr = (*m_cmInfo.GetItem)(i);
774 if (ptr) {
775 snprintf(buffer, sizeof(buffer), "%s", ptr);
776 // DLLRenderHUDText(color,al,0,x,y,buffer);
777 DLLgrtext_SetColor(color);
778 DLLgrtext_SetAlpha(al);
779 DLLgrtext_Printf(x, y, buffer);
780 }
781 }
782 } break;
783 case MIT_STATE: {
784 if (i == m_iState)
785 strcpy(buff, checked);
786 else
787 strcpy(buff, " ");
788 strcat(buff, SubMenus[i]->GetTitle());
789 // DLLRenderHUDText(color,al,0,x,y,buff);
790 DLLgrtext_SetColor(color);
791 DLLgrtext_SetAlpha(al);
792 DLLgrtext_Printf(x, y, buff);
793
794 } break;
795 }
796 }
797
798 y += height;
799 }
800
801 if (nodisp_custom) {
802 // check to see if we have focus...if we do...we got to move back to the previous menu
803 if (HasInputFocus) {
804 basethis->Menu.Back();
805 }
806 SubMenuCount = 1;
807 }
808
809 DLLgrtext_SetFont(old_font);
810 }
811 const char *MenuItem::GetTitle(void) { return m_sTitle; }
812 void MenuItem::SetInputFocus(void) {
813 // Sets this MenuItem with Input focus, reseting it's Current Sub Menu to 0 if it has a SubMenu
814 HasInputFocus = true;
815 if (SubMenuCount > 0)
816 CurrSubMenu = (m_iTopIndex == 0) ? 0 : m_iTopIndex + 1;
817 else
818 CurrSubMenu = -1;
819 }
820 void MenuItem::LoseInputFocus(void) {
821 // Make this guy lose focus, Set it's Current Submenu to -1
822 HasInputFocus = false;
823 CurrSubMenu = -1;
824 }
825 bool MenuItem::GetFocus(void) { return HasInputFocus; }
826 void MenuItem::CallFunc(int value) {
827 if (func)
828 (*func)(value);
829 }
830 bool MenuItem::HasSubMenus(void) { return (SubMenuCount > 0); }
831
832 int MenuItem::GetCustomSubMenuCount(void) {
833 if (m_cType != MIT_CUSTOM)
834 return -1;
835
836 if (!m_cmInfo.GetListCount)
837 return -1;
838
839 return (*m_cmInfo.GetListCount)();
840 }
841
842 char MenuItem::GetType(void) { return m_cType; }
843 void MenuItem::SetState(int state) {
844 if (m_cType != MIT_STATE)
845 return;
846
847 if ((state < 0) || (state >= SubMenuCount))
848 return;
849
850 m_iState = state;
851 }
852
853 bool MenuItem::SetStateItemList(int count, ...) {
854 if (m_cType != MIT_STATE)
855 return false;
856
857 // remove original states
858 for (int i = 0; i < SubMenuCount; i++) {
859 if (SubMenus[i]) {
860 delete SubMenus[i];
861 SubMenus[i] = NULL;
862 }
863 }
864 if (SubMenus) {
865 free(SubMenus);
866 SubMenus = NULL;
867 }
868
869 va_list marker;
870 va_start(marker, count);
871 SubMenuCount = count;
872 m_iState = 0;
873
874 if ((SubMenuCount > 0) && (SubMenuCount < MAX_STATE_SUBMENUS)) {
875 SubMenus = (IMenuItem **)malloc(sizeof(IMenuItem *) * SubMenuCount);
876 if (!SubMenus)
877 return false;
878 char *string;
879 for (int i = 0; i < SubMenuCount; i++) {
880 string = va_arg(marker, char *);
881 SubMenus[i] = new MenuItem(string, MIT_STATEITEM, 0, func);
882 }
883 } else
884 SubMenuCount = 0;
885 va_end(marker);
886 return true;
887 }
888
889 bool MenuItem::SetStateItemListArray(int count, char **array) {
890 if (m_cType != MIT_STATE)
891 return false;
892
893 // remove original states
894 for (int i = 0; i < SubMenuCount; i++) {
895 if (SubMenus[i]) {
896 delete SubMenus[i];
897 SubMenus[i] = NULL;
898 }
899 }
900 if (SubMenus) {
901 free(SubMenus);
902 SubMenus = NULL;
903 }
904
905 SubMenuCount = count;
906 m_iState = 0;
907
908 if ((SubMenuCount > 0) && (SubMenuCount < MAX_STATE_SUBMENUS)) {
909 SubMenus = (IMenuItem **)malloc(sizeof(IMenuItem *) * SubMenuCount);
910 if (!SubMenus)
911 return false;
912 char *string;
913 for (int i = 0; i < SubMenuCount; i++) {
914 string = array[i];
915 SubMenus[i] = new MenuItem(string, MIT_STATEITEM, 0, func);
916 }
917 } else
918 SubMenuCount = 0;
919 return true;
920 }
921
922 ///////////////////////////////////////////////////
923 // Menu Function handlers
924
925 int GetBanPlayerList(void) { return basethis->GetNumBannedPlayers(); }
926
927 char *GetBannedPlayerString(int index) {
928 static char r[MAX_CALLSIGN_SIZE + 8];
929 char *ptr = basethis->GetBannedPlayerCallsign(index);
930 if (ptr) {
931 snprintf(r, sizeof(r), "[%d]%s", index, ptr);
932 return r;
933 } else
934 return NULL;
935 }
936
937 // Removes a ban for a player, give the ban index #
938 void RemoveBanByIndex(int index) { basethis->RemoveBan(index); }
939
940 // Server Only. Kicks a player from the game
941 void KickPlayer(int pnum) {
942 if (basethis->GetLocalRole() != LR_SERVER) {
943 mprintf(0, "KickPlayer Error: You're Not The Server\n");
944 return;
945 }
946 if (pnum == basethis->GetPlayerNum()) {
947 mprintf(0, "KickPlayer Error: Server can't kick themself\n");
948 DLLAddHUDMessage(DTXT_SERVERCANTKICK);
949 return;
950 }
951 if (!basethis->CheckPlayerNum(pnum)) {
952 mprintf(0, "KickPlayer Error: Pnum %d not in game\n", pnum);
953 DLLAddHUDMessage(DTXT_INVALIDPNUM, pnum);
954 return;
955 }
956 basethis->SendControlMessageToPlayer(pnum, CM_KICKED);
957 DLLMultiDisconnectPlayer(pnum);
958 }
959 // Server Only. Temp bans a player from the game
960 void BanPlayer(int pnum) {
961 if (basethis->GetLocalRole() != LR_SERVER) {
962 mprintf(0, "BanPlayer Error: You're Not The Server\n");
963 return;
964 }
965 if (pnum == basethis->GetPlayerNum()) {
966 mprintf(0, "BanPlayer Error: Server can't ban themself\n");
967 DLLAddHUDMessage(DTXT_SERVERCANTBAN);
968 return;
969 }
970 if (!basethis->CheckPlayerNum(pnum)) {
971 mprintf(0, "BanPlayer Error: Pnum %d not in game\n", pnum);
972 DLLAddHUDMessage(DTXT_INVALIDPNUM, pnum);
973 return;
974 }
975 basethis->SendControlMessageToPlayer(pnum, CM_BANNED);
976 DLLMultiDisconnectPlayer(pnum);
977 basethis->BanPlayerFromGame(pnum);
978 }
979 // Server Only. Ends the current level
980 void EndMultiLevel(int i) {
981 if (basethis->GetLocalRole() != LR_SERVER) {
982 mprintf(0, "You're Not The Server\n");
983 return;
984 }
985 DLLMultiEndLevel();
986 basethis->EnableOnScreenMenu(false);
987 }
988 // Server Only. Automatically balances the teams
989 void BalanceTeams(int i) {
990 if (basethis->GetLocalRole() != LR_SERVER) {
991 mprintf(0, "You're Not The Server\n");
992 return;
993 }
994
995 mprintf(0, "Balancing Teams\n");
996 DPrintf(DTXT_BALANCINGTEAMS);
997
998 // First we need to get a count of how many are on each team
999 int TeamCount[DLLMAX_TEAMS];
1000 for (i = 0; i < DLLMAX_TEAMS; i++)
1001 TeamCount[i] = 0;
1002
1003 for (i = 0; i < DLLMAX_PLAYERS; i++) {
1004 if (basethis->CheckPlayerNum(i)) {
1005 if (basethis->Players[i].team != -1) { // don't count dedicated server
1006 TeamCount[basethis->Players[i].team]++;
1007 }
1008 }
1009 }
1010
1011 // Now determine how many should be on each team
1012 int optcount = 0;
1013 int ingame = 0;
1014 int numteams = basethis->GetNumTeams();
1015
1016 for (i = 0; i < MAX_TEAMS; i++)
1017 ingame += TeamCount[i];
1018
1019 optcount = ingame / numteams;
1020 int leftover = ingame - (optcount * numteams);
1021
1022 // fill in the number of players each team should have
1023 int ShouldHave[MAX_TEAMS];
1024 for (i = 0; i < MAX_TEAMS; i++) {
1025 if (i < numteams) {
1026 ShouldHave[i] = optcount;
1027 } else {
1028 ShouldHave[i] = 0;
1029 }
1030 }
1031
1032 // Make adjustments for the leftover players
1033 for (i = 0; i < leftover; i++)
1034 ShouldHave[i]++;
1035
1036 for (i = 0; i < MAX_TEAMS; i++) {
1037 mprintf(0, "%s team should have %d players and has %d now\n",
1038 basethis->GetTeamString(i),
1039 ShouldHave[i],
1040 TeamCount[i]);
1041 }
1042
1043 // Now move the players around until the teams are of the right size
1044 int j;
1045 for (i = 0; i < MAX_TEAMS; i++) {
1046 while (ShouldHave[i] > TeamCount[i]) {
1047 // We need to adjust this team by adding more players
1048 int pn;
1049 float lowseniority;
1050 int lowpn;
1051
1052 lowseniority = 0;
1053 lowpn = -1;
1054
1055 for (j = 0; j < MAX_TEAMS; j++) {
1056 if (ShouldHave[j] < TeamCount[j]) {
1057 // We can remove a player from this team
1058
1059 // Determine which player has least seniority
1060 for (pn = 0; pn < DLLMAX_PLAYERS; pn++) {
1061 if ((basethis->CheckPlayerNum(pn)) && (basethis->Players[pn].team == j) &&
1062 (basethis->Players[pn].team != -1)) {
1063 // get the pnum, and seniority info here
1064 if (lowseniority < basethis->Players[pn].time_in_game) {
1065 lowpn = pn;
1066 lowseniority = basethis->Players[pn].time_in_game;
1067 }
1068 } // end if
1069 } // end for
1070 if (lowpn != -1) {
1071 TeamCount[j]--;
1072 break;
1073 }
1074
1075 } // end if
1076 } // end for
1077 if (lowpn != -1) {
1078 // Change this player to the new team
1079 TeamCount[i]++;
1080 basethis->RequestTeamChange(i, lowpn, true);
1081 }
1082 } // end while
1083 } // end for
1084 }
1085 // Server Only. Switches AutoTeamSelect On/Off
1086 void SwitchAutoTeamSelect(int i) {
1087 if (basethis->GetLocalRole() != LR_SERVER) {
1088 mprintf(0, "You're Not The Server\n");
1089 return;
1090 }
1091 bool on = (i == 1) ? true : false;
1092 basethis->AutoTeamSelect(on);
1093 }
1094
1095 // Server Only. Switches allowing Team Changing on/off
1096 void SwitchTeamChange(int i) {
1097 if (basethis->GetLocalRole() != LR_SERVER) {
1098 mprintf(0, "You're not the server\n");
1099 return;
1100 }
1101 bool on = (i == 1) ? true : false;
1102 basethis->SwitchAllowTeamChange(on);
1103 }
1104
1105 // Switch's on/off Displaying a player's info
1106 void SwitchPlayerInfo(int pnum) {
1107 if (pnum == -1) {
1108 // the <None> was selected, so make sure that it's turned off
1109 int curr_disp = basethis->DisplayingPlayerInfo();
1110
1111 if (curr_disp == -1) // we're not displaying anyone now anyway
1112 return;
1113
1114 // turn off the pnum given to us
1115 basethis->SwitchPlayerInfoDisplay(curr_disp);
1116
1117 return;
1118 }
1119
1120 if (!basethis->CheckPlayerNum(pnum)) {
1121 mprintf(0, "%d is invalid for playerinfo\n", pnum);
1122 return;
1123 }
1124
1125 int curr_disp = basethis->DisplayingPlayerInfo();
1126
1127 if (curr_disp != -1 && curr_disp != pnum)
1128 basethis->SwitchPlayerInfoDisplay(pnum); // turn it off
1129
1130 basethis->SwitchPlayerInfoDisplay(pnum);
1131
1132 // Make the call to DisplayPlayerInfo now with passing true to dedicated_server so it will
1133 // print the info to the console once
1134 basethis->DisplayPlayerInfo(true);
1135 }
1136
1137 // Switch's on/off Displaying a player's name on the HUD
1138 void SwitchHudPlayerNum(int i) { basethis->SwitchShowHudCallsignLevel(i); }
1139
1140 // Switch the server's Max HUD Callsign level
1141 void SwitchServerHudPlayerName(int i) {
1142 if (basethis->GetLocalRole() != LR_SERVER)
1143 return;
1144 basethis->SwitchServerHudCallsignLevel(i);
1145 }
1146
1147 // Change teams (or more specifically request to change teams)
1148 void ChangeTeams(int team) {
1149 if ((team < 0) || (team > 3)) {
1150 mprintf(0, "Invalid team requested (%d)\n", team);
1151 return;
1152 }
1153 int curr_team = basethis->Players[basethis->GetPlayerNum()].team;
1154
1155 if (curr_team == -1) {
1156 mprintf(0, "Dedicated Server Can't Change Teams\n");
1157 DPrintf(DTXT_NODEDICATEDTEAM);
1158 return;
1159 }
1160
1161 if (team == curr_team) {
1162 mprintf(0, "You're already on the %s team\n", basethis->GetTeamString(team));
1163 DPrintf(DTXT_SAMETEAMCHANGE, basethis->GetTeamString(team));
1164 return;
1165 }
1166 basethis->RequestTeamChange(team, basethis->GetPlayerNum(), true);
1167 }
1168
1169 // Send a request to DMFC to save the game stats to file
1170 void SaveStatsToFile(int i) { basethis->CallOnSaveStatsToFile(); }
1171
1172 // Turns on/off Observer Mode
1173 void SwitchObserverMode(int i) {
1174 object *pobj;
1175 int pnum = basethis->GetPlayerNum();
1176
1177 if ((pnum < 0) || (pnum >= DLLMAX_PLAYERS))
1178 return;
1179
1180 pobj = &basethis->Objects[basethis->Players[pnum].objnum];
1181
1182 mprintf(0, "SwitchObserverMode %s [%d]\n", (i == 1) ? "On" : "Off", pnum);
1183
1184 if (pobj->type == OBJ_OBSERVER) {
1185 if ((i == 0) && (basethis->CallOnAllowObserverChange(false)))
1186 DLLMultiSendRequestToObserve(OBSERVER_MODE_ROAM, 0, 0);
1187 } else {
1188 if ((i == 1) && (basethis->CallOnAllowObserverChange(true)))
1189 DLLMultiSendRequestToObserve(OBSERVER_MODE_ROAM, 1, 0);
1190 }
1191 }
1192
1193 // Turns on/off PiggyBack mode
1194 void SwitchPiggyBack(int pnum) {
1195 if (!basethis->CheckPlayerNum(pnum)) {
1196 return;
1197 }
1198
1199 object *pobj;
1200 pobj = &basethis->Objects[basethis->Players[basethis->GetPlayerNum()].objnum];
1201
1202 if (pobj->type == OBJ_OBSERVER) {
1203 if (basethis->CallOnAllowObserverChange(false))
1204 DLLMultiSendRequestToObserve(OBSERVER_MODE_ROAM, 0, 0);
1205 }
1206 if (pnum == basethis->GetPlayerNum()) {
1207 mprintf(0, "Returning to self\n");
1208 return;
1209 }
1210
1211 if (basethis->CallOnAllowObserverChange(true)) {
1212 mprintf(0, "Switching to piggyback for player %d\n", pnum);
1213 DLLMultiSendRequestToObserve(OBSERVER_MODE_PIGGYBACK, 1, basethis->Players[pnum].objnum);
1214 }
1215 }
1216
1217 // Turns on/off the statistical hud messages
1218 void SwitchStatHUDMessages(int i) {
1219 bool on = (i) ? true : false;
1220 basethis->EnableStatisticalMessages(on);
1221 }
1222
1223 // Exits the on-screen menu
1224 void MenuExitMenu(int i) { basethis->EnableOnScreenMenu(false); }
1225
1226 // Switches on/off auto saving of the stats to file on level end
1227 void SwitchSaveStatsLevelEnd(int i) { basethis->EnableAutoSaveLevelEnd((i) ? true : false); }
1228
1229 // Switches on/off auto saving of the stats to file on disconnect from the game
1230 void SwitchSaveStatsDisconnect(int i) { basethis->EnableAutoSaveDisconnect((i) ? true : false); }
1231
1232 // Switches on/off displaying the background
1233 void SwitchMenuBackground(int i) {
1234 bool on = (i) ? true : false;
1235 basethis->EnableOnScreenMenuBackground(on);
1236 }
1237
1238 // Switches on/off displaying the netgame info
1239 void SwitchNetGameInfo(int i) { basethis->SwitchNetGameInfoDisplay(i); }
1240
1241 // Switches the death message filter
1242 void SwitchDeathMessageFilter(int i) { basethis->SetDeathMessageFilter(i); }
1243
1244 // brings up the team config dialog for the server
1245 void OnScreenDisplayTeamConfig(int i) {
1246 if (basethis->GetLocalRole() != LR_SERVER)
1247 return;
1248 if (basethis->GetNumTeams() < 2)
1249 return;
1250
1251 static char enable;
1252 enable = 2;
1253 basethis->StartUIWindow(UIID_TEAMPLACEMENT, &enable);
1254 basethis->EnableOnScreenMenu(false);
1255 }
1256
1257 // Switches turning on/off displaying ship logos
1258 void SwitchShipLogoEnable(int i) {
1259 bool enable = (i) ? true : false;
1260 basethis->EnableShipLogos(enable);
1261 DLLAddHUDMessage(DTXT_SHIPLOGOSMSG, (enable) ? DTXT_ENABLED : DTXT_DISABLED);
1262 }
1263
1264 void SwitchAudioTauntsEnable(int i) {
1265 bool enable = (i) ? true : false;
1266 basethis->EnableAudioTaunts(enable);
1267 DLLAddHUDMessage(DTXT_AUDIOTAUNTSMSG, (enable) ? DTXT_ENABLED : DTXT_DISABLED);
1268 }
1269
1270 // Rehashs the hosts.allow/deny lists
1271 void RehashAllowDenyLists(int i) {
1272 if (basethis->GetLocalRole() != LR_SERVER)
1273 return;
1274
1275 DLLAddHUDMessage(DTXT_REHASHINGMSG);
1276
1277 basethis->RehashAllowDeny();
1278 }
1279
1280 void SwitchLossPingIndicator(int i) {
1281 bool enable = (i) ? true : false;
1282 basethis->EnableLossGuage(enable);
1283 DLLAddHUDMessage(DTXT_LOSSINDICATOR, (enable) ? DTXT_ENABLED : DTXT_DISABLED);
1284 }