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 }) 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 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:ClearMpList(mpList) local tempList = {} for k, v in pairs(mpList) do if #v > 0 then table.insert(tempList, v) end end return tempList end 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 local _room = DataManager.CurrenRoom card.btn_card.sortingOrder = 0 -- -- print("button.y"..button.y .. "_room.curren_outcard_seat".._room.curren_outcard_seat) local currentCtrS = IsHasDictionary(card.card_item, DataManager.CurrenRoom.self_player.currentNotPutCardList) if currentCtrS == nil then currentCtrS = false end if (button.y < -380 and _room.curren_outcard_seat == _room.self_player.seat) and currentCtrS == false 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 CountCards = self:ClearMpList(CountCards) 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 if button.x + button.width / 2 < self.card_list[minmark].btn_card.x and #CountCards < 12 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 < 12 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 if CountCards[i] then 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 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:UpdateOutCardList(outcard, isShow, isMopai, seat) if (isShow == nil) then isShow = false end if (isMopai == nil) then isMopai = false 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" else outcards:GetChild("icon").icon = self:getCardItem("ui://Main_RunBeard/203_", outcard) end outcards.x, outcards.y = 0, 0 local show_di_bg = outcards:GetChild("show_di_bg") -- 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 else show_di_bg.visible = false outcards:GetTransition("cpai" .. seat):Play() end else --show_di_bg.visible = true end else show_di_bg.visible = false 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() end end self._area_qipai_list:AddChild(qicards) end end --摸牌动画 function M:PlayingOutCardAnima(card) coroutine.start(function() coroutine.wait(0.1) self:ClearOutCard() end) end function M:UpdateFzList(fz_list, ispaly) 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/ComponentNew") if (ispaly == false) then fzitem:RemoveChildren(0, -1, true) 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) 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 self:playAnim(fzitem, fzcards, #fz_list, i, ispaly) 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 self:playAnim(fzitem, fzcards, #fz_list, i, ispaly) 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 self:playAnim(fzitem,fzcards,#fz_list,i,ispaly)--]] 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" end fzcards:GetChild("card_" .. 3).icon = self:getCardItem("ui://Main_RunBeard/202_", fz_list[i].card) fzcards.x, fzcards.y = 0, 0 self:playAnim(fzitem, fzcards, #fz_list, i, ispaly) 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" end fzcards:GetChild("card_" .. 3).icon = self:getCardItem("ui://Main_RunBeard/202_", fz_list[i].card) fzcards.x, fzcards.y = 0, 0 self:playAnim(fzitem, fzcards, #fz_list, i, ispaly) 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 self:playAnim(fzitem, fzcards, #fz_list, i, ispaly) 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 self:playAnim(fzitem, fzcards, #fz_list, i, ispaly) end end end function M:playAnim(fzitem, fzcards, size, i, ispaly) if (ispaly == nil) then ispaly = false end if (ispaly and i == size) then local faArray = fzitem:GetChild("chiwei") if (faArray ~= nil) then faArray:AddChild(fzcards) else fzitem:AddChild(fzcards) end else fzitem:AddChild(fzcards) end self._area_fz_list:AddChild(fzitem) end --出牌提示动画 function M:ChuPaiTiShi() if DataManager.CurrenRoom == nil or DataManager.CurrenRoom.self_player == nil then 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] list_remove(player.handcard_list, card) local _player = membe_deep_clone(player) local tingList = CardCheck.tingPai(_player, DataManager.CurrenRoom) local isKan = false for j = 1, #player.fz_list do if card == player.fz_list[j].card and player.fz_list[j].type == RB_FZType.Kan then isKan = true end end if #tingList > 0 and isKan == false then mark_ting[#mark_ting + 1] = card end table.insert(player.handcard_list, card) table.sort(player.handcard_list, ViewUtil.HandCardSort) end -- -- print("ChuPaiTiShi",#mark_ting) --pt(mark_ting) 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] 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] card_view.btn_card:GetController("mark_ting").selectedIndex = 0 end end end return M