hengyang_client/lua_probject/extend_project/extend/poker/duoduo/EXPlayerPokerInfoView.lua

563 lines
22 KiB
Lua

---
--- Created by 谌建军.
--- DateTime: 2017/12/13 16:35
---
local EXPlayerPokerInfoView = {
_view = nil,
_mainView = nil,
_mask_liangpai = nil,
}
local M = EXPlayerPokerInfoView
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._gameCtr = ControllerManager.GetController(GameController)
self.item_data = json.decode(self._view:GetChild("area_mask").text)
self.out_card_data = self.item_data["outcard_list"]
self._mask_liangpai = view:GetChild("mask_liangpai")
self.ctr_outpoker = view:GetController("output")
self.outpoker_list = view:GetChild(self.out_card_data["parent"])
-- self.hand_card_list = view:GetChild("hand_card_list")
self.hand_card_list = view:GetChild("list_backHand")
self.ctr_one_card = view:GetController("one_card")
self.eff_one_card = view:GetChild("one_card_eff"):GetTransition("t0")
self.text_bomb_score = view:GetChild("Score")
self.ani_bomb_score = view:GetTransition("score")
self.ani_result_score = view:GetTransition("score_1")
------------------------------lingmeng------------------------
self._view_Out = self._view:GetChild('List_Out')
self._view_resultOut = self._view:GetChild('list_resultOut')
self._ctr_resultOut = self._view:GetController('resultOut')
self._ctr_time_clock = self._view:GetController('time_clock')
self._view_comp_clock = self._view:GetChild('Comp_Clock')
--------------------------------------------------------------
end
-- function M:SetOutCardInfo(cardlist, isPass, isAnim)
-- self.outpoker_list:RemoveChildren(0, -1, true)
-- if cardlist == nil then
-- if isPass == true then
-- self.ctr_outpoker.selectedIndex = 2
-- else
-- self.ctr_outpoker.selectedIndex = 0
-- end
-- else
-- if isAnim then
-- if self.move_cor then
-- coroutine.stop(self.move_cor)
-- self.move_cor = nil
-- end
-- local time = 0.1
-- for i = 1, #cardlist do
-- local poker_item = UIPackage.CreateObject("Extend_Poker_DuoDuo", "poker7")
-- local code = self:ChangeCodeByTo(cardlist[i])
-- -- local card_code_obj = UIPackage.CreateObjectFromURL("ui://Extend_Poker_RunFast/"..code)
-- -- local card_code_obj = UIPackage.CreateObjectFromURL("ui://Main_Poker/" .. code .. "_2")
-- local card_code_obj
-- -- if DataManager.CurrenRoom.pai==0 then
-- -- card_code_obj = UIPackage.CreateObjectFromURL("ui://Extend_Poker_RunFast/"..code)
-- -- else
-- -- card_code_obj = UIPackage.CreateObjectFromURL("ui://Main_Poker/" .. code .. "_2")
-- -- end
-- -- if code==310 and DataManager.CurrenRoom.room_config.Heart10 == 2 then
-- -- -- body
-- -- card_code_obj = UIPackage.CreateObjectFromURL("ui://Extend_Poker_RunFast/"..code.."_1")
-- -- end
-- if DataManager.CurrenRoom.pai == 0 then
-- if code == 310 and DataManager.CurrenRoom.room_config.Heart10 == 2 then
-- -- body
-- card_code_obj = UIPackage.CreateObjectFromURL("ui://Extend_Poker_DuoDuo/" .. code .. "_1")
-- else
-- card_code_obj = UIPackage.CreateObjectFromURL("ui://Extend_Poker_DuoDuo/" .. code)
-- end
-- else
-- if code == 310 and DataManager.CurrenRoom.room_config.Heart10 == 2 then
-- -- body
-- card_code_obj = UIPackage.CreateObjectFromURL("ui://Extend_Poker_DuoDuo/" .. code .. "_2")
-- else
-- card_code_obj = UIPackage.CreateObjectFromURL("ui://Main_Poker/" .. code .. "_2")
-- end
-- end
-- if card_code_obj == nil then
-- card_code_obj = UIPackage.CreateObjectFromURL("ui://Main_Poker/00")
-- end
-- poker_item:AddChild(card_code_obj)
-- --local poker = self:CreatPoker(cardlist[i],0.7)
-- self.outpoker_list:AddChild(poker_item)
-- poker_item.xy = Vector2.New(self.out_card_data["start_x"], self.out_card_data["start_y"])
-- poker_item:TweenMove(
-- self:GetOutCardEndPokerPos(i, #cardlist, self.outpoker_list, poker_item, self.out_card_data
-- ["maxcount_x"], 1.5), time)
-- --card_code_obj
-- -- self.tween = TweenUtils.TweenFloat(1,0.7,time,function(x)
-- -- card_code_obj:SetScale(x,x)
-- -- end)
-- card_code_obj:SetScale(1.5, 1.5)
-- end
-- self.move_cor = coroutine.start(function()
-- coroutine.wait(0.1)
-- ViewUtil.PlaySound("DuoDuo_PK", "extend/poker/duoduo/sound/chupai.mp3")
-- end)
-- else
-- for i = 1, #cardlist do
-- local poker_item = UIPackage.CreateObject("Extend_Poker_DuoDuo", "poker7")
-- local code = self:ChangeCodeByTo(cardlist[i])
-- local card_code_obj
-- if DataManager.CurrenRoom.pai == 0 then
-- if code == 310 and DataManager.CurrenRoom.room_config.Heart10 == 2 then
-- -- body
-- card_code_obj = UIPackage.CreateObjectFromURL("ui://Extend_Poker_DuoDuo/" .. code .. "_1")
-- else
-- card_code_obj = UIPackage.CreateObjectFromURL("ui://Extend_Poker_DuoDuo/" .. code)
-- end
-- else
-- if code == 310 and DataManager.CurrenRoom.room_config.Heart10 == 2 then
-- -- body
-- card_code_obj = UIPackage.CreateObjectFromURL("ui://Extend_Poker_DuoDuo/" .. code .. "_2")
-- else
-- card_code_obj = UIPackage.CreateObjectFromURL("ui://Main_Poker/" .. code .. "_2")
-- end
-- end
-- if card_code_obj == nil then
-- card_code_obj = UIPackage.CreateObjectFromURL("ui://Main_Poker/00")
-- end
-- card_code_obj:SetScale(1.5, 1.5)
-- poker_item:AddChild(card_code_obj)
-- --local poker = self:CreatPoker(cardlist[i],0.7)
-- self.outpoker_list:AddChild(poker_item)
-- poker_item.xy = self:GetOutCardEndPokerPos(i, #cardlist, self.outpoker_list, poker_item,
-- self.out_card_data["maxcount_x"], 1.5)
-- end
-- end
-- --self.ctr_outpoker.selectedIndex = 1
-- end
-- end
function M:SetOutCardInfo(cardlist, isPass, isAnim)
self._view_Out:RemoveChildren(0, -1, true)
if cardlist == nil then
if isPass == true then
self.ctr_outpoker.selectedIndex = 2
else
self.ctr_outpoker.selectedIndex = 0
end
else
self.ctr_outpoker.selectedIndex = 1
-- if isAnim then
-- if self.move_cor then
-- coroutine.stop(self.move_cor)
-- self.move_cor = nil
-- end
-- for i = 1, #cardlist do
-- local poker_item = self._view_Out:AddItemFromPool()
-- local code = self:ChangeCodeByTo(cardlist[i])
-- self:FillPoker(poker_item, "", cardlist[i])
-- end
-- self.move_cor = coroutine.start(function()
-- coroutine.wait(0.1)
-- ViewUtil.PlaySound("DuoDuo_PK", "extend/poker/duoduo/sound/chupai.mp3")
-- end)
-- else
local showOneCard
for i = 1, #cardlist do
if cardlist[i] % 100 < 3 then
local poker_item = self._view_Out:AddItemFromPool()
self:FillPoker2(poker_item, cardlist[i])
else
showOneCard = cardlist[i]
end
end
if showOneCard then
local poker_item = self._view_Out:AddItemFromPool()
self:FillPoker2(poker_item, showOneCard)
self._view:GetChild('text_paiNum').text = string.format("X%s", #cardlist)
else
printlog("error 190", "除了鬼牌没有其他牌")
end
self._view_Out:ResizeToFit(self._view_Out.numItems)
-- end
end
end
function M:SetOutCardBlack()
for i = 0, self.outpoker_list.numChildren - 1 do
self.outpoker_list:GetChildAt(i):GetChildAt(0):GetChildAt(0):GetChildAt(0).color = Color(0.7, 0.7, 0.7)
end
end
-- 12 -61 --11 58 --10 55 --46
function M:GetOffSet(cardLength) -- 15 -70
if cardLength > 8 then
return 52 --40
else
return -cardLength * -10 + 60
end
end
function M:GetOutCardEndFirstPokerPos(count, parent_com, poker_obj, max_count, scale)
local parent_width, parent_height = parent_com.width, parent_com.height
local poker_width, poker_height = poker_obj.width * scale, poker_obj.height * scale
local offset = self:GetOffSet(count)
local x, y = 0, 0
--local length = (count - 1) * (poker_width + offset) + poker_width
--if length <= parent_width then
-- x = (parent_width - length) / 2
-- y = (parent_height - poker_height) / 2
--end
if count <= max_count then
local length = (count - 1) * offset + poker_width
x = (parent_width - length) / 2
y = ((parent_height - poker_height) / 2)
end
return Vector2.New(x, y)
end
function M:GetOutCardEndPokerPos(index, count, parent_com, poker_obj, max_count, scale)
local offset_x, offset_y = self:GetOffSet(count), -100
local start_pos = self:GetOutCardEndFirstPokerPos(count, parent_com, poker_obj, max_count, scale)
local poker_width, poker_height = poker_obj.width * scale, poker_obj.height * scale
local parent_width, parent_height = parent_com.width, parent_com.height
local pos_x, pos_y = start_pos.x + (index - 1) * offset_x, start_pos.y
if index > max_count then
pos_x = (index - max_count - 1) * offset_x
pos_y = pos_y + poker_height + offset_y
end
return Vector2.New(pos_x, pos_y)
end
-- function M:PlayCardTypeEff(type1)
-- if type1 < 7 and type1 ~= 4 then return end
-- local eff_code = 0
-- if type1 == 10 then
-- eff_code = 2
-- elseif type1 == 11 then
-- eff_code = 3
-- elseif type1 == 4 then
-- eff_code = 4
-- else
-- eff_code = 1
-- end
-- if self.cro_type_eff ~= nil then
-- coroutine.stop(self.cro_type_eff)
-- end
-- self.cro_type_eff = nil
-- self.cro_type_eff = coroutine.start(function()
-- self.type_eff_view = UIPackage.CreateObjectFromURL("ui://Extend_Poker_RunFast/eff_"..eff_code)
-- if self.type_eff_view == nil then return end
-- self._view:AddChild(self.type_eff_view)
-- self.type_eff_view:SetXY((self._view.width - self.type_eff_view.width) / 2,self.outpoker_list.y)
-- self.type_eff_view:GetTransition("t0"):Play()
-- coroutine.wait(1.5)
-- if self.type_eff_view ~= nil then
-- self.type_eff_view:Dispose()
-- self.type_eff_view = nil
-- end
-- end)
-- end
function M:PlayScore(score, isBomb, isWin)
if score == nil then
self.text_bomb_score.alpha = 0
return
end
if isBomb then
self.text_bomb_score.text = score >= 0 and "+" .. score or tostring(score)
self.text_bomb_score.grayed = score < 0
self.ani_bomb_score:Play()
else
if score < 0 then
self.text_bomb_score.text = tostring(score)
self.text_bomb_score.grayed = true
elseif score > 0 then
self.text_bomb_score.text = "+" .. score
self.text_bomb_score.grayed = false
else
local str = isWin and "+" or "-"
self.text_bomb_score.text = str .. score
self.text_bomb_score.grayed = not isWin
end
self.ani_result_score:Play()
end
end
function M:UpdateHandPoker(cardList, isPlayAni, isMing)
if self.cor_init_poker ~= nil then
coroutine.stop(self.cor_init_poker)
end
self.cor_init_poker = nil
self.card_list = {}
self.hand_card_list:RemoveChildren(0, -1, true)
local card_length
local new_card_list
if isMing == true then
new_card_list = self._gameCtr:ChangeCodeByFrom(cardList, true)
card_length = #cardList
else
card_length = cardList
end
if isPlayAni == true then
self.cor_init_poker = coroutine.start(function()
for i = card_length, 1, -1 do
local code = isMing == true and new_card_list[i] or 0
coroutine.wait(0.01)
local poker = self:CreatPoker1(code, 0.4)
self.hand_card_list:AddChild(poker)
end
end)
else
for i = card_length, 1, -1 do
local code = isMing == true and new_card_list[i] or 0
local card_number_code = self:ChangeOneCodeByFrom(cardList[i])
local btn_card = self.hand_card_list:AddItemFromPool()
self:FillPoker(btn_card, "", card_number_code)
end
end
end
function M:SetRemainCardNumber(isPlay)
if isPlay then
self.ctr_one_card.selectedIndex = 1
self.eff_one_card:Play(-1, 0, nil)
else
self.ctr_one_card.selectedIndex = 0
end
--if self.card_number then
-- self.card_number.visible = show
-- self.card_number.text = string.format("剩余:%d",number)
--end
end
function M:PlayEffect(type, callback)
Timer.New(function()
local fristCard = self._view_Out:GetChildAt(0)
local lastCard = self._view_Out:GetChildAt(self._view_Out.numItems - 1)
local fristXy = self._view_Out:GlobalToLocal(fristCard:LocalToGlobal(Vector2.New(
fristCard.width * 0,
fristCard.height * 0.5)))
local lastXy = self._view_Out:GlobalToLocal(lastCard:LocalToGlobal(
Vector2.New(lastCard.width * 1,
lastCard.height * 0.5)))
local effect = ""
local y = 0
local x = 0
local width = 0
if type == 10 then
effect = "te_liandui"
y = self._view_Out.y + fristXy.y
x = self._view_Out.x + (lastXy.x + fristXy.x) / 2
elseif type == 4 then
effect = "te_sandaidui"
y = self._view_Out.y + fristXy.y
x = self._view_Out.x + (lastXy.x + fristXy.x) / 2
elseif type == 11 then
effect = "te_sandaidan"
y = self._view_Out.y + fristXy.y
x = self._view_Out.x + (lastXy.x + fristXy.x) / 2
elseif type == 2 then
effect = "te_shunzi"
y = self._view_Out.y + fristXy.y
x = self._view_Out.x + (lastXy.x + fristXy.x) / 2
width = (lastXy.x - fristXy.x) / 1.5
elseif type == 5 or type == 8 or type == 12 then
effect = "te_feiji"
y = self._view_Out.y + fristXy.y
x = self._view_Out.x + (lastXy.x + fristXy.x) / 2
width = (lastXy.x - fristXy.x) / 1.5
elseif type == 6 then
effect = "te_zhadan"
y = self._view_Out.y + fristXy.y
x = self._view_Out.x + (lastXy.x + fristXy.x) / 2
elseif type == 9 then
effect = "te_sidaisab"
y = self._view_Out.y + fristXy.y
x = self._view_Out.x + (lastXy.x + fristXy.x) / 2
end
if #effect > 0 then
local obj = UIPackage.CreateObjectFromURL(string.format("ui://Extend_Poker_DuoDuo/%s", effect))
obj.visible = false
self._view:AddChild(obj)
obj:SetScale(1.3, 1.3)
if y ~= 0 then
obj.y = y
end
if x ~= 0 then
obj.x = x
end
if width ~= 0 then
obj.width = width
end
obj.visible = true
if type == 2 then
obj:GetTransition('t0'):Play(1, 0, function()
obj:GetChild('n11'):TweenMoveX(width * 1.03, 0.3):OnComplete(function()
obj:Dispose()
callback()
end)
obj:GetChild('n12'):TweenMoveX(width * 1.03 - 121, 0.3)
obj:GetChild('n11'):TweenFade(0, 0.3)
obj:GetChild('n12'):TweenFade(0, 0.3)
end)
elseif type == 5 or type == 8 or type == 12 then
obj:GetTransition('t0'):Play(1, 0, function()
obj:GetChild('n13'):TweenMoveX(width * 0.7, 0.4):OnComplete(function()
obj:Dispose()
callback()
end)
obj:GetChild('n14'):TweenMoveX(width * 0.7 - 120, 0.4)
obj:GetChild('n13'):TweenFade(1, 0.2):OnComplete(function()
obj:GetChild('n13'):TweenFade(0, 0.4)
obj:GetChild('n14'):TweenFade(0, 0.4)
end)
end)
elseif type == 6 then
obj:GetTransition('t0'):Play(1, 0, function()
obj:Dispose()
end)
callback()
else
obj:GetTransition('t0'):Play(1, 0, function()
obj:Dispose()
callback()
end)
end
else
callback()
end
end, Time.deltaTime, 1, false):Start()
end
function M:ChangeOneCodeByFrom(card)
local flower = math.floor(card / 100)
local number = card % 100
if number == 2 then
number = 15
end
return number * 10 + flower
end
function M:FillPoker(poker, prefix, num, code)
if num ~= nil then
code = self:ChangeCodeByTo(num)
end
local suffix = code == 310 and
(DataManager.CurrenRoom.pai == 0 and (DataManager.CurrenRoom.room_config.Heart10 == 2 and "_1" or "") or "_2") or
""
code = code == 1 and "00" or code
if not poker.icon then
poker:GetChild('icon').url = string.format("ui://Main_Poker/%s%s%s", prefix, code, suffix)
else
poker.icon = string.format("ui://Main_Poker/%s%s%s", prefix, code, suffix)
end
end
function M:FillPoker2(poker, code, suffix)
suffix = suffix or ""
code = code == 1 and "00" or code
if not poker.icon then
poker:GetChild('icon').url = string.format("ui://Extend_Poker_DuoDuo/%s%s", code, suffix)
else
poker.icon = string.format("ui://Extend_Poker_DuoDuo/%s%s", code, suffix)
end
end
function M:CreatPoker1(poker, scale, bank)
local poker_item = UIPackage.CreateObject("Extend_Poker_DuoDuo", "poker" .. scale * 10)
local code = self:ChangeCodeByTo(poker)
local card_code_obj
if DataManager.CurrenRoom.pai == 0 then
if code == 310 and DataManager.CurrenRoom.room_config.Heart10 == 2 then
-- body
card_code_obj = UIPackage.CreateObjectFromURL("ui://Extend_Poker_DuoDuo/" .. code .. "_1")
else
card_code_obj = UIPackage.CreateObjectFromURL("ui://Extend_Poker_DuoDuo/" .. code)
end
else
if code == 310 and DataManager.CurrenRoom.room_config.Heart10 == 2 then
-- body
card_code_obj = UIPackage.CreateObjectFromURL("ui://Extend_Poker_DuoDuo/" .. code .. "_2")
else
card_code_obj = UIPackage.CreateObjectFromURL("ui://Main_Poker/" .. code .. "_2")
end
end
if card_code_obj == nil or bank == 1 then
card_code_obj = UIPackage.CreateObjectFromURL("ui://Main_Poker/00")
end
card_code_obj:SetScale(scale, scale)
poker_item:AddChild(card_code_obj)
return poker_item
end
function M:CreatPoker(poker, scale, bank)
local poker_item = UIPackage.CreateObject("Extend_Poker_DuoDuo", "poker" .. 12.5)
local code = self:ChangeCodeByTo(poker)
local card_code_obj
if DataManager.CurrenRoom.pai == 0 then
if code == 310 and DataManager.CurrenRoom.room_config.Heart10 == 2 then
-- body
card_code_obj = UIPackage.CreateObjectFromURL("ui://Extend_Poker_DuoDuo/" .. code .. "_1")
else
card_code_obj = UIPackage.CreateObjectFromURL("ui://Extend_Poker_DuoDuo/" .. code)
end
else
if code == 310 and DataManager.CurrenRoom.room_config.Heart10 == 2 then
-- body
card_code_obj = UIPackage.CreateObjectFromURL("ui://Extend_Poker_DuoDuo/" .. code .. "_2")
else
card_code_obj = UIPackage.CreateObjectFromURL("ui://Main_Poker/" .. code .. "_2")
end
end
if card_code_obj == nil or bank == 1 then
card_code_obj = UIPackage.CreateObjectFromURL("ui://Main_Poker/00")
end
card_code_obj:SetScale(scale, scale)
poker_item:AddChild(card_code_obj)
return poker_item
end
function M:ChangeCodeByTo(card)
local flower = card % 10
local number = math.floor(card / 10)
if number == 15 then
number = 2
end
return flower * 100 + number
end
function M:Clear()
self:PlayScore(nil)
self:SetRemainCardNumber(false)
self:SetOutCardInfo(nil, false)
self.hand_card_list:RemoveChildren(0, -1, true)
self._mask_liangpai:RemoveChildren(0, -1, true)
self._view_Out:RemoveChildren(0, -1, true)
self._view_resultOut:RemoveChildren(0, -1, true)
end
function M:Destroy()
end
return M