| 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 "inferno.h" |
| 33 |
#include "event.h" |
| 34 |
#include "segment.h" |
| 35 |
#include "editor.h" |
| 36 |
#include "editor/esegment.h" |
| 37 |
#include "maths.h" |
| 38 |
#include "dxxerror.h" |
| 39 |
#include "object.h" |
| 40 |
#include "robot.h" |
| 41 |
#include "game.h" |
| 42 |
#include "powerup.h" |
| 43 |
#include "medwall.h" |
| 44 |
#include "eswitch.h" |
| 45 |
#include "ehostage.h" |
| 46 |
#include "key.h" |
| 47 |
#include "medrobot.h" |
| 48 |
#include "bm.h" |
| 49 |
#include "centers.h" |
| 50 |
#include "u_mem.h" |
| 51 |
|
| 52 |
#include "compiler-range_for.h" |
| 53 |
#include "d_enumerate.h" |
| 54 |
#include <memory> |
| 55 |
|
| 56 |
//------------------------------------------------------------------------- |
| 57 |
// Variables for this module... |
| 58 |
//------------------------------------------------------------------------- |
| 59 |
|
| 60 |
namespace dsx { |
| 61 |
|
| 62 |
namespace { |
| 63 |
|
| 64 |
struct centers_dialog : UI_DIALOG |
| 65 |
{ |
| 66 |
using UI_DIALOG::UI_DIALOG; |
| 67 |
std::unique_ptr<UI_GADGET_BUTTON> quitButton; |
| 68 |
enumerated_array<std::unique_ptr<UI_GADGET_RADIO>, MAX_CENTER_TYPES, segment_special> centerFlag; |
| 69 |
std::array<std::unique_ptr<UI_GADGET_CHECKBOX>, MAX_ROBOT_TYPES> robotMatFlag; |
| 70 |
int old_seg_num; |
| 71 |
virtual window_event_result callback_handler(const d_event &) override; |
| 72 |
}; |
| 73 |
|
| 74 |
static centers_dialog *MainWindow; |
| 75 |
|
| 76 |
} |
| 77 |
|
| 78 |
//------------------------------------------------------------------------- |
| 79 |
// Called from the editor... does one instance of the centers dialog box |
| 80 |
//------------------------------------------------------------------------- |
| 81 |
int do_centers_dialog() |
| 82 |
{ |
| 83 |
// Only open 1 instance of this window... |
| 84 |
if ( MainWindow != NULL ) return 0; |
| 85 |
|
| 86 |
// Close other windows. |
| 87 |
close_trigger_window(); |
| 88 |
#if DXX_BUILD_DESCENT == 1 |
| 89 |
hostage_close_window(); |
| 90 |
#endif |
| 91 |
close_wall_window(); |
| 92 |
robot_close_window(); |
| 93 |
|
| 94 |
// Open a window with a quit button |
| 95 |
#if DXX_BUILD_DESCENT == 1 |
| 96 |
const unsigned x = TMAPBOX_X+20; |
| 97 |
const unsigned width = 765-TMAPBOX_X; |
| 98 |
#elif DXX_BUILD_DESCENT == 2 |
| 99 |
const unsigned x = 20; |
| 100 |
const unsigned width = 740; |
| 101 |
#endif |
| 102 |
MainWindow = window_create<centers_dialog>(x, TMAPBOX_Y + 20, width, 545 - TMAPBOX_Y, DF_DIALOG); |
| 103 |
return 1; |
| 104 |
} |
| 105 |
|
| 106 |
static window_event_result centers_dialog_created(centers_dialog *const c) |
| 107 |
{ |
| 108 |
#if DXX_BUILD_DESCENT == 1 |
| 109 |
int i{80}; |
| 110 |
#elif DXX_BUILD_DESCENT == 2 |
| 111 |
int i{40}; |
| 112 |
#endif |
| 113 |
c->quitButton = ui_add_gadget_button(*c, 20, 252, 48, 40, "Done", nullptr); |
| 114 |
// These are the checkboxes for each door flag. |
| 115 |
c->centerFlag[segment_special::nothing] = ui_add_gadget_radio(*c, 18, i, 16, 16, 0, "NONE"); i += 24; |
| 116 |
c->centerFlag[segment_special::fuelcen] = ui_add_gadget_radio(*c, 18, i, 16, 16, 0, "FuelCen"); i += 24; |
| 117 |
c->centerFlag[segment_special::repaircen] = ui_add_gadget_radio(*c, 18, i, 16, 16, 0, "RepairCen"); i += 24; |
| 118 |
c->centerFlag[segment_special::controlcen] = ui_add_gadget_radio(*c, 18, i, 16, 16, 0, "ControlCen"); i += 24; |
| 119 |
c->centerFlag[segment_special::robotmaker] = ui_add_gadget_radio(*c, 18, i, 16, 16, 0, "RobotCen"); i += 24; |
| 120 |
#if DXX_BUILD_DESCENT == 2 |
| 121 |
c->centerFlag[segment_special::goal_blue] = ui_add_gadget_radio(*c, 18, i, 16, 16, 0, "Blue Goal"); i += 24; |
| 122 |
c->centerFlag[segment_special::goal_red] = ui_add_gadget_radio(*c, 18, i, 16, 16, 0, "Red Goal"); i += 24; |
| 123 |
#endif |
| 124 |
// These are the checkboxes for each robot flag. |
| 125 |
#if DXX_BUILD_DESCENT == 1 |
| 126 |
const unsigned d = 2; |
| 127 |
#elif DXX_BUILD_DESCENT == 2 |
| 128 |
const unsigned d = 6; |
| 129 |
#endif |
| 130 |
const auto N_robot_types = LevelSharedRobotInfoState.N_robot_types; |
| 131 |
for (i=0; i < N_robot_types; i++) |
| 132 |
c->robotMatFlag[i] = ui_add_gadget_checkbox(*c, 128 + (i % d) * 92, 20 + (i / d) * 24, 16, 16, 0, Robot_names[static_cast<robot_id>(i)].data()); |
| 133 |
c->old_seg_num = -2; // Set to some dummy value so everything works ok on the first frame. |
| 134 |
return window_event_result::handled; |
| 135 |
} |
| 136 |
|
| 137 |
void close_centers_window() |
| 138 |
{ |
| 139 |
if ( MainWindow!=NULL ) { |
| 140 |
ui_close_dialog(*std::exchange(MainWindow, nullptr)); |
| 141 |
} |
| 142 |
} |
| 143 |
|
| 144 |
window_event_result centers_dialog::callback_handler(const d_event &event) |
| 145 |
{ |
| 146 |
auto &RobotCenters = LevelSharedRobotcenterState.RobotCenters; |
| 147 |
switch(event.type) |
| 148 |
{ |
| 149 |
case event_type::window_created: |
| 150 |
return centers_dialog_created(this); |
| 151 |
case event_type::window_close: |
| 152 |
MainWindow = NULL; |
| 153 |
return window_event_result::ignored; |
| 154 |
default: |
| 155 |
break; |
| 156 |
} |
| 157 |
// int robot_flags; |
| 158 |
int keypress{0}; |
| 159 |
window_event_result rval = window_event_result::ignored; |
| 160 |
|
| 161 |
Assert(MainWindow != NULL); |
| 162 |
|
| 163 |
if (event.type == event_type::key_command) |
| 164 |
keypress = event_key_get(event); |
| 165 |
//------------------------------------------------------------ |
| 166 |
// Call the ui code.. |
| 167 |
//------------------------------------------------------------ |
| 168 |
ui_button_any_drawn = 0; |
| 169 |
|
| 170 |
const auto N_robot_types = LevelSharedRobotInfoState.N_robot_types; |
| 171 |
|
| 172 |
//------------------------------------------------------------ |
| 173 |
// If we change centers, we need to reset the ui code for all |
| 174 |
// of the checkboxes that control the center flags. |
| 175 |
//------------------------------------------------------------ |
| 176 |
if (old_seg_num != Cursegp) |
| 177 |
{ |
| 178 |
range_for (auto &i, centerFlag) |
| 179 |
ui_radio_set_value(*i, 0); |
| 180 |
|
| 181 |
ui_radio_set_value(*centerFlag[Cursegp->special], 1); |
| 182 |
|
| 183 |
// Read materialization center robot bit flags |
| 184 |
for (unsigned i = 0, n = N_robot_types; i < n; ++i) |
| 185 |
ui_checkbox_check(robotMatFlag[i].get(), RobotCenters[Cursegp->matcen_num].robot_flags[i / 32] & (1 << (i % 32))); |
| 186 |
} |
| 187 |
|
| 188 |
//------------------------------------------------------------ |
| 189 |
// If any of the radio buttons that control the mode are set, then |
| 190 |
// update the corresponding center. |
| 191 |
//------------------------------------------------------------ |
| 192 |
|
| 193 |
for (auto &&[i, flag] : enumerate(centerFlag)) |
| 194 |
{ |
| 195 |
if (GADGET_PRESSED(flag.get())) |
| 196 |
{ |
| 197 |
if (i == segment_special::nothing) |
| 198 |
fuelcen_delete(Cursegp); |
| 199 |
else if (Cursegp->special != i) |
| 200 |
{ |
| 201 |
fuelcen_delete(Cursegp); |
| 202 |
Update_flags |= UF_WORLD_CHANGED; |
| 203 |
Cursegp->special = i; |
| 204 |
fuelcen_activate(Cursegp); |
| 205 |
} |
| 206 |
rval = window_event_result::handled; |
| 207 |
} |
| 208 |
} |
| 209 |
|
| 210 |
for (unsigned i = 0, n = N_robot_types; i < n; ++i) |
| 211 |
{ |
| 212 |
if (GADGET_PRESSED(robotMatFlag[i].get())) |
| 213 |
{ |
| 214 |
auto &f = RobotCenters[Cursegp->matcen_num].robot_flags[i / 32]; |
| 215 |
const auto mask = 1 << (i % 32); |
| 216 |
if (robotMatFlag[i]->flag) |
| 217 |
f |= mask; |
| 218 |
else |
| 219 |
f &= ~mask; |
| 220 |
rval = window_event_result::handled; |
| 221 |
} |
| 222 |
} |
| 223 |
//------------------------------------------------------------ |
| 224 |
// If anything changes in the ui system, redraw all the text that |
| 225 |
// identifies this wall. |
| 226 |
//------------------------------------------------------------ |
| 227 |
if (event.type == event_type::ui_dialog_draw) |
| 228 |
{ |
| 229 |
ui_dprintf_at(this, 12, 6, "Seg: %3hu", static_cast<segnum_t>(Cursegp)); |
| 230 |
} |
| 231 |
|
| 232 |
if (old_seg_num != Cursegp) |
| 233 |
Update_flags |= UF_WORLD_CHANGED; |
| 234 |
if (GADGET_PRESSED(quitButton.get()) || keypress == KEY_ESC) |
| 235 |
{ |
| 236 |
return window_event_result::close; |
| 237 |
} |
| 238 |
|
| 239 |
old_seg_num = Cursegp; |
| 240 |
return rval; |
| 241 |
} |
| 242 |
|
| 243 |
} |