From 8ccf1afbb65a66e2f0825bf32640f2d69161480e Mon Sep 17 00:00:00 2001 From: Hugues Ross Date: Thu, 23 Apr 2020 07:13:23 -0400 Subject: [PATCH] Table UI adjustments --- table.lua | 60 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/table.lua b/table.lua index 3d1692e..35a6b6a 100644 --- a/table.lua +++ b/table.lua @@ -215,17 +215,23 @@ end -- 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 +-- cost: 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 = ""; +function fs.cost(x, y, cost, skin) + local data = string.format("background9[%f,%f;1,0.5;%s.png;false;%s]", x, y - 0.125, skin.label.texture, tostring(skin.label.radius)); local i = 0; - for name,value in pairs(materials) do - 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); + for name,value in pairs(cost) do + if name == "paper" then + data = data .. string.format("image[%f,%f;0.25,0.25;%s.png]", x + 0.125, y + (i * 0.25) - 0.125, skin.paper_texture) + elseif name == "pigment" then + data = data .. string.format("image[%f,%f;0.25,0.25;%s.png]", x + 0.125, y + (i * 0.25) - 0.125, skin.pigment_texture) + end + + data = data .. string.format("label[%f,%f;%sx %d]", x + 0.375, y + (i * 0.25), minetest.get_color_escape_sequence(skin.label.font_color), value); i = i + 1; end @@ -247,8 +253,9 @@ function fs.convert(x, y, pos, skin) .. "formspec_version[3]" .. 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) - .. fs.button(1.25, 0.5, 2, 0.5, "convert", "Convert Materials", value.paper + value.pigment > 0) - .. fs.cost(1.25, 0.125, value, skin) + .. "tooltip[0,0;1,1;Place items here to convert\nthem into mapmaking materials]" + .. fs.button(2.5, 0.25, 2, 0.5, "convert", "Convert Materials", value.paper + value.pigment > 0) + .. fs.cost(1.25, 0.375, value, skin) .. "container_end[]"; end @@ -265,29 +272,32 @@ function fs.craft(x, y, pos, rank, meta, skin) local cost, is_positive = get_craft_material_cost(meta); local data = string.format("container[%f,%f]", x, y) .. "formspec_version[3]" - .. 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) - .. fs.button(1.25, 1.25, 2, 0.5, "craft", "Craft Map", is_positive and can_afford(cost, meta)) - .. fs.cost(1.25, 0.875, cost, skin); + .. inventory_bg(0, 1, 1, 1, skin.slot) + .. string.format("list[nodemeta:%d,%d,%d;output;0,1;1,1;]", pos.x, pos.y, pos.z) + .. "tooltip[0,1;1,1;Place a map here to upgrade it,\nor leave empty to craft]" + .. fs.button(2.5, 1.25, 2, 0.5, "craft", "Craft Map", is_positive and can_afford(cost, meta)) + .. fs.cost(1.25, 1.375, cost, skin); if rank > 1 then data = data .. string.format("style[%dx;bgimg=%s.png;bgimg_hovered=%s.png;bgimg_pressed=%s.png]", meta:get_int("scale"), skin.button.selected_texture, skin.button.selected_texture, skin.button.selected_texture) - .. "button[2.5,0;0.5,0.5;1x;1x]" - .. "button[3.0,0;0.5,0.5;2x;2x]"; + .. string.format("label[2.5,0;%sMap Scale]", minetest.get_color_escape_sequence(skin.label.font_color)) + .. "button[2.5,0.25;0.5,0.5;1x;1x]" + .. "button[3.0,0.25;0.5,0.5;2x;2x]"; if rank > 2 then - data = data .. "button[3.5,0;0.5,0.5;4x;4x]" - .. "button[4.0,0;0.5,0.5;8x;8x]"; + data = data .. "button[3.5,0.25;0.5,0.5;4x;4x]" + .. "button[4.0,0.25;0.5,0.5;8x;8x]"; end end data = data .. string.format("style[%d;bgimg=%s.png;bgimg_hovered=%s.png;bgimg_pressed=%s.png]", meta:get_int("detail") + 1, skin.button.selected_texture, skin.button.selected_texture, skin.button.selected_texture) - .. "button[0.0,0;0.5,0.5;1;1]" - .. "button[0.5,0;0.5,0.5;2;2]"; + .. string.format("label[0,0;%sDetail Level]", minetest.get_color_escape_sequence(skin.label.font_color)) + .. "button[0.0,0.25;0.5,0.5;1;1]" + .. "button[0.5,0.25;0.5,0.5;2;2]"; if rank > 1 then - data = data .. "button[1.0,0;0.5,0.5;3;3]"; + data = data .. "button[1.0,0.25;0.5,0.5;3;3]"; if rank > 2 then - data = data .. "button[1.5,0;0.5,0.5;4;4]"; + data = data .. "button[1.5,0.25;0.5,0.5;4;4]"; end end @@ -309,8 +319,8 @@ function fs.copy(x, y, pos, skin) .. "formspec_version[3]" .. 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) - .. fs.button(1.25, 0.5, 2, 0.5, "copy", "Copy Map", can_afford(costs, meta)) - .. fs.cost(1.25, 0.125, costs, skin) + .. fs.button(2.5, 0.25, 2, 0.5, "copy", "Copy Map", can_afford(costs, meta)) + .. fs.cost(1.25, 0.375, costs, 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[]"; @@ -369,12 +379,12 @@ local function table_formspec(player) ); elseif data.tab == 2 then minetest.show_formspec(player, "simple_table", - fs.header(10.25, 8.0, rank, data.tab, skin) .. + fs.header(10.25, 8.25, rank, data.tab, skin) .. fs.materials(0.25, 0.1875, meta, skin) .. fs.separator(0.6875, skin.separator) .. fs.craft(0.25, 0.875, pos, rank, meta, skin) .. - fs.separator(2.75, skin.separator) .. - fs.inv(0.25, 3, skin) + fs.separator(3, skin.separator) .. + fs.inv(0.25, 3.25, skin) ); elseif data.tab == 3 then minetest.show_formspec(player, "simple_table",