client/lua_probject/extend_project/extend/majiang/lichuan/MJPlayerSelfCardInfoView_ji...

386 lines
13 KiB
Lua

local MJPlayerSelfCardInfoView = require("main.majiang.MJPlayerSelfCardInfoView")
local MJPlayerCardInfoView = require("main.majiang.MJPlayerCardInfoView")
local CardCheck = import(".CardCheck")
local M = {}
-----------------------lingmeng---------------------------
--原有mianmajiang
local CardView = {
card = nil,
-- 牌序号
card_item = 0,
-- 索引
index = 0,
-- 原始位置
old_postion = Vector2.zero
}
local function NewCardView(card, cardItem)
local self = {}
setmetatable(self, { __index = CardView })
self.card = card
self.card_item = cardItem
return self
end
----------------------------------------------------------
--
function M.new(view, mainView)
setmetatable(MJPlayerSelfCardInfoView, { __index = MJPlayerCardInfoView })
setmetatable(M, { __index = MJPlayerSelfCardInfoView })
local self = setmetatable({}, { __index = M })
self.class = "PlayerSelfCardInfoView"
self._view = view
self._mainView = mainView
self:init()
return self
end
function M:init()
MJPlayerSelfCardInfoView.init(self)
local CardInfo = self._view:GetChild('Text_CardInfo')
self._viewText_cardInfo = json.decode(CardInfo.text)
self._view_handCardList = self._view:GetChild('List_HandCard')
self._view_FZList = self._view:GetChild('List_FZ')
self._view_outCardList = self._view:GetChild('List_OutCard')
self._viewBtn_getCard = self._view:GetChild('Btn_HandCard')
self._ctr_getCard = self._view:GetController('getCard')
self._ctr_seletedGet = self._view:GetController('seletedGetCard')
end
function M:ShowHuTip(card_list)
printlog("ShowHuTip")
local tingList = CardCheck.MuiltiplteCaculateTingPai(card_list, true, DataManager.CurrenRoom.room_config.Qidui,
DataManager.CurrenRoom.room_config.Laizi)
pt(tingList)
if #tingList > 0 then
if DataManager.CurrenRoom.laiziInfo and #DataManager.CurrenRoom.laiziInfo > 0 then
for i = 1, #DataManager.CurrenRoom.laiziInfo do
if IsHasDictionary(DataManager.CurrenRoom.laiziInfo[i], tingList) == false then
table.insert(tingList, DataManager.CurrenRoom.laiziInfo[i])
end
end
end
end
self._mainView._hu_tip:FillData(tingList)
end
function M:UpdateHandCard(getcard, mp)
-- MJPlayerSelfCardInfoView.UpdateHandCard(self, getcard, mp)
local _carViewList = self._carViewList
local card_list = DataManager.CurrenRoom.self_player.card_list
--[[
if DataManager.CurrenRoom.laiziInfo and #self._carViewList > 0 then
for i = 1, #self._carViewList do
local obj = self._carViewList[i]
if obj and obj.card then
if IsHasDictionary(obj.card_item, DataManager.CurrenRoom.laiziInfo) then
if obj.card.GetController then
if obj.card:GetController("laizi") then
obj.card:GetController("laizi").selectedIndex = 1
end
end
else
if obj.card.GetController then
if obj.card:GetController("laizi") then
obj.card:GetController("laizi").selectedIndex = 0
end
end
end
end
end
end
-- self:ShowHuTip(card_list)
if getcard then
self._out_card = true
local card_list = membe_clone(DataManager.CurrenRoom.self_player.card_list)
-- 记录需要标记听牌提示的牌
local lst_mark = {}
local total_num = 0
for i = 1, #_carViewList do
local btn = _carViewList[i].card
local card = self:GetCard(btn)
list_remove(card_list, card)
local tingList = CardCheck.MuiltiplteCaculateTingPai(card_list, true,
DataManager.CurrenRoom.room_config.Qidui, DataManager.CurrenRoom.room_config.Laizi)
if #tingList > 0 then
local count = 0
for j = 1, #tingList do
count = count + self._mainView:CountCardLeftNum(tingList[j])
end
local tem = {}
tem.item = btn
tem.count = count
total_num = total_num + count
table.insert(lst_mark, tem)
end
table.insert(card_list, card)
end
table.sort(lst_mark, function(a, b)
return a.count > b.count
end)
-- 如果几张牌的可胡牌数一致,也只显示'三角',可胡牌数不一致才显示'多'
local all_same = #lst_mark ~= 0 and lst_mark[1].count == total_num / #lst_mark or false
for i = 1, #lst_mark do
local tem = lst_mark[i]
if all_same or tem.count < lst_mark[1].count then
tem.item:GetController("mark_ting").selectedIndex = 1
else
tem.item:GetController("mark_ting").selectedIndex = 2
end
end
else
for i = 1, #_carViewList do
local btn = _carViewList[i].card
if btn:GetController("mark_ting").selectedIndex ~= 0 then
btn:GetController("mark_ting").selectedIndex = 0
end
end
self._out_card = false
end
]]
-----------------------lingmeng---------------------------
getcard = getcard or false
mp = mp or false
local handCardName = self._viewText_cardInfo['Hand_Card']
if self._view_handCardList.numItems > #card_list - 1 then
self._view_handCardList:RemoveChildrenToPool()
end
for i = 0, (#card_list) - 1 do
local tem_card = card_list[i + 1]
local btn_card
if getcard and i == (#card_list) - 1 then
btn_card = self._viewBtn_getCard
btn_card.onClick:Set(function(context)
self:__OnClickGetCard(context)
end)
else
if i >= self._view_handCardList.numItems then
btn_card = self._view_handCardList:AddItemFromPool()
else
btn_card = self._view_handCardList:GetChildAt(i)
end
end
self:fillCard2(btn_card, handCardName, tem_card)
local c_v = NewCardView(btn_card, tem_card)
c_v.index = i
c_v.old_postion = btn_card.xy
_carViewList[#_carViewList + 1] = c_v
btn_card.data = c_v
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
if getcard then
self._ctr_getCard.selectedIndex = 1
else
self._ctr_getCard.selectedIndex = 0
end
self._view_handCardList.onClickItem:Set(function(context)
self:__OnClickHandCard(context)
end)
----------------------------------------------------------
end
---[[
--新
function M:UpdateOutCardList(outcard, card_item)
outcard = outcard or nil
card_item = card_item or 0
local outCardName = self._viewText_cardInfo['Out_Card']
local outcard
local outlist = self._player.outcard_list
-- if self._view_outCardList.numItems < #outlist - 1 then
-- for i = 1, #outlist - 1 do
-- outcard = self._view_outCardList:AddItemFromPool()
-- -- end
-- self:fillCard2(outcard, outCardName, outlist[i])
-- end
-- end
for i = 0, #outlist - 1 do
outcard = self._view_outCardList:AddItemFromPool()
self:fillCard2(outcard, outCardName, outlist[i + 1])
end
-- if self._viewText_cardInfo['Order'] == "desc" then
-- outcard = self._view_handCardList:GetFromPool("ui://Main_Majiang/Comp_4_OutCard")
-- self._view_outCardList:AddChildAt(outcard, 0)
-- else
-- outcard = self._view_outCardList:AddItemFromPool()
-- -- end
-- self:fillCard2(outcard, outCardName, card_item)
end
function M:onTouchBegin(context)
local button = context.sender
self._touchPos = button.xy
local card = button.data
self._touchIndex = card.index
local xy = self._view_handCardList:GlobalToLocal(Vector2.New(context.inputEvent.x, context.inputEvent.y))
card.touch_pos = xy - button.xy
-- if self.__OnDragStart then
-- self:__OnDragStart(card.card_item)
-- end
end
function M:onTouchMove(context)
local button = context.sender
local card = button.data
local xy = self._view_handCardList:GlobalToLocal(Vector2.New(context.inputEvent.x, context.inputEvent.y))
button.xy = xy - card.touch_pos
end
function M:__OnDragEnd(context)
-- if self.outcard_button then
-- self.outcard_button:Dispose()
-- self.outcard_button = nil
-- end
local button = context.sender
-- -- button.onDragEnd:Set(nil)
-- --button:RemoveFromParent()
local card = button.data
local _room = DataManager.CurrenRoom
if not _room or _room:GetReloadStatus() then return end
-- -- -- print("button.y"..button.y .. "_room.curren_outcard_seat".._room.curren_outcard_seat)
if (button.y < -150 and _room.curren_outcard_seat == _room.self_player.seat) then
self._mainView:OutCard(card.card_item)
button.touchable = false
self.outcard_button = button
button.xy = self._touchPos
else
-- self._area_handcard_list:AddChildAt(button, card.index)
if self._touchIndex ~= card.index then
local tempPos = self._touchPos
self._touchPos = button.xy
button:TweenMove(tempPos, 0.2)
else
button:TweenMove(self._touchPos, 0.2)
self._touchPos = -1
self._touchIndex = -1
end
end
end
function M:__OnClickHandCard(context)
print("=======================lingmengclickhand")
self._ctr_seletedGet.selectedIndex = 0
local button = context.data
-- local _carViewList = self._carViewList
-- for i = 1, #_carViewList do
-- if (_carViewList[i].card ~= button) then
-- _carViewList[i].card.selected = false
-- end
-- end
local _room = DataManager.CurrenRoom
if (Utils.IsDoubleClick(context) and _room.curren_outcard_seat == _room.self_player.seat) then
local card = button.data
self._mainView:OutCard(card.card_item)
end
end
function M:__OnClickGetCard(context)
self._view_handCardList.selectedIndex = -1
local button = context.sender
-- local _carViewList = self._carViewList
-- for i = 1, #_carViewList do
-- if (_carViewList[i].card ~= button) then
-- _carViewList[i].card.selected = false
-- end
-- end
local _room = DataManager.CurrenRoom
if (Utils.IsDoubleClick(context) and _room.curren_outcard_seat == _room.self_player.seat) then
local card = button.data
self._mainView:OutCard(card.card_item)
end
end
function M:UpdateFzList(fz, index, show_card)
local isFour = false
if fz.type == FZType.Gang or fz.type == FZType.Gang_An or fz.type == FZType.Gang_Peng then
isFour = true
end
local FZame = self._viewText_cardInfo['FZ_Card']
index = index or 0
show_card = show_card or nil
local outCard
-- if self._view_outCardList.numItems < #outlist - 1 then
-- for i = 1, #outlist - 1 do
-- outcard = self._view_outCardList:AddItemFromPool()
-- -- end
-- self:fillCard2(outcard, outCardName, outlist[i])
-- end
-- end
outCard = self._view_FZList:AddItemFromPool()
if fz.type == FZType.Chi then
for i = 1, 3 do
local FZCard = outCard:GetChild(string.format("Comp_Card%d", i))
self:fillCard2(FZCard, FZame, fz.opcard[i])
end
else
local ctr_Four = outCard:GetController("isFour")
for i = 1, 3 do
local FZCard = outCard:GetChild(string.format("Comp_Card%d", i))
self:fillCard2(FZCard, FZame, fz.card)
end
if fz.type == FZType.Peng then
ctr_Four.selectedIndex = 0
else
ctr_Four.selectedIndex = 1
local FZCard = outCard:GetChild(string.format("Comp_Card%d", 4))
self:fillCard2(FZCard, FZame, fz.card)
if fz.type == FZType.Gang_An then
self:fillCard2(FZCard, FZame, '00')
end
end
end
-- self:fillCard2(outcard, outCardName, card_item)
end
--]]
function M:Clear(bskip)
--self._ctr_state.selectedIndex = 0
self._area_fz_list.x = self._src_fz_list.x
self._area_fz_list.y = self._src_fz_list.y
self._area_fz_list.width = self._src_fz_list.z
self._area_fz_list.height = self._src_fz_list.w
self._area_fz_list:RemoveChildren(0, -1, true)
self._area_handcard_list:RemoveChildren(0, -1, true)
self._area_outcard_list:RemoveChildren(0, -1, true)
self._view_handCardList:RemoveChildrenToPool()
self._view_outCardList:RemoveChildrenToPool()
self._view_FZList:RemoveChildrenToPool()
if bskip == nil or bskip == false then
self._mask_liangpai:RemoveChildren(0, -1, true)
end
for i = 1, #self._carViewList do
self._carViewList[i].card:Dispose()
end
self._carViewList = {}
end
return M