From 8a82b4b87a7542b6092cb07f912bdc47398e494e Mon Sep 17 00:00:00 2001 From: zhangbin Date: Fri, 19 Jul 2013 10:06:28 +0800 Subject: [PATCH 1/4] Rename the library file name of uc SDK. --- plugin/plugins/qh360/proj.android/ForManifest.xml | 1 - .../sdk/{alipay_msp.jar => alipay_plugin.jar} | Bin 2 files changed, 1 deletion(-) rename plugin/plugins/uc/proj.android/sdk/{alipay_msp.jar => alipay_plugin.jar} (100%) diff --git a/plugin/plugins/qh360/proj.android/ForManifest.xml b/plugin/plugins/qh360/proj.android/ForManifest.xml index a484866fc9..d7f0c9bc34 100644 --- a/plugin/plugins/qh360/proj.android/ForManifest.xml +++ b/plugin/plugins/qh360/proj.android/ForManifest.xml @@ -16,7 +16,6 @@ - diff --git a/plugin/plugins/uc/proj.android/sdk/alipay_msp.jar b/plugin/plugins/uc/proj.android/sdk/alipay_plugin.jar similarity index 100% rename from plugin/plugins/uc/proj.android/sdk/alipay_msp.jar rename to plugin/plugins/uc/proj.android/sdk/alipay_plugin.jar From b9bee5103f90975b7cd15f8357a636e63a074634 Mon Sep 17 00:00:00 2001 From: zhangbin Date: Tue, 23 Jul 2013 13:45:23 +0800 Subject: [PATCH 2/4] issue #2416, Add ProtocolSocial for android platform. --- plugin/protocols/include/ProtocolSocial.h | 96 +++++++++++ .../platform/android/PluginFactory.cpp | 5 + .../platform/android/ProtocolSocial.cpp | 159 ++++++++++++++++++ plugin/protocols/proj.android/jni/Android.mk | 1 + .../org/cocos2dx/plugin/InterfaceSocial.java | 39 +++++ .../org/cocos2dx/plugin/SocialWrapper.java | 46 +++++ 6 files changed, 346 insertions(+) create mode 100644 plugin/protocols/include/ProtocolSocial.h create mode 100644 plugin/protocols/platform/android/ProtocolSocial.cpp create mode 100755 plugin/protocols/proj.android/src/org/cocos2dx/plugin/InterfaceSocial.java create mode 100755 plugin/protocols/proj.android/src/org/cocos2dx/plugin/SocialWrapper.java diff --git a/plugin/protocols/include/ProtocolSocial.h b/plugin/protocols/include/ProtocolSocial.h new file mode 100644 index 0000000000..1af099da11 --- /dev/null +++ b/plugin/protocols/include/ProtocolSocial.h @@ -0,0 +1,96 @@ +/**************************************************************************** +Copyright (c) 2013 cocos2d-x.org + +http://www.cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ +#ifndef __CCX_PROTOCOL_SOCIAL_H__ +#define __CCX_PROTOCOL_SOCIAL_H__ + +#include "PluginProtocol.h" +#include +#include + +namespace cocos2d { namespace plugin { + +typedef std::map TSocialDeveloperInfo; +typedef std::map TAchievementInfo; + +typedef enum +{ + // code for leaderboard feature + SCORE_SUBMIT_SUCCESS = 1, + SCORE_SUBMIT_FAILED, + + // code for achievement feature + ACH_UNLOCK_SUCCESS, + ACH_UNLOCK_FAILED, + +} SocialRetCode; + +class SocialListener +{ +public: + virtual void onSocialResult(SocialRetCode code, const char* msg) = 0; +}; + +class ProtocolSocial : public PluginProtocol +{ +public: + ProtocolSocial(); + virtual ~ProtocolSocial(); + + /** + @brief config the share developer info + @param devInfo This parameter is the info of developer, + different plugin have different format + @warning Must invoke this interface before other interfaces. + And invoked only once. + */ + void configDeveloperInfo(TSocialDeveloperInfo devInfo); + + /** + * @brief methods of leaderboard feature + */ + void submitScore(const char* leadboardID, long score); + void showLeaderboard(const char* leaderboardID); + + /** + * @brief methods of achievement feature + */ + void unlockAchievement(TAchievementInfo achInfo); + void showAchievements(); + + inline void setListener(SocialListener* listener) { + _listener = listener; + } + + inline SocialListener* getListener() + { + return _listener; + } + +protected: + SocialListener* _listener; +}; + +}} // namespace cocos2d { namespace plugin { + +#endif /* ----- #ifndef __CCX_PROTOCOL_SOCIAL_H__ ----- */ diff --git a/plugin/protocols/platform/android/PluginFactory.cpp b/plugin/protocols/platform/android/PluginFactory.cpp index 5890c3e6af..f6468a394d 100644 --- a/plugin/protocols/platform/android/PluginFactory.cpp +++ b/plugin/protocols/platform/android/PluginFactory.cpp @@ -29,6 +29,7 @@ THE SOFTWARE. #include "ProtocolIAP.h" #include "ProtocolShare.h" #include "ProtocolUser.h" +#include "ProtocolSocial.h" namespace cocos2d { namespace plugin { @@ -38,6 +39,7 @@ enum { kPluginIAP, kPluginShare, kPluginUser, + kPluginSocial, }; #define ANDROID_PLUGIN_PACKAGE_PREFIX "org/cocos2dx/plugin/" @@ -134,6 +136,9 @@ PluginProtocol* PluginFactory::createPlugin(const char* name) case kPluginUser: pRet = new ProtocolUser(); break; + case kPluginSocial: + pRet = new ProtocolSocial(); + break; default: break; } diff --git a/plugin/protocols/platform/android/ProtocolSocial.cpp b/plugin/protocols/platform/android/ProtocolSocial.cpp new file mode 100644 index 0000000000..c599ce1a95 --- /dev/null +++ b/plugin/protocols/platform/android/ProtocolSocial.cpp @@ -0,0 +1,159 @@ +/**************************************************************************** +Copyright (c) 2013 cocos2d-x.org + +http://www.cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ +#include "ProtocolSocial.h" +#include "PluginJniHelper.h" +#include +#include "PluginUtils.h" +#include "PluginJavaData.h" + +namespace cocos2d { namespace plugin { + +extern "C" { + JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_SocialWrapper_nativeOnSocialResult(JNIEnv* env, jobject thiz, jstring className, jint ret, jstring msg) + { + std::string strMsg = PluginJniHelper::jstring2string(msg); + std::string strClassName = PluginJniHelper::jstring2string(className); + PluginProtocol* pPlugin = PluginUtils::getPluginPtr(strClassName); + PluginUtils::outputLog("ProtocolSocial", "nativeOnSocialResult(), Get plugin ptr : %p", pPlugin); + if (pPlugin != NULL) + { + PluginUtils::outputLog("ProtocolSocial", "nativeOnSocialResult(), Get plugin name : %s", pPlugin->getPluginName()); + ProtocolSocial* pSocial = dynamic_cast(pPlugin); + if (pSocial != NULL) + { + SocialListener* pListener = pSocial->getListener(); + if (NULL != pListener) + { + pListener->onSocialResult((SocialRetCode) ret, strMsg.c_str()); + } + } + } + } +} + +ProtocolSocial::ProtocolSocial() +: _listener(NULL) +{ +} + +ProtocolSocial::~ProtocolSocial() +{ +} + +void ProtocolSocial::configDeveloperInfo(TSocialDeveloperInfo devInfo) +{ + if (devInfo.empty()) + { + PluginUtils::outputLog("ProtocolSocial", "The developer info is empty!"); + return; + } + else + { + PluginJavaData* pData = PluginUtils::getPluginJavaData(this); + PluginJniMethodInfo t; + if (PluginJniHelper::getMethodInfo(t + , pData->jclassName.c_str() + , "configDeveloperInfo" + , "(Ljava/util/Hashtable;)V")) + { + // generate the hashtable from map + jobject obj_Map = PluginUtils::createJavaMapObject(&devInfo); + + // invoke java method + t.env->CallVoidMethod(pData->jobj, t.methodID, obj_Map); + t.env->DeleteLocalRef(obj_Map); + t.env->DeleteLocalRef(t.classID); + } + } +} + +void ProtocolSocial::submitScore(const char* leadboardID, long score) +{ + PluginJavaData* pData = PluginUtils::getPluginJavaData(this); + PluginJniMethodInfo t; + if (PluginJniHelper::getMethodInfo(t + , pData->jclassName.c_str() + , "submitScore" + , "(Ljava/lang/String;J)V")) + { + jstring strID = PluginUtils::getEnv()->NewStringUTF(leadboardID); + + // invoke java method + t.env->CallVoidMethod(pData->jobj, t.methodID, strID, score); + t.env->DeleteLocalRef(strID); + t.env->DeleteLocalRef(t.classID); + } +} + +void ProtocolSocial::showLeaderboard(const char* leaderboardID) +{ + PluginJavaData* pData = PluginUtils::getPluginJavaData(this); + PluginJniMethodInfo t; + if (PluginJniHelper::getMethodInfo(t + , pData->jclassName.c_str() + , "showLeaderboard" + , "(Ljava/lang/String;)V")) + { + jstring strID = PluginUtils::getEnv()->NewStringUTF(leaderboardID); + + // invoke java method + t.env->CallVoidMethod(pData->jobj, t.methodID, strID); + t.env->DeleteLocalRef(strID); + t.env->DeleteLocalRef(t.classID); + } +} + +void ProtocolSocial::unlockAchievement(TAchievementInfo achInfo) +{ + if (achInfo.empty()) + { + PluginUtils::outputLog("ProtocolSocial", "The achievement info is empty!"); + return; + } + else + { + PluginJavaData* pData = PluginUtils::getPluginJavaData(this); + PluginJniMethodInfo t; + if (PluginJniHelper::getMethodInfo(t + , pData->jclassName.c_str() + , "unlockAchievement" + , "(Ljava/util/Hashtable;)V")) + { + // generate the hashtable from map + jobject obj_Map = PluginUtils::createJavaMapObject(&achInfo); + + // invoke java method + t.env->CallVoidMethod(pData->jobj, t.methodID, obj_Map); + t.env->DeleteLocalRef(obj_Map); + t.env->DeleteLocalRef(t.classID); + } + } +} + +void ProtocolSocial::showAchievements() +{ + PluginUtils::callJavaFunctionWithName(this, "showAchievements"); +} + +}} // namespace cocos2d { namespace plugin { diff --git a/plugin/protocols/proj.android/jni/Android.mk b/plugin/protocols/proj.android/jni/Android.mk index 9bef67081c..c3fa21dfd5 100755 --- a/plugin/protocols/proj.android/jni/Android.mk +++ b/plugin/protocols/proj.android/jni/Android.mk @@ -17,6 +17,7 @@ $(addprefix ../../platform/android/, \ ProtocolAds.cpp \ ProtocolShare.cpp \ ProtocolUser.cpp \ + ProtocolSocial.cpp \ ) \ ../../PluginManager.cpp \ ../../PluginParam.cpp diff --git a/plugin/protocols/proj.android/src/org/cocos2dx/plugin/InterfaceSocial.java b/plugin/protocols/proj.android/src/org/cocos2dx/plugin/InterfaceSocial.java new file mode 100755 index 0000000000..395acb5abb --- /dev/null +++ b/plugin/protocols/proj.android/src/org/cocos2dx/plugin/InterfaceSocial.java @@ -0,0 +1,39 @@ +/**************************************************************************** +Copyright (c) 2012-2013 cocos2d-x.org + +http://www.cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ +package org.cocos2dx.plugin; + +import java.util.Hashtable; + +public interface InterfaceSocial { + public final int PluginType = 6; + + public void configDeveloperInfo(Hashtable cpInfo); + public void submitScore(String leaderboardID, long score); + public void showLeaderboard(String leaderboardID); + public void unlockAchievement(Hashtable achInfo); + public void showAchievements(); + public void setDebugMode(boolean debug); + public String getSDKVersion(); + public String getPluginVersion(); +} diff --git a/plugin/protocols/proj.android/src/org/cocos2dx/plugin/SocialWrapper.java b/plugin/protocols/proj.android/src/org/cocos2dx/plugin/SocialWrapper.java new file mode 100755 index 0000000000..c5ef9c24e5 --- /dev/null +++ b/plugin/protocols/proj.android/src/org/cocos2dx/plugin/SocialWrapper.java @@ -0,0 +1,46 @@ +/**************************************************************************** +Copyright (c) 2012-2013 cocos2d-x.org + +http://www.cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ +package org.cocos2dx.plugin; + +public class SocialWrapper { + public static final int SOCIAL_SUBMITSCORE_SUCCESS = 1; + public static final int SOCIAL_SUBMITSCORE_FAILED = 2; + public static final int SOCIAL_UNLOCKACH_SUCCESS = 3; + public static final int SOCIAL_UNLOCKACH_FAILED = 4; + + public static void onSocialResult(InterfaceSocial obj, int ret, String msg) { + final int curRet = ret; + final String curMsg = msg; + final InterfaceSocial curAdapter = obj; + PluginWrapper.runOnGLThread(new Runnable() { + @Override + public void run() { + String name = curAdapter.getClass().getName(); + name = name.replace('.', '/'); + nativeOnSocialResult(name, curRet, curMsg); + } + }); + } + private static native void nativeOnSocialResult(String className, int ret, String msg); +} From e35d06ae267cdcf3e8ce4e12b58620d058516b9b Mon Sep 17 00:00:00 2001 From: zhangbin Date: Tue, 23 Jul 2013 14:26:11 +0800 Subject: [PATCH 3/4] issue #2416, Add ProtocolSocial for iOS platform. --- .../protocols/platform/ios/InterfaceSocial.h | 36 ++++++ .../protocols/platform/ios/ProtocolSocial.mm | 115 ++++++++++++++++++ plugin/protocols/platform/ios/SocialWrapper.h | 42 +++++++ .../protocols/platform/ios/SocialWrapper.mm | 50 ++++++++ .../PluginProtocol.xcodeproj/project.pbxproj | 14 +++ 5 files changed, 257 insertions(+) create mode 100644 plugin/protocols/platform/ios/InterfaceSocial.h create mode 100644 plugin/protocols/platform/ios/ProtocolSocial.mm create mode 100644 plugin/protocols/platform/ios/SocialWrapper.h create mode 100644 plugin/protocols/platform/ios/SocialWrapper.mm diff --git a/plugin/protocols/platform/ios/InterfaceSocial.h b/plugin/protocols/platform/ios/InterfaceSocial.h new file mode 100644 index 0000000000..4d75991419 --- /dev/null +++ b/plugin/protocols/platform/ios/InterfaceSocial.h @@ -0,0 +1,36 @@ +/**************************************************************************** +Copyright (c) 2013 cocos2d+x.org + +http://www.cocos2d+x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ + +@protocol InterfaceSocial + +- (void) configDeveloperInfo : (NSMutableDictionary*) cpInfo; +- (void) submitScore: (NSString*) leaderboardID withScore: (long) score; +- (void) showLeaderboard: (NSString*) leaderboardID; +- (void) unlockAchievement: (NSMutableDictionary*) achInfo; +- (void) showAchievements; +- (void) setDebugMode: (BOOL) debug; +- (NSString*) getSDKVersion; +- (NSString*) getPluginVersion; + +@end diff --git a/plugin/protocols/platform/ios/ProtocolSocial.mm b/plugin/protocols/platform/ios/ProtocolSocial.mm new file mode 100644 index 0000000000..5a2db744ee --- /dev/null +++ b/plugin/protocols/platform/ios/ProtocolSocial.mm @@ -0,0 +1,115 @@ +/**************************************************************************** +Copyright (c) 2012-2013 cocos2d-x.org + +http://www.cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ +#include "ProtocolSocial.h" +#include "PluginUtilsIOS.h" +#import "InterfaceSocial.h" + +namespace cocos2d { namespace plugin { + +ProtocolSocial::ProtocolSocial() +: _listener(NULL) +{ +} + +ProtocolSocial::~ProtocolSocial() +{ +} + +void ProtocolSocial::configDeveloperInfo(TSocialDeveloperInfo devInfo) +{ + if (devInfo.empty()) + { + PluginUtilsIOS::outputLog("The developer info is empty for %s!", this->getPluginName()); + return; + } + else + { + PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this); + assert(pData != NULL); + + id ocObj = pData->obj; + if ([ocObj conformsToProtocol:@protocol(InterfaceSocial)]) { + NSObject* curObj = ocObj; + NSMutableDictionary* pDict = PluginUtilsIOS::createDictFromMap(&devInfo); + [curObj configDeveloperInfo:pDict]; + } + } +} + +void ProtocolSocial::submitScore(const char* leadboardID, long score) +{ + PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this); + assert(pData != NULL); + + id ocObj = pData->obj; + if ([ocObj conformsToProtocol:@protocol(InterfaceSocial)]) { + NSObject* curObj = ocObj; + + NSString* pID = [NSString stringWithUTF8String:leadboardID]; + [curObj submitScore:pID withScore:score]; + } +} + +void ProtocolSocial::showLeaderboard(const char* leaderboardID) +{ + PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this); + assert(pData != NULL); + + id ocObj = pData->obj; + if ([ocObj conformsToProtocol:@protocol(InterfaceSocial)]) { + NSObject* curObj = ocObj; + + NSString* pID = [NSString stringWithUTF8String:leaderboardID]; + [curObj showLeaderboard:pID]; + } +} + +void ProtocolSocial::unlockAchievement(TAchievementInfo achInfo) +{ + if (achInfo.empty()) + { + PluginUtilsIOS::outputLog("ProtocolSocial", "The achievement info is empty!"); + return; + } + else + { + PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this); + assert(pData != NULL); + + id ocObj = pData->obj; + if ([ocObj conformsToProtocol:@protocol(InterfaceSocial)]) { + NSObject* curObj = ocObj; + + NSMutableDictionary* pDict = PluginUtilsIOS::createDictFromMap(&achInfo); + [curObj unlockAchievement:pDict]; + } + } +} + +void ProtocolSocial::showAchievements() +{ + PluginUtilsIOS::callOCFunctionWithName(this, "showAchievements"); +} + +}} // namespace cocos2d { namespace plugin { diff --git a/plugin/protocols/platform/ios/SocialWrapper.h b/plugin/protocols/platform/ios/SocialWrapper.h new file mode 100644 index 0000000000..aa30f781e8 --- /dev/null +++ b/plugin/protocols/platform/ios/SocialWrapper.h @@ -0,0 +1,42 @@ +/**************************************************************************** +Copyright (c) 2013 cocos2d+x.org + +http://www.cocos2d+x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ + +#import + +typedef enum { + kSubmitScoreSuccess = 1, + kSubmitScoreFailed, + + kUnlockAchiSuccess, + kUnlockAchiFailed, +} SocialResult; + +@interface SocialWrapper : NSObject +{ + +} + ++ (void) onSocialResult:(id) obj withRet:(SocialResult) ret withMsg:(NSString*) msg; + +@end diff --git a/plugin/protocols/platform/ios/SocialWrapper.mm b/plugin/protocols/platform/ios/SocialWrapper.mm new file mode 100644 index 0000000000..1a0c488fd6 --- /dev/null +++ b/plugin/protocols/platform/ios/SocialWrapper.mm @@ -0,0 +1,50 @@ +/**************************************************************************** +Copyright (c) 2012+2013 cocos2d+x.org + +http://www.cocos2d+x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ + +#import "SocialWrapper.h" +#include "PluginUtilsIOS.h" +#include "ProtocolSocial.h" + +using namespace cocos2d::plugin; + +@implementation SocialWrapper + ++ (void) onSocialResult:(id) obj withRet:(SocialResult) ret withMsg:(NSString*) msg +{ + PluginProtocol* pPlugin = PluginUtilsIOS::getPluginPtr(obj); + ProtocolSocial* pSocial = dynamic_cast(pPlugin); + if (pSocial) { + SocialListener* pListener = pSocial->getListener(); + if (NULL != pListener) + { + const char* chMsg = [msg UTF8String]; + SocialRetCode cRet = (SocialRetCode) ret; + pListener->onSocialResult(cRet, chMsg); + } + } else { + PluginUtilsIOS::outputLog("Can't find the C++ object of the Social plugin"); + } +} + +@end diff --git a/plugin/protocols/proj.ios/PluginProtocol.xcodeproj/project.pbxproj b/plugin/protocols/proj.ios/PluginProtocol.xcodeproj/project.pbxproj index d25e99c866..b284140344 100644 --- a/plugin/protocols/proj.ios/PluginProtocol.xcodeproj/project.pbxproj +++ b/plugin/protocols/proj.ios/PluginProtocol.xcodeproj/project.pbxproj @@ -21,6 +21,8 @@ FAC2A7FA1777F8C200035D22 /* ShareWrapper.mm in Sources */ = {isa = PBXBuildFile; fileRef = FAC2A7F81777F8C200035D22 /* ShareWrapper.mm */; }; FAD55520177D1FA900968F54 /* ProtocolUser.mm in Sources */ = {isa = PBXBuildFile; fileRef = FAD5551D177D1FA900968F54 /* ProtocolUser.mm */; }; FAD55521177D1FA900968F54 /* UserWrapper.mm in Sources */ = {isa = PBXBuildFile; fileRef = FAD5551F177D1FA900968F54 /* UserWrapper.mm */; }; + FADBF89B179E509500F59B1D /* ProtocolSocial.mm in Sources */ = {isa = PBXBuildFile; fileRef = FADBF898179E509500F59B1D /* ProtocolSocial.mm */; }; + FADBF89C179E509500F59B1D /* SocialWrapper.mm in Sources */ = {isa = PBXBuildFile; fileRef = FADBF89A179E509500F59B1D /* SocialWrapper.mm */; }; FADC44CA176EABCF00B2D5ED /* AdsWrapper.mm in Sources */ = {isa = PBXBuildFile; fileRef = FADC44C9176EABCF00B2D5ED /* AdsWrapper.mm */; }; /* End PBXBuildFile section */ @@ -70,6 +72,11 @@ FAD5551E177D1FA900968F54 /* UserWrapper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UserWrapper.h; sourceTree = ""; }; FAD5551F177D1FA900968F54 /* UserWrapper.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = UserWrapper.mm; sourceTree = ""; }; FAD55522177D213F00968F54 /* ProtocolUser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProtocolUser.h; sourceTree = ""; }; + FADBF896179E504B00F59B1D /* ProtocolSocial.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProtocolSocial.h; sourceTree = ""; }; + FADBF897179E509500F59B1D /* InterfaceSocial.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InterfaceSocial.h; sourceTree = ""; }; + FADBF898179E509500F59B1D /* ProtocolSocial.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ProtocolSocial.mm; sourceTree = ""; }; + FADBF899179E509500F59B1D /* SocialWrapper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SocialWrapper.h; sourceTree = ""; }; + FADBF89A179E509500F59B1D /* SocialWrapper.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SocialWrapper.mm; sourceTree = ""; }; FADC44C8176EABCF00B2D5ED /* AdsWrapper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AdsWrapper.h; sourceTree = ""; }; FADC44C9176EABCF00B2D5ED /* AdsWrapper.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AdsWrapper.mm; sourceTree = ""; }; /* End PBXFileReference section */ @@ -119,6 +126,7 @@ FA09A336168ADC05008C1C7B /* include */ = { isa = PBXGroup; children = ( + FADBF896179E504B00F59B1D /* ProtocolSocial.h */, FAD55522177D213F00968F54 /* ProtocolUser.h */, FAC2A7F41777F88700035D22 /* ProtocolShare.h */, FAB6DF931755D7D100C90D89 /* PluginFactory.h */, @@ -136,6 +144,10 @@ FA0CB8B5168D3CC200E36B11 /* ios */ = { isa = PBXGroup; children = ( + FADBF897179E509500F59B1D /* InterfaceSocial.h */, + FADBF898179E509500F59B1D /* ProtocolSocial.mm */, + FADBF899179E509500F59B1D /* SocialWrapper.h */, + FADBF89A179E509500F59B1D /* SocialWrapper.mm */, FAD5551C177D1FA900968F54 /* InterfaceUser.h */, FAD5551D177D1FA900968F54 /* ProtocolUser.mm */, FAD5551E177D1FA900968F54 /* UserWrapper.h */, @@ -226,6 +238,8 @@ FAC2A7FA1777F8C200035D22 /* ShareWrapper.mm in Sources */, FAD55520177D1FA900968F54 /* ProtocolUser.mm in Sources */, FAD55521177D1FA900968F54 /* UserWrapper.mm in Sources */, + FADBF89B179E509500F59B1D /* ProtocolSocial.mm in Sources */, + FADBF89C179E509500F59B1D /* SocialWrapper.mm in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; From 9edc1dff80dd48523fdd7c5b4f2ec318e25f9b84 Mon Sep 17 00:00:00 2001 From: zhangbin Date: Tue, 23 Jul 2013 14:29:11 +0800 Subject: [PATCH 4/4] closed #2416, Add social plugin : SocialNd91 & add sample code for social plugins. --- .../src/org/cocos2dx/plugin/SocialNd91.java | 241 ++++++++++++++++++ .../HelloPlugins/Classes/HelloWorldScene.cpp | 12 +- .../Classes/TestAds/TestAdsScene.cpp | 2 +- .../TestAnalytics/TestAnalyticsScene.cpp | 2 +- .../Classes/TestIAP/TestIAPScene.cpp | 2 +- .../TestIAPOnline/TestIAPOnlineScene.cpp | 16 +- .../Classes/TestShare/TestShareScene.cpp | 16 +- .../Classes/TestSocial/MySocialManager.cpp | 170 ++++++++++++ .../Classes/TestSocial/MySocialManager.h | 59 +++++ .../Classes/TestSocial/TestSocialScene.cpp | 152 +++++++++++ .../Classes/TestSocial/TestSocialScene.h | 52 ++++ .../Classes/TestUser/TestUserScene.cpp | 41 ++- .../Classes/TestUser/TestUserScene.h | 23 ++ .../HelloPlugins/proj.android/jni/Android.mk | 7 +- .../HelloPlugins.xcodeproj/project.pbxproj | 21 ++ 15 files changed, 782 insertions(+), 34 deletions(-) create mode 100644 plugin/plugins/nd91/proj.android/src/org/cocos2dx/plugin/SocialNd91.java create mode 100644 plugin/samples/HelloPlugins/Classes/TestSocial/MySocialManager.cpp create mode 100755 plugin/samples/HelloPlugins/Classes/TestSocial/MySocialManager.h create mode 100644 plugin/samples/HelloPlugins/Classes/TestSocial/TestSocialScene.cpp create mode 100644 plugin/samples/HelloPlugins/Classes/TestSocial/TestSocialScene.h diff --git a/plugin/plugins/nd91/proj.android/src/org/cocos2dx/plugin/SocialNd91.java b/plugin/plugins/nd91/proj.android/src/org/cocos2dx/plugin/SocialNd91.java new file mode 100644 index 0000000000..7ff1229fae --- /dev/null +++ b/plugin/plugins/nd91/proj.android/src/org/cocos2dx/plugin/SocialNd91.java @@ -0,0 +1,241 @@ +/**************************************************************************** +Copyright (c) 2013 cocos2d-x.org + +http://www.cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ +package org.cocos2dx.plugin; + +import java.util.Hashtable; + +import com.nd.commplatform.NdCallbackListener; +import com.nd.commplatform.NdCommplatform; +import com.nd.commplatform.NdErrorCode; +import com.nd.commplatform.NdMiscCallbackListener.OnLoginProcessListener; +import com.nd.commplatform.entry.NdAchieveUnlockInfo; + +import android.app.Activity; +import android.content.Context; +import android.text.TextUtils; +import android.util.Log; + +public class SocialNd91 implements InterfaceSocial { + + private static final String LOG_TAG = "UserNd91"; + private static Activity mContext = null; + private static SocialNd91 mNd91 = null; + private static boolean bDebug = false; + private static NdCallbackListener submitListener = null; + private static NdCallbackListener unlockListener = null; + + protected static void LogE(String msg, Exception e) { + Log.e(LOG_TAG, msg, e); + e.printStackTrace(); + } + + protected static void LogD(String msg) { + if (bDebug) { + Log.d(LOG_TAG, msg); + } + } + + public SocialNd91(Context context) { + mContext = (Activity) context; + mNd91 = this; + + submitListener = new NdCallbackListener(){ + @Override + public void callback(int arg0, Object arg1) { + int nRet = SocialWrapper.SOCIAL_SUBMITSCORE_FAILED; + String msg = "Unknow Error"; + switch (arg0) { + case NdCommplatform.SCORE_SUBMIT_SUCCESS: + nRet = SocialWrapper.SOCIAL_SUBMITSCORE_SUCCESS; + msg = "Submit Success"; + break; + case NdCommplatform.SCORE_SAVE_LOCAL: + nRet = SocialWrapper.SOCIAL_SUBMITSCORE_FAILED; + msg = "Score saved locally"; + break; + case NdCommplatform.LEADERBOARD_NOT_EXIST: + nRet = SocialWrapper.SOCIAL_SUBMITSCORE_FAILED; + msg = "The leaderboard not exist"; + break; + default: + nRet = SocialWrapper.SOCIAL_SUBMITSCORE_FAILED; + break; + } + SocialWrapper.onSocialResult(mNd91, nRet, msg); + } + }; + + unlockListener = new NdCallbackListener(){ + @Override + public void callback(int arg0, Object arg1) { + int nRet = SocialWrapper.SOCIAL_UNLOCKACH_FAILED; + String msg = "Unknow Error"; + switch (arg0) { + case NdErrorCode.ND_COM_PLATFORM_SUCCESS: + nRet = SocialWrapper.SOCIAL_UNLOCKACH_SUCCESS; + msg = "Unlock Success"; + break; + case NdErrorCode.ND_COM_PLATFORM_ERROR_SERVER_RETURN_ERROR: + nRet = SocialWrapper.SOCIAL_UNLOCKACH_FAILED; + msg = "Server return error"; + break; + case NdErrorCode.ND_COM_PLATFORM_ERROR_ACHIEVEMENT_NO_EXIST: + nRet = SocialWrapper.SOCIAL_UNLOCKACH_FAILED; + msg = "Achievement not exist"; + break; + default: + nRet = SocialWrapper.SOCIAL_UNLOCKACH_FAILED; + break; + } + SocialWrapper.onSocialResult(mNd91, nRet, msg); + } + }; + } + + @Override + public void configDeveloperInfo(Hashtable cpInfo) { + LogD("initDeveloperInfo invoked " + cpInfo.toString()); + final Hashtable curCPInfo = cpInfo; + PluginWrapper.runOnMainThread(new Runnable() { + @Override + public void run() { + try { + String appId = curCPInfo.get("Nd91AppId"); + String appKey = curCPInfo.get("Nd91AppKey"); + int id = Integer.parseInt(appId); + + String orientation = curCPInfo.get("Nd91Orientation"); + Nd91Wrapper.initSDK(mContext, id, appKey, orientation); + + } catch (Exception e) { + LogE("Developer info is wrong!", e); + } + } + }); + } + + @Override + public void submitScore(String leaderboardID, long score) { + final String curID = leaderboardID; + final long curScore = score; + PluginWrapper.runOnMainThread(new Runnable() { + @Override + public void run() { + NdCommplatform.getInstance().ndSubmitScore(curID, (int) curScore, null, (Activity) mContext, submitListener); + } + }); + } + + @Override + public void showLeaderboard(String leaderboardID) { + final String curID = leaderboardID; + PluginWrapper.runOnMainThread(new Runnable() { + @Override + public void run() { + if (Nd91Wrapper.isLogined()) { + NdCommplatform.getInstance().ndOpenLeaderBoard(mContext, curID, 0); + } else { + Nd91Wrapper.userLogin(mContext, new OnLoginProcessListener() { + @Override + public void finishLoginProcess(int code) { + if (code == NdErrorCode.ND_COM_PLATFORM_SUCCESS) { + NdCommplatform.getInstance().ndOpenLeaderBoard(mContext, curID, 0); + } else { + LogD("User should login first"); + } + } + }); + } + } + }); + } + + @Override + public void unlockAchievement(Hashtable achInfo) { + final Hashtable curInfo = achInfo; + PluginWrapper.runOnMainThread(new Runnable() { + @Override + public void run() { + try { + String achID = curInfo.get("AchievementID"); + if (achID == null || TextUtils.isEmpty(achID)) + { + SocialWrapper.onSocialResult(mNd91, SocialWrapper.SOCIAL_UNLOCKACH_FAILED, "Achievement info error"); + return; + } + + String displayText = curInfo.get("NDDisplayText"); + String strScore = curInfo.get("NDScore"); + long score = Long.parseLong(strScore); + NdAchieveUnlockInfo info = new NdAchieveUnlockInfo(); + info.setAchievementId(achID); + info.setCurrentValue(score); + info.setDisplayText(displayText); + + NdCommplatform.getInstance().ndUnlockAchievement(info, mContext, unlockListener); + } catch (Exception e) { + LogE("Unknown Error!", e); + } + } + }); + } + + @Override + public void showAchievements() { + PluginWrapper.runOnMainThread(new Runnable() { + @Override + public void run() { + if (Nd91Wrapper.isLogined()) { + NdCommplatform.getInstance().ndOpenAchievement(mContext, 0); + } else { + Nd91Wrapper.userLogin(mContext, new OnLoginProcessListener() { + @Override + public void finishLoginProcess(int code) { + if (code == NdErrorCode.ND_COM_PLATFORM_SUCCESS) { + NdCommplatform.getInstance().ndOpenAchievement(mContext, 0); + } else { + LogD("User should login first"); + } + } + }); + } + } + }); + } + + @Override + public void setDebugMode(boolean debug) { + bDebug = debug; + } + + @Override + public String getSDKVersion() { + return Nd91Wrapper.getSDKVersion(); + } + + @Override + public String getPluginVersion() { + return Nd91Wrapper.getPluginVersion(); + } +} diff --git a/plugin/samples/HelloPlugins/Classes/HelloWorldScene.cpp b/plugin/samples/HelloPlugins/Classes/HelloWorldScene.cpp index 9b1e656089..e27b1da8ae 100644 --- a/plugin/samples/HelloPlugins/Classes/HelloWorldScene.cpp +++ b/plugin/samples/HelloPlugins/Classes/HelloWorldScene.cpp @@ -5,6 +5,7 @@ #include "TestIAPScene.h" #include "TestIAPOnlineScene.h" #include "TestUserScene.h" +#include "TestSocialScene.h" USING_NS_CC; @@ -16,6 +17,7 @@ std::string g_testCases[] = { "Test IAP", "Test IAP Online", "Test User", + "Test Social", #endif }; @@ -57,22 +59,22 @@ bool HelloWorld::init() "CloseSelected.png", CC_CALLBACK_1(HelloWorld::menuCloseCallback, this)); - pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 , + pCloseItem->setPosition(Point(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 , origin.y + pCloseItem->getContentSize().height/2)); // create menu, it's an autorelease object Menu* pMenu = Menu::create(pCloseItem, NULL); - pMenu->setPosition(PointZero); + pMenu->setPosition(Point::ZERO); this->addChild(pMenu, 1); - Point beginPos = ccp(origin.x + visibleSize.width / 2, origin.y + visibleSize.height - 50); + Point beginPos = Point(origin.x + visibleSize.width / 2, origin.y + visibleSize.height - 50); float step = 60.0f; int nCaseCount = sizeof(g_testCases) / sizeof(std::string); for (int i = 0; i < nCaseCount; ++i) { std::string caseName = g_testCases[i]; MenuItemFont *pItem = MenuItemFont::create(caseName.c_str(), CC_CALLBACK_1(HelloWorld::menuCallback, this)); pItem->setTag(i); - pItem->setPosition(ccp(beginPos.x, beginPos.y - i * step)); + pItem->setPosition(Point(beginPos.x, beginPos.y - i * step)); pMenu->addChild(pItem); } return true; @@ -101,6 +103,8 @@ void HelloWorld::menuCallback(Object* pSender) case 5: newScene = TestUser::scene(); break; + case 6: + newScene = TestSocial::scene(); default: break; } diff --git a/plugin/samples/HelloPlugins/Classes/TestAds/TestAdsScene.cpp b/plugin/samples/HelloPlugins/Classes/TestAds/TestAdsScene.cpp index 2f7857e36f..40a85b0ffe 100644 --- a/plugin/samples/HelloPlugins/Classes/TestAds/TestAdsScene.cpp +++ b/plugin/samples/HelloPlugins/Classes/TestAds/TestAdsScene.cpp @@ -103,7 +103,7 @@ bool TestAds::init() // create menu, it's an autorelease object Menu* pMenu = Menu::create(pBackItem, NULL); - pMenu->setPosition( PointZero ); + pMenu->setPosition( Point::ZERO ); LabelTTF* label1 = LabelTTF::create("ShowAds", "Arial", 24); MenuItemLabel* pItemShow = MenuItemLabel::create(label1, CC_CALLBACK_1(TestAds::testShow, this)); diff --git a/plugin/samples/HelloPlugins/Classes/TestAnalytics/TestAnalyticsScene.cpp b/plugin/samples/HelloPlugins/Classes/TestAnalytics/TestAnalyticsScene.cpp index c7393c12b8..b24d7b409f 100644 --- a/plugin/samples/HelloPlugins/Classes/TestAnalytics/TestAnalyticsScene.cpp +++ b/plugin/samples/HelloPlugins/Classes/TestAnalytics/TestAnalyticsScene.cpp @@ -102,7 +102,7 @@ bool TestAnalytics::init() // create menu, it's an autorelease object Menu* pMenu = Menu::create(pBackItem, NULL); - pMenu->setPosition( PointZero ); + pMenu->setPosition( Point::ZERO ); this->addChild(pMenu, 1); float yPos = 0; diff --git a/plugin/samples/HelloPlugins/Classes/TestIAP/TestIAPScene.cpp b/plugin/samples/HelloPlugins/Classes/TestIAP/TestIAPScene.cpp index baae4e4bbd..4d195d2952 100644 --- a/plugin/samples/HelloPlugins/Classes/TestIAP/TestIAPScene.cpp +++ b/plugin/samples/HelloPlugins/Classes/TestIAP/TestIAPScene.cpp @@ -87,7 +87,7 @@ bool TestIAP::init() // create menu, it's an autorelease object Menu* pMenu = Menu::create(pBackItem, NULL); - pMenu->setPosition( PointZero ); + pMenu->setPosition( Point::ZERO ); this->addChild(pMenu, 1); Point posStep = ccp(220, -150); diff --git a/plugin/samples/HelloPlugins/Classes/TestIAPOnline/TestIAPOnlineScene.cpp b/plugin/samples/HelloPlugins/Classes/TestIAPOnline/TestIAPOnlineScene.cpp index aefeb559a8..e8d59f9953 100644 --- a/plugin/samples/HelloPlugins/Classes/TestIAPOnline/TestIAPOnlineScene.cpp +++ b/plugin/samples/HelloPlugins/Classes/TestIAPOnline/TestIAPOnlineScene.cpp @@ -81,21 +81,21 @@ bool TestIAPOnline::init() // you may modify it. EGLView* pEGLView = EGLView::getInstance(); - Point posBR = ccp(pEGLView->getVisibleOrigin().x + pEGLView->getVisibleSize().width, pEGLView->getVisibleOrigin().y); - Point posTL = ccp(pEGLView->getVisibleOrigin().x, pEGLView->getVisibleOrigin().y + pEGLView->getVisibleSize().height); + Point posBR = Point(pEGLView->getVisibleOrigin().x + pEGLView->getVisibleSize().width, pEGLView->getVisibleOrigin().y); + Point posTL = Point(pEGLView->getVisibleOrigin().x, pEGLView->getVisibleOrigin().y + pEGLView->getVisibleSize().height); // add a "close" icon to exit the progress. it's an autorelease object MenuItemFont *pBackItem = MenuItemFont::create("Back", CC_CALLBACK_1(TestIAPOnline::menuBackCallback, this)); Size backSize = pBackItem->getContentSize(); - pBackItem->setPosition(ccpAdd(posBR, ccp(- backSize.width / 2, backSize.height / 2))); + pBackItem->setPosition(posBR + Point(- backSize.width / 2, backSize.height / 2)); // create menu, it's an autorelease object Menu* pMenu = Menu::create(pBackItem, NULL); - pMenu->setPosition( PointZero ); + pMenu->setPosition( Point::ZERO ); this->addChild(pMenu, 1); - Point posStep = ccp(220, -150); - Point beginPos = ccpAdd(posTL, ccpMult(posStep, 0.5f)); + Point posStep = Point(220, -150); + Point beginPos = posTL + (posStep * 0.5f); int line = 0; int row = 0; for (int i = 0; i < sizeof(s_EventMenuItem)/sizeof(s_EventMenuItem[0]); i++) { @@ -103,13 +103,13 @@ bool TestIAPOnline::init() CC_CALLBACK_1(TestIAPOnline::eventMenuCallback, this)); pMenu->addChild(pMenuItem, 0, s_EventMenuItem[i].tag); - Point pos = ccpAdd(beginPos, ccp(posStep.x * row, posStep.y * line)); + Point pos = beginPos + Point(posStep.x * row, posStep.y * line); Size itemSize = pMenuItem->getContentSize(); if ((pos.x + itemSize.width / 2) > posBR.x) { line += 1; row = 0; - pos = ccpAdd(beginPos, ccp(posStep.x * row, posStep.y * line)); + pos = beginPos + Point(posStep.x * row, posStep.y * line); } row += 1; pMenuItem->setPosition(pos); diff --git a/plugin/samples/HelloPlugins/Classes/TestShare/TestShareScene.cpp b/plugin/samples/HelloPlugins/Classes/TestShare/TestShareScene.cpp index 58633823c1..1be29f9439 100644 --- a/plugin/samples/HelloPlugins/Classes/TestShare/TestShareScene.cpp +++ b/plugin/samples/HelloPlugins/Classes/TestShare/TestShareScene.cpp @@ -77,34 +77,34 @@ bool TestShare::init() // you may modify it. EGLView* pEGLView = EGLView::getInstance(); - Point posBR = ccp(pEGLView->getVisibleOrigin().x + pEGLView->getVisibleSize().width, pEGLView->getVisibleOrigin().y); - Point posTL = ccp(pEGLView->getVisibleOrigin().x, pEGLView->getVisibleOrigin().y + pEGLView->getVisibleSize().height); + Point posBR = Point(pEGLView->getVisibleOrigin().x + pEGLView->getVisibleSize().width, pEGLView->getVisibleOrigin().y); + Point posTL = Point(pEGLView->getVisibleOrigin().x, pEGLView->getVisibleOrigin().y + pEGLView->getVisibleSize().height); // add a "close" icon to exit the progress. it's an autorelease object MenuItemFont *pBackItem = MenuItemFont::create("Back", CC_CALLBACK_1(TestShare::menuBackCallback, this)); Size backSize = pBackItem->getContentSize(); - pBackItem->setPosition(ccpAdd(posBR, ccp(- backSize.width / 2, backSize.height / 2))); + pBackItem->setPosition(posBR + Point(- backSize.width / 2, backSize.height / 2)); // create menu, it's an autorelease object Menu* pMenu = Menu::create(pBackItem, NULL); - pMenu->setPosition( PointZero ); + pMenu->setPosition( Point::ZERO ); this->addChild(pMenu, 1); - Point posStep = ccp(150, -150); - Point beginPos = ccpAdd(posTL, ccpMult(posStep, 0.5f)); + Point posStep = Point(150, -150); + Point beginPos = posTL + (posStep * 0.5f); int line = 0; int row = 0; for (int i = 0; i < sizeof(s_EventMenuItem)/sizeof(s_EventMenuItem[0]); i++) { MenuItemImage* pMenuItem = MenuItemImage::create(s_EventMenuItem[i].id.c_str(), s_EventMenuItem[i].id.c_str(), CC_CALLBACK_1(TestShare::eventMenuCallback, this)); pMenu->addChild(pMenuItem, 0, s_EventMenuItem[i].tag); - Point pos = ccpAdd(beginPos, ccp(posStep.x * row, posStep.y * line)); + Point pos = beginPos + Point(posStep.x * row, posStep.y * line); Size itemSize = pMenuItem->getContentSize(); if ((pos.x + itemSize.width / 2) > posBR.x) { line += 1; row = 0; - pos = ccpAdd(beginPos, ccp(posStep.x * row, posStep.y * line)); + pos = beginPos + Point(posStep.x * row, posStep.y * line); } row += 1; pMenuItem->setPosition(pos); diff --git a/plugin/samples/HelloPlugins/Classes/TestSocial/MySocialManager.cpp b/plugin/samples/HelloPlugins/Classes/TestSocial/MySocialManager.cpp new file mode 100644 index 0000000000..97ed27f872 --- /dev/null +++ b/plugin/samples/HelloPlugins/Classes/TestSocial/MySocialManager.cpp @@ -0,0 +1,170 @@ +/**************************************************************************** +Copyright (c) 2013 cocos2d-x.org + +http://www.cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ +#include "MySocialManager.h" +#include "PluginManager.h" +#include "cocos2d.h" + +using namespace cocos2d::plugin; +using namespace cocos2d; + +MySocialManager* MySocialManager::s_pManager = NULL; + +MySocialManager::MySocialManager() +: _pNd91(NULL) +{ + +} + +MySocialManager::~MySocialManager() +{ + unloadPlugins(); +} + +MySocialManager* MySocialManager::sharedManager() +{ + if (s_pManager == NULL) { + s_pManager = new MySocialManager(); + } + return s_pManager; +} + +void MySocialManager::purgeManager() +{ + if (s_pManager) + { + delete s_pManager; + s_pManager = NULL; + } + PluginManager::end(); +} + +void MySocialManager::loadPlugins() +{ + { + _pNd91 = dynamic_cast(PluginManager::getInstance()->loadPlugin("SocialNd91")); + if (NULL != _pNd91) + { + TSocialDeveloperInfo pNdInfo; + pNdInfo["Nd91AppId"] = "100010"; + pNdInfo["Nd91AppKey"] = "C28454605B9312157C2F76F27A9BCA2349434E546A6E9C75"; + pNdInfo["Nd91Orientation"] = "landscape"; + if (pNdInfo.empty()) { + char msg[256] = { 0 }; + sprintf(msg, "Developer info is empty. PLZ fill your Nd91 info in %s(nearby line %d)", __FILE__, __LINE__); + MessageBox(msg, "Nd91 Warning"); + } + _pNd91->configDeveloperInfo(pNdInfo); + _pNd91->setDebugMode(true); + _pNd91->setListener(this); + } + } +} + +void MySocialManager::submitScore(MySocialMode mode, const char* leaderboardID, long score) +{ + ProtocolSocial* pSocial = NULL; + switch (mode) + { + case eNd91: + pSocial = _pNd91; + break; + default: + break; + } + + if (NULL != pSocial) + { + pSocial->submitScore(leaderboardID, score); + } +} + +void MySocialManager::showLeaderboard(MySocialMode mode, const char* leaderboardID) +{ + ProtocolSocial* pSocial = NULL; + switch (mode) + { + case eNd91: + pSocial = _pNd91; + break; + default: + break; + } + + if (NULL != pSocial) + { + pSocial->showLeaderboard(leaderboardID); + } +} + +void MySocialManager::unlockAchievement(MySocialMode mode, TAchievementInfo info) +{ + ProtocolSocial* pSocial = NULL; + switch (mode) + { + case eNd91: + pSocial = _pNd91; + break; + default: + break; + } + + if (NULL != pSocial) + { + pSocial->unlockAchievement(info); + } +} + +void MySocialManager::showAchievement(MySocialMode mode) +{ + ProtocolSocial* pSocial = NULL; + switch (mode) + { + case eNd91: + pSocial = _pNd91; + break; + default: + break; + } + + if (NULL != pSocial) + { + pSocial->showAchievements(); + } +} + +void MySocialManager::unloadPlugins() +{ + if (_pNd91) + { + PluginManager::getInstance()->unloadPlugin("SocialNd91"); + _pNd91 = NULL; + } +} + +void MySocialManager::onSocialResult(SocialRetCode code, const char* msg) +{ + char socialStatus[1024] = { 0 }; + sprintf(socialStatus, "Social code %d", code); + MessageBox(msg, socialStatus); +} diff --git a/plugin/samples/HelloPlugins/Classes/TestSocial/MySocialManager.h b/plugin/samples/HelloPlugins/Classes/TestSocial/MySocialManager.h new file mode 100755 index 0000000000..69cfee5bba --- /dev/null +++ b/plugin/samples/HelloPlugins/Classes/TestSocial/MySocialManager.h @@ -0,0 +1,59 @@ +/**************************************************************************** +Copyright (c) 2013 cocos2d-x.org + +http://www.cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ +#ifndef __MY_SOCIAL_MANAGER_H__ +#define __MY_SOCIAL_MANAGER_H__ + +#include "ProtocolSocial.h" + +class MySocialManager : public cocos2d::plugin::SocialListener +{ +public: + static MySocialManager* sharedManager(); + static void purgeManager(); + + typedef enum { + eNoneMode = 0, + eNd91, + } MySocialMode; + + void unloadPlugins(); + void loadPlugins(); + + void submitScore(MySocialMode mode, const char* leaderboardID, long score); + void showLeaderboard(MySocialMode mode, const char* leaderboardID); + void unlockAchievement(MySocialMode mode, cocos2d::plugin::TAchievementInfo info); + void showAchievement(MySocialMode mode); + + virtual void onSocialResult(cocos2d::plugin::SocialRetCode code, const char* msg); + +private: + MySocialManager(); + virtual ~MySocialManager(); + + static MySocialManager* s_pManager; + + cocos2d::plugin::ProtocolSocial* _pNd91; +}; + +#endif // __MY_SOCIAL_MANAGER_H__ diff --git a/plugin/samples/HelloPlugins/Classes/TestSocial/TestSocialScene.cpp b/plugin/samples/HelloPlugins/Classes/TestSocial/TestSocialScene.cpp new file mode 100644 index 0000000000..2415ca6dd9 --- /dev/null +++ b/plugin/samples/HelloPlugins/Classes/TestSocial/TestSocialScene.cpp @@ -0,0 +1,152 @@ +/**************************************************************************** +Copyright (c) 2013 cocos2d-x.org + +http://www.cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ +#include "TestSocialScene.h" +#include "PluginManager.h" +#include "AppDelegate.h" +#include "MySocialManager.h" +#include "HelloWorldScene.h" + +using namespace cocos2d; +using namespace cocos2d::plugin; + +const std::string s_aTestCases[] = { + "Nd91", +}; + +Scene* TestSocial::scene() +{ + // 'scene' is an autorelease object + Scene *scene = Scene::create(); + + // 'layer' is an autorelease object + TestSocial *layer = TestSocial::create(); + + // add layer as a child to scene + scene->addChild(layer); + + // return the scene + return scene; +} + +// on "init" you need to initialize your instance +bool TestSocial::init() +{ + ////////////////////////////// + // 1. super init first + if ( !Layer::init() ) + { + return false; + } + + MySocialManager::sharedManager()->loadPlugins(); + + Size visibleSize = Director::getInstance()->getVisibleSize(); + Point origin = Director::getInstance()->getVisibleOrigin(); + Point posMid = Point(origin.x + visibleSize.width / 2, origin.y + visibleSize.height / 2); + Point posBR = Point(origin.x + visibleSize.width, origin.y); + + MenuItemFont *pBackItem = MenuItemFont::create("Back", CC_CALLBACK_1(TestSocial::menuBackCallback, this)); + Size backSize = pBackItem->getContentSize(); + pBackItem->setPosition(posBR + Point(- backSize.width / 2, backSize.height / 2)); + + // create menu, it's an autorelease object + Menu* pMenu = Menu::create(pBackItem, NULL); + pMenu->setPosition( Point::ZERO ); + + LabelTTF* label1 = LabelTTF::create("Submit Score", "Arial", 28); + MenuItemLabel* pItemSubmit = MenuItemLabel::create(label1, CC_CALLBACK_1(TestSocial::testSubmit, this)); + pItemSubmit->setAnchorPoint(Point(0.5f, 0)); + pMenu->addChild(pItemSubmit, 0); + pItemSubmit->setPosition(posMid + Point(-140, -60)); + + LabelTTF* label2 = LabelTTF::create("Unlock Achievement", "Arial", 28); + MenuItemLabel* pItemUnlock = MenuItemLabel::create(label2, CC_CALLBACK_1(TestSocial::testUnlock, this)); + pItemUnlock->setAnchorPoint(Point(0.5f, 0)); + pMenu->addChild(pItemUnlock, 0); + pItemUnlock->setPosition(posMid + Point(140, -60)); + + LabelTTF* label3 = LabelTTF::create("Show Leaderboard", "Arial", 28); + MenuItemLabel* pItemLeader = MenuItemLabel::create(label3, CC_CALLBACK_1(TestSocial::testLeaderboard, this)); + pItemLeader->setAnchorPoint(Point(0.5f, 0)); + pMenu->addChild(pItemLeader, 0); + pItemLeader->setPosition(posMid + Point(-140, -120)); + + LabelTTF* label4 = LabelTTF::create("Show Achievement", "Arial", 28); + MenuItemLabel* pItemAchi = MenuItemLabel::create(label4, CC_CALLBACK_1(TestSocial::testAchievement, this)); + pItemAchi->setAnchorPoint(Point(0.5f, 0)); + pMenu->addChild(pItemAchi, 0); + pItemAchi->setPosition(posMid + Point(140, -120)); + + // create optional menu + // cases item + _caseItem = MenuItemToggle::createWithCallback(NULL, + MenuItemFont::create( s_aTestCases[0].c_str() ), + NULL ); + int caseLen = sizeof(s_aTestCases) / sizeof(std::string); + for (int i = 1; i < caseLen; ++i) + { + _caseItem->getSubItems()->addObject( MenuItemFont::create( s_aTestCases[i].c_str() ) ); + } + _caseItem->setPosition(posMid + Point(0, 120)); + pMenu->addChild(_caseItem); + + this->addChild(pMenu, 1); + + return true; +} + +void TestSocial::testSubmit(Object* pSender) +{ + int nIdx = _caseItem->getSelectedIndex(); + MySocialManager::sharedManager()->submitScore((MySocialManager::MySocialMode)(nIdx + 1), "0", 30000); +} + +void TestSocial::testUnlock(Object* pSender) +{ + int nIdx = _caseItem->getSelectedIndex(); + TAchievementInfo info; + info["AchievementID"] = "MyAchiID"; + info["NDDisplayText"] = "Fighter"; + info["NDScore"] = "100"; + MySocialManager::sharedManager()->unlockAchievement((MySocialManager::MySocialMode)(nIdx + 1), info); +} + +void TestSocial::testLeaderboard(Object* pSender) +{ + int nIdx = _caseItem->getSelectedIndex(); + MySocialManager::sharedManager()->showLeaderboard((MySocialManager::MySocialMode)(nIdx + 1), "0"); +} + +void TestSocial::testAchievement(Object* pSender) +{ + int nIdx = _caseItem->getSelectedIndex(); + MySocialManager::sharedManager()->showAchievement((MySocialManager::MySocialMode)(nIdx + 1)); +} + +void TestSocial::menuBackCallback(Object* pSender) +{ + MySocialManager::purgeManager(); + Scene* newScene = HelloWorld::scene(); + Director::getInstance()->replaceScene(newScene); +} diff --git a/plugin/samples/HelloPlugins/Classes/TestSocial/TestSocialScene.h b/plugin/samples/HelloPlugins/Classes/TestSocial/TestSocialScene.h new file mode 100644 index 0000000000..2a49722afb --- /dev/null +++ b/plugin/samples/HelloPlugins/Classes/TestSocial/TestSocialScene.h @@ -0,0 +1,52 @@ +/**************************************************************************** +Copyright (c) 2013 cocos2d-x.org + +http://www.cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ +#ifndef __TEST_SOCIAL_SCENE_H__ +#define __TEST_SOCIAL_SCENE_H__ + +#include "cocos2d.h" + +class TestSocial : public cocos2d::Layer +{ +public: + // Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone + virtual bool init(); + + // there's no 'id' in cpp, so we recommand to return the exactly class pointer + static cocos2d::Scene* scene(); + + // a selector callback + void menuBackCallback(Object* pSender); + void testSubmit(Object* pSender); + void testUnlock(Object* pSender); + void testLeaderboard(Object* pSender); + void testAchievement(Object* pSender); + + // implement the "static node()" method manually + CREATE_FUNC(TestSocial); + +private: + cocos2d::MenuItemToggle* _caseItem; +}; + +#endif // __TEST_SOCIAL_SCENE_H__ diff --git a/plugin/samples/HelloPlugins/Classes/TestUser/TestUserScene.cpp b/plugin/samples/HelloPlugins/Classes/TestUser/TestUserScene.cpp index 1ee1bb9fd6..20aa643c1a 100644 --- a/plugin/samples/HelloPlugins/Classes/TestUser/TestUserScene.cpp +++ b/plugin/samples/HelloPlugins/Classes/TestUser/TestUserScene.cpp @@ -1,3 +1,26 @@ +/**************************************************************************** +Copyright (c) 2013 cocos2d-x.org + +http://www.cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ #include "TestUserScene.h" #include "MyUserManager.h" #include "HelloWorldScene.h" @@ -40,8 +63,8 @@ bool TestUser::init() MyUserManager::sharedManager()->loadPlugin(); Size visibleSize = Director::getInstance()->getVisibleSize(); Point origin = Director::getInstance()->getVisibleOrigin(); - Point posMid = ccp(origin.x + visibleSize.width / 2, origin.y + visibleSize.height / 2); - Point posBR = ccp(origin.x + visibleSize.width, origin.y); + Point posMid = Point(origin.x + visibleSize.width / 2, origin.y + visibleSize.height / 2); + Point posBR = Point(origin.x + visibleSize.width, origin.y); ///////////////////////////// // 2. add a menu item with "X" image, which is clicked to quit the program @@ -50,23 +73,23 @@ bool TestUser::init() // add a "close" icon to exit the progress. it's an autorelease object MenuItemFont *pBackItem = MenuItemFont::create("Back", CC_CALLBACK_1(TestUser::menuBackCallback, this)); Size backSize = pBackItem->getContentSize(); - pBackItem->setPosition(ccpAdd(posBR, ccp(- backSize.width / 2, backSize.height / 2))); + pBackItem->setPosition(posBR + Point(- backSize.width / 2, backSize.height / 2)); // create menu, it's an autorelease object Menu* pMenu = Menu::create(pBackItem, NULL); - pMenu->setPosition(PointZero); + pMenu->setPosition(Point::ZERO); LabelTTF* label1 = LabelTTF::create("Login", "Arial", 32); MenuItemLabel* pItemLogin = MenuItemLabel::create(label1, CC_CALLBACK_1(TestUser::testLogin, this)); - pItemLogin->setAnchorPoint(ccp(0.5f, 0)); + pItemLogin->setAnchorPoint(Point(0.5f, 0)); pMenu->addChild(pItemLogin, 0); - pItemLogin->setPosition(ccpAdd(posMid, ccp(-100, -120))); + pItemLogin->setPosition(posMid + Point(-100, -120)); LabelTTF* label2 = LabelTTF::create("Logout", "Arial", 32); MenuItemLabel* pItemLogout = MenuItemLabel::create(label2, CC_CALLBACK_1(TestUser::testLogout, this)); - pItemLogout->setAnchorPoint(ccp(0.5f, 0)); + pItemLogout->setAnchorPoint(Point(0.5f, 0)); pMenu->addChild(pItemLogout, 0); - pItemLogout->setPosition(ccpAdd(posMid, ccp(100, -120))); + pItemLogout->setPosition(posMid + Point(100, -120)); // create optional menu // cases item @@ -78,7 +101,7 @@ bool TestUser::init() { _caseItem->getSubItems()->addObject( MenuItemFont::create( s_aTestCases[i].c_str() ) ); } - _caseItem->setPosition(ccpAdd(posMid, ccp(0, 120))); + _caseItem->setPosition(posMid + Point(0, 120)); pMenu->addChild(_caseItem); _selectedCase = 0; diff --git a/plugin/samples/HelloPlugins/Classes/TestUser/TestUserScene.h b/plugin/samples/HelloPlugins/Classes/TestUser/TestUserScene.h index f146d7b0ec..483b4a7dbd 100644 --- a/plugin/samples/HelloPlugins/Classes/TestUser/TestUserScene.h +++ b/plugin/samples/HelloPlugins/Classes/TestUser/TestUserScene.h @@ -1,3 +1,26 @@ +/**************************************************************************** +Copyright (c) 2013 cocos2d-x.org + +http://www.cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ #ifndef __TEST_USER_SCENE_H__ #define __TEST_USER_SCENE_H__ diff --git a/plugin/samples/HelloPlugins/proj.android/jni/Android.mk b/plugin/samples/HelloPlugins/proj.android/jni/Android.mk index 0399ff741f..b281e62c3b 100644 --- a/plugin/samples/HelloPlugins/proj.android/jni/Android.mk +++ b/plugin/samples/HelloPlugins/proj.android/jni/Android.mk @@ -18,7 +18,9 @@ LOCAL_SRC_FILES := hellocpp/main.cpp \ ../../Classes/TestUser/TestUserScene.cpp \ ../../Classes/TestUser/MyUserManager.cpp \ ../../Classes/TestIAPOnline/TestIAPOnlineScene.cpp \ - ../../Classes/TestIAPOnline/MyIAPOLManager.cpp + ../../Classes/TestIAPOnline/MyIAPOLManager.cpp \ + ../../Classes/TestSocial/TestSocialScene.cpp \ + ../../Classes/TestSocial/MySocialManager.cpp LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes \ $(LOCAL_PATH)/../../Classes/TestAds \ @@ -26,7 +28,8 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes \ $(LOCAL_PATH)/../../Classes/TestIAP \ $(LOCAL_PATH)/../../Classes/TestShare \ $(LOCAL_PATH)/../../Classes/TestUser \ - $(LOCAL_PATH)/../../Classes/TestIAPOnline + $(LOCAL_PATH)/../../Classes/TestIAPOnline \ + $(LOCAL_PATH)/../../Classes/TestSocial LOCAL_WHOLE_STATIC_LIBRARIES += cocos2dx_static \ PluginProtocolStatic diff --git a/plugin/samples/HelloPlugins/proj.ios/HelloPlugins.xcodeproj/project.pbxproj b/plugin/samples/HelloPlugins/proj.ios/HelloPlugins.xcodeproj/project.pbxproj index 5ecb1a8265..f73b95c229 100644 --- a/plugin/samples/HelloPlugins/proj.ios/HelloPlugins.xcodeproj/project.pbxproj +++ b/plugin/samples/HelloPlugins/proj.ios/HelloPlugins.xcodeproj/project.pbxproj @@ -57,6 +57,8 @@ FAD55528177D2C2000968F54 /* BtnND91.png in Resources */ = {isa = PBXBuildFile; fileRef = FAD55524177D2C2000968F54 /* BtnND91.png */; }; FAD55529177D2C2000968F54 /* twitter.jpeg in Resources */ = {isa = PBXBuildFile; fileRef = FAD55525177D2C2000968F54 /* twitter.jpeg */; }; FAD5552A177D2C2000968F54 /* weibo.png in Resources */ = {isa = PBXBuildFile; fileRef = FAD55526177D2C2000968F54 /* weibo.png */; }; + FADBF8A2179E559900F59B1D /* MySocialManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FADBF89E179E559900F59B1D /* MySocialManager.cpp */; }; + FADBF8A3179E559900F59B1D /* TestSocialScene.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FADBF8A0179E559900F59B1D /* TestSocialScene.cpp */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -236,6 +238,10 @@ FAD55524177D2C2000968F54 /* BtnND91.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = BtnND91.png; sourceTree = ""; }; FAD55525177D2C2000968F54 /* twitter.jpeg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = twitter.jpeg; sourceTree = ""; }; FAD55526177D2C2000968F54 /* weibo.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = weibo.png; sourceTree = ""; }; + FADBF89E179E559900F59B1D /* MySocialManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MySocialManager.cpp; sourceTree = ""; }; + FADBF89F179E559900F59B1D /* MySocialManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MySocialManager.h; sourceTree = ""; }; + FADBF8A0179E559900F59B1D /* TestSocialScene.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TestSocialScene.cpp; sourceTree = ""; }; + FADBF8A1179E559900F59B1D /* TestSocialScene.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestSocialScene.h; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -289,6 +295,7 @@ 15AA9C4015B7EC450033D6C2 /* Classes */ = { isa = PBXGroup; children = ( + FADBF89D179E559900F59B1D /* TestSocial */, FA3D264717867219009B234A /* TestIAPOnline */, FAD5550E177D1EE900968F54 /* TestIAP */, FAD55513177D1EE900968F54 /* TestUser */, @@ -464,6 +471,18 @@ path = ../Classes/TestUser; sourceTree = ""; }; + FADBF89D179E559900F59B1D /* TestSocial */ = { + isa = PBXGroup; + children = ( + FADBF89E179E559900F59B1D /* MySocialManager.cpp */, + FADBF89F179E559900F59B1D /* MySocialManager.h */, + FADBF8A0179E559900F59B1D /* TestSocialScene.cpp */, + FADBF8A1179E559900F59B1D /* TestSocialScene.h */, + ); + name = TestSocial; + path = ../Classes/TestSocial; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -662,6 +681,8 @@ FAD5551B177D1EE900968F54 /* TestUserScene.cpp in Sources */, FA3D264D17867219009B234A /* MyIAPOLManager.cpp in Sources */, FA3D264E17867219009B234A /* TestIAPOnlineScene.cpp in Sources */, + FADBF8A2179E559900F59B1D /* MySocialManager.cpp in Sources */, + FADBF8A3179E559900F59B1D /* TestSocialScene.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; };