Skip to content

Commit 1839c3f

Browse files
author
minggo
committed
Merge pull request #37 from SunLightJuly/add_quick_evt_module
quick event module
2 parents 54e81f1 + 721fda0 commit 1839c3f

10 files changed

Lines changed: 2129 additions & 0 deletions

lua/quick/LuaEventNode.cpp

Lines changed: 542 additions & 0 deletions
Large diffs are not rendered by default.

lua/quick/LuaEventNode.h

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/****************************************************************************
2+
Copyright (c) 2013-2014 Chukong Technologies Inc.
3+
4+
http://www.cocos2d-x.org
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in
14+
all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
THE SOFTWARE.
23+
****************************************************************************/
24+
25+
#ifndef __LUA_EVENT_NODE_H_
26+
#define __LUA_EVENT_NODE_H_
27+
28+
#include "2d/CCNode.h"
29+
30+
NS_CC_BEGIN
31+
32+
#define NODE_EVENT 0
33+
#define NODE_ENTER_FRAME_EVENT 1
34+
#define NODE_TOUCH_EVENT 2
35+
#define NODE_TOUCH_CAPTURE_EVENT 3
36+
#define MENU_ITEM_CLICKED_EVENT 4
37+
#define ACCELERATE_EVENT 5
38+
#define KEYPAD_EVENT 6
39+
40+
#define NODE_TOUCH_CAPTURING_PHASE 0
41+
#define NODE_TOUCH_TARGETING_PHASE 1
42+
43+
/**
44+
* @addtogroup scene
45+
* @{
46+
*/
47+
48+
class CC_DLL LuaEventNode : public Ref
49+
{
50+
public:
51+
static const int modeTouchesOneByOne = (int)Touch::DispatchMode::ONE_BY_ONE;
52+
static const int modeTouchesAllAtOnce = (int)Touch::DispatchMode::ALL_AT_ONCE;
53+
54+
static LuaEventNode *create(Node *node);
55+
56+
~LuaEventNode();
57+
58+
Node *getNode() const;
59+
60+
virtual LuaEventNode* getParent();
61+
62+
virtual bool isVisible() const;
63+
virtual bool isRunning() const;
64+
65+
virtual void registerWithTouchDispatcher(void);
66+
virtual void unregisterWithTouchDispatcher(void);
67+
68+
virtual bool isTouchCaptureEnabled();
69+
virtual void setTouchCaptureEnabled(bool value);
70+
virtual bool isTouchSwallowEnabled();
71+
virtual void setTouchSwallowEnabled(bool value);
72+
73+
virtual bool ccTouchCaptureBegan(Touch *pTouch, LuaEventNode *pTarget);
74+
virtual bool ccTouchCaptureMoved(Touch *pTouch, LuaEventNode *pTarget);
75+
virtual void ccTouchCaptureEnded(Touch *pTouch, LuaEventNode *pTarget);
76+
virtual void ccTouchCaptureCancelled(Touch *pTouch, LuaEventNode *pTarget);
77+
78+
virtual void ccTouchesCaptureBegan(const std::vector<Touch*>& touches, LuaEventNode *pTarget);
79+
virtual void ccTouchesCaptureMoved(const std::vector<Touch*>& touches, LuaEventNode *pTarget);
80+
virtual void ccTouchesCaptureEnded(const std::vector<Touch*>& touches, LuaEventNode *pTarget);
81+
virtual void ccTouchesCaptureCancelled(const std::vector<Touch*>& touches, LuaEventNode *pTarget);
82+
virtual void ccTouchesCaptureAdded(const std::vector<Touch*>& touches, LuaEventNode *pTarget);
83+
virtual void ccTouchesCaptureRemoved(const std::vector<Touch*>& touches, LuaEventNode *pTarget);
84+
85+
virtual bool isTouchEnabled();
86+
virtual void setTouchEnabled(bool value);
87+
88+
virtual void setTouchMode(int mode);
89+
virtual int getTouchMode();
90+
91+
virtual bool ccTouchBegan(Touch *pTouch, Event *pEvent);
92+
virtual void ccTouchMoved(Touch *pTouch, Event *pEvent);
93+
virtual void ccTouchEnded(Touch *pTouch, Event *pEvent);
94+
virtual void ccTouchCancelled(Touch *pTouch, Event *pEvent);
95+
96+
virtual void ccTouchesBegan(const std::vector<Touch*>& touches, Event *pEvent);
97+
virtual void ccTouchesMoved(const std::vector<Touch*>& touches, Event *pEvent);
98+
virtual void ccTouchesEnded(const std::vector<Touch*>& touches, Event *pEvent);
99+
virtual void ccTouchesCancelled(const std::vector<Touch*>& touches, Event *pEvent);
100+
virtual void ccTouchesAdded(const std::vector<Touch*>& touches, Event *pEvent);
101+
virtual void ccTouchesRemoved(const std::vector<Touch*>& touches, Event *pEvent);
102+
103+
private:
104+
LuaEventNode(Node *node);
105+
106+
Node *_node;
107+
108+
// touch events
109+
bool _bTouchCaptureEnabled;
110+
bool _bTouchSwallowEnabled;
111+
bool _bTouchEnabled;
112+
int _eTouchMode;
113+
114+
virtual int executeScriptTouchHandler(int nEventType, Touch *pTouch, int phase = 1);
115+
virtual int executeScriptTouchHandler(int nEventType, const std::vector<Touch*>& touches, int phase = 1);
116+
117+
};
118+
119+
NS_CC_END
120+
121+
#endif // __LUA_EVENT_NODE_H_

lua/quick/LuaNodeManager.cpp

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/****************************************************************************
2+
Copyright (c) 2013-2014 Chukong Technologies Inc.
3+
4+
http://www.cocos2d-x.org
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in
14+
all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
THE SOFTWARE.
23+
****************************************************************************/
24+
25+
#include "LuaNodeManager.h"
26+
#include "base/CCDirector.h"
27+
28+
#include "ccUtils.h"
29+
#include "base/CCEventDispatcher.h"
30+
31+
NS_CC_BEGIN
32+
33+
LuaNodeManager* LuaNodeManager::s_sharedLuaNodeManager = nullptr;
34+
35+
LuaNodeManager* LuaNodeManager::getInstance()
36+
{
37+
if (s_sharedLuaNodeManager == nullptr)
38+
{
39+
s_sharedLuaNodeManager = new (std::nothrow) LuaNodeManager();
40+
if(!s_sharedLuaNodeManager->init())
41+
{
42+
delete s_sharedLuaNodeManager;
43+
s_sharedLuaNodeManager = nullptr;
44+
CCLOG("ERROR: Could not init LuaNodeManager");
45+
}
46+
}
47+
return s_sharedLuaNodeManager;
48+
}
49+
50+
void LuaNodeManager::destroyInstance()
51+
{
52+
// log("---> LuaNodeManager::destroyInstance");
53+
CC_SAFE_DELETE(s_sharedLuaNodeManager);
54+
}
55+
56+
LuaNodeManager::LuaNodeManager()
57+
{
58+
_luaNodes.reserve(100);
59+
}
60+
61+
LuaNodeManager::~LuaNodeManager()
62+
{
63+
// log("---> Release LuaNodeManager");
64+
if (_luaNodes.size()>0)
65+
{
66+
_luaNodes.clear();
67+
}
68+
}
69+
70+
bool LuaNodeManager::init()
71+
{
72+
return true;
73+
}
74+
75+
LuaEventNode* LuaNodeManager::getLuaNodeByNode(Node *node, bool toCreate)
76+
{
77+
LuaEventNode *lnode = nullptr;
78+
for (auto it = _luaNodes.begin(); it != _luaNodes.end(); ++it)
79+
{
80+
auto lt = (LuaEventNode *)*it;
81+
if (lt->getNode() == node)
82+
{
83+
lnode = lt;
84+
break;
85+
}
86+
}
87+
if (!lnode && toCreate)
88+
{
89+
lnode = LuaEventNode::create(node);
90+
if (lnode)
91+
{
92+
_luaNodes.pushBack(lnode);
93+
}
94+
}
95+
return lnode;
96+
}
97+
98+
void LuaNodeManager::removeLuaNode(LuaEventNode *lnode)
99+
{
100+
_luaNodes.eraseObject(lnode);
101+
if (_luaNodes.size()<1)
102+
{
103+
destroyInstance();
104+
}
105+
}
106+
107+
NS_CC_END

lua/quick/LuaNodeManager.h

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/****************************************************************************
2+
Copyright (c) 2013-2014 Chukong Technologies Inc.
3+
4+
http://www.cocos2d-x.org
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in
14+
all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
THE SOFTWARE.
23+
****************************************************************************/
24+
25+
#ifndef __LUA_NODE_MANAGER_H__
26+
#define __LUA_NODE_MANAGER_H__
27+
28+
#include <string>
29+
#include <set>
30+
#include "LuaEventNode.h"
31+
#include "platform/CCStdC.h"
32+
33+
NS_CC_BEGIN
34+
35+
class CC_DLL LuaNodeManager : public Ref
36+
{
37+
public:
38+
/**
39+
* The singleton pointer of LuaNodeManager.
40+
*/
41+
static LuaNodeManager* s_sharedLuaNodeManager;
42+
43+
/** returns a shared instance of the LuaNodeManager */
44+
static LuaNodeManager* getInstance();
45+
46+
/**
47+
* Destroys the instance of LuaNodeManager.
48+
*/
49+
static void destroyInstance();
50+
51+
LuaEventNode* getLuaNodeByNode(Node *node, bool toCreate);
52+
void removeLuaNode(LuaEventNode *lnode);
53+
54+
CC_CONSTRUCTOR_ACCESS:
55+
LuaNodeManager();
56+
~LuaNodeManager();
57+
58+
bool init();
59+
60+
protected:
61+
Vector<LuaEventNode*> _luaNodes;
62+
63+
};
64+
65+
// end of LuaNodeManager group
66+
/// @}
67+
68+
NS_CC_END
69+
70+
#endif // __LUA_NODE_MANAGER_H__

0 commit comments

Comments
 (0)