202 lines
7.5 KiB
Lua
202 lines
7.5 KiB
Lua
require("Base/BasePanel")
|
|
ArenaTopMatchGuessTipViewPopup = Inherit(BasePanel)
|
|
local this = ArenaTopMatchGuessTipViewPopup
|
|
local betBattleInfo = nil
|
|
--倒计时
|
|
local count = 10
|
|
--标题
|
|
local resultText = {[0] = Language[10107], [1] = Language[10108]}
|
|
local resultColor = {
|
|
[0] = Color.New(165 / 255, 165 / 255, 165 / 255, 1),
|
|
[1] = Color.New(232 / 255, 216 / 255, 186 / 255, 1)
|
|
}
|
|
--竞猜胜负图片
|
|
local resultImage = {
|
|
[0] = {name = "UI_effect_JJC_JieSuan_ShiBai_png_zh"},
|
|
[1] = {name = "UI_effect_JJC_JieSuan_ShengLi_png_zh"}
|
|
}
|
|
--头像容器
|
|
local headList = {}
|
|
--竞猜币ItemId
|
|
local GUESS_COIN = ArenaTopMatchManager.GetGuessCoinID()
|
|
--竞猜币动态显示持续时长
|
|
local duration=2
|
|
--计时间隔
|
|
local interval=0.1
|
|
--竞猜币数量浮动图
|
|
local upAndDownImage={[0]="r_hero_zhanlixiajiang_png",[1]="r_hero_zhanlishangsheng_png"}
|
|
--竞猜结果
|
|
local endResult = -1
|
|
|
|
--初始化组件(用于子类重写)
|
|
function ArenaTopMatchGuessTipViewPopup:InitComponent()
|
|
this.spLoader = SpriteLoader.New()
|
|
|
|
this.title = Util.GetGameObject(self.gameObject, "ATM_GuessTipView/Title"):GetComponent("Text")
|
|
this.backBtn = Util.GetGameObject(self.gameObject, "ATM_GuessTipView/BackBtn")
|
|
this.coinNum = Util.GetGameObject(self.gameObject, "ATM_GuessTipView/CoinNum"):GetComponent("Text")
|
|
this.coinState = Util.GetGameObject(self.gameObject, "ATM_GuessTipView/CoinNum/CoinState"):GetComponent("Image")
|
|
this.time = Util.GetGameObject(self.gameObject, "ATM_GuessTipView/Time"):GetComponent("Text")
|
|
|
|
this.leftName = Util.GetGameObject(self.gameObject, "ATM_GuessTipView/BattlePopup/Left/Grade/Name"):GetComponent("Text")
|
|
this.leftHead = Util.GetGameObject(self.gameObject, "ATM_GuessTipView/BattlePopup/Left/Grade/Head")
|
|
this.leftMark=Util.GetGameObject(self.gameObject,"ATM_GuessTipView/BattlePopup/Left/Grade/Mark"):GetComponent("Image")
|
|
this.leftResult = Util.GetGameObject(self.gameObject, "ATM_GuessTipView/BattlePopup/Left/Result"):GetComponent("Image")
|
|
|
|
this.rightName = Util.GetGameObject(self.gameObject, "ATM_GuessTipView/BattlePopup/Right/Grade/Name"):GetComponent("Text")
|
|
this.rightHead = Util.GetGameObject(self.gameObject, "ATM_GuessTipView/BattlePopup/Right/Grade/Head")
|
|
this.rightMark=Util.GetGameObject(self.gameObject,"ATM_GuessTipView/BattlePopup/Right/Grade/Mark"):GetComponent("Image")
|
|
this.rightResult = Util.GetGameObject(self.gameObject, "ATM_GuessTipView/BattlePopup/Right/Result"):GetComponent("Image")
|
|
end
|
|
|
|
--绑定事件(用于子类重写)
|
|
function ArenaTopMatchGuessTipViewPopup:BindEvent()
|
|
Util.AddClick(this.backBtn,function()
|
|
self:ClosePanel()
|
|
end)
|
|
end
|
|
|
|
--添加事件监听(用于子类重写)
|
|
function ArenaTopMatchGuessTipViewPopup:AddListener()
|
|
|
|
end
|
|
|
|
--移除事件监听(用于子类重写)
|
|
function ArenaTopMatchGuessTipViewPopup:RemoveListener()
|
|
|
|
end
|
|
|
|
--界面打开时调用(用于子类重写)
|
|
function ArenaTopMatchGuessTipViewPopup:OnOpen(...)
|
|
this.TimeCountDown()
|
|
local IsCanBet = ArenaTopMatchManager.IsCanBet()
|
|
--LogGreen("IsCanBet "..tostring(IsCanBet))
|
|
if IsCanBet then
|
|
betBattleInfo = ArenaTopMatchManager.GetBetBattleInfo()
|
|
local myBetTarget = ArenaTopMatchManager.GetMyBetTarget()
|
|
local isBetBlue = myBetTarget == betBattleInfo.myInfo.uid
|
|
local isBetRed = myBetTarget == betBattleInfo.enemyInfo.uid
|
|
if betBattleInfo.result == -1 then return end
|
|
endResult = -1
|
|
--设置标题
|
|
if isBetBlue then
|
|
local result=betBattleInfo.result
|
|
this.title.text = resultText[result]
|
|
this.title.color = resultColor[result]
|
|
this.coinState.sprite=this.spLoader:LoadSprite(upAndDownImage[result])
|
|
endResult = result
|
|
end
|
|
if isBetRed then
|
|
local result=(betBattleInfo.result+1)%2
|
|
this.title.text = resultText[result]
|
|
this.title.color = resultColor[result]
|
|
this.coinState.sprite=this.spLoader:LoadSprite(upAndDownImage[result])
|
|
endResult = result
|
|
end
|
|
this.coinState:SetNativeSize()
|
|
|
|
--设置玩家名
|
|
this.leftName.text = betBattleInfo.myInfo.name
|
|
this.rightName.text = betBattleInfo.enemyInfo.name
|
|
this.SetHead(this.leftHead, betBattleInfo.myInfo)
|
|
this.SetHead(this.rightHead, betBattleInfo.enemyInfo)
|
|
this.SetResultIcon(this.leftResult, this.rightResult, betBattleInfo.result)
|
|
|
|
--设置押注标志
|
|
this.leftMark.enabled=isBetBlue
|
|
this.rightMark.enabled=isBetRed
|
|
|
|
--设置竞猜币
|
|
this.SetCoin()
|
|
end
|
|
end
|
|
--倒计时
|
|
function this.TimeCountDown()
|
|
count = 10
|
|
if not this.timer then
|
|
this.timer = Timer.New(function()
|
|
this.time.text = string.format(Language[10109], count)
|
|
count = count - 1
|
|
if count <= 0 then
|
|
count = 0
|
|
this.timer:Stop()
|
|
this.timer = nil
|
|
this:ClosePanel()
|
|
end
|
|
end, 1, -1, true)
|
|
this.timer:Start()
|
|
end
|
|
end
|
|
|
|
--设置头像
|
|
function this.SetHead(head, data)
|
|
if not headList[head] then
|
|
headList[head] = CommonPool.CreateNode(POOL_ITEM_TYPE.PLAYER_HEAD, head)
|
|
end
|
|
headList[head]:Reset()
|
|
headList[head]:SetScale(Vector3.one * 0.7)
|
|
headList[head]:SetHead(data.head)
|
|
headList[head]:SetFrame(data.headFrame)
|
|
headList[head]:SetLevel(data.level)
|
|
headList[head]:SetLayer(this.sortingOrder)
|
|
headList[head]:SetEffectScale(0.8)
|
|
end
|
|
|
|
--设置胜负图片
|
|
function this.SetResultIcon(obj1, obj2, result)
|
|
if result == 1 then
|
|
obj1.sprite = this.spLoader:LoadSprite(resultImage[1].name)
|
|
obj2.sprite = this.spLoader:LoadSprite(resultImage[0].name)
|
|
elseif result == 0 then
|
|
obj1.sprite = this.spLoader:LoadSprite(resultImage[0].name)
|
|
obj2.sprite = this.spLoader:LoadSprite(resultImage[1].name)
|
|
end
|
|
end
|
|
|
|
--设置竞猜币
|
|
function this.SetCoin()
|
|
local oldNum= ArenaTopMatchManager.GetCoinNum() + ArenaTopMatchManager.GetMyBetCoins()
|
|
local newNum = BagManager.GetItemCountById(GUESS_COIN)
|
|
LogRed("endResult "..endResult.." oldNum "..oldNum.." newNum "..newNum.." GetCoinNum "..ArenaTopMatchManager.GetCoinNum().." GetMyBetCoins "..ArenaTopMatchManager.GetMyBetCoins())
|
|
local tempNum=oldNum
|
|
if this.coinTimer then
|
|
this.coinTimer:Stop()
|
|
this.coinTimer=nil
|
|
end
|
|
if not this.coinTimer then
|
|
this.coinTimer=Timer.New(function()
|
|
local addNum = math.floor(tonumber((newNum-tempNum)/(duration/interval)))
|
|
if newNum-tempNum > 0 then
|
|
addNum = addNum > 0 and addNum or 1
|
|
end
|
|
oldNum=oldNum+addNum
|
|
if oldNum>=newNum then
|
|
oldNum=newNum
|
|
this.coinTimer:Stop()
|
|
end
|
|
--LogGreen("oldNum "..oldNum)
|
|
this.coinNum.text=string.format(Language[10110],oldNum)
|
|
end,interval,-1,true)
|
|
this.coinTimer:Start()
|
|
end
|
|
end
|
|
--界面关闭时调用(用于子类重写)
|
|
function ArenaTopMatchGuessTipViewPopup:OnClose()
|
|
if this.timer then
|
|
this.timer:Stop()
|
|
this.timer = nil
|
|
end
|
|
if this.coinTimer then
|
|
this.coinTimer:Stop()
|
|
this.coinTimer=nil
|
|
end
|
|
end
|
|
|
|
--界面销毁时调用(用于子类重写)
|
|
function ArenaTopMatchGuessTipViewPopup:OnDestroy()
|
|
this.spLoader:Destroy()
|
|
|
|
end
|
|
|
|
return ArenaTopMatchGuessTipViewPopup
|