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

870 lines
34 KiB
Lua
Raw Normal View History

2025-05-24 14:29:14 +08:00
local CardCheck = import('.CardCheck')
local PendulumRule = import('.PendulumRule')
AreaOderType = {
left_right = 'left_right',
right_left = 'right_left',
up_down = 'up_down',
down_up = 'down_up'
}
local CardView = {
btn_card = nil,
-- 牌序号
card_item = 0,
-- 牌层级
Hierarchy = 0,
-- 牌的列数
index_X = 0,
-- 每一列第几张牌
index_Y = 0,
-- 原始位置
old_postion = Vector2.zero
}
local function NewCardView(card, cardItem, index_X, index_Y)
local self = {}
setmetatable(self, { __index = CardView })
self.btn_card = card
self.card_item = cardItem
self.index_X = index_X
self.index_Y = index_Y
return self
end
local PlayerSelfCardInfoView = {
_view = nil,
_mainView = nil,
_mask_liangpai = nil,
_area_outcard_list = nil,
_area_handcard_list = nil
}
local M = PlayerSelfCardInfoView
function M.new(view, mainView)
local self = {}
setmetatable(self, { __index = M })
self._view = view
self._mainView = mainView
self:init()
return self
end
function M:init()
local view = self._view
self._isDrg = false
self.card_list = {} -- 牌的btn code type pos 等等
self.cards_count = 0 -- 牌的总列数
self.card_width = 87
self.card_hight = 110
self.outcard_button = nil
self._room = DataManager.CurrenRoom
self._area_handcard_list = view:GetChild('area_handcard_list')
self._area_outcard_list = view:GetChild('area_outcard_list')
self._area_fz_list = view:GetChild('area_fz_list')
self._area_qipai_list = view:GetChild('windcard_list')
self._mask_liangpai = view:GetChild('mask_liangpai')
UIPackage.AddPackage('base/main_zipai/ui/Main_RunBeard')
self.ctr_piao = self._view:GetController('piao')
self.ctr_piao_value = self._view:GetController('piaovalue')
self:BtnEvent()
end
function M:ShowPiao(piao)
self.ctr_piao.selectedIndex = piao
end
function M:HidePiao()
self.ctr_piao.selectedIndex = 0
end
function M:BtnEvent()
self.btn_tips = self._view:GetChild('btn_tips')
local function click_piao()
local closePiaoTipsFunc = function()
self.ctr_piao.selectedIndex = 0
end
ControllerManager.GetController(GameController):SendPiao(tonumber(self.ctr_piao_value.selectedPage),
closePiaoTipsFunc)
end
local btn_piao0 = self._view:GetChild('piao0')
btn_piao0.onClick:Set(click_piao)
local btn_piao1 = self._view:GetChild('piao1')
btn_piao1.onClick:Set(click_piao)
local btn_piao2 = self._view:GetChild('piao2')
btn_piao2.onClick:Set(click_piao)
local btn_piao3 = self._view:GetChild('piao3')
btn_piao3.onClick:Set(click_piao)
local btn_piao5 = self._view:GetChild('piao5')
btn_piao5.onClick:Set(click_piao)
local btn_piao8 = self._view:GetChild('piao8')
btn_piao8.onClick:Set(click_piao)
end
function M:SetPlayer(p)
self._player = p
end
function M:FillData(begin)
end
function M:Clear()
self.outcard_button = nil
self._area_outcard_list:RemoveChildren(0, -1, true)
self._area_fz_list:RemoveChildren(0, -1, true)
self._area_handcard_list:RemoveChildren(0, -1, true)
self._area_qipai_list:RemoveChildren(0, -1, true)
self._mask_liangpai:RemoveChildren(0, -1, true)
self.card_list = {}
end
function M:fillCard(obj, card_type, cards)
end
function M:ShowHuTip(card)
if DataManager.CurrenRoom == nil or DataManager.CurrenRoom.self_player == nil then
local x = {}
self._mainView._hu_tip:FillData(x)
return
end
local _aplayer = DataManager.CurrenRoom.self_player
local selfplayeTable = {}
selfplayeTable.handcard_list = _aplayer.handcard_list
selfplayeTable.fz_list = _aplayer.fz_list
selfplayeTable.tiCount = _aplayer.tiCount
selfplayeTable.paoCount = _aplayer.paoCount
selfplayeTable.hu_xi = _aplayer.hu_xi
local player = membe_deep_clone(selfplayeTable)
if card ~= nil then
list_remove(player.handcard_list, card)
end
local tingList = CardCheck.tingPai(player, DataManager.CurrenRoom)
if self._mainView._hu_tip ~= nil then
self._mainView._hu_tip:FillData(tingList)
end
end
function M:SetNotPutCard()
local tempNotPutList = DataManager.CurrenRoom.self_player.currentNotPutCardList
if tempNotPutList and #tempNotPutList > 0 then
for i = 1, #tempNotPutList do
self:UpdateKan(tempNotPutList[i])
end
end
end
--手牌
function M:InitHandCard(isPlayAni, index)
if DataManager.CurrenRoom == nil or DataManager.CurrenRoom.self_player == nil then
return
end
self.outcard_button = nil
if self.cor_init_poker ~= nil then
coroutine.stop(self.cor_init_poker)
end
self.cor_init_poker = nil
local _room = DataManager.CurrenRoom
--得到排序好的 list
local pokerList = PendulumRule.GetHandCard(_room.self_player.handcard_list, index)
if pokerList == nil or #pokerList == 0 then
return
end
self.cards_count = #pokerList
self.card_list = {}
self._area_handcard_list:RemoveChildren(0, -1, true)
--开始发牌动画
if isPlayAni == true then
self.cor_init_poker =
coroutine.start(
function()
self._mainView._popEvent = false
if self._mainView._rightPanelView._settingView ~= nil then
self._mainView._rightPanelView._settingView:SetBtnUpdateCardEnable(false)
end
for i = 1, #pokerList do
local pokerListNum = 0
for j = 1, #pokerList[i] do
local card_code = pokerList[i][j]
local btn_card = UIPackage.CreateObjectFromURL('ui://Main_RunBeard/Btn_Card')
btn_card:GetChild('icon').icon = self:getCardItem('ui://Main_RunBeard/201_', card_code)
btn_card:GetChild('icon'):SetScale(self:getCardSize(), self:getCardSize())
btn_card:GetChild('n6'):SetScale(self:getCardSize(), self:getCardSize())
self.card_width = 87 * self:getCardSize()
self.card_hight = 110 * self:getCardSize()
local x, y = 500, (j * 75) - 500
btn_card:SetXY(x, y)
self._area_handcard_list:AddChild(btn_card)
self._area_handcard_list:SetChildIndex(btn_card, 5 - j)
local card_view = NewCardView(btn_card, card_code, i, j)
--存牌堆
self.card_list[#self.card_list + 1] = card_view
btn_card.data = card_view
btn_card.onTouchBegin:Set(handler(self, self.onTouchBegin))
btn_card.onTouchMove:Set(handler(self, self.onTouchMove))
btn_card.onTouchEnd:Set(handler(self, self.__OnDragEnd))
end
for j = #self.card_list, 1, -1 do
coroutine.wait(0.005)
if pokerListNum == #pokerList[i] then
break
end
pokerListNum = pokerListNum + 1
local card_view = self.card_list[j]
card_view.btn_card:RemoveFromParent()
self._area_handcard_list:AddChild(card_view.btn_card)
card_view.btn_card:TweenMove(self:GetHandCardPos(card_view, self.cards_count), 0.08)
end
end
self:UpdateHandCardsPos()
self._mainView._popEvent = true
self:UpdateIsOnClick(true)
if self._mainView._rightPanelView._settingView ~= nil then
coroutine.start(
function()
coroutine.wait(1)
self._mainView._rightPanelView._settingView:SetBtnUpdateCardEnable(true)
end
)
end
end
)
else
--没有发牌动画
for i = 1, #pokerList do
for j = 1, #pokerList[i] do
local card_code = pokerList[i][j]
local btn_card = UIPackage.CreateObjectFromURL('ui://Main_RunBeard/Btn_Card')
btn_card:GetChild('icon').icon = self:getCardItem('ui://Main_RunBeard/201_', card_code)
btn_card:GetChild('icon'):SetScale(self:getCardSize(), self:getCardSize())
btn_card:GetChild('n6'):SetScale(self:getCardSize(), self:getCardSize())
self.card_width = 87 * self:getCardSize()
self.card_hight = 110 * self:getCardSize()
self._area_handcard_list:AddChild(btn_card)
self._area_handcard_list:SetChildIndex(btn_card, 5 - j)
local card_view = NewCardView(btn_card, card_code, i, j)
--存牌堆
self.card_list[#self.card_list + 1] = card_view
btn_card.data = card_view
btn_card.onTouchBegin:Set(handler(self, self.onTouchBegin))
btn_card.onTouchMove:Set(handler(self, self.onTouchMove))
btn_card.onTouchEnd:Set(handler(self, self.__OnDragEnd))
end
--存牌堆
for j = 1, #self.card_list do
local card_view = self.card_list[j]
card_view.btn_card.xy = self:GetHandCardPos(card_view, self.cards_count)
end
end
if self._player.fz_list ~= nil then
for i = 1, #self._player.fz_list do
if self._player.fz_list[i].type == RB_FZType.Kan then
self:UpdateKan(self._player.fz_list[i].card)
end
end
end
self:UpdateHandCardsPos()
end
self:SetNotPutCard()
end
--更新手牌
function M:UpdateHandCards(list)
self.card_list = {}
self._area_handcard_list:RemoveChildren(0, -1, true)
self.outcard_button = nil
local CountCards = {}
2025-07-07 15:47:37 +08:00
-- print("lingmengUpdateHandCards")
-- pt(list)
2025-05-24 14:29:14 +08:00
for i = 1, #list do
CountCards[list[i].index_X] = CountCards[list[i].index_X] == nil and 1 or CountCards[list[i].index_X] + 1
end
for i = 1, #list do
local card_code = list[i].card_item
local btn_card = UIPackage.CreateObjectFromURL('ui://Main_RunBeard/Btn_Card')
btn_card:GetChild('icon').icon = self:getCardItem('ui://Main_RunBeard/201_', card_code)
btn_card:GetChild('icon'):SetScale(self:getCardSize(), self:getCardSize())
btn_card:GetChild('n6'):SetScale(self:getCardSize(), self:getCardSize())
self.card_width = 87 * self:getCardSize()
self.card_hight = 110 * self:getCardSize()
local card_view = NewCardView(btn_card, card_code, list[i].index_X, list[i].index_Y)
--存牌堆
self.card_list[#self.card_list + 1] = card_view
btn_card.data = card_view
btn_card.onTouchBegin:Set(handler(self, self.onTouchBegin))
btn_card.onTouchMove:Set(handler(self, self.onTouchMove))
btn_card.onTouchEnd:Set(handler(self, self.__OnDragEnd))
end
for j = #self.card_list, 1, -1 do
local card_view = self.card_list[j]
card_view.btn_card:RemoveFromParent()
self._area_handcard_list:AddChild(card_view.btn_card)
card_view.btn_card.xy = self:GetHandCardPos(card_view, #CountCards)
end
if self._player.fz_list ~= nil then
for i = 1, #self._player.fz_list do
if self._player.fz_list[i].type == RB_FZType.Kan then
self:UpdateKan(self._player.fz_list[i].card)
end
end
end
self:SetNotPutCard()
end
-- --
function M:onTouchBegin(context)
if DataManager.CurrenRoom == nil or DataManager.CurrenRoom.self_player == nil then
return
end
local button = context.sender
local card = button.data
if DataManager.CurrenRoom.curren_outcard_seat == DataManager.CurrenRoom.self_player.seat then
self:ShowHuTip(card.card_item)
end
card.btn_card:GetChild('icon').icon = self:getCardItem('ui://Main_RunBeard/203_', card.card_item)
-- card.btn_card.sortingOrder = 100
local xy = self._area_handcard_list:GlobalToLocal(Vector2.New(context.inputEvent.x, context.inputEvent.y))
card.btn_card.xy = Vector2.New(card.btn_card.x + 20, card.btn_card.y - 50)
card.touch_pos = xy - button.xy
end
function M:onTouchMove(context)
local button = context.sender
local card = button.data
local xy = self._area_handcard_list:GlobalToLocal(Vector2.New(context.inputEvent.x, context.inputEvent.y))
button.xy = xy - card.touch_pos
end
--出牌提示动画
function M:ChuPaiTiShi()
if DataManager.CurrenRoom == nil or DataManager.CurrenRoom.self_player == nil then
return
end
if DataManager.CurrenRoom.curren_outcard_seat == DataManager.CurrenRoom.self_player.seat then
self._view:GetController('chupai').selectedIndex = 1
else
self._view:GetController('chupai').selectedIndex = 0
end
end
-- 删手牌
function M:DeleteHandCard(carditem)
local card = nil
if self.outcard_button ~= nil and carditem == self.outcard_button.card_item then
list_remove(self.card_list, self.outcard_button)
self._area_handcard_list:RemoveChild(self.outcard_button.btn_card, true)
card = self.outcard_button
self.outcard_button = nil
else
for i = 1, #self.card_list do
local card_view = self.card_list[i]
if carditem == card_view.card_item then
card_view.btn_card.touchable = false
list_remove(self.card_list, card_view)
card = card_view
--card_view.btn_card:RemoveFromParent()
self._area_handcard_list:RemoveChild(card_view.btn_card, true)
break
end
end
end
if card ~= nil then
local num = 0
for i = 1, #self.card_list do
if card.index_X == self.card_list[i].index_X and card.index_Y < self.card_list[i].index_Y then
self.card_list[i].index_Y = self.card_list[i].index_Y - 1
end
if card.index_X == self.card_list[i].index_X then
num = num + 1
end
end
if num == 0 then
for i = 1, #self.card_list do
if self.card_list[i].index_X > card.index_X then
self.card_list[i].index_X = self.card_list[i].index_X - 1
end
end
end
end
self:UpdateHandCardsPos()
end
--更新手牌的坎
function M:UpdateKan(card)
for i = 1, #self.card_list do
local card_view = self.card_list[i]
if card_view.card_item == card then
card_view.btn_card.touchable = false
card_view.btn_card:GetController('Kan').selectedIndex = 1
end
end
end
-- 手牌更新位置方法 self.card_list 里面的对象 NewCardViewindex_X index_Y 就是xy序号
function M:UpdateHandCardsPos()
--得到有 多少列
local CountCards = {}
for i = 1, #self.card_list do
CountCards[self.card_list[i].index_X] =
CountCards[self.card_list[i].index_X] == nil and 1 or CountCards[self.card_list[i].index_X] + 1
end
for i = #self.card_list, 1, -1 do
local card_view = self.card_list[i]
card_view.btn_card:RemoveFromParent()
self._area_handcard_list:AddChild(card_view.btn_card)
card_view.old_postion = self:GetHandCardPos(card_view, #CountCards)
card_view.btn_card:TweenMove(card_view.old_postion, 0.3)
end
self:ShowHuTip()
end
--刷新手牌字体
function M:UpdateCardDisplay()
local CountCards = {}
for i = 1, #self.card_list do
CountCards[self.card_list[i].index_X] =
CountCards[self.card_list[i].index_X] == nil and 1 or CountCards[self.card_list[i].index_X] + 1
end
for i = #self.card_list, 1, -1 do
local card_view = self.card_list[i]
card_view.btn_card:RemoveFromParent()
card_view.btn_card:GetChild('icon').icon = self:getCardItem('ui://Main_RunBeard/201_', card_view.card_item)
self._area_handcard_list:AddChild(card_view.btn_card)
card_view.btn_card:TweenMove(self:GetHandCardPos(card_view, #CountCards), 0.3)
end
end
--更新手牌大小
function M:UpdateCardSize()
local CountCards = {}
for i = 1, #self.card_list do
CountCards[self.card_list[i].index_X] =
CountCards[self.card_list[i].index_X] == nil and 1 or CountCards[self.card_list[i].index_X] + 1
end
for i = #self.card_list, 1, -1 do
local card_view = self.card_list[i]
card_view.btn_card:RemoveFromParent()
card_view.btn_card:GetChild('icon').icon = self:getCardItem('ui://Main_RunBeard/201_', card_view.card_item)
card_view.btn_card:GetChild('icon'):SetScale(self:getCardSize(), self:getCardSize())
card_view.btn_card:GetChild('n6'):SetScale(self:getCardSize(), self:getCardSize())
self.card_width = 87 * self:getCardSize()
self.card_hight = 110 * self:getCardSize()
self._area_handcard_list:AddChild(card_view.btn_card)
card_view.btn_card:TweenMove(self:GetHandCardPos(card_view, #CountCards), 0.3)
end
end
function M:UpdateIsOnClick(isOut)
self._view.touchable = isOut
end
-- 结束 拖拽事件
-- 根据牌结束点的位置 判断是出牌还是调整位置 button.xy 和 牌的xy比较
function M:__OnDragEnd(context)
if DataManager.CurrenRoom == nil or DataManager.CurrenRoom.self_player == nil then
return
end
if self.outcard_button then
self.outcard_button = nil
end
local button = context.sender
local card = button.data
-- card.btn_card.sortingOrder = 0
local _room = DataManager.CurrenRoom
if (button.y < -320 and _room ~= nil and _room.curren_outcard_seat == _room.self_player.seat) then
button.touchable = false
self.outcard_button = card
self:UpdateIsOnClick(false)
self._mainView:OutCard(card.card_item)
else
local isChangeCard = false
self.outcard_button = nil
card.btn_card:GetChild('icon').icon = self:getCardItem('ui://Main_RunBeard/201_', card.card_item)
self._area_handcard_list:AddChild(button)
if #self.card_list == 1 then
isChangeCard = false
self:UpdateHandCardsPos()
return
end
local CountCards = {}
for i = 1, #self.card_list do
local lists = {}
if CountCards[self.card_list[i].index_X] == nil then
lists[#lists + 1] = self.card_list[i]
CountCards[self.card_list[i].index_X] = lists
else
CountCards[self.card_list[i].index_X][#CountCards[self.card_list[i].index_X] + 1] = self.card_list[i]
end
end
local minmark = 1
local maxmark = #self.card_list
if card == self.card_list[1] or card == self.card_list[#self.card_list] then
if self.card_list[1].index_X == self.card_list[2].index_X then
minmark = 2
end
if self.card_list[#self.card_list].index_X == self.card_list[#self.card_list - 1].index_X then
maxmark = #self.card_list - 1
end
end
--位置x小于第一张牌 放第一排
if button.x + button.width / 2 < self.card_list[minmark].btn_card.x and #CountCards < 10 then
--位置大于最后一张牌 放最后一排
list_remove(self.card_list, card)
local num = 0
for i = 1, #self.card_list do
if card.index_X == self.card_list[i].index_X and card.index_Y < self.card_list[i].index_Y then
self.card_list[i].index_Y = self.card_list[i].index_Y - 1
end
if card.index_X == self.card_list[i].index_X then
num = num + 1
end
end
if num == 0 then
for i = 1, #self.card_list do
if self.card_list[i].index_X < card.index_X then
self.card_list[i].index_X = self.card_list[i].index_X + 1
end
end
else
for i = 1, #self.card_list do
self.card_list[i].index_X = self.card_list[i].index_X + 1
end
end
card.index_X = 1
card.index_Y = 1
table.insert(self.card_list, 1, card)
isChangeCard = true
elseif button.x + button.width / 2 > (self.card_list[maxmark].btn_card.x + button.width) and #CountCards < 10 then
list_remove(self.card_list, card)
local num = 0
for i = 1, #self.card_list do
if card.index_X == self.card_list[i].index_X then
num = num + 1
end
if card.index_X == self.card_list[i].index_X and card.index_Y < self.card_list[i].index_Y then
self.card_list[i].index_Y = self.card_list[i].index_Y - 1
end
end
if num == 0 then
for i = 1, #self.card_list do
if self.card_list[i].index_X > card.index_X then
self.card_list[i].index_X = self.card_list[i].index_X - 1
end
end
end
card.index_X = self.card_list[#self.card_list].index_X + 1
card.index_Y = 1
self.card_list[#self.card_list + 1] = card
isChangeCard = true
else
--放已有的牌堆上 判断放第几列
local MoveCard = false
local MoveCardPos = 0
local MoveCardY = 0
for i = 1, #CountCards do
local card_view = CountCards[i][1]
if card_view ~= nil then
if
button.x + button.width / 2 > card_view.old_postion.x and
button.x + button.width / 2 < (card_view.old_postion.x + button.width)
then
if card ~= card_view and #CountCards[i] < 4 and card.index_X ~= card_view.index_X then
MoveCardPos = i
MoveCardY = #CountCards[i] + 1
MoveCard = true
list_remove(self.card_list, card)
end
end
end
end
local MoveCardindex = 0
-- local MoveCardY = 0
if
button.x + button.width / 2 > card.old_postion.x and
button.x + button.width / 2 < (card.old_postion.x + button.width)
then
if #CountCards[card.index_X] > 1 then
for i = 1, #CountCards[card.index_X] do
local _cv = CountCards[card.index_X][i]
if _cv ~= card then
if
button.y + button.height / 2 > _cv.btn_card.y and
button.y + button.height / 2 < (_cv.btn_card.y + button.height)
then
--向下移動
if ((button.y + button.height / 2) + 20) > (card.old_postion.y + button.height) then
--向上移動
MoveCardindex = -1
MoveCardPos = card.index_X
MoveCardY = _cv.index_Y
MoveCard = true
list_remove(self.card_list, card)
elseif ((button.y + button.height / 2) - 20) < card.old_postion.y then
MoveCardindex = 1
MoveCardPos = card.index_X
MoveCardY = _cv.index_Y
MoveCard = true
list_remove(self.card_list, card)
end
elseif i == #CountCards[card.index_X] and button.y + button.height / 2 < _cv.btn_card.y then
MoveCardindex = 1
MoveCardPos = card.index_X
MoveCardY = _cv.index_Y
MoveCard = true
list_remove(self.card_list, card)
elseif i == 1 and button.y + button.height / 2 > (_cv.btn_card.y + button.width) then
MoveCardindex = -1
MoveCardPos = card.index_X
MoveCardY = _cv.index_Y
MoveCard = true
list_remove(self.card_list, card)
end
end
end
end
end
if MoveCard == true and MoveCardindex == 0 then
--上下移动
local num = 0
for i = 1, #self.card_list do
if card.index_X == self.card_list[i].index_X and card.index_Y < self.card_list[i].index_Y then
self.card_list[i].index_Y = self.card_list[i].index_Y - 1
end
if card.index_X == self.card_list[i].index_X then
num = num + 1
end
end
if num == 0 then
for i = 1, #self.card_list do
if self.card_list[i].index_X > card.index_X then
self.card_list[i].index_X = self.card_list[i].index_X - 1
end
end
if MoveCardPos > card.index_X then
MoveCardPos = MoveCardPos - 1
end
end
card.index_X = MoveCardPos
card.index_Y = MoveCardY
for i = #self.card_list, 1, -1 do
if MoveCardPos == self.card_list[i].index_X then
table.insert(self.card_list, (i + 1), card)
break
end
end
isChangeCard = true
elseif MoveCard == true and MoveCardindex ~= 0 then
for i = 1, #self.card_list do
if card.index_X == self.card_list[i].index_X then
--向下移动
if MoveCardindex == -1 then
--向上移动
if self.card_list[i].index_Y < card.index_Y and self.card_list[i].index_Y >= MoveCardY then
self.card_list[i].index_Y = self.card_list[i].index_Y + 1
end
else
if self.card_list[i].index_Y > card.index_Y and self.card_list[i].index_Y <= MoveCardY then
self.card_list[i].index_Y = self.card_list[i].index_Y - 1
end
end
end
end
card.index_X = MoveCardPos
card.index_Y = MoveCardY
for i = #self.card_list, 1, -1 do
if MoveCardPos == self.card_list[i].index_X and self.card_list[i].index_Y == (MoveCardY - 1) then
table.insert(self.card_list, (i + 1), card)
break
elseif MoveCardPos == self.card_list[i].index_X and self.card_list[i].index_Y == (MoveCardY + 1) then
table.insert(self.card_list, i, card)
break
end
end
isChangeCard = true
else
isChangeCard = false
self._area_handcard_list:AddChild(button)
end
end
self:UpdateHandCardsPos()
--每次改变手牌排列发给服务器 重连 回放需要用 --回放需要没次改变都要显示
if isChangeCard == true then
self:SendChangeCard()
end
end
end
--改变手牌排列发给服务器
function M:SendChangeCard(...)
local list = {}
for i = 1, #self.card_list do
local data = {}
data.card = self.card_list[i].card_item
data.X = self.card_list[i].index_X
data.Y = self.card_list[i].index_Y
list[#list + 1] = data
end
self._mainView:ChangeCards(list)
end
--计算手牌位置
function M:GetHandCardPos(cards_view, cards)
local x, y = 0, 0
local card_width = self.card_width -- 牌的宽度
local middle_x = self._area_handcard_list.width / 2
local start_x = middle_x - (cards / 2 * (card_width))
x = start_x + (card_width) * (cards_view.index_X - 1)
if self:getCardSize() == 1 then
y = 90 - (85 * cards_view.index_Y)
elseif self:getCardSize() == 1.2 then
y = 70 - (100 * cards_view.index_Y)
elseif self:getCardSize() == 0.8 then
y = 100 - (65 * cards_view.index_Y)
end
return Vector2.New(x, y)
end
--更新 吃碰
function M:UpdateFzList(fz_list)
printlog("UpdateFzList=======")
pt(fz_list)
self._area_fz_list:RemoveChildren(0, -1, true)
for i = 1, #fz_list do
local fzitem = nil
if fz_list[i].type ~= RB_FZType.Kan then
fzitem = UIPackage.CreateObjectFromURL('ui://Main_RunBeard/Component1')
fzitem:RemoveChildren(0, -1, true)
end
if fz_list[i].type == RB_FZType.Chi or fz_list[i].type == RB_FZType.Bi then
local fzcards = UIPackage.CreateObjectFromURL('ui://Main_RunBeard/Fz_0_3')
fzcards:GetChild('card_' .. 1).icon = self:getCardItem('ui://Main_RunBeard/202_', fz_list[i].active_card)
fzcards:GetController('c2').selectedIndex = 1
fzcards:GetChild('card_' .. 2).icon = self:getCardItem('ui://Main_RunBeard/202_', fz_list[i].opcard[1])
fzcards:GetChild('card_' .. 3).icon = self:getCardItem('ui://Main_RunBeard/202_', fz_list[i].opcard[2])
fzcards.x, fzcards.y = 0, 0
fzitem:AddChildAt(fzcards, 0)
self._area_fz_list:AddChild(fzitem)
elseif fz_list[i].type == RB_FZType.Peng then
local fzcards = UIPackage.CreateObjectFromURL('ui://Main_RunBeard/Fz_0_3')
for j = 1, 3 do
fzcards:GetChild('card_' .. j).icon = self:getCardItem('ui://Main_RunBeard/202_', fz_list[i].card)
end
fzcards.x, fzcards.y = 0, 0
fzitem:AddChildAt(fzcards, 0)
self._area_fz_list:AddChild(fzitem)
elseif fz_list[i].type == RB_FZType.Wei then
local fzcards = UIPackage.CreateObjectFromURL('ui://Main_RunBeard/Fz_0_3')
fzcards:GetController('c1').selectedIndex = 1
for j = 1, 3 do
fzcards:GetChild('card_' .. j).icon = self:getCardItem('ui://Main_RunBeard/202_', fz_list[i].card)
end
fzcards.x, fzcards.y = 0, 0
fzitem:AddChildAt(fzcards, 0)
self._area_fz_list:AddChild(fzitem)
elseif fz_list[i].type == RB_FZType.ChouWei then
local fzcards = UIPackage.CreateObjectFromURL('ui://Main_RunBeard/Fz_0_3')
fzcards:GetController('c1').selectedIndex = 1
for j = 1, 3 do
fzcards:GetChild('card_' .. j).icon = self:getCardItem('ui://Main_RunBeard/202_', fz_list[i].card)
end
fzcards.x, fzcards.y = 0, 0
fzitem:AddChildAt(fzcards, 0)
self._area_fz_list:AddChild(fzitem)
elseif fz_list[i].type == RB_FZType.Pao then
local fzcards = UIPackage.CreateObjectFromURL('ui://Main_RunBeard/Fz_0_4')
for j = 1, 4 do
fzcards:GetChild('card_' .. j).icon = self:getCardItem('ui://Main_RunBeard/202_', fz_list[i].card)
end
fzcards.x, fzcards.y = 0, 0
fzitem:AddChildAt(fzcards, 0)
self._area_fz_list:AddChild(fzitem)
elseif fz_list[i].type == RB_FZType.Ti then
local fzcards = UIPackage.CreateObjectFromURL('ui://Main_RunBeard/Fz_0_4')
for j = 1, 4 do
if j == 4 then
fzcards:GetChild('card_' .. j).icon = self:getCardItem('ui://Main_RunBeard/202_', fz_list[i].card)
else
fzcards:GetChild('card_' .. j).icon = 'ui://Main_RunBeard/202_1_300'
end
end
fzcards.x, fzcards.y = 0, 0
fzitem:AddChildAt(fzcards, 0)
self._area_fz_list:AddChild(fzitem)
end
end
end
function M:ClearOutCard()
self._area_outcard_list:RemoveChildren(0, -1, true)
end
--出牌
function M:UpdateOutCardList(outcard)
self._area_outcard_list:RemoveChildren(0, -1, true)
local outcards = UIPackage.CreateObjectFromURL('ui://Main_RunBeard/Gcm_OutCard')
if outcard == 0 then
outcards:GetChild('icon').icon = 'ui://Main_RunBeard/202_1_300'
else
outcards:GetChild('icon').icon = self:getCardItem('ui://Main_RunBeard/203_', outcard)
end
outcards.x, outcards.y = 0, 0
self._area_outcard_list:AddChild(outcards)
end
--弃牌
function M:UpdateQiPai(qi_list)
self._area_qipai_list:RemoveChildren(0, -1, true)
for i = 1, #qi_list do
local qicards = UIPackage.CreateObjectFromURL('ui://Main_RunBeard/Qipai')
qicards:GetChild('icon').icon = self:getCardItem('ui://Main_RunBeard/202_', qi_list[i])
self._area_qipai_list:AddChild(qicards)
end
end
--摸牌动画
function M:PlayingOutCardAnima(card)
if (self._area_outcard_list ~= nil and self._area_outcard_list.numChildren > 0) then
self._area_outcard_list:GetChildAt(0):GetChild('icon').icon = self:getCardItem('ui://Main_RunBeard/202_', card)
self._view:GetTransition('t0'):Play()
end
coroutine.start(
function()
coroutine.wait(0.1)
self:ClearOutCard()
end
)
end
--得到设置的牌字体
function M:getCardItem(card_1, card_2)
if self._room.change_card_display ~= nil then
return card_1 .. self._room.change_card_display .. card_2
else
return card_1 .. '2_' .. card_2
end
end
--得到设置的牌大小
function M:getCardSize()
if self._room.change_card_size ~= nil then
return self._room.change_card_size
else
return 1
end
end
return M