miduo_client/Assets/ManagedResources/~Lua/Modules/NiuQiChongTian/NiuQiChongTianPanel.lua

226 lines
9.3 KiB
Lua

require("Base/BasePanel")
local NiuQiChongTian = Inherit(BasePanel)
local artConfig = ConfigManager.GetConfig(ConfigName.ArtResourcesConfig)
local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
local this = NiuQiChongTian
local sortingOrder = 0
local activityId = 0
local progressData = {}
local rewardData = {}
local curScore = 0
local itemsGrid = {}--item重复利用
local curPage = 1
local redPointList = {}
local TabBox = require("Modules/Common/TabBox")
local _TabData={ [1] = { default = "r_hero_xuanze_002", select = "r_hero_xuanze_001", name = Language[12251] ,rpType = RedPointType.NiuQiChongTian_1},
[2] = { default = "r_hero_xuanze_002", select = "r_hero_xuanze_001", name = Language[12252] ,rpType = RedPointType.NiuQiChongTian_2},
[3] = { default = "r_hero_xuanze_002", select = "r_hero_xuanze_001", name = Language[12253] ,rpType = RedPointType.NiuQiChongTian_3},}
local _TabFontColor = { default = Color.New(130 / 255, 128 / 255, 120 / 255, 1),
select = Color.New(243 / 255, 235 / 255, 202 / 255, 1)}
local curIndex = 1
local BtnState ={
[0] = {ImgName = "s_slbz_1anniuhuangse",Text = Language[10556]},
[1] = {ImgName = "s_slbz_1anniuongse",Text = Language[11948]},
[2] = {ImgName = "s_slbz_1anniuhuise",Text = Language[10101]},
}
--初始化组件(用于子类重写)
function NiuQiChongTian:InitComponent()
self.backBtn = Util.GetGameObject(self.gameObject,"backBtn")
self.tabBox = Util.GetGameObject(self.gameObject, "TabBox")
self.UpView = SubUIManager.Open(SubUIConfig.UpView, self.gameObject.transform, { showType = UpViewOpenType.ShowLeft})
--进度条
self.progress = Util.GetGameObject(self.gameObject, "mid/progress/value"):GetComponent("Image")--fillAmount
self.reward = Util.GetGameObject(self.gameObject, "mid/reward")
--任务列表
self.itemPre = Util.GetGameObject(self.gameObject, "rewardPre")
self.scrollItem = Util.GetGameObject(self.gameObject, "mid/rewardArena")
local rootHight = self.scrollItem.transform.rect.height
local width = self.scrollItem.transform.rect.width
self.ScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, self.scrollItem.transform,self.itemPre, nil, Vector2.New(width, rootHight), 1, 1, Vector2.New(0,0))
self.ScrollView.moveTween.MomentumAmount = 1
self.ScrollView.moveTween.Strength = 2
self.effect5 = Util.GetGameObject(self.reward, "icon (5)/UI_Effect_jinkuang_Yuan")
Util.SetParticleSortLayer(self.effect5, 1)
sortingOrder = 0
end
--绑定事件(用于子类重写)
function NiuQiChongTian:BindEvent()
Util.AddClick(self.backBtn,function ()
self:ClosePanel()
end)
end
--添加事件监听(用于子类重写)
function NiuQiChongTian:AddListener()
end
--移除事件监听(用于子类重写)
function NiuQiChongTian:RemoveListener()
end
function NiuQiChongTian:OnSortingOrderChange()
Util.AddParticleSortLayer(self.effect5, self.sortingOrder - sortingOrder)
sortingOrder = self.sortingOrder
end
--界面打开时调用(用于子类重写)
function NiuQiChongTian:OnOpen()
self.UpView:OnOpen({ showType = UpViewOpenType.ShowLeft, panelType = PanelType.NiuQiChongTian })
end
-- 打开,重新打开时回调
function NiuQiChongTian:OnShow()
local actId = ActivityGiftManager.IsActivityTypeOpen(ActivityTypeDef.NiuQi)
if not actId or actId <= 0 then return end
self.gameObject:SetActive(true)
self.TabCtrl = TabBox.New()
self.TabCtrl:SetTabAdapter(this.TabAdapter)
self.TabCtrl:SetChangeTabCallBack(this.SwitchView)
self.TabCtrl:Init(self.tabBox, _TabData, curIndex)
end
-- tab节点显示自定义
function this.TabAdapter(tab, index, status)
local tabLab = Util.GetGameObject(tab, "Text")
local redPoint = Util.GetGameObject(tab, "Redpot")
if _TabData[index].rpType > 0 then
if redPointList[_TabData[index].rpType] then
ClearRedPointObject(_TabData[index].rpType, redPointList[_TabData[index].rpType])
end
BindRedPointObject(_TabData[index].rpType,redPoint)
redPointList[_TabData[index].rpType] = redPoint
end
Util.GetGameObject(tab,"Image"):GetComponent("Image").sprite = Util.LoadSprite(_TabData[index][status])
tabLab:GetComponent("Text").text = _TabData[index].name
tabLab:GetComponent("Text").color = _TabFontColor[status]
end
--切换
function this.SwitchView(index,bool)
curPage = index
rewardData = NiuQiChongTianManager.GetNeedRewardData(curPage)
NiuQiChongTian:SetProgress()
NiuQiChongTian:SetReward(bool)
end
function NiuQiChongTian:SetProgress()
curScore = NiuQiChongTianManager.GetScore()
progressData = NiuQiChongTianManager.configData
self.progress.fillAmount = curScore/progressData[#progressData].value[2][1]
for i = 1, self.reward.transform.childCount do
local item = self.reward.transform:GetChild(i-1)
Util.GetGameObject(item, "num/Text"):GetComponent("Text").text = progressData[i].reward[1][2]
Util.GetGameObject(item, "Text"):GetComponent("Text").text = progressData[i].value[2][1]
Util.GetGameObject(item, "icon"):GetComponent("Image").sprite = Util.LoadSprite(artConfig[itemConfig[progressData[i].reward[1][1]].ResourceID].Name)
Util.GetGameObject(item, "red"):SetActive(progressData[i].state == 1)
local btn = Util.GetGameObject(item, "icon")
Util.AddOnceClick(btn,function ()
if progressData[i].state == 1 then
NetManager.GetActivityRewardRequest(progressData[i].missionId,progressData[i].activityId,function (drop)
UIManager.OpenPanel(UIName.RewardItemPopup, drop, 1,function ()
progressData[i].state = 2
NiuQiChongTian:SetProgress()
CheckRedPointStatus(RedPointType.NiuQiChongTian_4)
end)
end)
elseif progressData[i].state == 0 then
UIManager.OpenPanel(UIName.RewardItemSingleShowPopup,progressData[i].reward[1][1],nil)
else
PopupTipPanel.ShowTip(Language[10421])
end
end)
end
end
function NiuQiChongTian:SetReward(bool)
local anim = bool or false
local data = {}
self.ScrollView:SetData(rewardData, function (index, go)
NiuQiChongTian:SingleDataShow(go,index,rewardData[index])
end,false,anim)
end
function NiuQiChongTian:SingleDataShow(go, index,data)
local title = Util.GetGameObject(go, "title/titleText"):GetComponent("Text")
local btn = Util.GetGameObject(go, "btn"):GetComponent("Button")
local btnImg = Util.GetGameObject(go, "btn"):GetComponent("Image")
local btnText = Util.GetGameObject(go, "btn/Text"):GetComponent("Text")
local redPoint = Util.GetGameObject(go, "btn/redPoint")
local rewardList = Util.GetGameObject(go, "rewardList")
local grid = Util.GetGameObject(go, "rewardList")
local shadow = Util.GetGameObject(go, "shadow")
local shows = data.Reward
title.text = GetLanguageStrById(data.Text)
redPoint:SetActive(data.state == 1)
btn.interactable = data.state ~= 2
btnImg.sprite = Util.LoadSprite(BtnState[data.state].ImgName)
btnText.text = BtnState[data.state].Text
--滚动条复用重设itemview
if itemsGrid[go] then
for i = 1, 4 do
itemsGrid[go][i].gameObject:SetActive(false)
end
for i = 1, #shows do
if itemsGrid[go][i] then
itemsGrid[go][i]:OnOpen(false, {shows[i][1],shows[i][2]}, 0.9,false,false,false,sortingOrder)
itemsGrid[go][i].gameObject:SetActive(true)
end
end
else
itemsGrid[go]={}
for i = 1, 4 do
itemsGrid[go][i] = SubUIManager.Open(SubUIConfig.ItemView, grid.transform)
itemsGrid[go][i].gameObject:SetActive(false)
local obj = newObjToParent(shadow,itemsGrid[go][i].transform)
obj.transform:SetAsFirstSibling()
obj.transform:DOAnchorPos(Vector3(0,-3,0),0)
obj:GetComponent("RectTransform").transform.localScale = Vector3.one*1.1
obj.gameObject:SetActive(true)
obj.transform:SetSiblingIndex(0)
end
for i = 1, #shows do
itemsGrid[go][i]:OnOpen(false, {shows[i][1],shows[i][2]}, 0.9,false,false,false,sortingOrder)
itemsGrid[go][i].gameObject:SetActive(true)
end
end
Util.AddOnceClick(btn.gameObject,function ()
if data.state == 0 then
UIManager.OpenPanel(UIName.RecruitPanel)
elseif data.state == 1 then
NetManager.TakeMissionRewardRequest(TaskTypeDef.NiuQiChongTian,data.id,function (msg)
UIManager.OpenPanel(UIName.RewardItemPopup,msg.drop,1,function ()
CheckRedPointStatus(RedPointType.NiuQiChongTian + curPage)
CheckRedPointStatus(RedPointType.NiuQiChongTian_4)
this.SwitchView(curPage,true)
end)
end)
end
end)
end
--界面关闭时调用(用于子类重写)
function NiuQiChongTian:OnClose()
for key, value in pairs(redPointList) do
ClearRedPointObject(key, value)
end
redPointList = {}
end
--界面销毁时调用(用于子类重写)
function NiuQiChongTian:OnDestroy()
SubUIManager.Close(self.UpView)
sortingOrder = 0
end
return NiuQiChongTian