1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
#ifndef gfCInGameAdsManagerhdr
#define gfCInGameAdsManagerhdr

#include <fsCore/fsStr.h>
#include <fsCore/src/fsCUniqueId.h>
#include <fsPlatform/ads/fsAdsService.h>
#include <fsPlatform/ads/fsAdsFactory.h>

#include <string>
#include <memory>
#include <vector>

class gfCInGameAdsManager : public fsAdsService::Observer
{
public:
    static const fsCUniqueId mRewardUnlockGrantedMsg;

#if defined(fsInGameAds)
    static gfCInGameAdsManager& instanceGet();
#else
    static gfCInGameAdsManager& instanceGet()
    {
        static gfCInGameAdsManager sInstance;
        return sInstance;
    }
#endif

#if defined(fsInGameAds)
	void bannerAdBegin(const fsStr& pPlacementId = fsStr("banner"));
	void bannerAdReset();
	void bannerAdEnd();
	void interstitialAdShow(const fsStr& pPlacementId = fsStr(""));
	void rewardAdShow(const fsStr& pPlacementId = fsStr(""));
    void rewardUnlockAdShow(const fsStr& pPlacementId = fsStr(""));
    void rewardUnlockAdCancel();
	void playableAdShow(const fsStr& pPlacementId = fsStr(""));
    void placementIdSet(fsAdsPlacementKind pKind, const fsStr& pPlacementId);
    void appIdSet(const fsStr& pAppId);
    void supplierOrderSet(const std::vector<std::string>& pSupplierOrder);

    fsBool adActive() const;
    fsBool transitionBlocked() const;
    fsBool rewardUnlockAvailable() const;
    fsBool rewardUnlockInFlight() const;

    void onAdLoaded(const fsAdsPlacement& placement) override;
    void onAdFailed(const fsAdsPlacement& placement, const std::string& reason) override;
    void onAdShown(const fsAdsPlacement& placement) override;
    void onAdClosed(const fsAdsPlacement& placement) override;
    void onRewardEarned(const fsAdsPlacement& placement) override;
#else
	inline void bannerAdBegin(const fsStr&) {}<--- Either there is a missing 'override', or the member function 'gfCInGameAdsManager::bannerAdBegin' can be static.
	inline void bannerAdReset() {}<--- Either there is a missing 'override', or the member function 'gfCInGameAdsManager::bannerAdReset' can be static.
	inline void bannerAdEnd() {}<--- Either there is a missing 'override', or the member function 'gfCInGameAdsManager::bannerAdEnd' can be static.
	inline void interstitialAdShow(const fsStr& = fsStr("")) {}<--- Either there is a missing 'override', or the member function 'gfCInGameAdsManager::interstitialAdShow' can be static.
	inline void rewardAdShow(const fsStr& = fsStr("")) {}<--- Either there is a missing 'override', or the member function 'gfCInGameAdsManager::rewardAdShow' can be static.
    inline void rewardUnlockAdShow(const fsStr& = fsStr("")) {}<--- Either there is a missing 'override', or the member function 'gfCInGameAdsManager::rewardUnlockAdShow' can be static.
    inline void rewardUnlockAdCancel() {}<--- Either there is a missing 'override', or the member function 'gfCInGameAdsManager::rewardUnlockAdCancel' can be static.
	inline void playableAdShow(const fsStr& = fsStr("")) {}<--- Either there is a missing 'override', or the member function 'gfCInGameAdsManager::playableAdShow' can be static.
    inline void placementIdSet(fsAdsPlacementKind, const fsStr&) {}<--- Either there is a missing 'override', or the member function 'gfCInGameAdsManager::placementIdSet' can be static.
    inline void appIdSet(const fsStr&) {}<--- Either there is a missing 'override', or the member function 'gfCInGameAdsManager::appIdSet' can be static.
    inline void supplierOrderSet(const std::vector<std::string>&) {}<--- Either there is a missing 'override', or the member function 'gfCInGameAdsManager::supplierOrderSet' can be static.
	inline fsBool adActive() const { return false; }
    inline fsBool transitionBlocked() const { return false; }
    inline fsBool rewardUnlockAvailable() const { return false; }
    inline fsBool rewardUnlockInFlight() const { return false; }
#endif

private:

	gfCInGameAdsManager();
	~gfCInGameAdsManager();

	void initialise();
	void shutdown();
	void adShowRequest(fsAdsPlacementKind pKind, const fsStr& pPlacementId = fsStr(""));
	void adShowRequest(const fsAdsPlacement& pPlacement);
	void clearPendingRequest();
	void requestNextSupplier();
	void rewardUnlockStateClear();
	fsStr defaultPlacementIdFor(fsAdsPlacementKind pKind) const;
	bool pendingMatches(const fsAdsPlacement& pPlacement) const;

	std::unique_ptr<fsAdsService> mAdsService;

#if defined(fsInGameAds)
	std::vector<std::string> mSupplierOrder;
#endif
    fsStr mBannerPlacementId;
    fsStr mInterstitialPlacementId;
    fsStr mRewardPlacementId;
    fsStr mPlayablePlacementId;
    fsStr mAppId;

	fsAdsPlacement mPendingPlacement;
	fsBool mHasPendingPlacement;
	fsBool mPendingHasExplicitSupplier;
	int mSupplierIndex;
	fsBool mAdActive;
    fsBool mRewardUnlockPending;
    fsBool mRewardUnlockEarned;
    fsBool mRewardFallbackToInterstitial;
};

#endif