Magic_Game/core/components/Menu.cpp

77 lines
1.1 KiB
C++
Raw Normal View History

2018-09-05 13:17:07 +08:00
#include "..\e2dcomponent.h"
e2d::Menu::Menu()
2018-09-04 22:42:34 +08:00
: enabled_(true)
{
}
e2d::Menu::Menu(const std::vector<Button*>& buttons)
2018-09-04 22:42:34 +08:00
: enabled_(true)
{
2018-08-12 14:30:28 +08:00
for (const auto& button : buttons)
{
2018-09-04 22:42:34 +08:00
this->AddButton(button);
}
}
2018-09-04 22:42:34 +08:00
bool e2d::Menu::IsEnable() const
{
2018-09-04 22:42:34 +08:00
return enabled_;
}
2018-09-04 22:42:34 +08:00
size_t e2d::Menu::GetButtonCount() const
{
2018-09-04 22:42:34 +08:00
return buttons_.size();
}
2018-09-04 22:42:34 +08:00
void e2d::Menu::SetEnabled(bool enabled)
{
2018-09-04 22:42:34 +08:00
if (enabled_ != enabled)
{
2018-09-04 22:42:34 +08:00
enabled_ = enabled;
2018-09-04 22:42:34 +08:00
for (const auto& button : buttons_)
{
2018-09-04 22:42:34 +08:00
button->SetEnabled(enabled);
}
}
}
2018-09-04 22:42:34 +08:00
void e2d::Menu::AddButton(Button * button)
{
if (button)
{
2018-09-04 22:42:34 +08:00
this->AddChild(button);
buttons_.push_back(button);
button->SetEnabled(enabled_);
}
}
2018-09-04 22:42:34 +08:00
bool e2d::Menu::RemoveButton(Button * button)
{
2018-09-04 22:42:34 +08:00
if (buttons_.empty())
{
return false;
}
2018-09-04 22:42:34 +08:00
this->RemoveChild(button);
if (button)
{
2018-09-04 22:42:34 +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>
2018-09-04 22:42:34 +08:00
button->SetEnabled(true);
buttons_.erase(iter);
2018-08-12 15:38:02 +08:00
return true;
}
}
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
}