hengyang_client/lua_probject/base_project/Game/View/SettingView.lua

209 lines
6.2 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

--设置窗口对象
--author--
local TableBG = import 'Game.Data.TableBG'
local SettingView = {}
local M = SettingView
setmetatable(M, { __index = BaseWindow })
function SettingView.new(blur_view)
local self = setmetatable({}, { __index = M })
self.class = 'SettingView'
self._currenIndex = 0
self._blur_view = blur_view
self.onCallback = event('onCallback', true)
self.stateIndex = 0
self.cd_time = 0
self._btn_dismiss_room_enable = true
self._close_destroy = true
self._default_bg = 0
self:init('ui://Common/SettingWindow1')
return self
end
function M:init(url)
BaseWindow.init(self, url)
local view = self._view
local slider_sound = view:GetChild('slider_sound')
local slider_music = view:GetChild('slider_music')
local btn_music = view:GetChild('btn_music')
local btn_sound = view:GetChild('btn_sound')
btn_music.selected = (GameApplication.Instance.MusicValue < 5 and false or true)
slider_sound.value = GameApplication.Instance.SoundValue
slider_music.value = GameApplication.Instance.MusicValue
btn_sound.selected = GameApplication.Instance.SoundValue < 5 and false or true
slider_music.onChanged:Add(
function()
GameApplication.Instance.MusicValue = slider_music.value
btn_music.selected = GameApplication.Instance.MusicValue < 5 and false or true
end
)
slider_sound.onChanged:Add(
function()
GameApplication.Instance.SoundValue = slider_sound.value
btn_sound.selected = GameApplication.Instance.SoundValue < 5 and false or true
end
)
btn_sound.onChanged:Add(
function()
GameApplication.Instance.SoundValue = btn_sound.selected and 50 or 0
slider_sound.value = GameApplication.Instance.SoundValue
end
)
btn_music.onChanged:Add(
function()
GameApplication.Instance.MusicValue = btn_music.selected and 50 or 0
slider_music.value = GameApplication.Instance.MusicValue
end
)
self._stateController = view:GetController('state')
self.cd_time_text = view:GetChild('n35')
local _btn_quit = view:GetChild('btn_quit')
if _btn_quit then
_btn_quit.onClick:Set(
function()
local _curren_msg = MsgWindow.new(self._root_view, '您是否退出游戏?', MsgWindow.MsgMode.OkAndCancel)
_curren_msg.onOk:Add(
function()
Application.Quit()
end
)
_curren_msg:Show()
end
)
end
local _btn_logout = view:GetChild('btn_logout')
if _btn_logout then
_btn_logout.onClick:Add(
function()
local _curren_msg = MsgWindow.new(self._root_view, '您是否退出当前账号?', MsgWindow.MsgMode.OkAndCancel)
_curren_msg.onOk:Add(
function()
-- PlayerPrefs.DeleteKey('session_id')
-- PlayerPrefs.Save()
RestartGame()
end
)
_curren_msg:Show()
end
)
end
local _btn_dismiss_room = view:GetChild('btn_dismiss_room')
self._btn_dismiss_room = _btn_dismiss_room
if _btn_dismiss_room then
_btn_dismiss_room.onClick:Add(
function()
local _gamectr = ControllerManager.GetController(GameController)
_gamectr:AskDismissRoom()
self:Destroy()
end
)
end
local btn_close = self._view:GetChild("btn_close")
if btn_close then
btn_close.onClick:Add(function(...)
end)
end
end
--赋值bg_config
function M:GetBGConfig()
return TableBG.GetBGConfig()
end
--获得背景
function M:GetBgByGameId(game_id)
return TableBG.GetTableBG(game_id)
end
--显示背景选项,并加载背景
function M:FillBgSection(cb, game_id, default_bg, bg_config)
local view = self._view
local lst_bg = view:GetChild('lst_bg')
local ctr_bg = view:GetController('bg')
bg_config = bg_config or self:GetBGConfig()
for i = 1, #bg_config do
local config = bg_config[i]
local item = lst_bg:AddItemFromPool()
item.icon = config.thumb
--printlog("显示背景选项,并加载背景",item.icon)
item.data = config
if i > 6 then
ctr_bg:AddPage(i - 1)
end
item.onClick:Add(
function(index)
cb(config.url, i)
end
)
end
self._game_id = game_id
self._default_bg = default_bg
self._bg = self:GetBgByGameId(game_id)
if self._bg > 0 then
lst_bg.selectedIndex = self._bg - 1
else
lst_bg.selectedIndex = default_bg - 1
end
end
function M:Show()
self._stateController.selectedIndex = self.stateIndex
BaseWindow.Show(self)
if self.cd_coroutine ~= nil then
coroutine.stop(self.cd_coroutine)
end
if self._stateController.selectedIndex == 2 and self.cd_time_text ~= nil then
self.cd_coroutine =
coroutine.start(
function()
while (self.cd_time > 0) do
self:SetCanDissroom(false)
self.cd_time = self.cd_time - 1
self.cd_time = math.max(0, self.cd_time)
self.cd_time_text.text = tostring(math.ceil(self.cd_time))
if self.cd_time > 0 then
coroutine.wait(1)
end
end
self:SetCanDissroom(self._btn_dismiss_room_enable)
self.cd_time_text.text = ''
end
)
end
end
--[[
function M:Destroy()
local bg_id = self._view:GetController('bg').selectedIndex + 1
if self._bg ~= bg_id then
self._bg = bg_id
TableBG.SaveTableBG(self._game_id, self._bg)
end
BaseWindow.Destroy(self)
end
]]
function M:SetCanDissroom(enable)
self._btn_dismiss_room.enabled = enable
end
function M:SetBtnDismissRoomEnable(enable)
self._btn_dismiss_room_enable = enable
self:SetCanDissroom(enable)
end
return M