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

194 lines
6.7 KiB
Lua

require("Base/BasePanel")
local RedPacketPopup = Inherit(BasePanel)
local this=RedPacketPopup
this.playerScrollHead={}--滚动条头像
this.sendPlayerHead={}--发送者头像
--红包资源名
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","g_ghhb_lingqu","g_ghhb_lingwan_zh"}--抢 已领取 已领完
function RedPacketPopup:InitComponent()
this.spLoader = SpriteLoader.New()
this.panel=Util.GetGameObject(self.gameObject,"Panel")
this.backBtn=Util.GetGameObject(this.panel,"BackBtn")
this.title=Util.GetGameObject(this.panel,"Title"):GetComponent("Image")--红包类型名
this.titleTip=Util.GetGameObject(this.panel,"Title/Text"):GetComponent("Text")--红包寄语
this.playerHead=Util.GetGameObject(this.panel,"Info/PlayerHead")--发送者头像
this.playerInfo=Util.GetGameObject(this.panel,"Info/PlayerInfo"):GetComponent("Text")
this.image=Util.GetGameObject(this.panel,"Info/Image"):GetComponent("Image")--已领完提示
this.surplusNum=Util.GetGameObject(this.panel,"Info/SurplusNum"):GetComponent("Text")--剩余个数
this.surplusTime=Util.GetGameObject(this.panel,"Info/SurplusTime"):GetComponent("Text")--剩余时间
this.scrollRoot=Util.GetGameObject(this.panel,"ScrollRoot")--滚动条根节点
this.redPacketPre=Util.GetGameObject(this.panel,"ScrollRoot/RedPacketPre")
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,1,Vector2.New(0,0))
this.scrollView.moveTween.MomentumAmount = 1
this.scrollView.moveTween.Strength = 2
this.id=0 --红包表Id
this.redId=0 --红包动态Id
end
function RedPacketPopup:BindEvent()
Util.AddClick(this.backBtn,function()
self:ClosePanel()
end)
end
function RedPacketPopup:AddListener()
end
function RedPacketPopup:RemoveListener()
end
local func=nil
function RedPacketPopup:OnOpen(...)
local args={...}
this.redId=args[1]
this.id=args[2]
func=args[3]
end
function RedPacketPopup:OnShow()
this.InitView(this.redId, this.id)
end
function RedPacketPopup:OnClose()
if func then
func()
end
end
function RedPacketPopup:OnDestroy()
this.spLoader:Destroy()
this.scrollView=nil
if this.timer then
this.timer:Stop()
this.timer = nil
end
end
--初始化面板
function this.InitView(redId,id)
local config=ConfigManager.GetConfigData(ConfigName.GuildRedPackConfig,id)
local index=id
if index>3 then
index=4
end
this.title.sprite = this.spLoader:LoadSprite(RedPacketName[index])
if config.BaseType==1 then
this.titleTip.text=GetLanguageStrById(config.SendWord)
elseif config.BaseType==2 then
this.titleTip.text=GetLanguageStrById(config.RuleDes)
end
this.title.sprite=this.spLoader:LoadSprite(RedPacketName[index])
NetManager.GetRedPackageDetailRequest(redId,function(msg)
-- logWarnTrance(TimeToDHMS(msg.remainTime))
-- for k,v in ipairs(msg.info) do
-- logWarnTrance(tostring(v))
-- end
if not this.sendPlayerHead[this.panel] then
this.sendPlayerHead[this.panel]=CommonPool.CreateNode(POOL_ITEM_TYPE.PLAYER_HEAD,this.playerHead)
end
this.sendPlayerHead[this.panel]:Reset()
this.sendPlayerHead[this.panel]:SetHead(msg.head)
this.sendPlayerHead[this.panel]:SetFrame(msg.headFrame)
this.sendPlayerHead[this.panel]:SetLayer(this.sortingOrder)
this.playerInfo.text=PracticeManager.SetNameColor(msg.sendName,PracticeManager.PracticeLevel)..Language[11040]
local data=msg.info
this.image.enabled=(config.Num-#data)==0
this.image.sprite=this.spLoader:LoadSprite(BtnStateImage[3])
table.sort(data,function(a,b)
return a.count>b.count
end)
this.scrollView:SetData(data,function(index,root)
this.SetShow(root,data[index],index)
end)
this.scrollView:SetIndex(1)
this.surplusNum.text=Language[11041]..config.Num-#data.."/"..config.Num
this.TimeCountDown(msg.remainTime)
end)
end
--设置每一条数据
function this.SetShow(root,data,index)
local bg=Util.GetGameObject(root,"Bg"):GetComponent("Image")
local selfBG=Util.GetGameObject(root,"SelfBG"):GetComponent("Image")
local playerHead=Util.GetGameObject(root,"PlayerHead")
local bestImage=Util.GetGameObject(root,"BestImage"):GetComponent("Image")
local playerName=Util.GetGameObject(root,"PlayerName"):GetComponent("Text")
local time=Util.GetGameObject(root,"Time"):GetComponent("Text")
local rewardIcon=Util.GetGameObject(root,"RewardIcon"):GetComponent("Image")
local rewardNum=Util.GetGameObject(root,"RewardNum"):GetComponent("Text")
--颜色切换
if index%2==0 then
bg.color=Color.New(224/255,125/255,106/255,1)
else
bg.color=Color.New(226/255,159/255,131/255,1)
end
selfBG.enabled=PlayerManager.uid==data.uid
--设置头像
if not this.playerScrollHead[root] then
this.playerScrollHead[root]=CommonPool.CreateNode(POOL_ITEM_TYPE.PLAYER_HEAD,playerHead)
end
this.playerScrollHead[root]:Reset()
this.playerScrollHead[root]:SetHead(data.head)
this.playerScrollHead[root]:SetFrame(data.headFrame)
this.playerScrollHead[root]:SetScale(Vector3.one*0.6)
this.playerScrollHead[root]:SetLayer(this.sortingOrder)
this.playerScrollHead[root]:SetEffectScale(0.7)
--手气最佳
bestImage.enabled=index==1
bestImage.transform:SetSiblingIndex(1)
--职位
local grant
for k,v in pairs(GUILD_GRANT) do
if data.position==v then
grant=GUILD_GRANT_STR[v]
break
end
end
playerName.text=PracticeManager.SetNameColor(data.name,data.practiceLevel).." ("..grant..")"
time.text= TimeStampToMDHM(data.time)
rewardIcon.sprite=SetIcon(this.spLoader, data.itemId)
rewardNum.text=data.count
end
--活动时间倒计时
function this.TimeCountDown(timeDown)
if this.timer then
this.timer:Stop()
this.timer = nil
end
this.surplusTime.text = Language[10023]..TimeToHMS(timeDown)
this.timer = Timer.New(function()
if timeDown < 1 then
-- Log("==YSP== 活动时间到 关闭面板!")
this.timer:Stop()
this.timer = nil
this:ClosePanel()
Game.GlobalEvent:DispatchEvent(GameEvent.GuildRedPacket.OnRefreshGetRedPacket)
return
end
timeDown = timeDown - 1
this.surplusTime.text = Language[10023]..TimeToHMS(timeDown)
end, 1, -1, true)
this.timer:Start()
end
return RedPacketPopup