예제 #1
0
ControlButton* standardButtonWithTitle( const char * bgname, const char * bgseledname, const char * title){

	//Creates and return a button with a default background and title color.
//    Scale9Sprite *backgroundButton = Scale9Sprite::create(bgname);//按下前
//    Scale9Sprite *backgroundHighlightedButton = Scale9Sprite::create(bgseledname);//按下后
	

	ControlButton* btn = ControlButton::create();
	btn->setPreferredSize(Size(522, 88));

	Scale9Sprite*	normal = Scale9Sprite::create(bgname);
	Scale9Sprite*	select = Scale9Sprite::create(bgseledname);
	Scale9Sprite* hightlight = Scale9Sprite::create(bgseledname);
	Scale9Sprite* disable = Scale9Sprite::create(bgname);
	
	btn->setBackgroundSpriteForState(normal, Control::State::NORMAL);
	btn->setBackgroundSpriteForState(select, Control::State::SELECTED);
	btn->setBackgroundSpriteForState(hightlight, Control::State::HIGH_LIGHTED);
	btn->setBackgroundSpriteForState(disable, Control::State::DISABLED);
	
	
    LabelTTF *titleButton = LabelTTF::create(title, "AmericanTypewriter", 30);//添加文字
	titleButton->setAnchorPoint(Point(0.5f, 0.5f));
	titleButton->setPosition(Point(btn->getContentSize().width/2, btn->getContentSize().height/2));
	titleButton->setColor(Color3B::BLACK);//设置文字点击前的颜色
	titleButton->setTag(1000);
	btn->addChild(titleButton);

    return btn;
}
예제 #2
0
bool SkillTableView::init()
{
    if (!Node::init())
        return false;

    LayerColor* bg = LayerColor::create(Color4B(255, 255, 255, 127), 450, 500);
    bg->setPosition(bg->getContentSize()/-2);
    this->addChild(bg, -1);
    
    CCLabelTTF* title = CCLabelTTF::create("技能列表", "fonts/Marker Felt.ttf", 40);
    title->setPosition(Point(bg->getContentSize().width/2, bg->getContentSize().height-30));
    bg->addChild(title);
    
    ControlButton* button = ControlButton::create(Scale9Sprite::create("ui/closed_normal.png"));
    button->setBackgroundSpriteForState(Scale9Sprite::create("ui/closed_selected.png"), Control::State::HIGH_LIGHTED);
    button->setPreferredSize(Size(57, 58));
    button->setPosition(ccpSub(ccpAdd(bg->getPosition(), bg->getContentSize()), button->getContentSize()/2));
    this->addChild(button);
    button->addTargetWithActionForControlEvents(GAME_UILAYER, cccontrol_selector(GameInfoUIController::removeSmallMenuAndButton), Control::EventType::TOUCH_UP_INSIDE);
   // button->setTouchPriority(0);
    
    m_skillTableView = TableView::create(this, Size(420, 420));
    m_skillTableView->setPosition(Point(15, 15));
   // m_skillTableView->setDirection(kCCScrollViewDirectionVertical);
    m_skillTableView->setDelegate(this);
   // m_skillTableView->setVerticalFillOrder(kCCTableViewFillTopDown);
    bg->addChild(m_skillTableView);
    m_skillTableView->reloadData();
    return true;
}
예제 #3
0
bool PropColumnMenu::init()
{
    if (!Layer::init())
        return false;
    
    this->setTouchEnabled(true);
    
    Sprite* bg = Sprite::create("ui/prop_column.png");
    this->addChild(bg);
    
    m_propColumn = LayerColor::create(ccc4(255, 255, 255, 0), GRID_WIDTH*COL, GRID_HEIGHT*ROW);
    m_propColumn->setContentSize(Size(GRID_WIDTH*COL, GRID_HEIGHT*ROW));
    m_propColumn->setPosition(Point(PROP_X, PROP_Y));
    bg->addChild(m_propColumn);
    
    ControlButton* button = ControlButton::create(ui::Scale9Sprite::create("ui/closed_normal.png"));
    button->setBackgroundSpriteForState(ui::Scale9Sprite::create("ui/closed_selected.png"), Control::State::HIGH_LIGHTED);
    button->setPreferredSize(Size(57, 58));
    button->setPosition(ccpSub(ccpAdd(bg->getPosition(), bg->getContentSize()/2), button->getContentSize()/2));
    this->addChild(button);
    button->addTargetWithActionForControlEvents(GAME_UILAYER, cccontrol_selector(GameInfoUIController::removeSmallMenuAndButton), Control::EventType::TOUCH_UP_INSIDE);
   // button->setTouchPriority(0);
    
    for (int i=0; i<12; i++)
    {
        m_propVec[i] = PropIconShow::create(PropSystem::getPropInfo(i+1));
        m_propColumn->addChild(m_propVec[i]);
    }

    return true;
}
예제 #4
0
void PropColumnMenu::onTouchMoved(Touch *pTouch, Event *pEvent)
{
    Point point = pTouch->getLocation();
    
    m_editProp->setPosition(point);
    
    do
    {
        ControlButton* btn = GAME_UILAYER->getOperationMenu()->getDrugsBtn();
        
        Rect rect;
        rect.origin = btn->convertToWorldSpace(Point::ZERO);
        rect.size = btn->getContentSize();
        if (rect.containsPoint(point))
        {
            CC_BREAK_IF(m_editProp->getOpacity() == 255);
            m_editProp->setOpacity(255);
            btn->stopAllActions();
            ScaleTo* scaleTo = ScaleTo::create(0.1f, 1.1f);
            btn->runAction(scaleTo);
        }
        else
        {
            CC_BREAK_IF(m_editProp->getOpacity() == 127);
            m_editProp->setOpacity(127);
            btn->stopAllActions();
            ScaleTo* scaleTo = ScaleTo::create(0.1f, 1.0f);
            btn->runAction(scaleTo);
        }
    }
    while (0);
}
예제 #5
0
bool ControlButtonTest_Styling::init()
{
    if (ControlScene::init())
    {
        auto screenSize = Director::getInstance()->getWinSize();

        auto layer = Node::create();
        addChild(layer, 1);
        
        int space = 10; // px
        
        double max_w = 0, max_h = 0;
        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                // Add the buttons
                ControlButton *button = standardButtonWithTitle(StringUtils::format("%d",rand() % 30).c_str());
                button->setAdjustBackgroundImage(false);  // Tells the button that the background image must not be adjust
                                                    // It'll use the prefered size of the background image
                button->setPosition(button->getContentSize().width / 2 + (button->getContentSize().width + space) * i,
                                       button->getContentSize().height / 2 + (button->getContentSize().height + space) * j);
                layer->addChild(button);
                
                max_w = MAX(button->getContentSize().width * (i + 1) + space  * i, max_w);
                max_h = MAX(button->getContentSize().height * (j + 1) + space * j, max_h);
            }
        }
        
        layer->setAnchorPoint(Vec2(0.5, 0.5));
        layer->setContentSize(Size(max_w, max_h));
        layer->setPosition(screenSize.width / 2.0f, screenSize.height / 2.0f);
        
        // Add the black background
        auto backgroundButton = ui::Scale9Sprite::create("extensions/buttonBackground.png");
        backgroundButton->setContentSize(Size(max_w + 14, max_h + 14));
        backgroundButton->setPosition(screenSize.width / 2.0f, screenSize.height / 2.0f);
        addChild(backgroundButton);
        return true;
    }
    return false;
}
예제 #6
0
void GameScene::answerAnimation( int answerIndex){
	
	GameAnswerState st;
	ControlButton* btn;
	switch ( answerIndex ) {
		case 1:
		//	st = answerOneState_;
			btn = btn1;
			break;
		case 2:
		//	st = answerTwoState_;
			btn = btn2;
		    break;
		case 3:
		//	st = answerThreeState_;
			btn = btn3;
			break;
		case 4:
		//	st = answerFouState_;
			btn = btn4;
			break;
		default:
			break;
	}
	st = answerStateArr_[ answerIndex - 1];
	
	std::string correctwrongImgStr;
	
	if ( st == GameStateAnswerStateRight ) {
		//right
		correctwrongImgStr = "play_correct.png";
	}else{
		correctwrongImgStr = "play_wrong.png";
	}
	
	btn->setEnabled(false);
	Sprite* sp = Sprite::create(correctwrongImgStr);
	sp->setPosition( Point( btn->getPositionX() - btn->getContentSize().width/2 + sp->getContentSize().width, btn->getPositionY()));
	this->addChild(sp);
	
//	CCLabelBMFont* label = CCLabelBMFont::create("23","prim30.fnt");
//	label->setColor(Color3B::BLACK);
//	label->setPosition(sp->getPosition());
//	this->addChild(label);
	
}
예제 #7
0
void SkillTableView::onTouchMoved(Touch *pTouch, Event *pEvent)
{
    Point point = pTouch->getLocation();
    
    if (m_pEditingSkill == NULL)
        return;
        
    m_pEditingSkill->setPosition(point);
    
    if (m_pEditingBtn)
    {
        Rect rect;
        rect.origin = m_pEditingBtn->convertToWorldSpace(Point::ZERO);
        rect.size = m_pEditingBtn->getContentSize();
        if (!rect.containsPoint(point))
        {
            m_pEditingSkill->setOpacity(127);
            m_pEditingBtn->stopAllActions();
            ScaleTo* scaleTo = ScaleTo::create(0.1f, 1.0f);
            m_pEditingBtn->runAction(scaleTo);
            m_pEditingBtn = NULL;
        }
    }
    
    if (m_pEditingBtn == NULL)
    {
        for (unsigned int i=0; i<3; i++)
        {
            ControlButton* btn = GAME_UILAYER->getOperationMenu()->getSkillAttackBtn(i);
            Rect rect;
            rect.origin = btn->convertToWorldSpace(Point::ZERO);
            rect.size = btn->getContentSize();
            
            if (rect.containsPoint(point))
            {
                m_pEditingSkill->setOpacity(255);
                m_pEditingBtn = btn;
                m_pEditingBtn->stopAllActions();
                ScaleTo* scaleTo = ScaleTo::create(0.1f, 1.1f);
                m_pEditingBtn->runAction(scaleTo);
                break;
            }
        }
    }
}
예제 #8
0
bool ControlButtonTest_HelloVariableSize::init()
{
    if (ControlScene::init())
    {
        auto screenSize = Director::getInstance()->getWinSize();
        
        // Defines an array of title to create buttons dynamically
        std::vector<std::string> vec;
        vec.push_back("Hello");
        vec.push_back("Variable");
        vec.push_back("Size");
        vec.push_back("!");
        
        auto layer = Node::create();
        addChild(layer, 1);
        
        double total_width = 0, height = 0;
        
        int i = 0;
        
        for (auto& title : vec)
        {
            // Creates a button with this string as title
            ControlButton *button = standardButtonWithTitle(title.c_str());
            if (i == 0)
            {
                button->setOpacity(50);
                button->setColor(Color3B(0, 255, 0));
            }
            else if (i == 1)
            {
                button->setOpacity(200);
                button->setColor(Color3B(0, 255, 0));
            }
            else if (i == 2)
            {
                button->setOpacity(100);
                button->setColor(Color3B(0, 0, 255));
            }
            
            button->setPosition(total_width + button->getContentSize().width / 2, button->getContentSize().height / 2);
            layer->addChild(button);
            
            // Compute the size of the layer
            height = button->getContentSize().height;
            total_width += button->getContentSize().width;
            i++;
        }

        layer->setAnchorPoint(Vec2 (0.5, 0.5));
        layer->setContentSize(Size(total_width, height));
        layer->setPosition(screenSize.width / 2.0f, screenSize.height / 2.0f);
        
        // Add the black background
        auto background = ui::Scale9Sprite::create("extensions/buttonBackground.png");
        background->setContentSize(Size(total_width + 14, height + 14));
        background->setPosition(screenSize.width / 2.0f, screenSize.height / 2.0f);
        addChild(background);
        return true;
    }
    return false;
}