From 9fa3a0aff757ecf1377550233fddcc8e8f1d006c Mon Sep 17 00:00:00 2001 From: varttist Date: Tue, 17 Nov 2026 21:29:34 +0300 Subject: [PATCH] `PlayerInventoryUI`: item list count button update --- .../PlayerInventoryUI/actionHandling/adminList.lua | 9 ++++++--- .../src/PlayerInventoryUI/actionHandling/crafts.lua | 11 +++++++---- .../src/PlayerInventoryUI/baseGetCraftTab.lua | 4 ++-- .../src/PlayerInventoryUI/getAdminListTab.lua | 4 ++-- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/mods/UI/PlayerInventoryUI/src/PlayerInventoryUI/actionHandling/adminList.lua b/mods/UI/PlayerInventoryUI/src/PlayerInventoryUI/actionHandling/adminList.lua index b4d08b6..0354f60 100644 --- a/mods/UI/PlayerInventoryUI/src/PlayerInventoryUI/actionHandling/adminList.lua +++ b/mods/UI/PlayerInventoryUI/src/PlayerInventoryUI/actionHandling/adminList.lua @@ -2,6 +2,7 @@ local PlayerInventoryUI = ... local assert = assert +local tonumber = tonumber local stringMatch = string.match local coreCheckPlayerPrivs = core.check_player_privs @@ -13,9 +14,11 @@ local ItemStack = ItemStack -- Handling the addition of an item from the admin list. -- If the player does not have the 'give' privilege, nothing will happen. -PlayerInventoryUI:registerOnFormFieldActionMatch('%S+::add_item', function(player, fieldName, fieldValue) - local tabType = stringMatch(fieldName, '(%S+)::add_item') +PlayerInventoryUI:registerOnFormFieldActionMatch('%S+::add_item::%S+', function(player, fieldName, fieldValue) + local tabType, count = stringMatch(fieldName, '(%S+)::add_item::(%S+)') assert(tabType == 'left' or tabType == 'right') + count = tonumber(count) + assert(count ~= nil) local playerName = player:get_player_name() if not coreCheckPlayerPrivs(playerName, 'give') then @@ -28,7 +31,7 @@ PlayerInventoryUI:registerOnFormFieldActionMatch('%S+::add_item', function(playe local craftListTabData = PlayerInventoryUI:getAdminListTabData(playerName, tabType) local stack = ItemStack(craftListTabData.selectedItem) - stack:set_count(fieldValue) + stack:set_count(count) ---@type InvRef local inventory = player:get_inventory() diff --git a/mods/UI/PlayerInventoryUI/src/PlayerInventoryUI/actionHandling/crafts.lua b/mods/UI/PlayerInventoryUI/src/PlayerInventoryUI/actionHandling/crafts.lua index 7f650aa..3612c7e 100644 --- a/mods/UI/PlayerInventoryUI/src/PlayerInventoryUI/actionHandling/crafts.lua +++ b/mods/UI/PlayerInventoryUI/src/PlayerInventoryUI/actionHandling/crafts.lua @@ -3,6 +3,7 @@ local PlayerInventoryUI = ... local ipairs = ipairs local assert = assert +local tonumber = tonumber local stringMatch = string.match local SmcPutOrDrop = Smc.putOrDrop @@ -52,10 +53,12 @@ end) -- they are removed and the crafted item is added to the inventory. -- -- Note: Materials are only searched in the player's main inventory. -PlayerInventoryUI:registerOnFormFieldActionMatch('%S+::%S+::craft_item', function(player, fieldName, fieldValue) - local tabType, tabName = stringMatch(fieldName, '(%S+)::(%S+)::craft_item') +PlayerInventoryUI:registerOnFormFieldActionMatch('%S+::%S+::craft_item::%S+', function(player, fieldName, fieldValue) + local tabType, tabName, count = stringMatch(fieldName, '(%S+)::(%S+)::craft_item::(%S+)') assert(tabType == 'left' or tabType == 'right') assert(tabName == 'craft_tab' or tabName == 'node_tab') + count = tonumber(count) + assert(count ~= nil) local playerName = player:get_player_name() @@ -68,7 +71,7 @@ PlayerInventoryUI:registerOnFormFieldActionMatch('%S+::%S+::craft_item', functio assert(recipeIndex ~= nil) local craft = handler:getCraftByName(craftName) - local allowCrafting, materialStacks = CraftSystem:checkPossiblePlayerInventoryCrafting(player, craft, recipeIndex, fieldValue) + local allowCrafting, materialStacks = CraftSystem:checkPossiblePlayerInventoryCrafting(player, craft, recipeIndex, count) if allowCrafting and handler.baseType == 'primitive' then ---@type CraftSystem.PrimitiveCraft craft = craft @@ -85,7 +88,7 @@ PlayerInventoryUI:registerOnFormFieldActionMatch('%S+::%S+::craft_item', functio local inventory = player:get_inventory() local nodePos = PlayerInventoryUI:getContex(playerName, 'node_tab_pos') - local isCraftStart = craft:startCraft(nodePos, player, fieldValue) + local isCraftStart = craft:startCraft(nodePos, player, count) if not isCraftStart then return end diff --git a/mods/UI/PlayerInventoryUI/src/PlayerInventoryUI/baseGetCraftTab.lua b/mods/UI/PlayerInventoryUI/src/PlayerInventoryUI/baseGetCraftTab.lua index 441df3f..4fd4c1d 100644 --- a/mods/UI/PlayerInventoryUI/src/PlayerInventoryUI/baseGetCraftTab.lua +++ b/mods/UI/PlayerInventoryUI/src/PlayerInventoryUI/baseGetCraftTab.lua @@ -136,8 +136,8 @@ local function getCraftTabTemplate(self, playerName, tabType, tabName, handler) :label(13, 1.75, ('%s/%s'):format(recipeIndex, #craftsByOutput)) :textArea(8, 4, 5, 4, nil, nil, craft:toString(mainList)) :button(8.25, 7.5, 0.5, 1, tabType..'::'..tabName..'::alt_recipe_back', '<') - :button(8.75, 7.5, 2, 1, tabType..'::'..tabName..'::craft_item', '1') - :button(10.75, 7.5,2, 1, tabType..'::'..tabName..'::craft_item', ''..tostring(itemDef.stack_max)) + :button(8.75, 7.5, 2, 1, tabType..'::'..tabName..'::craft_item::'..'1', '1') + :button(10.75, 7.5,2, 1, tabType..'::'..tabName..'::craft_item::'..tostring(itemDef.stack_max), tostring(itemDef.stack_max)) :button(12.75, 7.5, 0.5, 1, tabType..'::'..tabName..'::alt_recipe_forward', '>') end diff --git a/mods/UI/PlayerInventoryUI/src/PlayerInventoryUI/getAdminListTab.lua b/mods/UI/PlayerInventoryUI/src/PlayerInventoryUI/getAdminListTab.lua index 104ac46..b2cf88c 100644 --- a/mods/UI/PlayerInventoryUI/src/PlayerInventoryUI/getAdminListTab.lua +++ b/mods/UI/PlayerInventoryUI/src/PlayerInventoryUI/getAdminListTab.lua @@ -97,8 +97,8 @@ local function getAdminListTab(self, playerName, tabType) AdminListTab :itemImage(8, 1.5, 2, 2, selectedItem) :textArea(8, 4, 5, 4, nil, nil, selectedItem) - :button(8.75, 7.5, 2, 1, tabType..'::add_item', '1') - :button(10.75, 7.5,2, 1, tabType..'::add_item', ''..tostring(itemDef.stack_max)) + :button(8.75, 7.5, 2, 1, tabType..'::add_item::'..'1', '1') + :button(10.75, 7.5,2, 1, tabType..'::add_item::'..tostring(itemDef.stack_max), ''..tostring(itemDef.stack_max)) end return AdminListTab