监听器从Common组移动到Tool组
This commit is contained in:
parent
6bed7dec95
commit
6deb3964fb
|
|
@ -227,35 +227,35 @@ void e2d::Input::addListener(const Function& func, const String& name, bool paus
|
||||||
s_vListeners.push_back(listener);
|
s_vListeners.push_back(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::Input::pauseListener(const String& name)
|
|
||||||
{
|
|
||||||
if (s_vListeners.empty() || name.isEmpty())
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (auto listener : s_vListeners)
|
|
||||||
{
|
|
||||||
if (listener->_name == name)
|
|
||||||
{
|
|
||||||
listener->_running = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void e2d::Input::resumeListener(const String& name)
|
|
||||||
{
|
|
||||||
if (s_vListeners.empty() || name.isEmpty())
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (auto listener : s_vListeners)
|
|
||||||
{
|
|
||||||
if (listener->_name == name)
|
|
||||||
{
|
|
||||||
listener->_running = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void e2d::Input::stopListener(const String& name)
|
void e2d::Input::stopListener(const String& name)
|
||||||
|
{
|
||||||
|
if (s_vListeners.empty() || name.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (auto listener : s_vListeners)
|
||||||
|
{
|
||||||
|
if (listener->_name == name)
|
||||||
|
{
|
||||||
|
listener->stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void e2d::Input::startListener(const String& name)
|
||||||
|
{
|
||||||
|
if (s_vListeners.empty() || name.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (auto listener : s_vListeners)
|
||||||
|
{
|
||||||
|
if (listener->_name == name)
|
||||||
|
{
|
||||||
|
listener->start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void e2d::Input::clearListener(const String& name)
|
||||||
{
|
{
|
||||||
if (s_vListeners.empty() || name.isEmpty())
|
if (s_vListeners.empty() || name.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
@ -269,23 +269,23 @@ void e2d::Input::stopListener(const String& name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::Input::pauseAllListeners()
|
|
||||||
{
|
|
||||||
for (auto listener : s_vListeners)
|
|
||||||
{
|
|
||||||
listener->_running = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void e2d::Input::resumeAllListeners()
|
|
||||||
{
|
|
||||||
for (auto listener : s_vListeners)
|
|
||||||
{
|
|
||||||
listener->_running = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void e2d::Input::stopAllListeners()
|
void e2d::Input::stopAllListeners()
|
||||||
|
{
|
||||||
|
for (auto listener : s_vListeners)
|
||||||
|
{
|
||||||
|
listener->stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void e2d::Input::startAllListeners()
|
||||||
|
{
|
||||||
|
for (auto listener : s_vListeners)
|
||||||
|
{
|
||||||
|
listener->start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void e2d::Input::clearAllListeners()
|
||||||
{
|
{
|
||||||
for (auto listener : s_vListeners)
|
for (auto listener : s_vListeners)
|
||||||
{
|
{
|
||||||
|
|
@ -310,7 +310,7 @@ void e2d::Input::__updateListeners()
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// 更新监听器
|
// 更新监听器
|
||||||
listener->update();
|
listener->_update();
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
#include "..\e2dcollider.h"
|
#include "..\e2dcollider.h"
|
||||||
#include "..\e2dnode.h"
|
#include "..\e2dnode.h"
|
||||||
|
#include "..\e2dtool.h"
|
||||||
|
|
||||||
typedef std::pair<UINT, UINT> HashPair;
|
typedef std::pair<UINT, UINT> HashPair;
|
||||||
|
|
||||||
|
|
@ -109,7 +110,7 @@ void e2d::Collision::__update(Node * active, Node * passive)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// ¸üмàÌýÆ÷
|
// ¸üмàÌýÆ÷
|
||||||
listener->update();
|
listener->_update();
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -124,35 +125,35 @@ void e2d::Collision::addListener(const Function& func, const String& name, bool
|
||||||
s_vListeners.push_back(listener);
|
s_vListeners.push_back(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::Collision::pauseListener(const String& name)
|
|
||||||
{
|
|
||||||
if (s_vListeners.empty() || name.isEmpty())
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (auto listener : s_vListeners)
|
|
||||||
{
|
|
||||||
if (listener->_name == name)
|
|
||||||
{
|
|
||||||
listener->_running = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void e2d::Collision::resumeListener(const String& name)
|
|
||||||
{
|
|
||||||
if (s_vListeners.empty() || name.isEmpty())
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (auto listener : s_vListeners)
|
|
||||||
{
|
|
||||||
if (listener->_name == name)
|
|
||||||
{
|
|
||||||
listener->_running = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void e2d::Collision::stopListener(const String& name)
|
void e2d::Collision::stopListener(const String& name)
|
||||||
|
{
|
||||||
|
if (s_vListeners.empty() || name.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (auto listener : s_vListeners)
|
||||||
|
{
|
||||||
|
if (listener->_name == name)
|
||||||
|
{
|
||||||
|
listener->stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void e2d::Collision::startListener(const String& name)
|
||||||
|
{
|
||||||
|
if (s_vListeners.empty() || name.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (auto listener : s_vListeners)
|
||||||
|
{
|
||||||
|
if (listener->_name == name)
|
||||||
|
{
|
||||||
|
listener->start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void e2d::Collision::clearListener(const String& name)
|
||||||
{
|
{
|
||||||
if (s_vListeners.empty() || name.isEmpty())
|
if (s_vListeners.empty() || name.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
@ -166,23 +167,23 @@ void e2d::Collision::stopListener(const String& name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::Collision::pauseAllListeners()
|
|
||||||
{
|
|
||||||
for (auto listener : s_vListeners)
|
|
||||||
{
|
|
||||||
listener->_running = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void e2d::Collision::resumeAllListeners()
|
|
||||||
{
|
|
||||||
for (auto listener : s_vListeners)
|
|
||||||
{
|
|
||||||
listener->_running = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void e2d::Collision::stopAllListeners()
|
void e2d::Collision::stopAllListeners()
|
||||||
|
{
|
||||||
|
for (auto listener : s_vListeners)
|
||||||
|
{
|
||||||
|
listener->stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void e2d::Collision::startAllListeners()
|
||||||
|
{
|
||||||
|
for (auto listener : s_vListeners)
|
||||||
|
{
|
||||||
|
listener->start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void e2d::Collision::clearAllListeners()
|
||||||
{
|
{
|
||||||
for (auto listener : s_vListeners)
|
for (auto listener : s_vListeners)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,15 @@
|
||||||
#include "..\e2dcommon.h"
|
#include "..\e2dcommon.h"
|
||||||
|
#include "..\e2dtool.h"
|
||||||
|
|
||||||
|
|
||||||
|
e2d::Listener::Listener()
|
||||||
|
: _name()
|
||||||
|
, _callback()
|
||||||
|
, _running(true)
|
||||||
|
, _stopped(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
e2d::Listener::Listener(const Function & func, const String & name, bool paused)
|
e2d::Listener::Listener(const Function & func, const String & name, bool paused)
|
||||||
: _name(name)
|
: _name(name)
|
||||||
, _callback(func)
|
, _callback(func)
|
||||||
|
|
@ -9,7 +18,7 @@ e2d::Listener::Listener(const Function & func, const String & name, bool paused)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::Listener::update()
|
void e2d::Listener::_update()
|
||||||
{
|
{
|
||||||
if (_callback)
|
if (_callback)
|
||||||
{
|
{
|
||||||
|
|
@ -31,3 +40,18 @@ void e2d::Listener::setName(const String & name)
|
||||||
{
|
{
|
||||||
_name = name;
|
_name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void e2d::Listener::setFunc(const Function & func)
|
||||||
|
{
|
||||||
|
_callback = func;
|
||||||
|
}
|
||||||
|
|
||||||
|
void e2d::Listener::start()
|
||||||
|
{
|
||||||
|
_running = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void e2d::Listener::stop()
|
||||||
|
{
|
||||||
|
_running = false;
|
||||||
|
}
|
||||||
|
|
@ -315,13 +315,8 @@ public:
|
||||||
bool paused = false /* 是否暂停 */
|
bool paused = false /* 是否暂停 */
|
||||||
);
|
);
|
||||||
|
|
||||||
// 暂停输入监听
|
// 启动输入监听
|
||||||
static void pauseListener(
|
static void startListener(
|
||||||
const String& name
|
|
||||||
);
|
|
||||||
|
|
||||||
// 暂停输入监听
|
|
||||||
static void resumeListener(
|
|
||||||
const String& name
|
const String& name
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -330,15 +325,20 @@ public:
|
||||||
const String& name
|
const String& name
|
||||||
);
|
);
|
||||||
|
|
||||||
// 暂停所有监听器
|
// 清除输入监听
|
||||||
static void pauseAllListeners();
|
static void clearListener(
|
||||||
|
const String& name
|
||||||
|
);
|
||||||
|
|
||||||
// 继续所有监听器
|
// 启动所有监听器
|
||||||
static void resumeAllListeners();
|
static void startAllListeners();
|
||||||
|
|
||||||
// 停止所有监听器
|
// 停止所有监听器
|
||||||
static void stopAllListeners();
|
static void stopAllListeners();
|
||||||
|
|
||||||
|
// 清除所有监听器
|
||||||
|
static void clearAllListeners();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// 初始化 DirectInput 以及键盘鼠标设备
|
// 初始化 DirectInput 以及键盘鼠标设备
|
||||||
static bool __init();
|
static bool __init();
|
||||||
|
|
|
||||||
|
|
@ -72,13 +72,8 @@ public:
|
||||||
bool paused = false /* 是否暂停 */
|
bool paused = false /* 是否暂停 */
|
||||||
);
|
);
|
||||||
|
|
||||||
// 暂停碰撞监听
|
// 启动碰撞监听
|
||||||
static void pauseListener(
|
static void startListener(
|
||||||
const String& name
|
|
||||||
);
|
|
||||||
|
|
||||||
// 暂停碰撞监听
|
|
||||||
static void resumeListener(
|
|
||||||
const String& name
|
const String& name
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -87,15 +82,20 @@ public:
|
||||||
const String& name
|
const String& name
|
||||||
);
|
);
|
||||||
|
|
||||||
// 暂停所有监听器
|
// 清除碰撞监听
|
||||||
static void pauseAllListeners();
|
static void clearListener(
|
||||||
|
const String& name
|
||||||
|
);
|
||||||
|
|
||||||
// 继续所有监听器
|
// 启动所有监听器
|
||||||
static void resumeAllListeners();
|
static void startAllListeners();
|
||||||
|
|
||||||
// 停止所有监听器
|
// 停止所有监听器
|
||||||
static void stopAllListeners();
|
static void stopAllListeners();
|
||||||
|
|
||||||
|
// 清除所有监听器
|
||||||
|
static void clearAllListeners();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// 更新监听器
|
// 更新监听器
|
||||||
static void __update(
|
static void __update(
|
||||||
|
|
|
||||||
|
|
@ -576,42 +576,4 @@ protected:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class Input;
|
|
||||||
class Collision;
|
|
||||||
|
|
||||||
// 监听器
|
|
||||||
class Listener
|
|
||||||
{
|
|
||||||
friend Input;
|
|
||||||
friend Collision;
|
|
||||||
|
|
||||||
public:
|
|
||||||
Listener(
|
|
||||||
const Function& func,
|
|
||||||
const String& name,
|
|
||||||
bool paused
|
|
||||||
);
|
|
||||||
|
|
||||||
// 更新监听器状态
|
|
||||||
virtual void update();
|
|
||||||
|
|
||||||
// 获取监听器运行状态
|
|
||||||
bool isRunning() const;
|
|
||||||
|
|
||||||
// 获取名称
|
|
||||||
String getName() const;
|
|
||||||
|
|
||||||
// 设置名称
|
|
||||||
void setName(
|
|
||||||
const String& name
|
|
||||||
);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
bool _running;
|
|
||||||
bool _stopped;
|
|
||||||
String _name;
|
|
||||||
Function _callback;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -318,6 +318,57 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class Collision;
|
||||||
|
|
||||||
|
// 监听器
|
||||||
|
class Listener
|
||||||
|
{
|
||||||
|
friend Input;
|
||||||
|
friend Collision;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Listener();
|
||||||
|
|
||||||
|
Listener(
|
||||||
|
const Function& func,
|
||||||
|
const String& name,
|
||||||
|
bool paused
|
||||||
|
);
|
||||||
|
|
||||||
|
// 启动监听
|
||||||
|
void start();
|
||||||
|
|
||||||
|
// 停止监听
|
||||||
|
void stop();
|
||||||
|
|
||||||
|
// 获取监听器运行状态
|
||||||
|
bool isRunning() const;
|
||||||
|
|
||||||
|
// 获取名称
|
||||||
|
String getName() const;
|
||||||
|
|
||||||
|
// 设置名称
|
||||||
|
void setName(
|
||||||
|
const String& name
|
||||||
|
);
|
||||||
|
|
||||||
|
// 设置监听回调函数
|
||||||
|
void setFunc(
|
||||||
|
const Function& func
|
||||||
|
);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// 更新监听器状态
|
||||||
|
virtual void _update();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool _running;
|
||||||
|
bool _stopped;
|
||||||
|
String _name;
|
||||||
|
Function _callback;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// 数据管理工具
|
// 数据管理工具
|
||||||
class Data
|
class Data
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -228,7 +228,6 @@
|
||||||
<ClCompile Include="..\..\core\Collider\Collision.cpp" />
|
<ClCompile Include="..\..\core\Collider\Collision.cpp" />
|
||||||
<ClCompile Include="..\..\core\Common\Color.cpp" />
|
<ClCompile Include="..\..\core\Common\Color.cpp" />
|
||||||
<ClCompile Include="..\..\core\Common\Function.cpp" />
|
<ClCompile Include="..\..\core\Common\Function.cpp" />
|
||||||
<ClCompile Include="..\..\core\Common\Listener.cpp" />
|
|
||||||
<ClCompile Include="..\..\core\Common\Object.cpp" />
|
<ClCompile Include="..\..\core\Common\Object.cpp" />
|
||||||
<ClCompile Include="..\..\core\Common\Point.cpp" />
|
<ClCompile Include="..\..\core\Common\Point.cpp" />
|
||||||
<ClCompile Include="..\..\core\Common\Scene.cpp" />
|
<ClCompile Include="..\..\core\Common\Scene.cpp" />
|
||||||
|
|
@ -252,6 +251,7 @@
|
||||||
<ClCompile Include="..\..\core\Node\Sprite.cpp" />
|
<ClCompile Include="..\..\core\Node\Sprite.cpp" />
|
||||||
<ClCompile Include="..\..\core\Node\Text.cpp" />
|
<ClCompile Include="..\..\core\Node\Text.cpp" />
|
||||||
<ClCompile Include="..\..\core\Tool\Data.cpp" />
|
<ClCompile Include="..\..\core\Tool\Data.cpp" />
|
||||||
|
<ClCompile Include="..\..\core\Tool\Listener.cpp" />
|
||||||
<ClCompile Include="..\..\core\Tool\Music.cpp" />
|
<ClCompile Include="..\..\core\Tool\Music.cpp" />
|
||||||
<ClCompile Include="..\..\core\Tool\Path.cpp" />
|
<ClCompile Include="..\..\core\Tool\Path.cpp" />
|
||||||
<ClCompile Include="..\..\core\Tool\Player.cpp" />
|
<ClCompile Include="..\..\core\Tool\Player.cpp" />
|
||||||
|
|
|
||||||
|
|
@ -219,9 +219,6 @@
|
||||||
<ClCompile Include="..\..\core\Base\GC.cpp">
|
<ClCompile Include="..\..\core\Base\GC.cpp">
|
||||||
<Filter>Base</Filter>
|
<Filter>Base</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\core\Common\Listener.cpp">
|
|
||||||
<Filter>Common</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\..\core\Custom\VoiceCallback.cpp">
|
<ClCompile Include="..\..\core\Custom\VoiceCallback.cpp">
|
||||||
<Filter>Custom</Filter>
|
<Filter>Custom</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
|
@ -231,6 +228,9 @@
|
||||||
<ClCompile Include="..\..\core\Transition\TransitionBox.cpp">
|
<ClCompile Include="..\..\core\Transition\TransitionBox.cpp">
|
||||||
<Filter>Transition</Filter>
|
<Filter>Transition</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\core\Tool\Listener.cpp">
|
||||||
|
<Filter>Tool</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\..\core\easy2d.h" />
|
<ClInclude Include="..\..\core\easy2d.h" />
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue