2018-04-21 21:24:46 +08:00
|
|
|
|
#include "..\e2dnode.h"
|
2017-11-07 23:32:44 +08:00
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
e2d::Menu::Menu()
|
2017-11-07 23:32:44 +08:00
|
|
|
|
: m_bEnable(true)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-04-02 23:01:38 +08:00
|
|
|
|
#if HIGHER_THAN_VS2012
|
|
|
|
|
|
e2d::Menu::Menu(const InitList<Button*>& vButtons)
|
|
|
|
|
|
: m_bEnable(true)
|
|
|
|
|
|
{
|
|
|
|
|
|
FOR_LOOP(button, vButtons)
|
|
|
|
|
|
{
|
|
|
|
|
|
this->addButton(button);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
e2d::Menu::Menu(int number, Button * button1, ...)
|
2017-12-15 21:51:07 +08:00
|
|
|
|
: m_bEnable(true)
|
2017-11-07 23:32:44 +08:00
|
|
|
|
{
|
2018-02-07 16:37:12 +08:00
|
|
|
|
Button ** ppButton = &button1;
|
2017-11-07 23:32:44 +08:00
|
|
|
|
|
|
|
|
|
|
while (number > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
this->addButton(*ppButton);
|
|
|
|
|
|
ppButton++;
|
|
|
|
|
|
number--;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-04-02 23:01:38 +08:00
|
|
|
|
#endif
|
2017-11-07 23:32:44 +08:00
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
bool e2d::Menu::isEnable() const
|
2017-11-07 23:32:44 +08:00
|
|
|
|
{
|
|
|
|
|
|
return m_bEnable;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
size_t e2d::Menu::getButtonCount() const
|
2017-11-07 23:32:44 +08:00
|
|
|
|
{
|
|
|
|
|
|
return m_vButtons.size();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
void e2d::Menu::setEnable(bool enable)
|
2017-11-07 23:32:44 +08:00
|
|
|
|
{
|
2017-11-08 11:18:11 +08:00
|
|
|
|
if (m_bEnable != enable)
|
2017-11-07 23:32:44 +08:00
|
|
|
|
{
|
2017-11-08 11:18:11 +08:00
|
|
|
|
m_bEnable = enable;
|
|
|
|
|
|
|
2018-04-01 23:08:11 +08:00
|
|
|
|
FOR_LOOP(button, m_vButtons)
|
2017-11-08 11:18:11 +08:00
|
|
|
|
{
|
2018-02-03 22:04:43 +08:00
|
|
|
|
button->setEnable(enable);
|
2017-11-08 11:18:11 +08:00
|
|
|
|
}
|
2017-11-07 23:32:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
void e2d::Menu::addButton(Button * button)
|
2017-11-07 23:32:44 +08:00
|
|
|
|
{
|
2017-11-08 11:18:11 +08:00
|
|
|
|
if (button)
|
|
|
|
|
|
{
|
|
|
|
|
|
this->addChild(button);
|
|
|
|
|
|
m_vButtons.push_back(button);
|
2018-01-30 16:45:38 +08:00
|
|
|
|
button->setEnable(m_bEnable);
|
2017-11-08 11:18:11 +08:00
|
|
|
|
}
|
2017-11-07 23:32:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
bool e2d::Menu::removeButton(Button * button)
|
2017-11-07 23:32:44 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (m_vButtons.empty())
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this->removeChild(button);
|
|
|
|
|
|
|
|
|
|
|
|
if (button)
|
|
|
|
|
|
{
|
|
|
|
|
|
size_t size = m_vButtons.size();
|
|
|
|
|
|
for (size_t i = 0; i < size; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (m_vButtons[i] == button)
|
|
|
|
|
|
{
|
2018-01-30 16:45:38 +08:00
|
|
|
|
// <20>Ƴ<EFBFBD><C6B3><EFBFBD>ťǰ<C5A5><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
button->setEnable(true);
|
2017-11-07 23:32:44 +08:00
|
|
|
|
m_vButtons.erase(m_vButtons.begin() + i);
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|