//------------------------------------------------------------------------- // Called from the editor... does one instance of the robot dialog box //------------------------------------------------------------------------- int do_robot_dialog() { int i; // Only open 1 instance of this window... if ( MainWindow != NULL ) return 0; // Close other windows close_all_windows(); Cur_goody_count = 0; // Open a window with a quit button MainWindow = ui_open_window( TMAPBOX_X+20, TMAPBOX_Y+20, 765-TMAPBOX_X, 545-TMAPBOX_Y, WIN_DIALOG ); 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 ); InitialMode[0] = ui_add_gadget_radio( MainWindow, 6, 58, 16, 16, 0, "Hover" ); InitialMode[1] = ui_add_gadget_radio( MainWindow, 76, 58, 16, 16, 0, "Normal" ); InitialMode[2] = ui_add_gadget_radio( MainWindow, 6, 78, 16, 16, 0, "(hide)" ); InitialMode[3] = ui_add_gadget_radio( MainWindow, 76, 78, 16, 16, 0, "Avoid" ); InitialMode[4] = ui_add_gadget_radio( MainWindow, 6, 98, 16, 16, 0, "Follow" ); InitialMode[5] = ui_add_gadget_radio( MainWindow, 76, 98, 16, 16, 0, "Station" ); // The little box the robots will spin in. RobotViewBox = ui_add_gadget_userbox( MainWindow,155, 5, 150, 125 ); // The little box the robots will spin in. 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 ); Time = timer_get_fixed_seconds(); old_object = -2; // Set to some dummy value so everything works ok on the first frame. if ( Cur_object_index == -1 ) LocalObjectSelectNextinMine(); return 1; }
static window_event_result robot_dialog_created(UI_DIALOG *const w, robot_dialog *const r) { r->quitButton = ui_add_gadget_button(w, 20, 286, 40, 32, "Done", NULL); r->prev_powerup_type = ui_add_gadget_button(w, GOODY_X+50, GOODY_Y-3, 25, 22, "<<", GoodyPrevType); r->next_powerup_type = ui_add_gadget_button(w, GOODY_X+80, GOODY_Y-3, 25, 22, ">>", GoodyNextType); r->prev_powerup_id = ui_add_gadget_button(w, GOODY_X+50, GOODY_Y+21, 25, 22, "<<", GoodyPrevID); r->next_powerup_id = ui_add_gadget_button(w, GOODY_X+80, GOODY_Y+21, 25, 22, ">>", GoodyNextID); r->prev_powerup_count = ui_add_gadget_button(w, GOODY_X+50, GOODY_Y+45, 25, 22, "<<", GoodyPrevCount); r->next_powerup_count = 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; r->prev_robot_type = ui_add_gadget_button(w, 190, i, 53, 26, "<<Typ", RobotPrevType); r->next_robot_type = ui_add_gadget_button(w, 247, i, 53, 26, "Typ>>", RobotNextType); i += 29; r->next_segment = ui_add_gadget_button(w, 190, i, 110, 26, "Next in Seg", LocalObjectSelectNextinSegment); i += 29; r->prev_object = ui_add_gadget_button(w, 190, i, 53, 26, "<<Obj", LocalObjectSelectPrevinMine); r->next_object = ui_add_gadget_button(w, 247, i, 53, 26, ">>Obj", LocalObjectSelectNextinMine); i += 29; r->delete_object = ui_add_gadget_button(w, 190, i, 110, 26, "Delete", LocalObjectDelete); i += 29; r->new_object = ui_add_gadget_button(w, 190, i, 110, 26, "Create New", LocalObjectPlaceObject); i += 29; r->set_path = 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 window_event_result::handled; }
void do_robot_window() { int i; fix DeltaTime, Temp; int first_object_index; if ( MainWindow == NULL ) return; first_object_index = Cur_object_index; while (!is_legal_type_for_this_window(Cur_object_index)) { LocalObjectSelectNextinMine(); if (first_object_index == Cur_object_index) { break; } } //------------------------------------------------------------ // Call the ui code.. //------------------------------------------------------------ ui_button_any_drawn = 0; ui_window_do_gadgets(MainWindow); //------------------------------------------------------------ // If we change objects, we need to reset the ui code for all // of the radio buttons that control the ai mode. Also makes // the current AI mode button be flagged as pressed down. //------------------------------------------------------------ if (old_object != Cur_object_index ) { for ( i=0; i < NUM_BOXES; i++ ) { InitialMode[i]->flag = 0; // Tells ui that this button isn't checked InitialMode[i]->status = 1; // Tells ui to redraw button } if ( Cur_object_index > -1 ) { int behavior = Objects[Cur_object_index].ctype.ai_info.behavior; if ( !((behavior >= MIN_BEHAVIOR) && (behavior <= MAX_BEHAVIOR))) { Objects[Cur_object_index].ctype.ai_info.behavior = AIB_NORMAL; behavior = AIB_NORMAL; } InitialMode[behavior - MIN_BEHAVIOR]->flag = 1; // Mark this button as checked } } //------------------------------------------------------------ // If any of the radio buttons that control the mode are set, then // update the cooresponding AI state. //------------------------------------------------------------ for ( i=0; i < NUM_BOXES; i++ ) { if ( InitialMode[i]->flag == 1 ) if (Objects[Cur_object_index].ctype.ai_info.behavior != MIN_BEHAVIOR+i) { Objects[Cur_object_index].ctype.ai_info.behavior = MIN_BEHAVIOR+i; // Set the ai_state to the cooresponding radio button call_init_ai_object(&Objects[Cur_object_index], MIN_BEHAVIOR+i); } } //------------------------------------------------------------ // A simple frame time counter for spinning the objects... //------------------------------------------------------------ Temp = timer_get_fixed_seconds(); DeltaTime = Temp - Time; Time = Temp; //------------------------------------------------------------ // Redraw the object in the little 64x64 box //------------------------------------------------------------ if (Cur_object_index > -1 ) { int id; gr_set_current_canvas( RobotViewBox->canvas ); id = get_object_id(&Objects[Cur_object_index]); if ( id > -1 ) draw_robot_picture(id, &angles, -1 ); else gr_clear_canvas( CGREY ); angles.h += fixmul(0x1000, DeltaTime ); } else { // no object, so just blank out gr_set_current_canvas( RobotViewBox->canvas ); gr_clear_canvas( CGREY ); // LocalObjectSelectNextInMine(); } //------------------------------------------------------------ // Redraw the contained object in the other little box //------------------------------------------------------------ if ((Cur_object_index > -1 ) && (Cur_goody_count > 0)) { int id; gr_set_current_canvas( ContainsViewBox->canvas ); id = Cur_goody_id; if ( id > -1 ) { int ol_type=0; if (Cur_goody_type == OBJ_ROBOT) ol_type = OL_ROBOT; else if (Cur_goody_type == OBJ_POWERUP) ol_type = OL_POWERUP; else Int3(); // Error? Unknown goody type! draw_robot_picture(id, &goody_angles, ol_type ); } else gr_clear_canvas( CGREY ); goody_angles.h += fixmul(0x1000, DeltaTime ); } else { // no object, so just blank out gr_set_current_canvas( ContainsViewBox->canvas ); gr_clear_canvas( CGREY ); // LocalObjectSelectNextInMine(); } //------------------------------------------------------------ // If anything changes in the ui system, redraw all the text that // identifies this robot. //------------------------------------------------------------ if (ui_button_any_drawn || (old_object != Cur_object_index) ) { int i; char type_text[STRING_LENGTH+1],id_text[STRING_LENGTH+1]; if (Cur_object_index != -1) { Cur_goody_type = Objects[Cur_object_index].contains_type; Cur_goody_id = Objects[Cur_object_index].contains_id; if (Objects[Cur_object_index].contains_count < 0) Objects[Cur_object_index].contains_count = 0; Cur_goody_count = Objects[Cur_object_index].contains_count; } ui_wprintf_at( MainWindow, GOODY_X, GOODY_Y, " Type:"); ui_wprintf_at( MainWindow, GOODY_X, GOODY_Y+24, " ID:"); ui_wprintf_at( MainWindow, GOODY_X, GOODY_Y+48, "Count:"); for (i=0; i<STRING_LENGTH; i++) id_text[i] = ' '; id_text[i] = 0; switch (Cur_goody_type) { case OBJ_ROBOT: strcpy(type_text, "Robot "); strncpy(id_text, Robot_names[Cur_goody_id], strlen(Robot_names[Cur_goody_id])); break; case OBJ_POWERUP: strcpy(type_text, "Powerup"); strncpy(id_text, Powerup_names[Cur_goody_id], strlen(Powerup_names[Cur_goody_id])); break; default: editor_status("Illegal contained object type (%i), changing to powerup.", Cur_goody_type); Cur_goody_type = OBJ_POWERUP; Cur_goody_id = 0; strcpy(type_text, "Powerup"); strncpy(id_text, Powerup_names[Cur_goody_id], strlen(Powerup_names[Cur_goody_id])); break; } ui_wprintf_at( MainWindow, GOODY_X+108, GOODY_Y, type_text); ui_wprintf_at( MainWindow, GOODY_X+108, GOODY_Y+24, id_text); ui_wprintf_at( MainWindow, GOODY_X+108, GOODY_Y+48, "%i", Cur_goody_count); if ( Cur_object_index > -1 ) { int id = Objects[Cur_object_index].id; char id_text[12]; int i; for (i=0; i<STRING_LENGTH; i++) id_text[i] = ' '; id_text[i] = 0; strncpy(id_text, Robot_names[id], strlen(Robot_names[id])); ui_wprintf_at( MainWindow, 12, 6, "Robot: %3d ", Cur_object_index ); ui_wprintf_at( MainWindow, 12, 22, " Id: %3d", id); ui_wprintf_at( MainWindow, 12, 38, " Name: %8s", id_text); } else { ui_wprintf_at( MainWindow, 12, 6, "Robot: none" ); ui_wprintf_at( MainWindow, 12, 22, " Type: ? " ); ui_wprintf_at( MainWindow, 12, 38, " Name: ________" ); } Update_flags |= UF_WORLD_CHANGED; } if ( QuitButton->pressed || (last_keypress==KEY_ESC)) { robot_close_window(); return; } old_object = Cur_object_index; }
int robot_dialog_handler(UI_DIALOG *, d_event *event, robot_dialog *r) { int i; fix DeltaTime; fix64 Temp; int first_object_index; int keypress = 0; int rval = 0; if (event->type == EVENT_KEY_COMMAND) keypress = event_key_get(event); Assert(MainWindow != NULL); first_object_index = Cur_object_index; while (!is_legal_type_for_this_window(Cur_object_index)) { LocalObjectSelectNextinMine(); if (first_object_index == Cur_object_index) { break; } } //------------------------------------------------------------ // Call the ui code.. //------------------------------------------------------------ ui_button_any_drawn = 0; //------------------------------------------------------------ // If we change objects, we need to reset the ui code for all // of the radio buttons that control the ai mode. Also makes // the current AI mode button be flagged as pressed down. //------------------------------------------------------------ if (r->old_object != Cur_object_index ) { for ( i=0; i < NUM_BOXES; i++ ) ui_radio_set_value(r->initialMode[i], 0); if ( Cur_object_index != object_none ) { int behavior = Objects[Cur_object_index].ctype.ai_info.behavior; if ( !((behavior >= MIN_BEHAVIOR) && (behavior <= MAX_BEHAVIOR))) { Objects[Cur_object_index].ctype.ai_info.behavior = AIB_NORMAL; behavior = AIB_NORMAL; } ui_radio_set_value(r->initialMode[behavior - MIN_BEHAVIOR], 1); } } //------------------------------------------------------------ // If any of the radio buttons that control the mode are set, then // update the cooresponding AI state. //------------------------------------------------------------ for ( i=0; i < NUM_BOXES; i++ ) { if ( GADGET_PRESSED(r->initialMode[i]) ) if (Objects[Cur_object_index].ctype.ai_info.behavior != MIN_BEHAVIOR+i) { Objects[Cur_object_index].ctype.ai_info.behavior = MIN_BEHAVIOR+i; // Set the ai_state to the cooresponding radio button call_init_ai_object(&Objects[Cur_object_index], MIN_BEHAVIOR+i); rval = 1; } } //------------------------------------------------------------ // Redraw the object in the little 64x64 box //------------------------------------------------------------ if (event->type == EVENT_UI_DIALOG_DRAW) { // A simple frame time counter for spinning the objects... Temp = timer_query(); DeltaTime = Temp - r->time; r->time = Temp; if (Cur_object_index != object_none ) { dxxobject *obj = &Objects[Cur_object_index]; gr_set_current_canvas( r->robotViewBox->canvas ); draw_object_picture(obj->id, &r->angles, obj->type ); r->angles.h += fixmul(0x1000, DeltaTime ); } else { // no object, so just blank out gr_set_current_canvas( r->robotViewBox->canvas ); gr_clear_canvas( CGREY ); // LocalObjectSelectNextInMine(); } } //------------------------------------------------------------ // Redraw the contained object in the other little box //------------------------------------------------------------ if (event->type == EVENT_UI_DIALOG_DRAW) { if ((Cur_object_index != object_none ) && (Cur_goody_count > 0)) { gr_set_current_canvas( r->containsViewBox->canvas ); if ( Cur_goody_id > -1 ) draw_object_picture(Cur_goody_id, &r->goody_angles, Cur_goody_type); else gr_clear_canvas( CGREY ); r->goody_angles.h += fixmul(0x1000, DeltaTime ); } else { // no object, so just blank out gr_set_current_canvas( r->containsViewBox->canvas ); gr_clear_canvas( CGREY ); // LocalObjectSelectNextInMine(); } } //------------------------------------------------------------ // If anything changes in the ui system, redraw all the text that // identifies this robot. //------------------------------------------------------------ if (event->type == EVENT_UI_DIALOG_DRAW) { int i; char id_text[STRING_LENGTH+1]; const char *type_text; if (Cur_object_index != object_none) { Cur_goody_type = Objects[Cur_object_index].contains_type; Cur_goody_id = Objects[Cur_object_index].contains_id; if (Objects[Cur_object_index].contains_count < 0) Objects[Cur_object_index].contains_count = 0; Cur_goody_count = Objects[Cur_object_index].contains_count; } ui_dprintf_at( MainWindow, GOODY_X, GOODY_Y, " Type:"); ui_dprintf_at( MainWindow, GOODY_X, GOODY_Y+24, " ID:"); ui_dprintf_at( MainWindow, GOODY_X, GOODY_Y+48, "Count:"); for (i=0; i<STRING_LENGTH; i++) id_text[i] = ' '; id_text[i] = 0; switch (Cur_goody_type) { case OBJ_ROBOT: type_text = "Robot "; strncpy(id_text, Robot_names[Cur_goody_id], strlen(Robot_names[Cur_goody_id])); break; case OBJ_POWERUP: type_text = "Powerup"; strncpy(id_text, Powerup_names[Cur_goody_id], strlen(Powerup_names[Cur_goody_id])); break; default: editor_status("Illegal contained object type (%i), changing to powerup.", Cur_goody_type); Cur_goody_type = OBJ_POWERUP; Cur_goody_id = 0; type_text = "Powerup"; strncpy(id_text, Powerup_names[Cur_goody_id], strlen(Powerup_names[Cur_goody_id])); break; } ui_dprintf_at( MainWindow, GOODY_X+108, GOODY_Y, "%s", type_text); ui_dprintf_at( MainWindow, GOODY_X+108, GOODY_Y+24, "%s", id_text); ui_dprintf_at( MainWindow, GOODY_X+108, GOODY_Y+48, "%i", Cur_goody_count); if ( Cur_object_index != object_none ) { int id = Objects[Cur_object_index].id; char id_text[12]; int i; for (i=0; i<STRING_LENGTH; i++) id_text[i] = ' '; id_text[i] = 0; strncpy(id_text, Robot_names[id], strlen(Robot_names[id])); ui_dprintf_at( MainWindow, 12, 6, "Robot: %3u ", static_cast<unsigned>(Cur_object_index) ); ui_dprintf_at( MainWindow, 12, 22, " Id: %3d", id); ui_dprintf_at( MainWindow, 12, 38, " Name: %8s", id_text); } else { ui_dprintf_at( MainWindow, 12, 6, "Robot: none" ); ui_dprintf_at( MainWindow, 12, 22, " Type: ? " ); ui_dprintf_at( MainWindow, 12, 38, " Name: ________" ); } } 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(); return 1; } r->old_object = Cur_object_index; return rval; }
//------------------------------------------------------------------------- // Called from the editor... does one instance of the robot dialog box //------------------------------------------------------------------------- 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; // Close other windows close_all_windows(); Cur_goody_count = 0; memset(&r->angles, 0, sizeof(vms_angvec)); 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, (int (*)(UI_DIALOG *, d_event *, void *))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(); return 1; }