Beispiel #1
0
bool NFCUISelectServer::initLayout()
{	
	if(!NFCUIDialog::initLayout())
		return false;

	m_pServerList = ui::ListView::create();
	m_pServerList->setSizeType(ui::SizeType::PERCENT);
	m_pServerList->setSizePercent(Vec2(0.1f, 0.25f));
	m_pServerList->setPositionType(ui::PositionType::PERCENT);
	m_pServerList->setPositionPercent(Vec2(0.5f, 0.5f));
	m_pServerList->setBackGroundColorType(ui::LayoutBackGroundColorType::SOLID);
	m_pServerList->setBackGroundColor(Color3B(150, 200, 255));
	m_pServerList->setAnchorPoint(Vec2(0.5, 0.5));
	m_pContent->addChild(m_pServerList);

	auto button = ui::Button::create();
	button->loadTextureNormal("Default/Button_Normal.png",ui::TextureResType::LOCAL);
	button->setScale9Enabled(true);
	button->setSizePercent(Vec2(1.0f, 0.2f));
	button->setSizeType(ui::SizeType::PERCENT);

	m_pServerList->setItemModel(button);
	
	g_pLoginLogic->AddEventCallBack(E_LoginEvent_WorldList, this, &NFCUISelectServer::OnWorldListEvent);
	g_pLoginLogic->AddEventCallBack(E_LoginEvent_ServerList, this, &NFCUISelectServer::OnServerListEvent);
	return true;
}
// on "init" you need to initialize your instance
bool SampleScene::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
    auto winSize = Director::getInstance()->getWinSize();
    
    auto intText = ui::Text::create("0", "fonts/arial.ttf", 30);
    intText->setPosition(Vec2(winSize.width/2, winSize.height - 100));
    this->addChild(intText);
    
    auto longText = ui::Text::create("0", "fonts/arial.ttf", 30);
    longText->setPosition(Vec2(winSize.width/2, winSize.height - 150));
    this->addChild(longText);
    
    auto floatText = ui::Text::create("0.00", "fonts/arial.ttf", 30);
    floatText->setPosition(Vec2(winSize.width/2, winSize.height - 200));
    this->addChild(floatText);
    
    auto doubleText = ui::Text::create("0.00", "fonts/arial.ttf", 30);
    doubleText->setPosition(Vec2(winSize.width/2, winSize.height - 250));
    this->addChild(doubleText);
    
    
    auto countUpButton = ui::Button::create();
    countUpButton->setSizePercent(Vec2(200,200));
    countUpButton->setTitleText("count up");
    countUpButton->setPosition(Vec2(winSize.width/4,100));
    
    countUpButton->addTouchEventListener([=](Ref* target, ui::Widget::TouchEventType type){
        
        if(type == ui::Widget::TouchEventType::ENDED)
        {
            
            {
                auto value = atoi(intText->getString().c_str());
                intText->runAction(LabelChangeTo<int>::create(0.4f, value + 20));
            }
            
            {
                auto value = atol(longText->getString().c_str());
                longText->runAction(LabelChangeTo<long>::create(0.4f, value + 20));
            }
            
            {
                auto value = (float)atof(floatText->getString().c_str());
                floatText->runAction(LabelChangeTo<float>::create(0.4f, value + 20.45f));
            }
            
            {
                auto value = atof(doubleText->getString().c_str());
                doubleText->runAction(LabelChangeTo<double>::create(0.4f, value + 20.45));
            }
        }
        
    });
    
    this->addChild(countUpButton);
    
    auto countDownButton = ui::Button::create();
    countDownButton->setSizePercent(Vec2(200,200));
    countDownButton->setTitleText("count down");
    countDownButton->setPosition(Vec2(winSize.width/4 * 3,100));
    
    countDownButton->addTouchEventListener([=](Ref* target, ui::Widget::TouchEventType type){
        
        if(type == ui::Widget::TouchEventType::ENDED)
        {
            
            {
                auto value = atoi(intText->getString().c_str());
                intText->runAction(LabelChangeTo<int>::create(0.4f, value - 20));
            }
            
            {
                auto value = atol(longText->getString().c_str());
                longText->runAction(LabelChangeTo<long>::create(0.4f, value - 20));
            }
            
            {
                auto value = (float)atof(floatText->getString().c_str());
                floatText->runAction(LabelChangeTo<float>::create(0.4f, value - 20.45f));
            }
            
            {
                auto value = atof(doubleText->getString().c_str());
                doubleText->runAction(LabelChangeTo<double>::create(0.4f, value - 20.45));
            }
        }
        
    });
    
    this->addChild(countDownButton);
    
    return true;
}