365 lines
15 KiB
Lua
365 lines
15 KiB
Lua
require("Base/BasePanel")
|
|
GodWeaponUpPanel = Inherit(BasePanel)
|
|
local this = GodWeaponUpPanel
|
|
local tabType = 1 --1升级 2升星
|
|
local godWeaponData
|
|
|
|
--长按升级状态
|
|
local _isClicked = false
|
|
local _isReqLvUp = false
|
|
local _isLongPress = false
|
|
local addLvNum = 0
|
|
local isTriggerLongClick = false --长按是否升过级
|
|
local costItems = {}
|
|
--初始化组件(用于子类重写)
|
|
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")
|
|
this.curPropGrid = Util.GetGameObject(self.gameObject, "infoLayout/propertyInfo/allProp/curProp")
|
|
this.nextPropGrid = Util.GetGameObject(self.gameObject, "infoLayout/propertyInfo/allProp/nextProp")
|
|
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")
|
|
this.upLvTrigger = Util.GetEventTriggerListener(this.upLvBtn)
|
|
this.limitText = Util.GetGameObject(self.gameObject, "infoLayout/btnLayout/limitText"):GetComponent("Text")
|
|
this.jiantou = Util.GetGameObject(self.gameObject, "infoLayout/propertyInfo/jiantou")
|
|
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")
|
|
this.upLvTabRedPoint = Util.GetGameObject(this.upLvTab, "redPoint")
|
|
this.upStarTabRedPoint = Util.GetGameObject(this.upStarTab, "redPoint")
|
|
this.costItemViews = {}
|
|
this.UpView = SubUIManager.Open(SubUIConfig.UpView, self.gameObject.transform, { showType = UpViewOpenType.ShowLeft })
|
|
end
|
|
|
|
--绑定事件(用于子类重写)
|
|
function this:BindEvent()
|
|
Util.AddClick(this.btnBack, function()
|
|
self:ClosePanel()
|
|
end)
|
|
Util.AddClick(this.upLvTab, function()
|
|
tabType = 1
|
|
this.SetSelectBtn()
|
|
this.UpdateWinInfo()
|
|
end)
|
|
Util.AddClick(this.upStarTab, function()
|
|
tabType = 2
|
|
this.SetSelectBtn()
|
|
this.UpdateWinInfo()
|
|
end)
|
|
|
|
Util.AddClick(this.upStarBtn, function()
|
|
local oldWarPower = FormationManager.GetFormationPower(FormationTypeDef.FORMATION_NORMAL)
|
|
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()
|
|
local newWarPower = FormationManager.GetFormationPower(FormationTypeDef.FORMATION_NORMAL)
|
|
--飘战力
|
|
PokemonManager.PiaoWarPowerChange(oldWarPower, newWarPower)
|
|
end)
|
|
else
|
|
PopupTipPanel.ShowTip(Language[10054])
|
|
end
|
|
end)
|
|
Util.AddClick(this.upLvBtn, function()
|
|
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
|
|
|
|
--长按升级处理
|
|
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
|
|
end)
|
|
end
|
|
|
|
--升级按钮点击事件处理
|
|
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(Language[11210])
|
|
else
|
|
PopupTipPanel.ShowTip(Language[10054])
|
|
end
|
|
return
|
|
end
|
|
if isSingleLvUp then --单次点击升级
|
|
local oldWarPower = FormationManager.GetFormationPower(FormationTypeDef.FORMATION_NORMAL)
|
|
NetManager.RequestMagicSoldierStrong(godWeaponData.Did, 1, 1, nil, function(msg)
|
|
GodWeaponManager.SetGodWeaponLv(godWeaponData.Did, 1)
|
|
this.UpdateWinInfo()
|
|
local newWarPower = FormationManager.GetFormationPower(FormationTypeDef.FORMATION_NORMAL)
|
|
--飘战力
|
|
PokemonManager.PiaoWarPowerChange(oldWarPower, newWarPower)
|
|
end)
|
|
else
|
|
isTriggerLongClick = true
|
|
local oldWarPower = FormationManager.GetFormationPower(FormationTypeDef.FORMATION_NORMAL)
|
|
--前端先扣除材料
|
|
for i = 1, #costItems do
|
|
BagManager.HeroLvUpUpdateItemsNum(costItems[i][1], costItems[i][2])
|
|
end
|
|
addLvNum = addLvNum + 1
|
|
GodWeaponManager.SetGodWeaponLv(godWeaponData.Did, 1)
|
|
this.UpdateWinInfo()
|
|
local newWarPower = FormationManager.GetFormationPower(FormationTypeDef.FORMATION_NORMAL)
|
|
--飘战力
|
|
PokemonManager.PiaoWarPowerChange(oldWarPower, newWarPower)
|
|
_isReqLvUp = false
|
|
end
|
|
end
|
|
|
|
function this.SetSelectBtn()
|
|
local _btnTab
|
|
if tabType == 1 then
|
|
_btnTab = this.upLvTab
|
|
|
|
this.selectText.text = Language[11010]
|
|
else
|
|
_btnTab = this.upStarTab
|
|
this.selectText.text = Language[11211]
|
|
end
|
|
this.selectBtn.transform:SetParent(_btnTab.transform)
|
|
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 = GetLanguageStrById(godWeaponData.config.Name)
|
|
this.UpdateWinInfo()
|
|
this.UpView:OnOpen({ showType = UpViewOpenType.ShowLeft, panelType = PanelType.GodWeapon })
|
|
end
|
|
|
|
function this:OnShow()
|
|
FixedUpdateBeat:Add(this.OnUpdate, self) --长按方法注册
|
|
end
|
|
|
|
function this.UpdateWinInfo()
|
|
costItems = {}
|
|
CheckRedPointStatus(RedPointType.GodWeapon)
|
|
local upLvRed = GodWeaponManager.CheckUpLvRedPoint(godWeaponData)
|
|
this.upLvTabRedPoint:SetActive(upLvRed)
|
|
local upStarRed = GodWeaponManager.CheckUpStarRedPoint(godWeaponData)
|
|
this.upStarTabRedPoint:SetActive(upStarRed)
|
|
this.curLv.text = Language[11212] .. godWeaponData.lv
|
|
local starSize = Vector2.New(80, 80)
|
|
PokemonManager.SetHeroStars(this.spLoader, this.starGrid, godWeaponData.star, 1, starSize)
|
|
local curPropDic
|
|
local nextPropDic
|
|
local isLimit = false
|
|
if tabType == 1 then
|
|
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)
|
|
local upLvCosts = ConfigManager.GetConfigDataByDoubleKey(ConfigName.ShenBingLevel, "Level", godWeaponData.lv,
|
|
"Quality", godWeaponData.config.Quality).Consume
|
|
for i = 1, #upLvCosts do
|
|
costItems[i] = upLvCosts[i]
|
|
end
|
|
end
|
|
this.limitText.text = Language[11213]
|
|
else
|
|
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)
|
|
local curSkillInfos = GodWeaponManager.GetSingleGodWeaponSkillDes(godWeaponData.Did)
|
|
this.SetSkillInfo(this.curSkillInfo, Language[11214], curSkillInfos)
|
|
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
|
|
local nextSkillInfos = GodWeaponManager.GetSingleGodWeaponSkillDes(godWeaponData.Did, godWeaponData.star + 1)
|
|
this.SetSkillInfo(this.nextSkillInfo, Language[11215], nextSkillInfos)
|
|
this.nextSkillInfo.gameObject:SetActive(true)
|
|
else
|
|
this.nextSkillInfo.gameObject:SetActive(false)
|
|
end
|
|
LayoutRebuilder.ForceRebuildLayoutImmediate(this.skillScroll.transform)
|
|
this.limitText.text = Language[11216]
|
|
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)
|
|
costItems = {}
|
|
else
|
|
this.costGrid.gameObject:SetActive(true)
|
|
this.SetPropInfo(nextPropDic, this.nextPropGrid)
|
|
this.SetCostItemInfo(costItems)
|
|
this.limitText.gameObject:SetActive(false)
|
|
end
|
|
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 = GetLanguageStrById(propInfoList[i].name)
|
|
Util.GetGameObject(propText, "val"):GetComponent("Text").text = propInfoList[i].val
|
|
end
|
|
end
|
|
end
|
|
|
|
--设置升星技能信息显示
|
|
function this.SetSkillInfo(_skillInfoObj, _titleStr, _skillDatas)
|
|
Util.GetGameObject(_skillInfoObj, "title"):GetComponent("Text").text = GetLanguageStrById(_titleStr)
|
|
local desStr = ""
|
|
for i = 1, #_skillDatas do
|
|
desStr = desStr .. string.format("【%s】%s", GetLanguageStrById(_skillDatas[i].title), GetLanguageStrById(_skillDatas[i].des))
|
|
if i < #_skillDatas then
|
|
desStr = desStr .. "\n"
|
|
end
|
|
end
|
|
Util.GetGameObject(_skillInfoObj, "des"):GetComponent("Text").text = desStr
|
|
LayoutRebuilder.ForceRebuildLayoutImmediate(_skillInfoObj.transform)
|
|
end
|
|
|
|
--设置消耗材料显示
|
|
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
|
|
local view
|
|
if i <= #this.costItemViews then
|
|
view = this.costItemViews[i]
|
|
else
|
|
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)
|
|
if tabType == 2 then
|
|
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
|
|
end
|
|
end
|
|
end
|
|
|
|
function this:OnSortingOrderChange()
|
|
this.sortingOrder = self.sortingOrder
|
|
end
|
|
|
|
--界面关闭时调用(用于子类重写)
|
|
function this:OnClose()
|
|
FixedUpdateBeat:Remove(this.OnUpdate, self)
|
|
end
|
|
|
|
--界面销毁时调用(用于子类重写)
|
|
function this:OnDestroy()
|
|
this.spLoader:Destroy()
|
|
SubUIManager.Close(this.UpView)
|
|
end
|
|
|
|
return this
|