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

513 lines
20 KiB
Lua
Raw Normal View History

2021-09-09 20:45:12 +08:00
require("Base/BasePanel")
FourQuadrantPopup = Inherit(BasePanel)
local this = FourQuadrantPopup
local ProfessionType = {
[1] = 2,--输出
[2] = 1,--肉盾
[3] = 3,--控制
[4] = 4,--辅助
}
2021-09-11 13:37:26 +08:00
local propertyType = {
[1] = 2,--攻击
[2] = 1,--生命
[3] = 3,--护甲
[4] = 4,--魔抗
}
2021-09-09 20:45:12 +08:00
--属性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--监听长按时间
2021-09-11 17:50:21 +08:00
local oldPropMap={}
local barWidth=700
2021-09-09 20:45:12 +08:00
--初始化组件用于子类重写FourQuadrantPopup
function this:InitComponent()
this.spLoader = SpriteLoader.New()
this.mask = Util.GetGameObject(self.gameObject, "mask")
2021-09-09 20:45:12 +08:00
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")
2021-09-10 14:37:47 +08:00
this.limitCost = Util.GetGameObject(self.gameObject, "bg/limitHint/costIcon"):GetComponent("Image")
2021-09-09 20:45:12 +08:00
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.professionIcon = Util.GetGameObject(self.gameObject, "bg/professionIcon"):GetComponent("Image")
this.btnList={
[1]=this.roudunBtn,
[2]=this.shuchuBtn,
[3]=this.kongzhiBtn,
[4]=this.fuzhuBtn,}
2021-09-11 17:50:21 +08:00
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
2021-09-10 14:37:47 +08:00
this.itemView= SubUIManager.Open(SubUIConfig.ItemView, this.limitCost.transform)
2021-09-09 20:45:12 +08:00
end
--绑定事件(用于子类重写)
function this:BindEvent()
Util.AddClick(this.backBtn, function()
self:ClosePanel()
end)
Util.AddClick(this.mask, function()
self:ClosePanel()
end)
2021-09-09 20:45:12 +08:00
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)
2021-09-10 14:37:47 +08:00
Util.AddClick(this.limitCost.gameObject, function()
this.itemView:OnBtnCkickEvent(this.upStarCostitem.Id)
end)
Util.AddOnceClick(this.upBtn, function()
2021-09-11 13:37:26 +08:00
if this.CheckIsUpStar() then
return
end
2021-09-09 20:45:12 +08:00
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()
2021-09-13 17:18:32 +08:00
if this.CheckXiuxingLv() then
2021-09-10 15:08:50 +08:00
local costArr=fourQuadConfig.RankupCost
for i = 1, #costArr do
if BagManager.GetTotalItemNum(costArr[i][1])<costArr[i][2]then
PopupTipPanel.ShowTip("材料不足")
return
end
2021-09-10 11:22:08 +08:00
end
2021-09-10 15:08:50 +08:00
NetManager.SendSixiangUpStarRequest(this.professionId,this.UpStarUpdate)
2021-09-13 17:18:32 +08:00
else
PopupTipPanel.ShowTip("修行等级不满足进阶条件")
end
2021-09-09 20:45:12 +08:00
end)
Util.AddClick(this.helpBtn, function()
2021-09-11 13:37:26 +08:00
UIManager.OpenPanel(UIName.HelpPopup, HELP_TYPE.FourQuadrant, self.helpPosition.x,self.helpPosition.y)
2021-09-09 20:45:12 +08:00
end)
Util.AddClick(this.upStarPropBtn, function()
this.upStarPropWin:SetActive(true);
2021-09-11 13:37:26 +08:00
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
2021-09-13 18:40:38 +08:00
_propText.text=string.format("%s神将%s+%s",GetProfessionNameById(this.professionId),PropertyName[propertyId],addProp)
2021-09-09 20:45:12 +08:00
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
2021-09-11 17:50:21 +08:00
-- this.ShowAddPropNum(this.professionId)
2021-09-09 20:45:12 +08:00
end
this.upLvTrigger.onPointerDown = this.upLvTrigger.onPointerDown + this._onPointerDown
this.upLvTrigger.onPointerUp = this.upLvTrigger.onPointerUp + this._onPointerUp
end
--长按升级处理
function this.OnUpdate()
if _isClicked then
2021-09-24 15:45:20 +08:00
if Time.realtimeSinceStartup - this.timePressStarted > 0.4 then
2021-09-09 20:45:12 +08:00
_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.zero
this.selectBtn.transform:SetAsFirstSibling();
end
function this.UpdateData(_professionId)
2021-09-11 17:50:21 +08:00
oldPropMap={}
2021-09-09 20:45:12 +08:00
this.professionId=_professionId;
2021-09-11 17:50:21 +08:00
this.curProfessionName=GetProfessionNameById(_professionId)
2021-09-09 20:45:12 +08:00
this.titleText.text="四象心法-"..this.curProfessionName
local professionInfo=PracticeManager.FourQuadrantData[_professionId]
this.professionLv=professionInfo and professionInfo.level or 0
2021-09-11 13:37:26 +08:00
this.upStarPropBtn:SetActive(this.professionLv>0)
2021-09-09 20:45:12 +08:00
local propertyList=professionInfo and professionInfo.propertyList or nil
fourQuadConfig = ConfigManager.GetConfigDataByKey(ConfigName.FourQuadrantConfig,"Star",this.professionLv)
2021-09-11 13:37:26 +08:00
2021-09-09 20:45:12 +08:00
---获取属性上限属性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)
2021-09-11 13:37:26 +08:00
---获取上一级属性上限属性id:属性上限值)
2021-09-09 20:45:12 +08:00
for i = 1, #lastFourQuadConfig.PropLimit do
lastPropertyLimit[lastFourQuadConfig.PropLimit[i][1]]=lastFourQuadConfig.PropLimit[i][2]
end
else
lastPropertyLimit={}
end
2021-09-11 13:37:26 +08:00
2021-09-18 15:43:32 +08:00
2021-09-11 13:37:26 +08:00
2021-09-11 17:50:21 +08:00
upStarProperty=PracticeManager.fourQuadrantUpStarPropMap[_professionId]
this.SaveOldProp(propertyList)
2021-09-09 20:45:12 +08:00
this.UpdateBtnStateAndCostShow()
this.UpdateProperty(propertyList)
this.UpdateStarLv()
this.professionIcon.sprite = this.spLoader:LoadSprite(GetHeroProfessionById(_professionId))
end
2021-09-11 17:50:21 +08:00
---更新职业等级显示
2021-09-09 20:45:12 +08:00
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()
2021-09-18 15:43:32 +08:00
this.UpdateUpStarTip()
2021-09-09 20:45:12 +08:00
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])
2021-09-11 17:50:21 +08:00
num.text = string.format("%s/%s",PrintWanNum2(cueHasNum),costStr[2])
2021-09-09 20:45:12 +08:00
if cueHasNum<costStr[2] then
2021-09-11 17:50:21 +08:00
num.text = string.format("<color=red>%s/%s</color>",PrintWanNum2(cueHasNum),costStr[2])
2021-09-09 20:45:12 +08:00
end
local itemBtn=Util.GetGameObject(costObj,"Image")
local itemId=costStr[1]
Util.AddOnceClick(itemBtn, function()
LogRed("itemid:"..itemId)
this.itemView:OnBtnCkickEvent(itemId)
end)
2021-09-09 20:45:12 +08:00
else
costObj:SetActive(false);
end
end
end
2021-09-18 15:43:32 +08:00
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
2021-09-10 11:22:08 +08:00
---更新属性信息
2021-09-09 20:45:12 +08:00
function this.UpdateProperty(_propertyInfoList)
local _propertyInfoMap={}
if _propertyInfoList then
for i = 1, #_propertyInfoList do
_propertyInfoMap[_propertyInfoList[i].propertyId]=_propertyInfoList[i].propertyNum
end
end
2021-09-11 13:37:26 +08:00
for i = 1, #propertyType do
local propertyId=propertyType[i]
2021-09-11 17:50:21 +08:00
this.propPreMap[propertyId].propertyIcon.sprite=this.spLoader:LoadSprite(PropertyTypeIconDef[propertyId])
this.propPreMap[propertyId].propertyNameText.text=string.format("%s神将%s",this.curProfessionName,PropertyName[propertyId])
2021-09-11 13:37:26 +08:00
local propertyNum=_propertyInfoMap[propertyId] and _propertyInfoMap[propertyId] or 0;
local curPropLimit=propertyLimit[propertyId]
2021-09-11 17:50:21 +08:00
local propBar=this.propPreMap[propertyId].bar
2021-09-09 20:45:12 +08:00
if this.professionLv>0 then
2021-09-11 13:37:26 +08:00
local progressNum=_propertyInfoMap[propertyId]-lastPropertyLimit[propertyId]
local progressLimit=curPropLimit-lastPropertyLimit[propertyId]
2021-09-11 17:50:21 +08:00
propBar.sizeDelta= Vector2.New(progressNum/progressLimit*barWidth,propBar.sizeDelta.y)
2021-09-09 20:45:12 +08:00
else
2021-09-11 18:05:55 +08:00
propBar.sizeDelta = Vector2.New(propertyNum/curPropLimit*barWidth,propBar.sizeDelta.y)
2021-09-09 20:45:12 +08:00
end
2021-09-11 17:50:21 +08:00
this.propPreMap[propertyId].propertyValueText.text=string.format("%s/%s",propertyNum,curPropLimit)
2021-09-09 20:45:12 +08:00
end
this.UpdateBtnStateAndCostShow()
_isReqLvUp = false
this.CheckWinRedPoint()
2021-09-11 17:50:21 +08:00
this.ShowAddPropNum(this.professionId)
2021-09-09 20:45:12 +08:00
end
---显示战斗力提升
function this.ShowPower()
newPower = FormationManager.GetFormationPower(FormationTypeDef.FORMATION_NORMAL)
2021-09-13 18:40:38 +08:00
if newPower~=oldPower then
UIManager.OpenPanel(UIName.WarPowerChangeNotifyPanelV2,{oldValue = oldPower,newValue = newPower})
oldPower = newPower
end
2021-09-09 20:45:12 +08:00
end
2021-09-11 17:50:21 +08:00
--保存打开界面时初始属性
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]
2021-09-13 17:18:32 +08:00
local oldPropNum=0
if oldPropMap[propertyInfo.propertyId] then
oldPropNum=oldPropMap[propertyInfo.propertyId]
end
local addNum=propertyInfo.propertyNum-oldPropNum
2021-09-11 17:50:21 +08:00
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
2021-09-09 20:45:12 +08:00
--进阶刷新界面
function this.UpStarUpdate()
this.UpdateData(this.professionId)
end
--检测当前强化进度是否可以进阶
function this.CheckIsUpStar()
local professionInfo=PracticeManager.FourQuadrantData[this.professionId]
2021-09-10 11:22:08 +08:00
if not professionInfo.propertyList then
2021-09-09 20:45:12 +08:00
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