Add EVENT_NEWMENU_SELECTED, allowing a newmenu/listbox selection to be handled in the callback. Demonstrate with "Select Song" menu
This commit is contained in:
parent
6b4d952ebc
commit
b97e08dfdc
|
@ -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)
|
||||
|
|
|
@ -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'.
|
||||
|
|
30
main/menu.c
30
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;
|
||||
case MENU_PLAY_SONG:
|
||||
{
|
||||
char * m[MAX_NUM_SONGS];
|
||||
int i;
|
||||
|
||||
for (i=0;i<Num_songs;i++) {
|
||||
for (i=0;i<Num_songs;i++)
|
||||
m[i] = Songs[i].filename;
|
||||
}
|
||||
i = newmenu_listbox( "Select Song", Num_songs, m, 1, NULL, NULL );
|
||||
|
||||
if ( i > -1 ) {
|
||||
songs_play_song( i, 0 );
|
||||
}
|
||||
}
|
||||
newmenu_listbox( "Select Song", Num_songs, m, 1, select_song_callback, NULL );
|
||||
break;
|
||||
}
|
||||
case MENU_LOAD_LEVEL:
|
||||
if (Current_mission || select_mission(0, "Load Level\n\nSelect mission"))
|
||||
{
|
||||
|
|
|
@ -876,6 +876,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;
|
||||
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue