fixed bugs about buttons.
This commit is contained in:
parent
7d36ea26fd
commit
556f8f76de
|
|
@ -1,5 +1,4 @@
|
||||||
#include "..\eactions.h"
|
#include "..\eactions.h"
|
||||||
#include "..\emanagers.h"
|
|
||||||
|
|
||||||
e2d::EAction::EAction()
|
e2d::EAction::EAction()
|
||||||
: m_bRunning(false)
|
: m_bRunning(false)
|
||||||
|
|
@ -13,7 +12,6 @@ e2d::EAction::EAction()
|
||||||
|
|
||||||
e2d::EAction::~EAction()
|
e2d::EAction::~EAction()
|
||||||
{
|
{
|
||||||
EActionManager::__destroyAction(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool e2d::EAction::isRunning()
|
bool e2d::EAction::isRunning()
|
||||||
|
|
@ -30,6 +28,7 @@ void e2d::EAction::startWith(ENode* pTarget)
|
||||||
{
|
{
|
||||||
m_bRunning = true;
|
m_bRunning = true;
|
||||||
m_pTarget = pTarget;
|
m_pTarget = pTarget;
|
||||||
|
this->reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::EAction::resume()
|
void e2d::EAction::resume()
|
||||||
|
|
|
||||||
|
|
@ -23,11 +23,7 @@ bool e2d::EGame::init(LPCTSTR sTitle, UINT32 nWidth, UINT32 nHeight, LPCTSTR pIc
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
// 初始化 COM 组件
|
// 初始化 COM 组件
|
||||||
if (FAILED(CoInitializeEx(NULL, COINIT_MULTITHREADED)))
|
CoInitializeEx(NULL, COINIT_MULTITHREADED);
|
||||||
{
|
|
||||||
WARN_IF(true, "CoInitializeEx Failed!");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建设备无关资源
|
// 创建设备无关资源
|
||||||
if (!ERenderer::__createDeviceIndependentResources())
|
if (!ERenderer::__createDeviceIndependentResources())
|
||||||
|
|
|
||||||
|
|
@ -39,21 +39,13 @@ void e2d::EScene::_render()
|
||||||
|
|
||||||
void e2d::EScene::_update()
|
void e2d::EScene::_update()
|
||||||
{
|
{
|
||||||
if (!EGame::isPaused())
|
// 执行 onUpdate 函数
|
||||||
|
if (m_bAutoUpdate)
|
||||||
{
|
{
|
||||||
// 执行 onUpdate 函数
|
this->onUpdate();
|
||||||
if (m_bAutoUpdate)
|
|
||||||
{
|
|
||||||
this->onUpdate();
|
|
||||||
}
|
|
||||||
// 更新根节点
|
|
||||||
m_pRoot->_update(false);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// 更新根节点
|
|
||||||
m_pRoot->_update(true);
|
|
||||||
}
|
}
|
||||||
|
// 更新根节点
|
||||||
|
m_pRoot->_update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::EScene::setAutoUpdate(bool bAutoUpdate)
|
void e2d::EScene::setAutoUpdate(bool bAutoUpdate)
|
||||||
|
|
|
||||||
|
|
@ -90,18 +90,6 @@ void e2d::EActionManager::__clearAllActionsBindedWith(ENode * pTargetNode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::EActionManager::__destroyAction(EAction * pAction)
|
|
||||||
{
|
|
||||||
for (size_t i = 0; i < s_vActions.size(); i++)
|
|
||||||
{
|
|
||||||
if (pAction == s_vActions[i])
|
|
||||||
{
|
|
||||||
s_vActions.erase(s_vActions.begin() + i);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void e2d::EActionManager::resumeAllActions()
|
void e2d::EActionManager::resumeAllActions()
|
||||||
{
|
{
|
||||||
for (auto child : ESceneManager::getCurrentScene()->getRoot()->getChildren())
|
for (auto child : ESceneManager::getCurrentScene()->getRoot()->getChildren())
|
||||||
|
|
@ -140,23 +128,26 @@ void e2d::EActionManager::__update()
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// 循环遍历所有正在运行的动作
|
// 循环遍历所有正在运行的动作
|
||||||
for (auto &action : s_vActions)
|
for (size_t i = 0; i < s_vActions.size(); i++)
|
||||||
{
|
{
|
||||||
|
auto &action = s_vActions[i];
|
||||||
// 获取动作运行状态
|
// 获取动作运行状态
|
||||||
if (action->isRunning() &&
|
if (action->isRunning() &&
|
||||||
action->getTarget() &&
|
action->getTarget() &&
|
||||||
action->getTarget()->getParentScene() == ESceneManager::getCurrentScene())
|
action->getTarget()->getParentScene() == ESceneManager::getCurrentScene())
|
||||||
{
|
{
|
||||||
if (action->_isEnding())
|
if (!action->_isEnding())
|
||||||
{
|
|
||||||
// 动作已经结束
|
|
||||||
action->release();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
// 执行动作
|
// 执行动作
|
||||||
action->_update();
|
action->_update();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 动作已经结束
|
||||||
|
action->release();
|
||||||
|
action->m_pTarget = nullptr;
|
||||||
|
s_vActions.erase(s_vActions.begin() + i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -77,6 +77,11 @@ e2d::EScene * e2d::ESceneManager::getCurrentScene()
|
||||||
return s_pCurrentScene;
|
return s_pCurrentScene;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool e2d::ESceneManager::isTransitioning()
|
||||||
|
{
|
||||||
|
return s_pTransition != nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
void e2d::ESceneManager::__update()
|
void e2d::ESceneManager::__update()
|
||||||
{
|
{
|
||||||
// 更新场景内容
|
// 更新场景内容
|
||||||
|
|
@ -147,8 +152,10 @@ void e2d::ESceneManager::__render()
|
||||||
|
|
||||||
bool e2d::ESceneManager::__init()
|
bool e2d::ESceneManager::__init()
|
||||||
{
|
{
|
||||||
if (s_pNextScene == nullptr)
|
if (!s_pNextScene)
|
||||||
return false;
|
{
|
||||||
|
s_pNextScene = new EScene();
|
||||||
|
}
|
||||||
|
|
||||||
s_pCurrentScene = s_pNextScene;
|
s_pCurrentScene = s_pNextScene;
|
||||||
s_pCurrentScene->onEnter();
|
s_pCurrentScene->onEnter();
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
#include "..\enodes.h"
|
#include "..\enodes.h"
|
||||||
|
#include "..\emanagers.h"
|
||||||
|
|
||||||
e2d::EButton::EButton()
|
e2d::EButton::EButton()
|
||||||
: m_Callback((const BtnClkCallback &)nullptr)
|
: m_Callback((const BtnClkCallback &)nullptr)
|
||||||
|
|
@ -93,6 +94,7 @@ void e2d::EButton::setNormal(ENode * normal)
|
||||||
{
|
{
|
||||||
this->addChild(normal);
|
this->addChild(normal);
|
||||||
normal->setPivot(m_fPivotX, m_fPivotY);
|
normal->setPivot(m_fPivotX, m_fPivotY);
|
||||||
|
this->_setSize(normal->getWidth(), normal->getHeight());
|
||||||
}
|
}
|
||||||
m_pNormal = normal;
|
m_pNormal = normal;
|
||||||
|
|
||||||
|
|
@ -203,18 +205,18 @@ void e2d::EButton::setPivot(float pivotX, float pivotY)
|
||||||
if (m_pDisabled) m_pDisabled->setPivot(pivotX, pivotY);
|
if (m_pDisabled) m_pDisabled->setPivot(pivotX, pivotY);
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::EButton::onUpdate()
|
void e2d::EButton::onFixedUpdate()
|
||||||
{
|
{
|
||||||
if (m_bEnable && m_pNormal)
|
if (ESceneManager::isTransitioning())
|
||||||
{
|
return;
|
||||||
ENode * pMouseover = m_pMouseover ? m_pMouseover : m_pNormal;
|
|
||||||
ENode * pSelected = m_pSelected ? m_pSelected : m_pNormal;
|
|
||||||
|
|
||||||
|
if (m_bEnable && m_bVisiable && m_pNormal)
|
||||||
|
{
|
||||||
if (EInput::isMouseLButtonRelease())
|
if (EInput::isMouseLButtonRelease())
|
||||||
{
|
{
|
||||||
// 鼠标左键抬起时,判断鼠标坐标是否在按钮内部
|
// 鼠标左键抬起时,判断鼠标坐标是否在按钮内部
|
||||||
if (m_bIsSelected &&
|
if (m_bIsSelected &&
|
||||||
pSelected->isPointIn(EInput::getMousePos()))
|
m_pNormal->isPointIn(EInput::getMousePos()))
|
||||||
{
|
{
|
||||||
_runCallback();
|
_runCallback();
|
||||||
}
|
}
|
||||||
|
|
@ -224,18 +226,17 @@ void e2d::EButton::onUpdate()
|
||||||
|
|
||||||
if (EInput::isMouseLButtonPress())
|
if (EInput::isMouseLButtonPress())
|
||||||
{
|
{
|
||||||
if (pMouseover->isPointIn(EInput::getMousePos()))
|
if (m_pNormal->isPointIn(EInput::getMousePos()))
|
||||||
{
|
{
|
||||||
// 鼠标左键按下,且位于按钮内时,标记 m_bIsSelected 为 true
|
// 鼠标左键按下,且位于按钮内时,标记 m_bIsSelected 为 true
|
||||||
m_bIsSelected = true;
|
m_bIsSelected = true;
|
||||||
_setState(EButton::SELECTED);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_bIsSelected && EInput::isMouseLButtonDown())
|
if (m_bIsSelected && EInput::isMouseLButtonDown())
|
||||||
{
|
{
|
||||||
if (pSelected->isPointIn(EInput::getMousePos()))
|
if (m_pNormal->isPointIn(EInput::getMousePos()))
|
||||||
{
|
{
|
||||||
_setState(EButton::SELECTED);
|
_setState(EButton::SELECTED);
|
||||||
return;
|
return;
|
||||||
|
|
@ -251,11 +252,6 @@ void e2d::EButton::onUpdate()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::EButton::onPause()
|
|
||||||
{
|
|
||||||
this->onUpdate();
|
|
||||||
}
|
|
||||||
|
|
||||||
void e2d::EButton::_setState(BTN_STATE state)
|
void e2d::EButton::_setState(BTN_STATE state)
|
||||||
{
|
{
|
||||||
if (m_eBtnState != state)
|
if (m_eBtnState != state)
|
||||||
|
|
|
||||||
|
|
@ -134,6 +134,7 @@ void e2d::EButtonToggle::setNormal(ENode * normal)
|
||||||
{
|
{
|
||||||
this->addChild(normal);
|
this->addChild(normal);
|
||||||
normal->setPivot(m_fPivotX, m_fPivotY);
|
normal->setPivot(m_fPivotX, m_fPivotY);
|
||||||
|
this->_setSize(normal->getWidth(), normal->getHeight());
|
||||||
}
|
}
|
||||||
m_pNormalOn = normal;
|
m_pNormalOn = normal;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ e2d::ENode::~ENode()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::ENode::_update(bool bPaused)
|
void e2d::ENode::_update()
|
||||||
{
|
{
|
||||||
if (m_bTransformNeeded)
|
if (m_bTransformNeeded)
|
||||||
{
|
{
|
||||||
|
|
@ -77,7 +77,7 @@ void e2d::ENode::_update(bool bPaused)
|
||||||
// 访问 Order 小于零的节点
|
// 访问 Order 小于零的节点
|
||||||
if (child->getOrder() < 0)
|
if (child->getOrder() < 0)
|
||||||
{
|
{
|
||||||
child->_update(bPaused);
|
child->_update();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -85,28 +85,28 @@ void e2d::ENode::_update(bool bPaused)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bPaused)
|
if (m_bAutoUpdate)
|
||||||
{
|
{
|
||||||
this->onPause();
|
if (!EGame::isPaused())
|
||||||
}
|
{
|
||||||
else if (m_bAutoUpdate)
|
this->onUpdate();
|
||||||
{
|
}
|
||||||
this->onUpdate();
|
this->onFixedUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 访问剩余节点
|
// 访问剩余节点
|
||||||
for (; i < size; i++)
|
for (; i < size; i++)
|
||||||
m_vChildren[i]->_update(bPaused);
|
m_vChildren[i]->_update();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (bPaused)
|
if (m_bAutoUpdate)
|
||||||
{
|
{
|
||||||
this->onPause();
|
if (!EGame::isPaused())
|
||||||
}
|
{
|
||||||
else if (m_bAutoUpdate)
|
this->onUpdate();
|
||||||
{
|
}
|
||||||
this->onUpdate();
|
this->onFixedUpdate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -765,15 +765,13 @@ bool e2d::ENode::isPointIn(EPoint point)
|
||||||
// 为节点创建一个形状
|
// 为节点创建一个形状
|
||||||
ID2D1RectangleGeometry * rect;
|
ID2D1RectangleGeometry * rect;
|
||||||
ERenderer::getID2D1Factory()->CreateRectangleGeometry(
|
ERenderer::getID2D1Factory()->CreateRectangleGeometry(
|
||||||
D2D1::RectF(0, 0, getRealWidth(), getRealHeight()),
|
D2D1::RectF(0, 0, getWidth(), getHeight()),
|
||||||
&rect
|
&rect
|
||||||
);
|
);
|
||||||
// 判断点是否在形状内
|
// 判断点是否在形状内
|
||||||
BOOL ret;
|
BOOL ret;
|
||||||
rect->FillContainsPoint(
|
rect->FillContainsPoint(
|
||||||
D2D1::Point2F(
|
D2D1::Point2F(point.x, point.y),
|
||||||
point.x,
|
|
||||||
point.y),
|
|
||||||
&m_MatriFinal,
|
&m_MatriFinal,
|
||||||
&ret
|
&ret
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -122,6 +122,9 @@ bool EMusic::play(int nLoopCount)
|
||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nLoopCount = min(nLoopCount, XAUDIO2_LOOP_INFINITE - 1);
|
||||||
|
nLoopCount = (nLoopCount < 0) ? XAUDIO2_LOOP_INFINITE : nLoopCount;
|
||||||
|
|
||||||
// 提交 wave 样本数据
|
// 提交 wave 样本数据
|
||||||
XAUDIO2_BUFFER buffer = { 0 };
|
XAUDIO2_BUFFER buffer = { 0 };
|
||||||
buffer.pAudioData = m_pbWaveData;
|
buffer.pAudioData = m_pbWaveData;
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,9 @@ public:
|
||||||
// 获取当前场景
|
// 获取当前场景
|
||||||
static EScene * getCurrentScene();
|
static EScene * getCurrentScene();
|
||||||
|
|
||||||
|
// 是否正在进行转场动画
|
||||||
|
static bool isTransitioning();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// 更新场景内容
|
// 更新场景内容
|
||||||
static void __update();
|
static void __update();
|
||||||
|
|
@ -198,11 +201,6 @@ private:
|
||||||
ENode * pTargetNode
|
ENode * pTargetNode
|
||||||
);
|
);
|
||||||
|
|
||||||
// 删除指定的动作
|
|
||||||
static void __destroyAction(
|
|
||||||
EAction * pAction
|
|
||||||
);
|
|
||||||
|
|
||||||
// 重置所有动作状态
|
// 重置所有动作状态
|
||||||
static void __resetAllActions();
|
static void __resetAllActions();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,9 @@ public:
|
||||||
// 更新节点
|
// 更新节点
|
||||||
virtual void onUpdate() {}
|
virtual void onUpdate() {}
|
||||||
|
|
||||||
|
// 固定地更新(游戏暂停时仍然运行)
|
||||||
|
virtual void onFixedUpdate() {}
|
||||||
|
|
||||||
// 渲染节点
|
// 渲染节点
|
||||||
virtual void onRender() {}
|
virtual void onRender() {}
|
||||||
|
|
||||||
|
|
@ -39,9 +42,6 @@ public:
|
||||||
int nRelation /* 碰撞关系,取值为 ERelation::VALUE 中的一种 */
|
int nRelation /* 碰撞关系,取值为 ERelation::VALUE 中的一种 */
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
// 游戏暂停时的处理
|
|
||||||
virtual void onPause() {}
|
|
||||||
|
|
||||||
// 节点被销毁时的处理
|
// 节点被销毁时的处理
|
||||||
virtual void onDestroy() {}
|
virtual void onDestroy() {}
|
||||||
|
|
||||||
|
|
@ -337,9 +337,7 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// 更新节点
|
// 更新节点
|
||||||
void _update(
|
void _update();
|
||||||
bool bPaused
|
|
||||||
);
|
|
||||||
|
|
||||||
// 渲染节点
|
// 渲染节点
|
||||||
void _render();
|
void _render();
|
||||||
|
|
@ -632,10 +630,7 @@ public:
|
||||||
) override;
|
) override;
|
||||||
|
|
||||||
// 更新按钮状态
|
// 更新按钮状态
|
||||||
virtual void onUpdate() override;
|
virtual void onFixedUpdate() override;
|
||||||
|
|
||||||
// 更新游戏暂停时的按钮状态
|
|
||||||
virtual void onPause() override;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
enum BTN_STATE { NORMAL, MOUSEOVER, SELECTED };
|
enum BTN_STATE { NORMAL, MOUSEOVER, SELECTED };
|
||||||
|
|
|
||||||
|
|
@ -223,7 +223,7 @@ class EMusic
|
||||||
public:
|
public:
|
||||||
// ²¥·Å
|
// ²¥·Å
|
||||||
bool play(
|
bool play(
|
||||||
int nLoopCount = 0 /* 重复播放次数,设置为 255 时循环播放 */
|
int nLoopCount = 0 /* 重复播放次数,设置 -1 为循环播放 */
|
||||||
);
|
);
|
||||||
|
|
||||||
// ÔÝÍ£
|
// ÔÝÍ£
|
||||||
|
|
@ -262,28 +262,21 @@ protected:
|
||||||
|
|
||||||
virtual ~EMusic();
|
virtual ~EMusic();
|
||||||
|
|
||||||
// 打开音乐文件
|
EMusic(const EMusic &) = delete;
|
||||||
bool _open(
|
|
||||||
LPWSTR strFileName
|
EMusic &operator =(const EMusic &) = delete;
|
||||||
);
|
|
||||||
|
bool _open(LPWSTR strFileName);
|
||||||
|
|
||||||
// 关闭该播放器
|
|
||||||
void _close();
|
void _close();
|
||||||
|
|
||||||
bool _readMMIO();
|
bool _readMMIO();
|
||||||
|
|
||||||
bool _resetFile();
|
bool _resetFile();
|
||||||
|
|
||||||
bool _read(
|
bool _read(BYTE* pBuffer, DWORD dwSizeToRead);
|
||||||
BYTE* pBuffer,
|
|
||||||
DWORD dwSizeToRead
|
|
||||||
);
|
|
||||||
|
|
||||||
bool _findMediaFileCch(
|
bool _findMediaFileCch(WCHAR* strDestPath, int cchDest, LPCWSTR strFilename);
|
||||||
WCHAR* strDestPath,
|
|
||||||
int cchDest,
|
|
||||||
LPCWSTR strFilename
|
|
||||||
);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool m_bOpened;
|
bool m_bOpened;
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,7 @@
|
||||||
<Optimization>Disabled</Optimization>
|
<Optimization>Disabled</Optimization>
|
||||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<SDLCheck>true</SDLCheck>
|
<SDLCheck>true</SDLCheck>
|
||||||
<DebugInformationFormat>None</DebugInformationFormat>
|
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
|
||||||
<MinimalRebuild>false</MinimalRebuild>
|
<MinimalRebuild>false</MinimalRebuild>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue