Exemplo n.º 1
0
EditorGridSettingsWindow::EditorGridSettingsWindow(EditorGrid *grid) : UIWindow("Grid Settings", 100, 190) {
    
    visible = false;
    enabled = false;
    
    this->grid = grid;
    
    visibleCheck = new UICheckBox("Enabled", grid->visible);
    addChild(visibleCheck);
    visibleCheck->setPosition(10, 40);
    visibleCheck->addEventListener(this, UIEvent::CHANGE_EVENT);
    
    UILabel *label = new UILabel("Size:", 12);
    label->setColor(1.0, 1.0 ,1.0, 1.0);
    addChild(label);
    label->setPosition(10, 70);
    
    sizeInput = new UITextInput(false, 50, 10);
    addChild(sizeInput);
    sizeInput->setPosition(60, 68);
    sizeInput->setNumberOnly(true);
    sizeInput->setText(String::NumberToString(grid->getGridSize()));
    sizeInput->addEventListener(this, UIEvent::CHANGE_EVENT);
    
    label = new UILabel("Count:", 12);
    label->setColor(1.0, 1.0 ,1.0, 1.0);
    addChild(label);
    label->setPosition(10, 100);

    countInput = new UITextInput(false, 50, 10);
    addChild(countInput);
    countInput->setPosition(60, 98);
    countInput->setNumberOnly(true);
    countInput->setText(String::IntToString(grid->getGridLen()));
    countInput->addEventListener(this, UIEvent::CHANGE_EVENT);
    
    xAxisBox = new UICheckBox("X Axis", grid->isXAxisEnabled());
    addChild(xAxisBox);
    xAxisBox->setPosition(10, 130);
    xAxisBox->addEventListener(this, UIEvent::CHANGE_EVENT);
    
    yAxisBox = new UICheckBox("Y Axis", grid->isYAxisEnabled());
    addChild(yAxisBox);
    yAxisBox->setPosition(10, 155);
    yAxisBox->addEventListener(this, UIEvent::CHANGE_EVENT);
    
    zAxisBox = new UICheckBox("Z Axis", grid->isZAxisEnabled());
    addChild(zAxisBox);
    zAxisBox->setPosition(10, 180);
    zAxisBox->addEventListener(this, UIEvent::CHANGE_EVENT);
}
bool UIImageViewTest_Scale9::init()
{
    if (UIScene::init())
    {
        CCSize screenSize = CCDirector::sharedDirector()->getWinSize();
        
        UILabel *alert = UILabel::create();
        alert->setText("ImageView scale9 render");
        alert->setFontName("Marker Felt");
        alert->setFontSize(30);
        alert->setColor(ccc3(159, 168, 176));
//        alert->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f - alert->getRect().size.height * 1.75));
        m_pUiLayer->addWidget(alert);
        
        // Create the ui layer
        UILayer *ul = UILayer::create();
        ul->scheduleUpdate();
        addChild(ul);
        
        // Create the imageview
        UIImageView *imageView = UIImageView::create();
        imageView->setScale9Enabled(true);
        imageView->loadTexture("cocosgui/buttonHighlighted.png");
//        imageView->setScale9Size(CCSizeMake(200, 85));
//        imageView->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f + imageView->getRect().size.height / 4.0f));
        ul->addWidget(imageView);
        
        return true;
    }
    return false;
}
bool UILoadingBarTest_Left::init()
{
    if (UIScene::init())
    {
        scheduleUpdate();
        
        CCSize widgetSize = m_pWidget->getSize();
        
        // Add the alert
        UILabel *alert = UILabel::create();
        alert->setText("LoadingBar left");
        alert->setFontName("Marker Felt");
        alert->setFontSize(30);
        alert->setColor(ccc3(159, 168, 176));
        alert->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75));
        m_pUiLayer->addWidget(alert);
        
        // Create the loading bar
        UILoadingBar* loadingBar = UILoadingBar::create();
        loadingBar->setName("LoadingBar");
        loadingBar->loadTexture("cocosui/sliderProgress.png");        
        loadingBar->setPercent(0);
        
        loadingBar->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f + loadingBar->getSize().height / 4.0f));
        m_pUiLayer->addWidget(loadingBar);
        
        return true;
    }
    return false;
}
bool UITextAreaTest::init()
{
    if (UIScene::init())
    {
        CCSize screenSize = CCDirector::sharedDirector()->getWinSize();
        
        UILabel *alert = UILabel::create();
        alert->setText("TextArea");
        alert->setFontName("Marker Felt");
        alert->setFontSize(30);
        alert->setColor(ccc3(159, 168, 176));
        alert->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f - alert->getRect().size.height * 1.75));
        m_pUiLayer->addWidget(alert);        
        
        // Create the text area
        UITextArea* textArea = UITextArea::create();
        textArea->setTextAreaSize(CCSizeMake(280, 150));
        textArea->setTextHorizontalAlignment(kCCTextAlignmentCenter);
        textArea->setText("TextArea widget can line wrap");
        textArea->setFontName("AmericanTypewriter");
        textArea->setFontSize(32);
        textArea->setPosition(ccp(screenSize.width / 2, screenSize.height / 2 - textArea->getRect().size.height / 8));
        m_pUiLayer->addWidget(textArea);
        
        return true;
    }
    return false;
}
bool UILoadingBarTest::init()
{
    if (UIScene::init())
    {
        scheduleUpdate();
        
        CCSize screenSize = CCDirector::sharedDirector()->getWinSize();
        
        // Add the alert
        UILabel *alert = UILabel::create();
        alert->setText("LoadingBar");
        alert->setFontName("Marker Felt");
        alert->setFontSize(30);
        alert->setColor(ccc3(159, 168, 176));
//        alert->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f - alert->getRect().size.height * 1.75));
        m_pUiLayer->addWidget(alert);
        
        // Create the loading bar
        UILoadingBar* loadingBar = UILoadingBar::create();
        loadingBar->setName("LoadingBar");
        loadingBar->loadTexture("cocosgui/sliderProgress.png");
//        loadingBar->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f + loadingBar->getRect().size.height / 4.0f));
        m_pUiLayer->addWidget(loadingBar);
        
        return true;
    }
    return false;
}
bool UIWidgetAddNodeTest::init()
{
    if (UIScene::init())
    {
        CCSize widgetSize = m_pWidget->getSize();
        
        // Add the alert
        UILabel *alert = UILabel::create();
        alert->setText("Widget Add Node");
        alert->setFontName("Marker Felt");
        alert->setFontSize(30);
        alert->setColor(ccc3(159, 168, 176));
        alert->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75));
        m_pUiLayer->addWidget(alert);
        
        // Create the ui node container
        UIWidget* widget = UIWidget::create();
        widget->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
        m_pUiLayer->addWidget(widget);
        
        CCSprite* sprite = CCSprite::create("cocosui/ccicon.png");
        sprite->setPosition(ccp(0, sprite->boundingBox().size.height / 4));
        widget->addNode(sprite);
        
        return true;
    }
    return false;
}
bool UILoadingBarTest_Left_Scale9::init()
{
    if (UIScene::init())
    {
        scheduleUpdate();
        
        CCSize widgetSize = m_pWidget->getSize();
        
        // Add the alert
        UILabel *alert = UILabel::create();
        alert->setText("LoadingBar left scale9 render");
        alert->setFontName("Marker Felt");
        alert->setFontSize(20);
        alert->setColor(ccc3(159, 168, 176));
        alert->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 2.7));
        m_pUiLayer->addWidget(alert);
        
        // Create the loading bar
        UILoadingBar* loadingBar = UILoadingBar::create();
        loadingBar->setName("LoadingBar");
        loadingBar->loadTexture("cocosui/slider_bar_active_9patch.png");
        loadingBar->setScale9Enabled(true);
        loadingBar->setCapInsets(CCRectMake(0, 0, 0, 0));
        /*===*/
        loadingBar->setSize(CCSizeMake(300, loadingBar->getContentSize().height));
        /*=*/
        loadingBar->setPercent(0);
        
        loadingBar->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f + loadingBar->getSize().height / 4.0f));
        m_pUiLayer->addWidget(loadingBar);
        
        return true;
    }
    return false;
}
bool UILabelTest::init()
{
    if (UIScene::init())
    {
        CCSize screenSize = CCDirector::sharedDirector()->getWinSize();
        
        UILabel *alert = UILabel::create();
        alert->setText("Label");
        alert->setFontName("Marker Felt");
        alert->setFontSize(30);
        alert->setColor(ccc3(159, 168, 176));
//        alert->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f - alert->getRect().size.height * 1.75));
        m_pUiLayer->addWidget(alert);
        
        // Create the label
        UILabel* label = UILabel::create();
        label->setText("Label");
        label->setFontName("AmericanTypewriter");
        label->setFontSize(30);
//        label->setPosition(ccp(screenSize.width / 2, screenSize.height / 2 + label->getRect().size.height / 4));
        m_pUiLayer->addWidget(label);
        
        return true;
    }
    return false;
}
Exemplo n.º 9
0
void UIMenu::addMenuOption(const char* text, bool isSelected) {
	UILabel* label = new UILabel(gfx);
	if(isSelected)
		label->setColor(MENU_TEXT_COLOR_SELECTED);
	else label->setColor(MENU_TEXT_COLOR);
	label->setText(text, text_font, text_size);
	label->setPosition(vector2());
	label->setActive(false);
//	label->fadeIn();
	
	float minMenuSizeX = strlen(text)*(text_size-text_size/2);
	if(minMenuSizeX > size[0]) size[0] = minMenuSizeX;
	size[1] = (labels_n+1)*text_size;
	
	gfx->addSceneNode(label, this);
	labels.push_back(label);
	labels_n++;
}
Exemplo n.º 10
0
bool UIScrollViewTest_Both::init()
{
    if (UIScene::init())
    {
        CCSize widgetSize = m_pWidget->getSize();;
        
        // Add a label in which the dragpanel events will be displayed
        m_pDisplayValueLabel = UILabel::create();
        m_pDisplayValueLabel->setText("Move by any direction");
        m_pDisplayValueLabel->setFontName("Marker Felt");
        m_pDisplayValueLabel->setFontSize(32);
        m_pDisplayValueLabel->setAnchorPoint(ccp(0.5f, -1));
        m_pDisplayValueLabel->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f + m_pDisplayValueLabel->getSize().height * 1.5));
        m_pUiLayer->addWidget(m_pDisplayValueLabel);
        
        // Add the alert
        UILabel *alert = UILabel::create();
        alert->setText("ScrollView both");
        alert->setFontName("Marker Felt");
        alert->setFontSize(30);
        alert->setColor(ccc3(159, 168, 176));
        alert->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.075));
        m_pUiLayer->addWidget(alert);
        
        Layout *background = dynamic_cast<Layout*>(m_pUiLayer->getWidgetByName("background_Panel"));
        
        // Create the dragpanel
        UIScrollView* scrollView = UIScrollView::create();
        scrollView->setDirection(SCROLLVIEW_DIR_BOTH);
        scrollView->setTouchEnabled(true);
        scrollView->setBounceEnabled(true);
        scrollView->setBackGroundImageScale9Enabled(true);
        scrollView->setBackGroundImage("cocosgui/green_edit.png");
        scrollView->setSize(CCSizeMake(210, 122.5));
        CCSize backgroundSize = background->getContentSize();
        scrollView->setPosition(ccp((widgetSize.width - backgroundSize.width) / 2 +
                                    (backgroundSize.width - scrollView->getSize().width) / 2,
                                    (widgetSize.height - backgroundSize.height) / 2 +
                                    (backgroundSize.height - scrollView->getSize().height) / 2));
        UIImageView* imageView = UIImageView::create();
        imageView->setTouchEnabled(true);
        imageView->loadTexture("cocosgui/b11.png");
        scrollView->addChild(imageView);
        
        scrollView->setInnerContainerSize(imageView->getContentSize());
        CCSize innerSize = scrollView->getInnerContainerSize();
        imageView->setPosition(ccp(innerSize.width / 2, innerSize.height / 2));
        
        m_pUiLayer->addWidget(scrollView);
        
        return true;
    }
    
    return false;
}
Exemplo n.º 11
0
/*===*/
bool UISliderTest::init()
{
    if (UIScene::init())
    {
        CCSize widgetSize = m_pWidget->getSize();
        
        // Add a label in which the slider alert will be displayed
        m_pDisplayValueLabel = UILabel::create();
        m_pDisplayValueLabel->setText("Move the slider thumb");
        m_pDisplayValueLabel->setFontName("Marker Felt");
        m_pDisplayValueLabel->setFontSize(32);
        m_pDisplayValueLabel->setAnchorPoint(ccp(0.5f, -1));
        m_pDisplayValueLabel->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
        m_pUiLayer->addWidget(m_pDisplayValueLabel);
        
        // Add the alert
        UILabel *alert = UILabel::create();
        alert->setText("Slider");
        alert->setFontName("Marker Felt");
        alert->setFontSize(30);
        alert->setColor(ccc3(159, 168, 176));
        alert->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75));
        m_pUiLayer->addWidget(alert);
        
        // Create the slider
        UISlider* slider = UISlider::create();
        slider->setTouchEnabled(true);
        slider->loadBarTexture("cocosgui/sliderTrack.png");
        slider->loadSlidBallTextures("cocosgui/sliderThumb.png", "cocosgui/sliderThumb.png", "");
        slider->loadProgressBarTexture("cocosgui/sliderProgress.png");
        slider->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
//        slider->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f + slider->getSize().height * 2));
        slider->addEventListenerSlider(this, sliderpercentchangedselector(UISliderTest::sliderEvent));
        m_pUiLayer->addWidget(slider);

        /*
        // Create the slider that set allow min progress and allow max progress
        UISlider* sliderAllow = UISlider::create();
        //===//
//        sliderAllow->setMinAllowPercent(20);
//        sliderAllow->setMaxAllowPercent(80);
        //
        sliderAllow->setTouchEnabled(true);
        sliderAllow->loadBarTexture("cocosgui/sliderTrack.png");
        sliderAllow->loadSlidBallTextures("cocosgui/sliderThumb.png", "cocosgui/sliderThumb.png", "");
        sliderAllow->loadProgressBarTexture("cocosgui/sliderProgress.png");
        sliderAllow->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f - sliderAllow->getSize().height * 2));
        sliderAllow->addEventListenerSlider(this, sliderpercentchangedselector(UISliderTest::sliderEvent));
        m_pUiLayer->addWidget(sliderAllow);
         */
        
        return true;
    }
    return false;
}
Exemplo n.º 12
0
FindBar::FindBar() : UIElement() {
	barBg = new UIRect(30,30);
	barBg->setAnchorPoint(-1.0, -1.0, 0.0);
	barBg->color.setColorHexFromString(CoreServices::getInstance()->getConfig()->getStringValue("Polycode", "uiHeaderBgColor"));
	addChild(barBg);
	setHeight(30);
	
	UILabel *findLabel = new UILabel("FIND", 18, "section");
	addChild(findLabel);
	findLabel->setColor(1.0, 1.0, 1.0, 0.6);
	findLabel->setPosition(10,3);

	UILabel *replaceLabel = new UILabel("REPLACE", 18, "section");
	addChild(replaceLabel);
	replaceLabel->setColor(1.0, 1.0, 1.0, 0.6);
	replaceLabel->setPosition(200,3);
	
	processInputEvents = true;
	
	findInput = new UITextInput(false, 120, 12);
	addFocusChild(findInput);
	findInput->setPosition(60, 4);

	replaceInput = new UITextInput(false, 120, 12);
	addFocusChild(replaceInput);
	replaceInput->setPosition(280, 4);
	
	replaceAllButton = new UIButton("Replace All", 100);
	addFocusChild(replaceAllButton);
	replaceAllButton->setPosition(420, 3);

	UIImage *functionIcon = new UIImage("main/function_icon.png", 11, 17);
	addChild(functionIcon);
	functionIcon->setPosition(540, 6);
	
	functionList = new UIComboBox(globalMenu, 200);
	addChild(functionList);
	functionList->setPosition(560, 4);	
		
	closeButton = new UIImageButton("main/barClose.png", 1.0, 17, 17);
	addChild(closeButton);
}
Exemplo n.º 13
0
bool UILayoutTest_Color::init()
{
    if (UIScene::init())
    {
        CCSize widgetSize = m_pWidget->getSize();
        
        // Add the alert
        UILabel* alert = UILabel::create();
        alert->setText("Layout color render");
        alert->setFontName("Marker Felt");
        alert->setFontSize(30);
        alert->setColor(ccc3(159, 168, 176));
        alert->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.075));
        m_pUiLayer->addWidget(alert);
        
        UILayout *background = dynamic_cast<UILayout*>(m_pUiLayer->getWidgetByName("background_Panel"));
        
        // Create the layout with color render
        UILayout* layout = UILayout::create();
        layout->setBackGroundColorType(LAYOUT_COLOR_SOLID);
        layout->setBackGroundColor(ccc3(128, 128, 128));
        layout->setSize(CCSizeMake(280, 150));
        CCSize backgroundSize = background->getContentSize();
        layout->setPosition(ccp((widgetSize.width - backgroundSize.width) / 2 +
                                (backgroundSize.width - layout->getSize().width) / 2,
                                (widgetSize.height - backgroundSize.height) / 2 +
                                (backgroundSize.height - layout->getSize().height) / 2));
        m_pUiLayer->addWidget(layout);
        
        UIButton* button = UIButton::create();
        button->setTouchEnabled(true);
        button->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "");
        button->setPosition(ccp(button->getSize().width / 2, layout->getSize().height - button->getSize().height / 2));
        layout->addChild(button);
        
        UIButton* titleButton = UIButton::create();
        titleButton->setTouchEnabled(true);
        titleButton->loadTextures("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png", "");
        titleButton->setTitleText("Title Button");
        titleButton->setPosition(ccp(layout->getSize().width / 2, layout->getSize().height / 2));
        layout->addChild(titleButton);
        
        UIButton* button_scale9 = UIButton::create();
        button_scale9->setTouchEnabled(true);
        button_scale9->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", "");
        button_scale9->setScale9Enabled(true);
        button_scale9->setSize(CCSizeMake(100, button_scale9->getContentSize().height));
        button_scale9->setPosition(ccp(layout->getSize().width - button_scale9->getSize().width / 2, button_scale9->getSize().height / 2));
        layout->addChild(button_scale9);        
        
        return true;
    }
    return false;
}
void EquipmentUpgradeUILayer::showCurrentName(const char* name,const ccColor3B& color)
{
	if(m_equipmentLayout)
	{
		UILabel* label = m_equipmentLayout->FindChildObjectByName<UILabel>("equipUpgradeChoosedName");
		if(label)
		{
			label->setString(name);
			label->setColor(color);
		}
	}
}
void EquipmentUpgradeUILayer::showEquipName(unsigned int index,const char* name,const ccColor3B& color)
{
	if(m_equipmentLayout)
	{
		char lableName[30];
		sprintf(lableName,"equipUpgradeLabel%d",index);
		UILabel* label = m_equipmentLayout->FindChildObjectByName<UILabel>(lableName);
		if(label)
		{
			label->setString(name);
			label->setColor(color);
		}
	}
}
Exemplo n.º 16
0
bool UIScrollViewTest_ScrollToPercentBothDirection_Bounce::init()
{
    if (UIScene::init())
    {
        CCSize widgetSize = m_pWidget->getSize();
        
        // Add a label in which the dragpanel events will be displayed
        m_pDisplayValueLabel = UILabel::create();
//        m_pDisplayValueLabel->setText("No Event");
        m_pDisplayValueLabel->setFontName("Marker Felt");
        m_pDisplayValueLabel->setFontSize(32);
        m_pDisplayValueLabel->setAnchorPoint(ccp(0.5f, -1));
        m_pDisplayValueLabel->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f + m_pDisplayValueLabel->getSize().height * 1.5));
        m_pUiLayer->addWidget(m_pDisplayValueLabel);
        
        // Add the alert
        UILabel *alert = UILabel::create();
        alert->setText("ScrollView scroll to percent both directrion bounce");
        alert->setFontName("Marker Felt");
        alert->setFontSize(20);
        alert->setColor(ccc3(159, 168, 176));
        alert->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 4.5));
        m_pUiLayer->addWidget(alert);
        
        UILayout* background = dynamic_cast<UILayout*>(m_pUiLayer->getWidgetByName("background_Panel"));
        
        UIScrollView* sc = UIScrollView::create();
        sc->setBackGroundColor(ccGREEN);
        sc->setBackGroundColorType(LAYOUT_COLOR_SOLID);
        sc->setBounceEnabled(true);
        sc->setDirection(SCROLLVIEW_DIR_BOTH);
        sc->setInnerContainerSize(CCSizeMake(480, 320));
        sc->setSize(CCSizeMake(100,100));
        CCSize backgroundSize = background->getContentSize();
        sc->setPosition(ccp((widgetSize.width - backgroundSize.width) / 2 +
                            (backgroundSize.width - sc->getSize().width) / 2,
                            (widgetSize.height - backgroundSize.height) / 2 +
                            (backgroundSize.height - sc->getSize().height) / 2));
        sc->scrollToPercentBothDirection(ccp(50, 50), 1, true);
        UIImageView* iv = UIImageView::create();
        iv->loadTexture("cocosgui/Hello.png");
        iv->setPosition(ccp(240, 160));
        sc->addChild(iv);
        m_pUiLayer->addWidget(sc);
        return true;
    }
    
    return false;
}
Exemplo n.º 17
0
bool UISwitchTest_VerticalAndTitleVertical::init()
{
    if (UIScene::init())
    {
        CCSize widgetSize = m_pWidget->getSize();
        
        // Add a label in which the switch events will be displayed
        m_pDisplayValueLabel = UILabel::create();
        m_pDisplayValueLabel->setText("No Event");
        m_pDisplayValueLabel->setFontName("Marker Felt");
        m_pDisplayValueLabel->setFontSize(32);
        m_pDisplayValueLabel->setAnchorPoint(ccp(0.5f, -1));
        m_pDisplayValueLabel->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
        m_pUiLayer->addWidget(m_pDisplayValueLabel);
        
        // Add the alert
        UILabel *alert = UILabel::create();
        alert->setText("Switch Vertical and Title Vertical");
        alert->setFontName("Marker Felt");
        alert->setFontSize(20);
        alert->setColor(ccc3(159, 168, 176));
        alert->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 2.7));
        m_pUiLayer->addWidget(alert);
        
        // Create the switch
        UISwitch* pSwitch = UISwitch::create();
        pSwitch->setTouchEnabled(true);
        pSwitch->loadTextures("cocosgui/switch-mask_v.png", "cocosgui/switch-on_v.png", "cocosgui/switch-off_v.png", "cocosgui/switch-thumb_v.png");
        pSwitch->setOnTitleText("On");
        pSwitch->setOffTitleText("Off");
        pSwitch->setOnTitleFontName("Arial-BoldMT");
        pSwitch->setOnTitleFontSize(16);
        pSwitch->setOffTitleFontName("Arial-BoldMT");
        pSwitch->setOffTitleFontSize(16);
        CCSize switchSize = pSwitch->getSize();
        pSwitch->setPosition(ccp((widgetSize.width - switchSize.width) / 2.0f, (widgetSize.height - switchSize.height) / 2.0f));
        pSwitch->addEventListenerSwitch(this, switchselector(UISwitchTest_Horizontal::switchEvent));
        m_pUiLayer->addWidget(pSwitch);
        
        
        pSwitch->setDirection(SWITCH_DIRECTION_VERTICAL);
        
        // set unicode text with title vertical direction
        pSwitch->setTitleDirection(SWITCH_TITLE_DIRECTION_VERTICAL);
        
        return true;
    }
    return false;
}
Exemplo n.º 18
0
void UIMenu::addMenuBreak() {
	UILabel* label = new UILabel(gfx);
	label->setColor(MENU_TEXT_COLOR);
	label->setText("...", 0, text_size);
	label->setPosition(vector2());
	label->setActive(false);
//	label->fadeIn();
	
	//size[0] = 18;
	size[1] = (labels_n+1)*text_size;
	
	gfx->addSceneNode(label, this);
	labels.push_back(label);
	labels_n++;	
}
Exemplo n.º 19
0
bool UISwitchTest_Horizontal::init()
{
    if (UIScene::init())
    {
        CCSize widgetSize = m_pWidget->getSize();
        
        // Add a label in which the switch events will be displayed
        m_pDisplayValueLabel = UILabel::create();
        m_pDisplayValueLabel->setText("No Event");
        m_pDisplayValueLabel->setFontName("Marker Felt");
        m_pDisplayValueLabel->setFontSize(32);
        m_pDisplayValueLabel->setAnchorPoint(ccp(0.5f, -1));
        m_pDisplayValueLabel->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
        m_pUiLayer->addWidget(m_pDisplayValueLabel);
        
        // Add the alert
        UILabel *alert = UILabel::create();
        alert->setText("Switch Horizontal");
        alert->setFontName("Marker Felt");
        alert->setFontSize(30);
        alert->setColor(ccc3(159, 168, 176));
        alert->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75));
        m_pUiLayer->addWidget(alert);
        
        // Create the switch
        UISwitch* pSwitch = UISwitch::create();
        pSwitch->setTouchEnabled(true);
        pSwitch->loadTextures("cocosgui/switch-mask.png", "cocosgui/switch-on.png", "cocosgui/switch-off.png", "cocosgui/switch-thumb.png");
        pSwitch->setOnTitleText("Hello\nWorld");
        pSwitch->setOffTitleText("Come\nOn");
        pSwitch->setOnTitleFontName("Arial-BoldMT");
        pSwitch->setOnTitleFontSize(10);
        pSwitch->setOffTitleFontName("Arial-BoldMT");
        pSwitch->setOffTitleFontSize(10);
        CCSize switchSize = pSwitch->getSize();
        pSwitch->setPosition(ccp((widgetSize.width - switchSize.width) / 2.0f, (widgetSize.height - switchSize.height) / 2.0f));
        pSwitch->addEventListenerSwitch(this, switchselector(UISwitchTest_Horizontal::switchEvent));
        m_pUiLayer->addWidget(pSwitch);
        
        return true;
    }
    return false;
}
Exemplo n.º 20
0
bool UITextFieldTest_LineWrap::init()
{
    if (UIScene::init())
    {
        CCSize widgetSize = m_pWidget->getSize();
        
        // Add a label in which the textfield events will be displayed
        m_pDisplayValueLabel = UILabel::create();
        m_pDisplayValueLabel->setText("No Event");
        m_pDisplayValueLabel->setFontName("Marker Felt");
        m_pDisplayValueLabel->setFontSize(30);
        m_pDisplayValueLabel->setAnchorPoint(ccp(0.5f, -1));
        m_pDisplayValueLabel->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f + m_pDisplayValueLabel->getSize().height * 1.5));
        m_pUiLayer->addWidget(m_pDisplayValueLabel);
        
        // Add the alert
        UILabel *alert = UILabel::create();
        alert->setText("TextField line wrap");
        alert->setFontName("Marker Felt");
        alert->setFontSize(30);
        alert->setColor(ccc3(159, 168, 176));
        alert->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.075));
        m_pUiLayer->addWidget(alert);
        
        // Create the textfield
        UITextField* textField = UITextField::create();
        UICCTextField* render = static_cast<UICCTextField*>(textField->getVirtualRenderer());
        render->setDimensions(CCSizeMake(240, 160));
        render->setHorizontalAlignment(kCCTextAlignmentCenter);
        render->setVerticalAlignment(kCCVerticalTextAlignmentCenter);
        textField->setTouchEnabled(true);
        textField->setFontName("Marker Felt");
        textField->setFontSize(30);
        textField->setPlaceHolder("input words here");
        textField->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
        textField->addEventListenerTextField(this, textfieldeventselector(UITextFieldTest_LineWrap::textFieldEvent));
        m_pUiLayer->addWidget(textField);
        
        return true;
    }
    return false;
}
Exemplo n.º 21
0
bool UITextFieldTest_Password::init()
{
    if (UIScene::init())
    {
        CCSize screenSize = CCDirector::sharedDirector()->getWinSize();
        
        // Add a label in which the textfield events will be displayed
        m_pDisplayValueLabel = UILabel::create();
        m_pDisplayValueLabel->setText("No Event");
        m_pDisplayValueLabel->setFontName("Marker Felt");
        m_pDisplayValueLabel->setFontSize(32);
        m_pDisplayValueLabel->setAnchorPoint(ccp(0.5f, -1));
        m_pDisplayValueLabel->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f + m_pDisplayValueLabel->getSize().height * 1.5));
        m_pUiLayer->addWidget(m_pDisplayValueLabel);
        
        // Add the alert
        UILabel *alert = UILabel::create();
        alert->setText("TextField password");
        alert->setFontName("Marker Felt");
        alert->setFontSize(30);
        alert->setColor(ccc3(159, 168, 176));
        alert->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f - alert->getSize().height * 3.0f));
        m_pUiLayer->addWidget(alert);
        
        // Create the textfield
        UITextField* textField = UITextField::create();
        textField->setPasswordEnabled(true);
        textField->setPasswordStyleText("*");
        textField->setTouchEnabled(true);
        textField->setFontName("Marker Felt");
        textField->setFontSize(30);
        textField->setPlaceHolder("input password here");
        textField->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f));
        textField->addEventListenerTextField(this, textfieldeventselector(UITextFieldTest_Password::textFieldEvent));
        m_pUiLayer->addWidget(textField);
        
        return true;
    }
    return false;
}
Exemplo n.º 22
0
bool UIButtonTest_Scale9::init()
{
    if (UIScene::init())
    {
        CCSize widgetSize = m_pWidget->getSize();
        
        // Add a label in which the button events will be displayed
        m_pDisplayValueLabel = UILabel::create();
        m_pDisplayValueLabel->setText("No Event");
        m_pDisplayValueLabel->setFontName("Marker Felt");
        m_pDisplayValueLabel->setFontSize(32);
        m_pDisplayValueLabel->setAnchorPoint(ccp(0.5f, -1));
        m_pDisplayValueLabel->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
        m_pUiLayer->addWidget(m_pDisplayValueLabel);
        
        // Add the alert
        UILabel* alert = UILabel::create();
        alert->setText("Button scale9 render");
        alert->setFontName("Marker Felt");
        alert->setFontSize(30);
        alert->setColor(ccc3(159, 168, 176));
        alert->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75));
        m_pUiLayer->addWidget(alert);
        
        // Create the button
        UIButton* button = UIButton::create();
        button->setTouchEnabled(true);
        // open scale9 render
        button->setScale9Enabled(true);
        button->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", "");
        button->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
        button->setSize(CCSizeMake(150, button->getContentSize().height * 1.5f));
        button->addTouchEventListener(this, toucheventselector(UIButtonTest_Scale9::touchEvent));
        m_pUiLayer->addWidget(button);
        
        return true;
    }
    return false;
}
bool UINodeContainerTest::init()
{
    if (UIScene::init())
    {
        CCSize screenSize = CCDirector::sharedDirector()->getWinSize();
        
        // Add a label in which the UINodeContainer alert will be displayed
        m_pDisplayValueLabel = UILabel::create();
        m_pDisplayValueLabel->setText("NodeContainer Add CCNode");
        m_pDisplayValueLabel->setFontName("Marker Felt");
        m_pDisplayValueLabel->setFontSize(32);
        m_pDisplayValueLabel->setAnchorPoint(ccp(0.5f, -1));
//        m_pDisplayValueLabel->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f + m_pDisplayValueLabel->getContentSize().height * 1.5));
        m_pUiLayer->addWidget(m_pDisplayValueLabel);
        
        // Add the alert
        UILabel *alert = UILabel::create();
        alert->setText("NodeContainer");
        alert->setFontName("Marker Felt");
        alert->setFontSize(30);
        alert->setColor(ccc3(159, 168, 176));
//        alert->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f - alert->getRect().size.height * 1.75));
        m_pUiLayer->addWidget(alert);
        
        // Create the ui node container
        UINodeContainer* nodeContainer = UINodeContainer::create();
        nodeContainer->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f));
        m_pUiLayer->addWidget(nodeContainer);
        
        CCSprite* sprite = CCSprite::create("cocosgui/ccicon.png");
        sprite->setPosition(ccp(0, sprite->boundingBox().size.height / 4));
        nodeContainer->addCCNode(sprite);
        
        return true;
    }
    return false;
}
bool UIImageViewTest::init()
{
    if (UIScene::init())
    {
        CCSize screenSize = CCDirector::sharedDirector()->getWinSize();                
        
        UILabel *alert = UILabel::create();
        alert->setText("ImageView");
        alert->setFontName("Marker Felt");
        alert->setFontSize(30);
        alert->setColor(ccc3(159, 168, 176));
//        alert->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f - alert->getRect().size.height * 1.75));
        m_pUiLayer->addWidget(alert);
        
        // Create the imageview
        UIImageView *imageView = UIImageView::create();
        imageView->loadTexture("cocosgui/ccicon.png");
//        imageView->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f + imageView->getRect().size.height / 4.0f));
        m_pUiLayer->addWidget(imageView);
        
        return true;
    }
    return false;
}
bool UIPanelTest_Color::init()
{
    if (UIScene::init())
    {
        CCSize screenSize = CCDirector::sharedDirector()->getWinSize();        
        
        // Add the alert
        UILabel *alert = UILabel::create();
        alert->setText("Panel color render");
        alert->setFontName("Marker Felt");
        alert->setFontSize(30);
        alert->setColor(ccc3(159, 168, 176));
        alert->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f - alert->getRect().size.height * 2.925));
        m_pUiLayer->addWidget(alert);
        
        UIPanel *background = dynamic_cast<UIPanel*>(m_pUiLayer->getWidgetByName("background_Panel"));
        
        // Create the panel with color render
        UIPanel* panel = UIPanel::create();
        panel->setBackGroundColorType(PANEL_COLOR_SOLID);
        panel->setBackGroundColor(ccc3(128, 128, 128));
        panel->setClippingEnable(true);
        panel->setSize(CCSizeMake(280, 150));
        CCSize backgroundSize = background->getContentSize();
        panel->setPosition(ccp((screenSize.width - backgroundSize.width) / 2 +
                               (backgroundSize.width - panel->getRect().size.width) / 2,
                               (screenSize.height - backgroundSize.height) / 2 +
                               (backgroundSize.height - panel->getRect().size.height) / 2));
        m_pUiLayer->addWidget(panel);
        
        UIButton* button = UIButton::create();
        button->setTouchEnable(true);
        button->setTextures("cocosgui/animationbuttonnormal.png", "cocosgui/animationbuttonpressed.png", "");
        button->setPosition(ccp(button->getRect().size.width / 2, panel->getRect().size.height - button->getRect().size.height / 2));
        panel->addChild(button);
        
        UITextButton* textButton = UITextButton::create();
        textButton->setTouchEnable(true);
        textButton->setTextures("cocosgui/backtotopnormal.png", "cocosgui/backtotoppressed.png", "");
        textButton->setText("Text Button");
        textButton->setPosition(ccp(panel->getRect().size.width / 2, panel->getRect().size.height / 2));
        panel->addChild(textButton);
        
        UIZoomButton* zoomButton = UIZoomButton::create();
        zoomButton->setTouchEnable(true);
        zoomButton->setTextures("cocosgui/button.png", "cocosgui/buttonHighlighted.png", "cocosgui/button.png");
        zoomButton->setTitle("ControlButton", "ControlButton", "ControlButton");
        zoomButton->setNormalFontSize(16);
        zoomButton->setNormalFontName("Marker Felt");
        zoomButton->setPressedFontSize(16);
        zoomButton->setPressedFontName("Marker Felt");
        zoomButton->setDisabledFontSize(16);
        zoomButton->setDisabledFontName("Marker Felt");
        zoomButton->setPreferredSize(CCSizeMake(100, zoomButton->getContentSize().height * 2.0f));
        zoomButton->setPosition(ccp(panel->getRect().size.width - zoomButton->getRect().size.width / 2,
                                       zoomButton->getRect().size.height / 2));
        panel->addChild(zoomButton);
        
        return true;
    }
    return false;
}
Exemplo n.º 26
0
void TaskChatLayer::ShowTaskItemWithFlagStateAndName(int itemIndex,eTaskState taskState,std::string content)
{
	UIPicture* newTaskIcon = 0;
	UIPicture* runingTaskIcon = 0;
	UIPicture* waitRewardIcon = 0;
	UILabel* taskNameLabel = 0;

	std::string newTaskIconName = "";
	std::string runingTaskIconName = "";
	std::string waitRewardIconName = "";
	std::string taskNameIconName = "";

	switch (itemIndex)
	{
	case 0:
		{
			newTaskIconName = "TaskNewFlagPic_01";
			runingTaskIconName = "TaskRuningFlagPic_01";
			waitRewardIconName = "TaskCompleteFlagPic_01";
			taskNameIconName = "HeroTaskTalkLabel_01";
		}
		break;
	case 1:
		{
			newTaskIconName = "TaskNewFlagPic_02";
			runingTaskIconName = "TaskRuningFlagPic_02";
			waitRewardIconName = "TaskCompleteFlagPic_02";
			taskNameIconName = "HeroTaskTalkLabel_02";
		}
		break;
	case 2:
		{
			newTaskIconName = "TaskNewFlagPic_03";
			runingTaskIconName = "TaskRuningFlagPic_03";
			waitRewardIconName = "TaskCompleteFlagPic_03";
			taskNameIconName = "HeroTaskTalkLabel_03";
		}
		break;
	}

	newTaskIcon = taskChatLayout->FindChildObjectByName<UIPicture>(newTaskIconName.c_str());
	runingTaskIcon = taskChatLayout->FindChildObjectByName<UIPicture>(runingTaskIconName.c_str());
	waitRewardIcon = taskChatLayout->FindChildObjectByName<UIPicture>(waitRewardIconName.c_str());
	taskNameLabel = taskChatLayout->FindChildObjectByName<UILabel>(taskNameIconName.c_str());

	newTaskIcon->getCurrentNode()->setVisible(false);
	runingTaskIcon->getCurrentNode()->setVisible(false);
	waitRewardIcon->getCurrentNode()->setVisible(false);

	bool bUseSpecialColor = false;

	switch(taskState)
	{
	case kType_TASK_NOT_ACCEPT:
		{
			newTaskIcon->getCurrentNode()->setVisible(true);
			bUseSpecialColor = true;
		}
		break;
	case kType_TASK_RUNNING:
		{
			runingTaskIcon->getCurrentNode()->setVisible(true);
		}
		break;
	case kType_TASK_WAIT_REWARD:
		{
			waitRewardIcon->getCurrentNode()->setVisible(true);
			bUseSpecialColor = true;
		}
		break;
	}

	taskNameLabel->setString(content.c_str());
	if (bUseSpecialColor)
	{
		taskNameLabel->setColor(ccc3(238,166,26));
	}	
	else
	{
		taskNameLabel->setColor(ccc3(255,255,255));
	}
}
Exemplo n.º 27
0
void Game::startIntroCutscene() {
	gfx->recomputeBackground();
	gfx->getUI()->darkenScreen(1.f);
	if(introCutscene) gfx->deleteSceneNode(introCutscene);
	introCutscene = new UICutscene(gfx);

	vector2 wparams = gfx->getRenderer()->getWindowParams();
	vector2 center = wparams*0.5f;

	/*** FRAME 0 ***/
	introCutscene->startFrame(3.f);

	UILabel* text = new UILabel(gfx);
	text->setColor(color(0.7f, 0.7f, 0.7f, 0.f));
	text->setText("powered by", 0, 32.f);
	text->setPosition(center+vector2(-150.f, 100.f));
//	text->fadeOut();

	UIImage* gllogo = new UIImage(gfx);
	gllogo->setImage("LOGOS");
	gllogo->setPosition(vector2(center[0]-100.f, center[1]-gllogo->getSize()[1]+100.f));
//	gllogo->fadeOut();
	introCutscene->addWidgetToFrame(text);
	introCutscene->addWidgetToFrame(gllogo);

	introCutscene->endFrame();

	/*** FRAME 1 ***/

	introCutscene->startFrame(6.f);

	text = new UILabel(gfx);
	text->setColor(color(0.7f, 0.7f, 0.7f, 0.f));
//	text->setText("Copyright 2010 Alexander Dzhoganov", 0, 32.f);
	text->setText(GNU_COPYRIGHT_NOTICE, 0, 20.f);
	text->setPosition(vector2(center[0]-400.f, center[1]));
	text->fadeOut();
	introCutscene->addWidgetToFrame(text);

	UILabel* skiplabel = new UILabel(gfx);
	skiplabel->setColor(color(0.4f, 0.4f, 0.4f, 0.f));
	skiplabel->setText("press  [space ] to skip intro", 0, 16.f);
	skiplabel->setPosition(vector2(wparams[0]-320.f, 50.f));

	introCutscene->addWidgetToFrame(skiplabel);

	introCutscene->endFrame();

	/*** FRAME 2 ***/

	introCutscene->startFrame(3.f);

	text = new UILabel(gfx);
	text->setColor(color(0.7f, 0.7f, 0.7f, 0.f));
	text->setText("a game by Alexander Dzhoganov", 0, 32.f);
	text->setPosition(center);
	text->fadeOut();
	introCutscene->addWidgetToFrame(text);

	introCutscene->endFrame();

	/*** FRAME 3 ***/

	introCutscene->startFrame(3.f);

	text = new UILabel(gfx);
	text->setColor(color(0.7f, 0.7f, 0.7f, 0.f));
	text->setText("programming by:\nAlexander Dzhoganov\n\nart by:\nViktor Popov", 0, 32.f);
	text->setPosition(center);
	text->fadeOut();
	introCutscene->addWidgetToFrame(text);

	introCutscene->endFrame();


	gfx->getUI()->addWidget(introCutscene);
}
bool UIListViewExTest_Horizontal::init()
{
    if (UIScene::init())
    {
        CCSize widgetSize = m_pWidget->getSize();
        
        m_pDisplayValueLabel = UILabel::create();
        m_pDisplayValueLabel->setText("Move by horizontal direction");
        m_pDisplayValueLabel->setFontName("Marker Felt");
        m_pDisplayValueLabel->setFontSize(32);
        m_pDisplayValueLabel->setAnchorPoint(ccp(0.5f, -1));
        m_pDisplayValueLabel->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f + m_pDisplayValueLabel->getContentSize().height * 1.5));
        m_pUiLayer->addWidget(m_pDisplayValueLabel);
        
        
        UILabel* alert = UILabel::create();
        alert->setText("ListView horizontal");
        alert->setFontName("Marker Felt");
        alert->setFontSize(30);
        alert->setColor(ccc3(159, 168, 176));
        alert->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.075));
        m_pUiLayer->addWidget(alert);
        
        Layout* background = dynamic_cast<Layout*>(m_pUiLayer->getWidgetByName("background_Panel"));
        CCSize backgroundSize = background->getContentSize();
        
        
        // create list view data
        m_array = CCArray::create();
        CC_SAFE_RETAIN(m_array);
        for (int i = 0; i < 20; ++i)
        {
            CCString* ccstr = CCString::createWithFormat("listview_item_%d", i);
            m_array->addObject(ccstr);
        }
        
        
        // Create the list view
        UIListView* listView = UIListView::create();
        // set list view direction
        listView->setDirection(SCROLLVIEW_DIR_HORIZONTAL);
        listView->setTouchEnabled(true);
        listView->setBounceEnabled(true);
        listView->setBackGroundImage("cocosgui/green_edit.png");
        listView->setBackGroundImageScale9Enabled(true);
        listView->setSize(CCSizeMake(240, 130));
        listView->setPosition(ccp((widgetSize.width - backgroundSize.width) / 2 +
                                    (backgroundSize.width - listView->getSize().width) / 2,
                                    (widgetSize.height - backgroundSize.height) / 2 +
                                    (backgroundSize.height - listView->getSize().height) / 2));
        listView->addEventListenerListView(this, listvieweventselector(UIListViewExTest_Horizontal::selectedItemEvent));
        m_pUiLayer->addWidget(listView);
        
        
        // create model
        UIButton* default_button = UIButton::create();
        default_button->setName("TextButton");
        default_button->setTouchEnabled(true);
        default_button->loadTextures("cocosgui/backtotoppressed.png", "cocosgui/backtotopnormal.png", "");
        
        Layout* default_item = Layout::create();
        default_item->setTouchEnabled(true);
        default_item->setSize(default_button->getSize());
        default_button->setPosition(ccp(default_item->getSize().width / 2, default_item->getSize().height / 2));
        default_item->addChild(default_button);
        
        // set model
        listView->setItemModel(default_item);
        
        // add default item
        int count = m_array->count();
        for (int i = 0; i < count / 4; ++i)
        {
            listView->pushBackDefaultItem();
        }
        // insert default item
        for (int i = 0; i < count / 4; ++i)
        {
            listView->insertDefaultItem(0);
        }
        
        // add custom item
        for (int i = 0; i < count / 4; ++i)
        {
            UIButton* custom_button = UIButton::create();
            custom_button->setName("TextButton");
            custom_button->setTouchEnabled(true);
            custom_button->loadTextures("cocosgui/button.png", "cocosgui/buttonHighlighted.png", "");
            custom_button->setScale9Enabled(true);
            custom_button->setSize(default_button->getSize());
            
            Layout *custom_item = Layout::create();
            custom_item->setSize(custom_button->getSize());
            custom_button->setPosition(ccp(custom_item->getSize().width / 2, custom_item->getSize().height / 2));
            custom_item->addChild(custom_button);
            
            listView->pushBackCustomItem(custom_item);
        }
        // insert custom item
        CCArray *items = listView->getItems();
        int items_count = items->count();
        for (int i = 0; i < count / 4; ++i)
        {
            UIButton* custom_button = UIButton::create();
            custom_button->setName("TextButton");
            custom_button->setTouchEnabled(true);
            custom_button->loadTextures("cocosgui/button.png", "cocosgui/buttonHighlighted.png", "");
            custom_button->setScale9Enabled(true);
            custom_button->setSize(default_button->getSize());
            
            Layout *custom_item = Layout::create();
            custom_item->setSize(custom_button->getSize());
            custom_button->setPosition(ccp(custom_item->getSize().width / 2, custom_item->getSize().height / 2));
            custom_item->addChild(custom_button);
            
            listView->insertCustomItem(custom_item, items_count);
        }
        
        // set item data
        items_count = items->count();
        for (int i = 0; i < items_count; ++i)
        {
            UIWidget *item = listView->getItem(i);
            UIButton *button = static_cast<UIButton*>(item->getChildByName("TextButton"));
            int index = listView->getIndex(item);
            button->setTitleText(static_cast<CCString*>(m_array->objectAtIndex(index))->getCString());
        }
        
        // remove last item
        listView->removeLastItem();
        
        // remove item by index
        items_count = items->count();
        listView->removeItem(items_count - 1);        
        
        // set all items layout gravity
        listView->setGravity(LISTVIEW_GRAVITY_CENTER_VERTICAL);
        
        // set items margin
        listView->setItemsMargin(2);
        
        return true;
    }
    
    return false;
}
Exemplo n.º 29
0
bool UIScrollViewTest_Vertical::init()
{
    if (UIScene::init())
    {
        CCSize widgetSize = m_pWidget->getSize();
        
        // Add a label in which the scrollview alert will be displayed
        m_pDisplayValueLabel = UILabel::create();
        m_pDisplayValueLabel->setText("Move by vertical direction");
        m_pDisplayValueLabel->setFontName("Marker Felt");
        m_pDisplayValueLabel->setFontSize(32);
        m_pDisplayValueLabel->setAnchorPoint(ccp(0.5f, -1));
        m_pDisplayValueLabel->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f + m_pDisplayValueLabel->getContentSize().height * 1.5));
        m_pUiLayer->addWidget(m_pDisplayValueLabel);
        
        // Add the alert
        UILabel *alert = UILabel::create();
        alert->setText("ScrollView vertical");
        alert->setFontName("Marker Felt");
        alert->setFontSize(30);
        alert->setColor(ccc3(159, 168, 176));
        alert->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.075));
        m_pUiLayer->addWidget(alert);
        
        UILayout *background = dynamic_cast<UILayout*>(m_pUiLayer->getWidgetByName("background_Panel"));
        
        // Create the scrollview by vertical
        UIScrollView* scrollView = UIScrollView::create();
        scrollView->setTouchEnabled(true);
        scrollView->setBounceEnabled(true);
        scrollView->setSize(CCSizeMake(280, 150));        
        CCSize backgroundSize = background->getContentSize();
        scrollView->setPosition(ccp((widgetSize.width - backgroundSize.width) / 2 +
                               (backgroundSize.width - scrollView->getSize().width) / 2,
                               (widgetSize.height - backgroundSize.height) / 2 +
                               (backgroundSize.height - scrollView->getSize().height) / 2));
        scrollView->addEventListenerScrollView(this, scrollvieweventselector(UIScrollViewTest_Vertical::scrollEvent));
        m_pUiLayer->addWidget(scrollView);
        
        UIImageView* imageView = UIImageView::create();
        imageView->loadTexture("cocosgui/ccicon.png");
        
        float innerWidth = scrollView->getSize().width;
        float innerHeight = scrollView->getSize().height + imageView->getSize().height * 2;
        
        scrollView->setInnerContainerSize(CCSizeMake(innerWidth, innerHeight));
        
        
        UIButton* button = UIButton::create();
        button->setTouchEnabled(true);
        button->loadTextures("cocosgui/animationbuttonnormal.png", "cocosgui/animationbuttonpressed.png", "");
        button->setPosition(ccp(innerWidth / 2, scrollView->getInnerContainerSize().height - button->getSize().height / 2));
        scrollView->addChild(button);
        
        UIButton* titleButton = UIButton::create();
        titleButton->setTouchEnabled(true);
        titleButton->loadTextures("cocosgui/backtotopnormal.png", "cocosgui/backtotoppressed.png", "");
        titleButton->setTitleText("Title Button");
        titleButton->setPosition(ccp(innerWidth / 2, button->getBottomInParent() - button->getSize().height));
        scrollView->addChild(titleButton);
        
        UIButton* button_scale9 = UIButton::create();
        button_scale9->setTouchEnabled(true);
        button_scale9->setScale9Enabled(true);
        button_scale9->loadTextures("cocosgui/button.png", "cocosgui/buttonHighlighted.png", "");
        button_scale9->setSize(CCSizeMake(100, button_scale9->getContentSize().height));
        button_scale9->setPosition(ccp(innerWidth / 2, titleButton->getBottomInParent() - titleButton->getSize().height));
        scrollView->addChild(button_scale9);
        
        imageView->setPosition(ccp(innerWidth / 2, imageView->getSize().height / 2));
        scrollView->addChild(imageView);
        
        
        
        
//        UIButton* button_1 = UIButton::create();
//        button_1->setTouchEnabled(true);
//        button_1->loadTextures("cocosgui/animationbuttonnormal.png", "cocosgui/animationbuttonpressed.png", "");
//        button_1->addTouchEventListener(this, toucheventselector(UIScrollViewTest_Vertical::touchEvent));
//        
//        Layout* layout = Layout::create();
//        layout->setSize(button_1->getSize());
//        layout->setBackGroundImage("cocosgui/green_edit.png");
//        layout->setBackGroundImageScale9Enabled(true);
////        layout->setBackGroundColorType(LAYOUT_COLOR_SOLID);
////        layout->setBackGroundColor(ccc3(0, 255, 0));
//        layout->setPosition(ccp(imageView->getPosition().x, layout->getSize().height * 2));
//        
//        button_1->setPosition(ccp(button_1->getSize().width / 2, button_1->getSize().height / 2));
//        
//        layout->addChild(button_1);
//        scrollView->addChild(layout);
        
        return true;
    }
    
    return false;
}
Exemplo n.º 30
0
bool UIScrollViewTest_Horizontal::init()
{
    if (UIScene::init())
    {
        CCSize widgetSize = m_pWidget->getSize();
        
        // Add a label in which the scrollview alert will be displayed
        m_pDisplayValueLabel = UILabel::create();
        m_pDisplayValueLabel->setText("Move by horizontal direction");
        m_pDisplayValueLabel->setFontName("Marker Felt");
        m_pDisplayValueLabel->setFontSize(32);
        m_pDisplayValueLabel->setAnchorPoint(ccp(0.5f, -1));
        m_pDisplayValueLabel->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f + m_pDisplayValueLabel->getContentSize().height * 1.5));
        m_pUiLayer->addWidget(m_pDisplayValueLabel);            
        
        UILabel *alert = UILabel::create();
        alert->setText("ScrollView horizontal");
        alert->setFontName("Marker Felt");
        alert->setFontSize(30);
        alert->setColor(ccc3(159, 168, 176));
        alert->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.075));
        m_pUiLayer->addWidget(alert);
        
        UILayout *background = dynamic_cast<UILayout*>(m_pUiLayer->getWidgetByName("background_Panel"));
        
        // Create the scrollview by horizontal
        UIScrollView* scrollView = UIScrollView::create();        
        scrollView->setDirection(SCROLLVIEW_DIR_HORIZONTAL);
        scrollView->setBounceEnabled(true);
        scrollView->setTouchEnabled(true);
        scrollView->setSize(CCSizeMake(280, 150));
        scrollView->setInnerContainerSize(scrollView->getSize());
        CCSize backgroundSize = background->getContentSize();
        scrollView->setPosition(ccp((widgetSize.width - backgroundSize.width) / 2 +
                                    (backgroundSize.width - scrollView->getSize().width) / 2,
                                    (widgetSize.height - backgroundSize.height) / 2 +
                                    (backgroundSize.height - scrollView->getSize().height) / 2));
        m_pUiLayer->addWidget(scrollView);
        
        UIImageView* imageView = UIImageView::create();
        imageView->loadTexture("cocosgui/ccicon.png");
        
        float innerWidth = scrollView->getSize().width + imageView->getSize().width * 2;
        float innerHeight = scrollView->getSize().height;
        
        scrollView->setInnerContainerSize(CCSizeMake(innerWidth, innerHeight));
        
        UIButton* button = UIButton::create();
        button->setTouchEnabled(true);
        button->loadTextures("cocosgui/animationbuttonnormal.png", "cocosgui/animationbuttonpressed.png", "");
        button->setPosition(ccp(button->getSize().width / 2,
                                scrollView->getInnerContainerSize().height - button->getSize().height / 2));
        scrollView->addChild(button);
        
        UIButton* titleButton = UIButton::create();
        titleButton->setTouchEnabled(true);
        titleButton->loadTextures("cocosgui/backtotopnormal.png", "cocosgui/backtotoppressed.png", "");
        titleButton->setTitleText("Title Button");
        titleButton->setPosition(ccp(button->getRightInParent() + button->getSize().width / 2,
                                    button->getBottomInParent() - button->getSize().height / 2));
        scrollView->addChild(titleButton);
        
        UIButton* button_scale9 = UIButton::create();
        button_scale9->setTouchEnabled(true);
        button_scale9->setScale9Enabled(true);
        button_scale9->loadTextures("cocosgui/button.png", "cocosgui/buttonHighlighted.png", "");
        button_scale9->setSize(CCSizeMake(100, button_scale9->getContentSize().height));
        button_scale9->setPosition(ccp(titleButton->getRightInParent() + titleButton->getSize().width / 2,
                                       titleButton->getBottomInParent() - titleButton->getSize().height / 2));
        scrollView->addChild(button_scale9);                
                
        imageView->setPosition(ccp(innerWidth - imageView->getSize().width / 2,
                                   button_scale9->getBottomInParent() - button_scale9->getSize().height / 2));
        scrollView->addChild(imageView);                
        
        return true;
    }
    
    return false;
}