460 lines
16 KiB
Lua
460 lines
16 KiB
Lua
local PendulumRule = import('.PendulumRule')
|
|
AreaOderType = {
|
|
left_right = "left_right",
|
|
right_left = "right_left",
|
|
up_down = "up_down",
|
|
down_up = "down_up"
|
|
}
|
|
|
|
local PlayerCardInfoView = {
|
|
_view = nil,
|
|
_mainView = nil,
|
|
|
|
_mask_liangpai = nil,
|
|
_area_outcard_list = nil,
|
|
_area_handcard_list = nil,
|
|
|
|
|
|
}
|
|
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 M = PlayerCardInfoView
|
|
|
|
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._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")
|
|
end
|
|
|
|
function M:SetPlayer(p)
|
|
self._player = p
|
|
end
|
|
|
|
function M:FillData(begin)
|
|
|
|
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
|
|
|
|
function M:fillCard(obj, card_type, card)
|
|
|
|
end
|
|
|
|
function M:ClearOutCard()
|
|
self._area_outcard_list:RemoveChildren(0, -1, true)
|
|
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:UpdateFzList(fz_list)
|
|
printlog("UpdateFzList----")
|
|
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: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)
|
|
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")
|
|
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
|
|
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")
|
|
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
|
|
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:InitHandCard(handcard)
|
|
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
|
|
end
|
|
end
|
|
for j = #self.card_lists, 1, -1 do
|
|
local card_view = self.card_lists[j]
|
|
card_view.btn_card:RemoveFromParent()
|
|
self._area_handcard_list:AddChild(card_view.btn_card)
|
|
card_view.btn_card.xy = self:GetHandCardPos(card_view, #pokerList)
|
|
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
|
|
end
|
|
|
|
function M:UpdateHandCards(list)
|
|
self.card_lists = {}
|
|
self._area_handcard_list:RemoveChildren(0, -1, true)
|
|
local CountCards = {}
|
|
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/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
|
|
end
|
|
for j = #self.card_lists, 1, -1 do
|
|
local card_view = self.card_lists[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
|
|
end
|
|
|
|
--牌位置
|
|
function M:GetHandCardPos(cards_view, cards)
|
|
local x, y = 0, 0
|
|
local card_width = 42 -- 牌的宽度
|
|
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)
|
|
y = 0 - (42 * cards_view.index_Y)
|
|
return Vector2.New(x, y)
|
|
end
|
|
|
|
function M:UpdateOutCardList(outcard)
|
|
printlog("UpdateOutCardList2222")
|
|
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"
|
|
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)
|
|
-- self._bgview.selectedIndex=1
|
|
end
|
|
|
|
--摸牌动画
|
|
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)
|
|
end
|
|
outcards:GetChild("icon").icon = self:getCardItem("ui://Main_RunBeard/203_", card)
|
|
outcards:GetTransition("qipai" .. seat):Play()
|
|
end
|
|
|
|
--摆牌规则
|
|
function M:PendulumRule(handcard)
|
|
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
|
|
local cs = {}
|
|
cs[1] = k
|
|
cs[2] = k
|
|
cs[3] = k
|
|
cs[4] = k
|
|
cards_map[#cards_map + 1] = cs
|
|
CountCards[k] = 0
|
|
card_count = card_count - 4
|
|
end
|
|
end
|
|
|
|
|
|
--find3
|
|
for k, v in pairs(CountCards) do
|
|
if (v >= 3) then
|
|
local cs = {}
|
|
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
|
|
end
|
|
end
|
|
--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
|
|
local cs = {}
|
|
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
|
|
end
|
|
end
|
|
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
|
|
local cs = {}
|
|
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
|
|
end
|
|
end
|
|
end
|
|
|
|
--find2
|
|
for k, v in pairs(CountCards) do
|
|
if (v >= 2) then
|
|
local cs = {}
|
|
cs[1] = k
|
|
cs[2] = k
|
|
cards_map[#cards_map + 1] = cs
|
|
CountCards[k] = CountCards[k] - 2
|
|
card_count = card_count - 2
|
|
end
|
|
end
|
|
--find 小 2 7 10
|
|
local counta = CountCards[102]
|
|
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
|
|
end
|
|
end
|
|
end
|
|
|
|
--find 大 2 7 10
|
|
local countA = CountCards[202]
|
|
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
|
|
end
|
|
end
|
|
end
|
|
|
|
--find abc
|
|
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
|
|
end
|
|
end
|
|
--find ABC
|
|
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
|
|
end
|
|
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
|
|
local cs = {}
|
|
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
|
|
end
|
|
end
|
|
end
|
|
|
|
local r_count = 9 - #cards_map
|
|
local merge = false
|
|
merge = r_count < card_count
|
|
local singleList = {}
|
|
--find else
|
|
|
|
for k, v in pairs(CountCards) do
|
|
if (v == 1) then
|
|
singleList[#singleList + 1] = k
|
|
CountCards[k] = CountCards[k] - 1
|
|
end
|
|
end
|
|
local index = 0
|
|
if merge then index = 3 else index = 1 end
|
|
for i = 1, #singleList, index do
|
|
local cs = {}
|
|
if merge then
|
|
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
|
|
else
|
|
cs[#cs + 1] = singleList[i]
|
|
cards_map[#cards_map + 1] = cs
|
|
end
|
|
end
|
|
--变成9列--这里牌多了也不会报错了
|
|
for i = 9, 1, -1 do
|
|
for j = #cards_map, 9, -1 do
|
|
if #cards_map[i] < 3 then
|
|
cards_map[i][#cards_map[i] + 1] = cards_map[j][1]
|
|
list_remove(cards_map[j], cards_map[j][1])
|
|
end
|
|
end
|
|
end
|
|
|
|
return cards_map
|
|
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 .. "6_" .. card_2
|
|
end
|
|
end
|
|
|
|
function M:GetFzMove()
|
|
return self._view:LocalToGlobal(Vector2.New(0, self._area_fz_list.height / 2))
|
|
end
|
|
|
|
return M
|