Use unique_ptr for robot_dialog
This commit is contained in:
parent
7e4e8f3501
commit
63ee79d988
|
@ -55,6 +55,8 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
|||
#include "bm.h"
|
||||
#include "u_mem.h"
|
||||
|
||||
#include "compiler-make_unique.h"
|
||||
|
||||
#define NUM_BOXES 6 // Number of boxes, AI modes
|
||||
|
||||
static int GoodyNextID();
|
||||
|
@ -459,16 +461,10 @@ void close_all_windows(void)
|
|||
//-------------------------------------------------------------------------
|
||||
int do_robot_dialog()
|
||||
{
|
||||
int i;
|
||||
robot_dialog *r;
|
||||
|
||||
// Only open 1 instance of this window...
|
||||
if ( MainWindow != NULL ) return 0;
|
||||
|
||||
MALLOC(r, robot_dialog, 1);
|
||||
if (!r)
|
||||
return 0;
|
||||
|
||||
auto r = make_unique<robot_dialog>();
|
||||
// Close other windows
|
||||
close_all_windows();
|
||||
Cur_goody_count = 0;
|
||||
|
@ -476,53 +472,44 @@ int do_robot_dialog()
|
|||
memset(&r->goody_angles, 0, sizeof(vms_angvec));
|
||||
|
||||
// Open a window with a quit button
|
||||
MainWindow = ui_create_dialog( TMAPBOX_X+20, TMAPBOX_Y+20, 765-TMAPBOX_X, 545-TMAPBOX_Y, DF_DIALOG, robot_dialog_handler, r );
|
||||
r->quitButton = ui_add_gadget_button( MainWindow, 20, 286, 40, 32, "Done", NULL );
|
||||
|
||||
ui_add_gadget_button( MainWindow, GOODY_X+50, GOODY_Y-3, 25, 22, "<<", GoodyPrevType );
|
||||
ui_add_gadget_button( MainWindow, GOODY_X+80, GOODY_Y-3, 25, 22, ">>", GoodyNextType );
|
||||
|
||||
ui_add_gadget_button( MainWindow, GOODY_X+50, GOODY_Y+21, 25, 22, "<<", GoodyPrevID );
|
||||
ui_add_gadget_button( MainWindow, GOODY_X+80, GOODY_Y+21, 25, 22, ">>", GoodyNextID );
|
||||
|
||||
ui_add_gadget_button( MainWindow, GOODY_X+50, GOODY_Y+45, 25, 22, "<<", GoodyPrevCount );
|
||||
ui_add_gadget_button( MainWindow, GOODY_X+80, GOODY_Y+45, 25, 22, ">>", GoodyNextCount );
|
||||
|
||||
r->initialMode[0] = ui_add_gadget_radio( MainWindow, 6, 58, 16, 16, 0, "Hover" );
|
||||
r->initialMode[1] = ui_add_gadget_radio( MainWindow, 76, 58, 16, 16, 0, "Normal" );
|
||||
r->initialMode[2] = ui_add_gadget_radio( MainWindow, 6, 78, 16, 16, 0, "(hide)" );
|
||||
r->initialMode[3] = ui_add_gadget_radio( MainWindow, 76, 78, 16, 16, 0, "Avoid" );
|
||||
r->initialMode[4] = ui_add_gadget_radio( MainWindow, 6, 98, 16, 16, 0, "Follow" );
|
||||
r->initialMode[5] = ui_add_gadget_radio( MainWindow, 76, 98, 16, 16, 0, "Station" );
|
||||
|
||||
// The little box the robots will spin in.
|
||||
r->robotViewBox = ui_add_gadget_userbox( MainWindow,155, 5, 150, 125 );
|
||||
|
||||
// The little box the robots will spin in.
|
||||
r->containsViewBox = ui_add_gadget_userbox( MainWindow,10, 202, 100, 80 );
|
||||
|
||||
// A bunch of buttons...
|
||||
i = 135;
|
||||
ui_add_gadget_button( MainWindow,190,i,53, 26, "<<Typ", RobotPrevType );
|
||||
ui_add_gadget_button( MainWindow,247,i,53, 26, "Typ>>", RobotNextType ); i += 29;
|
||||
ui_add_gadget_button( MainWindow,190,i,110, 26, "Next in Seg", LocalObjectSelectNextinSegment ); i += 29;
|
||||
|
||||
ui_add_gadget_button( MainWindow,190,i,53, 26, "<<Obj", LocalObjectSelectPrevinMine );
|
||||
ui_add_gadget_button( MainWindow,247,i,53, 26, ">>Obj", LocalObjectSelectNextinMine ); i += 29;
|
||||
|
||||
ui_add_gadget_button( MainWindow,190,i,110, 26, "Delete", LocalObjectDelete ); i += 29;
|
||||
ui_add_gadget_button( MainWindow,190,i,110, 26, "Create New", LocalObjectPlaceObject ); i += 29;
|
||||
ui_add_gadget_button( MainWindow,190,i,110, 26, "Set Path", med_set_ai_path );
|
||||
|
||||
r->time = timer_query();
|
||||
|
||||
r->old_object = -2; // Set to some dummy value so everything works ok on the first frame.
|
||||
|
||||
if ( Cur_object_index == object_none )
|
||||
LocalObjectSelectNextinMine();
|
||||
|
||||
MainWindow = ui_create_dialog(TMAPBOX_X+20, TMAPBOX_Y+20, 765-TMAPBOX_X, 545-TMAPBOX_Y, DF_DIALOG, robot_dialog_handler, std::move(r));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int robot_dialog_created(UI_DIALOG *const w, robot_dialog *const r)
|
||||
{
|
||||
r->quitButton = ui_add_gadget_button(w, 20, 286, 40, 32, "Done", NULL);
|
||||
ui_add_gadget_button(w, GOODY_X+50, GOODY_Y-3, 25, 22, "<<", GoodyPrevType);
|
||||
ui_add_gadget_button(w, GOODY_X+80, GOODY_Y-3, 25, 22, ">>", GoodyNextType);
|
||||
ui_add_gadget_button(w, GOODY_X+50, GOODY_Y+21, 25, 22, "<<", GoodyPrevID);
|
||||
ui_add_gadget_button(w, GOODY_X+80, GOODY_Y+21, 25, 22, ">>", GoodyNextID);
|
||||
ui_add_gadget_button(w, GOODY_X+50, GOODY_Y+45, 25, 22, "<<", GoodyPrevCount);
|
||||
ui_add_gadget_button(w, GOODY_X+80, GOODY_Y+45, 25, 22, ">>", GoodyNextCount);
|
||||
r->initialMode[0] = ui_add_gadget_radio(w, 6, 58, 16, 16, 0, "Hover");
|
||||
r->initialMode[1] = ui_add_gadget_radio(w, 76, 58, 16, 16, 0, "Normal");
|
||||
r->initialMode[2] = ui_add_gadget_radio(w, 6, 78, 16, 16, 0, "(hide)");
|
||||
r->initialMode[3] = ui_add_gadget_radio(w, 76, 78, 16, 16, 0, "Avoid");
|
||||
r->initialMode[4] = ui_add_gadget_radio(w, 6, 98, 16, 16, 0, "Follow");
|
||||
r->initialMode[5] = ui_add_gadget_radio(w, 76, 98, 16, 16, 0, "Station");
|
||||
// The little box the robots will spin in.
|
||||
r->robotViewBox = ui_add_gadget_userbox(w, 155, 5, 150, 125);
|
||||
// The little box the robots will spin in.
|
||||
r->containsViewBox = ui_add_gadget_userbox(w, 10, 202, 100, 80);
|
||||
// A bunch of buttons...
|
||||
int i = 135;
|
||||
ui_add_gadget_button(w, 190, i, 53, 26, "<<Typ", RobotPrevType);
|
||||
ui_add_gadget_button(w, 247, i, 53, 26, "Typ>>", RobotNextType); i += 29;
|
||||
ui_add_gadget_button(w, 190, i, 110, 26, "Next in Seg", LocalObjectSelectNextinSegment); i += 29;
|
||||
ui_add_gadget_button(w, 190, i, 53, 26, "<<Obj", LocalObjectSelectPrevinMine);
|
||||
ui_add_gadget_button(w, 247, i, 53, 26, ">>Obj", LocalObjectSelectNextinMine); i += 29;
|
||||
ui_add_gadget_button(w, 190, i, 110, 26, "Delete", LocalObjectDelete); i += 29;
|
||||
ui_add_gadget_button(w, 190, i, 110, 26, "Create New", LocalObjectPlaceObject); i += 29;
|
||||
ui_add_gadget_button(w, 190, i, 110, 26, "Set Path", med_set_ai_path);
|
||||
r->time = timer_query();
|
||||
r->old_object = -2; // Set to some dummy value so everything works ok on the first frame.
|
||||
if ( Cur_object_index == object_none)
|
||||
LocalObjectSelectNextinMine();
|
||||
return 1;
|
||||
}
|
||||
|
||||
void robot_close_window()
|
||||
|
@ -538,6 +525,17 @@ void robot_close_window()
|
|||
|
||||
int robot_dialog_handler(UI_DIALOG *dlg,const d_event &event, robot_dialog *r)
|
||||
{
|
||||
switch(event.type)
|
||||
{
|
||||
case EVENT_WINDOW_CREATED:
|
||||
return robot_dialog_created(dlg, r);
|
||||
case EVENT_WINDOW_CLOSE:
|
||||
std::default_delete<robot_dialog>()(r);
|
||||
MainWindow = NULL;
|
||||
return 0;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
fix DeltaTime;
|
||||
fix64 Temp;
|
||||
int first_object_index;
|
||||
|
@ -689,14 +687,6 @@ int robot_dialog_handler(UI_DIALOG *dlg,const d_event &event, robot_dialog *r)
|
|||
|
||||
if (ui_button_any_drawn || (r->old_object != Cur_object_index) )
|
||||
Update_flags |= UF_WORLD_CHANGED;
|
||||
|
||||
if (event.type == EVENT_WINDOW_CLOSE)
|
||||
{
|
||||
d_free(r);
|
||||
MainWindow = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( GADGET_PRESSED(r->quitButton) || (keypress==KEY_ESC))
|
||||
{
|
||||
robot_close_window();
|
||||
|
|
Loading…
Reference in a new issue