diff --git a/frameworks/js-bindings/bindings/auto/api/jsb_cocos2dx_auto_api.js b/frameworks/js-bindings/bindings/auto/api/jsb_cocos2dx_auto_api.js index 21c7361702..411d0ce396 100644 --- a/frameworks/js-bindings/bindings/auto/api/jsb_cocos2dx_auto_api.js +++ b/frameworks/js-bindings/bindings/auto/api/jsb_cocos2dx_auto_api.js @@ -3581,13 +3581,13 @@ getMouseButton : function ( }, /** - * @method getScrollY - * @return {float} + * @method setMouseButton + * @param {int} arg0 */ -getScrollY : function ( +setMouseButton : function ( +int ) { - return 0; }, /** @@ -3613,13 +3613,23 @@ getCursorY : function ( }, /** - * @method setMouseButton - * @param {int} arg0 + * @method getCursorX + * @return {float} */ -setMouseButton : function ( -int +getCursorX : function ( +) +{ + return 0; +}, + +/** + * @method getScrollY + * @return {float} + */ +getScrollY : function ( ) { + return 0; }, /** @@ -3644,16 +3654,6 @@ getScrollX : function ( return 0; }, -/** - * @method getCursorX - * @return {float} - */ -getCursorX : function ( -) -{ - return 0; -}, - /** * @method EventMouse * @constructor @@ -3672,16 +3672,6 @@ mouseeventtype */ cc.EventListenerMouse = { -/** - * @method create - * @return {cc.EventListenerMouse} - */ -create : function ( -) -{ - return cc.EventListenerMouse; -}, - }; /** diff --git a/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_auto.cpp b/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_auto.cpp index 717cd86c03..d8cdaf7d70 100644 --- a/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_auto.cpp +++ b/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_auto.cpp @@ -8956,21 +8956,24 @@ bool js_cocos2dx_EventMouse_getMouseButton(JSContext *cx, uint32_t argc, jsval * JS_ReportError(cx, "js_cocos2dx_EventMouse_getMouseButton : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_EventMouse_getScrollY(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_EventMouse_setMouseButton(JSContext *cx, uint32_t argc, jsval *vp) { + jsval *argv = JS_ARGV(cx, vp); + bool ok = true; JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EventMouse* cobj = (cocos2d::EventMouse *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventMouse_getScrollY : Invalid Native Object"); - if (argc == 0) { - double ret = cobj->getScrollY(); - jsval jsret = JSVAL_NULL; - jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventMouse_setMouseButton : Invalid Native Object"); + if (argc == 1) { + int arg0; + ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EventMouse_setMouseButton : Error processing arguments"); + cobj->setMouseButton(arg0); + JS_SET_RVAL(cx, vp, JSVAL_VOID); return true; } - JS_ReportError(cx, "js_cocos2dx_EventMouse_getScrollY : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_EventMouse_setMouseButton : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } bool js_cocos2dx_EventMouse_setScrollData(JSContext *cx, uint32_t argc, jsval *vp) @@ -9012,24 +9015,38 @@ bool js_cocos2dx_EventMouse_getCursorY(JSContext *cx, uint32_t argc, jsval *vp) JS_ReportError(cx, "js_cocos2dx_EventMouse_getCursorY : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_EventMouse_setMouseButton(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_EventMouse_getCursorX(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EventMouse* cobj = (cocos2d::EventMouse *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventMouse_setMouseButton : Invalid Native Object"); - if (argc == 1) { - int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EventMouse_setMouseButton : Error processing arguments"); - cobj->setMouseButton(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventMouse_getCursorX : Invalid Native Object"); + if (argc == 0) { + double ret = cobj->getCursorX(); + jsval jsret = JSVAL_NULL; + jsret = DOUBLE_TO_JSVAL(ret); + JS_SET_RVAL(cx, vp, jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_EventMouse_setMouseButton : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_EventMouse_getCursorX : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_EventMouse_getScrollY(JSContext *cx, uint32_t argc, jsval *vp) +{ + JSObject *obj = JS_THIS_OBJECT(cx, vp); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::EventMouse* cobj = (cocos2d::EventMouse *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventMouse_getScrollY : Invalid Native Object"); + if (argc == 0) { + double ret = cobj->getScrollY(); + jsval jsret = JSVAL_NULL; + jsret = DOUBLE_TO_JSVAL(ret); + JS_SET_RVAL(cx, vp, jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_EventMouse_getScrollY : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } bool js_cocos2dx_EventMouse_setCursorPosition(JSContext *cx, uint32_t argc, jsval *vp) @@ -9071,23 +9088,6 @@ bool js_cocos2dx_EventMouse_getScrollX(JSContext *cx, uint32_t argc, jsval *vp) JS_ReportError(cx, "js_cocos2dx_EventMouse_getScrollX : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_EventMouse_getCursorX(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::EventMouse* cobj = (cocos2d::EventMouse *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventMouse_getCursorX : Invalid Native Object"); - if (argc == 0) { - double ret = cobj->getCursorX(); - jsval jsret = JSVAL_NULL; - jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_EventMouse_getCursorX : wrong number of arguments: %d, was expecting %d", argc, 0); - return false; -} bool js_cocos2dx_EventMouse_constructor(JSContext *cx, uint32_t argc, jsval *vp) { jsval *argv = JS_ARGV(cx, vp); @@ -9143,14 +9143,14 @@ void js_register_cocos2dx_EventMouse(JSContext *cx, JSObject *global) { }; static JSFunctionSpec funcs[] = { - JS_FN("getMouseButton", js_cocos2dx_EventMouse_getMouseButton, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getScrollY", js_cocos2dx_EventMouse_getScrollY, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getButton", js_cocos2dx_EventMouse_getMouseButton, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setButton", js_cocos2dx_EventMouse_setMouseButton, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setScrollData", js_cocos2dx_EventMouse_setScrollData, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getLocationY", js_cocos2dx_EventMouse_getCursorY, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setMouseButton", js_cocos2dx_EventMouse_setMouseButton, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getLocationX", js_cocos2dx_EventMouse_getCursorX, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getScrollY", js_cocos2dx_EventMouse_getScrollY, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setLocation", js_cocos2dx_EventMouse_setCursorPosition, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getScrollX", js_cocos2dx_EventMouse_getScrollX, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getLocationX", js_cocos2dx_EventMouse_getCursorX, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; @@ -9187,26 +9187,6 @@ void js_register_cocos2dx_EventMouse(JSContext *cx, JSObject *global) { JSClass *jsb_cocos2d_EventListenerMouse_class; JSObject *jsb_cocos2d_EventListenerMouse_prototype; -bool js_cocos2dx_EventListenerMouse_create(JSContext *cx, uint32_t argc, jsval *vp) -{ - if (argc == 0) { - cocos2d::EventListenerMouse* ret = cocos2d::EventListenerMouse::create(); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::EventListenerMouse*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - JS_ReportError(cx, "js_cocos2dx_EventListenerMouse_create : wrong number of arguments"); - return false; -} - extern JSObject *jsb_cocos2d_EventListener_prototype; @@ -9236,10 +9216,7 @@ void js_register_cocos2dx_EventListenerMouse(JSContext *cx, JSObject *global) { JS_FS_END }; - static JSFunctionSpec st_funcs[] = { - JS_FN("create", js_cocos2dx_EventListenerMouse_create, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FS_END - }; + JSFunctionSpec *st_funcs = NULL; jsb_cocos2d_EventListenerMouse_prototype = JS_InitClass( cx, global, diff --git a/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_auto.hpp b/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_auto.hpp index 6dda24937d..08179999da 100644 --- a/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_auto.hpp +++ b/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_auto.hpp @@ -487,13 +487,13 @@ void js_cocos2dx_EventMouse_finalize(JSContext *cx, JSObject *obj); void js_register_cocos2dx_EventMouse(JSContext *cx, JSObject *global); void register_all_cocos2dx(JSContext* cx, JSObject* obj); bool js_cocos2dx_EventMouse_getMouseButton(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_EventMouse_getScrollY(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_EventMouse_setMouseButton(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EventMouse_setScrollData(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EventMouse_getCursorY(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_EventMouse_setMouseButton(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_EventMouse_getCursorX(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_EventMouse_getScrollY(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EventMouse_setCursorPosition(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EventMouse_getScrollX(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_EventMouse_getCursorX(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EventMouse_EventMouse(JSContext *cx, uint32_t argc, jsval *vp); extern JSClass *jsb_cocos2d_EventListenerMouse_class; @@ -503,7 +503,6 @@ bool js_cocos2dx_EventListenerMouse_constructor(JSContext *cx, uint32_t argc, js void js_cocos2dx_EventListenerMouse_finalize(JSContext *cx, JSObject *obj); void js_register_cocos2dx_EventListenerMouse(JSContext *cx, JSObject *global); void register_all_cocos2dx(JSContext* cx, JSObject* obj); -bool js_cocos2dx_EventListenerMouse_create(JSContext *cx, uint32_t argc, jsval *vp); extern JSClass *jsb_cocos2d_EventAcceleration_class; extern JSObject *jsb_cocos2d_EventAcceleration_prototype; diff --git a/frameworks/js-bindings/bindings/manual/ScriptingCore.cpp b/frameworks/js-bindings/bindings/manual/ScriptingCore.cpp index 9d73acf538..cd1110f610 100644 --- a/frameworks/js-bindings/bindings/manual/ScriptingCore.cpp +++ b/frameworks/js-bindings/bindings/manual/ScriptingCore.cpp @@ -185,6 +185,29 @@ static std::string getTouchFuncName(EventTouch::EventCode eventCode) return funcName; } +static std::string getMouseFuncName(EventMouse::MouseEventType eventType) +{ + std::string funcName; + switch(eventType) { + case EventMouse::MouseEventType::MOUSE_DOWN: + funcName = "onMouseDown"; + break; + case EventMouse::MouseEventType::MOUSE_UP: + funcName = "onMouseUp"; + break; + case EventMouse::MouseEventType::MOUSE_MOVE: + funcName = "onMouseMove"; + break; + case EventMouse::MouseEventType::MOUSE_SCROLL: + funcName = "onMouseScroll"; + break; + default: + CCASSERT(false, "Invalid event code!"); + } + + return funcName; +} + static void rootObject(JSContext *cx, JSObject *obj) { JS_AddNamedObjectRoot(cx, &obj, "unnamed"); } @@ -1092,6 +1115,49 @@ bool ScriptingCore::handleTouchEvent(void* nativeObj, cocos2d::EventTouch::Event return ret; } +bool ScriptingCore::handleMouseEvent(void* nativeObj, cocos2d::EventMouse::MouseEventType eventType, cocos2d::Event* event, jsval* jsvalRet/* = nullptr*/) +{ + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET + + std::string funcName = getMouseFuncName(eventType); + bool ret = false; + + do + { + js_proxy_t * p = jsb_get_native_proxy(nativeObj); + if (!p) break; + + jsval dataVal[1]; + dataVal[0] = getJSObject(_cx, event); + + if (jsvalRet != nullptr) + { + ret = executeFunctionWithOwner(OBJECT_TO_JSVAL(p->obj), funcName.c_str(), 1, dataVal, jsvalRet); + } + else + { + jsval retval; + executeFunctionWithOwner(OBJECT_TO_JSVAL(p->obj), funcName.c_str(), 1, dataVal, &retval); + if(JSVAL_IS_NULL(retval)) + { + ret = false; + } + else if(JSVAL_IS_BOOLEAN(retval)) + { + ret = JSVAL_TO_BOOLEAN(retval); + } + else + { + ret = false; + } + } + } while(false); + + removeJSObject(_cx, event); + + return ret; +} + bool ScriptingCore::executeFunctionWithObjectData(void* nativeObj, const char *name, JSObject *obj) { js_proxy_t * p = jsb_get_native_proxy(nativeObj); @@ -1497,7 +1563,7 @@ static void serverEntryPoint(void) char buf[1024] = {0}; int readBytes = 0; - while ((readBytes = ::recv(clientSocket, buf, sizeof(buf), 0)) > 0) + while ((readBytes = (int)::recv(clientSocket, buf, sizeof(buf), 0)) > 0) { buf[readBytes] = '\0'; // TRACE_DEBUGGER_SERVER("debug server : received command >%s", buf); diff --git a/frameworks/js-bindings/bindings/manual/ScriptingCore.h b/frameworks/js-bindings/bindings/manual/ScriptingCore.h index 951c4c95d9..d64b2fca10 100644 --- a/frameworks/js-bindings/bindings/manual/ScriptingCore.h +++ b/frameworks/js-bindings/bindings/manual/ScriptingCore.h @@ -245,6 +245,7 @@ class ScriptingCore : public cocos2d::ScriptEngineProtocol bool handleTouchesEvent(void* nativeObj, cocos2d::EventTouch::EventCode eventCode, const std::vector& touches, cocos2d::Event* event, jsval* jsvalRet = nullptr); bool handleTouchEvent(void* nativeObj, cocos2d::EventTouch::EventCode eventCode, cocos2d::Touch* touch, cocos2d::Event* event, jsval* jsvalRet = nullptr); + bool handleMouseEvent(void* nativeObj, cocos2d::EventMouse::MouseEventType eventType, cocos2d::Event* event, jsval* jsvalRet = nullptr); bool handleKeybardEvent(void* nativeObj, cocos2d::EventKeyboard::KeyCode keyCode, bool isPressed, cocos2d::Event* event); }; diff --git a/frameworks/js-bindings/bindings/manual/cocos2d_specifics.cpp b/frameworks/js-bindings/bindings/manual/cocos2d_specifics.cpp index 10c0785cd4..ad099dcae6 100644 --- a/frameworks/js-bindings/bindings/manual/cocos2d_specifics.cpp +++ b/frameworks/js-bindings/bindings/manual/cocos2d_specifics.cpp @@ -4232,6 +4232,9 @@ void register_cocos2dx_js_extensions(JSContext* cx, JSObject* global) tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return cc.EventListenerTouchAllAtOnce; })()")); JS_DefineFunction(cx, tmpObj, "create", js_EventListenerTouchAllAtOnce_create, 0, JSPROP_READONLY | JSPROP_PERMANENT); + tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return cc.EventListenerMouse; })()")); + JS_DefineFunction(cx, tmpObj, "create", js_EventListenerMouse_create, 0, JSPROP_READONLY | JSPROP_PERMANENT); + tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return cc.EventListenerKeyboard; })()")); JS_DefineFunction(cx, tmpObj, "create", js_EventListenerKeyboard_create, 0, JSPROP_READONLY | JSPROP_PERMANENT); diff --git a/frameworks/js-bindings/bindings/manual/jsb_event_dispatcher_manual.cpp b/frameworks/js-bindings/bindings/manual/jsb_event_dispatcher_manual.cpp index 36e05a39c7..f82dc9a418 100644 --- a/frameworks/js-bindings/bindings/manual/jsb_event_dispatcher_manual.cpp +++ b/frameworks/js-bindings/bindings/manual/jsb_event_dispatcher_manual.cpp @@ -95,6 +95,36 @@ bool js_EventListenerTouchAllAtOnce_create(JSContext *cx, uint32_t argc, jsval * return false; } +bool js_EventListenerMouse_create(JSContext *cx, uint32_t argc, jsval *vp) +{ + if (argc == 0) { + auto ret = EventListenerMouse::create(); + + ret->onMouseDown = [ret](Event* event) { + ScriptingCore::getInstance()->handleMouseEvent(ret, EventMouse::MouseEventType::MOUSE_DOWN, event); + }; + + ret->onMouseUp = [ret](Event* event) { + ScriptingCore::getInstance()->handleMouseEvent(ret, EventMouse::MouseEventType::MOUSE_UP, event); + }; + + ret->onMouseMove = [ret](Event* event) { + ScriptingCore::getInstance()->handleMouseEvent(ret, EventMouse::MouseEventType::MOUSE_MOVE, event); + }; + + ret->onMouseScroll = [ret](Event* event) { + ScriptingCore::getInstance()->handleMouseEvent(ret, EventMouse::MouseEventType::MOUSE_SCROLL, event); + }; + + jsval jsret = getJSObject(cx, ret); + JS_SET_RVAL(cx, vp, jsret); + return true; + } + + JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} + bool js_EventListenerKeyboard_create(JSContext *cx, uint32_t argc, jsval *vp) { if (argc == 0) { diff --git a/frameworks/js-bindings/bindings/manual/jsb_event_dispatcher_manual.h b/frameworks/js-bindings/bindings/manual/jsb_event_dispatcher_manual.h index cf10ed4b18..095a96f1b4 100644 --- a/frameworks/js-bindings/bindings/manual/jsb_event_dispatcher_manual.h +++ b/frameworks/js-bindings/bindings/manual/jsb_event_dispatcher_manual.h @@ -29,5 +29,6 @@ bool js_EventListenerTouchOneByOne_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_EventListenerTouchAllAtOnce_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_EventListenerKeyboard_create(JSContext *cx, uint32_t argc, jsval *vp); +bool js_EventListenerMouse_create(JSContext *cx, uint32_t argc, jsval *vp); #endif /* defined(__cocos2d_js_bindings__jsb_event_dispatcher__) */ diff --git a/frameworks/js-bindings/bindings/script/jsb_boot.js b/frameworks/js-bindings/bindings/script/jsb_boot.js index 3bc334af13..fdc5d52dff 100644 --- a/frameworks/js-bindings/bindings/script/jsb_boot.js +++ b/frameworks/js-bindings/bindings/script/jsb_boot.js @@ -978,7 +978,38 @@ cc._initSys = function(config, CONFIG_KEY){ * @type Boolean */ locSys.isNative = true; - locSys.isMobile = __getPlatform() == "mobile"; + + /** Get the os of system */ + locSys.os = __getOS(); + + // Forces the garbage collector + locSys.garbageCollect = function() { + __jsc__.garbageCollect(); + }; + + // Dumps rooted objects + locSys.dumpRoot = function() { + __jsc__.dumpRoot(); + }; + + // restarts the JS VM + locSys.restartVM = function() { + __restartVM(); + }; + + locSys.dump = function(){ + var self = this; + var str = ""; + str += "isMobile : " + self.isMobile + "\r\n"; + str += "language : " + self.language + "\r\n"; + str += "browserType : " + self.browserType + "\r\n"; + str += "capabilities : " + JSON.stringify(self.capabilities) + "\r\n"; + str += "os : " + self.os + "\r\n"; + cc.log(str); + } + + locSys.isMobile = (locSys.os == locSys.OS_ANDROID || locSys.os == locSys.OS_IOS) ? true : false; + locSys.language = (function(){ var language = cc.Application.getInstance().getCurrentLanguage(); switch(language){ @@ -1012,35 +1043,6 @@ cc._initSys = function(config, CONFIG_KEY){ capabilities["keyboard"] = true; capabilities["mouse"] = true; } - - /** Get the os of system */ - locSys.os = __getOS(); - - // Forces the garbage collector - locSys.garbageCollect = function() { - __jsc__.garbageCollect(); - }; - - // Dumps rooted objects - locSys.dumpRoot = function() { - __jsc__.dumpRoot(); - }; - - // restarts the JS VM - locSys.restartVM = function() { - __restartVM(); - }; - - locSys.dump = function(){ - var self = this; - var str = ""; - str += "isMobile : " + self.isMobile + "\r\n"; - str += "language : " + self.language + "\r\n"; - str += "browserType : " + self.browserType + "\r\n"; - str += "capabilities : " + JSON.stringify(self.capabilities) + "\r\n"; - str += "os : " + self.os + "\r\n"; - cc.log(str); - } }; //+++++++++++++++++++++++++something about sys end+++++++++++++++++++++++++++++ @@ -1248,7 +1250,7 @@ cc.game._initConfig(); // JS to Native bridges if(cc.sys.os == cc.sys.OS_ANDROID){ - cc.reflection = new JavascriptJavaBridge(); + jsb.reflection = new JavascriptJavaBridge(); cc.sys.capabilities["keyboard"] = true; } else if(cc.sys.os == cc.sys.OS_IOS){ diff --git a/frameworks/js-bindings/bindings/script/jsb_cocos2d.js b/frameworks/js-bindings/bindings/script/jsb_cocos2d.js index a58927d1ea..8ea1c9f136 100644 --- a/frameworks/js-bindings/bindings/script/jsb_cocos2d.js +++ b/frameworks/js-bindings/bindings/script/jsb_cocos2d.js @@ -1674,7 +1674,10 @@ cc.EventListener.create = function(argObj){ } for(var key in argObj) { - listener[key] = argObj[key]; + // Temporary fix for EventMouse to support getDelta functions (doesn't exist in Cocos2d-x) + if (key == "onMouseDown" || key == "onMouseMove") + listener["_" + key] = argObj[key]; + else listener[key] = argObj[key]; } return listener; @@ -1745,10 +1748,64 @@ cc.EventListenerKeyboard.prototype.clone = function() { return ret; }; +cc.EventListenerMouse.prototype.clone = function() { + var ret = cc.EventListenerMouse.create(); + ret._onMouseDown = this._onMouseDown; + ret._onMouseMove = this._onMouseMove; + ret.onMouseUp = this.onMouseUp; + ret.onMouseScroll = this.onMouseScroll; + return ret; +}; +cc.EventListenerMouse.prototype.onMouseMove = function(event) { + if (!this._onMouseMove) + return; + event._listener = this; + this._onMouseMove(event); + this._previousX = event.getLocationX(); + this._previousY = event.getLocationY(); +}; +cc.EventListenerMouse.prototype.onMouseDown = function(event) { + if (!this._onMouseDown) + return; + event._listener = this; + this._previousX = event.getLocationX(); + this._previousY = event.getLocationY(); + this._onMouseDown(event); +}; + cc.EventMouse.prototype.getLocation = function(){ return { x: this.getLocationX(), y: this.getLocationY() }; }; +cc.EventMouse.prototype.getLocationInView = function() { + return {x: this.getLocationX(), y: cc.view.getDesignResolutionSize().height - this.getLocationY()}; +}; + +// Temporary fix for EventMouse to support getDelta functions (doesn't exist in Cocos2d-x) +cc.EventMouse.prototype.getDelta = function(){ + if (isNaN(this._listener._previousX)) { + this._listener._previousX = this.getLocationX(); + this._listener._previousY = this.getLocationY(); + } + return { x: this.getLocationX() - this._listener._previousX, y: this.getLocationY() - this._listener._previousY }; +}; + +cc.EventMouse.prototype.getDeltaX = function(){ + if (isNaN(this._listener._previousX)) { + this._listener._previousX = this.getLocationX(); + this._listener._previousY = this.getLocationY(); + } + return this.getLocationX() - this._listener._previousX; +}; + +cc.EventMouse.prototype.getDeltaY = function(){ + if (isNaN(this._listener._previousX)) { + this._listener._previousX = this.getLocationX(); + this._listener._previousY = this.getLocationY(); + } + return this.getLocationY() - this._listener._previousY; +}; + cc.Touch.prototype.getLocationX = function(){ return this.getLocation().x; }; diff --git a/frameworks/js-bindings/bindings/script/jsb_create_apis.js b/frameworks/js-bindings/bindings/script/jsb_create_apis.js index ec15d77c09..1aa49423be 100644 --- a/frameworks/js-bindings/bindings/script/jsb_create_apis.js +++ b/frameworks/js-bindings/bindings/script/jsb_create_apis.js @@ -762,7 +762,7 @@ cc.LabelTTF.prototype._ctor = function(text, fontName, fontSize, dimensions, hAl this.initWithStringAndTextDefinition(text, fontName); } else { - fontName = fontName || "Arial"; + fontName = fontName || ""; fontSize = fontSize || 16; dimensions = dimensions || cc.size(0,0); hAlignment = hAlignment === undefined ? cc.TEXT_ALIGNMENT_LEFT : hAlignment; @@ -927,7 +927,7 @@ cc.LabelTTF.create = function (text, fontName, fontSize, dimensions, hAlignment, label = cc.LabelTTF.createWithFontDefinition(text, fontName); } else { - fontName = fontName || "Arial"; + fontName = fontName || ""; fontSize = fontSize || 16; dimensions = dimensions || cc.size(0, 0); hAlignment = hAlignment == undefined ? cc.TEXT_ALIGNMENT_CENTER : hAlignment; diff --git a/frameworks/js-bindings/cocos2d-x b/frameworks/js-bindings/cocos2d-x index 758577c73e..c67a854d6c 160000 --- a/frameworks/js-bindings/cocos2d-x +++ b/frameworks/js-bindings/cocos2d-x @@ -1 +1 @@ -Subproject commit 758577c73ee6328441e92439bdec52d5ef2aba53 +Subproject commit c67a854d6ca13285a9561b1e9d85b4677c2c1201 diff --git a/samples/js-moonwarriors/src/GameLayer.js b/samples/js-moonwarriors/src/GameLayer.js index b9ca1377da..1a9c7041b1 100755 --- a/samples/js-moonwarriors/src/GameLayer.js +++ b/samples/js-moonwarriors/src/GameLayer.js @@ -123,7 +123,7 @@ var GameLayer = cc.Layer.extend({ cc.eventManager.addListener({ event: cc.EventListener.MOUSE, onMouseMove: function(event){ - if(event.getButton() != undefined) + if(event.getButton() == cc.EventMouse.BUTTON_LEFT) event.getCurrentTarget().processEvent(event); } }, this); diff --git a/samples/js-tests/project/proj.android/AndroidManifest.xml b/samples/js-tests/project/proj.android/AndroidManifest.xml index 10b360053b..f89480cea1 100644 --- a/samples/js-tests/project/proj.android/AndroidManifest.xml +++ b/samples/js-tests/project/proj.android/AndroidManifest.xml @@ -32,7 +32,15 @@ - + + + + + + + - + + + + + diff --git a/samples/js-tests/res/Images/cocos-html5.png b/samples/js-tests/res/Images/cocos-html5.png new file mode 100644 index 0000000000..ab7c7118e3 Binary files /dev/null and b/samples/js-tests/res/Images/cocos-html5.png differ diff --git a/samples/js-tests/src/CocosDenshionTest/CocosDenshionTest.js b/samples/js-tests/src/CocosDenshionTest/CocosDenshionTest.js index 225a88f1ea..e86cdce75d 100644 --- a/samples/js-tests/src/CocosDenshionTest/CocosDenshionTest.js +++ b/samples/js-tests/src/CocosDenshionTest/CocosDenshionTest.js @@ -183,7 +183,7 @@ var CocosDenshionTest = cc.LayerGradient.extend({ cc.eventManager.addListener({ event: cc.EventListener.MOUSE, onMouseMove: function(event){ - if(event.getButton() != undefined) + if(event.getButton() == cc.EventMouse.BUTTON_LEFT) event.getCurrentTarget().moveMenu(event.getDelta()); } }, this); diff --git a/samples/js-tests/src/EventTest/EventTest.js b/samples/js-tests/src/EventTest/EventTest.js index 9c908f61a3..4e57eccf50 100644 --- a/samples/js-tests/src/EventTest/EventTest.js +++ b/samples/js-tests/src/EventTest/EventTest.js @@ -361,8 +361,8 @@ var MouseTest = EventTest.extend({ var pos = event.getLocation(), target = event.getCurrentTarget(); if(event.getButton() === cc.EventMouse.BUTTON_RIGHT) cc.log("onRightMouseDown at: " + pos.x + " " + pos.y ); - else - cc.log("onMouseDown at: " + pos.x + " " + pos.y ); + else if(event.getButton() === cc.EventMouse.BUTTON_LEFT) + cc.log("onLeftMouseDown at: " + pos.x + " " + pos.y ); target.sprite.x = pos.x; target.sprite.y = pos.y; }, diff --git a/samples/js-tests/src/ExtensionsTest/AssetsManagerTest/AssetsManagerTest.js b/samples/js-tests/src/ExtensionsTest/AssetsManagerTest/AssetsManagerTest.js index c1fdf21a5a..2d133cb6c4 100644 --- a/samples/js-tests/src/ExtensionsTest/AssetsManagerTest/AssetsManagerTest.js +++ b/samples/js-tests/src/ExtensionsTest/AssetsManagerTest/AssetsManagerTest.js @@ -131,7 +131,7 @@ var AssetsManagerLoaderScene = TestScene.extend({ if (!this._am.getLocalManifest().isLoaded()) { cc.log("Fail to update assets, step skipped."); - var scene = new jsb.AssetsManagerTestScene(backgroundPaths[currentScene]); + var scene = new AssetsManagerTestScene(backgroundPaths[currentScene]); cc.director.runScene(scene); } else @@ -208,7 +208,6 @@ var AssetsManagerLoaderScene = TestScene.extend({ }, updateProgress : function () { - cc.log("What the fuck::: " + this._percent); this._loadingBar.setPercent(this._percent); this._fileLoadingBar.setPercent(this._percentByFile); }, diff --git a/samples/js-tests/src/ExtensionsTest/ExtensionsTest.js b/samples/js-tests/src/ExtensionsTest/ExtensionsTest.js index 447785056e..8940ef0ed2 100644 --- a/samples/js-tests/src/ExtensionsTest/ExtensionsTest.js +++ b/samples/js-tests/src/ExtensionsTest/ExtensionsTest.js @@ -96,7 +96,7 @@ var extensionsTestItemNames = [ } ]; -if (cc.sys.os == cc.sys.OS_IOS || cc.sys.os == cc.sys.OS_ANDROID || true) { +if (cc.sys.isMobile || !cc.sys.isNative) { extensionsTestItemNames.push({ itemTitle:"PluginTest", testScene:function () { diff --git a/samples/js-tests/src/ExtensionsTest/PluginXTest/FacebookShareTest.js b/samples/js-tests/src/ExtensionsTest/PluginXTest/FacebookShareTest.js index f4981de992..d18ac3c8f6 100644 --- a/samples/js-tests/src/ExtensionsTest/PluginXTest/FacebookShareTest.js +++ b/samples/js-tests/src/ExtensionsTest/PluginXTest/FacebookShareTest.js @@ -50,11 +50,15 @@ var FacebookShareTest = PluginXTest.extend({ for (var action in buttons) { var label = cc.LabelTTF.create(action, "Arial", 24); var item = cc.MenuItemLabel.create(label, this[buttons[action]], this); - item.setPosition(winSize.width / 2, winSize.height - top); + item.setPosition(winSize.width * 1/3 , winSize.height - top); menu.addChild(item); top += 50; } + var logo = cc.Sprite.create(s_html5_logo); + logo.setPosition(winSize.width * 2/3, winSize.height / 2); + this.addChild(logo); + this._agentManager = plugin.AgentManager.getInstance(); }, @@ -87,13 +91,22 @@ var FacebookShareTest = PluginXTest.extend({ }, onSharePhoto : function(){ - var map = { - "dialog" : "share_photo", - "photo" : "http://files.cocos2d-x.org/images/orgsite/logo.png" - }; - this._agentManager.dialog(map, function(resultcode, msg) { - cc.log(msg); + + var img = this.screenshot("facebookshare.jpg"); + + var delay = cc.DelayTime.create(2); + var share = cc.CallFunc.create(function(){ + var map = { + "dialog" : "share_photo", + "photo" : img + }; + plugin.AgentManager.getInstance().dialog(map, function(resultcode, msg) { + cc.log(msg); + }); }); + var seq = cc.Sequence.create(delay, share); + this.runAction(seq); + }, onLinkMsg : function(){ @@ -125,13 +138,20 @@ var FacebookShareTest = PluginXTest.extend({ }, onPhotoMsg : function(){ - var map = { - "dialog" : "message_photo", - "photo" : "http://files.cocos2d-x.org/images/orgsite/logo.png" - }; - this._agentManager.dialog(map, function(resultcode, msg) { - cc.log(msg); + var img = this.screenshot("facebookmessage.jpg"); + + var delay = cc.DelayTime.create(2); + var share = cc.CallFunc.create(function(){ + var map = { + "dialog" : "message_photo", + "photo" : img + }; + plugin.AgentManager.getInstance().dialog(map, function(resultcode, msg) { + cc.log(msg); + }); }); + var seq = cc.Sequence.create(delay, share); + this.runAction(seq); }, onRequest : function(){ @@ -154,5 +174,25 @@ var FacebookShareTest = PluginXTest.extend({ var s = new PluginXTestScene(); s.addChild(new PluginXTestLayer()); director.runScene(s); + }, + + screenshot:function(fileName){ + var tex = cc.RenderTexture.create(winSize.width, winSize.height,cc.Texture2D.PIXEL_FORMAT_RGBA8888); + tex.setPosition(cc.p(winSize.width / 2, winSize.height / 2)); + tex.begin(); + cc.director.getRunningScene().visit(); + tex.end(); + + var imgPath = jsb.fileUtils.getWritablePath(); + if (imgPath.length == 0) { + return; + } + var result = tex.saveToFile(fileName, cc.IMAGE_FORMAT_JPEG); + if (result) { + imgPath += fileName; + cc.log("save image:"+imgPath); + return imgPath; + } + return ""; } }); \ No newline at end of file diff --git a/samples/js-tests/src/ExtensionsTest/PluginXTest/IOSIAPTest.js b/samples/js-tests/src/ExtensionsTest/PluginXTest/IOSIAPTest.js index 5a84aff2e6..aaff011fa0 100644 --- a/samples/js-tests/src/ExtensionsTest/PluginXTest/IOSIAPTest.js +++ b/samples/js-tests/src/ExtensionsTest/PluginXTest/IOSIAPTest.js @@ -45,7 +45,6 @@ var IAPTestLayer = PluginXTest.extend({ _serverMode: false, onEnter: function () { this._super(); - this.addCloseBtn(); this.initPlugin(); this.addMenuItem(); this.initToast(); @@ -53,7 +52,7 @@ var IAPTestLayer = PluginXTest.extend({ initPlugin: function () { var pluginManager = plugin.PluginManager.getInstance(); this.PluginIAP = pluginManager.loadPlugin("IOSIAP"); - this.PluginIAP.setResultListener(this); + this.PluginIAP.setListener(this); }, addMenuItem: function () { var payMenu = cc.Menu.create(); @@ -77,19 +76,6 @@ var IAPTestLayer = PluginXTest.extend({ payMenu.y = 0; this.addChild(payMenu); }, - addCloseBtn: function () { - var pCloseItem = cc.MenuItemImage.create( - "CloseNormal.png", - "CloseSelected.png", - this.closeFunction, - this); - pCloseItem.setPosition(cc.p(cc.winSize.width - 20, 20)); - - // create menu, it's an autorelease object - var pMenu = cc.Menu.create(pCloseItem); - pMenu.setPosition(cc.p(0, 0)); - this.addChild(pMenu, 1); - }, closeFunction: function (sender) { var scene = new ExtensionsTestScene(); scene.runThisTest(); @@ -105,13 +91,36 @@ var IAPTestLayer = PluginXTest.extend({ this.toastLayer.retain(); this.toastLayer.setColor(cc.color(100, 100, 100, 100)); }, + addTouch: function (bool) { + if (bool) { + var self = this.toastLayer; + this.listener = cc.EventListener.create({ + event: cc.EventListener.TOUCH_ONE_BY_ONE, + swallowTouches: true, + onTouchBegan: function (touch, event) { + return true; + }, + onTouchMoved: function (touch, event) { + }, + onTouchEnded: function (touch, event) { + }, + onTouchCancelled: function (touch, event) { + } + }); + cc.eventManager.addListener(this.listener, self); + } else { + cc.eventManager.removeListener(this.listener); + } + }, toggleToast: function (show) { if (show) { if (!this.getChildByTag(TAG_TOAST)) { this.addChild(this.toastLayer); + this.addTouch(true); } } else { this.toastLayer.removeFromParent(true); + this.addTouch(false); } }, menuCallBack: function (sender) { @@ -185,8 +194,9 @@ var IAPTestLayer = PluginXTest.extend({ postServerData: function (data) { var that = this; var xhr = cc.loader.getXMLHttpRequest(); + //replace to your own server address - xhr.open("POST", "http://192.168.52.22:8888/start"); + xhr.open("POST", "http://192.168.52.38:8888/start"); that.toggleToast(true); xhr.onreadystatechange = function () { if (xhr.readyState == 4 && xhr.status == 200) { diff --git a/samples/js-tests/src/LabelTest/LabelTest.js b/samples/js-tests/src/LabelTest/LabelTest.js index 31faf854b7..00291928f1 100644 --- a/samples/js-tests/src/LabelTest/LabelTest.js +++ b/samples/js-tests/src/LabelTest/LabelTest.js @@ -1582,7 +1582,7 @@ var BMFontMultiLineAlignmentTest = AtlasDemo.extend({ } }, onMouseMove:function (touch) { - if(event.getButton == undefined || event.getButton() == undefined) + if(!event.getButton || event.getButton() != cc.EventMouse.BUTTON_LEFT) return; var location = touch.getLocation(); diff --git a/samples/js-tests/src/LayerTest/LayerTest.js b/samples/js-tests/src/LayerTest/LayerTest.js index 9a3299d495..50344aa17b 100644 --- a/samples/js-tests/src/LayerTest/LayerTest.js +++ b/samples/js-tests/src/LayerTest/LayerTest.js @@ -103,7 +103,7 @@ var LayerTest1 = LayerTest.extend({ cc.eventManager.addListener({ event: cc.EventListener.MOUSE, onMouseMove: function(event){ - if(event.getButton() != undefined) + if(event.getButton() == cc.EventMouse.BUTTON_LEFT) event.getCurrentTarget().updateSize(event.getLocation()); } }, this); @@ -470,7 +470,7 @@ var LayerGradient = LayerTest.extend({ event.getCurrentTarget().updateGradient(event.getLocation()); }, onMouseMove: function(event){ - if(event.getButton() != undefined) + if(event.getButton() == cc.EventMouse.BUTTON_LEFT) event.getCurrentTarget().updateGradient(event.getLocation()); } }, this); diff --git a/samples/js-tests/src/NewEventManagerTest/NewEventManagerTest.js b/samples/js-tests/src/NewEventManagerTest/NewEventManagerTest.js index a9003406ff..b656ecad45 100644 --- a/samples/js-tests/src/NewEventManagerTest/NewEventManagerTest.js +++ b/samples/js-tests/src/NewEventManagerTest/NewEventManagerTest.js @@ -211,8 +211,10 @@ var TouchableSprite = cc.Sprite.extend({ }, onTouchEnded: function (touch, event) { selfPointer.setColor(cc.color.WHITE); - if(selfPointer._removeListenerOnTouchEnded) + if(selfPointer._removeListenerOnTouchEnded) { cc.eventManager.removeListener(selfPointer._listener); + selfPointer._listener = null; + } } }); @@ -224,7 +226,7 @@ var TouchableSprite = cc.Sprite.extend({ }, onExit: function(){ - cc.eventManager.removeListener(this._listener); + this._listener && cc.eventManager.removeListener(this._listener); this._super(); }, diff --git a/samples/js-tests/src/ParallaxTest/ParallaxTest.js b/samples/js-tests/src/ParallaxTest/ParallaxTest.js index 83b05065ee..965e0f35bf 100644 --- a/samples/js-tests/src/ParallaxTest/ParallaxTest.js +++ b/samples/js-tests/src/ParallaxTest/ParallaxTest.js @@ -177,7 +177,7 @@ Parallax2 = ParallaxDemo.extend({ cc.eventManager.addListener({ event: cc.EventListener.MOUSE, onMouseMove: function(event){ - if(event.getButton() != undefined){ + if(event.getButton() == cc.EventMouse.BUTTON_LEFT){ var node = event.getCurrentTarget().getChildByTag(TAG_NODE); node.x += event.getDeltaX(); node.y += event.getDeltaY(); diff --git a/samples/js-tests/src/ParticleTest/ParticleTest.js b/samples/js-tests/src/ParticleTest/ParticleTest.js index e87f77db4a..42bcd39024 100644 --- a/samples/js-tests/src/ParticleTest/ParticleTest.js +++ b/samples/js-tests/src/ParticleTest/ParticleTest.js @@ -197,7 +197,7 @@ var ParticleDemo = BaseTestLayer.extend({ event.getCurrentTarget()._moveToTouchPoint(event.getLocation()); }, onMouseMove: function(event){ - if(event.getButton() != undefined) + if(event.getButton() == cc.EventMouse.BUTTON_LEFT) event.getCurrentTarget()._moveToTouchPoint(event.getLocation()); } }, this); diff --git a/samples/js-tests/src/ReflectionTest/ReflectionTest.js b/samples/js-tests/src/ReflectionTest/ReflectionTest.js index 211edab257..86d27c572a 100644 --- a/samples/js-tests/src/ReflectionTest/ReflectionTest.js +++ b/samples/js-tests/src/ReflectionTest/ReflectionTest.js @@ -34,7 +34,7 @@ var ReflectionTestLayer = BaseTestLayer.extend({ var label = cc.LabelTTF.create("Show Alert Dialog", "Arial", 35); var menuItem = cc.MenuItemLabel.create(label, function(){ - cc.reflection.callStaticMethod("org/cocos2dx/js_tests/AppActivity", "showAlertDialog", "(Ljava/lang/String;Ljava/lang/String;)V", "How are you ?", "I'm great !"); + jsb.reflection.callStaticMethod("org/cocos2dx/js_tests/AppActivity", "showAlertDialog", "(Ljava/lang/String;Ljava/lang/String;)V", "How are you ?", "I'm great !"); }, this); menuItem.x = winSize.width / 2; menuItem.y = winSize.height / 2; diff --git a/samples/js-tests/src/RenderTextureTest/RenderTextureTest.js b/samples/js-tests/src/RenderTextureTest/RenderTextureTest.js index d8400069bb..88f3b5a635 100644 --- a/samples/js-tests/src/RenderTextureTest/RenderTextureTest.js +++ b/samples/js-tests/src/RenderTextureTest/RenderTextureTest.js @@ -96,7 +96,7 @@ var RenderTextureSave = RenderTextureBaseLayer.extend({ event.getCurrentTarget()._lastLocation = event.getLocation(); }, onMouseMove: function(event){ - if(event.getButton() != undefined) + if(event.getButton() == cc.EventMouse.BUTTON_LEFT) event.getCurrentTarget().drawInLocation(event.getLocation()); } }, this); diff --git a/samples/js-tests/src/TileMapTest/TileMapTest.js b/samples/js-tests/src/TileMapTest/TileMapTest.js index c53cdca46e..490243ac75 100644 --- a/samples/js-tests/src/TileMapTest/TileMapTest.js +++ b/samples/js-tests/src/TileMapTest/TileMapTest.js @@ -50,7 +50,7 @@ var TileDemoProps = { cc.eventManager.addListener({ event: cc.EventListener.MOUSE, onMouseMove: function(event){ - if(event.getButton() != undefined){ + if(event.getButton() == cc.EventMouse.BUTTON_LEFT){ var node = event.getCurrentTarget().getChildByTag(TAG_TILE_MAP); node.x += event.getDeltaX(); node.y += event.getDeltaY(); diff --git a/samples/js-tests/src/tests-main.js b/samples/js-tests/src/tests-main.js index 22146a8009..a8e0cb6021 100644 --- a/samples/js-tests/src/tests-main.js +++ b/samples/js-tests/src/tests-main.js @@ -160,7 +160,7 @@ var TestController = cc.LayerGradient.extend({ cc.eventManager.addListener({ event: cc.EventListener.MOUSE, onMouseMove: function (event) { - if(event.getButton() != undefined) + if(event.getButton() == cc.EventMouse.BUTTON_LEFT) event.getCurrentTarget().moveMenu(event.getDelta()); }, onMouseScroll: function (event) { diff --git a/samples/js-tests/src/tests_resources.js b/samples/js-tests/src/tests_resources.js index 11d47e1bcc..8d4c387e4b 100644 --- a/samples/js-tests/src/tests_resources.js +++ b/samples/js-tests/src/tests_resources.js @@ -203,6 +203,7 @@ var s_extensions_button = "res/extensions/button.png"; var s_extensions_buttonHighlighted = "res/extensions/buttonHighlighted.png"; var s_extensions_ribbon = "res/extensions/ribbon.png"; var s_image_icon = "res/Images/Icon.png"; +var s_html5_logo = "res/Images/cocos-html5.png"; var g_resources = [ //global diff --git a/templates/js-template-default/frameworks/runtime-src/proj.win32/build-cfg.json b/templates/js-template-default/frameworks/runtime-src/proj.win32/build-cfg.json index 185596a442..94dadfd8ec 100644 --- a/templates/js-template-default/frameworks/runtime-src/proj.win32/build-cfg.json +++ b/templates/js-template-default/frameworks/runtime-src/proj.win32/build-cfg.json @@ -18,7 +18,7 @@ }, { "from": "../../js-bindings/bindings/script", - "to": "" + "to": "script" } ] } diff --git a/templates/js-template-runtime/frameworks/runtime-src/proj.android/src/org/cocos2dx/javascript/AppActivity.java b/templates/js-template-runtime/frameworks/runtime-src/proj.android/src/org/cocos2dx/javascript/AppActivity.java index e436741e9c..0a3248749d 100644 --- a/templates/js-template-runtime/frameworks/runtime-src/proj.android/src/org/cocos2dx/javascript/AppActivity.java +++ b/templates/js-template-runtime/frameworks/runtime-src/proj.android/src/org/cocos2dx/javascript/AppActivity.java @@ -30,6 +30,7 @@ of this software and associated documentation files (the "Software"), to deal import java.net.NetworkInterface; import java.net.SocketException; import java.util.Enumeration; +import java.util.ArrayList; import org.cocos2dx.lib.Cocos2dxActivity; @@ -72,7 +73,7 @@ protected void onCreate(Bundle savedInstanceState) { // Check the wifi is opened when the native is debug. if(nativeIsDebug()) { - if(!isWifiConnected()) + if(!isNetworkConnected()) { AlertDialog.Builder builder=new AlertDialog.Builder(this); builder.setTitle("Warning"); @@ -92,17 +93,31 @@ public void onClick(DialogInterface dialog, int which) { } hostIPAdress = getHostIpAddress(); } - private boolean isWifiConnected() { - ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); - if (cm != null) { - NetworkInfo networkInfo = cm.getActiveNetworkInfo(); - if (networkInfo != null && networkInfo.getType() == ConnectivityManager.TYPE_WIFI) { - return true; - } - } - return false; - } - + + private boolean isNetworkConnected() { + ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); + if (cm != null) { + NetworkInfo networkInfo = cm.getActiveNetworkInfo(); + ArrayList networkTypes = new ArrayList(); + networkTypes.add(ConnectivityManager.TYPE_WIFI); + //We need to use getDeclaredField as TYPE_ETHERNET is only available from API level 13 (3.2) + //networkTypes.add(ConnectivityManager.TYPE_ETHERNET); // will not compile + try { + networkTypes.add(ConnectivityManager.class.getDeclaredField("TYPE_ETHERNET").getInt(null)); + } catch (NoSuchFieldException nsfe) { + //Ignore on older API levels + //throw new RuntimeException(nsfe); + } + catch (IllegalAccessException iae) { + throw new RuntimeException(iae); + } + if (networkInfo != null && networkTypes.contains(networkInfo.getType())) { + return true; + } + } + return false; + } + public String getHostIpAddress() { WifiManager wifiMgr = (WifiManager) getSystemService(WIFI_SERVICE); WifiInfo wifiInfo = wifiMgr.getConnectionInfo(); diff --git a/tools/tojs/cocos2dx.ini b/tools/tojs/cocos2dx.ini index 65730eed7d..815fdcf1c3 100644 --- a/tools/tojs/cocos2dx.ini +++ b/tools/tojs/cocos2dx.ini @@ -109,7 +109,7 @@ skip = Node::[^setPosition$ setGLServerState description getUserObject .*UserDat RenderTexture::[listenToBackground listenToForeground], TextFieldTTF::[(g|s)etDelegate], EventListenerVector::[*], - EventListener(Touch|Keyboard).*::[create], + EventListener(Touch|Keyboard|Mouse).*::[create], EventTouch::[(s|g)etTouches], Device::[getTextureDataForText], EventDispatcher::[dispatchCustomEvent], @@ -132,10 +132,10 @@ rename_functions = SpriteFrameCache::[addSpriteFramesWithFile=addSpriteFrames ge FileUtils::[loadFilenameLookupDictionaryFromFile=loadFilenameLookup], SimpleAudioEngine::[preloadBackgroundMusic=preloadMusic setBackgroundMusicVolume=setMusicVolume getBackgroundMusicVolume=getMusicVolume playBackgroundMusic=playMusic stopBackgroundMusic=stopMusic pauseBackgroundMusic=pauseMusic resumeBackgroundMusic=resumeMusic rewindBackgroundMusic=rewindMusic isBackgroundMusicPlaying=isMusicPlaying willPlayBackgroundMusic=willPlayMusic], EventDispatcher::[addCustomEventListener=addCustomListener removeEventListener=removeListener removeEventListenersForType=removeListeners removeEventListenersForTarget=removeListeners removeCustomEventListeners=removeCustomListeners removeAllEventListeners=removeAllListeners pauseEventListenersForTarget=pauseTarget resumeEventListenersForTarget=resumeTarget], + EventMouse::[getMouseButton=getButton setMouseButton=setButton setCursorPosition=setLocation getCursorX=getLocationX getCursorY=getLocationY], Configuration::[getInfo=dumpInfo], ComponentContainer::[get=getComponent], LayerColor::[initWithColor=init], - EventMouse::[getCursorX=getLocationX getCursorY=getLocationY setCursorPosition=setLocation], GLProgramCache::[getGLProgram=getProgram addGLProgram=addProgram reloadDefaultGLPrograms=reloadDefaultShaders loadDefaultGLPrograms=loadDefaultShaders] rename_classes = ParticleSystemQuad::ParticleSystem,