| 
									
										
										
										
											2018-04-21 21:24:46 +08:00
										 |  |  |  | #include "..\e2dmanager.h"
 | 
					
						
							|  |  |  |  | #include "..\e2dtool.h"
 | 
					
						
							| 
									
										
										
										
											2018-03-31 18:12:01 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-24 13:28:21 +08:00
										 |  |  |  | // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  | class Listener | 
					
						
							| 
									
										
										
										
											2018-03-31 18:12:01 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-04-24 13:28:21 +08:00
										 |  |  |  | public: | 
					
						
							|  |  |  |  | 	Listener( | 
					
						
							| 
									
										
										
										
											2018-05-08 11:37:11 +08:00
										 |  |  |  | 		const e2d::Function& func, | 
					
						
							| 
									
										
										
										
											2018-05-07 15:48:06 +08:00
										 |  |  |  | 		const e2d::String& name, | 
					
						
							| 
									
										
										
										
											2018-04-24 13:28:21 +08:00
										 |  |  |  | 		bool paused | 
					
						
							|  |  |  |  | 	) | 
					
						
							|  |  |  |  | 		: name(name) | 
					
						
							|  |  |  |  | 		, callback(func) | 
					
						
							|  |  |  |  | 		, running(!paused) | 
					
						
							|  |  |  |  | 		, stopped(false) | 
					
						
							| 
									
										
										
										
											2018-03-31 18:12:01 +08:00
										 |  |  |  | 	{ | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-24 13:28:21 +08:00
										 |  |  |  | 	// <20><><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD>״̬
 | 
					
						
							|  |  |  |  | 	virtual void update() | 
					
						
							| 
									
										
										
										
											2018-04-21 00:46:26 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-04-24 13:28:21 +08:00
										 |  |  |  | 		if (callback) | 
					
						
							|  |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			callback(); | 
					
						
							|  |  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-04-21 00:46:26 +08:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-03-31 18:12:01 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-24 13:28:21 +08:00
										 |  |  |  | public: | 
					
						
							|  |  |  |  | 	bool running; | 
					
						
							|  |  |  |  | 	bool stopped; | 
					
						
							|  |  |  |  | 	e2d::String name; | 
					
						
							|  |  |  |  | 	e2d::Function callback; | 
					
						
							|  |  |  |  | }; | 
					
						
							| 
									
										
										
										
											2018-03-31 18:12:01 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-24 13:28:21 +08:00
										 |  |  |  | // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  | static std::vector<Listener*> s_vListeners; | 
					
						
							| 
									
										
										
										
											2018-03-31 18:12:01 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-08 11:37:11 +08:00
										 |  |  |  | void e2d::InputManager::add(const Function& func, const String& name, bool paused) | 
					
						
							| 
									
										
										
										
											2018-03-31 18:12:01 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-04-24 13:28:21 +08:00
										 |  |  |  | 	auto listener = new Listener(func, name, paused); | 
					
						
							|  |  |  |  | 	s_vListeners.push_back(listener); | 
					
						
							| 
									
										
										
										
											2018-03-31 18:12:01 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-07 15:48:06 +08:00
										 |  |  |  | void e2d::InputManager::pause(const String& name) | 
					
						
							| 
									
										
										
										
											2018-03-31 18:12:01 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-08 11:37:11 +08:00
										 |  |  |  | 	for (auto listener : s_vListeners) | 
					
						
							| 
									
										
										
										
											2018-03-31 18:12:01 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-05-08 11:37:11 +08:00
										 |  |  |  | 		if (listener->name == name) | 
					
						
							| 
									
										
										
										
											2018-03-31 18:12:01 +08:00
										 |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-05-08 11:37:11 +08:00
										 |  |  |  | 			listener->running = false; | 
					
						
							| 
									
										
										
										
											2018-03-31 18:12:01 +08:00
										 |  |  |  | 		} | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-07 15:48:06 +08:00
										 |  |  |  | void e2d::InputManager::resume(const String& name) | 
					
						
							| 
									
										
										
										
											2018-03-31 18:12:01 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-08 11:37:11 +08:00
										 |  |  |  | 	for (auto listener : s_vListeners) | 
					
						
							| 
									
										
										
										
											2018-03-31 18:12:01 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-05-08 11:37:11 +08:00
										 |  |  |  | 		if (listener->name == name) | 
					
						
							| 
									
										
										
										
											2018-03-31 18:12:01 +08:00
										 |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-05-08 11:37:11 +08:00
										 |  |  |  | 			listener->running = true; | 
					
						
							| 
									
										
										
										
											2018-03-31 18:12:01 +08:00
										 |  |  |  | 		} | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-07 15:48:06 +08:00
										 |  |  |  | void e2d::InputManager::stop(const String& name) | 
					
						
							| 
									
										
										
										
											2018-03-31 18:12:01 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-08 11:37:11 +08:00
										 |  |  |  | 	for (auto listener : s_vListeners) | 
					
						
							| 
									
										
										
										
											2018-03-31 18:12:01 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-05-08 11:37:11 +08:00
										 |  |  |  | 		if (listener->name == name) | 
					
						
							| 
									
										
										
										
											2018-03-31 18:12:01 +08:00
										 |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-05-08 11:37:11 +08:00
										 |  |  |  | 			listener->stopped = true; | 
					
						
							| 
									
										
										
										
											2018-03-31 18:12:01 +08:00
										 |  |  |  | 		} | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-24 13:28:21 +08:00
										 |  |  |  | void e2d::InputManager::pauseAll() | 
					
						
							| 
									
										
										
										
											2018-03-31 18:12:01 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-08 11:37:11 +08:00
										 |  |  |  | 	for (auto listener : s_vListeners) | 
					
						
							| 
									
										
										
										
											2018-03-31 18:12:01 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-05-08 11:37:11 +08:00
										 |  |  |  | 		listener->running = false; | 
					
						
							| 
									
										
										
										
											2018-03-31 18:12:01 +08:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-24 13:28:21 +08:00
										 |  |  |  | void e2d::InputManager::resumeAll() | 
					
						
							| 
									
										
										
										
											2018-03-31 18:12:01 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-08 11:37:11 +08:00
										 |  |  |  | 	for (auto listener : s_vListeners) | 
					
						
							| 
									
										
										
										
											2018-03-31 18:12:01 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-05-08 11:37:11 +08:00
										 |  |  |  | 		listener->running = true; | 
					
						
							| 
									
										
										
										
											2018-03-31 18:12:01 +08:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-24 13:28:21 +08:00
										 |  |  |  | void e2d::InputManager::stopAll() | 
					
						
							| 
									
										
										
										
											2018-03-31 18:12:01 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-08 11:37:11 +08:00
										 |  |  |  | 	for (auto listener : s_vListeners) | 
					
						
							| 
									
										
										
										
											2018-03-31 18:12:01 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-05-08 11:37:11 +08:00
										 |  |  |  | 		listener->stopped = true; | 
					
						
							| 
									
										
										
										
											2018-03-31 18:12:01 +08:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-24 13:28:21 +08:00
										 |  |  |  | void e2d::InputManager::__update() | 
					
						
							| 
									
										
										
										
											2018-03-31 18:12:01 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-04-24 13:28:21 +08:00
										 |  |  |  | 	if (s_vListeners.empty() || Game::isPaused()) | 
					
						
							|  |  |  |  | 		return; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	for (size_t i = 0; i < s_vListeners.size(); i++) | 
					
						
							| 
									
										
										
										
											2018-03-31 18:12:01 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-05-08 11:37:11 +08:00
										 |  |  |  | 		auto listener = s_vListeners[i]; | 
					
						
							| 
									
										
										
										
											2018-04-24 13:28:21 +08:00
										 |  |  |  | 		// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹͣ<CDA3>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							| 
									
										
										
										
											2018-05-08 11:37:11 +08:00
										 |  |  |  | 		if (listener->stopped) | 
					
						
							| 
									
										
										
										
											2018-04-24 13:28:21 +08:00
										 |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-05-08 11:37:11 +08:00
										 |  |  |  | 			delete listener; | 
					
						
							| 
									
										
										
										
											2018-04-24 13:28:21 +08:00
										 |  |  |  | 			s_vListeners.erase(s_vListeners.begin() + i); | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 		else | 
					
						
							| 
									
										
										
										
											2018-03-31 18:12:01 +08:00
										 |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-04-24 13:28:21 +08:00
										 |  |  |  | 			// <20><><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							| 
									
										
										
										
											2018-05-08 11:37:11 +08:00
										 |  |  |  | 			listener->update(); | 
					
						
							| 
									
										
										
										
											2018-04-24 13:28:21 +08:00
										 |  |  |  | 			++i; | 
					
						
							| 
									
										
										
										
											2018-03-31 18:12:01 +08:00
										 |  |  |  | 		} | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-24 13:28:21 +08:00
										 |  |  |  | void e2d::InputManager::__uninit() | 
					
						
							| 
									
										
										
										
											2018-03-31 18:12:01 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-04-24 20:22:41 +08:00
										 |  |  |  | 	for (auto listener : s_vListeners) | 
					
						
							| 
									
										
										
										
											2018-04-24 13:28:21 +08:00
										 |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		delete listener; | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	s_vListeners.clear(); | 
					
						
							| 
									
										
										
										
											2018-03-31 18:12:01 +08:00
										 |  |  |  | } |