jx_client_neibu/lua_probject/main_project/main/majiang/MJSettingViewNew.lua

349 lines
9.9 KiB
Lua

local SettingView = require("Game.View.SettingView")
local TableBG = require("Game.Data.TableBG")
local MJSettingViewNew = {
-- 修改牌
onUpdataCardCallback = nil
}
local M = MJSettingViewNew
local function IsRoomOwer()
--local roomOwner = self._room.player_list[1].self_user.account_id
local roomOwner = DataManager.CurrenRoom.player_list[1].self_user.account_id
return roomOwner == DataManager.SelfUser.account_id
end
local function SaveClickMode(self)
Utils.SaveLocalFile("clickMode", json.encode(self._mainView.clickMode))
end
function M:Reflash()
if IsRoomOwer() then
self.cBtn.selectedIndex = 1
end
if DataManager.CurrenRoom.playing then
self.cBtn.selectedIndex = 1
end
if self._flag_witness then
self.cBtn.selectedIndex = 0
end
if self._mainView.clickMode == "single" then
self.cBtnSelect.selectedIndex = 0
elseif self._mainView.clickMode == "double" then
self.cBtnSelect.selectedIndex = 1
end
end
function M:Show()
BaseWindow.Show(self)
self:Reflash()
end
function M:Close()
SaveClickMode(self)
BaseWindow.Close(self)
end
-- show_dialect是否显示'切换方言'选项
function MJSettingViewNew.new(blur_view, flag_witness)
setmetatable(SettingView, { __index = BaseWindow })
setmetatable(M, { __index = SettingView })
local self = setmetatable({}, { __index = M })
self.class = "MJSettingViewNew"
self._blur_view = blur_view
self._flag_witness = flag_witness
self.onCallback = event("onCallback", true)
self.onChangeCardCallback = event("onCallback", true)
self.onChangeLanguageCallback = event("onCallback", true)
self._mainView = blur_view
--[[
self._currenIndex = 0
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_Majiang/SettingWindow2")
]]
self._scale = true
self:init("ui://Main_Majiang/Setting")
return self
end
function M:init(url)
BaseWindow.init(self, url)
self.btn_singleClick = self._view:GetChild("btn_singleClick")
self.btn_doubleClick = self._view:GetChild("btn_doubleClick")
self.slider_sound = self._view:GetChild('slider_vedio_sound')
self.slider_music = self._view:GetChild('slider_vedio_music')
self.btn_music = self._view:GetChild('btn_vedio_music')
self.btn_sound = self._view:GetChild('btn_vedio_sound')
self.btn_cancelRoom = self._view:GetChild("btn_cancelRoom")
self.btn_closeRoom = self._view:GetChild("btn_closeRoom")
self.cBtnSelect = self._view:GetController("cBtnSelect")
self.cBtn = self._view:GetController('cBtn')
self.btn_singleClick.onChanged:Set(function()
if self.btn_singleClick.selected then
self._mainView.clickMode = "single"
end
end)
self.btn_doubleClick.onChanged:Set(function()
if self.btn_doubleClick.selected then
self._mainView.clickMode = "double"
end
end)
self.slider_music.onChanged:Add(function()
GameApplication.Instance.MusicValue = self.slider_music.value
self.btn_music.selected = false
GameApplication.Instance.MusicMute = false;
end)
self.slider_sound.onChanged:Add(function()
GameApplication.Instance.SoundValue = self.slider_sound.value
self.btn_sound.selected = false
GameApplication.Instance.SoundMute = false;
end)
self.btn_sound.onClick:Add(function()
self.slider_sound.value = 0
GameApplication.Instance.SoundMute = self.btn_sound.selected;
end)
self.btn_music.onClick:Add(function()
self.slider_music.value = 0
GameApplication.Instance.MusicMute = self.btn_music.selected;
end)
self.btn_cancelRoom.onClick:Set(function()
if self._mainView.dismiss_room_cd_time > 0 then
ViewUtil.ErrorTip(nil, "您还处于解散冷却时间当中,请稍后重试!")
return
end
local _gamectr = ControllerManager.GetController(GameController)
_gamectr:AskDismissRoom()
end)
self.btn_closeRoom.onClick:Set(function()
if self._flag_witness then
local _room = DataManager.CurrenRoom
self._mainView._gamectr:ExitWitnessGame(_room.play_id, _room.game_id, _room.room_id)
ViewManager.ChangeView(ViewManager.View_Family)
return
end
local _gamectr = ControllerManager.GetController(GameController)
_gamectr:LevelRoom(function(res)
print("退出房间")
if res.ReturnCode ~= 0 then
ViewUtil.ErrorTip(res.ReturnCode)
return
end
ViewManager.ChangeView(ViewManager.View_Family)
end)
end)
--游戏内解散房间功能
self._view:GetController('lev').selectedIndex = 0
self.btn_closeRoom.onClick:Set(function()
if self._flag_witness then
local _room = DataManager.CurrenRoom
self._mainView._gamectr:ExitWitnessGame(_room.play_id, _room.game_id, _room.room_id)
ViewManager.ChangeView(ViewManager.View_Family)
return
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.selectedIndex=0
local game_id = tostring(DataManager.CurrenRoom.game_id)
local ctr_cardIndex=0
local ct_data = nil
local json_data = Utils.LoadLocalFile("CardTypeData")
if json_data then
ct_data = json.decode(json_data)
if ct_data[game_id] then
ctr_cardIndex=ct_data[game_id]
else
ctr_cardIndex=0
end
else
ctr_cardIndex=0
end
ctr_card.selectedIndex=ctr_cardIndex
local list_cardtype = DataManager.CardTypeList
if DataManager.CurrenRoom then
list_cardtype[game_id] = ctr_cardIndex
Utils.SaveLocalFile("CardTypeData",json.encode(list_cardtype))
end
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)
local ctr_size = self._view:GetController("size")
local filename = 'mjsize' .. DataManager.SelfUser.account_id
local json_data = Utils.LoadLocalFile(filename)
if json_data then
local _data = json.decode(json_data)
if _data and _data.size then
ctr_size.selectedIndex=_data.size
end
else
ctr_size.selectedIndex=1
end
ctr_size.onChanged:Set(function ()
local _gamectr = ControllerManager.GetController(GameController)
if _gamectr then
DispatchEvent(_gamectr._dispatcher,GameEvent.MJModifySzie,ctr_size.selectedIndex)
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