miduo_client/Assets/ManagedResources/~Lua/Modules/Practice/FourQuadrantPopup.lua

514 lines
20 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

require("Base/BasePanel")
FourQuadrantPopup = Inherit(BasePanel)
local this = FourQuadrantPopup
local ProfessionType = {
[1] = 2,--输出
[2] = 1,--肉盾
[3] = 3,--控制
[4] = 4,--辅助
}
local propertyType = {
[1] = 2,--攻击
[2] = 1,--生命
[3] = 3,--护甲
[4] = 4,--魔抗
}
--属性id对应属性名称
local PropertyName={
[1] = "生命",
[2] = "攻击",
[3] = "护甲",
[4] = "魔抗",
}
local lastPropertyLimit={}--上一级属性上限
local propertyLimit={}--属性上限
local fourQuadConfig
local upStarProperty={}--进阶属性
--长按升级状态
local _isClicked = false
local _isLongPress = false
local _isReqLvUp=false
local oldPower = 0
local newPower = 0
this.timePressStarted = 0--监听长按时间
local oldPropMap={}
local barWidth=700
--初始化组件用于子类重写FourQuadrantPopup
function this:InitComponent()
this.spLoader = SpriteLoader.New()
this.mask = Util.GetGameObject(self.gameObject, "mask")
this.backBtn = Util.GetGameObject(self.gameObject, "bg/btnBack")
this.titleText = Util.GetGameObject(self.gameObject, "bg/titleText"):GetComponent("Text")
this.limitHint = Util.GetGameObject(self.gameObject, "bg/limitHint"):GetComponent("Text")
this.limitCost = Util.GetGameObject(self.gameObject, "bg/limitHint/costIcon"):GetComponent("Image")
this.shuchuBtn = Util.GetGameObject(self.gameObject, "bg/TabBox/box/shuchuBtn")
this.roudunBtn =Util.GetGameObject(self.gameObject, "bg/TabBox/box/roudunBtn")
this.kongzhiBtn = Util.GetGameObject(self.gameObject, "bg/TabBox/box/kongzhiBtn")
this.fuzhuBtn = Util.GetGameObject(self.gameObject, "bg/TabBox/box/fuzhuBtn")
this.selectBtn = Util.GetGameObject(self.gameObject, "bg/TabBox/selectBtn")
this.upBtn = Util.GetGameObject(self.gameObject, "bg/upBtn")
this.upStarBtn = Util.GetGameObject(self.gameObject, "bg/upStarBtn")
this.helpBtn = Util.GetGameObject(self.gameObject, "bg/HelpBtn")
this.helpPosition=this.helpBtn:GetComponent("RectTransform").localPosition
this.propertyGrid=Util.GetGameObject(self.gameObject, "bg/propertyGrid")
this.costPreParent=Util.GetGameObject(self.gameObject, "bg/materialGrid")
this.upStarHint=Util.GetGameObject(self.gameObject, "bg/upStarHint"):GetComponent("Text")
this.upLvTrigger = Util.GetEventTriggerListener(this.upBtn)
this.grayImage=Util.GetGameObject(self.gameObject, "bg/gray"):GetComponent("Image")
this.upStarPropBtn = Util.GetGameObject(self.gameObject, "bg/upStarPropBtn")
this.upStarPropWin = Util.GetGameObject(self.gameObject, "upStarPropWin")
this.propWinGrid = Util.GetGameObject(self.gameObject, "upStarPropWin/grid")
this.propWinCloseBtn = Util.GetGameObject(self.gameObject, "upStarPropWin/closeBtn")
this.starLv = Util.GetGameObject(self.gameObject, "bg/starLv")
this.gongmingBtn = Util.GetGameObject(self.gameObject, "bg/gongmingBtn")
this.skillBtn = Util.GetGameObject(self.gameObject, "bg/skillBtn")
this.skillBtn:SetActive(false)
this.professionIcon = Util.GetGameObject(self.gameObject, "bg/professionIcon"):GetComponent("Image")
this.btnList={
[1]=this.roudunBtn,
[2]=this.shuchuBtn,
[3]=this.kongzhiBtn,
[4]=this.fuzhuBtn,}
this.propPreMap={}
for i = 1, #propertyType do
local obj=this.propertyGrid.transform:GetChild(i-1)
local propObjMap={}
propObjMap.bar=Util.GetGameObject(obj.gameObject,"progressBg/progressBar"):GetComponent("RectTransform")
propObjMap.addValue=Util.GetGameObject(obj.gameObject,"progressBg/addValue"):GetComponent("Text")
propObjMap.propertyValueText=Util.GetGameObject(obj.gameObject,"propertyValue"):GetComponent("Text")
propObjMap.propertyNameText=Util.GetGameObject(obj.gameObject,"propertyName"):GetComponent("Text")
propObjMap.propertyIcon=Util.GetGameObject(obj.gameObject,"propertyIcon"):GetComponent("Image")
propObjMap.fade=nil
this.propPreMap[propertyType[i]]=propObjMap
end
this.itemView= SubUIManager.Open(SubUIConfig.ItemView, this.limitCost.transform)
end
--绑定事件(用于子类重写)
function this:BindEvent()
Util.AddClick(this.backBtn, function()
self:ClosePanel()
end)
Util.AddClick(this.mask, function()
self:ClosePanel()
end)
Util.AddClick(this.shuchuBtn, function()
local professionId=ProfessionType[1]
this.SetSelectBtn(professionId)
this.UpdateData(professionId)
end)
Util.AddClick(this.roudunBtn, function()
local professionId=ProfessionType[2]
this.SetSelectBtn(professionId)
this.UpdateData(professionId)
end)
Util.AddClick(this.kongzhiBtn, function()
local professionId=ProfessionType[3]
this.SetSelectBtn(professionId)
this.UpdateData(professionId)
end)
Util.AddClick(this.fuzhuBtn, function()
local professionId=ProfessionType[4]
this.SetSelectBtn(professionId)
this.UpdateData(professionId)
end)
Util.AddClick(this.gongmingBtn, function()
UIManager.OpenPanel(UIName.FourQuadrantGongmingPopup)
end)
Util.AddClick(this.skillBtn, function()
UIManager.OpenPanel(UIName.GeneralInfoPopup,GENERALINFO_TYPE.FourQuadrant,this.professionId,this.professionLv,this.curProfessionName)
end)
Util.AddClick(this.limitCost.gameObject, function()
this.itemView:OnBtnCkickEvent(this.upStarCostitem.Id)
end)
Util.AddOnceClick(this.upBtn, function()
if this.CheckIsUpStar() then
return
end
local costArr=fourQuadConfig.LvupCost
for i = 1, #costArr do
if BagManager.GetTotalItemNum(costArr[i][1])<costArr[i][2]then
PopupTipPanel.ShowTip("材料不足")
return
end
end
NetManager.SendSixiangUpRequest(this.professionId,this.UpdateProperty)
end)
Util.AddClick(this.upStarBtn, function()
if this.CheckXiuxingLv() then
local costArr=fourQuadConfig.RankupCost
for i = 1, #costArr do
if BagManager.GetTotalItemNum(costArr[i][1])<costArr[i][2]then
PopupTipPanel.ShowTip("材料不足")
return
end
end
NetManager.SendSixiangUpStarRequest(this.professionId,this.UpStarUpdate)
else
PopupTipPanel.ShowTip("修行等级不满足进阶条件")
end
end)
Util.AddClick(this.helpBtn, function()
UIManager.OpenPanel(UIName.HelpPopup, HELP_TYPE.FourQuadrant, self.helpPosition.x,self.helpPosition.y)
end)
Util.AddClick(this.upStarPropBtn, function()
this.upStarPropWin:SetActive(true);
for i = 1, #propertyType do
local objIndex=i-1
local propertyId=propertyType[i]
local _propText= this.propWinGrid.transform:GetChild(objIndex):GetComponent("Text")
local addProp=0
if upStarProperty[propertyId] then
addProp=upStarProperty[propertyId]
end
_propText.text=string.format("%s英雄%s+%s",GetProfessionNameById(this.professionId),PropertyName[propertyId],addProp)
end
end)
Util.AddClick(this.propWinCloseBtn, function()
this.upStarPropWin:SetActive(false);
end)
--长按升级按下状态
this._onPointerDown = function(Pointgo, data)
LogRed("长按按下状态")
_isClicked = true
this.timePressStarted = Time.realtimeSinceStartup
end
--长按升级抬起状态
this._onPointerUp = function(Pointgo, data)
LogRed("长按抬起状态")
_isClicked = false
_isLongPress = false
-- this.ShowAddPropNum(this.professionId)
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.timePressStarted=Time.realtimeSinceStartup
local costArr=fourQuadConfig.LvupCost
for i = 1, #costArr do
if BagManager.GetTotalItemNum(costArr[i][1])<costArr[i][2]then
PopupTipPanel.ShowTip("材料不足")
_isClicked = false
_isLongPress = false
return
end
end
NetManager.SendSixiangUpRequest(this.professionId,this.UpdateProperty)
end
end
end
end
--添加事件监听(用于子类重写)
function this:AddListener()
Game.GlobalEvent:AddEvent(GameEvent.FourQuadrant.ShowPower, this.ShowPower)
end
--移除事件监听(用于子类重写)
function this:RemoveListener()
Game.GlobalEvent:RemoveEvent(GameEvent.FourQuadrant.ShowPower, this.ShowPower)
end
--界面打开时调用(用于子类重写)
function this:OnOpen(data)
FixedUpdateBeat:Add(this.OnUpdate, self)--长按方法注册
this.SetSelectBtn(ProfessionType[1])
this.UpdateData(ProfessionType[1])
oldPower = FormationManager.GetFormationPower(FormationTypeDef.FORMATION_NORMAL)
end
function this.SetSelectBtn(_professionId)
this.selectBtn.transform:SetParent(this.btnList[_professionId].transform)
this.selectBtn.transform.localPosition = Vector3.New(0,-6,0)
this.selectBtn.transform:SetAsFirstSibling();
end
function this.UpdateData(_professionId)
oldPropMap={}
this.professionId=_professionId;
this.curProfessionName=GetProfessionNameById(_professionId)
this.titleText.text="四象心法-"..this.curProfessionName
local professionInfo=PracticeManager.FourQuadrantData[_professionId]
this.professionLv=professionInfo and professionInfo.level or 0
this.upStarPropBtn:SetActive(this.professionLv>0)
local propertyList=professionInfo and professionInfo.propertyList or nil
fourQuadConfig = ConfigManager.GetConfigDataByKey(ConfigName.FourQuadrantConfig,"Star",this.professionLv)
---获取属性上限属性id:属性上限值)
for i = 1, #fourQuadConfig.PropLimit do
propertyLimit[fourQuadConfig.PropLimit[i][1]]=fourQuadConfig.PropLimit[i][2]
end
if this.professionLv>0 then
local lastStarLv=this.professionLv-1
local lastFourQuadConfig = ConfigManager.GetConfigDataByKey(ConfigName.FourQuadrantConfig,"Star",lastStarLv)
---获取上一级属性上限属性id:属性上限值)
for i = 1, #lastFourQuadConfig.PropLimit do
lastPropertyLimit[lastFourQuadConfig.PropLimit[i][1]]=lastFourQuadConfig.PropLimit[i][2]
end
else
lastPropertyLimit={}
end
upStarProperty=PracticeManager.fourQuadrantUpStarPropMap[_professionId]
this.SaveOldProp(propertyList)
this.UpdateBtnStateAndCostShow()
this.UpdateProperty(propertyList)
this.UpdateStarLv()
this.professionIcon.sprite = this.spLoader:LoadSprite(GetHeroProfessionById(_professionId))
end
---更新职业等级显示
function this.UpdateStarLv()
local lvCount=this.starLv.transform.childCount
for i = 0, lvCount-1 do
local star=this.starLv.transform:GetChild(i).gameObject
if i<this.professionLv then
star:SetActive(true)
else
star:SetActive(false)
end
end
end
---刷新界面强化进阶按钮状态和消耗显示
function this.UpdateBtnStateAndCostShow()
this.UpdateUpStarTip()
local costArr={}
--检测是否可以进阶
if this.CheckIsUpStar() then
if this.professionLv>=5 then
this.upStarHint.text=string.format("四象心法-%s已强化圆满",this.curProfessionName)
this.upBtn.gameObject:SetActive(false)
this.upStarBtn.gameObject:SetActive(false)
this.upStarHint.gameObject:SetActive(true)
elseif this.CheckXiuxingLv() then
this.upBtn.gameObject:SetActive(false)
this.upStarBtn.gameObject:SetActive(true)
this.upStarHint.gameObject:SetActive(false)
costArr=fourQuadConfig.RankupCost
this.upStarBtn.gameObject:GetComponent("Image").material=nil
else
this.upBtn.gameObject:SetActive(false)
this.upStarBtn.gameObject:SetActive(true)
this.upStarHint.gameObject:SetActive(true)
this.upStarBtn.gameObject:GetComponent("Image").material=this.grayImage.material
end
_isClicked = false
_isLongPress = false
else
this.upBtn.gameObject:SetActive(true)
this.upStarBtn.gameObject:SetActive(false)
this.upStarHint.gameObject:SetActive(false)
costArr=fourQuadConfig.LvupCost
end
--设置消耗显示
for i = 1, this.costPreParent.transform.childCount do
local costObj=this.costPreParent.transform:GetChild(i-1).gameObject;
if i<=#costArr then
local costStr=costArr[i]
costObj:SetActive(true);
local icon = Util.GetGameObject(costObj,"Image"):GetComponent("Image")
local num = costObj:GetComponent("Text")
icon.sprite = this.spLoader:LoadSprite(GetSpriteNameByItemId(costStr[1]))
local cueHasNum=BagManager.GetTotalItemNum(costArr[i][1])
num.text = string.format("%s/%s",PrintWanNum2(cueHasNum),costStr[2])
if cueHasNum<costStr[2] then
num.text = string.format("<color=red>%s/%s</color>",PrintWanNum2(cueHasNum),costStr[2])
end
local itemBtn=Util.GetGameObject(costObj,"Image")
local itemId=costStr[1]
Util.AddOnceClick(itemBtn, function()
LogRed("itemid:"..itemId)
this.itemView:OnBtnCkickEvent(itemId)
end)
else
costObj:SetActive(false);
end
end
end
function this.UpdateUpStarTip()
if fourQuadConfig.RankupCost then
this.upStarCostitem= ConfigManager.GetConfigData(ConfigName.ItemConfig,fourQuadConfig.RankupCost[1][1])
this.limitHint.gameObject:SetActive(true)
if this.CheckIsUpStar() then
this.limitCost.gameObject:SetActive(false)
this.limitHint.text=string.format("<color=#24F604>进阶后,四种属性全部提升%s%%</color>",10)
else
local itemName=this.upStarCostitem.Name
local itemIcon=GetResourcePath(this.upStarCostitem.ResourceID)
this.limitHint.text=string.format("四种属性强化至上限后使用 <color=#24F604>%s</color>进阶",itemName)
this.limitCost.gameObject:SetActive(true)
this.limitCost.sprite=this.spLoader:LoadSprite(itemIcon)
this.itemView:OnOpen(false, {this.upStarCostitem.Id,1}, 0, false,false,false)
end
else
this.limitHint.gameObject:SetActive(false)
end
end
---更新属性信息
function this.UpdateProperty(_propertyInfoList)
local _propertyInfoMap={}
if _propertyInfoList then
for i = 1, #_propertyInfoList do
_propertyInfoMap[_propertyInfoList[i].propertyId]=_propertyInfoList[i].propertyNum
end
end
for i = 1, #propertyType do
local propertyId=propertyType[i]
this.propPreMap[propertyId].propertyIcon.sprite=this.spLoader:LoadSprite(PropertyTypeIconDef[propertyId])
this.propPreMap[propertyId].propertyNameText.text=string.format("%s英雄%s",this.curProfessionName,PropertyName[propertyId])
local propertyNum=_propertyInfoMap[propertyId] and _propertyInfoMap[propertyId] or 0;
local curPropLimit=propertyLimit[propertyId]
local propBar=this.propPreMap[propertyId].bar
if this.professionLv>0 then
local progressNum=_propertyInfoMap[propertyId]-lastPropertyLimit[propertyId]
local progressLimit=curPropLimit-lastPropertyLimit[propertyId]
propBar.sizeDelta= Vector2.New(progressNum/progressLimit*barWidth,propBar.sizeDelta.y)
else
propBar.sizeDelta = Vector2.New(propertyNum/curPropLimit*barWidth,propBar.sizeDelta.y)
end
this.propPreMap[propertyId].propertyValueText.text=string.format("%s/%s",propertyNum,curPropLimit)
end
this.UpdateBtnStateAndCostShow()
_isReqLvUp = false
this.CheckWinRedPoint()
this.ShowAddPropNum(this.professionId)
end
---显示战斗力提升
function this.ShowPower()
newPower = FormationManager.GetFormationPower(FormationTypeDef.FORMATION_NORMAL)
if newPower~=oldPower then
UIManager.OpenPanel(UIName.WarPowerChangeNotifyPanelV2,{oldValue = oldPower,newValue = newPower})
oldPower = newPower
end
end
--保存打开界面时初始属性
function this.SaveOldProp(_propertyInfoList)
if _propertyInfoList then
for i = 1, #_propertyInfoList do
oldPropMap[_propertyInfoList[i].propertyId]=_propertyInfoList[i].propertyNum
end
end
end
--显示属性值增加
function this.ShowAddPropNum(_professionId)
local propertyList=PracticeManager.FourQuadrantData[_professionId].propertyList
if propertyList then
for i = 1, #propertyList do
local propertyInfo=propertyList[i]
local oldPropNum=0
if oldPropMap[propertyInfo.propertyId] then
oldPropNum=oldPropMap[propertyInfo.propertyId]
end
local addNum=propertyInfo.propertyNum-oldPropNum
if addNum>0 then
this.propPreMap[propertyInfo.propertyId].addValue.text=string.format("+%s",addNum);
this.propPreMap[propertyInfo.propertyId].addValue.gameObject:SetActive(true)
if this.propPreMap[propertyInfo.propertyId].fade then
this.propPreMap[propertyInfo.propertyId].fade:Kill()
end
this.propPreMap[propertyInfo.propertyId].addValue:DOFade(1, 0)
this.propPreMap[propertyInfo.propertyId].fade= this.propPreMap[propertyInfo.propertyId].addValue:DOFade(0, 3):OnComplete(function()
this.propPreMap[propertyInfo.propertyId].fade=nil
end)
end
oldPropMap[propertyInfo.propertyId]=propertyInfo.propertyNum
end
end
end
--进阶刷新界面
function this.UpStarUpdate()
this.UpdateData(this.professionId)
end
--检测当前强化进度是否可以进阶
function this.CheckIsUpStar()
local professionInfo=PracticeManager.FourQuadrantData[this.professionId]
if not professionInfo.propertyList then
return false
end
for i = 1, #professionInfo.propertyList do
local propertyInfo= professionInfo.propertyList[i];
if propertyInfo.propertyNum<propertyLimit[propertyInfo.propertyId] then
return false
end
end
return true
end
--检测修行等级是否满足进阶条件
function this.CheckXiuxingLv()
local nextLv= this.professionLv+1
local nextConfig=ConfigManager.GetConfigDataByKey(ConfigName.FourQuadrantConfig,"Star",nextLv)
if nextConfig==nil then
return false
end
local xiuxingConfig= ConfigManager.GetConfigData(ConfigName.XiuXianConfig,nextConfig.XiuxianLimit)
this.upStarHint.text=string.format("修行到达<color=#24F604>%s期</color>后方可进阶",xiuxingConfig.RealmName)
if PracticeManager.PracticeBigLevel<xiuxingConfig.RealmId then
return false
end
return true
end
--检测界面页签红点
function this.CheckWinRedPoint()
for i = 1, #this.btnList do
local rodPoint= Util.GetGameObject(this.btnList[i].gameObject,"Redpot")
if PracticeManager.CheckIsUpStarCondition(i) then
if PracticeManager.CheckIsUpStarByProfessionId(i) then
rodPoint:SetActive(true)
else
rodPoint:SetActive(false)
end
else
if PracticeManager.CheckIsUpByProfessionId(i) then
rodPoint:SetActive(true)
else
rodPoint:SetActive(false)
end
end
end
end
--界面关闭时调用(用于子类重写)
function this:OnClose()
FixedUpdateBeat:Remove(this.OnUpdate, self)
end
function this:OnDestroy()
this.spLoader:Destroy()
end
return FourQuadrantPopup