From f34c12c59ff915cb33b5a8b082063740cb7655cc Mon Sep 17 00:00:00 2001 From: Vanic Date: Sun, 19 Apr 2026 20:31:52 +0300 Subject: [PATCH] `PlayerInventoryUI`: add equipment slot overlay --- mods/CORE/Player/mod.conf | 2 +- mods/UI/PlayerInventoryUI/mod.conf | 2 +- .../src/PlayerInventoryUI.lua | 60 +++++++++++++++++ .../src/PlayerInventoryUI/getEquipTab.lua | 61 +++++++----------- ...ry_equip_tab_armor_slots_overlay_sheet.png | Bin 0 -> 4341 bytes 5 files changed, 84 insertions(+), 41 deletions(-) create mode 100644 mods/UI/PlayerInventoryUI/textures/sheets/player_inventory_equip_tab_armor_slots_overlay_sheet.png diff --git a/mods/CORE/Player/mod.conf b/mods/CORE/Player/mod.conf index 2d8650d..88337b5 100644 --- a/mods/CORE/Player/mod.conf +++ b/mods/CORE/Player/mod.conf @@ -1,2 +1,2 @@ name = smc__core__player -depends = smc__system__system_loader +depends = smc__system__system_loader, smc__ui__player_inventory diff --git a/mods/UI/PlayerInventoryUI/mod.conf b/mods/UI/PlayerInventoryUI/mod.conf index 3af568a..13904b7 100644 --- a/mods/UI/PlayerInventoryUI/mod.conf +++ b/mods/UI/PlayerInventoryUI/mod.conf @@ -1,2 +1,2 @@ name = smc__ui__player_inventory -depends = smc__core__formspec +depends = smc__core__formspec, smc__core__tilesheet diff --git a/mods/UI/PlayerInventoryUI/src/PlayerInventoryUI.lua b/mods/UI/PlayerInventoryUI/src/PlayerInventoryUI.lua index 77e16c8..62bef6d 100644 --- a/mods/UI/PlayerInventoryUI/src/PlayerInventoryUI.lua +++ b/mods/UI/PlayerInventoryUI/src/PlayerInventoryUI.lua @@ -449,4 +449,64 @@ PlayerInventoryUI:registerOnFormFieldActionMatch('.+::craft_item', function(play end end) +-- We only allow items to be placed in equipment slot +-- that have groups that match the slot name and index. +core.register_allow_player_inventory_action(function(player, action, inventory, inventoryInfo) + if action == 'move' then + -- Checking if a slot is an equipment slot. + local equipGroup = string.match(inventoryInfo.to_list, 'equip_%S+') + if equipGroup == nil then + return + end + + -- We receive the item that the player wants to place in the equipment slot. + local itemStack = inventory:get_stack(inventoryInfo.from_list, inventoryInfo.from_index) + assert(itemStack ~= nil) + + if core.get_item_group(itemStack:get_name(), equipGroup) == inventoryInfo.to_index then + return + else + return 0 + end + elseif action == 'put' then + -- Checking if a slot is an equipment slot. + local equipGroup = string.match(inventoryInfo.listname, 'equip_%S+') + if equipGroup == nil then + return + end + + -- We receive the item that the player wants to place in the equipment slot. + local itemStack = inventory:get_stack(inventoryInfo.listname, inventoryInfo.index) + assert(itemStack ~= nil) + + if core.get_item_group(itemStack:get_name(), equipGroup) == inventoryInfo.index then + return + else + return 0 + end + end +end) + +-- Update the interface if the player has moved something from the equipment slots +-- (this enables and disables the slot overlay). +core.register_on_player_inventory_action(function(player, action, inventory, inventoryInfo) + local playerName = player:get_player_name() + if action == 'move' then + local equipGroup = string.match(inventoryInfo.to_list, 'equip_%S+') or string.match(inventoryInfo.from_list, 'equip_%S+') + if equipGroup ~= nil then + PlayerInventoryUI:showForm(playerName) + end + elseif action == 'put' then + local equipGroup = string.match(inventoryInfo.listname, 'equip_%S+') + if equipGroup ~= nil then + PlayerInventoryUI:showForm(playerName) + end + elseif action == 'take' then + local equipGroup = string.match(inventoryInfo.listname, 'equip_%S+') + if equipGroup ~= nil then + PlayerInventoryUI:showForm(playerName) + end + end +end) + return PlayerInventoryUI diff --git a/mods/UI/PlayerInventoryUI/src/PlayerInventoryUI/getEquipTab.lua b/mods/UI/PlayerInventoryUI/src/PlayerInventoryUI/getEquipTab.lua index 80b734d..8210474 100644 --- a/mods/UI/PlayerInventoryUI/src/PlayerInventoryUI/getEquipTab.lua +++ b/mods/UI/PlayerInventoryUI/src/PlayerInventoryUI/getEquipTab.lua @@ -1,4 +1,6 @@ -local Formspec = Smc.requireFormspec() +local Formspec, TileSheet = Smc.requireFormspec(), Smc.requireTileSheet() + +local slotsOverlayTileSheet = TileSheet:new('player_inventory_equip_tab_armor_slots_overlay_sheet.png', 16, 16) ---@param self PlayerInventoryUI ---@param playerName string @@ -20,45 +22,26 @@ local function getEquipTab(self, playerName, tabType) :list('current_player', 'equip_legs', equipListsX, 3.5, 2, 1) :list('current_player', 'equip_feet', equipListsX, 4.75, 2, 1) + local player = core.get_player_by_name(playerName) + assert(player) + + local inv = player:get_inventory() + + -- If the equipment slots are empty, then we apply an overlay. + if inv:get_stack('equip_head', 2):is_empty() then + EquipTab:image(equipListsX+1.25, 1, 1, 1, slotsOverlayTileSheet:t(0,0)) + end + if inv:get_stack('equip_torso', 2):is_empty() then + EquipTab:image(equipListsX+1.25, 2.25, 1, 1, slotsOverlayTileSheet:t(0,1)) + end + if inv:get_stack('equip_legs', 2):is_empty() then + EquipTab:image(equipListsX+1.25, 3.5, 1, 1, slotsOverlayTileSheet:t(0,2)) + end + if inv:get_stack('equip_feet', 2):is_empty() then + EquipTab:image(equipListsX+1.25, 4.75, 1, 1, slotsOverlayTileSheet:t(0,3)) + end + return EquipTab end --- We only allow items to be placed in equipment slot --- that have groups that match the slot name and index. -core.register_allow_player_inventory_action(function(player, action, inventory, inventoryInfo) - if action == 'move' then - -- Checking if a slot is an equipment slot. - local equipGroup = string.match(inventoryInfo.to_list, 'equip_%S+') - if equipGroup == nil then - return - end - - -- We receive the item that the player wants to place in the equipment slot. - local itemStack = inventory:get_stack(inventoryInfo.from_list, inventoryInfo.from_index) - assert(itemStack ~= nil) - - if core.get_item_group(itemStack:get_name(), equipGroup) == inventoryInfo.to_index then - return - else - return 0 - end - elseif action == 'put' then - -- Checking if a slot is an equipment slot. - local equipGroup = string.match(inventoryInfo.listname, 'equip_%S+') - if equipGroup == nil then - return - end - - -- We receive the item that the player wants to place in the equipment slot. - local itemStack = inventory:get_stack(inventoryInfo.listname, inventoryInfo.index) - assert(itemStack ~= nil) - - if core.get_item_group(itemStack:get_name(), equipGroup) == inventoryInfo.index then - return - else - return 0 - end - end -end) - return getEquipTab diff --git a/mods/UI/PlayerInventoryUI/textures/sheets/player_inventory_equip_tab_armor_slots_overlay_sheet.png b/mods/UI/PlayerInventoryUI/textures/sheets/player_inventory_equip_tab_armor_slots_overlay_sheet.png new file mode 100644 index 0000000000000000000000000000000000000000..472d81e1d8a812554a26e97c16481b3e6ddac395 GIT binary patch literal 4341 zcmeHIO-NKx6h1TR%sAuEnv8Xwf1F!GZ{)N3>}rZ6c_p zn_L75LAXhmtz3vgf=e+5#$Zs#pTzEW^t;~o8gUav;DL9~z4v_QJ3sfn_g>z}_EpC( z#YLogpuc7 zMWf&hjfVn~p!hOingAgxOF`OrTsw(u2Hb$g5tfSPVmS8^;DVq|)(#R9A$qWZAn_4k z10XaLBqS=8I+3zFvAw-5o12?D$NDTO0|3rw zSbKZBEH5uhMMXu%G;_{%uBxi?lF4Kykw|2=wzjOzo&s+ijx8Jx3miy*Iri|HBM`HN zT?ugZymdUfpfm3S1JSMoIC~P{7DD#-_leQFL1N$#kirZ+mjp)B2Vzu{7zDslY!A3W z%?zM<6Y1<;C`&*PQza2I;XZM+TLLx-sk$jL6ZVLX)Rq7naCRF+5D8&tAliHcOq0f- zE@ig_h#X8mNKk5R31Gyh8*+GfD7(A6o-U3Dlu@cg`!c!U;5-_QdZEw}6sLeMR}k|b zuYc=7DwWduOcS-Nvpz090yuYcbjbSpy6ws0;-bz?BUOXgCA9=}o}Hbw4(W7SR#sL7 zq!f^Ylq9}i8$pQXItNLKgSG_ueBLuaueY~X?Q|lTq%4X1wghb8+Xo=(tgEY&jg1Y( zwYIjZURzt!J*JOMn}H(CfYc!XLqLeAB-Tx5umn6lIx;%2$flv8LEX?)lYymB0-gYN z(Pe<#h~___8A0=YkU@VeWo2cVcs#Dm$N(=4qZ}L@NNsJcX3)~oqW^_lE|)15i*q2c yB?P<6Mxn88IdF2b@SOsTr-}Qg0)_!j!~ebgrU&nbCg%%Hh&a%b?f%d;_WTzQq}A>K literal 0 HcmV?d00001