143 lines
5.0 KiB
Lua
143 lines
5.0 KiB
Lua
|
----- 试练性药 -----
|
|||
|
local this = {}
|
|||
|
--传入父脚本模块
|
|||
|
local parent
|
|||
|
--传入特效层级
|
|||
|
local sortingOrder=0
|
|||
|
|
|||
|
local itemConfig=ConfigManager.GetConfig(ConfigName.ItemConfig)
|
|||
|
local trialSetting=ConfigManager.GetConfig(ConfigName.TrialSetting)
|
|||
|
local heroConfig = ConfigManager.GetConfig(ConfigName.HeroConfig)
|
|||
|
local item
|
|||
|
local heroList={} --英雄预设容器
|
|||
|
local oldChoosed=nil--上一个选中英雄
|
|||
|
function this:InitComponent(gameObject)
|
|||
|
this.titleText=Util.GetGameObject(gameObject,"TitleText"):GetComponent("Text")
|
|||
|
this.body=Util.GetGameObject(gameObject,"Body")
|
|||
|
this.item=Util.GetGameObject(this.body,"Item")
|
|||
|
this.desc=Util.GetGameObject(this.body,"Desc"):GetComponent("Text")
|
|||
|
this.time=Util.GetGameObject(this.body,"Time"):GetComponent("Text")
|
|||
|
this.num=Util.GetGameObject(this.body,"Num"):GetComponent("Text")
|
|||
|
this.grid = Util.GetGameObject(gameObject, "Root/Grid")
|
|||
|
this.pre=Util.GetGameObject(gameObject,"Root/Grid/Pre")
|
|||
|
this.cancelBtn=Util.GetGameObject(gameObject,"CancelBtn")
|
|||
|
this.confirmBtn=Util.GetGameObject(gameObject,"ConfirmBtn")
|
|||
|
|
|||
|
item=SubUIManager.Open(SubUIConfig.ItemView, this.item.transform)
|
|||
|
end
|
|||
|
|
|||
|
function this:BindEvent()
|
|||
|
--取消按钮
|
|||
|
Util.AddClick(this.cancelBtn,function()
|
|||
|
parent:ClosePanel()
|
|||
|
end)
|
|||
|
--使用按钮
|
|||
|
Util.AddClick(this.confirmBtn,function()
|
|||
|
if (trialSetting[1].HealingId[2]-MapManager.addHpCount)<=0 then
|
|||
|
PopupTipPanel.ShowTip("可使用次数不足!")
|
|||
|
return
|
|||
|
end
|
|||
|
if BagManager.GetItemCountById(trialSetting[1].HealingId[1])<=0 then
|
|||
|
PopupTipPanel.ShowTip(string.format("%s不足!",itemConfig[trialSetting[1].HealingId[1]].Name))
|
|||
|
return
|
|||
|
end
|
|||
|
NetManager.UseAddHpItemRequest(MapTrialManager.selectHeroDid,function()
|
|||
|
PopupTipPanel.ShowTip("使用回春散成功!")
|
|||
|
local curHeroHp=0
|
|||
|
for i, v in ipairs(MapManager.trialHeroInfo) do
|
|||
|
if v.heroId==MapTrialManager.selectHeroDid then
|
|||
|
curHeroHp= v.heroHp
|
|||
|
end
|
|||
|
end
|
|||
|
curHeroHp=curHeroHp+5000
|
|||
|
if curHeroHp>=10000 then
|
|||
|
curHeroHp=10000
|
|||
|
end
|
|||
|
MapTrialManager.SetHeroHp({curHeroHp},function()
|
|||
|
-- this.RefreshPanel()
|
|||
|
end)
|
|||
|
end)
|
|||
|
end)
|
|||
|
end
|
|||
|
|
|||
|
function this:AddListener()
|
|||
|
Game.GlobalEvent:AddEvent(GameEvent.Map.RefreshHeroHp, this.RefreshPanel)
|
|||
|
end
|
|||
|
|
|||
|
function this:RemoveListener()
|
|||
|
Game.GlobalEvent:RemoveEvent(GameEvent.Map.RefreshHeroHp, this.RefreshPanel)
|
|||
|
end
|
|||
|
|
|||
|
function this:OnShow(_parent,...)
|
|||
|
parent=_parent
|
|||
|
sortingOrder = _parent.sortingOrder
|
|||
|
--不定参中包含的不定参 _args[1]为面板类型 _args[2]之后(包括)为打开面板后传入的不定参
|
|||
|
local _args = {...}
|
|||
|
|
|||
|
this.RefreshPanel()
|
|||
|
end
|
|||
|
|
|||
|
function this:OnClose()
|
|||
|
end
|
|||
|
|
|||
|
function this:OnDestroy()
|
|||
|
item=nil
|
|||
|
heroList={}
|
|||
|
end
|
|||
|
|
|||
|
|
|||
|
function this.RefreshPanel()
|
|||
|
local id=trialSetting[1].HealingId[1]
|
|||
|
this.titleText.text="回春散"
|
|||
|
item:OnOpen(false, {id,1}, 1.2,false,false,false,sortingOrder)
|
|||
|
this.desc.text=itemConfig[id].ItemDescribe
|
|||
|
this.time.text="本轮可使用次数:"..(trialSetting[1].HealingId[2]-MapManager.addHpCount)
|
|||
|
this.num.text="剩余数量:"..BagManager.GetItemCountById(id)
|
|||
|
LogPink("剩余"..BagManager.GetItemCountById(id))
|
|||
|
|
|||
|
for i, v in ipairs(MapManager.trialHeroInfo) do
|
|||
|
local o= heroList[i]
|
|||
|
if not o then
|
|||
|
o=newObjToParent(this.pre,this.grid)
|
|||
|
o.name="pre"..i
|
|||
|
heroList[i]=o
|
|||
|
end
|
|||
|
o.gameObject:SetActive(true)
|
|||
|
|
|||
|
local frame=Util.GetGameObject(o,"frame"):GetComponent("Image")
|
|||
|
local icon=Util.GetGameObject(o,"icon"):GetComponent("Image")
|
|||
|
local pro=Util.GetGameObject(o,"proIcon"):GetComponent("Image")
|
|||
|
local lv=Util.GetGameObject(o,"lv/Text"):GetComponent("Text")
|
|||
|
local star=Util.GetGameObject(o,"star")
|
|||
|
local choosed=Util.GetGameObject(o,"choosed")
|
|||
|
local hpExp=Util.GetGameObject(o,"hpExp"):GetComponent("Slider")
|
|||
|
frame.sprite=Util.LoadSprite(GetHeroQuantityImageByquality(heroConfig[v.tmpId].Quality))
|
|||
|
icon.sprite= Util.LoadSprite(GetResourcePath(heroConfig[v.tmpId].Icon))
|
|||
|
pro.sprite=Util.LoadSprite(GetProStrImageByProNum(heroConfig[v.tmpId].PropertyName))
|
|||
|
lv.text=v.level
|
|||
|
SetHeroStars(star, v.star)
|
|||
|
hpExp.value=v.heroHp/10000
|
|||
|
choosed:SetActive(i==1)
|
|||
|
if i==1 then
|
|||
|
oldChoosed=choosed
|
|||
|
MapTrialManager.selectHeroDid=v.heroId
|
|||
|
end
|
|||
|
|
|||
|
Util.AddOnceClick(o,function()
|
|||
|
if oldChoosed then
|
|||
|
if MapTrialManager.selectHeroDid==v.heroId then
|
|||
|
return
|
|||
|
end
|
|||
|
oldChoosed:SetActive(false)
|
|||
|
end
|
|||
|
if oldChoosed~=choosed then
|
|||
|
choosed:SetActive(true)
|
|||
|
oldChoosed=choosed
|
|||
|
MapTrialManager.selectHeroDid=v.heroId
|
|||
|
end
|
|||
|
end)
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
return this
|