120 lines
4.5 KiB
Lua
120 lines
4.5 KiB
Lua
local ____lualib = require("lualib_bundle")
|
|
local __TS__ClassExtends = ____lualib.__TS__ClassExtends
|
|
local ____exports = __module.env
|
|
local M__share_base_logger = __MODULE__.Import("share.base.logger", __module)
|
|
local Logger = M__share_base_logger.Logger
|
|
local M__framework_resource_asset_catalog = __MODULE__.Import("framework.resource.asset_catalog", __module)
|
|
local ASSET_KEYS = M__framework_resource_asset_catalog.ASSET_KEYS
|
|
local M__framework_ui_ui_config = __MODULE__.Import("framework.ui.ui_config", __module)
|
|
local RegisterUIConfig = M__framework_ui_ui_config.RegisterUIConfig
|
|
local M__framework_ui_ui_window = __MODULE__.Import("framework.ui.ui_window", __module)
|
|
local UIWindow = M__framework_ui_ui_window.UIWindow
|
|
local M__game_setting_setting_service = __MODULE__.Import("game.setting.setting_service", __module)
|
|
local SETTING_KEYS = M__game_setting_setting_service.SETTING_KEYS
|
|
local logger = Logger("MiniSettingsWindow")
|
|
____exports.MiniSettingsWindow = __TS__DefineClass("MiniSettingsWindow", __module)
|
|
local MiniSettingsWindow = ____exports.MiniSettingsWindow
|
|
MiniSettingsWindow.name = "MiniSettingsWindow"
|
|
__TS__ClassExtends(MiniSettingsWindow, UIWindow)
|
|
function MiniSettingsWindow.prototype.____constructor(self, ...)
|
|
UIWindow.prototype.____constructor(self, ...)
|
|
self.iconLoaded = false
|
|
self.toggleClickCount = 0
|
|
end
|
|
function MiniSettingsWindow.prototype.OnBindWidgets(self)
|
|
self.imgIcon = self:RequireWidget("ImgIcon")
|
|
self.txtStatus = self:RequireWidget("TxtStatus")
|
|
self.btnToggle = self:RequireWidget("BtnToggle")
|
|
self.txtToggleLabel = self:RequireWidget("TxtToggleLabel")
|
|
self.btnClose = self:RequireWidget("BtnClose")
|
|
self:BindButtonClick(
|
|
self.btnToggle,
|
|
function()
|
|
self:HandleToggleClicked()
|
|
end
|
|
)
|
|
self:BindButtonClick(
|
|
self.btnClose,
|
|
function()
|
|
self:Close()
|
|
end
|
|
)
|
|
end
|
|
function MiniSettingsWindow.prototype.OnPreShow(self)
|
|
local settingSvc = self.ctx:GetService("setting")
|
|
if settingSvc ~= nil then
|
|
settingSvc.events.on.OnBoolSettingChanged(
|
|
function(key, _val)
|
|
if key == SETTING_KEYS.SOUND_ENABLED then
|
|
self:RefreshDisplay()
|
|
end
|
|
end,
|
|
self
|
|
)
|
|
end
|
|
self:RefreshDisplay()
|
|
self:LoadIconTexture()
|
|
end
|
|
function MiniSettingsWindow.prototype.LoadIconTexture(self)
|
|
local resSvc = self.ctx:GetService("resource")
|
|
if resSvc == nil then
|
|
return
|
|
end
|
|
resSvc:LoadTextureAsync(
|
|
ASSET_KEYS.MINI_SETTINGS_ICON,
|
|
self,
|
|
function(ok, tex, _lease, err)
|
|
if not ok or tex == nil then
|
|
logger:Warn("Failed to load MiniSettings icon texture", {err = err})
|
|
return
|
|
end
|
|
self.iconLoaded = true
|
|
if self.imgIcon ~= nil and self.imgIcon.SetBrushFromTexture ~= nil then
|
|
self.imgIcon:SetBrushFromTexture(tex, false)
|
|
end
|
|
end
|
|
)
|
|
end
|
|
function MiniSettingsWindow.prototype.HandleToggleClicked(self)
|
|
self.toggleClickCount = self.toggleClickCount + 1
|
|
local settingSvc = self.ctx:GetService("setting")
|
|
if settingSvc ~= nil then
|
|
local nextVal = settingSvc:ToggleSoundEnabled()
|
|
logger:Info("Sound setting toggled", {soundEnabled = nextVal})
|
|
end
|
|
end
|
|
function MiniSettingsWindow.prototype.RefreshDisplay(self)
|
|
local settingSvc = self.ctx:GetService("setting")
|
|
local ____temp_0
|
|
if settingSvc ~= nil then
|
|
____temp_0 = settingSvc:GetSoundEnabled()
|
|
else
|
|
____temp_0 = true
|
|
end
|
|
local soundEnabled = ____temp_0
|
|
local statusText = soundEnabled and "Sound: ON" or "Sound: OFF"
|
|
local btnText = soundEnabled and "Disable Sound" or "Enable Sound"
|
|
if self.txtStatus ~= nil and self.txtStatus.SetText ~= nil then
|
|
self.txtStatus:SetText(statusText)
|
|
end
|
|
if self.txtToggleLabel ~= nil and self.txtToggleLabel.SetText ~= nil then
|
|
self.txtToggleLabel:SetText(btnText)
|
|
end
|
|
end
|
|
RegisterUIConfig(____exports.MiniSettingsWindow, {
|
|
name = "MiniSettingsWindow",
|
|
assetKey = ASSET_KEYS.MINI_SETTINGS_WIDGET,
|
|
singleton = true,
|
|
layer = "popup",
|
|
type = "popup",
|
|
cacheTag = "no_cache",
|
|
blockWorldClick = true
|
|
})
|
|
function __module.UpdateImports()
|
|
Logger = M__share_base_logger.Logger
|
|
ASSET_KEYS = M__framework_resource_asset_catalog.ASSET_KEYS
|
|
RegisterUIConfig = M__framework_ui_ui_config.RegisterUIConfig
|
|
UIWindow = M__framework_ui_ui_window.UIWindow
|
|
SETTING_KEYS = M__game_setting_setting_service.SETTING_KEYS
|
|
end
|