miduo_client/Assets/ManagedResources/~Lua/Modules/Guild/RedPacketView/RedPacket_GetView.lua

219 lines
8.4 KiB
Lua
Raw Normal View History

2020-08-25 15:46:38 +08:00
----- 公会红包-抢红包 -----
local this={}
2020-05-09 13:31:21 +08:00
local sortingOrder=0
--红包资源名
2021-05-21 14:47:04 +08:00
local RedPacketName={"g_ghhb_ming_01_zh","g_ghhb_ming_02_zh","g_ghhb_ming_03_zh","g_ghhb_ming_04_zh"}
2020-05-09 13:31:21 +08:00
--红包按钮状态图片
2021-01-26 17:08:39 +08:00
local BtnStateImage={"g_ghhb_qiang_zh","g_ghhb_lingqu_zh","g_ghhb_lingwan_zh"}--抢 已领取 已领完
2021-05-25 14:52:02 +08:00
local SpecialConfig=ConfigManager.GetConfigData(ConfigName.SpecialConfig,115)
2021-05-21 14:47:04 +08:00
2020-05-09 13:31:21 +08:00
function this:InitComponent(gameObject)
2021-04-21 13:12:04 +08:00
this.spLoader = SpriteLoader.New()
2020-05-09 13:31:21 +08:00
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()
2021-05-21 14:47:04 +08:00
2020-05-09 13:31:21 +08:00
end
function this:AddListener()
Game.GlobalEvent:AddEvent(GameEvent.GuildRedPacket.OnRefreshGetRedPacket, this.InitGetView)
2021-05-21 14:47:04 +08:00
Game.GlobalEvent:AddEvent(GameEvent.GuildRedPacket.AuoGetRedPackage, this.AutoGetRedPackage)
2020-05-09 13:31:21 +08:00
end
function this:RemoveListener()
Game.GlobalEvent:RemoveEvent(GameEvent.GuildRedPacket.OnRefreshGetRedPacket, this.InitGetView)
2021-05-21 14:47:04 +08:00
Game.GlobalEvent:RemoveEvent(GameEvent.GuildRedPacket.AuoGetRedPackage, this.AutoGetRedPackage)
end
local isAuto=false
--自动抢红包
function this:AutoGetRedPackage()
isAuto=true
2020-05-09 13:31:21 +08:00
end
2021-05-21 14:47:04 +08:00
2020-05-09 13:31:21 +08:00
function this:OnShow(_sortingOrder)
-- logWarnTrance("打开抢红包")
sortingOrder=_sortingOrder
this:InitGetView()
end
function this:OnClose()
-- logWarnTrance("关闭抢红包")
2021-05-21 14:47:04 +08:00
isAuto=false
2020-05-09 13:31:21 +08:00
end
function this:OnDestroy()
2021-04-21 13:12:04 +08:00
this.spLoader:Destroy()
2020-05-09 13:31:21 +08:00
this.scrollView=nil
end
--初始化抢红包面板
function this:InitGetView()
local dataLength=0
2021-05-21 14:47:04 +08:00
isAuto=false
2020-05-09 13:31:21 +08:00
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)
2021-05-21 17:32:52 +08:00
--this.scrollView:SetIndex(1)
2021-05-21 14:47:04 +08:00
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)
2021-05-21 14:47:04 +08:00
--红包类型大于3的是福利红包
if value.redType>3 then
PlayerManager.SettDailyRedPackageTime(PlayerManager.dailyRedPack+1)
end
2021-05-21 14:47:04 +08:00
PopupTipPanel.ShowTip(string.format(Language[11046],itemName,count))
else--抢红包失败
LogError(Language[11047])
PopupTipPanel.ShowTip(Language[11047])
end
end)
return
end
end
end
end
2020-05-09 13:31:21 +08:00
end)
end
2021-05-21 14:47:04 +08:00
2020-05-09 13:31:21 +08:00
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")--剩余礼包数或查看记录
2021-05-21 14:47:04 +08:00
local getInfo=Util.GetGameObject(root,"GetInfo"):GetComponent("Text")--获取信息
2020-05-09 13:31:21 +08:00
local redId=data.redId
2021-05-21 14:47:04 +08:00
local redType=data.redType
if redType>3 then
redType=4
end
2020-05-09 13:31:21 +08:00
local config=ConfigManager.GetConfigData(ConfigName.GuildRedPackConfig,data.redType)
2021-05-21 14:47:04 +08:00
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])
2021-04-09 12:26:35 +08:00
fromPlayer.text=Language[11042]..data.userName.."</color>"
2020-05-09 13:31:21 +08:00
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
2021-04-09 12:26:35 +08:00
numOrRecordText.text=Language[11043]
2021-04-21 13:12:04 +08:00
getBtnImage.sprite=this.spLoader:LoadSprite(BtnStateImage[2]) --Language[10101]
2020-05-09 13:31:21 +08:00
else
2021-04-09 12:26:35 +08:00
numOrRecordText.text=Language[10580]..(config.Num-data.getCount).."/"..config.Num
2021-04-21 13:12:04 +08:00
getBtnImage.sprite=this.spLoader:LoadSprite(BtnStateImage[1]) --Language[11044]
2020-05-09 13:31:21 +08:00
end
if (config.Num-data.getCount)==0 then
2021-04-09 12:26:35 +08:00
numOrRecordText.text=Language[11043]
2021-04-21 13:12:04 +08:00
getBtnImage.sprite=this.spLoader:LoadSprite(BtnStateImage[3]) --Language[11045]
2020-05-09 13:31:21 +08:00
end
getBtnImage:SetNativeSize()
Util.AddOnceClick(getBtn,function()
2021-05-25 14:52:02 +08:00
if data.redType>3 and PlayerManager.dailyRedPack>=tonumber(SpecialConfig.Value) then
PopupTipPanel.ShowTip("今日福利红包抢夺次数到达上限!")
return
end
2020-05-09 13:31:21 +08:00
NetManager.GetRobRedPackageRequest(redId,function(msg)
local success=msg.isSuccess
local itemId=msg.itemId
local count=msg.count
if success==1 then--红包抢成功
2021-01-26 17:08:39 +08:00
local itemName=GetLanguageStrById(ConfigManager.GetConfigData(ConfigName.ItemConfig,itemId).Name)
UIManager.OpenPanel(UIName.RedPacketPopup,redId,data.redType,function()
this:InitGetView()
MyGuildManager.ReuqsetRedPackage()
end)
2021-05-21 14:47:04 +08:00
if data.redType>3 then
PlayerManager.SettDailyRedPackageTime(PlayerManager.dailyRedPack+1)
end
2021-04-09 12:26:35 +08:00
PopupTipPanel.ShowTip(string.format(Language[11046],itemName,count))
2020-05-09 13:31:21 +08:00
else--抢红包失败
2021-04-09 12:26:35 +08:00
PopupTipPanel.ShowTip(Language[11047])
2020-05-09 13:31:21 +08:00
end
end)
2020-05-09 13:31:21 +08:00
end)
Util.AddOnceClick(numOrRecordBtn,function()--查看记录
NetManager.GetRedPackageDetailRequest(redId,function(msg)
UIManager.OpenPanel(UIName.RedPacketPopup,redId,data.redType)
--this:InitGetView()
2020-05-09 13:31:21 +08:00
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)<this:SortFun(b)
end
end)
end
function this:SortFun(x)
if x.isGet==0 then
return 1 --抢
else
local config=ConfigManager.GetConfigData(ConfigName.GuildRedPackConfig,x.redType)
if x.isGet==1 then
return 2--已领取
elseif (config.Num-x.getCount)==0 then
return 3 --已领完
end
end
end
2020-06-23 18:36:24 +08:00
return this