Merge branch 'develop' of https://github.com/cocos2d/cocos2d-x into iss2430-modify_enum

This commit is contained in:
minggo 2013-07-26 17:45:24 +08:00
commit 7817dd6c0f
24 changed files with 243 additions and 281 deletions

View File

@ -734,6 +734,28 @@ void js_register_pluginx_protocols_ProtocolIAP(JSContext *cx, JSObject *global)
JSClass *jsb_ProtocolAds_class;
JSObject *jsb_ProtocolAds_prototype;
JSBool js_pluginx_protocols_ProtocolAds_showAds(JSContext *cx, uint32_t argc, jsval *vp)
{
jsval *argv = JS_ARGV(cx, vp);
JSBool ok = JS_TRUE;
JSObject *obj = JS_THIS_OBJECT(cx, vp);
js_proxy_t *proxy = jsb_get_js_proxy(obj);
cocos2d::plugin::ProtocolAds* cobj = (cocos2d::plugin::ProtocolAds *)(proxy ? proxy->ptr : NULL);
JSB_PRECONDITION2( cobj, cx, JS_FALSE, "Invalid Native Object");
if (argc == 2) {
TAdsInfo arg0;
cocos2d::plugin::ProtocolAds::AdsPos arg1;
#pragma warning NO CONVERSION TO NATIVE FOR TAdsInfo;
ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1);
JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
cobj->showAds(arg0, arg1);
JS_SET_RVAL(cx, vp, JSVAL_VOID);
return JS_TRUE;
}
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 2);
return JS_FALSE;
}
JSBool js_pluginx_protocols_ProtocolAds_hideAds(JSContext *cx, uint32_t argc, jsval *vp)
{
jsval *argv = JS_ARGV(cx, vp);
@ -743,8 +765,8 @@ JSBool js_pluginx_protocols_ProtocolAds_hideAds(JSContext *cx, uint32_t argc, js
cocos2d::plugin::ProtocolAds* cobj = (cocos2d::plugin::ProtocolAds *)(proxy ? proxy->ptr : NULL);
JSB_PRECONDITION2( cobj, cx, JS_FALSE, "Invalid Native Object");
if (argc == 1) {
cocos2d::plugin::ProtocolAds::AdsType arg0;
ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0);
TAdsInfo arg0;
#pragma warning NO CONVERSION TO NATIVE FOR TAdsInfo;
JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
cobj->hideAds(arg0);
JS_SET_RVAL(cx, vp, JSVAL_VOID);
@ -769,28 +791,6 @@ JSBool js_pluginx_protocols_ProtocolAds_queryPoints(JSContext *cx, uint32_t argc
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 0);
return JS_FALSE;
}
JSBool js_pluginx_protocols_ProtocolAds_onAdsResult(JSContext *cx, uint32_t argc, jsval *vp)
{
jsval *argv = JS_ARGV(cx, vp);
JSBool ok = JS_TRUE;
JSObject *obj = JS_THIS_OBJECT(cx, vp);
js_proxy_t *proxy = jsb_get_js_proxy(obj);
cocos2d::plugin::ProtocolAds* cobj = (cocos2d::plugin::ProtocolAds *)(proxy ? proxy->ptr : NULL);
JSB_PRECONDITION2( cobj, cx, JS_FALSE, "Invalid Native Object");
if (argc == 2) {
cocos2d::plugin::AdsResultCode arg0;
const char* arg1;
ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0);
std::string arg1_tmp; ok &= jsval_to_std_string(cx, argv[1], &arg1_tmp); arg1 = arg1_tmp.c_str();
JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
cobj->onAdsResult(arg0, arg1);
JS_SET_RVAL(cx, vp, JSVAL_VOID);
return JS_TRUE;
}
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 2);
return JS_FALSE;
}
JSBool js_pluginx_protocols_ProtocolAds_spendPoints(JSContext *cx, uint32_t argc, jsval *vp)
{
jsval *argv = JS_ARGV(cx, vp);
@ -831,24 +831,28 @@ JSBool js_pluginx_protocols_ProtocolAds_configDeveloperInfo(JSContext *cx, uint3
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1);
return JS_FALSE;
}
JSBool js_pluginx_protocols_ProtocolAds_onPlayerGetPoints(JSContext *cx, uint32_t argc, jsval *vp)
JSBool js_pluginx_protocols_ProtocolAds_getAdsListener(JSContext *cx, uint32_t argc, jsval *vp)
{
jsval *argv = JS_ARGV(cx, vp);
JSBool ok = JS_TRUE;
JSObject *obj = JS_THIS_OBJECT(cx, vp);
js_proxy_t *proxy = jsb_get_js_proxy(obj);
cocos2d::plugin::ProtocolAds* cobj = (cocos2d::plugin::ProtocolAds *)(proxy ? proxy->ptr : NULL);
JSB_PRECONDITION2( cobj, cx, JS_FALSE, "Invalid Native Object");
if (argc == 1) {
int arg0;
ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0);
JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
cobj->onPlayerGetPoints(arg0);
JS_SET_RVAL(cx, vp, JSVAL_VOID);
if (argc == 0) {
cocos2d::plugin::AdsListener* ret = cobj->getAdsListener();
jsval jsret;
do {
if (ret) {
js_proxy_t *proxy = js_get_or_create_proxy<cocos2d::plugin::AdsListener>(cx, ret);
jsret = OBJECT_TO_JSVAL(proxy->obj);
} else {
jsret = JSVAL_NULL;
}
} while (0);
JS_SET_RVAL(cx, vp, jsret);
return JS_TRUE;
}
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1);
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 0);
return JS_FALSE;
}
@ -889,12 +893,12 @@ void js_register_pluginx_protocols_ProtocolAds(JSContext *cx, JSObject *global)
};
static JSFunctionSpec funcs[] = {
JS_FN("showAds", js_pluginx_protocols_ProtocolAds_showAds, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("hideAds", js_pluginx_protocols_ProtocolAds_hideAds, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("queryPoints", js_pluginx_protocols_ProtocolAds_queryPoints, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("onAdsResult", js_pluginx_protocols_ProtocolAds_onAdsResult, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("spendPoints", js_pluginx_protocols_ProtocolAds_spendPoints, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("configDeveloperInfo", js_pluginx_protocols_ProtocolAds_configDeveloperInfo, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("onPlayerGetPoints", js_pluginx_protocols_ProtocolAds_onPlayerGetPoints, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("getAdsListener", js_pluginx_protocols_ProtocolAds_getAdsListener, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FS_END
};

View File

@ -63,12 +63,12 @@ JSBool js_pluginx_protocols_ProtocolAds_constructor(JSContext *cx, uint32_t argc
void js_pluginx_protocols_ProtocolAds_finalize(JSContext *cx, JSObject *obj);
void js_register_pluginx_protocols_ProtocolAds(JSContext *cx, JSObject *global);
void register_all_pluginx_protocols(JSContext* cx, JSObject* obj);
JSBool js_pluginx_protocols_ProtocolAds_showAds(JSContext *cx, uint32_t argc, jsval *vp);
JSBool js_pluginx_protocols_ProtocolAds_hideAds(JSContext *cx, uint32_t argc, jsval *vp);
JSBool js_pluginx_protocols_ProtocolAds_queryPoints(JSContext *cx, uint32_t argc, jsval *vp);
JSBool js_pluginx_protocols_ProtocolAds_onAdsResult(JSContext *cx, uint32_t argc, jsval *vp);
JSBool js_pluginx_protocols_ProtocolAds_spendPoints(JSContext *cx, uint32_t argc, jsval *vp);
JSBool js_pluginx_protocols_ProtocolAds_configDeveloperInfo(JSContext *cx, uint32_t argc, jsval *vp);
JSBool js_pluginx_protocols_ProtocolAds_onPlayerGetPoints(JSContext *cx, uint32_t argc, jsval *vp);
JSBool js_pluginx_protocols_ProtocolAds_getAdsListener(JSContext *cx, uint32_t argc, jsval *vp);
extern JSClass *jsb_ProtocolShare_class;
extern JSObject *jsb_ProtocolShare_prototype;

View File

@ -152,9 +152,16 @@ configDeveloperInfo : function () {},
*/
plugin.ProtocolAds = {
/**
* @method showAds
* @param {TAdsInfo}
* @param {cocos2d::plugin::ProtocolAds::AdsPos}
*/
showAds : function () {},
/**
* @method hideAds
* @param {cocos2d::plugin::ProtocolAds::AdsType}
* @param {TAdsInfo}
*/
hideAds : function () {},
@ -163,13 +170,6 @@ hideAds : function () {},
*/
queryPoints : function () {},
/**
* @method onAdsResult
* @param {cocos2d::plugin::AdsResultCode}
* @param {const char*}
*/
onAdsResult : function () {},
/**
* @method spendPoints
* @param {int}
@ -183,10 +183,10 @@ spendPoints : function () {},
configDeveloperInfo : function () {},
/**
* @method onPlayerGetPoints
* @param {int}
* @method getAdsListener
* @return A value converted from C/C++ "cocos2d::plugin::AdsListener*"
*/
onPlayerGetPoints : function () {},
getAdsListener : function () {},
};

View File

@ -16,11 +16,6 @@ plugin.ProtocolAds.AdsResultCode.PointsSpendFailed = 4;
plugin.ProtocolAds.AdsResultCode.NetworkError = 5;
plugin.ProtocolAds.AdsResultCode.UnknownError = 6;
plugin.ProtocolAds.AdsType = {};
plugin.ProtocolAds.AdsType.BannerAd = 0;
plugin.ProtocolAds.AdsType.FullScreenAd = 1;
plugin.ProtocolAds.AdsType.MoreApp = 2;
plugin.ProtocolAds.AdsPos = {};
plugin.ProtocolAds.AdsPos.PosCenter = 0;
plugin.ProtocolAds.AdsPos.PosTop = 1;

View File

@ -206,6 +206,11 @@ JSBool jsval_to_TAdsDeveloperInfo(JSContext *cx, jsval v, TAdsDeveloperInfo* ret
return jsval_to_TProductInfo(cx, v, ret);
}
JSBool jsval_to_TAdsInfo(JSContext *cx, jsval v, TAdsInfo* ret)
{
return jsval_to_TProductInfo(cx, v, ret);
}
JSBool jsval_to_TShareDeveloperInfo(JSContext *cx, jsval v, TShareDeveloperInfo* ret)
{
return jsval_to_TProductInfo(cx, v, ret);

View File

@ -29,6 +29,7 @@ JSBool jsval_to_std_string(JSContext *cx, jsval v, std::string* ret);
JSBool jsval_to_TProductInfo(JSContext *cx, jsval v, TProductInfo* ret);
JSBool jsval_to_TIAPDeveloperInfo(JSContext *cx, jsval v, TIAPDeveloperInfo* ret);
JSBool jsval_to_TAdsDeveloperInfo(JSContext *cx, jsval v, TAdsDeveloperInfo* ret);
JSBool jsval_to_TAdsInfo(JSContext *cx, jsval v, TAdsInfo* ret);
JSBool jsval_to_TShareDeveloperInfo(JSContext *cx, jsval v, TShareDeveloperInfo* ret);
JSBool jsval_to_TShareInfo(JSContext *cx, jsval v, TShareInfo* ret);
JSBool jsval_to_TSocialDeveloperInfo(JSContext *cx, jsval v, TSocialDeveloperInfo* ret);

View File

@ -33,7 +33,6 @@ void register_pluginx_js_extensions(JSContext* cx, JSObject* global)
JS_DefineFunction(cx, jsb_ProtocolIAP_prototype, "setResultListener", js_pluginx_ProtocolIAP_setResultListener, 1, JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(cx, jsb_ProtocolAds_prototype, "setAdsListener", js_pluginx_ProtocolAds_setAdsListener, 1, JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(cx, jsb_ProtocolAds_prototype, "showAds", js_pluginx_ProtocolAds_showAds, 1, JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(cx, jsb_ProtocolShare_prototype, "setResultListener", js_pluginx_ProtocolShare_setResultListener, 1, JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(cx, jsb_ProtocolSocial_prototype, "setListener", js_pluginx_ProtocolSocial_setListener, 1, JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(cx, jsb_ProtocolUser_prototype, "setActionListener", js_pluginx_ProtocolUser_setActionListener, 1, JSPROP_READONLY | JSPROP_PERMANENT);

View File

@ -173,47 +173,6 @@ JSBool js_pluginx_ProtocolAds_setAdsListener(JSContext *cx, uint32_t argc, jsval
return JS_FALSE;
}
JSBool js_pluginx_ProtocolAds_showAds(JSContext *cx, uint32_t argc, jsval *vp)
{
jsval *argv = JS_ARGV(cx, vp);
JSBool ok = JS_TRUE;
JSObject *obj = JS_THIS_OBJECT(cx, vp);
js_proxy_t *proxy = jsb_get_js_proxy(obj);
cocos2d::plugin::ProtocolAds* cobj = (cocos2d::plugin::ProtocolAds *)(proxy ? proxy->ptr : NULL);
JSB_PRECONDITION2( cobj, cx, JS_FALSE, "Invalid Native Object");
if (argc == 1) {
jsval params = argv[0];
JSObject* tmp = JSVAL_TO_OBJECT(params);
JSB_PRECONDITION2(tmp, cx, JS_FALSE, "Error processing arguments");
jsval tempVal;
cocos2d::plugin::ProtocolAds::AdsType arg0;
ok &= JS_GetProperty(cx, tmp, "AdsType", &tempVal);
JSB_PRECONDITION2(ok, cx, JS_FALSE, "It should be contains 'AdsType' in parameter.");
ok &= jsval_to_int32(cx, tempVal, (int32_t *) &arg0);
JSB_PRECONDITION2(ok, cx, JS_FALSE, "Value of 'AdsType' must be int");
int sizeEnum = 0;
if (JS_GetProperty(cx, tmp, "SizeEnum", &tempVal)) {
ok &= jsval_to_int32(cx, tempVal, (int32_t *) &sizeEnum);
JSB_PRECONDITION2(ok, cx, JS_FALSE, "Value of 'SizeEnum' should be int");
}
cocos2d::plugin::ProtocolAds::AdsPos pos;
if (JS_GetProperty(cx, tmp, "AdsPos", &tempVal)) {
ok &= jsval_to_int32(cx, tempVal, (int32_t *) &pos);
JSB_PRECONDITION2(ok, cx, JS_FALSE, "Value of 'AdsPos' should be int");
}
cobj->showAds(arg0, sizeEnum, pos);
JS_SET_RVAL(cx, vp, JSVAL_VOID);
return JS_TRUE;
}
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1);
return JS_FALSE;
}
class Pluginx_ShareResult : public cocos2d::plugin::ShareResultListener
{
public:

View File

@ -6,7 +6,6 @@
JSBool js_pluginx_ProtocolIAP_setResultListener(JSContext *cx, uint32_t argc, jsval *vp);
JSBool js_pluginx_ProtocolAds_setAdsListener(JSContext *cx, uint32_t argc, jsval *vp);
JSBool js_pluginx_ProtocolAds_showAds(JSContext *cx, uint32_t argc, jsval *vp);
JSBool js_pluginx_ProtocolShare_setResultListener(JSContext *cx, uint32_t argc, jsval *vp);
JSBool js_pluginx_ProtocolSocial_setListener(JSContext *cx, uint32_t argc, jsval *vp);
JSBool js_pluginx_ProtocolUser_setActionListener(JSContext *cx, uint32_t argc, jsval *vp);

View File

@ -48,11 +48,14 @@ public class AdsAdmob implements InterfaceAds {
private Set<String> mTestDevices = null;
private WindowManager mWm = null;
private static final int ADMOB_SIZE_BANNER = 0;
private static final int ADMOB_SIZE_IABMRect = 1;
private static final int ADMOB_SIZE_IABBanner = 2;
private static final int ADMOB_SIZE_IABLeaderboard = 3;
private static final int ADMOB_SIZE_Skyscraper = 4;
private static final int ADMOB_SIZE_BANNER = 1;
private static final int ADMOB_SIZE_IABMRect = 2;
private static final int ADMOB_SIZE_IABBanner = 3;
private static final int ADMOB_SIZE_IABLeaderboard = 4;
private static final int ADMOB_SIZE_Skyscraper = 5;
private static final int ADMOB_TYPE_BANNER = 1;
private static final int ADMOB_TYPE_FULLSCREEN = 2;
protected static void LogE(String msg, Exception e) {
Log.e(LOG_TAG, msg, e);
@ -91,20 +94,29 @@ public class AdsAdmob implements InterfaceAds {
}
@Override
public void showAds(int adsType, int sizeEnum, int pos) {
switch (adsType) {
case AdsWrapper.ADS_TYPE_BANNER:
showBannerAd(sizeEnum, pos);
break;
case AdsWrapper.ADS_TYPE_FULL_SCREEN:
LogD("Now not support full screen view in Admob");
break;
case AdsWrapper.ADS_TYPE_MORE_APP:
LogD("Now not support more app ads in Admob");
break;
default:
break;
}
public void showAds(Hashtable<String, String> info, int pos) {
try
{
String strType = info.get("AdmobType");
int adsType = Integer.parseInt(strType);
switch (adsType) {
case ADMOB_TYPE_BANNER:
{
String strSize = info.get("AdmobSizeEnum");
int sizeEnum = Integer.parseInt(strSize);
showBannerAd(sizeEnum, pos);
break;
}
case ADMOB_TYPE_FULLSCREEN:
LogD("Now not support full screen view in Admob");
break;
default:
break;
}
} catch (Exception e) {
LogE("Error when show Ads ( " + info.toString() + " )", e);
}
}
@Override
@ -113,16 +125,25 @@ public class AdsAdmob implements InterfaceAds {
}
@Override
public void hideAds(int adsType) {
switch (adsType) {
case AdsWrapper.ADS_TYPE_BANNER:
hideBannerAd();
break;
case AdsWrapper.ADS_TYPE_FULL_SCREEN:
break;
default:
break;
}
public void hideAds(Hashtable<String, String> info) {
try
{
String strType = info.get("AdmobType");
int adsType = Integer.parseInt(strType);
switch (adsType) {
case ADMOB_TYPE_BANNER:
hideBannerAd();
break;
case ADMOB_TYPE_FULLSCREEN:
LogD("Now not support full screen view in Admob");
break;
default:
break;
}
} catch (Exception e) {
LogE("Error when hide Ads ( " + info.toString() + " )", e);
}
}
private void showBannerAd(int sizeEnum, int pos) {

View File

@ -28,13 +28,18 @@
#import "GADBannerViewDelegate.h"
typedef enum {
kSizeBanner = 0,
kSizeBanner = 1,
kSizeIABMRect,
kSizeIABBanner,
kSizeIABLeaderboard,
kSizeSkyscraper,
} AdmobSizeEnum;
typedef enum {
kTypeBanner = 1,
kTypeFullScreen,
} AdmobType;
@interface AdsAdmob : NSObject <InterfaceAds, GADBannerViewDelegate>
{
}
@ -48,8 +53,8 @@ typedef enum {
interfaces from InterfaceAds
*/
- (void) configDeveloperInfo: (NSMutableDictionary*) devInfo;
- (void) showAds: (int) type size:(int) sizeEnum position:(int) pos;
- (void) hideAds: (int) type;
- (void) showAds: (NSMutableDictionary*) info position:(int) pos;
- (void) hideAds: (NSMutableDictionary*) info;
- (void) queryPoints;
- (void) spendPoints: (int) points;
- (void) setDebugMode: (BOOL) isDebugMode;

View File

@ -54,7 +54,7 @@
self.strPublishID = (NSString*) [devInfo objectForKey:@"AdmobID"];
}
- (void) showAds: (int) type size:(int) sizeEnum position:(int) pos
- (void) showAds: (NSMutableDictionary*) info position:(int) pos
{
if (self.strPublishID == nil ||
[self.strPublishID length] == 0) {
@ -62,31 +62,45 @@
return;
}
NSString* strType = [info objectForKey:@"AdmobType"];
int type = [strType intValue];
switch (type) {
case kTypeBanner:
[self showBanner:sizeEnum atPos:pos];
break;
{
NSString* strSize = [info objectForKey:@"AdmobSizeEnum"];
int sizeEnum = [strSize intValue];
[self showBanner:sizeEnum atPos:pos];
break;
}
case kTypeFullScreen:
OUTPUT_LOG(@"Now not support full screen view in Admob");
break;
case kTypeMoreApp:
OUTPUT_LOG(@"Now not support more app ads in Admob");
break;
default:
OUTPUT_LOG(@"The value of 'AdmobType' is wrong (should be 1 or 2)");
break;
}
}
- (void) hideAds: (int) type
- (void) hideAds: (NSMutableDictionary*) info
{
if (type == kTypeBanner) {
if (nil != self.bannerView) {
[self.bannerView removeFromSuperview];
[self.bannerView release];
self.bannerView = nil;
NSString* strType = [info objectForKey:@"AdmobType"];
int type = [strType intValue];
switch (type) {
case kTypeBanner:
{
if (nil != self.bannerView) {
[self.bannerView removeFromSuperview];
[self.bannerView release];
self.bannerView = nil;
}
break;
}
} else {
case kTypeFullScreen:
OUTPUT_LOG(@"Now not support full screen view in Admob");
break;
default:
OUTPUT_LOG(@"The value of 'AdmobType' is wrong (should be 1 or 2)");
break;
}
}
@ -117,7 +131,7 @@
- (void) showBanner: (int) sizeEnum atPos:(int) pos
{
GADAdSize size;
GADAdSize size = kGADAdSizeBanner;
switch (sizeEnum) {
case kSizeBanner:
size = kGADAdSizeBanner;

View File

@ -31,6 +31,7 @@ THE SOFTWARE.
namespace cocos2d { namespace plugin {
typedef std::map<std::string, std::string> TAdsDeveloperInfo;
typedef std::map<std::string, std::string> TAdsInfo;
typedef enum
{
@ -69,12 +70,6 @@ public:
ProtocolAds();
virtual ~ProtocolAds();
typedef enum {
kBannerAd = 0,
kFullScreenAd,
kMoreApp,
} AdsType;
typedef enum {
kPosCenter = 0,
kPosTop,
@ -96,21 +91,17 @@ public:
/**
@brief show adview
@param type The adview type need to show.
@param sizeEnum The size of the banner view.
(only used when type is kBannerAd)
In different plugin, it's have different mean.
@param info The information of adview will be shown
Pay attention to the subclass definition
@param pos The position where the adview be shown.
(only used when type is kBannerAd)
*/
void showAds(AdsType type, int sizeEnum = 0, AdsPos pos = kPosCenter);
void showAds(TAdsInfo info, AdsPos pos = kPosCenter);
/**
@brief Hide the adview
@param type The adview type need to hide.
@param info The information of adview will be hided
*/
void hideAds(AdsType type);
void hideAds(TAdsInfo info);
/**
@brief Query the points of player
@ -127,11 +118,15 @@ public:
/**
@brief set the Ads listener
*/
void setAdsListener(AdsListener* pListener);
inline void setAdsListener(AdsListener* listener)
{
_listener = listener;
}
// For the callbak methods
void onAdsResult(AdsResultCode code, const char* msg);
void onPlayerGetPoints(int points);
inline AdsListener* getAdsListener()
{
return _listener;
}
protected:
AdsListener* _listener;

View File

@ -37,7 +37,7 @@ classes = PluginProtocol PluginManager ProtocolIAP ProtocolAnalytics ProtocolAds
# functions from all classes.
skip = ProtocolIAP::[setResultListener],
ProtocolAds::[setAdsListener showAds],
ProtocolAds::[setAdsListener],
ProtocolShare::[setResultListener],
ProtocolSocial::[setListener getListener],
ProtocolUser::[setActionListener getActionListener],

View File

@ -41,7 +41,11 @@ extern "C" {
ProtocolAds* pAds = dynamic_cast<ProtocolAds*>(pPlugin);
if (pAds != NULL)
{
pAds->onAdsResult((AdsResultCode) ret, strMsg.c_str());
AdsListener* listener = pAds->getAdsListener();
if (listener)
{
listener->onAdsResult((AdsResultCode) ret, strMsg.c_str());
}
}
}
}
@ -56,7 +60,11 @@ extern "C" {
ProtocolAds* pAds = dynamic_cast<ProtocolAds*>(pPlugin);
if (pAds != NULL)
{
pAds->onPlayerGetPoints(points);
AdsListener* listener = pAds->getAdsListener();
if (listener)
{
listener->onPlayerGetPoints(pAds, points);
}
}
}
}
@ -98,7 +106,7 @@ void ProtocolAds::configDeveloperInfo(TAdsDeveloperInfo devInfo)
}
}
void ProtocolAds::showAds(AdsType type, int sizeEnum, AdsPos pos)
void ProtocolAds::showAds(TAdsInfo info, AdsPos pos)
{
PluginJavaData* pData = PluginUtils::getPluginJavaData(this);
PluginJniMethodInfo t;
@ -107,16 +115,31 @@ void ProtocolAds::showAds(AdsType type, int sizeEnum, AdsPos pos)
if (PluginJniHelper::getMethodInfo(t
, pData->jclassName.c_str()
, "showAds"
, "(III)V"))
, "(Ljava/util/Hashtable;I)V"))
{
t.env->CallVoidMethod(pData->jobj, t.methodID, type, sizeEnum, pos);
jobject obj_Map = PluginUtils::createJavaMapObject(&info);
t.env->CallVoidMethod(pData->jobj, t.methodID, obj_Map, pos);
t.env->DeleteLocalRef(obj_Map);
t.env->DeleteLocalRef(t.classID);
}
}
void ProtocolAds::hideAds(AdsType type)
void ProtocolAds::hideAds(TAdsInfo info)
{
PluginUtils::callJavaFunctionWithName_oneParam(this, "hideAds", "(I)V", type);
PluginJavaData* pData = PluginUtils::getPluginJavaData(this);
PluginJniMethodInfo t;
PluginUtils::outputLog("ProtocolAds", "Class name : %s", pData->jclassName.c_str());
if (PluginJniHelper::getMethodInfo(t
, pData->jclassName.c_str()
, "hideAds"
, "(Ljava/util/Hashtable;)V"))
{
jobject obj_Map = PluginUtils::createJavaMapObject(&info);
t.env->CallVoidMethod(pData->jobj, t.methodID, obj_Map);
t.env->DeleteLocalRef(obj_Map);
t.env->DeleteLocalRef(t.classID);
}
}
void ProtocolAds::queryPoints()
@ -129,27 +152,4 @@ void ProtocolAds::spendPoints(int points)
PluginUtils::callJavaFunctionWithName_oneParam(this, "spendPoints", "(I)V", points);
}
void ProtocolAds::setAdsListener(AdsListener* pListener)
{
_listener = pListener;
}
void ProtocolAds::onAdsResult(AdsResultCode code, const char* msg)
{
PluginUtils::outputLog("ProtocolAds", "ProtocolAds::adsResult invoked!");
if (_listener != NULL)
{
_listener->onAdsResult(code, msg);
}
}
void ProtocolAds::onPlayerGetPoints(int points)
{
PluginUtils::outputLog("ProtocolAds", "ProtocolAds::onPlayerGetPoints invoked!");
if (_listener != NULL)
{
_listener->onPlayerGetPoints(this, points);
}
}
}} // namespace cocos2d { namespace plugin {

View File

@ -38,12 +38,6 @@ typedef enum {
kUnknownError,
} AdsResult;
typedef enum {
kTypeBanner = 0,
kTypeFullScreen,
kTypeMoreApp,
} AdsTypeEnum;
typedef enum {
kPosCenter = 0,
kPosTop,
@ -60,6 +54,7 @@ typedef enum {
}
+ (void) onAdsResult:(id) obj withRet:(AdsResult) ret withMsg:(NSString*) msg;
+ (void) onPlayerGetPoints:(id) obj withPoints: (int) points;
+ (void) addAdView:(UIView*) view atPos:(AdsPosEnum) pos;
+ (UIViewController *) getCurrentRootViewController;

View File

@ -32,12 +32,31 @@ using namespace cocos2d::plugin;
+ (void) onAdsResult:(id) obj withRet:(AdsResult) ret withMsg:(NSString*) msg
{
PluginProtocol* pPlugin = PluginUtilsIOS::getPluginPtr(obj);
ProtocolAds* pAds = dynamic_cast<ProtocolAds*>(pPlugin);
if (pAds) {
PluginProtocol* plugin = PluginUtilsIOS::getPluginPtr(obj);
ProtocolAds* adsPlugin = dynamic_cast<ProtocolAds*>(plugin);
if (adsPlugin) {
const char* chMsg = [msg UTF8String];
AdsResultCode cRet = (AdsResultCode) ret;
pAds->onAdsResult(cRet, chMsg);
AdsListener* listener = adsPlugin->getAdsListener();
if (listener)
{
listener->onAdsResult(cRet, chMsg);
}
} else {
PluginUtilsIOS::outputLog("Can't find the C++ object of the ads plugin");
}
}
+ (void) onPlayerGetPoints:(id) obj withPoints: (int) points
{
PluginProtocol* plugin = PluginUtilsIOS::getPluginPtr(obj);
ProtocolAds* adsPlugin = dynamic_cast<ProtocolAds*>(plugin);
if (adsPlugin) {
AdsListener* listener = adsPlugin->getAdsListener();
if (listener)
{
listener->onPlayerGetPoints(adsPlugin, points);
}
} else {
PluginUtilsIOS::outputLog("Can't find the C++ object of the ads plugin");
}

View File

@ -27,8 +27,8 @@ THE SOFTWARE.
@protocol InterfaceAds <NSObject>
- (void) configDeveloperInfo: (NSMutableDictionary*) devInfo;
- (void) showAds: (int) type size:(int) sizeEnum position:(int) pos;
- (void) hideAds: (int) type;
- (void) showAds: (NSMutableDictionary*) info position:(int) pos;
- (void) hideAds: (NSMutableDictionary*) info;
- (void) queryPoints;
- (void) spendPoints: (int) points;
- (void) setDebugMode: (BOOL) debug;

View File

@ -52,13 +52,13 @@ void ProtocolAds::configDeveloperInfo(TAdsDeveloperInfo devInfo)
id ocObj = pData->obj;
if ([ocObj conformsToProtocol:@protocol(InterfaceAds)]) {
NSObject<InterfaceAds>* curObj = ocObj;
NSMutableDictionary* pDict = PluginUtilsIOS::createDictFromMap(&devInfo);
[curObj configDeveloperInfo:pDict];
NSMutableDictionary* dict = PluginUtilsIOS::createDictFromMap(&devInfo);
[curObj configDeveloperInfo:dict];
}
}
}
void ProtocolAds::showAds(AdsType type, int sizeEnum, AdsPos pos)
void ProtocolAds::showAds(TAdsInfo info, AdsPos pos)
{
PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this);
assert(pData != NULL);
@ -66,11 +66,12 @@ void ProtocolAds::showAds(AdsType type, int sizeEnum, AdsPos pos)
id ocObj = pData->obj;
if ([ocObj conformsToProtocol:@protocol(InterfaceAds)]) {
NSObject<InterfaceAds>* curObj = ocObj;
[curObj showAds:type size:sizeEnum position:pos];
NSMutableDictionary* dict = PluginUtilsIOS::createDictFromMap(&info);
[curObj showAds:dict position:pos];
}
}
void ProtocolAds::hideAds(AdsType type)
void ProtocolAds::hideAds(TAdsInfo info)
{
PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this);
assert(pData != NULL);
@ -78,10 +79,16 @@ void ProtocolAds::hideAds(AdsType type)
id ocObj = pData->obj;
if ([ocObj conformsToProtocol:@protocol(InterfaceAds)]) {
NSObject<InterfaceAds>* curObj = ocObj;
[curObj hideAds:type];
NSMutableDictionary* dict = PluginUtilsIOS::createDictFromMap(&info);
[curObj hideAds:dict];
}
}
void ProtocolAds::queryPoints()
{
PluginUtilsIOS::callOCFunctionWithName(this, "queryPoints");
}
void ProtocolAds::spendPoints(int points)
{
PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this);
@ -94,26 +101,4 @@ void ProtocolAds::spendPoints(int points)
}
}
// For the callbak methods
void ProtocolAds::setAdsListener(AdsListener* pListener)
{
_listener = pListener;
}
void ProtocolAds::onAdsResult(AdsResultCode code, const char* msg)
{
if (_listener != NULL)
{
_listener->onAdsResult(code, msg);
}
}
void ProtocolAds::onPlayerGetPoints(int points)
{
if (_listener != NULL)
{
_listener->onPlayerGetPoints(this, points);
}
}
}} //namespace cocos2d { namespace plugin {

View File

@ -37,10 +37,6 @@ public class AdsWrapper {
public static final int RESULT_CODE_NetworkError = 5; // Network error
public static final int RESULT_CODE_UnknownError = 6; // Unknown error
public static final int ADS_TYPE_BANNER = 0;
public static final int ADS_TYPE_FULL_SCREEN = 1;
public static final int ADS_TYPE_MORE_APP = 2;
public static final int POS_CENTER = 0;
public static final int POS_TOP = 1;
public static final int POS_TOP_LEFT = 2;

View File

@ -30,8 +30,8 @@ public interface InterfaceAds {
public final int PluginType = 1;
public void configDeveloperInfo(Hashtable<String, String> devInfo);
public void showAds(int type, int sizeEnum, int pos);
public void hideAds(int type);
public void showAds(Hashtable<String, String> adsInfo, int pos);
public void hideAds(Hashtable<String, String> adsInfo);
public void queryPoints();
public void spendPoints(int points);
public void setDebugMode(boolean debug);

View File

@ -32,12 +32,6 @@ const std::string s_aTestCases[] = {
"Admob",
};
const std::string s_aTestTypes[] = {
"Banner",
"Full Screen",
"More App",
};
const std::string s_aTestPoses[] = {
"Pos: Center",
"Pos: Top",
@ -130,18 +124,6 @@ bool TestAds::init()
_caseItem->setPosition(posMid + Point(-200, 120));
pMenu->addChild(_caseItem);
// type item
_typeItem = MenuItemToggle::createWithCallback(CC_CALLBACK_1(TestAds::typeChanged, this),
MenuItemFont::create( s_aTestTypes[0].c_str() ),
NULL );
int typeLen = sizeof(s_aTestTypes) / sizeof(std::string);
for (int i = 1; i < typeLen; ++i)
{
_typeItem->getSubItems()->addObject( MenuItemFont::create( s_aTestTypes[i].c_str() ) );
}
_typeItem->setPosition(posMid + Point(0, 120));
pMenu->addChild(_typeItem);
// poses item
_posItem = MenuItemToggle::createWithCallback(CC_CALLBACK_1(TestAds::posChanged, this),
MenuItemFont::create( s_aTestPoses[0].c_str() ),
@ -157,7 +139,10 @@ bool TestAds::init()
// init options
_ads = _admob;
_pos = ProtocolAds::kPosCenter;
_type = ProtocolAds::kBannerAd;
// init the AdsInfo
adInfo["AdmobType"] = "1";
adInfo["AdmobSizeEnum"] = "1";
this->addChild(pMenu, 1);
@ -166,30 +151,22 @@ bool TestAds::init()
void TestAds::testShow(Object* pSender)
{
int nSize = 0;
if (_ads == _admob)
{
nSize = 0;
}
if (_ads)
{
_ads->showAds(_type, nSize, _pos);
_ads->showAds(adInfo, _pos);
}
}
void TestAds::testHide(Object* pSender)
{
_ads->hideAds(_type);
_ads->hideAds(adInfo);
}
void TestAds::menuBackCallback(Object* pSender)
{
if (_admob != NULL)
{
_admob->hideAds(ProtocolAds::kBannerAd);
_admob->hideAds(ProtocolAds::kFullScreenAd);
_admob->hideAds(ProtocolAds::kMoreApp);
_admob->hideAds(adInfo);
PluginManager::getInstance()->unloadPlugin("AdsAdmob");
_admob = NULL;
}
@ -219,13 +196,6 @@ void TestAds::caseChanged(Object* pSender)
log("case selected change to : %s", strLog.c_str());
}
void TestAds::typeChanged(Object* pSender)
{
int selectIndex = _typeItem->getSelectedIndex();
_type = (ProtocolAds::AdsType) selectIndex;
log("type selected change to : %d", _type);
}
void TestAds::posChanged(Object* pSender)
{
int selectIndex = _posItem->getSelectedIndex();

View File

@ -61,12 +61,12 @@ private:
MyAdsListener* _listener;
cocos2d::MenuItemToggle* _caseItem;
cocos2d::MenuItemToggle* _typeItem;
cocos2d::MenuItemToggle* _posItem;
cocos2d::plugin::ProtocolAds* _ads;
cocos2d::plugin::ProtocolAds::AdsPos _pos;
cocos2d::plugin::ProtocolAds::AdsType _type;
cocos2d::plugin::TAdsInfo adInfo;
};
#endif // __TEST_ADS_SCENE_H__

View File

@ -130,10 +130,10 @@ void TestIAPOnline::eventMenuCallback(Object* pSender)
pInfo["Nd91ProductId"] = "685994";
if (mode == MyIAPOLManager::eQH360) {
CCLog("To test the IAP online in plugin qh360, you should do this:");
CCLog("1. Login by UserQH360");
CCLog("2. Get QH360 user info by your game server (userID, AccessToken)");
CCLog("3. Fill the product info");
log("To test the IAP online in plugin qh360, you should do this:");
log("1. Login by UserQH360");
log("2. Get QH360 user info by your game server (userID, AccessToken)");
log("3. Fill the product info");
/**
* @warning ProductInfo you need filled