ProtocolAds.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /****************************************************************************
  2. Copyright (c) 2012-2013 cocos2d-x.org
  3. http://www.cocos2d-x.org
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. ****************************************************************************/
  20. #ifndef __CCX_PROTOCOL_ADS_H__
  21. #define __CCX_PROTOCOL_ADS_H__
  22. #include "PluginProtocol.h"
  23. #include <map>
  24. #include <string>
  25. #include <functional>
  26. namespace cocos2d { namespace plugin {
  27. typedef std::map<std::string, std::string> TAdsDeveloperInfo;
  28. typedef std::map<std::string, std::string> TAdsInfo;
  29. typedef enum
  30. {
  31. kAdsReceived = 0, // The ad is received
  32. kAdsShown, // The advertisement shown
  33. kAdsDismissed, // The advertisement dismissed
  34. kPointsSpendSucceed, // The points spend succeed
  35. kPointsSpendFailed, // The points spend failed
  36. kNetworkError, // Network error
  37. kUnknownError, // Unknown error
  38. } AdsResultCode;
  39. class ProtocolAds;
  40. class AdsListener
  41. {
  42. public:
  43. /**
  44. @brief The advertisement request result
  45. */
  46. virtual void onAdsResult(AdsResultCode code, const char* msg) = 0;
  47. /**
  48. @brief Player get points from advertisement(For example: Tapjoy)
  49. @param points The point number player has got.
  50. @param pAdsPlugin The plugin which the player get points. Used to spend the points.
  51. */
  52. virtual void onPlayerGetPoints(ProtocolAds* pAdsPlugin, int points) {}
  53. };
  54. class ProtocolAds : public PluginProtocol
  55. {
  56. public:
  57. ProtocolAds();
  58. virtual ~ProtocolAds();
  59. typedef enum {
  60. kPosCenter = 0,
  61. kPosTop,
  62. kPosTopLeft,
  63. kPosTopRight,
  64. kPosBottom,
  65. kPosBottomLeft,
  66. kPosBottomRight,
  67. } AdsPos;
  68. typedef std::function<void(int, std::string&)> ProtocolAdsCallback;
  69. /**
  70. @brief config the application info
  71. @param devInfo This parameter is the info of aplication,
  72. different plugin have different format
  73. @warning Must invoke this interface before other interfaces.
  74. And invoked only once.
  75. */
  76. void configDeveloperInfo(TAdsDeveloperInfo devInfo);
  77. /**
  78. @brief show adview
  79. @param info The information of adview will be shown
  80. Pay attention to the subclass definition
  81. @param pos The position where the adview be shown.
  82. */
  83. void showAds(TAdsInfo info, AdsPos pos = kPosCenter);
  84. /**
  85. @brief Hide the adview
  86. @param info The information of adview will be hided
  87. */
  88. void hideAds(TAdsInfo info);
  89. /**
  90. @brief Query the points of player
  91. */
  92. void queryPoints();
  93. /**
  94. @brief Spend the points.
  95. Use this method to notify server spend points.
  96. @param points Need spend number of points
  97. */
  98. void spendPoints(int points);
  99. /**
  100. @deprecated
  101. @brief set the Ads listener
  102. */
  103. CC_DEPRECATED_ATTRIBUTE inline void setAdsListener(AdsListener* listener)
  104. {
  105. _listener = listener;
  106. }
  107. /**
  108. @deprecated
  109. @brief set the Ads listener
  110. */
  111. CC_DEPRECATED_ATTRIBUTE inline AdsListener* getAdsListener()
  112. {
  113. return _listener;
  114. }
  115. /**
  116. @brief set the Ads callback function
  117. */
  118. inline void setCallback(ProtocolAdsCallback& cb)
  119. {
  120. _callback = cb;
  121. }
  122. /**
  123. @brief get the Ads callback function
  124. */
  125. inline ProtocolAdsCallback getCallback()
  126. {
  127. return _callback;
  128. }
  129. protected:
  130. AdsListener* _listener;
  131. ProtocolAdsCallback _callback;
  132. };
  133. }} // namespace cocos2d { namespace plugin {
  134. #endif /* __CCX_PROTOCOL_ADS_H__ */