Player: create PlayerInventoryUI class & change item count in hotbar (8->9). #34

This commit is contained in:
Van
2026-03-12 21:43:33 +03:00
parent e359c4be09
commit 145f65d4af
4 changed files with 66 additions and 1 deletions

View File

@@ -0,0 +1,4 @@
local modInfo = Mod.getInfo('smc__ui__player_inventory')
local require = modInfo.require
return require('PlayerInventoryUI')

View File

@@ -0,0 +1,2 @@
name = smc__ui__player_inventory
depends = smc__core__formspec

View 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