BaseUI: Clearing the context is now an optional parameter & edit /list command. close #33
This commit is contained in:
@@ -10,18 +10,26 @@ local BaseUI = {
|
||||
contex = {}
|
||||
}
|
||||
|
||||
---@param name string
|
||||
---@param name string The name of the formspec that will be shown to the player. It is recommended that the name be unique.
|
||||
---@param getFormSpecString fun(self:BaseUI,playerName:string,...):string
|
||||
function BaseUI:new(name, getFormSpecString)
|
||||
---@param clearContex boolean? Whether to clear the context stored for a player when that player closes the form. Default `true`.
|
||||
function BaseUI:new(name, getFormSpecString, clearContex)
|
||||
if clearContex == nil then
|
||||
clearContex = true
|
||||
end
|
||||
|
||||
---@type BaseUI
|
||||
local instance = getInstance(self, {})
|
||||
instance.name = name
|
||||
instance.getFormSpecString = getFormSpecString
|
||||
|
||||
-- Ensure that when the form is closed, the context is cleared.
|
||||
instance:registerOnFormQuit(function(player)
|
||||
instance:clearContex(player)
|
||||
end)
|
||||
if clearContex then
|
||||
core.log(name)
|
||||
-- Ensure that when the form is closed, the context is cleared.
|
||||
instance:registerOnFormQuit(function(player)
|
||||
instance:clearContex(player)
|
||||
end)
|
||||
end
|
||||
|
||||
return instance
|
||||
end
|
||||
|
||||
@@ -10,7 +10,7 @@ core.register_chatcommand('list', {
|
||||
func = function(name, param)
|
||||
local player = core.get_player_by_name(name)
|
||||
|
||||
AdminListUI:showForm(name, false)
|
||||
AdminListUI:showForm(name)
|
||||
|
||||
return true, ''
|
||||
end
|
||||
@@ -27,7 +27,7 @@ AdminListUI:registerOnFormFieldActionMatch('%S+::item_button',function(player, f
|
||||
local playerName = player:get_player_name()
|
||||
AdminListUI:setContex(playerName, 'select_item', stack)
|
||||
|
||||
AdminListUI:showForm(playerName, true)
|
||||
AdminListUI:showForm(playerName)
|
||||
end)
|
||||
|
||||
AdminListUI:registerOnFormFieldAction('admin_commands:list_add_item', function(player, fieldName, fieldValue)
|
||||
@@ -47,8 +47,8 @@ end)
|
||||
core.register_on_joinplayer(function(player, last_login)
|
||||
player:set_sky({
|
||||
sky_color = {
|
||||
day_sky = '#FAE6E0',
|
||||
day_horizon = '#E7A985',
|
||||
day_sky = '#FCF0ED',
|
||||
day_horizon = '#F1D4C3',
|
||||
},
|
||||
type = 'regular',
|
||||
})
|
||||
|
||||
@@ -2,9 +2,15 @@ local BaseUI, Formspec = Smc.requireBaseUI(), Smc.requireFormspec()
|
||||
|
||||
---@param self BaseUI
|
||||
---@param playerName string
|
||||
---@param isSelect boolean
|
||||
---@param isSelect boolean?
|
||||
---@return string
|
||||
local function getFormSpecString(self, playerName, isSelect)
|
||||
if isSelect == nil and self:getContex(playerName, 'select_item') ~= nil then
|
||||
isSelect = true
|
||||
else
|
||||
isSelect = false
|
||||
end
|
||||
|
||||
local items = {}
|
||||
|
||||
for name, def in pairs(core.registered_items) do
|
||||
@@ -58,9 +64,9 @@ local function getFormSpecString(self, playerName, isSelect)
|
||||
end
|
||||
|
||||
---@class AdminListUI : BaseUI
|
||||
---@field getFormSpecString fun(self:BaseUI,playerName:string,isSelect:boolean):string
|
||||
---@field showForm fun(self:BaseUI,playerName:string,isSelect:boolean):string
|
||||
local AdminListUI = BaseUI:new('admin_commands:list_form', getFormSpecString)
|
||||
---@field getFormSpecString fun(self:BaseUI,playerName:string,isSelect:boolean?):string
|
||||
---@field showForm fun(self:BaseUI,playerName:string,isSelect:boolean?):string
|
||||
local AdminListUI = BaseUI:new('admin_commands:list_form', getFormSpecString, false)
|
||||
|
||||
AdminListUI:registerOnFormFieldAction('admin_commands:list_items', function(player, fieldName, fieldValue)
|
||||
local scrollValue = string.match(fieldValue, 'CHG:(%S+)')
|
||||
|
||||
Reference in New Issue
Block a user