2006-03-20 17:12:09 +00:00
|
|
|
/*
|
2014-06-01 17:55:23 +00:00
|
|
|
* Portions of this file are copyright Rebirth contributors and licensed as
|
|
|
|
* described in COPYING.txt.
|
|
|
|
* Portions of this file are copyright Parallax Software and licensed
|
|
|
|
* according to the Parallax license below.
|
|
|
|
* See COPYING.txt for license details.
|
|
|
|
|
2006-03-20 17:12:09 +00:00
|
|
|
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
|
|
|
|
SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
|
|
|
|
END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
|
|
|
|
ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
|
|
|
|
IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
|
|
|
|
SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
|
|
|
|
FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
|
|
|
|
CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
|
|
|
|
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
|
|
|
|
COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Dialog box stuff for control centers, material centers, etc.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "fuelcen.h"
|
|
|
|
#include "inferno.h"
|
2015-10-09 02:46:10 +00:00
|
|
|
#include "event.h"
|
2006-03-20 17:12:09 +00:00
|
|
|
#include "segment.h"
|
|
|
|
#include "editor.h"
|
2013-03-16 03:10:55 +00:00
|
|
|
#include "editor/esegment.h"
|
2012-07-01 02:54:33 +00:00
|
|
|
#include "maths.h"
|
2012-07-07 18:35:06 +00:00
|
|
|
#include "dxxerror.h"
|
2021-02-05 12:54:08 +00:00
|
|
|
#include "object.h"
|
2015-04-02 02:36:57 +00:00
|
|
|
#include "robot.h"
|
2006-03-20 17:12:09 +00:00
|
|
|
#include "game.h"
|
|
|
|
#include "powerup.h"
|
|
|
|
#include "medwall.h"
|
|
|
|
#include "eswitch.h"
|
|
|
|
#include "ehostage.h"
|
|
|
|
#include "key.h"
|
|
|
|
#include "medrobot.h"
|
|
|
|
#include "bm.h"
|
|
|
|
#include "centers.h"
|
2013-12-26 04:18:28 +00:00
|
|
|
#include "u_mem.h"
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2014-12-20 04:36:10 +00:00
|
|
|
#include "compiler-range_for.h"
|
2021-11-01 03:37:19 +00:00
|
|
|
#include "d_enumerate.h"
|
2020-05-02 21:18:43 +00:00
|
|
|
#include <memory>
|
2014-12-20 04:36:08 +00:00
|
|
|
|
2006-03-20 17:12:09 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
// Variables for this module...
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
2020-09-21 03:18:12 +00:00
|
|
|
namespace dsx {
|
|
|
|
|
2015-08-12 03:11:46 +00:00
|
|
|
namespace {
|
|
|
|
|
2020-09-21 03:18:12 +00:00
|
|
|
struct centers_dialog : UI_DIALOG
|
2012-03-17 09:39:24 +00:00
|
|
|
{
|
2020-12-19 16:13:26 +00:00
|
|
|
using UI_DIALOG::UI_DIALOG;
|
2014-12-20 04:36:10 +00:00
|
|
|
std::unique_ptr<UI_GADGET_BUTTON> quitButton;
|
2021-11-01 03:37:19 +00:00
|
|
|
enumerated_array<std::unique_ptr<UI_GADGET_RADIO>, MAX_CENTER_TYPES, segment_special> centerFlag;
|
2020-05-02 21:18:42 +00:00
|
|
|
std::array<std::unique_ptr<UI_GADGET_CHECKBOX>, MAX_ROBOT_TYPES> robotMatFlag;
|
2012-03-17 09:39:24 +00:00
|
|
|
int old_seg_num;
|
2020-09-21 03:18:12 +00:00
|
|
|
virtual window_event_result callback_handler(const d_event &) override;
|
2013-12-22 22:03:07 +00:00
|
|
|
};
|
2012-03-17 09:39:24 +00:00
|
|
|
|
2020-09-21 03:18:12 +00:00
|
|
|
static centers_dialog *MainWindow;
|
2015-08-12 03:11:46 +00:00
|
|
|
|
2020-09-21 03:18:12 +00:00
|
|
|
}
|
2012-03-17 09:39:24 +00:00
|
|
|
|
2006-03-20 17:12:09 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
// Called from the editor... does one instance of the centers dialog box
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
int do_centers_dialog()
|
|
|
|
{
|
|
|
|
// Only open 1 instance of this window...
|
|
|
|
if ( MainWindow != NULL ) return 0;
|
|
|
|
|
|
|
|
// Close other windows.
|
|
|
|
close_trigger_window();
|
2020-09-21 03:18:12 +00:00
|
|
|
#if defined(DXX_BUILD_DESCENT_I)
|
2006-03-20 17:12:09 +00:00
|
|
|
hostage_close_window();
|
2020-09-21 03:18:12 +00:00
|
|
|
#endif
|
2006-03-20 17:12:09 +00:00
|
|
|
close_wall_window();
|
|
|
|
robot_close_window();
|
|
|
|
|
|
|
|
// Open a window with a quit button
|
2013-03-03 01:03:33 +00:00
|
|
|
#if defined(DXX_BUILD_DESCENT_I)
|
2014-12-20 04:36:08 +00:00
|
|
|
const unsigned x = TMAPBOX_X+20;
|
|
|
|
const unsigned width = 765-TMAPBOX_X;
|
2013-03-03 01:03:33 +00:00
|
|
|
#elif defined(DXX_BUILD_DESCENT_II)
|
2014-12-20 04:36:08 +00:00
|
|
|
const unsigned x = 20;
|
|
|
|
const unsigned width = 740;
|
2013-03-03 01:03:33 +00:00
|
|
|
#endif
|
2020-12-19 16:13:26 +00:00
|
|
|
MainWindow = window_create<centers_dialog>(x, TMAPBOX_Y + 20, width, 545 - TMAPBOX_Y, DF_DIALOG);
|
2014-12-20 04:36:08 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2020-09-21 03:18:12 +00:00
|
|
|
static window_event_result centers_dialog_created(centers_dialog *const c)
|
2014-12-20 04:36:08 +00:00
|
|
|
{
|
|
|
|
#if defined(DXX_BUILD_DESCENT_I)
|
|
|
|
int i = 80;
|
|
|
|
#elif defined(DXX_BUILD_DESCENT_II)
|
|
|
|
int i = 40;
|
|
|
|
#endif
|
2020-10-12 03:28:26 +00:00
|
|
|
c->quitButton = ui_add_gadget_button(*c, 20, 252, 48, 40, "Done", nullptr);
|
2006-03-20 17:12:09 +00:00
|
|
|
// These are the checkboxes for each door flag.
|
2021-11-01 03:37:19 +00:00
|
|
|
c->centerFlag[segment_special::nothing] = ui_add_gadget_radio(*c, 18, i, 16, 16, 0, "NONE"); i += 24;
|
|
|
|
c->centerFlag[segment_special::fuelcen] = ui_add_gadget_radio(*c, 18, i, 16, 16, 0, "FuelCen"); i += 24;
|
|
|
|
c->centerFlag[segment_special::repaircen] = ui_add_gadget_radio(*c, 18, i, 16, 16, 0, "RepairCen"); i += 24;
|
|
|
|
c->centerFlag[segment_special::controlcen] = ui_add_gadget_radio(*c, 18, i, 16, 16, 0, "ControlCen"); i += 24;
|
|
|
|
c->centerFlag[segment_special::robotmaker] = ui_add_gadget_radio(*c, 18, i, 16, 16, 0, "RobotCen"); i += 24;
|
2013-03-03 01:03:33 +00:00
|
|
|
#if defined(DXX_BUILD_DESCENT_II)
|
2021-11-01 03:37:19 +00:00
|
|
|
c->centerFlag[segment_special::goal_blue] = ui_add_gadget_radio(*c, 18, i, 16, 16, 0, "Blue Goal"); i += 24;
|
|
|
|
c->centerFlag[segment_special::goal_red] = ui_add_gadget_radio(*c, 18, i, 16, 16, 0, "Red Goal"); i += 24;
|
2013-03-03 01:03:33 +00:00
|
|
|
#endif
|
2006-03-20 17:12:09 +00:00
|
|
|
// These are the checkboxes for each robot flag.
|
2013-03-03 01:03:33 +00:00
|
|
|
#if defined(DXX_BUILD_DESCENT_I)
|
|
|
|
const unsigned d = 2;
|
|
|
|
#elif defined(DXX_BUILD_DESCENT_II)
|
|
|
|
const unsigned d = 6;
|
|
|
|
#endif
|
2018-12-30 00:43:59 +00:00
|
|
|
const auto N_robot_types = LevelSharedRobotInfoState.N_robot_types;
|
2014-12-20 04:36:08 +00:00
|
|
|
for (i=0; i < N_robot_types; i++)
|
2020-10-12 03:28:26 +00:00
|
|
|
c->robotMatFlag[i] = ui_add_gadget_checkbox(*c, 128 + (i % d) * 92, 20 + (i / d) * 24, 16, 16, 0, Robot_names[i].data());
|
2012-03-17 09:39:24 +00:00
|
|
|
c->old_seg_num = -2; // Set to some dummy value so everything works ok on the first frame.
|
2016-10-04 07:58:20 +00:00
|
|
|
return window_event_result::handled;
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void close_centers_window()
|
|
|
|
{
|
|
|
|
if ( MainWindow!=NULL ) {
|
2020-10-12 03:28:26 +00:00
|
|
|
ui_close_dialog(*std::exchange(MainWindow, nullptr));
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-21 03:18:12 +00:00
|
|
|
window_event_result centers_dialog::callback_handler(const d_event &event)
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
2019-02-02 18:36:39 +00:00
|
|
|
auto &RobotCenters = LevelSharedRobotcenterState.RobotCenters;
|
2014-12-20 04:36:08 +00:00
|
|
|
switch(event.type)
|
|
|
|
{
|
|
|
|
case EVENT_WINDOW_CREATED:
|
2020-09-21 03:18:12 +00:00
|
|
|
return centers_dialog_created(this);
|
2014-12-20 04:36:08 +00:00
|
|
|
case EVENT_WINDOW_CLOSE:
|
|
|
|
MainWindow = NULL;
|
2016-10-04 07:58:20 +00:00
|
|
|
return window_event_result::ignored;
|
2014-12-20 04:36:08 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2012-03-17 09:39:24 +00:00
|
|
|
// int robot_flags;
|
|
|
|
int keypress = 0;
|
2016-10-04 07:58:20 +00:00
|
|
|
window_event_result rval = window_event_result::ignored;
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2012-03-17 09:39:24 +00:00
|
|
|
Assert(MainWindow != NULL);
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2014-10-04 21:47:13 +00:00
|
|
|
if (event.type == EVENT_KEY_COMMAND)
|
2012-03-17 09:39:24 +00:00
|
|
|
keypress = event_key_get(event);
|
|
|
|
|
2006-03-20 17:12:09 +00:00
|
|
|
//------------------------------------------------------------
|
|
|
|
// Call the ui code..
|
|
|
|
//------------------------------------------------------------
|
|
|
|
ui_button_any_drawn = 0;
|
|
|
|
|
2018-12-30 00:43:59 +00:00
|
|
|
const auto N_robot_types = LevelSharedRobotInfoState.N_robot_types;
|
|
|
|
|
2006-03-20 17:12:09 +00:00
|
|
|
//------------------------------------------------------------
|
2010-12-24 04:34:30 +00:00
|
|
|
// If we change centers, we need to reset the ui code for all
|
|
|
|
// of the checkboxes that control the center flags.
|
2006-03-20 17:12:09 +00:00
|
|
|
//------------------------------------------------------------
|
2020-09-21 03:18:12 +00:00
|
|
|
if (old_seg_num != Cursegp)
|
2010-12-24 04:34:30 +00:00
|
|
|
{
|
2020-09-21 03:18:12 +00:00
|
|
|
range_for (auto &i, centerFlag)
|
2020-10-12 03:28:26 +00:00
|
|
|
ui_radio_set_value(*i, 0);
|
2010-12-24 04:34:30 +00:00
|
|
|
|
2020-10-12 03:28:26 +00:00
|
|
|
ui_radio_set_value(*centerFlag[Cursegp->special], 1);
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
// Read materialization center robot bit flags
|
2016-05-21 17:24:51 +00:00
|
|
|
for (unsigned i = 0, n = N_robot_types; i < n; ++i)
|
2020-09-21 03:18:12 +00:00
|
|
|
ui_checkbox_check(robotMatFlag[i].get(), RobotCenters[Cursegp->matcen_num].robot_flags[i / 32] & (1 << (i % 32)));
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------
|
|
|
|
// If any of the radio buttons that control the mode are set, then
|
|
|
|
// update the corresponding center.
|
|
|
|
//------------------------------------------------------------
|
|
|
|
|
2021-11-01 03:37:19 +00:00
|
|
|
for (auto &&[i, flag] : enumerate(centerFlag))
|
2012-03-17 09:39:24 +00:00
|
|
|
{
|
2021-11-01 03:37:19 +00:00
|
|
|
if (GADGET_PRESSED(flag.get()))
|
2012-03-17 09:39:24 +00:00
|
|
|
{
|
2021-11-01 03:37:19 +00:00
|
|
|
if (i == segment_special::nothing)
|
2006-03-20 17:12:09 +00:00
|
|
|
fuelcen_delete(Cursegp);
|
2013-03-03 01:03:33 +00:00
|
|
|
else if (Cursegp->special != i)
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
|
|
|
fuelcen_delete(Cursegp);
|
2012-03-24 09:19:30 +00:00
|
|
|
Update_flags |= UF_WORLD_CHANGED;
|
2016-10-29 23:16:17 +00:00
|
|
|
Cursegp->special = i;
|
|
|
|
fuelcen_activate(Cursegp);
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
2016-10-04 07:58:20 +00:00
|
|
|
rval = window_event_result::handled;
|
2012-03-17 09:39:24 +00:00
|
|
|
}
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
2016-05-21 17:24:51 +00:00
|
|
|
for (unsigned i = 0, n = N_robot_types; i < n; ++i)
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
2020-09-21 03:18:12 +00:00
|
|
|
if (GADGET_PRESSED(robotMatFlag[i].get()))
|
2012-03-17 09:39:24 +00:00
|
|
|
{
|
2016-05-21 17:24:51 +00:00
|
|
|
auto &f = RobotCenters[Cursegp->matcen_num].robot_flags[i / 32];
|
|
|
|
const auto mask = 1 << (i % 32);
|
2020-09-21 03:18:12 +00:00
|
|
|
if (robotMatFlag[i]->flag)
|
2016-05-21 17:24:51 +00:00
|
|
|
f |= mask;
|
2012-03-17 09:39:24 +00:00
|
|
|
else
|
2016-05-21 17:24:51 +00:00
|
|
|
f &= ~mask;
|
2016-10-04 07:58:20 +00:00
|
|
|
rval = window_event_result::handled;
|
2012-03-17 09:39:24 +00:00
|
|
|
}
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------
|
|
|
|
// If anything changes in the ui system, redraw all the text that
|
|
|
|
// identifies this wall.
|
|
|
|
//------------------------------------------------------------
|
2014-10-04 21:47:13 +00:00
|
|
|
if (event.type == EVENT_UI_DIALOG_DRAW)
|
2012-03-24 09:19:30 +00:00
|
|
|
{
|
2006-03-20 17:12:09 +00:00
|
|
|
// int i;
|
|
|
|
|
2020-09-21 03:18:12 +00:00
|
|
|
ui_dprintf_at(this, 12, 6, "Seg: %3hu", static_cast<segnum_t>(Cursegp));
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
2020-09-21 03:18:12 +00:00
|
|
|
if (old_seg_num != Cursegp)
|
2012-03-24 09:19:30 +00:00
|
|
|
Update_flags |= UF_WORLD_CHANGED;
|
2020-09-21 03:18:12 +00:00
|
|
|
if (GADGET_PRESSED(quitButton.get()) || keypress == KEY_ESC)
|
2012-03-17 09:39:24 +00:00
|
|
|
{
|
2016-10-27 09:15:31 +00:00
|
|
|
return window_event_result::close;
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
2020-09-21 03:18:12 +00:00
|
|
|
old_seg_num = Cursegp;
|
2012-03-17 09:39:24 +00:00
|
|
|
return rval;
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
2020-09-21 03:18:12 +00:00
|
|
|
}
|