2013-09-16 20:54:13 +08:00
|
|
|
#include "UILoadingBarTest.h"
|
|
|
|
|
2015-04-09 12:23:47 +08:00
|
|
|
USING_NS_CC;
|
|
|
|
using namespace cocos2d::ui;
|
|
|
|
|
2015-04-03 14:31:03 +08:00
|
|
|
UILoadingBarTests::UILoadingBarTests()
|
|
|
|
{
|
|
|
|
ADD_TEST_CASE(UILoadingBarTest_Left);
|
|
|
|
ADD_TEST_CASE(UILoadingBarTest_Right);
|
|
|
|
ADD_TEST_CASE(UILoadingBarTest_Left_Scale9);
|
|
|
|
ADD_TEST_CASE(UILoadingBarTest_Right_Scale9);
|
|
|
|
ADD_TEST_CASE(UILoadingBarTest_Scale9_State_Change);
|
|
|
|
ADD_TEST_CASE(UILoadingBarReloadTexture);
|
2015-12-09 17:15:09 +08:00
|
|
|
ADD_TEST_CASE(UILoadingBarIssue12249);
|
2015-12-19 15:59:27 +08:00
|
|
|
ADD_TEST_CASE(UILoadingBarTest_Direction);
|
2015-04-03 14:31:03 +08:00
|
|
|
}
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
// UILoadingBarTest_Left
|
|
|
|
|
|
|
|
UILoadingBarTest_Left::UILoadingBarTest_Left()
|
2013-12-23 15:35:35 +08:00
|
|
|
: _count(0)
|
2013-09-16 20:54:13 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
UILoadingBarTest_Left::~UILoadingBarTest_Left()
|
|
|
|
{
|
|
|
|
unscheduleUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UILoadingBarTest_Left::init()
|
|
|
|
{
|
|
|
|
if (UIScene::init())
|
|
|
|
{
|
|
|
|
scheduleUpdate();
|
|
|
|
|
2014-06-20 11:18:53 +08:00
|
|
|
Size widgetSize = _widget->getContentSize();
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
// Add the alert
|
2015-06-05 15:57:39 +08:00
|
|
|
Text* alert = Text::create("Test LoadingBar Change Direction",
|
|
|
|
"fonts/Marker Felt.ttf", 30);
|
2013-09-16 20:54:13 +08:00
|
|
|
alert->setColor(Color3B(159, 168, 176));
|
2015-06-05 15:57:39 +08:00
|
|
|
alert->setPosition(Vec2(widgetSize.width / 2.0f,
|
|
|
|
widgetSize.height / 2.0f - alert->getContentSize().height * 1.75f));
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(alert);
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
// Create the loading bar
|
2014-04-02 17:53:06 +08:00
|
|
|
LoadingBar* loadingBar = LoadingBar::create("cocosui/sliderProgress.png");
|
2013-12-23 15:35:35 +08:00
|
|
|
loadingBar->setTag(0);
|
2014-05-15 01:07:09 +08:00
|
|
|
loadingBar->setPosition(Vec2(widgetSize.width / 2.0f,
|
2014-06-20 11:18:53 +08:00
|
|
|
widgetSize.height / 2.0f + loadingBar->getContentSize().height / 4.0f));
|
2015-06-05 15:57:39 +08:00
|
|
|
|
|
|
|
auto loadingBarCopy = (LoadingBar*)loadingBar->clone();
|
|
|
|
loadingBarCopy->setTag(1);
|
|
|
|
loadingBarCopy->setPosition(loadingBar->getPosition()
|
|
|
|
+ Vec2(0, -40));
|
|
|
|
loadingBarCopy->setDirection(LoadingBar::Direction::RIGHT);
|
|
|
|
|
2014-08-08 11:17:17 +08:00
|
|
|
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!");
|
2015-06-05 15:57:39 +08:00
|
|
|
|
|
|
|
button->addTouchEventListener([=](Ref*, Widget::TouchEventType type)
|
|
|
|
{
|
|
|
|
if (type == Widget::TouchEventType::ENDED)
|
|
|
|
{
|
|
|
|
if (loadingBar->getDirection() == LoadingBar::Direction::LEFT)
|
|
|
|
{
|
2014-08-08 11:17:17 +08:00
|
|
|
loadingBar->setDirection(LoadingBar::Direction::RIGHT);
|
2015-06-05 15:57:39 +08:00
|
|
|
loadingBarCopy->setDirection(LoadingBar::Direction::LEFT);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-08 11:17:17 +08:00
|
|
|
loadingBar->setDirection(LoadingBar::Direction::LEFT);
|
2015-06-05 15:57:39 +08:00
|
|
|
loadingBarCopy->setDirection(LoadingBar::Direction::RIGHT);
|
2014-08-08 11:17:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2015-06-05 15:57:39 +08:00
|
|
|
_uiLayer->addChild(loadingBar,1);
|
|
|
|
_uiLayer->addChild(loadingBarCopy,2);
|
2014-08-08 11:17:17 +08:00
|
|
|
_uiLayer->addChild(button);
|
2015-11-30 16:17:13 +08:00
|
|
|
|
|
|
|
_loadingBar = loadingBar;
|
|
|
|
|
|
|
|
TTFConfig ttfConfig("fonts/arial.ttf", 15);
|
|
|
|
auto label1 = Label::createWithTTF(ttfConfig, "Print Resources");
|
2015-12-01 11:07:02 +08:00
|
|
|
auto item1 = MenuItemLabel::create(label1, CC_CALLBACK_1(UILoadingBarTest_Left::printWidgetResources, this));
|
2015-11-30 16:17:13 +08:00
|
|
|
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);
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UILoadingBarTest_Left::update(float delta)
|
|
|
|
{
|
2013-12-23 15:35:35 +08:00
|
|
|
_count++;
|
|
|
|
if (_count > 100)
|
2013-09-16 20:54:13 +08:00
|
|
|
{
|
2013-12-23 15:35:35 +08:00
|
|
|
_count = 0;
|
2013-09-16 20:54:13 +08:00
|
|
|
}
|
2013-12-23 15:35:35 +08:00
|
|
|
LoadingBar* loadingBar = static_cast<LoadingBar*>(_uiLayer->getChildByTag(0));
|
2015-06-05 15:57:39 +08:00
|
|
|
LoadingBar* loadingBarCopy = static_cast<LoadingBar*>(_uiLayer->getChildByTag(1));
|
2013-12-23 15:35:35 +08:00
|
|
|
loadingBar->setPercent(_count);
|
2015-06-05 15:57:39 +08:00
|
|
|
loadingBarCopy->setPercent(_count);
|
2013-09-16 20:54:13 +08:00
|
|
|
}
|
|
|
|
|
2015-12-01 11:07:02 +08:00
|
|
|
void UILoadingBarTest_Left::printWidgetResources(cocos2d::Ref* sender)
|
2015-11-30 16:17:13 +08:00
|
|
|
{
|
2015-12-10 14:27:39 +08:00
|
|
|
cocos2d::ResourceData textureFile = _loadingBar->getRenderFile();
|
2015-11-30 16:17:13 +08:00
|
|
|
CCLOG("textureFile Name : %s, Type: %d", textureFile.file.c_str(), textureFile.type);
|
|
|
|
}
|
|
|
|
|
2013-09-16 20:54:13 +08:00
|
|
|
// UILoadingBarTest_Right
|
|
|
|
|
|
|
|
UILoadingBarTest_Right::UILoadingBarTest_Right()
|
2013-12-23 15:35:35 +08:00
|
|
|
: _count(0)
|
2013-09-16 20:54:13 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
UILoadingBarTest_Right::~UILoadingBarTest_Right()
|
|
|
|
{
|
|
|
|
unscheduleUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UILoadingBarTest_Right::init()
|
|
|
|
{
|
|
|
|
if (UIScene::init())
|
|
|
|
{
|
|
|
|
scheduleUpdate();
|
|
|
|
|
2014-06-20 11:18:53 +08:00
|
|
|
Size widgetSize = _widget->getContentSize();
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
// Add the alert
|
2014-04-03 11:34:06 +08:00
|
|
|
Text *alert = Text::create("LoadingBar right", "fonts/Marker Felt.ttf", 30);
|
2013-09-16 20:54:13 +08:00
|
|
|
alert->setColor(Color3B(159, 168, 176));
|
2014-06-20 11:18:53 +08:00
|
|
|
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 1.75f));
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(alert);
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
// Create the loading bar
|
2014-04-03 11:34:06 +08:00
|
|
|
LoadingBar* loadingBar = LoadingBar::create("cocosui/sliderProgress.png");
|
2013-12-23 15:35:35 +08:00
|
|
|
loadingBar->setTag(0);
|
2014-05-14 10:48:16 +08:00
|
|
|
loadingBar->setDirection(LoadingBar::Direction::RIGHT);
|
2013-09-16 20:54:13 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
loadingBar->setPosition(Vec2(widgetSize.width / 2.0f,
|
2014-06-20 11:18:53 +08:00
|
|
|
widgetSize.height / 2.0f + loadingBar->getContentSize().height / 4.0f));
|
2014-04-03 11:34:06 +08:00
|
|
|
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(loadingBar);
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UILoadingBarTest_Right::update(float delta)
|
|
|
|
{
|
2013-12-23 15:35:35 +08:00
|
|
|
_count++;
|
|
|
|
if (_count > 100)
|
2013-09-16 20:54:13 +08:00
|
|
|
{
|
2013-12-23 15:35:35 +08:00
|
|
|
_count = 0;
|
2013-09-16 20:54:13 +08:00
|
|
|
}
|
2013-12-23 15:35:35 +08:00
|
|
|
LoadingBar* loadingBar = static_cast<LoadingBar*>(_uiLayer->getChildByTag(0));
|
|
|
|
loadingBar->setPercent(_count);
|
2013-09-16 20:54:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// UILoadingBarTest_Left_Scale9
|
|
|
|
|
|
|
|
UILoadingBarTest_Left_Scale9::UILoadingBarTest_Left_Scale9()
|
2013-12-23 15:35:35 +08:00
|
|
|
: _count(0)
|
2013-09-16 20:54:13 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
UILoadingBarTest_Left_Scale9::~UILoadingBarTest_Left_Scale9()
|
|
|
|
{
|
|
|
|
unscheduleUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UILoadingBarTest_Left_Scale9::init()
|
|
|
|
{
|
|
|
|
if (UIScene::init())
|
|
|
|
{
|
|
|
|
scheduleUpdate();
|
|
|
|
|
2014-06-20 11:18:53 +08:00
|
|
|
Size widgetSize = _widget->getContentSize();
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
// Add the alert
|
2014-04-03 11:34:06 +08:00
|
|
|
Text* alert = Text::create("LoadingBar left scale9 render", "fonts/Marker Felt.ttf", 20);
|
2013-09-16 20:54:13 +08:00
|
|
|
alert->setColor(Color3B(159, 168, 176));
|
2014-06-20 11:18:53 +08:00
|
|
|
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 2.7f));
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(alert);
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
// Create the loading bar
|
2014-04-03 11:34:06 +08:00
|
|
|
LoadingBar* loadingBar = LoadingBar::create("cocosui/slider_bar_active_9patch.png");
|
2013-12-23 15:35:35 +08:00
|
|
|
loadingBar->setTag(0);
|
2013-09-16 20:54:13 +08:00
|
|
|
loadingBar->setScale9Enabled(true);
|
|
|
|
loadingBar->setCapInsets(Rect(0, 0, 0, 0));
|
2014-06-20 14:03:33 +08:00
|
|
|
loadingBar->setContentSize(Size(300, 13));
|
2013-09-16 20:54:13 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
loadingBar->setPosition(Vec2(widgetSize.width / 2.0f,
|
2014-06-20 11:18:53 +08:00
|
|
|
widgetSize.height / 2.0f + loadingBar->getContentSize().height / 4.0f));
|
2014-04-03 11:34:06 +08:00
|
|
|
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(loadingBar);
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UILoadingBarTest_Left_Scale9::update(float delta)
|
|
|
|
{
|
2013-12-23 15:35:35 +08:00
|
|
|
_count++;
|
|
|
|
if (_count > 100)
|
2013-09-16 20:54:13 +08:00
|
|
|
{
|
2013-12-23 15:35:35 +08:00
|
|
|
_count = 0;
|
2013-09-16 20:54:13 +08:00
|
|
|
}
|
2013-12-23 15:35:35 +08:00
|
|
|
LoadingBar* loadingBar = static_cast<LoadingBar*>(_uiLayer->getChildByTag(0));
|
|
|
|
loadingBar->setPercent(_count);
|
2013-09-16 20:54:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// UILoadingBarTest_Right_Scale9
|
|
|
|
|
|
|
|
UILoadingBarTest_Right_Scale9::UILoadingBarTest_Right_Scale9()
|
2013-12-23 15:35:35 +08:00
|
|
|
: _count(0)
|
2013-09-16 20:54:13 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
UILoadingBarTest_Right_Scale9::~UILoadingBarTest_Right_Scale9()
|
|
|
|
{
|
|
|
|
unscheduleUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UILoadingBarTest_Right_Scale9::init()
|
|
|
|
{
|
|
|
|
if (UIScene::init())
|
|
|
|
{
|
|
|
|
scheduleUpdate();
|
|
|
|
|
2014-06-20 11:18:53 +08:00
|
|
|
Size widgetSize = _widget->getContentSize();
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
// Add the alert
|
2014-04-03 11:34:06 +08:00
|
|
|
Text *alert = Text::create("LoadingBar right scale9 render", "fonts/Marker Felt.ttf", 20);
|
2013-09-16 20:54:13 +08:00
|
|
|
alert->setColor(Color3B(159, 168, 176));
|
2014-06-20 11:18:53 +08:00
|
|
|
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 2.7f));
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(alert);
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
// Create the loading bar
|
2014-04-03 11:34:06 +08:00
|
|
|
LoadingBar* loadingBar = LoadingBar::create("cocosui/slider_bar_active_9patch.png");
|
2013-12-23 15:35:35 +08:00
|
|
|
loadingBar->setTag(0);
|
2013-09-16 20:54:13 +08:00
|
|
|
loadingBar->setScale9Enabled(true);
|
|
|
|
loadingBar->setCapInsets(Rect(0, 0, 0, 0));
|
2014-06-20 14:03:33 +08:00
|
|
|
loadingBar->setContentSize(Size(300, 13));
|
2014-05-14 10:48:16 +08:00
|
|
|
loadingBar->setDirection(LoadingBar::Direction::RIGHT);
|
2013-09-16 20:54:13 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
loadingBar->setPosition(Vec2(widgetSize.width / 2.0f,
|
2014-06-20 11:18:53 +08:00
|
|
|
widgetSize.height / 2.0f + loadingBar->getContentSize().height / 4.0f));
|
2014-04-03 11:34:06 +08:00
|
|
|
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(loadingBar);
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UILoadingBarTest_Right_Scale9::update(float delta)
|
|
|
|
{
|
2013-12-23 15:35:35 +08:00
|
|
|
_count++;
|
|
|
|
if (_count > 100)
|
2013-09-16 20:54:13 +08:00
|
|
|
{
|
2013-12-23 15:35:35 +08:00
|
|
|
_count = 0;
|
2013-09-16 20:54:13 +08:00
|
|
|
}
|
2013-12-23 15:35:35 +08:00
|
|
|
LoadingBar* loadingBar = static_cast<LoadingBar*>(_uiLayer->getChildByTag(0));
|
|
|
|
loadingBar->setPercent(_count);
|
2013-09-16 20:54:13 +08:00
|
|
|
}
|
|
|
|
|
2015-01-20 20:57:54 +08:00
|
|
|
// UILoadingBarTest_Scale9_State_Change
|
|
|
|
|
|
|
|
UILoadingBarTest_Scale9_State_Change::UILoadingBarTest_Scale9_State_Change()
|
|
|
|
: _count(0)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
UILoadingBarTest_Scale9_State_Change::~UILoadingBarTest_Scale9_State_Change()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2015-01-26 13:49:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// UILoadingBarReloadTexture
|
|
|
|
|
|
|
|
UILoadingBarReloadTexture::UILoadingBarReloadTexture()
|
|
|
|
: _count(0)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
UILoadingBarReloadTexture::~UILoadingBarReloadTexture()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UILoadingBarReloadTexture::init()
|
|
|
|
{
|
|
|
|
if (UIScene::init())
|
|
|
|
{
|
|
|
|
Size widgetSize = _widget->getContentSize();
|
|
|
|
|
|
|
|
// Add the alert
|
2015-01-26 14:46:45 +08:00
|
|
|
Text *alert = Text::create("Click button to Toggle Scale9 and switch Texture.", "fonts/Marker Felt.ttf", 20);
|
2015-01-26 13:49:54 +08:00
|
|
|
alert->setColor(Color3B(159, 168, 176));
|
2015-01-26 14:46:45 +08:00
|
|
|
alert->setPosition(Vec2(widgetSize.width / 2.0f,
|
|
|
|
widgetSize.height / 2.0f - alert->getContentSize().height * 2.7f));
|
2015-01-26 13:49:54 +08:00
|
|
|
_uiLayer->addChild(alert);
|
|
|
|
|
|
|
|
LoadingBar* loadingBar = LoadingBar::create("cocosui/slider_bar_active_9patch.png");
|
|
|
|
loadingBar->setTag(0);
|
|
|
|
loadingBar->ignoreContentAdaptWithSize(false);
|
2015-01-26 14:39:44 +08:00
|
|
|
// loadingBar->setScale9Enabled(true);
|
2015-01-26 13:49:54 +08:00
|
|
|
loadingBar->setCapInsets(Rect(0, 0, 0, 0));
|
|
|
|
loadingBar->setContentSize(Size(300, 13));
|
|
|
|
loadingBar->setName("texture0");
|
|
|
|
loadingBar->setDirection(LoadingBar::Direction::RIGHT);
|
2015-01-26 14:39:44 +08:00
|
|
|
loadingBar->setPercent(70);
|
2015-01-26 13:49:54 +08:00
|
|
|
loadingBar->setPosition(Vec2(widgetSize.width / 2.0f,
|
|
|
|
widgetSize.height / 2.0f + loadingBar->getContentSize().height / 4.0f));
|
|
|
|
|
|
|
|
_uiLayer->addChild(loadingBar);
|
|
|
|
|
2015-01-26 14:39:44 +08:00
|
|
|
auto buttonScale9 = Button::create("cocosui/animationbuttonnormal.png",
|
|
|
|
"cocosui/animationbuttonpressed.png");
|
2015-01-26 13:49:54 +08:00
|
|
|
buttonScale9->setTitleText("ToggleScale9");
|
|
|
|
buttonScale9->addClickEventListener([=](Ref*){
|
|
|
|
loadingBar->setScale9Enabled(!loadingBar->isScale9Enabled());
|
|
|
|
});
|
|
|
|
buttonScale9->setPosition(loadingBar->getPosition() + Vec2(-50,50));
|
|
|
|
_uiLayer->addChild(buttonScale9);
|
|
|
|
|
2015-01-26 14:39:44 +08:00
|
|
|
auto buttonChangeTexture = Button::create("cocosui/animationbuttonnormal.png",
|
|
|
|
"cocosui/animationbuttonpressed.png");
|
2015-01-26 13:49:54 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UILoadingBarReloadTexture::update(float delta)
|
|
|
|
{
|
|
|
|
_count++;
|
|
|
|
if (_count > 100)
|
|
|
|
{
|
|
|
|
_count = 0;
|
|
|
|
}
|
|
|
|
LoadingBar* loadingBar = static_cast<LoadingBar*>(_uiLayer->getChildByTag(0));
|
|
|
|
loadingBar->setPercent(_count);
|
2015-06-05 15:57:39 +08:00
|
|
|
}
|
2015-12-09 17:15:09 +08:00
|
|
|
|
|
|
|
|
|
|
|
// UILoadingBarIssue12249
|
|
|
|
|
|
|
|
UILoadingBarIssue12249::UILoadingBarIssue12249()
|
|
|
|
: _count(0)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
UILoadingBarIssue12249::~UILoadingBarIssue12249()
|
|
|
|
{
|
|
|
|
unscheduleUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UILoadingBarIssue12249::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->setScale9Enabled(true);
|
|
|
|
loadingBar->setContentSize(Size(200, loadingBar->getContentSize().height * 1.5));
|
|
|
|
loadingBar->setTag(0);
|
|
|
|
loadingBar->setPosition(Vec2(widgetSize.width / 2.0f,
|
|
|
|
widgetSize.height / 2.0f + loadingBar->getContentSize().height / 4.0f));
|
|
|
|
|
|
|
|
LoadingBar* loadingBarCopy = LoadingBar::create();
|
|
|
|
loadingBarCopy->setScale9Enabled(true);
|
|
|
|
loadingBarCopy->loadTexture("cocosui/sliderProgress.png");
|
|
|
|
loadingBarCopy->setContentSize(Size(200, loadingBarCopy->getContentSize().height * 1.5));
|
|
|
|
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);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2015-12-10 14:27:39 +08:00
|
|
|
}
|
2015-12-19 15:59:27 +08:00
|
|
|
|
|
|
|
// UILoadingBarTest_Direction
|
|
|
|
|
|
|
|
UILoadingBarTest_Direction::UILoadingBarTest_Direction()
|
|
|
|
: _count(0)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
UILoadingBarTest_Direction::~UILoadingBarTest_Direction()
|
|
|
|
{
|
|
|
|
//unscheduleUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2016-12-03 23:35:22 +08:00
|
|
|
}
|