Skip to content
This repository
Browse code

Added StoreInfo

Gathering information about game assets on runtime.
Fixed UI issues on iPhone
  • Loading branch information...
commit 438cefe1e7a722eb52b54984d7ce779b82fe357d 1 parent 95bade5
Refael Dakar refaelos authored

Showing 24 changed files with 723 additions and 554 deletions. Show diff stats Hide diff stats

  1. +2 1  .gitignore
  2. +7 9 cocos2dx-store.xcodeproj/project.pbxproj
  3. +0 22 cocos2dx-store/Classes/AnalyticXStringUtil.h
  4. +0 54 cocos2dx-store/Classes/AnalyticXStringUtil.mm
  5. +9 7 cocos2dx-store/Classes/AppDelegate.cpp
  6. +257 0 cocos2dx-store/Classes/JniHelpers.cpp
  7. +34 0 cocos2dx-store/Classes/JniHelpers.h
  8. +17 8 cocos2dx-store/Classes/StoreAScene.cpp
  9. +1 1  cocos2dx-store/Classes/StoreAScene.h
  10. +50 13 cocos2dx-store/Classes/StoreBScene.cpp
  11. +3 2 cocos2dx-store/Classes/StoreBScene.h
  12. +41 196 cocos2dx-store/Classes/cocos2dx_StoreController.cpp
  13. +1 1  cocos2dx-store/Classes/cocos2dx_StoreController.h
  14. +70 0 cocos2dx-store/Classes/cocos2dx_StoreInfo.cpp
  15. +32 0 cocos2dx-store/Classes/cocos2dx_StoreInfo.h
  16. +35 208 cocos2dx-store/Classes/cocos2dx_StoreInventory.cpp
  17. +4 5 cocos2dx-store/ios/cocos2dx_StoreController.mm
  18. +93 0 cocos2dx-store/ios/cocos2dx_StoreInfo.mm
  19. +6 7 cocos2dx-store/ios/cocos2dx_StoreInventory.mm
  20. +1 2  cocos2dx-store/ios/iOSHelper.mm
  21. +0 18 cocos2dx-store/proj.android/.idea/misc.xml
  22. +2 0  cocos2dx-store/proj.android/.idea/vcs.xml
  23. +2 0  cocos2dx-store/proj.android/jni/Android.mk
  24. +56 0 cocos2dx-store/proj.android/src/com/soomla/store/StoreInfoBridge.java
3  .gitignore
@@ -62,7 +62,8 @@ cocos2dx-store/proj.android/.settings
62 62 cocos2dx-store/proj.android/gen
63 63 cocos2dx-store/proj.android/bin
64 64 cocos2dx-store/proj.android/out
65   -
  65 +cocos2dx-store/proj.android/assets/iphone
  66 +cocos2dx-store/proj.android/assets/iphonehd
66 67 .idea/workspace.xml
67 68
68 69 cocos2dx-store/proj.android/.idea/workspace.xml
16 cocos2dx-store.xcodeproj/project.pbxproj
@@ -55,7 +55,7 @@
55 55 C069308F163C86D60037E975 /* libcocos2dx.a in Frameworks */ = {isa = PBXBuildFile; fileRef = C0B04372163C84860015400E /* libcocos2dx.a */; };
56 56 C0693091163C876C0037E975 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = C0693090163C876C0037E975 /* libz.dylib */; };
57 57 C0693093163C87760037E975 /* libxml2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = C0693092163C87760037E975 /* libxml2.dylib */; };
58   - C0B042D5163BFD150015400E /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = C0B042D4163BFD150015400E /* Info.plist */; };
  58 + C06930A1163D86E30037E975 /* cocos2dx_StoreInfo.mm in Sources */ = {isa = PBXBuildFile; fileRef = C06930A0163D86E30037E975 /* cocos2dx_StoreInfo.mm */; };
59 59 C0B042DC163BFD2B0015400E /* Icon-72.png in Resources */ = {isa = PBXBuildFile; fileRef = C0B042D6163BFD2B0015400E /* Icon-72.png */; };
60 60 C0B042DD163BFD2B0015400E /* Icon-Small-50.png in Resources */ = {isa = PBXBuildFile; fileRef = C0B042D7163BFD2B0015400E /* Icon-Small-50.png */; };
61 61 C0B042DE163BFD2B0015400E /* Icon-Small.png in Resources */ = {isa = PBXBuildFile; fileRef = C0B042D8163BFD2B0015400E /* Icon-Small.png */; };
@@ -66,7 +66,6 @@
66 66 C0B042F2163BFE960015400E /* MainScene.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C0B042E9163BFE960015400E /* MainScene.cpp */; };
67 67 C0B042F3163BFE960015400E /* StoreAScene.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C0B042EC163BFE960015400E /* StoreAScene.cpp */; };
68 68 C0B042F4163BFE960015400E /* StoreBScene.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C0B042EE163BFE960015400E /* StoreBScene.cpp */; };
69   - C0B04305163C067F0015400E /* AnalyticXStringUtil.mm in Sources */ = {isa = PBXBuildFile; fileRef = C0B04304163C067F0015400E /* AnalyticXStringUtil.mm */; };
70 69 C0B04308163C59700015400E /* iOSHelper.mm in Sources */ = {isa = PBXBuildFile; fileRef = C0B04306163C59700015400E /* iOSHelper.mm */; };
71 70 C0B04310163C5DDE0015400E /* MuffinRushAssets.m in Sources */ = {isa = PBXBuildFile; fileRef = C0B0430F163C5DDE0015400E /* MuffinRushAssets.m */; };
72 71 C0B0431B163C7B250015400E /* cocos2dx_StoreInventory.mm in Sources */ = {isa = PBXBuildFile; fileRef = C0B0431A163C7B250015400E /* cocos2dx_StoreInventory.mm */; };
@@ -170,6 +169,8 @@
170 169 C031BE341637FE84005F73E3 /* cocos2dx_StoreInventory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = cocos2dx_StoreInventory.h; path = Classes/cocos2dx_StoreInventory.h; sourceTree = "<group>"; };
171 170 C0693090163C876C0037E975 /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = usr/lib/libz.dylib; sourceTree = SDKROOT; };
172 171 C0693092163C87760037E975 /* libxml2.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libxml2.dylib; path = usr/lib/libxml2.dylib; sourceTree = SDKROOT; };
  172 + C0693095163D27730037E975 /* cocos2dx_StoreInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = cocos2dx_StoreInfo.h; path = Classes/cocos2dx_StoreInfo.h; sourceTree = "<group>"; };
  173 + C06930A0163D86E30037E975 /* cocos2dx_StoreInfo.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = cocos2dx_StoreInfo.mm; path = ios/cocos2dx_StoreInfo.mm; sourceTree = "<group>"; };
173 174 C0B042D3163BFCB50015400E /* Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Prefix.pch; sourceTree = "<group>"; };
174 175 C0B042D4163BFD150015400E /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = ios/Resources/Info.plist; sourceTree = "<group>"; };
175 176 C0B042D6163BFD2B0015400E /* Icon-72.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Icon-72.png"; path = "ios/Resources/Icon-72.png"; sourceTree = "<group>"; };
@@ -189,8 +190,6 @@
189 190 C0B042EE163BFE960015400E /* StoreBScene.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = StoreBScene.cpp; path = Classes/StoreBScene.cpp; sourceTree = "<group>"; };
190 191 C0B042EF163BFE960015400E /* StoreBScene.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = StoreBScene.h; path = Classes/StoreBScene.h; sourceTree = "<group>"; };
191 192 C0B042F5163C023A0015400E /* Includes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Includes.h; path = Classes/Includes.h; sourceTree = "<group>"; };
192   - C0B04303163C067F0015400E /* AnalyticXStringUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AnalyticXStringUtil.h; path = Classes/AnalyticXStringUtil.h; sourceTree = "<group>"; };
193   - C0B04304163C067F0015400E /* AnalyticXStringUtil.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = AnalyticXStringUtil.mm; path = Classes/AnalyticXStringUtil.mm; sourceTree = "<group>"; };
194 193 C0B04306163C59700015400E /* iOSHelper.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = iOSHelper.mm; path = ios/iOSHelper.mm; sourceTree = "<group>"; };
195 194 C0B04307163C59700015400E /* iOSHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = iOSHelper.h; path = ios/iOSHelper.h; sourceTree = "<group>"; };
196 195 C0B0430E163C5DDE0015400E /* MuffinRushAssets.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MuffinRushAssets.h; path = ios/MuffinRushAssets.h; sourceTree = "<group>"; };
@@ -303,12 +302,11 @@
303 302 C031BAA41635BDBA005F73E3 /* RootViewController.h */,
304 303 C031BAA51635BDBA005F73E3 /* RootViewController.mm */,
305 304 C031BAA71635BDBA005F73E3 /* main.m */,
306   - C0B04303163C067F0015400E /* AnalyticXStringUtil.h */,
307   - C0B04304163C067F0015400E /* AnalyticXStringUtil.mm */,
308 305 C0B04306163C59700015400E /* iOSHelper.mm */,
309 306 C0B04307163C59700015400E /* iOSHelper.h */,
310 307 C031BD471635C4C7005F73E3 /* cocos2dx_StoreController.mm */,
311 308 C0B0431A163C7B250015400E /* cocos2dx_StoreInventory.mm */,
  309 + C06930A0163D86E30037E975 /* cocos2dx_StoreInfo.mm */,
312 310 );
313 311 name = ios;
314 312 sourceTree = "<group>";
@@ -335,9 +333,10 @@
335 333 C0B042EF163BFE960015400E /* StoreBScene.h */,
336 334 C031BD251635BDBD005F73E3 /* AppDelegate.h */,
337 335 C031BD261635BDBD005F73E3 /* AppDelegate.cpp */,
  336 + C0B042F5163C023A0015400E /* Includes.h */,
338 337 C031BD4A1635C551005F73E3 /* cocos2dx_StoreController.h */,
339 338 C031BE341637FE84005F73E3 /* cocos2dx_StoreInventory.h */,
340   - C0B042F5163C023A0015400E /* Includes.h */,
  339 + C0693095163D27730037E975 /* cocos2dx_StoreInfo.h */,
341 340 C0B042E8163BFE960015400E /* cocos2dx_InsufficientFundsException.h */,
342 341 C0B042EB163BFE960015400E /* cocos2dx_NotEnoughGoodsException.h */,
343 342 C031BE3116370E9B005F73E3 /* cocos2dx_VirtualItemNotFoundException.h */,
@@ -544,7 +543,6 @@
544 543 isa = PBXResourcesBuildPhase;
545 544 buildActionMask = 2147483647;
546 545 files = (
547   - C0B042D5163BFD150015400E /* Info.plist in Resources */,
548 546 C0B042DC163BFD2B0015400E /* Icon-72.png in Resources */,
549 547 C0B042DD163BFD2B0015400E /* Icon-Small-50.png in Resources */,
550 548 C0B042DE163BFD2B0015400E /* Icon-Small.png in Resources */,
@@ -601,11 +599,11 @@
601 599 C0B042F2163BFE960015400E /* MainScene.cpp in Sources */,
602 600 C0B042F3163BFE960015400E /* StoreAScene.cpp in Sources */,
603 601 C0B042F4163BFE960015400E /* StoreBScene.cpp in Sources */,
604   - C0B04305163C067F0015400E /* AnalyticXStringUtil.mm in Sources */,
605 602 C0B04308163C59700015400E /* iOSHelper.mm in Sources */,
606 603 C0B04310163C5DDE0015400E /* MuffinRushAssets.m in Sources */,
607 604 C0B0431B163C7B250015400E /* cocos2dx_StoreInventory.mm in Sources */,
608 605 C0B0431E163C7C980015400E /* StoreInventory.m in Sources */,
  606 + C06930A1163D86E30037E975 /* cocos2dx_StoreInfo.mm in Sources */,
609 607 );
610 608 runOnlyForDeploymentPostprocessing = 0;
611 609 };
22 cocos2dx-store/Classes/AnalyticXStringUtil.h
... ... @@ -1,22 +0,0 @@
1   -//
2   -// AnalyticXStringUtil.h
3   -// AnalyticX
4   -//
5   -// Created by diwwu on 5/10/12.
6   -// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
7   -//
8   -
9   -#ifndef AnalyticX_AnalyticXStringUtil_h
10   -#define AnalyticX_AnalyticXStringUtil_h
11   -
12   -#include "cocos2d.h"
13   -
14   -@interface AnalyticXStringUtil:NSObject
15   -
16   -+ (NSString *)nsstringFromCString:(const char *)cstring;
17   -+ (const char *)cstringFromNSString:(NSString *)nsstring;
18   -+ (NSDictionary *)nsDictionaryFromCCDictionary:(cocos2d::CCDictionary *)ccDictionary;
19   -
20   -@end
21   -
22   -#endif
54 cocos2dx-store/Classes/AnalyticXStringUtil.mm
... ... @@ -1,54 +0,0 @@
1   -//
2   -// AnalyticXStringUtil.cpp
3   -// AnalyticX
4   -//
5   -// Created by diwwu on 5/10/12.
6   -// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
7   -//
8   -
9   -#import "AnalyticXStringUtil.h"
10   -
11   -@implementation AnalyticXStringUtil
12   -
13   -+ (NSString *)nsstringFromCString:(const char *)cstring {
14   - if (cstring == NULL) {
15   - return NULL;
16   - }
17   -
18   - NSString * nsstring = [[NSString alloc] initWithBytes:cstring length:strlen(cstring) encoding:NSUTF8StringEncoding];
19   - return [nsstring autorelease];
20   -}
21   -+ (const char *)cstringFromNSString:(NSString *)nsstring {
22   -
23   - if (nsstring == NULL) {
24   - return NULL;
25   - }
26   -
27   - return [nsstring UTF8String];
28   -}
29   -+ (NSDictionary *)nsDictionaryFromCCDictionary:(cocos2d::CCDictionary *)ccDictionary {
30   - if (ccDictionary == NULL) {
31   - return NULL;
32   - } else if (ccDictionary->allKeys() == NULL) {
33   - return NULL;
34   - } else if (ccDictionary->allKeys()->count() <= 0) {
35   - return NULL;
36   - }
37   -
38   - cocos2d::CCLog("1");
39   -
40   - NSMutableDictionary *nsDict = [NSMutableDictionary dictionaryWithCapacity:ccDictionary->allKeys()->count()];
41   -
42   - cocos2d::CCLog("2");
43   -
44   - for (int i = 0; i < ccDictionary->allKeys()->count(); i++) {
45   - cocos2d::CCLog("3");
46   -
47   - [nsDict setValue:[AnalyticXStringUtil nsstringFromCString:((cocos2d::CCString *)ccDictionary->objectForKey(((cocos2d::CCString *)ccDictionary->allKeys()->objectAtIndex(i))->getCString()))->getCString()] forKey:[AnalyticXStringUtil nsstringFromCString:((cocos2d::CCString *)ccDictionary->allKeys()->objectAtIndex(i))->getCString()]];
48   - }
49   -
50   - return nsDict;
51   -}
52   -
53   -
54   -@end
16 cocos2dx-store/Classes/AppDelegate.cpp
@@ -36,15 +36,17 @@ bool AppDelegate::applicationDidFinishLaunching() {
36 36 {
37 37 // iphone
38 38
39   - if (pDirector->enableRetinaDisplay(true))
40   - {
  39 +// if (pDirector->enableRetinaDisplay(true))
  40 +// {
41 41 // iphone hd
42 42 CCFileUtils::sharedFileUtils()->setResourceDirectory("iphonehd");
43   - }
44   - else
45   - {
46   - CCFileUtils::sharedFileUtils()->setResourceDirectory("iphone");
47   - }
  43 +// }
  44 +// else
  45 +// {
  46 +// CCFileUtils::sharedFileUtils()->setResourceDirectory("iphone");
  47 +// }
  48 +
  49 + CCEGLView::sharedOpenGLView()->setDesignResolutionSize(720, 1280, kResolutionNoBorder);
48 50 }
49 51 else
50 52 {
257 cocos2dx-store/Classes/JniHelpers.cpp
... ... @@ -0,0 +1,257 @@
  1 +//
  2 +// JniHelpers.cpp
  3 +// cocos2dx-store
  4 +//
  5 +// Created by Refael Dakar on 10/28/12.
  6 +//
  7 +//
  8 +
  9 +#include "JniHelpers.h"
  10 +#include <jni.h>
  11 +#include "platform/android/jni/JniHelper.h"
  12 +#include <android/log.h>
  13 +
  14 +void JniHelpers::jniCommonVoidCall(const char* methodName, const char* classPath) {
  15 + cocos2d::JniMethodInfo minfo;
  16 +
  17 + bool isHave = cocos2d::JniHelper::getStaticMethodInfo(minfo,classPath,methodName, "()V");
  18 +
  19 + if (!isHave) {
  20 + //do nothing
  21 + } else {
  22 + minfo.env->CallStaticVoidMethod(minfo.classID, minfo.methodID);
  23 + }
  24 +}
  25 +
  26 +void JniHelpers::jniCommonVoidCall(const char* methodName, const char* classPath, bool arg0) {
  27 + cocos2d::JniMethodInfo minfo;
  28 +
  29 + bool isHave = cocos2d::JniHelper::getStaticMethodInfo(minfo,classPath,methodName, "(Z)V");
  30 +
  31 + if (!isHave) {
  32 + //do nothing
  33 + } else {
  34 + minfo.env->CallStaticVoidMethod(minfo.classID, minfo.methodID, arg0);
  35 + }
  36 +}
  37 +
  38 +void JniHelpers::jniCommonVoidCall(const char* methodName, const char* classPath, const char* arg0)
  39 + throw (cocos2dx_VirtualItemNotFoundException&, cocos2dx_NotEnoughGoodsException&, cocos2dx_InsufficientFundsException&) {
  40 + cocos2d::JniMethodInfo minfo;
  41 +
  42 + bool isHave = cocos2d::JniHelper::getStaticMethodInfo(minfo, classPath, methodName, "(Ljava/lang/String;)V");
  43 +
  44 + if (!isHave) {
  45 + //do nothing
  46 + } else {
  47 + jstring stringArg0 = minfo.env->NewStringUTF(arg0);
  48 +
  49 + minfo.env->CallStaticVoidMethod(minfo.classID, minfo.methodID, stringArg0);
  50 +
  51 + minfo.env->DeleteLocalRef(stringArg0);
  52 +
  53 + if(minfo.env->ExceptionCheck() == JNI_TRUE ) {
  54 + __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "HAS EXCEPTION");
  55 + jthrowable exceptionObj = minfo.env->ExceptionOccurred();
  56 + minfo.env->ExceptionClear();
  57 +
  58 + jclass vinfEx = cocos2d::JniHelper::getClassID("com/soomla/store/exceptions/VirtualItemNotFoundException", minfo.env);
  59 + if (minfo.env->IsInstanceOf(exceptionObj, vinfEx)) {
  60 + __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Cought VirtualItemNotFoundException!");
  61 +
  62 + throw cocos2dx_VirtualItemNotFoundException();
  63 + }
  64 +
  65 + vinfEx = cocos2d::JniHelper::getClassID("com/soomla/store/exceptions/NotEnoughGoodsException", minfo.env);
  66 + if (minfo.env->IsInstanceOf(exceptionObj, vinfEx)) {
  67 + __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Cought NotEnoughGoodsException!");
  68 +
  69 + throw cocos2dx_NotEnoughGoodsException();
  70 + }
  71 +
  72 + vinfEx = cocos2d::JniHelper::getClassID("com/soomla/store/exceptions/InsufficientFundsException", minfo.env);
  73 + if (minfo.env->IsInstanceOf(exceptionObj, vinfEx)) {
  74 + __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Cought InsufficientFundsException!");
  75 +
  76 + throw cocos2dx_InsufficientFundsException();
  77 + }
  78 + }
  79 + }
  80 +}
  81 +
  82 +int JniHelpers::jniCommonIntCall(const char* methodName, const char* classPath, const char* arg0)
  83 + throw (cocos2dx_VirtualItemNotFoundException&) {
  84 + cocos2d::JniMethodInfo minfo;
  85 +
  86 + bool isHave = cocos2d::JniHelper::getStaticMethodInfo(minfo,classPath,methodName, "(Ljava/lang/String;)I");
  87 +
  88 + if (!isHave) {
  89 + //do nothing
  90 + } else {
  91 + jstring stringArg0 = minfo.env->NewStringUTF(arg0);
  92 +
  93 + jint ret = minfo.env->CallStaticIntMethod(minfo.classID, minfo.methodID, stringArg0);
  94 +
  95 + minfo.env->DeleteLocalRef(stringArg0);
  96 +
  97 + if(minfo.env->ExceptionCheck() == JNI_TRUE ) {
  98 + __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "HAS EXCEPTION");
  99 + jthrowable exceptionObj = minfo.env->ExceptionOccurred();
  100 + minfo.env->ExceptionClear();
  101 +
  102 + jclass vinfEx = cocos2d::JniHelper::getClassID("com/soomla/store/exceptions/VirtualItemNotFoundException", minfo.env);
  103 + if (minfo.env->IsInstanceOf(exceptionObj, vinfEx)) {
  104 + __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Cought VirtualItemNotFoundException!");
  105 +
  106 + throw cocos2dx_VirtualItemNotFoundException();
  107 + }
  108 + }
  109 +
  110 + return (int)ret;
  111 + }
  112 +
  113 + return 0;
  114 +}
  115 +
  116 +int JniHelpers::jniCommonIntCall(const char* methodName, const char* classPath, const char* arg0, int arg1)
  117 + throw (cocos2dx_VirtualItemNotFoundException&) {
  118 + cocos2d::JniMethodInfo minfo;
  119 +
  120 + bool isHave = cocos2d::JniHelper::getStaticMethodInfo(minfo,classPath,methodName, "(Ljava/lang/String;I)I");
  121 +
  122 + if (!isHave) {
  123 + //do nothing
  124 + } else {
  125 + jstring stringArg0 = minfo.env->NewStringUTF(arg0);
  126 +
  127 + jint ret = minfo.env->CallStaticIntMethod(minfo.classID, minfo.methodID, stringArg0, arg1);
  128 +
  129 + minfo.env->DeleteLocalRef(stringArg0);
  130 +
  131 + if(minfo.env->ExceptionCheck() == JNI_TRUE ) {
  132 + __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "HAS EXCEPTION");
  133 + jthrowable exceptionObj = minfo.env->ExceptionOccurred();
  134 + minfo.env->ExceptionClear();
  135 +
  136 + jclass vinfEx = cocos2d::JniHelper::getClassID("com/soomla/store/exceptions/VirtualItemNotFoundException", minfo.env);
  137 + if (minfo.env->IsInstanceOf(exceptionObj, vinfEx)) {
  138 + __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Cought VirtualItemNotFoundException!");
  139 +
  140 + throw cocos2dx_VirtualItemNotFoundException();
  141 + }
  142 + }
  143 +
  144 + return (int)ret;
  145 + }
  146 +
  147 + return 0;
  148 +}
  149 +
  150 +int JniHelpers::jniCommonIntCall(const char* methodName, const char* classPath, const char* arg0, const char* arg1)
  151 + throw (cocos2dx_VirtualItemNotFoundException&) {
  152 + cocos2d::JniMethodInfo minfo;
  153 +
  154 + bool isHave = cocos2d::JniHelper::getStaticMethodInfo(minfo,classPath,methodName, "(Ljava/lang/String;Ljava/lang/String;)I");
  155 +
  156 + if (!isHave) {
  157 + //do nothing
  158 + } else {
  159 + jstring stringArg0 = minfo.env->NewStringUTF(arg0);
  160 + jstring stringArg1 = minfo.env->NewStringUTF(arg1);
  161 +
  162 + jint ret = minfo.env->CallStaticIntMethod(minfo.classID, minfo.methodID, stringArg0, stringArg1);
  163 +
  164 + minfo.env->DeleteLocalRef(stringArg0);
  165 + minfo.env->DeleteLocalRef(stringArg1);
  166 +
  167 + if(minfo.env->ExceptionCheck() == JNI_TRUE ) {
  168 + __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "HAS EXCEPTION");
  169 + jthrowable exceptionObj = minfo.env->ExceptionOccurred();
  170 + minfo.env->ExceptionClear();
  171 +
  172 + jclass vinfEx = cocos2d::JniHelper::getClassID("com/soomla/store/exceptions/VirtualItemNotFoundException", minfo.env);
  173 + if (minfo.env->IsInstanceOf(exceptionObj, vinfEx)) {
  174 + __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Cought VirtualItemNotFoundException!");
  175 +
  176 + throw cocos2dx_VirtualItemNotFoundException();
  177 + }
  178 + }
  179 +
  180 + return (int)ret;
  181 + }
  182 +
  183 + return 0;
  184 +}
  185 +
  186 +string JniHelpers::jniCommonStringCall(const char* methodName, const char* classPath, const char* arg0)
  187 + throw (cocos2dx_VirtualItemNotFoundException&) {
  188 + cocos2d::JniMethodInfo minfo;
  189 +
  190 + bool isHave = cocos2d::JniHelper::getStaticMethodInfo(minfo,classPath,methodName, "(Ljava/lang/String;)Ljava/lang/String;");
  191 +
  192 + if (!isHave) {
  193 + //do nothing
  194 + } else {
  195 + jstring stringArg0 = minfo.env->NewStringUTF(arg0);
  196 +
  197 + jstring retString = (jstring) minfo.env->CallStaticObjectMethod(minfo.classID, minfo.methodID, stringArg0);
  198 +
  199 + minfo.env->DeleteLocalRef(stringArg0);
  200 +
  201 + const char *nativeString = minfo.env->GetStringUTFChars(retString, 0);
  202 + string ret(nativeString);
  203 + minfo.env->ReleaseStringUTFChars(retString, nativeString);
  204 +
  205 + if(minfo.env->ExceptionCheck() == JNI_TRUE ) {
  206 + __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "HAS EXCEPTION");
  207 + jthrowable exceptionObj = minfo.env->ExceptionOccurred();
  208 + minfo.env->ExceptionClear();
  209 +
  210 + jclass vinfEx = cocos2d::JniHelper::getClassID("com/soomla/store/exceptions/VirtualItemNotFoundException", minfo.env);
  211 + if (minfo.env->IsInstanceOf(exceptionObj, vinfEx)) {
  212 + __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Cought VirtualItemNotFoundException!");
  213 +
  214 + throw cocos2dx_VirtualItemNotFoundException();
  215 + }
  216 + }
  217 +
  218 + return ret;
  219 + }
  220 +
  221 + return NULL;
  222 +}
  223 +
  224 +double JniHelpers::jniCommonDoubleCall(const char* methodName, const char* classPath, const char* arg0)
  225 + throw (cocos2dx_VirtualItemNotFoundException&) {
  226 + cocos2d::JniMethodInfo minfo;
  227 +
  228 + bool isHave = cocos2d::JniHelper::getStaticMethodInfo(minfo,classPath,methodName, "(Ljava/lang/String;)D");
  229 +
  230 + if (!isHave) {
  231 + //do nothing
  232 + } else {
  233 + jstring stringArg0 = minfo.env->NewStringUTF(arg0);
  234 +
  235 + jdouble ret = minfo.env->CallStaticDoubleMethod(minfo.classID, minfo.methodID, stringArg0);
  236 +
  237 + minfo.env->DeleteLocalRef(stringArg0);
  238 +
  239 + if(minfo.env->ExceptionCheck() == JNI_TRUE ) {
  240 + __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "HAS EXCEPTION");
  241 + jthrowable exceptionObj = minfo.env->ExceptionOccurred();
  242 + minfo.env->ExceptionClear();
  243 +
  244 + jclass vinfEx = cocos2d::JniHelper::getClassID("com/soomla/store/exceptions/VirtualItemNotFoundException", minfo.env);
  245 + if (minfo.env->IsInstanceOf(exceptionObj, vinfEx)) {
  246 + __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Cought VirtualItemNotFoundException!");
  247 +
  248 + throw cocos2dx_VirtualItemNotFoundException();
  249 + }
  250 + }
  251 +
  252 + return (double)ret;
  253 + }
  254 +
  255 + return 0;
  256 +}
  257 +
34 cocos2dx-store/Classes/JniHelpers.h
... ... @@ -0,0 +1,34 @@
  1 +//
  2 +// JniHelpers.h
  3 +// cocos2dx-store
  4 +//
  5 +// Created by Refael Dakar on 10/28/12.
  6 +//
  7 +//
  8 +
  9 +#ifndef __cocos2dx_store__JniHelpers__
  10 +#define __cocos2dx_store__JniHelpers__
  11 +
  12 +#include "cocos2dx_VirtualItemNotFoundException.h"
  13 +#include "cocos2dx_InsufficientFundsException.h"
  14 +#include "cocos2dx_NotEnoughGoodsException.h"
  15 +
  16 +class JniHelpers {
  17 +public:
  18 + static void jniCommonVoidCall(const char* methodName, const char* classPath);
  19 + static void jniCommonVoidCall(const char* methodName, const char* classPath, bool arg0);
  20 + static void jniCommonVoidCall(const char* methodName, const char* classPath, const char* arg0)
  21 + throw(cocos2dx_VirtualItemNotFoundException&, cocos2dx_NotEnoughGoodsException&, cocos2dx_InsufficientFundsException&);
  22 + static int jniCommonIntCall(const char* methodName, const char* classPath, const char* arg0, int arg1)
  23 + throw (cocos2dx_VirtualItemNotFoundException&);
  24 + static int jniCommonIntCall(const char* methodName, const char* classPath, const char* arg0)
  25 + throw (cocos2dx_VirtualItemNotFoundException&);
  26 + static int jniCommonIntCall(const char* methodName, const char* classPath, const char* arg0, const char* arg1)
  27 + throw (cocos2dx_VirtualItemNotFoundException&);
  28 + static string jniCommonStringCall(const char* methodName, const char* classPath, const char* arg0)
  29 + throw (cocos2dx_VirtualItemNotFoundException&);
  30 + static double jniCommonDoubleCall(const char* methodName, const char* classPath, const char* arg0)
  31 + throw (cocos2dx_VirtualItemNotFoundException&);
  32 +};
  33 +
  34 +#endif /* defined(__cocos2dx_store__JniHelpers__) */
25 cocos2dx-store/Classes/StoreAScene.cpp
@@ -4,6 +4,7 @@
4 4 #include "StoreBScene.h"
5 5 #include "cocos2dx_StoreController.h"
6 6 #include "cocos2dx_StoreInventory.h"
  7 +#include "cocos2dx_StoreInfo.h"
7 8 #include "Includes.h"
8 9
9 10 #include <string>
@@ -86,10 +87,10 @@ bool StoreAScene::init()
86 87 // In Game Menu
87 88 CCMenu* menu = CCMenu::create(getMoreItem, backItem, NULL);
88 89
89   - createListViewItem(origin, menu, visibleSize, 0, "fruit_cake.png", "Fruit Cake", "Customers buy a double portion on each purchase of this cake", 225, 0);
90   - createListViewItem(origin, menu, visibleSize, 1, "pavlova.png", "Pavlova", "Gives customers a sugar rush and they call their friends", 175, 0);
91   - createListViewItem(origin, menu, visibleSize, 2, "cream_cup.png", "Cream Cup", "Increase bakery reputation with this original pastry", 50, 0);
92   - createListViewItem(origin, menu, visibleSize, 3, "chocolate_cake.png", "Chocolate Cake", "A classic cake to maximize customer satisfaction", 250, 0);
  90 + createListViewItem(origin, menu, visibleSize, 0, "fruit_cake.png");
  91 + createListViewItem(origin, menu, visibleSize, 1, "pavlova.png");
  92 + createListViewItem(origin, menu, visibleSize, 2, "cream_cup.png");
  93 + createListViewItem(origin, menu, visibleSize, 3, "chocolate_cake.png");
93 94
94 95 menu->setPosition(CCPointZero);
95 96 this->addChild(menu);
@@ -149,12 +150,23 @@ void StoreAScene::menuChooseCallback(CCObject* pSender)
149 150 }
150 151 }
151 152
152   -void StoreAScene::createListViewItem(CCPoint& origin, CCMenu* menu, CCSize& visibleSize, int tag, const char* img, const char* name, const char* info, int price, int balance) {
  153 +void StoreAScene::createListViewItem(CCPoint& origin, CCMenu* menu, CCSize& visibleSize, int tag, const char* img) {
153 154 GameMenuItem *pChooseItem = GameMenuItem::itemWithLabel(
154 155 CCSprite::create("button.png"),
155 156 this,
156 157 menu_selector(StoreAScene::menuChooseCallback));
157 158
  159 + char itemId[512];
  160 + snprintf(itemId, sizeof(itemId), itemIdFromTag(tag));
  161 +
  162 + // TODO: exception handling ..
  163 + string nameS = cocos2dx_StoreInfo::getGoodName(itemId);
  164 + string infoS = cocos2dx_StoreInfo::getGoodDescription(itemId);
  165 + int price = cocos2dx_StoreInfo::getGoodPriceForCurrency(itemId, "currency_muffin");
  166 + int balance = 0;
  167 + const char * name = nameS.c_str();
  168 + const char * info = infoS.c_str();
  169 +
158 170 float yOffset = - 200;
159 171
160 172 pChooseItem->setPosition(ccp(origin.x + visibleSize.width/2, yOffset + origin.y + visibleSize.height - 100 - (tag * pChooseItem->boundingBox().size.height)));
@@ -194,9 +206,6 @@ void StoreAScene::createListViewItem(CCPoint& origin, CCMenu* menu, CCSize& visi
194 206
195 207 menu->addChild(pChooseItem, 1);
196 208
197   - char itemId[512];
198   - snprintf(itemId, sizeof(itemId), itemIdFromTag(tag));
199   -
200 209 setPriceBalanceLabel(itemId);
201 210 }
202 211
2  cocos2dx-store/Classes/StoreAScene.h
@@ -8,7 +8,7 @@ USING_NS_CC;
8 8 class StoreAScene : public cocos2d::CCLayerColor
9 9 {
10 10 private:
11   - void createListViewItem(CCPoint& origin, CCMenu* menu, CCSize& visibleSize, int tag, const char* img, const char* name, const char* info, int price, int balance);
  11 + void createListViewItem(CCPoint& origin, CCMenu* menu, CCSize& visibleSize, int tag, const char* img);
12 12 const char* itemIdFromTag(int tag);
13 13 static int tagFromItemId(const char* itemId);
14 14
63 cocos2dx-store/Classes/StoreBScene.cpp
@@ -3,6 +3,7 @@
3 3 #include "StoreAScene.h"
4 4 #include "cocos2dx_StoreInventory.h"
5 5 #include "cocos2dx_StoreController.h"
  6 +#include "cocos2dx_StoreInfo.h"
6 7 #include "Includes.h"
7 8
8 9 #include <string>
@@ -75,11 +76,11 @@ bool StoreBScene::init()
75 76 // In Game Menu
76 77 CCMenu* menu = CCMenu::create(backItem, NULL);
77 78
78   - createListViewItem(origin, menu, visibleSize, 0, "no_ads.png", "Remove Ads!", "Test purchase of MANAGED item.", 5.99);
79   - createListViewItem(origin, menu, visibleSize, 1, "muffins01.png", "10 Muffins", "Test refund of an item", 0.99);
80   - createListViewItem(origin, menu, visibleSize, 2, "muffins02.png", "50 Muffins", "Test cancellation of an item", 1.99);
81   - createListViewItem(origin, menu, visibleSize, 3, "muffins03.png", "400 Muffins", "Test purchase of an item", 4.99);
82   - createListViewItem(origin, menu, visibleSize, 4, "muffins04.png", "1000 Muffins", "Test item unavailable", 8.99);
  79 + createListViewItem(origin, menu, visibleSize, 0, "no_ads.png");
  80 + createListViewItem(origin, menu, visibleSize, 1, "muffins01.png");
  81 + createListViewItem(origin, menu, visibleSize, 2, "muffins02.png");
  82 + createListViewItem(origin, menu, visibleSize, 3, "muffins03.png");
  83 + createListViewItem(origin, menu, visibleSize, 4, "muffins04.png");
83 84
84 85 menu->setPosition(CCPointZero);
85 86 this->addChild(menu);
@@ -143,12 +144,34 @@ void StoreBScene::setCurrencyBalanceLabel() {
143 144 pLabelBalance->setString(convert.str().c_str());
144 145 }
145 146
146   -void StoreBScene::createListViewItem(CCPoint& origin, CCMenu* menu, CCSize& visibleSize, int tag, const char* img, const char* name, const char* info, float price) {
  147 +void StoreBScene::createListViewItem(CCPoint& origin, CCMenu* menu, CCSize& visibleSize, int tag, const char* img) {
147 148 GameMenuItem *pChooseItem = GameMenuItem::itemWithLabel(
148 149 CCSprite::create("button.png"),
149 150 this,
150 151 menu_selector(StoreBScene::menuChooseCallback));
151 152
  153 + char itemId[512];
  154 + snprintf(itemId, sizeof(itemId), itemIdFromTag(tag));
  155 +
  156 + char name[512];
  157 + char info[512];
  158 + double price = 0;
  159 + int balance = 0;
  160 + if (strcmp (itemId,"ERROR") == 0) {
  161 + snprintf(name, sizeof(name), "Remove Ads!");
  162 + snprintf(info, sizeof(info), "Test purchase of MANAGED item.");
  163 + price = 5.99f;
  164 + }
  165 + else {
  166 + // TODO: exception handling ..
  167 + string nameS = cocos2dx_StoreInfo::getPackName(itemId);
  168 + string infoS = cocos2dx_StoreInfo::getPackDescription(itemId);
  169 + price = cocos2dx_StoreInfo::getPackPrice(itemId);
  170 +
  171 + snprintf(name, sizeof(name), nameS.c_str());
  172 + snprintf(info, sizeof(info), infoS.c_str());
  173 + }
  174 +
152 175 float yOffset = - 200;
153 176
154 177 pChooseItem->setPosition(ccp(origin.x + visibleSize.width/2, yOffset + origin.y + visibleSize.height - 100 - (tag * pChooseItem->boundingBox().size.height)));
@@ -190,18 +213,33 @@ void StoreBScene::createListViewItem(CCPoint& origin, CCMenu* menu, CCSize& visi
190 213 }
191 214
192 215 const char* StoreBScene::productIdFromTag(int tag) {
  216 +
  217 + char itemId[512];
  218 + snprintf(itemId, sizeof(itemId), itemIdFromTag(tag));
  219 +
  220 + if (strcmp (itemId,"ERROR") == 0) {
  221 + return "no_ads";
  222 + }
  223 + else {
  224 + // TODO: exception handling ..
  225 + string p = cocos2dx_StoreInfo::getPackProductId(itemId);
  226 + return p.c_str();
  227 + }
  228 +
  229 + return "ERROR";
  230 +}
  231 +
  232 +const char* StoreBScene::itemIdFromTag(int tag) {
193 233 switch (tag)
194 234 {
195   - case 0: return "no_ads";
  235 + case 1: return "muffins_10";
196 236 break;
197   - case 1: return "android.test.refunded";
  237 + case 2: return "muffins_50";
198 238 break;
199   - case 2: return "android.test.canceled";
  239 + case 3: return "muffins_400";
200 240 break;
201   - case 3: return "android.test.purchased";
  241 + case 4: return "muffins_1000";
202 242 break;
203   - case 4: return "android.test.item_unavailable";
204   - break;
205 243 default: return "ERROR";
206 244 break;
207 245 }
@@ -209,4 +247,3 @@ const char* StoreBScene::productIdFromTag(int tag) {
209 247 return "ERROR";
210 248 }
211 249
212   -
5 cocos2dx-store/Classes/StoreBScene.h
@@ -9,8 +9,9 @@ class StoreBScene : public cocos2d::CCLayerColor
9 9 {
10 10 private:
11 11 const char* productIdFromTag(int tag);
12   - void createListViewItem(CCPoint& origin, CCMenu* menu, CCSize& visibleSize, int tag, const char* img, const char* name, const char* info, float price);
13   -
  12 + void createListViewItem(CCPoint& origin, CCMenu* menu, CCSize& visibleSize, int tag, const char* img);
  13 + const char* itemIdFromTag(int tag);
  14 +
14 15 static CCLabelTTF* pLabelBalance;
15 16 public:
16 17 // Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
237 cocos2dx-store/Classes/cocos2dx_StoreController.cpp
@@ -7,224 +7,69 @@
7 7 //
8 8
9 9 #include "cocos2dx_StoreController.h"
10   -
11   -#include <jni.h>
12   -#include "platform/android/jni/JniHelper.h"
13   -#include <android/log.h>
  10 +#include "JniHelpers.h"
14 11
15 12 void cocos2dx_StoreController::storeOpening() {
16   - cocos2d::JniMethodInfo minfo;
17   -
18   - bool isHave = cocos2d::JniHelper::getStaticMethodInfo(minfo,"com/soomla/store/StoreControllerBridge","storeOpening", "()V");
19   -
20   - if (!isHave) {
21   - //do nothing
22   - } else {
23   - minfo.env->CallStaticVoidMethod(minfo.classID, minfo.methodID);
24   - }
  13 + JniHelpers::jniCommonVoidCall(
  14 + "storeOpening",
  15 + "com/soomla/store/StoreControllerBridge"
  16 + );
  17 +
25 18 }
26 19
27 20 void cocos2dx_StoreController::storeClosing() {
28   - cocos2d::JniMethodInfo minfo;
29   -
30   - bool isHave = cocos2d::JniHelper::getStaticMethodInfo(minfo,"com/soomla/store/StoreControllerBridge","storeClosing", "()V");
31   -
32   - if (!isHave) {
33   - //do nothing
34   - } else {
35   - minfo.env->CallStaticVoidMethod(minfo.classID, minfo.methodID);
36   - }
  21 + JniHelpers::jniCommonVoidCall(
  22 + "storeClosing",
  23 + "com/soomla/store/StoreControllerBridge"
  24 + );
  25 +
37 26 }
38 27
39 28 void cocos2dx_StoreController::initialize(bool debug) {
40   - cocos2d::JniMethodInfo minfo;
41   -
42   - bool isHave = cocos2d::JniHelper::getStaticMethodInfo(minfo,"com/soomla/store/StoreControllerBridge","initialize", "(Z)V");
43   -
44   - if (!isHave) {
45   - //do nothing
46   - } else {
47   - minfo.env->CallStaticVoidMethod(minfo.classID, minfo.methodID, debug);
48   - }
  29 + JniHelpers::jniCommonVoidCall(
  30 + "initialize",
  31 + "com/soomla/store/StoreControllerBridge",
  32 + debug
  33 + );
49 34 }
50 35
51 36 void cocos2dx_StoreController::buyCurrencyPack(string productId) throw(cocos2dx_VirtualItemNotFoundException&){
52   - cocos2d::JniMethodInfo minfo;
53   -
54   - __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Starting buyCurrencyPack");
55   -
56   - bool isHave = cocos2d::JniHelper::getStaticMethodInfo(minfo,"com/soomla/store/StoreControllerBridge","buyCurrencyPack", "(Ljava/lang/String;)V");
57   -
58   - if (!isHave) {
59   - //do nothing
60   - } else {
61   - jstring stringArg0 = minfo.env->NewStringUTF(productId.c_str());
62   -
63   - minfo.env->CallStaticVoidMethod(minfo.classID, minfo.methodID, stringArg0);
64   -
65   - minfo.env->DeleteLocalRef(stringArg0);
66   -
67   - __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "buyCurrencyPack returned");
68   -
69   - if(minfo.env->ExceptionCheck() == JNI_TRUE ) {
70   - __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "HAS EXCEPTION");
71   - jthrowable exceptionObj = minfo.env->ExceptionOccurred();
72   - minfo.env->ExceptionClear();
73   -
74   - jclass vinfEx = cocos2d::JniHelper::getClassID("com/soomla/store/exceptions/VirtualItemNotFoundException", minfo.env);
75   - if (minfo.env->IsInstanceOf(exceptionObj, vinfEx)) {
76   - __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Cought VirtualItemNotFoundException!");
77   -
78   - throw cocos2dx_VirtualItemNotFoundException();
79   - }
80   - }
81   - }
  37 + JniHelpers::jniCommonVoidCall(
  38 + "buyCurrencyPack",
  39 + "com/soomla/store/StoreControllerBridge",
  40 + productId.c_str()
  41 + );
82 42 }
83 43
84 44 void cocos2dx_StoreController::buyVirtualGood(string itemId) throw (cocos2dx_VirtualItemNotFoundException&, cocos2dx_InsufficientFundsException&) {
85   - cocos2d::JniMethodInfo minfo;
86   -
87   - __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Starting buyVirtualGood");
88   -
89   - bool isHave = cocos2d::JniHelper::getStaticMethodInfo(minfo,"com/soomla/store/StoreControllerBridge","buyVirtualGood", "(Ljava/lang/String;)V");
90   -
91   - if (!isHave) {
92   - //do nothing
93   - } else {
94   - jstring stringArg0 = minfo.env->NewStringUTF(itemId.c_str());
95   -
96   - minfo.env->CallStaticVoidMethod(minfo.classID, minfo.methodID, stringArg0);
97   -
98   - minfo.env->DeleteLocalRef(stringArg0);
99   -
100   - __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "buyVirtualGood returned");
101   -
102   - if(minfo.env->ExceptionCheck() == JNI_TRUE ) {
103   - __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "HAS EXCEPTION");
104   - jthrowable exceptionObj = minfo.env->ExceptionOccurred();
105   - minfo.env->ExceptionClear();
106   -
107   - jclass vinfEx = cocos2d::JniHelper::getClassID("com/soomla/store/exceptions/VirtualItemNotFoundException", minfo.env);
108   - if (minfo.env->IsInstanceOf(exceptionObj, vinfEx)) {
109   - __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Cought VirtualItemNotFoundException!");
110   -
111   - throw cocos2dx_VirtualItemNotFoundException();
112   - }
113   -
114   - vinfEx = cocos2d::JniHelper::getClassID("com/soomla/store/exceptions/InsufficientFundsException", minfo.env);
115   - if (minfo.env->IsInstanceOf(exceptionObj, vinfEx)) {
116   - __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Cought InsufficientFundsException!");
117   -
118   - throw cocos2dx_InsufficientFundsException();
119   - }
120   - }
121   - }
  45 + JniHelpers::jniCommonVoidCall(
  46 + "buyVirtualGood",
  47 + "com/soomla/store/StoreControllerBridge",
  48 + itemId.c_str()
  49 + );
122 50 }
123 51
124 52 void cocos2dx_StoreController::buyManagedItem(string productId) throw(cocos2dx_VirtualItemNotFoundException&) {
125   - cocos2d::JniMethodInfo minfo;
126   -
127   - __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Starting buyManagedItem");
128   -
129   - bool isHave = cocos2d::JniHelper::getStaticMethodInfo(minfo,"com/soomla/store/StoreControllerBridge","buyManagedItem", "(Ljava/lang/String;)V");
130   -
131   - if (!isHave) {
132   - //do nothing
133   - } else {
134   - jstring stringArg0 = minfo.env->NewStringUTF(productId.c_str());
135   -
136   - minfo.env->CallStaticVoidMethod(minfo.classID, minfo.methodID, stringArg0);
137   -
138   - minfo.env->DeleteLocalRef(stringArg0);
139   -
140   - __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "buyManagedItem returned");
141   -
142   - if(minfo.env->ExceptionCheck() == JNI_TRUE ) {
143   - __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "HAS EXCEPTION");
144   - jthrowable exceptionObj = minfo.env->ExceptionOccurred();
145   - minfo.env->ExceptionClear();
146   -
147   - jclass vinfEx = cocos2d::JniHelper::getClassID("com/soomla/store/exceptions/VirtualItemNotFoundException", minfo.env);
148   - if (minfo.env->IsInstanceOf(exceptionObj, vinfEx)) {
149   - __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Cought VirtualItemNotFoundException!");
150   -
151   - throw cocos2dx_VirtualItemNotFoundException();
152   - }
153   - }
154   - }
  53 + JniHelpers::jniCommonVoidCall(
  54 + "buyManagedItem",
  55 + "com/soomla/store/StoreControllerBridge",
  56 + productId.c_str()
  57 + );
155 58 }
156 59
157 60 void cocos2dx_StoreController::equipVirtualGood(string itemId) throw (cocos2dx_NotEnoughGoodsException&, cocos2dx_VirtualItemNotFoundException&) {
158   - cocos2d::JniMethodInfo minfo;
159   -
160   - __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Starting equipVirtualGood");
161   -
162   - bool isHave = cocos2d::JniHelper::getStaticMethodInfo(minfo,"com/soomla/store/StoreControllerBridge","equipVirtualGood", "(Ljava/lang/String;)V");
163   -
164   - if (!isHave) {
165   - //do nothing
166   - } else {
167   - jstring stringArg0 = minfo.env->NewStringUTF(itemId.c_str());
168   -
169   - minfo.env->CallStaticVoidMethod(minfo.classID, minfo.methodID, stringArg0);
170   -
171   - minfo.env->DeleteLocalRef(stringArg0);
172   -
173   - __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "equipVirtualGood returned");
174   -
175   - if(minfo.env->ExceptionCheck() == JNI_TRUE ) {
176   - __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "HAS EXCEPTION");
177   - jthrowable exceptionObj = minfo.env->ExceptionOccurred();
178   - minfo.env->ExceptionClear();
179   -
180   - jclass vinfEx = cocos2d::JniHelper::getClassID("com/soomla/store/exceptions/VirtualItemNotFoundException", minfo.env);
181   - if (minfo.env->IsInstanceOf(exceptionObj, vinfEx)) {
182   - __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Cought VirtualItemNotFoundException!");
183   -
184   - throw cocos2dx_VirtualItemNotFoundException();
185   - }
186   -
187   - vinfEx = cocos2d::JniHelper::getClassID("com/soomla/store/exceptions/NotEnoughGoodsException", minfo.env);
188   - if (minfo.env->IsInstanceOf(exceptionObj, vinfEx)) {
189   - __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Cought NotEnoughGoodsException!");
190   -
191   - throw cocos2dx_NotEnoughGoodsException();
192   - }
193   - }
194   - }
  61 + JniHelpers::jniCommonVoidCall(
  62 + "equipVirtualGood",
  63 + "com/soomla/store/StoreControllerBridge",
  64 + itemId.c_str()
  65 + );
195 66 }
196 67
197 68 void cocos2dx_StoreController::unequipVirtualGood(string itemId) throw(cocos2dx_VirtualItemNotFoundException&) {
198   - cocos2d::JniMethodInfo minfo;
199   -
200   - __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Starting unequipVirtualGood");
201   -
202   - bool isHave = cocos2d::JniHelper::getStaticMethodInfo(minfo,"com/soomla/store/StoreControllerBridge","unequipVirtualGood", "(Ljava/lang/String;)V");
203   -
204   - if (!isHave) {
205   - //do nothing
206   - } else {
207   - jstring stringArg0 = minfo.env->NewStringUTF(itemId.c_str());
208   -
209   - minfo.env->CallStaticVoidMethod(minfo.classID, minfo.methodID, stringArg0);
210   -
211   - minfo.env->DeleteLocalRef(stringArg0);
212   -
213   - __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "unequipVirtualGood returned");
214   -
215   - if(minfo.env->ExceptionCheck() == JNI_TRUE ) {
216   - __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "HAS EXCEPTION");
217   - jthrowable exceptionObj = minfo.env->ExceptionOccurred();
218   - minfo.env->ExceptionClear();
219   -
220   - jclass vinfEx = cocos2d::JniHelper::getClassID("com/soomla/store/exceptions/VirtualItemNotFoundException", minfo.env);
221   - if (minfo.env->IsInstanceOf(exceptionObj, vinfEx)) {
222   - __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Cought VirtualItemNotFoundException!");
223   -
224   - throw cocos2dx_VirtualItemNotFoundException();
225   - }
226   - }
227   - }
  69 + JniHelpers::jniCommonVoidCall(
  70 + "unequipVirtualGood",
  71 + "com/soomla/store/StoreControllerBridge",
  72 + itemId.c_str()
  73 + );
228 74 }
229 75
230   -
2  cocos2dx-store/Classes/cocos2dx_StoreController.h
@@ -18,7 +18,7 @@
18 18 using namespace std;
19 19
20 20 class cocos2dx_StoreController {
21   -
  21 +
22 22 public:
23 23
24 24 //iOS + Android
70 cocos2dx-store/Classes/cocos2dx_StoreInfo.cpp
... ... @@ -0,0 +1,70 @@
  1 +//
  2 +// cocos2dx_StoreInfo.cpp
  3 +// cocos2dx-store
  4 +//
  5 +// Created by Refael Dakar on 10/22/12.
  6 +//
  7 +//
  8 +
  9 +#include "cocos2dx_StoreInfo.h"
  10 +#include "JniHelpers.h"
  11 +
  12 +string cocos2dx_StoreInfo::getPackProductId(const char* itemId) throw (cocos2dx_VirtualItemNotFoundException&) {
  13 + return JniHelpers::jniCommonStringCall(
  14 + "getPackProductId",
  15 + "com/soomla/store/StoreInfoBridge",
  16 + itemId
  17 + );
  18 +}
  19 +
  20 +string cocos2dx_StoreInfo::getPackName(const char* itemId) throw (cocos2dx_VirtualItemNotFoundException&) {
  21 + return JniHelpers::jniCommonStringCall(
  22 + "getPackName",
  23 + "com/soomla/store/StoreInfoBridge",
  24 + itemId
  25 + );
  26 +}
  27 +
  28 +string cocos2dx_StoreInfo::getPackDescription(const char* itemId) throw (cocos2dx_VirtualItemNotFoundException&) {
  29 + return JniHelpers::jniCommonStringCall(
  30 + "getPackDescription",
  31 + "com/soomla/store/StoreInfoBridge",
  32 + itemId
  33 + );
  34 +}
  35 +
  36 +double cocos2dx_StoreInfo::getPackPrice(const char* itemId) throw (cocos2dx_VirtualItemNotFoundException&) {
  37 + return JniHelpers::jniCommonDoubleCall(
  38 + "getPackPrice",
  39 + "com/soomla/store/StoreInfoBridge",
  40 + itemId
  41 + );
  42 +}
  43 +
  44 +string cocos2dx_StoreInfo::getGoodName(const char* itemId) throw (cocos2dx_VirtualItemNotFoundException&) {
  45 + return JniHelpers::jniCommonStringCall(
  46 + "getGoodName",
  47 + "com/soomla/store/StoreInfoBridge",
  48 + itemId
  49 + );
  50 +}
  51 +
  52 +string cocos2dx_StoreInfo::getGoodDescription(const char* itemId) throw (cocos2dx_VirtualItemNotFoundException&) {
  53 + return JniHelpers::jniCommonStringCall(
  54 + "getGoodDescription",
  55 + "com/soomla/store/StoreInfoBridge",
  56 + itemId
  57 + );
  58 +}
  59 +
  60 +int cocos2dx_StoreInfo::getGoodPriceForCurrency(const char* goodItemId, const char* currencyItemId) throw (cocos2dx_VirtualItemNotFoundException&) {
  61 + return JniHelpers::jniCommonIntCall(
  62 + "getGoodPriceForCurrency",
  63 + "com/soomla/store/StoreInfoBridge",
  64 + goodItemId,
  65 + currencyItemId
  66 + );
  67 +}
  68 +
  69 +
  70 +
32 cocos2dx-store/Classes/cocos2dx_StoreInfo.h
... ... @@ -0,0 +1,32 @@
  1 +//
  2 +// cocos2dx_StoreInfo.h
  3 +// cocos2dx-store
  4 +//
  5 +// Created by Refael Dakar on 10/28/12.
  6 +//
  7 +//
  8 +
  9 +#ifndef __cocos2dx_store__cocos2dx_StoreInfo__
  10 +#define __cocos2dx_store__cocos2dx_StoreInfo__
  11 +
  12 +#include <iostream>
  13 +#include "cocos2dx_VirtualItemNotFoundException.h"
  14 +#include <string>
  15 +
  16 +using namespace std;
  17 +
  18 +class cocos2dx_StoreInfo {
  19 +public:
  20 +
  21 + static string getPackProductId(const char* itemId) throw (cocos2dx_VirtualItemNotFoundException&);
  22 + static string getPackName(const char* itemId) throw (cocos2dx_VirtualItemNotFoundException&);
  23 + static string getPackDescription(const char* itemId) throw (cocos2dx_VirtualItemNotFoundException&);
  24 + static double getPackPrice(const char* itemId) throw (cocos2dx_VirtualItemNotFoundException&);
  25 + static string getGoodName(const char* itemId) throw (cocos2dx_VirtualItemNotFoundException&);
  26 + static string getGoodDescription(const char* itemId) throw (cocos2dx_VirtualItemNotFoundException&);
  27 + static int getGoodPriceForCurrency(const char* goodItemId, const char* currencyItemId) throw (cocos2dx_VirtualItemNotFoundException&);
  28 +
  29 +};
  30 +
  31 +
  32 +#endif /* defined(__cocos2dx_store__cocos2dx_StoreInfo__) */
243 cocos2dx-store/Classes/cocos2dx_StoreInventory.cpp
@@ -7,229 +7,56 @@
7 7 //
8 8
9 9 #include "cocos2dx_StoreInventory.h"
10   -#include <jni.h>
11   -#include "platform/android/jni/JniHelper.h"
12   -#include <android/log.h>
  10 +#include "JniHelpers.h"
13 11
14 12 int cocos2dx_StoreInventory::getCurrencyBalance(string currencyItemId) throw (cocos2dx_VirtualItemNotFoundException&) {
15   - cocos2d::JniMethodInfo minfo;
16   -
17   - __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Starting getCurrencyBalance");
18   -
19   - bool isHave = cocos2d::JniHelper::getStaticMethodInfo(minfo,"com/soomla/store/StoreInventoryBridge","getCurrencyBalance", "(Ljava/lang/String;)I");
20   -
21   - if (!isHave) {
22   - //do nothing
23   - } else {
24   - jstring stringArg0 = minfo.env->NewStringUTF(currencyItemId.c_str());
25   -
26   - jint balance = minfo.env->CallStaticIntMethod(minfo.classID, minfo.methodID, stringArg0);
27   -
28   - minfo.env->DeleteLocalRef(stringArg0);