X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fmenu.c;h=40384c85fc97ec654b0ca94d40383ab413cc4965;hb=8d943097f7b1a0f417651d39149dffa726ef8cde;hp=e80e43612c2911159f50070bd163bd2692d71993;hpb=555a6c929ea8739502282844e6253b3326cb6e2f;p=flatwaifu.git diff --git a/src/menu.c b/src/menu.c index e80e436..40384c8 100644 --- a/src/menu.c +++ b/src/menu.c @@ -94,18 +94,23 @@ static void GM_say (const char nm[8]) { } } -static int GM_init_int (new_msg_t *msg, int i, int a, int b, int s) { +int GM_init_int0 (new_msg_t *msg, int i, int a, int b, int s) { assert(msg != NULL); - assert(a <= b); - assert(s >= 0); - msg->integer.i = min(max(i, a), b); + msg->integer.i = i; msg->integer.a = a; msg->integer.b = b; msg->integer.s = s; return 1; } -static int GM_init_str (new_msg_t *msg, char *str, int maxlen) { +int GM_init_int (new_msg_t *msg, int i, int a, int b, int s) { + assert(msg != NULL); + assert(a <= b); + assert(s >= 0); + return GM_init_int0(msg, min(max(i, a), b), a, b, s); +} + +int GM_init_str (new_msg_t *msg, char *str, int maxlen) { assert(msg != NULL); assert(str != NULL); assert(maxlen >= 0); @@ -221,6 +226,13 @@ static int GM_save_handler (new_msg_t *msg, const new_menu_t *m, void *data) { return 0; } +static int GM_options_handler (new_msg_t *msg, const new_menu_t *m, void *data) { + switch (msg->type) { + case GM_SELECT: GM_push(R_menu()); return 1; + } + return 0; +} + static int GM_exit_handler (new_msg_t *msg, const new_menu_t *m, void *data) { switch (msg->type) { case GM_ENTER: @@ -289,7 +301,7 @@ static const new_menu_t newgame_menu = { }, options_menu = { GM_BIG, "Options", NULL, NULL, { - //{ GM_BUTTON, "Video", NULL, NULL, NULL }, + { GM_BUTTON, "Video", NULL, &GM_options_handler, NULL }, { GM_BUTTON, "Sound", NULL, NULL, &sound_menu }, { GM_BUTTON, "Music", NULL, NULL, &music_menu }, { 0, NULL, NULL, NULL, NULL } // end @@ -369,12 +381,30 @@ static void GM_normalize_message (new_msg_t *msg) { } } +static int count_menu_entries (const new_menu_t *m) { + assert(m != NULL); + int i = 0; + while (m->entries[i].type != 0) { + i += 1; + } + return i; +} + int GM_send_this (const new_menu_t *m, new_msg_t *msg) { assert(m != NULL); assert(msg != NULL); - if (m->handler != NULL) { - GM_normalize_message(msg); - return m->handler(msg, m, m->data); + int n; + switch (msg->type) { + case GM_QUERY: + n = count_menu_entries(m); + return GM_init_int0(msg, GM_geti(), n, n, m->type); + case GM_GETTITLE: + return GM_init_str(msg, m->title, strlen(m->title)); + default: + if (m->handler != NULL) { + GM_normalize_message(msg); + return m->handler(msg, m, m->data); + } } return 0; } @@ -384,9 +414,14 @@ int GM_send (const new_menu_t *m, int i, new_msg_t *msg) { assert(i >= 0); assert(msg != NULL); const new_var_t *v = &m->entries[i]; - if (v->handler != NULL) { - GM_normalize_message(msg); - return v->handler(msg, m, v->data); + switch (msg->type) { + case GM_GETENTRY: return GM_init_int0(msg, v->type, 0, 0, 0); + case GM_GETCAPTION: return GM_init_str(msg, v->caption, strlen(v->caption)); + default: + if (v->handler != NULL) { + GM_normalize_message(msg); + return v->handler(msg, m, v->data); + } } return 0; } @@ -433,15 +468,6 @@ void G_code (void) { Z_sound(s,128); } -static int count_menu_entries (const new_menu_t *m) { - assert(m != NULL); - int i = 0; - while (m->entries[i].type != 0) { - i += 1; - } - return i; -} - static int strnlen (const char *s, int len) { int i = 0; while (i < len && s[i] != 0) {