Skip to content

Commit

Permalink
Keypad changes:
Browse files Browse the repository at this point in the history
Keypad -> Keyboard (it dispatche keyboard events, not just keypad
events)
Events:
  keyDown -> onKeyDown (in order to follow the new event convention)
  keyUp   -> onKeyUp
  • Loading branch information
ricardoquesada committed Aug 10, 2012
1 parent f627638 commit 7274831
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 69 deletions.
14 changes: 7 additions & 7 deletions cocos2d/CCDirector.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ cc.Director = cc.Class.extend(/** @lends cc.Director# */{
_scheduler:null,
_actionManager:null,
_touchDispatcher:null,
_keypadDispatcher:null,
_keyboardDispatcher:null,
_accelerometer:null,

_watcherFun:null,
Expand Down Expand Up @@ -248,8 +248,8 @@ cc.Director = cc.Class.extend(/** @lends cc.Director# */{
this._touchDispatcher = new cc.TouchDispatcher();
this._touchDispatcher.init();

//KeypadDispatcher
this._keypadDispatcher = cc.KeypadDispatcher.getInstance();
//KeyboardDispatcher
this._keyboardDispatcher = cc.KeyboardDispatcher.getInstance();

//accelerometer
//this._accelerometer = new cc.Accelerometer();
Expand Down Expand Up @@ -1115,11 +1115,11 @@ cc.Director = cc.Class.extend(/** @lends cc.Director# */{
}
},

getKeypadDispatcher:function () {
return this._keypadDispatcher;
getKeyboardDispatcher:function () {
return this._keyboardDispatcher;
},
setKeypadDispatcher:function (keypadDispatcher) {
this._keypadDispatcher = keypadDispatcher;
setKeyboardDispatcher:function (keyboardDispatcher) {
this._keyboardDispatcher = keyboardDispatcher;
},

getAccelerometer:function () {
Expand Down
6 changes: 3 additions & 3 deletions cocos2d/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@
<file name="touch_dispatcher/CCTouchDelegateProtocol.js"/>
<file name="touch_dispatcher/CCTouchHandler.js"/>
<file name="touch_dispatcher/CCTouchDispatcher.js"/>
<file name="keypad_dispatcher/CCKeypadDelegate.js"/>
<file name="keypad_dispatcher/CCKeypadDispatcher.js"/>
<file name="keyboard_dispatcher/CCKeyboardDelegate.js"/>
<file name="keyboard_dispatcher/CCKeyboardDispatcher.js"/>
<file name="text_input_node/CCIMEDispatcher.js"/>
<file name="text_input_node/CCTextFieldTTF.js"/>
<file name="CCDirector.js"/>
Expand All @@ -93,4 +93,4 @@
</sources>
</jscomp>
</target>
</project>
</project>
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -26,50 +26,50 @@


/**
* you must extend the keypadDelegate and
* you must extend the keyboardDelegate and
* implement your own game logic in
* keydown and keyup functions
* @class
* @extends cc.Class
*/
cc.KeypadDelegate = cc.Class.extend(/** @lends cc.KeypadDelegate# */{
cc.KeyboardDelegate = cc.Class.extend(/** @lends cc.KeyboardDelegate# */{
/**
* Call back when a key is pressed down
*/
keyDown:function () {
onKeyDown:function () {
},

/**
* Call back when a key is released
*/
keyUp:function () {
onKeyUp:function () {
}
});

/**
* KeypadHandler is an object that contains KeypadDelegate
* KeyboardHandler is an object that contains KeyboardDelegate
* @class
* @extends cc.Class
*/
cc.KeypadHandler = cc.Class.extend(/** @lends cc.KeypadHandler# */{
cc.KeyboardHandler = cc.Class.extend(/** @lends cc.KeyboardHandler# */{
/**
* returns the keypad delegate
* @return {cc.KeypadDelegate}
* returns the keyboard delegate
* @return {cc.KeyboardDelegate}
*/
getDelegate:function () {
return this._delegate;
},

/**
* set the keypad delegate
* @param {cc.KeypadDelegate} delegate
* set the keyboard delegate
* @param {cc.KeyboardDelegate} delegate
*/
setDelegate:function (delegate) {
this._delegate = delegate;
},
/**
* initializes a cc.KeypadHandler with a delegate
* @param {cc.KeypadDelegate} delegate
* initializes a cc.KeyboardHandler with a delegate
* @param {cc.KeyboardDelegate} delegate
* @return {Boolean}
*/
initWithDelegate:function (delegate) {
Expand All @@ -82,12 +82,12 @@ cc.KeypadHandler = cc.Class.extend(/** @lends cc.KeypadHandler# */{
_delegate:null
});
/**
* Create a KeypadHandler with KeypadDelegate
* Create a KeyboardHandler with KeyboardDelegate
* @param delegate
* @return {cc.KeypadHandler}
* @return {cc.KeyboardHandler}
*/
cc.KeypadHandler.create = function (delegate) {
var handler = new cc.KeypadHandler();
cc.KeyboardHandler.create = function (delegate) {
var handler = new cc.KeyboardHandler();
handler.initWithDelegate(delegate);
return handler;
};
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,14 @@ cc.KEY = {
};

/**
* Dispatch the keypad message
* Dispatch the keyboard message
* @class
* @extends cc.Class
*/
cc.KeypadDispatcher = cc.Class.extend(/** @lends cc.KeypadDispatcher# */{
cc.KeyboardDispatcher = cc.Class.extend(/** @lends cc.KeyboardDispatcher# */{
/**
* add delegate to concern keypad msg
* @param {cc.KeypadDelegate} delegate keypad delegate object
* add delegate to concern keyboard msg
* @param {cc.KeyboardDelegate} delegate keyboard delegate object
*/
addDelegate:function (delegate) {
if (!delegate) {
Expand All @@ -187,8 +187,8 @@ cc.KeypadDispatcher = cc.Class.extend(/** @lends cc.KeypadDispatcher# */{
},

/**
* remove the delegate from the delegates who concern keypad msg
* @param {cc.KeypadDelegate} delegate
* remove the delegate from the delegates who concern keyboard msg
* @param {cc.KeyboardDelegate} delegate
*/
removeDelegate:function (delegate) {
if (!delegate) {
Expand All @@ -205,10 +205,10 @@ cc.KeypadDispatcher = cc.Class.extend(/** @lends cc.KeypadDispatcher# */{

/**
* force add the delegate
* @param {cc.KeypadDelegate} delegate
* @param {cc.KeyboardDelegate} delegate
*/
forceAddDelegate:function (delegate) {
var handler = cc.KeypadHandler.create(delegate);
var handler = cc.KeyboardHandler.create(delegate);
if (handler) {
//if handler already exist
for (var i = 0; i < this._delegates; i++) {
Expand All @@ -221,7 +221,7 @@ cc.KeypadDispatcher = cc.Class.extend(/** @lends cc.KeypadDispatcher# */{

/**
* force remove the delegate
* @param {cc.KeypadDelegate} delegate
* @param {cc.KeyboardDelegate} delegate
*/
forceRemoveDelegate:function (delegate) {
for (var i = 0; i < this._delegates.length; i++) {
Expand All @@ -233,12 +233,12 @@ cc.KeypadDispatcher = cc.Class.extend(/** @lends cc.KeypadDispatcher# */{
},

/**
* dispatch the keypad message to the delegates
* dispatch the keyboard message to the delegates
* @param {event} e
* @param {Boolean} keydown whether this is a keydown or keyup
* @return {Boolean}
*/
dispatchKeypadMSG:function (e, keydown) {
dispatchKeyboardMSG:function (e, keydown) {
this._locked = true;
e.stopPropagation();
e.preventDefault();
Expand All @@ -247,13 +247,13 @@ cc.KeypadDispatcher = cc.Class.extend(/** @lends cc.KeypadDispatcher# */{
{
//execute all deletegate that registered a keyboard event
for (var i = 0; i < this._delegates.length; i++) {
this._delegates[i].getDelegate().keyDown(e.keyCode);
this._delegates[i].getDelegate().onKeyDown(e.keyCode);
}
}
else if (!keydown && e)//if keyup and our keymap have that key in it
{
for (var i = 0; i < this._delegates.length; i++) {
this._delegates[i].getDelegate().keyUp(e.keyCode);
this._delegates[i].getDelegate().onKeyUp(e.keyCode);
}
}
this._locked = false;
Expand Down Expand Up @@ -286,33 +286,33 @@ cc.KeypadDispatcher = cc.Class.extend(/** @lends cc.KeypadDispatcher# */{
});

/**
* Returns the shared cc.KeypadDispatcher object for the system.
* @return {cc.keypadDispatcher}
* Returns the shared cc.KeyboardDispatcher object for the system.
* @return {cc.keyboardDispatcher}
*/
cc.KeypadDispatcher.getInstance = function () {
if (!cc.keypadDispatcher) {
cc.keypadDispatcher = new cc.KeypadDispatcher();
cc.KeyboardDispatcher.getInstance = function () {
if (!cc.keyboardDispatcher) {
cc.keyboardDispatcher = new cc.KeyboardDispatcher();
//make canvas focusable
cc.canvas.setAttribute('contentEditable', true);
cc.canvas.style.outline = 'none';
cc.canvas.style.cursor = 'default';
cc.canvas.addEventListener("keydown", function (e) {
cc.keypadDispatcher.dispatchKeypadMSG(e, true);
cc.keyboardDispatcher.dispatchKeyboardMSG(e, true);
cc.IMEDispatcher.getInstance().processKeycode(e.keyCode);
});
cc.canvas.addEventListener("keyup", function (e) {
cc.keypadDispatcher.dispatchKeypadMSG(e, false);
cc.keyboardDispatcher.dispatchKeyboardMSG(e, false);
});
}
return cc.keypadDispatcher;
return cc.keyboardDispatcher;
};

/**
* Release the shared cc.KeypadDispatcher object from the system.
* Release the shared cc.KeyboardDispatcher object from the system.
*/
cc.KeypadDispatcher.purgeSharedDispatcher = function () {
if (cc.keypadDispatcher) {
delete cc.keypadDispatcher;
cc.keypadDispatcher = null;
cc.KeyboardDispatcher.purgeSharedDispatcher = function () {
if (cc.keyboardDispatcher) {
delete cc.keyboardDispatcher;
cc.keyboardDispatcher = null;
}
};
26 changes: 13 additions & 13 deletions cocos2d/layers_scenes_transitions_nodes/CCLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
cc.Layer = cc.Node.extend(/** @lends cc.Layer# */{
_isTouchEnabled:false,
_isAccelerometerEnabled:false,
_isKeypadEnabled:false,
_isKeyboardEnabled:false,

/**
* Constructor
Expand Down Expand Up @@ -134,28 +134,28 @@ cc.Layer = cc.Node.extend(/** @lends cc.Layer# */{
},

/**
* whether or not it will receive keypad events<br/>
* whether or not it will receive keyboard events<br/>
* You can enable / disable accelerometer events with this property.<br/>
* it's new in cocos2d-x
* @return {Boolean}
*/
isKeypadEnabled:function () {
return this._isKeypadEnabled;
isKeyboardEnabled:function () {
return this._isKeyboardEnabled;
},

/**
* Enable Keyboard interaction
* @param {Boolean} enabled
*/
setKeypadEnabled:function (enabled) {
if (enabled != this._isKeypadEnabled) {
this._isKeypadEnabled = enabled;
setKeyboardEnabled:function (enabled) {
if (enabled != this._isKeyboardEnabled) {
this._isKeyboardEnabled = enabled;
if (this._isRunning) {
var director = cc.Director.getInstance();
if (enabled) {
director.getKeypadDispatcher().addDelegate(this);
director.getKeyboardDispatcher().addDelegate(this);
} else {
director.getKeypadDispatcher().removeDelegate(this);
director.getKeyboardDispatcher().removeDelegate(this);
}
}
}
Expand All @@ -181,8 +181,8 @@ cc.Layer = cc.Node.extend(/** @lends cc.Layer# */{
}

// add this layer to concern the kaypad msg
if (this._isKeypadEnabled) {
director.getKeypadDispatcher().addDelegate(this);
if (this._isKeyboardEnabled) {
director.getKeyboardDispatcher().addDelegate(this);
}
},

Expand All @@ -201,8 +201,8 @@ cc.Layer = cc.Node.extend(/** @lends cc.Layer# */{
}

// remove this layer from the delegates who concern the kaypad msg
if (this._isKeypadEnabled) {
director.getKeypadDispatcher().removeDelegate(this);
if (this._isKeyboardEnabled) {
director.getKeyboardDispatcher().removeDelegate(this);
}

this._super();
Expand Down
4 changes: 2 additions & 2 deletions cocos2d/platform/jsloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ var cc = cc || cc || {};
'touch_dispatcher/CCTouchDelegateProtocol.js',
'touch_dispatcher/CCTouchHandler.js',
'touch_dispatcher/CCTouchDispatcher.js',
'keypad_dispatcher/CCKeypadDelegate.js',
'keypad_dispatcher/CCKeypadDispatcher.js',
'keyboard_dispatcher/CCKeyboardDelegate.js',
'keyboard_dispatcher/CCKeyboardDispatcher.js',
'text_input_node/CCIMEDispatcher.js',
'text_input_node/CCTextFieldTTF.js',
'CCDirector.js',
Expand Down
2 changes: 1 addition & 1 deletion cocos2d/text_input_node/CCIMEDispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ cc.IMEDispatcher.Impl = cc.Class.extend(/** @lends cc.IMEDispatcher.Impl# */{
cc.IMEDispatcher.getInstance = function () {
if (!cc.IMEDispatcher.instance) {
cc.IMEDispatcher.instance = new cc.IMEDispatcher();
cc.KeypadDispatcher.getInstance();
cc.KeyboardDispatcher.getInstance();
}
return cc.IMEDispatcher.instance;
};
Expand Down
2 changes: 1 addition & 1 deletion tests/src/testbasic.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ var testNames = [
return new IntervalTestScene();
}
},
//"KeypadTest",
//"KeyboardTest",
{
title:"LabelTest",
testScene:function () {
Expand Down

0 comments on commit 7274831

Please sign in to comment.