the main menu page now displays and can be entered/left. K_ESCAPE is now

handled exclusively by the console.
This commit is contained in:
Bill Currie 2002-01-18 23:45:28 +00:00
parent 10acad1ee4
commit fcc9cbf3b7
5 changed files with 91 additions and 25 deletions

View file

@ -33,7 +33,7 @@ void (string text, integer key) quit =
void () main_menu =
{
Menu_Begin (0, 0, "");
Menu_Begin (0, 0, "main");
Menu_Pic (16, 4, "gfx/qplaque.lmp");
Menu_CenterPic (160, 4, "gfx/ttl_main.lmp");
Menu_Pic (71,32, "gfx/mainmenu.lmp");

View file

@ -133,5 +133,7 @@ void Menu_Init (void);
void Menu_Load (void);
void Menu_Draw (void);
void Menu_KeyEvent (knum_t key, short unicode, qboolean down);
void Menu_Enter (void);
void Menu_Leave (void);
#endif // __console_h

View file

@ -469,12 +469,34 @@ C_KeyEvent (knum_t key, short unicode, qboolean down)
if (!down)
return;
if (key_dest == key_message) {
if (key == QFK_ESCAPE) {
if (down && (key == QFK_ESCAPE || unicode == '\x1b')) {
switch (key_dest) {
case key_menu:
Menu_Leave ();
return;
case key_message:
key_dest = key_game;
game_target = IMT_0;
return;
case key_console:
if (!con_data.force_commandline) {
Cbuf_AddText ("toggleconsole\n");
return;
}
case key_game:
Menu_Enter ();
return;
default:
Sys_Error ("Bad key_dest");
}
}
if (key_dest == key_menu) {
Menu_KeyEvent (key, unicode, down);
return;
}
if (key_dest == key_message) {
if (chat_team) {
il = say_team_line;
} else {
@ -700,9 +722,9 @@ C_DrawConsole (int lines)
} else {
if (key_dest == key_game || key_dest == key_message)
DrawNotify (); // only draw notify in game
else if (key_dest == key_menu)
Menu_Draw ();
}
if (key_dest == key_menu)
Menu_Draw ();
}
static void

View file

@ -34,6 +34,7 @@ static const char rcsid[] =
#include <string.h>
#include "QF/console.h"
#include "QF/draw.h"
#include "QF/hash.h"
#include "QF/plugin.h"
#include "QF/progs.h"
@ -64,6 +65,7 @@ static hashtab_t *menu_hash;
static func_t menu_init;
static func_t menu_keyevent;
static func_t menu_draw;
static const char *top_menu;
static int
menu_resolve_globals (void)
@ -138,6 +140,8 @@ bi_Menu_Begin (progs_t *pr)
m->text = strdup (text);
if (menu)
menu_add_item (menu, m);
else
top_menu = m->text;
menu = m;
Hash_Add (menu_hash, m);
}
@ -233,6 +237,7 @@ Menu_Load (void)
}
Hash_FlushTable (menu_hash);
menu = 0;
top_menu = 0;
if ((size = COM_FOpenFile (menu_pr_state.progs_name, &file)) != -1) {
menu_pr_state.progs = malloc (size + 256 * 1024);
@ -266,8 +271,31 @@ Menu_Load (void)
void
Menu_Draw (void)
{
menu_pic_t *m_pic;
int i;
if (!menu)
return;
for (m_pic = menu->pics; m_pic; m_pic = m_pic->next) {
qpic_t *pic = Draw_CachePic (m_pic->name, 1);
if (!pic)
continue;
Draw_Pic (m_pic->x, m_pic->y, pic);
}
for (i = 0; i < menu->num_items; i++) {
if (menu->items[i]->text) {
Draw_String (menu->items[i]->x, menu->items[i]->y,
menu->items[i]->text);
}
}
if (menu->cursor) {
G_INT (&menu_pr_state, OFS_PARM0) = 0;
G_INT (&menu_pr_state, OFS_PARM1) = 0;
PR_ExecuteProgram (&menu_pr_state, menu->cursor);
}
if (menu_draw) {
PR_ExecuteProgram (&menu_pr_state, menu_draw);
}
}
void
@ -276,3 +304,28 @@ Menu_KeyEvent (knum_t key, short unicode, qboolean down)
if (!menu)
return;
}
void
Menu_Enter ()
{
if (!top_menu) {
key_dest = key_console;
game_target = IMT_CONSOLE;
return;
}
key_dest = key_menu;
game_target = IMT_CONSOLE;
menu = Hash_Find (menu_hash, top_menu);
}
void
Menu_Leave ()
{
if (menu) {
menu = menu->parent;
if (!menu) {
key_dest = key_game;
game_target = IMT_0;
}
}
}

View file

@ -420,7 +420,9 @@ Key_Game (knum_t key, short unicode)
void
Key_Console (knum_t key, short unicode)
{
if (keydown[key] == 1 && Key_Game (key, unicode))
// escape is un-bindable
if (keydown[key] == 1 && key != QFK_ESCAPE && unicode != '\x1b'
&& Key_Game (key, unicode))
return;
Con_KeyEvent (key, unicode, keydown[key]);
@ -727,19 +729,7 @@ Key_Event (knum_t key, short unicode, qboolean down)
// handle escape specially, so the user can never unbind it
if (unicode == '\x1b' || key == QFK_ESCAPE) {
if (!down || (keydown[key] > 1))
return;
switch (key_dest) {
case key_message:
Key_Console (key, unicode);
break;
case key_game:
case key_console:
Cbuf_AddText ("toggleconsole\n");
break;
default:
Sys_Error ("Bad key_dest");
}
return;
}
@ -748,12 +738,11 @@ Key_Event (knum_t key, short unicode, qboolean down)
// if not a consolekey, send to the interpreter no matter what mode is
switch (key_dest) {
case key_message:
Key_Console (key, unicode);
break;
case key_game:
Key_Game (key, unicode);
break;
case key_message:
case key_menu:
case key_console:
Key_Console (key, unicode);
break;