Пример #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
ControlButton *TDDSubMenu::createButton(const std::string &name, int tag,
										  const Point &pos, const Size &size)
{
	Color3B colorNormal = Color3B::WHITE;
	//Color3B colorSelected = colorNormal;
	
	Scale9Sprite *bgButton = Scale9Sprite::create();
	Scale9Sprite *bgHiliButton = Scale9Sprite::create();
	
	// bgButton->setContentSize(Size(200, 50));
	Label *titleButton = Label::createWithSystemFont(name.c_str(), "Arial", 15);
	titleButton->setColor(colorNormal);
	
	
	ControlButton *button = ControlButton::create(titleButton, bgButton);
	button->setBackgroundSpriteForState(bgHiliButton, Control::State::HIGH_LIGHTED);

	TDDHelper::setAlphaPremultiplied(button);
	button->setTag(tag);
	button->setContentSize(size);
	button->setPosition(pos);
	button->setSelected(false);
	
	return button;
}
Пример #3
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;
}
Пример #4
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;
}
Пример #5
0
bool ControlButtonTest_Event::init()
{
    if (ControlScene::init())
    {
        auto screenSize = Director::getInstance()->getWinSize();

        // Add a label in which the button events will be displayed
        setDisplayValueLabel(Label::createWithTTF("No Event", "fonts/Marker Felt.ttf", 32));
        _displayValueLabel->setAnchorPoint(Vec2(0.5f, -1));
        _displayValueLabel->setPosition(screenSize.width / 2.0f, screenSize.height / 2.0f);
        addChild(_displayValueLabel, 1);

        setDisplayBitmaskLabel(Label::createWithTTF("No bitmask event", "fonts/Marker Felt.ttf", 24));
        _displayBitmaskLabel->setAnchorPoint(Vec2(0.5f, -1));
        Vec2 bitmaskLabelPos = _displayValueLabel->getPosition() - Vec2(0, _displayBitmaskLabel->getBoundingBox().size.height);
        _displayBitmaskLabel->setPosition(bitmaskLabelPos);
        addChild(_displayBitmaskLabel, 1);

        // Add the button
        auto backgroundButton = ui::Scale9Sprite::create("extensions/button.png");
        auto backgroundHighlightedButton = ui::Scale9Sprite::create("extensions/buttonHighlighted.png");
        
        auto titleButton = Label::createWithTTF("Touch Me!", "fonts/Marker Felt.ttf", 30);

        titleButton->setColor(Color3B(159, 168, 176));
        
        ControlButton *controlButton = ControlButton::create(titleButton, backgroundButton);
        controlButton->setBackgroundSpriteForState(backgroundHighlightedButton, Control::State::HIGH_LIGHTED);
        controlButton->setTitleColorForState(Color3B::WHITE, Control::State::HIGH_LIGHTED);
        
        controlButton->setAnchorPoint(Vec2(0.5f, 1));
        controlButton->setPosition(screenSize.width / 2.0f, screenSize.height / 2.0f);
        addChild(controlButton, 1);

        // Add the black background
        auto background = ui::Scale9Sprite::create("extensions/buttonBackground.png");
        background->setContentSize(Size(300, 170));
        background->setPosition(screenSize.width / 2.0f, screenSize.height / 2.0f);
        addChild(background);
        
        // Sets up event handlers
        controlButton->addTargetWithActionForControlEvents(this, cccontrol_selector(ControlButtonTest_Event::touchDownAction), Control::EventType::TOUCH_DOWN);
        controlButton->addTargetWithActionForControlEvents(this, cccontrol_selector(ControlButtonTest_Event::touchDragInsideAction), Control::EventType::DRAG_INSIDE);
        controlButton->addTargetWithActionForControlEvents(this, cccontrol_selector(ControlButtonTest_Event::touchDragOutsideAction), Control::EventType::DRAG_OUTSIDE);
        controlButton->addTargetWithActionForControlEvents(this, cccontrol_selector(ControlButtonTest_Event::touchDragEnterAction), Control::EventType::DRAG_ENTER);
        controlButton->addTargetWithActionForControlEvents(this, cccontrol_selector(ControlButtonTest_Event::touchDragExitAction), Control::EventType::DRAG_EXIT);
        controlButton->addTargetWithActionForControlEvents(this, cccontrol_selector(ControlButtonTest_Event::touchUpInsideAction), Control::EventType::TOUCH_UP_INSIDE);
        controlButton->addTargetWithActionForControlEvents(this, cccontrol_selector(ControlButtonTest_Event::touchUpOutsideAction), Control::EventType::TOUCH_UP_OUTSIDE);
        controlButton->addTargetWithActionForControlEvents(this, cccontrol_selector(ControlButtonTest_Event::touchCancelAction), Control::EventType::TOUCH_CANCEL);
        // test for issue 2882
        controlButton->addTargetWithActionForControlEvents(this, cccontrol_selector(ControlButtonTest_Event::touchBitmaskAction),
            Control::EventType::TOUCH_DOWN | Control::EventType::DRAG_INSIDE | Control::EventType::DRAG_OUTSIDE | Control::EventType::DRAG_ENTER | Control::EventType::DRAG_EXIT | Control::EventType::TOUCH_UP_INSIDE | Control::EventType::TOUCH_UP_OUTSIDE | Control::EventType::TOUCH_CANCEL | Control::EventType::VALUE_CHANGED);

        return true;
    }
    return false;
}
Пример #6
0
ControlButton* ButtonUtils::createButton(const char *normalFrame, 
										 const char *highLightFrame,
										 const char *disableFrame,
										 cocos2d::Size size,
										 const char *label,
										 float labelSize,
										 Color3B labelColor)
{
    Scale9Sprite *normal = Scale9Sprite::createWithSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(normalFrame));
    Scale9Sprite *highLight = Scale9Sprite::createWithSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(highLightFrame));
    Scale9Sprite *disable = Scale9Sprite::createWithSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(disableFrame));
    ControlButton *btn = ControlButton::create(label, "Arial", labelSize);
    btn->setPreferredSize(size);//设置按钮首选大小
    btn->setBackgroundSpriteForState(normal, Control::State::NORMAL);
    btn->setBackgroundSpriteForState(highLight, Control::State::HIGH_LIGHTED);
    btn->setBackgroundSpriteForState(disable, Control::State::DISABLED);
    btn->setTitleColorForState(labelColor, Control::State::NORMAL);
    btn->setTitleColorForState(labelColor, Control::State::HIGH_LIGHTED);
    btn->setTitleColorForState(labelColor, Control::State::DISABLED);
    //btn->setTouchPriority(0);
    
    return btn;
}
Пример #7
0
ControlButton *ControlButtonTest_HelloVariableSize::standardButtonWithTitle(const char * title)
{
    /** Creates and return a button with a default background and title color. */
    auto backgroundButton = ui::Scale9Sprite::create("extensions/button.png");
    auto backgroundHighlightedButton = ui::Scale9Sprite::create("extensions/buttonHighlighted.png");
    
    auto titleButton = Label::createWithTTF(title, "fonts/Marker Felt.ttf", 30);

    titleButton->setColor(Color3B(159, 168, 176));
    
    ControlButton *button = ControlButton::create(titleButton, backgroundButton);
    button->setBackgroundSpriteForState(backgroundHighlightedButton, Control::State::HIGH_LIGHTED);
    button->setTitleColorForState(Color3B::WHITE, Control::State::HIGH_LIGHTED);

    return button;
}
Пример #8
0
ControlButton *AboutLayer::standardButtonWithTitle(const std::string& string)
{
	/** Creates and return a button with a default background and title color. */
	auto backgroundButton = Scale9Sprite::create("button.png");
	auto backgroundHighlightedButton = Scale9Sprite::create("buttonHighlighted.png");

	auto titleButton = LabelTTF::create(string, "Marker Felt", 50);
    //auto label = LabelTTF::create("中国", "Marker Felt", 30);
	titleButton->setColor(Color3B(159, 168, 176));

	ControlButton *button = ControlButton::create(titleButton, backgroundButton);
	button->setBackgroundSpriteForState(backgroundHighlightedButton, Control::State::HIGH_LIGHTED);
	button->setTitleColorForState(Color3B::WHITE, Control::State::HIGH_LIGHTED);
	button->addTargetWithActionForControlEvents(this, cccontrol_selector(AboutLayer::touchUpInsideAction), Control::EventType::TOUCH_UP_INSIDE);
	this->addChild(button);
	return button;
}
Пример #9
0
ControlButton * createBtn(float x, float y, 
						  const char * normalBg, const char * pressBg, 
						  Ref* target, Control::Handler action)
{
	Scale9Sprite * spNormalBg = createDotaScale9Sprite(normalBg);
	Scale9Sprite * spPressBg = createDotaScale9Sprite(pressBg);

	ControlButton *btn = ControlButton::create(spNormalBg);
	if (spPressBg)
		btn->setBackgroundSpriteForState(spPressBg, Control::State::HIGH_LIGHTED);
	btn->setAnchorPoint(Vec2(0, 0));
	btn->setPosition(x, y);
	btn->setZoomOnTouchDown(false);
	btn->setPreferredSize(spNormalBg->getOriginalSize());
	if (target && action)
		btn->addTargetWithActionForControlEvents(target, action, 
			Control::EventType::TOUCH_UP_INSIDE);

	return btn;
}