miduo_client/Assets/ManagedResources/~Lua/Modules/Gem/SmallSoldierLvInfoPanel.lua

292 lines
11 KiB
Lua

local SmallSoldierLvInfoPanel = quick_class("SmallSoldierLvInfoPanel", BasePanel)
local itemData = ConfigManager.GetConfig(ConfigName.ItemConfig)
local gemConfig = ConfigManager.GetConfig(ConfigName.GemConfigNew)
local itemConfig=ConfigManager.GetConfig(ConfigName.ItemConfig)
local lotteryConfig=ConfigManager.GetConfig(ConfigName.SoldiersLotteryConfig)
local specialConfig=ConfigManager.GetConfigData(ConfigName.SpecialConfig,178).Value
local aaa=string.split(specialConfig,"#")
local list={}
local isMax=false
local activityId=0
local curLv=0
local progress=0
local curType=0
local rewardConfig=nil
local isCan=false
local curConfig
local quaName={"粗糙","普通","优良","优秀","稀有","史诗","传说","神话"}
local quaColor={
Color.New(165/255,165/255,165/255,1),
Color.New(184/255,200/255,110/255,1),
Color.New(139/255,126/255,192/255,1),
Color.New(169/255,84/255,149/255,1),
Color.New(243/255,164/255,79/255,1),
Color.New(181/255,21/255,6/255,1),
Color.New(255/255,193/255,0/255,1),
Color.New(149/255,178/255,229/255,1)
}
function SmallSoldierLvInfoPanel:InitComponent()
self.spLoader = SpriteLoader.New()
self.btn_close=Util.GetGameObject(self.gameObject, "bg/close")
Util.GetGameObject(self.gameObject, "bg/title"):GetComponent("Text").text="兵力等级"
self.info=Util.GetGameObject(self.gameObject, "bg/info"):GetComponent("Text")
self.curlv=Util.GetGameObject(self.gameObject, "bg/curLv/Text"):GetComponent("Text")
self.nextlv=Util.GetGameObject(self.gameObject, "bg/nextLv/Text"):GetComponent("Text")
self.btn_go=Util.GetGameObject(self.gameObject, "bg/upObj/Button")
Util.GetGameObject(self.gameObject, "bg/upObj/Button/Text"):GetComponent("Text").text="升级"
self.btn_Text=Util.GetGameObject(self.gameObject, "bg/upObj/Button/Text"):GetComponent("Text")
self.infoGrid=Util.GetGameObject(self.gameObject, "bg/grid")
self.infoPre=Util.GetGameObject(self.gameObject, "bg/pre")
local rootHight = self.infoGrid.transform.rect.height
local width = self.infoGrid.transform.rect.width
self.ScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, self.infoGrid.transform,self.infoPre, self.Scrollbar, Vector2.New(width, rootHight), 1, 1, Vector2.New(0,0))
self.ScrollView.moveTween.MomentumAmount = 1
self.ScrollView.moveTween.Strength = 2
self.ScrollView.elastic = false
self.upObj=Util.GetGameObject(self.gameObject, "bg/upObj")
self.costImg=Util.GetGameObject(self.gameObject, "bg/upObj/costImg"):GetComponent("Image")
self.costTxt=Util.GetGameObject(self.gameObject, "bg/upObj/costTxt"):GetComponent("Text")
self.skipObj=Util.GetGameObject(self.gameObject, "bg/skipObj")
self.btn_skip=Util.GetGameObject(self.gameObject, "bg/skipObj/skipBtn")
Util.GetGameObject(self.gameObject, "bg/skipObj/skipBtn/Text"):GetComponent("Text").text="立即完成"
self.timeDown=Util.GetGameObject(self.gameObject, "bg/timeTxt"):GetComponent("Text")
self.skipCostImg=Util.GetGameObject(self.gameObject, "bg/skipObj/costImg"):GetComponent("Image")
self.skipCostTxt=Util.GetGameObject(self.gameObject, "bg/skipObj/Text"):GetComponent("Text")
self.curInfo=Util.GetGameObject(self.gameObject, "bg/curInfo"):GetComponent("Text")
self.nextInfo=Util.GetGameObject(self.gameObject, "bg/nextInfo"):GetComponent("Text")
end
function SmallSoldierLvInfoPanel:BindEvent()
Util.AddClick(self.btn_close, function ()
self:ClosePanel()
end)
Util.AddClick(self.btn_go,function()
if isMax then
PopupTipPanel.ShowTip("已提升到最高等级")
return
end
if isCan==false then
PopupTipPanel.ShowTip("兵力不足")
return
end
if BagManager.GetItemCountById(curConfig.Consume[1])<curConfig.Consume[2] then
PopupTipPanel.ShowTip(BagManager.GetItemNameById(curConfig.Consume[1]).."不足")
return
end
NetManager.UpSoldierLevelRequest(1,function()
self.skipObj:SetActive(true)
self.upObj:SetActive(false)
self:ShowLeftTime()
Game.GlobalEvent:DispatchEvent(GameEvent.Solider.RefreshSoliderInfoWindow)
end)
end)
Util.AddClick(self.btn_skip,function()
NetManager.UpSoldierLevelRequest(2,function()
-- self.skipObj:SetActive(false)
-- self.upObj:SetActive(true)
self.timer:Stop()
self.timer = nil
self:OnShow()
end)
end)
end
function SmallSoldierLvInfoPanel:AddListener()
end
function SmallSoldierLvInfoPanel:RemoveListener()
end
--待功能扩展(试图打开某个状态)
function SmallSoldierLvInfoPanel:OnOpen(...)
local args={...}
curType=args[1]
end
function SmallSoldierLvInfoPanel:OnSortingOrderChange()
end
local itemList={}
function SmallSoldierLvInfoPanel:OnShow()
curLv=SmallSoldierManager.level
local nextLv=curLv+1
if nextLv>50 then
nextLv=50
isMax=true
end
--local
self.curlv.text="当前等级:"..curLv
self.nextlv.text="下一等级:"..nextLv
local qua=0
local lotteryData={}
curConfig=ConfigManager.GetConfigData(ConfigName.SoldiersLotteryConfig,curLv)
local nextConfig=ConfigManager.TryGetConfigData(ConfigName.SoldiersLotteryConfig,nextLv)
if nextConfig==nil then
nextConfig=curConfig
self.nextlv.text="下一等级:"..curLv
end
local qua=0
local priviConfig=ConfigManager.GetConfigData(ConfigName.PrivilegeTypeConfig,2044)
self.curInfo.text=string.format(priviConfig.Name,priviConfig.Condition[curLv][2]/100)
self.nextInfo.text=string.format(priviConfig.Name,priviConfig.Condition[nextLv][2]/100)
for i=1,#curConfig.Show do
local data={}
data.leftData={}
data.rightData={}
local settingConfig=ConfigManager.GetConfigDataByKey(ConfigName.SoldiersSetting,"ShowQuality",curConfig.Show[i][1])
local str=""
if settingConfig.QualityLevel>0 then
str=quaName[settingConfig.Quality].."+"..settingConfig.QualityLevel
else
str=quaName[settingConfig.Quality]
end
data.leftData.quaStr=str
data.leftData.qua=settingConfig.Quality
data.rightData.qua=settingConfig.Quality
data.leftData.pro=curConfig.Show[i][2]/100
data.rightData.pro=nextConfig.Show[i][2]/100
table.insert(lotteryData,data)
end
--LogError("GetResourcePath(curConfig.Consume[1])=="..GetResourcePath(curConfig.Consume[1]).." "..curConfig.Consume[1])
--self.spLoader:LoadSprite(GetResourcePath(curConfig.Consume[1]))
if curConfig.Consume and type(curConfig.Consume[1])~="userdata" then
self.costImg.gameObject:SetActive(true)
self.costTxt.gameObject:SetActive(true)
self.costImg.sprite=SetIcon(self.spLoader, curConfig.Consume[1])
self.costTxt.text=curConfig.Consume[2]
else
self.costImg.gameObject:SetActive(false)
self.costTxt.gameObject:SetActive(false)
end
self.skipObj:SetActive(SmallSoldierManager.upEndTime>0)
self.upObj:SetActive(SmallSoldierManager.upEndTime==0)
self.skipCostImg.sprite=SetIcon(self.spLoader,tonumber(aaa[1])) --self.spLoader:LoadSprite(GetResourcePath(tonumber(aaa[1])))
self.timeDown.text=TimeToFelaxible(curConfig.Time)
if SmallSoldierManager.upEndTime>0 then
self:ShowLeftTime()
end
self.ScrollView:SetData(lotteryData, function (index, go)
self:SingleDataShow(go,lotteryData[index])
end,false)
if BagManager.GetItemCountById(curConfig.Soldiers[1])>=curConfig.Soldiers[2] then
isCan=true
Util.SetGray(self.btn_go,false)
else
isCan=false
Util.SetGray(self.btn_go,true)
end
--self:CheckReward()
end
function SmallSoldierLvInfoPanel:ShowLeftTime()
--显示倒计时
if SmallSoldierManager.upEndTime>0 then
if self.timer then
self.timer:Stop()
self.timer = nil
end
local leftTime=SmallSoldierManager.upEndTime- GetTimeStamp()
--leftTime=60
if leftTime>0 then
self.timeDown.text=TimeToFelaxible(leftTime)
local time=0
if leftTime%60>0 then
time=math.floor(leftTime/60)+1
else
time=math.floor(leftTime/60)
end
self.skipCostTxt.text=time*tonumber(aaa[2])
self.timer = Timer.New(function ()
self.timeDown.text=TimeToFelaxible(leftTime)
leftTime=leftTime-1
local time=0
if leftTime%60>0 then
time=math.floor(leftTime/60)+1
else
time=math.floor(leftTime/60)
end
LogError("time================================"..time)
self.skipCostTxt.text=time*tonumber(aaa[2])
if leftTime<=0 then
SmallSoldierManager.upEndTime=0
SmallSoldierManager.level=SmallSoldierManager.level+1
if self.timer then
self.timer:Stop()
self.timer = nil
end
self:OnShow()
end
end, 1, -1, true)
self.timer:Start()
else
if self.timer then
self.timer:Stop()
self.timer = nil
end
SmallSoldierManager.upEndTime=0
self:OnShow()
end
end
end
function SmallSoldierLvInfoPanel:SingleDataShow(go,data)
local leftObj=Util.GetGameObject(go, "curLv")
local leftTxt=Util.GetGameObject(go, "curLv/Text"):GetComponent("Text")
local leftValue=Util.GetGameObject(go, "curLv/value"):GetComponent("Text")
local rightObj=Util.GetGameObject(go, "nextLv")
local rightTxt=Util.GetGameObject(go, "nextLv/Text"):GetComponent("Text")
leftObj:SetActive(data.leftData~=nil)
rightObj:SetActive(data.rightData~=nil)
if data.leftData then
leftTxt.text=data.leftData.quaStr
leftObj:GetComponent("Image").color=quaColor[data.leftData.qua]
leftValue.text=data.leftData.pro
end
if data.rightData then
rightTxt.text=data.rightData.pro
rightObj:GetComponent("Image").color=quaColor[data.rightData.qua]
end
end
--检测奖励
function SmallSoldierLvInfoPanel:CheckReward()
end
function SmallSoldierLvInfoPanel:OnClose()
end
function SmallSoldierLvInfoPanel:OnDestroy()
self.spLoader:Destroy()
if self.timer then
self.timer:Stop()
self.timer = nil
end
end
return SmallSoldierLvInfoPanel