2012-04-19 14:35:52 +08:00
|
|
|
#include "MenuTest.h"
|
|
|
|
#include "../testResource.h"
|
|
|
|
|
2010-08-28 15:47:51 +08:00
|
|
|
enum {
|
2012-04-19 14:35:52 +08:00
|
|
|
kTagMenu = 1,
|
|
|
|
kTagMenu0 = 0,
|
|
|
|
kTagMenu1 = 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
#define MID_CALLBACK 1000
|
|
|
|
#define MID_CALLBACK2 1001
|
|
|
|
#define MID_DISABLED 1002
|
|
|
|
#define MID_ENABLE 1003
|
|
|
|
#define MID_CONFIG 1004
|
|
|
|
#define MID_QUIT 1005
|
|
|
|
#define MID_OPACITY 1006
|
|
|
|
#define MID_ALIGN 1007
|
|
|
|
#define MID_CALLBACK3 1008
|
|
|
|
#define MID_BACKCALLBACK 1009
|
|
|
|
|
2010-08-28 15:47:51 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
2012-03-22 14:22:06 +08:00
|
|
|
// MenuLayerMainMenu
|
2010-08-28 15:47:51 +08:00
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
2012-03-22 14:22:06 +08:00
|
|
|
MenuLayerMainMenu::MenuLayerMainMenu()
|
2010-08-28 15:47:51 +08:00
|
|
|
{
|
2012-06-15 15:10:40 +08:00
|
|
|
setTouchEnabled(true);
|
2012-11-19 11:24:03 +08:00
|
|
|
setTouchPriority(kCCMenuHandlerPriority + 1);
|
|
|
|
setTouchMode(kCCTouchesOneByOne);
|
2012-11-19 13:57:54 +08:00
|
|
|
|
|
|
|
// Font Item
|
2012-06-14 15:13:16 +08:00
|
|
|
CCSprite* spriteNormal = CCSprite::create(s_MenuItem, CCRectMake(0,23*2,115,23));
|
|
|
|
CCSprite* spriteSelected = CCSprite::create(s_MenuItem, CCRectMake(0,23*1,115,23));
|
|
|
|
CCSprite* spriteDisabled = CCSprite::create(s_MenuItem, CCRectMake(0,23*0,115,23));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCMenuItemSprite* item1 = CCMenuItemSprite::create(spriteNormal, spriteSelected, spriteDisabled, this, menu_selector(MenuLayerMainMenu::menuCallback) );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// Image Item
|
2012-06-14 15:13:16 +08:00
|
|
|
CCMenuItem* item2 = CCMenuItemImage::create(s_SendScore, s_PressSendScore, this, menu_selector(MenuLayerMainMenu::menuCallback2) );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// Label Item (LabelAtlas)
|
2012-06-14 15:13:16 +08:00
|
|
|
CCLabelAtlas* labelAtlas = CCLabelAtlas::create("0123456789", "fonts/labelatlas.png", 16, 24, '.');
|
|
|
|
CCMenuItemLabel* item3 = CCMenuItemLabel::create(labelAtlas, this, menu_selector(MenuLayerMainMenu::menuCallbackDisabled) );
|
2012-04-19 14:35:52 +08:00
|
|
|
item3->setDisabledColor( ccc3(32,32,64) );
|
|
|
|
item3->setColor( ccc3(200,200,255) );
|
|
|
|
|
|
|
|
// Font Item
|
2012-06-14 15:13:16 +08:00
|
|
|
CCMenuItemFont *item4 = CCMenuItemFont::create("I toggle enable items", this, menu_selector(MenuLayerMainMenu::menuCallbackEnable) );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
item4->setFontSizeObj(20);
|
|
|
|
item4->setFontName("Marker Felt");
|
|
|
|
|
|
|
|
// Label Item (CCLabelBMFont)
|
2012-06-14 15:13:16 +08:00
|
|
|
CCLabelBMFont* label = CCLabelBMFont::create("configuration", "fonts/bitmapFontTest3.fnt");
|
|
|
|
CCMenuItemLabel* item5 = CCMenuItemLabel::create(label, this, menu_selector(MenuLayerMainMenu::menuCallbackConfig));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// Testing issue #500
|
|
|
|
item5->setScale( 0.8f );
|
|
|
|
|
|
|
|
// Events
|
|
|
|
CCMenuItemFont::setFontName("Marker Felt");
|
2012-06-14 15:13:16 +08:00
|
|
|
CCMenuItemFont *item6 = CCMenuItemFont::create("Priority Test", this, menu_selector(MenuLayerMainMenu::menuCallbackPriorityTest));
|
2012-11-19 13:57:54 +08:00
|
|
|
|
|
|
|
// Bugs Item
|
|
|
|
CCMenuItemFont *item7 = CCMenuItemFont::create("Bugs", this, menu_selector(MenuLayerMainMenu::menuCallbackBugsTest));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// Font Item
|
2012-11-19 13:57:54 +08:00
|
|
|
CCMenuItemFont* item8 = CCMenuItemFont::create("Quit", this, menu_selector(MenuLayerMainMenu::onQuit));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCActionInterval* color_action = CCTintBy::create(0.5f, 0, -255, -255);
|
2012-04-19 14:35:52 +08:00
|
|
|
CCActionInterval* color_back = color_action->reverse();
|
2012-12-10 14:12:56 +08:00
|
|
|
CCSequence* seq = CCSequence::create(color_action, color_back, NULL);
|
|
|
|
item8->runAction(CCRepeatForever::create(seq));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2012-11-19 13:57:54 +08:00
|
|
|
CCMenu* menu = CCMenu::create( item1, item2, item3, item4, item5, item6, item7, item8, NULL);
|
2012-04-19 14:35:52 +08:00
|
|
|
menu->alignItemsVertically();
|
|
|
|
|
|
|
|
|
|
|
|
// elastic effect
|
|
|
|
CCSize s = CCDirector::sharedDirector()->getWinSize();
|
|
|
|
|
|
|
|
int i=0;
|
|
|
|
CCNode* child;
|
|
|
|
CCArray * pArray = menu->getChildren();
|
2011-04-21 14:46:15 +08:00
|
|
|
CCObject* pObject = NULL;
|
|
|
|
CCARRAY_FOREACH(pArray, pObject)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
if(pObject == NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
child = (CCNode*)pObject;
|
|
|
|
|
|
|
|
CCPoint dstPoint = child->getPosition();
|
|
|
|
int offset = (int) (s.width/2 + 50);
|
|
|
|
if( i % 2 == 0)
|
|
|
|
offset = -offset;
|
|
|
|
|
2012-10-23 17:48:50 +08:00
|
|
|
child->setPosition( ccp( dstPoint.x + offset, dstPoint.y) );
|
2012-04-19 14:35:52 +08:00
|
|
|
child->runAction(
|
2012-10-23 17:48:50 +08:00
|
|
|
CCEaseElasticOut::create(CCMoveBy::create(2, ccp(dstPoint.x - offset,0)), 0.35f)
|
2012-04-19 14:35:52 +08:00
|
|
|
);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_disabledItem = item3; item3->retain();
|
2012-06-15 16:47:30 +08:00
|
|
|
m_disabledItem->setEnabled( false );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
addChild(menu);
|
|
|
|
menu->setPosition(ccp(s.width/2, s.height/2));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MenuLayerMainMenu::ccTouchBegan(CCTouch *touch, CCEvent * pEvent)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MenuLayerMainMenu::ccTouchEnded(CCTouch *touch, CCEvent * pEvent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void MenuLayerMainMenu::ccTouchCancelled(CCTouch *touch, CCEvent * pEvent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void MenuLayerMainMenu::ccTouchMoved(CCTouch *touch, CCEvent * pEvent)
|
|
|
|
{
|
|
|
|
}
|
2011-07-08 15:57:46 +08:00
|
|
|
|
2012-03-22 14:22:06 +08:00
|
|
|
MenuLayerMainMenu::~MenuLayerMainMenu()
|
2010-08-28 15:47:51 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
m_disabledItem->release();
|
2010-08-28 15:47:51 +08:00
|
|
|
}
|
|
|
|
|
2012-03-22 14:22:06 +08:00
|
|
|
void MenuLayerMainMenu::menuCallback(CCObject* sender)
|
2010-08-28 15:47:51 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
((CCLayerMultiplex*)m_pParent)->switchTo(1);
|
2010-08-28 15:47:51 +08:00
|
|
|
}
|
|
|
|
|
2012-03-22 14:22:06 +08:00
|
|
|
void MenuLayerMainMenu::menuCallbackConfig(CCObject* sender)
|
2010-08-28 15:47:51 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
((CCLayerMultiplex*)m_pParent)->switchTo(3);
|
2010-08-28 15:47:51 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void MenuLayerMainMenu::allowTouches(float dt)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
CCDirector* pDirector = CCDirector::sharedDirector();
|
|
|
|
pDirector->getTouchDispatcher()->setPriority(kCCMenuHandlerPriority+1, this);
|
|
|
|
unscheduleAllSelectors();
|
|
|
|
CCLog("TOUCHES ALLOWED AGAIN");
|
2011-07-08 15:57:46 +08:00
|
|
|
}
|
|
|
|
|
2012-03-22 14:22:06 +08:00
|
|
|
void MenuLayerMainMenu::menuCallbackDisabled(CCObject* sender)
|
2010-08-28 15:47:51 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
// hijack all touch events for 5 seconds
|
|
|
|
CCDirector* pDirector = CCDirector::sharedDirector();
|
|
|
|
pDirector->getTouchDispatcher()->setPriority(kCCMenuHandlerPriority-1, this);
|
|
|
|
schedule(schedule_selector(MenuLayerMainMenu::allowTouches), 5.0f);
|
2011-07-08 15:57:46 +08:00
|
|
|
CCLog("TOUCHES DISABLED FOR 5 SECONDS");
|
2010-08-28 15:47:51 +08:00
|
|
|
}
|
|
|
|
|
2012-03-22 14:22:06 +08:00
|
|
|
void MenuLayerMainMenu::menuCallbackEnable(CCObject* sender)
|
2010-08-28 15:47:51 +08:00
|
|
|
{
|
2012-06-15 16:47:30 +08:00
|
|
|
m_disabledItem->setEnabled(! m_disabledItem->isEnabled() );
|
2010-08-28 15:47:51 +08:00
|
|
|
}
|
|
|
|
|
2012-03-22 14:22:06 +08:00
|
|
|
void MenuLayerMainMenu::menuCallback2(CCObject* sender)
|
2010-08-28 15:47:51 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
((CCLayerMultiplex*)m_pParent)->switchTo(2);
|
2010-08-28 15:47:51 +08:00
|
|
|
}
|
|
|
|
|
2012-03-22 14:22:06 +08:00
|
|
|
void MenuLayerMainMenu::menuCallbackPriorityTest(CCObject* pSender)
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
((CCLayerMultiplex*)m_pParent)->switchTo(4);
|
2012-03-22 14:22:06 +08:00
|
|
|
}
|
|
|
|
|
2012-11-19 13:57:54 +08:00
|
|
|
void MenuLayerMainMenu::menuCallbackBugsTest(CCObject *pSender)
|
|
|
|
{
|
|
|
|
((CCLayerMultiplex*)m_pParent)->switchTo(5);
|
|
|
|
}
|
|
|
|
|
2012-03-22 14:22:06 +08:00
|
|
|
void MenuLayerMainMenu::onQuit(CCObject* sender)
|
2010-08-28 15:47:51 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
//[[Director sharedDirector] end];
|
|
|
|
//getCocosApp()->exit();
|
|
|
|
}
|
|
|
|
|
2010-08-28 15:47:51 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// MenuLayer2
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
MenuLayer2::MenuLayer2()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
for( int i=0;i < 2;i++ )
|
|
|
|
{
|
2012-06-14 15:13:16 +08:00
|
|
|
CCMenuItemImage* item1 = CCMenuItemImage::create(s_PlayNormal, s_PlaySelect, this, menu_selector(MenuLayer2::menuCallback));
|
|
|
|
CCMenuItemImage* item2 = CCMenuItemImage::create(s_HighNormal, s_HighSelect, this, menu_selector(MenuLayer2::menuCallbackOpacity) );
|
|
|
|
CCMenuItemImage* item3 = CCMenuItemImage::create(s_AboutNormal, s_AboutSelect, this, menu_selector(MenuLayer2::menuCallbackAlign) );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
item1->setScaleX( 1.5f );
|
|
|
|
item2->setScaleX( 0.5f );
|
|
|
|
item3->setScaleX( 0.5f );
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCMenu* menu = CCMenu::create(item1, item2, item3, NULL);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
CCSize s = CCDirector::sharedDirector()->getWinSize();
|
|
|
|
menu->setPosition(ccp(s.width/2, s.height/2));
|
|
|
|
|
|
|
|
menu->setTag( kTagMenu );
|
|
|
|
|
|
|
|
addChild(menu, 0, 100+i);
|
|
|
|
|
|
|
|
m_centeredMenu = menu->getPosition();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_alignedH = true;
|
|
|
|
alignMenusH();
|
2010-08-28 15:47:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
MenuLayer2::~MenuLayer2()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void MenuLayer2::alignMenusH()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
for(int i=0;i<2;i++)
|
|
|
|
{
|
|
|
|
CCMenu *menu = (CCMenu*)getChildByTag(100+i);
|
|
|
|
menu->setPosition( m_centeredMenu );
|
|
|
|
if(i==0)
|
|
|
|
{
|
|
|
|
// TIP: if no padding, padding = 5
|
|
|
|
menu->alignItemsHorizontally();
|
|
|
|
CCPoint p = menu->getPosition();
|
2012-10-23 17:48:50 +08:00
|
|
|
menu->setPosition( ccpAdd(p, ccp(0,30)) );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// TIP: but padding is configurable
|
|
|
|
menu->alignItemsHorizontallyWithPadding(40);
|
|
|
|
CCPoint p = menu->getPosition();
|
2012-10-23 17:48:50 +08:00
|
|
|
menu->setPosition( ccpSub(p, ccp(0,30)) );
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
2010-08-28 15:47:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MenuLayer2::alignMenusV()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
for(int i=0;i<2;i++)
|
|
|
|
{
|
|
|
|
CCMenu *menu = (CCMenu*)getChildByTag(100+i);
|
|
|
|
menu->setPosition( m_centeredMenu );
|
|
|
|
if(i==0)
|
|
|
|
{
|
|
|
|
// TIP: if no padding, padding = 5
|
|
|
|
menu->alignItemsVertically();
|
|
|
|
CCPoint p = menu->getPosition();
|
2012-10-23 17:48:50 +08:00
|
|
|
menu->setPosition( ccpAdd(p, ccp(100,0)) );
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// TIP: but padding is configurable
|
|
|
|
menu->alignItemsVerticallyWithPadding(40);
|
|
|
|
CCPoint p = menu->getPosition();
|
2012-10-23 17:48:50 +08:00
|
|
|
menu->setPosition( ccpSub(p, ccp(100,0)) );
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
2010-08-28 15:47:51 +08:00
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
void MenuLayer2::menuCallback(CCObject* sender)
|
2010-08-28 15:47:51 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
((CCLayerMultiplex*)m_pParent)->switchTo(0);
|
2010-08-28 15:47:51 +08:00
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
void MenuLayer2::menuCallbackOpacity(CCObject* sender)
|
2010-08-28 15:47:51 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCMenu* menu = (CCMenu*)(((CCNode*)(sender))->getParent());
|
|
|
|
GLubyte opacity = menu->getOpacity();
|
|
|
|
if( opacity == 128 )
|
|
|
|
menu->setOpacity(255);
|
|
|
|
else
|
|
|
|
menu->setOpacity(128);
|
2010-08-28 15:47:51 +08:00
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
void MenuLayer2::menuCallbackAlign(CCObject* sender)
|
2010-08-28 15:47:51 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
m_alignedH = ! m_alignedH;
|
|
|
|
|
|
|
|
if( m_alignedH )
|
|
|
|
alignMenusH();
|
|
|
|
else
|
|
|
|
alignMenusV();
|
|
|
|
}
|
|
|
|
|
2010-08-28 15:47:51 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// MenuLayer3
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
MenuLayer3::MenuLayer3()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCMenuItemFont::setFontName("Marker Felt");
|
|
|
|
CCMenuItemFont::setFontSize(28);
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCLabelBMFont* label = CCLabelBMFont::create("Enable AtlasItem", "fonts/bitmapFontTest3.fnt");
|
|
|
|
CCMenuItemLabel* item1 = CCMenuItemLabel::create(label, this, menu_selector(MenuLayer3::menuCallback2) );
|
|
|
|
CCMenuItemFont* item2 = CCMenuItemFont::create("--- Go Back ---", this, menu_selector(MenuLayer3::menuCallback) );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCSprite *spriteNormal = CCSprite::create(s_MenuItem, CCRectMake(0,23*2,115,23));
|
|
|
|
CCSprite *spriteSelected = CCSprite::create(s_MenuItem, CCRectMake(0,23*1,115,23));
|
|
|
|
CCSprite *spriteDisabled = CCSprite::create(s_MenuItem, CCRectMake(0,23*0,115,23));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCMenuItemSprite* item3 = CCMenuItemSprite::create(spriteNormal, spriteSelected, spriteDisabled, this, menu_selector(MenuLayer3::menuCallback3));
|
2012-04-19 14:35:52 +08:00
|
|
|
m_disabledItem = item3; item3->retain();
|
2012-06-15 16:47:30 +08:00
|
|
|
m_disabledItem->setEnabled( false );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCMenu *menu = CCMenu::create( item1, item2, item3, NULL);
|
2012-10-23 17:48:50 +08:00
|
|
|
menu->setPosition( ccp(0,0) );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
CCSize s = CCDirector::sharedDirector()->getWinSize();
|
|
|
|
|
2012-10-23 17:48:50 +08:00
|
|
|
item1->setPosition( ccp(s.width/2 - 150, s.height/2) );
|
|
|
|
item2->setPosition( ccp(s.width/2 - 200, s.height/2) );
|
|
|
|
item3->setPosition( ccp(s.width/2, s.height/2 - 100) );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2012-10-23 17:48:50 +08:00
|
|
|
CCJumpBy* jump = CCJumpBy::create(3, ccp(400,0), 50, 4);
|
2012-12-10 14:12:56 +08:00
|
|
|
item2->runAction( CCRepeatForever::create(CCSequence::create( jump, jump->reverse(), NULL)));
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCActionInterval* spin1 = CCRotateBy::create(3, 360);
|
2012-04-19 14:35:52 +08:00
|
|
|
CCActionInterval* spin2 = (CCActionInterval*)(spin1->copy()->autorelease());
|
|
|
|
CCActionInterval* spin3 = (CCActionInterval*)(spin1->copy()->autorelease());
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
item1->runAction( CCRepeatForever::create(spin1) );
|
|
|
|
item2->runAction( CCRepeatForever::create(spin2) );
|
|
|
|
item3->runAction( CCRepeatForever::create(spin3) );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
addChild( menu );
|
|
|
|
|
|
|
|
menu->setPosition(ccp(0,0));
|
2010-08-28 15:47:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
MenuLayer3::~MenuLayer3()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
m_disabledItem->release();
|
2010-08-28 15:47:51 +08:00
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
void MenuLayer3::menuCallback(CCObject* sender)
|
2010-08-28 15:47:51 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
((CCLayerMultiplex*)m_pParent)->switchTo(0);
|
2010-08-28 15:47:51 +08:00
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
void MenuLayer3::menuCallback2(CCObject* sender)
|
2010-08-28 15:47:51 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
//UXLOG("Label clicked. Toogling AtlasSprite");
|
2012-06-15 16:47:30 +08:00
|
|
|
m_disabledItem->setEnabled( ! m_disabledItem->isEnabled() );
|
2012-04-19 14:35:52 +08:00
|
|
|
m_disabledItem->stopAllActions();
|
2010-08-28 15:47:51 +08:00
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
void MenuLayer3::menuCallback3(CCObject* sender)
|
2010-08-28 15:47:51 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
//UXLOG("MenuItemSprite clicked");
|
|
|
|
}
|
|
|
|
|
2010-08-28 15:47:51 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// MenuLayer4
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
MenuLayer4::MenuLayer4()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCMenuItemFont::setFontName("American Typewriter");
|
|
|
|
CCMenuItemFont::setFontSize(18);
|
2012-06-14 15:13:16 +08:00
|
|
|
CCMenuItemFont*title1 = CCMenuItemFont::create("Sound");
|
2012-06-15 16:47:30 +08:00
|
|
|
title1->setEnabled(false);
|
2012-04-19 14:35:52 +08:00
|
|
|
CCMenuItemFont::setFontName( "Marker Felt" );
|
|
|
|
CCMenuItemFont::setFontSize(34);
|
2012-07-23 22:49:11 +08:00
|
|
|
CCMenuItemToggle* item1 = CCMenuItemToggle::createWithTarget(this,
|
2012-04-19 14:35:52 +08:00
|
|
|
menu_selector(MenuLayer4::menuCallback),
|
2012-06-14 15:13:16 +08:00
|
|
|
CCMenuItemFont::create( "On" ),
|
|
|
|
CCMenuItemFont::create( "Off"),
|
2012-04-19 14:35:52 +08:00
|
|
|
NULL );
|
2010-08-28 15:47:51 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCMenuItemFont::setFontName( "American Typewriter" );
|
|
|
|
CCMenuItemFont::setFontSize(18);
|
2012-06-14 15:13:16 +08:00
|
|
|
CCMenuItemFont* title2 = CCMenuItemFont::create( "Music" );
|
2012-06-15 16:47:30 +08:00
|
|
|
title2->setEnabled(false);
|
2012-04-19 14:35:52 +08:00
|
|
|
CCMenuItemFont::setFontName( "Marker Felt" );
|
|
|
|
CCMenuItemFont::setFontSize(34);
|
2012-07-23 22:49:11 +08:00
|
|
|
CCMenuItemToggle *item2 = CCMenuItemToggle::createWithTarget(this,
|
2012-04-19 14:35:52 +08:00
|
|
|
menu_selector(MenuLayer4::menuCallback),
|
2012-06-14 15:13:16 +08:00
|
|
|
CCMenuItemFont::create( "On" ),
|
|
|
|
CCMenuItemFont::create( "Off"),
|
2012-04-19 14:35:52 +08:00
|
|
|
NULL );
|
2010-08-28 15:47:51 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCMenuItemFont::setFontName( "American Typewriter" );
|
|
|
|
CCMenuItemFont::setFontSize(18);
|
2012-06-14 15:13:16 +08:00
|
|
|
CCMenuItemFont* title3 = CCMenuItemFont::create( "Quality" );
|
2012-06-15 16:47:30 +08:00
|
|
|
title3->setEnabled( false );
|
2012-04-19 14:35:52 +08:00
|
|
|
CCMenuItemFont::setFontName( "Marker Felt" );
|
|
|
|
CCMenuItemFont::setFontSize(34);
|
2012-07-23 22:49:11 +08:00
|
|
|
CCMenuItemToggle *item3 = CCMenuItemToggle::createWithTarget(this,
|
2012-04-19 14:35:52 +08:00
|
|
|
menu_selector(MenuLayer4::menuCallback),
|
2012-06-14 15:13:16 +08:00
|
|
|
CCMenuItemFont::create( "High" ),
|
|
|
|
CCMenuItemFont::create( "Low" ),
|
2012-04-19 14:35:52 +08:00
|
|
|
NULL );
|
2010-08-28 15:47:51 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCMenuItemFont::setFontName( "American Typewriter" );
|
|
|
|
CCMenuItemFont::setFontSize(18);
|
2012-06-14 15:13:16 +08:00
|
|
|
CCMenuItemFont* title4 = CCMenuItemFont::create( "Orientation" );
|
2012-06-15 16:47:30 +08:00
|
|
|
title4->setEnabled(false);
|
2012-04-19 14:35:52 +08:00
|
|
|
CCMenuItemFont::setFontName( "Marker Felt" );
|
|
|
|
CCMenuItemFont::setFontSize(34);
|
2012-07-23 22:49:11 +08:00
|
|
|
CCMenuItemToggle *item4 = CCMenuItemToggle::createWithTarget(this,
|
2012-04-19 14:35:52 +08:00
|
|
|
menu_selector(MenuLayer4::menuCallback),
|
2012-06-14 15:13:16 +08:00
|
|
|
CCMenuItemFont::create( "Off" ),
|
2012-04-19 14:35:52 +08:00
|
|
|
NULL );
|
|
|
|
|
|
|
|
//UxArray* more_items = UxArray::arrayWithObjects(
|
2012-06-14 15:13:16 +08:00
|
|
|
// CCMenuItemFont::create( "33%" ),
|
|
|
|
// CCMenuItemFont::create( "66%" ),
|
|
|
|
// CCMenuItemFont::create( "100%" ),
|
2012-04-19 14:35:52 +08:00
|
|
|
// NULL );
|
|
|
|
// TIP: you can manipulate the items like any other CCMutableArray
|
2012-06-14 15:13:16 +08:00
|
|
|
item4->getSubItems()->addObject( CCMenuItemFont::create( "33%" ) );
|
|
|
|
item4->getSubItems()->addObject( CCMenuItemFont::create( "66%" ) );
|
|
|
|
item4->getSubItems()->addObject( CCMenuItemFont::create( "100%" ) );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2010-08-28 15:47:51 +08:00
|
|
|
// you can change the one of the items by doing this
|
|
|
|
item4->setSelectedIndex( 2 );
|
|
|
|
|
|
|
|
CCMenuItemFont::setFontName( "Marker Felt" );
|
2012-04-19 14:35:52 +08:00
|
|
|
CCMenuItemFont::setFontSize( 34 );
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCLabelBMFont *label = CCLabelBMFont::create( "go back", "fonts/bitmapFontTest3.fnt" );
|
|
|
|
CCMenuItemLabel* back = CCMenuItemLabel::create(label, this, menu_selector(MenuLayer4::backCallback) );
|
2010-08-28 15:47:51 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCMenu *menu = CCMenu::create(
|
2010-08-28 15:47:51 +08:00
|
|
|
title1, title2,
|
|
|
|
item1, item2,
|
|
|
|
title3, title4,
|
2012-04-19 14:35:52 +08:00
|
|
|
item3, item4,
|
|
|
|
back, NULL ); // 9 items.
|
2010-08-28 15:47:51 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
menu->alignItemsInColumns(2, 2, 2, 2, 1, NULL);
|
2010-08-28 15:47:51 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild( menu );
|
2012-03-22 14:22:06 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCSize s = CCDirector::sharedDirector()->getWinSize();
|
|
|
|
menu->setPosition(ccp(s.width/2, s.height/2));
|
2010-08-28 15:47:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
MenuLayer4::~MenuLayer4()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
void MenuLayer4::menuCallback(CCObject* sender)
|
2010-08-28 15:47:51 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
//UXLOG("selected item: %x index:%d", dynamic_cast<CCMenuItemToggle*>(sender)->selectedItem(), dynamic_cast<CCMenuItemToggle*>(sender)->selectedIndex() );
|
2010-08-28 15:47:51 +08:00
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
void MenuLayer4::backCallback(CCObject* sender)
|
2010-08-28 15:47:51 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
((CCLayerMultiplex*)m_pParent)->switchTo(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
MenuLayerPriorityTest::MenuLayerPriorityTest()
|
|
|
|
{
|
|
|
|
// Testing empty menu
|
2012-06-14 15:13:16 +08:00
|
|
|
m_pMenu1 = CCMenu::create();
|
|
|
|
m_pMenu2 = CCMenu::create();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
|
|
// Menu 1
|
|
|
|
CCMenuItemFont::setFontName("Marker Felt");
|
|
|
|
CCMenuItemFont::setFontSize(18);
|
2012-06-14 15:13:16 +08:00
|
|
|
CCMenuItemFont *item1 = CCMenuItemFont::create("Return to Main Menu", this, menu_selector(MenuLayerPriorityTest::menuCallback));
|
|
|
|
CCMenuItemFont *item2 = CCMenuItemFont::create("Disable menu for 5 seconds", this, menu_selector(MenuLayerPriorityTest::disableMenuCallback));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
|
|
m_pMenu1->addChild(item1);
|
|
|
|
m_pMenu1->addChild(item2);
|
|
|
|
|
|
|
|
m_pMenu1->alignItemsVerticallyWithPadding(2);
|
|
|
|
|
|
|
|
addChild(m_pMenu1);
|
|
|
|
|
|
|
|
// Menu 2
|
|
|
|
m_bPriority = true;
|
|
|
|
CCMenuItemFont::setFontSize(48);
|
2012-06-14 15:13:16 +08:00
|
|
|
item1 = CCMenuItemFont::create("Toggle priority", this, menu_selector(MenuLayerPriorityTest::togglePriorityCallback));
|
2012-04-19 14:35:52 +08:00
|
|
|
item1->setColor(ccc3(0,0,255));
|
|
|
|
m_pMenu2->addChild(item1);
|
|
|
|
addChild(m_pMenu2);
|
|
|
|
}
|
|
|
|
|
|
|
|
MenuLayerPriorityTest::~MenuLayerPriorityTest()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void MenuLayerPriorityTest::menuCallback(CCObject* pSender)
|
|
|
|
{
|
|
|
|
((CCLayerMultiplex*)m_pParent)->switchTo(0);
|
|
|
|
// [[CCDirector sharedDirector] popScene];
|
2012-03-22 14:22:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MenuLayerPriorityTest::disableMenuCallback(CCObject* pSender)
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
m_pMenu1->setEnabled(false);
|
2012-06-14 15:13:16 +08:00
|
|
|
CCDelayTime *wait = CCDelayTime::create(5);
|
|
|
|
CCCallFunc *enable = CCCallFunc::create(this, callfunc_selector(MenuLayerPriorityTest::enableMenuCallback));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2012-12-10 14:12:56 +08:00
|
|
|
CCSequence* seq = CCSequence::create(wait, enable, NULL);
|
2012-04-19 14:35:52 +08:00
|
|
|
m_pMenu1->runAction(seq);
|
2012-03-22 14:22:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MenuLayerPriorityTest::enableMenuCallback()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
m_pMenu1->setEnabled(true);
|
2012-03-22 14:22:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MenuLayerPriorityTest::togglePriorityCallback(CCObject* pSender)
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
if( m_bPriority) {
|
|
|
|
m_pMenu2->setHandlerPriority(kCCMenuHandlerPriority + 20);
|
|
|
|
m_bPriority = false;
|
|
|
|
} else {
|
|
|
|
m_pMenu2->setHandlerPriority(kCCMenuHandlerPriority - 20);
|
|
|
|
m_bPriority = true;
|
|
|
|
}
|
2012-03-22 14:22:06 +08:00
|
|
|
}
|
|
|
|
|
2012-11-19 13:57:54 +08:00
|
|
|
// BugsTest
|
|
|
|
BugsTest::BugsTest()
|
|
|
|
{
|
|
|
|
CCMenuItemFont *issue1410 = CCMenuItemFont::create("Issue 1410", this, menu_selector(BugsTest::issue1410MenuCallback));
|
|
|
|
CCMenuItemFont *issue1410_2 = CCMenuItemFont::create("Issue 1410 #2", this, menu_selector(BugsTest::issue1410v2MenuCallback));
|
|
|
|
CCMenuItemFont *back = CCMenuItemFont::create("Back", this, menu_selector(BugsTest::backMenuCallback));
|
|
|
|
|
|
|
|
CCMenu *menu = CCMenu::create(issue1410, issue1410_2, back, NULL);
|
|
|
|
addChild(menu);
|
|
|
|
menu->alignItemsVertically();
|
|
|
|
|
|
|
|
CCSize s = CCDirector::sharedDirector()->getWinSize();
|
|
|
|
menu->setPosition(ccp(s.width/2, s.height/2));
|
|
|
|
}
|
|
|
|
|
|
|
|
void BugsTest::issue1410MenuCallback(cocos2d::CCObject *pSender)
|
|
|
|
{
|
|
|
|
CCMenu *menu = (CCMenu*)((CCMenuItem*)pSender)->getParent();
|
|
|
|
menu->setTouchEnabled(false);
|
|
|
|
menu->setTouchEnabled(true);
|
|
|
|
|
|
|
|
CCLog("NO CRASHES");
|
|
|
|
}
|
|
|
|
|
|
|
|
void BugsTest::issue1410v2MenuCallback(cocos2d::CCObject *pSender)
|
|
|
|
{
|
|
|
|
CCMenu *menu = (CCMenu*)((CCMenuItem*)pSender)->getParent();
|
|
|
|
menu->setTouchEnabled(true);
|
|
|
|
menu->setTouchEnabled(false);
|
|
|
|
|
|
|
|
CCLog("NO CRASHES. AND MENU SHOULD STOP WORKING");
|
|
|
|
}
|
|
|
|
|
|
|
|
void BugsTest::backMenuCallback(cocos2d::CCObject *pSender)
|
|
|
|
{
|
|
|
|
((CCLayerMultiplex*)m_pParent)->switchTo(0);
|
|
|
|
}
|
|
|
|
|
2010-08-28 15:47:51 +08:00
|
|
|
void MenuTestScene::runThisTest()
|
|
|
|
{
|
2012-03-22 14:22:06 +08:00
|
|
|
CCLayer* pLayer1 = new MenuLayerMainMenu();
|
2010-08-28 15:47:51 +08:00
|
|
|
CCLayer* pLayer2 = new MenuLayer2();
|
|
|
|
CCLayer* pLayer3 = new MenuLayer3();
|
|
|
|
CCLayer* pLayer4 = new MenuLayer4();
|
2012-04-19 14:35:52 +08:00
|
|
|
CCLayer* pLayer5 = new MenuLayerPriorityTest();
|
2012-11-19 13:57:54 +08:00
|
|
|
CCLayer* pLayer6 = new BugsTest();
|
2010-08-28 15:47:51 +08:00
|
|
|
|
2012-11-19 13:57:54 +08:00
|
|
|
CCLayerMultiplex* layer = CCLayerMultiplex::create(pLayer1, pLayer2, pLayer3, pLayer4, pLayer5, pLayer6, NULL);
|
2010-08-28 15:47:51 +08:00
|
|
|
addChild(layer, 0);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
pLayer1->release();
|
|
|
|
pLayer2->release();
|
|
|
|
pLayer3->release();
|
|
|
|
pLayer4->release();
|
|
|
|
pLayer5->release();
|
2012-11-19 13:57:54 +08:00
|
|
|
pLayer6->release();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2010-11-11 11:18:58 +08:00
|
|
|
CCDirector::sharedDirector()->replaceScene(this);
|
2010-08-28 15:47:51 +08:00
|
|
|
}
|