mirror of
https://github.com/luanti-org/luanti.git
synced 2025-12-31 18:35:20 +01:00
Show proper default key name in reset tooltip on keybindings menu (#16777)
* implement 'core.scancode_to_keyname()' and use it to fix something * fix whitespaces and fix another thing * ._. * lol * rename to get_key_description * add case for keybindings whose defaults are not bound * apply y5nw's suggestions * lmao I'm so dumb
This commit is contained in:
@@ -616,6 +616,14 @@ local function get_formspec(dialogdata)
|
||||
|
||||
if show_reset then
|
||||
local default = comp.setting.default
|
||||
if comp.setting.type == "key" then
|
||||
default = (default ~= "")
|
||||
and core.get_key_description(default)
|
||||
|
||||
--~ Indicates that the action does not have a corresponding keybinding.
|
||||
or fgettext_ne("Not bound")
|
||||
end
|
||||
|
||||
local reset_tooltip = default and
|
||||
fgettext("Reset setting to default ($1)", tostring(default)) or
|
||||
fgettext("Reset setting to default")
|
||||
|
||||
@@ -52,6 +52,16 @@ int ModApiMenuCommon::l_normalize_keycode(lua_State *L)
|
||||
}
|
||||
|
||||
|
||||
int ModApiMenuCommon::l_get_key_description(lua_State *L)
|
||||
{
|
||||
const char *keystr = luaL_checkstring(L, 1);
|
||||
KeyPress kp(keystr);
|
||||
std::string name = kp.name();
|
||||
lua_pushstring(L, name.c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
void ModApiMenuCommon::Initialize(lua_State *L, int top)
|
||||
{
|
||||
API_FCT(gettext);
|
||||
@@ -59,6 +69,7 @@ void ModApiMenuCommon::Initialize(lua_State *L, int top)
|
||||
API_FCT(driver_supports_shadows);
|
||||
API_FCT(irrlicht_device_supports_touch);
|
||||
API_FCT(normalize_keycode);
|
||||
API_FCT(get_key_description);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ private:
|
||||
static int l_driver_supports_shadows(lua_State *L);
|
||||
static int l_irrlicht_device_supports_touch(lua_State *L);
|
||||
static int l_normalize_keycode(lua_State *L);
|
||||
static int l_get_key_description(lua_State *L);
|
||||
|
||||
public:
|
||||
static void Initialize(lua_State *L, int top);
|
||||
|
||||
Reference in New Issue
Block a user