Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | pmbaty | 1 | /* |
2 | * Portions of this file are copyright Rebirth contributors and licensed as |
||
3 | * described in COPYING.txt. |
||
4 | * Portions of this file are copyright Parallax Software and licensed |
||
5 | * according to the Parallax license below. |
||
6 | * See COPYING.txt for license details. |
||
7 | |||
8 | THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX |
||
9 | SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO |
||
10 | END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A |
||
11 | ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS |
||
12 | IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS |
||
13 | SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE |
||
14 | FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE |
||
15 | CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS |
||
16 | AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. |
||
17 | COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. |
||
18 | */ |
||
19 | |||
20 | /* |
||
21 | * |
||
22 | * Dialog box stuff for control centers, material centers, etc. |
||
23 | * |
||
24 | */ |
||
25 | |||
26 | #include <stdio.h> |
||
27 | #include <stdlib.h> |
||
28 | #include <math.h> |
||
29 | #include <string.h> |
||
30 | |||
31 | #include "fuelcen.h" |
||
32 | #include "screens.h" |
||
33 | #include "inferno.h" |
||
34 | #include "event.h" |
||
35 | #include "segment.h" |
||
36 | #include "editor.h" |
||
37 | #include "editor/esegment.h" |
||
38 | #include "timer.h" |
||
39 | #include "objpage.h" |
||
40 | #include "maths.h" |
||
41 | #include "dxxerror.h" |
||
42 | #include "kdefs.h" |
||
43 | #include "object.h" |
||
44 | #include "robot.h" |
||
45 | #include "game.h" |
||
46 | #include "powerup.h" |
||
47 | #include "ai.h" |
||
48 | #include "hostage.h" |
||
49 | #include "eobject.h" |
||
50 | #include "medwall.h" |
||
51 | #include "eswitch.h" |
||
52 | #include "ehostage.h" |
||
53 | #include "key.h" |
||
54 | #include "medrobot.h" |
||
55 | #include "bm.h" |
||
56 | #include "centers.h" |
||
57 | #include "u_mem.h" |
||
58 | |||
59 | #include "compiler-range_for.h" |
||
60 | #include <memory> |
||
61 | |||
62 | //------------------------------------------------------------------------- |
||
63 | // Variables for this module... |
||
64 | //------------------------------------------------------------------------- |
||
65 | static UI_DIALOG *MainWindow = NULL; |
||
66 | |||
67 | namespace { |
||
68 | |||
69 | struct centers_dialog |
||
70 | { |
||
71 | std::unique_ptr<UI_GADGET_BUTTON> quitButton; |
||
72 | std::array<std::unique_ptr<UI_GADGET_RADIO>, MAX_CENTER_TYPES> centerFlag; |
||
73 | std::array<std::unique_ptr<UI_GADGET_CHECKBOX>, MAX_ROBOT_TYPES> robotMatFlag; |
||
74 | int old_seg_num; |
||
75 | }; |
||
76 | |||
77 | } |
||
78 | |||
79 | static window_event_result centers_dialog_handler(UI_DIALOG *dlg,const d_event &event, centers_dialog *c); |
||
80 | |||
81 | //------------------------------------------------------------------------- |
||
82 | // Called from the editor... does one instance of the centers dialog box |
||
83 | //------------------------------------------------------------------------- |
||
84 | namespace dsx { |
||
85 | int do_centers_dialog() |
||
86 | { |
||
87 | // Only open 1 instance of this window... |
||
88 | if ( MainWindow != NULL ) return 0; |
||
89 | |||
90 | // Close other windows. |
||
91 | close_trigger_window(); |
||
92 | hostage_close_window(); |
||
93 | close_wall_window(); |
||
94 | robot_close_window(); |
||
95 | |||
96 | auto c = std::make_unique<centers_dialog>(); |
||
97 | // Open a window with a quit button |
||
98 | #if defined(DXX_BUILD_DESCENT_I) |
||
99 | const unsigned x = TMAPBOX_X+20; |
||
100 | const unsigned width = 765-TMAPBOX_X; |
||
101 | #elif defined(DXX_BUILD_DESCENT_II) |
||
102 | const unsigned x = 20; |
||
103 | const unsigned width = 740; |
||
104 | #endif |
||
105 | MainWindow = ui_create_dialog(x, TMAPBOX_Y+20, width, 545-TMAPBOX_Y, DF_DIALOG, centers_dialog_handler, std::move(c)); |
||
106 | return 1; |
||
107 | } |
||
108 | } |
||
109 | |||
110 | namespace dsx { |
||
111 | static window_event_result centers_dialog_created(UI_DIALOG *const w, centers_dialog *const c) |
||
112 | { |
||
113 | #if defined(DXX_BUILD_DESCENT_I) |
||
114 | int i = 80; |
||
115 | #elif defined(DXX_BUILD_DESCENT_II) |
||
116 | int i = 40; |
||
117 | #endif |
||
118 | c->quitButton = ui_add_gadget_button(w, 20, 252, 48, 40, "Done", NULL); |
||
119 | // These are the checkboxes for each door flag. |
||
120 | c->centerFlag[0] = ui_add_gadget_radio(w, 18, i, 16, 16, 0, "NONE"); i += 24; |
||
121 | c->centerFlag[1] = ui_add_gadget_radio(w, 18, i, 16, 16, 0, "FuelCen"); i += 24; |
||
122 | c->centerFlag[2] = ui_add_gadget_radio(w, 18, i, 16, 16, 0, "RepairCen"); i += 24; |
||
123 | c->centerFlag[3] = ui_add_gadget_radio(w, 18, i, 16, 16, 0, "ControlCen"); i += 24; |
||
124 | c->centerFlag[4] = ui_add_gadget_radio(w, 18, i, 16, 16, 0, "RobotCen"); i += 24; |
||
125 | #if defined(DXX_BUILD_DESCENT_II) |
||
126 | c->centerFlag[5] = ui_add_gadget_radio(w, 18, i, 16, 16, 0, "Blue Goal"); i += 24; |
||
127 | c->centerFlag[6] = ui_add_gadget_radio(w, 18, i, 16, 16, 0, "Red Goal"); i += 24; |
||
128 | #endif |
||
129 | // These are the checkboxes for each robot flag. |
||
130 | #if defined(DXX_BUILD_DESCENT_I) |
||
131 | const unsigned d = 2; |
||
132 | #elif defined(DXX_BUILD_DESCENT_II) |
||
133 | const unsigned d = 6; |
||
134 | #endif |
||
135 | const auto N_robot_types = LevelSharedRobotInfoState.N_robot_types; |
||
136 | for (i=0; i < N_robot_types; i++) |
||
137 | c->robotMatFlag[i] = ui_add_gadget_checkbox( w, 128 + (i%d)*92, 20+(i/d)*24, 16, 16, 0, Robot_names[i].data()); |
||
138 | c->old_seg_num = -2; // Set to some dummy value so everything works ok on the first frame. |
||
139 | return window_event_result::handled; |
||
140 | } |
||
141 | } |
||
142 | |||
143 | void close_centers_window() |
||
144 | { |
||
145 | if ( MainWindow!=NULL ) { |
||
146 | ui_close_dialog( MainWindow ); |
||
147 | MainWindow = NULL; |
||
148 | } |
||
149 | } |
||
150 | |||
151 | window_event_result centers_dialog_handler(UI_DIALOG *dlg,const d_event &event, centers_dialog *c) |
||
152 | { |
||
153 | auto &RobotCenters = LevelSharedRobotcenterState.RobotCenters; |
||
154 | switch(event.type) |
||
155 | { |
||
156 | case EVENT_WINDOW_CREATED: |
||
157 | return centers_dialog_created(dlg, c); |
||
158 | case EVENT_WINDOW_CLOSE: |
||
159 | std::default_delete<centers_dialog>()(c); |
||
160 | MainWindow = NULL; |
||
161 | return window_event_result::ignored; |
||
162 | default: |
||
163 | break; |
||
164 | } |
||
165 | // int robot_flags; |
||
166 | int keypress = 0; |
||
167 | window_event_result rval = window_event_result::ignored; |
||
168 | |||
169 | Assert(MainWindow != NULL); |
||
170 | |||
171 | if (event.type == EVENT_KEY_COMMAND) |
||
172 | keypress = event_key_get(event); |
||
173 | |||
174 | //------------------------------------------------------------ |
||
175 | // Call the ui code.. |
||
176 | //------------------------------------------------------------ |
||
177 | ui_button_any_drawn = 0; |
||
178 | |||
179 | const auto N_robot_types = LevelSharedRobotInfoState.N_robot_types; |
||
180 | |||
181 | //------------------------------------------------------------ |
||
182 | // If we change centers, we need to reset the ui code for all |
||
183 | // of the checkboxes that control the center flags. |
||
184 | //------------------------------------------------------------ |
||
185 | if (c->old_seg_num != Cursegp) |
||
186 | { |
||
187 | range_for (auto &i, c->centerFlag) |
||
188 | ui_radio_set_value(i.get(), 0); |
||
189 | |||
190 | Assert(Cursegp->special < MAX_CENTER_TYPES); |
||
191 | ui_radio_set_value(c->centerFlag[Cursegp->special].get(), 1); |
||
192 | |||
193 | // Read materialization center robot bit flags |
||
194 | for (unsigned i = 0, n = N_robot_types; i < n; ++i) |
||
195 | ui_checkbox_check(c->robotMatFlag[i].get(), RobotCenters[Cursegp->matcen_num].robot_flags[i / 32] & (1 << (i % 32))); |
||
196 | } |
||
197 | |||
198 | //------------------------------------------------------------ |
||
199 | // If any of the radio buttons that control the mode are set, then |
||
200 | // update the corresponding center. |
||
201 | //------------------------------------------------------------ |
||
202 | |||
203 | for (unsigned i = 0; i < MAX_CENTER_TYPES; ++i) |
||
204 | { |
||
205 | if (GADGET_PRESSED(c->centerFlag[i].get())) |
||
206 | { |
||
207 | if ( i == 0) |
||
208 | fuelcen_delete(Cursegp); |
||
209 | else if (Cursegp->special != i) |
||
210 | { |
||
211 | fuelcen_delete(Cursegp); |
||
212 | Update_flags |= UF_WORLD_CHANGED; |
||
213 | Cursegp->special = i; |
||
214 | fuelcen_activate(Cursegp); |
||
215 | } |
||
216 | rval = window_event_result::handled; |
||
217 | } |
||
218 | } |
||
219 | |||
220 | for (unsigned i = 0, n = N_robot_types; i < n; ++i) |
||
221 | { |
||
222 | if (GADGET_PRESSED(c->robotMatFlag[i].get())) |
||
223 | { |
||
224 | auto &f = RobotCenters[Cursegp->matcen_num].robot_flags[i / 32]; |
||
225 | const auto mask = 1 << (i % 32); |
||
226 | if (c->robotMatFlag[i]->flag) |
||
227 | f |= mask; |
||
228 | else |
||
229 | f &= ~mask; |
||
230 | rval = window_event_result::handled; |
||
231 | } |
||
232 | } |
||
233 | |||
234 | //------------------------------------------------------------ |
||
235 | // If anything changes in the ui system, redraw all the text that |
||
236 | // identifies this wall. |
||
237 | //------------------------------------------------------------ |
||
238 | if (event.type == EVENT_UI_DIALOG_DRAW) |
||
239 | { |
||
240 | // int i; |
||
241 | |||
242 | ui_dprintf_at(dlg, 12, 6, "Seg: %3hu", static_cast<segnum_t>(Cursegp)); |
||
243 | } |
||
244 | |||
245 | if (c->old_seg_num != Cursegp) |
||
246 | Update_flags |= UF_WORLD_CHANGED; |
||
247 | if (GADGET_PRESSED(c->quitButton.get()) || keypress==KEY_ESC) |
||
248 | { |
||
249 | return window_event_result::close; |
||
250 | } |
||
251 | |||
252 | c->old_seg_num = Cursegp; |
||
253 | |||
254 | return rval; |
||
255 | } |
||
256 | |||
257 | |||
258 |