mirror of https://github.com/axmolengine/axmol.git
Merge pull request #15902 from ricardoquesada/little_menu_fixes
fix: little menu fixes
This commit is contained in:
commit
63e72ecf70
|
@ -238,10 +238,9 @@ void Menu::onExit()
|
||||||
|
|
||||||
void Menu::removeChild(Node* child, bool cleanup)
|
void Menu::removeChild(Node* child, bool cleanup)
|
||||||
{
|
{
|
||||||
MenuItem *menuItem = dynamic_cast<MenuItem*>(child);
|
CCASSERT(dynamic_cast<MenuItem*>(child) != nullptr, "Menu only supports MenuItem objects as children");
|
||||||
CCASSERT(menuItem != nullptr, "Menu only supports MenuItem objects as children");
|
|
||||||
|
|
||||||
if (_selectedItem == menuItem)
|
if (_selectedItem == child)
|
||||||
{
|
{
|
||||||
_selectedItem = nullptr;
|
_selectedItem = nullptr;
|
||||||
}
|
}
|
||||||
|
@ -266,8 +265,8 @@ bool Menu::onTouchBegan(Touch* touch, Event* event)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_selectedItem = this->getItemForTouch(touch, camera);
|
_selectedItem = this->getItemForTouch(touch, camera);
|
||||||
|
|
||||||
if (_selectedItem)
|
if (_selectedItem)
|
||||||
{
|
{
|
||||||
_state = Menu::State::TRACKING_TOUCH;
|
_state = Menu::State::TRACKING_TOUCH;
|
||||||
|
@ -559,21 +558,18 @@ void Menu::alignItemsInRowsWithArray(const ValueVector& columns)
|
||||||
MenuItem* Menu::getItemForTouch(Touch *touch, const Camera *camera)
|
MenuItem* Menu::getItemForTouch(Touch *touch, const Camera *camera)
|
||||||
{
|
{
|
||||||
Vec2 touchLocation = touch->getLocation();
|
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*>(item);
|
||||||
|
if (nullptr == child || false == child->isVisible() || false == child->isEnabled())
|
||||||
{
|
{
|
||||||
MenuItem* child = dynamic_cast<MenuItem*>(*iter);
|
continue;
|
||||||
if (nullptr == child || false == child->isVisible() || false == child->isEnabled())
|
}
|
||||||
{
|
Rect rect;
|
||||||
continue;
|
rect.size = child->getContentSize();
|
||||||
}
|
if (isScreenPointInRect(touchLocation, camera, child->getWorldToNodeTransform(), rect, nullptr))
|
||||||
Rect rect;
|
{
|
||||||
rect.size = child->getContentSize();
|
return child;
|
||||||
if (isScreenPointInRect(touchLocation, camera, child->getWorldToNodeTransform(), rect, nullptr))
|
|
||||||
{
|
|
||||||
return child;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
Loading…
Reference in New Issue