miduo_client/Assets/ManagedResources/~Lua/Modules/DynamicActivity/SheJiDaDian.lua

445 lines
17 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

local SheJiDaDian = quick_class("SheJiDaDian")
local this = SheJiDaDian
local orginLayer = 0
local parent
local actReward={}--奖励数据
local activityId--活动Id
local ActInfo={}--活动数据
local curRankType = RANK_TYPE.GOLD_EXPER
local canGetRewardList = {} --可领取的宝箱
local isPressed = false--是否按下
local isShortPress = false--点击捐献
local trigger = false --道具不足的trigger
local t = 20 --用来区分长按和点击的临界值
local curItemIndex = nil
local numCount = 1 --用于计算按下的时长(长按的捐献个数 = 用于计算按下的时长 - t
local curScore = 0
local myRank
local itemData = {--捐献道具id--三个按钮的数字显示--三个按钮的图片--三个trigger
[1] = { id = 50000 , num = nil , leftNum = nil , donImg = nil , trigger = nil , value = 1},
[2] = { id = 50001 , num = nil , leftNum = nil , donImg = nil , trigger = nil , value = 2},
[3] = { id = 50002 , num = nil , leftNum = nil , donImg = nil , trigger = nil , value = 10}
}
function this:ctor(mainPanel, gameObject)
this.mainPanel = mainPanel.transform
this.gameObject = gameObject
this:InitComponent(gameObject)
this:BindEvent()
end
function this:InitComponent(gameObject)
--down
this.tabList = Util.GetGameObject(this.mainPanel,"bg/tabbox")
this.btnBack = Util.GetGameObject(this.mainPanel,"bg/btnBack")
this.bottomBar = Util.GetGameObject(this.mainPanel,"bg/bottomBar")
--leftUp
this.leftUp = Util.GetGameObject(this.mainPanel,"leftUp")
this.firstName = Util.GetGameObject(this.leftUp,"text/first"):GetComponent("Text")
this.secendName = Util.GetGameObject(this.leftUp,"text/secend"):GetComponent("Text")
this.thirdName = Util.GetGameObject(this.leftUp,"text/third"):GetComponent("Text")
this.myScoreText = Util.GetGameObject(this.leftUp,"myScore")
this.guildScoreText = Util.GetGameObject(this.leftUp,"guildScore")
this.score = Util.GetGameObject(this.leftUp,"text/score"):GetComponent("Text")
this.btnDetail = Util.GetGameObject(this.leftUp,"btnDetail")
this.btnTeamRank = Util.GetGameObject(this.leftUp,"teamRank")
this.btnPersonRank = Util.GetGameObject(this.leftUp,"personRank")
--rightUp
this.btnHelp= Util.GetGameObject(this.gameObject,"btnHelp")
this.helpPosition=this.btnHelp:GetComponent("RectTransform").localPosition
this.rightUp = Util.GetGameObject(this.gameObject,"rightUp")
this.btnStore = Util.GetGameObject(this.rightUp,"store")
this.btnRewardList = Util.GetGameObject(this.rightUp,"reward")
--center
this.centerTime = Util.GetGameObject(this.gameObject,"center/time/num"):GetComponent("Text")
this.btnGet = Util.GetGameObject(this.gameObject,"center/btnGet")
this.effect = Util.GetGameObject(this.gameObject,"center/DynamicActivityPanel_daiji")
this.effect2 = Util.GetGameObject(this.gameObject,"center/DynamicActivityPanel_dakai")
--leftTime
this.leftTime = Util.GetGameObject(this.gameObject,"limitdi/limit"):GetComponent("Text")
--shop
this.shop = Util.GetGameObject(this.gameObject,"shop")
this.shopBack = Util.GetGameObject(this.shop,"shopBack/btnBack")
this.content = Util.GetGameObject(this.shop,"content")
--bottomArea
this.bottom = Util.GetGameObject(this.gameObject,"bottom")
this.slider = Util.GetGameObject(this.bottom,"slider")
this.value = Util.GetGameObject(this.slider,"Slider"):GetComponent("Slider")
this.level = Util.GetGameObject(this.slider,"level"):GetComponent("Text")
this.btnBox = Util.GetGameObject(this.slider,"reward/box")
this.scoreText = Util.GetGameObject(this.bottom,"score"):GetComponent("Text")
this.boxEffect = Util.GetGameObject(this.slider,"reward/box/UI_Effect_BaoXiang_KeKaiQi")
this.items = Util.GetGameObject(this.bottom,"items")
this.btnAdd = Util.GetGameObject(this.items,"item3/btnAdd")
for i = 1, 3 do
itemData[i].num = Util.GetGameObject(this.items,"item"..i.."/text/num"):GetComponent("Text")
itemData[i].donImg = Util.GetGameObject(this.items,"item"..i.."/Image")
itemData[i].trigger = Util.GetEventTriggerListener(itemData[i].donImg)
itemData[i].trigger.onPointerDown = itemData[i].trigger.onPointerDown + function(go, data) this.OnPointerDown(go, data, i) end
itemData[i].trigger.onPointerUp = itemData[i].trigger.onPointerUp + this.OnPointerUp
end
end
function SheJiDaDian:BindEvent()
Util.AddClick(this.btnHelp,function()
UIManager.OpenPanel(UIName.HelpPopup,HELP_TYPE.Celebration,this.helpPosition.x,this.helpPosition.y)
end)
Util.AddClick(this.btnGet,function()
ActInfo = ActivityGiftManager.GetActivityTypeInfo(ActivityTypeDef.Celebration)--活动数据
NetManager.GetSheJiRewardRequest(activityId,function (_drop)
this.effect2:SetActive(true)
local effectKaiQi = Util.GetGameObject(this.gameObject,"center/box"):GetComponent("Animator")
effectKaiQi:SetBool("dakai",true)
Timer.New(function ()
UIManager.OpenPanel(UIName.RewardItemPopup, _drop.drop,1,function()
this:Refresh()
end)
end,0.5):Start()
end)
end)
Util.AddClick(this.btnRewardList,function()
UIManager.OpenPanel(UIName.GeneralRankRewardPanel,2,myRank,activityId)--需要活动id和我的排名
end)
Util.AddClick(this.btnStore,function()
this.effect:SetActive(false)--特效还没加,加好后放开
this.shop:SetActive(true)
this.btnBack:SetActive(false)
this.tabList:SetActive(false)
this.bottomBar:SetActive(false)
this:StoreShow()--商店
end)
Util.AddClick(this.shopBack,function()
this.effect:SetActive(true)--特效还没加,加好后放开
this.shop:SetActive(false)
this.btnBack:SetActive(true)
this.tabList:SetActive(true)
this.bottomBar:SetActive(true)
end)
Util.AddClick(this.btnDetail,function()
if curRankType == RANK_TYPE.GOLD_EXPER then--个人排行
UIManager.OpenPanel(UIName.RankingSingleListPanel,rankKingList[13])
elseif curRankType == RANK_TYPE.CELEBRATION_GUILD then--工会排行
UIManager.OpenPanel(UIName.RankingSingleListPanel,rankKingList[14])
end
end)
Util.AddClick(this.btnTeamRank,function()
curRankType = RANK_TYPE.CELEBRATION_GUILD
this:LeftUpShow(curRankType)
this.btnTeamRank:GetComponent("Image").sprite = Util.LoadSprite("r_guanka_sheji_zhenyinganniudi_01")
this.btnPersonRank:GetComponent("Image").sprite = Util.LoadSprite("r_guanka_sheji_zhenyinganniudi_02")
end)
Util.AddClick(this.btnPersonRank,function()
curRankType = RANK_TYPE.GOLD_EXPER
this:LeftUpShow(curRankType)
this.btnTeamRank:GetComponent("Image").sprite = Util.LoadSprite("r_guanka_sheji_zhenyinganniudi_02")
this.btnPersonRank:GetComponent("Image").sprite = Util.LoadSprite("r_guanka_sheji_zhenyinganniudi_01")
end)
Util.AddOnceClick(this.btnAdd,function ()
UIManager.OpenPanel(UIName.DynamicActivityPanel,DynamicActivityManager.ZhenQiBaoGeIndex)
end)
Util.AddOnceClick(this.btnBox,function ()
DynamicActivityManager.SetCurLevel(math.floor(curScore/(actReward[1].Values[2][1])))
UIManager.OpenPanel(UIName.GeneralRewardPopup,1,ActivityTypeDef.Celebration,activityId)
end)
end
function this:OnShow(sortingOrder,_parent)
parent = _parent
Util.AddParticleSortLayer(this.effect, sortingOrder - orginLayer)
Util.AddParticleSortLayer(this.effect2, sortingOrder - orginLayer)
orginLayer = sortingOrder
FixedUpdateBeat:Add(this.OnUpdate, this)--长按方法注册
this:Refresh()
this:CheckGuild()
end
--检查是否有公会
function this:CheckGuild()
if PlayerManager.familyId == 0 then
UIManager.OpenPanel(UIName.GeneralPopup,GENERAL_POPUP_TYPE.SheJiCheckGuild)
end
end
--刷新整个页面
function this:Refresh()
trigger = false
this.effect:SetActive(true)
this.effect2:SetActive(false)
ActInfo = ActivityGiftManager.GetActivityTypeInfo(ActivityTypeDef.Celebration)--活动数据
activityId = ActInfo.activityId
actReward = ConfigManager.GetAllConfigsDataByKey(ConfigName.ActivityRewardConfig,"ActivityId",activityId)
this:RefreshItemsData()
this:TimeCountDown()--时间
this:LeftUpShow()
this:RefreshBottom()--刷新下部数字
this:RefreshRewardBox()--刷新奖励宝箱数据
end
--刷新物品剩余数量和当前积分
function this:RefreshItemsData()
for i = 1, 3 do
itemData[i].leftNum = BagManager.GetItemCountById(itemData[i].id)
end
curScore = ActInfo.mission[1].progress
end
function this:RefreshRewardBox()
canGetRewardList={}
this.boxEffect:SetActive(false)
this.btnBox:GetComponent("Image").enabled = true
for i = 1, #ActInfo.mission do
local curLevel = curScore/actReward[1].Values[2][1]
if ActInfo.mission[i].state == 0 and curLevel >= i then
table.insert(canGetRewardList,ActInfo.mission[i])
end
end
if #canGetRewardList > 0 then
this.boxEffect:SetActive(true)
this.btnBox:GetComponent("Image").enabled = false
end
end
--点击或长按处理升级处理
function this.OnPointerDown(Pointgo,data,i)--按下
if PlayerManager.level < 50 then
PopupTipPanel.ShowTip("本活动需玩家等级达到五十级!")
return
end
if PlayerManager.familyId == 0 then
PopupTipPanel.ShowTip("请先加入公会!")
return
end
curItemIndex = i
numCount = 1
isPressed = true
end
function this.OnPointerUp(Pointgo,data)--抬起
if PlayerManager.level < 50 or PlayerManager.familyId == 0 then
return
end
if isShortPress then
numCount = 1
this:RefreshBottom(numCount)
this:RequestDonate(numCount)
else
if itemData[curItemIndex].leftNum > 0 then
this:RequestDonate(numCount-t)
end
end
isPressed = false
isShortPress = false
end
function this.OnUpdate()
if isPressed then
numCount = numCount + 1
if numCount > t then
isShortPress = false
this:RefreshBottom(numCount-t)
else
if not isShortPress then
isShortPress = true
end
end
end
end
--发送捐献请求
function this:RequestDonate(numCount)
if numCount <= 0 then
PopupTipPanel.ShowTip(Language[11197])
return
end
if trigger and numCount == 1 then
trigger = false
this:Refresh()
else
NetManager.SheJiDonateItemRequest(itemData[curItemIndex].id,numCount,function()
PopupTipPanel.ShowTip("成功献出"..(itemData[curItemIndex].value * numCount).."点贡献!")
trigger = false
this:Refresh()
CheckRedPointStatus(RedPointType.Celebration)
end)
end
end
--刷新左上排行版
function this:LeftUpShow(_curRankType)
if _curRankType then
curRankType = _curRankType
else
if not curRankType then
curRankType = RANK_TYPE.GOLD_EXPER
end
end
this.myScoreText:SetActive(curRankType == RANK_TYPE.GOLD_EXPER)
this.guildScoreText:SetActive(curRankType ~= RANK_TYPE.GOLD_EXPER)
DynamicActivityManager.SheJiGetRankData(curRankType,ActInfo.activityId,function(allRankData,myRankData)
if curRankType == RANK_TYPE.GOLD_EXPER then
this.firstName.text = allRankData[1] and allRankData[1].userName or Language[11073]
this.secendName.text = allRankData[2] and allRankData[2].userName or Language[11073]
this.thirdName.text = allRankData[3] and allRankData[3].userName or Language[11073]
else
this.firstName.text = allRankData[1] and allRankData[1].guildName or Language[11073]
this.secendName.text = allRankData[2] and allRankData[2].guildName or Language[11073]
this.thirdName.text = allRankData[3] and allRankData[3].guildName or Language[11073]
end
local t = myRankData.param1 > 0 and myRankData.param1 or 0
-- LogPink("t:"..t)
-- LogPink("ActInfo.mission[1].progress :"..ActInfo.mission[1].progress )
this.score.text = curRankType == RANK_TYPE.GOLD_EXPER and t or ActInfo.mission[1].progress
myRank = myRankData.rank
end)
end
--刷新进度条和剩余数量
function this:RefreshBottom(num)
local score = 0
if num == nil then--初始、刷新进度条显示
num = 0
for i = 1, 3 do
itemData[i].num.text = itemData[i].leftNum
end
this.scoreText.text = (curScore%(actReward[1].Values[2][1])).."/"..actReward[1].Values[2][1]
else--实时更新进度条
--要判断是否还有道具进行捐献
if itemData[curItemIndex].leftNum - num < 0 then
this:RequestDonate(num - 1)
trigger = true
isPressed = false
-- return
end
itemData[curItemIndex].num.text = itemData[curItemIndex].leftNum - num
score = itemData[curItemIndex].value * num
this.scoreText.text = ((curScore + score)%(actReward[1].Values[2][1])).."/"..actReward[1].Values[2][1]
end
this.value.value = (((curScore + score))%(actReward[1].Values[2][1]))/actReward[1].Values[2][1]
this.level.text = math.floor((curScore + score)/(actReward[1].Values[2][1])) .. Language[10072]
end
--商店
function this:StoreShow()
if not this.shopView then
this.shopView = SubUIManager.Open(SubUIConfig.ShopView, this.content.transform)
end
this.shopView:ShowShop(SHOP_TYPE.CELEBRATION_SHOP,orginLayer)
end
--时间
function this:TimeCountDown()
local setting = ConfigManager.GetConfigDataByKey(ConfigName.GodSacrificeSetting,"ActivityId",activityId)
--活动结束时间
local canGet = false
local actTime = ActInfo.endTime - GetTimeStamp()
this.leftTime.text = Language[10028]..TimeToFelaxible(actTime)
--宝箱领取重置时间
local timeOne = Today_N_OClockTimeStamp(setting.TimePointList[1]) - GetTimeStamp()
local leftTimeOne = timeOne > 0 and timeOne or timeOne + 86400--距离下一个十二点的时间
local timeTwo = Today_N_OClockTimeStamp(setting.TimePointList[2]) - GetTimeStamp()
local leftTimeTwo = timeTwo > 0 and timeTwo or timeTwo + 86400--距离下一个二十点的时间
local giftTime = leftTimeOne < leftTimeTwo and leftTimeOne or leftTimeTwo--取小的
local t1 = GetTimeStamp() - Today_N_OClockTimeStamp(setting.TimePointList[1])
local t2 = GetTimeStamp() - Today_N_OClockTimeStamp(setting.TimePointList[2])
-- LogGreen("dao 12 dian:"..t1)
-- LogGreen("dao 20 dian:"..t2)
-- LogGreen("ActInfo.value:"..ActInfo.value)
-- LogGreen("GetTimeStamp():"..GetTimeStamp())
-- LogGreen("GetTimeStamp() - ActInfo.value"..(GetTimeStamp() - ActInfo.value))
-- LogGreen("giftTime:"..giftTime)
if ActInfo.value == 0 then
if (t1 > 0 and t1 < 1800) or (t2 > 0 and t2 < 1800) then
canGet = true
else
canGet = false
end
else
if (t1 > 0 and t1 < 1800) or (t2 > 0 and t2 < 1800) then
if (GetTimeStamp() - ActInfo.value) < 1800 then
canGet = false
else
canGet = true
end
else
canGet = false
end
end
-- LogGreen("canGet:"..tostring(canGet))
this.centerTime.text = canGet == false and TimeToFelaxible(giftTime) or Language[12183]
if this.timer1 then
this.timer1:Stop()
this.timer1 = nil
end
this.timer1 = Timer.New(function()
this.leftTime.text = Language[10028]..TimeToFelaxible(actTime)
this.centerTime.text = canGet == false and TimeToFelaxible(giftTime) or Language[12183]
if actTime < 1 then
this.timer1:Stop()
this.timer1 = nil
parent:ClosePanel()
return
end
if giftTime < 0 then
this:Refresh()
end
actTime = actTime -1
giftTime = giftTime - 1
end, 1, -1, true)
this.timer1:Start()
end
function this:OnSortingOrderChange(_sortingOrder)
orginLayer = _sortingOrder
end
function this:OnHide()
FixedUpdateBeat:Remove(this.OnUpdate, this)
if this.timer1 then
this.timer1:Stop()
this.timer1 = nil
end
if this.shopView then
this.shopView = SubUIManager.Close(this.shopView)
this.shopView = nil
end
end
--添加事件监听(用于子类重写)
function this:AddListener()
Game.GlobalEvent:AddEvent(GameEvent.DynamicTask.OnGetReward, this.Refresh)
end
--移除事件监听(用于子类重写)
function this:RemoveListener()
Game.GlobalEvent:RemoveEvent(GameEvent.DynamicTask.OnGetReward, this.Refresh)
end
return this