新增可以在游戏暂停时运行的监听器
This commit is contained in:
		
							parent
							
								
									109a86e19f
								
							
						
					
					
						commit
						c23d7e4066
					
				|  | @ -42,3 +42,8 @@ void e2d::EListener::setName(const EString & name) | ||||||
| { | { | ||||||
| 	m_sName = name; | 	m_sName = name; | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | void e2d::EListener::setAlwaysWorking(bool bAlways) | ||||||
|  | { | ||||||
|  | 	m_bAlways = bAlways; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | @ -60,17 +60,17 @@ void e2d::EMsgManager::KeyboardProc(UINT message, WPARAM wParam, LPARAM lParam) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void e2d::EMsgManager::bindListener(e2d::EListenerMouse * listener, EScene * pParentScene, bool always /* = false */) | void e2d::EMsgManager::bindListener(e2d::EListenerMouse * listener, EScene * pParentScene) | ||||||
| { | { | ||||||
| 	EMsgManager::bindListener(listener, pParentScene->getRoot(), always); | 	EMsgManager::bindListener(listener, pParentScene->getRoot()); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void e2d::EMsgManager::bindListener(EListenerKeyboard * listener, EScene * pParentScene, bool always /* = false */) | void e2d::EMsgManager::bindListener(EListenerKeyboard * listener, EScene * pParentScene) | ||||||
| { | { | ||||||
| 	EMsgManager::bindListener(listener, pParentScene->getRoot(), always); | 	EMsgManager::bindListener(listener, pParentScene->getRoot()); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void e2d::EMsgManager::bindListener(EListenerMouse * listener, ENode * pParentNode, bool always /* = false */) | void e2d::EMsgManager::bindListener(EListenerMouse * listener, ENode * pParentNode) | ||||||
| { | { | ||||||
| 	WARN_IF(listener == nullptr, "EListenerMouse NULL pointer exception!"); | 	WARN_IF(listener == nullptr, "EListenerMouse NULL pointer exception!"); | ||||||
| 	WARN_IF(pParentNode == nullptr, "Bind EListenerMouse with a NULL ENode pointer!"); | 	WARN_IF(pParentNode == nullptr, "Bind EListenerMouse with a NULL ENode pointer!"); | ||||||
|  | @ -84,13 +84,12 @@ void e2d::EMsgManager::bindListener(EListenerMouse * listener, ENode * pParentNo | ||||||
| 
 | 
 | ||||||
| 		listener->start(); | 		listener->start(); | ||||||
| 		listener->retain(); | 		listener->retain(); | ||||||
| 		listener->m_bAlways = always; |  | ||||||
| 		listener->m_pParentNode = pParentNode; | 		listener->m_pParentNode = pParentNode; | ||||||
| 		s_vMouseListeners.push_back(listener); | 		s_vMouseListeners.push_back(listener); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void e2d::EMsgManager::bindListener(EListenerKeyboard * listener, ENode * pParentNode, bool always /* = false */) | void e2d::EMsgManager::bindListener(EListenerKeyboard * listener, ENode * pParentNode) | ||||||
| { | { | ||||||
| 	WARN_IF(listener == nullptr, "EListenerKeyboard NULL pointer exception!"); | 	WARN_IF(listener == nullptr, "EListenerKeyboard NULL pointer exception!"); | ||||||
| 	WARN_IF(pParentNode == nullptr, "Bind EListenerKeyboard with a NULL ENode pointer!"); | 	WARN_IF(pParentNode == nullptr, "Bind EListenerKeyboard with a NULL ENode pointer!"); | ||||||
|  | @ -105,7 +104,6 @@ void e2d::EMsgManager::bindListener(EListenerKeyboard * listener, ENode * pParen | ||||||
| 		listener->start(); | 		listener->start(); | ||||||
| 		listener->retain(); | 		listener->retain(); | ||||||
| 		listener->m_pParentNode = pParentNode; | 		listener->m_pParentNode = pParentNode; | ||||||
| 		listener->m_bAlways = always; |  | ||||||
| 		s_vKeyboardListeners.push_back(listener); | 		s_vKeyboardListeners.push_back(listener); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -109,11 +109,14 @@ void e2d::EButton::setDisable(bool disable) | ||||||
| 
 | 
 | ||||||
| void e2d::EButton::setCallback(const BUTTON_CLICK_CALLBACK & callback) | void e2d::EButton::setCallback(const BUTTON_CLICK_CALLBACK & callback) | ||||||
| { | { | ||||||
| 	EMsgManager::stopAllMouseListenersBindedWith(this); |  | ||||||
| 
 |  | ||||||
| 	auto listener = new EListenerMouse(std::bind(&EButton::_listenerCallback, this)); |  | ||||||
| 	EMsgManager::bindListener(listener, this, true); |  | ||||||
| 	m_Callback = callback; | 	m_Callback = callback; | ||||||
|  | 
 | ||||||
|  | 	// 停止其他监听器
 | ||||||
|  | 	EMsgManager::stopAllMouseListenersBindedWith(this); | ||||||
|  | 	// 新建一个监听器
 | ||||||
|  | 	auto listener = new EListenerMouse(std::bind(&EButton::_listenerCallback, this)); | ||||||
|  | 	listener->setAlwaysWorking(true); | ||||||
|  | 	EMsgManager::bindListener(listener, this); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void e2d::EButton::_callOn() | void e2d::EButton::_callOn() | ||||||
|  |  | ||||||
|  | @ -42,6 +42,11 @@ public: | ||||||
| 		const EString &name | 		const EString &name | ||||||
| 	); | 	); | ||||||
| 
 | 
 | ||||||
|  | 	// 设置监听器在游戏暂停时继续工作
 | ||||||
|  | 	void setAlwaysWorking( | ||||||
|  | 		bool bAlways | ||||||
|  | 	); | ||||||
|  | 
 | ||||||
| 	// 绑定监听器到场景
 | 	// 绑定监听器到场景
 | ||||||
| 	virtual void bindWith( | 	virtual void bindWith( | ||||||
| 		EScene * pParentScene | 		EScene * pParentScene | ||||||
|  |  | ||||||
|  | @ -47,15 +47,13 @@ public: | ||||||
| 	// 绑定鼠标消息监听器到场景
 | 	// 绑定鼠标消息监听器到场景
 | ||||||
| 	static void bindListener( | 	static void bindListener( | ||||||
| 		EListenerMouse * listener, | 		EListenerMouse * listener, | ||||||
| 		EScene * pParentScene, | 		EScene * pParentScene | ||||||
| 		bool always = false /* 是否在游戏暂停时仍然监听 */ |  | ||||||
| 	); | 	); | ||||||
| 
 | 
 | ||||||
| 	// 绑定鼠标消息监听器到节点
 | 	// 绑定鼠标消息监听器到节点
 | ||||||
| 	static void bindListener( | 	static void bindListener( | ||||||
| 		EListenerMouse * listener, | 		EListenerMouse * listener, | ||||||
| 		ENode * pParentNode, | 		ENode * pParentNode | ||||||
| 		bool always = false /* 是否在游戏暂停时仍然监听 */ |  | ||||||
| 	); | 	); | ||||||
| 
 | 
 | ||||||
| 	// 启动具有相同名称的鼠标消息监听器
 | 	// 启动具有相同名称的鼠标消息监听器
 | ||||||
|  | @ -102,15 +100,13 @@ public: | ||||||
| 	// 绑定按键消息监听器到场景
 | 	// 绑定按键消息监听器到场景
 | ||||||
| 	static void bindListener( | 	static void bindListener( | ||||||
| 		EListenerKeyboard * listener, | 		EListenerKeyboard * listener, | ||||||
| 		EScene * pParentScene, | 		EScene * pParentScene | ||||||
| 		bool always = false /* 是否在游戏暂停时仍然监听 */ |  | ||||||
| 	); | 	); | ||||||
| 
 | 
 | ||||||
| 	// 绑定按键消息监听器到节点
 | 	// 绑定按键消息监听器到节点
 | ||||||
| 	static void bindListener( | 	static void bindListener( | ||||||
| 		EListenerKeyboard * listener, | 		EListenerKeyboard * listener, | ||||||
| 		ENode * pParentNode, | 		ENode * pParentNode | ||||||
| 		bool always = false /* 是否在游戏暂停时仍然监听 */ |  | ||||||
| 	); | 	); | ||||||
| 
 | 
 | ||||||
| 	// 启动名称相同的按键消息监听器
 | 	// 启动名称相同的按键消息监听器
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue