diff --git a/mods/CORE/Player/src/Player.lua b/mods/CORE/Player/src/Player.lua index 5eae71e..b2be420 100644 --- a/mods/CORE/Player/src/Player.lua +++ b/mods/CORE/Player/src/Player.lua @@ -14,6 +14,7 @@ core.register_on_joinplayer(function(player) inv:set_size('equip_torso', 2) inv:set_size('equip_legs', 2) inv:set_size('equip_feet', 2) + inv:set_size('listring_equip', 1) -- Slot for correct listring. end) core.register_chatcommand('show_inv', diff --git a/mods/GAME/ITEMS/equipment/init.lua b/mods/GAME/ITEMS/equipment/init.lua index 51a12c4..dae0a1f 100644 --- a/mods/GAME/ITEMS/equipment/init.lua +++ b/mods/GAME/ITEMS/equipment/init.lua @@ -31,3 +31,34 @@ Item:new({ } } }) + +Item:new({ + settings = { + name = 'bronze_knee_pads', + inventory_image = EquipTileSheet:t(2, 2), + groups = { + equip_legs = 2 + } + } +}) + +Item:new({ + settings = { + name = 'steel_boots', + inventory_image = EquipTileSheet:t(3, 3), + groups = { + equip_feet = 2 + } + } +}) + +Item:new({ + settings = { + name = 'steel_helmet', + inventory_image = EquipTileSheet:t(3, 0), + groups = { + equip_head = 2 + } + } +}) + diff --git a/mods/UI/PlayerInventoryUI/src/PlayerInventoryUI.lua b/mods/UI/PlayerInventoryUI/src/PlayerInventoryUI.lua index 62bef6d..0a41a5a 100644 --- a/mods/UI/PlayerInventoryUI/src/PlayerInventoryUI.lua +++ b/mods/UI/PlayerInventoryUI/src/PlayerInventoryUI.lua @@ -449,10 +449,78 @@ PlayerInventoryUI:registerOnFormFieldActionMatch('.+::craft_item', function(play end end) +---Automatically places equipment items into their corresponding slots. +---@param player Player +---@param inventory InvRef +---@param fromList string +---@param fromIndex integer +local function equipListring(player, inventory, fromList, fromIndex) + local itemStack = inventory:get_stack(fromList, fromIndex) + assert(itemStack ~= nil) + local playerName = player:get_player_name() + + -- We check whether the item has a group that matches the equipment slot. + -- If so, we move the item to the slot. + -- + -- We also check if the target slot is empty. + -- If it's already occupied, we prevent items from being moved. + -- + -- TODO: дописать автолистринг для одежды + if core.get_item_group(itemStack:get_name(), 'equip_head') == 2 then + if not inventory:get_stack('equip_head', 2):is_empty() then + return 0 + end + inventory:set_stack('equip_head', 2, itemStack) + inventory:set_stack(fromList, fromIndex, nil) + PlayerInventoryUI:showForm(playerName) + return + + elseif core.get_item_group(itemStack:get_name(), 'equip_torso') == 2 then + if not inventory:get_stack('equip_torso', 2):is_empty() then + return 0 + end + inventory:set_stack('equip_torso', 2, itemStack) + inventory:set_stack(fromList, fromIndex, nil) + PlayerInventoryUI:showForm(playerName) + return + + elseif core.get_item_group(itemStack:get_name(), 'equip_legs') == 2 then + if not inventory:get_stack('equip_legs', 2):is_empty() then + return 0 + end + inventory:set_stack('equip_legs', 2, itemStack) + inventory:set_stack(fromList, fromIndex, nil) + PlayerInventoryUI:showForm(playerName) + return + + elseif core.get_item_group(itemStack:get_name(), 'equip_feet') == 2 then + if not inventory:get_stack('equip_feet', 2):is_empty() then + return 0 + end + inventory:set_stack('equip_feet', 2, itemStack) + inventory:set_stack(fromList, fromIndex, nil) + PlayerInventoryUI:showForm(playerName) + return + + else + -- If an item does not have any equipment groups, + -- then we prohibit its movement (the item remains in its original location) + return 0 + 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 + -- If the move occurs in a special slot, then we add the item to the desired slot. + -- This is necessary to bypass the standard listring[] limitation. + -- Equipment items will automatically place themselves in their slots + -- when you hold down the shift key. + if inventoryInfo.to_list == 'listring_equip' then + return equipListring(player, inventory, inventoryInfo.from_list, inventoryInfo.from_index) + end + -- Checking if a slot is an equipment slot. local equipGroup = string.match(inventoryInfo.to_list, 'equip_%S+') if equipGroup == nil then @@ -490,7 +558,7 @@ 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() + 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 diff --git a/mods/UI/PlayerInventoryUI/src/PlayerInventoryUI/getEquipTab.lua b/mods/UI/PlayerInventoryUI/src/PlayerInventoryUI/getEquipTab.lua index 8210474..87eb595 100644 --- a/mods/UI/PlayerInventoryUI/src/PlayerInventoryUI/getEquipTab.lua +++ b/mods/UI/PlayerInventoryUI/src/PlayerInventoryUI/getEquipTab.lua @@ -21,6 +21,22 @@ local function getEquipTab(self, playerName, tabType) :list('current_player', 'equip_torso', equipListsX, 2.25, 2, 1) :list('current_player', 'equip_legs', equipListsX, 3.5, 2, 1) :list('current_player', 'equip_feet', equipListsX, 4.75, 2, 1) + -- Hidden equipment slot for correct listing + -- (distribute equipment across its slots while holding shift): + :list('current_player', 'listring_equip', 0, 0, 1, 1) + :listring({ + {'current_player', 'main'}, + {'current_player', 'listring_equip'}, + {'current_player', 'main'}, + {'current_player', 'equip_head'}, + {'current_player', 'main'}, + {'current_player', 'equip_torso'}, + {'current_player', 'main'}, + {'current_player', 'equip_legs'}, + {'current_player', 'main'}, + {'current_player', 'equip_feet'}, + {'current_player', 'main'}, + }) local player = core.get_player_by_name(playerName) assert(player) @@ -28,6 +44,7 @@ local function getEquipTab(self, playerName, tabType) local inv = player:get_inventory() -- If the equipment slots are empty, then we apply an overlay. + -- TODO: оверлей одежды if inv:get_stack('equip_head', 2):is_empty() then EquipTab:image(equipListsX+1.25, 1, 1, 1, slotsOverlayTileSheet:t(0,0)) end