2025-04-01 10:48:36 +08:00
|
|
|
local MJPlayerCardInfoView = import(".MJPlayerCardInfoView")
|
|
|
|
|
|
|
|
|
|
local PlayerSelfView = {
|
2025-04-16 15:52:21 +08:00
|
|
|
_dragCom = nil,
|
|
|
|
|
_carViewList = {}
|
2025-04-01 10:48:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
local M = PlayerSelfView
|
|
|
|
|
|
2025-04-01 13:56:18 +08:00
|
|
|
function PlayerSelfView.new(view, mainView)
|
2025-04-16 15:52:21 +08:00
|
|
|
setmetatable(M, { __index = MJPlayerCardInfoView })
|
|
|
|
|
local self = setmetatable({}, { __index = M })
|
|
|
|
|
self._view = view
|
|
|
|
|
self._mainView = mainView
|
|
|
|
|
self:init()
|
|
|
|
|
return self
|
2025-04-01 10:48:36 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function M:init()
|
2025-04-16 15:52:21 +08:00
|
|
|
MJPlayerCardInfoView.init(self)
|
|
|
|
|
|
2025-05-19 16:21:21 +08:00
|
|
|
self._view_getCard = self._view:GetChild('Btn_HandCard')
|
|
|
|
|
self._view_FZTips = self._view:GetChild('Comp_FZTips')
|
|
|
|
|
self._area_allDown = self._view:GetChild('area_allDown')
|
2025-06-13 13:33:34 +08:00
|
|
|
self._viewBtn_guoHu = self._view:GetChild('btn_guohu')
|
|
|
|
|
self._viewBtn_buGuoHu = self._view:GetChild('btn_buguohu')
|
|
|
|
|
|
2025-05-19 16:21:21 +08:00
|
|
|
|
|
|
|
|
self._ctr_seletedGet = self._view:GetController('seletedGetCard')
|
|
|
|
|
self._ctr_tip = self._view:GetController('tip')
|
2025-06-13 13:33:34 +08:00
|
|
|
self._ctr_showGuoHu = self._view:GetController('showGuoHu')
|
2025-05-19 16:21:21 +08:00
|
|
|
|
|
|
|
|
self._area_allDown.onClick:Set(function()
|
|
|
|
|
self._view_handCardList.selectedIndex = -1
|
|
|
|
|
self._click_index = self._view_handCardList.selectedIndex
|
|
|
|
|
self._ctr_seletedGet.selectedIndex = 1
|
|
|
|
|
end)
|
2025-06-13 13:33:34 +08:00
|
|
|
|
|
|
|
|
self._viewBtn_buGuoHu.onClick:Set(function()
|
|
|
|
|
self._ctr_tip.selectedIndex = 1
|
|
|
|
|
end)
|
2025-04-01 10:48:36 +08:00
|
|
|
end
|
|
|
|
|
|
2025-05-19 16:21:21 +08:00
|
|
|
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
|
2025-04-16 15:52:21 +08:00
|
|
|
end
|
2025-05-19 16:21:21 +08:00
|
|
|
self._mainView._hu_tip:FillData(tingList)
|
2025-04-01 10:48:36 +08:00
|
|
|
end
|
|
|
|
|
|
2025-04-01 13:56:18 +08:00
|
|
|
function M:UpdateHandCard(getcard, mp)
|
2025-05-19 16:21:21 +08:00
|
|
|
local _carViewList = self._carViewList
|
|
|
|
|
local card_list = DataManager.CurrenRoom.self_player.card_list
|
|
|
|
|
|
2025-04-16 15:52:21 +08:00
|
|
|
getcard = getcard or false
|
|
|
|
|
mp = mp or false
|
2025-05-19 16:21:21 +08:00
|
|
|
self.getcard = getcard
|
2025-04-16 15:52:21 +08:00
|
|
|
|
2025-05-19 16:21:21 +08:00
|
|
|
if self._view_handCardList.numItems > 0 then
|
|
|
|
|
self._view_handCardList:RemoveChildren()
|
2025-04-16 15:52:21 +08:00
|
|
|
end
|
2025-05-19 16:21:21 +08:00
|
|
|
if self._view_getCard.numItems > 0 then
|
|
|
|
|
self._view_getCard:RemoveChildren()
|
2025-04-16 15:52:21 +08:00
|
|
|
end
|
|
|
|
|
|
2025-05-19 16:21:21 +08:00
|
|
|
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._view_getCard:AddItemFromPool()
|
|
|
|
|
btn_card.onClick:Add(function(context)
|
|
|
|
|
self:__OnClickGetCard(context)
|
|
|
|
|
end)
|
|
|
|
|
else
|
|
|
|
|
btn_card = self._view_handCardList:AddItemFromPool()
|
|
|
|
|
end
|
|
|
|
|
self:FillHandCard(i, btn_card, tem_card, true)
|
|
|
|
|
-- btn_card.onClick:Set(handler(self, self.__OnClickHandCard))
|
2025-04-16 15:52:21 +08:00
|
|
|
end
|
|
|
|
|
|
2025-05-19 16:21:21 +08:00
|
|
|
if getcard then
|
|
|
|
|
self._ctr_getCard.selectedIndex = 1
|
2025-04-16 15:52:21 +08:00
|
|
|
else
|
2025-05-19 16:21:21 +08:00
|
|
|
self._ctr_getCard.selectedIndex = 0
|
|
|
|
|
end
|
|
|
|
|
self._view_handCardList.onClickItem:Set(function(context)
|
|
|
|
|
self:__OnClickHandCard(context)
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
self:ClearMove()
|
|
|
|
|
end
|
|
|
|
|
|
2025-06-10 18:48:57 +08:00
|
|
|
function M:UpdateHandCardWitness(getcard)
|
|
|
|
|
self._view_handCardList.columnGap = -10
|
|
|
|
|
MJPlayerCardInfoView.UpdateHandCardWitness(self, getcard, true)
|
|
|
|
|
end
|
|
|
|
|
|
2025-04-01 10:48:36 +08:00
|
|
|
function M:onTouchBegin(context)
|
2025-05-19 16:21:21 +08:00
|
|
|
self.touch = true
|
2025-04-16 15:52:21 +08:00
|
|
|
local button = context.sender
|
2025-05-19 16:21:21 +08:00
|
|
|
self.touchPos = Vector2.New(context.inputEvent.x, context.inputEvent.y)
|
2025-04-01 10:48:36 +08:00
|
|
|
end
|
|
|
|
|
|
2025-04-01 13:56:18 +08:00
|
|
|
function M:onTouchMove(context)
|
2025-04-16 15:52:21 +08:00
|
|
|
local button = context.sender
|
2025-05-19 16:21:21 +08:00
|
|
|
local xy = self._view_handCardList:GlobalToLocal(Vector2.New(context.inputEvent.x, context.inputEvent.y))
|
|
|
|
|
self.touchStart = true
|
|
|
|
|
if xy.y <= -35 or self.isMoive then
|
|
|
|
|
self.isMoive = true
|
|
|
|
|
if self.touch then
|
|
|
|
|
if self.ischoose then
|
|
|
|
|
if self._ctr_seletedGet.selectedIndex == 0 then
|
|
|
|
|
button = self._view_getCard:GetChildAt(0)
|
|
|
|
|
else
|
|
|
|
|
button = self._view_handCardList:GetChildAt(self._view_handCardList.selectedIndex)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
local xy_event = Vector2.New(context.inputEvent.x, context.inputEvent.y)
|
|
|
|
|
local xy_btnCard = self._view_getCard:GlobalToLocal(Vector2.New(context.inputEvent.x, context.inputEvent.y))
|
|
|
|
|
if self.__OnDragStart then
|
|
|
|
|
self:__OnDragStart(button, xy_event)
|
|
|
|
|
end
|
|
|
|
|
self.touch = false
|
|
|
|
|
end
|
|
|
|
|
self:outCardMove(context)
|
|
|
|
|
else
|
|
|
|
|
local touchPos = self._view_handCardList:GetChildAt(0):GlobalToLocal(Vector2.New(context.inputEvent.x,
|
|
|
|
|
context.inputEvent.y))
|
|
|
|
|
if touchPos.x < 0 then
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
local cardWidth = button.width;
|
|
|
|
|
local grap = self._view_handCardList.columnGap
|
|
|
|
|
local chooseIndex = math.floor(touchPos.x / (cardWidth + grap))
|
|
|
|
|
|
|
|
|
|
if chooseIndex >= self._view_handCardList.numItems then
|
|
|
|
|
self.ischoose = true
|
|
|
|
|
if touchPos.x > cardWidth + (cardWidth + grap) * (self._view_handCardList.numItems - 1) and self.getcard then
|
|
|
|
|
self:ChooseOut()
|
|
|
|
|
else
|
|
|
|
|
if self._view_handCardList.selectedIndex ~= self._view_handCardList.numItems - 1 then
|
|
|
|
|
self:ChooseHand(self._view_handCardList.numItems - 1)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
print("lingmengonTouchMove", chooseIndex, self._view_handCardList.numItems)
|
|
|
|
|
|
|
|
|
|
self.ischoose = true
|
|
|
|
|
if self._view_handCardList.selectedIndex ~= chooseIndex then
|
|
|
|
|
self:ChooseHand(chooseIndex)
|
|
|
|
|
else
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- local card = button.data
|
|
|
|
|
-- local xy = GRoot.inst:GlobalToLocal(Vector2.New(context.inputEvent.x, context.inputEvent.y))
|
|
|
|
|
-- button.xy = xy - card.touch_pos
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function M:__OnDragStart(button, xy_event, isGet)
|
|
|
|
|
button:GetController('move').selectedIndex = 1
|
|
|
|
|
|
2025-04-16 15:52:21 +08:00
|
|
|
local card = button.data
|
2025-05-19 16:21:21 +08:00
|
|
|
--复制一个按钮
|
|
|
|
|
|
|
|
|
|
local btn_card = self._view_getCard:GetFromPool(nil)
|
|
|
|
|
self._outCardMove = btn_card
|
|
|
|
|
|
|
|
|
|
self:FillHandCard(card.index, btn_card, card.card_item, false)
|
|
|
|
|
|
|
|
|
|
local xy = GRoot.inst:GlobalToLocal(xy_event)
|
|
|
|
|
|
|
|
|
|
--将虚影按钮替换移动的按钮
|
|
|
|
|
-- GRoot.inst:BringToFront(button)
|
|
|
|
|
GRoot.inst:AddChild(btn_card)
|
|
|
|
|
self._outCardMove.data = card
|
|
|
|
|
self._outCardMove.xy = xy - card.touch_pos
|
|
|
|
|
--设置弹起
|
|
|
|
|
-- if isGet then
|
|
|
|
|
-- self._view_handCardList.selectedIndex = -1
|
|
|
|
|
-- self._ctr_seletedGet.selectedIndex = 0
|
|
|
|
|
-- else
|
|
|
|
|
-- self._view_handCardList.selectedIndex = card.index
|
|
|
|
|
-- self._ctr_seletedGet.selectedIndex = 1
|
|
|
|
|
-- end
|
2025-04-01 10:48:36 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function M:__OnDragEnd(context)
|
2025-05-19 16:21:21 +08:00
|
|
|
if not self.touchStart then
|
|
|
|
|
return
|
2025-04-16 15:52:21 +08:00
|
|
|
end
|
|
|
|
|
local button = context.sender
|
2025-05-19 16:21:21 +08:00
|
|
|
if self.ischoose then
|
|
|
|
|
if self._ctr_seletedGet.selectedIndex == 0 then
|
|
|
|
|
button = self._view_getCard:GetChildAt(0)
|
|
|
|
|
else
|
|
|
|
|
button = self._view_handCardList:GetChildAt(self._view_handCardList.selectedIndex)
|
|
|
|
|
end
|
|
|
|
|
end
|
2025-04-16 15:52:21 +08:00
|
|
|
local card = button.data
|
|
|
|
|
local _room = DataManager.CurrenRoom
|
|
|
|
|
if not _room or _room:GetReloadStatus() then return end
|
|
|
|
|
|
2025-05-19 16:21:21 +08:00
|
|
|
local xy = self._view_handCardList:GlobalToLocal(Vector2.New(context.inputEvent.x, context.inputEvent.y))
|
|
|
|
|
local cardHeight = button.height
|
|
|
|
|
if ((xy.y < -35 or (self.ischoose and self._ctr_seletedGet.selectedIndex == 0) or (context.inputEvent.y - self.touchPos.y < -cardHeight * 0.2)) and _room.curren_outcard_seat == _room.self_player.seat) then
|
2025-04-16 15:52:21 +08:00
|
|
|
self._mainView:OutCard(card.card_item)
|
2025-05-19 16:21:21 +08:00
|
|
|
self.outcard_button = button
|
|
|
|
|
self:ClearChoose()
|
2025-04-16 15:52:21 +08:00
|
|
|
else
|
2025-05-19 16:21:21 +08:00
|
|
|
button:GetController('move').selectedIndex = 0
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if self._outCardMove then
|
|
|
|
|
self._outCardMove:Dispose()
|
2025-04-16 15:52:21 +08:00
|
|
|
end
|
2025-05-19 16:21:21 +08:00
|
|
|
self.isMoive = false
|
|
|
|
|
self.touch = false
|
|
|
|
|
self.ischoose = false
|
|
|
|
|
self.touchStart = false
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function M:outCardMove(context)
|
|
|
|
|
local card = self._outCardMove.data
|
|
|
|
|
local xy = GRoot.inst:GlobalToLocal(Vector2.New(context.inputEvent.x, context.inputEvent.y))
|
|
|
|
|
self._outCardMove.xy = xy - card.touch_pos
|
2025-04-01 10:48:36 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function M:__OnClickHandCard(context)
|
2025-05-19 16:21:21 +08:00
|
|
|
self._ctr_seletedGet.selectedIndex = 1
|
|
|
|
|
self._flag_seletedGet = 0
|
|
|
|
|
local button = context.data
|
|
|
|
|
|
|
|
|
|
local _room = DataManager.CurrenRoom
|
|
|
|
|
if ((Utils.IsDoubleClick(context) or self._click_index == self._view_handCardList.selectedIndex) and _room.curren_outcard_seat == _room.self_player.seat) then
|
|
|
|
|
local card = button.data
|
|
|
|
|
self._mainView:OutCard(card.card_item)
|
|
|
|
|
self:ClearChoose()
|
2025-04-16 15:52:21 +08:00
|
|
|
end
|
2025-05-19 16:21:21 +08:00
|
|
|
self._click_index = self._view_handCardList.selectedIndex
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function M:__OnClickGetCard(context, flag)
|
|
|
|
|
self._view_handCardList.selectedIndex = -1
|
|
|
|
|
self._click_index = self._view_handCardList.selectedIndex
|
|
|
|
|
local button = context.sender
|
2025-04-16 15:52:21 +08:00
|
|
|
local _room = DataManager.CurrenRoom
|
2025-05-19 16:21:21 +08:00
|
|
|
if ((Utils.IsDoubleClick(context) or self._flag_seletedGet == 1) and _room.curren_outcard_seat == _room.self_player.seat) then
|
2025-04-16 15:52:21 +08:00
|
|
|
local card = button.data
|
|
|
|
|
self._mainView:OutCard(card.card_item)
|
2025-05-19 16:21:21 +08:00
|
|
|
self:ClearChoose()
|
|
|
|
|
return
|
2025-04-16 15:52:21 +08:00
|
|
|
end
|
2025-05-19 16:21:21 +08:00
|
|
|
self._flag_seletedGet = 1
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function M:ChooseHand(index)
|
|
|
|
|
self._click_index = index
|
|
|
|
|
self._view_handCardList.selectedIndex = index
|
|
|
|
|
self._ctr_seletedGet.selectedIndex = 1
|
|
|
|
|
self._flag_seletedGet = 0
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function M:ChooseOut()
|
|
|
|
|
self._click_index = -1
|
|
|
|
|
self._view_handCardList.selectedIndex = -1
|
|
|
|
|
self._ctr_seletedGet.selectedIndex = 0
|
|
|
|
|
self._flag_seletedGet = 1
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function M:ClearChoose()
|
|
|
|
|
self._click_index = -1
|
|
|
|
|
self._view_handCardList.selectedIndex = -1
|
|
|
|
|
self._ctr_seletedGet.selectedIndex = 1
|
|
|
|
|
self._flag_seletedGet = 0
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function M:ClearMove()
|
|
|
|
|
self:ClearChoose()
|
|
|
|
|
if self._outCardMove then
|
|
|
|
|
self._outCardMove:Dispose()
|
|
|
|
|
end
|
|
|
|
|
self.isMoive = false
|
|
|
|
|
self.touch = false
|
|
|
|
|
self.ischoose = false
|
|
|
|
|
self.touchStart = false
|
2025-04-01 10:48:36 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- 获取手牌资源位置,可以在扩展中复写
|
|
|
|
|
function M:GetCardObjPack()
|
2025-04-16 15:52:21 +08:00
|
|
|
return "Main_Majiang"
|
2025-04-01 10:48:36 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function M:Clear()
|
2025-04-16 15:52:21 +08:00
|
|
|
MJPlayerCardInfoView.Clear(self)
|
2025-05-19 16:21:21 +08:00
|
|
|
|
|
|
|
|
-- self._view_FZTips:RemoveChildren(0, -1, true)
|
|
|
|
|
|
|
|
|
|
self._ctr_seletedGet.selectedIndex = 1
|
|
|
|
|
self._ctr_tip.selectedIndex = 0
|
2025-04-01 10:48:36 +08:00
|
|
|
end
|
|
|
|
|
|
2025-04-01 13:56:18 +08:00
|
|
|
return M
|