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