diff --git a/mods/CORE/Player/src/Player.lua b/mods/CORE/Player/src/Player.lua index 5882400..7e6d042 100644 --- a/mods/CORE/Player/src/Player.lua +++ b/mods/CORE/Player/src/Player.lua @@ -1,4 +1,23 @@ ---@class Player local Player = {} -return Player \ No newline at end of file +---@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 diff --git a/mods/UI/PlayerInventoryUI/init.lua b/mods/UI/PlayerInventoryUI/init.lua new file mode 100644 index 0000000..3154432 --- /dev/null +++ b/mods/UI/PlayerInventoryUI/init.lua @@ -0,0 +1,4 @@ +local modInfo = Mod.getInfo('smc__ui__player_inventory') +local require = modInfo.require + +return require('PlayerInventoryUI') diff --git a/mods/UI/PlayerInventoryUI/mod.conf b/mods/UI/PlayerInventoryUI/mod.conf new file mode 100644 index 0000000..3af568a --- /dev/null +++ b/mods/UI/PlayerInventoryUI/mod.conf @@ -0,0 +1,2 @@ +name = smc__ui__player_inventory +depends = smc__core__formspec diff --git a/mods/UI/PlayerInventoryUI/src/PlayerInventoryUI.lua b/mods/UI/PlayerInventoryUI/src/PlayerInventoryUI.lua new file mode 100644 index 0000000..834e4b7 --- /dev/null +++ b/mods/UI/PlayerInventoryUI/src/PlayerInventoryUI.lua @@ -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