require("Base/BasePanel") SevenDayCarnivalPanelV2 = Inherit(BasePanel) local this = SevenDayCarnivalPanelV2 local treasureTaskConfig = ConfigManager.GetConfig(ConfigName.TreasureTaskConfig) local TabBox = require("Modules/Common/TabBox") local _TabData={} local _TabData={ [1] = { default = "UI_hz_gonghui_31", select = "UI_hz_gonghui_31", name = "刷充GM",img = "gm_shuachong_scGM_01_zh",id=2201,scale=0,all=0 }, [2] = { default = "UI_hz_gonghui_32", select = "UI_hz_gonghui_32", name = "超级特权" ,img = "gm_shuachong_cjGM_01_zh",id=2202,scale=6,all=128}, [3] = { default = "UI_hz_gonghui_33", select = "UI_hz_gonghui_33", name = "神级特权" ,img = "gm_shuachong_sjGM_01_zh",id=2203,scale=5,all=400 }, [4] = { default = "UI_hz_gonghui_34", select = "UI_hz_gonghui_34", name = "无上特权",img = "gm_shuachong_wsGM_01_zh",id=2204,scale=2,all=3500 }, } local _TabFontColor = { default = Color.New(130 / 255, 128 / 255, 120 / 255, 1), select = Color.New(243 / 255, 235 / 255, 202 / 255, 1)} local curIndex local dayBtn = {}--天数btn local rewardBtn = {}--积分btn local curDayIndex = 1 local serverTaskList--服务器所有开服狂欢数据 local curServerTaskList--服务器所有开服狂欢某一天某页签数据 [missionid] = data local allTaskListConfigDtata--表里所有开服狂欢某一天数据 local curTaskListConfigDtata--表里所有开服狂欢某一天某页签数据 local currentDay -- 当前第几天 local allRewardTaskList --表里所有开服狂欢积分数据 local tabBoxRedPoint = {} local itemList = {}--优化itemView使用 local sorting=0 --半价购买数据 local shopInfoList local curShopData this.timer = Timer.New() --初始化组件(用于子类重写) function SevenDayCarnivalPanelV2:InitComponent() this.spLoader = SpriteLoader.New() --子模块脚本 this.BtnBack = Util.GetGameObject(self.transform, "bg/btnBack") Util.GetGameObject(self.transform, "bg/Image"):SetActive(false) this.helpBtn = Util.GetGameObject(self.gameObject, "bg/helpBtn") this.helpPosition=this.helpBtn:GetComponent("RectTransform").localPosition + Vector3(0,200,0) this.tabBox = Util.GetGameObject(self.gameObject, "TabBox") this.equipPre = Util.GetGameObject(self.gameObject, "bg/rewardPro") --this.ScrollBar=Util.GetGameObject(self.gameObject, "CompoundPanel_Equip/Scrollbar"):GetComponent("Scrollbar") local v2 = Util.GetGameObject(self.gameObject, "bg/taskList"):GetComponent("RectTransform").rect this.ScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, Util.GetGameObject(self.gameObject, "bg/taskList").transform, this.equipPre, nil, Vector2.New(-v2.x*2, -v2.y*2), 1, 1, Vector2.New(50,0)) this.ScrollView.moveTween.MomentumAmount = 1 this.ScrollView.moveTween.Strength = 1 for i = 1, 7 do dayBtn[i] = Util.GetGameObject(self.gameObject, "bg/daysTabBg/tabsGroup/day_".. i) end this.progressImage = Util.GetGameObject(self.gameObject, "bg/finalTarget/progressbar/progress"):GetComponent("Image") this.progressText = Util.GetGameObject(self.gameObject, "bg/finalTarget/curProgress/Text"):GetComponent("Text") for i = 1, 4 do rewardBtn[i] = Util.GetGameObject(self.gameObject, "bg/finalTarget/rewardProgress/rewardBoxBtn (" .. i .. ")") end this.dayBtnSelect = Util.GetGameObject(self.gameObject, "bg/daysTabBg/tabsGroup/selected") this.dayBtnSelect2 = Util.GetGameObject(self.gameObject, "bg/daysTabBg/tabsGroup/selected2") this.timeTextExpertgo = Util.GetGameObject(self.gameObject, "bg/actRemainTime") this.timeTextExpert = Util.GetGameObject(self.gameObject, "bg/actRemainTime"):GetComponent("Text") this.TabCtrl = TabBox.New() this.UpView = SubUIManager.Open(SubUIConfig.UpView, self.transform, { showType = UpViewOpenType.ShowLeft }) end --绑定事件(用于子类重写) function SevenDayCarnivalPanelV2:BindEvent() for i = 1, 7 do Util.AddClick(dayBtn[i], function() if i == curDayIndex then return end this.OnDayClickBtn(i) end) end Util.AddClick(this.BtnBack, function() self:ClosePanel() end) --帮助按钮 Util.AddClick(this.helpBtn, function() UIManager.OpenPanel(UIName.HelpPopup,HELP_TYPE.OpenSevenDay,this.helpPosition.x,this.helpPosition.y+220) end) end --添加事件监听(用于子类重写) function SevenDayCarnivalPanelV2:AddListener() Game.GlobalEvent:AddEvent(GameEvent.MissionDaily.OnMissionDailyChanged, this.RefreshTaskShow) Game.GlobalEvent:AddEvent(GameEvent.Activity.OnCloseSevenDayGift, self.OnClosePanelFun, self) end --移除事件监听(用于子类重写) function SevenDayCarnivalPanelV2:RemoveListener() Game.GlobalEvent:RemoveEvent(GameEvent.MissionDaily.OnMissionDailyChanged, this.RefreshTaskShow) Game.GlobalEvent:RemoveEvent(GameEvent.Activity.OnCloseSevenDayGift, self.OnClosePanelFun, self) end --界面打开时调用(用于子类重写) function SevenDayCarnivalPanelV2:OnOpen(_curDayIndex) curDayIndex = _curDayIndex or 1 end --界面打开或者重新打开后,界面刷新时调用(用于子类重写) function SevenDayCarnivalPanelV2:OnShow() currentDay = SevenDayCarnivalManager.GetCurrentDayNumber() this.OnDayClickBtn(curDayIndex) this.ShowTitleDayBtnsData() this.ShowTitleProgressRewardData() this.ShowTime() this.RefreshRedPoint() self.UpView:OnOpen({ showType = UpViewOpenType.ShowLeft, panelType = PanelType.Main }) end function SevenDayCarnivalPanelV2:OnSortingOrderChange() for i, v in pairs(itemList) do for j = 1, #v do v[j]:SetEffectLayer(self.sortingOrder) end end Util.AddParticleSortLayer(Util.GetGameObject(self.transform, "bg/effect"), self.sortingOrder-sorting) sorting=self.sortingOrder end function this.RefreshRedPoint() for i = 1, #dayBtn do if i > currentDay then Util.GetGameObject(dayBtn[i], "redPoint"):SetActive(false) else local redPoint = SevenDayCarnivalManager.GetDayNumberRedPointStatus(i) Util.GetGameObject(dayBtn[i], "redPoint"):SetActive(redPoint) end end end function SevenDayCarnivalPanelV2:OnClosePanelFun() self:ClosePanel() end function this.ShowTime() local downTime = 0 local SevenDayCarnivalData = ActivityGiftManager.GetActivityTypeInfo(ActivityTypeDef.SevenDayCarnival) if SevenDayCarnivalData then downTime = SevenDayCarnivalData.endTime - GetTimeStamp() end this.RemainTimeDown(this.timeTextExpertgo,this.timeTextExpert,downTime) end function this.RemainTimeDown(_timeTextExpertgo,_timeTextExpert,timeDown) if timeDown > 0 then if _timeTextExpertgo then _timeTextExpertgo:SetActive(true) end if _timeTextExpert then _timeTextExpert.text = Language[10023]..PatFaceManager.TimeStampToDateString(timeDown) end if this.timer then this.timer:Stop() this.timer = nil end this.timer = Timer.New(function() if _timeTextExpert then _timeTextExpert.text = Language[10023]..PatFaceManager.TimeStampToDateString(timeDown) end if timeDown < 0 then if _timeTextExpertgo then _timeTextExpertgo:SetActive(false) end this.timer:Stop() this.timer = nil end timeDown = timeDown - 1 end, 1, -1, true) this.timer:Start() else if _timeTextExpertgo then _timeTextExpertgo:SetActive(false) end end end --消息刷新 function this.RefreshTaskShow() this.OnClickTabBtn(curIndex,false,false) this.ShowTitleProgressRewardData() this.DownTabBtnRedPointShow() this.RefreshRedPoint() if SevenDayCarnivalManager.RefreshNextDayData(currentDay) then --跨天 currentDay = SevenDayCarnivalManager.GetCurrentDayNumber() this.OnDayClickBtn(curDayIndex) this.ShowTitleDayBtnsData() this.ShowTitleProgressRewardData() this.ShowTime() this.RefreshRedPoint() end end function this.CreateTabData() _TabData = {} for i = 1, #allTaskListConfigDtata do if allTaskListConfigDtata[i].DayNum == curDayIndex then if not _TabData[allTaskListConfigDtata[i].SheetId] then table.insert(_TabData,{ default = "UI_hz_gonghui_3"..allTaskListConfigDtata[i].SheetId, select = "UI_hz_gonghui_3"..allTaskListConfigDtata[i].SheetId, name =GetLanguageStrById(allTaskListConfigDtata[i].SheetName)}) end end end --必有此页签 写死 table.insert(_TabData,{ default = "UI_hz_gonghui_34", select = "UI_hz_gonghui_34", name = Language[11882] }) this.TabCtrl:SetTabAdapter(this.TabAdapter) this.TabCtrl:SetChangeTabCallBack(this.SwitchView) this.TabCtrl:Init(this.tabBox, _TabData,curIndex) tabBoxRedPoint = {} for i = 1, #_TabData do local curTabBtn = Util.GetGameObject(this.tabBox, "box").transform:GetChild(i-1) tabBoxRedPoint[i] = Util.GetGameObject(curTabBtn, "Redpot") end end --显示上边七天按钮 function this.ShowTitleDayBtnsData() for i = 1, 7 do local icon if i == 7 then icon = Util.GetGameObject(dayBtn[i], "iconMask/icon"):GetComponent("Image") else icon = Util.GetGameObject(dayBtn[i], "icon"):GetComponent("Image") end icon.sprite = this.spLoader:LoadSprite(GetResourcePath(ConfigManager.GetConfigData(ConfigName.SevenDaysActivity,i).ShowIcon)) Util.GetGameObject(dayBtn[i], "Text"):GetComponent("Text").text = Language[10262].. i ..Language[10017] if i <= currentDay then Util.SetGray(dayBtn[i], false) else Util.SetGray(dayBtn[i], true) end end end --显示上边积分奖励 function this.ShowTitleProgressRewardData() local curNum = 0 local maxNum = 0 allRewardTaskList = {} local curAllTaskListConfigDtata = ConfigManager.GetAllConfigsDataByKey(ConfigName.TreasureTaskConfig,"ActivityId",ActivityTypeDef.SevenDayCarnival) for i = 1, #curAllTaskListConfigDtata do if curAllTaskListConfigDtata[i].TaskType == 38 then--积分 table.insert(allRewardTaskList,curAllTaskListConfigDtata[i]) end end for i = 1, #rewardBtn do if allRewardTaskList[i] then if maxNum < allRewardTaskList[i].TaskValue[2][1] then maxNum = allRewardTaskList[i].TaskValue[2][1] end local curProgressData = curServerTaskList[allRewardTaskList[i].Id] if curProgressData then if curNum < curProgressData.progress then curNum = curProgressData.progress end Util.GetGameObject(rewardBtn[i], "redPoint"):SetActive(curProgressData.state == 1) Util.GetGameObject(rewardBtn[i], "Text"):GetComponent("Text").text = allRewardTaskList[i].TaskValue[2][1] Util.GetGameObject(rewardBtn[i], "getFinish"):SetActive(curProgressData.state == 2) Util.AddOnceClick(rewardBtn[i], function() if curProgressData.state == 0 then --PopupTipPanel.ShowTip("完成任务数量不足") UIManager.OpenPanel(UIName.BoxRewardShowPopup,allRewardTaskList[i].Reward,rewardBtn[i].transform.localPosition.x,rewardBtn[i].transform.localPosition.y,allRewardTaskList[i].TaskValue[2][1] .. Language[11883]) return end if curProgressData.state == 2 then PopupTipPanel.ShowTip(Language[10101]) return end NetManager.TakeMissionRewardRequest(TaskTypeDef.SevenDayCarnival, curProgressData.missionId, function(respond) UIManager.OpenPanel(UIName.RewardItemPopup, respond.drop, 1,function () this.OnClickTabBtn(curIndex,false,false) this.ShowTitleProgressRewardData() this.DownTabBtnRedPointShow() this.RefreshRedPoint() end) end) end) end end end this.progressImage.fillAmount = curNum/maxNum this.progressText.text = curNum end function this.OnDayClickBtn(_curDayIndex) if _curDayIndex > currentDay then PopupTipPanel.ShowTip(Language[11884]) return end if SevenDayCarnivalManager.GetSevenDayHalfPriceRedPoint(_curDayIndex) then local activityId = ActivityGiftManager.IsActivityTypeOpen(ActivityTypeDef.SevenDayCarnival) PlayerPrefs.SetInt(PlayerManager.uid .. "_SevenDay" .. "_" .. activityId .. "_" .. _curDayIndex, 1) end allTaskListConfigDtata = ConfigManager.GetAllConfigsDataByDoubleKey(ConfigName.TreasureTaskConfig,"ActivityId",ActivityTypeDef.SevenDayCarnival,"DayNum",_curDayIndex) curDayIndex = _curDayIndex curIndex = 1 if curDayIndex ~= 7 then this.dayBtnSelect.transform:SetParent(Util.GetGameObject(dayBtn[curDayIndex], "selectedParent").transform) this.dayBtnSelect.transform.localPosition = Vector3.zero else this.dayBtnSelect2.transform:SetParent(Util.GetGameObject(dayBtn[curDayIndex], "selectedParent").transform) this.dayBtnSelect2.transform.localPosition = Vector3.zero end this.dayBtnSelect:SetActive(curDayIndex ~= 7) this.dayBtnSelect2:SetActive(curDayIndex == 7) this.OnClickTabBtn(curIndex,false,false) this.CreateTabData() this.DownTabBtnRedPointShow() end -- tab节点显示自定义 function this.TabAdapter(tab, index, status) local tabLab = Util.GetGameObject(tab, "Text") local tabImage = Util.GetGameObject(tab,"Image") local select = Util.GetGameObject(tab,"select") select:SetActive(status=="select") tabImage:GetComponent("Image").sprite = this.spLoader:LoadSprite(_TabData[index][status]) tabLab:GetComponent("Text").text = GetCurLanguage() ~= 2 and _TabData[index].name or "".._TabData[index].name..""-- = _TabData[index].name tabLab:GetComponent("Text").color = _TabFontColor[status] end --切换视图 function this.SwitchView(index) this.OnClickTabBtn(index,true,true) end local sortTable = { [0] = 2, [1] = 1, [2] = 3 } function this.DownTabBtnRedPointShow() local redPointState = {} allTaskListConfigDtata = ConfigManager.GetAllConfigsDataByDoubleKey(ConfigName.TreasureTaskConfig,"ActivityId",ActivityTypeDef.SevenDayCarnival,"DayNum",curDayIndex) serverTaskList = TaskManager.GetTypeTaskList(TaskTypeDef.SevenDayCarnival) for i = 1, #serverTaskList do --普通的任务 if treasureTaskConfig[serverTaskList[i].missionId] and treasureTaskConfig[serverTaskList[i].missionId].SheetId then local SheetId = treasureTaskConfig[serverTaskList[i].missionId].SheetId if curDayIndex == treasureTaskConfig[serverTaskList[i].missionId].DayNum then if not redPointState[SheetId] then redPointState[SheetId] = serverTaskList[i].state == 1 end end end end redPointState[4] = SevenDayCarnivalManager.GetSevenDayCarnivalRedPoint2(curDayIndex)--半价 for i = 1, #tabBoxRedPoint do tabBoxRedPoint[i].gameObject:SetActive(redPointState[i]) end end --下方页签选择 function this.OnClickTabBtn(_curIndex,isTop,isAni) serverTaskList = TaskManager.GetTypeTaskList(TaskTypeDef.SevenDayCarnival) curIndex = _curIndex curTaskListConfigDtata = {} curServerTaskList = {} for i = 1, #allTaskListConfigDtata do if allTaskListConfigDtata[i].SheetId == curIndex then table.insert(curTaskListConfigDtata,allTaskListConfigDtata[i]) end end for i = 1, #serverTaskList do --普通的任务 if treasureTaskConfig[serverTaskList[i].missionId] and treasureTaskConfig[serverTaskList[i].missionId].SheetId then if treasureTaskConfig[serverTaskList[i].missionId].SheetId == curIndex then curServerTaskList[serverTaskList[i].missionId] = serverTaskList[i] end end --积分的任务 if treasureTaskConfig[serverTaskList[i].missionId].TaskType == 38 then curServerTaskList[serverTaskList[i].missionId] = serverTaskList[i] end end if _curIndex ~= 4 then table.sort(curTaskListConfigDtata, function(a, b) if sortTable[curServerTaskList[a.Id].state] == sortTable[curServerTaskList[b.Id].state] then return a.Id < b.Id else return sortTable[curServerTaskList[a.Id].state] < sortTable[curServerTaskList[b.Id].state] end end) this.ScrollView:SetData(curTaskListConfigDtata, function (index, go) this.SingleItemDataShow(go, curTaskListConfigDtata[index]) end,not isTop,not isAni) else-- 4 半价购买 curShopData = ConfigManager.TryGetConfigDataByDoubleKey(ConfigName.StoreTypeConfig,"StoreType",SHOP_TYPE.SEVENDAY_CARNIVAL_SHOP,"Sort",curDayIndex) if curShopData then shopInfoList = ShopManager.GetShopDataByShopId(curShopData.Id) end if shopInfoList then --self.storeConfig = ConfigManager.GetConfigData(ConfigName.StoreConfig,shopInfoList.storeItem[self.mainPanel.selectDayTab].id) --local goods = ShopManager.GetShopItemGoodsInfo(self.storeConfig.Id) this.ScrollView:SetData(shopInfoList.storeItem, function (index, go) this.SingleItemDataShow2(go, shopInfoList.storeItem[index],curShopData.Id) end,not isTop,not isAni) end end end --半价购买 function this.SingleItemDataShow2(go, data,curShopDataId) local storeConfig = ConfigManager.GetConfigData(ConfigName.StoreConfig,data.id) if not storeConfig then return end if not itemList[go.name] then itemList[go.name] = {} end for i = 1, #itemList[go.name] do itemList[go.name][i].gameObject:SetActive(false) end for i = 1, #storeConfig.Goods do if itemList[go.name][i] then itemList[go.name][i]:OnOpen(false, storeConfig.Goods[i], 0.8,false,false,false,sorting) else itemList[go.name][i] = SubUIManager.Open(SubUIConfig.ItemView, Util.GetGameObject(go, "itemContent").transform) itemList[go.name][i]:OnOpen(false, storeConfig.Goods[i], 0.8,false,false,false,sorting) end itemList[go.name][i].gameObject:SetActive(true) end Util.GetGameObject(go, "desc"):GetComponent("Text").text = GetLanguageStrById(storeConfig.GoodsName) Util.GetGameObject(go, "current/buyBtn"):SetActive(true) Util.GetGameObject(go, "current/dealBtn"):SetActive(false) Util.GetGameObject(go, "current/jumpBtn"):SetActive(false) Util.GetGameObject(go, "current/progress"):SetActive(false) --Util.GetGameObject(go, "current/finished"):SetActive(false) Util.GetGameObject(go, "current/buyBtn/progress"):SetActive(storeConfig.IsDiscount > 0) local item,num,oldNum = ShopManager.CalculateCostCountByShopId(curShopDataId, data.id, 1) Util.GetGameObject(go, "current/buyBtn/progress"):GetComponent("Text").text = oldNum local finished = Util.GetGameObject(go, "current/finished") finished:SetActive(not ((storeConfig.Limit - data.buyNum) > 0)) Util.SetGray(finished,not ((storeConfig.Limit - data.buyNum) > 0)) Util.GetGameObject(finished, "Text"):GetComponent("Text").text = Language[10514] Util.GetGameObject(go, "current/buyBtn/icon"):GetComponent("Image").sprite = this.spLoader:LoadSprite(GetResourcePath(ConfigManager.GetConfigData(ConfigName.ItemConfig,item).ResourceID)) Util.GetGameObject(go, "current/buyBtn/progress/icon"):GetComponent("Image").sprite = this.spLoader:LoadSprite(GetResourcePath(ConfigManager.GetConfigData(ConfigName.ItemConfig,item).ResourceID)) local buyBtn = Util.GetGameObject(go, "current/buyBtn") Util.GetGameObject(buyBtn, "Text"):GetComponent("Text").text = num Util.GetGameObject(buyBtn, "redPoint"):SetActive(num <= 0) buyBtn:SetActive((storeConfig.Limit - data.buyNum) > 0) Util.AddOnceClick(buyBtn, function() if BagManager.GetItemCountById(item) >= num then ShopManager.RequestBuyItemByShopId(curShopDataId, storeConfig.Id, 1, function () this.OnClickTabBtn(curIndex,false,false) this.ShowTitleProgressRewardData() this.DownTabBtnRedPointShow() this.RefreshRedPoint() end ) else PopupTipPanel.ShowTip(GetLanguageStrById(ConfigManager.GetConfigData(ConfigName.ItemConfig,item).Name)..Language[10657]) --UIManager.OpenPanel(UIName.QuickPurchasePanel,{ type = item }) end end) end function this.SingleItemDataShow(go, data) if not data or not curServerTaskList[data.Id] then return end local curServerTask = curServerTaskList[data.Id] if not itemList[go.name] then itemList[go.name] = {} end for i = 1, #itemList[go.name] do itemList[go.name][i].gameObject:SetActive(false) end for i = 1, #data.Reward do if itemList[go.name][i] then itemList[go.name][i]:OnOpen(false, data.Reward[i], 0.8,false,false,false,sorting) else itemList[go.name][i] = SubUIManager.Open(SubUIConfig.ItemView, Util.GetGameObject(go, "itemContent").transform) itemList[go.name][i]:OnOpen(false, data.Reward[i], 0.8,false,false,false,sorting) end itemList[go.name][i].gameObject:SetActive(true) end Util.GetGameObject(go, "desc"):GetComponent("Text").text = GetLanguageStrById(data.Show) Util.GetGameObject(go, "current/progress"):GetComponent("Text").text = "("..curServerTask.progress .."/"..data.TaskValue[2][1]..")" local dealBtn = Util.GetGameObject(go, "current/dealBtn") local jumpBtn = Util.GetGameObject(go, "current/jumpBtn") --state = 3; //0:未完成 1:完成未领取 2:已达成(已领取) dealBtn:SetActive(curServerTask.state == 1) --Util.GetGameObject(go, "current/redPoint"):SetActive(curServerTask.state == 1) local finished = Util.GetGameObject(go, "current/finished") finished:SetActive(curServerTask.state == 2) Util.SetGray(finished,curServerTask.state == 2) Util.GetGameObject(finished, "Text"):GetComponent("Text").text = Language[10101] Util.GetGameObject(go, "current/buyBtn"):SetActive(false) Util.GetGameObject(go, "current/progress"):SetActive(not curServerTask.state == 2) Util.AddOnceClick(dealBtn, function() NetManager.TakeMissionRewardRequest(TaskTypeDef.SevenDayCarnival, curServerTask.missionId, function(respond) UIManager.OpenPanel(UIName.RewardItemPopup, respond.drop, 1) end) end) -- 判断是否需要跳转 if curServerTask.state == 0 then jumpBtn:SetActive(true) local isJump = data.Jump and data.Jump[1] and data.Jump[1] ~= 0 local btnText = Util.GetGameObject(jumpBtn, "Text"):GetComponent("Text") btnText.fontSize = GetCurLanguage() ~= 2 and 45 or 30 btnText.text = isJump and Language[10019] or Language[10317] Util.SetGray(jumpBtn, not isJump) Util.AddOnceClick(jumpBtn, function() if isJump then JumpManager.GoJump(data.Jump[1]) end end) else jumpBtn:SetActive(false) end end --界面关闭时调用(用于子类重写) function SevenDayCarnivalPanelV2:OnClose() if this.timer then this.timer:Stop() this.timer = nil end end --界面销毁时调用(用于子类重写) function SevenDayCarnivalPanelV2:OnDestroy() this.spLoader:Destroy() if this.timer then this.timer:Stop() this.timer = nil end itemList = {} end return SevenDayCarnivalPanelV2