miduo_client/Assets/ManagedResources/~Lua/View/ShopView.lua

646 lines
26 KiB
Lua
Raw Normal View History

2020-08-25 15:46:38 +08:00

2020-06-03 19:09:01 +08:00
local _ShopTypeConfig = ConfigManager.GetConfig(ConfigName.StoreTypeConfig)
2020-05-09 13:31:21 +08:00
-- 通用得商店逻辑
local ShopView = {}
local this = ShopView
this.sortingOrder = 0
local isPlayShow = true
2020-05-09 13:31:21 +08:00
---===============================生命周期函数================================
function this:New(gameObject)
local o = {}
this.__index = this
setmetatable(o, this)
o.gameObject = gameObject
o.transform = gameObject.transform
return o
end
--初始化组件(用于子类重写)
function this:InitComponent()
self.live = Util.GetGameObject(self.gameObject, "live")
self.liveRoot = Util.GetGameObject(self.gameObject, "live/root")
self.liveImg = Util.GetGameObject(self.gameObject, "live/img")
self.basePanel = Util.GetGameObject(self.gameObject, "base")
self.closeTimePanel = Util.GetGameObject(self.gameObject, "base/closeTime")
2020-06-18 20:39:29 +08:00
self.closeTimeLab = Util.GetGameObject(self.closeTimePanel, "timelab")
2020-05-09 13:31:21 +08:00
self.closeTime = Util.GetGameObject(self.closeTimePanel, "time")
self.refreshTimePanel = Util.GetGameObject(self.gameObject, "base/refreshTime")
self.refreshTimeLab = Util.GetGameObject(self.refreshTimePanel, "timelab")
self.refreshTime = Util.GetGameObject(self.refreshTimePanel, "time")
2020-06-18 20:39:29 +08:00
self.countTimePanel = Util.GetGameObject(self.gameObject, "base/countTime")
self.countTimeLab = Util.GetGameObject(self.countTimePanel, "timelab")
self.countTime = Util.GetGameObject(self.countTimePanel, "time")
2020-05-09 13:31:21 +08:00
self.refreshCountPanel = Util.GetGameObject(self.gameObject, "base/refreshCount")
2021-01-26 17:08:39 +08:00
self.countLabTip = Util.GetGameObject(self.refreshCountPanel, "GameObject/tip")
self.countLab = Util.GetGameObject(self.refreshCountPanel, "GameObject/count")
2020-05-09 13:31:21 +08:00
self.refreshBtnPanel = Util.GetGameObject(self.gameObject, "base/refreshBtn")
self.refreshBtn = Util.GetGameObject(self.refreshBtnPanel, "btn")
self.refreshRedpot = Util.GetGameObject(self.refreshBtnPanel, "redpot")
self.costIcon = Util.GetGameObject(self.refreshBtnPanel, "costIcon")
self.costLab = Util.GetGameObject(self.refreshBtnPanel, "costLab")
self.contentBg = Util.GetGameObject(self.gameObject, "duihua")
self.content = Util.GetGameObject(self.gameObject, "duihua/Text")
self.scrollBg = Util.GetGameObject(self.gameObject, "scrollbg")
self.scrollRoot = Util.GetGameObject(self.gameObject, "scrollbg/scrollroot")
self.scrollBg1 = Util.GetGameObject(self.gameObject, "scrollbg/bg1")
self.scrollBg2 = Util.GetGameObject(self.gameObject, "scrollbg/bg2")
self.scrollBg3 = Util.GetGameObject(self.gameObject, "scrollbg/bg3")
self.bottom = Util.GetGameObject(self.gameObject, "scrollbg/bottom")
self.tip = Util.GetGameObject(self.gameObject, "scrollbg/tip")
self.shopItem = Util.GetGameObject(self.gameObject, "scrollbg/scrollroot/shopItem")
self.rechargeShopItem = Util.GetGameObject(self.gameObject, "scrollbg/scrollroot/item")
self.titleBg = Util.GetGameObject(self.gameObject, "scrollbg/titlebg")
self.titleImg = Util.GetGameObject(self.gameObject, "scrollbg/titlebg/title")
this.helpBtn = Util.GetGameObject(self.gameObject, "scrollbg/titlebg/helpBtn")--scrollbg/titlebg/
this.helpPosition=this.helpBtn:GetComponent("RectTransform").localPosition
-- 创建循环列表
if not self.ScrollView then
self.ScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, self.scrollRoot.transform,
self.shopItem, nil, Vector2.New(1000, 1024), 1, 3, Vector2.New(80, 0))
self.ScrollView.moveTween.MomentumAmount = 1
self.ScrollView.moveTween.Strength = 2
end
-- 创建循环列表
if not self.RechargeScrollView then
self.RechargeScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, self.scrollRoot.transform,
self.rechargeShopItem, nil, Vector2.New(1000, 1024), 1, 3, Vector2.New(80, 0))
self.RechargeScrollView.moveTween.MomentumAmount = 1
self.RechargeScrollView.moveTween.Strength = 2
self.RechargeScrollView.gameObject.transform.localPosition = Vector3.New(0, -20, 0)
self.RechargeScrollView.elastic = false
end
end
--绑定事件(用于子类重写)
function this:BindEvent()
local localSelf = self
Util.AddOnceClick(self.refreshBtn, function()
PlaySoundWithoutClick("UI_refresh")
isPlayShow = true
2020-05-09 13:31:21 +08:00
local isPopUp = RedPointManager.PlayerPrefsGetStr(PlayerManager.uid .. localSelf.ShopType)
local currentTime = os.date("%Y%m%d", PlayerManager.serverTime)
2020-06-18 20:39:29 +08:00
local shopType = localSelf.ShopType
local isAutoRecover = ShopManager.IsAutoRecoverCount(shopType)
if (isPopUp ~= currentTime) and not isAutoRecover then
2020-05-09 13:31:21 +08:00
local shopInfo = ShopManager.GetShopInfoByType(shopType)
local costId, abcd = shopInfo.RefreshItem[1][1], shopInfo.RefreshItem[2]
local refreshNum = PrivilegeManager.GetPrivilegeUsedTimes(shopInfo.RefreshPrivilege)
local costNum = CalculateCostCount(refreshNum, abcd)
local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
2021-01-26 17:08:39 +08:00
local costName = GetLanguageStrById(itemConfig[costId].Name)
2021-01-27 18:16:54 +08:00
local str = string.format(Language[12030], costNum, costName)
2020-05-09 13:31:21 +08:00
MsgPanel.ShowTwo(str, function()
end, function(isShow)
if (isShow) then
local currentTime = os.date("%Y%m%d", PlayerManager.serverTime)
RedPointManager.PlayerPrefsSetStr(PlayerManager.uid .. localSelf.ShopType, currentTime)
end
ShopManager.RequestRefreshShop(shopType, false)
2021-01-27 18:16:54 +08:00
end, Language[10731], Language[10732],nil,true)
2020-05-09 13:31:21 +08:00
else
ShopManager.RequestRefreshShop(localSelf.ShopType, false)
end
-- 重置商店刷新按钮点击状态
ShopManager.SetShopRefreshBtnClickStatus(localSelf.ShopType, true)
end)
--帮助按钮
Util.AddOnceClick(this.helpBtn, function()
2020-06-03 19:09:01 +08:00
if self.ShopConfig.HelpId==0 then
2020-05-09 13:31:21 +08:00
return
end
2020-06-03 19:09:01 +08:00
UIManager.OpenPanel(UIName.HelpPopup, self.ShopConfig.HelpId , this.helpPosition.x,this.helpPosition.y+372)--因层级锚点原因,需手动调整高度
2020-05-09 13:31:21 +08:00
end)
end
--添加事件监听(用于子类重写)
function this:AddListener()
Game.GlobalEvent:AddEvent(GameEvent.Shop.OnShopInfoChange, self.RefreshShopInfo, self)
end
--移除事件监听(用于子类重写)
function this:RemoveListener()
Game.GlobalEvent:RemoveEvent(GameEvent.Shop.OnShopInfoChange, self.RefreshShopInfo, self)
end
--界面打开时调用(用于子类重写)
function this:OnOpen(...)
2020-09-04 16:54:58 +08:00
2020-05-09 13:31:21 +08:00
end
--界面关闭时调用(用于子类重写)
function this:OnClose()
if self._TimeCounter then
self._TimeCounter:Stop()
self._TimeCounter = nil
end
2020-09-04 16:54:58 +08:00
2020-05-09 13:31:21 +08:00
-- 物品节点回收
if self._GoodsItemList then
for _, item in pairs(self._GoodsItemList) do
Util.SetColor(item.gameObject, Color.New(1,1,1,1))
Util.SetGray(item.gameObject, false)
SubUIManager.Close(item)
end
self._GoodsItemList = {}
2020-05-09 13:31:21 +08:00
end
-- 红点销毁
2020-07-17 11:32:20 +08:00
-- if self.ShopType == SHOP_TYPE.GENERAL_SHOP then
-- ClearRedPointObject(RedPointType.Shop_General_Refresh)
-- end
2020-05-09 13:31:21 +08:00
if self.ScrollView then
GameObject.DestroyImmediate(self.ScrollView.gameObject)
self.ScrollView = nil
end
if self.RechargeScrollView then
GameObject.DestroyImmediate(self.RechargeScrollView.gameObject)
self.RechargeScrollView = nil
end
if self.liveNode then
2020-06-03 19:09:01 +08:00
poolManager:UnLoadLive(self.LiveName, self.liveNode)
2020-05-09 13:31:21 +08:00
self.liveNode = nil
end
end
---=================================工具函数==========================================
-- 设置文本透明度
local function SetAlpha(text, a)
local color = text.color
color.a = a
text.color = color
end
---===================================内部函数========================================
-- 刷新商店内容显示
function this:RefreshShopInfo(isRefresh, isTop)
if self.ShopType == SHOP_TYPE.SOUL_STONE_SHOP then
self.RechargeShopData = OperatingManager.GetGiftGoodsInfoList(GoodsTypeDef.DemonCrystal)
else
self.ShopData = ShopManager.GetShopDataByType(self.ShopType)
end
self:RefreshLive()
self:RefreshBase()
self:RefreshItemList(isTop)
-- 刷新商店的查看时间
ShopManager.RefreshShopCheckTime(self.ShopType)
if isRefresh then
-- 物品节点播放特效
if self._GoodsItemList then
for _, item in pairs(self._GoodsItemList) do
item:OnShowUIeffectItemViewSaoguang()
end
2020-05-09 13:31:21 +08:00
end
end
end
-- 刷新立绘显示
function this:RefreshLive()
2020-06-03 19:09:01 +08:00
if not self.ShopConfig.LiveName or self.ShopConfig.LiveName == "" then
2020-05-09 13:31:21 +08:00
self.live:SetActive(false)
return
end
self.live:SetActive(true)
self.liveImg:SetActive(false)
self.liveRoot:SetActive(false)
-- 立绘
2020-06-03 19:09:01 +08:00
--TODO:动态加载立绘
self.liveRoot:SetActive(true)
2020-05-09 13:31:21 +08:00
2020-06-03 19:09:01 +08:00
if self.liveNode then
poolManager:UnLoadLive(self.LiveName, self.liveNode)
end
local scale = self.ShopConfig.LiveScale
scale = Vector3.New(scale[1], scale[2], scale[3])
local livePos = Vector3.zero
if self.ShopConfig.LivePos then
livePos.x = self.ShopConfig.LivePos[1]
livePos.y = self.ShopConfig.LivePos[2]
end
2020-05-09 13:31:21 +08:00
2020-06-03 19:09:01 +08:00
self.LiveName = self.ShopConfig.LiveName
self.liveNode = poolManager:LoadLive(self.ShopConfig.LiveName, self.liveRoot.transform, scale, livePos)
local SkeletonGraphic = self.liveNode:GetComponent("SkeletonGraphic")
local idle = function()
2020-05-09 13:31:21 +08:00
SkeletonGraphic.AnimationState:SetAnimation(0, "idle", true)
end
2020-06-03 19:09:01 +08:00
SkeletonGraphic.AnimationState:SetAnimation(0, "idle", true)
SkeletonGraphic.AnimationState.Complete = SkeletonGraphic.AnimationState.Complete + idle
poolManager:SetLiveClearCall(self.ShopConfig.LiveName, self.liveNode, function()
SkeletonGraphic.AnimationState.Complete = SkeletonGraphic.AnimationState.Complete - idle
end)
2020-05-09 13:31:21 +08:00
end
-- 开始倒计时
function this:StartTimeCount()
local localSelf = self
local function _TimeUpdate()
-- 检测计时器是否已销毁,避免计时器销毁后仍然会执行一次,导致报错的问题
if not localSelf._TimeCounter then
return
end
2020-06-18 20:39:29 +08:00
-- 刷新时间
if localSelf.isShowRefreshTime then
local refreshTime = ShopManager.GetShopRefreshLeftTime(localSelf.ShopType)
if refreshTime >= 0 then
localSelf.refreshTime:GetComponent("Text").text = TimeToHMS(refreshTime)
end
end
2020-05-09 13:31:21 +08:00
-- 关闭时间
2020-06-18 20:39:29 +08:00
if localSelf.isShowCloseTime then
2020-05-09 13:31:21 +08:00
local closeTime = ShopManager.GetShopCloseTime(localSelf.ShopType)
if closeTime >= 0 then
local timeStr = ""
2020-06-18 20:39:29 +08:00
-- if localSelf.ShopType == SHOP_TYPE.ACTIVITY_SHOP then
-- timeStr = TimeToDHMS(closeTime)
-- else
2020-05-09 13:31:21 +08:00
timeStr = TimeToHMS(closeTime)
2020-06-18 20:39:29 +08:00
-- end
2020-05-09 13:31:21 +08:00
localSelf.closeTime:GetComponent("Text").text = timeStr
end
end
2020-06-18 20:39:29 +08:00
-- 次数恢复时间
if localSelf.isShowCountTime then
local refreshTime = ShopManager.GetShopRefreshCountRecoverTime(localSelf.ShopType)
local maxTime = ShopManager.GetMaxRefreshCount(localSelf.ShopType)
local isAutoRecover, leftTime = ShopManager.IsAutoRecoverCount(localSelf.ShopType)
if refreshTime > 0 then
localSelf.countTime:GetComponent("Text").text = TimeToHMS(refreshTime)
2020-07-01 09:40:20 +08:00
elseif isAutoRecover and maxTime == leftTime and not localSelf.isMaxTime then
-- localSelf:RefreshBase()
2021-01-27 18:16:54 +08:00
localSelf.countTime:GetComponent("Text").text = Language[12031]
localSelf.countLabTip:GetComponent("Text").text = Language[12032]
2020-07-01 09:40:20 +08:00
localSelf.countLab:GetComponent("Text").text = leftTime
localSelf.isMaxTime = true
2020-06-18 20:39:29 +08:00
elseif isAutoRecover and maxTime ~= leftTime and refreshTime == 0 then
localSelf:RefreshBase()
2020-07-01 09:40:20 +08:00
localSelf.isMaxTime = false
2020-05-09 13:31:21 +08:00
end
end
end
-- 开始吧
if not self._TimeCounter then
self._TimeCounter = Timer.New(_TimeUpdate, 1, -1, true)
self._TimeCounter:Start()
end
-- 刷新一次
_TimeUpdate()
end
-- 刷新时间及刷新按钮
function this:RefreshBase()
2020-06-18 20:39:29 +08:00
-- 自动刷新时间倒计时
local leftTime = ShopManager.GetShopRefreshLeftTime(self.ShopType)
self.isShowRefreshTime = leftTime >= 0
self.refreshTimePanel:SetActive(self.isShowRefreshTime)
2020-05-09 13:31:21 +08:00
-- 商店关闭时间倒计时
local closeTime = ShopManager.GetShopCloseTime(self.ShopType)
2020-06-18 20:39:29 +08:00
self.isShowCloseTime = closeTime >= 0 and not self.isShowRefreshTime
self.closeTimePanel:SetActive(self.isShowCloseTime)
if self.isShowCloseTime then
2020-05-09 13:31:21 +08:00
if self.ShopType == SHOP_TYPE.ARENA_SHOP or self.ShopType == SHOP_TYPE.TOP_MATCH_SHOP then
2021-01-27 18:16:54 +08:00
self.closeTimeLab:GetComponent("Text").text = Language[12033]
2020-05-09 13:31:21 +08:00
else
2021-01-27 18:16:54 +08:00
self.closeTimeLab:GetComponent("Text").text = Language[12034]
2020-05-09 13:31:21 +08:00
end
end
2020-06-18 20:39:29 +08:00
-- 次数恢复时间
local countTime = ShopManager.GetShopRefreshCountRecoverTime(self.ShopType)
self.isShowCountTime = countTime >= 0
self.countTimePanel:SetActive(self.isShowCountTime)
2020-05-09 13:31:21 +08:00
--开始倒计时
self:StartTimeCount()
-- 主动刷新按钮
local leftCount = ShopManager.GetShopLeftRefreshCount(self.ShopType)
if leftCount == -2 then
-- 不支持刷新
self.refreshCountPanel:SetActive(false)
self.refreshBtnPanel:SetActive(false)
else
2020-06-18 20:39:29 +08:00
self.refreshBtnPanel:SetActive(true)
2020-05-09 13:31:21 +08:00
if leftCount == -1 then
-- 无限制次数刷新
self.refreshCountPanel:SetActive(false)
elseif leftCount >= 0 then
-- 限制次数刷新
self.refreshCountPanel:SetActive(true)
self.countLab:GetComponent("Text").text = leftCount
end
2020-06-18 20:39:29 +08:00
local isAutoRecover = ShopManager.IsAutoRecoverCount(self.ShopType)
if isAutoRecover then
self.costIcon:SetActive(false)
self.costLab:SetActive(false)
2021-01-27 18:16:54 +08:00
self.countLabTip:GetComponent("Text").text = Language[12032]
2020-07-01 18:14:03 +08:00
self.isMaxTime = false
2020-06-18 20:39:29 +08:00
else
self.costIcon:SetActive(true)
self.costLab:SetActive(true)
2021-01-27 18:16:54 +08:00
self.countLabTip:GetComponent("Text").text = Language[12035]
2020-06-18 20:39:29 +08:00
-- 刷新物品计算
local shopInfo = ShopManager.GetShopInfoByType(self.ShopType)
local costId, abcd = shopInfo.RefreshItem[1][1], shopInfo.RefreshItem[2]
self.costIcon:GetComponent("Image").sprite = SetIcon(costId)
-- 商店特权正确性检测
if not shopInfo.RefreshPrivilege or shopInfo.RefreshPrivilege == 0 then
Log("错误:商店类型 == " .. self.ShopType .. "商店支持手动刷新但是未配置刷新次数对应的特权id无限制次数也需要配置特权id请检查")
2020-06-18 20:39:29 +08:00
end
local refreshNum = PrivilegeManager.GetPrivilegeUsedTimes(shopInfo.RefreshPrivilege)
self.costLab:GetComponent("Text").text = "×" .. CalculateCostCount(refreshNum, abcd)
2020-05-09 13:31:21 +08:00
end
end
2020-06-18 20:39:29 +08:00
2020-05-09 13:31:21 +08:00
-- 商店标题
2020-06-03 19:09:01 +08:00
if self.ShopConfig.Title and self.ShopConfig.Title ~= "" then
self.titleImg:GetComponent("Image").sprite = Util.LoadSprite(self.ShopConfig.Title)
end
2020-05-09 13:31:21 +08:00
-- 对话显示
2020-06-03 19:09:01 +08:00
-- if self.ShopConfig.content then
-- self.contentBg:SetActive(true)
-- self.content:GetComponent("Text").text = self.ShopConfig.content
-- self.contentBg.transform.localPosition = Vector3(self.ShopConfig.contentPos[1], self.ShopConfig.contentPos[2], 0)
-- else
2020-05-09 13:31:21 +08:00
self.contentBg:SetActive(false)
2020-06-03 19:09:01 +08:00
-- end
2020-05-09 13:31:21 +08:00
end
-- 刷新物品列表
function this:RefreshItemList(isTop)
if self.ShopType == SHOP_TYPE.SOUL_STONE_SHOP then
self.ScrollView.gameObject:SetActive(false)
self.RechargeScrollView.gameObject:SetActive(true)
local itemlist = self.RechargeShopData
self.RechargeScrollView:SetData(itemlist, function(index, shopItem)
local itemData = itemlist[index]
self:RechargeShopItemAdapter(shopItem, itemData)
-- if isPlayShow then
-- shopItem.gameObject:SetActive(false)
-- end
end, not isTop)
-- if isPlayShow then
-- SecTorPlayAnimByScroll(self.RechargeScrollView,0.03)
-- isPlayShow = false
-- end
2020-05-09 13:31:21 +08:00
else
-- 重置列表
self.RechargeScrollView.gameObject:SetActive(false)
self.ScrollView.gameObject:SetActive(true)
local itemlist = ShopManager.CheckShopItemList(self.ShopData.storeItem)
2020-05-09 13:31:21 +08:00
self.ScrollView:SetData(itemlist, function(index, shopItem)
local itemData = itemlist[index]
self:ShopItemAdapter(shopItem, itemData)
if isPlayShow then
shopItem.gameObject:SetActive(true)
end
end, not isTop)
-- if isPlayShow then
-- -- SecTorPlayAnimByScroll(self.ScrollView, 0.03)
-- isPlayShow = false
-- end
2020-05-09 13:31:21 +08:00
end
end
-- 商店物品数据匹配
function this:ShopItemAdapter(shopItem, itemData)
-- 获取对象
2021-01-26 17:08:39 +08:00
local bg = Util.GetGameObject(shopItem, "GameObject/bg")
2020-05-09 13:31:21 +08:00
local item = Util.GetGameObject(bg, "item")
local itemName = Util.GetGameObject(bg, "itemName"):GetComponent("Text")
local limitBg = Util.GetGameObject(bg, "buyLimitbg")
2021-01-26 17:08:39 +08:00
local limitTip = Util.GetGameObject(limitBg, "tip"):GetComponent("Text")
2020-05-09 13:31:21 +08:00
local priceBg = Util.GetGameObject(bg, "pricebg")
local itemPrice = Util.GetGameObject(bg, "pricebg/price"):GetComponent("Text")
local costIcon = Util.GetGameObject(bg, "pricebg/costIcon"):GetComponent("Image")
local discountbg = Util.GetGameObject(bg, "discountbg")
local empty = Util.GetGameObject(shopItem, "empty")
local lock = Util.GetGameObject(shopItem, "lock")
local lockTip = Util.GetGameObject(shopItem, "lock/tip"):GetComponent("Text")
-- 计算数据
local itemInfo = ShopManager.GetShopItemInfo(itemData.id)
local curBuyCount = itemData.buyNum
local maxLimitCount = ShopManager.GetShopItemLimitBuyCount(itemData.id)
local costId, price = ShopManager.calculateBuyCost(self.ShopType, itemData.id, 1)
2020-05-25 19:16:23 +08:00
local goods = ShopManager.GetShopItemGoodsInfo(itemData.id)
2021-01-26 17:08:39 +08:00
itemName.text = SubString2(GetLanguageStrById(ConfigManager.GetConfigData(ConfigName.ItemConfig,goods[1][1]).Name),8)--itemInfo.GoodsName
2020-05-09 13:31:21 +08:00
-- 折扣
if price == 0 then
discountbg:SetActive(true)
2021-01-26 17:08:39 +08:00
discountbg:GetComponent("Image").sprite = Util.LoadSprite("s_shop_zhekou_00_zh")
2020-05-09 13:31:21 +08:00
else
local isDiscount = itemInfo.IsDiscount == 1
discountbg:SetActive(isDiscount)
if isDiscount then
2021-01-26 17:08:39 +08:00
discountbg:GetComponent("Image").sprite = Util.LoadSprite("s_shop_zhekou_0" .. itemInfo.DiscountDegree.."_zh")
2020-05-09 13:31:21 +08:00
end
end
-- 消耗物品的信息
2020-06-30 18:59:44 +08:00
itemPrice.text = PrintWanNum2(tonumber(price))--tostring(price)
2020-05-09 13:31:21 +08:00
costIcon.sprite = SetIcon(costId)
-- 判断商品栏位是否解锁
local _IsUnLock = true
if self.ShopType == SHOP_TYPE.GUILD_SHOP then
local isUnLock, unLockLevel = MyGuildManager.GetGuildShopSortIsUnLock(itemInfo.Sort)
if not isUnLock then
_IsUnLock = false
2021-01-27 18:16:54 +08:00
lockTip.text = string.format(Language[12036], unLockLevel)
2020-05-09 13:31:21 +08:00
end
end
lock:SetActive(not _IsUnLock)
priceBg.gameObject:SetActive(_IsUnLock)
itemName.gameObject:SetActive(_IsUnLock)
2021-01-26 17:08:39 +08:00
-- -- 限购
2020-05-09 13:31:21 +08:00
limitBg:SetActive(maxLimitCount ~= -1)
2021-01-27 18:16:54 +08:00
limitTip.text =Language[12037].." "..maxLimitCount.." "..Language[10048]
2021-01-26 17:08:39 +08:00
SetTextVerTial(limitTip,Vector3.New(12.65,-4.2,0),"MiddleLeft")
2020-05-09 13:31:21 +08:00
-- 售空 限购次数为-1 表示不限购
local isEmpty = maxLimitCount ~= -1 and curBuyCount >= maxLimitCount
if curBuyCount >= maxLimitCount then
empty:SetActive(true)
else
empty:SetActive(false)
end
empty:SetActive(isEmpty)
-- 数据匹配
if not self._GoodsItemList then
self._GoodsItemList = {}
2020-05-09 13:31:21 +08:00
end
if not self._GoodsItemList[shopItem] then
self._GoodsItemList[shopItem] = SubUIManager.Open(SubUIConfig.ItemView, item.transform)
end
Util.SetGray(self._GoodsItemList[shopItem].gameObject, not _IsUnLock)
2020-05-09 13:31:21 +08:00
if isEmpty or not _IsUnLock then -- 物品空或者未解锁不现实物品特效
self._GoodsItemList[shopItem]:OnOpen(false, goods[1],1,false,false,false)
2020-05-09 13:31:21 +08:00
else
self._GoodsItemList[shopItem]:OnOpen(false, goods[1],1,false,false,false,this.sortingOrder)
2020-05-09 13:31:21 +08:00
end
-- 商品颜色显示
local imgColor = isEmpty and Color.New(0.5, 0.5, 0.5, 1) or Color.New(1, 1, 1, 1)
local textA = isEmpty and 0.7 or 1
Util.SetColor(bg, imgColor)
SetAlpha(itemName, textA)
2021-01-26 17:08:39 +08:00
--SetAlpha(limitTip, textA)
2020-05-09 13:31:21 +08:00
SetAlpha(itemPrice, textA)
2021-01-26 17:08:39 +08:00
2020-05-09 13:31:21 +08:00
-- 购买事件
Util.AddOnceClick(lock, function()
2021-01-27 18:16:54 +08:00
PopupTipPanel.ShowTip(Language[12038])
2020-05-09 13:31:21 +08:00
end)
Util.AddOnceClick(empty, function()
2021-01-27 18:16:54 +08:00
PopupTipPanel.ShowTip(Language[12039])
2020-05-09 13:31:21 +08:00
end)
Util.AddOnceClick(bg, function()
-- 售空
if isEmpty then
2021-01-27 18:16:54 +08:00
PopupTipPanel.ShowTip(Language[12039])
2020-05-09 13:31:21 +08:00
return
end
if not _IsUnLock then
2021-01-27 18:16:54 +08:00
PopupTipPanel.ShowTip(Language[12038])
2020-05-09 13:31:21 +08:00
return
end
UIManager.OpenPanel(UIName.ShopBuyPopup, self.ShopType, itemData.id)
end)
end
-- 妖晶商店物品数据匹配
function this:RechargeShopItemAdapter(shopItem, itemData)
-- 获取对象
local first = Util.GetGameObject(shopItem, "first")
local firstNum = Util.GetGameObject(shopItem, "first/Text"):GetComponent("Text")
local icon = Util.GetGameObject(shopItem, "icon"):GetComponent("Image")
local num = Util.GetGameObject(shopItem, "itemName"):GetComponent("Text")
local price = Util.GetGameObject(shopItem, "price/Text"):GetComponent("Text")
-- 计算数据
local itemInfo = ShopManager.GetRechargeItemInfo(itemData.goodsId)
icon.sprite = Util.LoadSprite(GetResourcePath(itemInfo.Resources))
2021-01-26 17:08:39 +08:00
num.text = GetLanguageStrById(itemInfo.Name)
2020-08-22 15:31:14 +08:00
price.text = MoneyUtil.GetMoneyMark() .. MoneyUtil.GetMoney(itemInfo.Price)
2020-05-09 13:31:21 +08:00
-- 判断首充赠送
local curBuyCount = itemData.buyTimes
first:SetActive(curBuyCount < 1)
firstNum.text = itemInfo.FirstMultiple[1][2]
-- 购买事件
Util.AddOnceClick(shopItem, function()
PayManager.Pay(itemData.goodsId, function(id)
self:RechargeSuccessFunc(itemData.goodsId)
end)
2020-05-09 13:31:21 +08:00
end)
2020-05-09 13:31:21 +08:00
end
-- 充值成功回调
function this:RechargeSuccessFunc(id)
FirstRechargeManager.RefreshAccumRechargeValue(id)
OperatingManager.RefreshGiftGoodsBuyTimes(GoodsTypeDef.DemonCrystal, id)
self:RefreshShopInfo(false, false)
--PopupTipPanel.ShowTip("购买成功,请到邮箱中领取!")
PlayerPrefs.SetInt(PlayerManager.uid.."czlb", 0)
CheckRedPointStatus(RedPointType.GrowthPackage)--成长礼包红点检测
2020-05-09 13:31:21 +08:00
end
---=====================================对外接口=============================----
-- 设置要显示的商店类型
function this:ShowShop(shopType,_sortingOrder)
2020-09-04 16:54:58 +08:00
self.ScrollView:ForeachItemGO(function (index, go)
go.gameObject:SetActive(false)
end)
2020-12-23 17:28:20 +08:00
-- self.titleBg:GetComponent("Canvas").sortingOrder = _sortingOrder + 1
2020-05-09 13:31:21 +08:00
this.sortingOrder = _sortingOrder
-- 红点销毁
self.refreshRedpot:SetActive(false)
2020-07-17 11:32:20 +08:00
-- if self.ShopType == SHOP_TYPE.GENERAL_SHOP then
-- ClearRedPointObject(RedPointType.Shop_General_Refresh)
-- end
2020-05-09 13:31:21 +08:00
-- 绑定新红点
2020-07-17 11:32:20 +08:00
-- if shopType == SHOP_TYPE.GENERAL_SHOP then
-- BindRedPointObject(RedPointType.Shop_General_Refresh, self.refreshRedpot)
-- end
2020-05-09 13:31:21 +08:00
-- 刷新显示
self.ShopType = shopType
isPlayShow = true
2020-06-03 19:09:01 +08:00
self.ShopId = ShopManager.GetShopDataByType(self.ShopType).id
self.ShopConfig = _ShopTypeConfig[self.ShopId]
2020-05-09 13:31:21 +08:00
-- 显示帮助按钮
2020-06-03 19:09:01 +08:00
self.helpBtn:SetActive(self.ShopConfig.HelpId ~= 0)
2020-05-09 13:31:21 +08:00
self:RefreshShopInfo(false, true)
-- 设置tip显隐
local isSSSHop = self.ShopType == SHOP_TYPE.SOUL_STONE_SHOP
self.scrollBg1:SetActive(not isSSSHop)
self.scrollBg2:SetActive(not isSSSHop)
self.titleBg:SetActive(not isSSSHop)
self.bottom:SetActive(not isSSSHop)
self.scrollBg3:SetActive(isSSSHop)
self.tip:SetActive(isSSSHop)
end
-- 设置立绘位置
function this:SetLivePosition(pos)
-- 计算位置
if not pos then
return
end
2020-06-03 19:09:01 +08:00
if not self.liveNode then
return
2020-05-09 13:31:21 +08:00
end
2020-06-03 19:09:01 +08:00
self.liveNode.transform.localPosition = pos
2020-05-09 13:31:21 +08:00
end
-- 设置商店物品栏位置
function this:SetItemContentPosition(pos)
-- 计算位置
if not pos then
return
end
self.scrollBg.gameObject:GetComponent("RectTransform").anchoredPosition = Vector2.New(pos.x, pos.y)
--self.scrollBg.transform.localPosition = pos
end
-- 设置基础信息位置
function this:SetBasePanelPostion(pos)
self.basePanel:GetComponent("RectTransform").anchoredPosition = pos
end
-- 设置层级
function this:SetSortLayer(sortLayer)
if not self._GoodsItemList then
self._GoodsItemList = {}
end
2020-05-09 13:31:21 +08:00
--
-- Log("sortLayer _GoodsItemList "..sortLayer.." "..LengthOfTable(self._GoodsItemList))
for _, item in pairs(self._GoodsItemList) do
2020-05-09 13:31:21 +08:00
item:SetEffectLayer(sortLayer)--this.sortingOrder)
end
2020-12-23 17:28:20 +08:00
-- self.titleBg:GetComponent("Canvas").sortingOrder = sortLayer + 1
2020-05-09 13:31:21 +08:00
-- 保存层级
this.sortingOrder = sortLayer
end
2020-06-23 18:36:24 +08:00
return this