yunque9/lua_probject/extend_project/extend/zipai/fanpaofa/main/ZPPlayerCardInfoView.lua

460 lines
16 KiB
Lua
Raw Normal View History

2025-05-25 11:35:02 +08:00
local PendulumRule = import('.PendulumRule')
AreaOderType = {
2025-06-29 22:21:50 +08:00
left_right = "left_right",
right_left = "right_left",
up_down = "up_down",
down_up = "down_up"
2025-05-25 11:35:02 +08:00
}
local PlayerCardInfoView = {
2025-06-29 22:21:50 +08:00
_view = nil,
_mainView = nil,
_mask_liangpai = nil,
_area_outcard_list = nil,
_area_handcard_list = nil,
2025-05-25 11:35:02 +08:00
}
2025-06-29 22:21:50 +08:00
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
2025-05-25 11:35:02 +08:00
end
local M = PlayerCardInfoView
2025-06-29 22:21:50 +08:00
function M.new(view, mainView)
local self = {}
setmetatable(self, { __index = M })
self._view = view
self._mainView = mainView
self:init()
return self
2025-05-25 11:35:02 +08:00
end
function M:init()
2025-06-29 22:21:50 +08:00
local view = self._view
self._room = DataManager.CurrenRoom
self._area_outcard_list = view:GetChild("area_outcard_list")
self._bgview = view:GetController("bgview")
self._area_handcard_list = view:GetChild("area_handcard_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")
2025-05-25 11:35:02 +08:00
end
function M:SetPlayer(p)
self._player = p
end
function M:FillData(begin)
2025-06-29 22:21:50 +08:00
2025-05-25 11:35:02 +08:00
end
function M:Clear()
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)
end
2025-06-29 22:21:50 +08:00
function M:fillCard(obj, card_type, card)
2025-05-25 11:35:02 +08:00
end
function M:ClearOutCard()
self._area_outcard_list:RemoveChildren(0, -1, true)
end
--弃牌
2025-06-29 22:21:50 +08:00
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
2025-05-25 11:35:02 +08:00
end
2025-06-29 22:21:50 +08:00
--放字
function M:UpdateFzList(fz_list)
2025-06-24 22:13:50 +08:00
printlog("UpdateFzList----")
2025-06-29 22:21:50 +08:00
self._area_fz_list:RemoveChildren(0, -1, true)
for i = 1, #fz_list do
2025-05-25 11:35:02 +08:00
local fzitem = nil
if fz_list[i].type ~= RB_FZType.Kan then
2025-06-29 22:21:50 +08:00
fzitem = UIPackage.CreateObjectFromURL("ui://Main_RunBeard/Component1")
fzitem:RemoveChildren(0, -1, true)
2025-05-25 11:35:02 +08:00
end
2025-06-29 22:21:50 +08:00
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:GetController("c2").selectedIndex = 1
fzcards:GetChild("card_" .. 1).icon = self:getCardItem("ui://Main_RunBeard/202_", fz_list[i].active_card)
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)
2025-05-25 11:35:02 +08:00
self._area_fz_list:AddChild(fzitem)
elseif fz_list[i].type == RB_FZType.Peng then
2025-06-29 22:21:50 +08:00
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
2025-06-29 22:21:50 +08:00
fzcards.x, fzcards.y = 0, 0
fzitem:AddChildAt(fzcards, 0)
2025-05-25 11:35:02 +08:00
self._area_fz_list:AddChild(fzitem)
elseif fz_list[i].type == RB_FZType.Wei then
2025-06-29 22:21:50 +08:00
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
2025-06-29 22:21:50 +08:00
fzcards:GetChild("card_" .. 3).icon = self:getCardItem("ui://Main_RunBeard/202_", fz_list[i].card)
fzcards.x, fzcards.y = 0, 0
fzitem:AddChildAt(fzcards, 0)
2025-05-25 11:35:02 +08:00
self._area_fz_list:AddChild(fzitem)
elseif fz_list[i].type == RB_FZType.ChouWei then
2025-06-29 22:21:50 +08:00
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
2025-06-29 22:21:50 +08:00
fzcards:GetChild("card_" .. 3).icon = self:getCardItem("ui://Main_RunBeard/202_", fz_list[i].card)
fzcards.x, fzcards.y = 0, 0
fzitem:AddChildAt(fzcards, 0)
2025-05-25 11:35:02 +08:00
self._area_fz_list:AddChild(fzitem)
elseif fz_list[i].type == RB_FZType.Pao then
2025-06-29 22:21:50 +08:00
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
2025-06-29 22:21:50 +08:00
fzcards.x, fzcards.y = 0, 0
fzitem:AddChildAt(fzcards, 0)
2025-05-25 11:35:02 +08:00
self._area_fz_list:AddChild(fzitem)
elseif fz_list[i].type == RB_FZType.Ti then
2025-06-29 22:21:50 +08:00
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)
2025-05-25 11:35:02 +08:00
else
2025-06-29 22:21:50 +08:00
fzcards:GetChild("card_" .. j).icon = "ui://Main_RunBeard/202_1_300"
2025-05-25 11:35:02 +08:00
end
end
2025-06-29 22:21:50 +08:00
fzcards.x, fzcards.y = 0, 0
fzitem:AddChildAt(fzcards, 0)
2025-05-25 11:35:02 +08:00
self._area_fz_list:AddChild(fzitem)
end
end
end
--回放手牌
function M:InitHandCard(handcard)
2025-06-29 22:21:50 +08:00
self._area_handcard_list:RemoveChildren(0, -1, true)
local pokerList = PendulumRule.GetHandCard(handcard) --self:PendulumRule(handcard)
self.card_lists = {}
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/Qipais")
btn_card:GetChild("icon").icon = self:getCardItem("ui://Main_RunBeard/202_", card_code)
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_lists[#self.card_lists + 1] = card_view
2025-05-25 11:35:02 +08:00
end
end
2025-06-29 22:21:50 +08:00
for j = #self.card_lists, 1, -1 do
2025-05-25 11:35:02 +08:00
local card_view = self.card_lists[j]
card_view.btn_card:RemoveFromParent()
self._area_handcard_list:AddChild(card_view.btn_card)
2025-06-29 22:21:50 +08:00
card_view.btn_card.xy = self:GetHandCardPos(card_view, #pokerList)
end
2025-05-25 11:35:02 +08:00
2025-06-29 22:21:50 +08:00
if self._player.fz_list ~= nil then
for i = 1, #self._player.fz_list do
2025-05-25 11:35:02 +08:00
if self._player.fz_list[i].type == RB_FZType.Kan then
self:UpdateKan(self._player.fz_list[i].card)
end
end
end
end
2025-06-29 22:21:50 +08:00
function M:UpdateHandCards(list)
2025-05-25 11:35:02 +08:00
self.card_lists = {}
2025-06-29 22:21:50 +08:00
self._area_handcard_list:RemoveChildren(0, -1, true)
2025-05-25 11:35:02 +08:00
local CountCards = {}
2025-06-29 22:21:50 +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
2025-05-25 11:35:02 +08:00
end
2025-06-29 22:21:50 +08:00
for i = 1, #list do
2025-05-25 11:35:02 +08:00
local card_code = list[i].card_item
2025-06-29 22:21:50 +08:00
local btn_card = UIPackage.CreateObjectFromURL("ui://Main_RunBeard/Qipais")
btn_card:GetChild("icon").icon = self:getCardItem("ui://Main_RunBeard/202_", card_code)
local card_view = NewCardView(btn_card, card_code, list[i].index_X, list[i].index_Y)
--存牌堆
self.card_lists[#self.card_lists + 1] = card_view
2025-05-25 11:35:02 +08:00
end
2025-06-29 22:21:50 +08:00
for j = #self.card_lists, 1, -1 do
2025-05-25 11:35:02 +08:00
local card_view = self.card_lists[j]
card_view.btn_card:RemoveFromParent()
self._area_handcard_list:AddChild(card_view.btn_card)
2025-06-29 22:21:50 +08:00
card_view.btn_card.xy = self:GetHandCardPos(card_view, #CountCards)
end
2025-05-25 11:35:02 +08:00
end
--牌位置
2025-06-29 22:21:50 +08:00
function M:GetHandCardPos(cards_view, cards)
local x, y = 0, 0
local card_width = 42 -- 牌的宽度
2025-05-25 11:35:02 +08:00
local middle_x = self._area_handcard_list.width / 2
2025-06-29 22:21:50 +08:00
local start_x = middle_x - (cards / 2 * (card_width))
x = start_x + (card_width) * (cards_view.index_X - 1)
y = 0 - (42 * cards_view.index_Y)
return Vector2.New(x, y)
2025-05-25 11:35:02 +08:00
end
function M:UpdateOutCardList(outcard)
2025-06-26 02:19:44 +08:00
printlog("UpdateOutCardList2222")
2025-06-29 22:21:50 +08:00
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/201_1_300"
2025-05-25 11:35:02 +08:00
else
2025-06-29 22:21:50 +08:00
outcards:GetChild("icon").icon = self:getCardItem("ui://Main_RunBeard/203_", outcard)
2025-05-25 11:35:02 +08:00
end
2025-06-29 22:21:50 +08:00
outcards.x, outcards.y = 0, 0
2025-05-25 11:35:02 +08:00
self._area_outcard_list:AddChild(outcards)
2025-06-29 22:21:50 +08:00
-- self._bgview.selectedIndex=1
2025-05-25 11:35:02 +08:00
end
--摸牌动画
2025-06-29 22:21:50 +08:00
function M:PlayingOutCardAnima(card, seat)
local outcards = self._area_outcard_list:GetChildAt(0)
if not outcards then
local outcards = UIPackage.CreateObjectFromURL("ui://Main_RunBeard/Gcm_OutCard")
local show_di_bg = outcards:GetChild("show_di_bg")
show_di_bg.visible = false
self._area_outcard_list:AddChild(outcards)
2025-05-25 11:35:02 +08:00
end
2025-06-29 22:21:50 +08:00
outcards:GetChild("icon").icon = self:getCardItem("ui://Main_RunBeard/203_", card)
outcards:GetTransition("qipai" .. seat):Play()
2025-05-25 11:35:02 +08:00
end
--摆牌规则
function M:PendulumRule(handcard)
2025-06-29 22:21:50 +08:00
local room = DataManager.CurrenRoom
local card_list = handcard
local card_count = #card_list
local cards_map = {}
local CountCards = {}
for i = 1, #card_list do
CountCards[card_list[i]] = CountCards[card_list[i]] == nil and 1 or CountCards[card_list[i]] + 1
end
--find4
for k, v in pairs(CountCards) do
if (v == 4) then
2025-05-25 11:35:02 +08:00
local cs = {}
2025-06-29 22:21:50 +08:00
cs[1] = k
cs[2] = k
cs[3] = k
cs[4] = k
cards_map[#cards_map + 1] = cs
2025-05-25 11:35:02 +08:00
CountCards[k] = 0
2025-06-29 22:21:50 +08:00
card_count = card_count - 4
2025-05-25 11:35:02 +08:00
end
end
2025-06-29 22:21:50 +08:00
--find3
for k, v in pairs(CountCards) do
2025-05-25 11:35:02 +08:00
if (v >= 3) then
local cs = {}
2025-06-29 22:21:50 +08:00
cs[1] = k
cs[2] = k
cs[3] = k
cards_map[#cards_map + 1] = cs
CountCards[k] = CountCards[k] - 3
card_count = card_count - 3
2025-05-25 11:35:02 +08:00
end
end
2025-06-29 22:21:50 +08:00
--find AAa
for i = 201, 210 do
if CountCards[i] ~= nil and CountCards[i] >= 2 then
if CountCards[i - 100] ~= nil and CountCards[i - 100] == 1 then
2025-05-25 11:35:02 +08:00
local cs = {}
2025-06-29 22:21:50 +08:00
cs[1] = i
cs[2] = i
cs[3] = i - 100
cards_map[#cards_map + 1] = cs
CountCards[i] = CountCards[i] - 2;
CountCards[i - 100] = CountCards[i - 100] - 1
card_count = card_count - 3
2025-05-25 11:35:02 +08:00
end
end
2025-06-29 22:21:50 +08:00
end
--find aaA
for i = 101, 110 do
if CountCards[i] ~= nil and (CountCards[i] >= 2) then
if CountCards[i + 100] ~= nil and (CountCards[i + 100] == 1) then
2025-05-25 11:35:02 +08:00
local cs = {}
2025-06-29 22:21:50 +08:00
cs[1] = i
cs[2] = i
cs[3] = i + 100
cards_map[#cards_map + 1] = cs
CountCards[i] = CountCards[i] - 2;
CountCards[i + 100] = CountCards[i + 100] - 1
card_count = card_count - 3
2025-05-25 11:35:02 +08:00
end
end
end
--find2
2025-06-29 22:21:50 +08:00
for k, v in pairs(CountCards) do
2025-05-25 11:35:02 +08:00
if (v >= 2) then
local cs = {}
cs[1] = k
cs[2] = k
2025-06-29 22:21:50 +08:00
cards_map[#cards_map + 1] = cs
CountCards[k] = CountCards[k] - 2
card_count = card_count - 2
2025-05-25 11:35:02 +08:00
end
end
--find 小 2 7 10
local counta = CountCards[102]
2025-06-29 22:21:50 +08:00
if counta ~= nil and counta > 0 then
for i = 1, counta do
if CountCards[102] ~= nil and CountCards[107] ~= nil and CountCards[110] ~= nil and CountCards[102] > 0 and CountCards[107] > 0 and CountCards[110] > 0 then
local cs = {}
cs[1] = 102
cs[2] = 107
cs[3] = 110
cards_map[#cards_map + 1] = cs
CountCards[102] = CountCards[102] - 1
CountCards[107] = CountCards[107] - 1
CountCards[110] = CountCards[110] - 1
card_count = card_count - 3
2025-05-25 11:35:02 +08:00
end
end
end
--find 大 2 7 10
local countA = CountCards[202]
2025-06-29 22:21:50 +08:00
if countA ~= nil and countA > 0 then
for i = 1, countA do
if CountCards[202] ~= nil and CountCards[207] ~= nil and CountCards[210] ~= nil and CountCards[202] > 0 and CountCards[207] > 0 and CountCards[210] > 0 then
local cs = {}
cs[1] = 202
cs[2] = 207
cs[3] = 210
cards_map[#cards_map + 1] = cs
CountCards[202] = CountCards[202] - 1
CountCards[207] = CountCards[207] - 1
CountCards[210] = CountCards[210] - 1
card_count = card_count - 3
2025-05-25 11:35:02 +08:00
end
end
end
--find abc
2025-06-29 22:21:50 +08:00
for i = 101, 110 do
if (CountCards[i] ~= nil and CountCards[i + 1] ~= nil and CountCards[i + 2] ~= nil) and (CountCards[i] > 0 and CountCards[i + 1] > 0 and CountCards[i + 2] > 0) then
local cs = {}
cs[1] = i
cs[2] = i + 1
cs[3] = i + 2
cards_map[#cards_map + 1] = cs
CountCards[i] = CountCards[i] - 1
CountCards[i + 1] = CountCards[i + 1] - 1
CountCards[i + 2] = CountCards[i + 2] - 1
card_count = card_count - 3
2025-05-25 11:35:02 +08:00
end
2025-06-29 22:21:50 +08:00
end
2025-05-25 11:35:02 +08:00
--find ABC
2025-06-29 22:21:50 +08:00
for i = 201, 210 do
if (CountCards[i] ~= nil and CountCards[i + 1] ~= nil and CountCards[i + 2] ~= nil) and (CountCards[i] > 0 and CountCards[i + 1] > 0 and CountCards[i + 2] > 0) then
local cs = {}
cs[1] = i
cs[2] = i + 1
cs[3] = i + 2
cards_map[#cards_map + 1] = cs
CountCards[i] = CountCards[i] - 1
CountCards[i + 1] = CountCards[i + 1] - 1
CountCards[i + 2] = CountCards[i + 2] - 1
card_count = card_count - 3
2025-05-25 11:35:02 +08:00
end
2025-06-29 22:21:50 +08:00
end
--find Aa
for i = 201, 210 do
if CountCards[i] ~= nil and CountCards[i] == 1 then
if CountCards[i - 100] ~= nil and CountCards[i - 100] == 1 then
2025-05-25 11:35:02 +08:00
local cs = {}
2025-06-29 22:21:50 +08:00
cs[1] = i
cs[2] = i - 100
cards_map[#cards_map + 1] = cs
CountCards[i] = CountCards[i] - 1;
CountCards[i - 100] = CountCards[i - 100] - 1
card_count = card_count - 2
2025-05-25 11:35:02 +08:00
end
end
2025-06-29 22:21:50 +08:00
end
2025-05-25 11:35:02 +08:00
local r_count = 9 - #cards_map
local merge = false
2025-06-29 22:21:50 +08:00
merge = r_count < card_count
2025-05-25 11:35:02 +08:00
local singleList = {}
2025-06-29 22:21:50 +08:00
--find else
2025-05-25 11:35:02 +08:00
2025-06-29 22:21:50 +08:00
for k, v in pairs(CountCards) do
2025-05-25 11:35:02 +08:00
if (v == 1) then
2025-06-29 22:21:50 +08:00
singleList[#singleList + 1] = k
CountCards[k] = CountCards[k] - 1
2025-05-25 11:35:02 +08:00
end
end
local index = 0
2025-06-29 22:21:50 +08:00
if merge then index = 3 else index = 1 end
for i = 1, #singleList, index do
local cs = {}
2025-05-25 11:35:02 +08:00
if merge then
2025-06-29 22:21:50 +08:00
cs[#cs + 1] = singleList[i]
if i < #singleList then cs[#cs + 1] = singleList[i + 1] end
if i < #singleList - 1 then cs[#cs + 1] = singleList[i + 2] end
cards_map[#cards_map + 1] = cs
2025-05-25 11:35:02 +08:00
else
2025-06-29 22:21:50 +08:00
cs[#cs + 1] = singleList[i]
cards_map[#cards_map + 1] = cs
2025-05-25 11:35:02 +08:00
end
end
--变成9列--这里牌多了也不会报错了
2025-06-29 22:21:50 +08:00
for i = 9, 1, -1 do
for j = #cards_map, 9, -1 do
2025-05-25 11:35:02 +08:00
if #cards_map[i] < 3 then
2025-06-29 22:21:50 +08:00
cards_map[i][#cards_map[i] + 1] = cards_map[j][1]
list_remove(cards_map[j], cards_map[j][1])
2025-05-25 11:35:02 +08:00
end
end
end
return cards_map
end
2025-06-29 22:21:50 +08:00
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
2025-05-25 11:35:02 +08:00
else
2025-06-29 22:21:50 +08:00
return card_1 .. "6_" .. card_2
2025-05-25 11:35:02 +08:00
end
end
2025-06-29 22:21:50 +08:00
function M:GetFzMove()
return self._view:LocalToGlobal(Vector2.New(0, self._area_fz_list.height / 2))
end
2025-05-25 11:35:02 +08:00
2025-06-29 22:21:50 +08:00
return M