From 09dfe9dffffe1cc541b3e69382f3323b4b9c1937 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Thu, 29 Aug 2019 05:56:58 +0200 Subject: [PATCH] Refactor fake itemstack --- mods/default/formspec.lua | 10 +++------- mods/gold/init.lua | 6 +++--- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/mods/default/formspec.lua b/mods/default/formspec.lua index b82bbd6..17a6409 100644 --- a/mods/default/formspec.lua +++ b/mods/default/formspec.lua @@ -125,9 +125,7 @@ local function get_itemdef_field(itemname, fieldname) return minetest.registered_items[itemname][fieldname] end -function default.ui.fake_itemstack(x, y, itemstack, name) - local name = name or "fake_itemstack" - +function default.ui.fake_itemstack(x, y, itemstack) local itemname = itemstack:get_name() local itemamt = itemstack:get_count() @@ -141,12 +139,10 @@ function default.ui.fake_itemstack(x, y, itemstack, name) local result = "" if itemname ~= "" then - result = result .. "image_button["..x..","..y..";1,1;blank.png;" - ..name..";;false;false;blank.png]" result = result .. "item_image["..x..","..y..";1,1;" ..minetest.formspec_escape(itemname .. " " .. itemamt).."]" - result = result .. "tooltip["..name..";"..minetest.formspec_escape(itemdesc).."]" + result = result .. "tooltip["..x..","..y..";1,1;"..minetest.formspec_escape(itemdesc).."]" end return result @@ -210,7 +206,7 @@ function default.ui.fake_itemstack_any(x, y, itemstack, name) local group = string.match(itemstack:get_name(), "group:(.*)") if group == nil then - return default.ui.fake_itemstack(x, y, itemstack, name) + return default.ui.fake_itemstack(x, y, itemstack) else return default.ui.item_group(x, y, group, itemstack:get_count(), name) end diff --git a/mods/gold/init.lua b/mods/gold/init.lua index 09f4cca..d17d479 100644 --- a/mods/gold/init.lua +++ b/mods/gold/init.lua @@ -190,9 +190,9 @@ function gold.trade(trade, trade_type, player) local form = default.ui.get_page("gold_trading_book") form = form .. "label[0.25,0.25;"..minetest.formspec_escape(trade_name).."]" - form = form .. default.ui.fake_itemstack(1.25, 1.25, trade_wanted1, "trade_wanted1") - form = form .. default.ui.fake_itemstack(1.25, 2.25, trade_wanted2, "trade_wanted2") - form = form .. default.ui.fake_itemstack(3.75, 1.25, ItemStack(trade[3]), "trade_result") + form = form .. default.ui.fake_itemstack(1.25, 1.25, trade_wanted1) + form = form .. default.ui.fake_itemstack(1.25, 2.25, trade_wanted2) + form = form .. default.ui.fake_itemstack(3.75, 1.25, ItemStack(trade[3])) minetest.show_formspec(name, "gold:trading_book", form)