2021-04-21 13:12:04 +08:00
|
|
|
|
local GiftBuy = quick_class("GiftBuy")
|
2020-06-03 19:09:01 +08:00
|
|
|
|
local this = GiftBuy
|
|
|
|
|
local itemsGrid = {}--item重复利用
|
|
|
|
|
local allData = {}
|
|
|
|
|
local rechargeCommodityConfig = ConfigManager.GetConfig(ConfigName.RechargeCommodityConfig)
|
|
|
|
|
local cursortingOrder
|
|
|
|
|
local endTime = 0
|
|
|
|
|
function GiftBuy:ctor(mainPanel, gameObject)
|
|
|
|
|
self.mainPanel = mainPanel
|
|
|
|
|
self.gameObject = gameObject
|
|
|
|
|
self:InitComponent(gameObject)
|
|
|
|
|
self:BindEvent()
|
|
|
|
|
end
|
|
|
|
|
--初始化组件(用于子类重写)
|
|
|
|
|
function GiftBuy:InitComponent(gameObject)
|
2021-04-21 13:12:04 +08:00
|
|
|
|
this.spLoader = SpriteLoader.New()
|
2020-06-03 19:09:01 +08:00
|
|
|
|
|
|
|
|
|
this.itemPre = Util.GetGameObject(gameObject, "ItemPre")
|
|
|
|
|
this.endTime = Util.GetGameObject(gameObject, "Image/endTime"):GetComponent("Text")
|
|
|
|
|
this.endTimeBg = Util.GetGameObject(gameObject, "Image")
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
--绑定事件(用于子类重写)
|
|
|
|
|
function GiftBuy:BindEvent()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--添加事件监听(用于子类重写)
|
|
|
|
|
function GiftBuy:AddListener()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--移除事件监听(用于子类重写)
|
|
|
|
|
function GiftBuy:RemoveListener()
|
|
|
|
|
end
|
|
|
|
|
local sortingOrder = 0
|
|
|
|
|
--界面打开时调用(用于子类重写)
|
|
|
|
|
function GiftBuy:OnOpen()
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--界面打开或者重新打开后,界面刷新时调用(用于子类重写)
|
|
|
|
|
function GiftBuy:OnShow(_sortingOrder)
|
|
|
|
|
sortingOrder = _sortingOrder
|
2021-02-25 12:04:31 +08:00
|
|
|
|
this:OnShowData(true,true)
|
2020-06-03 19:09:01 +08:00
|
|
|
|
end
|
|
|
|
|
function GiftBuy:OnSortingOrderChange(_cursortingOrder)
|
|
|
|
|
cursortingOrder = _cursortingOrder
|
|
|
|
|
for i, v in pairs(itemsGrid) do
|
|
|
|
|
for j = 1, #v do
|
|
|
|
|
v[j]:SetEffectLayer(cursortingOrder)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2021-02-25 12:04:31 +08:00
|
|
|
|
function GiftBuy:OnShowData(isTop,isAni)
|
2020-06-03 19:09:01 +08:00
|
|
|
|
allData = ConfigManager.GetAllConfigsDataByDoubleKey(ConfigName.RechargeCommodityConfig, "ShowType", 20, "Type", GoodsTypeDef.DirectPurchaseGift)
|
|
|
|
|
this.SortData(allData)
|
|
|
|
|
this.ScrollView:SetData(allData, function (index, go)
|
|
|
|
|
this.SingleDataShow(go, allData[index])
|
2021-02-25 12:04:31 +08:00
|
|
|
|
end,not isTop,not isAni)
|
2020-06-03 19:09:01 +08:00
|
|
|
|
PatFaceManager.RemainTimeDown(this.endTimeBg,this.endTime,endTime - GetTimeStamp())
|
|
|
|
|
end
|
|
|
|
|
--刷新每一条的显示数据
|
|
|
|
|
function this.SingleDataShow(go, data)
|
|
|
|
|
--绑定组件
|
|
|
|
|
local shopItemData = data
|
|
|
|
|
local name = Util.GetGameObject(go, "context/text"):GetComponent("Text")
|
|
|
|
|
local price = Util.GetGameObject(go, "btnBuy/price"):GetComponent("Text")
|
|
|
|
|
local buyInfo = Util.GetGameObject(go, "buyInfo")
|
2021-01-27 16:12:39 +08:00
|
|
|
|
local buyInfo2 = Util.GetGameObject(go, "buyInfo2")
|
2020-06-03 19:09:01 +08:00
|
|
|
|
local btnBuy = Util.GetGameObject(go, "btnBuy")
|
|
|
|
|
local grid = Util.GetGameObject(go, "scrollView/grid")
|
|
|
|
|
local shadow = Util.GetGameObject(go, "shadow")
|
2021-03-05 16:41:59 +08:00
|
|
|
|
local LimitText=Util.GetGameObject(go,"tip/tip1/text1"):GetComponent("Text")
|
2020-06-03 19:09:01 +08:00
|
|
|
|
|
|
|
|
|
local goodData = OperatingManager.GetGiftGoodsInfo(GoodsTypeDef.DirectPurchaseGift, data.Id)
|
|
|
|
|
local boughtNum = OperatingManager.GetGoodsBuyTime(GoodsTypeDef.DirectPurchaseGift, data.Id) or 0
|
|
|
|
|
local shows = shopItemData.RewardShow
|
2021-02-24 14:04:32 +08:00
|
|
|
|
name.text = GetLanguageStrById(shopItemData.Name)
|
|
|
|
|
|
2021-03-05 16:41:59 +08:00
|
|
|
|
LimitText.text = string.format(Language[12232], "<color=#FAD88AFF>"..shopItemData.Limit.."</color>")
|
|
|
|
|
-- if GetCurLanguage() == 2 then
|
|
|
|
|
-- LimitText.gameObject.transform.localPosition = Vector3.New(4.7,-5,0)
|
|
|
|
|
-- else
|
|
|
|
|
-- LimitText.gameObject.transform.localPosition = Vector3.New(-147,-5,0)
|
|
|
|
|
-- end
|
2020-06-03 19:09:01 +08:00
|
|
|
|
buyInfo:SetActive( shopItemData.IsDiscount ~= 0 )
|
|
|
|
|
if shopItemData.IsDiscount and shopItemData.IsDiscount > 0 then
|
2021-03-02 16:53:12 +08:00
|
|
|
|
buyInfo:GetComponent("Text").text = Language[10582]..string.format(MoneyUtil.GetMoneyUnitName(), MoneyUtil.GetMoney(shopItemData.Price) / (shopItemData.IsDiscount/10))--shopItemData.Price / (shopItemData.IsDiscount/10)..MoneyUtil.GetMoneyUnitName()
|
2020-06-03 19:09:01 +08:00
|
|
|
|
end
|
|
|
|
|
if goodData then
|
|
|
|
|
endTime = goodData.endTime
|
|
|
|
|
end
|
|
|
|
|
if shopItemData.Limit - boughtNum > 0 then
|
2020-08-25 17:59:34 +08:00
|
|
|
|
price.text = string.format(MoneyUtil.GetMoneyUnitName(), MoneyUtil.GetMoney(shopItemData.Price))--..MoneyUtil.GetMoneyUnitName()
|
2020-06-03 19:09:01 +08:00
|
|
|
|
btnBuy:GetComponent("Button").enabled = true
|
|
|
|
|
Util.SetGray(btnBuy, false)
|
2021-01-27 16:12:39 +08:00
|
|
|
|
buyInfo2:SetActive(true)
|
2021-03-02 16:53:12 +08:00
|
|
|
|
buyInfo2:GetComponent("Text").text = Language[10580]..shopItemData.Limit - boughtNum..Language[10048]
|
2020-06-03 19:09:01 +08:00
|
|
|
|
else
|
2021-03-02 16:53:12 +08:00
|
|
|
|
price.text = Language[10514]
|
2020-06-03 19:09:01 +08:00
|
|
|
|
btnBuy:GetComponent("Button").enabled = false
|
|
|
|
|
Util.SetGray(btnBuy, true)
|
2021-01-27 16:12:39 +08:00
|
|
|
|
buyInfo2:SetActive(false)
|
2020-06-03 19:09:01 +08:00
|
|
|
|
end
|
|
|
|
|
--滚动条复用重设itemview
|
2020-10-15 21:24:08 +08:00
|
|
|
|
|
|
|
|
|
if not itemsGrid[go] then
|
|
|
|
|
itemsGrid[go] = {}
|
|
|
|
|
end
|
2020-10-15 21:28:23 +08:00
|
|
|
|
for k,v in pairs(itemsGrid[go]) do
|
|
|
|
|
v.gameObject:SetActive(false)
|
|
|
|
|
end
|
2020-10-15 21:24:08 +08:00
|
|
|
|
for i = 1, #shows do
|
|
|
|
|
if not itemsGrid[go][i] then
|
2020-06-03 19:09:01 +08:00
|
|
|
|
itemsGrid[go][i] = SubUIManager.Open(SubUIConfig.ItemView, grid.transform)
|
|
|
|
|
itemsGrid[go][i].gameObject:SetActive(false)
|
|
|
|
|
local obj= newObjToParent(shadow,itemsGrid[go][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
|
2020-10-15 21:24:08 +08:00
|
|
|
|
itemsGrid[go][i]:OnOpen(false, {shows[i][1],shows[i][2]}, 0.9,false,false,false,cursortingOrder)
|
|
|
|
|
itemsGrid[go][i].gameObject:SetActive(true)
|
2020-06-03 19:09:01 +08:00
|
|
|
|
end
|
2020-10-15 21:24:08 +08:00
|
|
|
|
-- if itemsGrid[go] then
|
|
|
|
|
-- for i = 1, 4 do
|
|
|
|
|
-- itemsGrid[go][i].gameObject:SetActive(false)
|
|
|
|
|
-- end
|
|
|
|
|
-- for i = 1, #shows do
|
|
|
|
|
-- if itemsGrid[go][i] then
|
|
|
|
|
-- itemsGrid[go][i]:OnOpen(false, {shows[i][1],shows[i][2]}, 0.9,false,false,false,cursortingOrder)
|
|
|
|
|
-- itemsGrid[go][i].gameObject:SetActive(true)
|
|
|
|
|
-- end
|
|
|
|
|
-- end
|
|
|
|
|
-- else
|
|
|
|
|
-- itemsGrid[go]={}
|
|
|
|
|
-- for i = 1, 4 do
|
|
|
|
|
-- itemsGrid[go][i] = SubUIManager.Open(SubUIConfig.ItemView, grid.transform)
|
|
|
|
|
-- itemsGrid[go][i].gameObject:SetActive(false)
|
|
|
|
|
-- local obj= newObjToParent(shadow,itemsGrid[go][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[go][i]:OnOpen(false, {shows[i][1],shows[i][2]}, 0.9,false,false,false,cursortingOrder)
|
|
|
|
|
-- itemsGrid[go][i].gameObject:SetActive(true)
|
|
|
|
|
-- end
|
|
|
|
|
-- end
|
2020-06-03 19:09:01 +08:00
|
|
|
|
--local costId, finalNum, oriCostNum = ShopManager.calculateBuyCost(SHOP_TYPE.FINDTREASURE_GIFT, data.id, 1)
|
|
|
|
|
Util.AddOnceClick(btnBuy, function()
|
|
|
|
|
if shopItemData.Limit <= boughtNum then
|
2021-03-02 16:53:12 +08:00
|
|
|
|
PopupTipPanel.ShowTip(Language[10515])
|
2020-06-03 19:09:01 +08:00
|
|
|
|
else
|
|
|
|
|
--直购商品
|
2020-09-09 18:47:17 +08:00
|
|
|
|
PayManager.Pay(data.Id, function(id)
|
|
|
|
|
this:RechargeSuccessFunc(id)
|
|
|
|
|
end)
|
2020-06-03 19:09:01 +08:00
|
|
|
|
end
|
|
|
|
|
end)
|
|
|
|
|
end
|
|
|
|
|
function this.RechargeSuccessFunc(id)
|
|
|
|
|
FirstRechargeManager.RefreshAccumRechargeValue(id)
|
|
|
|
|
--OperatingManager.RefreshGiftGoodsBuyTimes(GoodsTypeDef.GiftBuy, id)
|
2021-02-25 12:04:31 +08:00
|
|
|
|
this.OnShowData(false,false)
|
2020-06-03 19:09:01 +08:00
|
|
|
|
end
|
|
|
|
|
--购买点击事件
|
|
|
|
|
--function this.BuyAction(costId, costNum, shopType, itemId)
|
|
|
|
|
-- local haveNum = BagManager.GetItemCountById(costId)
|
|
|
|
|
-- local costName = ConfigManager.GetConfigData(ConfigName.ItemConfig, costId).Name
|
|
|
|
|
-- if haveNum < costNum then
|
|
|
|
|
-- NotEnoughPopup:Show(costId)
|
|
|
|
|
-- else
|
|
|
|
|
-- local isPopUp = RedPointManager.PlayerPrefsGetStr(PlayerManager.uid .. shopType)
|
|
|
|
|
-- local currentTime = os.date("%Y%m%d", PlayerManager.serverTime)
|
|
|
|
|
-- if (isPopUp ~= currentTime and costNum ~= 0) then
|
|
|
|
|
-- local str = string.format("确认花费%d%s购买本礼包吗?", costNum, costName)
|
|
|
|
|
-- MsgPanel.ShowTwo(str, function()
|
|
|
|
|
-- end, function(isShow)
|
|
|
|
|
-- if (isShow) then
|
|
|
|
|
-- local currentTime = os.date("%Y%m%d", PlayerManager.serverTime)
|
|
|
|
|
-- RedPointManager.PlayerPrefsSetStr(PlayerManager.uid .. shopType, currentTime)
|
|
|
|
|
-- end
|
|
|
|
|
-- ShopManager.RequestBuyShopItem(shopType, itemId, 1, function()
|
|
|
|
|
-- self:RefreshGiftData()
|
|
|
|
|
-- end) end, "取消", "确定",nil,true)
|
|
|
|
|
-- else
|
|
|
|
|
-- ShopManager.RequestBuyShopItem(shopType, itemId, 1, function()
|
|
|
|
|
-- self:RefreshGiftData()
|
|
|
|
|
-- end)
|
|
|
|
|
-- end
|
|
|
|
|
-- end
|
|
|
|
|
--end
|
|
|
|
|
function this.SortData(allData)
|
|
|
|
|
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 GiftBuy:OnClose()
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--界面销毁时调用(用于子类重写)
|
|
|
|
|
function GiftBuy:OnDestroy()
|
2021-04-21 13:12:04 +08:00
|
|
|
|
this.spLoader:Destroy()
|
2020-06-03 19:09:01 +08:00
|
|
|
|
|
|
|
|
|
sortingOrder = 0
|
2020-10-12 11:28:20 +08:00
|
|
|
|
itemsGrid = {}
|
2020-06-03 19:09:01 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return GiftBuy
|