示例#1
0
bool UILoadingBarTest_Right::init()
{
    if (UIScene::init())
    {
        scheduleUpdate();
        
        Size widgetSize = _widget->getContentSize();
        
        // Add the alert
        Text *alert = Text::create("LoadingBar right", "fonts/Marker Felt.ttf", 30);
        alert->setColor(Color3B(159, 168, 176));
        alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 1.75f));
        _uiLayer->addChild(alert);
        
        // Create the loading bar
        LoadingBar* loadingBar = LoadingBar::create("cocosui/sliderProgress.png");
        loadingBar->setTag(0);
        loadingBar->setDirection(LoadingBar::Direction::RIGHT);
        
        loadingBar->setPosition(Vec2(widgetSize.width / 2.0f,
                                      widgetSize.height / 2.0f + loadingBar->getContentSize().height / 4.0f));
        
        _uiLayer->addChild(loadingBar);
        
        return true;
    }
    return false;
}
示例#2
0
bool UILoadingBarTest_Right_Scale9::init()
{
    if (UIScene::init())
    {
        scheduleUpdate();
        
        Size widgetSize = _widget->getSize();
        
        // Add the alert
        Text *alert = Text::create();
        alert->setText("LoadingBar right scale9 render");
        alert->setFontName("Marker Felt");
        alert->setFontSize(20);
        alert->setColor(Color3B(159, 168, 176));
        alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 2.7f));
        _uiLayer->addChild(alert);
        
        // Create the loading bar
        LoadingBar* loadingBar = LoadingBar::create();
        loadingBar->setTag(0);
        loadingBar->loadTexture("cocosui/slider_bar_active_9patch.png");
        loadingBar->setScale9Enabled(true);
        loadingBar->setCapInsets(Rect(0, 0, 0, 0));
        loadingBar->setSize(Size(300, loadingBar->getContentSize().height));
        loadingBar->setDirection(LoadingBarTypeRight);        
        loadingBar->setPercent(0);
        
        loadingBar->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + loadingBar->getSize().height / 4.0f));
        _uiLayer->addChild(loadingBar);
        
        return true;
    }
    return false;
}
示例#3
0
bool UILoadingBarTest_Left::init()
{
    if (UIScene::init())
    {
        scheduleUpdate();
        
        Size widgetSize = _widget->getSize();
        
        // Add the alert
        Text* alert = Text::create();
        alert->setText("LoadingBar left");
        alert->setFontName("Marker Felt");
        alert->setFontSize(30);
        alert->setColor(Color3B(159, 168, 176));
        alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75f));
        _uiLayer->addChild(alert);
        
        // Create the loading bar
        LoadingBar* loadingBar = LoadingBar::create();
        loadingBar->setTag(0);
        loadingBar->loadTexture("cocosui/sliderProgress.png");
        loadingBar->setPercent(0);
        
        loadingBar->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + loadingBar->getSize().height / 4.0f));
        _uiLayer->addChild(loadingBar);
        
        return true;
    }
    return false;
}
示例#4
0
bool UILoadingBarTest_Direction::init()
{
    if (UIScene::init())
    {
        //scheduleUpdate();

        Size widgetSize = _widget->getContentSize();

        // Add the alert
        Text* alert = Text::create("Test LoadingBar Change Direction",
            "fonts/Marker Felt.ttf", 30);
        alert->setColor(Color3B(159, 168, 176));
        alert->setPosition(Vec2(widgetSize.width / 2.0f,
            widgetSize.height / 2.0f - alert->getContentSize().height * 1.75f));
        _uiLayer->addChild(alert);

        // Create the loading bar
        LoadingBar* loadingBar = LoadingBar::create("cocosui/sliderProgress.png");
        loadingBar->setTag(0);
        loadingBar->setPercent(80);
        loadingBar->setPosition(Vec2(widgetSize.width / 2.0f,
            widgetSize.height / 2.0f + loadingBar->getContentSize().height / 4.0f));

        auto loadingBarCopy = (LoadingBar*)loadingBar->clone();
        loadingBarCopy->setTag(1);
        loadingBarCopy->setPosition(loadingBar->getPosition()
            + Vec2(0, -40));
        loadingBarCopy->setDirection(LoadingBar::Direction::RIGHT);

        Button* button = Button::create("cocosui/animationbuttonnormal.png",
            "cocosui/animationbuttonpressed.png");
        button->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 50));
        button->setTitleText("Click to change direction!");

        button->addTouchEventListener([=](Ref*, Widget::TouchEventType type)
        {
            if (type == Widget::TouchEventType::ENDED)
            {
                if (loadingBar->getDirection() == LoadingBar::Direction::LEFT)
                {
                    loadingBar->setDirection(LoadingBar::Direction::RIGHT);
                    loadingBarCopy->setDirection(LoadingBar::Direction::LEFT);
                }
                else
                {
                    loadingBar->setDirection(LoadingBar::Direction::LEFT);
                    loadingBarCopy->setDirection(LoadingBar::Direction::RIGHT);
                }
            }
        });
        _uiLayer->addChild(loadingBar, 1);
        _uiLayer->addChild(loadingBarCopy, 2);
        _uiLayer->addChild(button);

        _loadingBar = loadingBar;
        return true;
    }
    return false;
}
示例#5
0
void UILoadingBarTest_Left::update(float delta)
{
    _count++;
    if (_count > 100)
    {
        _count = 0;
    }
    LoadingBar* loadingBar = static_cast<LoadingBar*>(_uiLayer->getChildByTag(0));
    loadingBar->setPercent(_count);
}
示例#6
0
文件: UI.cpp 项目: baokuanze/UIdemo
void UI::LoadingBarUpdate(float dt){
    LoadingBar *lb =dynamic_cast<LoadingBar*>(getChildByTag(1));
    CCASSERT(lb, "the childer with tag 1 is not a loadingBar Class");
    float per=lb->getPercent()+0.5f;
    lb->setPercent(per);
    if (per>=100) {
        per=100;
        unschedule("LoadingBarUpdate");
    }
}
LoadingBar* LoadingBar::create()
{
    LoadingBar* widget = new LoadingBar();
    if (widget && widget->init())
    {
        widget->autorelease();
        return widget;
    }
    CC_SAFE_DELETE(widget);
    return nullptr;
}
示例#8
0
void UILoadingBarIssue12249::update(float delta)
{
    _count++;
    if (_count > 100)
    {
        _count = 0;
    }
    LoadingBar* loadingBar = static_cast<LoadingBar*>(_uiLayer->getChildByTag(0));
    LoadingBar* loadingBarCopy = static_cast<LoadingBar*>(_uiLayer->getChildByTag(1));
    loadingBar->setPercent(_count);
    loadingBarCopy->setPercent(_count);
}
示例#9
0
void Upgrade::onProgress(int percent)
{
	if (percent < 0)
		return;
	
	LoadingBar* loadingBar = static_cast<LoadingBar*>(this->getChildByTag(1001));
	loadingBar->setPercent(percent);

	char progress[20];
	snprintf(progress, 20, "download %d%%", percent);
	_showDownloadInfo->setString(progress);
}
示例#10
0
LoadingBar* LoadingBar::create(cocos2d::SpriteFrame* frame)
{
	LoadingBar* widget = new (std::nothrow) LoadingBar;
	if (widget && widget->init())
	{
		widget->autorelease();
		widget->loadTexture(frame);
		widget->setPercent(0);
		return widget;
	}
	CC_SAFE_DELETE(widget);
	return nullptr;
}
示例#11
0
 void LoadingBarReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *cocoLoader, stExpCocoNode *cocoNode)
 {
     WidgetReader::setPropsFromBinary(widget, cocoLoader, cocoNode);
     
     LoadingBar* loadingBar = static_cast<LoadingBar*>(widget);
     this->beginSetBasicProperties(widget);
     float capsx = 0.0f, capsy = 0.0, capsWidth = 0.0, capsHeight = 0.0f;
     int percent = loadingBar->getPercent();
     
     stExpCocoNode *stChildArray = cocoNode->GetChildArray(cocoLoader);
     
     for (int i = 0; i < cocoNode->GetChildNum(); ++i) {
         std::string key = stChildArray[i].GetName(cocoLoader);
         std::string value = stChildArray[i].GetValue(cocoLoader);
         
         //read all basic properties of widget
         CC_BASIC_PROPERTY_BINARY_READER
         //read all color related properties of widget
         CC_COLOR_PROPERTY_BINARY_READER
         
         else if (key == P_Scale9Enable) {
             loadingBar->setScale9Enabled(valueToBool(value));
         }
         else if (key == P_TextureData){
             
             stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray(cocoLoader);
             std::string resType = backGroundChildren[2].GetValue(cocoLoader);;
             
             Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
             
             std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType);
             
             loadingBar->loadTexture(backgroundValue, imageFileNameType);
             
         }
         else if(key == P_CapInsetsX){
             capsx = valueToFloat(value);
         }else if(key == P_CapInsetsY){
             capsy = valueToFloat(value);
         }else if(key == P_CapInsetsWidth){
             capsWidth = valueToFloat(value);
         }else if(key == P_CapInsetsHeight){
             capsHeight = valueToFloat(value);
         }else if(key == P_Direction){
             loadingBar->setDirection((LoadingBar::Direction)valueToInt(value));
         }else if(key == P_Percent){
             percent = valueToInt(value);
         }
         
     } //end of for loop
     
     if (loadingBar->isScale9Enabled()) {
         loadingBar->setCapInsets(Rect(capsx, capsy, capsWidth, capsHeight));
     }
     loadingBar->setPercent(percent);
     this->endSetBasicProperties(widget);
 }
示例#12
0
bool UILoadingBarTest_Left_Scale9::init()
{
    if (UIScene::init())
    {
        scheduleUpdate();
        
        Size widgetSize = _widget->getContentSize();
        
        // Add the alert
        Text* alert = Text::create("LoadingBar left scale9 render", "fonts/Marker Felt.ttf", 20);
        alert->setColor(Color3B(159, 168, 176));
        alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 2.7f));
        _uiLayer->addChild(alert);
        
        // Create the loading bar
        LoadingBar* loadingBar = LoadingBar::create("cocosui/slider_bar_active_9patch.png");
        loadingBar->setTag(0);
        loadingBar->setScale9Enabled(true);
        loadingBar->setCapInsets(Rect(0, 0, 0, 0));
        loadingBar->setContentSize(Size(300, 13));
        
        loadingBar->setPosition(Vec2(widgetSize.width / 2.0f,
                                      widgetSize.height / 2.0f + loadingBar->getContentSize().height / 4.0f));
        
        _uiLayer->addChild(loadingBar);
        
        return true;
    }
    return false;
}
示例#13
0
 void LoadingBarReader::setPropsWithFlatBuffers(cocos2d::Node *node, const flatbuffers::Table *loadingBarOptions)
 {
     LoadingBar* loadingBar = static_cast<LoadingBar*>(node);
     auto options = (LoadingBarOptions*)loadingBarOptions;
     
     auto imageFileNameDic = options->textureData();
     int imageFileNameType = imageFileNameDic->resourceType();
     std::string imageFileName = imageFileNameDic->path()->c_str();
     loadingBar->loadTexture(imageFileName, (Widget::TextureResType)imageFileNameType);
     
     int direction = options->direction();
     loadingBar->setDirection(LoadingBar::Direction(direction));
     
     int percent = options->percent();
     loadingBar->setPercent(percent);
     
     auto widgetReader = WidgetReader::getInstance();
     widgetReader->setPropsWithFlatBuffers(node, (Table*)options->widgetOptions());
 }
    void LoadingBarReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
    {
        WidgetReader::setPropsFromJsonDictionary(widget, options);
        
        
        LoadingBar* loadingBar = static_cast<LoadingBar*>(widget);
        
        const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, P_TextureData);
        int imageFileNameType = DICTOOL->getIntValue_json(imageFileNameDic, P_ResourceType);
        std::string imageFileName = this->getResourcePath(imageFileNameDic, P_Path, (Widget::TextureResType)imageFileNameType);
        loadingBar->loadTexture(imageFileName, (Widget::TextureResType)imageFileNameType);

        
        /* gui mark add load bar scale9 parse */
        bool scale9Enable = DICTOOL->getBooleanValue_json(options, P_Scale9Enable);
        loadingBar->setScale9Enabled(scale9Enable);
        
        
        float cx = DICTOOL->getFloatValue_json(options, P_CapInsetsX);
        float cy = DICTOOL->getFloatValue_json(options, P_CapInsetsY);
        float cw = DICTOOL->getFloatValue_json(options, P_CapInsetsWidth,1);
        float ch = DICTOOL->getFloatValue_json(options, P_CapInsetsHeight,1);
        
        if (scale9Enable) {
            loadingBar->setCapInsets(Rect(cx, cy, cw, ch));

        }
        
        float width = DICTOOL->getFloatValue_json(options, P_Width);
        float height = DICTOOL->getFloatValue_json(options, P_Height);
        loadingBar->setContentSize(Size(width, height));
        
        /**/
        
        loadingBar->setDirection(LoadingBar::Direction(DICTOOL->getIntValue_json(options, P_Direction)));
        loadingBar->setPercent(DICTOOL->getIntValue_json(options, P_Percent,100));
        
        
        WidgetReader::setColorPropsFromJsonDictionary(widget, options);
    }        
示例#15
0
void monster::setupMonster()
{
    auto s = Director::getInstance()->getWinSize();
    //remove sigle resource
    ArmatureDataManager::getInstance()->removeArmatureFileInfo("Export/dongzuo.ExportJson");
    //load resource directly
    ArmatureDataManager::getInstance()->addArmatureFileInfo("Export/dongzuo.ExportJson");
    _pMonsterArmature = Armature::create("dongzuo");
    _pMonsterArmature->getAnimation()->playWithIndex(0);
    addChild(_pMonsterArmature,0,0);
    _pMonsterArmature->setPosition(Point(_pMonsterArmature->getContentSize().width,
                                s.height - _pMonsterArmature->getContentSize().height-50));
    
    _pMonsterArmature->setPosition(Point(s.width*0.8,
                              s.height - _pMonsterArmature->getContentSize().height-50));
    _monster_pos = _pMonsterArmature->getPosition();
    

    auto body = PhysicsBody::createCircle(_pMonsterArmature->getContentSize().width/3);
    body->setCategoryBitmask(0x01);
    body->setCollisionBitmask(0x01);
    body->setDynamic(false);
    _pMonsterArmature->setPhysicsBody(body);

    //setup monster hp
    auto bkbar = Sprite::create("slidbar.png");
    bkbar->setColor(Color3B::GRAY);
    addChild(bkbar,0,kMonsterHp);
    bkbar->setPosition(Point(Point(_monster_pos.x, _monster_pos.y - _pMonsterArmature->getContentSize().height/2-5)));
    
    LoadingBar* monsterHpBar = LoadingBar::create();
    monsterHpBar->setTag(0);
    monsterHpBar->loadTexture("slidbar.png");
    monsterHpBar->setDirection(LoadingBarTypeLeft);
    monsterHpBar->setPercent(50);
    monsterHpBar->setPosition(Point(bkbar->getContentSize().width/2, bkbar->getContentSize().height/2));
    bkbar->addChild(monsterHpBar,0,0);
}
示例#16
0
bool Upgrade::init()
{
//	CCLog("%s:%d", __FILE__, __LINE__);

		if (!Layer::init())
		{
			return false;
		}


	Size winSize = Director::getInstance()->getWinSize();

	//获取本地版本
	CCLOG("xml----location----%s", UserDefault::getInstance()->getXMLFilePath().c_str());
	std::string s =	UserDefault::getInstance()->getXMLFilePath().c_str();
//	CCLog("%s:%d", s.c_str(), __LINE__);
	


	//创建下载目录文件夹
	initDownloadDir();

	//加载tips 提示信息
	loadTipsInfo();


	LoadingBar *pLoadingBar = LoadingBar::create("load.png");
	pLoadingBar->setTag(1001);
	pLoadingBar->setPosition(Vec2(winSize.width / 2, 100));

	this->addChild(pLoadingBar);


	_showDownloadInfo = Label::create();
	_showDownloadInfo->setString("");
	_showDownloadInfo->setSystemFontSize(20);

	this->addChild(_showDownloadInfo);
	_showDownloadInfo->setPosition(Vec2(winSize.width / 2, winSize.height / 2 - 20));

	//提示label
	tipsLabel = Label::create();
	tipsLabel->setString(TipsVer[0]);
	tipsLabel->setSystemFontSize(20);
	tipsLabel->setTag(1002);
	tipsLabel->setPosition(Vec2(winSize.width / 2, winSize.height / 2+20));
	this->addChild(tipsLabel);



	//淡出淡出
	auto *fadeout = FadeOut::create(1.5f);
	auto *fadein = FadeIn::create(1.5f);
	auto *repeatForever = RepeatForever::create(Sequence::create(fadeout,
																CallFunc::create(CC_CALLBACK_0(Upgrade::actionCallBacn, this)),
																fadein,
																DelayTime::create(2.0f),
																nullptr));
	tipsLabel->runAction(repeatForever);


	upgrade();

	return true;
}
void HelloWorld::update(float delta)
{
	if(m_bStart)
	{
        ComRender *pHeroRender = (ComRender*)(m_pGameScene->getChildByTag(10005)->getComponent("CCArmature"));
		Armature *pHero = (Armature*)(pHeroRender->getNode());
		pHero->getParent()->setPositionX(pHero->getParent()->getPositionX() + m_fSpeed);
        
        ComRender *pEnemyRender = (ComRender*)(m_pGameScene->getChildByTag(10006)->getComponent("CCArmature"));
		Armature *pEnemy = (Armature*)(pEnemyRender->getNode());

        /* for 3.0 */
        float distance = Point(pHero->getParent()->getPositionX(), 0).getDistance(Point(pEnemy->getParent()->getPositionX(), 0));
        if (distance < m_fAttackDis)
        {
            pHero->getAnimation()->play("attack");
			pHero->getAnimation()->setMovementEventCallFunc(this,
                                                            movementEvent_selector(HelloWorld::animationEvent));
			m_bStart = false;
        }
        // before
        /*
		if(ccpDistance(ccp(pHero->getParent()->getPositionX(), 0), ccp(pEnemy->getParent()->getPositionX(), 0)) < m_fAttackDis)
		{	
			pHero->getAnimation()->play("attack");
			pHero->getAnimation()->setMovementEventCallFunc(this,
                                                        movementEvent_selector(HelloWorld::animationEvent));
			m_bStart = false;
		}
         */
        /**/
	}

	if(m_bDead)
	{
		ComRender *pUIRender = static_cast<ComRender*>(m_pGameScene->getChildByTag(10007)->getComponent("GUIComponent"));
        
        
        /* for 3.0 */
        Node* pUILayer = static_cast<Node*>(pUIRender->getNode());
        Layout* root = static_cast<Layout*>(pUILayer->getChildren().at(2));
        LoadingBar *pHPLoadingBar = static_cast<LoadingBar*>(Helper::seekWidgetByName(root, "hp02_LoadingBar"));
        LoadingBar *pMPLoadingBar = static_cast<LoadingBar*>(Helper::seekWidgetByName(root, "mp02_LoadingBar"));
        // before
        /*
		cocos2d::ui::TouchGroup *pUILayer = static_cast<cocos2d::ui::TouchGroup*>(pUIRender->getNode());
		cocos2d::ui::LoadingBar *pHPLoadingBar = static_cast<cocos2d::ui::LoadingBar*>(pUILayer->getWidgetByName("hp02_LoadingBar"));
		cocos2d::ui::LoadingBar *pMPLoadingBar = static_cast<cocos2d::ui::LoadingBar*>(pUILayer->getWidgetByName("mp02_LoadingBar"));
         */
        /**/

		pHPLoadingBar->setPercent(m_fPercentage);
		pMPLoadingBar->setPercent(m_fPercentage);

		m_fPercentage -= 2.0f;
        if (m_fPercentage < 0.0f) {
            unscheduleUpdate();
        }
	}
	
}
示例#18
0
bool UILoadingBarTest_Scale9_State_Change::init()
{
    if (UIScene::init())
    {
        Size widgetSize = _widget->getContentSize();

        // Add the alert
        Text *alert = Text::create("LoadingBar right scale9 render", "fonts/Marker Felt.ttf", 20);
        alert->setColor(Color3B(159, 168, 176));
        alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 2.7f));
        _uiLayer->addChild(alert);

        // Create the loading bar
        LoadingBar* loadingBar = LoadingBar::create("cocosui/sliderThumb.png");
        loadingBar->setTag(0);
        loadingBar->ignoreContentAdaptWithSize(false);
        //loadingBar->setScale9Enabled(true);
        loadingBar->setCapInsets(Rect(0, 0, 0, 0));
        loadingBar->setContentSize(Size(200, 80));
        loadingBar->setDirection(LoadingBar::Direction::LEFT);
        loadingBar->setPercent(100);

        loadingBar->setTouchEnabled(true);
        loadingBar->addTouchEventListener([=](Ref* sender, Widget::TouchEventType type){
            if (type == Widget::TouchEventType::ENDED) {
                if (loadingBar->isScale9Enabled())
                {
                    loadingBar->setScale9Enabled(false);
                }
                else
                    loadingBar->setScale9Enabled(true);
            }
        });

        loadingBar->setPosition(Vec2(widgetSize.width / 2.0f,
            widgetSize.height / 2.0f + loadingBar->getContentSize().height / 4.0f));

        _uiLayer->addChild(loadingBar);

        return true;
    }
    return false;
}
示例#19
0
bool UILoadingBarTest_Left::init()
{
    if (UIScene::init())
    {
        scheduleUpdate();
        
        Size widgetSize = _widget->getContentSize();
        
        // Add the alert
        Text* alert = Text::create("Test LoadingBar Change Direction",
                                   "fonts/Marker Felt.ttf", 30);
        alert->setColor(Color3B(159, 168, 176));
        alert->setPosition(Vec2(widgetSize.width / 2.0f,
                                widgetSize.height / 2.0f - alert->getContentSize().height * 1.75f));
        _uiLayer->addChild(alert);
        
        // Create the loading bar
        LoadingBar* loadingBar = LoadingBar::create("cocosui/sliderProgress.png");
        loadingBar->setTag(0);
        loadingBar->setPosition(Vec2(widgetSize.width / 2.0f,
                                      widgetSize.height / 2.0f + loadingBar->getContentSize().height / 4.0f));

        auto loadingBarCopy = (LoadingBar*)loadingBar->clone();
        loadingBarCopy->setTag(1);
        loadingBarCopy->setPosition(loadingBar->getPosition()
                                    + Vec2(0, -40));
        loadingBarCopy->setDirection(LoadingBar::Direction::RIGHT);

        Button* button = Button::create("cocosui/animationbuttonnormal.png",
                                        "cocosui/animationbuttonpressed.png");
        button->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 50));
        button->setTitleText("Click to change direction!");

        button->addTouchEventListener([=](Ref*, Widget::TouchEventType type)
        {
            if (type == Widget::TouchEventType::ENDED)
            {
                if (loadingBar->getDirection() == LoadingBar::Direction::LEFT)
                {
                    loadingBar->setDirection(LoadingBar::Direction::RIGHT);
                    loadingBarCopy->setDirection(LoadingBar::Direction::LEFT);
                }
                else
                {
                    loadingBar->setDirection(LoadingBar::Direction::LEFT);
                    loadingBarCopy->setDirection(LoadingBar::Direction::RIGHT);
                }
            }
        });
         _uiLayer->addChild(loadingBar,1);
        _uiLayer->addChild(loadingBarCopy,2);
        _uiLayer->addChild(button);

        _loadingBar = loadingBar;

        TTFConfig ttfConfig("fonts/arial.ttf", 15);
        auto label1 = Label::createWithTTF(ttfConfig, "Print Resources");
        auto item1 = MenuItemLabel::create(label1, CC_CALLBACK_1(UILoadingBarTest_Left::printWidgetResources, this));
        item1->setPosition(Vec2(VisibleRect::left().x + 60, VisibleRect::bottom().y + item1->getContentSize().height * 3));
        auto pMenu1 = Menu::create(item1, nullptr);
        pMenu1->setPosition(Vec2(0, 0));
        this->addChild(pMenu1, 10);
        
        return true;
    }
    return false;
}
 void LoadingBarReader::setPropsWithFlatBuffers(cocos2d::Node *node, const flatbuffers::Table *loadingBarOptions)
 {
     LoadingBar* loadingBar = static_cast<LoadingBar*>(node);
     auto options = (LoadingBarOptions*)loadingBarOptions;
     
     bool fileExist = false;
     std::string errorFilePath = "";
     auto imageFileNameDic = options->textureData();
     int imageFileNameType = imageFileNameDic->resourceType();
     std::string imageFileName = imageFileNameDic->path()->c_str();
     switch (imageFileNameType)
     {
         case 0:
         {
             if (FileUtils::getInstance()->isFileExist(imageFileName))
             {
                 fileExist = true;
             }
             else
             {
                 errorFilePath = imageFileName;
                 fileExist = false;
             }
             break;
         }
             
         case 1:
         {
             std::string plist = imageFileNameDic->plistFile()->c_str();
             SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(imageFileName);
             if (spriteFrame)
             {
                 fileExist = true;
             }
             else
             {
                 if (FileUtils::getInstance()->isFileExist(plist))
                 {
                     ValueMap value = FileUtils::getInstance()->getValueMapFromFile(plist);
                     ValueMap metadata = value["metadata"].asValueMap();
                     std::string textureFileName = metadata["textureFileName"].asString();
                     if (!FileUtils::getInstance()->isFileExist(textureFileName))
                     {
                         errorFilePath = textureFileName;
                     }
                 }
                 else
                 {
                     errorFilePath = plist;
                 }
                 fileExist = false;
             }
             break;
         }
             
         default:
             break;
     }
     if (fileExist)
     {
         loadingBar->loadTexture(imageFileName, (Widget::TextureResType)imageFileNameType);
     }
     else
     {
         auto label = Label::create();
         label->setString(__String::createWithFormat("%s missed", errorFilePath.c_str())->getCString());
         loadingBar->addChild(label);
     }
     
     int direction = options->direction();
     loadingBar->setDirection(LoadingBar::Direction(direction));
     
     int percent = options->percent();
     loadingBar->setPercent(percent);
     
     auto widgetReader = WidgetReader::getInstance();
     widgetReader->setPropsWithFlatBuffers(node, (Table*)options->widgetOptions());
 }
示例#21
0
bool UILoadingBarReloadTexture::init()
{
    if (UIScene::init())
    {
        Size widgetSize = _widget->getContentSize();
        
        // Add the alert
        Text *alert = Text::create("Click button to Toggle Scale9 and switch Texture.", "fonts/Marker Felt.ttf", 20);
        alert->setColor(Color3B(159, 168, 176));
        alert->setPosition(Vec2(widgetSize.width / 2.0f,
                                widgetSize.height / 2.0f - alert->getContentSize().height * 2.7f));
        _uiLayer->addChild(alert);
        
        LoadingBar* loadingBar = LoadingBar::create("cocosui/slider_bar_active_9patch.png");
        loadingBar->setTag(0);
        loadingBar->ignoreContentAdaptWithSize(false);
//        loadingBar->setScale9Enabled(true);
        loadingBar->setCapInsets(Rect(0, 0, 0, 0));
        loadingBar->setContentSize(Size(300, 13));
        loadingBar->setName("texture0");
        loadingBar->setDirection(LoadingBar::Direction::RIGHT);
        loadingBar->setPercent(70);
        loadingBar->setPosition(Vec2(widgetSize.width / 2.0f,
                                     widgetSize.height / 2.0f + loadingBar->getContentSize().height / 4.0f));
        
        _uiLayer->addChild(loadingBar);
        
        auto buttonScale9 = Button::create("cocosui/animationbuttonnormal.png",
                                           "cocosui/animationbuttonpressed.png");
        buttonScale9->setTitleText("ToggleScale9");
        buttonScale9->addClickEventListener([=](Ref*){
            loadingBar->setScale9Enabled(!loadingBar->isScale9Enabled());
        });
        buttonScale9->setPosition(loadingBar->getPosition() + Vec2(-50,50));
        _uiLayer->addChild(buttonScale9);
        
        auto buttonChangeTexture = Button::create("cocosui/animationbuttonnormal.png",
                                                  "cocosui/animationbuttonpressed.png");
        buttonChangeTexture->setTitleText("ChangeTexture");
        buttonChangeTexture->addClickEventListener([=](Ref*){
            auto name = loadingBar->getName();
            if (name == "texture0")
            {
                loadingBar->loadTexture("cocosui/slider_bar_active_9patch2.png");
                loadingBar->setName("texture1");
            }
            else
            {
                loadingBar->loadTexture("cocosui/slider_bar_active_9patch.png");
                loadingBar->setName("texture0");
            }
        });
        buttonChangeTexture->setPosition(loadingBar->getPosition() + Vec2(50,50));
        _uiLayer->addChild(buttonChangeTexture);
        
        this->scheduleUpdate();
        return true;
    }
    return false;
}
示例#22
0
/***************************************************************************
 Load star catalogue data from files.
 If a file is not found, it will be skipped.
***************************************************************************/
void HipStarMgr::load_data(const InitParser &baseConf, LoadingBar& lb)
{
	// Please do not init twice:
	assert(max_geodesic_grid_level < 0);

	cout << "Loading star data..." << endl;

	InitParser conf;
	conf.load(AppSettings::Instance()->getDataRoot() + "/stars/default/stars.ini");
				         
	for (int i=0; i<100; i++)
	{
		char key_name[64];
		sprintf(key_name,"cat_file_name_%02d",i);
		const string cat_file_name = conf.get_str("stars",key_name,"").c_str();
		if (!cat_file_name.empty()) {
			lb.SetMessage(_("Loading catalog ") + cat_file_name);
			ZoneArray *const z = ZoneArray::create(*this,cat_file_name,lb);
			if (z)
			{
				if (max_geodesic_grid_level < z->level)
				{
					max_geodesic_grid_level = z->level;
				}
				ZoneArray *&pos(zone_arrays[z->level]);
				if (pos)
				{
					cerr << cat_file_name << ", " << z->level
						 << ": duplicate level" << endl;
					delete z;
				}
				else
				{
					pos = z;
				}
			}
		}
	}

	for (int i=0; i<=NR_OF_HIP; i++)
	{
		hip_index[i].a = 0;
		hip_index[i].z = 0;
		hip_index[i].s = 0;
	}
	for (ZoneArrayMap::const_iterator it(zone_arrays.begin());
	                it != zone_arrays.end();it++)
	{
		it->second->updateHipIndex(hip_index);
	}

	const string cat_hip_sp_file_name = conf.get_str("stars","cat_hip_sp_file_name","").c_str();
	if (cat_hip_sp_file_name.empty())
	{
		cerr << "ERROR: stars:cat_hip_sp_file_name not found" << endl;
	}
	else
	{
		try
		{
			spectral_array.initFromFile(AppSettings::Instance()->getDataRoot() +
										"/stars/default/" + cat_hip_sp_file_name);
		}
		catch (std::exception& e)
		{
			cerr << "ERROR while loading data from "
			     << ("stars/default/" + cat_hip_sp_file_name)
		    	 << ": " << e.what();
		}
	}

	const string cat_hip_cids_file_name = conf.get_str("stars","cat_hip_cids_file_name","").c_str();
	if (cat_hip_cids_file_name.empty())
	{
		cerr << "ERROR: stars:cat_hip_cids_file_name not found" << endl;
	}
	else
	{
		try
		{
			component_array.initFromFile(AppSettings::Instance()->getDataRoot() +
										 "/stars/default/" + cat_hip_cids_file_name);
		}
		catch (std::exception& e)
		{
			cerr << "ERROR while loading data from "
			     << ("stars/default/" + cat_hip_cids_file_name)
		    	 << ": " << e.what() << endl;
		}
	}

	last_max_search_level = max_geodesic_grid_level;
	cout << "finished, max_geodesic_level: " << max_geodesic_grid_level << endl;
}