Debian Codegraph @

netgames/hoard/hoard_ui.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/hoard/hoard_ui.cpp $
21 * $Revision: 1.1.1.1 $
22 * $Date: 2003/08/26 03:57:53 $
23 * $Author: kevinb $
24 *
25 * Hoard UI Dialogs
26 *
27 * $Log: hoard_ui.cpp,v $
28 * Revision 1.1.1.1 2003/08/26 03:57:53 kevinb
29 * initial 1.5 import
30 *
31 *
32 * 10 5/19/99 2:42a Jeff
33 * call correct NewUIGameWindow functions
34 *
35 * 9 4/24/99 11:13p Jeff
36 * added flags for creating a newui window for a title bar
37 *
38 * 8 4/14/99 1:17a Jeff
39 * fixed case mismatched #includes
40 *
41 * 7 4/03/99 9:26p Jeff
42 * changed dialogs that weren't using UID_OK and UID_CANCEL to use and
43 * handle them properly
44 *
45 * 6 3/17/99 12:23p Jeff
46 * converted DMFC to be COM interface
47 *
48 * 5 2/11/99 3:54p Jeff
49 * localized
50 *
51 * 4 2/07/99 1:18a Jeff
52 * peppered UI dialogs that were missing NEWUIRES_FORCEQUIT to handle it
53 *
54 * 3 11/20/98 5:52p Jeff
55 * updated hyper anarchy and hoard a little
56 *
57 * 2 11/19/98 5:56p Jeff
58 * added slider exported and improved Hoard
59 *
60 * $NoKeywords: $
61 */
62
63 #include "gamedll_header.h"
64 #include <string.h>
65 #include "idmfc.h"
66 #include "hoardstr.h"
67 #include "hoardaux.h"
68 extern IDMFC *DMFCBase;
69
70 // Displays the Hoard game configuration dialog (Server)
71 void DisplayHoardConfigDialog(tGameConfig *config) {
72 #define WINDOW_H 152
73 #define WINDOW_W 352
74
75 if (DMFCBase->GetLocalRole() != LR_SERVER)
76 return;
77
78 if (DMFCBase->IAmDedicatedServer())
79 return;
80
81 if (config->min_hoard < 1)
82 config->min_hoard = 1;
83 if (config->min_hoard > 12)
84 config->min_hoard = 12;
85
86 // DMFCBase->MakeClientsWait(true);
87
88 // variable declarations
89 // ---------------------
90 bool exit_menu = false;
91 char buffer[10];
92 snprintf(buffer, sizeof(buffer), "%d", config->min_hoard);
93
94 // text items
95 // ----------
96 void *start_game_text_off = DLLCreateNewUITextItem(TXT_RETURNTOGAME, UICOL_HOTSPOT_LO, -1);
97 void *start_game_text_on = DLLCreateNewUITextItem(TXT_RETURNTOGAME, UICOL_HOTSPOT_HI, -1);
98 void *window_title = DLLCreateNewUITextItem(TXT_GAMECONFIG, UICOL_WINDOW_TITLE, -1);
99 void *min_count_label_ti = DLLCreateNewUITextItem(TXT_MINIMUMORBS, UICOL_TEXT_NORMAL, -1);
100 void *slider_val_ti = DLLCreateNewUITextItem(buffer, UICOL_TEXT_NORMAL, -1);
101
102 // main window
103 // -----------
104 void *main_wnd = DLLNewUIGameWindowCreate(0, 0, WINDOW_W, WINDOW_H, UIF_PROCESS_ALL | UIF_CENTER | NUWF_TITLEMED);
105
106 // item placement
107 // --------------
108 int cury = 35;
109 int left_x_col = 20;
110
111 void *start_game_hs = DLLHotSpotCreate(main_wnd, UID_OK, K_ENTER, start_game_text_off, start_game_text_on, 40,
112 WINDOW_H - OKCANCEL_YOFFSET, 130, 15, UIF_CENTER);
113 void *window_title_text = DLLTextCreate(main_wnd, window_title, 0, 7, UIF_CENTER | UIF_FIT);
114 void *min_count_label = DLLTextCreate(main_wnd, min_count_label_ti, left_x_col, cury, UIF_FIT | UIF_CENTER);
115 cury += 15;
116 void *count_slider = DLLSliderCreate(main_wnd, 31, 0, cury, UIF_CENTER | UIF_FIT);
117 cury += 30;
118 DLLSliderSetRange(count_slider, 11);
119 DLLSliderSetPos(count_slider, config->min_hoard - 1);
120 void *slider_val = DLLTextCreate(main_wnd, slider_val_ti, left_x_col, cury, UIF_FIT | UIF_CENTER);
121
122 // show window
123 // -----------
124 DLLNewUIGameWindowOpen(main_wnd);
125
126 // process
127 // -------
128 while (!exit_menu) {
129 int res;
130 res = DLLPollUI();
131
132 if (res == -1)
133 continue;
134
135 switch (res) {
136 case NEWUIRES_FORCEQUIT:
137 exit_menu = true;
138 break;
139 case UID_OK:
140 exit_menu = true;
141 break;
142 case 31: { // update slider
143 DLLRemoveUITextItem(slider_val_ti);
144 char buff[16];
145 int val = DLLSliderGetPos(count_slider);
146 snprintf(buff, sizeof(buff), "%d", val + 1);
147 slider_val_ti = DLLCreateNewUITextItem(buff, UICOL_TEXT_NORMAL, -1);
148 DLLTextSetTitle(slider_val, slider_val_ti);
149 } break;
150 }
151 }
152
153 config->min_hoard = DLLSliderGetPos(count_slider) + 1;
154
155 // close window
156 // ------------
157 DLLNewUIGameWindowClose(main_wnd);
158
159 // free up resources
160 // -----------------
161 DLLNewUIGameWindowDestroy(main_wnd);
162
163 DLLRemoveUITextItem(start_game_text_on);
164 DLLRemoveUITextItem(start_game_text_off);
165 DLLRemoveUITextItem(window_title);
166 DLLRemoveUITextItem(min_count_label_ti);
167 DLLRemoveUITextItem(slider_val_ti);
168
169 DLLDeleteUIItem(main_wnd);
170 DLLDeleteUIItem(start_game_hs);
171 DLLDeleteUIItem(window_title_text);
172 DLLDeleteUIItem(min_count_label);
173 DLLDeleteUIItem(count_slider);
174 DLLDeleteUIItem(slider_val);
175
176 // we're done
177 // ----------
178 // DMFCBase->MakeClientsWait(false);
179
180 SendGameConfig(SP_ALL);
181 }