BaseUI: add showForm & closeForm methods
This commit is contained in:
@@ -3,17 +3,20 @@ local getInstance = Class.getInstance
|
||||
---@class BaseUI
|
||||
---Context for transferring data between displaying
|
||||
---the form spec to the player and handling callbacks.
|
||||
---@field name string
|
||||
---@field contex table<string, table>
|
||||
---@field name string
|
||||
---@field getFormSpecString fun(self:BaseUI,playerName:string,...):string
|
||||
---@field contex table<string, table>
|
||||
local BaseUI = {
|
||||
contex = {}
|
||||
}
|
||||
|
||||
---@param name string
|
||||
function BaseUI:new(name)
|
||||
---@param name string
|
||||
---@param getFormSpecString fun(self:BaseUI,playerName:string,...):string
|
||||
function BaseUI:new(name, getFormSpecString)
|
||||
---@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)
|
||||
@@ -103,4 +106,17 @@ function BaseUI:registerOnFormFieldActionMatch( fieldNamePattern, callback)
|
||||
Smc.registerOnFormFieldActionMatch(self.name, fieldNamePattern, callback)
|
||||
end
|
||||
|
||||
---Shows the player the FormSpec registered by the instance of this UI.
|
||||
---@param playerName string
|
||||
function BaseUI:showForm(playerName, ...)
|
||||
core.show_formspec(playerName, self.name, self:getFormSpecString(playerName, ...))
|
||||
end
|
||||
|
||||
---Close the player the FormSpec registered by the instance of this UI.
|
||||
---@param playerName string
|
||||
function BaseUI:closeForm(playerName)
|
||||
core.close_formspec(playerName, self.name)
|
||||
end
|
||||
|
||||
|
||||
return BaseUI
|
||||
|
||||
Reference in New Issue
Block a user