PlayerInventoryUI: Draft version of the player inventory and pane templates. #34
This commit is contained in:
@@ -1,23 +1,78 @@
|
|||||||
local BaseUI, Formspec = Smc.requireBaseUI(), Smc.requireFormspec()
|
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
|
---@param playerName string
|
||||||
---@return string
|
---@return string
|
||||||
local function getFormSpecString(self, playerName)
|
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({
|
local InventoryForm = Formspec:new({
|
||||||
size = {x=24, y=8.5},
|
size = {x=22, y=12},
|
||||||
position = {x=0.5, y=0.6},
|
position = {x=0.5, y=0.5},
|
||||||
|
noPrepend = true,
|
||||||
})
|
})
|
||||||
|
|
||||||
InventoryForm:
|
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()
|
return InventoryForm:toString()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@alias PlayerInventoryUI.ContexKey 'left_pane_name'|'right_pane_name'|'left_pane_is_block'|'right_pane_is_block'
|
||||||
|
|
||||||
---@class PlayerInventoryUI : BaseUI
|
---@class PlayerInventoryUI : BaseUI
|
||||||
---@field getFormSpecString fun(self:BaseUI,playerName:string):string
|
---@field getFormSpecString fun(self:PlayerInventoryUI,playerName:string):string
|
||||||
---@field showForm fun(self:BaseUI,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)
|
local PlayerInventoryUI = BaseUI:new('', getFormSpecString, false)
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
@@ -37,4 +92,8 @@ function PlayerInventoryUI:closeForm(playerName)
|
|||||||
core.close_formspec(playerName, '')
|
core.close_formspec(playerName, '')
|
||||||
end--]]
|
end--]]
|
||||||
|
|
||||||
|
PlayerInventoryUI:registerOnFormFieldAction('close_left_pane', function(player, fieldName, fieldValue)
|
||||||
|
core.log(fieldName)
|
||||||
|
end)
|
||||||
|
|
||||||
return PlayerInventoryUI
|
return PlayerInventoryUI
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
local Formspec = Smc.requireFormspec()
|
||||||
|
|
||||||
|
local CraftPane = Formspec:new()
|
||||||
|
|
||||||
|
---@param self PlayerInventoryUI
|
||||||
|
---@param playerName string
|
||||||
|
---@return string
|
||||||
|
local function getCraftPane(self, playerName)
|
||||||
|
|
||||||
|
|
||||||
|
return CraftPane:toString()
|
||||||
|
end
|
||||||
|
|
||||||
|
return getCraftPane
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
local Formspec = Smc.requireFormspec()
|
||||||
|
|
||||||
|
local EquipPane = Formspec:new()
|
||||||
|
|
||||||
|
---@param self PlayerInventoryUI
|
||||||
|
---@param playerName string
|
||||||
|
---@return string
|
||||||
|
local function getEquipPane(self, playerName)
|
||||||
|
|
||||||
|
|
||||||
|
return EquipPane:toString()
|
||||||
|
end
|
||||||
|
|
||||||
|
return getEquipPane
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
local Formspec = Smc.requireFormspec()
|
||||||
|
|
||||||
|
local RefPane = Formspec:new()
|
||||||
|
|
||||||
|
---@param self PlayerInventoryUI
|
||||||
|
---@param playerName string
|
||||||
|
---@return string
|
||||||
|
local function getRefPane(self, playerName)
|
||||||
|
|
||||||
|
|
||||||
|
return RefPane:toString()
|
||||||
|
end
|
||||||
|
|
||||||
|
return getRefPane
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
local Formspec = Smc.requireFormspec()
|
||||||
|
|
||||||
|
local selectPaneMenu = Formspec:new()
|
||||||
|
|
||||||
|
---@param self PlayerInventoryUI
|
||||||
|
---@param playerName string
|
||||||
|
---@return string
|
||||||
|
local function getSelectPaneMenu(self, playerName)
|
||||||
|
|
||||||
|
|
||||||
|
return selectPaneMenu:toString()
|
||||||
|
end
|
||||||
|
|
||||||
|
return getSelectPaneMenu
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 266 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 199 B |
Binary file not shown.
|
After Width: | Height: | Size: 77 KiB |
Reference in New Issue
Block a user