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

233 lines
11 KiB
Lua
Raw Normal View History

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 = {
[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)},
[1] = { icon = Vector3.New(219.86,8,0),txt = Vector3.New(288.5,0.5,0),ima = Vector3.New(20.19,0,0),txt1 = Vector3.New(-162,0.5,0),icon1 = Vector3.New(-219.6,8,0)},
[2] = { icon = Vector3.New(30,8,0),txt = Vector3.New(86.4,0.5,0),ima = Vector3.New(30,0,0),txt1 = Vector3.New(-105.7,0.5,0),icon1 = Vector3.New(-155.7,8,0)}
}
--初始化组件(用于子类重写)
function GiftPre:InitComponent()
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
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.isCanBuy = 0
self.itemList = {}
end
--绑定事件(用于子类重写)
function GiftPre:BindEvent()
Util.AddOnceClick(self.btnBuy, function()
if self.isCanBuy == 1 then -- 0 可购买 1购买条件不足 2已购买
PopupTipPanel.ShowTip(Language[11701])
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)
else
--直购商品
PayManager.Pay(self.data.data.shopData.goodsId, function(id)
FirstRechargeManager.RefreshAccumRechargeValue(self.data.data.shopData.goodsId)
PlayerPrefs.SetInt(PlayerManager.uid.."czlb", 0)
CheckRedPointStatus(RedPointType.DailyGift)
CheckRedPointStatus(RedPointType.GrowthPackage)
self.parent:RefreshData()
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()
CheckRedPointStatus(RedPointType.DailyGift)
CheckRedPointStatus(RedPointType.GrowthPackage)
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[11457], 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[10719],
Language[10720],
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
if self.data.data.tagName and self.data.data.tagName ~= "" then
self.tagIma.gameObject:SetActive(true)
self.tagText.text = self.data.data.tagName
else
self.tagIma.gameObject:SetActive(false)
end
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]}, 0.9,false,false,false,sortingOrder)
self.itemList[i].gameObject:SetActive(true)
end
if self.data.data.tipImageText and self.data.data.tagName and self.data.data.tagName ~= "" then
self.tipImage.gameObject:SetActive(true)
self.tipText.text = self.data.data.tipImageText
else
self.tipImage.gameObject:SetActive(false)
end
self:SetIcon(self.data)
self:SetContent1()
end
function GiftPre:SetContent1()
self.type1.gameObject:SetActive(false)
self.type2.gameObject:SetActive(false)
self.btnBuy:GetComponent("Image").sprite = Util.LoadSprite("s_slbz_1anniuhuangse")
if self.data.DataType == DataType.Direct and self.data.buyType == DirectBuyType.DAILY_GIFT then
self.type2.gameObject:SetActive(true)
self.tagIma.gameObject:SetActive(true)
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
elseif self.data.DataType == DataType.Shop and self.data.buyType == SHOP_TYPE.VIP_GIFT then
self.type1.gameObject:SetActive(true)
self.tagIma.gameObject:SetActive(false)
CreatNumberPrefab(tostring(self.data.data.shopItemData.BuyRule[2]),self.numList)
self.type1Text1.text = "累计充值"
self.type1Text3.text = ""..rechargeNum.."/"..self.data.data.shopItemData.BuyRule[2]..Language[11698]--资格进度条
end
LayoutRebuilder.ForceRebuildLayoutImmediate(self.upLayout.transform)
end
function GiftPre:SetIcon(_itemdata)
self.btnBuy.gameObject:SetActive(true)
self.isCanBuy = 0
if self.data.DataType == DataType.Shop and self.data.buyType == SHOP_TYPE.VIP_GIFT then
self.isCanBuy = (rechargeNum >= self.data.data.shopItemData.BuyRule[2] and 0 or 1)
self.btnBuy:GetComponent("Image").sprite = Util.LoadSprite(self.isCanBuy == 0 and "s_slbz_1anniuongse" or "s_slbz_1anniuhuangse")
end
if self.isCanBuy == 0 then
self.isCanBuy = (_itemdata.data.limitNum - _itemdata.data.boughtNum > 0) and 0 or 2
end
self.btnBuy:GetComponent("Button").interactable = (self.isCanBuy == 0 or self.isCanBuy == 1)
Util.SetGray(self.btnBuy, (self.isCanBuy == 2))
if _itemdata.DataType == DataType.Shop then
self.icon.gameObject:SetActive(true)
self.icon.sprite = Util.LoadSprite(GetResourcePath(itemConfig[_itemdata.data.shopItemData.Cost[1][1]].ResourceID))
else
self.icon.gameObject:SetActive(false)
end
self.price.text = _itemdata.data.price
if self.isCanBuy == 2 then
self.icon.gameObject:SetActive(false)
self.price.text = "已购买"
end
LayoutRebuilder.ForceRebuildLayoutImmediate(self.btnBuy.transform)
self.buyInfo.text = self.isCanBuy == 2 and "" or _itemdata.data.buyInfo
end
function GiftPre:OnClose()
for k,v in pairs(self.itemList) do
SubUIManager.Close(v)
end
self.itemList = {}
end
return GiftPre