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

537 lines
23 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.

GiftPre = {}
local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
local rechargeConfig = ConfigManager.GetConfig(ConfigName.RechargeCommodityConfig)
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 = {
[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(-346.21,67.1,0),
},
[1] = {
icon = Vector3.New(513,-24,0),
txt = Vector3.New(575,-32,0),
ima = Vector3.New(20.19,0,0),
txt1 = Vector3.New(134,-32,0),
icon1 = Vector3.New(80.39999,-24,0),
scroll = Vector3.New(-294,71.9,0),
},
[2] = { icon = Vector3.New(316.7,-23,0),
txt = Vector3.New(373.1,-32.69999,0),
ima = Vector3.New(30,0,0),
txt1 = Vector3.New(179,-32.69999,0),
icon1 = Vector3.New(129,-23,0)
}
}
--初始化组件(用于子类重写)
function GiftPre:InitComponent()
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 = {}
self.gmConfig=nil
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")
self.redpot = Util.GetGameObject(self.gameObject, "bg/redpot")
self.UI_Effect_MianBan_LiBao_button_01 = Util.GetGameObject(self.gameObject, "UI_Effect_MianBan_LiBao_button_01")
self.isCanBuy = 0
self.itemList = {}
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已购买
if self.gmConfig then
for i = 1, #self.gmConfig.Unlock do
local can,str=CheckGMIsOpen(self.gmConfig.Unlock[i][1],self.gmConfig.Unlock[i][2])
if not can then
if self.gmConfig.Unlock[i][1]==4 then
local sureFunc=function()
JumpManager.GoJump(36010)
end
local args={}
args[1]="累充金额不满足条件,是否前往充值"
args[2]="我要升级"
args[3]="取消"
args[4]=sureFunc
UIManager.OpenPanel(UIName.GMCommonConfirmPanel,args)
return
elseif self.gmConfig.Unlock[i][1]==5 then
if rechargeConfig[self.gmConfig.Unlock[i][2]].Type==21 then
local sureFunc=function()
UIManager.OpenPanel(UIName.GMShuaChongTeQuan)
end
local args={}
args[1]="GM等级不满足条件是否前往提升GM等级"
args[2]="我要升级"
args[3]="取消"
args[4]=sureFunc
UIManager.OpenPanel(UIName.GMCommonConfirmPanel,args)
return
else
PopupTipPanel.ShowTip(str)
return
end
end
end
end
else
PopupTipPanel.ShowTip(Language[11701])
end
elseif self.isCanBuy == 2 then
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)
elseif self.data.DataType == DataType.Direct then
if self.data.data.linkAct then
NetManager.GetActivityRewardRequest(self.data.data.missionId,self.data.data.activityId,function (drop)
UIManager.OpenPanel(UIName.RewardItemPopup, drop, 1,function ()
self.parent:RefreshData(nil,false,false)
end)
end)
else
--直购商品
PayManager.Pay(self.data.data.shopData.goodsId, function(id)
FirstRechargeManager.RefreshAccumRechargeValue(self.data.data.shopData.goodsId)
CheckRedPointStatus(RedPointType.DailyGift)
CheckRedPointStatus(RedPointType.WeekGiftPage)
CheckRedPointStatus(RedPointType.MonthGiftPage)
CheckRedPointStatus(RedPointType.GrowthPackage)
self.parent:RefreshData(nil,false,false)
end)
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.isCanBuy=0
self.parent:RefreshData(nil,false,false)
CheckRedPointStatus(RedPointType.DailyGift)
CheckRedPointStatus(RedPointType.GrowthPackage)
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
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,
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)
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
--设置按钮
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
end
function GiftPre:Effect()
local isshow = false
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
isshow = true
break
end
end
end
if self.isCanBuy == 2 then
isshow = false
end
self.UI_Effect_MianBan_LiBao_button_01.gameObject:SetActive(isshow)
end
function GiftPre:SetContent1()
self.upLayout.gameObject:SetActive(true)
self.grid:GetComponent("RectTransform").anchoredPosition = offSetX[0].scroll
self.type1.gameObject:SetActive(false)
self.type2.gameObject:SetActive(false)
self.tipRoot:SetActive(false)
self.tip1:SetActive(false)
self.tip2:SetActive(false)
self.tip3:SetActive(false)
self.tip4:SetActive(false)
self.tip5:SetActive(false)
self.tip1_en:SetActive(false)
self.tip2_en:SetActive(false)
self.tip3_en:SetActive(false)
self.tip4_en:SetActive(false)
if self.data.DataType == DataType.Direct and self.data.buyType == DirectBuyType.DAILY_GIFT then--每日礼包
self:SetType2()
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 or self.data.buyType == DirectBuyType.linglongShagnshi) then--周月礼包
self.grid:GetComponent("RectTransform").anchoredPosition = offSetX[1].scroll
-- self.upLayout.gameObject:SetActive(false)
elseif self.data.DataType == DataType.Shop and self.data.buyType == SHOP_TYPE.VIP_GIFT then--特权
local str = ""..rechargeNum.."/"..self.data.data.shopItemData.BuyRule[2]..Language[11698]
self:SetType1(Language[11377],self.data.data.shopItemData.BuyRule[2],str)
elseif (self.data.DataType == DataType.Direct and self.data.buyType == DirectBuyType.FINDTREASURE_GIFT) or--寻宝特权
(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
function GiftPre:SetType1(type1Text1,num,type1Text3)
self.type1.gameObject:SetActive(true)
--CreatNumberPrefab(tostring(num),self.numList)
self.moneyNum:SetNum(num)
self.type1Text1.text = Language[11377]
self.type1Text3.text = type1Text3
end
function GiftPre:SetType2()
self.type2.gameObject:SetActive(false)
--self.type2Text1.text = self.data.data.shows[1][2]/1000
--self.type2Text1.text=self.data.data.shopItemData.GainCrystal[1][2]
if self.data.data.shopItemData and self.data.data.shopItemData.GainCrystal then
self.type2Text1.text=self.data.data.shopItemData.GainCrystal[1][2]
else
self.type2Text1.text = self.data.data.shows[1][2]
end
--LogError("aaaa=="..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
function GiftPre:SetTip()
--LogError("self.data.data.shopData.goodsId=="..self.data.data.shopData.goodsId)
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)
self.tip5Text.text = Language[12258]
elseif self.data.data.shopData.goodsId and self.data.data.shopData.goodsId == 7105 then
self.tip5:SetActive(true)
self.tip5Text.text = Language[12259]
elseif self.data.data.shopData.goodsId and (self.data.data.shopData.goodsId == 2301
or self.data.data.shopData.goodsId == 2302 or self.data.data.shopData.goodsId == 2303
or self.data.data.shopData.goodsId == 2304 ) then
self.tip5:SetActive(true)
local rechargeData=ConfigManager.GetConfigData(ConfigName.RechargeCommodityConfig,self.data.data.shopData.goodsId)
self.tip5Text.text = rechargeData.Desc
end
end
function GiftPre:SetIsCanBuy()
local isCanBuy = 0
self.btnBuy:GetComponent("Image").sprite = self.spLoader:LoadSprite("Btn_hz_cheng_01")
--如果是成长礼包 有一个1的状态 并且按钮图片有变化
if self.data.DataType == DataType.Shop and self.data.buyType == SHOP_TYPE.VIP_GIFT then
isCanBuy = (rechargeNum >= self.data.data.shopItemData.BuyRule[2] and 0 or 1)
--LogGreen("isCanBuy:"..isCanBuy)
end
if self.data.data.shopItemData.ShowType==17 then
self.gmConfig=ConfigManager.GetConfigDataByKey(ConfigName.GMMaster,"PackID",self.data.data.shopData.goodsId)
local isCan=CheckGMIsOpen(self.gmConfig.Unlock[1][1],self.gmConfig.Unlock[1][2])
if isCan then
if #self.gmConfig.Unlock>1 then
--LogError("self.gmConfig.Unlock[2][1]=="..self.gmConfig.Unlock[2][1].." self.gmConfig.Unlock[2][2]=="..self.gmConfig.Unlock[2][2])
local isCan2=CheckGMIsOpen(self.gmConfig.Unlock[2][1],self.gmConfig.Unlock[2][2])
if isCan2 then
isCanBuy=0
else
isCanBuy=1
end
end
--isCanBuy=0
else
isCanBuy=1
end
end
if isCanBuy == 0 then
--LogError("self.data.data.limitNum=="..self.data.data.limitNum.." self.data.data.boughtNum=="..self.data.data.boughtNum)
isCanBuy = (self.data.data.limitNum - self.data.data.boughtNum > 0) and 0 or 2
if self.data.data.linkAct then
isCanBuy = self.data.data.state == 0 and 0 or 2
end
end
if isCanBuy == 0 then
-- self.btnBuy:GetComponent("Image").sprite = self.spLoader:LoadSprite("s_slbz_1anniuongse")
else
--self.btnBuy:GetComponent("Image").sprite = self.spLoader:LoadSprite("s_slbz_1anniuhuangse")
end
return isCanBuy
end
function GiftPre:SetIcon()
if self.isCanBuy == 2 then
self.icon.gameObject:SetActive(false)
self.price.text = Language[10514]
if self.data.data.linkAct then
self.price.text = Language[10101]
end
else
--LogError("self.data.DataType=="..self.data.DataType)
self.price.text = self.data.data.price
if self.data.DataType == DataType.Shop then
self.icon.gameObject:SetActive(true)
self.icon.sprite = self.spLoader:LoadSprite(GetResourcePath(itemConfig[self.data.data.shopItemData.Cost[1][1]].ResourceID))
elseif self.data.data.shopItemData.ShowType==17 then
--gmConfig=ConfigManager.GetConfigDataByKey(ConfigName.GMMaster,"PackID",self.data.data.shopData.goodsId)
self.icon.gameObject:SetActive(true)
self.icon.sprite = self.spLoader:LoadSprite(GetResourcePath(itemConfig[self.gmConfig.Price[1][1]].ResourceID))
self.price.text = self.gmConfig.Price[1][2]
else
self.icon.gameObject:SetActive(false)
end
end
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()
Util.SetGray(self.btnBuy, self.isCanBuy ~= 0)
--设置按钮提示 -- 已经购买不显示(特权礼包需要显示时间)
self.buyInfo.text = self.isCanBuy == 2 and "" or _itemdata.data.buyInfo
if self.isCanBuy == 2 then
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()
if fresh <= 0 then
-- self.parent:RefreshData()
return
end
self.buyInfo.text = Language[10469]..self.parent:SpecialTime(fresh)
self.time = Timer.New(function()
fresh = fresh - 1
if fresh <= 0 then
self.parent:RefreshData()
return
end
self.buyInfo.text = Language[10469]..self.parent:SpecialTime(fresh)
end,1,-1,true)
self.time:Start()
end
end
--设置红点
if (_itemdata.data.finalNum == 0 or _itemdata.data.linkAct) and self.isCanBuy == 0 then
self.redPoint.gameObject:SetActive(true)
else
self.redPoint.gameObject:SetActive(false)
end
LogError("self.isCanBuy============"..self.isCanBuy)
ForceRebuildLayout(self.btnBuy.transform)
end
function GiftPre:OnClose()
if self.time then
self.time:Stop()
self.time = nil
end
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
return GiftPre