Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 36 additions & 3 deletions auriinventory/sidebar/callbacks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ ainv.register_callback("*", function(player, fields)
ainv.playerdata[name].lastspawntime = minetest.get_us_time()/1000000.0;
end
else --Recipe mode
ainv.playerdata[name].recipe_item = ind
ainv.playerdata[name].recipe_index = 1
ainv.playerdata[name].recipe_index = ind
ainv.playerdata[name].recipe_items = {}

ainv.show_recipe_preview(player)
ainv.reloadInventory(player)
Expand Down Expand Up @@ -89,4 +89,37 @@ ainv.register_callback("*", function(player, fields)
return false

end
end)
end)

--Recipe Previews--
ainv.register_callback("*", function(player, fields)
if fields.recipepreview_next then
local recipe_page = ainv.playerdata[player:get_player_name()]["recipe_page"] or 1
local recipe_amount = #ainv.playerdata[player:get_player_name()].recipe_items or 1

if recipe_page < recipe_amount then
ainv.playerdata[player:get_player_name()]["recipe_page"] = recipe_page + 1
end

ainv.reloadInventory(player)

return false
elseif fields.recipepreview_prev then
local recipe_page = ainv.playerdata[player:get_player_name()]["recipe_page"] or 1

if recipe_page > 1 then
ainv.playerdata[player:get_player_name()]["recipe_page"] = recipe_page - 1
end

ainv.reloadInventory(player)

return false
end
end)

--Quick Craft--
ainv.register_callback("*", function(player, fields)
if fields.quickcraft then

end
end)
47 changes: 28 additions & 19 deletions auriinventory/sidebar/create_sidebar.lua
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
--Calculate Sidebar size
ainv.sidebar_width = 7
ainv.sidebar_height = 17
ainv.sidebar_width = 9
ainv.sidebar_height = 10
ainv.sidebar_inv_size = ainv.sidebar_width * ainv.sidebar_height

local xorigin = -0.5
local xorigin = -2.0

function ainv.create_sidebar_menu(player, searchbar)
function ainv.create_sidebar_menu(player, searchbar, recipe_fs)
if not ainv.items_loaded then return "" end

--Item Iterator
local page = ainv.playerdata[player:get_player_name()].sidebar_page
local index = page * ainv.sidebar_inv_size + 1

--Cheat mode button
local cheat_button =
"image_button[-0.5,-2.46;0.5,0.5;auriinventory_small_icon_06.png;togglecheat;;true;false;auriinventory_small_icon_07.png]" .. --Cheat button
"image_button[-0.2,-2.42;1.6,0.5;auriinventory_blank.png;togglecheat_label;Recipe Mode;true;false;auriinventory_blank.png]" --Cheat button label
local cheat_button =
"image_button["..(xorigin-0.05)..",0.01;0.5,0.5;auriinventory_small_icon_06.png;togglecheat;;true;false;auriinventory_small_icon_07.png]" .. --Cheat button
"image_button["..(xorigin+0.35)..",0.05;1.8,0.5;auriinventory_blank.png;togglecheat_label;Recipe Mode;true;false;auriinventory_blank.png]" --Cheat label

if ainv.playerdata[player:get_player_name()].cheating then
cheat_button =
"image_button[-0.5,-2.46;0.5,0.5;auriinventory_small_icon_08.png;togglecheat;;true;false;auriinventory_small_icon_09.png]" .. --Cheat button
"image_button[-0.2,-2.42;1.6,0.5;auriinventory_blank.png;togglecheat_label;Cheat Mode;true;false;auriinventory_blank.png]" --Cheat button label
"image_button["..(xorigin-0.05)..",0.01;0.5,0.5;auriinventory_small_icon_08.png;togglecheat;;true;false;auriinventory_small_icon_09.png]" .. --Recipe button
"image_button["..(xorigin+0.35)..",0.05;1.8,0.5;auriinventory_blank.png;togglecheat_label;Cheat Mode;true;false;auriinventory_blank.png]" --Recipe label
end

local fs =
"container[18,0]" .. --Container
"box[-0.95,-2.6;6,13.3;#0001]".. --Background
cheat_button ..
"image_button[1.75,-2.48;2.5,0.6;auriinventory_blank.png;togglesearch;Toggle Search;true;true;auriinventory_blank.png]" --Search button
"image_button["..(xorigin+3.15)..",0.0;2.7,0.6;auriinventory_blank.png;togglesearch;Toggle Search;true;true;auriinventory_blank.png]" --Search button

--Create buttons
for j = 0, ainv.sidebar_height - 1 do
Expand All @@ -44,15 +43,20 @@ function ainv.create_sidebar_menu(player, searchbar)
if minetest.registered_items[name].description ~= "" then
tooltip = minetest.registered_items[name].description .. "\n(" .. name .. ")"
end
tooltip = tooltip .. "\n\nClick to Spawn\nDouble-Click for Stack"

if ainv.playerdata[player:get_player_name()].cheating then
tooltip = tooltip .. "\n\nClick to Spawn\nDouble-Click for Stack"
else
tooltip = tooltip .. "\n\nClick to view Recipe"
end

--Add elements
fs = fs ..
--Invisible button
"image_button[" .. (xorigin + i*0.65) .. "," .. (-2.0 + j*0.7) .. ";0.8,0.8;" ..
"image_button[" .. (xorigin - 0.12 + i*0.65) .. "," .. (0.53 + j*0.7) .. ";0.8,0.8;" ..
"auriinventory_blank.png;sidebar_item_" .. index .. ";;true;false;auriinventory_hover.png]" ..
--Image for button
"item_image[" .. (xorigin - 0.01 + i*0.65) .. "," .. (-2.02 + j*0.7) .. ";0.8,0.8;" .. name .. "]" ..
"item_image[" .. (xorigin - 0.13 + i*0.65) .. "," .. (0.53 + j*0.7) .. ";0.8,0.8;" .. name .. "]" ..
--Tooltip for button
"tooltip[sidebar_item_" .. index .. ";" .. tooltip .. ";#33333399;#fff]"

Expand All @@ -64,12 +68,17 @@ function ainv.create_sidebar_menu(player, searchbar)

--Bottom navigation
fs = fs ..
"image_button[" .. xorigin .. ",9.95;0.7,0.8;auriinventory_recipebook_icon_6.png;sidebar_firstpage;;true;false;auriinventory_recipebook_icon_7.png]" ..
"image_button[" .. (xorigin + 0.5) .. ",9.95;0.7,0.8;auriinventory_recipebook_icon_0.png;sidebar_prevpage;;true;false;auriinventory_recipebook_icon_1.png]" ..
"image_button[" .. (xorigin + 1.2) .. ",9.86;2.5,1;auriinventory_blank.png;regitemslabel;Registered Items (" .. page+1 .. "/" .. math.floor((ainv.itemcount-1)/ainv.sidebar_inv_size)+1 .. ");true;false;auriinventory_blank.png]" ..
"image_button[" .. (xorigin + 3.6) .. ",9.95;0.7,0.8;auriinventory_recipebook_icon_2.png;sidebar_nextpage;;true;false;auriinventory_recipebook_icon_3.png]" ..
"image_button[" .. (xorigin + 4.1) .. ",9.95;0.7,0.8;auriinventory_recipebook_icon_8.png;sidebar_lastpage;;true;false;auriinventory_recipebook_icon_9.png]" ..
"image_button[" .. (xorigin - 0.1) .. ",7.46;0.75,1.0;auriinventory_recipebook_icon_6.png;sidebar_firstpage;;true;false;auriinventory_recipebook_icon_7.png]" ..
"image_button[" .. (xorigin + 0.5) .. ",7.46;0.75,1.0;auriinventory_recipebook_icon_0.png;sidebar_prevpage;;true;false;auriinventory_recipebook_icon_1.png]" ..
"image_button[" .. (xorigin + 1.45) .. ",7.5;2.9,1;auriinventory_blank.png;regitemslabel;Registered Items (" .. page+1 .. "/"
.. math.floor((ainv.itemcount-1)/ainv.sidebar_inv_size)+1 .. ");true;false;auriinventory_blank.png]" ..
"image_button[" .. (xorigin + 4.5) .. ",7.46;0.75,1.0;auriinventory_recipebook_icon_2.png;sidebar_nextpage;;true;false;auriinventory_recipebook_icon_3.png]" ..
"image_button[" .. (xorigin + 5.1) .. ",7.46;0.75,1.0;auriinventory_recipebook_icon_8.png;sidebar_lastpage;;true;false;auriinventory_recipebook_icon_9.png]" ..
"container_end[]" --End container

if player:get_inventory():get_list("recipepreview") then
fs = fs .. ainv.gen_formspec_recipe(player)
end

return fs
end
4 changes: 2 additions & 2 deletions auriinventory/sidebar/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,5 @@ end

local path = minetest.get_modpath("auriinventory") .. "/sidebar"
dofile(path .. "/create_sidebar.lua")
-- dofile(path .. "/recipe_preview.lua")
dofile(path .. "/callbacks.lua")
dofile(path .. "/recipe_preview.lua")
dofile(path .. "/callbacks.lua")
136 changes: 110 additions & 26 deletions auriinventory/sidebar/recipe_preview.lua
Original file line number Diff line number Diff line change
@@ -1,41 +1,125 @@
--Use this to get the name of the first item in a given group or list of groups, or "" if no item is found in the given group
local function get_first_item_in_group(groupname)
local groupnametable = {}
local lastCommaIndex = 0

for i = 2, #groupname do
if groupname:sub(i,i) == ',' then
table.insert(groupnametable, groupname:sub(lastCommaIndex+1, i-1))
lastCommaIndex = i
end
end
if lastCommaIndex ~= #groupname then table.insert(groupnametable, groupname:sub(lastCommaIndex+1)) end

for k,v in pairs(minetest.registered_items) do
local still_in_all_groups = true

for n,g in pairs(groupnametable) do
if minetest.get_item_group(k, g) == 0 then
still_in_all_groups = false
end
end

if still_in_all_groups then
return k
end
end

return ""
end

function ainv.show_recipe_preview(player)
local playerdata = ainv.playerdata[player:get_player_name()]
local item = ainv.items[playerdata.recipe_item]

local item = ainv.items[playerdata.recipe_index]
local recipes = minetest.get_all_craft_recipes(item)
if recipes then
player:get_inventory():set_stack("recipepreview", 10, item)

if recipes[playerdata.recipe_index] then
ainv.playerdata[player:get_player_name()]["recipe_page"] = 1

if recipes[playerdata.recipe_index].width > 3 then
--Give up on life
return false
end
if recipes and #recipes > 0 then
for h = 1, #recipes do
ainv.playerdata[player:get_player_name()].recipe_items[h] = {{}, {}, {}}

local grid = {{}, {}, {}}
local recipe_width = recipes[h].width
if recipes[h] then
if recipe_width > 3 then
--Give up on life
return false
end

if #recipes[playerdata.recipe_index].items > 0 then
for i, v in pairs(recipes[playerdata.recipe_index].items) do
if v then
if recipes[playerdata.recipe_index].width and recipes[playerdata.recipe_index].width ~= 0 then
grid[math.ceil(i / recipes[playerdata.recipe_index].width)][(i-1) % recipes[playerdata.recipe_index].width + 1] = v
else
grid[math.ceil(i / 3)][(i-1) % 3 + 1] = v
if #recipes[h].items > 0 then
for i, v in pairs(recipes[h].items) do
if v then
if recipe_width and recipe_width ~= 0 then
ainv.playerdata[player:get_player_name()].recipe_items[h][math.ceil(i / recipe_width)][(i-1) % recipe_width + 1] = v
else
ainv.playerdata[player:get_player_name()].recipe_items[h][math.ceil(i / 3)][(i-1) % 3 + 1] = v
end
end
end

ainv.reloadInventory(player)
end
for i = 1, 3 do
for j = 1, 3 do
player:get_inventory():set_stack("recipepreview", (i-1)*3 + j, grid[i][j])
end
end
end
else
ainv.playerdata[player:get_player_name()].recipe_index = -1
ainv.playerdata[player:get_player_name()].recipe_items = {}
end
end

function ainv.gen_formspec_recipe(player)
local recipe_index = ainv.playerdata[player:get_player_name()]["recipe_page"] or 1
local fs = "size[3,3]"
local player_inv = player:get_inventory()
local recipe_to_display = ainv.playerdata[player:get_player_name()].recipe_items or {}
local recipe_amount = #recipe_to_display

if #recipe_to_display > 0 and recipe_to_display[recipe_index] and #recipe_to_display[recipe_index] > 0 then
for i = 1, 3 do
for n = 1, 3 do
local itemname
local item_is_group = false

if recipe_to_display[recipe_index][i] and recipe_to_display[recipe_index][i][n] then
itemname = recipe_to_display[recipe_index][i][n]
else
itemname = ""
end

--Make Tooltip
local tooltip = itemname
if minetest.registered_items[itemname] and minetest.registered_items[itemname].description ~= "" then
tooltip = minetest.registered_items[itemname].description .. "\n(" .. itemname .. ")"
end

minetest.show_formspec(player:get_player_name(), "recipe", ainv.gen_formspec_recipe(player))
--minetest.log("itemname = "..itemname)

if itemname:sub(1,6) == "group:" then
local itemsub = itemname:sub(7)
itemname = get_first_item_in_group(itemsub)
item_is_group = true
end

--minetest.log("real item name = "..itemname)

fs = fs.."image_button["..(n-0.5)..","..(i-1.0)..";1.0,1.0;auriinventory_emptyinventoryslot.png;recprevbutton_"..((i-1)*3+n)..";;;]"
.."item_image["..(n-0.5)..","..(i-1.0)..";1.0,1.0;"..itemname.."]"

if item_is_group then
fs = fs.."image["..(n-0.5)..","..(i-1.0)..";1.0,1.0;auriinventory_group.png]"
end

fs = fs.."tooltip[recprevbutton_"..((i-1)*3+n)..";".. tooltip..";#33333399;#fff]"
end
end
else
ainv.playerdata[player:get_player_name()].recipe_item = -1
player:get_inventory():set_list("recipepreview", {})

fs = fs..
"image_button[0.5,3.0;0.75,1.0;auriinventory_recipebook_icon_0.png;recipepreview_prev;;true;false;auriinventory_recipebook_icon_1.png]"..
"image_button[2.75,3.0;0.75,1.0;auriinventory_recipebook_icon_2.png;recipepreview_next;;true;false;auriinventory_recipebook_icon_3.png]"..
"label[1.5,3.0;Recipe]"..
"label[1.75,3.5;"..(recipe_index).."/"..(recipe_amount).."]"..
"image_button[0.7,4.0;2.7,0.6;auriinventory_blank.png;quickcraft;Quick Craft;true;true;auriinventory_blank.png]"
end
end

return fs
end
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added auriinventory/textures/auriinventory_group.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.