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()
|
2018-07-04 17:00:21 +08:00
|
|
|
|
: _enabled(true)
|
2017-11-07 23:32:44 +08:00
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-10 17:02:18 +08:00
|
|
|
|
e2d::Menu::Menu(const std::vector<Button*>& buttons)
|
2018-07-04 17:00:21 +08:00
|
|
|
|
: _enabled(true)
|
2018-04-02 23:01:38 +08:00
|
|
|
|
{
|
2018-08-12 14:30:28 +08:00
|
|
|
|
for (const auto& button : buttons)
|
2017-11-07 23:32:44 +08:00
|
|
|
|
{
|
2018-05-10 00:58:43 +08:00
|
|
|
|
this->addButton(button);
|
2017-11-07 23:32:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-08-23 16:37:44 +08:00
|
|
|
|
bool e2d::Menu::enabled() const
|
2017-11-07 23:32:44 +08:00
|
|
|
|
{
|
2018-07-04 17:00:21 +08:00
|
|
|
|
return _enabled;
|
2017-11-07 23:32:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-08-23 16:37:44 +08:00
|
|
|
|
int e2d::Menu::buttonCount() const
|
2017-11-07 23:32:44 +08:00
|
|
|
|
{
|
2018-08-23 16:37:44 +08:00
|
|
|
|
return static_cast<int>(_buttons.size());
|
2017-11-07 23:32:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-08-23 16:37:44 +08:00
|
|
|
|
e2d::Menu& e2d::Menu::enabled(bool enabled)
|
2017-11-07 23:32:44 +08:00
|
|
|
|
{
|
2018-07-04 17:00:21 +08:00
|
|
|
|
if (_enabled != enabled)
|
2017-11-07 23:32:44 +08:00
|
|
|
|
{
|
2018-07-04 17:00:21 +08:00
|
|
|
|
_enabled = enabled;
|
2017-11-08 11:18:11 +08:00
|
|
|
|
|
2018-08-12 14:30:28 +08:00
|
|
|
|
for (const auto& button : _buttons)
|
2017-11-08 11:18:11 +08:00
|
|
|
|
{
|
2018-08-23 16:37:44 +08:00
|
|
|
|
button->enabled(enabled);
|
2017-11-08 11:18:11 +08:00
|
|
|
|
}
|
2017-11-07 23:32:44 +08:00
|
|
|
|
}
|
2018-08-23 16:37:44 +08:00
|
|
|
|
return *this;
|
2017-11-07 23:32:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-08-23 16:37:44 +08:00
|
|
|
|
e2d::Menu& 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);
|
2018-05-09 00:34:15 +08:00
|
|
|
|
_buttons.push_back(button);
|
2018-08-23 16:37:44 +08:00
|
|
|
|
button->enabled(_enabled);
|
2017-11-08 11:18:11 +08:00
|
|
|
|
}
|
2018-08-23 16:37:44 +08:00
|
|
|
|
return *this;
|
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
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
if (_buttons.empty())
|
2017-11-07 23:32:44 +08:00
|
|
|
|
{
|
|
|
|
|
|
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())
|
2017-11-07 23:32:44 +08:00
|
|
|
|
{
|
2018-08-12 15:38:02 +08:00
|
|
|
|
// <20>Ƴ<EFBFBD><C6B3><EFBFBD>ťǰ<C5A5><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2018-08-23 16:37:44 +08:00
|
|
|
|
button->enabled(true);
|
2018-08-12 15:38:02 +08:00
|
|
|
|
_buttons.erase(iter);
|
|
|
|
|
|
return true;
|
2017-11-07 23:32:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2018-05-10 14:16:36 +08:00
|
|
|
|
|
2018-08-23 16:37:44 +08:00
|
|
|
|
const std::vector<e2d::Button*>& e2d::Menu::buttons() const
|
2018-05-10 14:16:36 +08:00
|
|
|
|
{
|
|
|
|
|
|
return _buttons;
|
|
|
|
|
|
}
|