PlayerInventory & PlayerInventoryUI: Completion of work on a sane version of the crafting menu. #34
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
local modInfo = Mod.getInfo('smc__core__player')
|
||||
local require = modInfo.require
|
||||
|
||||
return require('Player')
|
||||
return require('Player')
|
||||
|
||||
@@ -3,23 +3,43 @@ local PrimitiveCraftHandler = Smc.requireCraftSystemPrimitiveCraftHandler()
|
||||
---@type PlayerInventoryUI
|
||||
local PlayerInventoryUI = Mod.getInfo('smc__ui__player_inventory').require('PlayerInventoryUI')
|
||||
|
||||
PlayerInventoryUI:registerOnFormFieldActionMatch('%S+::%S+::item_button',function(player, fieldName, fieldValue)
|
||||
local craftName, paneType = string.match(fieldName, '(%S+)::(%S+)::item_button')
|
||||
-- Handling the button click for selecting an item for crafting.
|
||||
-- Opens the item description and allows you to craft the selected item.
|
||||
PlayerInventoryUI:registerOnFormFieldActionMatch('.+::%S+::item_button',function(player, fieldName, fieldValue)
|
||||
local craftName, paneType = string.match(fieldName, '(.+)::(%S+)::item_button')
|
||||
assert(craftName ~= nil)
|
||||
assert(paneType == 'left' or paneType == 'right')
|
||||
|
||||
local playerName = player:get_player_name()
|
||||
PlayerInventoryUI:setContex(playerName, paneType..'_pane_craft_selected_craft', craftName)
|
||||
player:set_inventory_formspec(PlayerInventoryUI:getFormSpecString(playerName))
|
||||
PlayerInventoryUI:showForm(playerName)
|
||||
end)
|
||||
|
||||
PlayerInventoryUI:registerOnFormFieldActionMatch('%S+::craft_item', function(player, fieldName, fieldValue)
|
||||
-- Handling the click of the crafting group selection button.
|
||||
-- Causes grouped items to be expanded into a separate list.
|
||||
PlayerInventoryUI:registerOnFormFieldActionMatch('.+::%S+::group_button',function(player, fieldName, fieldValue)
|
||||
local groupName, paneType = string.match(fieldName, '(.+)::(%S+)::group_button')
|
||||
assert(groupName ~= nil)
|
||||
assert(paneType == 'left' or paneType == 'right')
|
||||
|
||||
local playerName = player:get_player_name()
|
||||
PlayerInventoryUI:setContex(playerName, paneType..'_pane_craft_selected_group', groupName)
|
||||
PlayerInventoryUI:showForm(playerName)
|
||||
end)
|
||||
|
||||
Smc.registerGlobalStepForEachPlayer(1, function(deltaTime, player)
|
||||
local playerName = player:get_player_name()
|
||||
if Smc.getActiveFormspec(playerName) == '' then
|
||||
player:set_inventory_formspec(PlayerInventoryUI:getFormSpecString(playerName))
|
||||
end
|
||||
end)
|
||||
|
||||
PlayerInventoryUI:registerOnFormFieldActionMatch('.+::craft_item', function(player, fieldName, fieldValue)
|
||||
---@type InvRef
|
||||
local inv = player:get_inventory()
|
||||
|
||||
local playerName = player:get_player_name()
|
||||
local paneType = string.match(fieldName, '(%S+)::craft_item')
|
||||
local paneType = string.match(fieldName, '(.+)::craft_item')
|
||||
assert(paneType == 'left' or paneType == 'right')
|
||||
|
||||
local craftName = PlayerInventoryUI:getContex(playerName, paneType..'_pane_craft_selected_craft')
|
||||
|
||||
Reference in New Issue
Block a user