----- 公会红包-抢红包 ----- local this={} local sortingOrder=0 --红包资源名 local RedPacketName={"g_ghhb_ming_01_zh","g_ghhb_ming_02_zh","g_ghhb_ming_03_zh","g_ghhb_ming_04_zh"} --红包按钮状态图片 local BtnStateImage={"g_ghhb_qiang_zh","g_ghhb_lingqu_zh","g_ghhb_lingwan_zh"}--抢 已领取 已领完 local SpecialConfig=ConfigManager.GetConfigData(ConfigName.SpecialConfig,115) function this:InitComponent(gameObject) this.spLoader = SpriteLoader.New() this.group=Util.GetGameObject(gameObject,"Root/Group")--红包父节点 this.noInfo=Util.GetGameObject(gameObject,"NoInfo")--无红包提示 this.redPacketPre=Util.GetGameObject(gameObject,"ScrollRoot/RedPacketPre")--红包预设 this.scrollRoot=Util.GetGameObject(gameObject,"ScrollRoot") this.scrollView=SubUIManager.Open(SubUIConfig.ScrollCycleView,this.scrollRoot.transform,this.redPacketPre, nil, Vector2.New(this.scrollRoot.transform.rect.width,this.scrollRoot.transform.rect.height),1,2,Vector2.New(60,30)) this.scrollView.moveTween.MomentumAmount = 1 this.scrollView.moveTween.Strength = 2 end function this:BindEvent() end function this:AddListener() Game.GlobalEvent:AddEvent(GameEvent.GuildRedPacket.OnRefreshGetRedPacket, this.InitGetView) Game.GlobalEvent:AddEvent(GameEvent.GuildRedPacket.AuoGetRedPackage, this.AutoGetRedPackage) end function this:RemoveListener() Game.GlobalEvent:RemoveEvent(GameEvent.GuildRedPacket.OnRefreshGetRedPacket, this.InitGetView) Game.GlobalEvent:RemoveEvent(GameEvent.GuildRedPacket.AuoGetRedPackage, this.AutoGetRedPackage) end local isAuto=false --自动抢红包 function this:AutoGetRedPackage() isAuto=true end function this:OnShow(_sortingOrder) -- logWarnTrance("打开抢红包") sortingOrder=_sortingOrder this:InitGetView() end function this:OnClose() -- logWarnTrance("关闭抢红包") isAuto=false end function this:OnDestroy() this.spLoader:Destroy() this.scrollView=nil end --初始化抢红包面板 function this:InitGetView() local dataLength=0 isAuto=false NetManager.GetAllRedPacketResponse(function(msg) local data={} for i,v in ipairs(msg.info) do table.insert(data,v) end this:DataSort(data) dataLength=#msg.info this.noInfo:SetActive(dataLength==0) this.scrollView:SetData(data,function(index,root) this:SetView(root,data[index]) end,true,true) --this.scrollView:SetIndex(1) if isAuto then local SpecialConfig=ConfigManager.GetConfigData(ConfigName.SpecialConfig,115) for key, value in pairs(data) do local config=ConfigManager.GetConfigData(ConfigName.GuildRedPackConfig,value.redType) if value.isGet==0 and (config.Num-value.getCount)>0 and isAuto then if config.BaseType~=2 or PlayerManager.dailyRedPack< tonumber(SpecialConfig.Value) then isAuto=false NetManager.GetRobRedPackageRequest(value.redId,function(msg) local success=msg.isSuccess local itemId=msg.itemId local count=msg.count if success==1 then--红包抢成功 local itemName=GetLanguageStrById(ConfigManager.GetConfigData(ConfigName.ItemConfig,itemId).Name) UIManager.OpenPanel(UIName.RedPacketPopup,value.redId,value.redType,function () this.InitGetView() MyGuildManager.ReuqsetRedPackage() end) --红包类型大于3的是福利红包 if value.redType>3 then PlayerManager.SettDailyRedPackageTime(PlayerManager.dailyRedPack+1) end PopupTipPanel.ShowTip(string.format(Language[11046],itemName,count)) else--抢红包失败 LogError(Language[11047]) PopupTipPanel.ShowTip(Language[11047]) end end) return end end end end end) end function this:SetView(root,data) local nameImage=Util.GetGameObject(root,"NameImage"):GetComponent("Image")--红包名 local fromPlayer=Util.GetGameObject(root,"FromPlayer"):GetComponent("Text")--红包来自玩家名 local getBtn=Util.GetGameObject(root,"GetBtn")--抢红包按钮 local mask=Util.GetGameObject(root,"Mask"):GetComponent("Image")--红包遮罩 local getBtnImage=Util.GetGameObject(root,"GetBtn/Image"):GetComponent("Image")--按钮状态图片 local numOrRecordBtn=Util.GetGameObject(root,"NumOrRecord") local numOrRecordText=Util.GetGameObject(root,"NumOrRecord/Text"):GetComponent("Text")--剩余礼包数或查看记录 local getInfo=Util.GetGameObject(root,"GetInfo"):GetComponent("Text")--获取信息 local redId=data.redId local redType=data.redType if redType>3 then redType=4 end local config=ConfigManager.GetConfigData(ConfigName.GuildRedPackConfig,data.redType) if config.BaseType==1 then getInfo.gameObject:SetActive(false) else getInfo.gameObject:SetActive(true) getInfo.text=config.RuleDes end nameImage.sprite = this.spLoader:LoadSprite(RedPacketName[redType]) fromPlayer.text=Language[11042]..data.userName.."" getBtn:GetComponent("Button").interactable=(config.Num-data.getCount)~=0 and data.isGet==0 --抢红包按钮开关 numOrRecordBtn:GetComponent("Button").interactable=data.isGet==1 or (config.Num-data.getCount)==0 mask.enabled=data.isGet==1 or (config.Num-data.getCount)==0 --已领取或已领完 打开遮罩 mask.transform:SetSiblingIndex(2) if data.isGet==1 then numOrRecordText.text=Language[11043] getBtnImage.sprite=this.spLoader:LoadSprite(BtnStateImage[2]) --Language[10101] else numOrRecordText.text=Language[10580]..(config.Num-data.getCount).."/"..config.Num getBtnImage.sprite=this.spLoader:LoadSprite(BtnStateImage[1]) --Language[11044] end if (config.Num-data.getCount)==0 then numOrRecordText.text=Language[11043] getBtnImage.sprite=this.spLoader:LoadSprite(BtnStateImage[3]) --Language[11045] end getBtnImage:SetNativeSize() Util.AddOnceClick(getBtn,function() if data.redType>3 and PlayerManager.dailyRedPack>=tonumber(SpecialConfig.Value) then PopupTipPanel.ShowTip("今日福利红包抢夺次数到达上限!") return end NetManager.GetRobRedPackageRequest(redId,function(msg) local success=msg.isSuccess local itemId=msg.itemId local count=msg.count if success==1 then--红包抢成功 local itemName=GetLanguageStrById(ConfigManager.GetConfigData(ConfigName.ItemConfig,itemId).Name) UIManager.OpenPanel(UIName.RedPacketPopup,redId,data.redType,function() this:InitGetView() MyGuildManager.ReuqsetRedPackage() end) if data.redType>3 then PlayerManager.SettDailyRedPackageTime(PlayerManager.dailyRedPack+1) end PopupTipPanel.ShowTip(string.format(Language[11046],itemName,count)) else--抢红包失败 PopupTipPanel.ShowTip(Language[11047]) end end) end) Util.AddOnceClick(numOrRecordBtn,function()--查看记录 NetManager.GetRedPackageDetailRequest(redId,function(msg) UIManager.OpenPanel(UIName.RedPacketPopup,redId,data.redType) --this:InitGetView() end) end) end --数据排序 function this:DataSort(data) table.sort(data,function(a,b) if a.isGet==b.isGet then return a.sendTime>b.sendTime else return this:SortFun(a)