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);
|
2013-06-20 14:17:10 +08:00
|
|
|
setTouchPriority(kMenuHandlerPriority + 1);
|
|
|
|
setTouchMode(kTouchesOneByOne);
|
2012-11-19 13:57:54 +08:00
|
|
|
|
|
|
|
// Font Item
|
2013-06-20 14:17:10 +08:00
|
|
|
Sprite* spriteNormal = Sprite::create(s_MenuItem, CCRectMake(0,23*2,115,23));
|
|
|
|
Sprite* spriteSelected = Sprite::create(s_MenuItem, CCRectMake(0,23*1,115,23));
|
|
|
|
Sprite* spriteDisabled = Sprite::create(s_MenuItem, CCRectMake(0,23*0,115,23));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
MenuItemSprite* item1 = MenuItemSprite::create(spriteNormal, spriteSelected, spriteDisabled, CC_CALLBACK_1(MenuLayerMainMenu::menuCallback, this) );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// Image Item
|
2013-06-20 14:17:10 +08:00
|
|
|
MenuItem* item2 = MenuItemImage::create(s_SendScore, s_PressSendScore, CC_CALLBACK_1(MenuLayerMainMenu::menuCallback2, this) );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// Label Item (LabelAtlas)
|
2013-06-20 14:17:10 +08:00
|
|
|
LabelAtlas* labelAtlas = LabelAtlas::create("0123456789", "fonts/labelatlas.png", 16, 24, '.');
|
|
|
|
MenuItemLabel* item3 = MenuItemLabel::create(labelAtlas, CC_CALLBACK_1(MenuLayerMainMenu::menuCallbackDisabled, this) );
|
2012-04-19 14:35:52 +08:00
|
|
|
item3->setDisabledColor( ccc3(32,32,64) );
|
|
|
|
item3->setColor( ccc3(200,200,255) );
|
|
|
|
|
|
|
|
// Font Item
|
2013-06-20 14:17:10 +08:00
|
|
|
MenuItemFont *item4 = MenuItemFont::create("I toggle enable items", [&](Object *sender) {
|
2013-06-15 14:03:30 +08:00
|
|
|
_disabledItem->setEnabled(! _disabledItem->isEnabled() );
|
2013-06-06 08:51:40 +08:00
|
|
|
});
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
item4->setFontSizeObj(20);
|
|
|
|
item4->setFontName("Marker Felt");
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
// Label Item (LabelBMFont)
|
|
|
|
LabelBMFont* label = LabelBMFont::create("configuration", "fonts/bitmapFontTest3.fnt");
|
|
|
|
MenuItemLabel* item5 = MenuItemLabel::create(label, CC_CALLBACK_1(MenuLayerMainMenu::menuCallbackConfig, this));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// Testing issue #500
|
|
|
|
item5->setScale( 0.8f );
|
|
|
|
|
|
|
|
// Events
|
2013-06-20 14:17:10 +08:00
|
|
|
MenuItemFont::setFontName("Marker Felt");
|
|
|
|
MenuItemFont *item6 = MenuItemFont::create("Priority Test", CC_CALLBACK_1(MenuLayerMainMenu::menuCallbackPriorityTest, this));
|
2012-11-19 13:57:54 +08:00
|
|
|
|
|
|
|
// Bugs Item
|
2013-06-20 14:17:10 +08:00
|
|
|
MenuItemFont *item7 = MenuItemFont::create("Bugs", CC_CALLBACK_1(MenuLayerMainMenu::menuCallbackBugsTest, this));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// Font Item
|
2013-06-20 14:17:10 +08:00
|
|
|
MenuItemFont* item8 = MenuItemFont::create("Quit", CC_CALLBACK_1(MenuLayerMainMenu::onQuit, this));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
MenuItemFont* item9 = MenuItemFont::create("Remove menu item when moving", CC_CALLBACK_1(MenuLayerMainMenu::menuMovingCallback, this));
|
2013-01-17 15:04:48 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
ActionInterval* color_action = TintBy::create(0.5f, 0, -255, -255);
|
|
|
|
ActionInterval* color_back = color_action->reverse();
|
|
|
|
Sequence* seq = Sequence::create(color_action, color_back, NULL);
|
|
|
|
item8->runAction(RepeatForever::create(seq));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Menu* menu = Menu::create( item1, item2, item3, item4, item5, item6, item7, item8, item9, NULL);
|
2012-04-19 14:35:52 +08:00
|
|
|
menu->alignItemsVertically();
|
|
|
|
|
|
|
|
|
|
|
|
// elastic effect
|
2013-06-20 14:17:10 +08:00
|
|
|
Size s = Director::sharedDirector()->getWinSize();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
int i=0;
|
2013-06-20 14:17:10 +08:00
|
|
|
Node* child;
|
|
|
|
Array * pArray = menu->getChildren();
|
|
|
|
Object* pObject = NULL;
|
2011-04-21 14:46:15 +08:00
|
|
|
CCARRAY_FOREACH(pArray, pObject)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
if(pObject == NULL)
|
|
|
|
break;
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
child = (Node*)pObject;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Point dstPoint = child->getPosition();
|
2012-04-19 14:35:52 +08:00
|
|
|
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(
|
2013-06-20 14:17:10 +08:00
|
|
|
EaseElasticOut::create(MoveBy::create(2, ccp(dstPoint.x - offset,0)), 0.35f)
|
2012-04-19 14:35:52 +08:00
|
|
|
);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_disabledItem = item3; item3->retain();
|
|
|
|
_disabledItem->setEnabled( false );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
addChild(menu);
|
|
|
|
menu->setPosition(ccp(s.width/2, s.height/2));
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
bool MenuLayerMainMenu::ccTouchBegan(Touch *touch, Event * pEvent)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void MenuLayerMainMenu::ccTouchEnded(Touch *touch, Event * pEvent)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void MenuLayerMainMenu::ccTouchCancelled(Touch *touch, Event * pEvent)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void MenuLayerMainMenu::ccTouchMoved(Touch *touch, Event * pEvent)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
}
|
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
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_disabledItem->release();
|
2010-08-28 15:47:51 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void MenuLayerMainMenu::menuCallback(Object* sender)
|
2010-08-28 15:47:51 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
((LayerMultiplex*)_parent)->switchTo(1);
|
2010-08-28 15:47:51 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void MenuLayerMainMenu::menuCallbackConfig(Object* sender)
|
2010-08-28 15:47:51 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
((LayerMultiplex*)_parent)->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
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Director* pDirector = Director::sharedDirector();
|
|
|
|
pDirector->getTouchDispatcher()->setPriority(kMenuHandlerPriority+1, this);
|
2012-04-19 14:35:52 +08:00
|
|
|
unscheduleAllSelectors();
|
|
|
|
CCLog("TOUCHES ALLOWED AGAIN");
|
2011-07-08 15:57:46 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void MenuLayerMainMenu::menuCallbackDisabled(Object* sender)
|
2010-08-28 15:47:51 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
// hijack all touch events for 5 seconds
|
2013-06-20 14:17:10 +08:00
|
|
|
Director* pDirector = Director::sharedDirector();
|
|
|
|
pDirector->getTouchDispatcher()->setPriority(kMenuHandlerPriority-1, this);
|
2012-04-19 14:35:52 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void MenuLayerMainMenu::menuCallback2(Object* sender)
|
2010-08-28 15:47:51 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
((LayerMultiplex*)_parent)->switchTo(2);
|
2010-08-28 15:47:51 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void MenuLayerMainMenu::menuCallbackPriorityTest(Object* pSender)
|
2012-03-22 14:22:06 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
((LayerMultiplex*)_parent)->switchTo(4);
|
2012-03-22 14:22:06 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void MenuLayerMainMenu::menuCallbackBugsTest(Object *pSender)
|
2012-11-19 13:57:54 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
((LayerMultiplex*)_parent)->switchTo(5);
|
2012-11-19 13:57:54 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void MenuLayerMainMenu::onQuit(Object* sender)
|
2010-08-28 15:47:51 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
//[[Director sharedDirector] end];
|
|
|
|
//getCocosApp()->exit();
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void MenuLayerMainMenu::menuMovingCallback(Object *pSender)
|
2013-01-17 15:04:48 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
((LayerMultiplex*)_parent)->switchTo(6);
|
2013-01-17 15:04:48 +08:00
|
|
|
}
|
|
|
|
|
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++ )
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
MenuItemImage* item1 = MenuItemImage::create(s_PlayNormal, s_PlaySelect, CC_CALLBACK_1(MenuLayer2::menuCallback, this));
|
|
|
|
MenuItemImage* item2 = MenuItemImage::create(s_HighNormal, s_HighSelect, CC_CALLBACK_1(MenuLayer2::menuCallbackOpacity, this));
|
|
|
|
MenuItemImage* item3 = MenuItemImage::create(s_AboutNormal, s_AboutSelect, CC_CALLBACK_1(MenuLayer2::menuCallbackAlign, this));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
item1->setScaleX( 1.5f );
|
|
|
|
item2->setScaleX( 0.5f );
|
|
|
|
item3->setScaleX( 0.5f );
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Menu* menu = Menu::create(item1, item2, item3, NULL);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Size s = Director::sharedDirector()->getWinSize();
|
2012-04-19 14:35:52 +08:00
|
|
|
menu->setPosition(ccp(s.width/2, s.height/2));
|
|
|
|
|
|
|
|
menu->setTag( kTagMenu );
|
|
|
|
|
|
|
|
addChild(menu, 0, 100+i);
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_centeredMenu = menu->getPosition();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_alignedH = true;
|
2012-04-19 14:35:52 +08:00
|
|
|
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++)
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Menu *menu = (Menu*)getChildByTag(100+i);
|
2013-06-15 14:03:30 +08:00
|
|
|
menu->setPosition( _centeredMenu );
|
2012-04-19 14:35:52 +08:00
|
|
|
if(i==0)
|
|
|
|
{
|
|
|
|
// TIP: if no padding, padding = 5
|
|
|
|
menu->alignItemsHorizontally();
|
2013-06-20 14:17:10 +08:00
|
|
|
Point 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);
|
2013-06-20 14:17:10 +08:00
|
|
|
Point 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++)
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Menu *menu = (Menu*)getChildByTag(100+i);
|
2013-06-15 14:03:30 +08:00
|
|
|
menu->setPosition( _centeredMenu );
|
2012-04-19 14:35:52 +08:00
|
|
|
if(i==0)
|
|
|
|
{
|
|
|
|
// TIP: if no padding, padding = 5
|
|
|
|
menu->alignItemsVertically();
|
2013-06-20 14:17:10 +08:00
|
|
|
Point 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);
|
2013-06-20 14:17:10 +08:00
|
|
|
Point 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
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void MenuLayer2::menuCallback(Object* sender)
|
2010-08-28 15:47:51 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
((LayerMultiplex*)_parent)->switchTo(0);
|
2010-08-28 15:47:51 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void MenuLayer2::menuCallbackOpacity(Object* sender)
|
2010-08-28 15:47:51 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Menu* menu = (Menu*)(((Node*)(sender))->getParent());
|
2012-04-19 14:35:52 +08:00
|
|
|
GLubyte opacity = menu->getOpacity();
|
|
|
|
if( opacity == 128 )
|
|
|
|
menu->setOpacity(255);
|
|
|
|
else
|
|
|
|
menu->setOpacity(128);
|
2010-08-28 15:47:51 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void MenuLayer2::menuCallbackAlign(Object* sender)
|
2010-08-28 15:47:51 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_alignedH = ! _alignedH;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if( _alignedH )
|
2012-04-19 14:35:52 +08:00
|
|
|
alignMenusH();
|
|
|
|
else
|
|
|
|
alignMenusV();
|
|
|
|
}
|
|
|
|
|
2010-08-28 15:47:51 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// MenuLayer3
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
MenuLayer3::MenuLayer3()
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
MenuItemFont::setFontName("Marker Felt");
|
|
|
|
MenuItemFont::setFontSize(28);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
LabelBMFont* label = LabelBMFont::create("Enable AtlasItem", "fonts/bitmapFontTest3.fnt");
|
|
|
|
MenuItemLabel* item1 = MenuItemLabel::create(label, [&](Object *sender) {
|
2013-06-06 08:51:40 +08:00
|
|
|
//CCLOG("Label clicked. Toogling AtlasSprite");
|
2013-06-15 14:03:30 +08:00
|
|
|
_disabledItem->setEnabled( ! _disabledItem->isEnabled() );
|
|
|
|
_disabledItem->stopAllActions();
|
2013-06-06 08:51:40 +08:00
|
|
|
});
|
2013-06-20 14:17:10 +08:00
|
|
|
MenuItemFont* item2 = MenuItemFont::create("--- Go Back ---", [&](Object *sender) {
|
|
|
|
((LayerMultiplex*)_parent)->switchTo(0);
|
2013-06-06 08:51:40 +08:00
|
|
|
});
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Sprite *spriteNormal = Sprite::create(s_MenuItem, CCRectMake(0,23*2,115,23));
|
|
|
|
Sprite *spriteSelected = Sprite::create(s_MenuItem, CCRectMake(0,23*1,115,23));
|
|
|
|
Sprite *spriteDisabled = Sprite::create(s_MenuItem, CCRectMake(0,23*0,115,23));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
MenuItemSprite* item3 = MenuItemSprite::create(spriteNormal, spriteSelected, spriteDisabled, [](Object *sender) {
|
2013-06-06 08:51:40 +08:00
|
|
|
CCLog("sprite clicked!");
|
|
|
|
});
|
2013-06-15 14:03:30 +08:00
|
|
|
_disabledItem = item3; item3->retain();
|
|
|
|
_disabledItem->setEnabled( false );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Menu *menu = Menu::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
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Size s = Director::sharedDirector()->getWinSize();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
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
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
JumpBy* jump = JumpBy::create(3, ccp(400,0), 50, 4);
|
|
|
|
item2->runAction( RepeatForever::create(Sequence::create( jump, jump->reverse(), NULL)));
|
2012-12-10 14:12:56 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
ActionInterval* spin1 = RotateBy::create(3, 360);
|
|
|
|
ActionInterval* spin2 = spin1->clone();
|
|
|
|
ActionInterval* spin3 = spin1->clone();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
item1->runAction( RepeatForever::create(spin1) );
|
|
|
|
item2->runAction( RepeatForever::create(spin2) );
|
|
|
|
item3->runAction( RepeatForever::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()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_disabledItem->release();
|
2010-08-28 15:47:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// MenuLayer4
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
MenuLayer4::MenuLayer4()
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
MenuItemFont::setFontName("American Typewriter");
|
|
|
|
MenuItemFont::setFontSize(18);
|
|
|
|
MenuItemFont*title1 = MenuItemFont::create("Sound");
|
2012-06-15 16:47:30 +08:00
|
|
|
title1->setEnabled(false);
|
2013-06-20 14:17:10 +08:00
|
|
|
MenuItemFont::setFontName( "Marker Felt" );
|
|
|
|
MenuItemFont::setFontSize(34);
|
|
|
|
MenuItemToggle* item1 = MenuItemToggle::createWithCallback( CC_CALLBACK_1(MenuLayer4::menuCallback, this),
|
|
|
|
MenuItemFont::create( "On" ),
|
|
|
|
MenuItemFont::create( "Off"),
|
2012-04-19 14:35:52 +08:00
|
|
|
NULL );
|
2010-08-28 15:47:51 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
MenuItemFont::setFontName( "American Typewriter" );
|
|
|
|
MenuItemFont::setFontSize(18);
|
|
|
|
MenuItemFont* title2 = MenuItemFont::create( "Music" );
|
2012-06-15 16:47:30 +08:00
|
|
|
title2->setEnabled(false);
|
2013-06-20 14:17:10 +08:00
|
|
|
MenuItemFont::setFontName( "Marker Felt" );
|
|
|
|
MenuItemFont::setFontSize(34);
|
|
|
|
MenuItemToggle *item2 = MenuItemToggle::createWithCallback(CC_CALLBACK_1(MenuLayer4::menuCallback, this),
|
|
|
|
MenuItemFont::create( "On" ),
|
|
|
|
MenuItemFont::create( "Off"),
|
2012-04-19 14:35:52 +08:00
|
|
|
NULL );
|
2010-08-28 15:47:51 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
MenuItemFont::setFontName( "American Typewriter" );
|
|
|
|
MenuItemFont::setFontSize(18);
|
|
|
|
MenuItemFont* title3 = MenuItemFont::create( "Quality" );
|
2012-06-15 16:47:30 +08:00
|
|
|
title3->setEnabled( false );
|
2013-06-20 14:17:10 +08:00
|
|
|
MenuItemFont::setFontName( "Marker Felt" );
|
|
|
|
MenuItemFont::setFontSize(34);
|
|
|
|
MenuItemToggle *item3 = MenuItemToggle::createWithCallback(CC_CALLBACK_1(MenuLayer4::menuCallback, this),
|
|
|
|
MenuItemFont::create( "High" ),
|
|
|
|
MenuItemFont::create( "Low" ),
|
2012-04-19 14:35:52 +08:00
|
|
|
NULL );
|
2010-08-28 15:47:51 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
MenuItemFont::setFontName( "American Typewriter" );
|
|
|
|
MenuItemFont::setFontSize(18);
|
|
|
|
MenuItemFont* title4 = MenuItemFont::create( "Orientation" );
|
2012-06-15 16:47:30 +08:00
|
|
|
title4->setEnabled(false);
|
2013-06-20 14:17:10 +08:00
|
|
|
MenuItemFont::setFontName( "Marker Felt" );
|
|
|
|
MenuItemFont::setFontSize(34);
|
|
|
|
MenuItemToggle *item4 = MenuItemToggle::createWithCallback(CC_CALLBACK_1(MenuLayer4::menuCallback, this),
|
|
|
|
MenuItemFont::create( "Off" ),
|
2012-04-19 14:35:52 +08:00
|
|
|
NULL );
|
|
|
|
|
|
|
|
//UxArray* more_items = UxArray::arrayWithObjects(
|
2013-06-20 14:17:10 +08:00
|
|
|
// MenuItemFont::create( "33%" ),
|
|
|
|
// MenuItemFont::create( "66%" ),
|
|
|
|
// MenuItemFont::create( "100%" ),
|
2012-04-19 14:35:52 +08:00
|
|
|
// NULL );
|
2013-06-20 14:17:10 +08:00
|
|
|
// TIP: you can manipulate the items like any other MutableArray
|
|
|
|
item4->getSubItems()->addObject( MenuItemFont::create( "33%" ) );
|
|
|
|
item4->getSubItems()->addObject( MenuItemFont::create( "66%" ) );
|
|
|
|
item4->getSubItems()->addObject( MenuItemFont::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 );
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
MenuItemFont::setFontName( "Marker Felt" );
|
|
|
|
MenuItemFont::setFontSize( 34 );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
LabelBMFont *label = LabelBMFont::create( "go back", "fonts/bitmapFontTest3.fnt" );
|
|
|
|
MenuItemLabel* back = MenuItemLabel::create(label, CC_CALLBACK_1(MenuLayer4::backCallback, this) );
|
2010-08-28 15:47:51 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Menu *menu = Menu::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
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Size s = Director::sharedDirector()->getWinSize();
|
2012-04-19 14:35:52 +08:00
|
|
|
menu->setPosition(ccp(s.width/2, s.height/2));
|
2010-08-28 15:47:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
MenuLayer4::~MenuLayer4()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void MenuLayer4::menuCallback(Object* sender)
|
2010-08-28 15:47:51 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
//CCLOG("selected item: %x index:%d", dynamic_cast<MenuItemToggle*>(sender)->selectedItem(), dynamic_cast<MenuItemToggle*>(sender)->selectedIndex() );
|
2010-08-28 15:47:51 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void MenuLayer4::backCallback(Object* sender)
|
2010-08-28 15:47:51 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
((LayerMultiplex*)_parent)->switchTo(0);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
MenuLayerPriorityTest::MenuLayerPriorityTest()
|
|
|
|
{
|
|
|
|
// Testing empty menu
|
2013-06-20 14:17:10 +08:00
|
|
|
_menu1 = Menu::create();
|
|
|
|
_menu2 = Menu::create();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
|
|
// Menu 1
|
2013-06-20 14:17:10 +08:00
|
|
|
MenuItemFont::setFontName("Marker Felt");
|
|
|
|
MenuItemFont::setFontSize(18);
|
|
|
|
MenuItemFont *item1 = MenuItemFont::create("Return to Main Menu", CC_CALLBACK_1(MenuLayerPriorityTest::menuCallback, this));
|
|
|
|
MenuItemFont *item2 = MenuItemFont::create("Disable menu for 5 seconds", [&](Object *sender) {
|
2013-06-15 14:03:30 +08:00
|
|
|
_menu1->setEnabled(false);
|
2013-06-20 14:17:10 +08:00
|
|
|
DelayTime *wait = DelayTime::create(5);
|
|
|
|
CallFunc *enable = CallFunc::create( [&]() {
|
2013-06-15 14:03:30 +08:00
|
|
|
_menu1->setEnabled(true);
|
2013-06-06 08:51:40 +08:00
|
|
|
});
|
2013-06-20 14:17:10 +08:00
|
|
|
Sequence* seq = Sequence::create(wait, enable, NULL);
|
2013-06-15 14:03:30 +08:00
|
|
|
_menu1->runAction(seq);
|
2013-06-06 08:51:40 +08:00
|
|
|
});
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_menu1->addChild(item1);
|
|
|
|
_menu1->addChild(item2);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_menu1->alignItemsVerticallyWithPadding(2);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
addChild(_menu1);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// Menu 2
|
2013-06-15 14:03:30 +08:00
|
|
|
_priority = true;
|
2013-06-20 14:17:10 +08:00
|
|
|
MenuItemFont::setFontSize(48);
|
|
|
|
item1 = MenuItemFont::create("Toggle priority", [&](Object *sender) {
|
2013-06-15 14:03:30 +08:00
|
|
|
if( _priority) {
|
2013-06-20 14:17:10 +08:00
|
|
|
_menu2->setHandlerPriority(kMenuHandlerPriority + 20);
|
2013-06-15 14:03:30 +08:00
|
|
|
_priority = false;
|
2013-06-06 08:51:40 +08:00
|
|
|
} else {
|
2013-06-20 14:17:10 +08:00
|
|
|
_menu2->setHandlerPriority(kMenuHandlerPriority - 20);
|
2013-06-15 14:03:30 +08:00
|
|
|
_priority = true;
|
2013-06-06 08:51:40 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
item1->setColor(ccc3(0,0,255));
|
2013-06-15 14:03:30 +08:00
|
|
|
_menu2->addChild(item1);
|
|
|
|
addChild(_menu2);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
MenuLayerPriorityTest::~MenuLayerPriorityTest()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void MenuLayerPriorityTest::menuCallback(Object* pSender)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
((LayerMultiplex*)_parent)->switchTo(0);
|
|
|
|
// [[Director sharedDirector] popScene];
|
2012-03-22 14:22:06 +08:00
|
|
|
}
|
|
|
|
|
2012-11-19 13:57:54 +08:00
|
|
|
// BugsTest
|
|
|
|
BugsTest::BugsTest()
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
MenuItemFont *issue1410 = MenuItemFont::create("Issue 1410", CC_CALLBACK_1(BugsTest::issue1410MenuCallback, this));
|
|
|
|
MenuItemFont *issue1410_2 = MenuItemFont::create("Issue 1410 #2", CC_CALLBACK_1(BugsTest::issue1410v2MenuCallback, this));
|
|
|
|
MenuItemFont *back = MenuItemFont::create("Back", CC_CALLBACK_1(BugsTest::backMenuCallback, this));
|
2012-11-19 13:57:54 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Menu *menu = Menu::create(issue1410, issue1410_2, back, NULL);
|
2012-11-19 13:57:54 +08:00
|
|
|
addChild(menu);
|
|
|
|
menu->alignItemsVertically();
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Size s = Director::sharedDirector()->getWinSize();
|
2012-11-19 13:57:54 +08:00
|
|
|
menu->setPosition(ccp(s.width/2, s.height/2));
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void BugsTest::issue1410MenuCallback(cocos2d::Object *pSender)
|
2012-11-19 13:57:54 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Menu *menu = (Menu*)((MenuItem*)pSender)->getParent();
|
2012-11-19 13:57:54 +08:00
|
|
|
menu->setTouchEnabled(false);
|
|
|
|
menu->setTouchEnabled(true);
|
|
|
|
|
|
|
|
CCLog("NO CRASHES");
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void BugsTest::issue1410v2MenuCallback(cocos2d::Object *pSender)
|
2012-11-19 13:57:54 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Menu *menu = (Menu*)((MenuItem*)pSender)->getParent();
|
2012-11-19 13:57:54 +08:00
|
|
|
menu->setTouchEnabled(true);
|
|
|
|
menu->setTouchEnabled(false);
|
|
|
|
|
|
|
|
CCLog("NO CRASHES. AND MENU SHOULD STOP WORKING");
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void BugsTest::backMenuCallback(cocos2d::Object *pSender)
|
2012-11-19 13:57:54 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
((LayerMultiplex*)_parent)->switchTo(0);
|
2012-11-19 13:57:54 +08:00
|
|
|
}
|
|
|
|
|
2013-01-17 15:04:48 +08:00
|
|
|
RemoveMenuItemWhenMove::RemoveMenuItemWhenMove()
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Size s = Director::sharedDirector()->getWinSize();
|
2013-01-17 15:04:48 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
LabelTTF* label = LabelTTF::create("click item and move, should not crash", "Arial", 20);
|
2013-01-17 15:04:48 +08:00
|
|
|
label->setPosition(ccp(s.width/2, s.height - 30));
|
|
|
|
addChild(label);
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
item = MenuItemFont::create("item 1");
|
2013-01-17 15:04:48 +08:00
|
|
|
item->retain();
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
MenuItemFont *back = MenuItemFont::create("go back", CC_CALLBACK_1(RemoveMenuItemWhenMove::goBack, this));
|
2013-01-17 15:04:48 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Menu *menu = Menu::create(item, back, NULL);
|
2013-01-17 15:04:48 +08:00
|
|
|
addChild(menu);
|
|
|
|
menu->alignItemsVertically();
|
|
|
|
|
|
|
|
menu->setPosition(ccp(s.width/2, s.height/2));
|
|
|
|
|
|
|
|
setTouchEnabled(true);
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void RemoveMenuItemWhenMove::goBack(Object *pSender)
|
2013-01-17 15:04:48 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
((LayerMultiplex*)_parent)->switchTo(0);
|
2013-01-17 15:04:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
RemoveMenuItemWhenMove::~RemoveMenuItemWhenMove()
|
|
|
|
{
|
|
|
|
CC_SAFE_RELEASE(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveMenuItemWhenMove::registerWithTouchDispatcher(void)
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Director::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, -129, false);
|
2013-01-17 15:04:48 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
bool RemoveMenuItemWhenMove::ccTouchBegan(Touch *pTouch, Event *pEvent)
|
2013-01-17 15:04:48 +08:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void RemoveMenuItemWhenMove::ccTouchMoved(Touch *pTouch, Event *pEvent)
|
2013-01-17 15:04:48 +08:00
|
|
|
{
|
|
|
|
if (item)
|
|
|
|
{
|
|
|
|
item->removeFromParentAndCleanup(true);
|
|
|
|
item->release();
|
|
|
|
item = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-28 15:47:51 +08:00
|
|
|
void MenuTestScene::runThisTest()
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer* pLayer1 = new MenuLayerMainMenu();
|
|
|
|
Layer* pLayer2 = new MenuLayer2();
|
|
|
|
Layer* pLayer3 = new MenuLayer3();
|
|
|
|
Layer* pLayer4 = new MenuLayer4();
|
|
|
|
Layer* pLayer5 = new MenuLayerPriorityTest();
|
|
|
|
Layer* pLayer6 = new BugsTest();
|
|
|
|
Layer* pLayer7 = new RemoveMenuItemWhenMove();
|
2010-08-28 15:47:51 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
LayerMultiplex* layer = LayerMultiplex::create(pLayer1, pLayer2, pLayer3, pLayer4, pLayer5, pLayer6, pLayer7, 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();
|
2013-01-17 15:04:48 +08:00
|
|
|
pLayer7->release();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Director::sharedDirector()->replaceScene(this);
|
2010-08-28 15:47:51 +08:00
|
|
|
}
|