修复了EMenu禁用后,EButton仍然可以自行启用的bug

This commit is contained in:
Nomango 2017-11-08 11:18:11 +08:00
parent 1ac6f0a33d
commit a7b29bbdf9
5 changed files with 41 additions and 13 deletions

View File

@ -214,6 +214,7 @@
<ClCompile Include="Common\EMouseMsg.cpp" />
<ClCompile Include="Common\EObject.cpp" />
<ClCompile Include="Common\EPhysicsMsg.cpp" />
<ClCompile Include="Common\ESpriteFrame.cpp" />
<ClCompile Include="Common\ETexture.cpp" />
<ClCompile Include="Geometry\ECircle.cpp" />
<ClCompile Include="Geometry\EEllipse.cpp" />

View File

@ -213,6 +213,9 @@
<ClCompile Include="Common\EPhysicsMsg.cpp">
<Filter>Common</Filter>
</ClCompile>
<ClCompile Include="Common\ESpriteFrame.cpp">
<Filter>Common</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Win\winbase.h">

View File

@ -14,6 +14,9 @@ e2d::EButton::EButton()
, m_pDisabled(nullptr)
, m_pListener(nullptr)
{
m_pListener = new EListenerMouse(std::bind(&EButton::_updateStatus, this));
m_pListener->setAlwaysWorking(true);
EMsgManager::bindListener(m_pListener, this);
}
e2d::EButton::EButton(ENode * normal, const BUTTON_CLICK_CALLBACK & callback)
@ -145,13 +148,6 @@ void e2d::EButton::setCallback(const BUTTON_CLICK_CALLBACK & callback)
WARN_IF(m_pNormal == nullptr, "EButton cannot work without something to show. Please set its normal displayed.");
m_Callback = callback;
if (m_pListener == nullptr)
{
m_pListener = new EListenerMouse(std::bind(&EButton::_updateStatus, this));
m_pListener->setAlwaysWorking(true);
EMsgManager::bindListener(m_pListener, this);
}
}
void e2d::EButton::_setStatus(STATUS status)

View File

@ -1,4 +1,5 @@
#include "..\enodes.h"
#include "..\elisteners.h"
e2d::EMenu::EMenu()
: m_bEnable(true)
@ -30,18 +31,40 @@ size_t e2d::EMenu::getButtonCount() const
void e2d::EMenu::setEnable(bool enable)
{
m_bEnable = enable;
for (auto &buttons : m_vButtons)
if (m_bEnable != enable)
{
buttons->setEnable(enable);
m_bEnable = enable;
for (auto &button : m_vButtons)
{
if (enable)
{
button->m_pListener->start();
}
else
{
button->m_pListener->stop();
}
}
}
}
void e2d::EMenu::addButton(EButton * button)
{
this->addChild(button);
m_vButtons.push_back(button);
if (button)
{
this->addChild(button);
m_vButtons.push_back(button);
if (m_bEnable)
{
button->m_pListener->start();
}
else
{
button->m_pListener->stop();
}
}
}
bool e2d::EMenu::removeButton(EButton * button)
@ -60,6 +83,8 @@ bool e2d::EMenu::removeButton(EButton * button)
{
if (m_vButtons[i] == button)
{
// 移除按钮前,将它的监听器启用
button->m_pListener->start();
m_vButtons.erase(m_vButtons.begin() + i);
return true;
}

View File

@ -10,6 +10,7 @@ class EAction;
class EButton;
class EButtonToggle;
class EGeometry;
class EMenu;
class ENode :
public EObject
@ -570,6 +571,8 @@ protected:
class EButton :
public ENode
{
friend EMenu;
public:
// 创建一个空按钮
EButton();