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-09-04 22:42:34 +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-09-04 22:42:34 +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-09-04 22:42:34 +08:00
|
|
|
|
this->AddButton(button);
|
2017-11-07 23:32:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
bool e2d::Menu::IsEnable() const
|
2017-11-07 23:32:44 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return enabled_;
|
2017-11-07 23:32:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
size_t e2d::Menu::GetButtonCount() const
|
2017-11-07 23:32:44 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return buttons_.size();
|
2017-11-07 23:32:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Menu::SetEnabled(bool enabled)
|
2017-11-07 23:32:44 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (enabled_ != enabled)
|
2017-11-07 23:32:44 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
enabled_ = enabled;
|
2017-11-08 11:18:11 +08:00
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
for (const auto& button : buttons_)
|
2017-11-08 11:18:11 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
button->SetEnabled(enabled);
|
2017-11-08 11:18:11 +08:00
|
|
|
|
}
|
2017-11-07 23:32:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +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)
|
|
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
this->AddChild(button);
|
|
|
|
|
|
buttons_.push_back(button);
|
|
|
|
|
|
button->SetEnabled(enabled_);
|
2017-11-08 11:18:11 +08:00
|
|
|
|
}
|
2017-11-07 23:32:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
bool e2d::Menu::RemoveButton(Button * button)
|
2017-11-07 23:32:44 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (buttons_.empty())
|
2017-11-07 23:32:44 +08:00
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
this->RemoveChild(button);
|
2017-11-07 23:32:44 +08:00
|
|
|
|
|
|
|
|
|
|
if (button)
|
|
|
|
|
|
{
|
2018-09-04 22:42:34 +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-09-04 22:42:34 +08:00
|
|
|
|
button->SetEnabled(true);
|
|
|
|
|
|
buttons_.erase(iter);
|
2018-08-12 15:38:02 +08:00
|
|
|
|
return true;
|
2017-11-07 23:32:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2018-05-10 14:16:36 +08:00
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
const std::vector<e2d::Button*>& e2d::Menu::GetAllButtons() const
|
2018-05-10 14:16:36 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return buttons_;
|
2018-05-10 14:16:36 +08:00
|
|
|
|
}
|