mirror of
https://github.com/minetest/minetest.git
synced 2024-12-23 22:52:25 +01:00
Fix Enter key after creating a new world (#12997)
Prevents Enter key or "double-click" event to play the world just after creating a new world
This commit is contained in:
parent
2f9f0c0900
commit
a2a280691c
@ -352,6 +352,12 @@ local function create_world_buttonhandler(this, fields)
|
||||
if fields["world_create_confirm"] or
|
||||
fields["key_enter"] then
|
||||
|
||||
if fields["key_enter"] then
|
||||
-- HACK: This timestamp prevents double-triggering when pressing Enter on an input box
|
||||
-- and releasing it on a button[] or textlist[] due to instant formspec updates.
|
||||
this.parent.dlg_create_world_closed_at = core.get_us_time()
|
||||
end
|
||||
|
||||
local worldname = fields["te_world_name"]
|
||||
local game, _ = pkgmgr.find_by_gameid(core.settings:get("menu_last_game"))
|
||||
|
||||
|
@ -215,6 +215,10 @@ local function main_button_handler(this, fields, name, tabdata)
|
||||
|
||||
assert(name == "local")
|
||||
|
||||
if this.dlg_create_world_closed_at == nil then
|
||||
this.dlg_create_world_closed_at = 0
|
||||
end
|
||||
|
||||
local world_doubleclick = false
|
||||
|
||||
if fields["sp_worlds"] ~= nil then
|
||||
@ -269,6 +273,12 @@ local function main_button_handler(this, fields, name, tabdata)
|
||||
end
|
||||
|
||||
if fields["play"] ~= nil or world_doubleclick or fields["key_enter"] then
|
||||
local enter_key_duration = core.get_us_time() - this.dlg_create_world_closed_at
|
||||
if world_doubleclick and enter_key_duration <= 200000 then -- 200 ms
|
||||
this.dlg_create_world_closed_at = 0
|
||||
return true
|
||||
end
|
||||
|
||||
local selected = core.get_textlist_index("sp_worlds")
|
||||
gamedata.selected_world = menudata.worldlist:get_raw_index(selected)
|
||||
|
||||
@ -316,6 +326,7 @@ local function main_button_handler(this, fields, name, tabdata)
|
||||
end
|
||||
|
||||
if fields["world_create"] ~= nil then
|
||||
this.dlg_create_world_closed_at = 0
|
||||
local create_world_dlg = create_create_world_dlg()
|
||||
create_world_dlg:set_parent(this)
|
||||
this:hide()
|
||||
|
Loading…
Reference in New Issue
Block a user