mirror of
https://github.com/minetest-mods/technic.git
synced 2024-12-26 10:50:33 +01:00
Better forcefield control dialog
The size configuration is no longer cleared when exiting the dialog with <esc>. The enable/disable toggle button now indicates the current state. The name of the toggle button now varies according to state, so that pressing the button multiple times in one state (which can arise due to lag making the user unsure about whether the first press registered) only makes the state change that the user requested, rather than toggling repeatedly.
This commit is contained in:
parent
c0a17396bf
commit
2d6f34df15
@ -62,35 +62,34 @@ local function update_forcefield(pos, range, active)
|
|||||||
vm:update_map()
|
vm:update_map()
|
||||||
end
|
end
|
||||||
|
|
||||||
local get_forcefield_formspec = function(range)
|
local function set_forcefield_formspec(meta)
|
||||||
return "size[3,1.5]"..
|
local formspec = "size[5,1.5]"..
|
||||||
"field[1,0.5;2,1;range;"..S("Range")..";"..range.."]"..
|
"field[2,0.5;2,1;range;"..S("Range")..";"..meta:get_int("range").."]"
|
||||||
"button[0,1;3,1;toggle;"..S("Enable/Disable").."]"
|
if meta:get_int("enabled") == 0 then
|
||||||
|
formspec = formspec.."button[0,1;5,1;enable;"..S("%s Disabled"):format(S("%s Forcefield Emitter"):format("HV")).."]"
|
||||||
|
else
|
||||||
|
formspec = formspec.."button[0,1;5,1;disable;"..S("%s Enabled"):format(S("%s Forcefield Emitter"):format("HV")).."]"
|
||||||
|
end
|
||||||
|
meta:set_string("formspec", formspec)
|
||||||
end
|
end
|
||||||
|
|
||||||
local forcefield_receive_fields = function(pos, formname, fields, sender)
|
local forcefield_receive_fields = function(pos, formname, fields, sender)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local range = tonumber(fields.range) or 0
|
if fields.range then
|
||||||
|
local range = tonumber(fields.range) or 0
|
||||||
if fields.toggle then
|
-- Smallest field is 5. Anything less is asking for trouble.
|
||||||
if meta:get_int("enabled") == 1 then
|
-- Largest is 20. It is a matter of pratical node handling.
|
||||||
meta:set_int("enabled", 0)
|
-- At the maximim range updating the forcefield takes about 0.2s
|
||||||
else
|
range = math.max(range, 5)
|
||||||
meta:set_int("enabled", 1)
|
range = math.min(range, 20)
|
||||||
|
if meta:get_int("range") ~= range then
|
||||||
|
update_forcefield(pos, meta:get_int("range"), false)
|
||||||
|
meta:set_int("range", range)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if fields.enable then meta:set_int("enabled", 1) end
|
||||||
-- Smallest field is 5. Anything less is asking for trouble.
|
if fields.disable then meta:set_int("enabled", 0) end
|
||||||
-- Largest is 20. It is a matter of pratical node handling.
|
set_forcefield_formspec(meta)
|
||||||
-- At the maximim range updating the forcefield takes about 0.2s
|
|
||||||
range = math.max(range, 5)
|
|
||||||
range = math.min(range, 20)
|
|
||||||
|
|
||||||
if meta:get_int("range") ~= range then
|
|
||||||
update_forcefield(pos, meta:get_int("range"), false)
|
|
||||||
meta:set_int("range", range)
|
|
||||||
meta:set_string("formspec", get_forcefield_formspec(range))
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local mesecons = {
|
local mesecons = {
|
||||||
@ -115,8 +114,8 @@ minetest.register_node("technic:forcefield_emitter_off", {
|
|||||||
meta:set_int("HV_EU_demand", 0)
|
meta:set_int("HV_EU_demand", 0)
|
||||||
meta:set_int("range", 10)
|
meta:set_int("range", 10)
|
||||||
meta:set_int("enabled", 0)
|
meta:set_int("enabled", 0)
|
||||||
meta:set_string("formspec", get_forcefield_formspec(10))
|
|
||||||
meta:set_string("infotext", S("%s Forcefield Emitter"):format("HV"))
|
meta:set_string("infotext", S("%s Forcefield Emitter"):format("HV"))
|
||||||
|
set_forcefield_formspec(meta)
|
||||||
end,
|
end,
|
||||||
mesecons = mesecons
|
mesecons = mesecons
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user