yunque9/lua_probject/extend_project/extend/poker/mushi/MuShi_PlayerSelfPokerInfoVi...

310 lines
9.8 KiB
Lua

---
--- Created by 谌建军.
--- DateTime: 2017/12/13 17:04
---
local MuShi_PlayerPokerInfoView = import('.MuShi_PlayerPokerInfoView')
local MuShi_CardType = import('.MuShi_CardType')
local CardView = {
btn_card = nil,
-- 牌号码 (大小)
card_code_number = 0,
-- 牌号码 (花色)
card_code_flower = 0,
-- 索引
index = 0
}
local function NewCardView(card, cardcodenum, cardcodeflower)
local self = {}
setmetatable(self, {__index = CardView})
self.btn_card = card
self.card_code_number = cardcodenum
self.card_code_flower = cardcodeflower
self.card_isTouchable = 0
return self
end
local function tableSortNumber(a, b)
return a.card_code_number > b.card_code_number
end
local MuShi_PlayerSelfPokerInfoView = {
_view = nil,
_mainView = nil,
_mask_liangpai = nil
}
local M = MuShi_PlayerSelfPokerInfoView
function M.new(view, mainView)
setmetatable(M, {__index = MuShi_PlayerPokerInfoView})
local self = setmetatable({}, {__index = M})
self._view = view
self._mainView = mainView
self.gameCtr = ControllerManager.GetController(GameController)
self:init()
return self
end
function M:init()
self.Reset = false
self.ctr_outpoker = self._view:GetController('output')
self.outpoker_list = self._view:GetChild('out_card_list')
self.item_data = json.decode(self._view:GetChild('area_mask').text)
self.out_card_data = self.item_data['outcard_list']
self.hand_card_list = self._view:GetChild('hand_card_list')
self.ctr_hand_card_pos = self._view:GetChild('hand_card_list')
self._mask_liangpai = self._view:GetChild('mask_liangpai')
self.card_width = 129
self.cards_view = self._view:GetChild('hand_poker_c')
self.card_list = {}
self.out_card_list = {}
self.touchMoveFun = handler(self, self.TouchMoving)
self.ctr_put_card_option = self._view:GetController('out_card_option')
self.ctr_piao = self._view:GetController('piao')
self.ctr_piao_value = self._view:GetController('piao_value')
self.ctr_put_error = self._view:GetController('put_error')
self.put_error_text = self._view:GetChild('put_error')
self.ctr_select_card_type = self._view:GetController('select_card_type')
self.select_card_type_view = self._view:GetChild('choose_type')
self.text_bomb_score = self._view:GetChild('Score')
self.ani_bomb_score = self._view:GetTransition('score')
self.ani_result_score = self._view:GetTransition('score_1')
-- self.carType = self._view:GetChild("cardType")
-- self.carType.visible = false
self.carType = self._view:GetChild("iconType")
self.carIcon = self.carType:GetChild("n0")
self.carType.visible = false
self.carText = self.carType:GetChild("n1")
self.carText.text = ""
-- self.carIcon.icon = "ui://Extend_Poker_MuShi/ms_type_10"
--card_niao.icon = "ui://Main_Majiang/202_" .. currentNiaoList[i].card
self.btnBuPai = self._view:GetChild("bupai")
self.btnBu = self._view:GetChild("bubu")
self.btnKaiPai = self._view:GetChild("kaipai")
self.btnCuoPai = self._view:GetChild("cuopai")
self.ctr_bupai = self._view:GetController("bupai")
self.ctr_bupai.selectedIndex = 0
self.ctr_zhuang = self._view:GetController("zhuang")
self.ctr_bei = self._view:GetController("bei")
self.ctr_zhuang.selectedIndex = 0
self.ctr_bei.selectedIndex = 0
self.send_card = {}
self.tips_click_count = 0
self.btnBank1 = self._view:GetChild("buzhuang")
self.btnBank2 = self._view:GetChild("zhuang1")
self.btnBank3 = self._view:GetChild("zhuang2")
self.btnBank4 = self._view:GetChild("zhuang3")
self.btnBei1 = self._view:GetChild("bei1")
self.btnBei2 = self._view:GetChild("bei2")
self.btnBei3 = self._view:GetChild("bei3")
self.btnBei4 = self._view:GetChild("bei4")
self.btnBei5 = self._view:GetChild("bei5")
self.endcard = self._view:GetChild("endcard")
self.cardopen = false
self:BtnEvent()
end
function M:BtnEvent()
self.btnBuPai.onClick:Set(function()
--printlog("点击补牌=================================")
local _gamectr = ControllerManager.GetController(GameController)
_gamectr:SendBuPai(1)
end)
self.btnBu.onClick:Set(function()
--printlog("点击不补牌=================================")
local _gamectr = ControllerManager.GetController(GameController)
_gamectr:SendBuPai(0)
end)
self.btnKaiPai.onClick:Set(function()
--printlog("点击开牌=================================")
local _gamectr = ControllerManager.GetController(GameController)
_gamectr:SendBuPai(2)
end)
self.btnCuoPai.onClick:Set(function()
--printlog("点击搓牌=================================")
local _gamectr = ControllerManager.GetController(GameController)
_gamectr:SendBuPai(3)
end)
self.btnBank1.onClick:Set(function()
local _gamectr = ControllerManager.GetController(GameController)
_gamectr:SendQiangZhuang(0)
end)
self.btnBank2.onClick:Set(function()
local _gamectr = ControllerManager.GetController(GameController)
_gamectr:SendQiangZhuang(1)
end)
self.btnBank3.onClick:Set(function()
local _gamectr = ControllerManager.GetController(GameController)
_gamectr:SendQiangZhuang(2)
end)
self.btnBank4.onClick:Set(function()
local _gamectr = ControllerManager.GetController(GameController)
_gamectr:SendQiangZhuang(3)
end)
self.btnBei1.onClick:Set(function()
local _gamectr = ControllerManager.GetController(GameController)
_gamectr:SendBet(1)
end)
self.btnBei2.onClick:Set(function()
local _gamectr = ControllerManager.GetController(GameController)
_gamectr:SendBet(2)
end)
self.btnBei3.onClick:Set(function()
local _gamectr = ControllerManager.GetController(GameController)
_gamectr:SendBet(3)
end)
self.btnBei4.onClick:Set(function()
local _gamectr = ControllerManager.GetController(GameController)
_gamectr:SendBet(4)
end)
self.btnBei5.onClick:Set(function()
local _gamectr = ControllerManager.GetController(GameController)
_gamectr:SendBet(5)
end)
end
function M:StarQiangZhuang(b)
self.ctr_zhuang.selectedIndex = b
end
function M:StarBet(b)
self.ctr_bei.selectedIndex = b
end
function M:ChangeCtrBuPai(b)
self.ctr_bupai.selectedIndex = b
end
function M:InitPoker(pokerList,cardtype,cardopen)
self.cardopen = cardopen
for i = 1, #pokerList do
local card_number_code = self:ChangeOneCodeByFrom(pokerList[i])
local card_flower_code = pokerList[i]
local btn_card = self:CreatPoker(pokerList[i], 1, 0)
self.cards_view:AddChild(btn_card)
local card_view = NewCardView(btn_card, card_number_code, card_flower_code)
self.card_list[#self.card_list + 1] = card_view
self.card_list[i].btn_card.visible = false
end
--table.sort(self.card_list, tableSortNumber)
for i = 1, #self.card_list do
local card = self.card_list[i]
card.index = i
-- self.cards_view:SetChildIndex(card.btn_card, card.index - 1)
--card.btn_card.xy = self:GetHandCardPos(i, #self.card_list)
end
if cardtype == MuShi_CardType.TYPE_TIANGONG or cardtype == MuShi_CardType.TYPE_DOUBLE_TIANGONG then
self:SetCarType(cardtype)
end
self._view.visible = true
end
function M:InitPoker2(pokerList)
self.cards_view:RemoveChildren(0, -1, true)
for i = 1, #pokerList do
local card_number_code = self:ChangeOneCodeByFrom(pokerList[i])
local card_flower_code = pokerList[i]
local btn_card = self:CreatPoker(pokerList[i], 1, 0)
self.cards_view:AddChild(btn_card)
local card_view = NewCardView(btn_card, card_number_code, card_flower_code)
self.card_list[#self.card_list + 1] = card_view
end
end
function M:AddPoker(poker)
--print("玩家自己加牌===========================================")
local card_number_code = self:ChangeOneCodeByFrom(poker)
local card_flower_code = poker
local btn_card = self:CreatPoker(poker, 1, 0)
self.cards_view:AddChild(btn_card)
local card_view = NewCardView(btn_card, card_number_code, card_flower_code)
self.card_list[#self.card_list + 1] = card_view
--card_view.btn_card.xy = self:GetHandCardPos(3, #self.card_list)
end
function M:ShowCard(index)
self.cards_view:GetChildAt(index).visible = true
if self.cardopen == true then
self.carType.visible = true
end
end
function M:GetHandCardPos(index, card_count)
local x, y = 0, -18
local offset = 40
x = offset*index
return Vector2.New(x, y)
end
function M:ChangeOneCodeByFrom(card)
if(card > 500) then
return card
end
local flower = math.floor(card / 100)
local number = card % 100
if number == 2 then
number = 15
end
return number * 10 + flower
end
function M:ErrorTip(error_text)
if self.cor_init_poker ~= nil then
coroutine.stop(self.cor_init_poker)
end
self.cor_init_poker = nil
self.cor_init_poker =
coroutine.start(
function()
self.put_error_text.text = error_text
self.ctr_put_error.selectedIndex = 1
coroutine.wait(2)
self.ctr_put_error.selectedIndex = 0
end
)
end
function M:Clear()
self:PlayScore(nil)
--self:SetOutCardInfo(nil, false)
self.card_list = {}
self.out_card_list = {}
self.cards_view:RemoveChildren(0, -1, true)
self.carType.visible = false
--self.mask_liangpai:RemoveChildren(0,-1,true)
end
function M:Destroy()
Stage.inst.onTouchMove:Remove(self.touchMoveFun)
end
return M