Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Method to create a CCMenuItemToggle from a CCArray with a target selector #2143

Merged
merged 1 commit into from May 7, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions cocos2dx/menu_nodes/CCMenuItem.cpp
Expand Up @@ -714,6 +714,24 @@ CCArray* CCMenuItemToggle::getSubItems()
return m_pSubItems;
}

CCMenuItemToggle * CCMenuItemToggle::createWithTarget(CCObject* target, SEL_MenuHandler selector, CCArray* menuItems)
{
CCMenuItemToggle *pRet = new CCMenuItemToggle();
pRet->CCMenuItem::initWithTarget(target, selector);
pRet->m_pSubItems = CCArray::create();
pRet->m_pSubItems->retain();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not determine the return value of pRet and initWithTarget?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I didn't get your statement.


for (int z=0; z < menuItems->count(); z++)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not determine the validation of menuItems?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validation can be added but are you sure that we have validation for cases as well while creating a CCMenuItemToggle object?

I didn't find any.

Check the method body of:

bool CCMenuItemToggle::initWithTarget(CCObject* target, SEL_MenuHandler selector, CCMenuItem* item, va_list args)

and

CCMenuItemToggle * CCMenuItemToggle::createWithTarget(CCObject* target, SEL_MenuHandler selector, CCMenuItem* item, ...)

{
CCMenuItem* menuItem = (CCMenuItem*)menuItems->objectAtIndex(z);
pRet->m_pSubItems->addObject(menuItem);
}

pRet->m_uSelectedIndex = UINT_MAX;
pRet->setSelectedIndex(0);
return pRet;
}

CCMenuItemToggle * CCMenuItemToggle::createWithTarget(CCObject* target, SEL_MenuHandler selector, CCMenuItem* item, ...)
{
va_list args;
Expand Down
3 changes: 3 additions & 0 deletions cocos2dx/menu_nodes/CCMenuItem.h
Expand Up @@ -322,6 +322,9 @@ class CC_DLL CCMenuItemToggle : public CCMenuItem
, m_pSubItems(NULL)
{}
virtual ~CCMenuItemToggle();

** creates a menu item from a CCArray with a target selector */
static CCMenuItemToggle * createWithTarget(CCObject* target, SEL_MenuHandler selector, CCArray* menuItems);

/** creates a menu item from a list of items with a target/selector */
static CCMenuItemToggle* createWithTarget(CCObject* target, SEL_MenuHandler selector, CCMenuItem* item, ...);
Expand Down