diff --git a/CHANGELOG.txt b/CHANGELOG.txt index ee6aa3710..269ae6185 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -3,6 +3,7 @@ D1X-Rebirth Changelog 20120318 -------- editor/med.c, editor/texpage.c, include/editor/editor.h, main/game.c: Do a bit of a tidy up for the editor, dump code from editor() within the loop into new editor_handler() +editor/info.c, editor/med.c, editor/medmisc.c, editor/objpage.c, editor/texpage.c, include/editor/objpage.h, include/editor/texpage.h, include/ui.h, ui/userbox.c: Make editor_handler into a proper callback, iron some problems out. Seems to draw a different bunch of stuff now (still erroneous) 20120317 -------- diff --git a/editor/info.c b/editor/info.c index b481441b4..a9248a367 100644 --- a/editor/info.c +++ b/editor/info.c @@ -361,7 +361,13 @@ int info_display_all(window *wind, d_event *event, void *userdata) // ------------------------------------------------------------------------------------ window *info_window_create(void) { - return window_create(Canv_editor, PAD_X + 250, PAD_Y + 8, 180, 160, info_display_all, NULL); + window *wind; + + wind = window_create(Canv_editor, PAD_X + 250, PAD_Y + 8, 180, 160, info_display_all, NULL); + if (wind) + window_set_modal(wind, 0); + + return wind; } diff --git a/editor/med.c b/editor/med.c index 7a13cc1ff..bb40097e9 100644 --- a/editor/med.c +++ b/editor/med.c @@ -40,6 +40,7 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #include "gamesave.h" #include "gameseg.h" #include "key.h" +#include "mouse.h" #include "error.h" #include "kfuncs.h" #include "macro.h" @@ -651,10 +652,10 @@ int ToggleLighting(void) Update_flags |= UF_GAME_VIEW_CHANGED; - if (last_keypress == KEY_L + KEY_SHIFTED) + //if (keypress == KEY_L + KEY_SHIFTED) chindex = 0; - else - chindex = 10; + //else + // chindex = 10; switch (Lighting_on) { case 0: @@ -733,17 +734,17 @@ int ToggleOutlineMode() if (mode) { - if (last_keypress != KEY_O) + //if (keypress != KEY_O) diagnostic_message("[O] Outline Mode ON."); - else - diagnostic_message("Outline Mode ON."); + //else + // diagnostic_message("Outline Mode ON."); } else { - if (last_keypress != KEY_O) + //if (keypress != KEY_O) diagnostic_message("[O] Outline Mode OFF."); - else - diagnostic_message("Outline Mode OFF."); + //else + // diagnostic_message("Outline Mode OFF."); } Update_flags |= UF_GAME_VIEW_CHANGED; @@ -794,6 +795,8 @@ int med_keypad_goto_8() { ui_pad_goto(8); return 0; } int editor_screen_open = 0; +int editor_handler(UI_DIALOG *dlg, d_event *event, void *data); + //setup the editors windows, canvases, gadgets, etc. void init_editor_screen() { @@ -825,7 +828,7 @@ void init_editor_screen() gr_set_curfont(editor_font); gr_set_fontcolor( CBLACK, CWHITE ); - EditorWindow = ui_create_dialog( 0 , 0, ED_SCREEN_W, ED_SCREEN_H, DF_FILLED, NULL, NULL ); + EditorWindow = ui_create_dialog( 0 , 0, ED_SCREEN_W, ED_SCREEN_H, DF_FILLED, editor_handler, NULL ); LargeViewBox = ui_add_gadget_userbox( EditorWindow,LVIEW_X,LVIEW_Y,LVIEW_W,LVIEW_H); #if ORTHO_VIEWS @@ -1070,7 +1073,6 @@ int RestoreGameState() { } extern void check_wall_validity(void); -void editor_handler(void); // --------------------------------------------------------------------------------------------------- //this function is the editor. called when editor mode selected. runs until @@ -1080,19 +1082,23 @@ void editor(void) init_editor(); while (Function_mode == FMODE_EDITOR) - { event_process(); - editor_handler(); - } close_editor(); } // Handler for the main editor dialog -void editor_handler(void) +int editor_handler(UI_DIALOG *dlg, d_event *event, void *data) { editor_view *new_cv; + int keypress = 0; + int rval = 0; + if (event->type == EVENT_KEY_COMMAND) + keypress = event_key_get(event); + else if (event->type == EVENT_WINDOW_CLOSE) + return 0; + // Update the windows // Only update if there is no key waiting and we're not in @@ -1101,7 +1107,6 @@ void editor_handler(void) // medlisp_update_screen(); //do editor stuff - last_keypress &= ~KEY_DEBUGGED; // mask off delete key bit which has no function in editor. check_wall_validity(); Assert(Num_walls>=0); @@ -1117,10 +1122,10 @@ void editor_handler(void) } if ( ui_get_idle_seconds() > COMPRESS_INTERVAL ) - { + { med_compress_mine(); ui_reset_idle_seconds(); - } + } // Commented out because it occupies about 25% of time in twirling the mine. // Removes some Asserts.... @@ -1131,62 +1136,67 @@ void editor_handler(void) gr_set_current_canvas( GameViewBox->canvas ); // Remove keys used for slew - switch(last_keypress) + switch(keypress) { - case KEY_PAD9: - case KEY_PAD7: - case KEY_PADPLUS: - case KEY_PADMINUS: - case KEY_PAD8: - case KEY_PAD2: - case KEY_LBRACKET: - case KEY_RBRACKET: - case KEY_PAD1: - case KEY_PAD3: - case KEY_PAD6: - case KEY_PAD4: - last_keypress = 0; + case KEY_PAD9: + case KEY_PAD7: + case KEY_PADPLUS: + case KEY_PADMINUS: + case KEY_PAD8: + case KEY_PAD2: + case KEY_LBRACKET: + case KEY_RBRACKET: + case KEY_PAD1: + case KEY_PAD3: + case KEY_PAD6: + case KEY_PAD4: + keypress = 0; } - if ((last_keypress&0xff)==KEY_LSHIFT) last_keypress=0; - if ((last_keypress&0xff)==KEY_RSHIFT) last_keypress=0; - if ((last_keypress&0xff)==KEY_LCTRL) last_keypress=0; - if ((last_keypress&0xff)==KEY_RCTRL) last_keypress=0; -// if ((last_keypress&0xff)==KEY_LALT) last_keypress=0; -// if ((last_keypress&0xff)==KEY_RALT) last_keypress=0; + if ((keypress&0xff)==KEY_LSHIFT) keypress=0; + if ((keypress&0xff)==KEY_RSHIFT) keypress=0; + if ((keypress&0xff)==KEY_LCTRL) keypress=0; + if ((keypress&0xff)==KEY_RCTRL) keypress=0; +// if ((keypress&0xff)==KEY_LALT) keypress=0; +// if ((keypress&0xff)==KEY_RALT) keypress=0; gr_set_curfont(editor_font); //=================== DO FUNCTIONS ==================== - if ( KeyFunction[ last_keypress ] != NULL ) { - KeyFunction[last_keypress](); - last_keypress = 0; - } - switch (last_keypress) + if ( KeyFunction[ keypress ] != NULL ) { - case 0: - case KEY_Z: - case KEY_G: - case KEY_LALT: - case KEY_RALT: - case KEY_LCTRL: - case KEY_RCTRL: - case KEY_LSHIFT: - case KEY_RSHIFT: - case KEY_LAPOSTRO: - break; - case KEY_SHIFTED + KEY_L: - ToggleLighting(); - break; - case KEY_F1: - render_3d_in_big_window = !render_3d_in_big_window; - Update_flags |= UF_ALL; - break; - default: + KeyFunction[keypress](); + keypress = 0; + rval = 1; + } + + switch (keypress) + { + case 0: + case KEY_Z: + case KEY_G: + case KEY_LALT: + case KEY_RALT: + case KEY_LCTRL: + case KEY_RCTRL: + case KEY_LSHIFT: + case KEY_RSHIFT: + case KEY_LAPOSTRO: + break; + case KEY_SHIFTED + KEY_L: + ToggleLighting(); + rval = 1; + break; + case KEY_F1: + render_3d_in_big_window = !render_3d_in_big_window; + Update_flags |= UF_ALL; + rval = 1; + break; + default: { - char kdesc[100]; - GetKeyDescription( kdesc, last_keypress ); - editor_status("Error: %s isn't bound to anything.", kdesc ); + char kdesc[100]; + GetKeyDescription( kdesc, keypress ); + editor_status("Error: %s isn't bound to anything.", kdesc ); } } @@ -1196,7 +1206,7 @@ void editor_handler(void) { close_editor_screen(); Function_mode=FMODE_EXIT; - return; + return 0; } if (ModeFlag==2) //-- && MacroStatus==UI_STATUS_NORMAL ) @@ -1204,7 +1214,7 @@ void editor_handler(void) close_editor_screen(); Function_mode = FMODE_MENU; set_screen_mode(SCREEN_MENU); //put up menu screen - return; + return 0; } if (ModeFlag==3) //-- && MacroStatus==UI_STATUS_NORMAL ) @@ -1213,13 +1223,13 @@ void editor_handler(void) close_editor_screen(); Function_mode=FMODE_GAME; //force back into game set_screen_mode(SCREEN_GAME); //put up game screen - return; + return 0; } // if (EditorWindow->keyboard_focus_gadget == (UI_GADGET *)GameViewBox) current_view=NULL; // if (EditorWindow->keyboard_focus_gadget == (UI_GADGET *)GroupViewBox) current_view=NULL; - new_cv = current_view ; + new_cv = current_view; #if ORTHO_VIEWS if (EditorWindow->keyboard_focus_gadget == (UI_GADGET *)LargeViewBox) new_cv=&LargeView; @@ -1244,12 +1254,15 @@ void editor_handler(void) } // DO TEXTURE STUFF - texpage_do(); - objpage_do(); + if (texpage_do(event)) + rval = 1; + + if (objpage_do(event)) + rval = 1; // Process selection of Cursegp using mouse. - if (LargeViewBox->mouse_onme && LargeViewBox->b1_clicked && !render_3d_in_big_window) + if (GADGET_PRESSED(LargeViewBox) && !render_3d_in_big_window) { int xcrd,ycrd; xcrd = LargeViewBox->b1_drag_x1; @@ -1276,7 +1289,8 @@ void editor_handler(void) Update_flags |= UF_ED_STATE_CHANGED | UF_VIEWPOINT_MOVED; } - if (GameViewBox->mouse_onme && GameViewBox->b1_dragging) { + if ((event->type == EVENT_UI_USERBOX_DRAGGED) && (ui_event_get_gadget(event) == (UI_GADGET *)GameViewBox)) + { int x, y; x = GameViewBox->b1_drag_x2; y = GameViewBox->b1_drag_y2; @@ -1292,9 +1306,9 @@ void editor_handler(void) // Set current segment and side by clicking on a polygon in game window. // If ctrl pressed, also assign current texture map to that side. //if (GameViewBox->mouse_onme && (GameViewBox->b1_done_dragging || GameViewBox->b1_clicked)) { - if ((GameViewBox->mouse_onme && GameViewBox->b1_clicked && !render_3d_in_big_window) || - (LargeViewBox->mouse_onme && LargeViewBox->b1_clicked && render_3d_in_big_window)) { - + if ((GADGET_PRESSED(GameViewBox) && !render_3d_in_big_window) || + (GADGET_PRESSED(LargeViewBox) && render_3d_in_big_window)) + { int xcrd,ycrd; int seg,side,face,poly,tmap; @@ -1351,31 +1365,43 @@ void editor_handler(void) } // Allow specification of LargeView using mouse - if (keyd_pressed[ KEY_LCTRL ] || keyd_pressed[ KEY_RCTRL ]) { + if (event->type == EVENT_MOUSE_MOVED && (keyd_pressed[ KEY_LCTRL ] || keyd_pressed[ KEY_RCTRL ])) + { + int dx, dy, dz; + + event_mouse_get_delta(event, &dx, &dy, &dz); ui_mouse_hide(); - if ( (Mouse.dx!=0) && (Mouse.dy!=0) ) + if ((dx != 0) && (dy != 0)) { vms_matrix MouseRotMat,tempm; - GetMouseRotation( Mouse.dx, Mouse.dy, &MouseRotMat ); + GetMouseRotation( dx, dy, &MouseRotMat ); vm_matrix_x_matrix(&tempm,&LargeView.ev_matrix,&MouseRotMat); LargeView.ev_matrix = tempm; LargeView.ev_changed = 1; Large_view_index = -1; // say not one of the orthogonal views + rval = 1; } } else { ui_mouse_show(); } - if ( keyd_pressed[ KEY_Z ] ) { + if (event->type == EVENT_MOUSE_MOVED && keyd_pressed[ KEY_Z ]) + { + int dx, dy, dz; + + event_mouse_get_delta(event, &dx, &dy, &dz); ui_mouse_hide(); - if ( Mouse.dy!=0 ) { - current_view->ev_dist += Mouse.dy*10000; + if (dy != 0) + { + current_view->ev_dist += dy*10000; current_view->ev_changed = 1; } } else { ui_mouse_show(); } + + return rval; } void test_fade(void) diff --git a/editor/medmisc.c b/editor/medmisc.c index 6a70dae79..23fff0656 100644 --- a/editor/medmisc.c +++ b/editor/medmisc.c @@ -103,16 +103,16 @@ int ToggleLockstep() { Gameview_lockstep = !Gameview_lockstep; if (Gameview_lockstep == 0) { - if (last_keypress != KEY_L) + //if (keypress != KEY_L) diagnostic_message("[L] - Lock mode OFF"); - else - diagnostic_message("Lock mode OFF"); + //else + // diagnostic_message("Lock mode OFF"); } if (Gameview_lockstep) { - if (last_keypress != KEY_L) + //if (keypress != KEY_L) diagnostic_message("[L] Lock mode ON"); - else - diagnostic_message("Lock mode ON"); + //else + // diagnostic_message("Lock mode ON"); Cursegp = &Segments[ConsoleObject->segnum]; med_create_new_segment_from_cursegp(); @@ -172,16 +172,16 @@ int ToggleLockViewToCursegp(void) Lock_view_to_cursegp = !Lock_view_to_cursegp; Update_flags = UF_ED_STATE_CHANGED; if (Lock_view_to_cursegp) { - if (last_keypress != KEY_V+KEY_CTRLED) + //if (keypress != KEY_V+KEY_CTRLED) diagnostic_message("[ctrl-V] View locked to Cursegp."); - else - diagnostic_message("View locked to Cursegp."); + //else + // diagnostic_message("View locked to Cursegp."); set_view_target_from_segment(Cursegp); } else { - if (last_keypress != KEY_V+KEY_CTRLED) + //if (keypress != KEY_V+KEY_CTRLED) diagnostic_message("[ctrl-V] View not locked to Cursegp."); - else - diagnostic_message("View not locked to Cursegp."); + //else + // diagnostic_message("View not locked to Cursegp."); } return Lock_view_to_cursegp; } @@ -191,16 +191,16 @@ int ToggleDrawAllSegments() Draw_all_segments = !Draw_all_segments; Update_flags = UF_ED_STATE_CHANGED; if (Draw_all_segments == 1) { - if (last_keypress != KEY_A+KEY_CTRLED) + //if (keypress != KEY_A+KEY_CTRLED) diagnostic_message("[ctrl-A] Draw all segments ON."); - else - diagnostic_message("Draw all segments ON."); + //else + // diagnostic_message("Draw all segments ON."); } if (Draw_all_segments == 0) { - if (last_keypress != KEY_A+KEY_CTRLED) + //if (keypress != KEY_A+KEY_CTRLED) diagnostic_message("[ctrl-A] Draw all segments OFF."); - else - diagnostic_message("Draw all segments OFF."); + //else + // diagnostic_message("Draw all segments OFF."); } return Draw_all_segments; } @@ -230,16 +230,16 @@ int ToggleCoordAxes() Show_axes_flag = !Show_axes_flag; LargeView.ev_changed = 1; if (Show_axes_flag == 1) { - if (last_keypress != KEY_D+KEY_CTRLED) + //if (keypress != KEY_D+KEY_CTRLED) diagnostic_message("[ctrl-D] Coordinate axes ON."); - else - diagnostic_message("Coordinate axes ON."); + //else + // diagnostic_message("Coordinate axes ON."); } if (Show_axes_flag == 0) { - if (last_keypress != KEY_D+KEY_CTRLED) + //if (keypress != KEY_D+KEY_CTRLED) diagnostic_message("[ctrl-D] Coordinate axes OFF."); - else - diagnostic_message("Coordinate axes OFF."); + //else + // diagnostic_message("Coordinate axes OFF."); } return Show_axes_flag; } diff --git a/editor/objpage.c b/editor/objpage.c index fc3f2589c..ca4695aad 100644 --- a/editor/objpage.c +++ b/editor/objpage.c @@ -407,19 +407,22 @@ void objpage_close() // DO TEXTURE STUFF -void objpage_do() +int objpage_do(d_event *event) { int i; for (i=0; ib1_clicked && (i+ObjectPage*OBJS_PER_PAGE < Num_object_subtypes)) + if (GADGET_PRESSED(ObjBox[i]) && (i+ObjectPage*OBJS_PER_PAGE < Num_object_subtypes)) { Cur_object_id = i+ObjectPage*OBJS_PER_PAGE; gr_set_current_canvas(ObjCurrent->canvas); //gr_ubitmap(0,0, robot_bms[robot_bm_nums[ Cur_robot_type ] ] ); gr_label_box(Cur_object_id); //objpage_display_name( Texture[Cur_robot_type]->filename ); + return 1; } } + + return 0; } diff --git a/editor/texpage.c b/editor/texpage.c index 592bb4b33..5a07c35f8 100644 --- a/editor/texpage.c +++ b/editor/texpage.c @@ -228,12 +228,12 @@ typedef struct replacement { replacement Replacement_list[MAX_REPLACEMENTS]; int Num_replacements=0; -void texpage_do() +int texpage_do(d_event *event) { int i; for (i=0; ib1_clicked && (i + TexturePage*TMAPS_PER_PAGE < NumTextures)) + if (GADGET_PRESSED(TmapBox[i]) && (i + TexturePage*TMAPS_PER_PAGE < NumTextures)) { CurrentTexture = i + TexturePage*TMAPS_PER_PAGE; texpage_show_current(); @@ -246,8 +246,12 @@ void texpage_do() Replacement_list[Num_replacements].new = CurrentTexture; Num_replacements++; } + + return 1; } } + + return 0; } void init_replacements(void) diff --git a/include/editor/objpage.h b/include/editor/objpage.h index d0d95f583..b7fa57b66 100644 --- a/include/editor/objpage.h +++ b/include/editor/objpage.h @@ -23,12 +23,14 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #include "ui.h" +struct d_event; + int objpage_grab_current(int n); int objpage_goto_first(); void objpage_init( UI_DIALOG *dlg ); void objpage_close(); -void objpage_do(); +int objpage_do(struct d_event *event); extern void draw_object_picture(int id, vms_angvec *orient_angles, int type); diff --git a/include/editor/texpage.h b/include/editor/texpage.h index 072141100..0160f5af3 100644 --- a/include/editor/texpage.h +++ b/include/editor/texpage.h @@ -22,6 +22,8 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #include "ui.h" +struct d_event; + extern int TextureLights; extern int TextureEffects; extern int TextureMetals; @@ -30,6 +32,6 @@ int texpage_grab_current(int n); int texpage_goto_first(); void texpage_init( UI_DIALOG * dlg ); void texpage_close(); -void texpage_do(); +int texpage_do(struct d_event *event); #endif diff --git a/include/ui.h b/include/ui.h index 2b39738d3..2ed51073b 100644 --- a/include/ui.h +++ b/include/ui.h @@ -249,7 +249,6 @@ extern UI_MOUSE Mouse; extern unsigned char CBLACK,CGREY,CWHITE,CBRIGHT,CRED; extern UI_GADGET * selected_gadget; -extern int last_keypress; extern void Hline(short x1, short x2, short y ); extern void Vline(short y1, short y2, short x ); diff --git a/ui/userbox.c b/ui/userbox.c index fb08b252a..023695dd7 100644 --- a/ui/userbox.c +++ b/ui/userbox.c @@ -89,12 +89,13 @@ int ui_userbox_do( UI_DIALOG *dlg, UI_GADGET_USERBOX * userbox, d_event *event ) mouse_get_pos(&x, &y, &z); OnMe = ui_mouse_on_gadget( (UI_GADGET *)userbox ); - olddrag = userbox->b1_dragging; + olddrag = userbox->b1_held_down; userbox->mouse_onme = OnMe; userbox->mouse_x = x - userbox->x1; userbox->mouse_y = y - userbox->y1; + userbox->b1_dragging = 0; userbox->b1_clicked = 0; if (OnMe) @@ -108,7 +109,6 @@ int ui_userbox_do( UI_DIALOG *dlg, UI_GADGET_USERBOX * userbox, d_event *event ) } else if (B1_JUST_RELEASED) { - userbox->b1_dragging = 0; if (userbox->b1_held_down) userbox->b1_clicked = 1; userbox->b1_held_down = 0; @@ -133,11 +133,11 @@ int ui_userbox_do( UI_DIALOG *dlg, UI_GADGET_USERBOX * userbox, d_event *event ) } if (B1_JUST_RELEASED) - userbox->b1_dragging = 0; + userbox->b1_held_down = 0; userbox->b1_done_dragging = 0; - if (olddrag==1 && userbox->b1_dragging==0 ) + if (olddrag==1 && userbox->b1_held_down==0 ) { if ((userbox->b1_drag_x1 != userbox->b1_drag_x2) || (userbox->b1_drag_y1 != userbox->b1_drag_y2) ) userbox->b1_done_dragging = 1;