Merge pull request #15902 from ricardoquesada/little_menu_fixes

fix: little menu fixes
This commit is contained in:
Ricardo Quesada 2016-06-21 17:19:27 -07:00 committed by GitHub
commit 63e72ecf70
1 changed files with 13 additions and 17 deletions

View File

@ -238,10 +238,9 @@ void Menu::onExit()
void Menu::removeChild(Node* child, bool cleanup)
{
MenuItem *menuItem = dynamic_cast<MenuItem*>(child);
CCASSERT(menuItem != nullptr, "Menu only supports MenuItem objects as children");
CCASSERT(dynamic_cast<MenuItem*>(child) != nullptr, "Menu only supports MenuItem objects as children");
if (_selectedItem == menuItem)
if (_selectedItem == child)
{
_selectedItem = nullptr;
}
@ -266,8 +265,8 @@ bool Menu::onTouchBegan(Touch* touch, Event* event)
return false;
}
}
_selectedItem = this->getItemForTouch(touch, camera);
if (_selectedItem)
{
_state = Menu::State::TRACKING_TOUCH;
@ -559,11 +558,9 @@ void Menu::alignItemsInRowsWithArray(const ValueVector& columns)
MenuItem* Menu::getItemForTouch(Touch *touch, const Camera *camera)
{
Vec2 touchLocation = touch->getLocation();
if (!_children.empty())
for (const auto &item: _children)
{
for (auto iter = _children.crbegin(); iter != _children.crend(); ++iter)
{
MenuItem* child = dynamic_cast<MenuItem*>(*iter);
MenuItem* child = dynamic_cast<MenuItem*>(item);
if (nullptr == child || false == child->isVisible() || false == child->isEnabled())
{
continue;
@ -575,7 +572,6 @@ MenuItem* Menu::getItemForTouch(Touch *touch, const Camera *camera)
return child;
}
}
}
return nullptr;
}