Add tooltips to buffers!

This commit is contained in:
Evert Prants 2018-08-06 12:53:00 +03:00
parent cc909b2f51
commit c4949c2935
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
11 changed files with 59 additions and 37 deletions

View File

@ -3,6 +3,7 @@
function ele.formspec.fluid_bar(x, y, fluid_buffer) function ele.formspec.fluid_bar(x, y, fluid_buffer)
local texture = "default_water.png" local texture = "default_water.png"
local metric = 0 local metric = 0
local tooltip = ("tooltip[%d,%d;1,2.5;%s]"):format(x, y, "Empty Buffer")
if fluid_buffer and fluid_buffer.fluid and fluid_buffer.fluid ~= "" and if fluid_buffer and fluid_buffer.fluid and fluid_buffer.fluid ~= "" and
minetest.registered_nodes[fluid_buffer.fluid] ~= nil then minetest.registered_nodes[fluid_buffer.fluid] ~= nil then
@ -10,10 +11,15 @@ function ele.formspec.fluid_bar(x, y, fluid_buffer)
if type(texture) == "table" then if type(texture) == "table" then
texture = texture.name texture = texture.name
end end
local fdesc = fluid_lib.cleanse_node_description(fluid_buffer.fluid)
metric = math.floor(100 * fluid_buffer.amount / fluid_buffer.capacity) metric = math.floor(100 * fluid_buffer.amount / fluid_buffer.capacity)
tooltip = ("tooltip[%d,%d;1,2.5;%s\n%s / %s %s]"):format(x, y, fdesc,
ele.helpers.comma_value(fluid_buffer.amount), ele.helpers.comma_value(fluid_buffer.capacity), fluid_lib.unit)
end end
return "image["..x..","..y..";1,2.8;elepower_gui_barbg.png".. return "image["..x..","..y..";1,2.8;elepower_gui_barbg.png"..
"\\^[lowpart\\:"..metric.."\\:"..texture.."\\\\^[resize\\\\:64x128]".. "\\^[lowpart\\:"..metric.."\\:"..texture.."\\\\^[resize\\\\:64x128]"..
"image["..x..","..y..";1,2.8;elepower_gui_gauge.png]" "image["..x..","..y..";1,2.8;elepower_gui_gauge.png]"..
tooltip
end end

View File

@ -135,10 +135,10 @@ local function on_timer(pos, elapsed)
ele.helpers.swap_node(pos, "elepower_farming:harvester") ele.helpers.swap_node(pos, "elepower_farming:harvester")
end end
local power_percent = math.floor((storage / capacity)*100) local power = {capacity = capacity, storage = storage}
local work_percent = math.floor((work / HARVESTER_TICK)*100) local work_percent = math.floor((work / HARVESTER_TICK)*100)
meta:set_string("formspec", get_formspec(work_percent, power_percent, sludge)) meta:set_string("formspec", get_formspec(work_percent, power, sludge))
meta:set_int("storage", storage) meta:set_int("storage", storage)
meta:set_int("src_time", work) meta:set_int("src_time", work)
@ -179,7 +179,8 @@ ele.register_machine("elepower_farming:harvester", {
meta:set_int("src_time", 0) meta:set_int("src_time", 0)
meta:set_string("formspec", get_formspec(0, 0)) local capacity = ele.helpers.get_node_property(meta, pos, "capacity")
meta:set_string("formspec", get_formspec(0, {capacity = capacity, storage = 0}))
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
end, end,

View File

@ -252,10 +252,10 @@ local function on_timer(pos, elapsed)
refresh = true refresh = true
end end
local power_percent = math.floor((storage / capacity)*100) local power = {capacity = capacity, storage = storage}
local work_percent = math.floor((work / PLANTER_TICK)*100) local work_percent = math.floor((work / PLANTER_TICK)*100)
meta:set_string("formspec", get_formspec(work_percent, power_percent)) meta:set_string("formspec", get_formspec(work_percent, power))
meta:set_int("storage", storage) meta:set_int("storage", storage)
meta:set_int("src_time", work) meta:set_int("src_time", work)
@ -287,7 +287,8 @@ ele.register_base_device("elepower_farming:planter", {
meta:set_int("src_time", 0) meta:set_int("src_time", 0)
meta:set_string("formspec", get_formspec(0,0)) local capacity = ele.helpers.get_node_property(meta, pos, "capacity")
meta:set_string("formspec", get_formspec(0, {capacity = capacity, storage = 0}))
end, end,
allow_metadata_inventory_put = allow_metadata_inventory_put, allow_metadata_inventory_put = allow_metadata_inventory_put,
allow_metadata_inventory_take = allow_metadata_inventory_take, allow_metadata_inventory_take = allow_metadata_inventory_take,

View File

@ -150,10 +150,10 @@ local function on_timer(pos, elapsed)
meta:set_string("infotext", ("Powered Mob Spawner %s\nMob: %s\n%s"):format( meta:set_string("infotext", ("Powered Mob Spawner %s\nMob: %s\n%s"):format(
active, mob_desc, ele.capacity_text(capacity, storage))) active, mob_desc, ele.capacity_text(capacity, storage)))
local power_percent = math.floor((storage / capacity)*100) local power = {capacity = capacity, storage = storage}
local work_percent = math.floor((work / SPAWNER_TICK)*100) local work_percent = math.floor((work / SPAWNER_TICK)*100)
meta:set_string("formspec", get_formspec(work_percent, power_percent)) meta:set_string("formspec", get_formspec(work_percent, power))
meta:set_int("storage", storage) meta:set_int("storage", storage)
meta:set_int("src_time", work) meta:set_int("src_time", work)
@ -184,7 +184,9 @@ ele.register_machine("elepower_farming:spawner", {
inv:set_size("src", 1) inv:set_size("src", 1)
meta:set_int("src_time", 0) meta:set_int("src_time", 0)
meta:set_string("formspec", get_formspec(0,0))
local capacity = ele.helpers.get_node_property(meta, pos, "capacity")
meta:set_string("formspec", get_formspec(0, {capacity = capacity, storage = 0}))
end, end,
can_dig = can_dig, can_dig = can_dig,
on_timer = on_timer, on_timer = on_timer,

View File

@ -131,7 +131,7 @@ local function on_timer(pos, elapsed)
end end
local timer = 0 local timer = 0
local power = math.floor(100 * storage / capacity) local power = {capacity = capacity, storage = storage}
if time_max > 0 then if time_max > 0 then
timer = math.floor(100 * time / time_max) timer = math.floor(100 * time / time_max)
end end
@ -167,7 +167,9 @@ ele.register_machine("elepower_farming:tree_processor", {
local inv = meta:get_inventory() local inv = meta:get_inventory()
inv:set_size("dst", 1) inv:set_size("dst", 1)
meta:set_string("formspec", get_formspec(0, 0))
local capacity = ele.helpers.get_node_property(meta, pos, "capacity")
meta:set_string("formspec", get_formspec(0, {capacity = capacity, storage = 0}))
end, end,
tiles = { tiles = {
"elefarming_machine_tree_processor.png", "elefarming_machine_base.png", "elefarming_machine_side.png", "elefarming_machine_tree_processor.png", "elefarming_machine_base.png", "elefarming_machine_side.png",

View File

@ -96,7 +96,7 @@ function elepm.register_crafter(nodename, nodedef)
local usage = ele.helpers.get_node_property(meta, pos, "usage") local usage = ele.helpers.get_node_property(meta, pos, "usage")
local storage = ele.helpers.get_node_property(meta, pos, "storage") local storage = ele.helpers.get_node_property(meta, pos, "storage")
local pow_percent = math.floor((storage / capacity) * 100) local pow_buffer = {capacity = capacity, storage = storage}
local power_operation = false local power_operation = false
@ -109,13 +109,13 @@ function elepm.register_crafter(nodename, nodedef)
ele.helpers.swap_node(pos, machine_node) ele.helpers.swap_node(pos, machine_node)
if result.time == 0 then if result.time == 0 then
meta:set_string("formspec", get_formspec(craft_type, pow_percent, nil, pos)) meta:set_string("formspec", get_formspec(craft_type, pow_buffer, nil, pos))
time = 0 time = 0
meta:set_string("infotext", ("%s Idle"):format(nodedef.description) .. meta:set_string("infotext", ("%s Idle"):format(nodedef.description) ..
"\n" .. ele.capacity_text(capacity, storage)) "\n" .. ele.capacity_text(capacity, storage))
else else
local pct = math.floor((ele.helpers.round(result.time * 10) / meta:get_int("src_time")) * 100) local pct = math.floor((ele.helpers.round(result.time * 10) / meta:get_int("src_time")) * 100)
meta:set_string("formspec", get_formspec(craft_type, pow_percent, pct, pos)) meta:set_string("formspec", get_formspec(craft_type, pow_buffer, pct, pos))
meta:set_string("infotext", ("%s Out of Power!"):format(nodedef.description) .. meta:set_string("infotext", ("%s Out of Power!"):format(nodedef.description) ..
"\n" .. ele.capacity_text(capacity, storage)) "\n" .. ele.capacity_text(capacity, storage))
end end
@ -127,7 +127,7 @@ function elepm.register_crafter(nodename, nodedef)
-- One step -- One step
meta:set_int("storage", storage - usage) meta:set_int("storage", storage - usage)
pow_percent = math.floor((storage / capacity) * 100) pow_buffer = {capacity = capacity, storage = storage}
time = time + ele.helpers.round(machine_speed * 10) time = time + ele.helpers.round(machine_speed * 10)
meta:set_string("infotext", ("%s Active"):format(nodedef.description) .. meta:set_string("infotext", ("%s Active"):format(nodedef.description) ..
"\n" .. ele.capacity_text(capacity, storage)) "\n" .. ele.capacity_text(capacity, storage))
@ -143,7 +143,7 @@ function elepm.register_crafter(nodename, nodedef)
if time <= ele.helpers.round(result.time * 10) then if time <= ele.helpers.round(result.time * 10) then
local pct = math.floor((time / ele.helpers.round(result.time * 10)) * 100) local pct = math.floor((time / ele.helpers.round(result.time * 10)) * 100)
meta:set_string("formspec", get_formspec(craft_type, pow_percent, pct, pos)) meta:set_string("formspec", get_formspec(craft_type, pow_buffer, pct, pos))
break break
end end
@ -168,7 +168,7 @@ function elepm.register_crafter(nodename, nodedef)
if not room_for_output then if not room_for_output then
ele.helpers.swap_node(pos, machine_node) ele.helpers.swap_node(pos, machine_node)
meta:set_string("formspec", get_formspec(craft_type, pow_percent, nil, pos)) meta:set_string("formspec", get_formspec(craft_type, pow_buffer, nil, pos))
time = ele.helpers.round(result.time*10) time = ele.helpers.round(result.time*10)
meta:set_string("infotext", ("%s Output Full!"):format(nodedef.description) .. meta:set_string("infotext", ("%s Output Full!"):format(nodedef.description) ..
"\n" .. ele.capacity_text(capacity, storage)) "\n" .. ele.capacity_text(capacity, storage))
@ -194,8 +194,8 @@ function elepm.register_crafter(nodename, nodedef)
local storage = ele.helpers.get_node_property(meta, pos, "storage") local storage = ele.helpers.get_node_property(meta, pos, "storage")
local capacity = ele.helpers.get_node_property(meta, pos, "capacity") local capacity = ele.helpers.get_node_property(meta, pos, "capacity")
local pow_percent = math.floor((storage / capacity) * 100) local pow_buffer = {capacity = capacity, storage = storage}
meta:set_string("formspec", get_formspec(craft_type, pow_percent, nil, pos)) meta:set_string("formspec", get_formspec(craft_type, pow_buffer, nil, pos))
end end
ele.register_machine(nodename, nodedef) ele.register_machine(nodename, nodedef)

View File

@ -60,7 +60,7 @@ function ele.register_fluid_generator(nodename, nodedef)
-- Fluid buffer -- Fluid buffer
local flbuffer = fluid_lib.get_buffer_data(pos, buffer_name) local flbuffer = fluid_lib.get_buffer_data(pos, buffer_name)
local pow_percent local pow_buffer
if not flbuffer or flbuffer.fluid == "" then return false end if not flbuffer or flbuffer.fluid == "" then return false end
while true do while true do
@ -70,13 +70,14 @@ function ele.register_fluid_generator(nodename, nodedef)
break break
end end
meta:set_int("storage", storage + generation) storage = storage + generation
meta:set_int("storage", storage)
burn_time = burn_time - 1 burn_time = burn_time - 1
meta:set_int("burn_time", burn_time) meta:set_int("burn_time", burn_time)
end end
pow_percent = math.floor((storage / capacity) * 100) pow_buffer = {capacity = capacity, storage = storage}
-- Burn another bucket of lava -- Burn another bucket of lava
if burn_time == 0 then if burn_time == 0 then
@ -93,7 +94,7 @@ function ele.register_fluid_generator(nodename, nodedef)
refresh = true refresh = true
else else
meta:set_string("formspec", get_formspec(pow_percent, 0, flbuffer)) meta:set_string("formspec", get_formspec(pow_buffer, 0, flbuffer))
meta:set_string("infotext", ("%s Idle\n%s\n%s"):format(nodedef.description, meta:set_string("infotext", ("%s Idle\n%s\n%s"):format(nodedef.description,
ele.capacity_text(capacity, storage), fluid_lib.buffer_to_string(flbuffer))) ele.capacity_text(capacity, storage), fluid_lib.buffer_to_string(flbuffer)))
@ -105,7 +106,7 @@ function ele.register_fluid_generator(nodename, nodedef)
end end
local percent = math.floor((burn_time / burn_totaltime) * 100) local percent = math.floor((burn_time / burn_totaltime) * 100)
meta:set_string("formspec", get_formspec(pow_percent, percent, flbuffer)) meta:set_string("formspec", get_formspec(pow_buffer, percent, flbuffer))
meta:set_string("infotext", ("%s Active\n%s\n%s"):format(nodedef.description, meta:set_string("infotext", ("%s Active\n%s\n%s"):format(nodedef.description,
ele.capacity_text(capacity, storage), fluid_lib.buffer_to_string(flbuffer))) ele.capacity_text(capacity, storage), fluid_lib.buffer_to_string(flbuffer)))
@ -119,7 +120,7 @@ function ele.register_fluid_generator(nodename, nodedef)
local capacity = ele.helpers.get_node_property(meta, pos, "capacity") local capacity = ele.helpers.get_node_property(meta, pos, "capacity")
local storage = ele.helpers.get_node_property(meta, pos, "storage") local storage = ele.helpers.get_node_property(meta, pos, "storage")
meta:set_string("formspec", get_formspec(math.floor((storage / capacity) * 100), 0)) meta:set_string("formspec", get_formspec({capacity = capacity, storage = storage}, 0))
end end
} }

View File

@ -49,13 +49,14 @@ function elepm.register_fuel_generator(nodename, nodedef)
return false return false
end end
meta:set_int("storage", storage + generation) storage = storage + generation
meta:set_int("storage", storage)
burn_time = burn_time - 1 burn_time = burn_time - 1
meta:set_int("burn_time", burn_time) meta:set_int("burn_time", burn_time)
end end
local pow_percent = math.floor((storage / capacity) * 100) local pow_buffer = {capacity = capacity, storage = storage}
-- Burn another piece of fuel -- Burn another piece of fuel
if burn_time == 0 then if burn_time == 0 then
@ -82,7 +83,7 @@ function elepm.register_fuel_generator(nodename, nodedef)
ele.helpers.swap_node(pos, active_node) ele.helpers.swap_node(pos, active_node)
end end
else else
meta:set_string("formspec", get_formspec(pow_percent, 0)) meta:set_string("formspec", get_formspec(pow_buffer, 0))
meta:set_string("infotext", ("%s Idle"):format(nodedef.description) .. meta:set_string("infotext", ("%s Idle"):format(nodedef.description) ..
"\n" .. ele.capacity_text(capacity, storage)) "\n" .. ele.capacity_text(capacity, storage))
ele.helpers.swap_node(pos, nodename) ele.helpers.swap_node(pos, nodename)
@ -92,7 +93,7 @@ function elepm.register_fuel_generator(nodename, nodedef)
if burn_totaltime == 0 then burn_totaltime = 1 end if burn_totaltime == 0 then burn_totaltime = 1 end
local percent = math.floor((burn_time / burn_totaltime) * 100) local percent = math.floor((burn_time / burn_totaltime) * 100)
meta:set_string("formspec", get_formspec(pow_percent, percent)) meta:set_string("formspec", get_formspec(pow_buffer, percent))
meta:set_string("infotext", ("%s Active"):format(nodedef.description) .. meta:set_string("infotext", ("%s Active"):format(nodedef.description) ..
"\n" .. ele.capacity_text(capacity, storage)) "\n" .. ele.capacity_text(capacity, storage))
@ -107,7 +108,7 @@ function elepm.register_fuel_generator(nodename, nodedef)
local capacity = ele.helpers.get_node_property(meta, pos, "capacity") local capacity = ele.helpers.get_node_property(meta, pos, "capacity")
local storage = ele.helpers.get_node_property(meta, pos, "storage") local storage = ele.helpers.get_node_property(meta, pos, "storage")
meta:set_string("formspec", get_formspec(math.floor((storage / capacity) * 100), 0)) meta:set_string("formspec", get_formspec({capacity = capacity, storage = storage}, 0))
end end
ele.register_machine(nodename, nodedef) ele.register_machine(nodename, nodedef)

View File

@ -58,10 +58,9 @@ function elepm.register_storage(nodename, nodedef)
local percent = storage / capacity local percent = storage / capacity
local level = math.floor(percent * levels) local level = math.floor(percent * levels)
local rounded = math.floor(percent * 100)
ele.helpers.swap_node(pos, nodename .. "_" .. level) ele.helpers.swap_node(pos, nodename .. "_" .. level)
meta:set_string("formspec", get_formspec(rounded)) meta:set_string("formspec", get_formspec({capacity = capacity, storage = storage}))
meta:set_string("infotext", ("%s Active"):format(nodedef.description) .. "\n" .. meta:set_string("infotext", ("%s Active"):format(nodedef.description) .. "\n" ..
ele.capacity_text(capacity, storage)) ele.capacity_text(capacity, storage))
@ -139,7 +138,9 @@ function elepm.register_storage(nodename, nodedef)
local inv = meta:get_inventory() local inv = meta:get_inventory()
inv:set_size("out", 1) inv:set_size("out", 1)
inv:set_size("in", 1) inv:set_size("in", 1)
meta:set_string("formspec", get_formspec(0))
local capacity = ele.helpers.get_node_property(meta, pos, "capacity")
meta:set_string("formspec", get_formspec({ capacity = capacity, storage = 0 }))
end end
for i = 0, levels do for i = 0, levels do

View File

@ -105,7 +105,7 @@ local function lava_cooler_timer(pos, elapsed)
active = "Idle" active = "Idle"
end end
local power = math.floor(100 * storage / capacity) local power = {capacity = capacity, storage = storage}
local timer = math.floor(100 * time / TIME) local timer = math.floor(100 * time / TIME)
meta:set_int("src_time", time) meta:set_int("src_time", time)

View File

@ -19,6 +19,13 @@ function ele.formspec.create_bar(x, y, metric, color, small)
gauge gauge
end end
function ele.formspec.power_meter(pw_percent) function ele.formspec.power_meter(capacitor)
return ele.formspec.create_bar(0, 0, pw_percent, "#00a1ff") if not capacitor then
capacitor = { capacity = 8000, storage = 0 }
end
local pw_percent = math.floor(100 * capacitor.storage / capacitor.capacity)
return ele.formspec.create_bar(0, 0, pw_percent, "#00a1ff") ..
"tooltip[0,0;1,2.5;Power Buffer\n" .. ele.capacity_text(capacitor.capacity, capacitor.storage) .. "]"
end end