From 8951c3f52b73e22eaff79a86281d498a97fbfd12 Mon Sep 17 00:00:00 2001 From: Noodlemire Date: Mon, 16 Jul 2018 19:44:36 -0500 Subject: [PATCH] Add files via upload --- auriinventory/sidebar/callbacks.lua | 39 ++++- auriinventory/sidebar/create_sidebar.lua | 47 +++--- auriinventory/sidebar/init.lua | 4 +- auriinventory/sidebar/recipe_preview.lua | 136 ++++++++++++++---- .../auriinventory_emptyinventoryslot.png | Bin 0 -> 175 bytes .../textures/auriinventory_group.png | Bin 0 -> 777 bytes 6 files changed, 176 insertions(+), 50 deletions(-) create mode 100644 auriinventory/textures/auriinventory_emptyinventoryslot.png create mode 100644 auriinventory/textures/auriinventory_group.png diff --git a/auriinventory/sidebar/callbacks.lua b/auriinventory/sidebar/callbacks.lua index cfc15ee..35c7f70 100644 --- a/auriinventory/sidebar/callbacks.lua +++ b/auriinventory/sidebar/callbacks.lua @@ -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) @@ -89,4 +89,37 @@ ainv.register_callback("*", function(player, fields) return false end -end) \ No newline at end of file +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) diff --git a/auriinventory/sidebar/create_sidebar.lua b/auriinventory/sidebar/create_sidebar.lua index 285aef0..8bb6b76 100644 --- a/auriinventory/sidebar/create_sidebar.lua +++ b/auriinventory/sidebar/create_sidebar.lua @@ -1,11 +1,11 @@ --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 @@ -13,21 +13,20 @@ function ainv.create_sidebar_menu(player, searchbar) 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 @@ -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]" @@ -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 diff --git a/auriinventory/sidebar/init.lua b/auriinventory/sidebar/init.lua index 1e8be3f..d3a947c 100644 --- a/auriinventory/sidebar/init.lua +++ b/auriinventory/sidebar/init.lua @@ -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") \ No newline at end of file +dofile(path .. "/recipe_preview.lua") +dofile(path .. "/callbacks.lua") diff --git a/auriinventory/sidebar/recipe_preview.lua b/auriinventory/sidebar/recipe_preview.lua index 7cb8584..0a1caf2 100644 --- a/auriinventory/sidebar/recipe_preview.lua +++ b/auriinventory/sidebar/recipe_preview.lua @@ -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 \ No newline at end of file + + return fs +end diff --git a/auriinventory/textures/auriinventory_emptyinventoryslot.png b/auriinventory/textures/auriinventory_emptyinventoryslot.png new file mode 100644 index 0000000000000000000000000000000000000000..954b444c2eb57e3b49954cc0e933547fdd651f0a GIT binary patch literal 175 zcmeAS@N?(olHy`uVBq!ia0vp^h9Jzy3?w~+F2@5Ywg8_H*XZczj*gD}e<`nlBAf*t zk;M!Q+`=Ht$S`Y;1W=H@#M9T6{SiC22m|MYt{(5(ej@)Wnk1 z6ovB4k_-iRPv3y>Mm}+%B5_X_#}J9j$v^nnczJkv6b!sB&u(k8XL$S7`m68KA4`Br O7(8A5T-G@yGywp)`7Uz+ literal 0 HcmV?d00001 diff --git a/auriinventory/textures/auriinventory_group.png b/auriinventory/textures/auriinventory_group.png new file mode 100644 index 0000000000000000000000000000000000000000..110f07be52419dd364b0a61b17a5efa49082d43a GIT binary patch literal 777 zcmV+k1NQuhP)e zSad^gZEa<4bO1wgWnpw>WFU8GbZ8()Nlj2!fese{00MDIL_t(o!_Ajnh)q!x$A9;B z-Dc*6E;D7PkO-wDNhXT%MDl{vsCk;zq^R*CnUdzoi<5GS2$@OUdD*9S+d0=cGwxy6sk=I>yMBA^wf|==_{Xb|#aUHbfHq(wund^xo-!~5 zd;wkokAQv=8Tcyzs=5F;1hfN1Yi&(`V@&k(1#k*DD2k5famXoqpNZ5TBaMBAt0&EqLyIHGTRp$ej zfmI^%TfAaIr5_E_zH>6c0Yv0IunssK_df0j_5h9kQHaRxsoZrD83Q`w-W6jCZ+GBx zq@F?)9>Hp$;-&w-h`h}cU~ORc*ISB1fHi^rEN_50fy}$AWrAg98Fk+9|C)E-nZak zkj9mH1KbPjw!8rzyT&qFt*W{tHvkd&37jy-_?5dq&kO(@2Yz@E9jdxHHvkbC1iGVp z?I13x>iS#<6IHzk?23fM7&GoQrQcFWa{<@}T=CoVEK=O*0NY(A%Ep*pV6UoP1^R#i zuPtu`W&%rrR$x1@DCjM-Pe!VG05}Xxiy1hw3@1;3eIoK;GNajCpa