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

432 lines
17 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,--辅助
}
--职业id对应职业名称
local ProfessionName={
[1] = "肉盾",
[2] = "输出",
[3] = "控制",
[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--监听长按时间
--初始化组件用于子类重写FourQuadrantPopup
function this:InitComponent()
this.spLoader = SpriteLoader.New()
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.professionIcon = Util.GetGameObject(self.gameObject, "bg/professionIcon"):GetComponent("Image")
this.btnList={
[1]=this.roudunBtn,
[2]=this.shuchuBtn,
[3]=this.kongzhiBtn,
[4]=this.fuzhuBtn,}
this.itemView= SubUIManager.Open(SubUIConfig.ItemView, this.limitCost.transform)
end
--绑定事件(用于子类重写)
function this:BindEvent()
Util.AddClick(this.backBtn, 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.AddClick(this.upBtn, function()
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
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)
end)
Util.AddClick(this.helpBtn, function()
UIManager.OpenPanel(UIName.HelpPopup, HELP_TYPE.Practice, self.helpPosition.x,self.helpPosition.y)
LogYellow("点击帮助按钮")
end)
Util.AddClick(this.upStarPropBtn, function()
this.upStarPropWin:SetActive(true);
for i = 0, this.propWinGrid.transform.childCount-1 do
local _propText= this.propWinGrid.transform:GetChild(i):GetComponent("Text")
local _index=i+1;
_propText.text=string.format("%s神将%s+%s",ProfessionName[this.professionId],PropertyName[_index],upStarProperty[_index])
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
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.2 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.zero
this.selectBtn.transform:SetAsFirstSibling();
end
function this.UpdateData(_professionId)
this.professionId=_professionId;
this.curProfessionName=ProfessionName[_professionId]
this.titleText.text="四象心法-"..this.curProfessionName
local professionInfo=PracticeManager.FourQuadrantData[_professionId]
this.professionLv=professionInfo and professionInfo.level or 0
local propertyList=professionInfo and professionInfo.propertyList or nil
fourQuadConfig = ConfigManager.GetConfigDataByKey(ConfigName.FourQuadrantConfig,"Star",this.professionLv)
this.upStarCostitem= ConfigManager.GetConfigData(ConfigName.ItemConfig,fourQuadConfig.RankupCost[1][1])
local itemName=this.upStarCostitem.Name
local itemIcon=GetResourcePath(this.upStarCostitem.ResourceID)
LogRed("icon:"..itemIcon)
this.limitHint.text=string.format("四种属性强化至上限后使用 <color=#24F604>%s</color>进阶",itemName)
this.limitCost.sprite=this.spLoader:LoadSprite(itemIcon)
this.itemView:OnOpen(false, {this.upStarCostitem.Id,1}, 0, false,false,false)
upStarProperty=PracticeManager.fourQuadrantUpStarPropMap[_professionId]
---获取属性上限属性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
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()
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",cueHasNum,costStr[2])
if cueHasNum<costStr[2] then
num.text = string.format("<color=red>%s/%s</color>",cueHasNum,costStr[2])
end
else
costObj:SetActive(false);
end
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 key,limitValue in ipairs(propertyLimit)do
local obj=this.propertyGrid.transform:GetChild(key-1)
local bar=Util.GetGameObject(obj.gameObject,"progressBg/progressBar"):GetComponent("Image")
local propertyValueText=Util.GetGameObject(obj.gameObject,"propertyValue"):GetComponent("Text")
local propertyNameText=Util.GetGameObject(obj.gameObject,"propertyName"):GetComponent("Text")
local propertyIcon=Util.GetGameObject(obj.gameObject,"propertyIcon"):GetComponent("Image")
propertyIcon.sprite=this.spLoader:LoadSprite(PropertyTypeIconDef[key])
propertyNameText.text=string.format("%s神将%s",this.curProfessionName,PropertyName[key])
local propertyNum=_propertyInfoMap[key] and _propertyInfoMap[key] or 0;
if this.professionLv>0 then
local progressNum=_propertyInfoMap[key]-lastPropertyLimit[key]
local progressLimit=limitValue-lastPropertyLimit[key]
bar.fillAmount = progressNum/progressLimit
else
bar.fillAmount = propertyNum/limitValue
end
propertyValueText.text=string.format("%s/%s",propertyNum,limitValue)
end
this.UpdateBtnStateAndCostShow()
_isReqLvUp = false
this.CheckWinRedPoint()
end
---显示战斗力提升
function this.ShowPower()
newPower = FormationManager.GetFormationPower(FormationTypeDef.FORMATION_NORMAL)
UIManager.OpenPanel(UIName.WarPowerChangeNotifyPanelV2,{oldValue = oldPower,newValue = newPower})
oldPower = newPower
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