From 2a2737f6cb7929625feb3a91309ba1b37f4a4dfa Mon Sep 17 00:00:00 2001 From: LoneWolfHT Date: Tue, 24 Oct 2023 18:07:47 -0700 Subject: [PATCH] Allow saving the order of items in your inv --- mods/ctf/ctf_modebase/player.lua | 105 ++++++++++++++++++ mods/other/crafting/gui.lua | 14 ++- .../crafting/sounds/crafting_save_sound.ogg | Bin 0 -> 7091 bytes .../crafting/textures/crafting_save_icon.png | Bin 0 -> 718 bytes 4 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 mods/other/crafting/sounds/crafting_save_sound.ogg create mode 100644 mods/other/crafting/textures/crafting_save_icon.png diff --git a/mods/ctf/ctf_modebase/player.lua b/mods/ctf/ctf_modebase/player.lua index 0e7f12410b..97cd31abc8 100644 --- a/mods/ctf/ctf_modebase/player.lua +++ b/mods/ctf/ctf_modebase/player.lua @@ -1,5 +1,57 @@ ctf_modebase.player = {} +local simplify_for_saved_stuff = function(iname) + if not iname or iname == "" then return iname end + + if iname:match("default:pick_(%a+)") then + return "pick" + elseif iname:match("default:axe_(%a+)") then + return "axe" + elseif iname:match("default:shovel_(%a+)") then + return "shovel" + elseif iname:match("ctf_mode_nade_fight:") then + return "nade_fight_grenade" + end + + local mod, match = iname:match("(%a+):sword_(%a+)") + + if mod and (mod == "default" or mod == "ctf_melee") and match then + return "sword" + end + + return iname +end + +function ctf_modebase.player.save_initial_stuff_order(player, soft) + if not ctf_modebase.current_mode then return end + + local inv = player:get_inventory() + local meta = player:get_meta() + local ssp = meta:get_string("ctf_modebase:player:initial_stuff_order:"..ctf_modebase.current_mode) + + if ssp == "" then + ssp = {} + else + ssp = minetest.deserialize(ssp) + end + + local done = {} + for i, s in pairs(inv:get_list("main")) do + if s:get_name() ~= "" then + local k = simplify_for_saved_stuff(s:get_name():match("[^%s]*")) + + if not soft or not ssp[k] then + if not done[k] or i < k then + ssp[k] = i + done[k] = true + end + end + end + end + + meta:set_string("ctf_modebase:player:initial_stuff_order:"..ctf_modebase.current_mode, minetest.serialize(ssp)) +end + local function get_initial_stuff(player, f) local mode = ctf_modebase:get_current_mode() if mode and mode.stuff_provider then @@ -19,6 +71,8 @@ function ctf_modebase.player.give_initial_stuff(player) minetest.log("action", "Giving initial stuff to player " .. player:get_player_name()) local inv = player:get_inventory() + local meta = player:get_meta() + local item_level = {} get_initial_stuff(player, function(item) local mode = ctf_modebase:get_current_mode() @@ -57,6 +111,57 @@ function ctf_modebase.player.give_initial_stuff(player) inv:remove_item("main", item) inv:add_item("main", item) end) + + -- Check for new items not yet in the order list + ctf_modebase.player.save_initial_stuff_order(player, true) + + local saved_stuff_positions = meta:get_string("ctf_modebase:player:initial_stuff_order:"..ctf_modebase.current_mode) + + if saved_stuff_positions == "" then + saved_stuff_positions = {} + else + saved_stuff_positions = minetest.deserialize(saved_stuff_positions) + end + + local new = {} + local tmp = {} + local current = inv:get_list("main") + for search, idx in pairs(saved_stuff_positions) do + for sidx, stack in ipairs(current) do + if stack then + local sname = simplify_for_saved_stuff(stack:get_name()) + + if sname ~= "" and sname:match(search) then + tmp[stack] = idx + current[sidx] = false + end + end + end + end + + for stack, idx in pairs(tmp) do + for i = 1, #new+1 do + if new[i] then + if idx < tmp[new[i]] then + table.insert(new, i, stack) + break + end + else + new[i] = stack + break + end + end + end + + for _, stack in ipairs(current) do + if stack then + table.insert(new, stack) + end + end + + inv:set_list("main", new) +end + end function ctf_modebase.player.empty_inv(player) diff --git a/mods/other/crafting/gui.lua b/mods/other/crafting/gui.lua index 44627c6fe4..2e0bbd646d 100644 --- a/mods/other/crafting/gui.lua +++ b/mods/other/crafting/gui.lua @@ -202,7 +202,10 @@ if minetest.global_exists("sfinv") then local formspec = crafting.make_result_selector(player, { x = 8, y = 3 }, context) formspec = formspec .. "list[detached:crafting_trash;main;0,3.4;1,1;]" .. - "image[0.05,3.5;0.8,0.8;crafting_trash_icon.png]" + "image[0.05,3.5;0.8,0.8;crafting_trash_icon.png]" .. + "image_button[1,3.4;1,1;crafting_save_icon.png;save_inv_order;]" .. + "tooltip[save_inv_order;Saves the order of the items in your inventory" .. + "\n(Your saved order is used when you respawn, and is per-mode)]" return sfinv.make_formspec(player, context, formspec, true) end, @@ -210,6 +213,15 @@ if minetest.global_exists("sfinv") then if crafting.result_select_on_receive_results(player, context, fields) then sfinv.set_player_inventory_formspec(player) end + + if fields.save_inv_order then + ctf_modebase.player.save_initial_stuff_order(player) + + minetest.sound_play("crafting_save_sound", { + to_player = player:get_player_name(), + }, true) + end + return true end }) diff --git a/mods/other/crafting/sounds/crafting_save_sound.ogg b/mods/other/crafting/sounds/crafting_save_sound.ogg new file mode 100644 index 0000000000000000000000000000000000000000..4dca8784b36ce8755c36ea4fa5259ddde4732c94 GIT binary patch literal 7091 zcmai22|SeR_djE7!_Z{OsHuj?jL4FSsT4{v2*cQwwX&A6w9?S%Qj(Y?sm3xwNJ6D< zrp2TZQkJ?cT4>Sl*1fJ$lK=CL?(+ZrKA+$3`MmSY^FHT&&Uwx`-*evcysjHJdVmc4 zXmN9=28$XN&ce;XC2i)0M8soLxK-6Z9@&bM4ldwav6X){Y$Zm?%v_Bp)lB}sb_+kn z$O6%QBDQQ==*rzljgAQMlCq~dQq4`xO-(ILEvPhhcvxa+MC?YYeQZ($cXMn^cx(b) z7Ohi9KU=n^qlc%pb8u`}FxM-XyD>PHfTma3dfHnf7K_Z$%}Q4n7yGrI9@Z|wVd2!R z5eb{9n-UVX#4j;1iQKS_yKn<{^N#S?4cy?+gy86fp_^k&l+h~Zh|uuZ_;Bl$D@}27 zQ=6sRt@OfyA|jeOQ(JjmIUE2IK#(3?HE)9>T_h-`Z7&cwV53&k%mP7XD>*dFO!8+( zwFuJ$kOdx%kX<_D7}>$xNH)mk3YigWtxi!D_PGx*3D-vFhsKsSlt;yO(DfBneB}Un z!p1=-U4xBvAsIS*$*B8@!fn$zRm4>?tPrLtnYU5*IGevM%UiqTZAEGJl6SO*E<0u8 zhHjR#S&vs}?a%UoyW%^TuZwmU8!=p6l;M?&^$ti|jo-T{x&E26`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>BpRE7<%j+Qt|=)7_ueSJ`5EAZ)EwAqB0rYM|z$S=s^yH2XH0)+w$?9 zJD)^$Oq%UK$$s?Yyv#PJAPQzW(^PG84MF)W1WgW~nY-BgOu!@l-1dn@i59Cxk9NHn ztyw=m7q;YYvz}a_h8ys`%^2T~c~a;Vzk75@yw83z+G4VK$K?A5-09YCuh-Yi`J%>a XH43saip7~yc%M$2M4-&z5TNjXUH;1} literal 0 HcmV?d00001 diff --git a/mods/other/crafting/textures/crafting_save_icon.png b/mods/other/crafting/textures/crafting_save_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..3f2b05f530386f5d2e6ae0d5a368e91549273fc2 GIT binary patch literal 718 zcmV;<0x|uGP)EX>4Tx04R}tkv&MmKpe$iQ>9WWg6&YmAwzYti;6gwDi*;)X)CnqU~=gfG%+M8 zE{=k0!NHHks)LKOt`4q(Aou~|>f)s6A|?JWDYS_3;J6>}?mh0_0YaNsH83DxK48vDJ&w53`EFipoTgu#A($?F_ESHq=$dR@n^^-ldA?s zj(KcAh2;3b|KNAGW_fDTO$sG}{ukT+7y|;kK)Y$%-^aGyJ^}pCz?IhZZ?u5fPtu!R zEp`M9Z37qAT}|EtE_ZuCsDy00006VoOIv0RI600RN!9r;`8x010qNS#tmY zE+YT{E+YYWr9XB6000McNliru=L#4T8Z!wMV6OlG02y>eSad^gZEa<4bO1wgWnpw> zWFU8GbZ8()Nlj2!fese{005>*L_t(I%VS`m5HK<@FfbSzTmS$0^CtrX0|P^IYd?mf z+Ui2M9E^SK${9um1_lNua&6YqG5JrC0WdJ|2CxvL2wTA7j0IA_wJT>BQM_PoVaLF} zcrF720|SGlxjsWsfCmEu0|Ud=3yciAYA?dom|NIk_rjkW+Zha|GBBKEU|@Lh;ssnh z&fyCK1A_{kya00^F>IK=JHvng0ES~b$QM_a6aWAK07*qoM6N<$g8YUi Ab^rhX literal 0 HcmV?d00001