Magic_Game/core/Node/Menu.cpp

77 lines
1.1 KiB
C++
Raw Normal View History

2018-04-21 21:24:46 +08:00
#include "..\e2dnode.h"
e2d::Menu::Menu()
2018-07-04 17:00:21 +08:00
: _enabled(true)
{
}
e2d::Menu::Menu(const std::vector<Button*>& buttons)
2018-07-04 17:00:21 +08:00
: _enabled(true)
{
2018-08-12 14:30:28 +08:00
for (const auto& button : buttons)
{
2018-05-10 00:58:43 +08:00
this->addButton(button);
}
}
bool e2d::Menu::isEnable() const
{
2018-07-04 17:00:21 +08:00
return _enabled;
}
size_t e2d::Menu::getButtonCount() const
{
return _buttons.size();
}
void e2d::Menu::setEnabled(bool enabled)
{
2018-07-04 17:00:21 +08:00
if (_enabled != enabled)
{
2018-07-04 17:00:21 +08:00
_enabled = enabled;
2018-08-12 14:30:28 +08:00
for (const auto& button : _buttons)
{
button->setEnabled(enabled);
}
}
}
void e2d::Menu::addButton(Button * button)
{
if (button)
{
this->addChild(button);
_buttons.push_back(button);
button->setEnabled(_enabled);
}
}
bool e2d::Menu::removeButton(Button * button)
{
if (_buttons.empty())
{
return false;
}
this->removeChild(button);
if (button)
{
2018-08-12 15:38:02 +08:00
auto iter = std::find(_buttons.begin(), _buttons.end(), button);
if (iter != _buttons.end())
{
2018-08-12 15:38:02 +08:00
// <20>Ƴ<EFBFBD><C6B3><EFBFBD>ťǰ<C5A5><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
button->setEnabled(true);
2018-08-12 15:38:02 +08:00
_buttons.erase(iter);
return true;
}
}
return false;
}
2018-05-10 14:16:36 +08:00
const std::vector<e2d::Button*>& e2d::Menu::getAllButtons() const
2018-05-10 14:16:36 +08:00
{
return _buttons;
}