local UICommandTheWorldWindow = UIViewClass() local EventSystem = require('Event/EventSystem') local private ={} --兑换商城Tab ids private.StoreTabData ={} --排行奖励 tab ids private.RankTabData ={ [1] = {id = 1 , ids = Const_IDS.IDS_MyServer}, [2] = {id = 2 , ids = Const_IDS.IDS_BattlefieldMuster_WarZone}, } --region 生命周期方法 function UICommandTheWorldWindow:OnOpened(context) self:RegistSystemEvent(EventID.UI_CommandTheWorld_SingleRankOver, self.ForceClose) --单服排行结束,需关闭界面,防止重复领奖 UIManager.ActiveUIModle(false, "UICommandTheWorldWindow") self.popWindowType = context.popWindowType if self.popWindowType == CTL.CommandTheWorld.PopWindowType.Store then private.InitStoreTabData() end self:InitData() end function UICommandTheWorldWindow:ForceClose() CTL.Tips.AddTipsMsg(Const_IDS.IDS_BattlefieldMuster_Box_Single) self:CloseView() end function UICommandTheWorldWindow:OnBackButtonPressed() self:OnButtonClicked(self.btn_Close) end function UICommandTheWorldWindow:OnButtonClicked(comp) if comp == self.btn_Close then self:CloseView() end end function private.InitStoreTabData() private.StoreTabData = {} local storeData= MDL.CommandTheWorld.GetCommandWorldStore() for i, v in ipairs(storeData) do if v.StoreID > 0 then local storeTypeName = MDL.Shop.GetStoreTypeTabName(v.StoreID) if storeTypeName then local data = {id = i,ids = Const_IDS[storeTypeName]} table.insert(private.StoreTabData,data) end end end end function UICommandTheWorldWindow:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.loop_LeftTab then UIUtils.SetLabelText(cellTable.txt_SelectedTabName,data.ids) UIUtils.SetLabelText(cellTable.txt_UnselectedTabName,data.ids) UIUtils.SetLabelText(cellTable.txt_UnselectedTime,data.ids) if self.popWindowType == CTL.CommandTheWorld.PopWindowType.Store then UIUtils.SetActive(cellTable.txt_UnselectedTime,false) UIUtils.SetActive(cellTable.txt_SelectedTime,false) UIUtils.SetActive(cellTable.img_RedPoint,false) elseif self.popWindowType == CTL.CommandTheWorld.PopWindowType.Rank then UIUtils.SetActive(cellTable.txt_UnselectedTime,true) UIUtils.SetActive(cellTable.txt_SelectedTime,true) UIUtils.SetActive(cellTable.img_RedPoint,false) if index == 0 then UIUtils.SetLabel(cellTable.txt_UnselectedTime,self.remainTimeStr1) UIUtils.SetLabel(cellTable.txt_SelectedTime,self.remainTimeStr1) else UIUtils.SetLabel(cellTable.txt_UnselectedTime,self.remainTimeStr2) UIUtils.SetLabel(cellTable.txt_SelectedTime,self.remainTimeStr2) end end end end function UICommandTheWorldWindow:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.loop_LeftTab then --排行奖励界面,若点击的战区排行,判断一下 if self.popWindowType == CTL.CommandTheWorld.PopWindowType.Rank then --若是战区排行,判断是否开启了 if (index+1) == private.RankTabData[2].id and CTL.CommandTheWorld.IsBeforeBattleAreaOpen() then CTL.Tips.AddTipsMsg(Const_IDS.IDS_BattlefieldMuster_Unopened) self.loop_LeftTab:SelectIndex(0) return end end self:OpenSubView(data.id) end end function UICommandTheWorldWindow:OnClosed() self.subView:CloseAll() UIManager.ActiveUIModle(true, "UICommandTheWorldWindow") end --endregion function UICommandTheWorldWindow:InitData() --设置数据 if self.popWindowType == CTL.CommandTheWorld.PopWindowType.Store then --兑换商城 UIUtils.SetActive(self.loop_LeftTab,true) UIUtils.SetActive(self.img_LfetLine,true) for i,v in ipairs(private.StoreTabData) do self.loop_LeftTab:AddData(v, 0) end self.loop_LeftTab:SelectIndex(0) elseif self.popWindowType == CTL.CommandTheWorld.PopWindowType.Reward then --势力宝箱界面 UIUtils.SetActive(self.loop_LeftTab,false) UIUtils.SetActive(self.img_LfetLine,false) self:OpenSubView(self.popWindowType) elseif self.popWindowType == CTL.CommandTheWorld.PopWindowType.Rank then --排行奖励界面 UIUtils.SetActive(self.loop_LeftTab,true) UIUtils.SetActive(self.img_LfetLine,true) if MDL.CommandTheWorld.IsSingleSerActivity() then self.loop_LeftTab:AddData(private.RankTabData[1], 0) else for i,v in ipairs(private.RankTabData) do self.loop_LeftTab:AddData(v, 0) end end local index = 1 --本服没结束或是战区没开始的时候就选中本服排行,否则选中战区 if CTL.CommandTheWorld.IsLocalServerOpen() then index = MDL.CommandTheWorld.CommandWorldType.LocalRank elseif CTL.CommandTheWorld.IsBattleAreaOpen() then index = MDL.CommandTheWorld.CommandWorldType.CrossRank elseif CTL.CommandTheWorld.IsBalanceWait() or CTL.CommandTheWorld.IsHonorRankStage() then index = MDL.CommandTheWorld.CommandWorldType.CrossRank else index = MDL.CommandTheWorld.CommandWorldType.LocalRank end self.loop_LeftTab:SelectIndex(index - 1) self.currentIndex = index - 1 -- 本服和跨服数据都更新一下 MDL.CommandTheWorld.SendRankReq(MDL.CommandTheWorld.CommandWorldType.LocalRank) MDL.CommandTheWorld.SendRankReq(MDL.CommandTheWorld.CommandWorldType.CrossRank) --定时刷新活动时间 self:StartRepeatFunc(self.RefreshActivityTime, 1, -1) self:RefreshActivityTime() end end function UICommandTheWorldWindow:OpenSubView(tabId) if self.view == nil then self.view = CTL.CommandTheWorld.OpenSubView(self.popWindowType,self.subView,tabId) elseif self.popWindowType == CTL.CommandTheWorld.PopWindowType.Store then EventSystem.Dispatch(EventID.UI_OACommon_StoreRefresh,tabId) --刷新商场 elseif self.popWindowType == CTL.CommandTheWorld.PopWindowType.Rank then EventSystem.Dispatch(EventID.UI_CommandTheWorld_RefreshRankReward,tabId) --刷新排行奖励 end end --刷新活动的剩余时间 function UICommandTheWorldWindow:RefreshActivityTime() --本服开启后的剩余时间 if CTL.CommandTheWorld.IsLocalServerOpen() then local remainTimeStr = "" local remainTime = CTL.CommandTheWorld.GetRemainTimeOfLocalServer() --已结束 显示红字,否则显示倒计时 if remainTime > 0 then remainTimeStr = UTL.Time.FormatTimeForDayOrClock(remainTime) remainTimeStr = string.format(UIUtils.GetLocalizedTxt(Const_IDS.IDS_BattlefieldMuster_CloseTime),remainTimeStr) end self.remainTimeStr1 = remainTimeStr self.loop_LeftTab:UpdateIndex(0) else self.remainTimeStr1 = UTL.Color.FormatRedColor(UIUtils.GetLocalizedTxt(Const_IDS["IDS_ActivityItem_End"])) self.loop_LeftTab:UpdateIndex(0) end if CTL.CommandTheWorld.IsBeforeBattleAreaOpen() then --战区排行没打开的时候 -- 显示X月Y日开启 local openTime = CTL.CommandTheWorld.GetBattleAreaOpenTime() if GameAppInfo.IsVietnamPackage() then self.remainTimeStr2 = string.FormatByIdsId(Const_IDS.IDS_BattlefieldMuster_OpenTime, UTL.Time.OsDateOriginal("%d", openTime), UTL.Time.OsDateOriginal("%m", openTime)) else self.remainTimeStr2 = string.FormatByIdsId(Const_IDS.IDS_BattlefieldMuster_OpenTime,UTL.Time.FormatTimeSimple(openTime)) end self.loop_LeftTab:UpdateIndex(1) elseif CTL.CommandTheWorld.IsBattleAreaOpen() then --战区排行 开启状态 local remainTimeStr = "" local remainTime = CTL.CommandTheWorld.GetRemainTimeOfBattleServer() --已结束 显示红字,否则显示倒计时 if remainTime > 0 then remainTimeStr = UTL.Time.FormatTimeForDayOrClock(remainTime) remainTimeStr = string.format(UIUtils.GetLocalizedTxt(Const_IDS.IDS_BattlefieldMuster_CloseTime),remainTimeStr) end self.remainTimeStr2 = remainTimeStr self.loop_LeftTab:UpdateIndex(1) else self.remainTimeStr2 = UTL.Color.FormatRedColor(UIUtils.GetLocalizedTxt(Const_IDS["IDS_ActivityItem_End"])) self.loop_LeftTab:UpdateIndex(1) self:StopRepeatFunc(self.RefreshActivityTime) end end return UICommandTheWorldWindow