ProtocolSocial.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /****************************************************************************
  2. Copyright (c) 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_SOCIAL_H__
  21. #define __CCX_PROTOCOL_SOCIAL_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> TSocialDeveloperInfo;
  28. typedef std::map<std::string, std::string> TAchievementInfo;
  29. typedef enum
  30. {
  31. // code for leaderboard feature
  32. SCORE_SUBMIT_SUCCESS = 1,
  33. SCORE_SUBMIT_FAILED,
  34. // code for achievement feature
  35. ACH_UNLOCK_SUCCESS,
  36. ACH_UNLOCK_FAILED,
  37. } SocialRetCode;
  38. class SocialListener
  39. {
  40. public:
  41. virtual void onSocialResult(SocialRetCode code, const char* msg) = 0;
  42. };
  43. class ProtocolSocial : public PluginProtocol
  44. {
  45. public:
  46. ProtocolSocial();
  47. virtual ~ProtocolSocial();
  48. typedef std::function<void(int, std::string&)> ProtocolSocialCallback;
  49. /**
  50. @brief config the share developer info
  51. @param devInfo This parameter is the info of developer,
  52. different plugin have different format
  53. @warning Must invoke this interface before other interfaces.
  54. And invoked only once.
  55. */
  56. void configDeveloperInfo(TSocialDeveloperInfo devInfo);
  57. /**
  58. * @brief methods of leaderboard feature
  59. */
  60. void submitScore(const char* leadboardID, long score);
  61. void submitScore(const char* leadboardID, long score, ProtocolSocialCallback cb);
  62. void showLeaderboard(const char* leaderboardID);
  63. /**
  64. * @brief methods of achievement feature
  65. */
  66. void unlockAchievement(TAchievementInfo achInfo);
  67. void unlockAchievement(TAchievementInfo achInfo, ProtocolSocialCallback cb);
  68. void showAchievements();
  69. /*
  70. @deprecated
  71. @brief set listener
  72. */
  73. CC_DEPRECATED_ATTRIBUTE inline void setListener(SocialListener* listener) {
  74. _listener = listener;
  75. }
  76. /*
  77. @deprecated
  78. @brief get listener
  79. */
  80. CC_DEPRECATED_ATTRIBUTE inline SocialListener* getListener()
  81. {
  82. return _listener;
  83. }
  84. /*
  85. @brief set callback function
  86. */
  87. inline void setCallback(ProtocolSocialCallback &cb)
  88. {
  89. _callback = cb;
  90. }
  91. /*
  92. @brief get callback function
  93. */
  94. inline ProtocolSocialCallback& getCallback()
  95. {
  96. return _callback;
  97. }
  98. protected:
  99. SocialListener* _listener;
  100. ProtocolSocialCallback _callback;
  101. };
  102. }} // namespace cocos2d { namespace plugin {
  103. #endif /* ----- #ifndef __CCX_PROTOCOL_SOCIAL_H__ ----- */