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(
|
|
|
|
|
|
e2d::Function func,
|
|
|
|
|
|
e2d::String name,
|
|
|
|
|
|
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-04-24 13:28:21 +08:00
|
|
|
|
void e2d::InputManager::add(Function func, 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-04-24 13:28:21 +08:00
|
|
|
|
void e2d::InputManager::pause(String name)
|
2018-03-31 18:12:01 +08:00
|
|
|
|
{
|
2018-04-01 23:08:11 +08:00
|
|
|
|
FOR_LOOP(pListener, s_vListeners)
|
2018-03-31 18:12:01 +08:00
|
|
|
|
{
|
2018-04-24 13:28:21 +08:00
|
|
|
|
if (pListener->name == name)
|
2018-03-31 18:12:01 +08:00
|
|
|
|
{
|
2018-04-24 13:28:21 +08:00
|
|
|
|
pListener->running = false;
|
2018-03-31 18:12:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-04-24 13:28:21 +08:00
|
|
|
|
void e2d::InputManager::resume(String name)
|
2018-03-31 18:12:01 +08:00
|
|
|
|
{
|
2018-04-01 23:08:11 +08:00
|
|
|
|
FOR_LOOP(pListener, s_vListeners)
|
2018-03-31 18:12:01 +08:00
|
|
|
|
{
|
2018-04-24 13:28:21 +08:00
|
|
|
|
if (pListener->name == name)
|
2018-03-31 18:12:01 +08:00
|
|
|
|
{
|
2018-04-24 13:28:21 +08:00
|
|
|
|
pListener->running = true;
|
2018-03-31 18:12:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-04-24 13:28:21 +08:00
|
|
|
|
void e2d::InputManager::stop(String name)
|
2018-03-31 18:12:01 +08:00
|
|
|
|
{
|
2018-04-01 23:08:11 +08:00
|
|
|
|
FOR_LOOP(pListener, s_vListeners)
|
2018-03-31 18:12:01 +08:00
|
|
|
|
{
|
2018-04-24 13:28:21 +08:00
|
|
|
|
if (pListener->name == name)
|
2018-03-31 18:12:01 +08:00
|
|
|
|
{
|
2018-04-24 13:28:21 +08:00
|
|
|
|
pListener->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-04-01 23:08:11 +08:00
|
|
|
|
FOR_LOOP(pListener, s_vListeners)
|
2018-03-31 18:12:01 +08:00
|
|
|
|
{
|
2018-04-24 13:28:21 +08:00
|
|
|
|
pListener->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-04-01 23:08:11 +08:00
|
|
|
|
FOR_LOOP(pListener, s_vListeners)
|
2018-03-31 18:12:01 +08:00
|
|
|
|
{
|
2018-04-24 13:28:21 +08:00
|
|
|
|
pListener->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-04-01 23:08:11 +08:00
|
|
|
|
FOR_LOOP(pListener, s_vListeners)
|
2018-03-31 18:12:01 +08:00
|
|
|
|
{
|
2018-04-24 13:28:21 +08:00
|
|
|
|
pListener->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-04-24 13:28:21 +08:00
|
|
|
|
auto pListener = s_vListeners[i];
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹͣ<CDA3>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
if (pListener->stopped)
|
|
|
|
|
|
{
|
|
|
|
|
|
delete pListener;
|
|
|
|
|
|
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>
|
|
|
|
|
|
pListener->update();
|
|
|
|
|
|
++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 13:28:21 +08:00
|
|
|
|
FOR_LOOP(listener, s_vListeners)
|
|
|
|
|
|
{
|
|
|
|
|
|
delete listener;
|
|
|
|
|
|
}
|
|
|
|
|
|
s_vListeners.clear();
|
2018-03-31 18:12:01 +08:00
|
|
|
|
}
|