Better quarry 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:
Zefram 2014-05-23 22:37:44 +01:00 committed by RealBadAngel
parent 4d20e4473e
commit b74c2d38b9
5 changed files with 23 additions and 23 deletions

View File

@ -36,6 +36,7 @@ Inventory move disallowed due to protection = Das Inventar ist geschuetzt, Zugri
# $1: Machine name (Includes tier) # $1: Machine name (Includes tier)
%s Active = %s ist eingeschaltet %s Active = %s ist eingeschaltet
%s Disabled = %s ist ausgeschaltet %s Disabled = %s ist ausgeschaltet
%s Enabled =
%s Idle = %s ist bereit %s Idle = %s ist bereit
%s Improperly Placed = %s ist falsch plaziert %s Improperly Placed = %s ist falsch plaziert
%s Unpowered = %s hat keine Stromversorgung %s Unpowered = %s hat keine Stromversorgung

View File

@ -35,6 +35,7 @@ Machine cannot be removed because it is not empty = La maquina no puede removers
Inventory move disallowed due to protection = Inventory move disallowed due to protection =
# $1: Machine name (Includes tier) # $1: Machine name (Includes tier)
%s Active = %s Activo %s Active = %s Activo
%s Enabled =
%s Idle = %s Quieto %s Idle = %s Quieto
%s Unpowered = %s Sin Energia %s Unpowered = %s Sin Energia
%s Out Of Fuel = %s Sin Combustible %s Out Of Fuel = %s Sin Combustible

View File

@ -33,6 +33,7 @@ Inventory move disallowed due to protection = Impossibile muovere l'inventario a
# $1: Machine name (Includes tier) # $1: Machine name (Includes tier)
%s Active = %s Attivo %s Active = %s Attivo
%s Disabled = %s Disabilitato %s Disabled = %s Disabilitato
%s Enabled =
%s Idle = %s Inattivo %s Idle = %s Inattivo
%s Improperly Placed = %s Piazzato impropiamente %s Improperly Placed = %s Piazzato impropiamente
%s Unpowered = %s Non alimentato %s Unpowered = %s Non alimentato

View File

@ -36,6 +36,7 @@ Inventory move disallowed due to protection =
# $1: Machine name (Includes tier) # $1: Machine name (Includes tier)
%s Active = %s Active =
%s Disabled = %s Disabled =
%s Enabled =
%s Idle = %s Idle =
%s Improperly Placed = %s Improperly Placed =
%s Unpowered = %s Unpowered =

View File

@ -12,32 +12,28 @@ minetest.register_craft({
local quarry_dig_above_nodes = 3 -- How far above the quarry we will dig nodes local quarry_dig_above_nodes = 3 -- How far above the quarry we will dig nodes
local quarry_max_depth = 100 local quarry_max_depth = 100
local function get_quarry_formspec(size) local function set_quarry_formspec(meta)
return "size[3,1.5]".. local formspec = "size[3,1.5]"..
"field[1,0.5;2,1;size;Radius;"..size.."]".. "field[1,0.5;2,1;size;Radius;"..meta:get_int("size").."]"
"button[0,1;3,1;toggle;"..S("Enable/Disable").."]" if meta:get_int("enabled") == 0 then
formspec = formspec.."button[0,1;3,1;enable;"..S("%s Disabled"):format(S("Quarry")).."]"
else
formspec = formspec.."button[0,1;3,1;disable;"..S("%s Enabled"):format(S("Quarry")).."]"
end
meta:set_string("formspec", formspec)
end end
local function quarry_receive_fields(pos, formname, fields, sender) local function quarry_receive_fields(pos, formname, fields, sender)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local size = tonumber(fields.size) or 0 if fields.size then
local size = tonumber(fields.size) or 0
if fields.toggle then size = math.max(size, 2)
if meta:get_int("enabled") == 0 then size = math.min(size, 8)
meta:set_int("enabled", 1)
else
meta:set_int("enabled", 0)
end
end
-- Smallest size is 2. Largest is 8.
size = math.max(size, 2)
size = math.min(size, 8)
if meta:get_int("size") ~= size then
meta:set_int("size", size) meta:set_int("size", size)
meta:set_string("formspec", get_quarry_formspec(size))
end end
if fields.enable then meta:set_int("enabled", 1) end
if fields.disable then meta:set_int("enabled", 0) end
set_quarry_formspec(meta)
end end
local function get_quarry_center(pos, size) local function get_quarry_center(pos, size)
@ -103,6 +99,7 @@ local function quarry_dig(pos, center, size)
end end
if minetest.is_protected and minetest.is_protected(digpos, owner) then if minetest.is_protected and minetest.is_protected(digpos, owner) then
meta:set_int("enabled", 0) meta:set_int("enabled", 0)
set_quarry_formspec(meta)
return {} return {}
end end
dig_y = digpos.y dig_y = digpos.y
@ -140,11 +137,10 @@ minetest.register_node("technic:quarry", {
connect_sides = {top = 1}, connect_sides = {top = 1},
}, },
on_construct = function(pos) on_construct = function(pos)
local size = 4
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
meta:set_string("infotext", S("Quarry")) meta:set_string("infotext", S("Quarry"))
meta:set_string("formspec", get_quarry_formspec(4)) meta:set_int("size", 4)
meta:set_int("size", size) set_quarry_formspec(meta)
meta:set_int("dig_y", pos.y) meta:set_int("dig_y", pos.y)
end, end,
after_place_node = function(pos, placer, itemstack) after_place_node = function(pos, placer, itemstack)