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 0000000..472d81e Binary files /dev/null and b/mods/UI/PlayerInventoryUI/textures/sheets/player_inventory_equip_tab_armor_slots_overlay_sheet.png differ