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)
local texture = "default_water.png"
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
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
texture = texture.name
end
local fdesc = fluid_lib.cleanse_node_description(fluid_buffer.fluid)
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
return "image["..x..","..y..";1,2.8;elepower_gui_barbg.png"..
"\\^[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

View File

@ -135,10 +135,10 @@ local function on_timer(pos, elapsed)
ele.helpers.swap_node(pos, "elepower_farming:harvester")
end
local power_percent = math.floor((storage / capacity)*100)
local power = {capacity = capacity, storage = storage}
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("src_time", work)
@ -179,7 +179,8 @@ ele.register_machine("elepower_farming:harvester", {
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)
end,

View File

@ -252,10 +252,10 @@ local function on_timer(pos, elapsed)
refresh = true
end
local power_percent = math.floor((storage / capacity)*100)
local power = {capacity = capacity, storage = storage}
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("src_time", work)
@ -287,7 +287,8 @@ ele.register_base_device("elepower_farming:planter", {
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,
allow_metadata_inventory_put = allow_metadata_inventory_put,
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(
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)
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("src_time", work)
@ -184,7 +184,9 @@ ele.register_machine("elepower_farming:spawner", {
inv:set_size("src", 1)
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,
can_dig = can_dig,
on_timer = on_timer,

View File

@ -131,7 +131,7 @@ local function on_timer(pos, elapsed)
end
local timer = 0
local power = math.floor(100 * storage / capacity)
local power = {capacity = capacity, storage = storage}
if time_max > 0 then
timer = math.floor(100 * time / time_max)
end
@ -167,7 +167,9 @@ ele.register_machine("elepower_farming:tree_processor", {
local inv = meta:get_inventory()
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,
tiles = {
"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 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
@ -109,13 +109,13 @@ function elepm.register_crafter(nodename, nodedef)
ele.helpers.swap_node(pos, machine_node)
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
meta:set_string("infotext", ("%s Idle"):format(nodedef.description) ..
"\n" .. ele.capacity_text(capacity, storage))
else
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) ..
"\n" .. ele.capacity_text(capacity, storage))
end
@ -127,7 +127,7 @@ function elepm.register_crafter(nodename, nodedef)
-- One step
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)
meta:set_string("infotext", ("%s Active"):format(nodedef.description) ..
"\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
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
end
@ -168,7 +168,7 @@ function elepm.register_crafter(nodename, nodedef)
if not room_for_output then
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)
meta:set_string("infotext", ("%s Output Full!"):format(nodedef.description) ..
"\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 capacity = ele.helpers.get_node_property(meta, pos, "capacity")
local pow_percent = math.floor((storage / capacity) * 100)
meta:set_string("formspec", get_formspec(craft_type, pow_percent, nil, pos))
local pow_buffer = {capacity = capacity, storage = storage}
meta:set_string("formspec", get_formspec(craft_type, pow_buffer, nil, pos))
end
ele.register_machine(nodename, nodedef)

View File

@ -60,7 +60,7 @@ function ele.register_fluid_generator(nodename, nodedef)
-- Fluid buffer
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
while true do
@ -70,13 +70,14 @@ function ele.register_fluid_generator(nodename, nodedef)
break
end
meta:set_int("storage", storage + generation)
storage = storage + generation
meta:set_int("storage", storage)
burn_time = burn_time - 1
meta:set_int("burn_time", burn_time)
end
pow_percent = math.floor((storage / capacity) * 100)
pow_buffer = {capacity = capacity, storage = storage}
-- Burn another bucket of lava
if burn_time == 0 then
@ -93,7 +94,7 @@ function ele.register_fluid_generator(nodename, nodedef)
refresh = true
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,
ele.capacity_text(capacity, storage), fluid_lib.buffer_to_string(flbuffer)))
@ -105,7 +106,7 @@ function ele.register_fluid_generator(nodename, nodedef)
end
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,
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 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
}

View File

@ -49,13 +49,14 @@ function elepm.register_fuel_generator(nodename, nodedef)
return false
end
meta:set_int("storage", storage + generation)
storage = storage + generation
meta:set_int("storage", storage)
burn_time = burn_time - 1
meta:set_int("burn_time", burn_time)
end
local pow_percent = math.floor((storage / capacity) * 100)
local pow_buffer = {capacity = capacity, storage = storage}
-- Burn another piece of fuel
if burn_time == 0 then
@ -82,7 +83,7 @@ function elepm.register_fuel_generator(nodename, nodedef)
ele.helpers.swap_node(pos, active_node)
end
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) ..
"\n" .. ele.capacity_text(capacity, storage))
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
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) ..
"\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 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
ele.register_machine(nodename, nodedef)

View File

@ -58,10 +58,9 @@ function elepm.register_storage(nodename, nodedef)
local percent = storage / capacity
local level = math.floor(percent * levels)
local rounded = math.floor(percent * 100)
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" ..
ele.capacity_text(capacity, storage))
@ -139,7 +138,9 @@ function elepm.register_storage(nodename, nodedef)
local inv = meta:get_inventory()
inv:set_size("out", 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
for i = 0, levels do

View File

@ -105,7 +105,7 @@ local function lava_cooler_timer(pos, elapsed)
active = "Idle"
end
local power = math.floor(100 * storage / capacity)
local power = {capacity = capacity, storage = storage}
local timer = math.floor(100 * 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
end
function ele.formspec.power_meter(pw_percent)
return ele.formspec.create_bar(0, 0, pw_percent, "#00a1ff")
function ele.formspec.power_meter(capacitor)
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