From c70bf9673445f7bcbeff21c31deacf4983d9c88c Mon Sep 17 00:00:00 2001 From: Vanic Date: Wed, 18 Feb 2026 22:18:10 +0300 Subject: [PATCH] `BaseUI`: add `showForm` & `closeForm` methods --- mods/CORE/BaseUI/src/BaseUI.lua | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/mods/CORE/BaseUI/src/BaseUI.lua b/mods/CORE/BaseUI/src/BaseUI.lua index 5c16745..3695a4a 100644 --- a/mods/CORE/BaseUI/src/BaseUI.lua +++ b/mods/CORE/BaseUI/src/BaseUI.lua @@ -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 +---@field name string +---@field getFormSpecString fun(self:BaseUI,playerName:string,...):string +---@field contex 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