changhong/lua_probject/extend_project/extend/zipai/fanpaofa/PlayerSelfCardInfoView.lua

493 lines
21 KiB
Lua
Raw Normal View History

2025-05-25 11:35:02 +08:00
local PlayerSelfCardInfoView = import(".main.ZPPlayerSelfCardInfoView")
local CardCheck = import(".main.CardCheck")
local M = {}
--
function M.new(view, mainView)
setmetatable(M, { __index = PlayerSelfCardInfoView })
local self = setmetatable({}, { __index = M })
2025-05-25 11:35:02 +08:00
self.class = "PlayerSelfCardInfoView"
self._view = view
self._mainView = mainView
self._full = true
self:init()
return self
end
function M:onTouchBegin(context)
if DataManager.CurrenRoom == nil or DataManager.CurrenRoom.self_player == nil then
2025-05-25 11:35:02 +08:00
return
end
local button = context.sender
local card = button.data
if DataManager.CurrenRoom.curren_outcard_seat == DataManager.CurrenRoom.self_player.seat then
2025-05-25 11:35:02 +08:00
self:ShowHuTip(card.card_item)
end
card.btn_card:GetChild("icon").icon = self:getCardItem("ui://Main_RunBeard/204_", card.card_item)
-- card.btn_card:GetController('touch').selectedIndex = 1
2025-05-25 11:35:02 +08:00
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)
2025-05-25 11:35:02 +08:00
card.touch_pos = xy - button.xy
end
function M:__OnDragEnd(context)
if DataManager.CurrenRoom == nil or DataManager.CurrenRoom.self_player == nil then
2025-05-25 11:35:02 +08:00
return
end
if self.outcard_button then
self.outcard_button = nil
end
local button = context.sender
2025-06-29 22:21:50 +08:00
local xy = self._area_handcard_list:GlobalToLocal(Vector2.New(context.inputEvent.x, context.inputEvent.y))
2025-05-25 11:35:02 +08:00
local card = button.data
2025-05-25 11:35:02 +08:00
local _room = DataManager.CurrenRoom
card.btn_card.sortingOrder = 0
2025-06-29 22:21:50 +08:00
if (button.y < self._data_outLinePos - button.height * 0.66 and _room.curren_outcard_seat == _room.self_player.seat) then
2025-05-25 11:35:02 +08:00
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)
2025-05-25 11:35:02 +08:00
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
2025-05-25 11:35:02 +08:00
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
2025-05-25 11:35:02 +08:00
else
CountCards[self.card_list[i].index_X][#CountCards[self.card_list[i].index_X] + 1] = self.card_list[i]
2025-05-25 11:35:02 +08:00
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
2025-05-25 11:35:02 +08:00
if self.card_list[1].index_X == self.card_list[2].index_X then
minmark = 2
2025-05-25 11:35:02 +08:00
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
2025-05-25 11:35:02 +08:00
end
end
2025-06-29 22:21:50 +08:00
if xy.x < self.card_list[minmark].btn_card.x and #CountCards < 10 and xy.y > self._data_outLinePos then
list_remove(self.card_list, card)
2025-05-25 11:35:02 +08:00
local num = 0
for i = 1, #self.card_list do
2025-05-25 11:35:02 +08:00
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
2025-05-25 11:35:02 +08:00
end
if card.index_X == self.card_list[i].index_X then
num = num + 1
2025-05-25 11:35:02 +08:00
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
2025-05-25 11:35:02 +08:00
end
else
for i = 1, #self.card_list do
self.card_list[i].index_X = self.card_list[i].index_X + 1
2025-05-25 11:35:02 +08:00
end
end
card.index_X = 1
card.index_Y = 1
table.insert(self.card_list, 1, card)
2025-05-25 11:35:02 +08:00
isChangeCard = true
2025-06-29 22:21:50 +08:00
elseif xy.x > (self.card_list[maxmark].btn_card.x + button.width) and #CountCards < 10 and xy.y > self._data_outLinePos then
list_remove(self.card_list, card)
2025-05-25 11:35:02 +08:00
local num = 0
for i = 1, #self.card_list do
2025-05-25 11:35:02 +08:00
if card.index_X == self.card_list[i].index_X then
num = num + 1
2025-05-25 11:35:02 +08:00
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
2025-05-25 11:35:02 +08:00
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
2025-05-25 11:35:02 +08:00
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
2025-05-25 11:35:02 +08:00
isChangeCard = true
else
2025-05-25 11:35:02 +08:00
local MoveCard = false
local MoveCardPos = 0
local MoveCardY = 0
for i = 1, #CountCards do
2025-05-25 11:35:02 +08:00
local card_view = CountCards[i][1]
if card_view ~= nil then
2025-06-29 22:21:50 +08:00
if xy.x > card_view.old_postion.x and xy.x < (card_view.old_postion.x + button.width) and xy.y > self._data_outLinePos then
if card ~= card_view and #CountCards[i] < 4 and card.index_X ~= card_view.index_X then
2025-05-25 11:35:02 +08:00
MoveCardPos = i
MoveCardY = #CountCards[i] + 1
2025-05-25 11:35:02 +08:00
MoveCard = true
list_remove(self.card_list, card)
2025-05-25 11:35:02 +08:00
end
end
end
end
local MoveCardindex = 0
-- local MoveCardY = 0
2025-06-29 22:21:50 +08:00
-- print("lingmeng end", button.y, MoveCard, button.y > self._data_outLinePos,
2025-06-27 03:16:36 +08:00
-- button.x + button.width / 2 > card.old_postion.x and
2025-06-29 22:21:50 +08:00
-- button.x + button.width / 2 < (card.old_postion.x + button.width) and button.y > self._data_outLinePos)
if xy.x > card.old_postion.x and xy.x < (card.old_postion.x + button.width) and button.y > self._data_outLinePos then
if #CountCards[card.index_X] > 1 then
for i = 1, #CountCards[card.index_X] do
2025-05-25 11:35:02 +08:00
local _cv = CountCards[card.index_X][i]
if _cv ~= card then
2025-06-29 22:21:50 +08:00
if xy.y > _cv.btn_card.y and xy.y < (_cv.btn_card.y + button.height) then
2025-05-25 11:35:02 +08:00
--向下移動
2025-06-29 22:21:50 +08:00
if i < card.index_Y then
MoveCardindex = -1
MoveCardPos = card.index_X
MoveCardY = _cv.index_Y
MoveCard = true
list_remove(self.card_list, card)
--向上移動
2025-06-29 22:21:50 +08:00
elseif i > card.index_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)
2025-05-25 11:35:02 +08:00
end
end
end
end
end
2025-06-29 22:21:50 +08:00
-- print("lingmeng end", MoveCard, MoveCardindex)
if MoveCard == true and MoveCardindex == 0 then
2025-05-25 11:35:02 +08:00
local num = 0
for i = 1, #self.card_list do
2025-05-25 11:35:02 +08:00
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
2025-05-25 11:35:02 +08:00
end
if card.index_X == self.card_list[i].index_X then
num = num + 1
2025-05-25 11:35:02 +08:00
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
2025-05-25 11:35:02 +08:00
end
if MoveCardPos > card.index_X then
MoveCardPos = MoveCardPos - 1
2025-05-25 11:35:02 +08:00
end
end
card.index_X = MoveCardPos
card.index_Y = MoveCardY
for i = #self.card_list, 1, -1 do
2025-05-25 11:35:02 +08:00
if MoveCardPos == self.card_list[i].index_X then
table.insert(self.card_list, (i + 1), card)
2025-05-25 11:35:02 +08:00
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
2025-05-25 11:35:02 +08:00
--向下移动
if MoveCardindex == -1 then
if self.card_list[i].index_Y < card.index_Y and self.card_list[i].index_Y >= MoveCardY then
2025-05-25 11:35:02 +08:00
self.card_list[i].index_Y = self.card_list[i].index_Y + 1
end
--向上移动
2025-05-25 11:35:02 +08:00
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
2025-05-25 11:35:02 +08:00
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)
2025-05-25 11:35:02 +08:00
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)
2025-05-25 11:35:02 +08:00
break
end
end
isChangeCard = true
else
isChangeCard = false
self._area_handcard_list:AddChild(button)
end
end
2025-05-25 11:35:02 +08:00
self:UpdateHandCardsPos()
if isChangeCard == true then
2025-05-25 11:35:02 +08:00
self:SendChangeCard()
end
end
end
function M:UpdateOutCardList(outcard, isShow, isMopai, seat)
if (isShow == nil) then
isShow = false
2025-05-25 11:35:02 +08:00
end
if (isMopai == nil) then
isMopai = false
2025-05-25 11:35:02 +08:00
end
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"
2025-05-25 11:35:02 +08:00
else
outcards:GetChild("icon").icon = self:getCardItem("ui://Main_RunBeard/203_", outcard)
2025-05-25 11:35:02 +08:00
end
outcards.x, outcards.y = 0, 0
local show_di_bg = outcards:GetChild("show_di_bg")
2025-05-25 11:35:02 +08:00
--show_di_bg.visible = true
if (isShow) then
if outcard == 0 then
show_di_bg.visible = false
end
if (seat ~= nil and outcards ~= nil) then
if (isMopai) then
if outcard ~= 0 then
outcards:GetTransition("mopai" .. seat):Play(function()
-- show_di_bg.visible = true
end)
end
2025-05-25 11:35:02 +08:00
else
show_di_bg.visible = false
outcards:GetTransition("cpai" .. seat):Play()
2025-05-25 11:35:02 +08:00
end
else
--show_di_bg.visible = true
end
2025-05-25 11:35:02 +08:00
else
show_di_bg.visible = false
2025-05-25 11:35:02 +08:00
end
self._area_outcard_list:AddChild(outcards)
end
--弃牌
function M:UpdateQiPai(qi_list, isplay)
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])
if (isplay) then
if (i == #qi_list) then
qicards:GetTransition("t0"):Play()
2025-05-25 11:35:02 +08:00
end
end
self._area_qipai_list:AddChild(qicards)
end
2025-05-25 11:35:02 +08:00
end
--摸牌动画
2025-06-29 22:21:50 +08:00
-- 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._bgview.selectedIndex = 1
-- self:ClearOutCard()
-- end
-- )
-- end
2025-05-25 11:35:02 +08:00
2025-06-29 22:21:50 +08:00
function M:UpdateFzList(fz_list, ispaly, seat, flag_pengPao)
2025-06-20 11:52:54 +08:00
--printlog("UpdateFzList area_fz_list2")
self._area_fz_list:RemoveChildren(0, -1, true)
for i = 1, #fz_list do
local fzitem = nil
2025-05-25 11:35:02 +08:00
if fz_list[i].type ~= RB_FZType.Kan then
fzitem = UIPackage.CreateObjectFromURL("ui://Main_RunBeard/ComponentNew")
if (ispaly == false) then
fzitem:RemoveChildren(0, -1, true)
2025-05-25 11:35:02 +08:00
end
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)
2025-05-25 11:35:02 +08:00
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
2025-05-25 11:35:02 +08:00
2025-06-29 22:21:50 +08:00
self:playAnim(fzitem, fzcards, #fz_list, i, ispaly, flag_pengPao)
2025-05-25 11:35:02 +08:00
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)
2025-05-25 11:35:02 +08:00
end
fzcards.x, fzcards.y = 0, 0
2025-06-29 22:21:50 +08:00
self:playAnim(fzitem, fzcards, #fz_list, i, ispaly, flag_pengPao)
2025-05-25 11:35:02 +08:00
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
if j == 1 then
fzcards:GetChild("card_" .. j).icon = self:getCardItem("ui://Main_RunBeard/202_", fz_list[i].card)
2025-05-28 03:06:01 +08:00
else
fzcards:GetChild("card_" .. j).icon = "ui://Main_RunBeard/202_1_300"
2025-05-28 03:06:01 +08:00
end
2025-05-25 11:35:02 +08:00
end
fzcards.x, fzcards.y = 0, 0
2025-06-29 22:21:50 +08:00
self:playAnim(fzitem, fzcards, #fz_list, i, ispaly, flag_pengPao)
2025-05-25 11:35:02 +08:00
elseif fz_list[i].type == RB_FZType.ChouWei then
local fzcards = UIPackage.CreateObjectFromURL("ui://Main_RunBeard/Fz_0_3")
for j = 1, 2 do
fzcards:GetChild("card_" .. j).icon = "ui://Main_RunBeard/202_1_300"
2025-05-25 11:35:02 +08:00
end
fzcards:GetChild("card_" .. 3).icon = self:getCardItem("ui://Main_RunBeard/202_", fz_list[i].card)
fzcards.x, fzcards.y = 0, 0
2025-06-29 22:21:50 +08:00
self:playAnim(fzitem, fzcards, #fz_list, i, ispaly, flag_pengPao)
2025-05-25 11:35:02 +08:00
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)
2025-05-25 11:35:02 +08:00
end
fzcards.x, fzcards.y = 0, 0
2025-06-29 22:21:50 +08:00
self:playAnim(fzitem, fzcards, #fz_list, i, ispaly, flag_pengPao)
2025-05-25 11:35:02 +08:00
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 == 1 then
fzcards:GetChild("card_" .. j).icon = self:getCardItem("ui://Main_RunBeard/202_", fz_list[i].card)
2025-05-25 11:35:02 +08:00
else
fzcards:GetChild("card_" .. j).icon = "ui://Main_RunBeard/202_1_300"
2025-05-25 11:35:02 +08:00
end
end
fzcards.x, fzcards.y = 0, 0
2025-06-29 22:21:50 +08:00
self:playAnim(fzitem, fzcards, #fz_list, i, ispaly, flag_pengPao)
2025-05-25 11:35:02 +08:00
end
end
end
2025-06-29 22:21:50 +08:00
function M:playAnim(fzitem, fzcards, size, i, ispaly, flag_pengPao)
print("lingmeng playAnim", fzitem, fzcards, size, i, ispaly, flag_pengPao)
if (ispaly == nil) then
ispaly = false
end
2025-06-29 22:21:50 +08:00
if (ispaly and i == size and not flag_pengPao) then
local fristCard = self.card_list[1].btn_card
print("lingmeng btn_card", self.card_list[1].index_X)
2025-07-06 07:47:20 +08:00
self._area_handcard_list:AddChild(fzcards)
2025-06-29 22:21:50 +08:00
fzcards:SetPivot(0.5, 0.5)
fzcards.rotation = 180
fzcards.xy = fristCard.xy - Vector2.New(fzcards.width, fzcards.height)
2025-07-06 07:47:20 +08:00
---[[
fzcards:TweenMove(
2025-06-29 22:21:50 +08:00
self._area_fz_list.xy + Vector2.New(fzcards.width, 0) * self._area_fz_list.numItems -
self._area_handcard_list.xy, 0.2)
2025-07-06 07:47:20 +08:00
fzcards:TweenScale(Vector2.New(0.5, 0.5), 0.2)
--]]
---[[
coroutine.start(
2025-06-29 22:21:50 +08:00
function()
2025-07-06 07:47:20 +08:00
coroutine.wait(0.21)
fzcards:RemoveFromParent()
fzcards.xy = Vector2.zero
fzcards.rotation = 0
fzcards:SetScale(1, 1)
fzitem:AddChild(fzcards)
self._area_fz_list:AddChildAt(fzitem, 0)
2025-06-29 22:21:50 +08:00
end
2025-07-06 07:47:20 +08:00
)
--]]
else
fzitem:AddChild(fzcards)
2025-06-29 22:21:50 +08:00
self._area_fz_list:AddChildAt(fzitem, 0)
end
2025-05-25 11:35:02 +08:00
end
--出牌提示动画
function M:ChuPaiTiShi()
if DataManager.CurrenRoom == nil or DataManager.CurrenRoom.self_player == nil then
2025-05-25 11:35:02 +08:00
return
end
local chu_player = DataManager.CurrenRoom.self_player
local selfplayeTable = {}
selfplayeTable.handcard_list = chu_player.handcard_list
selfplayeTable.fz_list = chu_player.fz_list
selfplayeTable.tiCount = chu_player.tiCount
selfplayeTable.paoCount = chu_player.paoCount
selfplayeTable.hu_xi = chu_player.hu_xi
local player = membe_deep_clone(selfplayeTable)
local mark_ting = {}
for i = 1, #DataManager.CurrenRoom.self_player.handcard_list do
local card = DataManager.CurrenRoom.self_player.handcard_list[i]
2025-05-25 11:35:02 +08:00
list_remove(player.handcard_list, card)
local _player = membe_deep_clone(player)
local tingList = CardCheck.tingPai(_player, DataManager.CurrenRoom)
2025-05-25 11:35:02 +08:00
local isKan = false
for j = 1, #player.fz_list do
2025-05-25 11:35:02 +08:00
if card == player.fz_list[j].card and player.fz_list[j].type == RB_FZType.Kan then
isKan = true
2025-05-25 11:35:02 +08:00
end
end
if #tingList > 0 and isKan == false then
mark_ting[#mark_ting + 1] = card
2025-05-25 11:35:02 +08:00
end
table.insert(player.handcard_list, card)
table.sort(player.handcard_list, ViewUtil.HandCardSort)
2025-05-25 11:35:02 +08:00
end
if DataManager.CurrenRoom.curren_outcard_seat == DataManager.CurrenRoom.self_player.seat then
self._view:GetController("chupai").selectedIndex = 1
if #mark_ting > 0 then
for i = 1, #mark_ting do
for k = 1, #self.card_list do
local card_view = self.card_list[k]
2025-05-25 11:35:02 +08:00
if card_view.card_item == mark_ting[i] then
card_view.btn_card:GetController("mark_ting").selectedIndex = 1
end
end
end
end
else
self._view:GetController("chupai").selectedIndex = 0
for k = 1, #self.card_list do
local card_view = self.card_list[k]
2025-05-25 11:35:02 +08:00
card_view.btn_card:GetController("mark_ting").selectedIndex = 0
end
end
end
return M