134 lines
5.1 KiB
Lua
134 lines
5.1 KiB
Lua
----- 御剑行竞猜 -----
|
|
local this = {}
|
|
local swordImg = {
|
|
[1] = "y_yujianxing_banner01",
|
|
[2] = "y_yujianxing_banner02",
|
|
[3] = "y_yujianxing_banner03",
|
|
[4] = "y_yujianxing_banner04",
|
|
}
|
|
local configData = ConfigManager.GetConfigData(ConfigName.RidingSwardConfig,1)
|
|
|
|
function this:InitComponent(gameObject)
|
|
self.spLoader = SpriteLoader.New()
|
|
self.grid = Util.GetGameObject(gameObject,"Grid")
|
|
self.SwordPre = Util.GetGameObject(self.grid,"SwordPre")
|
|
self.SwordPre:SetActive(false)
|
|
self.roundTime = Util.GetGameObject(gameObject,"tips (2)"):GetComponent("Text")
|
|
|
|
self.itemNum = Util.GetGameObject(gameObject,"itemBar/Text"):GetComponent("Text")
|
|
self.itemImage = Util.GetGameObject(gameObject,"itemBar/Image"):GetComponent("Image")
|
|
self.preList = {}
|
|
end
|
|
|
|
function this:BindEvent()
|
|
end
|
|
|
|
function this:AddListener()
|
|
Game.GlobalEvent:AddEvent(GameEvent.YuJianXing.UpdateRank, self.Refresh,self)
|
|
end
|
|
|
|
function this:RemoveListener()
|
|
Game.GlobalEvent:RemoveEvent(GameEvent.YuJianXing.UpdateRank, self.Refresh,self)
|
|
end
|
|
|
|
function this:OnShow(_parent)
|
|
self.parent = _parent
|
|
self:Refresh()
|
|
end
|
|
|
|
function this:Refresh(func)
|
|
NetManager.RidingSwardInfoRequest(function ()
|
|
local serverData = YuJianXingManager.curBetList
|
|
for i = 1, 4 do
|
|
local go = self.preList[i]
|
|
if not go then
|
|
go = newObjToParent(self.SwordPre,self.grid)
|
|
go:SetActive(true)
|
|
self.preList[i] = go
|
|
end
|
|
local Img = go:GetComponent("Image")
|
|
local selectImg = Util.GetGameObject(go,"State")
|
|
local betImg = Util.GetGameObject(go,"Info"):GetComponent("Image")
|
|
local costImg = Util.GetGameObject(go,"Cost/Image"):GetComponent("Image")
|
|
local num = Util.GetGameObject(go,"Cost/num"):GetComponent("Text")
|
|
local betNum = Util.GetGameObject(go,"Info/Text"):GetComponent("Text")
|
|
local btnBet = Util.GetGameObject(go,"btnBet")
|
|
local btnBetText = Util.GetGameObject(btnBet,"Text"):GetComponent("Text")
|
|
|
|
Img.sprite = self.spLoader:LoadSprite(swordImg[i])
|
|
selectImg:SetActive(false)
|
|
betImg.sprite = self.spLoader:LoadSprite("y_yujianxing_weijingcai")
|
|
costImg.sprite = self.spLoader:LoadSprite(GetSpriteNameByItemId(configData.JoinCost[1]))
|
|
num.text = string.format( "最低%s",configData.JoinCost[2])
|
|
betNum.text = string.format("<color=#9599A7>赔率1:%s</color>",(configData.RateList[i])/10000)
|
|
Util.SetGray(btnBet,false)
|
|
btnBet:GetComponent("Button").interactable = true
|
|
btnBetText.text = "竞 猜"
|
|
for j = 1, #serverData do
|
|
if serverData[j].swardId == i then
|
|
betNum.text = string.format("<color=#CF9258>赔率1:%s</color>",(configData.RateList[i])/10000)
|
|
selectImg:SetActive(true)
|
|
betImg.sprite = self.spLoader:LoadSprite("y_yujianxing_yijingcai")
|
|
Util.SetGray(btnBet,true)
|
|
btnBet:GetComponent("Button").interactable = false
|
|
btnBetText.text = "已竞猜"
|
|
end
|
|
end
|
|
Util.AddOnceClick(btnBet,function ()
|
|
if BagManager.GetTotalItemNum(configData.JoinCost[1]) < configData.JoinCost[2] then
|
|
PopupTipPanel.ShowTip("御剑令不足,无法开始竞猜!")
|
|
return
|
|
end
|
|
if 2 - #serverData <= 0 then
|
|
PopupTipPanel.ShowTip("每轮仅可押注两把剑!")
|
|
return
|
|
end
|
|
if configData.JoinCount - YuJianXingManager.joinCount <= 0 then
|
|
if #serverData == 0 then
|
|
PopupTipPanel.ShowTip("竞猜次数不足,无法开始竞猜!")
|
|
return
|
|
end
|
|
end
|
|
UIManager.OpenPanel(UIName.GeneralPopup,GENERAL_POPUP_TYPE.YuJianXingBetSelectNum,i)
|
|
end)
|
|
end
|
|
self:SetTime()
|
|
self.itemNum.text = BagManager.GetTotalItemNum(configData.JoinCost[1])
|
|
self.itemImage.sprite = self.spLoader:LoadSprite(GetSpriteNameByItemId(configData.JoinCost[1]))
|
|
if func then
|
|
func()
|
|
end
|
|
end)
|
|
end
|
|
|
|
function this:SetTime()
|
|
local roundTime = YuJianXingManager.nextTimeCount- GetTimeStamp()
|
|
if self.timer then
|
|
self.timer:Stop()
|
|
self.timer = nil
|
|
end
|
|
self.roundTime.text = string.format("距本轮竞猜结束: %s",TimeToMS(roundTime))
|
|
self.timer = Timer.New(function ()
|
|
roundTime = roundTime - 1
|
|
self.roundTime.text = string.format("距本轮竞猜结束: %s",TimeToMS(roundTime))
|
|
if roundTime <= 0 then
|
|
self.parent:ClosePanel()
|
|
Game.GlobalEvent:DispatchEvent(GameEvent.YuJianXing.EndBetPanel)
|
|
end
|
|
end,1,-1)
|
|
self.timer:Start()
|
|
end
|
|
|
|
function this:OnClose()
|
|
if self.timer then
|
|
self.timer:Stop()
|
|
self.timer = nil
|
|
end
|
|
end
|
|
|
|
function this:OnDestroy()
|
|
self.preList = {}
|
|
self.spLoader:Destroy()
|
|
end
|
|
|
|
return this |