yunque9/lua_probject/main_project/main/zipai/ZPMainView.lua

355 lines
12 KiB
Lua

local PlayerSelfCardInfoView = import('.ZPPlayerSelfCardInfoView')
local PlayerCardInfoView = import('.ZPPlayerCardInfoView')
local ZPSettingView = import('.ZPSettingView')
local ZPTableBG = import('.ZPTableBG')
local HuTipView = import('.HuTipView')
local ZPGameEvent = import('.ZPGameEvent')
local M = {
default_btn = false
}
setmetatable(M, {__index = MainView})
local default_bg = 1
function M:InitView(url, isdisplay, open_social, change_card_size, qihu)
UIPackage.AddPackage('base/main_zipai/ui/Main_RunBeard')
MainView.InitView(self, url)
self._full_offset = false
--显示背景
ZPTableBG.LoadTableBG(default_bg, self._room.game_id, self._root_view)
self.qihu = qihu
if qihu ~= nil then
local id = ZPTableBG.GetTableBG(self._room.game_id)
if id > 3 or id <= 0 then
id = 1
end
if self._room.score_times ~= nil and self._room.score_times > 0 then
self._view:GetChild('di_text').text =
self._room.room_config:GetGameName() .. ' ' .. qihu .. '胡息起 ' .. self._room.score_times .. ''
else
self._view:GetChild('di_text').text = self._room.room_config:GetGameName() .. ' ' .. qihu .. '胡息起'
end
self._view:GetController('bg_state').selectedIndex = id - 1
end
self.cd_time = 0
self.default_btn = open_social
if isdisplay == nil then
isdisplay = false
end
local tex_round = self._view:GetChild('tex_round')
self._tex_leftTime = self._view:GetChild('time')
local remaining_card = self._view:GetChild('remaining_card')
self._tex_LeftCard = self._view:GetChild('remaining_card')
self._rightPanelView._opt = 2
self._rightPanelView:__UpdateTime()
local rightpanel = self._view:GetChild('right_panel')
if (rightpanel ~= nil) then
self.tex_gametype = rightpanel:GetChild('tex_gametype')
if (self.tex_gametype ~= nil) then
self.tex_gametype.text = self._room.room_config:GetGameName()
end
end
self._player_card_info = {}
local _room = self._room
self._hu_tip = HuTipView.new(self)
--加载上次游戏的牌字体
local user_id = DataManager.SelfUser.account_id
local json_data = Utils.LoadLocalFile(user_id .. _room.game_id)
if json_data ~= nil then
local _data = json.decode(json_data)
local typeface = _data['game_typeface']
local _gamectr = self._gamectr
_gamectr:SendChangeTypeFace(typeface)
if typeface == 1 then
if isdisplay then
self._room.change_card_display = '7_'
else
self._room.change_card_display = '2_'
end
elseif typeface == 2 then
self._room.change_card_display = '1_'
elseif typeface == 3 then
self._room.change_card_display = '3_'
elseif typeface == 4 then
self._room.change_card_display = '8_'
end
end
-- self._view.fairyBatching = true
--加载上次游戏的手牌大小
local user_id = DataManager.SelfUser.account_id
local json_data = Utils.LoadLocalFile(user_id .. _room.game_id .. 'cardsize_new')
if json_data ~= nil then
local _data = json.decode(json_data)
local typeface = _data['game_cardsize']
local _gamectr = self._gamectr
if typeface == 0 then
self._room.change_card_size = 1.2
elseif typeface == 1 then
self._room.change_card_size = 1
elseif typeface == 2 then
self._room.change_card_size = 0.8
end
else
self._room.change_card_size = change_card_size
end
--加载上次游戏的接收语音
if self.default_btn then
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')
self._room.yuyin_typeface = 1
self._room.chupai_typeface = 1
self._room.fangyan_typeface = 1
if json_data ~= nil then
local _data = json.decode(json_data)
local typeface = _data['game_typeface']
self._room.yuyin_typeface = typeface
self:SetInteractEnabled(typeface == 1 and 0 or 1)
end
if json_data1 ~= nil then
local _data = json.decode(json_data1)
local typeface = _data['game_typeface']
self._room.chupai_typeface = typeface
end
if json_data2 ~= nil then
local _data = json.decode(json_data2)
local typeface = _data['game_typeface']
self._room.fangyan_typeface = typeface
end
end
local _player_card_info = self._player_card_info
for i = 1, _room.room_config.people_num do
local tem = self._view:GetChild('player_card_info' .. i)
_player_card_info[i] = self:NewPlayerCardInfoView(tem, i)
end
local list = _room.player_list
for i = 1, #list do
local p = list[i]
local info = _player_card_info[self:GetPos(p.seat)]
info:SetPlayer(p)
info:FillData()
end
self._rightPanelView.ctr_log.selectedIndex = 0
local list = _room.player_list
local readyNum = 0
for i = 1, #list do
local p = list[i]
local info = self._player_info[self:GetPos(p.seat)]
info._view.visible = true
info:FillData(p)
if p.ready then
readyNum = readyNum + 1
end
end
if (_room.curren_round > 0) then
self._rightPanelView.ctr_log.selectedIndex = 0
end
self._ctr_action = self._view:GetController('action')
if _room.banker_seat == _room.self_player.seat and readyNum > 1 and readyNum == _room.room_config.people_num then
elseif not _room.self_player.ready then
self._ctr_action.selectedIndex = 1
else
self._ctr_action.selectedIndex = 0
end
self:ResetHandCard()
self:showBackBtnView()
self:InitXiPai()
end
function M:InitXiPai()
self._xipaiPanel = UIPackage.CreateObjectFromURL("ui://Common/panel_handzipai02")
self._root_view:AddChild(self._xipaiPanel)
local offset = get_offset(self._full_offset)
self._xipaiPanel.width = GRoot.inst.width - (offset * 2)
self._xipaiPanel.height = GRoot.inst.height
self._xipaiPanel.x = offset
self._xipaiPanel.visible=false
--self:PlayXiPai()
end
function M:PlayXiPai(xipaiCallBack)
if self._xipaiPanel then
coroutine.start(function()
self._xipaiPanel.visible=true
self._xipaiPanel:GetTransition("XiPai"):Play()
coroutine.wait(3.5)
self._xipaiPanel.visible=false
if xipaiCallBack then
xipaiCallBack()
end
end)
end
end
function M:NewSettingView()
local settingView = ZPSettingView.new(self._view, 2, self.default_btn)
settingView:FillBgSection(
function(url)
LoadGameBg(url, self._root_view)
end,
self._room.game_id,
default_bg,
self._room,
self.qihu
)
return settingView
end
function M:EventInit()
MainView.EventInit(self)
end
function M:NewPlayerCardInfoView(view, index)
if index == 1 then
return PlayerSelfCardInfoView.new(view, self)
end
return PlayerCardInfoView.new(view, self)
end
-- 设置 更新 手牌字体 三套
function M:UpdateCardDisplay(index)
local _gamectr = self._gamectr
_gamectr:SendChangeTypeFace(index)
if index == 1 then
self._room.change_card_display = '2_'
elseif index == 2 then
self._room.change_card_display = '1_'
elseif index == 3 then
self._room.change_card_display = '3_'
elseif index == 4 then
self._room.change_card_display = '8_'
end
for i = 1, #self._room.player_list do
local p = self._room.player_list[i]
local info = self._player_card_info[self:GetPos(p.seat)]
if p.DiceCard ~= nil and p.DiceCard ~= 0 then
info:UpdateOutCardList(p.DiceCard)
end
if p.outcard_list ~= nil and #p.outcard_list > 0 then
info:UpdateQiPai(p.outcard_list)
end
if p.fz_list ~= nil and #p.fz_list > 0 then
info:UpdateFzList(p.fz_list)
end
if p.seat == self._room.self_player.seat then
info:UpdateCardDisplay()
end
end
end
-- 设置 更新 手牌大小
function M:UpdateCardSize(index)
if index == 0 then
self._room.change_card_size = 1.2
elseif index == 1 then
self._room.change_card_size = 1
elseif index == 2 then
self._room.change_card_size = 0.8
end
local info = self._player_card_info[1]
info:UpdateCardSize()
end
-- 设置 更新 方言
function M:UpdateFangyan(index)
self._room.fangyan_typeface = index
end
--刷新手牌排列 按钮 三种 排列方法 在 PendulumRule 里
function M:ResetHandCard(...)
local btn_reset = self._view:GetChild('btn_reset')
btn_reset.onClick:Set(
function(...)
if self._popEvent == false then
return
end
--加载上次的
local index = 1
local user_id = DataManager.SelfUser.account_id
local json_data = Utils.LoadLocalFile(user_id .. 'ResetHandCard')
if json_data ~= nil then
local _data = json.decode(json_data)
index = _data['index']
end
--点击换牌按钮后保存当前游戏的牌字体
local user_id = DataManager.SelfUser.account_id
local _data = {}
_data['ResetHandCard'] = true
if index == 1 then
_data['index'] = 2
elseif index == 2 then
_data['index'] = 3
elseif index == 3 then
_data['index'] = 1
end
local key = user_id .. 'ResetHandCard'
Utils.SaveLocalFile(key, json.encode(_data))
local x = _data['index']
local card_info = self._player_card_info[1]
card_info:InitHandCard(false, x)
end
)
end
function M:showBackBtnView()
local btn_back_lobby = self._view:GetChild('btn_back_lobby')
local btn_jiesan_lobby1 = self._view:GetChild('Btn_jiesan_lobby')
--btn_jiesan_lobby1.displayObject.gameObject:SetActive(false)
--btn_jiesan_lobby1:GetChild("n8").displayObject.gameObject:SetActive(false)
if (btn_jiesan_lobby1 ~= nil) then
btn_jiesan_lobby1.onClick:Set(
function()
if (self.cd_time > 0) then
ViewUtil.ErrorTip(nil, '您还处于解散冷却时间当中,请稍后再试')
else
self.cd_time = 30
self._gamectr:AskDismissRoom(
function(res)
ViewUtil.ErrorTip(res.ReturnCode, '')
end
)
self:onDisBandTimer()
end
end
)
end
end
--解散计时器
function M:onDisBandTimer()
if self.cd_coroutine ~= nil then
coroutine.stop(self.cd_coroutine)
end
self.cd_coroutine =
coroutine.start(
function()
while (self.cd_time > 0) do
self.cd_time = self.cd_time - 1
self.cd_time = math.max(0, self.cd_time)
if self.cd_time > 0 then
coroutine.wait(1)
end
end
end
)
end
function M:Destroy()
UIPackage.RemovePackage('base/main_zipai/ui/Main_RunBeard')
MainView.Destroy(self)
end
return M