void HelloScene::addSetupSwitch(const CCPoint &position, string lable, const ccColor3B &c, int colorCode)//, SEL_CCControlHandler joinInFunc, SEL_CCControlHandler aiFunc)
{
    CCLabelTTF *lab = CCLabelTTF::create(lable.c_str(), "Arial", 24);
    lab->setColor(c);
    lab->setPosition(position);
    addChild(lab);

    CCControlSwitch *consJoinIn = CCControlSwitch::create(
        CCSprite::create("switch-mask.png"),
        CCSprite::create("switch-on.png"),
        CCSprite::create("switch-off.png"),
        CCSprite::create("switch-thumb.png"),
        CCLabelTTF::create("In", "Arial", 20),
        CCLabelTTF::create("Out", "Arial", 20)
        );
    consJoinIn->setPosition(ccp(position.x + 110, position.y));
    addChild(consJoinIn, 10, 100 + colorCode * 10 + 1);
    //consJoinIn->addTargetWithActionForControlEvents(this, joinInFunc, CCControlEventValueChanged);

    CCControlSwitch *consAI = CCControlSwitch::create(
        CCSprite::create("switch-mask.png"),
        CCSprite::create("switch-on.png"),
        CCSprite::create("switch-off.png"),
        CCSprite::create("switch-thumb1.png"),
        CCLabelTTF::create("PLY", "Arial", 20),
        CCLabelTTF::create("NPC", "Arial", 20)
        );
    consAI->setPosition(ccp(position.x + 220, position.y));
    addChild(consAI, 10, 100 + colorCode * 10 + 2);
    //consAI->addTargetWithActionForControlEvents(this, aiFunc, CCControlEventValueChanged);
}
CCControlSwitch* CCControlSwitch::create(CCSprite *maskSprite, CCSprite * onSprite, CCSprite * offSprite, CCSprite * thumbSprite, CCLabelTTF* onLabel, CCLabelTTF* offLabel)
{
    CCControlSwitch* pRet = new CCControlSwitch();
    if (pRet && pRet->initWithMaskSprite(maskSprite, onSprite, offSprite, thumbSprite, onLabel, offLabel))
    {
        pRet->autorelease();
    }
    else
    {
        CC_SAFE_DELETE(pRet);
    }
    return pRet;
}
//事件响应函数
void HelloWorld::valueChanged(CCObject* sender, CCControlEvent controlEvent)
{
//获取事件的传递者CCControlSwitch
	CCControlSwitch* controlSwitch = (CCControlSwitch*)sender;
	
//根据开关控件的状态,设置label标签的内容
	if( controlSwitch->isOn() ) 
	{
		label->setString("ON");
	}
	else 
	{
		label->setString("OFF");
	}
}
void HelloScene::playBtnCallback(CCObject* pSender, CCControlEvent e)
{
    Enviroment *env = Enviroment::getInstance();
    for (int i = 1; i <= 4; i++)
    {
        CCControlSwitch *consJoinIn = (CCControlSwitch*) getChildByTag(100 + i * 10 + 1);
        CCControlSwitch *consAI = (CCControlSwitch*) getChildByTag(100 + i * 10 + 2);

        if (consJoinIn->isOn())
        {
            env->players.add(i);
        }

        env->AIMap.insert(map<int, bool>::value_type(i, !consAI->isOn()));
    }

    CCDirector::sharedDirector()->purgeCachedData();
    CCScene *chessBoardScene = ChessBoardScene::scene();
    CCTransitionScene *tran = CCTransitionShrinkGrow::create(0.7f, chessBoardScene);
    CCDirector::sharedDirector()->replaceScene(tran);
}
bool ControllerScene::init(){
    CCMenu *menu = CCMenu::create();
    menu->setPosition(CCPointZero);
    this->addChild(menu);
    
    CCLabelTTF *label = CCLabelTTF::create("CCTextFieldTTF", "Arial", 24);
    CCMenuItemLabel *item = CCMenuItemLabel::create(label, this, menu_selector(ControllerScene::menuItemClick1));
    item->setPosition(ccp(320, 1100));
    menu->addChild(item);
    
    label = CCLabelTTF::create("确定", "Arial", 24);
    m_btn = CCMenuItemLabel::create(label, this, menu_selector(ControllerScene::btnOk));
    m_btn->setPosition(ccp(400, 1050));
    menu->addChild(m_btn);
    
    m_texField = CCTextFieldTTF::textFieldWithPlaceHolder("input", CCSizeMake(200, 50), kCCTextAlignmentLeft, "Arial", 24);
    m_texField->setPosition(ccp(320, 1050));
    this->addChild(m_texField);
    m_texField->attachWithIME();
    
    m_name = CCLabelTTF::create("show info", "Arial", 24);
    m_name->setPosition(ccp(100, 1100));
    this->addChild(m_name);
    
    //CCControlButton label+s9
    label = CCLabelTTF::create("BUTTON", "Arial", 24);
    CCControlButton *btn = CCControlButton::create(label , CCScale9Sprite::create("start.png"));
    btn->setPreferredSize(CCSizeMake(228, 81));
    btn->setLabelAnchorPoint(ccp(0.5, 2));
    btn->setPosition(ccp(320, 1000));
    this->addChild(btn);
    btn->addTargetWithActionForControlEvents(this, cccontrol_selector(ControllerScene::btnClick), CCControlEventTouchDown);
    
    //CCControlButton s9
    CCScale9Sprite *s9 = CCScale9Sprite::create("start.png");
    btn = CCControlButton::create(s9);
    btn->setPosition(ccp(320, 900));
    btn->setPreferredSize(CCSizeMake(228, 81));
    this->addChild(btn);
    
    //CCControlButton title
    btn = CCControlButton::create("CCControlButton", "Arial", 24);
    btn->setPosition(ccp(320, 800));
    this->addChild(btn);
    
    //s9
//    s9 = CCScale9Sprite::create("home.png");
//    s9->setPosition(ccp(100, 800));
//    this->addChild(s9);
    
    //CCControlColourPicker not useful
    CCControlColourPicker *cp = CCControlColourPicker::create();
    cp->setPosition(ccp(320, 750));
    this->addChild(cp);
    
    //CCControlPotentiometer
    CCControlPotentiometer *pot = CCControlPotentiometer::create("potentiometerTrack.png", "potentiometerProgress.png", "potentiometerButton.png");
    pot->setPosition(ccp(100, 750));
    this->addChild(pot);
    pot->setValue(90);
    
    //CCControlSlider
    CCControlSlider *slider = CCControlSlider::create("sliderTrack.png", "sliderProgress.png", "sliderThumb.png");
    slider->setPosition(ccp(150, 600));
    slider->setMinimumValue(0);
    slider->setMaximumValue(100);
    this->addChild(slider);
    slider->addTargetWithActionForControlEvents(this, cccontrol_selector(ControllerScene::valueChanged), CCControlEventValueChanged);
    
    //CCControlStepper
    CCControlStepper *ste = CCControlStepper::create(CCSprite::create("stepper-minus.png"), CCSprite::create("stepper-plus.png"));
    ste->setPosition(ccp(320, 600));
    this->addChild(ste);
    
    //CCControlSwitch
    CCControlSwitch *swi = CCControlSwitch::create(CCSprite::create("switch-mask.png"), CCSprite::create("switch-on.png"), CCSprite::create("switch-off.png"), CCSprite::create("switch-thumb.png"), CCLabelTTF::create("on", "Arial", 24), CCLabelTTF::create("off", "Arial", 24));
    swi->setPosition(ccp(500, 600));
    this->addChild(swi);

    //
    CCEditBox *edi = CCEditBox::create(CCSizeMake(200, 50), CCScale9Sprite::create("start.png"));
    edi->setPosition(ccp(150, 500));
    this->addChild(edi);
    
    return true;
}