diff --git a/cocos/editor-support/cocostudio/WidgetReader/LoadingBarReader/LoadingBarReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/LoadingBarReader/LoadingBarReader.cpp index 6b5c77785d..39f430b7b6 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/LoadingBarReader/LoadingBarReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/LoadingBarReader/LoadingBarReader.cpp @@ -63,7 +63,7 @@ namespace cocostudio } /**/ - loadingBar->setDirection(LoadingBarType(DICTOOL->getIntValue_json(options, "direction"))); + loadingBar->setBarDirection(LoadingBar::Direction(DICTOOL->getIntValue_json(options, "direction"))); loadingBar->setPercent(DICTOOL->getIntValue_json(options, "percent")); diff --git a/cocos/ui/UIDeprecated.h b/cocos/ui/UIDeprecated.h index 1dcf6ab36d..7be1f63b92 100644 --- a/cocos/ui/UIDeprecated.h +++ b/cocos/ui/UIDeprecated.h @@ -121,6 +121,9 @@ CC_DEPRECATED_ATTRIBUTE const ListView::Gravity LISTVIEW_GRAVITY_CENTER_HORIZONT CC_DEPRECATED_ATTRIBUTE const ListView::Gravity LISTVIEW_GRAVITY_TOP = ListView::Gravity::TOP; CC_DEPRECATED_ATTRIBUTE const ListView::Gravity LISTVIEW_GRAVITY_BOTTOM = ListView::Gravity::BOTTOM; CC_DEPRECATED_ATTRIBUTE const ListView::Gravity LISTVIEW_GRAVITY_CENTER_VERTICAL = ListView::Gravity::CENTER_VERTICAL; +CC_DEPRECATED_ATTRIBUTE const LoadingBar::Direction LoadingBarTypeLeft = LoadingBar::Direction::LEFT; +CC_DEPRECATED_ATTRIBUTE const LoadingBar::Direction LoadingBarTypeRight = LoadingBar::Direction::RIGHT; + CC_DEPRECATED_ATTRIBUTE typedef Widget::TextureResType TextureResType; CC_DEPRECATED_ATTRIBUTE typedef Widget::PositionType PositionType; @@ -134,6 +137,7 @@ CC_DEPRECATED_ATTRIBUTE typedef LayoutParameter::Type LayoutParameterType; CC_DEPRECATED_ATTRIBUTE typedef LinearLayoutParameter::LinearGravity LinearGravity; CC_DEPRECATED_ATTRIBUTE typedef RelativeLayoutParameter::RelativeAlign RelativeAlign; CC_DEPRECATED_ATTRIBUTE typedef ListView::Gravity ListViewGravity; + CC_DEPRECATED_ATTRIBUTE typedef LoadingBar::Direction LoadingBarType; } diff --git a/cocos/ui/UILoadingBar.cpp b/cocos/ui/UILoadingBar.cpp index 901d69a0de..831a73feed 100644 --- a/cocos/ui/UILoadingBar.cpp +++ b/cocos/ui/UILoadingBar.cpp @@ -34,7 +34,7 @@ static const int BAR_RENDERER_Z = (-1); IMPLEMENT_CLASS_GUI_INFO(LoadingBar) LoadingBar::LoadingBar(): -_barType(LoadingBarTypeLeft), +_direction(Direction::LEFT), _percent(100), _totalLength(0), _barRenderer(nullptr), @@ -85,17 +85,22 @@ void LoadingBar::initRenderer() _barRenderer->setAnchorPoint(Vector2(0.0,0.5)); } -void LoadingBar::setDirection(LoadingBarType dir) +void LoadingBar::setDirection(Direction direction) { - if (_barType == dir) + this->setBarDirection(direction); +} + +void LoadingBar::setBarDirection(cocos2d::ui::LoadingBar::Direction direction) +{ + if (_direction == direction) { return; } - _barType = dir; - - switch (_barType) + _direction = direction; + + switch (_direction) { - case LoadingBarTypeLeft: + case Direction::LEFT: _barRenderer->setAnchorPoint(Vector2(0.0f,0.5f)); _barRenderer->setPosition(Vector2(-_totalLength*0.5f,0.0f)); if (!_scale9Enabled) @@ -103,7 +108,7 @@ void LoadingBar::setDirection(LoadingBarType dir) static_cast(_barRenderer)->setFlippedX(false); } break; - case LoadingBarTypeRight: + case Direction::RIGHT: _barRenderer->setAnchorPoint(Vector2(1.0f,0.5f)); _barRenderer->setPosition(Vector2(_totalLength*0.5f,0.0f)); if (!_scale9Enabled) @@ -112,11 +117,17 @@ void LoadingBar::setDirection(LoadingBarType dir) } break; } + } +LoadingBar::Direction LoadingBar::getBarDirection() +{ + return _direction; +} + int LoadingBar::getDirection() { - return _barType; + return static_cast(_direction); } void LoadingBar::loadTexture(const std::string& texture,TextureResType texType) @@ -159,22 +170,22 @@ int LoadingBar::getDirection() updateRGBAToRenderer(_barRenderer); _barRendererTextureSize = _barRenderer->getContentSize(); - switch (_barType) + switch (_direction) { - case LoadingBarTypeLeft: - _barRenderer->setAnchorPoint(Vector2(0.0f,0.5f)); - if (!_scale9Enabled) - { - static_cast(_barRenderer)->setFlippedX(false); - } - break; - case LoadingBarTypeRight: - _barRenderer->setAnchorPoint(Vector2(1.0f,0.5f)); - if (!_scale9Enabled) - { - static_cast(_barRenderer)->setFlippedX(true); - } - break; + case Direction::LEFT: + _barRenderer->setAnchorPoint(Vector2(0.0f,0.5f)); + if (!_scale9Enabled) + { + static_cast(_barRenderer)->setFlippedX(false); + } + break; + case Direction::RIGHT: + _barRenderer->setAnchorPoint(Vector2(1.0f,0.5f)); + if (!_scale9Enabled) + { + static_cast(_barRenderer)->setFlippedX(true); + } + break; } // barRendererScaleChangedWithSize(); updateContentSizeWithTextureSize(_barRendererTextureSize); @@ -331,12 +342,12 @@ void LoadingBar::barRendererScaleChangedWithSize() _barRenderer->setScaleY(scaleY); } } - switch (_barType) + switch (_direction) { - case LoadingBarTypeLeft: + case Direction::LEFT: _barRenderer->setPosition(Vector2(0.0f, _contentSize.height / 2.0f)); break; - case LoadingBarTypeRight: + case Direction::RIGHT: _barRenderer->setPosition(Vector2(_totalLength, _contentSize.height / 2.0f)); break; default: @@ -385,7 +396,7 @@ void LoadingBar::copySpecialProperties(Widget *widget) loadTexture(loadingBar->_textureFile, loadingBar->_renderBarTexType); setCapInsets(loadingBar->_capInsets); setPercent(loadingBar->_percent); - setDirection(loadingBar->_barType); + setDirection(loadingBar->_direction); } } diff --git a/cocos/ui/UILoadingBar.h b/cocos/ui/UILoadingBar.h index f23e2e4b89..cf6c2a8acb 100644 --- a/cocos/ui/UILoadingBar.h +++ b/cocos/ui/UILoadingBar.h @@ -31,11 +31,6 @@ NS_CC_BEGIN namespace ui { -typedef enum -{ - LoadingBarTypeLeft, - LoadingBarTypeRight -}LoadingBarType; /** * @js NA * @lua NA @@ -46,6 +41,11 @@ class LoadingBar : public Widget DECLARE_CLASS_GUI_INFO public: + enum class Direction + { + LEFT, + RIGHT + }; /** * Default constructor */ @@ -73,7 +73,8 @@ public: * * @param LoadingBarType */ - void setDirection(LoadingBarType dir); + CC_DEPRECATED_ATTRIBUTE void setDirection(Direction direction); + void setBarDirection(Direction direction); /** * Gets the progress direction of loadingbar. @@ -82,7 +83,8 @@ public: * * @param LoadingBarType */ - int getDirection(); + CC_DEPRECATED_ATTRIBUTE int getDirection(); + Direction getBarDirection(); /** * Load texture for loadingbar. @@ -150,7 +152,7 @@ protected: virtual void copySpecialProperties(Widget* model) override; virtual void adaptRenderers() override; protected: - LoadingBarType _barType; + Direction _direction; int _percent; float _totalLength; Node* _barRenderer; diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest.cpp index 11effd77fe..0386580fdd 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest.cpp @@ -314,7 +314,6 @@ bool UIListViewTest_Horizontal::init() ssize_t index = listView->getIndex(item); button->setTitleText(static_cast<__String*>(_array->getObjectAtIndex(index))->getCString()); } - // remove last item listView->removeLastItem(); diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp index 21f3e2dc7f..aaec09b33e 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp @@ -111,7 +111,7 @@ bool UILoadingBarTest_Right::init() // Create the loading bar LoadingBar* loadingBar = LoadingBar::create("cocosui/sliderProgress.png"); loadingBar->setTag(0); - loadingBar->setDirection(LoadingBarTypeRight); + loadingBar->setBarDirection(LoadingBar::Direction::RIGHT); loadingBar->setPosition(Vector2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + loadingBar->getSize().height / 4.0f)); @@ -276,7 +276,7 @@ bool UILoadingBarTest_Right_Scale9::init() loadingBar->setScale9Enabled(true); loadingBar->setCapInsets(Rect(0, 0, 0, 0)); loadingBar->setSize(Size(300, 13)); - loadingBar->setDirection(LoadingBarTypeRight); + loadingBar->setBarDirection(LoadingBar::Direction::RIGHT); loadingBar->setPosition(Vector2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + loadingBar->getSize().height / 4.0f));