Skip to content
Browse files

supporting new currency and good changed events

  • Loading branch information...
1 parent dc8c04d commit e8986d3d8094210bb15bd5852d91d7a1a7e5410e @refaelos refaelos committed Jan 5, 2013
View
16 cocos2dx-store/Classes/EventHandler.cpp
@@ -19,16 +19,15 @@
#include "StoreBScene.h"
void EventHandler::marketPurchase(string& productId) {
- StoreBScene::setCurrencyBalanceLabel();
+
}
void EventHandler::marketRefund(string& productId) {
- StoreBScene::setCurrencyBalanceLabel();
+
}
void EventHandler::virtualGoodPurchased(string& itemId) {
- StoreAScene::setPriceBalanceLabel(itemId.c_str());
- StoreAScene::setCurrencyBalanceLabel();
+
}
void EventHandler::virtualGoodEquipped(string& itemId) {
@@ -67,3 +66,12 @@ void EventHandler::openingStore() {
}
+void EventHandler::currencyBalanceChanged(string &itemId, int balance) {
+ StoreBScene::setCurrencyBalanceLabel();
+ StoreAScene::setCurrencyBalanceLabel();
+}
+
+void EventHandler::goodBalanceChanged(string &itemId, int balance) {
+ StoreAScene::setPriceBalanceLabel(itemId.c_str());
+}
+
View
2 cocos2dx-store/Classes/EventHandler.h
@@ -36,6 +36,8 @@ class EventHandler : public IEventHandler {
void closingStore();
void unexpectedErrorInStore();
void openingStore();
+ void currencyBalanceChanged(string &itemId, int balance);
+ void goodBalanceChanged(string &itemId, int balance);
};
#endif
View
9 cocos2dx-store/Classes/StoreAScene.cpp
@@ -89,6 +89,11 @@ bool StoreAScene::init()
pLabelBalance->setPosition(ccp(origin.x + visibleSize.width - 40, visibleSize.height + origin.y - 50));
this->addChild(pLabelBalance, 1);
setCurrencyBalanceLabel();
+#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
+ __android_log_write(ANDROID_LOG_ERROR, "SOOMLA JNI", "HHHHHHHHHHHHHHH");
+#elif (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
+ iOSHelper::LogMessage("HHHHHHHHHHHHHHH");
+#endif
GameMenuItem* getMoreItem = GameMenuItem::itemWithLabel(
CCSprite::create("get_more.png"),
@@ -229,6 +234,10 @@ void StoreAScene::createListViewItem(CCPoint& origin, CCMenu* menu, CCSize& visi
}
void StoreAScene::setCurrencyBalanceLabel() {
+ if (!pLabelBalance) {
+ return;
+ }
+
int balance = 0;
try{
balance = cocos2dx_StoreInventory::getCurrencyBalance("currency_muffin");
View
6 cocos2dx-store/Classes/StoreAScene.h
@@ -53,6 +53,12 @@ class StoreAScene : public cocos2d::CCLayerColor
{
menuBackCallback(NULL);
}
+
+ ~StoreAScene() {
+ if (pLabelBalance) {
+ pLabelBalance = NULL;
+ }
+ }
static void setCurrencyBalanceLabel();
static void setPriceBalanceLabel(const char* itemId);
View
4 cocos2dx-store/Classes/StoreBScene.cpp
@@ -145,6 +145,10 @@ void StoreBScene::menuChooseCallback(CCObject* pSender)
}
void StoreBScene::setCurrencyBalanceLabel() {
+ if (!pLabelBalance) {
+ return;
+ }
+
int balance = 0;
try{
balance = cocos2dx_StoreInventory::getCurrencyBalance("currency_muffin");
View
6 cocos2dx-store/Classes/StoreBScene.h
@@ -50,6 +50,12 @@ class StoreBScene : public cocos2d::CCLayerColor
{
menuBackCallback(NULL);
}
+
+ ~StoreBScene() {
+ if (pLabelBalance) {
+ pLabelBalance = NULL;
+ }
+ }
static void setCurrencyBalanceLabel();
};
View
12 cocos2dx-store/Classes/StoreBridge/cocos2dx_EventHandlers.cpp
@@ -106,3 +106,15 @@ void cocos2dx_EventHandlers::openingStore() {
(*itr)->openingStore();
}
+void cocos2dx_EventHandlers::currencyBalanceChanged(string& itemId, int balance) {
+ set<IEventHandler*>::iterator itr;
+ for ( itr = handlers.begin(); itr != handlers.end(); itr++ )
+ (*itr)->currencyBalanceChanged(itemId, balance);
+}
+
+void cocos2dx_EventHandlers::goodBalanceChanged(string& itemId, int balance) {
+ set<IEventHandler*>::iterator itr;
+ for ( itr = handlers.begin(); itr != handlers.end(); itr++ )
+ (*itr)->goodBalanceChanged(itemId, balance);
+}
+
View
4 cocos2dx-store/Classes/StoreBridge/cocos2dx_EventHandlers.h
@@ -36,6 +36,8 @@ class IEventHandler {
virtual void closingStore() = 0;
virtual void unexpectedErrorInStore() = 0;
virtual void openingStore() = 0;
+ virtual void currencyBalanceChanged(string &itemId, int balance) = 0;
+ virtual void goodBalanceChanged(string &itemId, int balance) = 0;
};
class cocos2dx_EventHandlers {
@@ -60,6 +62,8 @@ class cocos2dx_EventHandlers {
void closingStore();
void unexpectedErrorInStore();
void openingStore();
+ void currencyBalanceChanged(string &itemId, int balance);
+ void goodBalanceChanged(string &itemId, int balance);
};
#endif /* defined(__cocos2dx_store__cocos2dx_EventHandler__) */
View
23 cocos2dx-store/Classes/StoreBridge/com_soomla_cocos2dx_store_EventHandlerBridge.cpp
@@ -126,3 +126,26 @@ JNIEXPORT void JNICALL Java_com_soomla_cocos2dx_store_EventHandlerBridge_opening
cocos2dx_EventHandlers::getInstance()->openingStore();
}
+
+JNIEXPORT void JNICALL Java_com_soomla_cocos2dx_store_EventHandlerBridge_currencyBalanceChanged
+ (JNIEnv * env, jobject obj, jstring itemId, jint balance){
+ string itemIdStr = cocos2d::JniHelper::jstring2string(itemId);
+ string msg("Currency balance changed for: ");
+ msg += itemIdStr;
+ __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", msg.c_str());
+
+
+ cocos2dx_EventHandlers::getInstance()->currencyBalanceChanged(itemIdStr, balance);
+ }
+
+JNIEXPORT void JNICALL Java_com_soomla_cocos2dx_store_EventHandlerBridge_goodBalanceChanged
+ (JNIEnv * env, jobject obj, jstring itemId, jint balance){
+ string itemIdStr = cocos2d::JniHelper::jstring2string(itemId);
+ string msg("Good balance changed for: ");
+ msg += itemIdStr;
+ __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", msg.c_str());
+
+
+ cocos2dx_EventHandlers::getInstance()->goodBalanceChanged(itemIdStr, balance);
+ }
+
View
16 cocos2dx-store/Classes/StoreBridge/com_soomla_cocos2dx_store_EventHandlerBridge.h
@@ -118,6 +118,22 @@ JNIEXPORT void JNICALL Java_com_soomla_cocos2dx_store_EventHandlerBridge_unexpec
*/
JNIEXPORT void JNICALL Java_com_soomla_cocos2dx_store_EventHandlerBridge_openingStore
(JNIEnv *, jobject);
+
+/*
+ * Class: com_soomla_cocos2dx_store_EventHandlerBridge
+ * Method: currencyBalanceChanged
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_com_soomla_cocos2dx_store_EventHandlerBridge_currencyBalanceChanged
+ (JNIEnv *, jobject, jstring itemId, jint balance);
+
+/*
+ * Class: com_soomla_cocos2dx_store_EventHandlerBridge
+ * Method: goodBalanceChanged
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_com_soomla_cocos2dx_store_EventHandlerBridge_goodBalanceChanged
+ (JNIEnv *, jobject, jstring itemId, jint balance);
#ifdef __cplusplus
}
View
15 cocos2dx-store/ios/AppController.mm
@@ -9,6 +9,7 @@
#import "VirtualCurrencyPack.h"
#import "AppStoreItem.h"
#import "VirtualGood.h"
+#import "VirtualCurrency.h"
#import "RootViewController.h"
@@ -139,7 +140,19 @@ - (void)eventFired:(NSNotification*)notification{
}
else if ([notification.name isEqualToString:EVENT_UNEXPECTED_ERROR_IN_STORE]) {
cocos2dx_EventHandlers::getInstance()->unexpectedErrorInStore();
- }
+ }
+ else if ([notification.name isEqualToString:EVENT_CHANGED_CURRENCY_BALANCE]) {
+ int balance = [(NSNumber*)[notification.userInfo objectForKey:@"balance"] intValue];
+ VirtualCurrency* currency = (VirtualCurrency*)[notification.userInfo objectForKey:@"VirtualCurrency"];
+ string itemId([currency.itemId UTF8String]);
+ cocos2dx_EventHandlers::getInstance()->currencyBalanceChanged(itemId, balance);
+ }
+ else if ([notification.name isEqualToString:EVENT_CHANGED_GOOD_BALANCE]) {
+ int balance = [(NSNumber*)[notification.userInfo objectForKey:@"balance"] intValue];
+ VirtualGood* good = (VirtualGood*)[notification.userInfo objectForKey:@"VirtualGood"];
+ string itemId([good.itemId UTF8String]);
+ cocos2dx_EventHandlers::getInstance()->goodBalanceChanged(itemId, balance);
+ }
}
2 submodules/android-store
@@ -1 +1 @@
-Subproject commit 88daca1083315dc7c7bf7c205d2e4108eca1d281
+Subproject commit 57c75f7f38189d2704d994ac72ad890b6ca81c4f
2 submodules/ios-store
@@ -1 +1 @@
-Subproject commit be6d4ce4d516c67c6b3d61426e75c500002ed0d9
+Subproject commit 858174c69add68cd1e46d25ac2eb981b5188fd01

0 comments on commit e8986d3

Please sign in to comment.
Something went wrong with that request. Please try again.