miduo_client/Assets/ManagedResources/~Lua/Modules/Carbon/DailyCarbonPanel.lua

502 lines
21 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")
DailyCarbonPanel = Inherit(BasePanel)
local this = DailyCarbonPanel
local dailyChallengeConfig=ConfigManager.GetConfig(ConfigName.DailyChallengeConfig)
local mainLevelConfig = ConfigManager.GetConfig(ConfigName.MainLevelConfig)
local itemConfig=ConfigManager.GetConfig(ConfigName.ItemConfig)
local specialConfig=ConfigManager.GetConfig(ConfigName.SpecialConfig)
local curData={}
local orginLayer=0
local carbonIndex=0--副本索引
local maxForce = 0
--顶部背景图
local titleBg={
--金币
[1]={bg="OPY154", titleImg = "r_richang_banner_5_zi_zh",name="和之石副本", titleTip = GetLanguageStrById(specialConfig[41].Value),pos = Vector3.New(257.08,658.37,0)},
--经验
[2]={bg="OPX13", titleImg = "r_richang_banner_4_zi_zh",name="酒铁矿副本", titleTip = GetLanguageStrById(specialConfig[42].Value),pos = Vector3.New(257.08,651.24,0)},
--神将
[3]={bg="r_richang_banner_3_zh", titleImg = "r_richang_banner_3_zi_zh", name="英雄副本",titleTip = GetLanguageStrById(specialConfig[43].Value),pos = Vector3.New(257.08,658.37,0)},
--法宝
[4]={bg="r_richang_banner_2_zh", titleImg = "r_richang_banner_2_zi_zh",name="生命卡副本", titleTip = GetLanguageStrById(specialConfig[44].Value),pos = Vector3.New(257.08,651.24,0)},
--魂印
[5]={bg="r_richang_banner_1_zh", titleImg = "r_richang_banner_1_zi_zh", name="霸气副本",titleTip = GetLanguageStrById(specialConfig[45].Value),pos = Vector3.New(257.08,651.24,0)},
}
--难度图片
local qualityBg={
[1]={s="gm_richang_jd_zh",b="gm_richang_di1",name="简单"},
[2]={s="gm_richang_pt_zh",b="gm_richang_di1",name="普通"},
[3]={s="gm_richang_kn_zh",b="gm_richang_di1",name="困难"},
[4]={s="gm_richang_em_zh",b="gm_richang_di1",name="噩梦"},
[5]={s="gm_richang_ly_zh",b="gm_richang_di2",name="炼狱"},
[6]={s="gm_richang_dy_zh",b="gm_richang_di2",name="地狱"},
[7]={s="gm_richang_sy_zh",b="gm_richang_di2",name="深渊"},
[8]={s="gm_richang_cq_zh",b="gm_richang_di2",name="传奇"},
[9]={s="gm_richang_sh_zh",b="gm_richang_di2",name="神话"}
}
--副本难度颜色
local txtColor={
[1]="<color=#9F9F9F>%s</color>",
[2]="<color=#7EE01F>%s</color>",
[3]="<color=#FFA136>%s</color>",
[4]="<color=#CC36EC>%s</color>",
[5]="<color=#FF364E>%s</color>",
[6]="<color=#FF364E>%s</color>",
[7]="<color=#FF364E>%s</color>",
[8]="<color=#FF364E>%s</color>",
[9]="<color=#FF364E>%s</color>",
}
local itemList={}--奖励容器
--每日副本服务器数据
local buyTime=0--购买次数
local freeTime=0--免费次数
local maxBuyTime=0
local maxFreeTime=0
--Tab
local TabBox = require("Modules/Common/TabBox")
local _TabData={ [1] = { default = "UI_hz_zhonghe01_83", select = "UI_hz_zhonghe01_82",lock = "UI_hz_gonghui_Lock", name = Language[10282],type=FUNCTION_OPEN_TYPE.DAILYCHALLENGE_COIN },
[2] = { default = "UI_hz_zhonghe01_83", select = "UI_hz_zhonghe01_82",lock = "UI_hz_gonghui_Lock", name = Language[10283],type=FUNCTION_OPEN_TYPE.DAILYCHALLENGE_EXP },
--[3] = { default = "r_richang_anniu_lieyaoshi_01_zh", select = "r_richang_anniu_lieyaoshi_zh",lock = "r_richang_anniu_lieyaoshi_zh", name = Language[10284],type=FUNCTION_OPEN_TYPE.DAILYCHALLENGE_HERODEBRIS },
--[4] = { default = "r_richang_anniu_fabao_01_zh", select = "r_richang_anniu_fabao_zh",lock = "r_richang_anniu_fabao_zh", name = Language[10285],type=FUNCTION_OPEN_TYPE.DAILYCHALLENGE_TALISMAN },
--[5] = { default = "r_richang_anniu_hunyin_01_zh", select = "r_richang_anniu_hunyin_zh",lock = "r_richang_anniu_hunyin_zh", name = Language[10286],type=FUNCTION_OPEN_TYPE.DAILYCHALLENGE_SOULPRINT }
}
local _TabFontColor = { default = Color.New(255 / 255, 255 / 255, 255 / 255, 1),
select = Color.New(255 / 255, 255 / 255, 255 / 255, 1),
lock=Color.New(255 / 255, 255 / 255, 255 / 255, 1)}
function DailyCarbonPanel:InitComponent()
this.spLoader = SpriteLoader.New()
this.panel=Util.GetGameObject(this.gameObject,"Panel")
this.titleBg=Util.GetGameObject(this.panel,"TitleBg"):GetComponent("Image")
this.titleImg=Util.GetGameObject(this.panel,"TitleBg/Image"):GetComponent("Image")
this.titleTip=Util.GetGameObject(this.panel,"TitleBg/Text"):GetComponent("Text")
this.titleName=Util.GetGameObject(this.panel,"TitleBg/titleName"):GetComponent("Text")
this.timeTip=Util.GetGameObject(this.panel,"TimeTip"):GetComponent("Text")
this.titleName=Util.GetGameObject(this.panel,"titleName"):GetComponent("Text")
this.backBtn=Util.GetGameObject(this.panel,"BackBtn")
this.helpBtn= Util.GetGameObject(this.panel, "HelpBtn")
this.helpPosition=this.helpBtn:GetComponent("RectTransform").localPosition
--滚动条
this.pre = Util.GetGameObject(this.panel, "Scroll/Pre")
this.scroll = Util.GetGameObject(this.panel, "Scroll")
this.scrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView,this.scroll.transform,
this.pre, nil, Vector2.New(1080.4, 897.3), 1, 1, Vector2.New(0, 10))
this.scrollView.moveTween.MomentumAmount = 1
this.scrollView.moveTween.Strength = 2
this.upView = SubUIManager.Open(SubUIConfig.UpView, self.gameObject.transform)
this.tabBox = Util.GetGameObject(this.panel, "TabBox")
this.TabCtrl = TabBox.New()
end
function DailyCarbonPanel:BindEvent()
--返回按钮
Util.AddClick(this.backBtn, function()
PlaySoundWithoutClick(SoundConfig.Sound_UICancel)
self:ClosePanel()
end)
--帮助按钮
Util.AddClick(this.helpBtn, function()
UIManager.OpenPanel(UIName.HelpPopup,HELP_TYPE.DailyCarbon,this.helpPosition.x,this.helpPosition.y)
end)
end
function DailyCarbonPanel:OnSortingOrderChange()
orginLayer = self.sortingOrder
for i, v in pairs(itemList) do
for j = 1, #itemList[i] do
itemList[i][j]:SetEffectLayer(orginLayer)
end
end
end
function DailyCarbonPanel:AddListener()
Game.GlobalEvent:AddEvent(GameEvent.FiveAMRefresh.ServerNotifyRefresh,this.FiveRefresh)
end
function DailyCarbonPanel:RemoveListener()
Game.GlobalEvent:RemoveEvent(GameEvent.FiveAMRefresh.ServerNotifyRefresh,this.FiveRefresh)
end
function DailyCarbonPanel:OnOpen(_carbonIndex)
carbonIndex = _carbonIndex and _carbonIndex or 1
this.upView:OnOpen({ showType = UpViewOpenType.ShowLeft, panelType = PanelType.Main })
end
function DailyCarbonPanel:OnShow()
SoundManager.PlayMusic(SoundConfig.BGM_Carbon)
local curFormationForce = FormationManager.GetFormationPower(FormationTypeDef.FORMATION_NORMAL)
if PlayerManager.maxForce < curFormationForce then
PlayerManager.maxForce = curFormationForce
end
maxForce = PlayerManager.maxForce
if carbonIndex==0 then carbonIndex=1 end
this.TabCtrl:SetTabAdapter(this.TabAdapter)
this.TabCtrl:SetTabIsLockCheck(this.TabIsLockCheck)
this.TabCtrl:SetChangeTabCallBack(function(index)
this.RefreshShow(index, true,true)
end)
this.TabCtrl:Init(this.tabBox, _TabData,carbonIndex)
-- 音效
SoundManager.PlayMusic(SoundConfig.BGM_Carbon)
end
function DailyCarbonPanel:RefreshRedPotShow()
local tabs = Util.GetGameObject(this.tabBox,"box").transform
for i = 1,tabs.childCount do
Util.GetGameObject(tabs:GetChild(i-1),"Redpot").gameObject:SetActive(CarbonManager.GetDailyCarbons(i).state)
end
CheckRedPointStatus(RedPointType.HeroExplore)
end
function DailyCarbonPanel:OnClose()
end
function DailyCarbonPanel:OnDestroy()
this.spLoader:Destroy()
itemList={}
this.scrollView=nil
SubUIManager.Close(this.upView)
end
function this.FiveRefresh()
this.RefreshShow(1,false,false)
DailyCarbonPanel:RefreshRedPotShow()
end
--刷新面板
function this.RefreshShow(i,isTop,isAni)
carbonIndex = i
curData={}
curData=ConfigManager.GetAllConfigsDataByKey(ConfigName.DailyChallengeConfig,"Type",i)
this.titleBg.sprite=this.spLoader:LoadSprite(titleBg[i].bg)
this.titleImg.sprite=this.spLoader:LoadSprite(titleBg[i].titleImg)
this.titleTip.text=titleBg[i].titleTip
this.titleName.text=titleBg[i].name
-- this.titleTip.gameObject:GetComponent("RectTransform").localPosition = titleBg[i].pos
this.SetTimeTip()
this.SetScroll(i,isTop,isAni)
DailyCarbonPanel:RefreshRedPotShow()
end
--设置滚动条
local curMaxOpenId = 1
local curName=""
function this.SetScroll(i,isTop,isAni)
local list={}
for k,v in ipairs(curData) do
if not CarbonManager.IsDailyCarbonPass(v.Id) then
curMaxOpenId = v.Quality
break
end
end
local isEnd=false
if CarbonManager.IsDailyCarbonPass(curData[#curData].Id) then
isEnd=true
curMaxOpenId = #curData
end
curName=qualityBg[curMaxOpenId].name
--this.titleName.text=_TabData[curMaxOpenId].name
LogError("curMaxOpenId============="..curMaxOpenId)
this.timeTip.text="<color=#FEF693>当前难度:</color>"..string.format(txtColor[curMaxOpenId],curName)
--state 1:挑战 2未开启 3.扫荡
for k,v in ipairs(curData) do
local aaa={}
aaa.config=v
--解锁状态
local _lv=0 --等级
local _point=0 --关卡
local _power = 0 --data.ForceShow--表战力
for i = 1, #v.OpenRules do
if v.OpenRules[i][1] == 1 then
_lv = v.OpenRules[i][2]
elseif v.OpenRules[i][1] == 2 then
_point = v.OpenRules[i][2]
elseif v.OpenRules[i][1] == 3 then
_power = v.OpenRules[i][2]
end
end
-- LogError("lv==".._lv.." point==".._point.." power==".._power)
local lastData=curData[k-1]
-- 判断每日副本是否解锁
local isOpen = (not lastData or CarbonManager.IsDailyCarbonPass(lastData.Id)) -- 上一个副本解锁
and PlayerManager.level >= _lv -- 等级
and (_point == 0 or FightPointPassManager.IsFightPointPass(_point))
and PlayerManager.maxForce >= _power -- 战斗力
if isOpen then
if CarbonManager.IsDailyCarbonPass(v.Id) then
if isEnd then
if v.Quality==curMaxOpenId then
aaa.state=0
else
aaa.state=3
end
else
if v.Quality==curMaxOpenId-1 then
aaa.state=0
else
aaa.state=3
end
end
else
aaa.state=1
end
else
aaa.state=2
end
--table.insert(list,aaa)
list[k]=aaa
end
table.sort(list,function(a,b)
if a.state==b.state then
return a.config.Id<b.config.Id
else
return a.state<b.state
end
end)
this.scrollView:SetData(list,function(index,root)
this.SetData(root,list[index].config, list[index - 1],list[index].state)
end,not isTop,not isAni)
LogError("curMaxOpenId=="..curMaxOpenId)
-- if CarbonManager.IsDailyCarbonPass(curData[#curData].Id) then
-- curMaxOpenId = #curData
-- end
-- this.scrollView:SetIndex(curMaxOpenId - 2 < 1 and 1 or (curMaxOpenId - 2))
end
--设置滚动条数据 root根节点 data本地表数据 ldata 上一条数据
function this.SetData(root, data, ldata,state)
local type=0 --0为未开启 1为挑战 2为扫荡
local bgQuality=Util.GetGameObject(root,"Bg"):GetComponent("Image")
local title=Util.GetGameObject(root,"Title"):GetComponent("Image")
-- local frame=Util.GetGameObject(root,"frame"):GetComponent("Image")
local reward=Util.GetGameObject(root,"Reward")
local tip=Util.GetGameObject(root,"Tip"):GetComponent("Text")
local power=Util.GetGameObject(root,"powerBtn/value"):GetComponent("Text")
local info=Util.GetGameObject(root,"TitleText"):GetComponent("Text")
local TitleDes=Util.GetGameObject(root,"TitleDes"):GetComponent("Text")
local goBtn=Util.GetGameObject(root,"GoBtn")
local cost=Util.GetGameObject(root,"cost")
local goBtnImage=goBtn:GetComponent("Image")
local goBtnText=Util.GetGameObject(goBtn,"Text"):GetComponent("Text")
local goIcon=Util.GetGameObject(cost,"Icon")
local goIconNum=Util.GetGameObject(cost,"IconNum")
local goIconNumText=Util.GetGameObject(goBtn,"Text"):GetComponent("Text")
local storeData=ConfigManager.GetConfigDataByDoubleKey(ConfigName.StoreConfig,"StoreId",7,"Limit",data.PrivilegeId[1])--商店表数据
title.sprite=this.spLoader:LoadSprite(qualityBg[data.Quality].s)
title:SetNativeSize()
--frame.sprite=this.spLoader:LoadSprite(qualityBg[data.Quality].b)
ResetItemView(root,reward.transform,itemList,3,0.9,orginLayer,false,data.RewardView)
--LogError("state==="..state)
--解锁状态
local _lv=0 --等级
local _point=0 --关卡
local _power = 0 --data.ForceShow--表战力
for i = 1, #data.OpenRules do
if data.OpenRules[i][1] == 1 then
_lv = data.OpenRules[i][2]
elseif data.OpenRules[i][1] == 2 then
_point = data.OpenRules[i][2]
elseif data.OpenRules[i][1] == 3 then
_power = data.OpenRules[i][2]
end
end
if data.OpenRules[2] ~= nil and data.OpenRules[1][1] == 1 then
_lv = data.OpenRules[1][2]
end
if data.OpenRules[1] ~= nil and data.OpenRules[1][1] == 2 then
_point= data.OpenRules[1][2]
end
if data.OpenRules[2][1]==3 then
_power= data.OpenRules[2][2]
end
-- 判断每日副本是否解锁
local isOpen = (not ldata or CarbonManager.IsDailyCarbonPass(ldata.config.Id)) -- 上一个副本解锁
and PlayerManager.level >= _lv -- 等级
and (_point == 0 or FightPointPassManager.IsFightPointPass(_point))
and PlayerManager.maxForce >= _power -- 战斗力
--显示挑战或扫荡道具消耗
goIcon:SetActive(false)
goIconNum:SetActive( false)
if freeTime<=0 then
goIconNumText.text=storeData.Cost[2][4]
end
goBtn:SetActive(false)
--表现显示
if state==1 then
goBtnText.text=Language[10287]
goBtn:SetActive(true)
-- goBtnImage.sprite=this.spLoader:LoadSprite("s_slbz_1anniuhuangse")
--power.text = _power--string.format(Language[10288], _power)
--power.transform.parent.gameObject:SetActive(true)
info.text=_power
TitleDes.text=Language[10028]
tip.gameObject:SetActive(false)
type=1
elseif state==2 then
--power.text = _power --string.format(Language[10291], _power)
goBtnText.text=Language[10292]
goBtn:SetActive(false)
TitleDes.text=Language[10028]
tip.gameObject:SetActive(true)
tip.text="未达成"
info.text=_power
--power.transform.parent.gameObject:SetActive(true)
type=0
elseif state==3 then
goIcon:SetActive(state==1 and freeTime<=0)
goIconNum:SetActive(state==1 and freeTime<=0)
type=2
info.text=_power
goBtnText.text=Language[10289]
-- goBtnImage.sprite=this.spLoader:LoadSprite("s_slbz_1anniuhuise")
goBtn:SetActive(false)
TitleDes.text=Language[10028]
tip.text="已达成"
tip.gameObject:SetActive(true)
--power.transform.parent.gameObject:SetActive(false)
elseif state==0 then
goIcon:SetActive(freeTime<=0)
goIconNum:SetActive(freeTime<=0)
goBtn:SetActive(true)
type=2
goBtnText.text="可扫荡"
TitleDes.text="扫荡次数"
info.text=string.format("%s/%s次",buyTime+freeTime,maxBuyTime+maxFreeTime)
-- goBtnImage.sprite=this.spLoader:LoadSprite("s_slbz_1anniuhuangse")
tip.gameObject:SetActive(false)
--power.transform.parent.gameObject:SetActive(false)
end
-- Util.SetGray(goBtn,state==1)
--点击事件
Util.AddOnceClick(goBtn,function()
if PlayerManager.level<_lv then
PopupTipPanel.ShowTip(string.format(Language[10293],_lv))
return
elseif PlayerManager.maxForce < _power then
PopupTipPanel.ShowTip(string.format(Language[10294], _power))
return
elseif _point ~= 0 and not FightPointPassManager.IsFightPointPass(_point) then
PopupTipPanel.ShowTip(string.format(Language[10295], GetLanguageStrById(mainLevelConfig[_point].Name)))
return
-- elseif PlayerManager.curMapId ~= 0 and FightPointPassManager.IsFightPointPass(PlayerManager.curMapId)==false then
-- PopupTipPanel.ShowTip(string.format("未通关%s",mainLevelConfig[_point].Name))
-- return
end
if state==2 then
PopupTipPanel.ShowTip(Language[10296])
return
end
--检测剩余次数
if buyTime<=0 and freeTime<=0 and type==2 then
PopupTipPanel.ShowTip(Language[10297])
return
end
--检测妖晶数量
local itemId=storeData.Cost[1][1] --消耗道具
if BagManager.GetItemCountById(itemId)<storeData.Cost[2][4] and freeTime<=0 and type==2 then
PopupTipPanel.ShowTip(string.format(Language[10298],GetLanguageStrById(itemConfig[itemId].Name)))
return
end
--当免费次数不足 是扫荡 购买次数
if freeTime<=0 and type==2 then
ShopManager.RequestBuyShopItem(SHOP_TYPE.FUNCTION_SHOP,storeData.Id,1,function() end)
end
-- TODO: 没有战斗结果校验
NetManager.DailyChallengeRequest(data.Id,type,function(msg)
local fightData = BattleManager.GetBattleServerData(msg)
if state==1 then --挑战
UIManager.OpenPanel(UIName.BattlePanel, fightData, BATTLE_TYPE.DAILY_CHALLENGE , function(result)
if result.result ==0 then
elseif result.result==1 then
UIManager.OpenPanel(UIName.RewardItemPopup,msg.drop,1,function()
-- PrivilegeManager.RefreshPrivilegeUsedTimes(data.PrivilegeId[2],1)
CarbonManager.AddDailyChallengeInfo(data.Id)
this.RefreshShow(carbonIndex,false,false)
end)
end
end)
elseif state==0 then --扫荡
UIManager.OpenPanel(UIName.RewardItemPopup,msg.drop,1,function()
PrivilegeManager.RefreshPrivilegeUsedTimes(data.PrivilegeId[2],1)
this.RefreshShow(carbonIndex,false,false)
end)
end
end)
end)
end
--设置剩余次数
function this.SetTimeTip()
LogError("curData[1].PrivilegeId[1]=="..curData[1].PrivilegeId[1])
local storeData=ConfigManager.GetConfigDataByDoubleKey(ConfigName.StoreConfig,"StoreId",7,"Limit",curData[1].PrivilegeId[1])--商店表数据
local buyTimeId= curData[1].PrivilegeId[1]
local freeTimeId=curData[1].PrivilegeId[2]
LogError("buytimeid=="..buyTimeId.." freetimeid=="..freeTimeId)
buyTime=ShopManager.GetShopItemRemainBuyTimes(SHOP_TYPE.FUNCTION_SHOP,storeData.Id) --购买次数
maxBuyTime=ShopManager.GetShopItemLimitBuyCount(storeData.Id)
freeTime=PrivilegeManager.GetPrivilegeRemainValue(freeTimeId) --免费次数
maxFreeTime=PrivilegeManager.GetPrivilegeNumberById(freeTimeId)
--LogGreen("buyTime "..buyTime.." freeTime "..freeTime)
LogError("maxBuyTime=="..maxBuyTime.." maxFreeTime=="..maxFreeTime)
local str=""
if freeTime>0 then
str=string.format(Language[12292],tostring(freeTime))
else
str=string.format(Language[10300],tostring(buyTime))
end
-- this.titleName=_TabData[curMaxOpenId].name
--this.timeTip.text=str
end
-- tab节点显示自定义
function this.TabAdapter(tab, index, status)
-- local tabLab = Util.GetGameObject(tab, "Text")
local lock = Util.GetGameObject(tab, "LockImage")
local islock = status == "lock"
Util.SetGray( Util.GetGameObject(tab,"Image").gameObject, islock)
lock:SetActive(islock)
Util.GetGameObject(tab,"Image"):GetComponent("Image").sprite = this.spLoader:LoadSprite(_TabData[index][status])
Util.GetGameObject(tab,"Text"):GetComponent("Text").text = _TabData[index].name
Util.GetGameObject(tab,"select"):SetActive(status=="select")
-- tabLab:GetComponent("Text").text = _TabData[index].name
-- tabLab:GetComponent("Text").color = _TabFontColor[status]
end
function this.TabIsLockCheck(index)
if not ActTimeCtrlManager.SingleFuncState(_TabData[index].type) then
return true,ActTimeCtrlManager.SystemOpenTip(_TabData[index].type)
end
return false
end
return DailyCarbonPanel