local UILuckyLotteryFriendPopUp = UIViewClass() local SelectType = { Give = 0, Receive = 1, } local OfflineColor = "8891a4" function UILuckyLotteryFriendPopUp:OnOpened(context) self.activityId = context.activityId self:RegistSystemEvent(EventID.UI_UpdateFriendInfo, self.RefreshFriendList) self:RegistSystemEvent(EventID.UI_LuckyLottery_FriendUpdate, self.RefreshReceiveList) self:RegistSystemEvent(EventID.BagItem_Update, self.RefreshLoop) local modeData = MDL.OperationActivity.LuckyLotteryModeData:GetDataByActivityID(self.activityId) self.luckyStarItemId = modeData.LuckyStarItemID self.friendLotteryItemId = modeData.FriendLotteryItemID self.loop_LuckyLotteryList:AddData({title = "IDS_LuckyLottery_LuckyBoxHint_2"}, 0) self.loop_LuckyLotteryList:AddData({title = "IDS_LuckyLottery_LuckyBoxHint_1"}, 0) self.isInit = true MDL.LuckyLottery.ActivityLuckyLotteryBoxOpenReq(self.activityId) end function UILuckyLotteryFriendPopUp:RefreshLoop() self.loop_LuckyLotteryList:RefreshCells() end function UILuckyLotteryFriendPopUp:RefreshReceiveList(activityId, receiveList) if activityId == self.activityId then if not self.selectType and self.isInit and #receiveList == 0 then self.loop_LuckyLotteryList:SelectIndex(SelectType.Give) return end self.loop_LuckyLotteryList:SelectIndex(SelectType.Receive) if self.loop_Friend.Count > 0 then self.loop_Friend:ClearCells() end for i, v in ipairs(receiveList) do self.loop_Friend:AddData(v, 1) end self.state_Empty:SetState(1) UIUtils.SetActive(self.group_Empty, self.loop_Friend.Count == 0) UIUtils.SetActive(self.btn_Get, self.loop_Friend.Count > 0) self.btn_Get:SetRedPoint(true) end end function UILuckyLotteryFriendPopUp:RefreshFriendList() if self.selectType == SelectType.Give then if self.loop_Friend.Count > 0 then self.loop_Friend:ClearCells() end for i, v in ipairs(MDL.Friend.GetSortedList(MDL.Friend.ListType.Friend)) do self.loop_Friend:AddData(v, 0) end self.state_Empty:SetState(0) UIUtils.SetActive(self.group_Empty, self.loop_Friend.Count == 0) UIUtils.SetActive(self.btn_Get, false) end end function UILuckyLotteryFriendPopUp:OnButtonClicked(comp) if comp == self.btn_Close then self:CloseView() elseif comp == self.btn_Get then --一键领取,index传0即为一键领取 MDL.LuckyLottery.ActivityLuckyLotteryGetPresentReq(self.activityId, 0) end end function UILuckyLotteryFriendPopUp:OnBackButtonPressed() self:OnButtonClicked(self.btn_Close) end function UILuckyLotteryFriendPopUp:OnCellSelect(scrollRect, index, cellTable, data) if scrollRect == self.loop_LuckyLotteryList then self.selectType = index if self.selectType == SelectType.Give then self:RefreshFriendList() elseif self.selectType == SelectType.Receive then if self.isInit then self.isInit = false else MDL.LuckyLottery.ActivityLuckyLotteryBoxOpenReq(self.activityId) end end self.isInit = false end end function UILuckyLotteryFriendPopUp:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.loop_LuckyLotteryList then UIUtils.SetLabelText(cellTable.lab_UnSelected, Const_IDS[data.title]) UIUtils.SetLabelText(cellTable.lab_Selected, Const_IDS[data.title]) elseif scrollRect == self.loop_Friend then if self.selectType == SelectType.Give then CTL.Character.SetPortraitAndFrame(cellTable.HeroHead, data.portraitId, data.frameId, data.level) cellTable.txt_Name.text = data.name if data.isOnline then local str = UTL.Color.FormatGreenColor(UIUtils.GetLocalizedTxt(Const_IDS.IDS_Friend_Online)) cellTable.txt_Online.text = str else local timeOffset = UTL.Time.GetServerTimestamp() - (data.logoutTime or data.lastOnlineTimestamp) local str = UTL.Color.FormatTextByColor(OfflineColor, UTL.Time.GetBeyondTime(timeOffset)) cellTable.txt_Online.text = str end UTL.Item.SetItemIcon(cellTable.img_Icon, self.luckyStarItemId) cellTable.txt_Num.text = UTL.Item.GetItemStockCount(self.luckyStarItemId) >= 1 and "x1" or UTL.Color.FormatRedColor("x1") elseif self.selectType == SelectType.Receive then CTL.Character.SetPortraitAndFrame(cellTable.HeroHead, data.PortraitId, data.FrameId, data.level) cellTable.txt_Name.text = data.name if data.isOnline then local str = UTL.Color.FormatGreenColor(UIUtils.GetLocalizedTxt(Const_IDS.IDS_Friend_Online)) cellTable.txt_Online.text = str else local timeOffset = UTL.Time.GetServerTimestamp() - (data.logoutTime or data.lastOnlineTimestamp) local str = UTL.Color.FormatTextByColor(OfflineColor, UTL.Time.GetBeyondTime(timeOffset)) cellTable.txt_Online.text = str end UTL.Item.SetItemIcon(cellTable.img_Icon, self.friendLotteryItemId) cellTable.btn_Receive:SetRedPoint(true) end end end function UILuckyLotteryFriendPopUp:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.loop_Friend then if target == cellTable.btn_Give then if UTL.Item.GetItemStockCount(self.luckyStarItemId) >= 1 then MDL.LuckyLottery.ActivityLuckyLotteryGivePresentReq(self.activityId, data.acid) else CTL.Tips.AddTipsMsg(Const_IDS.IDS_LuckyLottery_LuckyBoxHint_4) end elseif target == cellTable.btn_Receive then MDL.LuckyLottery.ActivityLuckyLotteryGetPresentReq(self.activityId, index + 1) elseif target == cellTable.HeroHead.img_PlayerAvatarBg then CTL.PlayerInteract.OpenFriendInteractView(data.acid) end end end return UILuckyLotteryFriendPopUp