local Currency_Controller = {} local EventSystem = require 'Event/EventSystem' local LuaFuncEntry = require("Main/LuaFuncEntry") Currency_Controller.CurrencyStyle = { ShowAll = 1, HideEnergy = 2, Shop = 3,--商城显示样式 } local private = {} local MaxEnergy = DataSheetManager.ConstData:GetDataByID("ServerMaxEnergy").IntValue local MaxSkuDetailsCount = 3 --最大请求货币本地化的次数 local curSkuDetailsCount = 1 function Currency_Controller.OnStartup() private.SetupEntryFunc(true) private.QuerySkuDetails() --道具id事件存储 private.currencyTypeEvents = {} private.currencyTypeParams = {} end function private.SetupEntryFunc(isRegist) LuaFuncEntry.SetupMainEntryFunc(isRegist, LuaFuncEntry.FuncType.SkuDetailFailed, private.OnSkuDetailFailed) end function Currency_Controller.OnShutdown() private.SetupEntryFunc(false) end function Currency_Controller.IsEnergyPillUseLegal() if MDL.Player.GetEnergyValue() >= MaxEnergy then return false else return true end end function Currency_Controller.OpenCurrencyPanel(viewClassPath, currencyInfo, currencyTypeContext, paramContext) local currencyTypeIds = viewClassPath and Currency_Controller.GetCurrentTypeIds(viewClassPath) or currencyTypeContext if currencyTypeIds then if not currencyInfo then logging.error(LTAG.ERROR, "当前View:", viewClassPath, "不存在资源条挂点currency_Info") return end if currencyInfo:GetType() ~= typeof(Tai.Lua.UIScriptableCanvas) then logging.error(LTAG.ERROR, "当前View:", viewClassPath, "UI挂点类型有误(不是UIScriptableCanvas):", currencyInfo:GetType()) return end if currencyInfo:IsViewOpened(Const_UI_Lua.UIEnum.UICurrencyPanel) then EventSystem.Dispatch(EventID.UI_Shop_Refresh_Currency, currencyTypeContext, viewClassPath, paramContext) else currencyInfo:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UICurrencyPanel), {viewClassPath = viewClassPath, currencyTypeIds = currencyTypeIds, param = paramContext}) end end end function Currency_Controller.GetCurrentTypeIds(viewClassPath) if viewClassPath == nil or viewClassPath == "" then logging.error(LTAG.ERROR, "[通用资源HUD] : 当前父级Panel的viewClassPath无效", viewClassPath) return nil end local success, cfg = DataSheetManager.HUDData:TryGetDataByUIName(viewClassPath) if success then local currencyTypeIds = cfg.Money local currencyCount = #currencyTypeIds if currencyCount > 0 then return currencyTypeIds end end return nil end --这里是查询订单信息 用于充值金额价格货币单位本地化使用 只有海外在用 function private.QuerySkuDetails() if GameAppInfo.IsMacPackage() then local jsonStr = CTL.Login.GetMacSkuDetailJsonStr() if jsonStr then MDL.Currency.SetSkuDetail(jsonStr) end end if GameAppInfo.IsOverseaPackage() or GameAppInfo.IsJapanesePackage() or GameAppInfo.IsVietnamPackage() then local str = "" local count = DataSheetManager.IAP:GetDataCount() for i, v in DataSheetManager.IAP:GetEnumerator() do if i == count then str = str .. v.IapID else str = str .. v.IapID .. ";" end end SDKUtil.QuerySkuDetails(str) end end function private.OnSkuDetailFailed() if curSkuDetailsCount <= MaxSkuDetailsCount then private.QuerySkuDetails() curSkuDetailsCount = curSkuDetailsCount + 1 end end --日服使用龙玉,需要特殊处理 function Currency_Controller.IsDragonJadeUsedInJapan(id) if GameAppInfo.IsJapanesePackage() and id == MDL.Currency.CurrencyType.DragonJade then return true end return false end -- 判断是否首冲重置过 function Currency_Controller.FirstPayIsReset() local resetTime = 0 for _, v in DataSheetManager.FirstChargeReset:GetEnumerator() do resetTime = v.ResetTime break end -- 表里面的时间加上时区偏移 return UTL.Time.GetServerTimestamp() >= UTL.Time.GetConfigTimestampById(resetTime) + UTL.Time.GetDisplayDiffLocalTimeZone() end --一个占位符,保证currencyTypeEvents和currencyTypeParams 数组长度相等 local EmptyTable = {} --根据道具类型注册监听事件,道具第二类型可选 --listener 如果是面板监听self,如果是controller或者model,空 function Currency_Controller.RegisteEventByCurrencyType(currencyType, listenCallback, listener) if not private.currencyTypeEvents[currencyType] then private.currencyTypeEvents[currencyType] = {} end if not private.currencyTypeParams[currencyType] then private.currencyTypeParams[currencyType] = {} end local typeEventLen = #private.currencyTypeEvents[currencyType] private.currencyTypeEvents[currencyType][typeEventLen+1] = listenCallback private.currencyTypeParams[currencyType][typeEventLen+1] = listener or EmptyTable end function Currency_Controller.UnRegisteEventByCurrencyType(currencyType, listenCallback, listener) if private.currencyTypeEvents[currencyType] then for index, func in ipairs(private.currencyTypeEvents[currencyType]) do if func == listenCallback then if listener then if private.currencyTypeParams[currencyType][index]==listener then table.remove(private.currencyTypeEvents[currencyType], index) table.remove(private.currencyTypeParams[currencyType], index) break end elseif private.currencyTypeParams[currencyType][index]==EmptyTable then table.remove(private.currencyTypeEvents[currencyType], index) table.remove(private.currencyTypeParams[currencyType], index) break end end end end end function private.DispatchCurrencyEventErrorMsg(msg) logging.error(LTAG.ERROR, "DispatchCurrencyEventErrorMsg执行失败", msg) end function Currency_Controller.CheckAndDispatchCurrencyEvent(msgId, currencyList) for i = 1, #currencyList do --此处既有CfgId又有CfgID是因为硬货币和软货币的协议里定义的大小写字段不同 local currencyType = currencyList[i].CfgId or currencyList[i].CfgID if private.currencyTypeEvents[currencyType] then for index, func in ipairs(private.currencyTypeEvents[currencyType]) do if private.currencyTypeParams[currencyType][index] ~= EmptyTable then xpcall(func, private.DispatchCurrencyEventErrorMsg, private.currencyTypeParams[currencyType][index], msgId, currencyType) else xpcall(func, private.DispatchCurrencyEventErrorMsg, msgId, currencyType) end end end end end return Currency_Controller