Zefram
2014-05-23 b74c2d38b99417c0e69f66191dd8231d75366e36
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.
5 files modified
46 ■■■■ changed files
technic/locale/de.txt 1 ●●●● patch | view | raw | blame | history
technic/locale/es.txt 1 ●●●● patch | view | raw | blame | history
technic/locale/it.txt 1 ●●●● patch | view | raw | blame | history
technic/locale/template.txt 1 ●●●● patch | view | raw | blame | history
technic/machines/HV/quarry.lua 42 ●●●● patch | view | raw | blame | history
technic/locale/de.txt
@@ -36,6 +36,7 @@
# $1: Machine name (Includes tier)
%s Active = %s ist eingeschaltet
%s Disabled = %s ist ausgeschaltet
%s Enabled =
%s Idle = %s ist bereit
%s Improperly Placed = %s ist falsch plaziert
%s Unpowered = %s hat keine Stromversorgung 
technic/locale/es.txt
@@ -35,6 +35,7 @@
Inventory move disallowed due to protection =
# $1: Machine name (Includes tier)
%s Active = %s Activo
%s Enabled =
%s Idle = %s Quieto
%s Unpowered = %s Sin Energia
%s Out Of Fuel = %s Sin Combustible
technic/locale/it.txt
@@ -33,6 +33,7 @@
# $1: Machine name (Includes tier)
%s Active = %s Attivo
%s Disabled = %s Disabilitato
%s Enabled =
%s Idle = %s Inattivo
%s Improperly Placed = %s Piazzato impropiamente
%s Unpowered = %s Non alimentato
technic/locale/template.txt
@@ -36,6 +36,7 @@
# $1: Machine name (Includes tier)
%s Active =
%s Disabled =
%s Enabled =
%s Idle =
%s Improperly Placed =
%s Unpowered =
technic/machines/HV/quarry.lua
@@ -12,32 +12,28 @@
local quarry_dig_above_nodes = 3 -- How far above the quarry we will dig nodes
local quarry_max_depth       = 100
local function get_quarry_formspec(size)
    return "size[3,1.5]"..
        "field[1,0.5;2,1;size;Radius;"..size.."]"..
        "button[0,1;3,1;toggle;"..S("Enable/Disable").."]"
local function set_quarry_formspec(meta)
    local formspec = "size[3,1.5]"..
        "field[1,0.5;2,1;size;Radius;"..meta:get_int("size").."]"
    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
local function quarry_receive_fields(pos, formname, fields, sender)
    local meta = minetest.get_meta(pos)
    local size = tonumber(fields.size) or 0
    if fields.toggle then
        if meta:get_int("enabled") == 0 then
            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
    if fields.size then
        local size = tonumber(fields.size) or 0
        size = math.max(size, 2)
        size = math.min(size, 8)
        meta:set_int("size", size)
        meta:set_string("formspec", get_quarry_formspec(size))
    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
local function get_quarry_center(pos, size)
@@ -103,6 +99,7 @@
        end
        if minetest.is_protected and minetest.is_protected(digpos, owner) then
            meta:set_int("enabled", 0)
            set_quarry_formspec(meta)
            return {}
        end
        dig_y = digpos.y
@@ -140,11 +137,10 @@
        connect_sides = {top = 1},
    },
    on_construct = function(pos)
        local size = 4
        local meta = minetest.get_meta(pos)
        meta:set_string("infotext", S("Quarry"))
        meta:set_string("formspec", get_quarry_formspec(4))
        meta:set_int("size", size)
        meta:set_int("size", 4)
        set_quarry_formspec(meta)
        meta:set_int("dig_y", pos.y)
    end,
    after_place_node = function(pos, placer, itemstack)