X-Git-Url: https://deadsoftware.ru/gitweb?p=flatwaifu.git;a=blobdiff_plain;f=src%2Fmenu.c;h=ddbf0b4deb8a35a4e8735d9fec8d060bcdb457cd;hp=639fed9cfddeed963cc9862a5316f4d59c1ca989;hb=14813cefff1cc036bf217346188c168429b52e81;hpb=99e9995ba077aa90b20b47d528ccd3ff27949652 diff --git a/src/menu.c b/src/menu.c index 639fed9..ddbf0b4 100644 --- a/src/menu.c +++ b/src/menu.c @@ -162,7 +162,7 @@ static int start_game (int twoplayers, int dm, int level) { return GM_popall(); } -static int new_game_menu_handler (menu_msg_t *msg, const menu_t *m, void *data, int i) { +static int new_game_menu_handler (menu_msg_t *msg, const menu_t *m, int i) { static int cur; enum { ONEPLAYER, TWOPLAYERS, DEATHMATCH, __NUM__ }; static const simple_menu_t sm = { @@ -184,11 +184,7 @@ static int new_game_menu_handler (menu_msg_t *msg, const menu_t *m, void *data, return simple_menu_handler(msg, i, __NUM__, &sm, &cur); } -static const menu_t new_game_menu = { - NULL, &new_game_menu_handler -}; - -static int load_game_menu_handler (menu_msg_t *msg, const menu_t *m, void *data, int i) { +static int load_game_menu_handler (menu_msg_t *msg, const menu_t *m, int i) { static int cur; const int max_slots = 7; assert(i >= 0 && i < max_slots); @@ -206,11 +202,7 @@ static int load_game_menu_handler (menu_msg_t *msg, const menu_t *m, void *data, return basic_menu_handler(msg, GM_BIG, "Load game", "_OLDGAME", max_slots, &cur); } -static const menu_t load_game_menu = { - NULL, &load_game_menu_handler -}; - -static int save_game_menu_handler (menu_msg_t *msg, const menu_t *m, void *data, int i) { +static int save_game_menu_handler (menu_msg_t *msg, const menu_t *m, int i) { static int cur; const int max_slots = 7; assert(i >= 0 && i < max_slots); @@ -234,92 +226,33 @@ static int save_game_menu_handler (menu_msg_t *msg, const menu_t *m, void *data, return basic_menu_handler(msg, GM_BIG, "Save game", "_SAVGAME", max_slots, &cur); } -static const menu_t save_game_menu = { - NULL, &save_game_menu_handler -}; - -static int sound_menu_handler (menu_msg_t *msg, const menu_t *m, void *data, int i) { - static int cur; - enum { VOLUME, __NUM__ }; - static const simple_menu_t sm = { - GM_BIG, "Sound", NULL, - { - { "Volume", NULL }, - } - }; - if (i == VOLUME) { - switch (msg->type) { - case GM_GETENTRY: return GM_init_int0(msg, GM_SCROLLER, 0, 0, 0); - case GM_GETINT: return GM_init_int(msg, snd_vol, 0, 128, 8); - case GM_SETINT: S_volume(msg->integer.i); return 1; - } - } - return simple_menu_handler(msg, i, __NUM__, &sm, &cur); -} - -static const menu_t sound_menu = { - NULL, &sound_menu_handler -}; - -static int music_menu_handler (menu_msg_t *msg, const menu_t *m, void *data, int i) { - static int cur; - enum { VOLUME, MUSIC, __NUM__ }; - static const simple_menu_t sm = { - GM_BIG, "Music", NULL, - { - { "Volume", NULL }, - { "Music: ", NULL }, - } - }; - if (i == VOLUME) { - switch (msg->type) { - case GM_GETENTRY: return GM_init_int0(msg, GM_SCROLLER, 0, 0, 0); - case GM_GETINT: return GM_init_int(msg, mus_vol, 0, 128, 8); - case GM_SETINT: S_volumemusic(msg->integer.i); return 1; - } - } else if (i == MUSIC) { - switch (msg->type) { - case GM_GETSTR: return GM_init_str(msg, g_music, strlen(g_music)); - case GM_SELECT: - F_freemus(); - F_nextmus(g_music); - F_loadmus(g_music); - S_startmusic(music_time * 2); // ??? - return 1; - } - } - return simple_menu_handler(msg, i, __NUM__, &sm, &cur); -} - -static const menu_t music_menu = { - NULL, &music_menu_handler -}; - -static int options_menu_handler (menu_msg_t *msg, const menu_t *m, void *data, int i) { +static int options_menu_handler (menu_msg_t *msg, const menu_t *m, int i) { static int cur; + const menu_t *mm; enum { VIDEO, SOUND, MUSIC, __NUM__ }; static const simple_menu_t sm = { GM_BIG, "Options", NULL, { { "Video", NULL }, - { "Sound", &sound_menu }, - { "Music", &music_menu }, + { "Sound", NULL }, + { "Music", NULL }, } }; if (msg->type == GM_SELECT) { - if (i == VIDEO) { - const menu_t *mm = R_menu(); - return mm ? GM_push(mm) : 1; + switch (i) { + case VIDEO: mm = R_menu(); break; + case SOUND: mm = S_menu(); break; + case MUSIC: mm = MUS_menu(); break; + default: mm = NULL; + } + if (mm != NULL) { + return GM_push(mm); } } return simple_menu_handler(msg, i, __NUM__, &sm, &cur); } -static const menu_t options_menu = { - NULL, &options_menu_handler -}; - -static int exit_menu_handler (menu_msg_t *msg, const menu_t *m, void *data, int i) { +static int exit_menu_handler (menu_msg_t *msg, const menu_t *m, int i) { static int cur; enum { YES, NO, __NUM__ }; static const simple_menu_t sm = { @@ -334,7 +267,7 @@ static int exit_menu_handler (menu_msg_t *msg, const menu_t *m, void *data, int } else if (msg->type == GM_SELECT) { switch (i) { case YES: - F_freemus(); + MUS_free(); GM_stop(); Z_sound(S_get(qsnd[myrand(QSND_NUM)]), 255); S_wait(); @@ -347,30 +280,31 @@ static int exit_menu_handler (menu_msg_t *msg, const menu_t *m, void *data, int return simple_menu_handler(msg, i, __NUM__, &sm, &cur); } -static const menu_t exit_menu = { - NULL, &exit_menu_handler -}; - -static int main_menu_handler (menu_msg_t *msg, const menu_t *m, void *data, int i) { - static int cur; +static int main_menu_handler (menu_msg_t *msg, const menu_t *m, int i) { enum { NEWGAME, OLDGAME, SAVEGAME, OPTIONS, EXIT, __NUM__ }; assert(i >= 0 && i < __NUM__); + static int cur; + static const menu_t hm[__NUM__] = { + { new_game_menu_handler }, + { load_game_menu_handler }, + { save_game_menu_handler }, + { options_menu_handler}, + { exit_menu_handler } + }; static const simple_menu_t sm = { GM_BIG, "Menu", NULL, { - { "New Game", &new_game_menu }, - { "Load Game", &load_game_menu }, - { "Save Game", &save_game_menu }, - { "Options", &options_menu }, - { "Exit", &exit_menu }, + { "New Game", &hm[NEWGAME] }, + { "Load Game", &hm[OLDGAME] }, + { "Save Game", &hm[SAVEGAME] }, + { "Options", &hm[OPTIONS] }, + { "Exit", &hm[EXIT] } } }; return simple_menu_handler(msg, i, __NUM__, &sm, &cur); } -static const menu_t main_menu = { - NULL, &main_menu_handler -}; +static const menu_t main_menu = { &main_menu_handler }; int GM_push (const menu_t *m) { assert(m != NULL); @@ -425,7 +359,7 @@ int GM_send_this (const menu_t *m, menu_msg_t *msg) { assert(msg != NULL); if (m->handler != NULL) { GM_normalize_message(msg); - return m->handler(msg, m, m->data, 0); + return m->handler(msg, m, 0); } return 0; } @@ -436,7 +370,7 @@ int GM_send (const menu_t *m, int i, menu_msg_t *msg) { assert(msg != NULL); if (m->handler != NULL) { GM_normalize_message(msg); - return m->handler(msg, m, m->data, i); + return m->handler(msg, m, i); } return 0; } @@ -656,6 +590,6 @@ void GM_init (void) { msnd4 = Z_getsnd("SWTCHX"); msnd5 = Z_getsnd("SUDI"); msnd6 = Z_getsnd("TUDI"); - F_loadmus("MENU"); - S_startmusic(0); + MUS_load("MENU"); + MUS_start(0); }