diff --git a/CHANGELOG b/CHANGELOG index 609b4923b015..8d2f8079c275 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,8 @@ -cocos2d-x-3.4 ?? - [NEW] UI:LoadingBar: add TextureResType to LoadingBar's create method +cocos2d-x-3.4beta0 ?? + [NEW] Action: MoveTo and MoveBy support Vec3 [NEW] Allocator: add custom allocator support, global, default, fixed block, object pool. + [NEW] UI:LoadingBar: add TextureResType to LoadingBar's create method + [NEW] Director: add setClearColor() to set clear values for the color buffers [FIX] FileUtils: WebP format with alpha channel displayed wrong [FIX] Label: content size of Label is incorrect if the string is set to empty string diff --git a/build/cocos2d_libs.xcodeproj/project.pbxproj b/build/cocos2d_libs.xcodeproj/project.pbxproj index 228a3d019cd5..592a58106b26 100644 --- a/build/cocos2d_libs.xcodeproj/project.pbxproj +++ b/build/cocos2d_libs.xcodeproj/project.pbxproj @@ -1257,6 +1257,12 @@ 38B8E2E219E671D2002D7CE7 /* UILayoutComponent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 38B8E2DF19E671D2002D7CE7 /* UILayoutComponent.cpp */; }; 38B8E2E319E671D2002D7CE7 /* UILayoutComponent.h in Headers */ = {isa = PBXBuildFile; fileRef = 38B8E2E019E671D2002D7CE7 /* UILayoutComponent.h */; }; 38B8E2E419E671D2002D7CE7 /* UILayoutComponent.h in Headers */ = {isa = PBXBuildFile; fileRef = 38B8E2E019E671D2002D7CE7 /* UILayoutComponent.h */; }; + 38F5263E1A48363B000DB7F7 /* ArmatureNodeReader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 38F5263B1A48363B000DB7F7 /* ArmatureNodeReader.cpp */; }; + 38F5263F1A48363B000DB7F7 /* ArmatureNodeReader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 38F5263B1A48363B000DB7F7 /* ArmatureNodeReader.cpp */; }; + 38F526401A48363B000DB7F7 /* ArmatureNodeReader.h in Headers */ = {isa = PBXBuildFile; fileRef = 38F5263C1A48363B000DB7F7 /* ArmatureNodeReader.h */; }; + 38F526411A48363B000DB7F7 /* ArmatureNodeReader.h in Headers */ = {isa = PBXBuildFile; fileRef = 38F5263C1A48363B000DB7F7 /* ArmatureNodeReader.h */; }; + 38F526421A48363B000DB7F7 /* CSArmatureNode_generated.h in Headers */ = {isa = PBXBuildFile; fileRef = 38F5263D1A48363B000DB7F7 /* CSArmatureNode_generated.h */; }; + 38F526431A48363B000DB7F7 /* CSArmatureNode_generated.h in Headers */ = {isa = PBXBuildFile; fileRef = 38F5263D1A48363B000DB7F7 /* CSArmatureNode_generated.h */; }; 3E2BDADE19C030ED0055CDCD /* AudioEngine.h in Headers */ = {isa = PBXBuildFile; fileRef = 3E2BDADD19C030ED0055CDCD /* AudioEngine.h */; }; 3E2BDAEC19C0436F0055CDCD /* AudioEngine.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3E2BDAEB19C0436F0055CDCD /* AudioEngine.cpp */; }; 3E2F27A619CFBFE100E7C490 /* AudioEngine.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3E2BDAEB19C0436F0055CDCD /* AudioEngine.cpp */; }; @@ -1304,6 +1310,10 @@ 46C02E0818E91123004B7456 /* xxhash.c in Sources */ = {isa = PBXBuildFile; fileRef = 46C02E0518E91123004B7456 /* xxhash.c */; }; 46C02E0918E91123004B7456 /* xxhash.h in Headers */ = {isa = PBXBuildFile; fileRef = 46C02E0618E91123004B7456 /* xxhash.h */; }; 46C02E0A18E91123004B7456 /* xxhash.h in Headers */ = {isa = PBXBuildFile; fileRef = 46C02E0618E91123004B7456 /* xxhash.h */; }; + 4D76BE3A1A4AAF0A00102962 /* CCActionTimelineNode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D76BE381A4AAF0A00102962 /* CCActionTimelineNode.cpp */; }; + 4D76BE3B1A4AAF0A00102962 /* CCActionTimelineNode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D76BE381A4AAF0A00102962 /* CCActionTimelineNode.cpp */; }; + 4D76BE3C1A4AAF0A00102962 /* CCActionTimelineNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 4D76BE391A4AAF0A00102962 /* CCActionTimelineNode.h */; }; + 4D76BE3D1A4AAF0A00102962 /* CCActionTimelineNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 4D76BE391A4AAF0A00102962 /* CCActionTimelineNode.h */; }; 5027253A190BF1B900AAF4ED /* cocos2d.h in Headers */ = {isa = PBXBuildFile; fileRef = 50272538190BF1B900AAF4ED /* cocos2d.h */; }; 5027253B190BF1B900AAF4ED /* cocos2d.h in Headers */ = {isa = PBXBuildFile; fileRef = 50272538190BF1B900AAF4ED /* cocos2d.h */; }; 5027253C190BF1B900AAF4ED /* cocos2d.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 50272539190BF1B900AAF4ED /* cocos2d.cpp */; }; @@ -2450,6 +2460,9 @@ 38B8E2D419E66581002D7CE7 /* CSLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSLoader.h; sourceTree = ""; }; 38B8E2DF19E671D2002D7CE7 /* UILayoutComponent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UILayoutComponent.cpp; sourceTree = ""; }; 38B8E2E019E671D2002D7CE7 /* UILayoutComponent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UILayoutComponent.h; sourceTree = ""; }; + 38F5263B1A48363B000DB7F7 /* ArmatureNodeReader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ArmatureNodeReader.cpp; sourceTree = ""; }; + 38F5263C1A48363B000DB7F7 /* ArmatureNodeReader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ArmatureNodeReader.h; sourceTree = ""; }; + 38F5263D1A48363B000DB7F7 /* CSArmatureNode_generated.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSArmatureNode_generated.h; sourceTree = ""; }; 3E2BDADD19C030ED0055CDCD /* AudioEngine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AudioEngine.h; sourceTree = ""; }; 3E2BDAEB19C0436F0055CDCD /* AudioEngine.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AudioEngine.cpp; sourceTree = ""; }; 3E6176551960F89B00DE83F5 /* CCController-iOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = "CCController-iOS.mm"; path = "../base/CCController-iOS.mm"; sourceTree = ""; }; @@ -2629,6 +2642,8 @@ 46A170781807CE7A005B8026 /* CCPhysicsWorld.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CCPhysicsWorld.h; sourceTree = ""; }; 46C02E0518E91123004B7456 /* xxhash.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = xxhash.c; sourceTree = ""; }; 46C02E0618E91123004B7456 /* xxhash.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = xxhash.h; sourceTree = ""; }; + 4D76BE381A4AAF0A00102962 /* CCActionTimelineNode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCActionTimelineNode.cpp; sourceTree = ""; }; + 4D76BE391A4AAF0A00102962 /* CCActionTimelineNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCActionTimelineNode.h; sourceTree = ""; }; 50272538190BF1B900AAF4ED /* cocos2d.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = cocos2d.h; path = ../cocos/cocos2d.h; sourceTree = ""; }; 50272539190BF1B900AAF4ED /* cocos2d.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = cocos2d.cpp; path = ../cocos/cocos2d.cpp; sourceTree = ""; }; 5034C9FB191D591000CE6051 /* ccShader_PositionTextureColorAlphaTest.frag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = ccShader_PositionTextureColorAlphaTest.frag; sourceTree = ""; }; @@ -3081,6 +3096,8 @@ 0634A4C4194B19E400E608AF /* ActionTimeline */ = { isa = PBXGroup; children = ( + 4D76BE381A4AAF0A00102962 /* CCActionTimelineNode.cpp */, + 4D76BE391A4AAF0A00102962 /* CCActionTimelineNode.h */, 38B8E2D319E66581002D7CE7 /* CSLoader.cpp */, 38B8E2D419E66581002D7CE7 /* CSLoader.h */, 0634A4C5194B19E400E608AF /* CCActionTimeline.cpp */, @@ -4380,6 +4397,16 @@ path = SpriteReader; sourceTree = ""; }; + 38F5263A1A48363B000DB7F7 /* ArmatureNodeReader */ = { + isa = PBXGroup; + children = ( + 38F5263B1A48363B000DB7F7 /* ArmatureNodeReader.cpp */, + 38F5263C1A48363B000DB7F7 /* ArmatureNodeReader.h */, + 38F5263D1A48363B000DB7F7 /* CSArmatureNode_generated.h */, + ); + path = ArmatureNodeReader; + sourceTree = ""; + }; 46A15FD01807A56F005B8026 /* audio */ = { isa = PBXGroup; children = ( @@ -4981,6 +5008,7 @@ 50FCEB6818C72017004AD434 /* WidgetReader */ = { isa = PBXGroup; children = ( + 38F5263A1A48363B000DB7F7 /* ArmatureNodeReader */, 382384251A2590F9002C4610 /* NodeReader */, 3823843A1A259140002C4610 /* SingleNodeReader */, 382384411A25915C002C4610 /* SpriteReader */, @@ -5227,6 +5255,7 @@ 15AE180A19AAD2F700C27E9E /* CCAABB.h in Headers */, 46A170E71807CECA005B8026 /* CCPhysicsBody.h in Headers */, 15AE1A5A19AAD40300C27E9E /* b2StackAllocator.h in Headers */, + 38F526401A48363B000DB7F7 /* ArmatureNodeReader.h in Headers */, B29A7E3119EE1B7700872B35 /* SkinnedMeshAttachment.h in Headers */, 15AE1B6F19AADA9900C27E9E /* GUIDefine.h in Headers */, 15AE1A8119AAD40300C27E9E /* b2FrictionJoint.h in Headers */, @@ -5269,6 +5298,7 @@ 15AE1AD919AAD41000C27E9E /* b2Rope.h in Headers */, 15AE187B19AAD33D00C27E9E /* CCBAnimationManager.h in Headers */, 1A57006B180BC5A10088DEC7 /* CCActionCatmullRom.h in Headers */, + 4D76BE3C1A4AAF0A00102962 /* CCActionTimelineNode.h in Headers */, 1A57006F180BC5A10088DEC7 /* CCActionEase.h in Headers */, 15AE1BD719AAE01E00C27E9E /* CCControlSlider.h in Headers */, 15AE1BE519AAE01E00C27E9E /* CCTableView.h in Headers */, @@ -5355,6 +5385,7 @@ 15AE1B6C19AADA9900C27E9E /* UIWidget.h in Headers */, 15AE180E19AAD2F700C27E9E /* CCAnimate3D.h in Headers */, 1A5701B3180BCB590088DEC7 /* CCFontFNT.h in Headers */, + 38F526421A48363B000DB7F7 /* CSArmatureNode_generated.h in Headers */, 15AE1BD919AAE01E00C27E9E /* CCControlStepper.h in Headers */, 15AE192119AAD35000C27E9E /* CocoStudio.h in Headers */, 15AE18A119AAD33D00C27E9E /* CCNodeLoaderListener.h in Headers */, @@ -5981,6 +6012,7 @@ 15AE1AA819AAD40300C27E9E /* b2Island.h in Headers */, 15B3708B19EE414C00ABE682 /* Manifest.h in Headers */, 1A570213180BCBF40088DEC7 /* CCProgressTimer.h in Headers */, + 38F526431A48363B000DB7F7 /* CSArmatureNode_generated.h in Headers */, B37510821823ACA100B3BA6A /* CCPhysicsJointInfo_chipmunk.h in Headers */, 1A570217180BCBF40088DEC7 /* CCRenderTexture.h in Headers */, 15AE1ABB19AAD40300C27E9E /* b2EdgeAndPolygonContact.h in Headers */, @@ -6012,6 +6044,7 @@ 15AE1A3B19AAD3D500C27E9E /* b2BroadPhase.h in Headers */, 15AE195619AAD35100C27E9E /* CCDisplayManager.h in Headers */, 15AE1B8719AADA9A00C27E9E /* UIButton.h in Headers */, + 38F526411A48363B000DB7F7 /* ArmatureNodeReader.h in Headers */, 50ABBE441925AB6F00A911A9 /* CCDirector.h in Headers */, 5034CA4A191D591100CE6051 /* ccShader_Label_df.frag in Headers */, 15AE1B7519AADA9A00C27E9E /* UILoadingBar.h in Headers */, @@ -6239,6 +6272,7 @@ 15AE1B8B19AADA9A00C27E9E /* UIImageView.h in Headers */, 15AE1A4619AAD3D500C27E9E /* b2TimeOfImpact.h in Headers */, 50ABBE601925AB6F00A911A9 /* CCEventListener.h in Headers */, + 4D76BE3D1A4AAF0A00102962 /* CCActionTimelineNode.h in Headers */, 50ABBEB21925AB6F00A911A9 /* CCUserDefault.h in Headers */, 15AE198B19AAD36A00C27E9E /* ButtonReader.h in Headers */, ); @@ -6554,6 +6588,7 @@ 382383F01A258FA7002C4610 /* flatc.cpp in Sources */, 1A57028A180BCC900088DEC7 /* CCSpriteFrameCache.cpp in Sources */, 15AE18E619AAD35000C27E9E /* CCActionFrameEasing.cpp in Sources */, + 38F5263E1A48363B000DB7F7 /* ArmatureNodeReader.cpp in Sources */, B29A7DC919EE1B7700872B35 /* SlotData.c in Sources */, 15AE190F19AAD35000C27E9E /* CCInputDelegate.cpp in Sources */, 15AE181A19AAD2F700C27E9E /* CCBundle3D.cpp in Sources */, @@ -6739,6 +6774,7 @@ 15AE182819AAD2F700C27E9E /* CCMeshSkin.cpp in Sources */, 15AE19A619AAD39600C27E9E /* TextReader.cpp in Sources */, 15AE198819AAD36A00C27E9E /* ButtonReader.cpp in Sources */, + 4D76BE3A1A4AAF0A00102962 /* CCActionTimelineNode.cpp in Sources */, 15AE1A6319AAD40300C27E9E /* b2Island.cpp in Sources */, 15AE1A8419AAD40300C27E9E /* b2Joint.cpp in Sources */, 50ABBD601925AB0000A911A9 /* Vec4.cpp in Sources */, @@ -6952,6 +6988,7 @@ 50ABBE241925AB6F00A911A9 /* base64.cpp in Sources */, 1A5701A6180BCB590088DEC7 /* CCFontAtlasCache.cpp in Sources */, 15AE192B19AAD35100C27E9E /* TriggerObj.cpp in Sources */, + 4D76BE3B1A4AAF0A00102962 /* CCActionTimelineNode.cpp in Sources */, 15AE198519AAD36400C27E9E /* WidgetReader.cpp in Sources */, 15AE1AAA19AAD40300C27E9E /* b2World.cpp in Sources */, 15AE1AB019AAD40300C27E9E /* b2ChainAndPolygonContact.cpp in Sources */, @@ -7038,6 +7075,7 @@ 15AE19B619AAD39700C27E9E /* TextBMFontReader.cpp in Sources */, 15AE1BFD19AAE01E00C27E9E /* CCInvocation.cpp in Sources */, B24AA98A195A675C007B4522 /* CCFastTMXTiledMap.cpp in Sources */, + 38F5263F1A48363B000DB7F7 /* ArmatureNodeReader.cpp in Sources */, 15AE18CE19AAD33D00C27E9E /* CCNodeLoader.cpp in Sources */, 38ACD1FD1A27111900C3093D /* WidgetCallBackHandlerProtocol.cpp in Sources */, 29394CF719B01DBA00D2DE1A /* UIWebViewImpl-ios.mm in Sources */, diff --git a/cocos/2d/CCNode.cpp b/cocos/2d/CCNode.cpp index e756ae32baa8..95f98f91278d 100644 --- a/cocos/2d/CCNode.cpp +++ b/cocos/2d/CCNode.cpp @@ -457,6 +457,7 @@ void Node::setScale(float scaleX,float scaleY) #if CC_USE_PHYSICS if(g_physicsSceneCount == 0) return; + auto scene = getScene(); if (!scene || scene->getPhysicsWorld()) { @@ -477,6 +478,7 @@ void Node::setScaleX(float scaleX) #if CC_USE_PHYSICS if(g_physicsSceneCount == 0) return; + auto scene = getScene(); if (!scene || scene->getPhysicsWorld()) { @@ -524,8 +526,9 @@ void Node::setScaleY(float scaleY) _transformUpdated = _transformDirty = _inverseDirty = true; #if CC_USE_PHYSICS - if(g_physicsSceneCount == 0) + if (g_physicsSceneCount == 0) return; + auto scene = getScene(); if (!scene || scene->getPhysicsWorld()) { @@ -580,11 +583,7 @@ void Node::setPosition3D(const Vec3& position) Vec3 Node::getPosition3D() const { - Vec3 ret; - ret.x = _position.x; - ret.y = _position.y; - ret.z = _positionZ; - return ret; + return Vec3(_position.x, _position.y, _positionZ); } float Node::getPositionX() const @@ -661,7 +660,8 @@ void Node::setVisible(bool visible) if(visible != _visible) { _visible = visible; - if(_visible) _transformUpdated = _transformDirty = _inverseDirty = true; + if(_visible) + _transformUpdated = _transformDirty = _inverseDirty = true; } } @@ -686,10 +686,10 @@ void Node::setAnchorPoint(const Vec2& point) } #endif - if( ! point.equals(_anchorPoint)) + if (! point.equals(_anchorPoint)) { _anchorPoint = point; - _anchorPointInPoints = Vec2(_contentSize.width * _anchorPoint.x, _contentSize.height * _anchorPoint.y ); + _anchorPointInPoints = Vec2(_contentSize.width * _anchorPoint.x, _contentSize.height * _anchorPoint.y); _transformUpdated = _transformDirty = _inverseDirty = true; } } @@ -702,11 +702,11 @@ const Size& Node::getContentSize() const void Node::setContentSize(const Size & size) { - if ( ! size.equals(_contentSize)) + if (! size.equals(_contentSize)) { _contentSize = size; - _anchorPointInPoints = Vec2(_contentSize.width * _anchorPoint.x, _contentSize.height * _anchorPoint.y ); + _anchorPointInPoints = Vec2(_contentSize.width * _anchorPoint.x, _contentSize.height * _anchorPoint.y); _transformUpdated = _transformDirty = _inverseDirty = _contentSizeDirty = true; } } @@ -794,7 +794,8 @@ GLProgramState* Node::getGLProgramState() const void Node::setGLProgramState(cocos2d::GLProgramState *glProgramState) { - if(glProgramState != _glProgramState) { + if (glProgramState != _glProgramState) + { CC_SAFE_RELEASE(_glProgramState); _glProgramState = glProgramState; CC_SAFE_RETAIN(_glProgramState); @@ -818,7 +819,7 @@ GLProgram * Node::getGLProgram() const Scene* Node::getScene() const { - if(!_parent) + if (!_parent) return nullptr; auto sceneNode = _parent; @@ -832,7 +833,7 @@ Scene* Node::getScene() const Rect Node::getBoundingBox() const { - Rect rect = Rect(0, 0, _contentSize.width, _contentSize.height); + Rect rect(0, 0, _contentSize.width, _contentSize.height); return RectApplyAffineTransform(rect, getNodeToParentAffineTransform()); } @@ -848,7 +849,7 @@ Node* Node::getChildByTag(int tag) const { CCASSERT( tag != Node::INVALID_TAG, "Invalid tag"); - for (auto& child : _children) + for (const auto& child : _children) { if(child && child->_tag == tag) return child; @@ -1038,7 +1039,8 @@ void Node::addChildHelper(Node* child, int localZOrder, int tag, const std::stri { child->onEnter(); // prevent onEnterTransitionDidFinish to be called twice when a node is added in onEnter - if (_isTransitionFinished) { + if (_isTransitionFinished) + { child->onEnterTransitionDidFinish(); } } @@ -1151,7 +1153,7 @@ void Node::removeFromPhysicsWorld() void Node::removeAllChildrenWithCleanup(bool cleanup) { // not using detachChild improves speed here - for (auto& child : _children) + for (const auto& child : _children) { // IMPORTANT: // -1st do onExit @@ -1225,8 +1227,9 @@ void Node::reorderChild(Node *child, int zOrder) void Node::sortAllChildren() { - if( _reorderChildDirty ) { - std::sort( std::begin(_children), std::end(_children), nodeComparisonLess ); + if (_reorderChildDirty) + { + std::sort(std::begin(_children), std::end(_children), nodeComparisonLess); _reorderChildDirty = false; } } @@ -1246,16 +1249,18 @@ void Node::draw(Renderer* renderer, const Mat4 &transform, uint32_t flags) void Node::visit() { auto renderer = Director::getInstance()->getRenderer(); - Mat4 parentTransform = Director::getInstance()->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); + auto& parentTransform = Director::getInstance()->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); visit(renderer, parentTransform, true); } uint32_t Node::processParentFlags(const Mat4& parentTransform, uint32_t parentFlags) { - if(_usingNormalizedPosition) { + if(_usingNormalizedPosition) + { CCASSERT(_parent, "setNormalizedPosition() doesn't work with orphan nodes"); - if ((parentFlags & FLAGS_CONTENT_SIZE_DIRTY) || _normalizedPositionDirty) { - auto s = _parent->getContentSize(); + if ((parentFlags & FLAGS_CONTENT_SIZE_DIRTY) || _normalizedPositionDirty) + { + auto& s = _parent->getContentSize(); _position.x = _normalizedPosition.x * s.width; _position.y = _normalizedPosition.y * s.height; _transformUpdated = _transformDirty = _inverseDirty = true; @@ -1313,7 +1318,7 @@ void Node::visit(Renderer* renderer, const Mat4 &parentTransform, uint32_t paren { auto node = _children.at(i); - if ( node && node->_localZOrder < 0 ) + if (node && node->_localZOrder < 0) node->visit(renderer, _modelViewTransform, flags); else break; @@ -1340,9 +1345,7 @@ void Node::visit(Renderer* renderer, const Mat4 &parentTransform, uint32_t paren Mat4 Node::transform(const Mat4& parentTransform) { - Mat4 ret = this->getNodeToParentTransform(); - ret = parentTransform * ret; - return ret; + return parentTransform * this->getNodeToParentTransform(); } // MARK: events @@ -1467,7 +1470,8 @@ void Node::setEventDispatcher(EventDispatcher* dispatcher) void Node::setActionManager(ActionManager* actionManager) { - if( actionManager != _actionManager ) { + if( actionManager != _actionManager ) + { this->stopAllActions(); CC_SAFE_RETAIN(actionManager); CC_SAFE_RELEASE(_actionManager); @@ -1521,7 +1525,8 @@ ssize_t Node::getNumberOfRunningActions() const void Node::setScheduler(Scheduler* scheduler) { - if( scheduler != _scheduler ) { + if( scheduler != _scheduler ) + { this->unscheduleAllCallbacks(); CC_SAFE_RETAIN(scheduler); CC_SAFE_RELEASE(_scheduler); @@ -1719,9 +1724,7 @@ const Mat4& Node::getNodeToParentTransform() const bool needsSkewMatrix = ( _skewX || _skewY ); - Vec2 anchorPoint; - anchorPoint.x = _anchorPointInPoints.x * _scaleX; - anchorPoint.y = _anchorPointInPoints.y * _scaleY; + Vec2 anchorPoint(_anchorPointInPoints.x * _scaleX, _anchorPointInPoints.y * _scaleY); // optimization: // inline anchor point calculation if skew is not needed @@ -1750,12 +1753,14 @@ const Mat4& Node::getNodeToParentTransform() const // FIXME: // FIX ME: Expensive operation. // FIX ME: It should be done together with the rotationZ - if(_rotationY) { + if(_rotationY) + { Mat4 rotY; Mat4::createRotationY(CC_DEGREES_TO_RADIANS(_rotationY), &rotY); _transform = _transform * rotY; } - if(_rotationX) { + if(_rotationX) + { Mat4 rotX; Mat4::createRotationX(CC_DEGREES_TO_RADIANS(_rotationX), &rotX); _transform = _transform * rotX; @@ -1818,9 +1823,12 @@ void Node::setAdditionalTransform(const AffineTransform& additionalTransform) void Node::setAdditionalTransform(Mat4* additionalTransform) { - if(additionalTransform == nullptr) { + if (additionalTransform == nullptr) + { _useAdditionalTransform = false; - } else { + } + else + { _additionalTransform = *additionalTransform; _useAdditionalTransform = true; } @@ -1831,15 +1839,15 @@ void Node::setAdditionalTransform(Mat4* additionalTransform) AffineTransform Node::getParentToNodeAffineTransform() const { AffineTransform ret; - Mat4 ret4 = getParentToNodeTransform(); - GLToCGAffine(ret4.m,&ret); + GLToCGAffine(getParentToNodeTransform().m,&ret); return ret; } const Mat4& Node::getParentToNodeTransform() const { - if ( _inverseDirty ) { + if ( _inverseDirty ) + { _inverse = _transform.getInversed(); _inverseDirty = false; } @@ -1850,7 +1858,7 @@ const Mat4& Node::getParentToNodeTransform() const AffineTransform Node::getNodeToWorldAffineTransform() const { - AffineTransform t = this->getNodeToParentAffineTransform(); + AffineTransform t(this->getNodeToParentAffineTransform()); for (Node *p = _parent; p != nullptr; p = p->getParent()) t = AffineTransformConcat(t, p->getNodeToParentAffineTransform()); @@ -1860,7 +1868,7 @@ AffineTransform Node::getNodeToWorldAffineTransform() const Mat4 Node::getNodeToWorldTransform() const { - Mat4 t = this->getNodeToParentTransform(); + Mat4 t(this->getNodeToParentTransform()); for (Node *p = _parent; p != nullptr; p = p->getParent()) { @@ -1902,27 +1910,25 @@ Vec2 Node::convertToWorldSpace(const Vec2& nodePoint) const Vec2 Node::convertToNodeSpaceAR(const Vec2& worldPoint) const { - Vec2 nodePoint = convertToNodeSpace(worldPoint); + Vec2 nodePoint(convertToNodeSpace(worldPoint)); return nodePoint - _anchorPointInPoints; } Vec2 Node::convertToWorldSpaceAR(const Vec2& nodePoint) const { - Vec2 pt = nodePoint + _anchorPointInPoints; - return convertToWorldSpace(pt); + return convertToWorldSpace(nodePoint + _anchorPointInPoints); } Vec2 Node::convertToWindowSpace(const Vec2& nodePoint) const { - Vec2 worldPoint = this->convertToWorldSpace(nodePoint); + Vec2 worldPoint(this->convertToWorldSpace(nodePoint)); return Director::getInstance()->convertToUI(worldPoint); } // convenience methods which take a Touch instead of Vec2 Vec2 Node::convertTouchToNodeSpace(Touch *touch) const { - Vec2 point = touch->getLocation(); - return this->convertToNodeSpace(point); + return this->convertToNodeSpace(touch->getLocation()); } Vec2 Node::convertTouchToNodeSpaceAR(Touch *touch) const @@ -1942,37 +1948,42 @@ void Node::updateTransform() Component* Node::getComponent(const std::string& name) { - if( _componentContainer ) + if (_componentContainer) return _componentContainer->get(name); + return nullptr; } bool Node::addComponent(Component *component) { // lazy alloc - if( !_componentContainer ) + if (!_componentContainer) _componentContainer = new (std::nothrow) ComponentContainer(this); + return _componentContainer->add(component); } bool Node::removeComponent(const std::string& name) { - if( _componentContainer ) + if (_componentContainer) return _componentContainer->remove(name); + return false; } bool Node::removeComponent(Component *component) { - if (_componentContainer) { + if (_componentContainer) + { return _componentContainer->remove(component); } + return false; } void Node::removeAllComponents() { - if( _componentContainer ) + if (_componentContainer) _componentContainer->removeAll(); } @@ -2055,7 +2066,7 @@ void Node::updatePhysicsBodyScale(Scene* scene) } } - for (auto child : _children) + for (const auto& child : _children) { child->updatePhysicsBodyScale(scene); } @@ -2159,7 +2170,8 @@ void Node::updateDisplayedOpacity(GLubyte parentOpacity) if (_cascadeOpacityEnabled) { - for(auto child : _children){ + for(const auto& child : _children) + { child->updateDisplayedOpacity(_displayedOpacity); } } @@ -2205,7 +2217,8 @@ void Node::disableCascadeOpacity() { _displayedOpacity = _realOpacity; - for(auto child : _children){ + for(const auto& child : _children) + { child->updateDisplayedOpacity(255); } } @@ -2236,7 +2249,8 @@ void Node::updateDisplayedColor(const Color3B& parentColor) if (_cascadeColorEnabled) { - for(const auto &child : _children){ + for(const auto &child : _children) + { child->updateDisplayedColor(_displayedColor); } } @@ -2279,7 +2293,8 @@ void Node::updateCascadeColor() void Node::disableCascadeColor() { - for(auto child : _children){ + for(const auto& child : _children) + { child->updateDisplayedColor(Color3B::WHITE); } } @@ -2290,7 +2305,8 @@ void Node::setCameraMask(unsigned short mask, bool applyChildren) _cameraMask = mask; if (applyChildren) { - for (auto child : _children) { + for (const auto& child : _children) + { child->setCameraMask(mask, applyChildren); } } diff --git a/cocos/2d/libcocos2d.vcxproj b/cocos/2d/libcocos2d.vcxproj index 84c68111274c..395dbfdcf116 100644 --- a/cocos/2d/libcocos2d.vcxproj +++ b/cocos/2d/libcocos2d.vcxproj @@ -322,6 +322,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\chipmunk\prebuilt\win32\release-lib\*.* + @@ -363,6 +364,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\chipmunk\prebuilt\win32\release-lib\*.* + @@ -722,6 +724,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\chipmunk\prebuilt\win32\release-lib\*.* + @@ -768,6 +771,8 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\chipmunk\prebuilt\win32\release-lib\*.* + + diff --git a/cocos/2d/libcocos2d.vcxproj.filters b/cocos/2d/libcocos2d.vcxproj.filters index c75176338166..2b7c3c2788d1 100644 --- a/cocos/2d/libcocos2d.vcxproj.filters +++ b/cocos/2d/libcocos2d.vcxproj.filters @@ -1,4 +1,4 @@ - + @@ -241,8 +241,8 @@ {92ff4e66-3943-47da-a439-c8f182bb871a} - - {0b27077c-fc08-496c-b2da-80f0d10dd9f4} + + {e1848cce-b225-42c4-bb6e-6430b6da123b} @@ -1295,6 +1295,9 @@ cocostudio\json + + cocostudio\TimelineAction + base @@ -1307,8 +1310,8 @@ base\allocator - - ui\shaders + + cocostudio\reader\WidgetReader\ArmatureNodeReader @@ -2526,6 +2529,9 @@ cocostudio\json + + cocostudio\TimelineAction + base @@ -2556,8 +2562,11 @@ base\allocator - - ui\shaders + + cocostudio\reader\WidgetReader\ArmatureNodeReader + + + cocostudio\reader\WidgetReader\ArmatureNodeReader @@ -2586,8 +2595,5 @@ 3d - - ui\shaders - \ No newline at end of file diff --git a/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems b/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems index 6b378c1202c7..67f88846951b 100644 --- a/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems +++ b/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems @@ -87,6 +87,7 @@ + @@ -230,6 +231,8 @@ + + @@ -511,6 +514,7 @@ + @@ -633,6 +637,7 @@ + diff --git a/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems.filters b/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems.filters index b159f9c6f5b8..abd28a29b844 100644 --- a/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems.filters +++ b/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems.filters @@ -1258,8 +1258,14 @@ cocostudio\reader\WidgetReader\ProjectNodeReader - - ui\shaders + + base + + + cocostudio\reader\WidgetReader\ArmatureNodeReader + + + cocostudio\reader\WidgetReader\ArmatureNodeReader @@ -2333,8 +2339,11 @@ cocostudio\reader\WidgetReader\ProjectNodeReader - - ui\shaders + + base + + + cocostudio\reader\WidgetReader\ArmatureNodeReader @@ -2566,8 +2575,8 @@ {a6638f35-5c81-4835-9897-0f9efb0be02b} - - {6fc0eff9-aaac-4be0-9d66-2730b072cb21} + + {1151b6b3-739f-4cff-add0-6b772fa7d226} @@ -2680,8 +2689,5 @@ 2d - - ui\shaders - \ No newline at end of file diff --git a/cocos/2d/libcocos2d_wp8.vcxproj b/cocos/2d/libcocos2d_wp8.vcxproj index 9eaf08b78c37..746ca21c297b 100644 --- a/cocos/2d/libcocos2d_wp8.vcxproj +++ b/cocos/2d/libcocos2d_wp8.vcxproj @@ -239,6 +239,7 @@ + @@ -376,6 +377,8 @@ + + @@ -713,6 +716,7 @@ + @@ -852,6 +856,7 @@ + diff --git a/cocos/2d/libcocos2d_wp8.vcxproj.filters b/cocos/2d/libcocos2d_wp8.vcxproj.filters index b13cc1f9dc56..4222bbc3d3c0 100644 --- a/cocos/2d/libcocos2d_wp8.vcxproj.filters +++ b/cocos/2d/libcocos2d_wp8.vcxproj.filters @@ -242,8 +242,8 @@ {02d389d5-8f57-4bd6-b12a-95af86c5b356} - - {0d094a09-b8c2-4fc8-a817-5840cf3ca542} + + {939d9d3e-06b3-494e-affd-070c2c1cbe1d} @@ -1311,8 +1311,11 @@ cocostudio\reader\WidgetReader\GameMapReader - - ui\shaders + + base + + + cocostudio\reader\WidgetReader\ArmatureNodeReader @@ -2544,8 +2547,14 @@ cocostudio\reader\WidgetReader\GameMapReader - - ui\shaders + + base + + + cocostudio\reader\WidgetReader\ArmatureNodeReader + + + cocostudio\reader\WidgetReader\ArmatureNodeReader @@ -2636,8 +2645,5 @@ renderer\shaders - - ui\shaders - \ No newline at end of file diff --git a/cocos/3d/CCBundle3D.cpp b/cocos/3d/CCBundle3D.cpp index 252bc962ec20..bde5b47a926e 100644 --- a/cocos/3d/CCBundle3D.cpp +++ b/cocos/3d/CCBundle3D.cpp @@ -271,7 +271,7 @@ bool Bundle3D::loadObj(MeshDatas& meshdatas, MaterialDatas& materialdatas, NodeD for (const auto& it : shapes.shapes) { NTextureData tex; - tex.filename = dir + it.material.diffuse_texname; + tex.filename = it.material.diffuse_texname.empty() ? it.material.diffuse_texname : dir + it.material.diffuse_texname; tex.type = NTextureData::Usage::Diffuse; tex.wrapS = GL_CLAMP_TO_EDGE; tex.wrapT = GL_CLAMP_TO_EDGE; @@ -846,7 +846,7 @@ bool Bundle3D::loadMaterialsBinary(MaterialDatas& materialdatas) return false; } - textureData.filename = _modelPath + texturePath; + textureData.filename = texturePath.empty() ? texturePath : _modelPath + texturePath; float uvdata[4]; _binaryReader.read(&uvdata,sizeof(float), 4); textureData.type = parseGLTextureType(_binaryReader.readString()); @@ -873,7 +873,7 @@ bool Bundle3D::loadMaterialsBinary_0_1(MaterialDatas& materialdatas) } NTextureData textureData; - textureData.filename = _modelPath + texturePath; + textureData.filename = texturePath.empty() ? texturePath : _modelPath + texturePath; textureData.type= NTextureData::Usage::Diffuse; textureData.id=""; materialData.textures.push_back(textureData); @@ -901,7 +901,7 @@ bool Bundle3D::loadMaterialsBinary_0_2(MaterialDatas& materialdatas) } NTextureData textureData; - textureData.filename = _modelPath + texturePath; + textureData.filename = texturePath.empty() ? texturePath : _modelPath + texturePath; textureData.type= NTextureData::Usage::Diffuse; textureData.id=""; materialData.textures.push_back(textureData); @@ -927,7 +927,7 @@ bool Bundle3D::loadMaterialsJson(MaterialDatas& materialdatas) NTextureData textureData; const rapidjson::Value& texture_val = testure_array[j]; std::string filename = texture_val[FILENAME].GetString(); - textureData.filename = _modelPath + filename; + textureData.filename = filename.empty() ? filename : _modelPath + filename; textureData.type = parseGLTextureType(texture_val["type"].GetString()); textureData.wrapS = parseGLType(texture_val["wrapModeU"].GetString()); textureData.wrapT = parseGLType(texture_val["wrapModeV"].GetString()); @@ -1292,7 +1292,8 @@ bool Bundle3D::loadMaterialDataJson_0_1(MaterialDatas& materialdatas) const rapidjson::Value& material_data_base_array_0 = material_data_base_array[(rapidjson::SizeType)0]; NTextureData textureData; // set texture - textureData.filename =_modelPath + material_data_base_array_0[FILENAME].GetString(); + std::string filename = material_data_base_array_0[FILENAME].GetString(); + textureData.filename = filename.empty() ? filename : _modelPath + filename; textureData.type= NTextureData::Usage::Diffuse; textureData.id=""; materialData.textures.push_back(textureData); @@ -1316,7 +1317,8 @@ bool Bundle3D::loadMaterialDataJson_0_2(MaterialDatas& materialdatas) const rapidjson::Value& material_val = material_array[i]; // set texture - textureData.filename = _modelPath + material_val[TEXTURES].GetString(); + std::string filename = material_val[TEXTURES].GetString(); + textureData.filename = filename.empty() ? filename : _modelPath + filename; textureData.type= NTextureData::Usage::Diffuse; textureData.id=""; materialData.textures.push_back(textureData); diff --git a/cocos/3d/CCSprite3D.cpp b/cocos/3d/CCSprite3D.cpp index 168cb5a80de0..165d03c078b3 100644 --- a/cocos/3d/CCSprite3D.cpp +++ b/cocos/3d/CCSprite3D.cpp @@ -317,7 +317,8 @@ Sprite3D* Sprite3D::createSprite3DNode(NodeData* nodedata,ModelData* modeldata,c if (modeldata->matrialId == "" && matrialdatas.materials.size()) { const NTextureData* textureData = matrialdatas.materials[0].getTextureData(NTextureData::Usage::Diffuse); - mesh->setTexture(textureData->filename); + if (!textureData->filename.empty()) + mesh->setTexture(textureData->filename); } else { @@ -325,7 +326,7 @@ Sprite3D* Sprite3D::createSprite3DNode(NodeData* nodedata,ModelData* modeldata,c if(materialData) { const NTextureData* textureData = materialData->getTextureData(NTextureData::Usage::Diffuse); - if(textureData) + if(textureData && !textureData->filename.empty()) { auto tex = Director::getInstance()->getTextureCache()->addImage(textureData->filename); if(tex) @@ -460,7 +461,7 @@ void Sprite3D::createNode(NodeData* nodedata, Node* root, const MaterialDatas& m if(materialData) { const NTextureData* textureData = materialData->getTextureData(NTextureData::Usage::Diffuse); - if(textureData) + if(textureData && !textureData->filename.empty()) { auto tex = Director::getInstance()->getTextureCache()->addImage(textureData->filename); if(tex) diff --git a/cocos/base/CCDirector.cpp b/cocos/base/CCDirector.cpp index 4d5d7a931722..87feec6c8226 100644 --- a/cocos/base/CCDirector.cpp +++ b/cocos/base/CCDirector.cpp @@ -157,6 +157,12 @@ bool Director::init(void) _renderer = new (std::nothrow) Renderer; _console = new (std::nothrow) Console; + + // default clear color + _clearColor.r = 0; + _clearColor.g = 0; + _clearColor.b = 0; + _clearColor.a = 1.0; return true; } @@ -242,7 +248,7 @@ void Director::setGLDefaultValues() setProjection(_projection); // set other opengl default values - glClearColor(0.0f, 0.0f, 0.0f, 1.0f); + glClearColor(_clearColor.r, _clearColor.g, _clearColor.b, _clearColor.a); } // Draw the Scene @@ -705,6 +711,12 @@ void Director::setDepthTest(bool on) CHECK_GL_ERROR_DEBUG(); } +void Director::setClearColor(const Color4F& clearColor) +{ + _clearColor = clearColor; + glClearColor(clearColor.r, clearColor.g, clearColor.b, clearColor.a); +} + static void GLToClipTransform(Mat4 *transformOut) { if(nullptr == transformOut) return; @@ -1114,7 +1126,7 @@ void Director::showStats() prevVerts = currentVerts; } - Mat4 identity = Mat4::IDENTITY; + const Mat4& identity = Mat4::IDENTITY; _drawnVerticesLabel->visit(_renderer, identity, 0); _drawnBatchesLabel->visit(_renderer, identity, 0); _FPSLabel->visit(_renderer, identity, 0); diff --git a/cocos/base/CCDirector.h b/cocos/base/CCDirector.h index 5283d87db00d..644722629d32 100644 --- a/cocos/base/CCDirector.h +++ b/cocos/base/CCDirector.h @@ -322,6 +322,9 @@ class CC_DLL Director : public Ref /** enables/disables OpenGL alpha blending */ void setAlphaBlending(bool on); + + /** set clear values for the color buffers, value range of each element is [0.0, 1.0] */ + void setClearColor(const Color4F& clearColor); /** enables/disables OpenGL depth test */ void setDepthTest(bool on); @@ -463,6 +466,9 @@ class CC_DLL Director : public Ref unsigned int _totalFrames; float _secondsPerFrame; + /* clear color set outside be used in setGLDefaultValues() */ + Color4F _clearColor; + /* The running scene */ Scene *_runningScene; diff --git a/cocos/base/allocator/CCAllocatorMutex.h b/cocos/base/allocator/CCAllocatorMutex.h index 6f419e1178d1..d2104cdbe859 100644 --- a/cocos/base/allocator/CCAllocatorMutex.h +++ b/cocos/base/allocator/CCAllocatorMutex.h @@ -44,10 +44,17 @@ #elif CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_WP8 || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT #include "windows.h" #define MUTEX HANDLE +#if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 #define MUTEX_INIT(m) \ m = CreateMutex(0, FALSE, 0) #define MUTEX_LOCK(m) \ WaitForSingleObject(m, INFINITE) +#elif CC_TARGET_PLATFORM == CC_PLATFORM_WP8 || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT +#define MUTEX_INIT(m) \ + m = OpenMutex(0, FALSE, 0) +#define MUTEX_LOCK(m) \ + WaitForSingleObjectEx(m, INFINITE, false) +#endif #define MUTEX_UNLOCK(m) \ ReleaseMutex(m) #else diff --git a/cocos/cocos2d.cpp b/cocos/cocos2d.cpp index fab01b53d148..0ebb62b653b1 100644 --- a/cocos/cocos2d.cpp +++ b/cocos/cocos2d.cpp @@ -31,7 +31,7 @@ NS_CC_BEGIN CC_DLL const char* cocos2dVersion() { - return "cocos2d-x 3.3"; + return "cocos2d-x 3.4beta0"; } NS_CC_END diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineNode.cpp b/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineNode.cpp new file mode 100644 index 000000000000..a1e423ee8a89 --- /dev/null +++ b/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineNode.cpp @@ -0,0 +1,91 @@ +/**************************************************************************** + Copyright (c) 2013 cocos2d-x.org + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#include "CCActionTimelineNode.h" +#include "CSLoader.h" + +USING_NS_CC; + +NS_TIMELINE_BEGIN + +ActionTimelineNode* ActionTimelineNode::create(Node* root, ActionTimeline* action) +{ + ActionTimelineNode* object = new (std::nothrow) ActionTimelineNode(); + if (object && object->init(root, action)) + { + object->autorelease(); + return object; + } + CC_SAFE_DELETE(object); + return nullptr; +} + +ActionTimelineNode::ActionTimelineNode() +: _root(nullptr) +, _action(nullptr) +{ +} + +ActionTimelineNode::~ActionTimelineNode() +{ +} + +bool ActionTimelineNode::init() +{ + return Node::init(); +} + +bool ActionTimelineNode::init(Node* root, ActionTimeline* action) +{ + _root = root; + _action = action; + + if(_root) + { + _root->removeFromParent(); + addChild(_root); + } + + return true; +} + +void ActionTimelineNode::setRoot(cocos2d::Node* root) +{ + _root = root; +} +cocos2d::Node* ActionTimelineNode::getRoot() +{ + return _root; +} + +void ActionTimelineNode::setActionTimeline(ActionTimeline* action) +{ + _action = action; +} +ActionTimeline* ActionTimelineNode::getActionTimeline() +{ + return _action; +} + +NS_TIMELINE_END diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineNode.h b/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineNode.h new file mode 100644 index 000000000000..c8c5b6023abd --- /dev/null +++ b/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineNode.h @@ -0,0 +1,61 @@ +/**************************************************************************** + Copyright (c) 2013 cocos2d-x.org + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#ifndef __COCOSSTUDIO_CCACTIONTIMELINENODE_H__ +#define __COCOSSTUDIO_CCACTIONTIMELINENODE_H__ + +#include "CCActionTimeline.h" +#include "CCTimelineMacro.h" +#include "cocostudio/CocosStudioExport.h" + +NS_TIMELINE_BEGIN + +class ActionTimeline; + +class CC_STUDIO_DLL ActionTimelineNode : public cocos2d::Node +{ +public: + static ActionTimelineNode* create(cocos2d::Node* root, ActionTimeline* action); + + ActionTimelineNode(); + ~ActionTimelineNode(); + + bool init() override; + bool init(cocos2d::Node* root, ActionTimeline* action); + + virtual void setRoot(cocos2d::Node* root); + virtual cocos2d::Node* getRoot(); + + virtual void setActionTimeline(ActionTimeline* action); + virtual ActionTimeline* getActionTimeline(); + +protected: + cocos2d::Node* _root; + ActionTimeline* _action; +}; + +NS_TIMELINE_END + + +#endif /*__COCOSSTUDIO_CCACTIONTIMELINENODE_H__*/ diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp b/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp index 0c62cdb5de8f..04164ab28bad 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp +++ b/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp @@ -29,6 +29,7 @@ #include "../../cocos/ui/CocosGUI.h" #include "CCActionTimelineCache.h" #include "CCActionTimeline.h" +#include "CCActionTimelineNode.h" #include "../CCSGUIReader.h" #include "cocostudio/CocoStudio.h" #include "cocostudio/CSParseBinary_generated.h" @@ -57,6 +58,7 @@ #include "cocostudio/WidgetReader/ScrollViewReader/ScrollViewReader.h" #include "cocostudio/WidgetReader/PageViewReader/PageViewReader.h" #include "cocostudio/WidgetReader/ListViewReader/ListViewReader.h" +#include "cocostudio/WidgetReader/ArmatureNodeReader/ArmatureNodeReader.h" #include "flatbuffers/flatbuffers.h" #include "flatbuffers/util.h" @@ -200,6 +202,8 @@ CSLoader::CSLoader() CREATE_CLASS_NODE_READER_INFO(PageViewReader); CREATE_CLASS_NODE_READER_INFO(ListViewReader); + CREATE_CLASS_NODE_READER_INFO(ArmatureNodeReader); + } void CSLoader::purge() @@ -280,6 +284,32 @@ ActionTimeline* CSLoader::createTimeline(const std::string &filename) return nullptr; } +ActionTimelineNode* CSLoader::createActionTimelineNode(const std::string& filename) +{ + Node* root = createNode(filename); + ActionTimeline* action = createTimeline(filename); + + if(root && action) + { + root->runAction(action); + action->gotoFrameAndPlay(0); + } + + ActionTimelineNode* node = ActionTimelineNode::create(root, action); + return node; +} +ActionTimelineNode* CSLoader::createActionTimelineNode(const std::string& filename, int startIndex, int endIndex, bool loop) +{ + ActionTimelineNode* node = createActionTimelineNode(filename); + ActionTimeline* action = node->getActionTimeline(); + if(action) + action->gotoFrameAndPlay(startIndex, endIndex, loop); + + return node; +} + + + Node* CSLoader::createNodeFromJson(const std::string& filename) { if (_recordJsonPath) @@ -762,6 +792,9 @@ Node* CSLoader::nodeWithFlatBuffersFile(const std::string &fileName) SpriteFrameCache::getInstance()->addSpriteFramesWithFile(textures->Get(i)->c_str()); } + auto v = csparsebinary->version(); + if (v) _csdVersion = v->c_str(); + Node* node = nodeWithFlatBuffers(csparsebinary->nodeTree()); return node; @@ -784,15 +817,29 @@ Node* CSLoader::nodeWithFlatBuffers(const flatbuffers::NodeTree *nodetree) CCLOG("filePath = %s", filePath.c_str()); if (filePath != "" && FileUtils::getInstance()->isFileExist(filePath)) { - node = createNodeWithFlatBuffersFile(filePath); - reader->setPropsWithFlatBuffers(node, options->data()); - + + Node* root = createNodeWithFlatBuffersFile(filePath); + reader->setPropsWithFlatBuffers(root, options->data()); + + bool isloop = projectNodeOptions->isLoop(); + bool isautoplay = projectNodeOptions->isAutoPlay(); + cocostudio::timeline::ActionTimeline* action = cocostudio::timeline::ActionTimelineCache::getInstance()->createActionWithFlatBuffersFile(filePath); - if(action) + if (action) { - node->runAction(action); - action->gotoFrameAndPlay(0); + root->runAction(action); + if (isautoplay) + { + action->gotoFrameAndPlay(0, isloop); + } + else + { + action->gotoFrameAndPause(0); + } } + + node = ActionTimelineNode::create(root, action); + node->setName(root->getName()); } } else if (classname == "SimpleAudio") @@ -1089,6 +1136,10 @@ Node* CSLoader::createNodeWithFlatBuffersForSimulator(const std::string& filenam } auto nodeTree = csparsebinary->nodeTree(); + + auto v = csparsebinary->version(); + if (v) _csdVersion = v->c_str(); + Node* node = nodeWithFlatBuffersForSimulator(nodeTree); _rootNode = nullptr; @@ -1118,12 +1169,22 @@ Node* CSLoader::nodeWithFlatBuffersForSimulator(const flatbuffers::NodeTree *nod { node = createNodeWithFlatBuffersForSimulator(filePath); reader->setPropsWithFlatBuffers(node, options->data()); - - cocostudio::timeline::ActionTimeline* action = cocostudio::timeline::ActionTimelineCache::getInstance()->createActionWithFlatBuffersForSimulator(filePath); + + bool isloop = projectNodeOptions->isLoop(); + bool isautoplay = projectNodeOptions->isAutoPlay(); + cocostudio::timeline::ActionTimeline* action = cocostudio::timeline::ActionTimelineCache::getInstance()->createActionWithFlatBuffersFile(filePath); if (action) { node->runAction(action); action->gotoFrameAndPlay(0); + if (isautoplay) + { + action->gotoFrameAndPlay(0, isloop); + } + else + { + action->gotoFrameAndPause(0); + } } } } @@ -1201,6 +1262,7 @@ Node* CSLoader::nodeWithFlatBuffersForSimulator(const flatbuffers::NodeTree *nod node->addChild(child); } } + Helper::doLayout(node); } // _loadingNodeParentHierarchy.pop_back(); diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.h b/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.h index d80d792ef53c..93b2e16d7acb 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.h +++ b/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.h @@ -57,6 +57,7 @@ namespace cocostudio namespace timeline { class ActionTimeline; + class ActionTimelineNode; } } @@ -75,6 +76,9 @@ class CC_STUDIO_DLL CSLoader static cocos2d::Node* createNode(const std::string& filename); static cocostudio::timeline::ActionTimeline* createTimeline(const std::string& filename); + + static cocostudio::timeline::ActionTimelineNode* createActionTimelineNode(const std::string& filename); + static cocostudio::timeline::ActionTimelineNode* createActionTimelineNode(const std::string& filename, int startIndex, int endIndex, bool loop); cocos2d::Node* createNodeFromJson(const std::string& filename); cocos2d::Node* loadNodeWithFile(const std::string& fileName); @@ -100,7 +104,8 @@ class CC_STUDIO_DLL CSLoader cocos2d::Node* createNodeWithFlatBuffersForSimulator(const std::string& filename); cocos2d::Node* nodeWithFlatBuffersForSimulator(const flatbuffers::NodeTree* nodetree); - + std::string getCsdVersion() { return _csdVersion; } + protected: cocos2d::Node* loadNode(const rapidjson::Value& json); @@ -147,6 +152,7 @@ class CC_STUDIO_DLL CSLoader Node* _rootNode; // std::vector _loadingNodeParentHierarchy; + std::string _csdVersion; }; NS_CC_END diff --git a/cocos/editor-support/cocostudio/Android.mk b/cocos/editor-support/cocostudio/Android.mk index 76c658543af4..72b3c914e328 100644 --- a/cocos/editor-support/cocostudio/Android.mk +++ b/cocos/editor-support/cocostudio/Android.mk @@ -66,10 +66,11 @@ ActionTimeline/CCActionTimelineCache.cpp \ ActionTimeline/CCFrame.cpp \ ActionTimeline/CCTimeLine.cpp \ ActionTimeline/CCActionTimeline.cpp \ +ActionTimeline/CCActionTimelineNode.cpp \ ActionTimeline/CSLoader.cpp \ FlatBuffersSerialize.cpp \ -WidgetCallBackHandlerProtocol.cpp - +WidgetCallBackHandlerProtocol.cpp \ +WidgetReader/ArmatureNodeReader/ArmatureNodeReader.cpp LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/.. diff --git a/cocos/editor-support/cocostudio/CMakeLists.txt b/cocos/editor-support/cocostudio/CMakeLists.txt index 0e7fe8710a78..238b094634f0 100644 --- a/cocos/editor-support/cocostudio/CMakeLists.txt +++ b/cocos/editor-support/cocostudio/CMakeLists.txt @@ -65,10 +65,12 @@ set(COCOS_CS_SRC editor-support/cocostudio/WidgetReader/ScrollViewReader/ScrollViewReader.cpp editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.cpp editor-support/cocostudio/ActionTimeline/CCActionTimeline.cpp + editor-support/cocostudio/ActionTimeline/CCActionTimelineNode.cpp editor-support/cocostudio/ActionTimeline/CCFrame.cpp editor-support/cocostudio/ActionTimeline/CCTimeLine.cpp editor-support/cocostudio/ActionTimeline/CSLoader.cpp editor-support/cocostudio/FlatBuffersSerialize.cpp + editor-support/cocostudio/WidgetReader/ArmatureNodeReader/ArmatureNodeReader.cpp ) include_directories( editor-support ) diff --git a/cocos/editor-support/cocostudio/CSParseBinary_generated.h b/cocos/editor-support/cocostudio/CSParseBinary_generated.h index d4360f64a084..d4ebff737155 100644 --- a/cocos/editor-support/cocostudio/CSParseBinary_generated.h +++ b/cocos/editor-support/cocostudio/CSParseBinary_generated.h @@ -12,6 +12,7 @@ struct CSParseBinary; struct NodeTree; struct Options; struct WidgetOptions; +struct LayoutComponentTable; struct SingleNodeOptions; struct SpriteOptions; struct ParticleSystemOptions; @@ -176,6 +177,7 @@ struct CSParseBinary : private flatbuffers::Table { const flatbuffers::Vector> *texturePngs() const { return GetPointer> *>(6); } const NodeTree *nodeTree() const { return GetPointer(8); } const NodeAction *action() const { return GetPointer(10); } + const flatbuffers::String *version() const { return GetPointer(12); } bool Verify(flatbuffers::Verifier &verifier) const { return VerifyTableStart(verifier) && VerifyField(verifier, 4 /* textures */) && @@ -188,6 +190,8 @@ struct CSParseBinary : private flatbuffers::Table { verifier.VerifyTable(nodeTree()) && VerifyField(verifier, 10 /* action */) && verifier.VerifyTable(action()) && + VerifyField(verifier, 12 /* version */) && + verifier.Verify(version()) && verifier.EndTable(); } }; @@ -199,10 +203,11 @@ struct CSParseBinaryBuilder { void add_texturePngs(flatbuffers::Offset>> texturePngs) { fbb_.AddOffset(6, texturePngs); } void add_nodeTree(flatbuffers::Offset nodeTree) { fbb_.AddOffset(8, nodeTree); } void add_action(flatbuffers::Offset action) { fbb_.AddOffset(10, action); } + void add_version(flatbuffers::Offset version) { fbb_.AddOffset(12, version); } CSParseBinaryBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } CSParseBinaryBuilder &operator=(const CSParseBinaryBuilder &); flatbuffers::Offset Finish() { - auto o = flatbuffers::Offset(fbb_.EndTable(start_, 4)); + auto o = flatbuffers::Offset(fbb_.EndTable(start_, 5)); return o; } }; @@ -211,8 +216,10 @@ inline flatbuffers::Offset CreateCSParseBinary(flatbuffers::FlatB flatbuffers::Offset>> textures = 0, flatbuffers::Offset>> texturePngs = 0, flatbuffers::Offset nodeTree = 0, - flatbuffers::Offset action = 0) { + flatbuffers::Offset action = 0, + flatbuffers::Offset version = 0) { CSParseBinaryBuilder builder_(_fbb); + builder_.add_version(version); builder_.add_action(action); builder_.add_nodeTree(nodeTree); builder_.add_texturePngs(texturePngs); @@ -318,6 +325,7 @@ struct WidgetOptions : private flatbuffers::Table { const flatbuffers::String *customProperty() const { return GetPointer(38); } const flatbuffers::String *callBackType() const { return GetPointer(40); } const flatbuffers::String *callBackName() const { return GetPointer(42); } + const LayoutComponentTable *layoutComponent() const { return GetPointer(44); } bool Verify(flatbuffers::Verifier &verifier) const { return VerifyTableStart(verifier) && VerifyField(verifier, 4 /* name */) && @@ -345,6 +353,8 @@ struct WidgetOptions : private flatbuffers::Table { verifier.Verify(callBackType()) && VerifyField(verifier, 42 /* callBackName */) && verifier.Verify(callBackName()) && + VerifyField(verifier, 44 /* layoutComponent */) && + verifier.VerifyTable(layoutComponent()) && verifier.EndTable(); } }; @@ -372,10 +382,11 @@ struct WidgetOptionsBuilder { void add_customProperty(flatbuffers::Offset customProperty) { fbb_.AddOffset(38, customProperty); } void add_callBackType(flatbuffers::Offset callBackType) { fbb_.AddOffset(40, callBackType); } void add_callBackName(flatbuffers::Offset callBackName) { fbb_.AddOffset(42, callBackName); } + void add_layoutComponent(flatbuffers::Offset layoutComponent) { fbb_.AddOffset(44, layoutComponent); } WidgetOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } WidgetOptionsBuilder &operator=(const WidgetOptionsBuilder &); flatbuffers::Offset Finish() { - auto o = flatbuffers::Offset(fbb_.EndTable(start_, 20)); + auto o = flatbuffers::Offset(fbb_.EndTable(start_, 21)); return o; } }; @@ -400,8 +411,10 @@ inline flatbuffers::Offset CreateWidgetOptions(flatbuffers::FlatB flatbuffers::Offset frameEvent = 0, flatbuffers::Offset customProperty = 0, flatbuffers::Offset callBackType = 0, - flatbuffers::Offset callBackName = 0) { + flatbuffers::Offset callBackName = 0, + flatbuffers::Offset layoutComponent = 0) { WidgetOptionsBuilder builder_(_fbb); + builder_.add_layoutComponent(layoutComponent); builder_.add_callBackName(callBackName); builder_.add_callBackType(callBackType); builder_.add_customProperty(customProperty); @@ -425,6 +438,111 @@ inline flatbuffers::Offset CreateWidgetOptions(flatbuffers::FlatB return builder_.Finish(); } +struct LayoutComponentTable : private flatbuffers::Table { + uint8_t positionXPercentEnabled() const { return GetField(4, 0); } + uint8_t positionYPercentEnabled() const { return GetField(6, 0); } + float positionXPercent() const { return GetField(8, 0); } + float positionYPercent() const { return GetField(10, 0); } + uint8_t sizeXPercentEnable() const { return GetField(12, 0); } + uint8_t sizeYPercentEnable() const { return GetField(14, 0); } + float sizeXPercent() const { return GetField(16, 0); } + float sizeYPercent() const { return GetField(18, 0); } + uint8_t stretchHorizontalEnabled() const { return GetField(20, 0); } + uint8_t stretchVerticalEnabled() const { return GetField(22, 0); } + const flatbuffers::String *horizontalEdge() const { return GetPointer(24); } + const flatbuffers::String *verticalEdge() const { return GetPointer(26); } + float leftMargin() const { return GetField(28, 0); } + float rightMargin() const { return GetField(30, 0); } + float topMargin() const { return GetField(32, 0); } + float bottomMargin() const { return GetField(34, 0); } + bool Verify(flatbuffers::Verifier &verifier) const { + return VerifyTableStart(verifier) && + VerifyField(verifier, 4 /* positionXPercentEnabled */) && + VerifyField(verifier, 6 /* positionYPercentEnabled */) && + VerifyField(verifier, 8 /* positionXPercent */) && + VerifyField(verifier, 10 /* positionYPercent */) && + VerifyField(verifier, 12 /* sizeXPercentEnable */) && + VerifyField(verifier, 14 /* sizeYPercentEnable */) && + VerifyField(verifier, 16 /* sizeXPercent */) && + VerifyField(verifier, 18 /* sizeYPercent */) && + VerifyField(verifier, 20 /* stretchHorizontalEnabled */) && + VerifyField(verifier, 22 /* stretchVerticalEnabled */) && + VerifyField(verifier, 24 /* horizontalEdge */) && + verifier.Verify(horizontalEdge()) && + VerifyField(verifier, 26 /* verticalEdge */) && + verifier.Verify(verticalEdge()) && + VerifyField(verifier, 28 /* leftMargin */) && + VerifyField(verifier, 30 /* rightMargin */) && + VerifyField(verifier, 32 /* topMargin */) && + VerifyField(verifier, 34 /* bottomMargin */) && + verifier.EndTable(); + } +}; + +struct LayoutComponentTableBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_positionXPercentEnabled(uint8_t positionXPercentEnabled) { fbb_.AddElement(4, positionXPercentEnabled, 0); } + void add_positionYPercentEnabled(uint8_t positionYPercentEnabled) { fbb_.AddElement(6, positionYPercentEnabled, 0); } + void add_positionXPercent(float positionXPercent) { fbb_.AddElement(8, positionXPercent, 0); } + void add_positionYPercent(float positionYPercent) { fbb_.AddElement(10, positionYPercent, 0); } + void add_sizeXPercentEnable(uint8_t sizeXPercentEnable) { fbb_.AddElement(12, sizeXPercentEnable, 0); } + void add_sizeYPercentEnable(uint8_t sizeYPercentEnable) { fbb_.AddElement(14, sizeYPercentEnable, 0); } + void add_sizeXPercent(float sizeXPercent) { fbb_.AddElement(16, sizeXPercent, 0); } + void add_sizeYPercent(float sizeYPercent) { fbb_.AddElement(18, sizeYPercent, 0); } + void add_stretchHorizontalEnabled(uint8_t stretchHorizontalEnabled) { fbb_.AddElement(20, stretchHorizontalEnabled, 0); } + void add_stretchVerticalEnabled(uint8_t stretchVerticalEnabled) { fbb_.AddElement(22, stretchVerticalEnabled, 0); } + void add_horizontalEdge(flatbuffers::Offset horizontalEdge) { fbb_.AddOffset(24, horizontalEdge); } + void add_verticalEdge(flatbuffers::Offset verticalEdge) { fbb_.AddOffset(26, verticalEdge); } + void add_leftMargin(float leftMargin) { fbb_.AddElement(28, leftMargin, 0); } + void add_rightMargin(float rightMargin) { fbb_.AddElement(30, rightMargin, 0); } + void add_topMargin(float topMargin) { fbb_.AddElement(32, topMargin, 0); } + void add_bottomMargin(float bottomMargin) { fbb_.AddElement(34, bottomMargin, 0); } + LayoutComponentTableBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } + LayoutComponentTableBuilder &operator=(const LayoutComponentTableBuilder &); + flatbuffers::Offset Finish() { + auto o = flatbuffers::Offset(fbb_.EndTable(start_, 16)); + return o; + } +}; + +inline flatbuffers::Offset CreateLayoutComponentTable(flatbuffers::FlatBufferBuilder &_fbb, + uint8_t positionXPercentEnabled = 0, + uint8_t positionYPercentEnabled = 0, + float positionXPercent = 0, + float positionYPercent = 0, + uint8_t sizeXPercentEnable = 0, + uint8_t sizeYPercentEnable = 0, + float sizeXPercent = 0, + float sizeYPercent = 0, + uint8_t stretchHorizontalEnabled = 0, + uint8_t stretchVerticalEnabled = 0, + flatbuffers::Offset horizontalEdge = 0, + flatbuffers::Offset verticalEdge = 0, + float leftMargin = 0, + float rightMargin = 0, + float topMargin = 0, + float bottomMargin = 0) { + LayoutComponentTableBuilder builder_(_fbb); + builder_.add_bottomMargin(bottomMargin); + builder_.add_topMargin(topMargin); + builder_.add_rightMargin(rightMargin); + builder_.add_leftMargin(leftMargin); + builder_.add_verticalEdge(verticalEdge); + builder_.add_horizontalEdge(horizontalEdge); + builder_.add_sizeYPercent(sizeYPercent); + builder_.add_sizeXPercent(sizeXPercent); + builder_.add_positionYPercent(positionYPercent); + builder_.add_positionXPercent(positionXPercent); + builder_.add_stretchVerticalEnabled(stretchVerticalEnabled); + builder_.add_stretchHorizontalEnabled(stretchHorizontalEnabled); + builder_.add_sizeYPercentEnable(sizeYPercentEnable); + builder_.add_sizeXPercentEnable(sizeXPercentEnable); + builder_.add_positionYPercentEnabled(positionYPercentEnabled); + builder_.add_positionXPercentEnabled(positionXPercentEnabled); + return builder_.Finish(); +} + struct SingleNodeOptions : private flatbuffers::Table { const WidgetOptions *nodeOptions() const { return GetPointer(4); } bool Verify(flatbuffers::Verifier &verifier) const { @@ -1557,12 +1675,16 @@ inline flatbuffers::Offset CreateListViewOptions(flatbuffers::F struct ProjectNodeOptions : private flatbuffers::Table { const WidgetOptions *nodeOptions() const { return GetPointer(4); } const flatbuffers::String *fileName() const { return GetPointer(6); } + uint8_t isLoop() const { return GetField(8, 1); } + uint8_t isAutoPlay() const { return GetField(10, 1); } bool Verify(flatbuffers::Verifier &verifier) const { return VerifyTableStart(verifier) && VerifyField(verifier, 4 /* nodeOptions */) && verifier.VerifyTable(nodeOptions()) && VerifyField(verifier, 6 /* fileName */) && verifier.Verify(fileName()) && + VerifyField(verifier, 8 /* isLoop */) && + VerifyField(verifier, 10 /* isAutoPlay */) && verifier.EndTable(); } }; @@ -1572,20 +1694,26 @@ struct ProjectNodeOptionsBuilder { flatbuffers::uoffset_t start_; void add_nodeOptions(flatbuffers::Offset nodeOptions) { fbb_.AddOffset(4, nodeOptions); } void add_fileName(flatbuffers::Offset fileName) { fbb_.AddOffset(6, fileName); } + void add_isLoop(uint8_t isLoop) { fbb_.AddElement(8, isLoop, 1); } + void add_isAutoPlay(uint8_t isAutoPlay) { fbb_.AddElement(10, isAutoPlay, 1); } ProjectNodeOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } ProjectNodeOptionsBuilder &operator=(const ProjectNodeOptionsBuilder &); flatbuffers::Offset Finish() { - auto o = flatbuffers::Offset(fbb_.EndTable(start_, 2)); + auto o = flatbuffers::Offset(fbb_.EndTable(start_, 4)); return o; } }; inline flatbuffers::Offset CreateProjectNodeOptions(flatbuffers::FlatBufferBuilder &_fbb, flatbuffers::Offset nodeOptions = 0, - flatbuffers::Offset fileName = 0) { + flatbuffers::Offset fileName = 0, + uint8_t isLoop = 1, + uint8_t isAutoPlay = 1) { ProjectNodeOptionsBuilder builder_(_fbb); builder_.add_fileName(fileName); builder_.add_nodeOptions(nodeOptions); + builder_.add_isAutoPlay(isAutoPlay); + builder_.add_isLoop(isLoop); return builder_.Finish(); } diff --git a/cocos/editor-support/cocostudio/CocoStudio.h b/cocos/editor-support/cocostudio/CocoStudio.h index 8a17a193ebad..76df1225961c 100644 --- a/cocos/editor-support/cocostudio/CocoStudio.h +++ b/cocos/editor-support/cocostudio/CocoStudio.h @@ -61,6 +61,7 @@ THE SOFTWARE. #include "cocostudio/ActionTimeline/CCFrame.h" #include "cocostudio/ActionTimeline/CCTimeLine.h" #include "cocostudio/ActionTimeline/CCActionTimeline.h" +#include "cocostudio/ActionTimeline/CCActionTimelineNode.h" #include "cocostudio/CocosStudioExport.h" #include "cocostudio/ActionTimeline/CSLoader.h" diff --git a/cocos/editor-support/cocostudio/FlatBuffersSerialize.cpp b/cocos/editor-support/cocostudio/FlatBuffersSerialize.cpp index d3c135a83139..8397e5668c3e 100644 --- a/cocos/editor-support/cocostudio/FlatBuffersSerialize.cpp +++ b/cocos/editor-support/cocostudio/FlatBuffersSerialize.cpp @@ -167,7 +167,15 @@ std::string FlatBuffersSerialize::serializeFlatBuffersWithXMLFile(const std::str while (element) { // CCLOG("entity name = %s", element->Name()); - + if (strcmp("PropertyGroup", element->Name()) == 0) + { + const tinyxml2::XMLAttribute* attribute = element->FirstAttribute(); + while (attribute && strcmp("Version", attribute->Name()) != 0) + attribute = attribute->Next(); + if (attribute) + _csdVersion = attribute->Value(); + } + if (strcmp("Content", element->Name()) == 0) { const tinyxml2::XMLAttribute* attribute = element->FirstAttribute(); @@ -248,10 +256,11 @@ std::string FlatBuffersSerialize::serializeFlatBuffersWithXMLFile(const std::str auto csparsebinary = CreateCSParseBinary(*_builder, _builder->CreateVector(_textures), - _builder->CreateVector(_texturePngs), + _builder->CreateVector(_texturePngs), nodeTree, - aciton); - _builder->Finish(csparsebinary); + aciton, + _builder->CreateString(_csdVersion)); + _builder->Finish(csparsebinary); _textures.clear(); _texturePngs.clear(); @@ -988,7 +997,15 @@ FlatBufferBuilder* FlatBuffersSerialize::createFlatBuffersWithXMLFileForSimulato while (element) { // CCLOG("entity name = %s", element->Name()); - + if (strcmp("PropertyGroup", element->Name()) == 0) + { + const tinyxml2::XMLAttribute* attribute = element->FirstAttribute(); + while (attribute && strcmp("Version", attribute->Name()) != 0) + attribute = attribute->Next(); + if (attribute) + _csdVersion = attribute->Value(); + } + if (strcmp("Content", element->Name()) == 0) { const tinyxml2::XMLAttribute* attribute = element->FirstAttribute(); @@ -1046,10 +1063,11 @@ FlatBufferBuilder* FlatBuffersSerialize::createFlatBuffersWithXMLFileForSimulato } auto csparsebinary = CreateCSParseBinary(*_builder, - _builder->CreateVector(_textures), - _builder->CreateVector(_texturePngs), + _builder->CreateVector(_textures), + _builder->CreateVector(_texturePngs), nodeTree, - aciton); + aciton, + _builder->CreateString(_csdVersion)); _builder->Finish(csparsebinary); _textures.clear(); @@ -1169,9 +1187,29 @@ Offset FlatBuffersSerialize::createProjectNodeOptionsForSimu { auto temp = NodeReader::getInstance()->createOptionsWithFlatBuffers(objectData, _builder); auto nodeOptions = *(Offset*)(&temp); - + std::string filename = ""; - + + + bool isloop = true; + bool isAutoPlay = true; + const tinyxml2::XMLAttribute* attribute = objectData->FirstAttribute(); + while (attribute) + { + std::string attriname = attribute->Name(); + std::string value = attribute->Value(); + if (attriname == "IsLoop") + { + isloop = (value == "True") ? true : false; + + } + else if (attriname == "IsAutoPlay") + { + isAutoPlay = (value == "True") ? true : false; + } + attribute = attribute->Next(); + } + // FileData const tinyxml2::XMLElement* child = objectData->FirstChildElement(); while (child) @@ -1201,7 +1239,9 @@ Offset FlatBuffersSerialize::createProjectNodeOptionsForSimu return CreateProjectNodeOptions(*_builder, nodeOptions, - _builder->CreateString(filename)); + _builder->CreateString(filename), + isloop, + isAutoPlay); } } diff --git a/cocos/editor-support/cocostudio/FlatBuffersSerialize.h b/cocos/editor-support/cocostudio/FlatBuffersSerialize.h index f514a8f38f81..bdaea811eafe 100644 --- a/cocos/editor-support/cocostudio/FlatBuffersSerialize.h +++ b/cocos/editor-support/cocostudio/FlatBuffersSerialize.h @@ -128,6 +128,7 @@ class CC_STUDIO_DLL FlatBuffersSerialize std::string classType); flatbuffers::Offset createProjectNodeOptionsForSimulator(const tinyxml2::XMLElement* objectData); /**/ + std::string getCsdVersion() { return _csdVersion; } public: std::vector> _textures; @@ -137,7 +138,7 @@ class CC_STUDIO_DLL FlatBuffersSerialize private: flatbuffers::FlatBufferBuilder* _builder; flatbuffers::Offset* _csparsebinary; - + std::string _csdVersion; }; } diff --git a/cocos/editor-support/cocostudio/WidgetReader/ArmatureNodeReader/ArmatureNodeReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/ArmatureNodeReader/ArmatureNodeReader.cpp new file mode 100644 index 000000000000..2494264820d3 --- /dev/null +++ b/cocos/editor-support/cocostudio/WidgetReader/ArmatureNodeReader/ArmatureNodeReader.cpp @@ -0,0 +1,160 @@ +#include "tinyxml2/tinyxml2.h" +#include "flatbuffers/flatbuffers.h" +#include "cocostudio/WidgetReader/NodeReader/NodeReader.h" +#include "cocostudio/CSParseBinary_generated.h" +#include "CSArmatureNode_generated.h" +#include "cocostudio/WidgetReader/ArmatureNodeReader/ArmatureNodeReader.h" +#include "cocostudio/CCArmature.h" + + +USING_NS_CC; +using namespace cocostudio; +using namespace flatbuffers; + +IMPLEMENT_CLASS_NODE_READER_INFO(ArmatureNodeReader) + +ArmatureNodeReader::ArmatureNodeReader() +{ + +} + +ArmatureNodeReader::~ArmatureNodeReader() +{ + +} + +static ArmatureNodeReader* _instanceArmatureNodeReader = nullptr; + +ArmatureNodeReader* ArmatureNodeReader::getInstance() +{ + if (_instanceArmatureNodeReader == nullptr) + { + _instanceArmatureNodeReader = new (std::nothrow) ArmatureNodeReader(); + } + return _instanceArmatureNodeReader; +} + +Offset ArmatureNodeReader::createOptionsWithFlatBuffers(const tinyxml2::XMLElement *objectData, + flatbuffers::FlatBufferBuilder *builder) +{ + + auto temp = NodeReader::getInstance()->createOptionsWithFlatBuffers(objectData, builder); + auto nodeOptions = *(Offset*)(&temp); + + bool isloop = false; + bool isAutoPlay = false; + std::string currentAnimationName = ""; + + int type = 0; + std::string path = ""; + + const tinyxml2::XMLAttribute* attribute = objectData->FirstAttribute(); + while (attribute) + { + std::string attriname = attribute->Name(); + std::string value = attribute->Value(); + + if (attriname == "IsLoop") + { + isloop = (value == "True") ? true : false; + } + else if (attriname == "IsAutoPlay") + { + isAutoPlay = (value == "True") ? true : false; + } + else if (attriname == "CurrentAnimationName") + { + currentAnimationName = value; + } + + attribute = attribute->Next(); + } + + const tinyxml2::XMLElement* child = objectData->FirstChildElement(); + while (child) + { + std::string attriname = child->Name(); + if (attriname == "FileData") + { + attribute = child->FirstAttribute(); + + while (attribute) + { + attriname = attribute->Name(); + std::string value = attribute->Value(); + + if (attriname == "Type") + { + type = 0; + } + else if (attriname == "Path") + { + path = value; + } + + attribute = attribute->Next(); + } + } + + child = child->NextSiblingElement(); + } + + auto options = CreateCSArmatureNodeOption(*builder, + nodeOptions, + CreateResourceItemData(*builder, + type, + builder->CreateString(path)), + isloop, + isAutoPlay, + builder->CreateString(currentAnimationName)); + + return *(Offset
*)(&options); +} + +void ArmatureNodeReader::setPropsWithFlatBuffers(cocos2d::Node *node, + const flatbuffers::Table *nodeOptions) +{ + + auto* custom = static_cast(node); + auto options = (flatbuffers::CSArmatureNodeOption*)nodeOptions; + auto reader = ArmatureNodeReader::getInstance(); + + std::string filepath(options->fileData()->path()->c_str()); + ArmatureDataManager::getInstance()->addArmatureFileInfo(FileUtils::getInstance()->fullPathForFilename(filepath)); + custom->init(getArmatureName(filepath)); + if (options->isAutoPlay()) + custom->getAnimation()->play(options->currentAnimationName()->c_str(), -1, options->isLoop()); + else + custom->getAnimation()->setIsPlaying(false); +} + +cocos2d::Node* ArmatureNodeReader::createNodeWithFlatBuffers(const flatbuffers::Table *nodeOptions) +{ + auto node = CCArmature::create(); + + // self + auto options = (flatbuffers::CSArmatureNodeOption*)nodeOptions; + setPropsWithFlatBuffers(node, (Table*)options); + + // super node + auto NodeReader = NodeReader::getInstance(); + NodeReader->setPropsWithFlatBuffers(node, (Table*)options->nodeOptions()); + + return node; +} + + + +std::string ArmatureNodeReader::getArmatureName(const std::string& exporJsonPath) +{ + //FileUtils.getFileData(exporJsonPath, "r", size) // need read armature name in exportJsonPath + int end = exporJsonPath.find_last_of("."); + int start = exporJsonPath.find_last_of("\\") + 1; + int start1 = exporJsonPath.find_last_of("/") + 1; + if (start < start1) + start = start1; + + if (start == -1) + start = 0; + return exporJsonPath.substr(start, end - start); +} \ No newline at end of file diff --git a/cocos/editor-support/cocostudio/WidgetReader/ArmatureNodeReader/ArmatureNodeReader.h b/cocos/editor-support/cocostudio/WidgetReader/ArmatureNodeReader/ArmatureNodeReader.h new file mode 100644 index 000000000000..941680c4f58e --- /dev/null +++ b/cocos/editor-support/cocostudio/WidgetReader/ArmatureNodeReader/ArmatureNodeReader.h @@ -0,0 +1,65 @@ +/**************************************************************************** +Copyright (c) 2014 cocos2d-x.org + +http://www.cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ + +#ifndef __ARMATURENODEREADER_H_ +#define __ARMATURENODEREADER_H_ + +#include "cocos2d.h" +#include "cocostudio/FlatBuffersSerialize.h" +#include "cocostudio/WidgetReader/NodeReaderProtocol.h" +#include "cocostudio/WidgetReader/NodeReaderDefine.h" + + +/**************************************** +* reader of CSArmatureNode +* @param register reader before use it: +CSLoader* instance = CSLoader::getInstance(); +instance->registReaderObject("ArmatureNodeReader", (ObjectFactory::Instance)CustomSpriteReader::getInstance); +*@param Reader's name must be CLASSNAME#Reader, CLASSNAME is the dataobject's prefix: CLASSNAME#ObjectData +* +* +*****************************************/ +class ArmatureNodeReader : public cocos2d::Ref, public cocostudio::NodeReaderProtocol +{ + DECLARE_CLASS_NODE_READER_INFO + +public: + + ArmatureNodeReader(); + ~ArmatureNodeReader(); + + static ArmatureNodeReader* getInstance(); + static void purge(); + + flatbuffers::Offset createOptionsWithFlatBuffers(const tinyxml2::XMLElement* objectData, + flatbuffers::FlatBufferBuilder* builder); + void setPropsWithFlatBuffers(cocos2d::Node* node, const flatbuffers::Table* textBMFontOptions); + + //CSArmatureNode + cocos2d::Node* createNodeWithFlatBuffers(const flatbuffers::Table* nodeOptions) override; +private: + std::string getArmatureName(const std::string& exporJsonPath); +}; + +#endif /* defined(__ARMATURENODEREADER_H_) */ diff --git a/cocos/editor-support/cocostudio/WidgetReader/ArmatureNodeReader/CSArmatureNode_generated.h b/cocos/editor-support/cocostudio/WidgetReader/ArmatureNodeReader/CSArmatureNode_generated.h new file mode 100644 index 000000000000..8122ddf54ea0 --- /dev/null +++ b/cocos/editor-support/cocostudio/WidgetReader/ArmatureNodeReader/CSArmatureNode_generated.h @@ -0,0 +1,108 @@ +// automatically generated by the FlatBuffers compiler, do not modify + +#ifndef FLATBUFFERS_GENERATED_CSARMATURENODE_FLATBUFFERS_H_ +#define FLATBUFFERS_GENERATED_CSARMATURENODE_FLATBUFFERS_H_ + +#include "flatbuffers/flatbuffers.h" + + +namespace flatbuffers { + +struct CSArmatureNodeOption; +struct ResourceItemData; + + +struct CSArmatureNodeOption : private flatbuffers::Table { + const WidgetOptions *nodeOptions() const { return GetPointer(4); } + const ResourceItemData *fileData() const { return GetPointer(6); } + uint8_t isLoop() const { return GetField(8, 1); } + uint8_t isAutoPlay() const { return GetField(10, 1); } + const flatbuffers::String *currentAnimationName() const { return GetPointer(12); } + bool Verify(flatbuffers::Verifier &verifier) const { + return VerifyTableStart(verifier) && + VerifyField(verifier, 4 /* nodeOptions */) && + verifier.VerifyTable(nodeOptions()) && + VerifyField(verifier, 6 /* fileData */) && + verifier.VerifyTable(fileData()) && + VerifyField(verifier, 8 /* isLoop */) && + VerifyField(verifier, 10 /* isAutoPlay */) && + VerifyField(verifier, 12 /* currentAnimationName */) && + verifier.Verify(currentAnimationName()) && + verifier.EndTable(); + } +}; + +struct CSArmatureNodeOptionBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_nodeOptions(flatbuffers::Offset nodeOptions) { fbb_.AddOffset(4, nodeOptions); } + void add_fileData(flatbuffers::Offset fileData) { fbb_.AddOffset(6, fileData); } + void add_isLoop(uint8_t isLoop) { fbb_.AddElement(8, isLoop, 1); } + void add_isAutoPlay(uint8_t isAutoPlay) { fbb_.AddElement(10, isAutoPlay, 1); } + void add_currentAnimationName(flatbuffers::Offset currentAnimationName) { fbb_.AddOffset(12, currentAnimationName); } + CSArmatureNodeOptionBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } + CSArmatureNodeOptionBuilder &operator=(const CSArmatureNodeOptionBuilder &); + flatbuffers::Offset Finish() { + auto o = flatbuffers::Offset(fbb_.EndTable(start_, 5)); + return o; + } +}; + +inline flatbuffers::Offset CreateCSArmatureNodeOption(flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset nodeOptions = 0, + flatbuffers::Offset fileData = 0, + uint8_t isLoop = 1, + uint8_t isAutoPlay = 1, + flatbuffers::Offset currentAnimationName = 0) { + CSArmatureNodeOptionBuilder builder_(_fbb); + builder_.add_currentAnimationName(currentAnimationName); + builder_.add_fileData(fileData); + builder_.add_nodeOptions(nodeOptions); + builder_.add_isAutoPlay(isAutoPlay); + builder_.add_isLoop(isLoop); + return builder_.Finish(); +} + +struct ResourceItemData : private flatbuffers::Table { + int32_t type() const { return GetField(4, 0); } + const flatbuffers::String *path() const { return GetPointer(6); } + bool Verify(flatbuffers::Verifier &verifier) const { + return VerifyTableStart(verifier) && + VerifyField(verifier, 4 /* type */) && + VerifyField(verifier, 6 /* path */) && + verifier.Verify(path()) && + verifier.EndTable(); + } +}; + +struct ResourceItemDataBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_type(int32_t type) { fbb_.AddElement(4, type, 0); } + void add_path(flatbuffers::Offset path) { fbb_.AddOffset(6, path); } + ResourceItemDataBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } + ResourceItemDataBuilder &operator=(const ResourceItemDataBuilder &); + flatbuffers::Offset Finish() { + auto o = flatbuffers::Offset(fbb_.EndTable(start_, 2)); + return o; + } +}; + +inline flatbuffers::Offset CreateResourceItemData(flatbuffers::FlatBufferBuilder &_fbb, + int32_t type = 0, + flatbuffers::Offset path = 0) { + ResourceItemDataBuilder builder_(_fbb); + builder_.add_path(path); + builder_.add_type(type); + return builder_.Finish(); +} + +inline const CSArmatureNodeOption *GetCSArmatureNodeOption(const void *buf) { return flatbuffers::GetRoot(buf); } + +inline bool VerifyCSArmatureNodeOptionBuffer(flatbuffers::Verifier &verifier) { return verifier.VerifyBuffer(); } + +inline void FinishCSArmatureNodeOptionBuffer(flatbuffers::FlatBufferBuilder &fbb, flatbuffers::Offset root) { fbb.Finish(root); } + +} // namespace flatbuffers + +#endif // FLATBUFFERS_GENERATED_CSARMATURENODE_FLATBUFFERS_H_ diff --git a/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp index 05200f632777..9d87029ef002 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp @@ -796,6 +796,11 @@ namespace cocostudio Size scale9Size(options->scale9Size()->width(), options->scale9Size()->height()); button->setContentSize(scale9Size); } + else + { + Size contentSize(options->widgetOptions()->size()->width(), options->widgetOptions()->size()->height()); + button->setContentSize(contentSize); + } } Node* ButtonReader::createNodeWithFlatBuffers(const flatbuffers::Table *buttonOptions) diff --git a/cocos/editor-support/cocostudio/WidgetReader/ImageViewReader/ImageViewReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/ImageViewReader/ImageViewReader.cpp index 224505822eba..ed461ae865d6 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ImageViewReader/ImageViewReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/ImageViewReader/ImageViewReader.cpp @@ -375,7 +375,11 @@ namespace cocostudio Rect capInsets(f_capInset->x(), f_capInset->y(), f_capInset->width(), f_capInset->height()); imageView->setCapInsets(capInsets); } - + else + { + Size contentSize(options->widgetOptions()->size()->width(), options->widgetOptions()->size()->height()); + imageView->setContentSize(contentSize); + } } Node* ImageViewReader::createNodeWithFlatBuffers(const flatbuffers::Table *imageViewOptions) diff --git a/cocos/editor-support/cocostudio/WidgetReader/NodeReader/NodeReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/NodeReader/NodeReader.cpp index 38d46b4a8851..9353f4f5fbac 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/NodeReader/NodeReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/NodeReader/NodeReader.cpp @@ -29,13 +29,31 @@ #include "tinyxml2.h" #include "flatbuffers/flatbuffers.h" - +#include "ui/UILayoutComponent.h" USING_NS_CC; using namespace flatbuffers; namespace cocostudio { + const char* Layout_PositionPercentXEnabled = "PositionPercentXEnable"; + const char* Layout_PositionPercentYEnabled = "PositionPercentYEnable"; + const char* Layout_PercentWidthEnable = "PercentWidthEnable"; + const char* Layout_PercentHeightEnable = "PercentHeightEnable"; + const char* Layout_StretchWidthEnable = "StretchWidthEnable"; + const char* Layout_StretchHeightEnable = "StretchHeightEnable"; + const char* Layout_HorizontalEdge = "HorizontalEdge"; + const char* Layout_VerticalEdge = "VerticalEdge"; + const char* Layout_LeftMargin = "LeftMargin"; + const char* Layout_RightMargin = "RightMargin"; + const char* Layout_TopMargin = "TopMargin"; + const char* Layout_BottomMargin = "BottomMargin"; + const char* Layout_BothEdge = "BothEdge"; + const char* Layout_LeftEdge = "LeftEdge"; + const char* Layout_RightEdge = "RightEdge"; + const char* Layout_TopEdge = "TopEdge"; + const char* Layout_BottomEdge = "BottomEdge"; + IMPLEMENT_CLASS_NODE_READER_INFO(NodeReader) NodeReader::NodeReader() @@ -87,6 +105,23 @@ namespace cocostudio bool touchEnabled = false; std::string frameEvent = ""; std::string customProperty = ""; + + bool positionXPercentEnabled = false; + bool positionYPercentEnabled = false; + float positionXPercent = 0; + float positionYPercent = 0; + bool sizeXPercentEnable = false; + bool sizeYPercentEnable = false; + float sizeXPercent = 0; + float sizeYPercent = 0; + bool stretchHorizontalEnabled = false; + bool stretchVerticalEnabled = false; + std::string horizontalEdge; + std::string verticalEdge; + float leftMargin = 0; + float rightMargin = 0; + float topMargin = 0; + float bottomMargin = 0; // attributes const tinyxml2::XMLAttribute* attribute = objectData->FirstAttribute(); @@ -151,6 +186,54 @@ namespace cocostudio { frameEvent = value; } + else if (attriname == Layout_PositionPercentXEnabled) + { + positionXPercentEnabled = value == "True"; + } + else if (attriname == Layout_PositionPercentYEnabled) + { + positionYPercentEnabled = value == "True"; + } + else if (attriname == Layout_PercentWidthEnable) + { + sizeXPercentEnable = value == "True"; + } + else if (attriname == Layout_PercentHeightEnable) + { + sizeYPercentEnable = value == "True"; + } + else if (attriname == Layout_StretchWidthEnable) + { + stretchHorizontalEnabled = value == "True"; + } + else if (attriname == Layout_StretchHeightEnable) + { + stretchVerticalEnabled = value == "True"; + } + else if (attriname == Layout_HorizontalEdge) + { + horizontalEdge = value; + } + else if (attriname == Layout_VerticalEdge) + { + verticalEdge = value; + } + else if (attriname == Layout_LeftMargin) + { + leftMargin = atof(value.c_str()); + } + else if (attriname == Layout_RightMargin) + { + rightMargin = atof(value.c_str()); + } + else if (attriname == Layout_TopMargin) + { + topMargin = atof(value.c_str()); + } + else if (attriname == Layout_BottomMargin) + { + bottomMargin = atof(value.c_str()); + } attribute = attribute->Next(); } @@ -276,7 +359,48 @@ namespace cocostudio attribute = attribute->Next(); } } - + else if (attriname == "PrePosition") + { + attribute = child->FirstAttribute(); + + while (attribute) + { + attriname = attribute->Name(); + std::string value = attribute->Value(); + + if (attriname == "X") + { + positionXPercent = atof(value.c_str()); + } + else if (attriname == "Y") + { + positionYPercent = atof(value.c_str()); + } + + attribute = attribute->Next(); + } + } + else if (attriname == "PreSize") + { + attribute = child->FirstAttribute(); + + while (attribute) + { + attriname = attribute->Name(); + std::string value = attribute->Value(); + + if (attriname == "X") + { + sizeXPercent = atof(value.c_str()); + } + else if (attriname == "Y") + { + sizeYPercent = atof(value.c_str()); + } + + attribute = attribute->Next(); + } + } child = child->NextSiblingElement(); } @@ -286,7 +410,23 @@ namespace cocostudio AnchorPoint f_anchortpoint(anchorPoint.x, anchorPoint.y); Color f_color(color.a, color.r, color.g, color.b); FlatSize f_size(size.x, size.y); - + auto f_layoutComponent = CreateLayoutComponentTable(*builder, + positionXPercentEnabled, + positionYPercentEnabled, + positionXPercent, + positionYPercent, + sizeXPercentEnable, + sizeYPercentEnable, + sizeXPercent, + sizeYPercent, + stretchHorizontalEnabled, + stretchVerticalEnabled, + builder->CreateString(horizontalEdge), + builder->CreateString(verticalEdge), + leftMargin, + rightMargin, + topMargin, + bottomMargin); auto options = CreateWidgetOptions(*builder, builder->CreateString(name), @@ -306,8 +446,10 @@ namespace cocostudio ignoreSize, touchEnabled, builder->CreateString(frameEvent), - builder->CreateString(customProperty) - ); + builder->CreateString(customProperty), + 0, + 0, + f_layoutComponent); return *(Offset
*)(&options); } @@ -368,8 +510,80 @@ namespace cocostudio node->setCascadeColorEnabled(true); node->setCascadeOpacityEnabled(true); + + setLayoutComponentPropsWithFlatBuffers(node, nodeOptions); } - + + void NodeReader::setLayoutComponentPropsWithFlatBuffers(cocos2d::Node* node, const flatbuffers::Table* nodeOptions) + { + auto layoutComponentTable = ((WidgetOptions*)nodeOptions)->layoutComponent(); + if (!layoutComponentTable) return; + + bool positionXPercentEnabled = layoutComponentTable->positionXPercentEnabled(); + bool positionYPercentEnabled = layoutComponentTable->positionYPercentEnabled(); + float positionXPercent = layoutComponentTable->positionXPercent(); + float positionYPercent = layoutComponentTable->positionYPercent(); + bool sizeXPercentEnable = layoutComponentTable->sizeXPercentEnable(); + bool sizeYPercentEnable = layoutComponentTable->sizeYPercentEnable(); + float sizeXPercent = layoutComponentTable->sizeXPercent(); + float sizeYPercent = layoutComponentTable->sizeYPercent(); + bool stretchHorizontalEnabled = layoutComponentTable->stretchHorizontalEnabled(); + bool stretchVerticalEnabled = layoutComponentTable->stretchVerticalEnabled(); + std::string horizontalEdge = layoutComponentTable->horizontalEdge()->c_str(); + std::string verticalEdge = layoutComponentTable->verticalEdge()->c_str(); + float leftMargin = layoutComponentTable->leftMargin(); + float rightMargin = layoutComponentTable->rightMargin(); + float topMargin = layoutComponentTable->topMargin(); + float bottomMargin = layoutComponentTable->bottomMargin(); + + auto layoutComponent = ui::LayoutComponent::create(); + node->addComponent(layoutComponent); + + layoutComponent->setPositionPercentXEnabled(positionXPercentEnabled); + layoutComponent->setPositionPercentYEnabled(positionYPercentEnabled); + layoutComponent->setPositionPercentX(positionXPercent); + layoutComponent->setPositionPercentY(positionYPercent); + layoutComponent->setPercentWidthEnabled(sizeXPercentEnable); + layoutComponent->setPercentHeightEnabled(sizeYPercentEnable); + layoutComponent->setPercentWidth(sizeXPercent); + layoutComponent->setPercentHeight(sizeYPercent); + layoutComponent->setStretchWidthEnabled(stretchHorizontalEnabled); + layoutComponent->setStretchHeightEnabled(stretchVerticalEnabled); + ui::LayoutComponent::HorizontalEdge horizontalEdgeType = ui::LayoutComponent::HorizontalEdge::None; + if (horizontalEdge == Layout_LeftEdge) + { + horizontalEdgeType = ui::LayoutComponent::HorizontalEdge::Left; + } + else if (horizontalEdge == Layout_RightEdge) + { + horizontalEdgeType = ui::LayoutComponent::HorizontalEdge::Right; + } + else if (horizontalEdge == Layout_BothEdge) + { + horizontalEdgeType = ui::LayoutComponent::HorizontalEdge::Center; + } + layoutComponent->setHorizontalEdge(horizontalEdgeType); + ui::LayoutComponent::VerticalEdge verticalEdgeType = ui::LayoutComponent::VerticalEdge::None; + if (verticalEdge == Layout_TopEdge) + { + verticalEdgeType = ui::LayoutComponent::VerticalEdge::Top; + } + else if (verticalEdge == Layout_BottomEdge) + { + verticalEdgeType = ui::LayoutComponent::VerticalEdge::Bottom; + } + else if (verticalEdge == Layout_BothEdge) + { + verticalEdgeType = ui::LayoutComponent::VerticalEdge::Center; + } + layoutComponent->setVerticalEdge(verticalEdgeType); + + layoutComponent->setTopMargin(topMargin); + layoutComponent->setBottomMargin(bottomMargin); + layoutComponent->setLeftMargin(leftMargin); + layoutComponent->setRightMargin(rightMargin); + } + Node* NodeReader::createNodeWithFlatBuffers(const flatbuffers::Table *nodeOptions) { Node* node = Node::create(); diff --git a/cocos/editor-support/cocostudio/WidgetReader/NodeReader/NodeReader.h b/cocos/editor-support/cocostudio/WidgetReader/NodeReader/NodeReader.h index 57fb46f660c5..84049e6d7399 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/NodeReader/NodeReader.h +++ b/cocos/editor-support/cocostudio/WidgetReader/NodeReader/NodeReader.h @@ -46,6 +46,7 @@ namespace cocostudio flatbuffers::Offset createOptionsWithFlatBuffers(const tinyxml2::XMLElement* objectData, flatbuffers::FlatBufferBuilder* builder); void setPropsWithFlatBuffers(cocos2d::Node* node, const flatbuffers::Table* nodeOptions); + void setLayoutComponentPropsWithFlatBuffers(cocos2d::Node* node, const flatbuffers::Table* nodeOptions); cocos2d::Node* createNodeWithFlatBuffers(const flatbuffers::Table* nodeOptions); }; } diff --git a/cocos/editor-support/cocostudio/WidgetReader/ProjectNodeReader/ProjectNodeReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/ProjectNodeReader/ProjectNodeReader.cpp index 3b733b434eef..23ff6f16b508 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ProjectNodeReader/ProjectNodeReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/ProjectNodeReader/ProjectNodeReader.cpp @@ -69,51 +69,27 @@ namespace cocostudio auto nodeOptions = *(Offset*)(&temp); std::string filename = ""; - - // FileData - const tinyxml2::XMLElement* child = objectData->FirstChildElement(); - while (child) + bool isloop = true; + bool isAutoPlay = true; + + const tinyxml2::XMLAttribute* attribute = objectData->FirstAttribute(); + while (attribute) { - std::string name = child->Name(); - - if (name == "FileData") + std::string attriname = attribute->Name(); + std::string value = attribute->Value(); + + if (attriname == "IsLoop") { - const tinyxml2::XMLAttribute* attribute = child->FirstAttribute(); - - while (attribute) - { - name = attribute->Name(); - std::string value = attribute->Value(); - - if (name == "Path") - { - size_t pos = value.find_last_of('.'); - std::string convert = value.substr(0, pos).append(".csb"); - filename = convert; - } - - attribute = attribute->Next(); - } + isloop = (value == "True") ? true : false; } - - child = child->NextSiblingElement(); + else if (attriname == "IsAutoPlay") + { + isAutoPlay = (value == "True") ? true : false; + } + + attribute = attribute->Next(); } - - auto options = CreateProjectNodeOptions(*builder, - nodeOptions, - builder->CreateString(filename)); - - return *(Offset
*)(&options); - } - - Offset
ProjectNodeReader::createOptionsWithFlatBuffersForSimulator(const tinyxml2::XMLElement *objectData, - flatbuffers::FlatBufferBuilder *builder) - { - auto temp = NodeReader::getInstance()->createOptionsWithFlatBuffers(objectData, builder); - auto nodeOptions = *(Offset*)(&temp); - - std::string filename = ""; - + // FileData const tinyxml2::XMLElement* child = objectData->FirstChildElement(); while (child) @@ -131,7 +107,9 @@ namespace cocostudio if (name == "Path") { - filename = value; + size_t pos = value.find_last_of('.'); + std::string convert = value.substr(0, pos).append(".csb"); + filename = convert; } attribute = attribute->Next(); @@ -143,7 +121,9 @@ namespace cocostudio auto options = CreateProjectNodeOptions(*builder, nodeOptions, - builder->CreateString(filename)); + builder->CreateString(filename), + isloop, + isAutoPlay); return *(Offset
*)(&options); } diff --git a/cocos/editor-support/cocostudio/WidgetReader/ProjectNodeReader/ProjectNodeReader.h b/cocos/editor-support/cocostudio/WidgetReader/ProjectNodeReader/ProjectNodeReader.h index e32b6ab2d598..48b2fccd43cd 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ProjectNodeReader/ProjectNodeReader.h +++ b/cocos/editor-support/cocostudio/WidgetReader/ProjectNodeReader/ProjectNodeReader.h @@ -44,8 +44,7 @@ namespace cocostudio flatbuffers::Offset createOptionsWithFlatBuffers(const tinyxml2::XMLElement* objectData, flatbuffers::FlatBufferBuilder* builder); - flatbuffers::Offset createOptionsWithFlatBuffersForSimulator(const tinyxml2::XMLElement* objectData, - flatbuffers::FlatBufferBuilder* builder); + void setPropsWithFlatBuffers(cocos2d::Node* node, const flatbuffers::Table* projectNodeOptions); cocos2d::Node* createNodeWithFlatBuffers(const flatbuffers::Table* nodeOptions) { return nullptr; }; }; diff --git a/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp index 5e382580c3eb..7807517b41ec 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp @@ -9,6 +9,8 @@ #include "tinyxml2.h" #include "flatbuffers/flatbuffers.h" +#include "ui/UILayoutComponent.h" +#include "cocostudio/ActionTimeline/CSLoader.h" USING_NS_CC; using namespace ui; @@ -20,7 +22,6 @@ using namespace flatbuffers; namespace cocostudio { - const char* P_IgnoreSize = "ignoreSize"; const char* P_SizeType = "sizeType"; const char* P_PositionType = "positionType"; @@ -66,6 +67,24 @@ namespace cocostudio const char* P_ResourceType = "resourceType"; const char* P_Path = "path"; + const char* P_Layout_PositionPercentXEnabled = "PositionPercentXEnable"; + const char* P_Layout_PositionPercentYEnabled = "PositionPercentYEnable"; + const char* P_Layout_PercentWidthEnable = "PercentWidthEnable"; + const char* P_Layout_PercentHeightEnable = "PercentHeightEnable"; + const char* P_Layout_StretchWidthEnable = "StretchWidthEnable"; + const char* P_Layout_StretchHeightEnable = "StretchHeightEnable"; + const char* P_Layout_HorizontalEdge = "HorizontalEdge"; + const char* P_Layout_VerticalEdge = "VerticalEdge"; + const char* P_Layout_LeftMargin = "LeftMargin"; + const char* P_Layout_RightMargin = "RightMargin"; + const char* P_Layout_TopMargin = "TopMargin"; + const char* P_Layout_BottomMargin = "BottomMargin"; + const char* P_Layout_BothEdge = "BothEdge"; + const char* P_Layout_LeftEdge = "LeftEdge"; + const char* P_Layout_RightEdge = "RightEdge"; + const char* P_Layout_TopEdge = "TopEdge"; + const char* P_Layout_BottomEdge = "BottomEdge"; + static WidgetReader* instanceWidgetReader = nullptr; @@ -384,6 +403,23 @@ namespace cocostudio std::string customProperty = ""; std::string callbackType = ""; std::string callbackName = ""; + + bool positionXPercentEnabled = false; + bool positionYPercentEnabled = false; + float positionXPercent = 0; + float positionYPercent = 0; + bool sizeXPercentEnable = false; + bool sizeYPercentEnable = false; + float sizeXPercent = 0; + float sizeYPercent = 0; + bool stretchHorizontalEnabled = false; + bool stretchVerticalEnabled = false; + std::string horizontalEdge; + std::string verticalEdge; + float leftMargin = 0; + float rightMargin = 0; + float topMargin = 0; + float bottomMargin = 0; // attributes const tinyxml2::XMLAttribute* attribute = objectData->FirstAttribute(); @@ -456,7 +492,55 @@ namespace cocostudio { callbackName = value; } - + else if (attriname == P_Layout_PositionPercentXEnabled) + { + positionXPercentEnabled = value == "True"; + } + else if (attriname == P_Layout_PositionPercentYEnabled) + { + positionYPercentEnabled = value == "True"; + } + else if (attriname == P_Layout_PercentWidthEnable) + { + sizeXPercentEnable = value == "True"; + } + else if (attriname == P_Layout_PercentHeightEnable) + { + sizeYPercentEnable = value == "True"; + } + else if (attriname == P_Layout_StretchWidthEnable) + { + stretchHorizontalEnabled = value == "True"; + } + else if (attriname == P_Layout_StretchHeightEnable) + { + stretchVerticalEnabled = value == "True"; + } + else if (attriname == P_Layout_HorizontalEdge) + { + horizontalEdge = value; + } + else if (attriname == P_Layout_VerticalEdge) + { + verticalEdge = value; + } + else if (attriname == P_Layout_LeftMargin) + { + leftMargin = atof(value.c_str()); + } + else if (attriname == P_Layout_RightMargin) + { + rightMargin = atof(value.c_str()); + } + else if (attriname == P_Layout_TopMargin) + { + topMargin = atof(value.c_str()); + } + else if (attriname == P_Layout_BottomMargin) + { + bottomMargin = atof(value.c_str()); + } + attribute = attribute->Next(); } @@ -581,6 +665,48 @@ namespace cocostudio attribute = attribute->Next(); } } + else if (attriname == "PrePosition") + { + attribute = child->FirstAttribute(); + + while (attribute) + { + attriname = attribute->Name(); + std::string value = attribute->Value(); + + if (attriname == "X") + { + positionXPercent = atof(value.c_str()); + } + else if (attriname == "Y") + { + positionYPercent = atof(value.c_str()); + } + + attribute = attribute->Next(); + } + } + else if (attriname == "PreSize") + { + attribute = child->FirstAttribute(); + + while (attribute) + { + attriname = attribute->Name(); + std::string value = attribute->Value(); + + if (attriname == "X") + { + sizeXPercent = atof(value.c_str()); + } + else if (attriname == "Y") + { + sizeYPercent = atof(value.c_str()); + } + + attribute = attribute->Next(); + } + } child = child->NextSiblingElement(); } @@ -591,6 +717,23 @@ namespace cocostudio AnchorPoint f_anchortpoint(anchorPoint.x, anchorPoint.y); Color f_color(color.a, color.r, color.g, color.b); FlatSize f_size(size.x, size.y); + auto f_layoutComponent = CreateLayoutComponentTable(*builder, + positionXPercentEnabled, + positionYPercentEnabled, + positionXPercent, + positionYPercent, + sizeXPercentEnable, + sizeYPercentEnable, + sizeXPercent, + sizeYPercent, + stretchHorizontalEnabled, + stretchVerticalEnabled, + builder->CreateString(horizontalEdge), + builder->CreateString(verticalEdge), + leftMargin, + rightMargin, + topMargin, + bottomMargin); auto options = CreateWidgetOptions(*builder, builder->CreateString(name), @@ -612,8 +755,8 @@ namespace cocostudio builder->CreateString(frameEvent), builder->CreateString(customProperty), builder->CreateString(callbackType), - builder->CreateString(callbackName) - ); + builder->CreateString(callbackName), + f_layoutComponent); return *(Offset
*)(&options); } @@ -629,7 +772,36 @@ namespace cocostudio widget->setAnchorPoint(Vec2::ZERO); widget->setUnifySizeEnabled(true); - + std::string versionString = CSLoader::getInstance()->getCsdVersion(); + + //assume versionString is like "2.0.6.0" + if (versionString.length() > 0) + { + int p1, p2, p3, v1, v2, v3; + p1 = p2 = p3 = v1 = v2 = v3 = 0; + p1 = versionString.find('.'); + if (p1 > 0) + { + p2 = versionString.find('.', p1 + 1); + v1 = atoi(versionString.substr(0, p1).c_str()); + } + if (p2 > p1) + { + p3 = versionString.find('.', p2 + 1); + v2 = atoi(versionString.substr(p1 + 1, p2 - p1 - 1).c_str()); + } + if (p3 > p2) + { + v3 = atoi(versionString.substr(p2 + 1, p3 - p2 - 1).c_str()); + } + + if (!(v1 <= 2 && v2 == 0 && v3 <= 6)) + { + widget->setUnifySizeEnabled(false); + widget->setLayoutComponentEnabled(true); + } + } + bool ignoreSize = options->ignoreSize(); widget->ignoreContentAdaptWithSize(ignoreSize); @@ -691,6 +863,77 @@ namespace cocostudio std::string callbackName = options->callBackName()->c_str(); widget->setCallbackName(callbackName); + setLayoutComponentPropsWithFlatBuffers(widget, widgetOptions); + } + + void WidgetReader::setLayoutComponentPropsWithFlatBuffers(cocos2d::Node* node, const flatbuffers::Table* nodeOptions) + { + auto layoutComponentTable = ((WidgetOptions*)nodeOptions)->layoutComponent(); + if (!layoutComponentTable) return; + + bool positionXPercentEnabled = layoutComponentTable->positionXPercentEnabled(); + bool positionYPercentEnabled = layoutComponentTable->positionYPercentEnabled(); + float positionXPercent = layoutComponentTable->positionXPercent(); + float positionYPercent = layoutComponentTable->positionYPercent(); + bool sizeXPercentEnable = layoutComponentTable->sizeXPercentEnable(); + bool sizeYPercentEnable = layoutComponentTable->sizeYPercentEnable(); + float sizeXPercent = layoutComponentTable->sizeXPercent(); + float sizeYPercent = layoutComponentTable->sizeYPercent(); + bool stretchHorizontalEnabled = layoutComponentTable->stretchHorizontalEnabled(); + bool stretchVerticalEnabled = layoutComponentTable->stretchVerticalEnabled(); + std::string horizontalEdge = layoutComponentTable->horizontalEdge()->c_str(); + std::string verticalEdge = layoutComponentTable->verticalEdge()->c_str(); + float leftMargin = layoutComponentTable->leftMargin(); + float rightMargin = layoutComponentTable->rightMargin(); + float topMargin = layoutComponentTable->topMargin(); + float bottomMargin = layoutComponentTable->bottomMargin(); + + auto layoutComponent = ui::LayoutComponent::create(); + node->addComponent(layoutComponent); + + layoutComponent->setPositionPercentXEnabled(positionXPercentEnabled); + layoutComponent->setPositionPercentYEnabled(positionYPercentEnabled); + layoutComponent->setPositionPercentX(positionXPercent); + layoutComponent->setPositionPercentY(positionYPercent); + layoutComponent->setPercentWidthEnabled(sizeXPercentEnable); + layoutComponent->setPercentHeightEnabled(sizeYPercentEnable); + layoutComponent->setPercentWidth(sizeXPercent); + layoutComponent->setPercentHeight(sizeYPercent); + layoutComponent->setStretchWidthEnabled(stretchHorizontalEnabled); + layoutComponent->setStretchHeightEnabled(stretchVerticalEnabled); + ui::LayoutComponent::HorizontalEdge horizontalEdgeType = ui::LayoutComponent::HorizontalEdge::None; + if (horizontalEdge == P_Layout_LeftEdge) + { + horizontalEdgeType = ui::LayoutComponent::HorizontalEdge::Left; + } + else if (horizontalEdge == P_Layout_RightEdge) + { + horizontalEdgeType = ui::LayoutComponent::HorizontalEdge::Right; + } + else if (horizontalEdge == P_Layout_BothEdge) + { + horizontalEdgeType = ui::LayoutComponent::HorizontalEdge::Center; + } + layoutComponent->setHorizontalEdge(horizontalEdgeType); + ui::LayoutComponent::VerticalEdge verticalEdgeType = ui::LayoutComponent::VerticalEdge::None; + if (verticalEdge == P_Layout_TopEdge) + { + verticalEdgeType = ui::LayoutComponent::VerticalEdge::Top; + } + else if (verticalEdge == P_Layout_BottomEdge) + { + verticalEdgeType = ui::LayoutComponent::VerticalEdge::Bottom; + } + else if (verticalEdge == P_Layout_BothEdge) + { + verticalEdgeType = ui::LayoutComponent::VerticalEdge::Center; + } + layoutComponent->setVerticalEdge(verticalEdgeType); + + layoutComponent->setTopMargin(topMargin); + layoutComponent->setBottomMargin(bottomMargin); + layoutComponent->setLeftMargin(leftMargin); + layoutComponent->setRightMargin(rightMargin); } Node* WidgetReader::createNodeWithFlatBuffers(const flatbuffers::Table *widgetOptions) diff --git a/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.h b/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.h index 19276f3ea233..6e0a45675314 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.h +++ b/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.h @@ -60,6 +60,7 @@ namespace cocostudio flatbuffers::Offset createOptionsWithFlatBuffers(const tinyxml2::XMLElement* objectData, flatbuffers::FlatBufferBuilder* builder); void setPropsWithFlatBuffers(cocos2d::Node* node, const flatbuffers::Table* widgetOptions); + void setLayoutComponentPropsWithFlatBuffers(cocos2d::Node* node, const flatbuffers::Table* widgetOptions); cocos2d::Node* createNodeWithFlatBuffers(const flatbuffers::Table* widgetOptions); /**/ diff --git a/cocos/network/WebSocket.cpp b/cocos/network/WebSocket.cpp index ec35a1309ed4..790e193035ac 100644 --- a/cocos/network/WebSocket.cpp +++ b/cocos/network/WebSocket.cpp @@ -187,6 +187,12 @@ void WsThreadHelper::update(float dt) { WsMessage *msg = nullptr; + /* Avoid locking if, in most cases, the queue is empty. This could be a little faster. + size() is not thread-safe, it might return a strange value, but it should be OK in our scenario. + */ + if (0 == _UIWsMessageQueue->size()) + return; + // Returns quickly if no message _UIWsMessageQueueMutex.lock(); diff --git a/cocos/platform/CCPlatformMacros.h b/cocos/platform/CCPlatformMacros.h index 0f0afdfe9cf6..3e321cdff674 100644 --- a/cocos/platform/CCPlatformMacros.h +++ b/cocos/platform/CCPlatformMacros.h @@ -39,7 +39,7 @@ Copyright (c) 2013-2014 Chukong Technologies #define CREATE_FUNC(__TYPE__) \ static __TYPE__* create() \ { \ - __TYPE__ *pRet = new __TYPE__(); \ + __TYPE__ *pRet = new(std::nothrow) __TYPE__(); \ if (pRet && pRet->init()) \ { \ pRet->autorelease(); \ @@ -61,7 +61,7 @@ static __TYPE__* create() \ #define NODE_FUNC(__TYPE__) \ CC_DEPRECATED_ATTRIBUTE static __TYPE__* node() \ { \ - __TYPE__ *pRet = new __TYPE__(); \ + __TYPE__ *pRet = new(std::nothrow) __TYPE__(); \ if (pRet && pRet->init()) \ { \ pRet->autorelease(); \ diff --git a/cocos/scripting/lua-bindings/auto/api/ActionTimelineNode.lua b/cocos/scripting/lua-bindings/auto/api/ActionTimelineNode.lua new file mode 100644 index 000000000000..dea11fbb00b0 --- /dev/null +++ b/cocos/scripting/lua-bindings/auto/api/ActionTimelineNode.lua @@ -0,0 +1,53 @@ + +-------------------------------- +-- @module ActionTimelineNode +-- @extend Node +-- @parent_module ccs + +-------------------------------- +-- +-- @function [parent=#ActionTimelineNode] getRoot +-- @param self +-- @return Node#Node ret (return value: cc.Node) + +-------------------------------- +-- +-- @function [parent=#ActionTimelineNode] getActionTimeline +-- @param self +-- @return ActionTimeline#ActionTimeline ret (return value: ccs.ActionTimeline) + +-------------------------------- +-- +-- @function [parent=#ActionTimelineNode] setActionTimeline +-- @param self +-- @param #ccs.ActionTimeline action + +-------------------------------- +-- @overload self, cc.Node, ccs.ActionTimeline +-- @overload self +-- @function [parent=#ActionTimelineNode] init +-- @param self +-- @param #cc.Node root +-- @param #ccs.ActionTimeline action +-- @return bool#bool ret (return value: bool) + +-------------------------------- +-- +-- @function [parent=#ActionTimelineNode] setRoot +-- @param self +-- @param #cc.Node root + +-------------------------------- +-- +-- @function [parent=#ActionTimelineNode] create +-- @param self +-- @param #cc.Node root +-- @param #ccs.ActionTimeline action +-- @return ActionTimelineNode#ActionTimelineNode ret (return value: ccs.ActionTimelineNode) + +-------------------------------- +-- +-- @function [parent=#ActionTimelineNode] ActionTimelineNode +-- @param self + +return nil diff --git a/cocos/scripting/lua-bindings/auto/api/CSLoader.lua b/cocos/scripting/lua-bindings/auto/api/CSLoader.lua index bd2a5d6945eb..271d32122749 100644 --- a/cocos/scripting/lua-bindings/auto/api/CSLoader.lua +++ b/cocos/scripting/lua-bindings/auto/api/CSLoader.lua @@ -82,6 +82,12 @@ -- @param #string filename -- @return Node#Node ret (return value: cc.Node) +-------------------------------- +-- +-- @function [parent=#CSLoader] getCsdVersion +-- @param self +-- @return string#string ret (return value: string) + -------------------------------- -- -- @function [parent=#CSLoader] destroyInstance diff --git a/cocos/scripting/lua-bindings/auto/api/Director.lua b/cocos/scripting/lua-bindings/auto/api/Director.lua index 6373be31ecea..738d1a0873e7 100644 --- a/cocos/scripting/lua-bindings/auto/api/Director.lua +++ b/cocos/scripting/lua-bindings/auto/api/Director.lua @@ -226,6 +226,12 @@ -- @param self -- @return bool#bool ret (return value: bool) +-------------------------------- +-- set clear values for the color buffers, value range of each element is [0.0, 1.0] +-- @function [parent=#Director] setClearColor +-- @param self +-- @param #color4f_table clearColor + -------------------------------- -- Ends the execution, releases the running scene.
-- It doesn't remove the OpenGL view from its parent. You have to do it manually.
diff --git a/cocos/scripting/lua-bindings/auto/api/Helper.lua b/cocos/scripting/lua-bindings/auto/api/Helper.lua index 02860c10d93c..a7ad2570bb21 100644 --- a/cocos/scripting/lua-bindings/auto/api/Helper.lua +++ b/cocos/scripting/lua-bindings/auto/api/Helper.lua @@ -53,7 +53,20 @@ -- @return Widget#Widget ret (return value: ccui.Widget) -------------------------------- --- +-- brief restrict capInsetSize, when the capInsets's width is larger than the textureSize, it will restrict to 0,
+-- the height goes the same way as width.
+-- param capInsets A user defined capInsets.
+-- param textureSize The size of a scale9enabled texture
+-- return a restricted capInset. +-- @function [parent=#Helper] restrictCapInsetRect +-- @param self +-- @param #rect_table capInsets +-- @param #size_table textureSize +-- @return rect_table#rect_table ret (return value: rect_table) + +-------------------------------- +-- Refresh object and it's children layout state
+-- param rootNode object which will be changed -- @function [parent=#Helper] doLayout -- @param self -- @param #cc.Node rootNode diff --git a/cocos/scripting/lua-bindings/auto/api/ListView.lua b/cocos/scripting/lua-bindings/auto/api/ListView.lua index 550f7ede5d60..b7acf93467f2 100644 --- a/cocos/scripting/lua-bindings/auto/api/ListView.lua +++ b/cocos/scripting/lua-bindings/auto/api/ListView.lua @@ -147,6 +147,11 @@ -- @param #int zOrder -- @param #string name +-------------------------------- +-- +-- @function [parent=#ListView] forceDoLayout +-- @param self + -------------------------------- -- Changes scroll direction of scrollview.
-- see Direction Direction::VERTICAL means vertical scroll, Direction::HORIZONTAL means horizontal scroll
diff --git a/cocos/scripting/lua-bindings/auto/api/Widget.lua b/cocos/scripting/lua-bindings/auto/api/Widget.lua index 28296c3d8952..17dcc9a09a91 100644 --- a/cocos/scripting/lua-bindings/auto/api/Widget.lua +++ b/cocos/scripting/lua-bindings/auto/api/Widget.lua @@ -4,6 +4,13 @@ -- @extend ProtectedNode,LayoutParameterProtocol -- @parent_module ccui +-------------------------------- +-- param enable Layout Component of a widget
+-- return void +-- @function [parent=#Widget] setLayoutComponentEnabled +-- @param self +-- @param #bool enable + -------------------------------- -- Changes the percent that is widget's percent size
-- param percent that is widget's percent size @@ -335,6 +342,12 @@ -- @param #vec2_table pt -- @return bool#bool ret (return value: bool) +-------------------------------- +-- return true represent the widget use Layout Component, false represent the widget couldn't use Layout Component. +-- @function [parent=#Widget] isLayoutComponentEnabled +-- @param self +-- @return bool#bool ret (return value: bool) + -------------------------------- -- when a widget calls this method, it will get focus immediately. -- @function [parent=#Widget] requestFocus diff --git a/cocos/scripting/lua-bindings/auto/api/lua_cocos2dx_studio_auto_api.lua b/cocos/scripting/lua-bindings/auto/api/lua_cocos2dx_studio_auto_api.lua index c4941b835424..2c1a6f7f29fe 100644 --- a/cocos/scripting/lua-bindings/auto/api/lua_cocos2dx_studio_auto_api.lua +++ b/cocos/scripting/lua-bindings/auto/api/lua_cocos2dx_studio_auto_api.lua @@ -261,4 +261,9 @@ -- @field [parent=#ccs] ActionTimeline#ActionTimeline ActionTimeline preloaded module +-------------------------------------------------------- +-- the ccs ActionTimelineNode +-- @field [parent=#ccs] ActionTimelineNode#ActionTimelineNode ActionTimelineNode preloaded module + + return nil diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp index 7eb2cac19e76..d8b45c1198b3 100644 --- a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp @@ -12924,6 +12924,55 @@ int lua_cocos2dx_Director_isNextDeltaTimeZero(lua_State* tolua_S) return 0; } +int lua_cocos2dx_Director_setClearColor(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::Director* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"cc.Director",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::Director*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_Director_setClearColor'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 1) + { + cocos2d::Color4F arg0; + + ok &=luaval_to_color4f(tolua_S, 2, &arg0, "cc.Director:setClearColor"); + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_Director_setClearColor'", nullptr); + return 0; + } + cobj->setClearColor(arg0); + return 0; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.Director:setClearColor",argc, 1); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_Director_setClearColor'.",&tolua_err); +#endif + + return 0; +} int lua_cocos2dx_Director_end(lua_State* tolua_S) { int argc = 0; @@ -14349,6 +14398,7 @@ int lua_register_cocos2dx_Director(lua_State* tolua_S) tolua_function(tolua_S,"popToSceneStackLevel",lua_cocos2dx_Director_popToSceneStackLevel); tolua_function(tolua_S,"resume",lua_cocos2dx_Director_resume); tolua_function(tolua_S,"isNextDeltaTimeZero",lua_cocos2dx_Director_isNextDeltaTimeZero); + tolua_function(tolua_S,"setClearColor",lua_cocos2dx_Director_setClearColor); tolua_function(tolua_S,"endToLua",lua_cocos2dx_Director_end); tolua_function(tolua_S,"setOpenGLView",lua_cocos2dx_Director_setOpenGLView); tolua_function(tolua_S,"convertToGL",lua_cocos2dx_Director_convertToGL); diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.hpp b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.hpp index 03c009ff62ab..160022630539 100644 --- a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.hpp +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.hpp @@ -1620,6 +1620,7 @@ int register_all_cocos2dx(lua_State* tolua_S); + #endif // __cocos2dx_h__ diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_csloader_auto.cpp b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_csloader_auto.cpp index 524716110b8a..8d83129c8b60 100644 --- a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_csloader_auto.cpp +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_csloader_auto.cpp @@ -598,6 +598,53 @@ int lua_cocos2dx_csloader_CSLoader_createNodeWithFlatBuffersForSimulator(lua_Sta return 0; } +int lua_cocos2dx_csloader_CSLoader_getCsdVersion(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::CSLoader* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"cc.CSLoader",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::CSLoader*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_csloader_CSLoader_getCsdVersion'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 0) + { + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_csloader_CSLoader_getCsdVersion'", nullptr); + return 0; + } + std::string ret = cobj->getCsdVersion(); + tolua_pushcppstring(tolua_S,ret); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.CSLoader:getCsdVersion",argc, 0); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_csloader_CSLoader_getCsdVersion'.",&tolua_err); +#endif + + return 0; +} int lua_cocos2dx_csloader_CSLoader_destroyInstance(lua_State* tolua_S) { int argc = 0; @@ -761,6 +808,7 @@ int lua_register_cocos2dx_csloader_CSLoader(lua_State* tolua_S) tolua_function(tolua_S,"getJsonPath",lua_cocos2dx_csloader_CSLoader_getJsonPath); tolua_function(tolua_S,"setRecordJsonPath",lua_cocos2dx_csloader_CSLoader_setRecordJsonPath); tolua_function(tolua_S,"createNodeWithFlatBuffersForSimulator",lua_cocos2dx_csloader_CSLoader_createNodeWithFlatBuffersForSimulator); + tolua_function(tolua_S,"getCsdVersion",lua_cocos2dx_csloader_CSLoader_getCsdVersion); tolua_function(tolua_S,"destroyInstance", lua_cocos2dx_csloader_CSLoader_destroyInstance); tolua_function(tolua_S,"createNode", lua_cocos2dx_csloader_CSLoader_createNode); tolua_function(tolua_S,"getInstance", lua_cocos2dx_csloader_CSLoader_getInstance); diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_csloader_auto.hpp b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_csloader_auto.hpp index 4c4e5bc66647..30e076262f9f 100644 --- a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_csloader_auto.hpp +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_csloader_auto.hpp @@ -29,4 +29,5 @@ int register_all_cocos2dx_csloader(lua_State* tolua_S); + #endif // __cocos2dx_csloader_h__ diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_studio_auto.cpp b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_studio_auto.cpp index d92c0e08246e..49b42f4482b6 100644 --- a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_studio_auto.cpp +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_studio_auto.cpp @@ -21341,6 +21341,354 @@ int lua_register_cocos2dx_studio_ActionTimeline(lua_State* tolua_S) g_typeCast["ActionTimeline"] = "ccs.ActionTimeline"; return 1; } + +int lua_cocos2dx_studio_ActionTimelineNode_getRoot(lua_State* tolua_S) +{ + int argc = 0; + cocostudio::timeline::ActionTimelineNode* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccs.ActionTimelineNode",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocostudio::timeline::ActionTimelineNode*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_studio_ActionTimelineNode_getRoot'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 0) + { + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_studio_ActionTimelineNode_getRoot'", nullptr); + return 0; + } + cocos2d::Node* ret = cobj->getRoot(); + object_to_luaval(tolua_S, "cc.Node",(cocos2d::Node*)ret); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccs.ActionTimelineNode:getRoot",argc, 0); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_studio_ActionTimelineNode_getRoot'.",&tolua_err); +#endif + + return 0; +} +int lua_cocos2dx_studio_ActionTimelineNode_getActionTimeline(lua_State* tolua_S) +{ + int argc = 0; + cocostudio::timeline::ActionTimelineNode* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccs.ActionTimelineNode",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocostudio::timeline::ActionTimelineNode*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_studio_ActionTimelineNode_getActionTimeline'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 0) + { + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_studio_ActionTimelineNode_getActionTimeline'", nullptr); + return 0; + } + cocostudio::timeline::ActionTimeline* ret = cobj->getActionTimeline(); + object_to_luaval(tolua_S, "ccs.ActionTimeline",(cocostudio::timeline::ActionTimeline*)ret); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccs.ActionTimelineNode:getActionTimeline",argc, 0); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_studio_ActionTimelineNode_getActionTimeline'.",&tolua_err); +#endif + + return 0; +} +int lua_cocos2dx_studio_ActionTimelineNode_setActionTimeline(lua_State* tolua_S) +{ + int argc = 0; + cocostudio::timeline::ActionTimelineNode* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccs.ActionTimelineNode",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocostudio::timeline::ActionTimelineNode*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_studio_ActionTimelineNode_setActionTimeline'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 1) + { + cocostudio::timeline::ActionTimeline* arg0; + + ok &= luaval_to_object(tolua_S, 2, "ccs.ActionTimeline",&arg0); + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_studio_ActionTimelineNode_setActionTimeline'", nullptr); + return 0; + } + cobj->setActionTimeline(arg0); + return 0; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccs.ActionTimelineNode:setActionTimeline",argc, 1); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_studio_ActionTimelineNode_setActionTimeline'.",&tolua_err); +#endif + + return 0; +} +int lua_cocos2dx_studio_ActionTimelineNode_init(lua_State* tolua_S) +{ + int argc = 0; + cocostudio::timeline::ActionTimelineNode* cobj = nullptr; + bool ok = true; +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccs.ActionTimelineNode",0,&tolua_err)) goto tolua_lerror; +#endif + cobj = (cocostudio::timeline::ActionTimelineNode*)tolua_tousertype(tolua_S,1,0); +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_studio_ActionTimelineNode_init'", nullptr); + return 0; + } +#endif + argc = lua_gettop(tolua_S)-1; + do{ + if (argc == 2) { + cocos2d::Node* arg0; + ok &= luaval_to_object(tolua_S, 2, "cc.Node",&arg0); + + if (!ok) { break; } + cocostudio::timeline::ActionTimeline* arg1; + ok &= luaval_to_object(tolua_S, 3, "ccs.ActionTimeline",&arg1); + + if (!ok) { break; } + bool ret = cobj->init(arg0, arg1); + tolua_pushboolean(tolua_S,(bool)ret); + return 1; + } + }while(0); + ok = true; + do{ + if (argc == 0) { + bool ret = cobj->init(); + tolua_pushboolean(tolua_S,(bool)ret); + return 1; + } + }while(0); + ok = true; + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccs.ActionTimelineNode:init",argc, 0); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_studio_ActionTimelineNode_init'.",&tolua_err); +#endif + + return 0; +} +int lua_cocos2dx_studio_ActionTimelineNode_setRoot(lua_State* tolua_S) +{ + int argc = 0; + cocostudio::timeline::ActionTimelineNode* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccs.ActionTimelineNode",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocostudio::timeline::ActionTimelineNode*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_studio_ActionTimelineNode_setRoot'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 1) + { + cocos2d::Node* arg0; + + ok &= luaval_to_object(tolua_S, 2, "cc.Node",&arg0); + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_studio_ActionTimelineNode_setRoot'", nullptr); + return 0; + } + cobj->setRoot(arg0); + return 0; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccs.ActionTimelineNode:setRoot",argc, 1); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_studio_ActionTimelineNode_setRoot'.",&tolua_err); +#endif + + return 0; +} +int lua_cocos2dx_studio_ActionTimelineNode_create(lua_State* tolua_S) +{ + int argc = 0; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertable(tolua_S,1,"ccs.ActionTimelineNode",0,&tolua_err)) goto tolua_lerror; +#endif + + argc = lua_gettop(tolua_S) - 1; + + if (argc == 2) + { + cocos2d::Node* arg0; + cocostudio::timeline::ActionTimeline* arg1; + ok &= luaval_to_object(tolua_S, 2, "cc.Node",&arg0); + ok &= luaval_to_object(tolua_S, 3, "ccs.ActionTimeline",&arg1); + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_studio_ActionTimelineNode_create'", nullptr); + return 0; + } + cocostudio::timeline::ActionTimelineNode* ret = cocostudio::timeline::ActionTimelineNode::create(arg0, arg1); + object_to_luaval(tolua_S, "ccs.ActionTimelineNode",(cocostudio::timeline::ActionTimelineNode*)ret); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d\n ", "ccs.ActionTimelineNode:create",argc, 2); + return 0; +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_studio_ActionTimelineNode_create'.",&tolua_err); +#endif + return 0; +} +int lua_cocos2dx_studio_ActionTimelineNode_constructor(lua_State* tolua_S) +{ + int argc = 0; + cocostudio::timeline::ActionTimelineNode* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + + + argc = lua_gettop(tolua_S)-1; + if (argc == 0) + { + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_studio_ActionTimelineNode_constructor'", nullptr); + return 0; + } + cobj = new cocostudio::timeline::ActionTimelineNode(); + cobj->autorelease(); + int ID = (int)cobj->_ID ; + int* luaID = &cobj->_luaID ; + toluafix_pushusertype_ccobject(tolua_S, ID, luaID, (void*)cobj,"ccs.ActionTimelineNode"); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccs.ActionTimelineNode:ActionTimelineNode",argc, 0); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_studio_ActionTimelineNode_constructor'.",&tolua_err); +#endif + + return 0; +} + +static int lua_cocos2dx_studio_ActionTimelineNode_finalize(lua_State* tolua_S) +{ + printf("luabindings: finalizing LUA object (ActionTimelineNode)"); + return 0; +} + +int lua_register_cocos2dx_studio_ActionTimelineNode(lua_State* tolua_S) +{ + tolua_usertype(tolua_S,"ccs.ActionTimelineNode"); + tolua_cclass(tolua_S,"ActionTimelineNode","ccs.ActionTimelineNode","cc.Node",nullptr); + + tolua_beginmodule(tolua_S,"ActionTimelineNode"); + tolua_function(tolua_S,"new",lua_cocos2dx_studio_ActionTimelineNode_constructor); + tolua_function(tolua_S,"getRoot",lua_cocos2dx_studio_ActionTimelineNode_getRoot); + tolua_function(tolua_S,"getActionTimeline",lua_cocos2dx_studio_ActionTimelineNode_getActionTimeline); + tolua_function(tolua_S,"setActionTimeline",lua_cocos2dx_studio_ActionTimelineNode_setActionTimeline); + tolua_function(tolua_S,"init",lua_cocos2dx_studio_ActionTimelineNode_init); + tolua_function(tolua_S,"setRoot",lua_cocos2dx_studio_ActionTimelineNode_setRoot); + tolua_function(tolua_S,"create", lua_cocos2dx_studio_ActionTimelineNode_create); + tolua_endmodule(tolua_S); + std::string typeName = typeid(cocostudio::timeline::ActionTimelineNode).name(); + g_luaType[typeName] = "ccs.ActionTimelineNode"; + g_typeCast["ActionTimelineNode"] = "ccs.ActionTimelineNode"; + return 1; +} TOLUA_API int register_all_cocos2dx_studio(lua_State* tolua_S) { tolua_open(tolua_S); @@ -21348,6 +21696,7 @@ TOLUA_API int register_all_cocos2dx_studio(lua_State* tolua_S) tolua_module(tolua_S,"ccs",0); tolua_beginmodule(tolua_S,"ccs"); + lua_register_cocos2dx_studio_ActionTimelineNode(tolua_S); lua_register_cocos2dx_studio_ActionFrame(tolua_S); lua_register_cocos2dx_studio_ActionRotationFrame(tolua_S); lua_register_cocos2dx_studio_Frame(tolua_S); diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_studio_auto.hpp b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_studio_auto.hpp index 4d6cac2de3f9..2286bc7daae4 100644 --- a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_studio_auto.hpp +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_studio_auto.hpp @@ -481,6 +481,14 @@ int register_all_cocos2dx_studio(lua_State* tolua_S); + + + + + + + + diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.cpp b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.cpp index 070dbf613eea..d630b0b075ef 100644 --- a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.cpp +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.cpp @@ -867,6 +867,55 @@ int lua_register_cocos2dx_ui_RelativeLayoutParameter(lua_State* tolua_S) return 1; } +int lua_cocos2dx_ui_Widget_setLayoutComponentEnabled(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::ui::Widget* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccui.Widget",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::ui::Widget*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_ui_Widget_setLayoutComponentEnabled'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 1) + { + bool arg0; + + ok &= luaval_to_boolean(tolua_S, 2,&arg0, "ccui.Widget:setLayoutComponentEnabled"); + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_ui_Widget_setLayoutComponentEnabled'", nullptr); + return 0; + } + cobj->setLayoutComponentEnabled(arg0); + return 0; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccui.Widget:setLayoutComponentEnabled",argc, 1); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_ui_Widget_setLayoutComponentEnabled'.",&tolua_err); +#endif + + return 0; +} int lua_cocos2dx_ui_Widget_setSizePercent(lua_State* tolua_S) { int argc = 0; @@ -3127,6 +3176,53 @@ int lua_cocos2dx_ui_Widget_hitTest(lua_State* tolua_S) return 0; } +int lua_cocos2dx_ui_Widget_isLayoutComponentEnabled(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::ui::Widget* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccui.Widget",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::ui::Widget*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_ui_Widget_isLayoutComponentEnabled'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 0) + { + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_ui_Widget_isLayoutComponentEnabled'", nullptr); + return 0; + } + bool ret = cobj->isLayoutComponentEnabled(); + tolua_pushboolean(tolua_S,(bool)ret); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccui.Widget:isLayoutComponentEnabled",argc, 0); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_ui_Widget_isLayoutComponentEnabled'.",&tolua_err); +#endif + + return 0; +} int lua_cocos2dx_ui_Widget_requestFocus(lua_State* tolua_S) { int argc = 0; @@ -4020,6 +4116,7 @@ int lua_register_cocos2dx_ui_Widget(lua_State* tolua_S) tolua_beginmodule(tolua_S,"Widget"); tolua_function(tolua_S,"new",lua_cocos2dx_ui_Widget_constructor); + tolua_function(tolua_S,"setLayoutComponentEnabled",lua_cocos2dx_ui_Widget_setLayoutComponentEnabled); tolua_function(tolua_S,"setSizePercent",lua_cocos2dx_ui_Widget_setSizePercent); tolua_function(tolua_S,"getCustomSize",lua_cocos2dx_ui_Widget_getCustomSize); tolua_function(tolua_S,"getLeftBoundary",lua_cocos2dx_ui_Widget_getLeftBoundary); @@ -4067,6 +4164,7 @@ int lua_register_cocos2dx_ui_Widget(lua_State* tolua_S) tolua_function(tolua_S,"isPropagateTouchEvents",lua_cocos2dx_ui_Widget_isPropagateTouchEvents); tolua_function(tolua_S,"getCurrentFocusedWidget",lua_cocos2dx_ui_Widget_getCurrentFocusedWidget); tolua_function(tolua_S,"hitTest",lua_cocos2dx_ui_Widget_hitTest); + tolua_function(tolua_S,"isLayoutComponentEnabled",lua_cocos2dx_ui_Widget_isLayoutComponentEnabled); tolua_function(tolua_S,"requestFocus",lua_cocos2dx_ui_Widget_requestFocus); tolua_function(tolua_S,"updateSizeAndPosition",lua_cocos2dx_ui_Widget_updateSizeAndPosition); tolua_function(tolua_S,"getTouchMovePosition",lua_cocos2dx_ui_Widget_getTouchMovePosition); @@ -18174,6 +18272,44 @@ int lua_cocos2dx_ui_Helper_seekWidgetByTag(lua_State* tolua_S) #endif return 0; } +int lua_cocos2dx_ui_Helper_restrictCapInsetRect(lua_State* tolua_S) +{ + int argc = 0; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertable(tolua_S,1,"ccui.Helper",0,&tolua_err)) goto tolua_lerror; +#endif + + argc = lua_gettop(tolua_S) - 1; + + if (argc == 2) + { + cocos2d::Rect arg0; + cocos2d::Size arg1; + ok &= luaval_to_rect(tolua_S, 2, &arg0, "ccui.Helper:restrictCapInsetRect"); + ok &= luaval_to_size(tolua_S, 3, &arg1, "ccui.Helper:restrictCapInsetRect"); + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_ui_Helper_restrictCapInsetRect'", nullptr); + return 0; + } + cocos2d::Rect ret = cocos2d::ui::Helper::restrictCapInsetRect(arg0, arg1); + rect_to_luaval(tolua_S, ret); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d\n ", "ccui.Helper:restrictCapInsetRect",argc, 2); + return 0; +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_ui_Helper_restrictCapInsetRect'.",&tolua_err); +#endif + return 0; +} int lua_cocos2dx_ui_Helper_doLayout(lua_State* tolua_S) { int argc = 0; @@ -18226,6 +18362,7 @@ int lua_register_cocos2dx_ui_Helper(lua_State* tolua_S) tolua_function(tolua_S,"seekActionWidgetByActionTag", lua_cocos2dx_ui_Helper_seekActionWidgetByActionTag); tolua_function(tolua_S,"seekWidgetByName", lua_cocos2dx_ui_Helper_seekWidgetByName); tolua_function(tolua_S,"seekWidgetByTag", lua_cocos2dx_ui_Helper_seekWidgetByTag); + tolua_function(tolua_S,"restrictCapInsetRect", lua_cocos2dx_ui_Helper_restrictCapInsetRect); tolua_function(tolua_S,"doLayout", lua_cocos2dx_ui_Helper_doLayout); tolua_endmodule(tolua_S); std::string typeName = typeid(cocos2d::ui::Helper).name(); diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.hpp b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.hpp index b3d1c1de3cf8..e9f6ed54cbfa 100644 --- a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.hpp +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.hpp @@ -485,6 +485,9 @@ int register_all_cocos2dx_ui(lua_State* tolua_S); + + + diff --git a/cocos/scripting/lua-bindings/manual/CCLuaStack.cpp b/cocos/scripting/lua-bindings/manual/CCLuaStack.cpp index 5a918d57eb4f..8a33aa14346b 100644 --- a/cocos/scripting/lua-bindings/manual/CCLuaStack.cpp +++ b/cocos/scripting/lua-bindings/manual/CCLuaStack.cpp @@ -274,10 +274,20 @@ int LuaStack::executeString(const char *codes) int LuaStack::executeScriptFile(const char* filename) { - std::string code("require \""); - code.append(filename); - code.append("\""); - return executeString(code.c_str()); + CCAssert(filename, "CCLuaStack::executeScriptFile() - invalid filename"); + + FileUtils *utils = FileUtils::getInstance(); + std::string fullPath = utils->fullPathForFilename(filename); + Data data = utils->getDataFromFile(fullPath); + int rn = 0; + if (!data.isNull()) + { + if (luaLoadBuffer(_state, (const char*)data.getBytes(), (int)data.getSize(), fullPath.c_str()) == 0) + { + rn = executeFunction(0); + } + } + return rn; } int LuaStack::executeGlobalFunction(const char* functionName) diff --git a/cocos/scripting/lua-bindings/manual/cocostudio/lua_cocos2dx_csloader_manual.cpp b/cocos/scripting/lua-bindings/manual/cocostudio/lua_cocos2dx_csloader_manual.cpp index 5928dd5df859..3525f2940ac0 100644 --- a/cocos/scripting/lua-bindings/manual/cocostudio/lua_cocos2dx_csloader_manual.cpp +++ b/cocos/scripting/lua-bindings/manual/cocostudio/lua_cocos2dx_csloader_manual.cpp @@ -28,6 +28,7 @@ #include "CCLuaEngine.h" #include "ActionTimeline/CCActionTimeline.h" #include "ActionTimeline/CSLoader.h" +#include "ActionTimeline/CCActionTimelineNode.h" int lua_cocos2dx_csloader_CSLoader_createTimeline(lua_State* tolua_S) { @@ -63,6 +64,65 @@ int lua_cocos2dx_csloader_CSLoader_createTimeline(lua_State* tolua_S) return 0; } +int lua_cocos2dx_csloader_CSLoader_createActionTimelineNode(lua_State* tolua_S) +{ + int argc = 0; + bool ok = true; +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertable(tolua_S, 1, "cc.CSLoader", 0, &tolua_err)) goto tolua_lerror; +#endif + + argc = lua_gettop(tolua_S) - 1; + + do + { + if (argc == 4) + { + std::string arg0; + ok &= luaval_to_std_string(tolua_S, 2, &arg0, "cc.CSLoader:createActionTimelineNode"); + if (!ok) { break; } + int arg1; + ok &= luaval_to_int32(tolua_S, 3, (int *)&arg1, "cc.CSLoader:createActionTimelineNode"); + if (!ok) { break; } + int arg2; + ok &= luaval_to_int32(tolua_S, 4, (int *)&arg2, "cc.CSLoader:createActionTimelineNode"); + if (!ok) { break; } + bool arg3; + ok &= luaval_to_boolean(tolua_S, 5, &arg3, "cc.CSLoader:createActionTimelineNode"); + if (!ok) { break; } + cocostudio::timeline::ActionTimelineNode* ret = cocos2d::CSLoader::createActionTimelineNode(arg0, arg1, arg2, arg3); + object_to_luaval(tolua_S, "ccs.ActionTimelineNode", (cocostudio::timeline::ActionTimelineNode*)ret); + return 1; + } + } while (0); + ok = true; + do + { + if (argc == 1) + { + std::string arg0; + ok &= luaval_to_std_string(tolua_S, 2, &arg0, "cc.CSLoader:createActionTimelineNode"); + if (!ok) { break; } + cocostudio::timeline::ActionTimelineNode* ret = cocos2d::CSLoader::createActionTimelineNode(arg0); + object_to_luaval(tolua_S, "ccs.ActionTimelineNode", (cocostudio::timeline::ActionTimelineNode*)ret); + return 1; + } + } while (0); + ok = true; + CCLOG("%s has wrong number of arguments: %d, was expecting %d", "cc.CSLoader:createActionTimelineNode", argc, 1); + return 0; +#if COCOS2D_DEBUG >= 1 +tolua_lerror: + tolua_error(tolua_S, "#ferror in function 'lua_cocos2dx_csloader_CSLoader_createActionTimelineNode'.", &tolua_err); +#endif + return 0; + +} + int register_all_cocos2dx_csloader_manual(lua_State* L) { lua_pushstring(L, "cc.CSLoader"); @@ -70,6 +130,7 @@ int register_all_cocos2dx_csloader_manual(lua_State* L) if (lua_istable(L,-1)) { tolua_function(L, "createTimeline", lua_cocos2dx_csloader_CSLoader_createTimeline); + tolua_function(L, "createActionTimelineNode", lua_cocos2dx_csloader_CSLoader_createActionTimelineNode); } lua_pop(L, 1); diff --git a/cocos/ui/UIHelper.cpp b/cocos/ui/UIHelper.cpp index 8335944b5530..b523dcb44a40 100644 --- a/cocos/ui/UIHelper.cpp +++ b/cocos/ui/UIHelper.cpp @@ -167,19 +167,7 @@ void Helper::doLayout(cocos2d::Node *rootNode) if (nullptr != com && nullptr != parent) { LayoutComponent* layoutComponent = (LayoutComponent*)com; - if (layoutComponent->isUsingPercentPosition()) - { - layoutComponent->setPercentPosition(layoutComponent->getPercentPosition()); - } - else if (layoutComponent->getReferencePoint() != LayoutComponent::ReferencePoint::BOTTOM_LEFT) - { - layoutComponent->setRelativePosition(layoutComponent->getRelativePosition()); - } - - if (layoutComponent->isUsingPercentContentSize()) - { - layoutComponent->setPercentContentSize(layoutComponent->getPercentContentSize()); - } + layoutComponent->refreshLayout(); } } } diff --git a/cocos/ui/UIHelper.h b/cocos/ui/UIHelper.h index 3562dec58811..09fa7589e8d4 100644 --- a/cocos/ui/UIHelper.h +++ b/cocos/ui/UIHelper.h @@ -79,6 +79,12 @@ class CC_GUI_DLL Helper std::string::size_type start, std::string::size_type length); + /** + * Refresh object and it's children layout state + * + *@param rootNode object which will be changed + * + */ static void doLayout(Node *rootNode); static void changeLayoutSystemActiveState(bool bActive); diff --git a/cocos/ui/UILayoutComponent.cpp b/cocos/ui/UILayoutComponent.cpp index 64f6f39beba9..907cafc0298a 100644 --- a/cocos/ui/UILayoutComponent.cpp +++ b/cocos/ui/UILayoutComponent.cpp @@ -1,18 +1,18 @@ /**************************************************************************** Copyright (c) 2013-2014 Chukong Technologies Inc. - + http://www.cocos2d-x.org - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -25,25 +25,55 @@ #include "UILayoutComponent.h" #include "2d/CCNode.h" #include "GUIDefine.h" - +#include "UIHelper.h" NS_CC_BEGIN namespace ui { LayoutComponent::LayoutComponent() - : _usingPercentContentSize(false) - , _referencePoint(ReferencePoint::BOTTOM_LEFT) - , _usingPercentPosition(false) - , _actived(true) + :_horizontalEdge(HorizontalEdge::None) + , _verticalEdge(VerticalEdge::None) + , _leftMargin(0) + , _rightMargin(0) + , _bottomMargin(0) + , _topMargin(0) + , _usingPositionPercentX(false) + , _positionPercentX(0) + , _usingPositionPercentY(false) + , _positionPercentY(0) + , _usingStretchWidth(false) + , _usingStretchHeight(false) + , _percentWidth(0) + , _usingPercentWidth(false) + , _percentHeight(0) + , _usingPercentHeight(false) + , _actived(true) { _name = __LAYOUT_COMPONENT_NAME; } - + LayoutComponent::~LayoutComponent() { - + + } + + LayoutComponent* LayoutComponent::boundingLayoutComponent(Node* node) + { + LayoutComponent * layout = (LayoutComponent*)node->getComponent(__LAYOUT_COMPONENT_NAME); + if (layout != nullptr) + return layout; + + layout = new (std::nothrow) LayoutComponent(); + if (layout && layout->init()) + { + layout->autorelease(); + node->addComponent(layout); + return layout; + } + CC_SAFE_DELETE(layout); + return nullptr; } - + bool LayoutComponent::init() { bool ret = true; @@ -54,253 +84,571 @@ namespace ui { ret = false; break; } - + //put layout component initalized code here - + } while (0); return ret; } - - //Size - Vec2 LayoutComponent::getOwnerContentSize()const + + Node* LayoutComponent::getOwnerParent() { - return this->getOwner()->getContentSize(); + Node* parent = _owner->getParent(); + return parent; } - void LayoutComponent::setOwnerContentSize(const Vec2& size) + void LayoutComponent::refreshHorizontalMargin() { - this->getOwner()->setContentSize(Size(size.x,size.y)); + Node* parent = this->getOwnerParent(); + if (parent == nullptr) + return; - Node* parentNode = this->getOwner()->getParent(); - if (parentNode != NULL && _actived) + const Point& ownerPoint = _owner->getPosition(); + const Point& ownerAnchor = _owner->getAnchorPoint(); + const Size& ownerSize = _owner->getContentSize(); + const Size& parentSize = parent->getContentSize(); + + _leftMargin = ownerPoint.x - ownerAnchor.x * ownerSize.width; + _rightMargin = parentSize.width - (ownerPoint.x + (1 - ownerAnchor.x) * ownerSize.width); + } + void LayoutComponent::refreshVerticalMargin() + { + Node* parent = this->getOwnerParent(); + if (parent == nullptr) + return; + + const Point& ownerPoint = _owner->getPosition(); + const Point& ownerAnchor = _owner->getAnchorPoint(); + const Size& ownerSize = _owner->getContentSize(); + const Size& parentSize = parent->getContentSize(); + + _bottomMargin = ownerPoint.y - ownerAnchor.y * ownerSize.height; + _topMargin = parentSize.height - (ownerPoint.y + (1 - ownerAnchor.y) * ownerSize.height); + } + + //OldVersion + void LayoutComponent::setUsingPercentContentSize(bool isUsed) + { + _usingPercentWidth = _usingPercentHeight = isUsed; + } + bool LayoutComponent::getUsingPercentContentSize()const + { + return _usingPercentWidth && _usingPercentHeight; + } + + void LayoutComponent::setPercentContentSize(const Vec2 &percent) + { + this->setPercentWidth(percent.x); + this->setPercentHeight(percent.y); + } + Vec2 LayoutComponent::getPercentContentSize()const + { + Vec2 vec2=Vec2(_percentWidth,_percentHeight); + return vec2; + } + + //Position & Margin + const Point& LayoutComponent::getAnchorPosition()const + { + return _owner->getAnchorPoint(); + } + void LayoutComponent::setAnchorPosition(const Point& point) + { + Rect oldRect = _owner->getBoundingBox(); + _owner->setAnchorPoint(point); + Rect newRect = _owner->getBoundingBox(); + float offSetX = oldRect.origin.x - newRect.origin.x; + float offSetY = oldRect.origin.y - newRect.origin.y; + + Point ownerPosition = _owner->getPosition(); + ownerPosition.x += offSetX; + ownerPosition.y += offSetY; + + this->setPosition(ownerPosition); + } + + const Point& LayoutComponent::getPosition()const + { + return _owner->getPosition(); + } + void LayoutComponent::setPosition(const Point& position) + { + Node* parent = this->getOwnerParent(); + if (parent != nullptr) { - Size parentSize = parentNode->getContentSize(); + Point ownerPoint = position; + const Size& parentSize = parent->getContentSize(); - if (parentSize.width != 0 && parentSize.height != 0) + if (parentSize.width != 0) + _positionPercentX = ownerPoint.x / parentSize.width; + else { - _percentContentSize = Point(size.x/parentSize.width,size.y/parentSize.height); + _positionPercentX = 0; + if (_usingPositionPercentX) + ownerPoint.x = 0; } + + if (parentSize.height != 0) + _positionPercentY = ownerPoint.y / parentSize.height; else { - _percentContentSize = Point(0,0); + _positionPercentY = 0; + if (_usingPositionPercentY) + ownerPoint.y = 0; } + + _owner->setPosition(ownerPoint); + + this->refreshHorizontalMargin(); + this->refreshVerticalMargin(); + } + else + _owner->setPosition(position); + } + + bool LayoutComponent::isPositionPercentXEnabled()const + { + return _usingPositionPercentX; + } + void LayoutComponent::setPositionPercentXEnabled(bool isUsed) + { + _usingPositionPercentX = isUsed; + if (_usingPositionPercentX) + { + _horizontalEdge = HorizontalEdge::None; } } - const Vec2& LayoutComponent::getPercentContentSize()const + float LayoutComponent::getPositionPercentX()const { - return _percentContentSize; + return _positionPercentX; } - - void LayoutComponent::setPercentContentSize(const Vec2& percent) + void LayoutComponent::setPositionPercentX(float percentMargin) { - _percentContentSize = percent; + _positionPercentX = percentMargin; - Node* parentNode = this->getOwner()->getParent(); - if (parentNode != NULL && _actived) + Node* parent = this->getOwnerParent(); + if (parent != nullptr) { - Size parentSize = parentNode->getContentSize(); - if (_usingPercentContentSize) - { - this->getOwner()->setContentSize(Size(percent.x*parentSize.width,percent.y*parentSize.height)); - } + _owner->setPositionX(parent->getContentSize().width * _positionPercentX); + this->refreshHorizontalMargin(); } } - - bool LayoutComponent::isUsingPercentContentSize() + + bool LayoutComponent::isPositionPercentYEnabled()const + { + return _usingPositionPercentY; + } + void LayoutComponent::setPositionPercentYEnabled(bool isUsed) { - return _usingPercentContentSize; + _usingPositionPercentY = isUsed; + if (_usingPositionPercentY) + { + _verticalEdge = VerticalEdge::None; + } } - void LayoutComponent::setUsingPercentContentSize(bool flag) + float LayoutComponent::getPositionPercentY()const + { + return _positionPercentY; + } + void LayoutComponent::setPositionPercentY(float percentMargin) { - _usingPercentContentSize = flag; + _positionPercentY = percentMargin; - Node* parentNode = this->getOwner()->getParent(); - if (parentNode != NULL && _actived) + Node* parent = this->getOwnerParent(); + if (parent != nullptr) { - Size parentSize = parentNode->getContentSize(); - if (_usingPercentContentSize) - { - Size baseSize = this->getOwner()->getContentSize(); - if (parentSize.width != 0) - { - _percentContentSize.x = baseSize.width/parentSize.width; - } - else - { - _percentContentSize.x = 0; - baseSize.width = 0; - } - - if (parentSize.height != 0) - { - _percentContentSize.y = baseSize.height/parentSize.height; - } - else - { - _percentContentSize.y = 0; - baseSize.height = 0; - } - - this->getOwner()->setContentSize(baseSize); - } + _owner->setPositionY(parent->getContentSize().height * _positionPercentY); + this->refreshVerticalMargin(); } } - //Position - bool LayoutComponent::isUsingPercentPosition() + LayoutComponent::HorizontalEdge LayoutComponent::getHorizontalEdge()const { - return _usingPercentPosition; + return _horizontalEdge; } - void LayoutComponent::setUsingPercentPosition(bool flag) + void LayoutComponent::setHorizontalEdge(HorizontalEdge hEage) { - _usingPercentPosition = flag; - - Node* parentNode = this->getOwner()->getParent(); - if (parentNode != NULL && _actived) + _horizontalEdge = hEage; + if (_horizontalEdge != HorizontalEdge::None) { - Size parentSize = parentNode->getContentSize(); + _usingPositionPercentX = false; + } - if (_usingPercentPosition) + Node* parent = this->getOwnerParent(); + if (parent != nullptr) + { + Point ownerPoint = _owner->getPosition(); + const Size& parentSize = parent->getContentSize(); + if (parentSize.width != 0) + _positionPercentX = ownerPoint.x / parentSize.width; + else { - if (parentSize.width != 0) - { - _percentPosition.x = _relativePosition.x/parentSize.width; - } - else - { - _percentPosition.x = 0; - _relativePosition.x = 0; - } - - if (parentSize.height != 0) - { - _percentPosition.y = _relativePosition.y/parentSize.height; - } - else - { - _percentPosition.y = 0; - _relativePosition.y = 0; - } + _positionPercentX = 0; + ownerPoint.x = 0; + if (_usingPositionPercentX) + _owner->setPosition(ownerPoint); } - Point inversePoint = this->converPointWithReferencePointAndSize(_relativePosition,parentSize); - this->getOwner()->setPosition(inversePoint); + this->refreshHorizontalMargin(); } } - const Vec2& LayoutComponent::getPercentPosition() + LayoutComponent::VerticalEdge LayoutComponent::getVerticalEdge()const { - return _percentPosition; + return _verticalEdge; } - void LayoutComponent::setPercentPosition(const Vec2& percent) + void LayoutComponent::setVerticalEdge(VerticalEdge vEage) { - _percentPosition = percent; + _verticalEdge = vEage; + if (_verticalEdge != VerticalEdge::None) + { + _usingPositionPercentY = false; + } - Node* parentNode = this->getOwner()->getParent(); - if (parentNode != NULL && _actived) + Node* parent = this->getOwnerParent(); + if (parent != nullptr) { - Size parentSize = parentNode->getContentSize(); - _relativePosition = Point(_percentPosition.x*parentSize.width,_percentPosition.y*parentSize.height); - Point inversePoint = this->converPointWithReferencePointAndSize(_relativePosition,parentSize); - this->getOwner()->setPosition(inversePoint); + Point ownerPoint = _owner->getPosition(); + const Size& parentSize = parent->getContentSize(); + if (parentSize.height != 0) + _positionPercentY = ownerPoint.y / parentSize.height; + else + { + _positionPercentY = 0; + ownerPoint.y = 0; + if (_usingPositionPercentY) + _owner->setPosition(ownerPoint); + } + + this->refreshVerticalMargin(); } } - const Vec2& LayoutComponent::getOwnerPosition()const + float LayoutComponent::getLeftMargin()const + { + return _leftMargin; + } + void LayoutComponent::setLeftMargin(float margin) + { + _leftMargin = margin; + } + + float LayoutComponent::getRightMargin()const { - return this->getOwner()->getPosition(); + return _rightMargin; } - void LayoutComponent::setOwnerPosition(const Vec2& point) + void LayoutComponent::setRightMargin(float margin) { - Node* parentNode = this->getOwner()->getParent(); - if (parentNode != NULL && _actived) + _rightMargin = margin; + } + + float LayoutComponent::getTopMargin()const + { + return _topMargin; + } + void LayoutComponent::setTopMargin(float margin) + { + _topMargin = margin; + } + + float LayoutComponent::getBottomMargin()const + { + return _bottomMargin; + } + void LayoutComponent::setBottomMargin(float margin) + { + _bottomMargin = margin; + } + + //Size & Percent + const Size& LayoutComponent::getSize()const + { + return this->getOwner()->getContentSize(); + } + void LayoutComponent::setSize(const Size& size) + { + Node* parent = this->getOwnerParent(); + if (parent != nullptr) { - Size parentSize = parentNode->getContentSize(); + Size ownerSize = size; + const Size& parentSize = parent->getContentSize(); - Point inversePoint = this->converPointWithReferencePointAndSize(point,parentSize); - this->getOwner()->setPosition(point); - _relativePosition = inversePoint; - if (parentSize.width != 0 && parentSize.height != 0) + if (parentSize.width != 0) + _percentWidth = ownerSize.width / parentSize.width; + else { - _percentPosition = Point(_relativePosition.x/parentSize.width,_relativePosition.y/parentSize.height); + _percentWidth = 0; + if (_usingPercentWidth) + ownerSize.width = 0; } + + if (parentSize.height != 0) + _percentHeight = ownerSize.height / parentSize.height; else { - _percentPosition = Point(0,0); + _percentHeight = 0; + if (_usingPercentHeight) + ownerSize.height = 0; } + + _owner->setContentSize(ownerSize); + + this->refreshHorizontalMargin(); + this->refreshVerticalMargin(); } else + _owner->setContentSize(size); + } + + bool LayoutComponent::isPercentWidthEnabled()const + { + return _usingPercentWidth; + } + void LayoutComponent::setPercentWidthEnabled(bool isUsed) + { + _usingPercentWidth = isUsed; + if (_usingPercentWidth) + { + _usingStretchWidth = false; + } + } + + float LayoutComponent::getSizeWidth()const + { + return _owner->getContentSize().width; + } + void LayoutComponent::setSizeWidth(float width) + { + Size ownerSize = _owner->getContentSize(); + ownerSize.width = width; + + Node* parent = this->getOwnerParent(); + if (parent != nullptr) { - this->getOwner()->setPosition(point); - if (_referencePoint == ReferencePoint::BOTTOM_LEFT) + const Size& parentSize = parent->getContentSize(); + if (parentSize.width != 0) + _percentWidth = ownerSize.width / parentSize.width; + else { - _relativePosition = point; + _percentWidth = 0; + if (_usingPercentWidth) + ownerSize.width = 0; } + _owner->setContentSize(ownerSize); + this->refreshHorizontalMargin(); } - + else + _owner->setContentSize(ownerSize); } - const Vec2& LayoutComponent::getRelativePosition() + float LayoutComponent::getPercentWidth()const { - return _relativePosition; + return _percentWidth; } - void LayoutComponent::setRelativePosition(const Vec2& position) + void LayoutComponent::setPercentWidth(float percentWidth) { - _relativePosition = position; + _percentWidth = percentWidth; - Node* parentNode = this->getOwner()->getParent(); - if (parentNode != NULL && _actived) + Node* parent = this->getOwnerParent(); + if (parent != nullptr) { - Size parentSize = parentNode->getContentSize(); + Size ownerSize = _owner->getContentSize(); + ownerSize.width = parent->getContentSize().width * _percentWidth; + _owner->setContentSize(ownerSize); - Point inversePoint = this->converPointWithReferencePointAndSize(_relativePosition,parentSize); - this->getOwner()->setPosition(inversePoint); - if (parentSize.width != 0 && parentSize.height != 0) - { - _percentPosition = Point(_relativePosition.x/parentSize.width,_relativePosition.y/parentSize.height); - } + this->refreshHorizontalMargin(); + } + } + + bool LayoutComponent::isPercentHeightEnabled()const + { + return _usingPercentHeight; + } + void LayoutComponent::setPercentHeightEnabled(bool isUsed) + { + _usingPercentHeight = isUsed; + if (_usingPercentHeight) + { + _usingStretchHeight = false; + } + } + + float LayoutComponent::getSizeHeight()const + { + return _owner->getContentSize().height; + } + void LayoutComponent::setSizeHeight(float height) + { + Size ownerSize = _owner->getContentSize(); + ownerSize.height = height; + + Node* parent = this->getOwnerParent(); + if (parent != nullptr) + { + const Size& parentSize = parent->getContentSize(); + if (parentSize.height != 0) + _percentHeight = ownerSize.height / parentSize.height; else { - _percentPosition = Point(0,0); + _percentHeight = 0; + if (_usingPercentHeight) + ownerSize.height = 0; } + _owner->setContentSize(ownerSize); + this->refreshVerticalMargin(); } + else + _owner->setContentSize(ownerSize); } - LayoutComponent::ReferencePoint LayoutComponent::getReferencePoint() + float LayoutComponent::getPercentHeight()const { - return _referencePoint; + return _percentHeight; } - void LayoutComponent::setReferencePoint(ReferencePoint point) + void LayoutComponent::setPercentHeight(float percentHeight) { - _referencePoint = point; - this->setRelativePosition(_relativePosition); + _percentHeight = percentHeight; + + Node* parent = this->getOwnerParent(); + if (parent != nullptr) + { + Size ownerSize = _owner->getContentSize(); + ownerSize.height = parent->getContentSize().height * _percentHeight; + _owner->setContentSize(ownerSize); + + this->refreshVerticalMargin(); + } } - void LayoutComponent::setActiveEnable(bool enable) + bool LayoutComponent::isStretchWidthEnabled()const { - _actived = enable; + return _usingStretchWidth; + } + void LayoutComponent::setStretchWidthEnabled(bool isUsed) + { + _usingStretchWidth = isUsed; + if (_usingStretchWidth) + { + _usingPercentWidth = false; + } + } + + bool LayoutComponent::isStretchHeightEnabled()const + { + return _usingStretchHeight; + } + void LayoutComponent::setStretchHeightEnabled(bool isUsed) + { + _usingStretchHeight = isUsed; + if (_usingStretchHeight) + { + _usingPercentHeight = false; + } } - Vec2 LayoutComponent::converPointWithReferencePointAndSize(const Vec2& point,const Size& size) + void LayoutComponent::refreshLayout() { - Point inversePoint = point; - switch (_referencePoint) + Node* parent = this->getOwnerParent(); + if (parent == nullptr) + return; + + const Size& parentSize = parent->getContentSize(); + const Point& ownerAnchor = _owner->getAnchorPoint(); + Size ownerSize = _owner->getContentSize(); + Point ownerPosition = _owner->getPosition(); + + switch (this->_horizontalEdge) + { + case HorizontalEdge::None: + if (_usingStretchWidth) + { + ownerSize.width = parentSize.width * _percentWidth; + ownerPosition.x = _leftMargin + ownerAnchor.x * ownerSize.width; + } + else + { + if (_usingPositionPercentX) + ownerPosition.x = parentSize.width * _positionPercentX; + if (_usingPercentWidth) + ownerSize.width = parentSize.width * _percentWidth; + } + break; + case HorizontalEdge::Left: + if (_usingPercentWidth || _usingStretchWidth) + ownerSize.width = parentSize.width * _percentWidth; + ownerPosition.x = _leftMargin + ownerAnchor.x * ownerSize.width; + break; + case HorizontalEdge::Right: + if (_usingPercentWidth || _usingStretchWidth) + ownerSize.width = parentSize.width * _percentWidth; + ownerPosition.x = parentSize.width - (_rightMargin + (1 - ownerAnchor.x) * ownerSize.width); + break; + case HorizontalEdge::Center: + if (_usingPercentWidth || _usingStretchWidth) + { + ownerSize.width = parentSize.width - _leftMargin - _rightMargin; + if (ownerSize.width < 0) + ownerSize.width = 0; + ownerPosition.x = _leftMargin + ownerAnchor.x * ownerSize.width; + } + else + ownerPosition.x = parentSize.width * _positionPercentX; + break; + default: + break; + } + + switch (this->_verticalEdge) { - case ReferencePoint::TOP_LEFT: - inversePoint.y = size.height - inversePoint.y; + case VerticalEdge::None: + if (_usingStretchHeight) + { + ownerSize.height = parentSize.height * _percentHeight; + ownerPosition.y = _bottomMargin + ownerAnchor.y * ownerSize.height; + } + else + { + if (_usingPositionPercentY) + ownerPosition.y = parentSize.height * _positionPercentY; + if (_usingPercentHeight) + ownerSize.height = parentSize.height * _percentHeight; + } + break; + case VerticalEdge::Bottom: + if (_usingPercentHeight || _usingStretchHeight) + ownerSize.height = parentSize.height * _percentHeight; + ownerPosition.y = _bottomMargin + ownerAnchor.y * ownerSize.height; break; - case ReferencePoint::BOTTOM_RIGHT: - inversePoint.x = size.width - inversePoint.x; + case VerticalEdge::Top: + if (_usingPercentHeight || _usingStretchHeight) + ownerSize.height = parentSize.height * _percentHeight; + ownerPosition.y = parentSize.height - (_topMargin + (1 - ownerAnchor.y) * ownerSize.height); break; - case ReferencePoint::TOP_RIGHT: - inversePoint.x = size.width - inversePoint.x; - inversePoint.y = size.height - inversePoint.y; + case VerticalEdge::Center: + if (_usingPercentHeight || _usingStretchHeight) + { + ownerSize.height = parentSize.height - _topMargin - _bottomMargin; + if (ownerSize.height < 0) + ownerSize.height = 0; + ownerPosition.y = _bottomMargin + ownerAnchor.y * ownerSize.height; + } + else + ownerPosition.y = parentSize.height* _positionPercentY; break; default: break; } - return inversePoint; + + _owner->setPosition(ownerPosition); + _owner->setContentSize(ownerSize); + + ui::Helper::doLayout(_owner); + } + + void LayoutComponent::setActiveEnabled(bool enable) + { + _actived = enable; } } diff --git a/cocos/ui/UILayoutComponent.h b/cocos/ui/UILayoutComponent.h index b45b5ad7c0f7..a824e7e19012 100644 --- a/cocos/ui/UILayoutComponent.h +++ b/cocos/ui/UILayoutComponent.h @@ -29,68 +29,136 @@ THE SOFTWARE. NS_CC_BEGIN - namespace ui { - class CC_GUI_DLL LayoutComponent : public Component +namespace ui { + class CC_GUI_DLL LayoutComponent : public Component + { + public: + LayoutComponent(); + ~LayoutComponent(); + virtual bool init()override; + CREATE_FUNC(LayoutComponent); + + static LayoutComponent* boundingLayoutComponent(Node* node); + + enum class HorizontalEdge { - public: - LayoutComponent(); - ~LayoutComponent(); - virtual bool init()override; - CREATE_FUNC(LayoutComponent); - /** - * When a node has a ReferencePositoin with value equals LEFT_BOTTOM, - * it will treat the left bottom corner of its parent as the origin(0,0) when positioning itself - * which is the same as cocos2d-x does. But you can change it by assigning a - * different ReferencePosition. - * For example: If you use ReferencePosition with value equals RIGHT_TOP, - * then it will treat the right top corner of its parent as the origin(0,0) when positioning itself. - */ - enum class ReferencePoint - { - BOTTOM_LEFT, - TOP_LEFT, - BOTTOM_RIGHT, - TOP_RIGHT - }; - - bool isUsingPercentPosition(); - void setUsingPercentPosition(bool flag); - - const Vec2& getPercentPosition(); - void setPercentPosition(const Vec2& percent); - - const Vec2& getRelativePosition(); - void setRelativePosition(const Vec2& position); - - void setReferencePoint(ReferencePoint point); - ReferencePoint getReferencePoint(); - - const Vec2& getOwnerPosition()const; - void setOwnerPosition(const Vec2& point); - - Vec2 getOwnerContentSize()const; - void setOwnerContentSize(const Vec2& size); - - const Vec2& getPercentContentSize()const; - void setPercentContentSize(const Vec2& percent); - - bool isUsingPercentContentSize(); - void setUsingPercentContentSize(bool flag); - - void setActiveEnable(bool enable); - private: - Vec2 converPointWithReferencePointAndSize(const Vec2& point,const Size& size); - private: - - Vec2 _percentContentSize; - bool _usingPercentContentSize; - - ReferencePoint _referencePoint; - Vec2 _relativePosition; - Vec2 _percentPosition; - bool _usingPercentPosition; - bool _actived; + None, + Left, + Right, + Center }; + enum class VerticalEdge + { + None, + Bottom, + Top, + Center + }; + + // OldVersion + void setUsingPercentContentSize(bool isUsed); + bool getUsingPercentContentSize()const; + + void setPercentContentSize(const Vec2 &percent); + Vec2 getPercentContentSize()const; + + // Position & Margin + const Point& getAnchorPosition()const; + void setAnchorPosition(const Point& point); + + const Point& getPosition()const; + void setPosition(const Point& position); + + bool isPositionPercentXEnabled()const; + void setPositionPercentXEnabled(bool isUsed); + + float getPositionPercentX()const; + void setPositionPercentX(float percentMargin); + + bool isPositionPercentYEnabled()const; + void setPositionPercentYEnabled(bool isUsed); + + float getPositionPercentY()const; + void setPositionPercentY(float percentMargin); + + HorizontalEdge getHorizontalEdge()const; + void setHorizontalEdge(HorizontalEdge hEage); + + VerticalEdge getVerticalEdge()const; + void setVerticalEdge(VerticalEdge vEage); + + float getLeftMargin()const; + void setLeftMargin(float margin); + + float getRightMargin()const; + void setRightMargin(float margin); + + float getTopMargin()const; + void setTopMargin(float margin); + + float getBottomMargin()const; + void setBottomMargin(float margin); + + // Size & Percent + const Size& getSize()const; + void setSize(const Size& size); + + bool isPercentWidthEnabled()const; + void setPercentWidthEnabled(bool isUsed); + + float getSizeWidth()const; + void setSizeWidth(float width); + + float getPercentWidth()const; + void setPercentWidth(float percentWidth); + + bool isPercentHeightEnabled()const; + void setPercentHeightEnabled(bool isUsed); + + float getSizeHeight()const; + void setSizeHeight(float height); + + float getPercentHeight()const; + void setPercentHeight(float percentHeight); + + bool isStretchWidthEnabled()const; + void setStretchWidthEnabled(bool isUsed); + + bool isStretchHeightEnabled()const; + void setStretchHeightEnabled(bool isUsed); + + void setActiveEnabled(bool enable); + void refreshLayout(); + + protected: + Node* getOwnerParent(); + void refreshHorizontalMargin(); + void refreshVerticalMargin(); + protected: + HorizontalEdge _horizontalEdge; + VerticalEdge _verticalEdge; + + float _leftMargin; + float _rightMargin; + float _bottomMargin; + float _topMargin; + + bool _usingPositionPercentX; + float _positionPercentX; + bool _usingPositionPercentY; + float _positionPercentY; + + bool _usingStretchWidth; + bool _usingStretchHeight; + + float _percentWidth; + bool _usingPercentWidth; + + float _percentHeight; + bool _usingPercentHeight; + + bool _actived; + }; } NS_CC_END diff --git a/cocos/ui/UIWidget.cpp b/cocos/ui/UIWidget.cpp index 2bfa6dae5edd..1dca852496f6 100644 --- a/cocos/ui/UIWidget.cpp +++ b/cocos/ui/UIWidget.cpp @@ -140,6 +140,7 @@ Widget* Widget::_focusedWidget = nullptr; Widget::FocusNavigationController* Widget::_focusNavigationController = nullptr; Widget::Widget(): +_usingLayoutComponent(false), _unifySize(false), _enabled(true), _bright(true), @@ -226,7 +227,8 @@ bool Widget::init() void Widget::onEnter() { - updateSizeAndPosition(); + if (!_usingLayoutComponent) + updateSizeAndPosition(); ProtectedNode::onEnter(); } @@ -285,7 +287,7 @@ void Widget::setContentSize(const cocos2d::Size &contentSize) { _contentSize = getVirtualRendererSize(); } - if (_running) + if (!_usingLayoutComponent && _running) { Widget* widgetParent = getWidgetParent(); Size pSize; @@ -319,29 +321,39 @@ void Widget::setSize(const Size &size) void Widget::setSizePercent(const Vec2 &percent) { - _sizePercent = percent; - Size cSize = _customSize; - if (_running) + if (_usingLayoutComponent) { - Widget* widgetParent = getWidgetParent(); - if (widgetParent) + auto component = this->getOrCreateLayoutComponent(); + component->setUsingPercentContentSize(true); + component->setPercentContentSize(percent); + component->refreshLayout(); + } + else + { + _sizePercent = percent; + Size cSize = _customSize; + if (_running) { - cSize = Size(widgetParent->getContentSize().width * percent.x , widgetParent->getContentSize().height * percent.y); + Widget* widgetParent = getWidgetParent(); + if (widgetParent) + { + cSize = Size(widgetParent->getContentSize().width * percent.x, widgetParent->getContentSize().height * percent.y); + } + else + { + cSize = Size(_parent->getContentSize().width * percent.x, _parent->getContentSize().height * percent.y); + } + } + if (_ignoreSize) + { + this->setContentSize(getVirtualRendererSize()); } else { - cSize = Size(_parent->getContentSize().width * percent.x , _parent->getContentSize().height * percent.y); + this->setContentSize(cSize); } + _customSize = cSize; } - if (_ignoreSize) - { - this->setContentSize(getVirtualRendererSize()); - } - else - { - this->setContentSize(cSize); - } - _customSize = cSize; } void Widget::updateSizeAndPosition() @@ -426,8 +438,21 @@ void Widget::updateSizeAndPosition(const cocos2d::Size &parentSize) void Widget::setSizeType(SizeType type) { _sizeType = type; -} + + if (_usingLayoutComponent) + { + auto component = this->getOrCreateLayoutComponent(); + if (_sizeType == Widget::SizeType::PERCENT) + { + component->setUsingPercentContentSize(true); + } + else + { + component->setUsingPercentContentSize(false); + } + } +} Widget::SizeType Widget::getSizeType() const { return _sizeType; @@ -473,6 +498,12 @@ const Size& Widget::getCustomSize() const const Vec2& Widget::getSizePercent() { + if (_usingLayoutComponent) + { + auto component = this->getOrCreateLayoutComponent(); + _sizePercent = component->getPercentContentSize(); + } + return _sizePercent; } @@ -488,12 +519,15 @@ Node* Widget::getVirtualRenderer() void Widget::onSizeChanged() { - for (auto& child : getChildren()) + if (!_usingLayoutComponent) { - Widget* widgetChild = dynamic_cast(child); - if (widgetChild) + for (auto& child : getChildren()) { - widgetChild->updateSizeAndPosition(); + Widget* widgetChild = dynamic_cast(child); + if (widgetChild) + { + widgetChild->updateSizeAndPosition(); + } } } } @@ -952,7 +986,7 @@ void Widget::interceptTouchEvent(cocos2d::ui::Widget::TouchEventType event, coco void Widget::setPosition(const Vec2 &pos) { - if (_running) + if (!_usingLayoutComponent && _running) { Widget* widgetParent = getWidgetParent(); if (widgetParent) @@ -973,26 +1007,60 @@ void Widget::setPosition(const Vec2 &pos) void Widget::setPositionPercent(const Vec2 &percent) { - _positionPercent = percent; - if (_running) + if (_usingLayoutComponent) { - Widget* widgetParent = getWidgetParent(); - if (widgetParent) + auto component = this->getOrCreateLayoutComponent(); + component->setPositionPercentX(percent.x); + component->setPositionPercentY(percent.y); + component->refreshLayout(); + } + else + { + _positionPercent = percent; + if (_running) { - Size parentSize = widgetParent->getContentSize(); - Vec2 absPos = Vec2(parentSize.width * _positionPercent.x, parentSize.height * _positionPercent.y); - setPosition(absPos); + Widget* widgetParent = getWidgetParent(); + if (widgetParent) + { + Size parentSize = widgetParent->getContentSize(); + Vec2 absPos = Vec2(parentSize.width * _positionPercent.x, parentSize.height * _positionPercent.y); + setPosition(absPos); + } } } } -const Vec2& Widget::getPositionPercent()const{ +const Vec2& Widget::getPositionPercent(){ + + if (_usingLayoutComponent) + { + auto component = this->getOrCreateLayoutComponent(); + float percentX = component->getPositionPercentX(); + float percentY = component->getPositionPercentY(); + + _positionPercent = Vec2(percentX, percentY); + } return _positionPercent; } void Widget::setPositionType(PositionType type) { _positionType = type; + + if (_usingLayoutComponent) + { + auto component = this->getOrCreateLayoutComponent(); + if (type == Widget::PositionType::ABSOLUTE) + { + component->setPositionPercentXEnabled(false); + component->setPositionPercentYEnabled(false); + } + else + { + component->setPositionPercentXEnabled(true); + component->setPositionPercentYEnabled(true); + } + } } Widget::PositionType Widget::getPositionType() const @@ -1399,5 +1467,17 @@ void Widget::setUnifySizeEnabled(bool enable) } +void Widget::setLayoutComponentEnabled(bool enable) +{ + _usingLayoutComponent = enable; +} + +bool Widget::isLayoutComponentEnabled()const +{ + return _usingLayoutComponent; +} + + + } NS_CC_END diff --git a/cocos/ui/UIWidget.h b/cocos/ui/UIWidget.h index 2f41681e9804..5300326e677c 100644 --- a/cocos/ui/UIWidget.h +++ b/cocos/ui/UIWidget.h @@ -272,7 +272,7 @@ class CC_GUI_DLL Widget : public ProtectedNode, public LayoutParameterProtocol * * @return The percent (x,y) of the widget in OpenGL coordinates */ - const Vec2& getPositionPercent()const; + const Vec2& getPositionPercent(); /** * Changes the position type of the widget @@ -635,6 +635,16 @@ class CC_GUI_DLL Widget : public ProtectedNode, public LayoutParameterProtocol void setCallbackType(const std::string& callbackType) { _callbackType = callbackType; } const std::string& getCallbackType() const{ return _callbackType; } + /** + *@param enable Layout Component of a widget + *@return void + */ + void setLayoutComponentEnabled(bool enable); + /** + *@return true represent the widget use Layout Component, false represent the widget couldn't use Layout Component. + */ + bool isLayoutComponentEnabled()const; + CC_CONSTRUCTOR_ACCESS: //initializes state of widget. @@ -725,6 +735,7 @@ class CC_GUI_DLL Widget : public ProtectedNode, public LayoutParameterProtocol LayoutComponent* getOrCreateLayoutComponent(); protected: + bool _usingLayoutComponent; bool _unifySize; bool _enabled; bool _bright; diff --git a/docs/RELEASE_NOTES.md b/docs/RELEASE_NOTES.md index 10f57de84092..dea0f3ae40b9 100644 --- a/docs/RELEASE_NOTES.md +++ b/docs/RELEASE_NOTES.md @@ -1,8 +1,8 @@ -# cocos2d-x v3.3 Release Notes # +# cocos2d-x v3.4 Release Notes # **Table of Contents** *generated with [DocToc](http://doctoc.herokuapp.com/)* -- [cocos2d-x v3.3 Release Notes](#) +- [cocos2d-x v3.4 Release Notes](#) - [Misc Information](#) - [Requirements](#) - [Runtime Requirements](#) @@ -13,44 +13,9 @@ - [Windows](#) - [Linux](#) - [How to start a new game](#) -- [v3.3](#) -- [v3.3rc2](#) - - [Highlights of v3.3rc2](#) - - [Notes of v3.3rc1](#) -- [v3.3rc1](#) - - [Highlights of v3.3rc1](#) - - [Notes of v3.3rc0](#) -- [v3.3rc0](#) - - [Highlights of v3.3rc0](#) +- [v3.4beta0](#) + - [Highlights of v3.4beta0](#) - [Features in detail](#) - - [Light](#) - - [Spine runtime](#) - - [AssetsManagerEx](#) - - [Application::openURL](#) - - [ClippingRectangleNode](#) - - [Facebook platform support](#) -- [v3.3beta0](#) - - [Highlights of v3.3beta0](#) - - [Features in detail](#) - - [BillBoard](#) - - [Triangles command](#) - - [WebView](#) - - [New audio](#) -- [v3.3alpha0](#) - - [Highlights of v3.3alpha0](#) - - [Features in detail](#) - - [Camera](#) - - [Reskin](#) - - [Attachment](#) - - [Better support for FBX](#) - - [New fbx-conv](#) - - [AABB, OBB and Ray](#) - - [ui::Scale9Sprite](#) - - [c++11 random support](#) - - [RenderTexture save function](#) - - [Primitive](#) - - [Consistent way to set GL context attributes](#) - - [Only two libraries left](#) # Misc Information @@ -140,567 +105,13 @@ Run Please refer to this document: [ReadMe](../README.md) -# v3.3 - -It just fixed some bugs since v3.3rc2. - -# v3.3rc2 - -## Highlights of v3.3rc2 -* Support for android arm64 architecture, all test cases run on Nexus 9 -* Cocos Studio Reader: Replace [Protobuffer](https://github.com/google/protobuf) by [FlatBuffer](https://github.com/google/flatbuffers) - -## Notes of v3.3rc1 - -**android** - -Android NDK-r10c is needed. Here is the detailed link for this: -http://discuss.cocos2d-x.org/t/build-android-base-on-ndk-r10c/18543. - -# v3.3rc1 - -## Highlights of v3.3rc1 - -* WP8: add Win8.1 universal app support -* Many other bugfix. - -## Notes of v3.3rc0 - -**wp8** - -You need to use `VS2013 with update 3` to use `Cocos2dShaderCompiler` used to compile precompiled shaders for WP8. - -**lua** - -All internal lua files are copied into `src/cocos` when creating a new lua project. And we added `cocos/init.lua` to load all these internal lua files. `cocos/init.lua` is loaded by default which means you don't have to load these lua files by yourself. So you have to remove all these codes in your lua codes: - -* require "Cocos2d" -* require "Cocos2dConstants" -* require "bitExtend" -* require "DrawPrimitives" -* require "extern" -* require "json" -* require "Opengl" -* require "OpenglConstants" -* require "CCBReaderLoad" -* require "AudioEngine" -* require “CocoStudio” -* require “StudioConstants” -* require “ControllerConstants” -* require “ExtensionConstants” -* require “NetworkConstants” -* require “GuiConstants” -* require “experimentalUIConstants” - -`luaj` and `luaoc` are special. They can not be loaded in `cocos/init.lua` because they will return an object to be used in codes. So you have to replace the codes like this: - -* require "luaj" -> require "cocos.cocos2d.luaj" -* require "luaoc" -> require "cocos.cocos2d.luaoc" - -All lua files used for deprecated API are not loaded by default. If you want to use deprecated API, you should uncomment a line in `src/main.lua` like this: -``` --- uncomment this line to use deprecated API --- CC_USE_DEPRECATED_API = true -require "cocos.init" +# v3.4beta0 -``` +## Highlights of v3.4beta0 -`cc.EditBox` and `cc.Scale9Sprite` were deprecated, you should use `ccui.EditBox` and `ccui.Scale9Sprite` instead. -`ccs.NodeReader` was removed because native class `cocostudio::timeline::NodeReader` was removed.In the v3.3rc0,you could use `cc.CSLoader` instead. - -`sp.Skeleton` was removed because native class `spine::Skeleton` was removed after updating spine runtime. - -`registerSpineEventHandler` of `sp.SkeletonAnimation` has changed: - -* registerSpineEventHandler(fucntion) -> registerSpineEventHandler(funtion, eventType) - - -# v3.3rc0 - -## Highlights of v3.3rc0 - -* 3d: added light support: including directional light, point light, spot light and ambient light -* New audio: more platfroms supported(Mac OS X and Windows) -* Spine runtime: updated to v2.0.18 -* Application: added openURL() -* Added `AssetsManagerEx`, it is an enhancement version of `AssetsManager` -* TileMap: supported staggered tile map -* Added `ClippingRectangleNode`, it is more efficient for renctangle clipping -* Node: schedule/unschedule lambda functions -* Facebook platform support in `plugin` on iOS and Android, all features has been added, but the API needs to be polished with Facebook guys ## Features in detail -### Light - -To make 3d objects looks realistic, we add lights to this version. cocos2d-x supports four types of lights, directional light, point light, spot light and ambient light. - -`DirectionLight` is meant to represent an extremely distant light source (like the sun or moon). Rays cast from directional lights run parallel in a single direction from every point in the sky, and are typically used to simulate the sun light. - -The following code can add a directional light to the scene, - -```c++ -auto directionalLight = DirectionLight::create(Vec3(-1.0f, -1.0f, 0.0f), Color3B(200, 200, 200)); -addChild(directionalLight); -``` - -The light is enabled by default. And it can be disabled using the following code, - -```c++ -directionalLight->setEnabled(false); -``` - -You can also set a light flag to the light. - -```c++ -directionalLight->setLightFlag(LightFlag::LIGHT0); -``` - -Then the 3d sprite whose light mask AND light flag is none zero can effect by the light. - -`PointLight` casts illumination outward in every direction from a single, infinitely small point in 3D space. It is useful for simulating any omnidirectional light source. - -`SpotLight` emits a cone shaped light field from a single point in space. It can be used to simulate desk lamps, overhead cone lighting, etc. Note that `SpotLight` will take more GPU time. - -`AmbientLight` casts soft rays in every direction. - -Note that we use forward render method, the number of lights can effect the performance. You can set the max number of lights supported in the shader in a the configuration file. - -```c++ -cocos2d.x.3d.max_dir_light_in_shader -1 -cocos2d.x.3d.max_point_light_in_shader -1 -cocos2d.x.3d.max_spot_light_in_shader -1 -``` - -### Spine runtime - -Spine runtime is updated to latest version `v2.0.18`. This version supports `Free-Form-Deformation(FFD)`, which allows meshes to stretch, squash, blend and bounce in ways that aren't possible using rectangle images. - -`Spine rutnime has updated its license which only allows engine to use unmodified version even it has bugs. So you guys don't send pull requests for spine runtime, we can not merge them.` - -Please refer to `tests/cpp-tests/Classes/SpineTest/SpineTest.cpp` for usage. - -### AssetsManagerEx - -`AssetsMangerEx` is an enhancement version of `AssetsManager`. Compared to `AssetsManager`, there are some pros using `AssetsManagerEx`: - -* complex update package support with manifest file -* multi-thread downloading support -* continue transferring from breakpoint - -Please refer to [this document](http://cocos2d-x.org/wiki/Assets_manager) for detail information. - -### Application::openURL - -Because in iOS, there is an function named `openURL` in `UIApplication`, so we added this function in Application too. You can use this function to open a url. - -```c++ -Application::getInstance()->openURL("http://www.cocos2d-x.org/"); -``` - -### ClippingRectangleNode - -`ClippingRectangleNode` is a lite version of `ClippingNode`. Compared to `ClippingNode`, there re some pros and cons: - -* pros - * it doesn't depend on stencil buffer, which means it can run on more Android devices - * it is more efficient - -* cons - * it can only used to clip rectangle area - -```c++ -auto clipper = ClippingRectangleNode::create(); -clipper->setClippingRegion(0, 0, 200, 200); -this->addChild(clipper); - -auto content = Sprite::create("MyPicture.png"); -... -clipper->addChild(content); -``` - -### Facebook platform support - -All features has been added, but the API needs to be polished with Facebook guys. There is a test case in `plugin` for it. Steps to run test case - -* open `plugin/pluing-x_ios.xcworkspace` -* select `HelloPlugins` to run -* there are `Test Facebook User` and `Test Facebook Share` items - -You can refer to [this document](http://www.cocos2d-x.org/wiki/Integrate_the_Facebook_SDK_for_Cocos2d-x) for detail information. - -# v3.3beta0 - -## Highlights of v3.3beta0 - -* 3d: `BillBoard` -* audio: new audio is added on iOS and Android -* DrawNode: added as many functions as `DrawPrimitive`, and `DrawPrimitive` is deprecated -* Renderer: added `triangle command` -* UI: added `WebView` on iOS and Android -* Many other small features added and many bugs fixed - -## Features in detail - -### BillBoard - -`BillBoard` is a rectangle always faces to the camera. It is useful in the 3D world. People use BillBoard to create trees in some racing games. It looks real, but the cost is much lower than 3d tree. - -`BillBoard` inherits from Sprite, so it also supports animate. Here is example of creating BillBoard. - -```c++ -//create billboard from .png -auto billboard = BillBoard::create("Images/Icon.png"); -addChild(billboard); - -//create camera that is looking at this billboard. Otherwise, it is seen by the default camera -auto camera = Camera::createPerspective(60, (GLfloat)s.width/s.height, 1, 1000); -camera->setCameraFlag(CameraFlag::CAMERA_USER1); -addChild(camera); //add this camera - -//This billboard is only seen by the camera with flag CameraFlag::CAMERA_USER1. -billboard->setCameraMask((unsigned short)CameraFlag::CAMERA_USER1); -``` - -### Triangles command - -We have enhanced auto batching feature by introduce `TrianglesCommand`, the rendering of the `Triangles` can be auto batched. Now if we have anything which can be rendered by `Triangles`, we can use `TrianglesCommand` or inherit from `TrianglesCommand` to take use of auto batching feature and gain rendering improvements. The `QuadCommand`, which is used for `Quad` rendering, is a good example of inheriting from `TrianglesCommand`. - -The step to use Triangle Command is very simple. - -``` - Triangles trs{verts, indices, vertCount, indexCount}; - command->init(globalZOrder,textureID, glProgramState,blend,trs,matrix); - renderer->addCommand(command); -``` -To improve performance, `Triangles` will hold a weak reference to the vertices and indices data to be rendered, which is the same like `QuadCommand`. The userer should not release any rendered data before the `Command` is executed by `Renderer`. - -### WebView - -WebView is an new widget type which allows you to display web content inside Cocos2D-X. We only provide iOS and Android implementation currently, more platform might be added in the future. - -The class is under `cocos2d::ui::experimental` namespace. - -As we clarified the `experimental` namespace before, the `experimental` namespace doesn't mean the widget is incomplete, but only due to the lack of full platform support. Feel free to use the WebView -widget in your game. - -To display the website Google in a WebView, we could simply write: - -```cpp - _webView = cocos2d::experimental::ui::WebView::create(); - _webView->setPosition(winSize/2); - _webView->setContentSize(winSize * 0.5); - _webView->loadUrl("http://www.google.com"); - _webView->setScalesPageToFit(true); -``` - -The `setscalesPageToFit` method will adjust the WebView content to fit the content size you set. - -We could also set some callback to the WebView: - -```cpp - //we should check the validation of the URL and decide whether to continue or not - _webView->shouldStartLoading = CC_CALLBACK_2(WebViewTest::onWebViewShouldStartLoading, this); - //called when web page is finish loading - _webView->didFinishLoading = CC_CALLBACK_2(WebViewTest::onWebViewDidFinishLoading, this); - //called when web page is fail loading - _webView->didFailLoading = CC_CALLBACK_2(WebViewTest::onWebViewDidFailLoading, this); -``` - -For full test case, please refer to [WebViewTest](https://github.com/cocos2d/cocos2d-x/blob/v3/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIWebViewTest/UIWebViewTest.cpp) - - -### New audio - -New audio is more powerful than old one, and it is not compatible with old one. We will deprecated old one when new audio is ready on all supported platforms. Now it only supports iOS and Android. We plan to finish it on v3.4. - -What's enhanced in new audio engine: - -* can play more than one backgournd music -* can have a call back when an audio(music or effect) finishs -* can get duration of an audio -* can get/set playback position of a playing audio -* can change loop state when playing - -The difference compared to old audio engine - -* all functions are static, which means you can more easy to invoke function, such as `Audio::play2d()` -* there is only one method `play2d()` to play music or effect -* should use `Audio::getState()` to determine an audio is playing, paused -* its class name is `cocos2d::experimental::AudioEngine` in c++, and its module name is `ccexp.AudioEngine` in lua-binding -* there is not preload function, you can play an audio immediately - -Full test case please refer to `tests/cpp-tests/Classes/NewAudioEngineTest/NewAudioEngineTest.cpp`. - -# v3.3alpha0 - -## Highlights of v3.3alpha0 - -* 3d: `Camera`, `Reskin`, `Attachment`, `Better support for FBX`, `New fbx-conv`, `AABB`, `OBB` and `Ray` -* ui: added `Scale9Sprite` -* FileUitls: added `isDirectoryExist()`, `createDirectory()`, `removeDirectory()`, `removeFile()`, `renameFile()` and `getFileSize()` -* Device: added `setKeepScreenOn()` on iOS and Android -* Added c++11 random support -* RenderTexture: added a call back function for `saveToFile()` -* Primitive: Support Points, Lines and Triangles for rendering -* SpriteFrameCache: support loading from plist file content data -* Added a consistent way to set GL context attributes for all platforms -* Only two libraries in cocos2d-x, one for c++ codes, another one for lua-binding codes -* Many other small features added and many bugs fixed - -## Features in detail - -### Camera - -This version of camera is powerful than previous one. And you can add it as a child anywhere. If you want to let a Node to be visited by a camera, Node's camera mask should include Camera's flag: - -```c++ -// let sprite to be visited by a camera -auto sprite = Sprite::create("myFile.png"); -sprite->setCameraMask(CameraFlag::USER1); -auto camera = Camera::createPerspective(60, winSize.width/winSize.height, 1, 1000); -camera->setCameraFlag(CameraFlag::USER1); -scene->addChild(camera); -``` - -If you have many Nodes that want to be visited by a camera, there is a convenient way: - -```c++ -auto layer = Layer::create(); -auto sprite1 = Sprite::create(); -auto sprite2 = Sprite::create(); -layer->addChild(sprite1); -layer->addChild(sprite2); -// it will set camera mask for all its children -layer->setCameraMask(CameraFlg::USER1); - -auto camera = Camera::createPerspective(); -camera->setCameraFlag(CameraFlag::USER1); -scene->addChild(camera); -``` - -Full test case please refer to `tests/cpp-tests/res/Camera3DTest/Camera3DTest.cpp`. - -### Reskin - -It is a powerful feature, all the user change the appearance of character. - -For example, there a model named girl.c3b, which has two coats, coat0 and coat1. -The character's coat can be changed like this, - -```c++ -//load the girl from file -auto sprite3d = Sprite3D::create("girl.c3b"); -//get the mesh named coat0 -auto mesh0 = sprite3d->getMeshByName("coat0"); -//you can change texture of this mesh if you like -mesh0->setTexture("cloth.png"); -//you can change visibility for this mesh, too -mesh0->setVisible(true); -//hide coat1 -auto mesh1 = sprite3d->getMeshByName("coat1"); -mesh1->setVisible(false); -``` - -Full test case please refer to 'tests/cpp-tests/Classes/Spret3DTest/Sprite3DTest.cpp' - -### Attachment - -Allows to attach a node to a bone - -Usage, - -```c++ -auto sprite = Sprite3D::create("girl.c3b"); -auto weapon = Sprite::create("weapon.c3b"); -auto attachNode = sprite->getAttachNode("left_hand"); -attachNode->addChild(weapon); -``` - -Full test case please refer to 'tests/cpp-tests/Classes/Spret3DTest/Sprite3DTest.cpp' - -### Better support for FBX - -support multiple mesh -support multiple material -bones bind to each mesh limited to 40. But the FBX model can contain more meshes. So the model can contain much more bones. - -### New fbx-conv - -It can export more complex model, which contains multiple meshes and multiple materials. - -### AABB, OBB and Ray - -AABB means Axis Aligned Bounding Box -OBB means Oriented Bounding Box -Ray has a origin position and direction - -Each Sprite3D or Mesh has its own AABB. -AABB and OBB can be picked by Ray. - -Usage, - -```c++ -//get ray from camera -Vec3 nearP(location.x, location.y, -1.0f), farP(location.x, location.y, 1.0f); -auto size = Director::getInstance()->getWinSize(); -camera->unproject(size, &nearP, &nearP); -camera->unproject(size, &farP, &farP); -ray._origin = nearP; -ray._direction = farP - nearP; -ray.intersects(sprite3d->getAABB( ) ); -``` - -Full test case please refer to 'tests/cpp-tests/Classes/Spret3DTest/Sprite3DTest.cpp' - -### ui::Scale9Sprite - -Now we have implemented a new Scale9Sprite class under ui module. Its internal implementation is concise than the previous one plus more features. -The main reason of reimplementing this class is that the Scale9Sprite is heavily used in ui module. Now the ui module is not dependent from extension module. -By applying the new ui::Scale9Sprite, the code inside many widget classes are more cleaner and elegant. - -We could manually toggle "slice 9" feature by one function call: - -```c++ -//ui::Scale9Sprite is slice 9 enabled on default -auto sprite = ui::Scale9Sprite::create("foo.png"); -sprite->setScale9Enabled(false); -``` - -It also supports Flipping now. - -```c++ -auto sprite = ui::Scale9Sprite::create("bar.png"); -sprite->setFlippedX(true); -sprite->setFlippedY(false); -``` - -Since the ui::Scale9Sprite is a Node rather than a Sprite, so you can't add it to a batch node. If you do want to do some actions on the internal sprite, -you could call `sprite->getSprite()` to access it. - -Full test case please refer to `tests/cpp-tests/Classes/UITests/CocostudioGUITest/UIScale9SpriteTest.cpp`. - -### c++11 random support - -Since `rand()` is not good(refer to [this document](http://c-faq.com/lib/randrange.html)), we use c++11 random library to do generate random number, and provide a function to easily using: - -```c++ -int randInt = cocos2d::random(1, 10); -float randFloat = cocos2d::random(1.f, 10.f); -``` - -### RenderTexture save function - -`RenderTexture::saveToFile()` will not save rendertexture when the function returns, because it just send render command to renderer. The file will be saved after render command is executed. It is not convenient if you want to use the saved file to do some work. So we added a parameter in `RenderTexture::saveToFile()` to set a call back function when the file is saved. - -```c++ -renderTexture->begin(); -... -renderTexture->end(); - -renderTexture->saveToFile("myFile.png", true, callback); - -``` - -### Primitive - -`Primitive` is added to support `Points`,`Lines`,`Triangles` rendering. Previously, if we want to draw a custom geometry(sphere, line), we can only do this by using `CustomCommand`. Now, what is need is to create a Primitive, set datas, and use the corresponding `PrimitiveCommand` to draw the Primitive. - -Here is a simple example of rendering a quad in `Sprite`. - -1. create verexBuffer - - ```c++ - auto vertexBuffer = VerexBuffer::create(sizeof(V3F_C4B_T2F), 4); - vertexBuffer->updateVertices(&_quad, 4, 0); - ``` - -2. create vertexData - - ```c++ - auto vertexData = VertexData::create(); - vertexData->addStream(vertexBuffer, VertexStreamAttribute(0, VERTEX_ATTRIB_POSITION, GL_FLOAT, 3, fasle)); - vertexData->addStream(vertexBuffer, VertexStreamAttribute(12, VERTEX_ATTRIB_COLOR, GL_UNSIGNED_BTYE, 4, true)); - vertexData->addStream(vertexBuffer, VertexStreamAttribute(16, VERTEX_ATTRIB_TEX_COORD, GL_FLOAT, 2, fasle)); - ``` -3. create IndexBuffer - - ```c++ - auto indexBuffer = IndexBuffer::create(IndexType::INDEX_TYPE_SHORT_16, 6); - short indices[6] = {0,1,2,3,2,1}; - indexBuffer->updateIndices(indices,6, 0); - ``` -4. create primitive - - ```c++ - auto primitve = Primitive::create(vertexData, indexBuffer, GL_TRIANGLES); - primitive->setStart(0); - primitive->setCount(6); - ``` -5. add command to renderer - - ```c++ - _command->init(globalZorder,textureID, glprogramState, blend, primitve, modelViewMatrix); - renderer->addCommand(&_command); - ``` - -Primitive supports three typs of primitives (POINTS, LINES, TRIANGLES), vertex and index sharing, multiple streams. It has some constrains: - -1. The size of vertex and index Buffer is fixed, which means data must be pre allocated. -2. Batching is not supported. - -### Consistent way to set GL context attributes - -Now you can set GL context attributes by override `Application::initGLContextAttrs()`, then set GL context attributes there. - -```c++ -void AppDelegate::initGLContextAttrs() -{ - // r:8 g:8 a:8 depth:24 stencil:8 - GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8}; - GLView::setGLContextAttrs(glContextAttrs); -} -``` - -Now can only support setting bits of `r`, `g`, `b`, `a`, `depth buffer` and `stencil buffer`. We will support other attributes if needed. - -### Only two libraries left - -Now there are two libraries left: one for all c++ codes and another one for lua-bindings codes. - -If you are developing with c++, you only have to link to `libcocos2d`. `libcocos2d` includes all c++ codes: - -* cocos2d(including 2d and 3d) -* network -* cocosstudio -* ui -* cocosbuilder -* spine -* chipmunk -* box2d -* ... - -Not used codes will be stripped by linker. - -If you are developing with lua, you should link to `libcocos2d` and `libluacocos2d`. You can comment codes in `lua_module_register.h` if you don't want to some module. - -```c++ -int lua_module_register(lua_State* L) -{ - register_cocosdenshion_module(L); // comment this line to remove cocosdenshion - register_network_module(L); // comment this line to remove network - register_cocosbuilder_module(L); // comment this line to remove cocosbuilder - register_cocostudio_module(L); // comment this line to remove cocostudio - register_extension_module(L); // comment this line to remove extension - register_ui_moudle(L); // comment this line to remove ui - register_spine_module(L); // comment this line to remove spine - register_cocos3d_module(L); // comment this line to remove 3d - return 1; -} -``` diff --git a/templates/cocos2dx_files.json b/templates/cocos2dx_files.json index d0182d7e355b..5b84c0b9b0ca 100644 --- a/templates/cocos2dx_files.json +++ b/templates/cocos2dx_files.json @@ -545,6 +545,8 @@ "cocos/editor-support/cocostudio/ActionTimeline/CCActionTimeline.h", "cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.cpp", "cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.h", + "cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineNode.cpp", + "cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineNode.h", "cocos/editor-support/cocostudio/ActionTimeline/CCFrame.cpp", "cocos/editor-support/cocostudio/ActionTimeline/CCFrame.h", "cocos/editor-support/cocostudio/ActionTimeline/CCNodeReader.cpp", @@ -634,6 +636,9 @@ "cocos/editor-support/cocostudio/TriggerObj.h", "cocos/editor-support/cocostudio/WidgetCallBackHandlerProtocol.cpp", "cocos/editor-support/cocostudio/WidgetCallBackHandlerProtocol.h", + "cocos/editor-support/cocostudio/WidgetReader/ArmatureNodeReader/ArmatureNodeReader.cpp", + "cocos/editor-support/cocostudio/WidgetReader/ArmatureNodeReader/ArmatureNodeReader.h", + "cocos/editor-support/cocostudio/WidgetReader/ArmatureNodeReader/CSArmatureNode_generated.h", "cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp", "cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.h", "cocos/editor-support/cocostudio/WidgetReader/CheckBoxReader/CheckBoxReader.cpp", diff --git a/templates/lua-template-runtime/src/main.lua b/templates/lua-template-runtime/src/main.lua index 8b980f63b5e9..2c6c6b7f1236 100644 --- a/templates/lua-template-runtime/src/main.lua +++ b/templates/lua-template-runtime/src/main.lua @@ -34,17 +34,17 @@ local function main() --set FPS. the default value is 1.0/60 if you don't call this director:setAnimationInterval(1.0 / 60) - cc.Director:getInstance():getOpenGLView():setDesignResolutionSize(480, 320, 1) + director:getOpenGLView():setDesignResolutionSize(480, 320, 1) --create scene local scene = require("GameScene") local gameScene = scene.create() gameScene:playBgMusic() - if cc.Director:getInstance():getRunningScene() then - cc.Director:getInstance():replaceScene(gameScene) + if director:getRunningScene() then + director:replaceScene(gameScene) else - cc.Director:getInstance():runWithScene(gameScene) + director:runWithScene(gameScene) end end diff --git a/tests/cpp-tests/Classes/AppDelegate.cpp b/tests/cpp-tests/Classes/AppDelegate.cpp index 66a9bbbd6eda..ddf3f8a4befc 100644 --- a/tests/cpp-tests/Classes/AppDelegate.cpp +++ b/tests/cpp-tests/Classes/AppDelegate.cpp @@ -110,6 +110,7 @@ bool AppDelegate::applicationDidFinishLaunching() searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UILayout/Layout"); searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UILayout/Gradient_Color"); searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UILayout/Scale9_BackgroundImage"); + searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UILayout/LayoutComponent"); searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UILoadingBar"); searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UIPageView"); searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UIScrollView/Both"); @@ -122,6 +123,7 @@ bool AppDelegate::applicationDidFinishLaunching() searchPaths.push_back("ccs-res/hd/cocosui/CustomTest/CustomWidgetCallbackBindTest"); searchPaths.push_back("hd/ActionTimeline"); + searchPaths.push_back("ccs-res/hd/armature"); } else { @@ -149,6 +151,7 @@ bool AppDelegate::applicationDidFinishLaunching() searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UILayout/Layout"); searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UILayout/Gradient_Color"); searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UILayout/Scale9_BackgroundImage"); + searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UILayout/LayoutComponent"); searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UILoadingBar"); searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UIPageView"); searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UIScrollView/Both"); @@ -161,6 +164,8 @@ bool AppDelegate::applicationDidFinishLaunching() searchPaths.push_back("ccs-res/cocosui/CustomTest/CustomWidgetCallbackBindTest"); searchPaths.push_back("ActionTimeline"); + searchPaths.push_back("ccs-res/armature"); + } fileUtils->setSearchPaths(searchPaths); diff --git a/tests/cpp-tests/Classes/ConsoleTest/ConsoleTest.cpp b/tests/cpp-tests/Classes/ConsoleTest/ConsoleTest.cpp index 61c0bb616ba3..7e1b6961c4c7 100644 --- a/tests/cpp-tests/Classes/ConsoleTest/ConsoleTest.cpp +++ b/tests/cpp-tests/Classes/ConsoleTest/ConsoleTest.cpp @@ -327,7 +327,7 @@ void ConsoleUploadFile::uploadFile() // terminate fclose (fp); -#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) +#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) closesocket(sfd); WSACleanup(); #else diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioActionTimelineTest/ActionTimelineTestScene.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioActionTimelineTest/ActionTimelineTestScene.cpp index d07e0745212d..70ac3c14b99a 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioActionTimelineTest/ActionTimelineTestScene.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioActionTimelineTest/ActionTimelineTestScene.cpp @@ -197,11 +197,7 @@ void TestActionTimeline::onEnter() { ActionTimelineTestLayer::onEnter(); - Node* node = CSLoader::createNode("ActionTimeline/DemoPlayer.csb"); - ActionTimeline* action = CSLoader::createTimeline("ActionTimeline/DemoPlayer.csb"); - - node->runAction(action); - action->gotoFrameAndPlay(0, 40, true); + ActionTimelineNode* node = CSLoader::createActionTimelineNode("ActionTimeline/DemoPlayer.csb", 0, 40, true); node->setScale(0.2f); node->setPosition(VisibleRect::center()); @@ -221,11 +217,8 @@ void TestChangePlaySection::onEnter() { ActionTimelineTestLayer::onEnter(); - Node* node = CSLoader::createNode("ActionTimeline/DemoPlayer.csb"); - action = CSLoader::createTimeline("ActionTimeline/DemoPlayer.csb"); - - node->runAction(action); - action->gotoFrameAndPlay(41, action->getDuration(), true); + ActionTimelineNode* node = CSLoader::createActionTimelineNode("ActionTimeline/DemoPlayer.csb", 41, 81, true); + action = node->getActionTimeline(); node->setScale(0.2f); node->setPosition(VisibleRect::center()); @@ -247,7 +240,7 @@ std::string TestChangePlaySection::title() const void TestChangePlaySection::onTouchesEnded(const std::vector& touches, Event* event) { if(action->getStartFrame() == 0) - action->gotoFrameAndPlay(41, action->getDuration(), true); + action->gotoFrameAndPlay(41, 81, true); else action->gotoFrameAndPlay(0, 40, true); } @@ -257,13 +250,8 @@ void TestTimelineFrameEvent::onEnter() { ActionTimelineTestLayer::onEnter(); - SpriteFrameCache::getInstance()->addSpriteFramesWithFile("armature/Cowboy0.plist", "armature/Cowboy0.png"); - - Node* node = CSLoader::createNode("ActionTimeline/boy_1.csb"); - ActionTimeline* action = CSLoader::createTimeline("ActionTimeline/boy_1.csb"); - - node->runAction(action); - action->gotoFrameAndPlay(0, 60, true); + ActionTimelineNode* node = CSLoader::createActionTimelineNode("ActionTimeline/DemoPlayer.csb", 0, 40, true); + ActionTimeline* action = node->getActionTimeline(); node->setScale(0.2f); node->setPosition(150,100); @@ -303,11 +291,7 @@ void TestTimelinePerformance::onEnter() for (int i = 0; i< 100; i++) { - Node* node = CSLoader::createNode("ActionTimeline/DemoPlayer.csb"); - ActionTimeline* action = CSLoader::createTimeline("ActionTimeline/DemoPlayer.csb"); - - node->runAction(action); - action->gotoFrameAndPlay(41, action->getDuration(), true); + ActionTimelineNode* node = CSLoader::createActionTimelineNode("ActionTimeline/DemoPlayer.csb", 41, 81, true); node->setScale(0.1f); node->setPosition(i*2,100); diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp index 08e53d316ee1..2093b6e67aac 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp @@ -78,6 +78,9 @@ Layer *CreateLayer(int index) case TEST_DIRECT_FROM_BINARY: pLayer = new (std::nothrow) TestLoadFromBinary(); break; + case TEST_ARMATURE_NODE: + pLayer = new (std::nothrow) TestArmatureNode(); + break; default: break; } @@ -1601,3 +1604,27 @@ void TestLoadFromBinary::dataLoaded( float percent ) m_armatureIndex = 0; } } + + + +//TestArmatureNode + +void TestArmatureNode::onEnter() +{ + ArmatureTestLayer::onEnter(); + + auto node = CSLoader::createNode("TestArmatureNode.csb"); + addChild(node); + node->setPositionX(Director::getInstance()->getVisibleSize().width * .25f); +} + + +std::string TestArmatureNode::title() const +{ + return "Test Armature Node"; +} +std::string TestArmatureNode::subtitle() const +{ + return "Csb file loaded"; +} + diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h index a5e1a3f49ac0..82d273ebee3d 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h @@ -46,6 +46,7 @@ enum { TEST_EASING, TEST_CHANGE_ANIMATION_INTERNAL, TEST_DIRECT_FROM_BINARY, + TEST_ARMATURE_NODE, TEST_LAYER_COUNT }; @@ -412,4 +413,12 @@ class TestLoadFromBinary : public ArmatureTestLayer int m_armatureIndex; // index of sync loaded armature, default -1 is none }; +class TestArmatureNode : public ArmatureTestLayer +{ +public: + virtual void onEnter(); + virtual std::string title() const override; + virtual std::string subtitle() const override; +}; + #endif // __HELLOWORLD_SCENE_H__ diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp index 065fb5c27b85..0a63ebbf5f18 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp @@ -199,7 +199,7 @@ g_guisTests[] = UISceneManager* sceneManager = UISceneManager::sharedUISceneManager(); sceneManager->setCurrentUISceneId(kUILayoutTest); sceneManager->setMinUISceneId(kUILayoutTest); - sceneManager->setMaxUISceneId(kUILayoutTest_Layout_Relative_Location); + sceneManager->setMaxUISceneId(kUILayoutComponent_Berth_Stretch_Test); Scene* scene = sceneManager->currentUIScene(); Director::getInstance()->replaceScene(scene); } diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/GUIEditorTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/GUIEditorTest.cpp index f59843dbe570..152bfc4cbf2a 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/GUIEditorTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/GUIEditorTest.cpp @@ -177,7 +177,7 @@ g_guisTests[] = UISceneManager_Editor* pManager = UISceneManager_Editor::sharedUISceneManager_Editor(); pManager->setCurrentUISceneId(kUILayoutTest_Editor); pManager->setMinUISceneId(kUILayoutTest_Editor); - pManager->setMaxUISceneId(kUILayoutTest_BackGroundImage_Scale9_Editor); + pManager->setMaxUISceneId(kUILayoutComponentTest_Editor); // pManager->setMaxUISceneId(kUILayoutTest_Layout_Relative_Location_Editor); Scene* pScene = pManager->currentUIScene(); Director::getInstance()->replaceScene(pScene); diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest.cpp index 3868af3b0cad..bbb8e316054a 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest.cpp @@ -694,3 +694,153 @@ bool UILayoutTest_Layout_Relative_Location::init() return false; } +bool UILayoutComponentTest::init() +{ + if (UIScene::init()) + { + Size widgetSize = _widget->getContentSize(); + + _baseLayer = LayerColor::create(); + _baseLayer->setColor(Color3B(50, 100, 0)); + _baseLayer->setOpacity(100); + _baseLayer->setContentSize(Size(200, 200)); + _uiLayer->addChild(_baseLayer); + + Button* button = Button::create("cocosui/animationbuttonnormal.png"); + CCLOG("content size should be greater than 0: width = %f, height = %f", button->getContentSize().width, + button->getContentSize().height); + button->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); + button->addTouchEventListener(CC_CALLBACK_2(UILayoutComponentTest::touchEvent, this)); + button->setZoomScale(0.4f); + button->setPressedActionEnabled(true); + _uiLayer->addChild(button); + + return true; + } + return false; +} + +void UILayoutComponentTest::touchEvent(Ref *pSender, Widget::TouchEventType type) +{ + switch (type) + { + case Widget::TouchEventType::BEGAN: + break; + + case Widget::TouchEventType::MOVED: + break; + + case Widget::TouchEventType::ENDED: + { + Size widgetSize = _widget->getContentSize(); + Size layerSize = _baseLayer->getContentSize(); + if (layerSize.width == widgetSize.width && layerSize.height == widgetSize.height) + _baseLayer->setContentSize(Size(200, 200)); + else + _baseLayer->setContentSize(widgetSize); + ui:Helper::doLayout(_baseLayer); + } + break; + + case Widget::TouchEventType::CANCELED: + break; + + default: + break; + } +} + +bool UILayoutComponent_Berth_Test::init() +{ + if (UILayoutComponentTest::init()) + { + Sprite* leftTopSprite = Sprite::create("cocosui/CloseSelected.png"); + LayoutComponent* leftTop = LayoutComponent::boundingLayoutComponent(leftTopSprite); + leftTop->setHorizontalEdge(LayoutComponent::HorizontalEdge::Left); + leftTop->setVerticalEdge(LayoutComponent::VerticalEdge::Top); + _baseLayer->addChild(leftTopSprite); + + Sprite* leftBottomSprite = Sprite::create("cocosui/CloseSelected.png"); + LayoutComponent* leftBottom = LayoutComponent::boundingLayoutComponent(leftBottomSprite); + leftBottom->setHorizontalEdge(LayoutComponent::HorizontalEdge::Left); + leftBottom->setVerticalEdge(LayoutComponent::VerticalEdge::Bottom); + _baseLayer->addChild(leftBottomSprite); + + Sprite* rightTopSprite = Sprite::create("cocosui/CloseSelected.png"); + LayoutComponent* rightTop = LayoutComponent::boundingLayoutComponent(rightTopSprite); + rightTop->setHorizontalEdge(LayoutComponent::HorizontalEdge::Right); + rightTop->setVerticalEdge(LayoutComponent::VerticalEdge::Top); + _baseLayer->addChild(rightTopSprite); + + Sprite* rightBottomSprite = Sprite::create("cocosui/CloseSelected.png"); + LayoutComponent* rightBottom = LayoutComponent::boundingLayoutComponent(rightBottomSprite); + rightBottom->setHorizontalEdge(LayoutComponent::HorizontalEdge::Right); + rightBottom->setVerticalEdge(LayoutComponent::VerticalEdge::Bottom); + _baseLayer->addChild(rightBottomSprite); + + ui::Helper::doLayout(_baseLayer); + + return true; + } + return false; +} + +bool UILayoutComponent_Berth_Stretch_Test::init() +{ + if (UILayoutComponentTest::init()) + { + ImageView* leftTopSprite = ImageView::create("cocosui/CloseSelected.png"); + leftTopSprite->ignoreContentAdaptWithSize(false); + LayoutComponent* leftTop = LayoutComponent::boundingLayoutComponent(leftTopSprite); + leftTop->setHorizontalEdge(LayoutComponent::HorizontalEdge::Left); + leftTop->setVerticalEdge(LayoutComponent::VerticalEdge::Top); + leftTop->setStretchWidthEnabled(true); + leftTop->setStretchHeightEnabled(true); + _baseLayer->addChild(leftTopSprite); + leftTop->setSize(leftTopSprite->getContentSize()); + leftTop->setLeftMargin(0); + leftTop->setTopMargin(0); + + ImageView* leftBottomSprite = ImageView::create("cocosui/CloseSelected.png"); + leftBottomSprite->ignoreContentAdaptWithSize(false); + LayoutComponent* leftBottom = LayoutComponent::boundingLayoutComponent(leftBottomSprite); + leftBottom->setHorizontalEdge(LayoutComponent::HorizontalEdge::Left); + leftBottom->setVerticalEdge(LayoutComponent::VerticalEdge::Bottom); + leftBottom->setStretchWidthEnabled(true); + leftBottom->setStretchHeightEnabled(true); + _baseLayer->addChild(leftBottomSprite); + leftBottom->setSize(leftBottomSprite->getContentSize()); + leftBottom->setLeftMargin(0); + leftBottom->setBottomMargin(0); + + ImageView* rightTopSprite = ImageView::create("cocosui/CloseSelected.png"); + rightTopSprite->ignoreContentAdaptWithSize(false); + LayoutComponent* rightTop = LayoutComponent::boundingLayoutComponent(rightTopSprite); + rightTop->setHorizontalEdge(LayoutComponent::HorizontalEdge::Right); + rightTop->setVerticalEdge(LayoutComponent::VerticalEdge::Top); + rightTop->setStretchWidthEnabled(true); + rightTop->setStretchHeightEnabled(true); + _baseLayer->addChild(rightTopSprite); + rightTop->setSize(rightTopSprite->getContentSize()); + rightTop->setTopMargin(0); + rightTop->setRightMargin(0); + + ImageView* rightBottomSprite = ImageView::create("cocosui/CloseSelected.png"); + rightBottomSprite->ignoreContentAdaptWithSize(false); + LayoutComponent* rightBottom = LayoutComponent::boundingLayoutComponent(rightBottomSprite); + rightBottom->setHorizontalEdge(LayoutComponent::HorizontalEdge::Right); + rightBottom->setVerticalEdge(LayoutComponent::VerticalEdge::Bottom); + rightBottom->setStretchWidthEnabled(true); + rightBottom->setStretchHeightEnabled(true); + _baseLayer->addChild(rightBottomSprite); + rightBottom->setSize(rightBottomSprite->getContentSize()); + rightBottom->setBottomMargin(0); + rightBottom->setRightMargin(0); + + ui::Helper::doLayout(_baseLayer); + + return true; + } + return false; +} + diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest.h index 811192d55af7..c81f02a32209 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest.h @@ -126,6 +126,32 @@ class UILayoutTest_Layout_Relative_Location : public UIScene UI_SCENE_CREATE_FUNC(UILayoutTest_Layout_Relative_Location) }; +class UILayoutComponentTest : public UIScene +{ +public: + virtual bool init(); + void touchEvent(Ref *pSender, Widget::TouchEventType type); +protected: + LayerColor* _baseLayer; + UI_SCENE_CREATE_FUNC(UILayoutComponentTest) +}; + +class UILayoutComponent_Berth_Test : public UILayoutComponentTest +{ +public: + virtual bool init() override; +protected: + UI_SCENE_CREATE_FUNC(UILayoutComponent_Berth_Test) +}; + +class UILayoutComponent_Berth_Stretch_Test : public UILayoutComponentTest +{ +public: + virtual bool init() override; +protected: + UI_SCENE_CREATE_FUNC(UILayoutComponent_Berth_Stretch_Test) +}; + /* class UILayoutTest_Layout_Grid : public UIScene { diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest_Editor.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest_Editor.cpp index ac7b794a89d4..cc2e483b32d7 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest_Editor.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest_Editor.cpp @@ -1214,3 +1214,71 @@ bool UILayoutTest_Layout_Relative_Location_Editor::init() return false; } + +UILayoutComponentTest_Editor::UILayoutComponentTest_Editor() +{ + +} + +UILayoutComponentTest_Editor::~UILayoutComponentTest_Editor() +{ + +} + +void UILayoutComponentTest_Editor::configureGUIScene() +{ + Size screenSize = CCDirector::getInstance()->getWinSize(); + + _sceneTitle = Text::create("UILayoutComponentTest_Editor", "", 20); + _sceneTitle->setPosition(Vec2(screenSize.width / 2, screenSize.height - _sceneTitle->getContentSize().height / 2)); + _layout->addChild(_sceneTitle); + + Text* back_label = Text::create("Back", "", 20); + back_label->setTouchEnabled(true); + auto labelLayout = LayoutComponent::boundingLayoutComponent(back_label); + labelLayout->setHorizontalEdge(LayoutComponent::HorizontalEdge::Right); + labelLayout->setVerticalEdge(LayoutComponent::VerticalEdge::Bottom); + back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); + _layout->addChild(back_label); + + Button* left_button = Button::create(); + left_button->loadTextures("Images/b1.png", "Images/b2.png", ""); + left_button->setPosition(Vec2(_layout->getContentSize().width / 2 - left_button->getContentSize().width, + left_button->getContentSize().height * 0.625)); + left_button->setTouchEnabled(true); + left_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::previousCallback, this)); + left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); + _layout->addChild(left_button); + + Button* right_button = Button::create(); + right_button->loadTextures("Images/f1.png", "Images/f2.png", ""); + right_button->setPosition(Vec2(_layout->getContentSize().width / 2 + right_button->getContentSize().width, + right_button->getContentSize().height * 0.625)); + right_button->setTouchEnabled(true); + right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); + right_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::nextCallback, this)); + _layout->addChild(right_button); + +} + +bool UILayoutComponentTest_Editor::init() +{ + if (UIScene_Editor::init()) + { + Size screenSize = CCDirector::getInstance()->getWinSize(); + _layout = Layout::create(); + _layout->setContentSize(screenSize); + _touchGroup->addChild(_layout); + + Node* node = CSLoader::createNode("cocosui/UIEditorTest/UILayout/LayoutComponent/Scene.csb"); + node->setContentSize(screenSize); + _layout->addChild(node); + this->configureGUIScene(); + + ui::Helper::doLayout(_layout); + + return true; + } + + return false; +} \ No newline at end of file diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest_Editor.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest_Editor.h index 5b0fb91c4fac..52004b5d9d59 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest_Editor.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest_Editor.h @@ -144,4 +144,16 @@ class UILayoutTest_Layout_Relative_Location_Editor : public UIScene_Editor UI_SCENE_EDITOR_CREATE_FUNC(UILayoutTest_Layout_Relative_Location_Editor) }; +class UILayoutComponentTest_Editor : public UIScene_Editor +{ +public: + UILayoutComponentTest_Editor(); + ~UILayoutComponentTest_Editor(); + virtual bool init(); + void configureGUIScene(); +protected: + LayerColor* _baseLayer; + UI_SCENE_EDITOR_CREATE_FUNC(UILayoutComponentTest_Editor) +}; + #endif /* defined(__TestCpp__UILayoutTest_Editor__) */ diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.cpp index b95d74395703..1eea8a741a13 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.cpp @@ -92,6 +92,8 @@ static const char* s_testArray[] = "UILayoutTest_Layout_Linear_Horizontal", "UILayoutTest_Layout_Relative_Align_Parent", "UILayoutTest_Layout_Relative_Location", + "UILayoutComponent_Berth_Test", + "UILayoutComponent_Berth_Stretch_Test", "UIScrollViewTest_Vertical", "UIScrollViewTest_Horizontal", @@ -333,6 +335,12 @@ Scene *UISceneManager::currentUIScene() case kUILayoutTest_Layout_Relative_Location: return UILayoutTest_Layout_Relative_Location::sceneWithTitle(s_testArray[_currentUISceneId]); + case kUILayoutComponent_Berth_Test: + return UILayoutComponent_Berth_Test::sceneWithTitle(s_testArray[_currentUISceneId]); + + case kUILayoutComponent_Berth_Stretch_Test: + return UILayoutComponent_Berth_Stretch_Test::sceneWithTitle(s_testArray[_currentUISceneId]); + case kUIScrollViewTest_Vertical: return UIScrollViewTest_Vertical::sceneWithTitle(s_testArray[_currentUISceneId]); diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.h index 35567d739668..d50545ff7d4e 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.h @@ -85,6 +85,8 @@ enum kUILayoutTest_Layout_Linear_Horizontal, kUILayoutTest_Layout_Relative_Align_Parent, kUILayoutTest_Layout_Relative_Location, + kUILayoutComponent_Berth_Test, + kUILayoutComponent_Berth_Stretch_Test, kUIScrollViewTest_Vertical, kUIScrollViewTest_Horizontal, kUIScrollViewTest_Both, diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager_Editor.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager_Editor.cpp index 2e9346bfeddc..b0106a96c39f 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager_Editor.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager_Editor.cpp @@ -36,12 +36,15 @@ static const char* s_testArray[] = "UILayoutTest_Gradient_Editor", "UILayoutTest_BackGroundImage_Editor", "UILayoutTest_BackGroundImage_Scale9_Editor", + "UILayoutComponentTest_Editor", + /* "UILayoutTest_Layout_Linear_Vertical_Editor", "UILayoutTest_Layout_Linear_Horizontal_Editor", "UILayoutTest_Layout_Relative_Align_Parent_Editor", "UILayoutTest_Layout_Relative_Location_Editor", */ + "UIListViewTest_Vertical_Editor", "UIListViewTest_Horizontal_Editor", "UIPageViewTest_Editor", @@ -148,7 +151,9 @@ Scene* UISceneManager_Editor::currentUIScene() case kUILayoutTest_BackGroundImage_Scale9_Editor: return UILayoutTest_BackGroundImage_Scale9_Editor::sceneWithTitle(s_testArray[_currentUISceneId]); - + + case kUILayoutComponentTest_Editor: + return UILayoutComponentTest_Editor::sceneWithTitle(s_testArray[_currentUISceneId]); /* case kUILayoutTest_Layout_Linear_Vertical_Editor: return UILayoutTest_Layout_Linear_Vertical_Editor::sceneWithTitle(s_testArray[_currentUISceneId]); @@ -162,6 +167,7 @@ Scene* UISceneManager_Editor::currentUIScene() case kUILayoutTest_Layout_Relative_Location_Editor: return UILayoutTest_Layout_Relative_Location_Editor::sceneWithTitle(s_testArray[_currentUISceneId]); */ + case kUIListViewTest_Vertical_Editor: return UIListViewTest_Vertical_Editor::sceneWithTitle(s_testArray[_currentUISceneId]); diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager_Editor.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager_Editor.h index c932da5dec8e..a754cc2e2b5f 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager_Editor.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager_Editor.h @@ -46,12 +46,15 @@ enum kUILayoutTest_Gradient_Editor, kUILayoutTest_BackGroundImage_Editor, kUILayoutTest_BackGroundImage_Scale9_Editor, + kUILayoutComponentTest_Editor, + /* kUILayoutTest_Layout_Linear_Vertical_Editor, kUILayoutTest_Layout_Linear_Horizontal_Editor, kUILayoutTest_Layout_Relative_Align_Parent_Editor, kUILayoutTest_Layout_Relative_Location_Editor, */ + kUIListViewTest_Vertical_Editor, kUIListViewTest_Horizontal_Editor, kUIPageViewTest_Editor, diff --git a/tests/cpp-tests/Resources/ccs-res b/tests/cpp-tests/Resources/ccs-res index 1d8bede8e900..3a3364d79fe4 160000 --- a/tests/cpp-tests/Resources/ccs-res +++ b/tests/cpp-tests/Resources/ccs-res @@ -1 +1 @@ -Subproject commit 1d8bede8e900625bc47972c4a925763e43f70ba2 +Subproject commit 3a3364d79fe4c8fa6487b65edf7a2104a496903e diff --git a/tests/cpp-tests/proj.win8.1-universal/cpp-tests.Shared/cpp-tests.Shared.vcxitems b/tests/cpp-tests/proj.win8.1-universal/cpp-tests.Shared/cpp-tests.Shared.vcxitems index ef371f48031e..28d70cbcaf33 100644 --- a/tests/cpp-tests/proj.win8.1-universal/cpp-tests.Shared/cpp-tests.Shared.vcxitems +++ b/tests/cpp-tests/proj.win8.1-universal/cpp-tests.Shared/cpp-tests.Shared.vcxitems @@ -29,6 +29,7 @@ + @@ -222,6 +223,7 @@ + diff --git a/tests/cpp-tests/proj.win8.1-universal/cpp-tests.Shared/cpp-tests.Shared.vcxitems.filters b/tests/cpp-tests/proj.win8.1-universal/cpp-tests.Shared/cpp-tests.Shared.vcxitems.filters index 8251cb3e7901..973fb7a35f6b 100644 --- a/tests/cpp-tests/proj.win8.1-universal/cpp-tests.Shared/cpp-tests.Shared.vcxitems.filters +++ b/tests/cpp-tests/proj.win8.1-universal/cpp-tests.Shared/cpp-tests.Shared.vcxitems.filters @@ -763,6 +763,9 @@ Classes\UITest\CocostudioGUISceneTest\CustomTest\CustomWidgetCallbackBindTest + + Classes\AllocatorTest + @@ -1656,6 +1659,9 @@ {f93dc8a9-3901-446e-bb08-5e51a31a470c} + + {2840e615-0b65-4bd3-87b5-b1b36b5e4a3f} + @@ -1674,5 +1680,8 @@ Classes\UITest\CocostudioGUISceneTest\CustomTest\CustomWidgetCallbackBindTest + + Classes\AllocatorTest + \ No newline at end of file diff --git a/tests/cpp-tests/proj.wp8-xaml/cpp-testsComponent/cpp-testsComponent.vcxproj b/tests/cpp-tests/proj.wp8-xaml/cpp-testsComponent/cpp-testsComponent.vcxproj index 83fefe1c24ed..093c710c6074 100644 --- a/tests/cpp-tests/proj.wp8-xaml/cpp-testsComponent/cpp-testsComponent.vcxproj +++ b/tests/cpp-tests/proj.wp8-xaml/cpp-testsComponent/cpp-testsComponent.vcxproj @@ -193,6 +193,7 @@ + @@ -386,6 +387,7 @@ + diff --git a/tests/cpp-tests/proj.wp8-xaml/cpp-testsComponent/cpp-testsComponent.vcxproj.filters b/tests/cpp-tests/proj.wp8-xaml/cpp-testsComponent/cpp-testsComponent.vcxproj.filters index 43ed310ab893..58ce1dad5341 100644 --- a/tests/cpp-tests/proj.wp8-xaml/cpp-testsComponent/cpp-testsComponent.vcxproj.filters +++ b/tests/cpp-tests/proj.wp8-xaml/cpp-testsComponent/cpp-testsComponent.vcxproj.filters @@ -340,6 +340,9 @@ {942d4f52-f141-4d09-9466-163098b2e331} + + {573248d9-7443-49ad-aa92-dd9defa29a76} + @@ -900,6 +903,9 @@ Classes\UITest\CocosStudioGUITest\CustomTest\CustomWidgetCallbackBindTest + + Classes\AllocatorTest + @@ -1659,6 +1665,9 @@ Classes\UITest\CocosStudioGUITest\CustomTest\CustomWidgetCallbackBindTest + + Classes\AllocatorTest + diff --git a/tests/lua-tests/src/CocoStudioTest/CocoStudioActionTimelineTest/CocoStudioActionTimelineTest.lua b/tests/lua-tests/src/CocoStudioTest/CocoStudioActionTimelineTest/CocoStudioActionTimelineTest.lua index bf40597fca7f..a789e939fdae 100644 --- a/tests/lua-tests/src/CocoStudioTest/CocoStudioActionTimelineTest/CocoStudioActionTimelineTest.lua +++ b/tests/lua-tests/src/CocoStudioTest/CocoStudioActionTimelineTest/CocoStudioActionTimelineTest.lua @@ -62,8 +62,8 @@ function TimelineTestLayer.title(idx) return "Test ActionTimeline" elseif TimelineTestIndex.TEST_CHANGE_PLAY_SECTION == idx then return "Test Change Play Section" - -- elseif TimelineTestIndex.TEST_TIMELINE_FRAME_EVENT == idx then - -- return "Test Frame Event" + --elseif TimelineTestIndex.TEST_TIMELINE_FRAME_EVENT == idx then + -- return "Test Frame Event" elseif TimelineTestIndex.TEST_TIMELINE_PERFORMACE == idx then return "Test ActionTimeline performance" end @@ -158,6 +158,7 @@ function TimelineTestLayer:createToExtensionMenu() end function TimelineTestLayer:creatTitleAndSubTitle(idx) + print("set title") local title = cc.Label:createWithTTF(TimelineTestLayer.title(idx), "fonts/Thonburi.ttf", 18) title:setColor(cc.c3b(255,0,0)) self:addChild(title, 1, 10000) @@ -185,11 +186,8 @@ function TestActionTimeline.extend(target) end function TestActionTimeline:onEnter() - local node = cc.CSLoader:createNode("ActionTimeline/DemoPlayer.csb") - local action = cc.CSLoader:createTimeline("ActionTimeline/DemoPlayer.csb") - node:runAction(action) - action:gotoFrameAndPlay(0, 40, true) + local node = cc.CSLoader:createActionTimelineNode("ActionTimeline/DemoPlayer.csb", 0, 40, true) node:setScale(0.2) node:setPosition(VisibleRect:center()) @@ -237,11 +235,8 @@ end function TestChangePlaySection:onEnter() - local node = cc.CSLoader:createNode("ActionTimeline/DemoPlayer.csb") - local action = cc.CSLoader:createTimeline("ActionTimeline/DemoPlayer.csb") - - node:runAction(action) - action:gotoFrameAndPlay(41, action:getDuration(), true) + local node = cc.CSLoader:createActionTimelineNode("ActionTimeline/DemoPlayer.csb", 41, 81, true); + local action = node:getActionTimeline() node:setScale(0.2) node:setPosition(VisibleRect:center()) @@ -302,16 +297,12 @@ function TestTimelineFrameEvent.extend(target) end function TestTimelineFrameEvent:onEnter() - cc.SpriteFrameCache:getInstance():addSpriteFrames("armature/Cowboy0.plist", "armature/Cowboy0.png") - - local node = cc.CSLoader:createNode("ActionTimeline/boy_1.csb") - local action = cc.CSLoader:createTimeline("ActionTimeline/boy_1.csb") - node:runAction(action) - action:gotoFrameAndPlay(0, 60, true) + local node = cc.CSLoader:createActionTimelineNode("ActionTimeline/DemoPlayer.csb", 0, 40, true); + local action = node:getActionTimeline() node:setScale(0.2) - node:setPosition(150, 100) + node:setPosition(VisibleRect:center()) self:addChild(node) local function onFrameEvent(frame) @@ -372,11 +363,7 @@ end function TestTimelinePerformance:onEnter() for i = 1,100 do - local node = cc.CSLoader:createNode("ActionTimeline/DemoPlayer.csb") - local action = cc.CSLoader:createTimeline("ActionTimeline/DemoPlayer.csb") - - node:runAction(action) - action:gotoFrameAndPlay(70, action:getDuration(), true) + local node = cc.CSLoader:createActionTimelineNode("ActionTimeline/DemoPlayer.csb", 41, 81, true); node:setScale(0.1) node:setPosition((i - 1) * 2, 100) diff --git a/tools/release/generate_docs.sh b/tools/release/generate_docs.sh new file mode 100755 index 000000000000..1040fb8efb99 --- /dev/null +++ b/tools/release/generate_docs.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +#try to grab the doxygen version modified by me +#TODO: if the doxygen is not correct, we should install it manually + + +sed -i .bak '/CC_DEPRECATED_ATTRIBUTE CC_DLL/,/NS_CC_END/d' ../../cocos/base/ccUTF8.h +# git diff > doc-patch.patch +# mv doc-patch.patch docs +#we need to generate the patch automatically and remove it after applying +# patch -fp1 < docs/doc-patch.patch + + +version=`grep -e 'return' ../../cocos/cocos2d.cpp | awk '{print substr($3,0,length($3)-2)}'` +echo $version +cd ../../docs +#we should read cocos2d.cpp and retrieve the version number +sed -i .bak "s/3\.0/${version}/g" doxygen.config + +rm doxygen.config.bak + +doxygen doxygen.config + +git checkout . ../cocos/base/ccUTF8.h + +rm debug.txt diff --git a/tools/tolua/cocos2dx_csloader.ini b/tools/tolua/cocos2dx_csloader.ini index ef7116c724ab..a4710ed4737d 100644 --- a/tools/tolua/cocos2dx_csloader.ini +++ b/tools/tolua/cocos2dx_csloader.ini @@ -36,7 +36,7 @@ classes = CSLoader # will apply to all class names. This is a convenience wildcard to be able to skip similar named # functions from all classes. -skip = CSLoader::[nodeFromXML nodeFromProtocolBuffers createTimeline nodeWithFlatBuffers] +skip = CSLoader::[nodeFromXML nodeFromProtocolBuffers createTimeline nodeWithFlatBuffers createActionTimelineNode] rename_functions = diff --git a/tools/tolua/cocos2dx_studio.ini b/tools/tolua/cocos2dx_studio.ini index 995692a6c125..34639066d7d9 100644 --- a/tools/tolua/cocos2dx_studio.ini +++ b/tools/tolua/cocos2dx_studio.ini @@ -30,7 +30,7 @@ headers = %(cocosdir)s/cocos/editor-support/cocostudio/CocoStudio.h # what classes to produce code for. You can use regular expressions here. When testing the regular # expression, it will be enclosed in "^$", like this: "^Menu*$". -classes = Armature ArmatureAnimation Skin Bone ArmatureDataManager \w+Data$ ActionManagerEx ComAudio ComController ComAttribute ComRender BatchNode SceneReader GUIReader ActionObject Tween DisplayManager NodeReader ActionTimeline.* .*Frame$ Timeline +classes = Armature ArmatureAnimation Skin Bone ArmatureDataManager \w+Data$ ActionManagerEx ComAudio ComController ComAttribute ComRender BatchNode SceneReader GUIReader ActionObject Tween DisplayManager NodeReader ActionTimeline.* .*Frame$ Timeline ActionTimelineNode # what should we skip? in the format ClassName::[function function] # ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also diff --git a/tools/travis-scripts/travis_mac.yml b/tools/travis-scripts/travis_mac.yml index 611e72263f10..2b00d9849287 100644 --- a/tools/travis-scripts/travis_mac.yml +++ b/tools/travis-scripts/travis_mac.yml @@ -10,10 +10,10 @@ env: # - PLATFORM=mac-ios SDK=iphonesimulator7.1 ARCH=x86_64 SCHEME="build all tests iOS" - PLATFORM=mac-ios SDK=macosx10.9 ARCH=x86_64 SCHEME="build all tests Mac" -notifications: - email: - - xiaoming.zhang@cocos2d-x.org - - jianhua.chen@cocos2d-x.org +#notifications: +# email: +# - xiaoming.zhang@cocos2d-x.org +# - jianhua.chen@cocos2d-x.org # whitelist branches: