Compare commits
6 Commits
mapgen-opt
...
44916bcd3b
| Author | SHA1 | Date | |
|---|---|---|---|
| 44916bcd3b | |||
| 3483cd650a | |||
| c4104a1834 | |||
| e98935cf6f | |||
| 338cc7a36b | |||
| 18f06d13d3 |
@@ -24,7 +24,6 @@ function BaseUI:new(name, getFormSpecString, clearContex)
|
||||
instance.getFormSpecString = getFormSpecString
|
||||
|
||||
if clearContex then
|
||||
core.log(name)
|
||||
-- Ensure that when the form is closed, the context is cleared.
|
||||
instance:registerOnFormQuit(function(player)
|
||||
instance:clearContex(player)
|
||||
|
||||
@@ -296,7 +296,7 @@ end
|
||||
---@param w number
|
||||
---@param h number
|
||||
---@param textureName string
|
||||
---@param middle boolean? Makes the image render in 9-sliced mode and defines the middle rect.
|
||||
---@param middle string? Makes the image render in 9-sliced mode and defines the middle rect.
|
||||
---@return Formspec
|
||||
function Formspec:image(x, y, w, h, textureName, middle)
|
||||
local element = ('image[%s,%s;%s,%s;%s;%s]'):format(
|
||||
@@ -441,7 +441,7 @@ end
|
||||
--- * All numbers in middle are integers.
|
||||
---@return Formspec
|
||||
function Formspec:background9(x, y, w, h, textureName, autoClip, middle)
|
||||
local element = ('background9[%s,%s;%s,%s;%s;%s]'):format(
|
||||
local element = ('background9[%s,%s;%s,%s;%s;%s;%s]'):format(
|
||||
x, y, w, h, textureName, autoClip, middle)
|
||||
|
||||
self:addElement(element)
|
||||
|
||||
@@ -4,6 +4,14 @@ local tableCopy, tableMerge, colorize = table.copy, table.merge, core.colorize
|
||||
|
||||
local ItemFactory = Smc.requireItemFactory()
|
||||
|
||||
---Colors the title according to the rarity of the item.
|
||||
---
|
||||
---Note: that if `true`, the `_title_color` will be ignored.
|
||||
local TITLE_RARITY_COLOR = true
|
||||
|
||||
---Shows rarity on a separate line.
|
||||
local SHOW_RARITY = false
|
||||
|
||||
---Determines whether common rarity will be shown in item descriptions or not.
|
||||
local SHOW_COMMON_RARITY = true
|
||||
|
||||
@@ -57,6 +65,10 @@ local Item = {
|
||||
---@param desc string
|
||||
---@return string
|
||||
local function addRarityToDesc(rarity, desc)
|
||||
if not SHOW_RARITY then
|
||||
return desc
|
||||
end
|
||||
|
||||
if not SHOW_COMMON_RARITY and rarity == 'common' then
|
||||
return desc
|
||||
end
|
||||
@@ -98,15 +110,19 @@ local function itemDefToLuantiDef(itemDef)
|
||||
description = string.match(s.name, '%S:(%S+)')..'-desc'
|
||||
end
|
||||
|
||||
assert(s._rarity ~= nil, 'The rarity of an item cannot be empty.')
|
||||
|
||||
if s._title_color ~= nil and s._description_color ~= nil then
|
||||
if TITLE_RARITY_COLOR then
|
||||
title = colorize(RARITY_COLORS[s._rarity], S(title))
|
||||
else
|
||||
title = colorize(s._title_color, S(title))
|
||||
end
|
||||
description = colorize(s._description_color, S(description))
|
||||
else
|
||||
error('Item description color parameters cannot be empty.')
|
||||
end
|
||||
|
||||
assert(s._rarity ~= nil, 'The rarity of an item cannot be empty.')
|
||||
|
||||
local luantiDescription = addRarityToDesc(s._rarity, title..'\n '..description)
|
||||
|
||||
s._title = title
|
||||
|
||||
@@ -64,3 +64,26 @@ function Smc.requireFormspec()
|
||||
return class
|
||||
end
|
||||
|
||||
---@return CraftSystem
|
||||
function Smc.requireCraftSystem()
|
||||
---@type CraftSystem
|
||||
local class = Mod.getInfo('smc__core__craft_system').require('CraftSystem')
|
||||
|
||||
return class
|
||||
end
|
||||
|
||||
---@return CraftSystem.PrimitiveCraftHandler
|
||||
function Smc.requireCraftSystemPrimitiveCraftHandler()
|
||||
---@type CraftSystem.PrimitiveCraftHandler
|
||||
local class = Mod.getInfo('smc__core__craft_system').require('CraftSystem.PrimitiveCraftHandler')
|
||||
|
||||
return class
|
||||
end
|
||||
|
||||
---@return CraftSystem.ImmersiveCraftHandler
|
||||
function Smc.requireCraftSystemImmersiveCraftHandler()
|
||||
---@type CraftSystem.ImmersiveCraftHandler
|
||||
local class = Mod.getInfo('smc__core__craft_system').require('CraftSystem.ImmersiveCraftHandler')
|
||||
|
||||
return class
|
||||
end
|
||||
|
||||
@@ -1,23 +1,83 @@
|
||||
local BaseUI, Formspec = Smc.requireBaseUI(), Smc.requireFormspec()
|
||||
|
||||
---@param self BaseUI
|
||||
local require = Mod.getInfo('smc__ui__player_inventory').require
|
||||
|
||||
---@alias PlayerInventoryUI.PaneType 'left'|'right'
|
||||
---@alias PlayerInventoryUI.getPaneFunc fun(self:PlayerInventoryUI,playerName:string,paneType:PlayerInventoryUI.PaneType):Formspec
|
||||
|
||||
---@alias PlayerInventoryUI.PaneName 'select_pane_menu'|'bag_pane'|'craft_pane'|'equip_pane'|'ref_pane'
|
||||
|
||||
---@type PlayerInventoryUI.getPaneFunc
|
||||
local getSelectPaneMenu = require('PlayerInventoryUI.getSelectPaneMenu')
|
||||
---@type PlayerInventoryUI.getPaneFunc
|
||||
local getBagPane = require('PlayerInventoryUI.getBagPane')
|
||||
---@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,
|
||||
['bag_pane'] = getBagPane,
|
||||
['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
|
||||
---@return string
|
||||
local function getFormSpecString(self, playerName)
|
||||
---@type PlayerInventoryUI.PaneName
|
||||
local leftPaneName = self:getContex(playerName, 'left_pane_name') or 'select_pane_menu'
|
||||
---@type PlayerInventoryUI.PaneName
|
||||
local rightPaneName = self:getContex(playerName, 'right_pane_name') or 'select_pane_menu'
|
||||
|
||||
local leftPaneIsBlock = self:getContex(playerName, 'left_pane_is_block')
|
||||
local rightPaneIsBlock = self:getContex(playerName, 'right_pane_is_block')
|
||||
|
||||
local InventoryForm = Formspec:new({
|
||||
size = {x=24, y=8.5},
|
||||
position = {x=0.5, y=0.6},
|
||||
size = {x=22, y=12},
|
||||
position = {x=0.5, y=0.5},
|
||||
noPrepend = true,
|
||||
})
|
||||
|
||||
|
||||
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):
|
||||
background(0, 9, 22, 3.5, 'player_inventory_middle_background.png', false):
|
||||
container(panes[leftPaneName](self, playerName, 'left'), 0, 0):
|
||||
container(panes[rightPaneName](self, playerName, 'right'), 11, 0):
|
||||
button(10.5, 0, .5, .5, 'close_left_pane', 'x'):
|
||||
button(21.5, 0, .5, .5, 'close_right_pane', 'x')
|
||||
|
||||
return InventoryForm:toString()
|
||||
end
|
||||
|
||||
---@alias PlayerInventoryUI.ContexKey 'left_pane_name'|'right_pane_name'|'left_pane_is_block'|'right_pane_is_block'
|
||||
|
||||
---@class PlayerInventoryUI : BaseUI
|
||||
---@field getFormSpecString fun(self:BaseUI,playerName:string):string
|
||||
---@field showForm fun(self:BaseUI,playerName:string):string
|
||||
---@field getFormSpecString fun(self:PlayerInventoryUI,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)
|
||||
|
||||
--[[
|
||||
@@ -37,4 +97,41 @@ function PlayerInventoryUI:closeForm(playerName)
|
||||
core.close_formspec(playerName, '')
|
||||
end--]]
|
||||
|
||||
PlayerInventoryUI:registerOnFormFieldAction('close_left_pane', function(player, fieldName, fieldValue)
|
||||
local playerName = player:get_player_name()
|
||||
|
||||
PlayerInventoryUI:setContex(playerName, 'left_pane_name', 'select_pane_menu')
|
||||
PlayerInventoryUI:showForm(playerName)
|
||||
end)
|
||||
|
||||
PlayerInventoryUI:registerOnFormFieldActionMatch('select_left_%S+', function(player, fieldName, fieldValue)
|
||||
local paneName = string.match(fieldName, 'select_%S+_(%S+_%S+)')
|
||||
assert(paneName ~= nil)
|
||||
|
||||
local playerName = player:get_player_name()
|
||||
|
||||
PlayerInventoryUI:setContex(playerName, 'left_pane_name', paneName)
|
||||
PlayerInventoryUI:showForm(playerName)
|
||||
player:set_inventory_formspec(PlayerInventoryUI:getFormSpecString(playerName))
|
||||
end)
|
||||
|
||||
PlayerInventoryUI:registerOnFormFieldAction('close_right_pane', function(player, fieldName, fieldValue)
|
||||
local playerName = player:get_player_name()
|
||||
|
||||
PlayerInventoryUI:setContex(playerName, 'right_pane_name', 'select_pane_menu')
|
||||
PlayerInventoryUI:showForm(playerName)
|
||||
player:set_inventory_formspec(PlayerInventoryUI:getFormSpecString(playerName))
|
||||
end)
|
||||
|
||||
PlayerInventoryUI:registerOnFormFieldActionMatch('select_right_%S+', function(player, fieldName, fieldValue)
|
||||
local paneName = string.match(fieldName, 'select_%S+_(%S+_%S+)')
|
||||
assert(paneName ~= nil)
|
||||
|
||||
local playerName = player:get_player_name()
|
||||
|
||||
PlayerInventoryUI:setContex(playerName, 'right_pane_name', paneName)
|
||||
PlayerInventoryUI:showForm(playerName)
|
||||
player:set_inventory_formspec(PlayerInventoryUI:getFormSpecString(playerName))
|
||||
end)
|
||||
|
||||
return PlayerInventoryUI
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
local Formspec = Smc.requireFormspec()
|
||||
|
||||
local BagPane = Formspec:new()
|
||||
|
||||
---@param self PlayerInventoryUI
|
||||
---@param playerName string
|
||||
---@param paneType PlayerInventoryUI.PaneType
|
||||
---@return Formspec
|
||||
local function getBagPane(self, playerName, paneType)
|
||||
BagPane:
|
||||
image(0, 0, 11, 9, 'player_inventory_background_block.png^[colorize:#BF59EE:120'):
|
||||
label(2,2, 'BAG PANE')
|
||||
|
||||
return BagPane
|
||||
end
|
||||
|
||||
return getBagPane
|
||||
@@ -0,0 +1,17 @@
|
||||
local Formspec = Smc.requireFormspec()
|
||||
|
||||
local CraftPane = Formspec:new()
|
||||
|
||||
---@param self PlayerInventoryUI
|
||||
---@param playerName string
|
||||
---@param paneType PlayerInventoryUI.PaneType
|
||||
---@return Formspec
|
||||
local function getCraftPane(self, playerName, paneType)
|
||||
CraftPane:
|
||||
image(0, 0, 11, 9, 'player_inventory_background_block.png^[colorize:#E7CC35:120'):
|
||||
label(2,2, 'CRAFTING PANE')
|
||||
|
||||
return CraftPane
|
||||
end
|
||||
|
||||
return getCraftPane
|
||||
@@ -0,0 +1,17 @@
|
||||
local Formspec = Smc.requireFormspec()
|
||||
|
||||
local EquipPane = Formspec:new()
|
||||
|
||||
---@param self PlayerInventoryUI
|
||||
---@param playerName string
|
||||
---@param paneType PlayerInventoryUI.PaneType
|
||||
---@return Formspec
|
||||
local function getEquipPane(self, playerName, paneType)
|
||||
EquipPane:
|
||||
image(0, 0, 11, 9, 'player_inventory_background_block.png^[colorize:#72FAC6:120'):
|
||||
label(2,2, 'EQUIPMENT PANE')
|
||||
|
||||
return EquipPane
|
||||
end
|
||||
|
||||
return getEquipPane
|
||||
@@ -0,0 +1,17 @@
|
||||
local Formspec = Smc.requireFormspec()
|
||||
|
||||
local RefPane = Formspec:new()
|
||||
|
||||
---@param self PlayerInventoryUI
|
||||
---@param playerName string
|
||||
---@param paneType PlayerInventoryUI.PaneType
|
||||
---@return Formspec
|
||||
local function getRefPane(self, playerName, paneType)
|
||||
RefPane:
|
||||
image(0, 0, 11, 9, 'player_inventory_background_block.png^[colorize:#8072FA:120'):
|
||||
label(2,2, 'REFERENCE PANE')
|
||||
|
||||
return RefPane
|
||||
end
|
||||
|
||||
return getRefPane
|
||||
@@ -0,0 +1,21 @@
|
||||
local Formspec = Smc.requireFormspec()
|
||||
|
||||
local selectPaneMenu = Formspec:new()
|
||||
|
||||
---@param self PlayerInventoryUI
|
||||
---@param playerName string
|
||||
---@param paneType PlayerInventoryUI.PaneType
|
||||
---@return Formspec
|
||||
local function getSelectPaneMenu(self, playerName, paneType)
|
||||
|
||||
selectPaneMenu:
|
||||
image(0, 0, 11, 9, 'player_inventory_background_block.png^[colorize:#FA8072:120'):
|
||||
button(3.5,2.5,2,2,'select_'..paneType..'_bag_pane', 'bag'):
|
||||
button(5.5,2.5,2,2,'select_'..paneType..'_craft_pane', 'craft'):
|
||||
button(3.5,4.5,2,2,'select_'..paneType..'_equip_pane', 'equip'):
|
||||
button(5.5,4.5,2,2,'select_'..paneType..'_ref_pane', 'ref')
|
||||
|
||||
return selectPaneMenu
|
||||
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