Player: create PlayerInventoryUI class & change item count in hotbar (8->9). #34
This commit is contained in:
40
mods/UI/PlayerInventoryUI/src/PlayerInventoryUI.lua
Normal file
40
mods/UI/PlayerInventoryUI/src/PlayerInventoryUI.lua
Normal file
@@ -0,0 +1,40 @@
|
||||
local BaseUI, Formspec = Smc.requireBaseUI(), Smc.requireFormspec()
|
||||
|
||||
---@param self BaseUI
|
||||
---@param playerName string
|
||||
---@return string
|
||||
local function getFormSpecString(self, playerName)
|
||||
local InventoryForm = Formspec:new({
|
||||
size = {x=24, y=8.5},
|
||||
position = {x=0.5, y=0.6},
|
||||
})
|
||||
|
||||
InventoryForm:
|
||||
list('current_player', 'main', 12,0.5, 9,2)
|
||||
|
||||
return InventoryForm:toString()
|
||||
end
|
||||
|
||||
---@class PlayerInventoryUI : BaseUI
|
||||
---@field getFormSpecString fun(self:BaseUI,playerName:string):string
|
||||
---@field showForm fun(self:BaseUI,playerName:string):string
|
||||
local PlayerInventoryUI = BaseUI:new('', getFormSpecString, false)
|
||||
|
||||
--[[
|
||||
---Shows the player their inventory.
|
||||
---@param playerName string
|
||||
function PlayerInventoryUI:showForm(playerName)
|
||||
local player = core.get_player_by_name(playerName)
|
||||
assert(player ~= nil)
|
||||
|
||||
player:set_inventory_formspec(self:getFormSpecString(playerName))
|
||||
core.show_formspec(playerName, '', '')
|
||||
end
|
||||
|
||||
---Closes the player's inventory.
|
||||
---@param playerName string
|
||||
function PlayerInventoryUI:closeForm(playerName)
|
||||
core.close_formspec(playerName, '')
|
||||
end--]]
|
||||
|
||||
return PlayerInventoryUI
|
||||
Reference in New Issue
Block a user