|
|
|
|
@@ -1,23 +1,78 @@
|
|
|
|
|
local BaseUI, Formspec = Smc.requireBaseUI(), Smc.requireFormspec()
|
|
|
|
|
|
|
|
|
|
---@param self BaseUI
|
|
|
|
|
local require = Mod.getInfo('smc__ui__player_inventory').require
|
|
|
|
|
|
|
|
|
|
---@alias PlayerInventoryUI.getPaneFunc fun(self:PlayerInventoryUI,playerName:string):string
|
|
|
|
|
|
|
|
|
|
---@alias PlayerInventoryUI.PaneName 'select_pane_menu'|'craft_pane'|'equip_pane'|'ref_pane'
|
|
|
|
|
|
|
|
|
|
---@type PlayerInventoryUI.getPaneFunc
|
|
|
|
|
local getSelectPaneMenu = require('PlayerInventoryUI.getSelectPaneMenu')
|
|
|
|
|
---@type PlayerInventoryUI.getPaneFunc
|
|
|
|
|
local getCraftPane = require('PlayerInventoryUI.getCraftPane')
|
|
|
|
|
---@type PlayerInventoryUI.getPaneFunc
|
|
|
|
|
local getEquipPane = require('PlayerInventoryUI.getEquipPane')
|
|
|
|
|
---@type PlayerInventoryUI.getPaneFunc
|
|
|
|
|
local getRefPane = require('PlayerInventoryUI.getRefPane')
|
|
|
|
|
|
|
|
|
|
---@type table<PlayerInventoryUI.PaneName, PlayerInventoryUI.getPaneFunc>
|
|
|
|
|
local panes = {
|
|
|
|
|
['select_pane_menu'] = getSelectPaneMenu,
|
|
|
|
|
['craft_pane'] = getCraftPane,
|
|
|
|
|
['equip_pane'] = getEquipPane,
|
|
|
|
|
['ref_pane'] = getRefPane,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
---@param paneName PlayerInventoryUI.PaneName
|
|
|
|
|
local function getPane(paneName)
|
|
|
|
|
if paneName == nil then
|
|
|
|
|
---@type PlayerInventoryUI.PaneName
|
|
|
|
|
paneName = 'select_pane_menu'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local pane = panes[paneName]
|
|
|
|
|
assert(pane ~= nil, ('The pane with the `%s` does not exist.'):format(paneName))
|
|
|
|
|
|
|
|
|
|
return pane
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
---@param self PlayerInventoryUI
|
|
|
|
|
---@param playerName string
|
|
|
|
|
---@return string
|
|
|
|
|
local function getFormSpecString(self, playerName)
|
|
|
|
|
---@type PlayerInventoryUI.PaneName
|
|
|
|
|
local leftPaneName = self:getContex(playerName, 'left_pane_name')
|
|
|
|
|
---@type PlayerInventoryUI.PaneName
|
|
|
|
|
local rightPaneName = self:getContex(playerName, 'right_pane_name')
|
|
|
|
|
|
|
|
|
|
local leftPaneIsBlock = self:getContex(playerName, 'left_pane_is_block')
|
|
|
|
|
local rightPaneIsBlock = self:getContex(playerName, 'right_pane_is_block')
|
|
|
|
|
|
|
|
|
|
local InventoryForm = Formspec:new({
|
|
|
|
|
size = {x=24, y=8.5},
|
|
|
|
|
position = {x=0.5, y=0.6},
|
|
|
|
|
size = {x=22, y=12},
|
|
|
|
|
position = {x=0.5, y=0.5},
|
|
|
|
|
noPrepend = true,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
InventoryForm:
|
|
|
|
|
list('current_player', 'main', 12,0.5, 9,2)
|
|
|
|
|
--bgcolor('#00000000'):
|
|
|
|
|
listColors('#00000000', '#C4C4C433'):
|
|
|
|
|
list('current_player', 'main', 5.5,9.5, 9,2):
|
|
|
|
|
image(0, 0, 11, 9, 'player_inventory_background_block.png'):
|
|
|
|
|
image(11, 0, 11, 9, 'player_inventory_background_block.png'):
|
|
|
|
|
background(0, 9, 22, 3.5, 'player_inventory_middle_background.png', false):
|
|
|
|
|
button(10.5, 0, .5, .5, 'close_left_pane', 'x'):
|
|
|
|
|
button(21.5, 0, .5, .5, 'close_right_pane', 'x')
|
|
|
|
|
|
|
|
|
|
return InventoryForm:toString()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
---@alias PlayerInventoryUI.ContexKey 'left_pane_name'|'right_pane_name'|'left_pane_is_block'|'right_pane_is_block'
|
|
|
|
|
|
|
|
|
|
---@class PlayerInventoryUI : BaseUI
|
|
|
|
|
---@field getFormSpecString fun(self:BaseUI,playerName:string):string
|
|
|
|
|
---@field showForm fun(self:BaseUI,playerName:string):string
|
|
|
|
|
---@field getFormSpecString fun(self:PlayerInventoryUI,playerName:string):string
|
|
|
|
|
---@field showForm fun(self:PlayerInventoryUI,playerName:string):string
|
|
|
|
|
---@field getContex fun(self:PlayerInventoryUI,player:string|Player,key:PlayerInventoryUI.ContexKey):any
|
|
|
|
|
local PlayerInventoryUI = BaseUI:new('', getFormSpecString, false)
|
|
|
|
|
|
|
|
|
|
--[[
|
|
|
|
|
@@ -37,4 +92,8 @@ function PlayerInventoryUI:closeForm(playerName)
|
|
|
|
|
core.close_formspec(playerName, '')
|
|
|
|
|
end--]]
|
|
|
|
|
|
|
|
|
|
PlayerInventoryUI:registerOnFormFieldAction('close_left_pane', function(player, fieldName, fieldValue)
|
|
|
|
|
core.log(fieldName)
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
return PlayerInventoryUI
|
|
|
|
|
|