hengyang_client/lua_probject/main_project/main/majiang/MJPlayerSelfCardInfoView_ji...

330 lines
12 KiB
Lua

local MJPlayerCardInfoView = import(".MJPlayerCardInfoView_jiangxi")
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
local PlayerSelfView = {
_dragCom = nil,
_carViewList = {}
}
local M = PlayerSelfView
function PlayerSelfView.new(view, mainView)
setmetatable(M, { __index = MJPlayerCardInfoView })
local self = setmetatable({}, { __index = M })
self._view = view
self._mainView = mainView
self:init()
return self
end
function M:init()
MJPlayerCardInfoView.init(self)
self._view_getCard = self._view:GetChild('Btn_HandCard')
self._view_FZTips = self._view:GetChild('Comp_FZTips')
self._area_allDown = self._view:GetChild('area_allDown')
self._ctr_seletedGet = self._view:GetController('seletedGetCard')
self._ctr_tip = self._view:GetController('tip')
self._area_allDown.onClick:Set(function()
self._view_handCardList.selectedIndex = -1
self._click_index = self._view_handCardList.selectedIndex
self._ctr_seletedGet.selectedIndex = 1
end)
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)
local _carViewList = self._carViewList
local card_list = DataManager.CurrenRoom.self_player.card_list
getcard = getcard or false
mp = mp or false
if self._view_handCardList.numItems > 0 then
self._view_handCardList:RemoveChildren()
end
if self._view_getCard.numItems > 0 then
self._view_getCard:RemoveChildren()
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._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)
-- btn_card.onClick:Set(handler(self, self.__OnClickHandCard))
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:FillHandCard(i, btn_card, tem_card)
local handCardName = self._viewText_cardInfo['Hand_Card']
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
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
function M:onTouchBegin(context)
local button = context.sender
self._touchPos = button.xy
local card = button.data
self._touchIndex = card.index
local xy_event = Vector2.New(context.inputEvent.x, context.inputEvent.y)
card.touch_pos = Vector2.New(button.width / 2, button.height / 2)
if self.__OnDragStart then
self:__OnDragStart(button, xy_event)
end
end
function M:onTouchMove(context)
local button = context.sender
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)
local card = button.data
--复制一个按钮
local btn_card = self._view_handCardList:GetFromPool("")
print("__OnDragStart", btn_card)
self:FillHandCard(card.index, btn_card, card.card_item)
btn_card:GetController('move').selectedIndex = 1
local xy = GRoot.inst:GlobalToLocal(xy_event)
--将虚影按钮替换移动的按钮
GRoot.inst:AddChild(button)
-- GRoot.inst:BringToFront(button)
self._view_handCardList:AddChildAt(btn_card, card.index)
print("__OnDragStart1", btn_card, card.index)
self._view_handCardList.selectedIndex = card.index
button.xy = xy - card.touch_pos
end
function M:__OnDragEnd(context)
local button = context.sender
local card = button.data
local _room = DataManager.CurrenRoom
if not _room or _room:GetReloadStatus() then return end
local xy = self._view_handCardList:GlobalToLocal(Vector2.New(context.inputEvent.x, context.inputEvent.y))
local buttonHeight = button.height
local temp_button = self._view_handCardList:GetChildAt(card.index)
if (xy.y < 0 - buttonHeight and _room.curren_outcard_seat == _room.self_player.seat) then
self._mainView:OutCard(card.card_item)
self.outcard_button = button
self._notMove = true
else
-- xy = self._view_handCardList:GetChildAt(0):GlobalToLocal(Vector2.New(context.inputEvent.x, context.inputEvent.y))
-- local xy_btnCard = self._view_getCard:GlobalToLocal(Vector2.New(context.inputEvent.x, context.inputEvent.y))
-- if xy.x > 0 then
-- print("lingmeng__OnDragEnd1")
-- if xy_btnCard.x > 0 then
-- coroutine.start(function()
-- print("lingmeng__OnDragEnd2")
-- local card = card
-- local temp_button = temp_button
-- local move_button = self._view_getCard:GetChildAt(0)
-- local move_button_xy = self._view_handCardList:GlobalToLocal(self._view_getCard:LocalToGlobal(
-- Vector2.New(move_button.xy.x, move_button.xy.y)))
-- local temp_button_xy = self._view_getCard:GlobalToLocal(self._view_handCardList:LocalToGlobal(
-- Vector2.New(temp_button.xy.x, temp_button.xy.y)))
-- move_button:TweenMove(temp_button_xy, 0.3)
-- temp_button:TweenMove(move_button_xy, 0.3)
-- coroutine.wait(0.3)
-- self._view_handCardList:RemoveChildAt(card.index)
-- self._view_getCard:RemoveChildren()
-- self._view_getCard:AddChild(temp_button)
-- temp_button.xy = Vector2.New(0, 0)
-- move_button.data.index = card.index
-- self._view_handCardList:AddChildAt(move_button, card.index)
-- coroutine.wait(0.1)
-- self._notMove = true
-- end
-- )
-- else
-- local cardIndex = math.floor(xy.x / (buttonWidth + listGrap))
-- cardIndex = cardIndex >= self._view_handCardList.numItems and self._view_handCardList.numItems - 1 or
-- cardIndex
-- if cardIndex ~= card.index then
-- coroutine.start(function()
-- print("lingmeng__OnDragEnd2")
-- local card = card
-- local cardIndex = cardIndex
-- local temp_button = temp_button
-- local move_button = self._view_handCardList:GetChildAt(cardIndex)
-- local move_button_xy = move_button.xy
-- move_button:TweenMove(temp_button.xy, 0.3)
-- temp_button:TweenMove(move_button_xy, 0.3)
-- coroutine.wait(0.3)
-- self._view_handCardList:RemoveChildAt(card.index)
-- cardIndex = cardIndex > card.index and cardIndex - 1 or cardIndex
-- self._view_handCardList:RemoveChildAt(cardIndex)
-- temp_button.data.index = cardIndex
-- self._view_handCardList:AddChildAt(temp_button, cardIndex)
-- move_button.data.index = card.index
-- self._view_handCardList:AddChildAt(move_button, card.index)
-- coroutine.wait(0.1)
-- self._notMove = true
-- end
-- )
-- else
-- self._notMove = true
-- end
-- end
-- end
temp_button:GetController('move').selectedIndex = 0
button:Dispose()
end
end
function M:__OnClickHandCard(context)
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._view_handCardList.selectedIndex = -1
self._click_index = self._view_handCardList.selectedIndex
self._ctr_seletedGet.selectedIndex = 1
end
self._click_index = self._view_handCardList.selectedIndex
end
function M:__OnClickGetCard(context, flag)
self._view_handCardList.selectedIndex = -1
local button = context.sender
local _room = DataManager.CurrenRoom
if ((Utils.IsDoubleClick(context) or self._flag_seletedGet == 1) and _room.curren_outcard_seat == _room.self_player.seat) then
local card = button.data
self._mainView:OutCard(card.card_item)
self._view_handCardList.selectedIndex = -1
self._click_index = self._view_handCardList.selectedIndex
self._ctr_seletedGet.selectedIndex = 1
self._flag_seletedGet = 0
return
end
self._flag_seletedGet = 1
end
-- function M:UpdateFzList(fz, index, show_card)
-- -- local FZame = self._viewText_cardInfo['FZ_Card']
-- local FZame = "202_"
-- index = index or 0
-- show_card = show_card or nil
-- local outCard
-- 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')
-- elseif fz.type == FZType.Gang_Peng then
-- self._view_FZList:RemoveChildAt(self._view_FZList.numItems - 2)
-- end
-- end
-- end
-- end
-- 获取手牌资源位置,可以在扩展中复写
function M:GetCardObjPack()
return "Main_Majiang"
end
function M:Clear()
MJPlayerCardInfoView.Clear(self)
-- self._view_FZTips:RemoveChildren(0, -1, true)
self._ctr_seletedGet.selectedIndex = 1
end
return M