hengyang_client/lua_probject/main_project/main/majiang/MJMainView.lua

554 lines
18 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.

local MJPlayerCardInfoView = import(".MJPlayerCardInfoView")
local MJPlayerSelfCardInfoView = import(".MJPlayerSelfCardInfoView")
local TableBG = require("Game.Data.TableBG")
local MJSettingView = import(".MJSettingViewNew")
local MJMainRightPanelView = import(".MJMainRightPanelView")
local MJCheckG = import('.MJCheckG')
local bg_config = {
{ id = 1, url = "base/main_majiang/bg/bg1", thumb = "ui://Main_Majiang/b01" },
{ id = 2, url = "base/main_majiang/bg/bg2", thumb = "ui://Main_Majiang/b02" },
{ id = 3, url = "base/main_majiang/bg/bg3", thumb = "ui://Main_Majiang/b03" }
}
local M = {}
setmetatable(M, { __index = MainView })
local default_bg = 1
function M:InitView(url, use_custom_bg, custom_bg_config)
-- 加载牌型数据
if not DataManager.CardTypeList then
local json_data = Utils.LoadLocalFile("CardTypeData")
if json_data then
DataManager.CardTypeList = json.decode(json_data)
else
DataManager.CardTypeList = {}
end
end
self._room.card_type = DataManager.CardTypeList[tostring(self._room.game_id)] or 1
UIPackage.AddPackage("base/main_majiang/ui/Main_Majiang")
MainView.InitView(self, url)
local _view = self._view
self._cursor = UIPackage.CreateObjectFromURL("ui://Main_Majiang/Ani_play_bj")
bg_config = custom_bg_config == nil and bg_config or custom_bg_config
if use_custom_bg then
TableBG.LoadTableBG(default_bg, self._room.game_id, self._root_view, bg_config)
end
local _room = self._room
local _cardbox = _view:GetChild("cardbox")
self._zhuanpanCtr = _cardbox:GetController("zuozi")
-- self._ctr_cardbox = _cardbox:GetController("c1")
-- self._tex_leftTime = _cardbox:GetChild("tex_leftnum")
local centerBox = _view:GetChild("Comp_ConterBox")
self._ctr_cardbox = centerBox:GetController("seat")
self._tex_leftTime = centerBox:GetChild("Text_Time")
if self._room.card_type == 2 then
self:Change3d(true)
else
self:Change3d(false)
end
local rightpanel = self._view:GetChild("com_roominfo")
if self._rightPanelView ~= nil then
self._rightPanelView:Destroy()
end
self._rightPanelView = MJMainRightPanelView.new(self, rightpanel)
--local tempdsaf=self._view:GetChild("btn_back_jiesan")
--tempdsaf:GetChild("n3").displayObject.gameObject:SetActive(false)
---- print("2222222222222222222222")
---- print(self._view:GetChild("btn_back_jiesan").displayObject.gameObject.name)
--self._view:GetChild("btn_back_jiesan").displayObject.gameObject:SetActive(false)
--local temp111=self._view:GetChild("btn_back_jiesan").displayObject.gameObject
--temp111:SetActive(false)
self._view:GetChild("btn_back_jiesan").onClick:Set(function()
if self.dismiss_room_cd_time > 0 then
ViewUtil.ErrorTip(nil, "您还处于解散冷却时间当中,请稍后重试!")
else
local _gamectr = ControllerManager.GetController(GameController)
_gamectr:AskDismissRoom()
end
end)
self._tex_LeftCard = _view:GetChild("remaining_card")
self._player_card_info = {}
local _player_card_info = self._player_card_info
for i = 1, _room.room_config.people_num do
local tem = _view:GetChild("player_card_info" .. i)
print("====================================", "player_card_info" .. i, tem)
pt(_view)
_player_card_info[i] = self:NewMJPlayerCardInfoView(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
local list = _room.player_list
local readyNum = 0
for i = 1, #list do
local p = list[i]
if p.ready then readyNum = readyNum + 1 end
end
for i = 1, #_room.player_list do
local p = _room.player_list[i]
local zi, icon = self:GetPosString(p.seat)
if self._room.card_type == 2 then
_cardbox:GetChild("3d_direction" .. self:GetIndex(self:GetPos(p.seat))).icon = "ui://MajiangCard3d/" .. icon
end
_cardbox:GetChild("direction" .. self:GetIndex(self:GetPos(p.seat))).text = zi
end
self._ctr_action = _view:GetController("action")
if _room.banker_seat == _room.self_player.seat and readyNum == _room.room_config.people_num then
--self._ctr_action.selectedIndex = 2
elseif not _room.self_player.ready then
local round = DataManager.CurrenRoom.room_config.config.times or 1
local xpconfig = DataManager.CurrenRoom.room_config.config.xi_pai
if xpconfig then
if round > 1 then
self._ctr_action.selectedIndex = 1
else
self._ctr_action.selectedIndex = 2
end
else
self._ctr_action.selectedIndex = 1
end
else
self._ctr_action.selectedIndex = 0
end
local changeTable = self._view:GetChild('btn_change')
if changeTable then
changeTable.onClick:Set(function()
default_bg = default_bg + 1 > #bg_config and 1 or default_bg + 1
TableBG.LoadTableBG(default_bg, self._room.game_id, self._root_view, bg_config)
end)
end
local checkG = self._view:GetChild('btn_check')
if checkG then
checkG.onClick:Set(function()
local checkG = MJCheckG.new()
checkG:Show()
end)
end
self:InitXiPai()
self:InitXiPai1()
end
function M:InitXiPai()
self._xipaiPanel = UIPackage.CreateObjectFromURL("ui://Common/panel_handanim")
self._xipaiPanel.visible = false
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._handAnimCtr = self._xipaiPanel:GetController("anim")
self._handAnimCtr.selectedIndex = 0
--self:PlayXiPai()
end
function M:InitXiPai1()
self._xipaiPanel1 = UIPackage.CreateObjectFromURL("ui://Common/panel_handanim02")
self._xipaiPanel1.visible = false
self._root_view:AddChild(self._xipaiPanel1)
local offset = get_offset(self._full_offset)
self._xipaiPanel1.width = GRoot.inst.width - (offset * 2)
self._xipaiPanel1.height = GRoot.inst.height
self._xipaiPanel1.x = offset
self._handAnimCtr1 = self._xipaiPanel1:GetController("anim1")
self._handAnimCtr1.selectedIndex = 0
end
function M:PlayXiPai(xipaiCallBack)
if self._xipaiPanel then
coroutine.start(function()
self._xipaiPanel.visible = true
self._xipaiPanel:GetTransition("XiPai"):Play()
self._handAnimCtr.selectedIndex = 1
coroutine.wait(3)
self._handAnimCtr.selectedIndex = 0
self._xipaiPanel.visible = false
if xipaiCallBack then
xipaiCallBack()
end
end)
end
end
function M:PlayXiPai1(xipaiCallBack)
if self._xipaiPanel1 then
coroutine.start(function()
self._xipaiPanel1.visible = true
self._xipaiPanel1:GetTransition("XiPai"):Play()
self._handAnimCtr1.selectedIndex = 1
coroutine.wait(3)
self._handAnimCtr1.selectedIndex = 0
self._xipaiPanel1.visible = false
if xipaiCallBack then
xipaiCallBack()
end
end)
end
end
function M:EventInit()
MainView.EventInit(self)
end
function M:Change3d(flag)
local _room = self._room
local _view = self._view
local _cardbox = _view:GetChild("cardbox")
for i = 1, #_room.player_list do
local p = _room.player_list[i]
local zi, icon = self:GetPosString(p.seat)
if self._room.card_type == 2 then
_cardbox:GetChild("3d_direction" .. self:GetIndex(self:GetPos(p.seat))).icon = "ui://MajiangCard3d/" .. icon
end
_cardbox:GetChild("direction" .. self:GetIndex(self:GetPos(p.seat))).text = zi
end
-- 如果要切换3d牌桌的cardbox位置及上方文字(剩余牌,回合数)显示不错乱,需要做以下改动
-- 取消文字组合的3d控制器的位置 并设置对cardbox的关联左左顶顶
if flag == true then
if _view:GetController("3d") ~= nil then
_view:GetController("3d").selectedIndex = 1
_cardbox.x = (_view.width - _cardbox.width) * 0.5
end
_cardbox:GetController("3d").selectedIndex = 1
_cardbox.x = (_view.width - _cardbox.width) * 0.5
else
if _view:GetController("3d") ~= nil then
_view:GetController("3d").selectedIndex = 0
_cardbox.x = (_view.width - _cardbox.width) * 0.5
end
_cardbox:GetController("3d").selectedIndex = 0
_cardbox.x = (_view.width - _cardbox.width) * 0.5
end
end
-- function M:NewSettingView()
-- local settingView = MJSettingView.new(self._root_view)
-- settingView:FillBgSection(function(url)
-- LoadGameBg(url, self._root_view)
-- end, self._room.game_id, default_bg)
-- settingView.onChangeCardCallback:Add(function()
-- self:Change3d(DataManager.CurrenRoom.card_type == 2)
-- self:ReloadRoom()
-- for i = 1, #self._room.player_list do
-- local p = self._room.player_list[i]
-- local card_info = self._player_card_info[self:GetPos(p.seat)]
-- card_info:ResetCardType()
-- end
-- end)
-- settingView.onEXVoiceCallback:Add(function()
-- end)
-- settingView.onEXChuPaiCallback:Add(function()
-- end)
-- return settingView
-- end
function M:NewSettingView()
local settingView = MJSettingView.new(self._root_view)
-- settingView._view:GetChild("btn_card_1").icon = pack_full_name .. "com_card_preview"
-- local gear = settingView._view:GetChild("panel_bg"):GetGear(0)
-- gear.pages = {"0", "1", "2"}
-- gear:Apply()
-- settingView.Change3d = function() end
settingView:FillBgSection(function(url, index)
LoadGameBg(url, self._root_view)
self._zhuanpanCtr.selectedIndex = index - 1
end, self._room.game_id, 1, bg_config)
settingView.onChangeCardCallback:Add(function()
self:RemoveCursor()
for i = 1, #self._room.player_list do
local p = self._room.player_list[i]
local card_info = self._player_card_info[self:GetPos(p.seat)]
card_info:Clear(true)
card_info:ResetCardType()
end
self:Change3d(DataManager.CurrenRoom.card_type == 2)
self:ReloadRoom(true)
end)
return settingView
end
function M:GetIndex(seat)
local index = seat
local people_num = self._room.room_config.people_num
if people_num == 2 and seat == 2 then
index = 3
elseif people_num == 3 and seat == 3 then
index = 4
end
return index
end
function M:GetPosString(seat)
if DataManager.CurrenRoom.room_config.people_num == 4 then
if seat == 1 then
return "", "dir_1"
elseif seat == 2 then
return "", "dir_2"
elseif seat == 3 then
return "西", "dir_3"
elseif seat == 4 then
return "", "dir_4"
end
elseif DataManager.CurrenRoom.room_config.people_num == 3 then
if seat == 1 then
return "", "dir_1"
elseif seat == 2 then
return "", "dir_2"
elseif seat == 3 then
return "西", "dir_3"
end
elseif DataManager.CurrenRoom.room_config.people_num == 2 then
if seat == 1 then
return "", "dir_1"
elseif seat == 2 then
return "西", "dir_3"
end
end
end
function M:SetCardBoxPosition()
local _room = self._room
for i = 1, _room.room_config.people_num do
local tex = self._view:GetChild("cardbox"):GetChild("direction" .. i)
local index = _room.self_player.seat + i - 1
index = index > 4 and index - 4 or index
tex.text = self._gamectr:GetPosString(index)
end
end
function M:markOutCards(showTip, data)
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)]
for j = 1, #p.outcard_list do
local card = p.outcard_list[j]
if card == data then
for k = 1, #p.outcard_list do
local obj = info:GetOutCardByIndex(k)
if obj.data == card then
obj:GetController("gray").selectedIndex = showTip and 1 or 0
end
end
end
end
end
end
function M:OnPlayerEnter(...)
MainView.OnPlayerEnter(self, ...)
local arg = { ... }
local p = arg[1]
local info = self._player_card_info[self:GetPos(p.seat)]
info:SetPlayer(p)
info:FillData()
end
function M:OnPlayerReady(...)
local arg = { ... }
local p = arg[1]
local _room = self._room
local _view = self._view
local _player_info = self._player_info
if p.seat == _room.self_player.seat then
self._ctr_action.selectedIndex = 0
if p.entrust and self._clearingView and self._clearingView.DestroyWithCallback then
self._clearingView:DestroyWithCallback()
end
end
local info = _player_info[self:GetPos(p.seat)]
info:Ready(true)
local readyNum = self:GetReadyNum()
if readyNum == _room.room_config.people_num then
local _cardbox = _view:GetChild("cardbox")
for i = 1, #_room.player_list do
local p = _room.player_list[i]
local zi, icon = self:GetPosString(p.seat)
_cardbox:GetChild("3d_direction" .. self:GetIndex(self:GetPos(p.seat))).icon = "ui://MajiangCard3d/" .. icon
_cardbox:GetChild("direction" .. self:GetIndex(self:GetPos(p.seat))).text = zi
end
end
if _room.banker_seat == _room.self_player.seat and readyNum == _room.room_config.people_num then
if self._state.selectedIndex == 2 then
local _gamectr = ControllerManager.GetController(GameController)
_gamectr:StartGame()
end
--self._ctr_action.selectedIndex = 2
elseif not _room.self_player.ready then
--self._ctr_action.selectedIndex = 1
local round = DataManager.CurrenRoom.room_config.config.times or 1
local xpconfig = DataManager.CurrenRoom.room_config.config.xi_pai
if xpconfig then
if round > 1 then
self._ctr_action.selectedIndex = 1
else
self._ctr_action.selectedIndex = 2
end
else
self._ctr_action.selectedIndex = 1
end
else
self._ctr_action.selectedIndex = 0
end
end
function M:CountCardLeftNum(card)
local player_list = DataManager.CurrenRoom.player_list
local count = 4
for i = 1, #player_list do
local p = player_list[i]
if p.card_list then
for j = 1, #p.card_list do
if p.card_list[j] == card then
count = count - 1
end
end
end
for j = 1, #p.outcard_list do
if p.outcard_list[j] == card then
count = count - 1
end
end
for j = 1, #p.fz_list do
local fz = p.fz_list[j]
if fz.type == FZType.Chi then
for k = 1, #fz.opcard do
if card == fz.opcard[k] then
count = count - 1
break
end
end
else
local num = fz.type == FZType.Peng and 3 or 4
if card == fz.card then
count = count - num
end
end
end
end
return count
end
function M:OnPlayerLeave(...)
MainView.OnPlayerLeave(self, ...)
local _room = self._room
if _room.banker_seat == _room.self_player.seat then
self._ctr_action.selectedIndex = 0
end
end
function M:PlayerChangeLineState()
local isOutCard = true
local str = "玩家 "
for _, player in ipairs(self._room.player_list) do
if player.line_state == 0 then
isOutCard = false
-- str = str .. self._gamectr:GetPosString(player.seat) .. "、"
end
end
-- if not isOutCard then
-- str = str.sub(str, 1, string.len(str) - string.len("、"))
-- str = str .. " 正在赶来,请稍等"
-- if self._room.curren_round > 0 then
-- self._waitingView = ModalWaitingView.new(self._view, str)
-- end
-- else
-- if self._waitingView then
-- self._waitingView:CloseWaitingView()
-- end
-- end
self._player_card_info[1]._area_handcard_list.touchable = isOutCard
end
function M:NewMJPlayerCardInfoView(view, index)
if index == 1 then
return MJPlayerSelfCardInfoView.new(view, self)
end
return MJPlayerCardInfoView.new(view, self)
end
function M:RemoveCursor()
-- if self._cursor.parent then
-- self._cursor.parent:GetController("color").selectedIndex = 0
-- end
self._cursor:RemoveFromParent()
end
function M:Destroy()
UIPackage.RemovePackage("base/main_majiang/ui/Main_Majiang")
MainView.Destroy(self)
self._cursor:Dispose()
self._xipaiPanel:Dispose()
end
local majiang_asset_path = "base/main_majiang/sound/"
function M:PlayMJSound(path)
ViewUtil.PlaySound(self.asset_group, majiang_asset_path .. path)
end
function M:PlayMJMusic(path)
ViewUtil.PlayMuisc(self.asset_group, majiang_asset_path .. path)
end
function M:PlaySound(group, sex, path)
local sex_path = ViewUtil.Sex_Chat[sex]
local path1 = majiang_asset_path .. string.format("%s/%s.mp3", sex_path, path)
ViewUtil.PlaySound(group, path1)
end
function M:GetPrefix()
return get_majiang_prefix(DataManager.CurrenRoom.game_id)
end
return M