diff --git a/src/menu.c b/src/menu.c
index 629f0c8d02f2b5129cbba7deff70efcb0d9c15ab..491e5cc605cb7487c261f57167c36fb59cf2dc79 100644 (file)
--- a/src/menu.c
+++ b/src/menu.c
-/*
- Copyright (C) Prikol Software 1996-1997
- Copyright (C) Aleksey Volynskov 1996-1997
- Copyright (C) <ARembo@gmail.com> 2011
-
- This file is part of the Doom2D:Rembo project.
-
- Doom2D:Rembo is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License version 2 as
- published by the Free Software Foundation.
-
- Doom2D:Rembo is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, see <http://www.gnu.org/licenses/> or
- write to the Free Software Foundation, Inc.,
- 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+/* Copyright (C) 2020 SovietPony
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License ONLY.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
#include "glob.h"
#include "files.h"
#include "input.h"
#include "system.h"
+#include "save.h"
+
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX_STACK 8
static struct {
- int n;
- const new_menu_t *m;
+ const menu_t *m;
} stack[MAX_STACK];
static int stack_p = -1;
}
}
-static void GM_say (const char nm[8]) {
+static int GM_say (const char nm[8]) {
snd_t *snd = S_load(nm);
if (snd) {
GM_stop();
voc = S_load(nm);
voc_ch = S_play(voc, 0, 255);
}
+ return 1;
}
-static int GM_init_int (new_msg_t *msg, int i, int a, int b, int s) {
+int GM_init_int0 (menu_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 (menu_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 (menu_msg_t *msg, char *str, int maxlen) {
assert(msg != NULL);
assert(str != NULL);
assert(maxlen >= 0);
return 1;
}
-static int GM_newgame_handler (new_msg_t *msg, const new_menu_t *m, void *data) {
+int basic_menu_handler (menu_msg_t *msg, byte type, char *title, char *say, int n, int *cur) {
assert(msg != NULL);
- intptr_t i = (intptr_t)data;
+ assert(type == GM_BIG || type == GM_SMALL);
+ assert(title != NULL);
+ assert(n >= 0);
+ assert(cur != NULL);
switch (msg->type) {
- case GM_ENTER:
- GM_say("_NEWGAME");
- return 1;
- case GM_SELECT:
- _2pl = 0;
- g_dm = 0;
- switch (i) {
- case 0: GM_say("_1PLAYER"); break;
- case 1: GM_say("_2PLAYER"); break;
- case 2: GM_say("_DM"); break;
- // GM_say("_COOP");
- }
- switch (i) {
- case 2: // DEATHMATCH
- g_dm = 1;
- case 1: // COOPERATIVE
- _2pl = 1;
- case 0: // SINGLEPLAYER
- g_map = _warp ? _warp : 1;
- PL_reset();
- pl1.color = pcolortab[p1color];
- pl2.color = pcolortab[p2color];
- G_start();
- GM_popall();
- return 1;
- }
- break;
+ case GM_QUERY: return GM_init_int0(msg, *cur, n, n, type);
+ case GM_GETTITLE: return GM_init_str(msg, title, strlen(title));
+ case GM_ENTER: return say ? GM_say(say) : 1;
+ case GM_UP: *cur = GM_CYCLE(*cur - 1, 0, n - 1); return 1;
+ case GM_DOWN: *cur = GM_CYCLE(*cur + 1, 0, n - 1); return 1;
}
return 0;
}
-static int GM_var_handler (new_msg_t *msg, const new_menu_t *m, void *data) {
+int simple_menu_handler (menu_msg_t *msg, int i, int n, const simple_menu_t *m, int *cur) {
assert(msg != NULL);
- if (data == &snd_vol) {
- switch (msg->type) {
- case GM_GETINT: return GM_init_int(msg, snd_vol, 0, 128, 8);
- case GM_SETINT: S_volume(msg->integer.i); return 1;
- }
- } else if (data == &mus_vol) {
- switch (msg->type) {
- case GM_GETINT: return GM_init_int(msg, mus_vol, 0, 128, 8);
- case GM_SETINT: S_volumemusic(msg->integer.i); return 1;
+ assert(n >= 0);
+ assert(i >= 0 && i < n);
+ assert(m != NULL);
+ assert(cur != NULL);
+ switch (msg->type) {
+ case GM_GETENTRY: return GM_init_int0(msg, m->type == GM_SMALL ? GM_SMALL_BUTTON : GM_BUTTON, 0, 0, 0);
+ case GM_GETCAPTION: return GM_init_str(msg, m->entries[i].caption, strlen(m->entries[i].caption));
+ case GM_SELECT: return m->entries[i].submenu ? GM_push(m->entries[i].submenu) : 1;
+ }
+ return basic_menu_handler(msg, m->type, m->title, m->say, n, cur);
+}
+
+static int start_game (int twoplayers, int dm, int level) {
+ _2pl = twoplayers;
+ g_dm = dm;
+ g_map = level ? level : 1;
+ PL_reset();
+ pl1.color = pcolortab[p1color];
+ pl2.color = pcolortab[p2color];
+ G_start();
+ return GM_popall();
+}
+
+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 = {
+ GM_BIG, "New Game", "_NEWGAME",
+ {
+ { "One Player", NULL },
+ { "Two Players", NULL },
+ { "Deathmatch", NULL },
}
- } else if (data == g_music) {
- switch (msg->type) {
- case GM_GETSTR:
- return GM_init_str(msg, g_music, 8);
- case GM_SELECT:
- F_freemus();
- F_nextmus(g_music);
- F_loadmus(g_music);
- S_startmusic(music_time * 2); // ???
- return 1;
+ };
+ if (msg->type == GM_SELECT) {
+ switch (i) {
+ case ONEPLAYER: GM_say("_1PLAYER"); return start_game(0, 0, _warp);
+ case TWOPLAYERS: GM_say("_2PLAYER"); return start_game(1, 0, _warp);
+ case DEATHMATCH: GM_say("_DM"); return start_game(1, 1, _warp);
+ // GM_say("_COOP");
}
}
- return 0;
+ return simple_menu_handler(msg, i, __NUM__, &sm, &cur);
}
-static int GM_load_handler (new_msg_t *msg, const new_menu_t *m, void *data) {
- assert(msg != NULL);
- intptr_t i = (intptr_t)data;
+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);
switch (msg->type) {
- case GM_ENTER:
- F_getsavnames();
- return 1;
- case GM_GETSTR:
- return GM_init_str(msg, (char*)savname[i], 24);
+ case GM_ENTER: F_getsavnames(); break;
+ case GM_GETENTRY: return GM_init_int0(msg, GM_TEXTFIELD_BUTTON, 0, 0, 0);
+ case GM_GETSTR: return GM_init_str(msg, (char*)savname[i], 24);
case GM_SELECT:
if (savok[i]) {
load_game(i);
GM_popall();
- return 1;
}
- break;
+ return 1;
}
- return 0;
+ return basic_menu_handler(msg, GM_BIG, "Load game", "_OLDGAME", max_slots, &cur);
}
-static int GM_save_handler (new_msg_t *msg, const new_menu_t *m, void *data) {
- assert(msg != NULL);
- intptr_t i = (intptr_t)data;
+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);
switch (msg->type) {
- case GM_ENTER:
+ case GM_SELECT:
if (g_st == GS_GAME) {
F_getsavnames();
+ break;
} else {
- GM_pop();
+ return GM_pop();
}
- return 1;
- case GM_GETSTR:
- F_getsavnames();
- return GM_init_str(msg, (char*)savname[i], 24);
+ case GM_GETENTRY: return GM_init_int0(msg, GM_TEXTFIELD, 0, 0, 0);
+ case GM_GETSTR: return GM_init_str(msg, (char*)savname[i], 24);
case GM_END:
if (g_st == GS_GAME) {
- F_savegame(i, msg->string.s); // TODO check size
- GM_popall();
- return 1;
+ assert(msg->string.maxlen >= 24);
+ F_savegame(i, msg->string.s);
}
- break;
+ return GM_popall();
}
- return 0;
+ return basic_menu_handler(msg, GM_BIG, "Save game", "_SAVGAME", max_slots, &cur);
}
-static int GM_exit_handler (new_msg_t *msg, const new_menu_t *m, void *data) {
+typedef struct controls_menu_t {
+ menu_t base;
+ int *pl_keys;
+} controls_menu_t;
+
+static int controls_menu_handler (menu_msg_t *msg, const menu_t *m, int i) {
+ static int cur = 0;
+ static int state = 0;
+ const int max_controls = 9;
+ const char *str = NULL;
+ const controls_menu_t *mm = (controls_menu_t*)m;
+ const char *captions[] = {
+ "Up: ", "Down: ", "Left: ", "Right: ", "Fire: ", "Jump: ", "Prev: ", "Next: ", "Press: "
+ };
+ assert(i >= 0 && i < max_controls);
switch (msg->type) {
case GM_ENTER:
- GM_say(rand() & 1 ? "_EXIT1" : "_EXIT2");
+ state = 0;
+ break; /* default behavior */
+ case GM_LEAVE:
+ if (state == 0) {
+ break; /* default behavior */
+ } else {
+ state = 0;
+ return 1;
+ }
+ case GM_UP:
+ case GM_DOWN:
+ if (state == 0) {
+ break; /* default behavior */
+ } else {
+ return 1; /* ignore */
+ }
+ case GM_KEY:
+ if (state != 0 && msg->integer.i != KEY_UNKNOWN) {
+ mm->pl_keys[cur] = msg->integer.i;
+ state = 0;
+ }
return 1;
+ case GM_GETENTRY:
+ return GM_init_int0(msg, GM_SMALL_BUTTON, 0, 0, 0);
+ case GM_GETCAPTION:
+ return GM_init_str(msg, (char*)captions[i], strlen(captions[i]));
+ case GM_GETSTR:
+ str = state == 0 || i != cur ? I_key_to_string(mm->pl_keys[i]) : "...";
+ return GM_init_str(msg, (char*)str, strlen(str));
case GM_SELECT:
- if (data != NULL) {
- F_freemus();
+ state = state == 0 ? 1 : 0;
+ return 1;
+ }
+ return basic_menu_handler(msg, GM_BIG, "Player 1 controls", NULL, max_controls, &cur);
+}
+
+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, CONTROLS_1, CONTROLS_2, __NUM__ };
+ static const controls_menu_t c1 = {
+ { controls_menu_handler },
+ &pl1.ku
+ };
+ static const controls_menu_t c2 = {
+ { controls_menu_handler },
+ &pl2.ku
+ };
+ static const simple_menu_t sm = {
+ GM_BIG, "Options", NULL,
+ {
+ { "Video", NULL },
+ { "Sound", NULL },
+ { "Music", NULL },
+ { "Controls 1", &c1.base },
+ { "Controls 2", &c2.base },
+ }
+ };
+ if (msg->type == GM_SELECT) {
+ 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 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 = {
+ GM_SMALL, "You are sure?", NULL,
+ {
+ { "Yes", NULL },
+ { "No", NULL },
+ }
+ };
+ if (msg->type == GM_ENTER) {
+ return GM_say(rand() & 1 ? "_EXIT1" : "_EXIT2");
+ } else if (msg->type == GM_SELECT) {
+ switch (i) {
+ case YES:
+ MUS_free();
GM_stop();
Z_sound(S_get(qsnd[myrand(QSND_NUM)]), 255);
S_wait();
ERR_quit();
- } else {
- GM_pop();
- }
- return 1;
+ return 1;
+ case NO:
+ return GM_pop();
+ }
}
- return 0;
+ return simple_menu_handler(msg, i, __NUM__, &sm, &cur);
}
-static const new_menu_t newgame_menu = {
- GM_BIG, "New game", NULL, NULL,
- {
- { GM_BUTTON, "One player", (void*)0, &GM_newgame_handler, NULL },
- { GM_BUTTON, "Two players", (void*)1, &GM_newgame_handler, NULL },
- { GM_BUTTON, "Deathmatch", (void*)2, &GM_newgame_handler, NULL },
- { 0, NULL, NULL, NULL, NULL } // end
- }
-}, loadgame_menu = {
- GM_BIG, "Load game", NULL, &GM_load_handler,
- {
- { GM_TEXTFIELD_BUTTON, "", (void*)0, &GM_load_handler, NULL },
- { GM_TEXTFIELD_BUTTON, "", (void*)1, &GM_load_handler, NULL },
- { GM_TEXTFIELD_BUTTON, "", (void*)2, &GM_load_handler, NULL },
- { GM_TEXTFIELD_BUTTON, "", (void*)3, &GM_load_handler, NULL },
- { GM_TEXTFIELD_BUTTON, "", (void*)4, &GM_load_handler, NULL },
- { GM_TEXTFIELD_BUTTON, "", (void*)5, &GM_load_handler, NULL },
- { GM_TEXTFIELD_BUTTON, "", (void*)6, &GM_load_handler, NULL },
- { 0, NULL, NULL, NULL, NULL } // end
- }
-}, savegame_menu = {
- GM_BIG, "Save game", NULL, &GM_save_handler,
- {
- { GM_TEXTFIELD, "", (void*)0, &GM_save_handler, NULL },
- { GM_TEXTFIELD, "", (void*)1, &GM_save_handler, NULL },
- { GM_TEXTFIELD, "", (void*)2, &GM_save_handler, NULL },
- { GM_TEXTFIELD, "", (void*)3, &GM_save_handler, NULL },
- { GM_TEXTFIELD, "", (void*)4, &GM_save_handler, NULL },
- { GM_TEXTFIELD, "", (void*)5, &GM_save_handler, NULL },
- { GM_TEXTFIELD, "", (void*)6, &GM_save_handler, NULL },
- { 0, NULL, NULL, NULL, NULL } // end
- }
-}, sound_menu = {
- GM_BIG, "Sound", NULL, NULL,
- {
- { GM_SCROLLER, "Volume", &snd_vol, &GM_var_handler, NULL },
- { 0, NULL, NULL, NULL, NULL } // end
- }
-}, music_menu = {
- GM_BIG, "Music", NULL, NULL,
- {
- { GM_SCROLLER, "Volume", &mus_vol, &GM_var_handler, NULL },
- { GM_BUTTON, "Music: ", g_music, &GM_var_handler, NULL },
- { 0, NULL, NULL, NULL, NULL } // end
- }
-}, options_menu = {
- GM_BIG, "Options", NULL, NULL,
- {
- //{ GM_BUTTON, "Video", NULL, NULL, NULL },
- { GM_BUTTON, "Sound", NULL, NULL, &sound_menu },
- { GM_BUTTON, "Music", NULL, NULL, &music_menu },
- { 0, NULL, NULL, NULL, NULL } // end
- }
-}, exit_menu = {
- GM_SMALL, "You are sure?", NULL, &GM_exit_handler,
- {
- { GM_SMALL_BUTTON, "Yes", (void*)1, &GM_exit_handler, NULL },
- { GM_SMALL_BUTTON, "No", (void*)0, &GM_exit_handler, NULL },
- { 0, NULL, NULL, NULL, NULL } // end
- }
-}, main_menu = {
- GM_BIG, "Menu", NULL, NULL,
- {
- { GM_BUTTON, "New game", NULL, NULL, &newgame_menu },
- { GM_BUTTON, "Load game", NULL, NULL, &loadgame_menu },
- { GM_BUTTON, "Save game", NULL, NULL, &savegame_menu },
- { GM_BUTTON, "Options", NULL, NULL, &options_menu },
- { GM_BUTTON, "Exit", NULL, NULL, &exit_menu },
- { 0, NULL, NULL, NULL, NULL } // end
- }
-};
+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", &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 = { &main_menu_handler };
-void GM_push (const new_menu_t *m) {
+int GM_push (const menu_t *m) {
assert(m != NULL);
assert(stack_p >= -1);
assert(stack_p < MAX_STACK - 1);
- new_msg_t msg;
+ menu_msg_t msg;
stack_p += 1;
- if (stack[stack_p].m != m) {
- stack[stack_p].n = 0;
- stack[stack_p].m = m;
- }
+ stack[stack_p].m = m;
msg.type = GM_ENTER;
GM_send_this(m, &msg);
+ return 1;
}
-void GM_pop (void) {
+int GM_pop (void) {
assert(stack_p >= 0);
- new_msg_t msg;
+ menu_msg_t msg;
stack_p -= 1;
msg.type = GM_LEAVE;
GM_send_this(stack[stack_p + 1].m, &msg);
+ return 1;
}
-void GM_popall (void) {
+int GM_popall (void) {
int i;
for (i = 0; i >= -1; i--) {
GM_pop();
}
+ return 1;
}
-const new_menu_t *GM_get (void) {
+const menu_t *GM_get (void) {
if (stack_p >= 0) {
return stack[stack_p].m;
} else {
}
}
-int GM_geti (void) {
- if (stack_p >= 0) {
- return stack[stack_p].n;
- } else {
- return 0;
- }
-}
-
-static void GM_normalize_message (new_msg_t *msg) {
+static void GM_normalize_message (menu_msg_t *msg) {
switch (msg->type) {
case GM_SETINT:
msg->integer.i = min(max(msg->integer.i, msg->integer.a), msg->integer.b);
}
}
-int GM_send_this (const new_menu_t *m, new_msg_t *msg) {
+int GM_send_this (const menu_t *m, menu_msg_t *msg) {
assert(m != NULL);
assert(msg != NULL);
if (m->handler != NULL) {
GM_normalize_message(msg);
- return m->handler(msg, m, m->data);
+ return m->handler(msg, m, 0);
}
return 0;
}
-int GM_send (const new_menu_t *m, int i, new_msg_t *msg) {
+int GM_send (const menu_t *m, int i, menu_msg_t *msg) {
assert(m != NULL);
assert(i >= 0);
assert(msg != NULL);
- const new_var_t *v = &m->entries[i];
- if (v->handler != NULL) {
+ if (m->handler != NULL) {
GM_normalize_message(msg);
- return v->handler(msg, m, v->data);
+ return m->handler(msg, m, i);
}
return 0;
}
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) {
+static int x_strnlen (const char *s, int len) {
int i = 0;
while (i < len && s[i] != 0) {
i++;
}
int GM_act (void) {
- int n, cur;
- new_msg_t msg;
- const new_var_t *v;
- const new_menu_t *m = GM_get ();
+ menu_msg_t msg;
+ int n, cur, type;
+ const menu_t *m = GM_get();
if (m == NULL) {
if (lastkey == KEY_ESCAPE || (state_for_anykey(g_st) && lastkey != KEY_UNKNOWN)) {
GM_push(&main_menu);
Z_sound(msnd3, 128);
}
} else {
- n = count_menu_entries(m);
- cur = stack[stack_p].n;
- v = &m->entries[cur];
- switch (lastkey) {
- case KEY_ESCAPE:
- if (v->type == GM_TEXTFIELD && input) {
- input = 0;
- Y_disable_text_input();
- msg.type = GM_CANCEL;
- GM_send(m, cur, &msg);
- } else {
- GM_pop();
- Z_sound(msnd4, 128);
- }
- break;
- case KEY_UP:
- stack[stack_p].n = stack[stack_p].n - 1 < 0 ? n - 1 : stack[stack_p].n - 1;
- Z_sound(msnd1, 128);
- break;
- case KEY_DOWN:
- stack[stack_p].n = stack[stack_p].n + 1 >= n ? 0 : stack[stack_p].n + 1;
- Z_sound(msnd1, 128);
- break;
- case KEY_LEFT:
- case KEY_RIGHT:
- if (v->type == GM_SCROLLER) {
- msg.integer.type = GM_GETINT;
- if (GM_send(m, cur, &msg)) {
- msg.integer.type = GM_SETINT;
- msg.integer.i += lastkey == KEY_LEFT ? -msg.integer.s : msg.integer.s;
- msg.integer.i = min(max(msg.integer.i, msg.integer.a), msg.integer.b);
- if (GM_send(m, cur, &msg)) {
- Z_sound(lastkey == KEY_LEFT ? msnd5 : msnd6, 255);
+ /* 1. send key */
+ msg.type = GM_KEY;
+ GM_init_int0(&msg, lastkey, 0, 0, 0);
+ GM_send_this(m, &msg);
+ /* 2. send query */
+ msg.type = GM_QUERY;
+ if (GM_send_this(m, &msg)) {
+ /* 3. send getentry */
+ cur = msg.integer.i;
+ n = msg.integer.a;
+ msg.type = GM_GETENTRY;
+ if (GM_send(m, cur, &msg)) {
+ /* 4. send actions */
+ type = msg.integer.i;
+ switch (lastkey) {
+ case KEY_ESCAPE:
+ if (type == GM_TEXTFIELD && input) {
+ input = 0;
+ Y_disable_text_input();
+ msg.type = GM_CANCEL;
+ GM_send(m, cur, &msg);
+ } else {
+ GM_pop();
+ Z_sound(msnd4, 128);
}
- }
- } else if (v->type == GM_TEXTFIELD && input) {
- //icur += lastkey == KEY_LEFT ? -1 : +1;
- //icur = min(max(icur, 0), strnlen(ibuf, imax));
- }
- break;
- case KEY_BACKSPACE:
- if (v->type == GM_TEXTFIELD && input) {
- if (icur > 0) {
- // FIXIT buffers in strncpy must not overlap
- strncpy(&ibuf[icur - 1], &ibuf[icur], imax - icur);
- ibuf[imax - 1] = 0;
- icur -= 1;
- }
- }
- break;
- case KEY_RETURN:
- if (v->submenu != NULL) {
- GM_push(v->submenu);
- Z_sound(msnd2, 128);
- } else if (v->type == GM_TEXTFIELD) {
- if (input) {
- input = 0;
- Y_disable_text_input();
- msg.type = GM_END;
- msg.string.s = ibuf;
- msg.string.maxlen = imax;
- GM_send(m, cur, &msg);
- } else {
- msg.type = GM_GETSTR;
- if (GM_send(m, cur, &msg)) {
- imax = min(msg.string.maxlen, GM_MAX_INPUT);
- strncpy(ibuf, msg.string.s, imax);
- icur = strnlen(ibuf, imax);
+ break;
+ case KEY_UP:
+ case KEY_DOWN:
+ if (input == 0) {
+ msg.type = lastkey == KEY_UP ? GM_UP : GM_DOWN;
+ if (GM_send(m, cur, &msg)) {
+ Z_sound(msnd1, 128);
+ }
}
- input = 1;
- Y_enable_text_input();
- msg.type = GM_BEGIN;
- GM_send(m, cur, &msg);
- }
- } else {
- msg.type = GM_SELECT;
- GM_send(m, cur, &msg);
+ break;
+ case KEY_LEFT:
+ case KEY_RIGHT:
+ if (type == GM_SCROLLER) {
+ msg.integer.type = GM_GETINT;
+ if (GM_send(m, cur, &msg)) {
+ msg.integer.type = GM_SETINT;
+ msg.integer.i += lastkey == KEY_LEFT ? -msg.integer.s : msg.integer.s;
+ msg.integer.i = min(max(msg.integer.i, msg.integer.a), msg.integer.b);
+ if (GM_send(m, cur, &msg)) {
+ Z_sound(lastkey == KEY_LEFT ? msnd5 : msnd6, 255);
+ }
+ }
+ } else if (type == GM_TEXTFIELD) {
+ //if (input) {
+ // icur += lastkey == KEY_LEFT ? -1 : +1;
+ // icur = min(max(icur, 0), x_strnlen(ibuf, imax));
+ //}
+ }
+ break;
+ case KEY_BACKSPACE:
+ if (type == GM_TEXTFIELD) {
+ if (input && icur > 0) {
+ // FIXIT buffers in strncpy must not overlap
+ strncpy(&ibuf[icur - 1], &ibuf[icur], imax - icur);
+ ibuf[imax - 1] = 0;
+ icur -= 1;
+ }
+ }
+ break;
+ case KEY_RETURN:
+ if (type == GM_TEXTFIELD) {
+ if (input) {
+ input = 0;
+ Y_disable_text_input();
+ msg.type = GM_END;
+ msg.string.s = ibuf;
+ msg.string.maxlen = imax;
+ GM_send(m, cur, &msg);
+ } else {
+ msg.type = GM_GETSTR;
+ if (GM_send(m, cur, &msg)) {
+ imax = min(msg.string.maxlen, GM_MAX_INPUT);
+ strncpy(ibuf, msg.string.s, imax);
+ icur = x_strnlen(ibuf, imax);
+ } else {
+ memset(ibuf, 0, GM_MAX_INPUT);
+ imax = GM_MAX_INPUT;
+ icur = 0;
+ }
+ input = 1;
+ Y_enable_text_input();
+ msg.type = GM_BEGIN;
+ GM_send(m, cur, &msg);
+ }
+ Z_sound(msnd2, 128);
+ } else {
+ msg.type = GM_SELECT;
+ if (GM_send(m, cur, &msg)) {
+ Z_sound(msnd2, 128);
+ }
+ }
+ break;
}
- break;
+ }
}
}
lastkey = KEY_UNKNOWN;
if (down) {
lastkey = key;
if (!_2pl || cheat) {
- for (i = 0; i < 31; ++i) {
+ for (i = 0; i < 31; i++) {
cbuf[i] = cbuf[i + 1];
}
- //cbuf[31] = get_keychar(key);
+ if (key >= KEY_0 && key <= KEY_9) {
+ cbuf[31] = key - KEY_0 + '0';
+ } else if (key >= KEY_A && key <= KEY_Z) {
+ cbuf[31] = key - KEY_A + 'A';
+ } else {
+ cbuf[31] = 0;
+ }
}
}
}
msnd4 = Z_getsnd("SWTCHX");
msnd5 = Z_getsnd("SUDI");
msnd6 = Z_getsnd("TUDI");
- F_loadmus("MENU");
- S_startmusic(0);
+ MUS_load("MENU");
+ MUS_start(0);
}