336 lines
11 KiB
Lua
336 lines
11 KiB
Lua
local SettingView = require('Game.View.SettingView')
|
|
local ZPTableBG = import('.ZPTableBG')
|
|
|
|
local ZPSettingView = {
|
|
-- 修改牌字体
|
|
onEXMainCallback = nil,
|
|
-- 修改手牌大小
|
|
onUpdataCardSizeCallback = nil,
|
|
-- 语音
|
|
onEXVoiceCallback = nil,
|
|
-- 快速出牌
|
|
onEXChuPaiCallback = nil,
|
|
-- 方言
|
|
onEXFangYanCallback = nil
|
|
}
|
|
local M = ZPSettingView
|
|
|
|
function ZPSettingView.new(blur_view, index, open_social, cardIndex)
|
|
setmetatable(SettingView, { __index = BaseWindow })
|
|
setmetatable(M, { __index = SettingView })
|
|
local self = setmetatable({}, { __index = M })
|
|
self.class = 'ZPSettingView'
|
|
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 = false
|
|
self._close_destroy = true
|
|
self.bigSize = 1.4
|
|
self.mediumSize = 1.2
|
|
self.smallSize = 1.2
|
|
self._full = true
|
|
self._anim_pop = 2
|
|
self._open_social = open_social
|
|
self._cardType = cardIndex
|
|
self:init('ui://Main_RunBeard/New_SettingWindow')
|
|
return self
|
|
end
|
|
|
|
function M:init(url)
|
|
SettingView.init(self, url)
|
|
if DataManager.CurrenRoom == nil then
|
|
return
|
|
end
|
|
self._view = self._view:GetChild('showview')
|
|
|
|
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
|
|
)
|
|
|
|
local room = DataManager.CurrenRoom
|
|
local c1 = self._view:GetController('cards')
|
|
if self._cardType then
|
|
c1.selectedIndex = self._cardType
|
|
end
|
|
|
|
local size = self._view:GetController('size')
|
|
if room.change_card_size ~= nil then
|
|
if room.change_card_size == self.bigSize then
|
|
size.selectedIndex = 0
|
|
elseif room.change_card_size == self.mediumSize then
|
|
size.selectedIndex = 1
|
|
elseif room.change_card_size == self.smallSize then
|
|
size.selectedIndex = 2
|
|
end
|
|
else
|
|
room.change_card_size = 0
|
|
size.selectedIndex = 0
|
|
end
|
|
if room.change_card_display ~= nil then
|
|
local _str = string.sub(room.change_card_display, 1, 1)
|
|
local n = tonumber(_str)
|
|
if n == 1 then
|
|
c1.selectedIndex = 1
|
|
elseif n == 2 then
|
|
c1.selectedIndex = 0
|
|
elseif n == 8 then
|
|
c1.selectedIndex = 3
|
|
else
|
|
c1.selectedIndex = 2
|
|
end
|
|
end
|
|
if self._open_social then
|
|
self._view:GetChild('n78').visible = true
|
|
self._view:GetChild('n88').visible = true
|
|
self._view:GetChild('n57').visible = true
|
|
|
|
local yuyin = self._view:GetController('yuyin')
|
|
local chupai = self._view:GetController('chupai')
|
|
local fangyan = self._view:GetController('fangyan')
|
|
local user_id = DataManager.SelfUser.account_id
|
|
local json_data = Utils.LoadLocalFile(user_id .. room.game_id .. 'yuyin')
|
|
local json_data1 = Utils.LoadLocalFile(user_id .. room.game_id .. 'chupai')
|
|
local json_data2 = Utils.LoadLocalFile(user_id .. room.game_id .. 'fangyan')
|
|
yuyin.selectedIndex = 1
|
|
chupai.selectedIndex = 1
|
|
room.yuyin_typeface = 1
|
|
room.chupai_typeface = 1
|
|
fangyan.selectedIndex = 1
|
|
room.fangyan_typeface = 1
|
|
if json_data ~= nil then
|
|
local _data = json.decode(json_data)
|
|
local typeface = _data['game_typeface']
|
|
room.yuyin_typeface = typeface
|
|
end
|
|
if json_data1 ~= nil then
|
|
local _data = json.decode(json_data1)
|
|
local typeface = _data['game_typeface']
|
|
room.chupai_typeface = typeface
|
|
end
|
|
if json_data2 ~= nil then
|
|
local _data = json.decode(json_data2)
|
|
local typeface = _data['game_typeface']
|
|
room.fangyan_typeface = typeface
|
|
end
|
|
if room.yuyin_typeface ~= nil then
|
|
yuyin.selectedIndex = room.yuyin_typeface
|
|
end
|
|
if room.chupai_typeface ~= nil then
|
|
chupai.selectedIndex = room.chupai_typeface
|
|
end
|
|
if room.fangyan_typeface ~= nil then
|
|
fangyan.selectedIndex = room.fangyan_typeface
|
|
end
|
|
else
|
|
self._view:GetChild('n78').visible = false
|
|
self._view:GetChild('n88').visible = false
|
|
self._view:GetChild('n57').visible = false
|
|
end
|
|
|
|
c1.onChanged:Set(
|
|
function()
|
|
if self.onEXMainCallback then
|
|
self.onEXMainCallback(c1.selectedIndex + 1)
|
|
end
|
|
--点击换牌按钮后保存当前游戏的牌字体
|
|
local user_id = DataManager.SelfUser.account_id
|
|
local _data = {}
|
|
_data['game_typeface'] = c1.selectedIndex + 1
|
|
local key = user_id .. room.game_id
|
|
Utils.SaveLocalFile(key, json.encode(_data))
|
|
end
|
|
)
|
|
|
|
size.onChanged:Set(
|
|
function()
|
|
if self.onUpdataCardSizeCallback then
|
|
self.onUpdataCardSizeCallback(size.selectedIndex)
|
|
end
|
|
--点击换牌按钮后保存当前游戏的牌字体
|
|
local user_id = DataManager.SelfUser.account_id
|
|
local _data = {}
|
|
_data['game_cardsize'] = size.selectedIndex
|
|
local key = user_id .. room.game_id .. 'cardsize_new'
|
|
Utils.SaveLocalFile(key, json.encode(_data))
|
|
end
|
|
)
|
|
if self._open_social then
|
|
self._view:GetChild('n78').visible = false
|
|
local yuyin = self._view:GetController('yuyin')
|
|
local chupai = self._view:GetController('chupai')
|
|
local fangyan = self._view:GetController('fangyan')
|
|
yuyin.onChanged:Set(
|
|
function()
|
|
if self.onEXVoiceCallback then
|
|
room.yuyin_typeface = yuyin.selectedIndex
|
|
self.onEXVoiceCallback(yuyin.selectedIndex)
|
|
end
|
|
--点击换牌按钮后保存当前游戏的牌字体
|
|
local user_id = DataManager.SelfUser.account_id
|
|
local _data = {}
|
|
_data['game_typeface'] = yuyin.selectedIndex
|
|
local key = user_id .. room.game_id .. 'yuyin'
|
|
Utils.SaveLocalFile(key, json.encode(_data))
|
|
end
|
|
)
|
|
chupai.onChanged:Set(
|
|
function()
|
|
if self.onEXChuPaiCallback then
|
|
room.chupai_typeface = chupai.selectedIndex
|
|
self.onEXChuPaiCallback(chupai.selectedIndex)
|
|
end
|
|
--点击换牌按钮后保存当前游戏的牌字体
|
|
local user_id = DataManager.SelfUser.account_id
|
|
local _data = {}
|
|
_data['game_typeface'] = chupai.selectedIndex
|
|
local key = user_id .. room.game_id .. 'chupai'
|
|
Utils.SaveLocalFile(key, json.encode(_data))
|
|
end
|
|
)
|
|
fangyan.onChanged:Set(
|
|
function()
|
|
if self.onEXFangYanCallback then
|
|
room.fangyan_typeface = fangyan.selectedIndex
|
|
self.onEXFangYanCallback(fangyan.selectedIndex)
|
|
end
|
|
--点击换牌按钮后保存当前游戏的牌字体
|
|
local user_id = DataManager.SelfUser.account_id
|
|
local _data = {}
|
|
_data['game_typeface'] = fangyan.selectedIndex
|
|
local key = user_id .. room.game_id .. 'fangyan'
|
|
Utils.SaveLocalFile(key, json.encode(_data))
|
|
end
|
|
)
|
|
else
|
|
self._view:GetChild('n78').visible = false
|
|
end
|
|
end
|
|
|
|
function M:Show()
|
|
SettingView.Show(self)
|
|
self:UpdateIndex()
|
|
self:UpdateCardSizeIndex()
|
|
end
|
|
|
|
--根据存的数据改变设置里面的控制器
|
|
|
|
function M:UpdateIndex()
|
|
local room = DataManager.CurrenRoom
|
|
local c1 = self._view:GetController('cards')
|
|
if room.change_card_display ~= nil then
|
|
local _str = string.sub(room.change_card_display, 1, 1)
|
|
local n = tonumber(_str)
|
|
if n == 7 then
|
|
n = 6
|
|
end
|
|
if n == 1 then
|
|
c1.selectedIndex = 1
|
|
elseif n == 2 then
|
|
c1.selectedIndex = 0
|
|
elseif n == 8 then
|
|
c1.selectedIndex = 3
|
|
else
|
|
c1.selectedIndex = 0
|
|
end
|
|
end
|
|
end
|
|
|
|
function M:UpdateCardSizeIndex()
|
|
local room = DataManager.CurrenRoom
|
|
local size = self._view:GetController('size')
|
|
if room.change_card_size ~= nil then
|
|
if room.change_card_size == self.bigSize then
|
|
size.selectedIndex = 0
|
|
elseif room.change_card_size == self.mediumSize then
|
|
size.selectedIndex = 1
|
|
elseif room.change_card_size == self.smallSize then
|
|
size.selectedIndex = 2
|
|
end
|
|
else
|
|
size.selectedIndex = 0
|
|
end
|
|
end
|
|
|
|
function M:SetBtnUpdateCardEnable(enable)
|
|
self._view:GetChild('n37').enabled = enable
|
|
self._view:GetChild('n38').enabled = enable
|
|
self._view:GetChild('n49').enabled = enable
|
|
end
|
|
|
|
function M:FillBgSection(cb, game_id, default_bg, room, qihu)
|
|
if (default_bg == nil) then
|
|
default_bg = 1
|
|
end
|
|
local view = self._view
|
|
local lst_bg = view:GetChild('lst_bg')
|
|
local ctr_bg = view:GetController('bg')
|
|
for i = 1, #bg_config_zipai do
|
|
local config = bg_config_zipai[i]
|
|
local item = lst_bg:AddItemFromPool()
|
|
item.icon = config.thumb
|
|
if i > 3 then
|
|
ctr_bg:AddPage(i - 1)
|
|
end
|
|
item.onClick:Add(
|
|
function()
|
|
cb(config.url)
|
|
ctr_bg.selectedIndex = i - 1
|
|
if qihu ~= nil then
|
|
self._blur_view:GetController('bg_state').selectedIndex = i - 1
|
|
end
|
|
end
|
|
)
|
|
end
|
|
self._game_id = game_id
|
|
self._bg = ZPTableBG.GetTableBG(game_id)
|
|
local index = 0
|
|
if self._bg > 0 then
|
|
lst_bg.selectedIndex = self._bg - 1
|
|
index = lst_bg.selectedIndex
|
|
else
|
|
ctr_bg.selectedIndex = default_bg - 1
|
|
index = ctr_bg.selectedIndex
|
|
end
|
|
if qihu ~= nil then
|
|
if index < 3 then
|
|
self._blur_view:GetController('bg_state').selectedIndex = index
|
|
else
|
|
self._blur_view:GetController('bg_state').selectedIndex = 0
|
|
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
|
|
ZPTableBG.SaveTableBG(self._game_id, self._bg)
|
|
end
|
|
SettingView.Destroy(self)
|
|
end
|
|
|
|
return M
|