diff --git a/src/console.c b/src/console.c index 50ecfec9c..2eb5b26c3 100644 --- a/src/console.c +++ b/src/console.c @@ -954,6 +954,9 @@ boolean CON_Responder(event_t *ev) if ((key == gamecontrol[GC_CONSOLE][0] || key == gamecontrol[GC_CONSOLE][1]) && !shiftdown) { + if (con_destlines == 0 && I_GetTextInputMode()) + return false; // some other component is holding keyboard input, don't hijack it! + I_SetTextInputMode(con_destlines == 0); // inverse, since this is changed next tic. consoletoggle = true; return true; diff --git a/src/g_game.c b/src/g_game.c index 1c186ae03..4e5c3e668 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -2270,6 +2270,11 @@ boolean G_LuaResponder(event_t *ev) cancelled = LUA_HookKey(ev, HOOK(KeyUp)); LUA_InvalidateUserdata(ev); } + else if (ev->type == ev_text) + { + cancelled = LUA_HookText(ev, HOOK(TextInput)); + LUA_InvalidateUserdata(ev); + } return cancelled; } diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 1ffa3968b..c253fa3b1 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -238,6 +238,7 @@ static const struct { {META_LUABANKS, "luabanks[]"}, {META_KEYEVENT, "keyevent_t"}, + {META_TEXTEVENT, "textevent_t"}, {META_MOUSE, "mouse_t"}, {NULL, NULL} }; diff --git a/src/lua_hook.h b/src/lua_hook.h index ce79cd1cb..326df3761 100644 --- a/src/lua_hook.h +++ b/src/lua_hook.h @@ -75,6 +75,7 @@ automatically. X (AddonLoaded),\ X (KeyDown),\ X (KeyUp),\ + X (TextInput),\ #define STRING_HOOK_LIST(X) \ X (BotAI),/* B_BuildTailsTiccmd by skin name */\ @@ -135,6 +136,7 @@ void LUA_HookBool(boolean value, int hook); int LUA_HookPlayer(player_t *, int hook); int LUA_HookTiccmd(player_t *, ticcmd_t *, int hook); int LUA_HookKey(event_t *event, int hook); // Hooks for key events +int LUA_HookText(event_t *event, int hook); // Hooks for text events void LUA_HookPreThinkFrame(void); void LUA_HookThinkFrame(void); diff --git a/src/lua_hooklib.c b/src/lua_hooklib.c index 1bf3caf65..a39745438 100644 --- a/src/lua_hooklib.c +++ b/src/lua_hooklib.c @@ -690,6 +690,17 @@ int LUA_HookKey(event_t *event, int hook_type) return hook.status; } +int LUA_HookText(event_t *event, int hook_type) +{ + Hook_State hook; + if (prepare_hook(&hook, false, hook_type)) + { + LUA_PushUserdata(gL, event, META_TEXTEVENT); + call_hooks(&hook, 1, res_true); + } + return hook.status; +} + void LUA_HookHUD(int hook_type, huddrawlist_h list) { Hook_State hook; diff --git a/src/lua_inputlib.c b/src/lua_inputlib.c index ef3a9011f..eb9fe7dc5 100644 --- a/src/lua_inputlib.c +++ b/src/lua_inputlib.c @@ -129,6 +129,18 @@ static int lib_getCursorPosition(lua_State *L) return 2; } +static int lib_setTextInputMode(lua_State *L) +{ + I_SetTextInputMode(luaL_checkboolean(L, 1)); + return 0; +} + +static int lib_getTextInputMode(lua_State *L) +{ + lua_pushinteger(L, I_GetTextInputMode()); + return 1; +} + static luaL_Reg lib[] = { {"gameControlDown", lib_gameControlDown}, {"gameControl2Down", lib_gameControl2Down}, @@ -143,6 +155,8 @@ static luaL_Reg lib[] = { {"getMouseGrab", lib_getMouseGrab}, {"setMouseGrab", lib_setMouseGrab}, {"getCursorPosition", lib_getCursorPosition}, + {"setTextInputMode", lib_setTextInputMode}, + {"getTextInputMode", lib_getTextInputMode}, {NULL, NULL} }; @@ -220,6 +234,28 @@ static int lib_lenGameKeyDown(lua_State *L) return 1; } +//////////////// +// TEXT EVENT // +//////////////// + +static int textevent_get(lua_State *L) +{ + event_t *event = *((event_t **)luaL_checkudata(L, 1, META_TEXTEVENT)); + const char *field = luaL_checkstring(L, 2); + + I_Assert(event != NULL); + + if (fastcmp(field,"text")) + { + char s[2] = { event->key, 0 }; + lua_pushstring(L, s); + } + else + return luaL_error(L, "textevent_t has no field named %s", field); + + return 1; +} + /////////////// // KEY EVENT // /////////////// @@ -285,6 +321,7 @@ static int mouse_num(lua_State *L) int LUA_InputLib(lua_State *L) { + LUA_RegisterUserdataMetatable(L, META_TEXTEVENT, textevent_get, NULL, NULL); LUA_RegisterUserdataMetatable(L, META_KEYEVENT, keyevent_get, NULL, NULL); LUA_RegisterUserdataMetatable(L, META_MOUSE, mouse_get, NULL, mouse_num); diff --git a/src/lua_libs.h b/src/lua_libs.h index e1585f488..592f46df5 100644 --- a/src/lua_libs.h +++ b/src/lua_libs.h @@ -93,6 +93,7 @@ extern boolean ignoregameinputs; #define META_LUABANKS "LUABANKS[]*" +#define META_TEXTEVENT "TEXTEVENT_T*" #define META_KEYEVENT "KEYEVENT_T*" #define META_MOUSE "MOUSE_T*" diff --git a/src/sdl/i_main.c b/src/sdl/i_main.c index b2177e563..f5fe9fb04 100644 --- a/src/sdl/i_main.c +++ b/src/sdl/i_main.c @@ -186,9 +186,6 @@ int main(int argc, char **argv) #endif #endif - // disable text input right off the bat, since we don't need it at the start. - I_SetTextInputMode(false); - #ifdef LOGMESSAGES if (!M_CheckParm("-nolog")) InitLogging(); diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 82583ccb4..2d1029ed0 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -1857,6 +1857,9 @@ void I_StartupGraphics(void) if (mousegrabok && !disable_mouse) SDLdoGrabMouse(); + // disable text input right off the bat, since we don't need it at the start. + I_SetTextInputMode(false); + graphics_started = true; }