mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
show key name in keybinding form
This commit is contained in:
parent
77142181f2
commit
5a8bae5fff
3 changed files with 11 additions and 1 deletions
|
@ -24,7 +24,7 @@ local function get_formspec(dialogdata)
|
|||
|
||||
local cells = {}
|
||||
for _, key in ipairs(value) do
|
||||
table.insert(cells, core.formspec_escape(key))
|
||||
table.insert(cells, core.formspec_escape(core.get_keycode_name(key)))
|
||||
end
|
||||
table.insert(fs, ("textlist[0.5,1.3;5,4;keylist;%s;%d;false]"):format(table.concat(cells, ","), selection))
|
||||
|
||||
|
|
|
@ -42,6 +42,14 @@ int ModApiMenuCommon::l_normalize_keycode(lua_State *L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
int ModApiMenuCommon::l_get_keycode_name(lua_State *L)
|
||||
{
|
||||
auto keystr = luaL_checkstring(L, 1);
|
||||
auto name = KeyPress(keystr).name();
|
||||
lua_pushstring(L, name.empty() ? "" : gettext(name.c_str()));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
void ModApiMenuCommon::Initialize(lua_State *L, int top)
|
||||
{
|
||||
|
@ -49,6 +57,7 @@ void ModApiMenuCommon::Initialize(lua_State *L, int top)
|
|||
API_FCT(get_active_driver);
|
||||
API_FCT(irrlicht_device_supports_touch);
|
||||
API_FCT(normalize_keycode);
|
||||
API_FCT(get_keycode_name);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ private:
|
|||
static int l_get_active_driver(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_keycode_name(lua_State *L);
|
||||
|
||||
public:
|
||||
static void Initialize(lua_State *L, int top);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue