[console] Get message modes and menus working again

I'm not at all happy with con_message and con_menu, but fixing them
properly will take a rework of the menus (planned, though). Also, the
Menu_ console command implementations are a bit iffy and could also do
with a rewrite (probably part of the rest of the menu rework) or just
nuking (they were part of Johnny on Flame's work, so I suspect had
something to do with joystick bindings).
This commit is contained in:
Bill Currie 2021-11-28 22:42:01 +09:00
parent 376e838d1c
commit b0447c1cf1
5 changed files with 116 additions and 130 deletions

View file

@ -64,6 +64,8 @@ typedef enum {
con_inactive, con_inactive,
con_active, con_active,
con_fullscreen, con_fullscreen,
con_message, //FIXME should not be here ?
con_menu, //FIXME should not be here ?
} con_state_t; } con_state_t;
extern int con_linewidth; extern int con_linewidth;
@ -121,7 +123,8 @@ void Menu_Init (void);
void Menu_Load (void); void Menu_Load (void);
void Menu_Draw (struct view_s *view); void Menu_Draw (struct view_s *view);
void Menu_Draw_Hud (struct view_s *view); void Menu_Draw_Hud (struct view_s *view);
int Menu_KeyEvent (knum_t key, short unicode, qboolean down); struct IE_event_s;
int Menu_EventHandler (const struct IE_event_s *ie_event);
void Menu_Enter (void); void Menu_Enter (void);
void Menu_Leave (void); void Menu_Leave (void);

View file

@ -123,21 +123,26 @@ ClearNotify (void)
static void static void
C_SetState (con_state_t state) C_SetState (con_state_t state)
{ {
con_state_t old_state = con_state;
con_state = state; con_state = state;
if (con_state == con_inactive) { if (con_state == con_inactive) {
IE_Set_Focus (con_saved_focos); IE_Set_Focus (con_saved_focos);
} else { } else if (old_state == con_inactive) {
con_saved_focos = IE_Get_Focus (); con_saved_focos = IE_Get_Focus ();
IE_Set_Focus (con_event_id); IE_Set_Focus (con_event_id);
} }
if (con_state == con_menu && old_state != con_menu) {
Menu_Enter ();
}
} }
static void static void
ToggleConsole_f (void) ToggleConsole_f (void)
{ {
Con_ClearTyping (input_line, 0);
switch (con_state) { switch (con_state) {
case con_menu:
case con_message:
return;
case con_inactive: case con_inactive:
C_SetState (con_active); C_SetState (con_active);
break; break;
@ -147,6 +152,8 @@ ToggleConsole_f (void)
case con_fullscreen: case con_fullscreen:
break; break;
} }
Con_ClearTyping (input_line, 0);
ClearNotify (); ClearNotify ();
} }
@ -163,19 +170,19 @@ Clear_f (void)
static void static void
MessageMode_f (void) MessageMode_f (void)
{ {
if (con_data.force_commandline) if (con_state != con_inactive)
return; return;
chat_team = false; chat_team = false;
//Key_SetKeyDest (key_message); C_SetState (con_message);
} }
static void static void
MessageMode2_f (void) MessageMode2_f (void)
{ {
if (con_data.force_commandline) if (con_state != con_inactive)
return; return;
chat_team = true; chat_team = true;
//Key_SetKeyDest (key_message); C_SetState (con_message);
} }
static void static void
@ -322,30 +329,36 @@ cl_conmode_f (cvar_t *var)
} }
} }
static void
con_end_message (inputline_t *line)
{
Con_ClearTyping (line, 1);
C_SetState (con_inactive);
}
static void static void
C_Say (inputline_t *il) C_Say (inputline_t *il)
{ {
const char *line = il->line; const char *line = il->line;
if (!*line) if (*line) {
return; Cbuf_AddText (con_data.cbuf, "say \"");
Cbuf_AddText (con_data.cbuf, line);
Cbuf_AddText (con_data.cbuf, "say \""); Cbuf_AddText (con_data.cbuf, "\"\n");
Cbuf_AddText (con_data.cbuf, line); }
Cbuf_AddText (con_data.cbuf, "\"\n"); con_end_message (il);
//Key_SetKeyDest (key_game);
} }
static void static void
C_SayTeam (inputline_t *il) C_SayTeam (inputline_t *il)
{ {
const char *line = il->line; const char *line = il->line;
if (!*line)
return;
Cbuf_AddText (con_data.cbuf, "say_team \""); if (*line) {
Cbuf_AddText (con_data.cbuf, line); Cbuf_AddText (con_data.cbuf, "say_team \"");
Cbuf_AddText (con_data.cbuf, "\"\n"); Cbuf_AddText (con_data.cbuf, line);
//Key_SetKeyDest (key_game); Cbuf_AddText (con_data.cbuf, "\"\n");
}
con_end_message (il);
} }
static void static void
@ -480,7 +493,7 @@ C_DrawInputLine (inputline_t *il)
static void static void
draw_input (view_t *view) draw_input (view_t *view)
{ {
if (con_state == con_inactive)// && !con_data.force_commandline) if (con_state == con_inactive)
return; return;
DrawInputLine (view->xabs + 8, view->yabs, 1, input_line); DrawInputLine (view->xabs + 8, view->yabs, 1, input_line);
@ -634,6 +647,8 @@ setup_console (void)
float lines = 0; float lines = 0;
switch (con_state) { switch (con_state) {
case con_message:
case con_menu:
case con_inactive: case con_inactive:
lines = 0; lines = 0;
break; break;
@ -669,9 +684,9 @@ C_DrawConsole (void)
if (console_view->ylen != con_data.lines) if (console_view->ylen != con_data.lines)
view_resize (console_view, console_view->xlen, con_data.lines); view_resize (console_view, console_view->xlen, con_data.lines);
say_view->visible = 0;//FIXME say_view->visible = con_state == con_message;
console_view->visible = con_data.lines != 0; console_view->visible = con_data.lines != 0;
menu_view->visible = 0;//FIXME menu_view->visible = con_state == con_menu;
con_data.view->draw (con_data.view); con_data.view->draw (con_data.view);
} }
@ -710,54 +725,6 @@ exec_line (inputline_t *il)
{ {
Con_ExecLine (il->line); Con_ExecLine (il->line);
} }
#if 0
static void
con_end_message (void *line)
{
//Key_PopEscape ();
Con_ClearTyping (line, 1);
//Key_SetKeyDest (key_game);
}
static void
con_leave_console (void *data)
{
ToggleConsole_f ();
}
static void
con_keydest_callback (keydest_t kd, void *data)
{
if (kd == key_unfocused || kd == con_curr_keydest) {
return;
}
if (kd != key_console && con_curr_keydest == key_console) {
//Key_PopEscape ();
}
switch (kd) {
case key_last:
case key_game:
case key_demo:
case key_unfocused:
case key_menu:
break;
case key_message:
//Key_PushEscape (con_end_message,
// chat_team ? say_team_line : say_line);
break;
case key_console:
//Key_PushEscape (con_leave_console, 0);
break;
}
con_curr_keydest = kd;
}
static void
con_enter_menu (void *data)
{
Menu_Enter ();
}
#endif
static void static void
con_key_event (const IE_event_t *event) con_key_event (const IE_event_t *event)
@ -778,15 +745,17 @@ con_key_event (const IE_event_t *event)
} }
} }
#endif #endif
#if 0 if (con_state == con_message) {
if (con_curr_keydest == key_message) {
if (chat_team) { if (chat_team) {
il = say_team_line; il = say_team_line;
} else { } else {
il = say_line; il = say_line;
} }
if (key->code == QFK_ESCAPE) {
con_end_message (il);
return;
}
} else { } else {
#endif
switch (key->code) { switch (key->code) {
case QFK_ESCAPE: case QFK_ESCAPE:
ToggleConsole_f (); ToggleConsole_f ();
@ -823,18 +792,8 @@ con_key_event (const IE_event_t *event)
break; break;
} }
il = input_line; il = input_line;
#if 0
} }
#endif
#if 0
//FIXME should this translation be here?
if ((unicode==0x0A) && (key==QFK_RETURN)) {
Con_ProcessInputLine (il, key);
}
if ((unicode==0x7F) && (key==QFK_BACKSPACE)) {
Con_ProcessInputLine (il, key);
}
#endif
if (key->unicode) { if (key->unicode) {
Con_ProcessInputLine (il, key->code >= 256 ? (int) key->code Con_ProcessInputLine (il, key->code >= 256 ? (int) key->code
: key->unicode); : key->unicode);
@ -851,6 +810,9 @@ con_mouse_event (const IE_event_t *event)
static int static int
con_event_handler (const IE_event_t *ie_event, void *data) con_event_handler (const IE_event_t *ie_event, void *data)
{ {
if (con_state == con_menu) {
return Menu_EventHandler (ie_event);
}
static void (*handlers[ie_event_count]) (const IE_event_t *ie_event) = { static void (*handlers[ie_event_count]) (const IE_event_t *ie_event) = {
[ie_key] = con_key_event, [ie_key] = con_key_event,
[ie_mouse] = con_mouse_event, [ie_mouse] = con_mouse_event,
@ -874,11 +836,6 @@ C_Init (void)
con_event_id = IE_Add_Handler (con_event_handler, 0); con_event_id = IE_Add_Handler (con_event_handler, 0);
//Key_PushEscape (con_enter_menu, 0);
//Key_KeydestCallback (con_keydest_callback, 0);
//Key_SetKeyEvent (key_message, C_KeyEvent, 0);
//Key_SetKeyEvent (key_menu, C_KeyEvent, 0);
//Key_SetKeyEvent (key_console, C_KeyEvent, 0);
Menu_Init (); Menu_Init ();
con_notifytime = Cvar_Get ("con_notifytime", "3", CVAR_NONE, NULL, con_notifytime = Cvar_Get ("con_notifytime", "3", CVAR_NONE, NULL,

View file

@ -47,6 +47,7 @@
#include "QF/sound.h" #include "QF/sound.h"
#include "QF/sys.h" #include "QF/sys.h"
#include "QF/input/event.h"
#include "QF/ui/view.h" #include "QF/ui/view.h"
#include "QF/plugin/console.h" #include "QF/plugin/console.h"
@ -358,13 +359,7 @@ bi_Menu_TopMenu (progs_t *pr)
free ((char *) top_menu); free ((char *) top_menu);
top_menu = strdup (name); top_menu = strdup (name);
} }
/*
static void
menu_leave (void *data)
{
Menu_Leave ();
}
*/
static void static void
bi_Menu_SelectMenu (progs_t *pr) bi_Menu_SelectMenu (progs_t *pr)
{ {
@ -374,11 +369,7 @@ bi_Menu_SelectMenu (progs_t *pr)
if (name && *name) if (name && *name)
menu = Hash_Find (menu_hash, name); menu = Hash_Find (menu_hash, name);
if (menu) { if (menu) {
/*if (Key_GetKeyDest () != key_menu) { Con_SetState (con_menu);
menu_keydest = Key_GetKeyDest ();
Key_PushEscape (menu_leave, 0);
Key_SetKeyDest (key_menu);
}*/
if (menu->enter_hook) { if (menu->enter_hook) {
run_menu_pre (); run_menu_pre ();
PR_ExecuteProgram (&menu_pr_state, menu->enter_hook); PR_ExecuteProgram (&menu_pr_state, menu->enter_hook);
@ -387,8 +378,7 @@ bi_Menu_SelectMenu (progs_t *pr)
} else { } else {
if (name && *name) if (name && *name)
Sys_Printf ("no menu \"%s\"\n", name); Sys_Printf ("no menu \"%s\"\n", name);
//Key_PopEscape (); Con_SetState (con_inactive);
//Key_SetKeyDest (menu_keydest);
} }
} }
@ -473,8 +463,7 @@ bi_Menu_Leave (progs_t *pr)
} }
menu = menu->parent; menu = menu->parent;
if (!menu) { if (!menu) {
//Key_PopEscape (); Con_SetState (con_inactive);
//Key_SetKeyDest (menu_keydest);
} }
} }
} }
@ -550,7 +539,19 @@ static builtin_t builtins[] = {
{0}, {0},
}; };
static int//FIXME reimplement users properly (or remove?)
Menu_KeyEvent (int key, int unicode, int pressed)
{
IE_event_t event = {
.type = ie_key,
.when = Sys_LongTime (),
.key = {
.code = key,
.unicode = unicode,
}
};
return IE_Send_Event (&event);
}
void void
Menu_Enter_f (void) Menu_Enter_f (void)
@ -734,20 +735,21 @@ Menu_Draw_Hud (view_t *view)
run_menu_post (); run_menu_post ();
} }
int static int
Menu_KeyEvent (knum_t key, short unicode, qboolean down) menu_key_event (const IE_event_t *ie_event)
{ {
menu_item_t *item; menu_item_t *item;
int ret; int ret;
__auto_type key = ie_event->key;
if (!menu) if (!menu)
return 0; return 0;
if (menu->keyevent) { if (menu->keyevent) {
run_menu_pre (); run_menu_pre ();
PR_RESET_PARAMS (&menu_pr_state); PR_RESET_PARAMS (&menu_pr_state);
P_INT (&menu_pr_state, 0) = key; P_INT (&menu_pr_state, 0) = key.code;
P_INT (&menu_pr_state, 1) = unicode; P_INT (&menu_pr_state, 1) = key.unicode;
P_INT (&menu_pr_state, 2) = down; P_INT (&menu_pr_state, 2) = 1; //FIXME only presses now
menu_pr_state.pr_argc = 3; menu_pr_state.pr_argc = 3;
PR_ExecuteProgram (&menu_pr_state, menu->keyevent); PR_ExecuteProgram (&menu_pr_state, menu->keyevent);
ret = R_INT (&menu_pr_state); ret = R_INT (&menu_pr_state);
@ -762,7 +764,7 @@ Menu_KeyEvent (knum_t key, short unicode, qboolean down)
PR_RESET_PARAMS (&menu_pr_state); PR_RESET_PARAMS (&menu_pr_state);
P_STRING (&menu_pr_state, 0) = PR_SetTempString (&menu_pr_state, P_STRING (&menu_pr_state, 0) = PR_SetTempString (&menu_pr_state,
item->text); item->text);
P_INT (&menu_pr_state, 1) = key; P_INT (&menu_pr_state, 1) = key.code;
menu_pr_state.pr_argc = 2; menu_pr_state.pr_argc = 2;
PR_ExecuteProgram (&menu_pr_state, item->func); PR_ExecuteProgram (&menu_pr_state, item->func);
PR_PopFrame (&menu_pr_state); PR_PopFrame (&menu_pr_state);
@ -771,38 +773,65 @@ Menu_KeyEvent (knum_t key, short unicode, qboolean down)
if (ret) if (ret)
return 1; return 1;
} }
if (key.code == QFK_ESCAPE) {
Menu_Leave ();
return 1;
}
if (!menu || !menu->items) if (!menu || !menu->items)
return 0; return 0;
switch (key) { switch (key.code) {
case QFK_ESCAPE:
break;
case QFK_DOWN: case QFK_DOWN:
// case QFM_WHEEL_DOWN: // case QFM_WHEEL_DOWN:
bi_Menu_Next (&menu_pr_state); bi_Menu_Next (&menu_pr_state);
return 1; break;
case QFK_UP: case QFK_UP:
// case QFM_WHEEL_UP: // case QFM_WHEEL_UP:
bi_Menu_Prev (&menu_pr_state); bi_Menu_Prev (&menu_pr_state);
return 1; break;
case QFK_RETURN: case QFK_RETURN:
// case QFM_BUTTON1: // case QFM_BUTTON1:
bi_Menu_Enter (&menu_pr_state); bi_Menu_Enter (&menu_pr_state);
return 1; break;
default: default:
return 0; break;
} }
return 1;
}
static int
menu_mouse_event (const IE_event_t *ie_event)
{
return 0;
}
int
Menu_EventHandler (const IE_event_t *ie_event)
{
static int (*handlers[ie_event_count]) (const IE_event_t *ie_event) = {
[ie_key] = menu_key_event,
[ie_mouse] = menu_mouse_event,
};
if (ie_event->type < 0 || ie_event->type >= ie_event_count
|| !handlers[ie_event->type]) {
return 0;
}
return handlers[ie_event->type] (ie_event);
} }
void void
Menu_Enter () Menu_Enter ()
{ {
if (!top_menu) { if (!top_menu) {
//Key_SetKeyDest (key_console); Con_SetState (con_active);
return; return;
} }
menu = Hash_Find (menu_hash, top_menu); if (!menu) {
menu = Hash_Find (menu_hash, top_menu);
}
if (menu) { if (menu) {
//menu_keydest = Key_GetKeyDest (); Con_SetState (con_menu);
//Key_PushEscape (menu_leave, 0);
//Key_SetKeyDest (key_menu);
if (menu->enter_hook) { if (menu->enter_hook) {
run_menu_pre (); run_menu_pre ();
PR_ExecuteProgram (&menu_pr_state, menu->enter_hook); PR_ExecuteProgram (&menu_pr_state, menu->enter_hook);
@ -822,8 +851,7 @@ Menu_Leave ()
} }
menu = menu->parent; menu = menu->parent;
if (!menu) { if (!menu) {
//Key_PopEscape (); Con_SetState (con_inactive);
//Key_SetKeyDest (menu_keydest);
} }
} }
r_data->vid->recalc_refdef = true; r_data->vid->recalc_refdef = true;

View file

@ -409,8 +409,7 @@ cl_event_handler (const IE_event_t *ie_event, void *unused)
{ {
if (ie_event->type == ie_key) { if (ie_event->type == ie_key) {
if (ie_event->key.code == QFK_ESCAPE) { if (ie_event->key.code == QFK_ESCAPE) {
// FIXME this should bring up the menu Con_SetState (con_menu);
Con_SetState (con_active);
return 1; return 1;
} }
} }

View file

@ -566,8 +566,7 @@ cl_event_handler (const IE_event_t *ie_event, void *unused)
{ {
if (ie_event->type == ie_key) { if (ie_event->type == ie_key) {
if (ie_event->key.code == QFK_ESCAPE) { if (ie_event->key.code == QFK_ESCAPE) {
// FIXME this should bring up the menu Con_SetState (con_menu);
Con_SetState (con_active);
return 1; return 1;
} }
} }