189 lines
5.7 KiB
Lua
189 lines
5.7 KiB
Lua
local SettingView = require("Game.View.SettingView")
|
|
local TableBG = require("Game.Data.TableBG")
|
|
local MJSettingViewNew = {
|
|
-- 修改牌
|
|
onUpdataCardCallback = nil
|
|
}
|
|
local M = MJSettingViewNew
|
|
|
|
-- show_dialect是否显示'切换方言'选项
|
|
function MJSettingViewNew.new(blur_view, show_dialect)
|
|
setmetatable(SettingView, {__index = BaseWindow})
|
|
setmetatable(M, {__index = SettingView})
|
|
local self = setmetatable({}, {__index = M})
|
|
self.class = "MJSettingViewNew"
|
|
self._currenIndex = 0
|
|
self._blur_view = blur_view
|
|
self.onCallback = event("onCallback", true)
|
|
self.onChangeCardCallback = event("onCallback",true)
|
|
self.onChangeLanguageCallback = event("onCallback", true)
|
|
self.stateIndex = 0
|
|
self.cd_time = 0
|
|
self._btn_dismiss_room_enable = true
|
|
self._full = true
|
|
self._anim_pop = 2
|
|
self._close_zone = true
|
|
self._show_dialect = show_dialect
|
|
self:init("ui://Main_PokeMaJiang/SettingWindow2")
|
|
|
|
return self
|
|
end
|
|
function M:init(url)
|
|
|
|
SettingView.init(self, url)
|
|
|
|
self._view:GetChild("btn_close22").onClick:Set(function( ... )
|
|
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
|
|
self:Destroy()
|
|
end)
|
|
|
|
self._view:GetChild("btn_close").onClick:Set(function( ... )
|
|
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
|
|
self:Destroy()
|
|
end)
|
|
|
|
if self._show_dialect == true then
|
|
self._view:GetController("show_dialect").selectedIndex = 1
|
|
local ctr_language = self._view:GetController("language")
|
|
ctr_language.selectedIndex = self:GetLanguage()
|
|
ctr_language.onChanged:Set(function()
|
|
self:SaveLanguage(ctr_language.selectedIndex)
|
|
if self.onChangeLanguageCallback then
|
|
self:onChangeLanguageCallback(ctr_language.selectedIndex)
|
|
end
|
|
end)
|
|
end
|
|
end
|
|
|
|
--赋值bg_config
|
|
function M:GetBGConfig()
|
|
return TableBG.GetBGConfig()
|
|
end
|
|
|
|
function M:Change3d(mode,oldCardType)
|
|
|
|
local lst_bg = self._view:GetChild("lst_bg")
|
|
|
|
if mode == 2 then
|
|
|
|
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
|
|
|
|
for i = 1, lst_bg.numChildren do
|
|
local item = lst_bg:GetChildAt(i - 1)
|
|
if item.data.id == 4 then
|
|
item.onClick:Call();
|
|
break
|
|
end
|
|
end
|
|
|
|
else
|
|
|
|
if oldCardType == 2 and DataManager.CurrenRoom.card_type ~= 2 then
|
|
for i = 1, lst_bg.numChildren do
|
|
local item = lst_bg:GetChildAt(i - 1)
|
|
if item.data.id == self._default_bg then
|
|
item.onClick:Call();
|
|
break
|
|
end
|
|
end
|
|
end
|
|
|
|
local bg_id = self._view:GetController("bg").selectedIndex + 1
|
|
if self._bg ~= bg_id and bg_id ~= 4 then
|
|
self._bg = bg_id
|
|
TableBG.SaveTableBG(self._game_id, self._bg)
|
|
end
|
|
|
|
bg_id = TableBG.GetTableBG(self._game_id)
|
|
if bg_id > 0 then
|
|
for i = 1, lst_bg.numChildren do
|
|
local item = lst_bg:GetChildAt(i - 1)
|
|
if item.data.id == bg_id then
|
|
item.onClick:Call();
|
|
break
|
|
end
|
|
end
|
|
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:GetLanguage()
|
|
return PlayerPrefs.GetInt("Languauge" .. DataManager.CurrenRoom.game_id)
|
|
end
|
|
--保存选择的语言
|
|
function M:SaveLanguage(languauge)
|
|
PlayerPrefs.SetInt("Languauge" .. DataManager.CurrenRoom.game_id, languauge)
|
|
end
|
|
|
|
function M:Show()
|
|
self:UpdateIndex()
|
|
SettingView.Show(self)
|
|
|
|
local ctr_card = self._view:GetController("card")
|
|
ctr_card.onChanged:Set(function ()
|
|
|
|
if self.onChangeCardCallback then
|
|
local oldCardType = DataManager.CurrenRoom.card_type
|
|
DataManager.CurrenRoom.card_type = ctr_card.selectedIndex
|
|
self.onChangeCardCallback()
|
|
|
|
local cardtype = ctr_card.selectedIndex
|
|
local list_cardtype = DataManager.CardTypeList
|
|
if DataManager.CurrenRoom then
|
|
local game_id = tostring(DataManager.CurrenRoom.game_id)
|
|
if not list_cardtype[game_id] or list_cardtype[game_id] ~= cardtype then
|
|
list_cardtype[game_id] = cardtype
|
|
Utils.SaveLocalFile("CardTypeData",json.encode(list_cardtype))
|
|
end
|
|
end
|
|
|
|
self:Change3d(ctr_card.selectedIndex,oldCardType)
|
|
end
|
|
end)
|
|
end
|
|
|
|
function M:Change3DMode()
|
|
|
|
DataManager.CurrenRoom.card_type = 2
|
|
|
|
local list_cardtype = DataManager.CardTypeList
|
|
if DataManager.CurrenRoom then
|
|
local game_id = tostring(DataManager.CurrenRoom.game_id)
|
|
if not list_cardtype[game_id] or list_cardtype[game_id] ~= cardtype then
|
|
list_cardtype[game_id] = cardtype
|
|
Utils.SaveLocalFile("CardTypeData",json.encode(list_cardtype))
|
|
end
|
|
end
|
|
|
|
TableBG.SaveTableBG(DataManager.CurrenRoom.game_id, 4)
|
|
end
|
|
|
|
|
|
function M:UpdateIndex()
|
|
local room = DataManager.CurrenRoom
|
|
local ctr_card = self._view:GetController("card")
|
|
ctr_card.selectedIndex = room.card_type
|
|
end
|
|
|
|
return M |