PlayerInventoryUI: item list count button update
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user