diff --git a/.gitignore b/.gitignore index 408f951..e6dda43 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ .DS_Store Thumbs.db /.github +/.editor_settings \ No newline at end of file diff --git a/steam/src/steam.cpp b/steam/src/steam.cpp index da625e0..c43b1a6 100644 --- a/steam/src/steam.cpp +++ b/steam/src/steam.cpp @@ -178,6 +178,8 @@ static const luaL_reg Module_methods[] = { { "utils_get_image_size", SteamUtils_GetImageSize }, { "utils_get_image_rgba", SteamUtils_GetImageRGBA }, { "utils_get_server_real_time", SteamUtils_GetServerRealTime }, + { "utils_show_floating_gamepad_text_input", SteamUtils_ShowFloatingGamepadTextInput }, + { "utils_show_gamepad_text_input", SteamUtils_ShowGamepadTextInput }, // USERSTATS - stats @@ -245,6 +247,46 @@ static void LuaInit(lua_State* L) lua_pushnumber(L, (lua_Number) val); \ lua_setfield(L, -2, #name); + // + // EFloatingGamepadTextInputMode + // + /** + * Enter dismisses the keyboard + * @field EFloatingGamepadTextInputModeModeSingleLine + */ + SETCONSTANT(EFloatingGamepadTextInputModeModeSingleLine, k_EFloatingGamepadTextInputModeModeSingleLine); + /** + * User needs to explicitly dismiss the keyboard + * @field EFloatingGamepadTextInputModeModeMultipleLines + */ + SETCONSTANT(EFloatingGamepadTextInputModeModeMultipleLines, k_EFloatingGamepadTextInputModeModeMultipleLines); + /** + * Keyboard is displayed in a special mode that makes it easier to enter emails + * @field EFloatingGamepadTextInputModeModeEmail + */ + SETCONSTANT(EFloatingGamepadTextInputModeModeEmail, k_EFloatingGamepadTextInputModeModeEmail); + /** + * Numeric keypad is shown + * @field EFloatingGamepadTextInputModeModeNumeric + */ + SETCONSTANT(EFloatingGamepadTextInputModeModeNumeric, k_EFloatingGamepadTextInputModeModeNumeric); + + + // + // EGamepadTextInputMode + // + /** + * Normal text input + * @field EGamepadTextInputModeNormal + */ + SETCONSTANT(EGamepadTextInputModeNormal, k_EGamepadTextInputModeNormal); + /** + * Password text input + * @field EGamepadTextInputModePassword + */ + SETCONSTANT(EGamepadTextInputModePassword, k_EGamepadTextInputModePassword); + + // // ELeaderboardDataRequest // diff --git a/steam/src/steam_utils.cpp b/steam/src/steam_utils.cpp index 8895aba..7b448ba 100644 --- a/steam/src/steam_utils.cpp +++ b/steam/src/steam_utils.cpp @@ -2,6 +2,72 @@ #include #include "steam_api.h" +#include "steam_listener.h" + +const uint32 MAX_INPUT_LENGTH = 1024; +const uint32 FOO = MAX_INPUT_LENGTH + 1; + + +int SteamUtils_OnFloatingGamepadTextInputDismissed(lua_State* L, void* data) +{ + FloatingGamepadTextInputDismissed_t* s = (FloatingGamepadTextInputDismissed_t*)data; + lua_pushstring(L, "FloatingGamepadTextInputDismissed_t"); + return 1; +} + +int SteamUtils_OnGamepadTextInputDismissed(lua_State* L, void* data) +{ + GamepadTextInputDismissed_t* s = (GamepadTextInputDismissed_t*)data; + // The user canceled, + if (!s->m_bSubmitted) { + lua_pushnil(L); + return 1; + } + + const uint32 length = SteamUtils()->GetEnteredGamepadTextLength(); + char* szTextInput = (char*)malloc(length); + bool success = SteamUtils()->GetEnteredGamepadTextInput( szTextInput, length ); + + if ( !success ) { + // Log an error. This should only ever happen if length is > MaxInputLength + free(szTextInput); + lua_pushnil(L); + return 1; + } + + lua_pushstring(L, "GamepadTextInputDismissed_t"); + + lua_newtable(L); + lua_pushstring(L, "m_szTextInput"); + lua_pushstring(L, szTextInput); + lua_settable(L, -3); + + free(szTextInput); + return 2; +} + +class SteamUtilsCallbacks +{ + public: + SteamUtilsCallbacks(); + STEAM_CALLBACK(SteamUtilsCallbacks, OnGamepadTextInputDismissed, GamepadTextInputDismissed_t, m_CallbackGamepadTextInputDismissed); + STEAM_CALLBACK(SteamUtilsCallbacks, OnFloatingGamepadTextInputDismissed, FloatingGamepadTextInputDismissed_t, m_CallbackFloatingGamepadTextInputDismissed); +}; +SteamUtilsCallbacks::SteamUtilsCallbacks() : + m_CallbackGamepadTextInputDismissed(this, &SteamUtilsCallbacks::OnGamepadTextInputDismissed), + m_CallbackFloatingGamepadTextInputDismissed(this, &SteamUtilsCallbacks::OnFloatingGamepadTextInputDismissed) +{} +void SteamUtilsCallbacks::OnGamepadTextInputDismissed(GamepadTextInputDismissed_t *s) +{ + SteamListener_Invoke(SteamUtils_OnGamepadTextInputDismissed, s); +} +void SteamUtilsCallbacks::OnFloatingGamepadTextInputDismissed(FloatingGamepadTextInputDismissed_t *s) +{ + SteamListener_Invoke(SteamUtils_OnFloatingGamepadTextInputDismissed, s); +} + + +static SteamUtilsCallbacks* g_SteamUtilsCallbacks = new SteamUtilsCallbacks(); static ISteamUtils* g_SteamUtils = 0; @@ -139,4 +205,55 @@ int SteamUtils_GetServerRealTime(lua_State* L) } + +/** Opens a floating keyboard over the game content and sends OS keyboard keys directly to the game. + * @name utils_show_floating_gamepad_text_input + * @number mode EFloatingGamepadTextInputMode + * @number x Text field x position + * @number y Text field y position + * @number width Text field width + * @number height Text field height + * @treturn bool result True if the floating keyboard was shown, otherwise, false. + */ +int SteamUtils_ShowFloatingGamepadTextInput(lua_State* L) +{ + if (!g_SteamUtils) return 0; + DM_LUA_STACK_CHECK(L, 1); + + EFloatingGamepadTextInputMode eKeyboardMode = (EFloatingGamepadTextInputMode)luaL_checknumber(L, 1); + int nTextFieldXPosition = luaL_checknumber(L, 2); + int nTextFieldYPosition = luaL_checknumber(L, 3); + int nTextFieldWidth = luaL_checknumber(L, 4); + int nTextFieldHeight = luaL_checknumber(L, 5); + + bool was_shown = g_SteamUtils->ShowFloatingGamepadTextInput(eKeyboardMode, nTextFieldXPosition, nTextFieldYPosition, nTextFieldWidth, nTextFieldHeight); + lua_pushboolean(L, was_shown); + return 1; +} + + +/** Activates the Big Picture text input dialog which only supports gamepad input. + * @name utils_show_gamepad_text_input + * @number input_mode EGamepadTextInputMode + * @number line_input_mode EGamepadTextInputLineMode + * @string description Sets the description that should inform the user what the input dialog is for + * @string existing_text Sets the preexisting text which the user can edit. + * @treturn bool result True if the big picture overlay is running; otherwise, false + */ +int SteamUtils_ShowGamepadTextInput(lua_State* L) +{ + if (!g_SteamUtils) return 0; + DM_LUA_STACK_CHECK(L, 1); + + EGamepadTextInputMode eInputMode = (EGamepadTextInputMode)luaL_checknumber(L, 1); + EGamepadTextInputLineMode eLineInputMode = (EGamepadTextInputLineMode)luaL_checknumber(L, 2); + const char *pchDescription = luaL_checkstring(L, 3); + uint32 unCharMax = MAX_INPUT_LENGTH; + const char *pchExistingText = luaL_checkstring(L, 4); + + bool big_picture = g_SteamUtils->ShowGamepadTextInput(eInputMode, eLineInputMode, pchDescription, unCharMax, pchExistingText); + lua_pushboolean(L, big_picture); + return 1; +} + #endif \ No newline at end of file diff --git a/steam/src/steam_utils.h b/steam/src/steam_utils.h index 956c88a..3d90e8d 100644 --- a/steam/src/steam_utils.h +++ b/steam/src/steam_utils.h @@ -5,6 +5,9 @@ #include +int SteamUtils_OnGamepadTextInputDismissed(lua_State* L, void* data); +int SteamUtils_OnFloatingGamepadTextInputDismissed(lua_State* L, void* data); + int SteamUtils_Init(lua_State* L); int SteamUtils_GetAppId(lua_State* L); int SteamUtils_GetSecondsSinceAppActive(lua_State* L); @@ -12,6 +15,8 @@ int SteamUtils_IsSteamRunningOnSteamDeck(lua_State* L); int SteamUtils_GetImageSize(lua_State* L); int SteamUtils_GetImageRGBA(lua_State* L); int SteamUtils_GetServerRealTime(lua_State* L); +int SteamUtils_ShowFloatingGamepadTextInput(lua_State* L); +int SteamUtils_ShowGamepadTextInput(lua_State* L); #endif