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

150 lines
5.5 KiB
Lua
Raw Normal View History

2020-08-25 15:46:38 +08:00
----- 公会红包-抢红包 -----
2020-05-09 13:31:21 +08:00
local this = {}
local sortingOrder=0
--红包资源名
2021-01-26 17:08:39 +08:00
local RedPacketName={"g_ghhb_ming_01_zh","g_ghhb_ming_02_zh","g_ghhb_ming_03_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"}--抢 已领取 已领完
2020-05-09 13:31:21 +08:00
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)
2021-01-26 17:08:39 +08:00
nameImage.sprite=Util.LoadSprite(RedPacketName[data.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]
getBtnImage.sprite=Util.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
getBtnImage.sprite=Util.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]
getBtnImage.sprite=Util.LoadSprite(BtnStateImage[3]) --Language[11045]
2020-05-09 13:31:21 +08:00
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--红包抢成功
2021-01-26 17:08:39 +08:00
local itemName=GetLanguageStrById(ConfigManager.GetConfigData(ConfigName.ItemConfig,itemId).Name)
2020-05-09 13:31:21 +08:00
UIManager.OpenPanel(UIName.RedPacketPopup,redId,data.redType)
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
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)<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