PGRData/Script/matrix/xui/xuipassport/card/XUiPassportCard.lua

149 lines
No EOL
6.6 KiB
Lua

local XUiPassportCardGrid = require("XUi/XUiPassport/Card/XUiPassportCardGrid")
local XUiPassportCard = XLuaUiManager.Register(XLuaUi, "UiPassportCard")
local CSXTextManagerGetText = CS.XTextManager.GetText
local tableInsert = table.insert
--购买通行证
function XUiPassportCard:OnAwake()
self.AssetPanel = XUiPanelAsset.New(self, self.PanelAsset, XDataCenter.ItemManager.ItemId.HongKa)
self:RegisterButtonEvent()
-- self.PanelAsset.gameObject:SetActiveEx(false) -- 日服没有虹卡,隐藏虹卡资源框 -- 英文服使用虹卡
self:InitTextBuyCaption()
end
function XUiPassportCard:OnStart(passportId, closeCb)
self.PassportId = passportId
self.CloseCb = closeCb
self.DynamicTable = XDynamicTableNormal.New(self.PanelIconList.transform)
self.DynamicTable:SetProxy(XUiPassportCardGrid)
self.DynamicTable:SetDelegate(self)
self.PanelBagItem.gameObject:SetActive(false)
self:UpdateDynamicTable(passportId)
self:UpdateDesc(passportId)
self:UpdateFashionShow(passportId)
self:InitBtnXqActive(passportId)
end
function XUiPassportCard:OnEnable()
self:Refresh()
end
function XUiPassportCard:OnDestroy()
if self.CloseCb then
self.CloseCb()
end
end
function XUiPassportCard:InitTextBuyCaption()
local time = XPassportConfigs.GetPassportBuyPassPortEarlyEndTime()
local timeDesc = time > 0 and XUiHelper.GetTimeDesc(time, 2) or 0 .. CSXTextManagerGetText("Second")
timeDesc = string.gsub(timeDesc, "^%s*(.-)%s*$", "%1")
-- timeDesc = string.gsub(timeDesc, " ", "") 英文服需要数字与min之间有空格 20 min
local buyCaptionDesc = CSXTextManagerGetText("PassportBuyCaptionDesc", timeDesc)
self.TextBuyTime.text = buyCaptionDesc
end
function XUiPassportCard:InitBtnXqActive(passportId)
local fashionId = XPassportConfigs.GetPassportBuyFashionShowFashionId(passportId)
self.BtnXq.gameObject:SetActiveEx(XTool.IsNumberValid(fashionId))
end
function XUiPassportCard:Refresh()
local passportId = self:GetPassportId()
local isUnLock = XDataCenter.PassportManager.GetPassportInfos(passportId) and true or false
self.BtnBuy:SetDisable(isUnLock, not isUnLock)
local costItemId = XPassportConfigs.GetPassportTypeInfoCostItemId(passportId)
local costItemCount = XPassportConfigs.GetPassportTypeInfoCostItemCount(passportId) -- 英文服使用虹卡
-- local costItemCount = XPassportConfigs.GetPassportTypeInfoIsFree(passportId) and 0 or XPayConfigs.GetPayTemplate(XDataCenter.PayManager.GetProductKey(XPassportConfigs.GetPassportTypeInfoPayKeySuffix(passportId))).Amount
local costItemName = "" --策划需求,不显示道具名字
local btnName = isUnLock and CSXTextManagerGetText("AlreadyBuy") or CSXTextManagerGetText("PassportBtnBuyPassportDesc", costItemCount, costItemName)
self.BtnBuy:SetName(btnName)
if self.IconBtnBuy then
local costItemIcon = XItemConfigs.GetItemIconById(costItemId)
self.IconBtnBuy:SetRawImage(costItemIcon) -- 英文服使用虹卡
-- self.IconBtnBuy:SetRawImage("Assets/Product/Texture/Image/UiPurchase/UiPurchaseYuan1.png") -- 直购写死日元图标
self.IconBtnBuy.gameObject:SetActiveEx(not isUnLock)
end
end
function XUiPassportCard:UpdateFashionShow(passportId)
local isHavePassportId = XTool.IsNumberValid(passportId)
if isHavePassportId then
local icon = XPassportConfigs.GetPassportBuyFashionShowIcon(passportId)
self.RImgShow:SetRawImage(icon)
end
self.RImgShow.gameObject:SetActiveEx(isHavePassportId)
end
function XUiPassportCard:UpdateDesc(passportId)
self.TxtName.text = XPassportConfigs.GetPassportTypeInfoName(passportId)
local icon = XPassportConfigs.GetPassportTypeInfoIcon(passportId)
self.RImgIcon:SetRawImage(icon)
local buyDesc = XPassportConfigs.GetPassportTypeInfoBuyDesc(passportId)
self.TxtMessage.text = string.gsub(buyDesc, "\\n", "\n")
end
function XUiPassportCard:UpdateDynamicTable(passportId)
self.BuyRewardShowIdList = XPassportConfigs.GetBuyRewardShowIdList(passportId)
self.DynamicTable:SetDataSource(self.BuyRewardShowIdList)
self.DynamicTable:ReloadDataSync()
end
function XUiPassportCard:OnDynamicTableEvent(event, index, grid)
if event == DYNAMIC_DELEGATE_EVENT.DYNAMIC_GRID_INIT then
grid:Init(self)
elseif event == DYNAMIC_DELEGATE_EVENT.DYNAMIC_GRID_ATINDEX then
local passportRewardId = self.BuyRewardShowIdList[index]
grid:Refresh(passportRewardId)
end
end
function XUiPassportCard:RegisterButtonEvent()
self:RegisterClickEvent(self.BtnClose, self.Close)
self:RegisterClickEvent(self.BtnXq, self.OnBtnXqClick)
self.BtnBuy.CallBack = handler(self, self.OnBtnBuyClick)
end
function XUiPassportCard:OnBtnXqClick()
local passportId = self:GetPassportId()
local fashionId = XPassportConfigs.GetPassportBuyFashionShowFashionId(passportId)
local isWeaponFahion = XPassportConfigs.IsPassportBuyFashionShowIsWeaponFahion(passportId)
XLuaUiManager.Open("UiFashionDetail", fashionId, isWeaponFahion)
end
function XUiPassportCard:OnBtnBuyClick()
local passportId = self:GetPassportId()
local costItemId = XPassportConfigs.GetPassportTypeInfoCostItemId(passportId)
local haveCostItemCount = XDataCenter.ItemManager.GetCount(costItemId)
-- local costItemCount = XPassportConfigs.GetPassportTypeInfoIsFree(passportId) and 0 or XPayConfigs.GetPayTemplate(XDataCenter.PayManager.GetProductKey(XPassportConfigs.GetPassportTypeInfoPayKeySuffix(passportId))).Amount
local costItemCount = XPassportConfigs.GetPassportTypeInfoCostItemCount(passportId)
local passportName = XPassportConfigs.GetPassportTypeInfoName(passportId)
local costItemName = XItemConfigs.GetItemNameById(costItemId)
local title = CSXTextManagerGetText("BuyConfirmTipsTitle")
-- local desc = CSXTextManagerGetText("PassportBuyPassportTipsDesc", costItemCount, passportName)
local desc = CSXTextManagerGetText("PassportBuyPassportTipsDesc", costItemCount, costItemName, passportName)
local sureCallback = function()
-- if string.IsNilOrEmpty(XPassportConfigs.GetPassportTypeInfoPayKeySuffix(passportId)) and haveCostItemCount < costItemCount then
if haveCostItemCount < costItemCount then -- 英文服使用虹卡
XUiManager.TipText("ShopItemHongKaNotEnough")
XLuaUiManager.Open("UiPurchase", XPurchaseConfigs.TabsConfig.Pay)
return
end
XDataCenter.PassportManager.RequestPassportBuyPassport(passportId, handler(self, self.Refresh))
end
XUiManager.DialogTip(title, desc, XUiManager.DialogType.Passport, nil, sureCallback)
end
function XUiPassportCard:GetPassportId()
return self.PassportId
end