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

192 lines
6.8 KiB
Lua
Raw Normal View History

2020-08-21 11:23:46 +08:00
local XianShiShangShi = quick_class("XianShiShangShi")
2020-08-13 15:38:20 +08:00
local allData={}
local itemsGrid = {}--item重复利用
2020-08-21 11:23:46 +08:00
local this=XianShiShangShi
2020-08-21 18:30:44 +08:00
local parent
2020-08-21 11:23:46 +08:00
function XianShiShangShi:ctor(mainPanel, gameObject)
2020-08-13 15:38:20 +08:00
self.mainPanel = mainPanel
self.gameObject = gameObject
self:InitComponent(gameObject)
self:BindEvent()
end
2020-08-21 11:23:46 +08:00
function XianShiShangShi:InitComponent(gameObject)
2020-08-21 18:30:44 +08:00
this.time = Util.GetGameObject(gameObject, "tiao/time"):GetComponent("Text")
2020-08-13 15:38:20 +08:00
this.itemPre = Util.GetGameObject(gameObject, "ItemPre3")
this.scrollItem = Util.GetGameObject(gameObject, "scrollItem")
local rootHight = this.scrollItem.transform.rect.height
local width = this.scrollItem.transform.rect.width
this.ScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, this.scrollItem.transform,
this.itemPre, nil, Vector2.New(width, rootHight), 1, 1, Vector2.New(0, 35))
this.ScrollView.moveTween.MomentumAmount = 1
this.ScrollView.moveTween.Strength = 2
end
--绑定事件(用于子类重写)
2020-08-21 11:23:46 +08:00
function XianShiShangShi:BindEvent()
2020-08-13 15:38:20 +08:00
end
--添加事件监听(用于子类重写)
2020-08-21 11:23:46 +08:00
function XianShiShangShi:AddListener()
2020-08-13 15:38:20 +08:00
Game.GlobalEvent:AddEvent(GameEvent.MoneyPay.OnPayResultSuccess, this.RechargeSuccessFunc)
end
--移除事件监听(用于子类重写)
2020-08-21 11:23:46 +08:00
function XianShiShangShi:RemoveListener()
2020-08-13 15:38:20 +08:00
Game.GlobalEvent:RemoveEvent(GameEvent.MoneyPay.OnPayResultSuccess, this.RechargeSuccessFunc)
end
local sortingOrder = 0
--界面打开时调用(用于子类重写)
2020-08-21 11:23:46 +08:00
function XianShiShangShi:OnOpen()
2020-08-13 15:38:20 +08:00
end
--界面打开或者重新打开后,界面刷新时调用(用于子类重写)
2020-08-21 18:30:44 +08:00
function XianShiShangShi:OnShow(_sortingOrder,_parent)
2020-08-13 15:38:20 +08:00
sortingOrder = _sortingOrder
2020-08-21 18:30:44 +08:00
parent = _parent
2020-08-13 15:38:20 +08:00
this:OnShowData()
2020-08-21 18:30:44 +08:00
XianShiShangShi:SetTime()
2020-08-13 15:38:20 +08:00
end
2020-08-21 11:23:46 +08:00
function XianShiShangShi:OnShowData()
allData = ConfigManager.GetAllConfigsDataByDoubleKey(ConfigName.RechargeCommodityConfig, "ShowType", 22, "Type", GoodsTypeDef.DirectPurchaseGift)
2020-08-13 15:38:20 +08:00
if allData then
this.SortData(allData)
this.ScrollView:SetData(allData, function (index, go)
this.SingleDataShow(go, allData[index])
end)
end
end
2020-08-21 18:30:44 +08:00
function XianShiShangShi:SetTime()
if self.timer then
self.timer:Stop()
self.timer = nil
end
local endTime = ActivityGiftManager.GetTaskEndTime(ActivityTypeDef.pozhenzhuxian_TimeLimitShop)
local timeDown = endTime - GetTimeStamp()
this.time.text = "剩余时间:"..TimeToDHMS(timeDown)
self.timer = Timer.New(function()
timeDown = timeDown - 1
if timeDown < 1 then
parent:ClosePanel()
end
this.time.text = "剩余时间:"..TimeToDHMS(timeDown)
end, 1, -1, true)
self.timer:Start()
end
2020-08-21 11:23:46 +08:00
function XianShiShangShi:SortData()
2020-08-13 15:38:20 +08:00
if allData==nil then
return
end
table.sort(allData, function(a,b)
local aboughtNum = a.Limit - OperatingManager.GetGoodsBuyTime(GoodsTypeDef.DirectPurchaseGift, a.Id) > 0 and 2 or 1
local bboughtNum = b.Limit - OperatingManager.GetGoodsBuyTime(GoodsTypeDef.DirectPurchaseGift, b.Id) > 0 and 2 or 1
if aboughtNum == bboughtNum then
return a.Id < b.Id
else
return aboughtNum > bboughtNum
end
end)
end
--刷新每一条的显示数据
function this.SingleDataShow(pre,value)
if pre==nil or value==nil then
return
end
--绑定组件
local shopItemData = value
local price = Util.GetGameObject(pre, "btnBuy/price"):GetComponent("Text")
local buyInfo = Util.GetGameObject(pre, "buyInfo")
local btnBuy = Util.GetGameObject(pre, "btnBuy")
local grid = Util.GetGameObject(pre, "scrollView/grid")
local shadow = Util.GetGameObject(pre, "shadow")
--local goodData = OperatingManager.GetGiftGoodsInfo(GoodsTypeDef.DirectPurchaseGift, value.Id)
local boughtNum = OperatingManager.GetGoodsBuyTime(GoodsTypeDef.DirectPurchaseGift, value.Id) or 0
local shows = shopItemData.RewardShow
2020-08-21 11:23:46 +08:00
buyInfo:GetComponent("Text").text =Language[11454].. shopItemData.Limit-boughtNum.."/".. shopItemData.Limit..Language[10054] ..")"
2020-08-13 15:38:20 +08:00
if shopItemData.Limit - boughtNum > 0 then
price.text = shopItemData.Price..Language[10538]
btnBuy:GetComponent("Button").enabled = true
Util.SetGray(btnBuy, false)
else
2020-08-21 11:23:46 +08:00
price.text = Language[10526]
2020-08-13 15:38:20 +08:00
btnBuy:GetComponent("Button").enabled = false
Util.SetGray(btnBuy, true)
end
--滚动条复用重设itemview
if itemsGrid[pre] then
for i = 1, 4 do
itemsGrid[pre][i].gameObject:SetActive(false)
end
for i = 1, #shows do
if itemsGrid[pre][i] then
itemsGrid[pre][i]:OnOpen(false, {shows[i][1],shows[i][2]}, 0.9,false,false,false,cursortingOrder)
itemsGrid[pre][i].gameObject:SetActive(true)
end
end
else
itemsGrid[pre]={}
for i = 1, 4 do
itemsGrid[pre][i] = SubUIManager.Open(SubUIConfig.ItemView, grid.transform)
itemsGrid[pre][i].gameObject:SetActive(false)
local obj= newObjToParent(shadow,itemsGrid[pre][i].transform)
obj.transform:SetAsFirstSibling()
obj.transform:DOAnchorPos(Vector3(0,-3,0),0)
obj:GetComponent("RectTransform").transform.localScale=Vector3.one*1.1
obj.gameObject:SetActive(true)
end
for i = 1, #shows do
itemsGrid[pre][i]:OnOpen(false, {shows[i][1],shows[i][2]}, 0.9,false,false,false,cursortingOrder)
itemsGrid[pre][i].gameObject:SetActive(true)
end
end
--local costId, finalNum, oriCostNum = ShopManager.calculateBuyCost(SHOP_TYPE.FINDTREASURE_GIFT, data.id, 1)
Util.AddOnceClick(btnBuy, function()
if shopItemData.Limit <= boughtNum then
PopupTipPanel.ShowTip(Language[10540])
else
--直购商品
if AppConst.isSDKLogin then
PayManager.Pay({ Id = value.Id })
else
NetManager.RequestBuyGiftGoods(value.Id, function(msg)
FirstRechargeManager.RefreshAccumRechargeValue(value.Id)
-- OperatingManager.RefreshGiftGoodsBuyTimes(GoodsTypeDef.DirectPurchaseGift, data.goodsId) -- 改成后端推了
2020-08-21 11:23:46 +08:00
this.OnShowData()
2020-08-13 15:38:20 +08:00
end)
end
end
end)
end
--界面打开时调用(用于子类重写)
2020-08-21 11:23:46 +08:00
function XianShiShangShi:OnOpen()
2020-08-13 15:38:20 +08:00
end
function this.RechargeSuccessFunc(id)
FirstRechargeManager.RefreshAccumRechargeValue(id)
--OperatingManager.RefreshGiftGoodsBuyTimes(GoodsTypeDef.GiftBuy, id)
this.OnShowData()
end
2020-08-21 11:23:46 +08:00
function XianShiShangShi:OnClose()
2020-08-13 15:38:20 +08:00
end
--界面销毁时调用(用于子类重写)
2020-08-21 11:23:46 +08:00
function XianShiShangShi:OnDestroy()
2020-08-13 15:38:20 +08:00
sortingOrder = 0
end
2020-08-21 11:23:46 +08:00
function XianShiShangShi:OnHide()
2020-08-13 15:38:20 +08:00
sortingOrder = 0
end
2020-08-21 11:23:46 +08:00
return XianShiShangShi