----- 公会红包-抢红包 ----- local this = {} local sortingOrder=0 --红包资源名 local RedPacketName={"g_ghhb_ming_01_zh","g_ghhb_ming_02_zh","g_ghhb_ming_03_zh"} --红包按钮状态图片 local BtnStateImage={"g_ghhb_qiang_zh","g_ghhb_lingqu_zh","g_ghhb_lingwan_zh"}--抢 已领取 已领完 function this:InitComponent(gameObject) 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) end function this:RemoveListener() Game.GlobalEvent:RemoveEvent(GameEvent.GuildRedPacket.OnRefreshGetRedPacket, this.InitGetView) end function this:OnShow(_sortingOrder) -- logWarnTrance("打开抢红包") sortingOrder=_sortingOrder this:InitGetView() end function this:OnClose() -- logWarnTrance("关闭抢红包") end function this:OnDestroy() this.scrollView=nil end --初始化抢红包面板 function this:InitGetView() local dataLength=0 NetManager.GetAllRedPacketResponse(function(msg) -- logWarnTrance(#msg.info) -- for index, value in ipairs(msg.info) do -- Log(tostring(value)) -- end 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) this.scrollView:SetIndex(1) 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 redId=data.redId local config=ConfigManager.GetConfigData(ConfigName.GuildRedPackConfig,data.redType) nameImage.sprite=Util.LoadSprite(RedPacketName[data.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=Util.LoadSprite(BtnStateImage[2]) --Language[10101] else numOrRecordText.text=Language[10580]..(config.Num-data.getCount).."/"..config.Num getBtnImage.sprite=Util.LoadSprite(BtnStateImage[1]) --Language[11044] end if (config.Num-data.getCount)==0 then numOrRecordText.text=Language[11043] getBtnImage.sprite=Util.LoadSprite(BtnStateImage[3]) --Language[11045] end getBtnImage:SetNativeSize() Util.AddOnceClick(getBtn,function() 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) PopupTipPanel.ShowTip(string.format(Language[11046],itemName,count)) else--抢红包失败 PopupTipPanel.ShowTip(Language[11047]) end this:InitGetView() 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)