Skip to content

Commit

Permalink
Merge pull request #12 from VanessaE/master
Browse files Browse the repository at this point in the history
Update to work with Unified Inventory since formspec v4 update
  • Loading branch information
bousket committed Mar 10, 2021
2 parents b38be14 + 7a7696d commit 74d9135
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 11 deletions.
11 changes: 8 additions & 3 deletions craft_all.lua
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
local S = minetest.get_translator("unified_inventory")
local F = minetest.formspec_escape

local has_stamina = minetest.global_exists("stamina")
local ui = unified_inventory

-- Backup to inject code
unified_inventory_plus.craft_all = unified_inventory.pages["craft"].get_formspec

local function onload()
unified_inventory.pages["craft"] = {
get_formspec = function(player, perplayer_formspec)
local formspecy = perplayer_formspec.formspec_y
local formspec = unified_inventory_plus.craft_all(player, perplayer_formspec).formspec
formspec = formspec.."button[5.15, "..(formspecy + 1.18)..";0.8,0.6;craft_craftall;"..F(S("All")).."]"
formspec = formspec..string.format("image[%f,%f;%f,%f;ui_crafting_long_arrow.png]",
perplayer_formspec.craft_arrow_x, perplayer_formspec.craft_y,
ui.imgscale, ui.imgscale * 3)..
string.format("button[%f,%f;%f,%f;craft_craftall;%s]",
perplayer_formspec.craft_arrow_x + 0.23, perplayer_formspec.craft_y + 1.50,
perplayer_formspec.btn_size, perplayer_formspec.btn_size,
F(S("All")))
return {formspec=formspec}
end,
}
Expand Down
7 changes: 5 additions & 2 deletions craft_clear.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Clear items in the craft inventory

local ui = unified_inventory

-- Backup to inject code
unified_inventory_plus.craft_clear = unified_inventory.pages["craft"].get_formspec
Expand All @@ -9,7 +9,10 @@ local function onload()
get_formspec = function(player, perplayer_formspec)
local formspecy = perplayer_formspec.formspec_y + 1
local formspec = unified_inventory_plus.craft_clear(player, perplayer_formspec).formspec
formspec = formspec.."image_button[1.25,"..(formspecy)..";0.75,0.75;pattern_clear.png;craft_clear;]"
formspec = formspec..string.format("image_button[%f,%f;%f,%f;pattern_clear.png;craft_clear;]",
perplayer_formspec.craft_x - perplayer_formspec.btn_spc,
perplayer_formspec.craft_y + ui.imgscale,
perplayer_formspec.btn_size, perplayer_formspec.btn_size)
return {formspec=formspec}
end,
}
Expand Down
22 changes: 18 additions & 4 deletions craft_organize.lua
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
-- Organize items in the craft inventory following a pattern:

local ui = unified_inventory

-- Backup to inject code
unified_inventory_plus.craft_organize = unified_inventory.pages["craft"].get_formspec

local function onload()
unified_inventory.pages["craft"] = {
get_formspec = function(player, perplayer_formspec)
local formspecy = perplayer_formspec.formspec_y
local formspec = unified_inventory_plus.craft_organize(player, perplayer_formspec).formspec
for i,v in ipairs(unified_inventory_plus.craft_patterns) do
formspec = formspec.."image_button["..(2.0 + 0.5 * ((i-1)%6))..","..(formspecy - 0.5 * math.ceil(i/6))..";0.5,0.5;"..v.ico..";craft_organize_"..i..";]"
local btnsz = ui.imgscale/3
local btnspc = ui.imgscale/2

if perplayer_formspec.pagecols == 4 then -- UI is in lite mode.
for i,v in ipairs(unified_inventory_plus.craft_patterns) do
formspec = formspec..string.format("image_button[%f,%f;%f,%f;%s;craft_organize_%i;]",
perplayer_formspec.craft_x + btnspc * (i-1),
perplayer_formspec.craft_y + 0.1 - btnspc,
btnsz, btnsz, v.ico, i)
end
else
for i,v in ipairs(unified_inventory_plus.craft_patterns) do
formspec = formspec..string.format("image_button[%f,%f;%f,%f;%s;craft_organize_%i;]",
perplayer_formspec.craft_x + btnspc * ((i-1)%6) + 0.1,
perplayer_formspec.craft_y + 0.22 - (math.ceil(i/6)) * btnspc,
btnsz, btnsz, v.ico, i)
end
end
return {formspec=formspec}
end,
Expand Down
7 changes: 5 additions & 2 deletions craft_rotate.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Rotate items in the craft inventory

local ui = unified_inventory

-- Backup to inject code
unified_inventory_plus.craft_rotate = unified_inventory.pages["craft"].get_formspec
Expand All @@ -9,7 +9,10 @@ local function onload()
get_formspec = function(player, perplayer_formspec)
local formspecy = perplayer_formspec.formspec_y
local formspec = unified_inventory_plus.craft_rotate(player, perplayer_formspec).formspec
formspec = formspec.."image_button[1.25,"..(formspecy)..";0.75,0.75;pattern_rotate.png;craft_rotate;]"
formspec = formspec..string.format("image_button[%f,%f;%f,%f;pattern_rotate.png;craft_rotate;]",
perplayer_formspec.craft_x - perplayer_formspec.btn_spc,
perplayer_formspec.craft_y,
perplayer_formspec.btn_size, perplayer_formspec.btn_size)
return {formspec=formspec}
end,
}
Expand Down
1 change: 1 addition & 0 deletions mod.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
name = unified_inventory_plus
depends = unified_inventory
optional_depends = stamina
min_minetest_version = 5.4.0
Binary file removed textures/ui_crafting_form.png
Binary file not shown.
Binary file added textures/ui_crafting_long_arrow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 74d9135

Please sign in to comment.