Example #1
0
bool UIStrengthen::init()
{
	if (!CCLayer::init())
	{
		return false;
	}

	uiLayer = UILayer::create();

	UILayout* strengthenRoot = dynamic_cast<UILayout*>(GUIReader::shareReader()->widgetFromJsonFile("ui/UIStrengthen.ExportJson"));
	uiLayer->addWidget(strengthenRoot);

	UIButton* closeButton = dynamic_cast<UIButton*>(uiLayer->getWidgetByName("CloseButton"));
	closeButton->addTouchEventListener(this, toucheventselector(UIStrengthen::closeButtonClicked));

	UIButton* strengthenButton = dynamic_cast<UIButton*>(uiLayer->getWidgetByName("StrengthenButton"));
	strengthenButton->addTouchEventListener(this, toucheventselector(UIStrengthen::strengthenButtonClicked));

	UIButton* pageLeftButton = dynamic_cast<UIButton*>(uiLayer->getWidgetByName("PageLeftButton"));
	pageLeftButton->addTouchEventListener(this, toucheventselector(UIStrengthen::pageLeftButtonClicked));

	UIButton* pageRightButton = dynamic_cast<UIButton*>(uiLayer->getWidgetByName("PageRightButton"));
	pageRightButton->addTouchEventListener(this, toucheventselector(UIStrengthen::pageRightButtonClicked));

	for (int i = 0; i < 4; i++)
	{
		const char* s = CCString::createWithFormat("EquipmentButton_%d", i+1)->getCString();
		UIButton* equipmentButton = dynamic_cast<UIButton*>(uiLayer->getWidgetByName(s));
		equipmentButton->addTouchEventListener(this, toucheventselector(UIStrengthen::equipmentButtonClicked));
	}

	for (int i = 0; i < 2; i++)
	{
		const char* s = CCString::createWithFormat("GemButton_%d", i+1)->getCString();
		UIButton* gemButton = dynamic_cast<UIButton*>(uiLayer->getWidgetByName(s));
		gemButton->addTouchEventListener(this, toucheventselector(UIStrengthen::gemButtonClicked));
	}

	for (int i = 0; i < 4; i++)
	{
		const char* s = CCString::createWithFormat("EquipmentImageView_%d", i+1)->getCString();
		equipmentImageView[i] = dynamic_cast<UIImageView*>(uiLayer->getWidgetByName(s));
	}

	for (int i = 0; i < 3; i++)
	{
		const char* s = CCString::createWithFormat("GemImageView_%d", i+1)->getCString();
		gemImageView[i] = dynamic_cast<UIImageView*>(uiLayer->getWidgetByName(s));
	}

	for (int i = 0; i < 2; i++)
	{
		const char* s = CCString::createWithFormat("GemFrontImageView_%d", i+1)->getCString();
		gemFrontImageView[i] = dynamic_cast<UIImageView*>(uiLayer->getWidgetByName(s));
	}

	strengthenfeatureImageView = dynamic_cast<UIImageView*>(uiLayer->getWidgetByName("FeatureImageView"));

	strengthenTestButton = dynamic_cast<UIButton*>(uiLayer->getWidgetByName("StrengthenTestButton"));

	selectFrameImageView = dynamic_cast<UIImageView*>(uiLayer->getWidgetByName("SelectFrameImageView"));

	UIPanel* tableViewPanel = dynamic_cast<UIPanel*>(uiLayer->getWidgetByName("TableViewPanel"));

	CCTableView* strengthenTableView = CCTableView::create(this, CCSizeMake(strengthenTestButton->getContentSize().width, tableViewPanel->getContentSize().height));
	strengthenTableView->setDirection(kCCScrollViewDirectionVertical);
	strengthenTableView->setVerticalFillOrder(kCCTableViewFillTopDown);

	CCPoint strengthenTestPosition = strengthenTestButton->getPosition();
	strengthenTableView->setPosition(ccp(strengthenTestPosition.x, strengthenTestPosition.y - tableViewPanel->getContentSize().height));
	strengthenTableView->setDelegate(this);
	strengthenTableView->reloadData();

	addChild(uiLayer);
	addChild(strengthenTableView);

	setVisible(false);
	refresh();
	return true;
}
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;
}
bool UIPageViewTest::init()
{
    if (UIScene::init())
    {
        CCSize screenSize = CCDirector::sharedDirector()->getWinSize();
        
        // Add a label in which the dragpanel events 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(screenSize.width / 2.0f, screenSize.height / 2.0f + m_pDisplayValueLabel->getContentSize().height * 1.5));
        m_pUiLayer->addWidget(m_pDisplayValueLabel);
        
        // Add the black background
        UILabel *alert = UILabel::create();
        alert->setText("PageView");
        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 page view
        UIPageView* pageView = UIPageView::create();
        pageView->setTouchEnable(true);
        pageView->setSize(CCSizeMake(240, 130));
        CCSize backgroundSize = background->getContentSize();
        pageView->setPosition(ccp((screenSize.width - backgroundSize.width) / 2 +
                                  (backgroundSize.width - pageView->getRect().size.width) / 2,
                                  (screenSize.height - backgroundSize.height) / 2 +
                                  (backgroundSize.height - pageView->getRect().size.height) / 2));
        
        for (int i = 0; i < 3; ++i)
        {
            UIPanel* panel = UIPanel::create();
            panel->setSize(CCSizeMake(240, 130));
            
            UIImageView* imageView = UIImageView::create();
            imageView->setTouchEnable(true);
            imageView->setScale9Enable(true);
            imageView->setTexture("cocosgui/scrollviewbg.png");
            imageView->setScale9Size(CCSizeMake(240, 130));
            imageView->setPosition(ccp(panel->getRect().size.width / 2, panel->getRect().size.height / 2));
            panel->addChild(imageView);
            
            UILabel* label = UILabel::create();
            label->setText(CCString::createWithFormat("page %d", (i + 1))->getCString());
            label->setFontName("Marker Felt");
            label->setFontSize(30);
            label->setColor(ccc3(192, 192, 192));
            label->setPosition(ccp(panel->getRect().size.width / 2, panel->getRect().size.height / 2));
            panel->addChild(label);
            
            pageView->addPage(panel);
        }
        
        m_pUiLayer->addWidget(pageView);
        
        return true;
    }
    return false;
}