miduo_client/Assets/ManagedResources/~Lua/Modules/GeneralPanel/View/GeneralBigPopup_YuJianBet.lua

124 lines
4.6 KiB
Lua
Raw Normal View History

2021-10-08 20:49:25 +08:00
----- 御剑行竞猜 -----
local this = {}
local swordImg = {
2021-10-13 19:15:39 +08:00
[1] = "y_yujianxing_banner01",
[2] = "y_yujianxing_banner02",
[3] = "y_yujianxing_banner03",
[4] = "y_yujianxing_banner04",
}
local configData = ConfigManager.GetConfigData(ConfigName.RidingSwardConfig,1)
2021-10-08 20:49:25 +08:00
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 = {}
2021-10-08 20:49:25 +08:00
end
function this:BindEvent()
end
function this:AddListener()
Game.GlobalEvent:AddEvent(GameEvent.YuJianXing.UpdateRank, self.Refresh,self)
2021-10-08 20:49:25 +08:00
end
function this:RemoveListener()
Game.GlobalEvent:RemoveEvent(GameEvent.YuJianXing.UpdateRank, self.Refresh,self)
end
function this:OnShow(_parent)
self.parent = _parent
self:Refresh()
end
2021-10-13 19:15:39 +08:00
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")
2021-10-13 19:15:39 +08:00
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 = 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
2021-10-13 19:15:39 +08:00
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
2021-10-13 19:15:39 +08:00
btnBetText.text = "已竞猜"
end
end
Util.AddOnceClick(btnBet,function ()
2021-10-14 11:25:44 +08:00
if BagManager.GetTotalItemNum(configData.JoinCost[1]) < configData.JoinCost[2] then
PopupTipPanel.ShowTip("御剑令不足,无法开示竞猜!")
return
end
2021-10-14 09:53:51 +08:00
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]))
2021-10-13 19:15:39 +08:00
if func then
func()
end
end)
2021-10-08 20:49:25 +08:00
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()
2021-10-14 11:25:44 +08:00
Game.GlobalEvent:DispatchEvent(GameEvent.YuJianXing.EndBetPanel)
end
end,1,-1)
self.timer:Start()
2021-10-08 20:49:25 +08:00
end
function this:OnClose()
if self.timer then
self.timer:Stop()
self.timer = nil
end
2021-10-08 20:49:25 +08:00
end
function this:OnDestroy()
self.preList = {}
2021-10-08 20:49:25 +08:00
self.spLoader:Destroy()
end
return this