local UINewYearExchange = UIViewClass() local ExchangeType = { Guild = false, Friend = true, } function UINewYearExchange:OnOpened(context) self.activityId = context.activityId self.activityType = MDL.OperationActivity.ActivityType.NewYear self.modeData = MDL.OperationActivity.ActivityBaseData[self.activityType]:GetDataByActivityID(self.activityId) self.dailyExchangeNum = self.modeData.LuckyBagItemDailyNum self:RegistSystemEvent(EventID.UI_NewYear_OthersExchangeInfoRefresh, self.RefreshExchangeList) self:RegistSystemEvent(EventID.UI_NewYear_ExchangeNumRefresh, self.RefreshExchangeNum) self:RegistSystemEvent(EventID.UI_NewYear_RefreshRp, self.SetButtonRedPoint) self:RegistSystemEvent(EventID.BagItem_Update, self.RefreshPrayItem) self:RefreshPrayItem() self:RefreshExchangeNum() self:SetButtonRedPoint() self.group_Tab:SelectIndex(context.type and context.type or 0) end function UINewYearExchange:SetButtonRedPoint() self.btn_Init:SetRedPoint(CTL.NewYear.IsShowActivityRedPoint(self.activityId)) end function UINewYearExchange:RefreshExchangeNum() local num = self.dailyExchangeNum - MDL.NewYear.GetExchangeNum(self.activityId) self.isCanExchange = num > 0 num = self.isCanExchange and num or UTL.Color.FormatRedColor(num) self.txt_ExchangeNum.text = string.FormatByIdsKey("IDS_NewYearActivity_LuckyBagExchangeMainHint_3", num, self.dailyExchangeNum) end function UINewYearExchange:RefreshExchangeList(activityId, type, info) if activityId == self.activityId then if type == self.type then self.info = info if self.loop_ExchangeList.Count > 0 then self.loop_ExchangeList:ClearCells() end for i, v in ipairs(info) do if not self.filterSelect or self.filterSelect == v.exchangeInfo.itemId then self.loop_ExchangeList:AddData(v, 0) end end end UIUtils.SetActive(self.group_Empty, self.loop_ExchangeList.Count == 0) if self.type == ExchangeType.Friend then self.state_Empty:SetState(2) elseif self.type == ExchangeType.Guild then self.state_Empty:SetState(MDL.Guild.IsHasGuild() and 0 or 1) end end end function UINewYearExchange:RefreshPrayItem() if self.loop_PrayItem.Count > 0 then self.loop_PrayItem:RefreshCells() else local modeData = MDL.OperationActivity.ActivityBaseData[self.activityType]:GetDataByActivityID(self.activityId) for i, v in ipairs(modeData.LuckyBagItem) do self.loop_PrayItem:AddData(v, 0) end end end function UINewYearExchange:OnValueChanged(comp, value) if comp == self.group_Tab then if value == 0 then self.type = ExchangeType.Guild self.state_Tab:SetState(0) elseif value == 1 then self.type = ExchangeType.Friend self.state_Tab:SetState(1) end MDL.NewYear.NewYearGetOtherExchangeInfoReq(self.activityId, self.type) self.context.type = self.type end end function UINewYearExchange:OnBackButtonPressed() self:OnButtonClicked(self.btn_Close) end function UINewYearExchange:OnButtonClicked(comp) if comp == self.btn_Close then self:CloseView() elseif comp == self.btn_Refresh then MDL.NewYear.NewYearGetOtherExchangeInfoReq(self.activityId, self.type) elseif comp == self.btn_MyList then CTL.NewYear.OpenView(self.activityId, CTL.NewYear.ViewName.UINewYearPrayMyExchange, {activityId = self.activityId}) elseif comp == self.btn_Init then if self.isCanExchange then CTL.NewYear.OpenView(self.activityId, CTL.NewYear.ViewName.UINewYearExchangeInitiate, {activityId = self.activityId}) else CTL.Tips.AddTipsMsg(Const_IDS.IDS_NewYearActivity_LuckyBagExchangeMainHint_6) end end end function UINewYearExchange:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.loop_PrayItem then local hasCount = UTL.Item.GetItemStockCount(data) UTL.Item.SetItemCell(cellTable.Item, data, hasCount > 0 and hasCount or UTL.Color.FormatRedColor(hasCount)) UIUtils.SetActive(cellTable.img_Select, data == self.filterSelect) elseif scrollRect == self.loop_ExchangeList then CTL.Character.SetPortraitAndFrame(cellTable.UIHeroHead150, data.portraitId, data.frameId, data.level) cellTable.txt_Name.text = data.name UTL.Item.SetItemCell(cellTable.item_Give, data.exchangeInfo.itemId, 1) UTL.Item.SetItemCell(cellTable.item_Need, data.exchangeInfo.targetItemId, 1) end end function UINewYearExchange:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.loop_PrayItem then if target == cellTable.Item.event_Click then if self.filterSelect == data then self.filterSelect = nil else self.filterSelect = data end UIUtils.SetActive(cellTable.img_Select, data == self.filterSelect) if self.filterIndex then self.loop_PrayItem:UpdateIndex(self.filterIndex) end self.filterIndex = index self:RefreshExchangeList(self.activityId, self.type, self.info) --UTL.ItemTips.ShowCommonTipsById(data) end elseif scrollRect == self.loop_ExchangeList then if target == cellTable.btn_Exchange then if self.isCanExchange then if UTL.Item.GetItemStockCount(data.exchangeInfo.targetItemId) > 0 then CTL.NewYear.OpenView(self.activityId, CTL.NewYear.ViewName.UINewYearExchangeConfirm, {activityId = self.activityId, data = data, type = self.type}) else CTL.Tips.AddTipsMsg(Const_IDS.IDS_NewYearActivity_LuckyBagExchangeMainHint_7) end else CTL.Tips.AddTipsMsg(Const_IDS.IDS_NewYearActivity_LuckyBagExchangeMainHint_6) end elseif target == cellTable.UIHeroHead150.img_PlayerAvatarBg then CTL.PlayerInteract.OpenFriendInteractView(data.acid) elseif target == cellTable.item_Give.event_Click then UTL.ItemTips.ShowCommonTipsById(data.exchangeInfo.itemId) elseif target == cellTable.item_Need.event_Click then UTL.ItemTips.ShowCommonTipsById(data.exchangeInfo.targetItemId) end end end return UINewYearExchange