diff --git a/table.lua b/table.lua index ca58986..df15c14 100644 --- a/table.lua +++ b/table.lua @@ -115,11 +115,20 @@ function fs.materials(x, y, meta, skin) .. "container_end[]"; end -function fs.cost(x, y, materials) +-- Draw a label with material costs from a table +-- x: The x position of the interface +-- y: The y position of the interface +-- materials: A table of material costs, with string keys for the material +-- names and iteger values +-- skin: A formspec skin table +-- +-- Returns a formspec string +function fs.cost(x, y, materials, skin) local data = ""; local i = 0; + for name,value in pairs(materials) do - data = data .. "label[" .. tostring(x) .. "," .. tostring(y + (i * 0.25)) .. ";" .. minetest.get_color_escape_sequence("#694a3a") .. name .. " x " .. tostring(value) .. "]"; + data = data .. string.format("label[%f,%f;%s%s x %d]", x, y + (i * 0.25), minetest.get_color_escape_sequence(skin.label.font_color), name, value); i = i + 1; end @@ -139,7 +148,7 @@ function fs.convert(x, y, pos, skin) .. inventory_bg(0, 0, 1, 1, skin.slot) .. string.format("list[nodemeta:%d,%d,%d;input;0,0;1,1;]", pos.x, pos.y, pos.z) .. "button[1.25,0.5;2,0.5;convert;Convert Materials]" - .. fs.cost(1.25, 0.125, { Paper = 0, Pigment = 0, }) + .. fs.cost(1.25, 0.125, { Paper = 0, Pigment = 0, }, skin) .. "container_end[]"; end @@ -158,7 +167,7 @@ function fs.craft(x, y, pos, rank, meta, skin) .. inventory_bg(0, 0.75, 1, 1, skin.slot) .. string.format("list[nodemeta:%d,%d,%d;output;0,0.75;1,1;]", pos.x, pos.y, pos.z) .. "button[1.25,1.25;2,0.5;craft;Craft Map]" - .. fs.cost(1.25, 0.875, get_full_material_cost(meta)); + .. fs.cost(1.25, 0.875, get_full_material_cost(meta), skin); if rank > 1 then local size = "s"; @@ -208,7 +217,7 @@ function fs.copy(x, y, pos, skin) .. inventory_bg(0, 0, 1, 1, skin.slot) .. string.format("list[nodemeta:%d,%d,%d;copy_input;0,0;1,1;]", pos.x, pos.y, pos.z) .. "button[1.25,0.5;2,0.5;copy;Copy Map]" - .. fs.cost(1.25, 0.125, { Paper = 0, Pigment = 0, }) + .. fs.cost(1.25, 0.125, { Paper = 0, Pigment = 0, }, skin) .. inventory_bg(8.75, 0, 1, 1, skin.slot) .. string.format("list[nodemeta:%d,%d,%d;copy_output;8.75,0;1,1;]", pos.x, pos.y, pos.z) .. "container_end[]";