Player: create PlayerInventoryUI class & change item count in hotbar (8->9). #34
This commit is contained in:
@@ -1,4 +1,23 @@
|
|||||||
---@class Player
|
---@class Player
|
||||||
local Player = {}
|
local Player = {}
|
||||||
|
|
||||||
return Player
|
---@type PlayerInventoryUI
|
||||||
|
local PlayerInventoryUI = Mod.getInfo('smc__ui__player_inventory').require('PlayerInventoryUI')
|
||||||
|
|
||||||
|
core.register_on_joinplayer(function(player)
|
||||||
|
player:set_inventory_formspec(PlayerInventoryUI:getFormSpecString(player:get_player_name()))
|
||||||
|
player:hud_set_hotbar_itemcount(9)
|
||||||
|
local inv = player:get_inventory()
|
||||||
|
inv:set_size('main', 18)
|
||||||
|
end)
|
||||||
|
|
||||||
|
core.register_chatcommand('show_inv',
|
||||||
|
{
|
||||||
|
func = function(name, param)
|
||||||
|
PlayerInventoryUI:showForm(name)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
return Player
|
||||||
|
|||||||
4
mods/UI/PlayerInventoryUI/init.lua
Normal file
4
mods/UI/PlayerInventoryUI/init.lua
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
local modInfo = Mod.getInfo('smc__ui__player_inventory')
|
||||||
|
local require = modInfo.require
|
||||||
|
|
||||||
|
return require('PlayerInventoryUI')
|
||||||
2
mods/UI/PlayerInventoryUI/mod.conf
Normal file
2
mods/UI/PlayerInventoryUI/mod.conf
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
name = smc__ui__player_inventory
|
||||||
|
depends = smc__core__formspec
|
||||||
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