180 lines
6.5 KiB
Lua
180 lines
6.5 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--上一个选中英雄
|
||
local selectHeroDid --选中英雄did
|
||
local itemId=0 --消耗道具ID
|
||
local itemNum=0 --消耗道具数量
|
||
local optionType={ --选择类型
|
||
First=0,
|
||
Refresh=1,
|
||
}
|
||
|
||
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,"obj/Num"):GetComponent("Text")
|
||
this.addBtn=Util.GetGameObject(this.body,"obj/Add")
|
||
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()
|
||
Game.GlobalEvent:DispatchEvent(GameEvent.Bag.OnTempBagChanged)
|
||
parent:ClosePanel()
|
||
end)
|
||
--使用按钮
|
||
Util.AddClick(this.confirmBtn,function()
|
||
local maxNum=trialSetting[1].HealingId[2]
|
||
local curHeroHp=0
|
||
for i, v in ipairs(MapManager.trialHeroInfo) do
|
||
if selectHeroDid==v.heroId then
|
||
curHeroHp= v.heroHp
|
||
if v.heroHp<=0 then
|
||
PopupTipPanel.ShowTip("神将已阵亡,无法使用!")
|
||
return
|
||
end
|
||
end
|
||
end
|
||
if (maxNum-MapManager.addHpCount)<=0 then
|
||
PopupTipPanel.ShowTip("本轮使用次数到达上限!")
|
||
return
|
||
end
|
||
if BagManager.GetItemCountById(itemId)<=0 then
|
||
PopupTipPanel.ShowTip(string.format("%s数量不足!",GetLanguageStrById(itemConfig[itemId].Name)))
|
||
return
|
||
end
|
||
if curHeroHp>=10000 then
|
||
PopupTipPanel.ShowTip("所选神将生命值已满!")
|
||
return
|
||
end
|
||
if not selectHeroDid then
|
||
PopupTipPanel.ShowTip("未选择目标神将")
|
||
return
|
||
end
|
||
NetManager.UseAddHpItemRequest(selectHeroDid,function()
|
||
PopupTipPanel.ShowTip(string.format("已使用%s!",GetLanguageStrById(itemConfig[itemId].Name)))
|
||
MapManager.addHpCount=MapManager.addHpCount+1
|
||
curHeroHp=curHeroHp+5000 --5000增加的血量也是要配表的
|
||
if curHeroHp>=10000 then
|
||
curHeroHp=10000
|
||
end
|
||
MapTrialManager.SetHeroHp({curHeroHp},selectHeroDid)
|
||
Game.GlobalEvent:DispatchEvent(GameEvent.Map.RefreshHeroHp,false,nil,false)
|
||
Game.GlobalEvent:DispatchEvent(GameEvent.Bag.OnTempBagChanged)
|
||
end)
|
||
end)
|
||
--购买道具按钮
|
||
Util.AddClick(this.addBtn,function()
|
||
UIManager.OpenPanel(UIName.QuickPurchasePanel, { type = UpViewRechargeType.XingYao })
|
||
end)
|
||
end
|
||
|
||
function this:AddListener()
|
||
Game.GlobalEvent:AddEvent(GameEvent.Bag.BagGold, this.RefreshPanel)--监听背包信息改变刷新 用于回春散数量刷新
|
||
end
|
||
|
||
function this:RemoveListener()
|
||
Game.GlobalEvent:RemoveEvent(GameEvent.Bag.BagGold, this.RefreshPanel)
|
||
end
|
||
|
||
function this:OnShow(_parent,...)
|
||
oldChoosed = nil
|
||
parent=_parent
|
||
sortingOrder = _parent.sortingOrder
|
||
--不定参中包含的不定参 _args[1]为面板类型 _args[2]之后(包括)为打开面板后传入的不定参
|
||
local _args = {...}
|
||
itemId=trialSetting[1].HealingId[1]
|
||
itemNum= BagManager.GetItemCountById(itemId)
|
||
this.RefreshPanel()
|
||
end
|
||
|
||
function this:OnClose()
|
||
end
|
||
|
||
function this:OnDestroy()
|
||
item=nil
|
||
heroList={}
|
||
end
|
||
|
||
|
||
--刷新面板
|
||
function this.RefreshPanel()
|
||
this.titleText.text="回春散"
|
||
item:OnOpen(false, {itemId,1}, 1.2,false,false,false,sortingOrder)
|
||
item:Reset({itemId,1},ItemType.NoType,{nil,false,nil,false})
|
||
this.desc.text=GetLanguageStrById(itemConfig[itemId].ItemDescribe)
|
||
this.time.text="本轮可使用次数:"..(trialSetting[1].HealingId[2]-MapManager.addHpCount)
|
||
this.num.text="剩余数量:"..BagManager.GetItemCountById(itemId)
|
||
|
||
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,v.star))
|
||
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,1,Vector2.New(30,30),-8.21)
|
||
--血量相关
|
||
hpExp.value=v.heroHp/10000
|
||
Util.SetGray(o,v.heroHp<=0)
|
||
|
||
choosed:SetActive(false)
|
||
if MapTrialManager.selectHeroDid == v.heroId then
|
||
choosed:SetActive(true)
|
||
oldChoosed=choosed
|
||
selectHeroDid=v.heroId
|
||
end
|
||
|
||
Util.AddOnceClick(o,function()
|
||
if v.heroHp<=0 then
|
||
PopupTipPanel.ShowTip("无法选择已死亡的神将!")
|
||
return
|
||
end
|
||
if oldChoosed then
|
||
if selectHeroDid==v.heroId then
|
||
return
|
||
end
|
||
oldChoosed:SetActive(false)
|
||
end
|
||
if oldChoosed~=choosed then
|
||
choosed:SetActive(true)
|
||
oldChoosed=choosed
|
||
selectHeroDid=v.heroId
|
||
end
|
||
end)
|
||
end
|
||
end
|
||
|
||
return this |