整理了整体架构;监听器添加了吞噬消息功能。
This commit is contained in:
parent
0aa057c8a7
commit
339a0724fb
|
|
@ -1,4 +1,4 @@
|
||||||
#include "..\enodes.h"
|
#include "..\ecommon.h"
|
||||||
|
|
||||||
e2d::ESpriteFrame::ESpriteFrame()
|
e2d::ESpriteFrame::ESpriteFrame()
|
||||||
: m_fSourceClipX(0)
|
: m_fSourceClipX(0)
|
||||||
|
|
@ -238,7 +238,6 @@
|
||||||
<ClCompile Include="Node\EButtonToggle.cpp" />
|
<ClCompile Include="Node\EButtonToggle.cpp" />
|
||||||
<ClCompile Include="Node\ENode.cpp" />
|
<ClCompile Include="Node\ENode.cpp" />
|
||||||
<ClCompile Include="Node\ESprite.cpp" />
|
<ClCompile Include="Node\ESprite.cpp" />
|
||||||
<ClCompile Include="Node\ESpriteFrame.cpp" />
|
|
||||||
<ClCompile Include="Node\EText.cpp" />
|
<ClCompile Include="Node\EText.cpp" />
|
||||||
<ClCompile Include="Tool\EFileUtils.cpp" />
|
<ClCompile Include="Tool\EFileUtils.cpp" />
|
||||||
<ClCompile Include="Tool\EMusicUtils.cpp" />
|
<ClCompile Include="Tool\EMusicUtils.cpp" />
|
||||||
|
|
|
||||||
|
|
@ -99,9 +99,6 @@
|
||||||
<ClCompile Include="Action\EActionTwoAtSameTime.cpp">
|
<ClCompile Include="Action\EActionTwoAtSameTime.cpp">
|
||||||
<Filter>Action</Filter>
|
<Filter>Action</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="Node\ESpriteFrame.cpp">
|
|
||||||
<Filter>Node</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Action\EActionGradual.cpp">
|
<ClCompile Include="Action\EActionGradual.cpp">
|
||||||
<Filter>Action</Filter>
|
<Filter>Action</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#include "..\egeometry.h"
|
#include "..\ecommon.h"
|
||||||
|
|
||||||
e2d::EPhysicsMsg::INTERSECT_RELATION e2d::EPhysicsMsg::s_nRelation = e2d::EPhysicsMsg::INTERSECT_RELATION::UNKNOWN;
|
e2d::EPhysicsMsg::INTERSECT_RELATION e2d::EPhysicsMsg::s_nRelation = e2d::EPhysicsMsg::INTERSECT_RELATION::UNKNOWN;
|
||||||
e2d::EGeometry * e2d::EPhysicsMsg::s_pActiveGeometry = nullptr;
|
e2d::EGeometry * e2d::EPhysicsMsg::s_pActiveGeometry = nullptr;
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ e2d::EListener::EListener()
|
||||||
: m_bRunning(false)
|
: m_bRunning(false)
|
||||||
, m_bAlways(false)
|
, m_bAlways(false)
|
||||||
, m_pParentNode(nullptr)
|
, m_pParentNode(nullptr)
|
||||||
|
, m_bSwallow(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -43,6 +44,11 @@ void e2d::EListener::setName(const EString & name)
|
||||||
m_sName = name;
|
m_sName = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void e2d::EListener::setSwallow(bool bSwallow)
|
||||||
|
{
|
||||||
|
m_bSwallow = bSwallow;
|
||||||
|
}
|
||||||
|
|
||||||
void e2d::EListener::setAlwaysWorking(bool bAlways)
|
void e2d::EListener::setAlwaysWorking(bool bAlways)
|
||||||
{
|
{
|
||||||
m_bAlways = bAlways;
|
m_bAlways = bAlways;
|
||||||
|
|
|
||||||
|
|
@ -16,10 +16,15 @@ void e2d::EMsgManager::MouseProc(UINT message, WPARAM wParam, LPARAM lParam)
|
||||||
EMouseMsg::s_nMsg = message;
|
EMouseMsg::s_nMsg = message;
|
||||||
EMouseMsg::s_wParam = wParam;
|
EMouseMsg::s_wParam = wParam;
|
||||||
EMouseMsg::s_lParam = lParam;
|
EMouseMsg::s_lParam = lParam;
|
||||||
|
|
||||||
|
if (s_vMouseListeners.empty()) return;
|
||||||
|
|
||||||
// 执行鼠标消息监听函数
|
// 执行鼠标消息监听函数
|
||||||
for (size_t i = 0; i < s_vMouseListeners.size(); i++)
|
EVector<EListenerMouse*>::size_type i = s_vMouseListeners.size();
|
||||||
|
|
||||||
|
do
|
||||||
{
|
{
|
||||||
auto &mlistener = s_vMouseListeners[i];
|
auto &mlistener = s_vMouseListeners[--i];
|
||||||
|
|
||||||
if (EApp::isPaused() && !mlistener->m_bAlways)
|
if (EApp::isPaused() && !mlistener->m_bAlways)
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -30,9 +35,12 @@ void e2d::EMsgManager::MouseProc(UINT message, WPARAM wParam, LPARAM lParam)
|
||||||
mlistener->getParentNode()->getParentScene() == EApp::getCurrentScene())
|
mlistener->getParentNode()->getParentScene() == EApp::getCurrentScene())
|
||||||
{
|
{
|
||||||
mlistener->_callOn();
|
mlistener->_callOn();
|
||||||
|
|
||||||
|
if (mlistener->m_bSwallow)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} while (i != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::EMsgManager::KeyboardProc(UINT message, WPARAM wParam, LPARAM lParam)
|
void e2d::EMsgManager::KeyboardProc(UINT message, WPARAM wParam, LPARAM lParam)
|
||||||
|
|
@ -41,10 +49,15 @@ void e2d::EMsgManager::KeyboardProc(UINT message, WPARAM wParam, LPARAM lParam)
|
||||||
EKeyboardMsg::s_nMsg = message;
|
EKeyboardMsg::s_nMsg = message;
|
||||||
EKeyboardMsg::s_wParam = wParam;
|
EKeyboardMsg::s_wParam = wParam;
|
||||||
EKeyboardMsg::s_lParam = lParam;
|
EKeyboardMsg::s_lParam = lParam;
|
||||||
|
|
||||||
|
if (s_vKeyboardListeners.empty()) return;
|
||||||
|
|
||||||
// 执行按键消息监听函数
|
// 执行按键消息监听函数
|
||||||
for (size_t i = 0; i < s_vKeyboardListeners.size(); i++)
|
EVector<EListenerMouse*>::size_type i = s_vKeyboardListeners.size();
|
||||||
|
|
||||||
|
do
|
||||||
{
|
{
|
||||||
auto &klistener = s_vKeyboardListeners[i];
|
auto &klistener = s_vKeyboardListeners[--i];
|
||||||
|
|
||||||
if (EApp::isPaused() && !klistener->m_bAlways)
|
if (EApp::isPaused() && !klistener->m_bAlways)
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -55,9 +68,12 @@ void e2d::EMsgManager::KeyboardProc(UINT message, WPARAM wParam, LPARAM lParam)
|
||||||
klistener->getParentNode()->getParentScene() == EApp::getCurrentScene())
|
klistener->getParentNode()->getParentScene() == EApp::getCurrentScene())
|
||||||
{
|
{
|
||||||
klistener->_callOn();
|
klistener->_callOn();
|
||||||
|
|
||||||
|
if (klistener->m_bSwallow)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} while (i != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::EMsgManager::bindListener(e2d::EListenerMouse * listener, EScene * pParentScene)
|
void e2d::EMsgManager::bindListener(e2d::EListenerMouse * listener, EScene * pParentScene)
|
||||||
|
|
|
||||||
118
Easy2D/ecommon.h
118
Easy2D/ecommon.h
|
|
@ -307,6 +307,37 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class EGeometry;
|
||||||
|
|
||||||
|
// 物理消息
|
||||||
|
class EPhysicsMsg
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum INTERSECT_RELATION
|
||||||
|
{
|
||||||
|
UNKNOWN = 0, /* 关系不确定 */
|
||||||
|
DISJOINT = 1, /* 没有交集 */
|
||||||
|
IS_CONTAINED = 2, /* 完全被包含 */
|
||||||
|
CONTAINS = 3, /* 完全包含 */
|
||||||
|
OVERLAP = 4 /* 部分重叠 */
|
||||||
|
};
|
||||||
|
|
||||||
|
// 获取当前物理碰撞消息类型
|
||||||
|
static INTERSECT_RELATION getMsg();
|
||||||
|
|
||||||
|
// 获取主动方
|
||||||
|
static EGeometry * getActiveGeometry();
|
||||||
|
|
||||||
|
// 获取被动方
|
||||||
|
static EGeometry * getPassiveGeometry();
|
||||||
|
|
||||||
|
public:
|
||||||
|
static INTERSECT_RELATION s_nRelation;
|
||||||
|
static EGeometry * s_pActiveGeometry;
|
||||||
|
static EGeometry * s_pPassiveGeometry;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
class EObjectManager;
|
class EObjectManager;
|
||||||
|
|
||||||
class EObject
|
class EObject
|
||||||
|
|
@ -470,4 +501,91 @@ protected:
|
||||||
ID2D1Bitmap * m_pBitmap;
|
ID2D1Bitmap * m_pBitmap;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class ESpriteFrame :
|
||||||
|
public EObject
|
||||||
|
{
|
||||||
|
friend ESprite;
|
||||||
|
|
||||||
|
public:
|
||||||
|
// 创建空的精灵帧
|
||||||
|
ESpriteFrame();
|
||||||
|
|
||||||
|
// 创建空的精灵帧
|
||||||
|
ESpriteFrame(
|
||||||
|
ETexture * texture
|
||||||
|
);
|
||||||
|
|
||||||
|
// 创建空的精灵帧
|
||||||
|
ESpriteFrame(
|
||||||
|
const EString & imageFileName
|
||||||
|
);
|
||||||
|
|
||||||
|
// 创建空的精灵帧
|
||||||
|
ESpriteFrame(
|
||||||
|
LPCTSTR resourceName,
|
||||||
|
LPCTSTR resourceType
|
||||||
|
);
|
||||||
|
|
||||||
|
// 创建空的精灵帧
|
||||||
|
ESpriteFrame(
|
||||||
|
ETexture * texture,
|
||||||
|
float x,
|
||||||
|
float y,
|
||||||
|
float width,
|
||||||
|
float height
|
||||||
|
);
|
||||||
|
|
||||||
|
// 创建空的精灵帧
|
||||||
|
ESpriteFrame(
|
||||||
|
const EString & imageFileName,
|
||||||
|
float x,
|
||||||
|
float y,
|
||||||
|
float width,
|
||||||
|
float height
|
||||||
|
);
|
||||||
|
|
||||||
|
// 创建空的精灵帧
|
||||||
|
ESpriteFrame(
|
||||||
|
LPCTSTR resourceName,
|
||||||
|
LPCTSTR resourceType,
|
||||||
|
float x,
|
||||||
|
float y,
|
||||||
|
float width,
|
||||||
|
float height
|
||||||
|
);
|
||||||
|
|
||||||
|
virtual ~ESpriteFrame();
|
||||||
|
|
||||||
|
// 获取宽度
|
||||||
|
float getWidth() const;
|
||||||
|
|
||||||
|
// 获取高度
|
||||||
|
float getHeight() const;
|
||||||
|
|
||||||
|
// 获取纹理
|
||||||
|
ETexture * getTexture() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// 获取纹理
|
||||||
|
void _setTexture(
|
||||||
|
ETexture * texture
|
||||||
|
);
|
||||||
|
|
||||||
|
// 裁剪纹理
|
||||||
|
void _clipTexture(
|
||||||
|
float x,
|
||||||
|
float y,
|
||||||
|
float width,
|
||||||
|
float height
|
||||||
|
);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
float m_fSourceClipX;
|
||||||
|
float m_fSourceClipY;
|
||||||
|
float m_fSourceClipWidth;
|
||||||
|
float m_fSourceClipHeight;
|
||||||
|
ETexture * m_pTexture;
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -7,36 +7,7 @@ namespace e2d
|
||||||
|
|
||||||
class EPhysicsManager;
|
class EPhysicsManager;
|
||||||
class ENode;
|
class ENode;
|
||||||
class EGeometry;
|
|
||||||
|
|
||||||
class EPhysicsMsg
|
|
||||||
{
|
|
||||||
friend EPhysicsManager;
|
|
||||||
|
|
||||||
public:
|
|
||||||
enum INTERSECT_RELATION
|
|
||||||
{
|
|
||||||
UNKNOWN = 0, /* 关系不确定 */
|
|
||||||
DISJOINT = 1, /* 没有交集 */
|
|
||||||
IS_CONTAINED = 2, /* 完全被包含 */
|
|
||||||
CONTAINS = 3, /* 完全包含 */
|
|
||||||
OVERLAP = 4 /* 部分重叠 */
|
|
||||||
};
|
|
||||||
|
|
||||||
// 获取当前物理碰撞消息类型
|
|
||||||
static INTERSECT_RELATION getMsg();
|
|
||||||
|
|
||||||
// 获取主动方
|
|
||||||
static EGeometry * getActiveGeometry();
|
|
||||||
|
|
||||||
// 获取被动方
|
|
||||||
static EGeometry * getPassiveGeometry();
|
|
||||||
|
|
||||||
public:
|
|
||||||
static INTERSECT_RELATION s_nRelation;
|
|
||||||
static EGeometry * s_pActiveGeometry;
|
|
||||||
static EGeometry * s_pPassiveGeometry;
|
|
||||||
};
|
|
||||||
|
|
||||||
class EGeometry :
|
class EGeometry :
|
||||||
public EObject
|
public EObject
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,11 @@ public:
|
||||||
const EString &name
|
const EString &name
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// 设置监听器吞噬消息
|
||||||
|
void setSwallow(
|
||||||
|
bool bSwallow
|
||||||
|
);
|
||||||
|
|
||||||
// 设置监听器在游戏暂停时继续工作
|
// 设置监听器在游戏暂停时继续工作
|
||||||
void setAlwaysWorking(
|
void setAlwaysWorking(
|
||||||
bool bAlways
|
bool bAlways
|
||||||
|
|
@ -65,6 +70,7 @@ protected:
|
||||||
EString m_sName;
|
EString m_sName;
|
||||||
bool m_bRunning;
|
bool m_bRunning;
|
||||||
bool m_bAlways;
|
bool m_bAlways;
|
||||||
|
bool m_bSwallow;
|
||||||
ENode * m_pParentNode;
|
ENode * m_pParentNode;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -392,93 +392,6 @@ protected:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class ESpriteFrame :
|
|
||||||
public EObject
|
|
||||||
{
|
|
||||||
friend ESprite;
|
|
||||||
|
|
||||||
public:
|
|
||||||
// 创建空的精灵帧
|
|
||||||
ESpriteFrame();
|
|
||||||
|
|
||||||
// 创建空的精灵帧
|
|
||||||
ESpriteFrame(
|
|
||||||
ETexture * texture
|
|
||||||
);
|
|
||||||
|
|
||||||
// 创建空的精灵帧
|
|
||||||
ESpriteFrame(
|
|
||||||
const EString & imageFileName
|
|
||||||
);
|
|
||||||
|
|
||||||
// 创建空的精灵帧
|
|
||||||
ESpriteFrame(
|
|
||||||
LPCTSTR resourceName,
|
|
||||||
LPCTSTR resourceType
|
|
||||||
);
|
|
||||||
|
|
||||||
// 创建空的精灵帧
|
|
||||||
ESpriteFrame(
|
|
||||||
ETexture * texture,
|
|
||||||
float x,
|
|
||||||
float y,
|
|
||||||
float width,
|
|
||||||
float height
|
|
||||||
);
|
|
||||||
|
|
||||||
// 创建空的精灵帧
|
|
||||||
ESpriteFrame(
|
|
||||||
const EString & imageFileName,
|
|
||||||
float x,
|
|
||||||
float y,
|
|
||||||
float width,
|
|
||||||
float height
|
|
||||||
);
|
|
||||||
|
|
||||||
// 创建空的精灵帧
|
|
||||||
ESpriteFrame(
|
|
||||||
LPCTSTR resourceName,
|
|
||||||
LPCTSTR resourceType,
|
|
||||||
float x,
|
|
||||||
float y,
|
|
||||||
float width,
|
|
||||||
float height
|
|
||||||
);
|
|
||||||
|
|
||||||
virtual ~ESpriteFrame();
|
|
||||||
|
|
||||||
// 获取宽度
|
|
||||||
float getWidth() const;
|
|
||||||
|
|
||||||
// 获取高度
|
|
||||||
float getHeight() const;
|
|
||||||
|
|
||||||
// 获取纹理
|
|
||||||
ETexture * getTexture() const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
// 获取纹理
|
|
||||||
void _setTexture(
|
|
||||||
ETexture * texture
|
|
||||||
);
|
|
||||||
|
|
||||||
// 裁剪纹理
|
|
||||||
void _clipTexture(
|
|
||||||
float x,
|
|
||||||
float y,
|
|
||||||
float width,
|
|
||||||
float height
|
|
||||||
);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
float m_fSourceClipX;
|
|
||||||
float m_fSourceClipY;
|
|
||||||
float m_fSourceClipWidth;
|
|
||||||
float m_fSourceClipHeight;
|
|
||||||
ETexture * m_pTexture;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class ESprite :
|
class ESprite :
|
||||||
public ENode
|
public ENode
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue