From b97e08dfdc16406fb00e924e00202f32ac9f1901 Mon Sep 17 00:00:00 2001 From: kreatordxx <> Date: Fri, 8 Jan 2010 01:55:12 +0000 Subject: [PATCH] Add EVENT_NEWMENU_SELECTED, allowing a newmenu/listbox selection to be handled in the callback. Demonstrate with "Select Song" menu --- CHANGELOG.txt | 4 ++++ arch/include/event.h | 3 ++- main/menu.c | 34 ++++++++++++++++++++++------------ main/newmenu.c | 26 ++++++++++++++++++++++++++ main/newmenu.h | 5 +++++ 5 files changed, 59 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 8bbd64c3a..56d4a8d89 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,5 +1,9 @@ D1X-Rebirth Changelog +20100108 +-------- +arch/sdl/event.h, main/menu.c, main/newmenu.c, main/newmenu.h: Add EVENT_NEWMENU_SELECTED, allowing a newmenu/listbox selection to be handled in the callback. Demonstrate with "Select Song" menu + 20100107 -------- main/gamecntl.c, main/newdemo.c: New Interpolation method for demos and a small hack to fix this Interpolation if duplicate object signatures appear (mostly) diff --git a/arch/include/event.h b/arch/include/event.h index 9a5052192..e3be95c88 100644 --- a/arch/include/event.h +++ b/arch/include/event.h @@ -8,7 +8,8 @@ typedef enum event_type EVENT_IDLE = 0, EVENT_KEY_COMMAND, EVENT_DRAW, - EVENT_CLOSE + EVENT_CLOSE, + EVENT_USER // spare for use by modules that use windows (e.g. newmenu) } event_type; // A vanilla event. Cast to the correct type of event according to 'type'. diff --git a/main/menu.c b/main/menu.c index 9aaf4f011..78b0b8be0 100644 --- a/main/menu.c +++ b/main/menu.c @@ -228,6 +228,20 @@ int DoMenu() extern void show_order_form(void); // John didn't want this in inferno.h so I just externed it. +int select_song_callback(listbox *lb, d_event *event, void *userdata) +{ + int citem = listbox_get_citem(lb); + + userdata = userdata; + if (event->type != EVENT_NEWMENU_SELECTED) + return 0; + + if (citem > -1) + songs_play_song( citem, 0 ); + + return 1; // stay in menu until user escapes +} + //returns flag, true means quit menu void do_option ( int select) { @@ -273,20 +287,16 @@ void do_option ( int select) #ifndef RELEASE - case MENU_PLAY_SONG: { - int i; - char * m[MAX_NUM_SONGS]; + case MENU_PLAY_SONG: + { + char * m[MAX_NUM_SONGS]; + int i; - for (i=0;i -1 ) { - songs_play_song( i, 0 ); - } - } + for (i=0;itype = EVENT_NEWMENU_SELECTED; + if (menu->subfunction && (*menu->subfunction)(menu, event, menu->userdata)) + return 1; + menu->done = 1; gr_set_current_canvas(save_canvas); return 1; @@ -1084,6 +1089,11 @@ int newmenu_handler(window *wind, d_event *event, newmenu *menu) if (Hack_DblClick_MenuMode) { if (menu->dblclick_flag) { + // Tell callback, allow staying in menu + event->type = EVENT_NEWMENU_SELECTED; + if (menu->subfunction && (*menu->subfunction)(menu, event, menu->userdata)) + return 1; + menu->done = 1; gr_set_current_canvas(save_canvas); return 1; @@ -1092,6 +1102,11 @@ int newmenu_handler(window *wind, d_event *event, newmenu *menu) } else { + // Tell callback, allow staying in menu + event->type = EVENT_NEWMENU_SELECTED; + if (menu->subfunction && (*menu->subfunction)(menu, event, menu->userdata)) + return 1; + menu->done = 1; gr_set_current_canvas(save_canvas); return 1; @@ -1802,6 +1817,11 @@ int listbox_handler(window *wind, d_event *event, listbox *lb) break; case KEY_ENTER: case KEY_PADENTER: + // Tell callback, allow staying in menu + event->type = EVENT_NEWMENU_SELECTED; + if (lb->listbox_callback && (*lb->listbox_callback)(lb, event, lb->userdata)) + return 1; + lb->done = 1; return 1; break; @@ -1868,6 +1888,12 @@ int listbox_handler(window *wind, d_event *event, listbox *lb) y2 = y1+h; if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) { lb->citem = i; + + // Tell callback, allow staying in menu + event->type = EVENT_NEWMENU_SELECTED; + if (lb->listbox_callback && (*lb->listbox_callback)(lb, event, lb->userdata)) + return 1; + lb->done = 1; return 1; break; diff --git a/main/newmenu.h b/main/newmenu.h index f2ed08a72..325688995 100644 --- a/main/newmenu.h +++ b/main/newmenu.h @@ -38,6 +38,11 @@ typedef struct listbox listbox; #define NM_MAX_TEXT_LEN 255 +enum newmenu_event +{ + EVENT_NEWMENU_SELECTED = EVENT_USER +}; + typedef struct newmenu_item { int type; // What kind of item this is, see NM_TYPE_????? defines int value; // For checkboxes and radio buttons, this is 1 if marked initially, else 0