miduo_client/Assets/ManagedResources/~Lua/Modules/GodWeapon/GodWeaponUpPanel.lua

363 lines
14 KiB
Lua
Raw Normal View History

2023-03-30 13:16:11 +08:00
require("Base/BasePanel")
GodWeaponUpPanel = Inherit(BasePanel)
local this = GodWeaponUpPanel
2023-04-04 14:54:14 +08:00
local tabType=1 --1升级 2升星
2023-03-30 13:16:11 +08:00
local godWeaponData
2023-03-31 17:52:12 +08:00
--长按升级状态
local _isClicked = false
local _isReqLvUp = false
local _isLongPress = false
local addLvNum=0
local isTriggerLongClick = false--长按是否升过级
local costItems={}
2023-03-30 13:16:11 +08:00
--初始化组件(用于子类重写)
function this:InitComponent()
this.btnBack = Util.GetGameObject(self.gameObject, "btnBack")
this.spLoader = SpriteLoader.New()
this.icon= Util.GetGameObject(self.gameObject, "iconBg/icon"):GetComponent("Image")
this.nameText=Util.GetGameObject(self.gameObject, "nameInfo/nameText"):GetComponent("Text")
2023-03-30 16:27:13 +08:00
this.curPropGrid=Util.GetGameObject(self.gameObject, "infoLayout/propertyInfo/allProp/curProp")
this.nextPropGrid=Util.GetGameObject(self.gameObject, "infoLayout/propertyInfo/allProp/nextProp")
2023-03-30 13:16:11 +08:00
this.upStarTab=Util.GetGameObject(self.gameObject,"tabBg/tabBox/upStarTab")
this.upLvTab=Util.GetGameObject(self.gameObject,"tabBg/tabBox/upLvTab")
this.selectBtn=Util.GetGameObject(self.gameObject,"tabBg/tabBox/selectBtn")
this.selectText=Util.GetGameObject(self.gameObject,"tabBg/tabBox/selectBtn/Text"):GetComponent("Text")
this.curLv=Util.GetGameObject(self.gameObject,"infoLayout/costMatBg/curLv/Text"):GetComponent("Text")
this.costGrid=Util.GetGameObject(self.gameObject,"infoLayout/costMatBg/costGrid")
this.skillLayout=Util.GetGameObject(self.gameObject,"infoLayout/skillLayout")
this.upStarBtn=Util.GetGameObject(self.gameObject,"infoLayout/btnLayout/upStarBtn")
this.upLvBtn=Util.GetGameObject(self.gameObject,"infoLayout/btnLayout/upLvBtn")
2023-03-31 17:52:12 +08:00
this.upLvTrigger = Util.GetEventTriggerListener(this.upLvBtn)
2023-03-30 13:16:11 +08:00
this.limitText=Util.GetGameObject(self.gameObject,"infoLayout/btnLayout/limitText"):GetComponent("Text")
this.jiantou=Util.GetGameObject(self.gameObject,"infoLayout/propertyInfo/jiantou")
2023-03-30 16:27:13 +08:00
this.starGrid=Util.GetGameObject(self.gameObject,"starGrid/starGrid")
this.skillScroll=Util.GetGameObject(self.gameObject,"infoLayout/skillLayout/skillScroll/skillGrid")
this.curSkillInfo=Util.GetGameObject(self.gameObject,"infoLayout/skillLayout/skillScroll/skillGrid/curSkillInfo")
this.nextSkillInfo=Util.GetGameObject(self.gameObject,"infoLayout/skillLayout/skillScroll/skillGrid/nextSkillInfo")
2023-04-04 14:54:14 +08:00
this.upLvTabRedPoint = Util.GetGameObject(this.upLvTab, "redPoint")
this.upStarTabRedPoint = Util.GetGameObject(this.upStarTab, "redPoint")
2023-03-30 13:16:11 +08:00
this.costItemViews={}
2023-03-31 17:52:12 +08:00
this.UpView = SubUIManager.Open(SubUIConfig.UpView, self.gameObject.transform, { showType = UpViewOpenType.ShowLeft })
2023-03-30 13:16:11 +08:00
end
--绑定事件(用于子类重写)
function this:BindEvent()
Util.AddClick(this.btnBack, function()
self:ClosePanel()
end)
2023-04-04 14:54:14 +08:00
Util.AddClick(this.upLvTab, function()
2023-03-30 13:16:11 +08:00
tabType=1
this.SetSelectBtn()
this.UpdateWinInfo()
end)
2023-04-04 14:54:14 +08:00
Util.AddClick(this.upStarTab, function()
2023-03-30 13:16:11 +08:00
tabType=2
this.SetSelectBtn()
this.UpdateWinInfo()
end)
2023-04-04 14:54:14 +08:00
2023-03-30 13:16:11 +08:00
Util.AddClick(this.upStarBtn, function()
2023-04-04 11:59:36 +08:00
local oldWarPower = FormationManager.GetFormationPower(FormationTypeDef.FORMATION_NORMAL)
2023-03-31 17:52:12 +08:00
local haveUpStarCost=GodWeaponManager.GetUpStarCost(godWeaponData)
local starConfig=ConfigManager.GetConfigDataByDoubleKey(ConfigName.ShenbingStar,"Star",godWeaponData.star,"Quality",godWeaponData.config.Quality)
local needNum=starConfig.ConsumeItemNum
if #haveUpStarCost>=needNum then
local costList={}
for i = 1, needNum do
costList[i]=haveUpStarCost[i]
end
NetManager.RequestMagicSoldierStrong(godWeaponData.Did,2,0,costList,function(msg)
this.UpdateWinInfo()
2023-04-04 11:59:36 +08:00
local newWarPower = FormationManager.GetFormationPower(FormationTypeDef.FORMATION_NORMAL)
--飘战力
PokemonManager.PiaoWarPowerChange(oldWarPower,newWarPower)
2023-03-31 17:52:12 +08:00
end)
2023-04-03 11:18:04 +08:00
else
PopupTipPanel.ShowTip("道具不足")
2023-03-31 17:52:12 +08:00
end
2023-03-30 13:16:11 +08:00
end)
Util.AddClick(this.upLvBtn, function()
2023-03-31 17:52:12 +08:00
this.LvUpClick(true)
end)
--长按升级按下状态
this._onPointerDown = function(Pointgo, data)
isTriggerLongClick = false
_isClicked = true
this.timePressStarted = Time.realtimeSinceStartup
end
--长按升级抬起状态
this._onPointerUp = function(Pointgo, data)
if _isLongPress and isTriggerLongClick then
--连续升级抬起请求升级
this.LongLvUpClick()
end
_isClicked = false
_isLongPress = false
end
this.upLvTrigger.onPointerDown = this.upLvTrigger.onPointerDown + this._onPointerDown
this.upLvTrigger.onPointerUp = this.upLvTrigger.onPointerUp + this._onPointerUp
end
2023-03-30 13:16:11 +08:00
2023-03-31 17:52:12 +08:00
--长按升级处理
function this.OnUpdate()
if _isClicked then
if Time.realtimeSinceStartup - this.timePressStarted > 0.4 then
_isLongPress = true
if not _isReqLvUp then
_isReqLvUp = true
this.LvUpClick(false)
end
end
end
end
--长按升级结束后请求协议
function this.LongLvUpClick()
NetManager.RequestMagicSoldierStrong(godWeaponData.Did,1,addLvNum,nil,function(msg)
_isReqLvUp = false
addLvNum=0
2023-03-30 13:16:11 +08:00
end)
end
2023-03-31 17:52:12 +08:00
--升级按钮点击事件处理
function this.LvUpClick(isSingleLvUp)
local isCost=true
local isLimit=godWeaponData.lv>=200
if #costItems>0 then
for i = 1, #costItems do
local haveCount=BagManager.GetItemCountById(costItems[i][1])
if haveCount<costItems[i][2] then
isCost=false
end
end
end
--各种判断能否升级
if isLimit or not isCost then
if not isSingleLvUp then
this.LongLvUpClick()
_isClicked = false
_isLongPress = false
isTriggerLongClick = true
end
if godWeaponData.lv>=200 then
PopupTipPanel.ShowTip("等级已达上限")
else
PopupTipPanel.ShowTip("道具不足")
end
return
end
if isSingleLvUp then --单次点击升级
2023-04-04 11:59:36 +08:00
local oldWarPower = FormationManager.GetFormationPower(FormationTypeDef.FORMATION_NORMAL)
2023-03-31 17:52:12 +08:00
NetManager.RequestMagicSoldierStrong(godWeaponData.Did,1,1,nil,function(msg)
GodWeaponManager.SetGodWeaponLv(godWeaponData.Did,1)
this.UpdateWinInfo()
2023-04-04 11:59:36 +08:00
local newWarPower = FormationManager.GetFormationPower(FormationTypeDef.FORMATION_NORMAL)
--飘战力
PokemonManager.PiaoWarPowerChange(oldWarPower,newWarPower)
2023-03-31 17:52:12 +08:00
end)
else
isTriggerLongClick = true
2023-04-04 11:59:36 +08:00
local oldWarPower = FormationManager.GetFormationPower(FormationTypeDef.FORMATION_NORMAL)
2023-03-31 17:52:12 +08:00
--前端先扣除材料
for i = 1, #costItems do
BagManager.HeroLvUpUpdateItemsNum(costItems[i][1],costItems[i][2])
end
addLvNum=addLvNum+1
GodWeaponManager.SetGodWeaponLv(godWeaponData.Did,1)
this.UpdateWinInfo()
2023-04-04 11:59:36 +08:00
local newWarPower = FormationManager.GetFormationPower(FormationTypeDef.FORMATION_NORMAL)
--飘战力
PokemonManager.PiaoWarPowerChange(oldWarPower,newWarPower)
2023-03-31 17:52:12 +08:00
_isReqLvUp = false
end
end
2023-03-30 13:16:11 +08:00
function this.SetSelectBtn()
local _btnTab
if tabType==1 then
_btnTab=this.upLvTab
2023-04-04 14:54:14 +08:00
2023-03-30 13:16:11 +08:00
this.selectText.text="升级"
2023-04-04 14:54:14 +08:00
else
_btnTab=this.upStarTab
this.selectText.text="升星"
2023-03-30 13:16:11 +08:00
end
this.selectBtn.transform:SetParent(_btnTab.transform)
2024-01-20 18:33:29 +08:00
this.selectBtn.transform:SetSiblingIndex(1)
2023-03-30 13:16:11 +08:00
this.selectBtn.transform.localPosition = Vector3.zero
this.selectBtn.transform.localScale = Vector3.one
end
--界面打开时调用(用于子类重写)
function this:OnOpen(_type,_data)
tabType=_type
godWeaponData=_data
this.SetSelectBtn()
this.icon.sprite = this.spLoader:LoadSprite(GetResourcePath(godWeaponData.config.Icon))
this.nameText.text=godWeaponData.config.Name
this.UpdateWinInfo()
2023-03-31 17:52:12 +08:00
this.UpView:OnOpen({ showType = UpViewOpenType.ShowLeft, panelType = PanelType.GodWeapon })
end
function this:OnShow()
FixedUpdateBeat:Add(this.OnUpdate, self)--长按方法注册
2023-03-30 13:16:11 +08:00
end
function this.UpdateWinInfo()
2023-04-06 13:40:13 +08:00
costItems={}
2023-04-04 18:21:14 +08:00
CheckRedPointStatus(RedPointType.GodWeapon)
2023-04-04 14:54:14 +08:00
local upLvRed = GodWeaponManager.CheckUpLvRedPoint(godWeaponData)
this.upLvTabRedPoint:SetActive(upLvRed)
local upStarRed = GodWeaponManager.CheckUpStarRedPoint(godWeaponData)
this.upStarTabRedPoint:SetActive(upStarRed)
2023-03-30 13:16:11 +08:00
this.curLv.text="等级:"..godWeaponData.lv
2023-03-30 16:27:13 +08:00
local starSize = Vector2.New(80,80)
PokemonManager.SetHeroStars(this.spLoader, this.starGrid, godWeaponData.star,1,starSize)
2023-03-30 13:16:11 +08:00
local curPropDic
local nextPropDic
local isLimit=false
if tabType==1 then
2023-04-04 14:54:14 +08:00
isLimit=godWeaponData.lv>=200
this.skillLayout.gameObject:SetActive(false)
this.upStarBtn.gameObject:SetActive(false)
this.upLvBtn.gameObject:SetActive(true)
this.curLv.transform.parent.gameObject:SetActive(true)
curPropDic=GodWeaponManager.GetSinglePokemonAddProData(godWeaponData.Did,godWeaponData.star,godWeaponData.lv)
if not isLimit then
nextPropDic=GodWeaponManager.GetSinglePokemonAddProData(godWeaponData.Did,godWeaponData.star,godWeaponData.lv+1)
2023-04-06 13:40:13 +08:00
local upLvCosts=ConfigManager.GetConfigDataByDoubleKey(ConfigName.ShenBingLevel,"Level",godWeaponData.lv,"Quality",godWeaponData.config.Quality).Consume
for i = 1, #upLvCosts do
costItems[i]=upLvCosts[i]
end
2023-04-04 14:54:14 +08:00
end
this.limitText.text="等级已满"
else
2023-03-30 13:16:11 +08:00
isLimit=godWeaponData.star>=5
this.skillLayout.gameObject:SetActive(true)
this.upStarBtn.gameObject:SetActive(true)
this.upLvBtn.gameObject:SetActive(false)
this.curLv.transform.parent.gameObject:SetActive(false)
curPropDic=GodWeaponManager.GetSinglePokemonAddProData(godWeaponData.Did,godWeaponData.star,godWeaponData.lv)
2023-03-31 17:52:12 +08:00
local curSkillInfos= GodWeaponManager.GetSingleGodWeaponSkillDes(godWeaponData.Did)
this.SetSkillInfo(this.curSkillInfo,"升星前技能",curSkillInfos)
2023-03-30 13:16:11 +08:00
if not isLimit then
nextPropDic=GodWeaponManager.GetSinglePokemonAddProData(godWeaponData.Did,godWeaponData.star+1,godWeaponData.lv)
local starConfig=ConfigManager.GetConfigDataByDoubleKey(ConfigName.ShenbingStar,"Star",godWeaponData.star,"Quality",godWeaponData.config.Quality)
costItems[1]={}
costItems[1][1]=godWeaponData.id
costItems[1][2]=starConfig.ConsumeItemNum
2023-03-31 17:52:12 +08:00
local nextSkillInfos=GodWeaponManager.GetSingleGodWeaponSkillDes(godWeaponData.Did,godWeaponData.star+1)
this.SetSkillInfo(this.nextSkillInfo,"升星后技能",nextSkillInfos)
this.nextSkillInfo.gameObject:SetActive(true)
else
this.nextSkillInfo.gameObject:SetActive(false)
2023-03-30 13:16:11 +08:00
end
2023-03-31 17:52:12 +08:00
LayoutRebuilder.ForceRebuildLayoutImmediate(this.skillScroll.transform)
2023-03-30 13:16:11 +08:00
this.limitText.text="星级已满"
end
this.SetPropInfo(curPropDic,this.curPropGrid)
---判断等级星级是否达到上限
if isLimit then
this.jiantou.gameObject:SetActive(false)
this.upStarBtn.gameObject:SetActive(false)
this.upLvBtn.gameObject:SetActive(false)
this.limitText.gameObject:SetActive(true)
this.nextPropGrid.gameObject:SetActive(false)
this.costGrid.gameObject:SetActive(false)
2023-04-04 14:54:14 +08:00
costItems={}
2023-03-30 13:16:11 +08:00
else
this.costGrid.gameObject:SetActive(true)
this.SetPropInfo(nextPropDic,this.nextPropGrid)
this.SetCostItemInfo(costItems)
2023-03-31 17:52:12 +08:00
this.limitText.gameObject:SetActive(false)
2023-03-30 13:16:11 +08:00
end
2023-03-31 17:52:12 +08:00
2023-03-30 13:16:11 +08:00
end
---设置属性信息
function this.SetPropInfo(_propDic,_propGrid)
local propInfoList={}
local index=1
for key, value in pairs(_propDic) do
propInfoList[index]={}
local propConfig=ConfigManager.GetConfigData(ConfigName.PropertyConfig,key)
propInfoList[index].name=propConfig.Info
propInfoList[index].val=value
index=index+1
end
for i = 1, _propGrid.transform.childCount do
local propText=_propGrid.transform:GetChild(i-1).gameObject
if i>#propInfoList then
propText:SetActive(false)
else
propText:SetActive(true)
propText:GetComponent("Text").text=propInfoList[i].name
Util.GetGameObject(propText,"val"):GetComponent("Text").text=propInfoList[i].val
end
end
end
--设置升星技能信息显示
2023-03-30 16:27:13 +08:00
function this.SetSkillInfo(_skillInfoObj,_titleStr,_skillDatas)
Util.GetGameObject(_skillInfoObj,"title"):GetComponent("Text").text=_titleStr
local desStr=""
for i = 1, #_skillDatas do
desStr=desStr..string.format("【%s】%s",_skillDatas[i].title,_skillDatas[i].des)
if i< #_skillDatas then
desStr=desStr.."\n"
end
end
Util.GetGameObject(_skillInfoObj,"des"):GetComponent("Text").text=desStr
LayoutRebuilder.ForceRebuildLayoutImmediate(_skillInfoObj.transform)
2023-03-30 13:16:11 +08:00
end
2023-03-31 17:52:12 +08:00
2023-03-30 13:16:11 +08:00
--设置消耗材料显示
function this.SetCostItemInfo(_costItems)
if not this.costItemViews then
this.costItemViews = {}
end
for k,v in ipairs(this.costItemViews) do
v.gameObject:SetActive(false)
end
for i = 1, #_costItems do
2023-03-31 17:52:12 +08:00
local view
if i<=#this.costItemViews then
view=this.costItemViews[i]
2023-03-30 13:16:11 +08:00
else
2023-03-31 17:52:12 +08:00
view= SubUIManager.Open(SubUIConfig.ItemView, this.costGrid.transform)
table.insert(this.costItemViews,view)
end
view:OnOpen(false,{_costItems[i][1],_costItems[i][2]},0.9,true,true,false,this.sortingOrder)
view.gameObject:SetActive(true)
view.addImage.gameObject:SetActive(false)
2023-04-04 14:54:14 +08:00
if tabType==2 then
2023-03-31 17:52:12 +08:00
local haveUpStarCost=GodWeaponManager.GetUpStarCost(godWeaponData)
local needNum=_costItems[i][2]
view.num:GetComponent("Text").text=string.format("%s/%s",#haveUpStarCost,_costItems[i][2])
if #haveUpStarCost>=needNum then
view.num:GetComponent("Text").color=UIColor.WRITE
end
2023-03-30 13:16:11 +08:00
end
end
end
function this:OnSortingOrderChange()
this.sortingOrder = self.sortingOrder
end
--界面关闭时调用(用于子类重写)
function this:OnClose()
2023-03-31 17:52:12 +08:00
FixedUpdateBeat:Remove(this.OnUpdate, self)
2023-03-30 13:16:11 +08:00
end
--界面销毁时调用(用于子类重写)
function this:OnDestroy()
this.spLoader:Destroy()
2023-03-31 17:52:12 +08:00
SubUIManager.Close(this.UpView)
2023-03-30 13:16:11 +08:00
end
return this