miduo_client/Assets/ManagedResources/~Lua/Modules/Recharge/View/GiftPre.lua

434 lines
18 KiB
Lua
Raw Normal View History

2021-04-21 13:12:04 +08:00
GiftPre = {}
local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
local parent
function GiftPre:New(gameObject)
local b = {}
b.gameObject = gameObject
b.transform = gameObject.transform
setmetatable(b, { __index = GiftPre })
return b
end
local rechargeNum
local offSetX = {
2021-03-30 10:48:34 +08:00
[0] = {
icon = Vector3.New(336,-27,0),
txt = Vector3.New(407,-31.5,0),
ima = Vector3.New(315.5,-32,0),
txt1 = Vector3.New(158,-31.5,0),
icon1 = Vector3.New(95,-27,0),
scroll = Vector3.New(-306.21,67.1,0),
},
[1] = {
2021-04-07 16:38:26 +08:00
icon = Vector3.New(513,-24,0),
txt = Vector3.New(575,-32,0),
2021-03-30 10:48:34 +08:00
ima = Vector3.New(20.19,0,0),
2021-04-07 16:38:26 +08:00
txt1 = Vector3.New(134,-32,0),
icon1 = Vector3.New(80.39999,-24,0),
2021-03-30 10:48:34 +08:00
scroll = Vector3.New(-254,71.9,0),
},
2021-04-07 16:38:26 +08:00
[2] = { icon = Vector3.New(316.7,-23,0),
txt = Vector3.New(373.1,-32.69999,0),
2021-03-30 10:48:34 +08:00
ima = Vector3.New(30,0,0),
2021-04-07 16:38:26 +08:00
txt1 = Vector3.New(179,-32.69999,0),
icon1 = Vector3.New(129,-23,0)
2021-03-30 10:48:34 +08:00
}
}
--初始化组件(用于子类重写)
function GiftPre:InitComponent()
2021-04-21 13:12:04 +08:00
self.spLoader = SpriteLoader.New()
self.upLayout = Util.GetGameObject(self.gameObject, "bg/upLayout")
self.middleLayout = Util.GetGameObject(self.gameObject, "bg/middleLayout")
self.tipImage = Util.GetGameObject(self.upLayout, "tipImage")
self.tipText = Util.GetGameObject(self.tipImage, "Text"):GetComponent("Text")
self.tagIma = Util.GetGameObject(self.upLayout, "tag")
self.tagText = Util.GetGameObject(self.tagIma, "tagTxt"):GetComponent("Text")
self.type1 = Util.GetGameObject(self.upLayout, "type1")
self.type1Text1 = Util.GetGameObject(self.type1, "text1"):GetComponent("Text")
self.type1Text3 = Util.GetGameObject(self.type1, "text3"):GetComponent("Text")
self.numGrid = Util.GetGameObject(self.type1, "NumTextPre")
self.numList = {}
for i = 1, self.numGrid.transform.childCount do
table.insert(self.numList,self.numGrid.transform:GetChild(i-1):GetComponent("Text"))
end
if not self.moneyNum then
self.moneyNum = SubUIManager.Open(SubUIConfig.MoneyNumView, self.type1.transform,
0, MoneyNumViewType.Image_Horizontal, "ArtFont_1_cfont", 42, 1, Vector2.New(46, 46), Vector2.New(0, -25), MoneyNumViewImageType.Small_1)
end
self.moneyNum:SetOffsetPosition(Vector2.New(0, 0))
self.moneyNum.transform:SetSiblingIndex(2)
self.type2 = Util.GetGameObject(self.upLayout, "type2")
self.type2Ima = Util.GetGameObject(self.upLayout, "Image")
self.type2Icon1 = Util.GetGameObject(self.type2, "icon_1")
self.type2Text1 = Util.GetGameObject(self.type2, "text1"):GetComponent("Text")
self.type2Icon2 = Util.GetGameObject(self.type2, "icon_2")
self.type2Text2 = Util.GetGameObject(self.type2, "text2"):GetComponent("Text")
self.btnBuy = Util.GetGameObject(self.middleLayout, "btnBuy")
self.icon = Util.GetGameObject(self.btnBuy, "icon"):GetComponent("Image")
self.price = Util.GetGameObject(self.btnBuy, "price"):GetComponent("Text")
self.buyInfo = Util.GetGameObject(self.middleLayout, "buyInfo"):GetComponent("Text")
self.redPoint = Util.GetGameObject(self.btnBuy, "redPoint")
self.shadow=Util.GetGameObject(self.middleLayout,"shadow")
self.grid = Util.GetGameObject(self.middleLayout, "scrollView/grid")
2021-03-30 10:48:34 +08:00
self.redpot = Util.GetGameObject(self.gameObject, "bg/redpot")
2021-03-30 18:26:10 +08:00
self.UI_Effect_MianBan_LiBao_button_01 = Util.GetGameObject(self.gameObject, "UI_Effect_MianBan_LiBao_button_01")
self.isCanBuy = 0
self.itemList = {}
2021-03-31 18:38:57 +08:00
self.tipRoot = Util.GetGameObject(self.upLayout,"type3")
self.tip1 = Util.GetGameObject(self.tipRoot,"tip1")
self.tip1_en = Util.GetGameObject(self.tipRoot,"tip1_en")
self.tip2 = Util.GetGameObject(self.tipRoot,"tip2")
self.tip2_en = Util.GetGameObject(self.tipRoot,"tip2_en")
self.tip3 = Util.GetGameObject(self.tipRoot,"tip3")
self.tip3_en = Util.GetGameObject(self.tipRoot,"tip3_en")
self.tip4 = Util.GetGameObject(self.tipRoot,"tip4")
self.tip4_en = Util.GetGameObject(self.tipRoot,"tip4_en")
self.tip5 = Util.GetGameObject(self.tipRoot,"tip5")
self.tip5Text = Util.GetGameObject(self.tip5,"Text"):GetComponent("Text")
end
--绑定事件(用于子类重写)
function GiftPre:BindEvent()
Util.AddOnceClick(self.btnBuy, function()
if self.isCanBuy == 1 then -- 0 可购买 1购买条件不足 2已购买
2021-04-09 12:26:35 +08:00
PopupTipPanel.ShowTip(Language[11701])
elseif self.isCanBuy == 2 then
2021-04-09 12:26:35 +08:00
PopupTipPanel.ShowTip(Language[10515])
else
--道具商品
if self.data.DataType == DataType.Shop then
self:BuyAction(self.data.data.costId, self.data.data.finalNum, self.data.buyType, self.data.data.shopData.id)--特权商城
CheckRedPointStatus(RedPointType.GrowthPackage)
else
--直购商品
PayManager.Pay(self.data.data.shopData.goodsId, function(id)
FirstRechargeManager.RefreshAccumRechargeValue(self.data.data.shopData.goodsId)
CheckRedPointStatus(RedPointType.DailyGift)
2021-03-30 10:48:34 +08:00
CheckRedPointStatus(RedPointType.WeekGiftPage)
CheckRedPointStatus(RedPointType.MonthGiftPage)
CheckRedPointStatus(RedPointType.GrowthPackage)
self.parent:RefreshData(nil,false,false)
end)
end
end
end)
end
--购买点击事件
function GiftPre:BuyAction(costId, costNum, shopType, itemId)
local haveNum = BagManager.GetItemCountById(costId)
local costName = ConfigManager.GetConfigData(ConfigName.ItemConfig, costId).Name
--Log("需要消耗的道具ID" .. costId)
if haveNum < costNum then
NotEnoughPopup:Show(costId)
else
local func = function(shopType, itemId)
ShopManager.RequestBuyShopItem(shopType, itemId, 1, function()
self.parent:RefreshData(nil,false,false)
CheckRedPointStatus(RedPointType.DailyGift)
CheckRedPointStatus(RedPointType.GrowthPackage)
2021-06-02 15:12:44 +08:00
if shopType==20 and (itemId==1107 or itemId==1110 or itemId==1111 or itemId==1108 )then
PlayerPrefs.SetString(PlayerManager.uid..PlayerManager.serverInfo.server_id.."supermeMan",666)
end
end)
end
local isPopUp = RedPointManager.PlayerPrefsGetStr(PlayerManager.uid .. shopType)
local currentTime = os.date("%Y%m%d", PlayerManager.serverTime)
if (isPopUp ~= currentTime and costNum ~= 0) then
2021-04-09 12:26:35 +08:00
local str = string.format(Language[11360], 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
func(shopType, itemId)
end,
2021-04-09 12:26:35 +08:00
Language[10731],
Language[10732],
nil,
true)
else
func(shopType, itemId)
end
end
end
--添加事件监听(用于子类重写)
function GiftPre:AddListener()
end
--移除事件监听(用于子类重写)
function GiftPre:RemoveListener()
end
function GiftPre:OnOpen()
end
function GiftPre:SetData(data,_parent,_rechargeNum,sortingOrder)
rechargeNum = _rechargeNum
self.data = data
self.parent = _parent
Util.SetParticleSortLayer(self.UI_Effect_MianBan_LiBao_button_01, sortingOrder + 1 or 1)
2021-04-01 15:42:59 +08:00
self:SetTag()
self:SetTipTag()
--设置礼包内容
if not self.itemList then
self.itemList = {}
end
for i = 1, #self.itemList do
self.itemList[i].gameObject:SetActive(false)
end
for i = 1, #self.data.data.shows do
if not self.itemList[i] then
self.itemList[i] = SubUIManager.Open(SubUIConfig.ItemView,self.grid.transform)
self.itemList[i].gameObject:SetActive(false)
end
self.itemList[i]:OnOpen(false, {self.data.data.shows[i][1],self.data.data.shows[i][2],self.data.data.shows[i][3]}, 0.9,false,false,false,sortingOrder)
self.itemList[i].gameObject:SetActive(true)
end
2021-04-01 15:42:59 +08:00
--设置按钮
self:SetBtn(self.data)
--设置礼包标题
self:SetContent1()
--设置特效
self:Effect()
end
--设置礼包名称(红色标签)
function GiftPre:SetTag()
if self.data.data.tagName and self.data.data.tagName ~= "" and not (self.data.DataType == DataType.Shop and self.data.buyType == SHOP_TYPE.VIP_GIFT) then
self.tagIma.gameObject:SetActive(true)
self.tagText.text = self.data.data.tagName
else
self.tagIma.gameObject:SetActive(false)
end
end
--设置礼包限购标签
function GiftPre:SetTipTag()
if self.data.data.tipImageText and self.data.data.tipImageText ~= "" then
self.tipImage.gameObject:SetActive(true)
self.tipText.text = self.data.data.tipImageText
else
self.tipImage.gameObject:SetActive(false)
end
2021-03-31 17:55:33 +08:00
end
function GiftPre:Effect()
2021-03-30 18:26:10 +08:00
local isshow = false
2021-04-28 05:10:00 +08:00
if self.data.DataType == DynamicActivityManager.selectIndex2.dataType then
for i = 1 , #DynamicActivityManager.selectIndex2.goodsId do
if (self.data.data.shopData.id or self.data.data.shopData.goodsId) == DynamicActivityManager.selectIndex2.goodsId[i] then
2021-03-30 18:26:10 +08:00
isshow = true
break
end
end
end
2021-03-31 17:55:33 +08:00
if self.isCanBuy == 2 then
isshow = false
end
2021-03-30 18:26:10 +08:00
self.UI_Effect_MianBan_LiBao_button_01.gameObject:SetActive(isshow)
end
function GiftPre:SetContent1()
2021-03-30 10:48:34 +08:00
self.upLayout.gameObject:SetActive(true)
self.grid:GetComponent("RectTransform").anchoredPosition = offSetX[0].scroll
self.type1.gameObject:SetActive(false)
self.type2.gameObject:SetActive(false)
2021-03-31 19:56:31 +08:00
self.tipRoot:SetActive(false)
self.tip1:SetActive(false)
self.tip2:SetActive(false)
self.tip3:SetActive(false)
self.tip4:SetActive(false)
self.tip5:SetActive(false)
2021-04-01 15:42:59 +08:00
self.tip1_en:SetActive(false)
self.tip2_en:SetActive(false)
self.tip3_en:SetActive(false)
self.tip4_en:SetActive(false)
2021-04-14 12:00:06 +08:00
if self.data.DataType == DataType.Direct and self.data.buyType == DirectBuyType.DAILY_GIFT then--每日礼包
2021-04-01 15:42:59 +08:00
self:SetType2()
2021-05-10 10:06:53 +08:00
elseif self.data.DataType == DataType.Direct and (self.data.buyType == DirectBuyType.WEEK_GIFT or self.data.buyType == DirectBuyType.MONTH_GIFT or self.data.buyType == DirectBuyType.XIANSHISHANGSHI or self.data.buyType == DirectBuyType.ZHENQIBAOGE) then--周月礼包
2021-03-30 10:48:34 +08:00
self.grid:GetComponent("RectTransform").anchoredPosition = offSetX[1].scroll
self.upLayout.gameObject:SetActive(false)
2021-04-14 12:00:06 +08:00
elseif self.data.DataType == DataType.Shop and self.data.buyType == SHOP_TYPE.VIP_GIFT then--特权
2021-04-09 12:26:35 +08:00
local str = ""..rechargeNum.."/"..self.data.data.shopItemData.BuyRule[2]..Language[11698]
self:SetType1(Language[11377],self.data.data.shopItemData.BuyRule[2],str)
2021-04-14 12:00:06 +08:00
elseif (self.data.DataType == DataType.Direct and self.data.buyType == DirectBuyType.FINDTREASURE_GIFT) or--寻宝特权
2021-03-31 18:38:57 +08:00
(self.data.DataType == DataType.Shop and self.data.buyType == SHOP_TYPE.FINDTREASURE_GIFT) then
self.tipRoot:SetActive(true)
self:SetTip()
end
ForceRebuildLayout(self.upLayout.transform)
end
2021-04-01 15:42:59 +08:00
function GiftPre:SetType1(type1Text1,num,type1Text3)
self.type1.gameObject:SetActive(true)
2021-04-07 19:52:25 +08:00
--CreatNumberPrefab(tostring(num),self.numList)
self.moneyNum:SetNum(num)
2021-04-09 12:26:35 +08:00
self.type1Text1.text = Language[11377]
2021-04-01 15:42:59 +08:00
self.type1Text3.text = type1Text3
end
function GiftPre:SetType2()
self.type2.gameObject:SetActive(true)
self.type2Text1.text = self.data.data.shows[1][2]
self.type2Text2.text=self.data.data.shopItemData.Rebate
if GetCurLanguage() == 0 then
self.type2Text1.gameObject:GetComponent("RectTransform").anchoredPosition = offSetX[0].txt1
self.type2Icon1.gameObject:GetComponent("RectTransform").anchoredPosition = offSetX[0].icon1
self.type2Text2.gameObject:GetComponent("RectTransform").anchoredPosition = offSetX[0].txt
self.type2Icon2.gameObject:GetComponent("RectTransform").anchoredPosition = offSetX[0].icon
self.type2Ima.gameObject:GetComponent("RectTransform").anchoredPosition = offSetX[0].ima
elseif GetCurLanguage() == 1 then
self.type2Text1.gameObject:GetComponent("RectTransform").anchoredPosition = offSetX[1].txt1
self.type2Icon1.gameObject:GetComponent("RectTransform").anchoredPosition = offSetX[1].icon1
self.type2Text2.gameObject:GetComponent("RectTransform").anchoredPosition = offSetX[1].txt
self.type2Icon2.gameObject:GetComponent("RectTransform").anchoredPosition = offSetX[1].icon
self.type2Ima.gameObject:GetComponent("RectTransform").anchoredPosition = offSetX[1].ima
else
self.type2Text1.gameObject:GetComponent("RectTransform").anchoredPosition = offSetX[2].txt1
self.type2Icon1.gameObject:GetComponent("RectTransform").anchoredPosition = offSetX[2].icon1
self.type2Text2.gameObject:GetComponent("RectTransform").anchoredPosition = offSetX[2].txt
self.type2Icon2.gameObject:GetComponent("RectTransform").anchoredPosition = offSetX[2].icon
self.type2Ima.gameObject:GetComponent("RectTransform").anchoredPosition = offSetX[2].ima
end
end
2021-03-31 18:38:57 +08:00
function GiftPre:SetTip()
if self.data.data.shopData.id and self.data.data.shopData.id == 20091 then
if GetCurLanguage() ~= 0 then
self.tip1_en:SetActive(true)
else
self.tip1:SetActive(true)
end
elseif self.data.data.shopData.id and self.data.data.shopData.id == 20092 then
if GetCurLanguage() ~= 0 then
self.tip2_en:SetActive(true)
else
self.tip2:SetActive(true)
end
elseif self.data.data.shopData.goodsId and self.data.data.shopData.goodsId == 4002 then
if GetCurLanguage() ~= 0 then
self.tip3_en:SetActive(true)
else
self.tip3:SetActive(true)
end
elseif self.data.data.shopData.goodsId and self.data.data.shopData.goodsId == 4001 then
if GetCurLanguage() ~= 0 then
self.tip4_en:SetActive(true)
else
self.tip4:SetActive(true)
end
elseif self.data.data.shopData.goodsId and self.data.data.shopData.goodsId == 4003 then
self.tip5:SetActive(true)
2021-04-09 12:26:35 +08:00
self.tip5Text.text = Language[12258]
2021-03-31 18:38:57 +08:00
elseif self.data.data.shopData.goodsId and self.data.data.shopData.goodsId == 7105 then
self.tip5:SetActive(true)
2021-04-09 12:26:35 +08:00
self.tip5Text.text = Language[12259]
2021-03-31 18:38:57 +08:00
end
end
2021-04-01 15:42:59 +08:00
function GiftPre:SetIsCanBuy()
local isCanBuy = 0
2021-04-21 13:12:04 +08:00
self.btnBuy:GetComponent("Image").sprite = self.spLoader:LoadSprite("s_slbz_1anniuhuangse")
2021-04-01 15:42:59 +08:00
--如果是成长礼包 有一个1的状态 并且按钮图片有变化
if self.data.DataType == DataType.Shop and self.data.buyType == SHOP_TYPE.VIP_GIFT then
2021-04-01 15:42:59 +08:00
isCanBuy = (rechargeNum >= self.data.data.shopItemData.BuyRule[2] and 0 or 1)
--LogGreen("isCanBuy:"..isCanBuy)
2021-04-01 19:04:01 +08:00
if isCanBuy == 0 then
2021-04-21 13:12:04 +08:00
self.btnBuy:GetComponent("Image").sprite = self.spLoader:LoadSprite("s_slbz_1anniuongse")
2021-04-01 19:04:01 +08:00
else
2021-04-21 13:12:04 +08:00
self.btnBuy:GetComponent("Image").sprite = self.spLoader:LoadSprite("s_slbz_1anniuhuangse")
2021-04-01 19:04:01 +08:00
end
end
2021-04-01 15:42:59 +08:00
if isCanBuy == 0 then
isCanBuy = (self.data.data.limitNum - self.data.data.boughtNum > 0) and 0 or 2
end
2021-04-01 15:42:59 +08:00
return isCanBuy
end
function GiftPre:SetIcon()
if self.isCanBuy == 2 then
self.icon.gameObject:SetActive(false)
2021-04-09 12:26:35 +08:00
self.price.text = Language[10514]
2021-04-01 15:42:59 +08:00
else
if self.data.DataType == DataType.Shop then
self.icon.gameObject:SetActive(true)
2021-04-21 13:12:04 +08:00
self.icon.sprite = self.spLoader:LoadSprite(GetResourcePath(itemConfig[self.data.data.shopItemData.Cost[1][1]].ResourceID))
2021-04-01 15:42:59 +08:00
else
self.icon.gameObject:SetActive(false)
end
self.price.text = self.data.data.price
end
2021-04-01 15:42:59 +08:00
end
function GiftPre:SetBtn(_itemdata)
self.btnBuy.gameObject:SetActive(true)
self.isCanBuy = self:SetIsCanBuy()
self.btnBuy:GetComponent("Button").interactable = (self.isCanBuy == 0 or self.isCanBuy == 1)
--设置icon
self:SetIcon()
--设置按钮提示 -- 已经购买不显示(特权礼包需要显示时间)
2021-03-30 22:59:01 +08:00
self.buyInfo.text = self.isCanBuy == 2 and "" or _itemdata.data.buyInfo
if self.isCanBuy == 2 then
2021-03-30 22:59:01 +08:00
if self.data.DataType == DataType.Direct and self.data.buyType == DirectBuyType.FINDTREASURE_GIFT then
if self.time then
self.time:Stop()
self.time = nil
end
local fresh = _itemdata.data.endTime - GetTimeStamp()
2021-04-01 15:42:59 +08:00
if fresh <= 0 then
-- self.parent:RefreshData()
2021-04-01 15:42:59 +08:00
return
end
2021-04-09 12:26:35 +08:00
self.buyInfo.text = Language[10469]..self.parent:SpecialTime(fresh)
2021-03-30 22:59:01 +08:00
self.time = Timer.New(function()
2021-04-01 15:42:59 +08:00
fresh = fresh - 1
2021-03-30 22:59:01 +08:00
if fresh <= 0 then
self.parent:RefreshData()
return
2021-04-01 15:42:59 +08:00
end
2021-04-09 12:26:35 +08:00
self.buyInfo.text = Language[10469]..self.parent:SpecialTime(fresh)
2021-03-30 22:59:01 +08:00
end,1,-1,true)
self.time:Start()
2021-04-01 15:42:59 +08:00
end
end
2021-04-01 15:42:59 +08:00
--设置红点
2021-03-30 10:48:34 +08:00
if _itemdata.data.finalNum == 0 and self.isCanBuy == 0 then
self.redPoint.gameObject:SetActive(true)
else
self.redPoint.gameObject:SetActive(false)
end
Util.SetGray(self.btnBuy, (self.isCanBuy == 2))
ForceRebuildLayout(self.btnBuy.transform)
end
function GiftPre:OnClose()
2021-03-30 22:59:01 +08:00
if self.time then
self.time:Stop()
self.time = nil
end
2021-03-30 18:26:10 +08:00
DynamicActivityManager.SetSelectIndex(0,{})
for k,v in pairs(self.itemList) do
SubUIManager.Close(v)
end
self.itemList = {}
if self.moneyNum then
SubUIManager.Close(self.moneyNum)
self.moneyNum = nil
end
end
2021-04-21 13:12:04 +08:00
return GiftPre