Merge branch 'v3' of https://github.com/cocos2d/cocos2d-x into v3luaruntime

This commit is contained in:
chuanweizhang2013 2014-06-25 11:39:17 +08:00
commit ac539131e2
151 changed files with 5323 additions and 2371 deletions

View File

@ -1,10 +1,15 @@
cocos2d-x-3.2 ???
[NEW] Node: added getName(), setName(), getChildByName(), enumerateChildren()
[NEW] Label: support setting line height and additional kerning of label that not using system font
[NEW] Lua-binding: Animation3D supported
[NEW] Node: added getName(), setName(), getChildByName(), enumerateChildren()
[NEW] Node: physical body supports rotation
[FIX] FileUtils: getStringFromFile may return a unterminated string
[FIX] Lua-binding: Sequence:create will cause drop-dead issue
[FIX] Studio support: NodeReader may cause crash
[FIX] UIButton: doesn't support TTF font
[FIX] UIListView: addEventListener can not work
cocos2d-x-3.2-alpha0 Jun.17 2014
[NEW] Console: add a command to show engine version

View File

@ -999,6 +999,10 @@
29CB8F4D1929D1BB00C841D6 /* UILayoutManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 29CB8F4A1929D1BB00C841D6 /* UILayoutManager.cpp */; };
29CB8F4E1929D1BB00C841D6 /* UILayoutManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 29CB8F4B1929D1BB00C841D6 /* UILayoutManager.h */; };
29CB8F4F1929D1BB00C841D6 /* UILayoutManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 29CB8F4B1929D1BB00C841D6 /* UILayoutManager.h */; };
29E99D1E1957BA7000046604 /* CocoLoader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 29E99D1C1957BA7000046604 /* CocoLoader.cpp */; };
29E99D1F1957BA7000046604 /* CocoLoader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 29E99D1C1957BA7000046604 /* CocoLoader.cpp */; };
29E99D201957BA7000046604 /* CocoLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 29E99D1D1957BA7000046604 /* CocoLoader.h */; };
29E99D211957BA7000046604 /* CocoLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 29E99D1D1957BA7000046604 /* CocoLoader.h */; };
2AC795DB1862870F005EC8E1 /* SkeletonBounds.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2AC795D918628689005EC8E1 /* SkeletonBounds.cpp */; };
2AC795DC1862870F005EC8E1 /* Event.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2AC795D51862867D005EC8E1 /* Event.cpp */; };
2AC795DD1862870F005EC8E1 /* EventData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2AC795D71862867D005EC8E1 /* EventData.cpp */; };
@ -2309,6 +2313,8 @@
299754F3193EC95400A54AC3 /* ObjectFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ObjectFactory.h; path = ../base/ObjectFactory.h; sourceTree = "<group>"; };
29CB8F4A1929D1BB00C841D6 /* UILayoutManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UILayoutManager.cpp; sourceTree = "<group>"; };
29CB8F4B1929D1BB00C841D6 /* UILayoutManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UILayoutManager.h; sourceTree = "<group>"; };
29E99D1C1957BA7000046604 /* CocoLoader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CocoLoader.cpp; sourceTree = "<group>"; };
29E99D1D1957BA7000046604 /* CocoLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CocoLoader.h; sourceTree = "<group>"; };
2AC795D318628672005EC8E1 /* BoundingBoxAttachment.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BoundingBoxAttachment.cpp; sourceTree = "<group>"; };
2AC795D418628672005EC8E1 /* BoundingBoxAttachment.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BoundingBoxAttachment.h; sourceTree = "<group>"; };
2AC795D51862867D005EC8E1 /* Event.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Event.cpp; sourceTree = "<group>"; };
@ -3641,6 +3647,8 @@
1A8C5946180E930E00EF57C3 /* cocostudio */ = {
isa = PBXGroup;
children = (
29E99D1C1957BA7000046604 /* CocoLoader.cpp */,
29E99D1D1957BA7000046604 /* CocoLoader.h */,
0634A4C4194B19E400E608AF /* ActionTimeline */,
50FCEB6818C72017004AD434 /* WidgetReader */,
06CAAAC1186AD63B0012A414 /* TriggerObj.h */,
@ -5162,6 +5170,7 @@
1AD71E0D180E26E600808F54 /* CocosBuilder.h in Headers */,
1AD71E97180E26E600808F54 /* Animation.h in Headers */,
1AD71E9B180E26E600808F54 /* AnimationState.h in Headers */,
29E99D201957BA7000046604 /* CocoLoader.h in Headers */,
1A01C69218F57BE800EFE3A6 /* CCDouble.h in Headers */,
50ABBE251925AB6F00A911A9 /* base64.h in Headers */,
50ABBEC91925AB6F00A911A9 /* firePngData.h in Headers */,
@ -5469,6 +5478,7 @@
06CAAACE186AD7FA0012A414 /* TriggerBase.h in Headers */,
503DD8EC1926736A00CD74DD /* CCGLView.h in Headers */,
50FCEBC218C72017004AD434 /* TextFieldReader.h in Headers */,
29E99D211957BA7000046604 /* CocoLoader.h in Headers */,
50ABBEBA1925AB6F00A911A9 /* ccUTF8.h in Headers */,
1A570068180BC5A10088DEC7 /* CCActionCamera.h in Headers */,
1A57006C180BC5A10088DEC7 /* CCActionCatmullRom.h in Headers */,
@ -6173,6 +6183,7 @@
ED9C6A9418599AD8000A5232 /* CCNodeGrid.cpp in Sources */,
06CAAACB186AD7F20012A414 /* TriggerMng.cpp in Sources */,
46A170E61807CECA005B8026 /* CCPhysicsBody.cpp in Sources */,
29E99D1E1957BA7000046604 /* CocoLoader.cpp in Sources */,
50ABBDA71925AB4100A911A9 /* CCRenderCommand.cpp in Sources */,
50ABBD501925AB0000A911A9 /* Quaternion.cpp in Sources */,
50ABBEBB1925AB6F00A911A9 /* ccUtils.cpp in Sources */,
@ -6633,6 +6644,7 @@
50ABBE621925AB6F00A911A9 /* CCEventListenerAcceleration.cpp in Sources */,
B37510811823ACA100B3BA6A /* CCPhysicsJointInfo_chipmunk.cpp in Sources */,
2905FA8D18CF08D100240AA3 /* UIWidget.cpp in Sources */,
29E99D1F1957BA7000046604 /* CocoLoader.cpp in Sources */,
B29594B51926D5EC003EEF37 /* CCMeshCommand.cpp in Sources */,
0634A4D5194B19E400E608AF /* CCActionTimelineCache.cpp in Sources */,
50ABBE7E1925AB6F00A911A9 /* CCEventTouch.cpp in Sources */,

View File

@ -5476,6 +5476,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_IDENTITY = "iPhone Developer";
DEBUG_INFORMATION_FORMAT = dwarf;
GCC_PREPROCESSOR_DEFINITIONS = (
"$(inherited)",
CC_TARGET_OS_IPHONE,
@ -5492,6 +5493,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_IDENTITY = "iPhone Developer";
DEBUG_INFORMATION_FORMAT = dwarf;
GCC_PREPROCESSOR_DEFINITIONS = (
"$(inherited)",
CC_TARGET_OS_IPHONE,

View File

@ -828,9 +828,27 @@ void RotateTo::update(float time)
{
if (_target)
{
#if CC_USE_PHYSICS
if (_target->getPhysicsBody() != nullptr && _startAngleX == _startAngleY && _diffAngleX == _diffAngleY)
{
_target->setRotation(_startAngleX + _diffAngleX * time);
}
else
{
// _startAngleX != _startAngleY || _diffAngleX != _diffAngleY
if (_target->getPhysicsBody() != nullptr)
{
CCLOG("RotateTo WARNING: PhysicsBody doesn't support skew rotation");
}
_target->setRotationSkewX(_startAngleX + _diffAngleX * time);
_target->setRotationSkewY(_startAngleY + _diffAngleY * time);
}
#else
_target->setRotationSkewX(_startAngleX + _diffAngleX * time);
_target->setRotationSkewY(_startAngleY + _diffAngleY * time);
#endif // CC_USE_PHYSICS
}
}
RotateTo *RotateTo::reverse() const
@ -952,9 +970,27 @@ void RotateBy::update(float time)
}
else
{
#if CC_USE_PHYSICS
if (_target->getPhysicsBody() != nullptr && _startAngleZ_X == _startAngleZ_Y && _angleZ_X == _angleZ_Y)
{
_target->setRotation(_startAngleZ_X + _angleZ_X * time);
}
else
{
// _startAngleZ_X != _startAngleZ_Y || _angleZ_X != _angleZ_Y
if (_target->getPhysicsBody() != nullptr)
{
CCLOG("RotateBy WARNING: PhysicsBody doesn't support skew rotation");
}
_target->setRotationSkewX(_startAngleZ_X + _angleZ_X * time);
_target->setRotationSkewY(_startAngleZ_Y + _angleZ_Y * time);
}
#else
_target->setRotationSkewX(_startAngleZ_X + _angleZ_X * time);
_target->setRotationSkewY(_startAngleZ_Y + _angleZ_Y * time);
#endif // CC_USE_PHYSICS
}
}
}

View File

@ -370,6 +370,7 @@ class CC_DLL RotateBy : public ActionInterval
public:
/** creates the action */
static RotateBy* create(float duration, float deltaAngle);
/** @warning The physics body contained in Node doesn't support rotate with different x and y angle. */
static RotateBy* create(float duration, float deltaAngleZ_X, float deltaAngleZ_Y);
static RotateBy* create(float duration, const Vec3& deltaAngle3D);
@ -387,6 +388,7 @@ CC_CONSTRUCTOR_ACCESS:
/** initializes the action */
bool initWithDuration(float duration, float deltaAngle);
/** @warning The physics body contained in Node doesn't support rotate with different x and y angle. */
bool initWithDuration(float duration, float deltaAngleZ_X, float deltaAngleZ_Y);
bool initWithDuration(float duration, const Vec3& deltaAngle3D);
@ -675,6 +677,7 @@ private:
/** @brief Scales a Node object to a zoom factor by modifying it's scale attribute.
@warning This action doesn't support "reverse"
@warning The physics body contained in Node doesn't support this action.
*/
class CC_DLL ScaleTo : public ActionInterval
{
@ -726,6 +729,7 @@ private:
};
/** @brief Scales a Node object a zoom factor by modifying it's scale attribute.
@warning The physics body contained in Node doesn't support this action.
*/
class CC_DLL ScaleBy : public ScaleTo
{

View File

@ -203,6 +203,13 @@ void Node::setSkewX(float skewX)
if (_skewX == skewX)
return;
#if CC_USE_PHYSICS
if (_physicsBody != nullptr)
{
CCLOG("Node WARNING: PhysicsBody doesn't support setSkewX");
}
#endif
_skewX = skewX;
_transformUpdated = _transformDirty = _inverseDirty = true;
}
@ -217,6 +224,13 @@ void Node::setSkewY(float skewY)
if (_skewY == skewY)
return;
#if CC_USE_PHYSICS
if (_physicsBody != nullptr)
{
CCLOG("Node WARNING: PhysicsBody doesn't support setSkewY");
}
#endif
_skewY = skewY;
_transformUpdated = _transformDirty = _inverseDirty = true;
}
@ -298,10 +312,9 @@ void Node::setRotation3D(const Vec3& rotation)
_rotationZ_Y = _rotationZ_X = rotation.z;
#if CC_USE_PHYSICS
if (_physicsBody)
if (_physicsBody != nullptr)
{
Scene* scene = _physicsBody->getWorld() != nullptr ? &_physicsBody->getWorld()->getScene() : nullptr;
updatePhysicsBodyRotation(scene);
CCLOG("Node WARNING: PhysicsBody doesn't support setRotation3D");
}
#endif
}
@ -319,6 +332,13 @@ void Node::setRotationSkewX(float rotationX)
if (_rotationZ_X == rotationX)
return;
#if CC_USE_PHYSICS
if (_physicsBody != nullptr)
{
CCLOG("Node WARNING: PhysicsBody doesn't support setRotationSkewX");
}
#endif
_rotationZ_X = rotationX;
_transformUpdated = _transformDirty = _inverseDirty = true;
}
@ -333,6 +353,13 @@ void Node::setRotationSkewY(float rotationY)
if (_rotationZ_Y == rotationY)
return;
#if CC_USE_PHYSICS
if (_physicsBody != nullptr)
{
CCLOG("Node WARNING: PhysicsBody doesn't support setRotationSkewY");
}
#endif
_rotationZ_Y = rotationY;
_transformUpdated = _transformDirty = _inverseDirty = true;
}
@ -350,6 +377,13 @@ void Node::setScale(float scale)
if (_scaleX == scale)
return;
#if CC_USE_PHYSICS
if (_physicsBody != nullptr)
{
CCLOG("Node WARNING: PhysicsBody doesn't support setScale");
}
#endif
_scaleX = _scaleY = _scaleZ = scale;
_transformUpdated = _transformDirty = _inverseDirty = true;
}
@ -366,6 +400,13 @@ void Node::setScale(float scaleX,float scaleY)
if (_scaleX == scaleX && _scaleY == scaleY)
return;
#if CC_USE_PHYSICS
if (_physicsBody != nullptr)
{
CCLOG("Node WARNING: PhysicsBody doesn't support setScale");
}
#endif
_scaleX = scaleX;
_scaleY = scaleY;
_transformUpdated = _transformDirty = _inverseDirty = true;
@ -377,6 +418,13 @@ void Node::setScaleX(float scaleX)
if (_scaleX == scaleX)
return;
#if CC_USE_PHYSICS
if (_physicsBody != nullptr)
{
CCLOG("Node WARNING: PhysicsBody doesn't support setScaleX");
}
#endif
_scaleX = scaleX;
_transformUpdated = _transformDirty = _inverseDirty = true;
}
@ -393,6 +441,13 @@ void Node::setScaleZ(float scaleZ)
if (_scaleZ == scaleZ)
return;
#if CC_USE_PHYSICS
if (_physicsBody != nullptr)
{
CCLOG("Node WARNING: PhysicsBody doesn't support setScaleZ");
}
#endif
_scaleZ = scaleZ;
_transformUpdated = _transformDirty = _inverseDirty = true;
}
@ -409,6 +464,13 @@ void Node::setScaleY(float scaleY)
if (_scaleY == scaleY)
return;
#if CC_USE_PHYSICS
if (_physicsBody != nullptr)
{
CCLOG("Node WARNING: PhysicsBody doesn't support setScaleY");
}
#endif
_scaleY = scaleY;
_transformUpdated = _transformDirty = _inverseDirty = true;
}

View File

@ -201,6 +201,8 @@ public:
* It is a scaling factor that multiplies the width of the node and its children.
*
* @param scaleX The scale factor on X axis.
*
* @warning The physics body doesn't support this.
*/
virtual void setScaleX(float scaleX);
/**
@ -219,6 +221,8 @@ public:
* It is a scaling factor that multiplies the height of the node and its children.
*
* @param scaleY The scale factor on Y axis.
*
* @warning The physics body doesn't support this.
*/
virtual void setScaleY(float scaleY);
/**
@ -236,6 +240,8 @@ public:
* The Default value is 1.0 if you haven't changed it before.
*
* @param scaleY The scale factor on Y axis.
*
* @warning The physics body doesn't support this.
*/
virtual void setScaleZ(float scaleZ);
/**
@ -254,6 +260,8 @@ public:
* It is a scaling factor that multiplies the width, height and depth of the node and its children.
*
* @param scale The scale factor for both X and Y axis.
*
* @warning The physics body doesn't support this.
*/
virtual void setScale(float scale);
/**
@ -273,6 +281,8 @@ public:
*
* @param scaleX The scale factor on X axis.
* @param scaleY The scale factor on Y axis.
*
* @warning The physics body doesn't support this.
*/
virtual void setScale(float scaleX, float scaleY);
@ -395,6 +405,8 @@ public:
* The default skewX angle is 0. Positive values distort the node in a CW direction.
*
* @param skewX The X skew angle of the node in degrees.
*
* @warning The physics body doesn't support this.
*/
virtual void setSkewX(float skewX);
/**
@ -418,6 +430,8 @@ public:
* The default skewY angle is 0. Positive values distort the node in a CCW direction.
*
* @param skewY The Y skew angle of the node in degrees.
*
* @warning The physics body doesn't support this.
*/
virtual void setSkewY(float skewY);
/**
@ -520,6 +534,8 @@ public:
/**
* Sets the rotation (X,Y,Z) in degrees.
* Useful for 3d rotations
*
* @warning The physics body doesn't support this.
*/
virtual void setRotation3D(const Vec3& rotation);
/**
@ -537,6 +553,8 @@ public:
* Positive values rotate node clockwise, and negative values for anti-clockwise.
*
* @param rotationX The X rotation in degrees which performs a horizontal rotational skew.
*
* @warning The physics body doesn't support this.
*/
virtual void setRotationSkewX(float rotationX);
CC_DEPRECATED_ATTRIBUTE virtual void setRotationX(float rotationX) { return setRotationSkewX(rotationX); }
@ -561,6 +579,8 @@ public:
* Positive values rotate node clockwise, and negative values for anti-clockwise.
*
* @param rotationY The Y rotation in degrees.
*
* @warning The physics body doesn't support this.
*/
virtual void setRotationSkewY(float rotationY);
CC_DEPRECATED_ATTRIBUTE virtual void setRotationY(float rotationY) { return setRotationSkewY(rotationY); }

View File

@ -521,8 +521,8 @@ void Sprite::updateTransform(void)
else
{
CCASSERT( dynamic_cast<Sprite*>(_parent), "Logic error in Sprite. Parent must be a Sprite");
Mat4 nodeToParent = getNodeToParentTransform();
Mat4 parentTransform = static_cast<Sprite*>(_parent)->_transformToBatch;
const Mat4 &nodeToParent = getNodeToParentTransform();
Mat4 &parentTransform = static_cast<Sprite*>(_parent)->_transformToBatch;
_transformToBatch = parentTransform * nodeToParent;
}
@ -530,7 +530,7 @@ void Sprite::updateTransform(void)
// calculate the Quad based on the Affine Matrix
//
Size size = _rect.size;
Size &size = _rect.size;
float x1 = _offsetPosition.x;
float y1 = _offsetPosition.y;

View File

@ -171,7 +171,7 @@ void ActionTimeline::step(float delta)
if(!_playing)
_time = _endFrame * _frameInternal;
else
_time = _startFrame * _frameInternal;
gotoFrameAndPlay(_startFrame, _endFrame, _loop);
}
}

View File

@ -332,7 +332,7 @@ Frame* ActionTimelineCache::loadTextureFrame(const rapidjson::Value& json)
const char* texture = DICTOOL->getStringValue_json(json, Value);
if(texture != NULL)
if(texture != nullptr)
{
std::string path = texture;
@ -354,7 +354,7 @@ Frame* ActionTimelineCache::loadEventFrame(const rapidjson::Value& json)
const char* evnt = DICTOOL->getStringValue_json(json, Value);
if(evnt != NULL)
if(evnt != nullptr)
frame->setEvent(evnt);
return frame;

View File

@ -175,7 +175,7 @@ void RotationFrame::onEnter(Frame *nextFrame)
void RotationFrame::apply(float percent)
{
if (_tween && percent != 0 || _betwennRotation != 0)
if (_tween && percent != 0 && _betwennRotation != 0)
{
float rotation = _rotation + percent * _betwennRotation;
_node->setRotation(rotation);
@ -227,7 +227,7 @@ void SkewFrame::onEnter(Frame *nextFrame)
void SkewFrame::apply(float percent)
{
if (_tween && percent != 0 || (_betweenSkewX != 0 || _betweenSkewY != 0))
if (_tween && percent != 0 && (_betweenSkewX != 0 || _betweenSkewY != 0))
{
float skewx = _skewX + percent * _betweenSkewX;
float skewy = _skewY + percent * _betweenSkewY;
@ -282,7 +282,7 @@ void RotationSkewFrame::onEnter(Frame *nextFrame)
void RotationSkewFrame::apply(float percent)
{
if (_tween && percent != 0 || (_betweenSkewX != 0 || _betweenSkewY != 0))
if (_tween && percent != 0 && (_betweenSkewX != 0 || _betweenSkewY != 0))
{
float skewx = _skewX + percent * _betweenSkewX;
float skewy = _skewY + percent * _betweenSkewY;
@ -335,7 +335,7 @@ void PositionFrame::onEnter(Frame *nextFrame)
void PositionFrame::apply(float percent)
{
if (_tween && percent != 0 || (_betweenX != 0 || _betweenY != 0))
if (_tween && percent != 0 && (_betweenX != 0 || _betweenY != 0))
{
Point p;
p.x = _position.x + _betweenX * percent;
@ -389,7 +389,7 @@ void ScaleFrame::onEnter(Frame *nextFrame)
void ScaleFrame::apply(float percent)
{
if (_tween && percent != 0 || (_betweenScaleX != 0 || _betweenScaleY != 0))
if (_tween && percent != 0 && (_betweenScaleX != 0 || _betweenScaleY != 0))
{
float scaleX = _scaleX + _betweenScaleX * percent;
float scaleY = _scaleY + _betweenScaleY * percent;
@ -523,7 +523,7 @@ void ColorFrame::onEnter(Frame *nextFrame)
void ColorFrame::apply(float percent)
{
if (_tween && percent != 0 || (_betweenAlpha !=0 || _betweenRed != 0 || _betweenGreen != 0 || _betweenBlue != 0))
if (_tween && percent != 0 && (_betweenAlpha !=0 || _betweenRed != 0 || _betweenGreen != 0 || _betweenBlue != 0))
{
GLubyte alpha = _alpha + _betweenAlpha * percent;

View File

@ -26,7 +26,7 @@ THE SOFTWARE.
#include "CCActionTimelineCache.h"
#include "CCActionTimeline.h"
#include "../CCSGUIReader.h"
#include "cocostudio/CCSGUIReader.h"
using namespace cocos2d;
using namespace ui;
@ -150,7 +150,6 @@ void NodeReader::init()
_funcs.insert(Pair(ClassName_Widget, std::bind(&NodeReader::loadWidget, this, _1)));
_funcs.insert(Pair(ClassName_Label, std::bind(&NodeReader::loadWidget, this, _1)));
_guiReader = new WidgetPropertiesReader0300();
}
Node* NodeReader::createNode(const std::string& filename)
@ -220,7 +219,7 @@ Node* NodeReader::loadNode(const rapidjson::Value& json)
Node* node = nullptr;
std::string nodeType = DICTOOL->getStringValue_json(json, CLASSNAME);
NodeCreateFunc func = _funcs.at(nodeType);
NodeCreateFunc func = _funcs[nodeType];
if (func != nullptr)
{
const rapidjson::Value& options = DICTOOL->getSubDictionary_json(json, OPTIONS);
@ -383,9 +382,9 @@ Node* NodeReader::loadSprite(const rapidjson::Value& json)
bool flipY = DICTOOL->getBooleanValue_json(json, FLIPY);
if(flipX != false)
sprite->setFlipX(flipX);
sprite->setFlippedX(flipX);
if(flipY != false)
sprite->setFlipY(flipY);
sprite->setFlippedY(flipY);
return sprite;
}
@ -445,7 +444,9 @@ Node* NodeReader::loadWidget(const rapidjson::Value& json)
WidgetReaderProtocol* reader = dynamic_cast<WidgetReaderProtocol*>(ObjectFactory::getInstance()->createObject(readerName));
_guiReader->setPropsForAllWidgetFromJsonDictionary(reader, widget, json);
WidgetPropertiesReader0300* guiReader = new WidgetPropertiesReader0300();
guiReader->setPropsForAllWidgetFromJsonDictionary(reader, widget, json);
CC_SAFE_DELETE(guiReader);
int actionTag = DICTOOL->getIntValue_json(json, ACTION_TAG);
widget->setUserObject(ActionTimelineData::create(actionTag));

View File

@ -30,7 +30,6 @@ THE SOFTWARE.
namespace cocostudio {
class WidgetPropertiesReader0300;
namespace timeline{
@ -78,7 +77,6 @@ protected:
std::unordered_map<std::string, NodeCreateFunc> _funcs;
WidgetPropertiesReader0300* _guiReader;
bool _recordJsonPath;
std::string _jsonPath;

View File

@ -39,6 +39,7 @@ CCSSceneReader.cpp \
TriggerBase.cpp \
TriggerMng.cpp \
TriggerObj.cpp \
CocoLoader.cpp \
WidgetReader/WidgetReader.cpp \
WidgetReader/ButtonReader/ButtonReader.cpp \
WidgetReader/CheckBoxReader/CheckBoxReader.cpp \

View File

@ -24,6 +24,7 @@ THE SOFTWARE.
#include "cocostudio/CCActionManagerEx.h"
#include "cocostudio/DictionaryHelper.h"
#include "cocostudio/CocoLoader.h"
using namespace cocos2d;
@ -71,6 +72,42 @@ void ActionManagerEx::initWithDictionary(const char* jsonName,const rapidjson::V
_actionDic.insert(std::pair<std::string, cocos2d::Vector<ActionObject*>>(fileName, actionList));
}
void ActionManagerEx::initWithBinary(const char* file,
cocos2d::Ref *root,
CocoLoader* cocoLoader,
stExpCocoNode* pCocoNode)
{
std::string path = file;
ssize_t pos = path.find_last_of("/");
std::string fileName = path.substr(pos+1,path.length());
CCLOG("filename == %s",fileName.c_str());
cocos2d::Vector<ActionObject*> actionList;
stExpCocoNode *stChildArray = pCocoNode->GetChildArray();
stExpCocoNode *actionNode = nullptr;
for (int i=0; i < pCocoNode->GetChildNum(); ++i) {
std::string key = stChildArray[i].GetName(cocoLoader);
if (key == "actionlist") {
actionNode = &stChildArray[i];
break;
}
}
if (nullptr != actionNode)
{
int actionCount = actionNode->GetChildNum();
for (int i = 0; i < actionCount; ++i) {
ActionObject* action = new ActionObject();
action->autorelease();
action->initWithBinary(cocoLoader, actionNode->GetChildArray(), root);
actionList.pushBack(action);
}
}
_actionDic.insert(std::pair<std::string, cocos2d::Vector<ActionObject*>>(fileName, actionList));
}
ActionObject* ActionManagerEx::getActionByName(const char* jsonName,const char* actionName)
{

View File

@ -30,6 +30,9 @@ THE SOFTWARE.
namespace cocostudio {
class CocoLoader;
struct stExpCocoNode;
class ActionManagerEx:public cocos2d::Ref
{
public:
@ -96,6 +99,8 @@ public:
/*init properties with json dictionay*/
void initWithDictionary(const char* jsonName,const rapidjson::Value &dic, Ref* root);
void initWithBinary(const char* file, Ref* root, CocoLoader* cocoLoader, stExpCocoNode* pCocoNode);
/**
* Release all actions.
*

View File

@ -27,6 +27,7 @@ THE SOFTWARE.
#include "cocostudio/DictionaryHelper.h"
#include "ui/UIWidget.h"
#include "ui/UIHelper.h"
#include "cocostudio/CocoLoader.h"
using namespace cocos2d;
using namespace ui;
@ -168,6 +169,149 @@ void ActionNode::initWithDictionary(const rapidjson::Value& dic, Ref* root)
initActionNodeFromRoot(root);
}
int ActionNode::valueToInt(const std::string& value)
{
return atoi(value.c_str());
}
bool ActionNode::valueToBool(const std::string& value)
{
int intValue = valueToInt(value);
if (1 == intValue) {
return true;
}else{
return false;
}
}
float ActionNode::valueToFloat(const std::string& value)
{
return atof(value.c_str());
}
void ActionNode::initWithBinary(CocoLoader *cocoLoader,
stExpCocoNode *cocoNode,
cocos2d::Ref *root)
{
stExpCocoNode *stChildNode = cocoNode;
int actionNodeCount = stChildNode->GetChildNum();
stChildNode = stChildNode[0].GetChildArray();
stExpCocoNode *frameListNode = nullptr;
for (int i = 0; i < actionNodeCount; ++i) {
std::string key = stChildNode[i].GetName(cocoLoader);
std::string value = stChildNode[i].GetValue();
if (key == "ActionTag") {
setActionTag(valueToInt(value));
}else if (key == "actionframelist"){
frameListNode = &stChildNode[i];
}
}
int actionFrameCount = frameListNode->GetChildNum();
stExpCocoNode *stFrameChildNode = frameListNode->GetChildArray();
for (int i=0; i<actionFrameCount; i++) {
int frameIndex;
int frameTweenType;
float positionX;
float positionY;
float scaleX;
float scaleY;
float rotation;
int opacity;
int colorR = -1;
int colorG = -1;
int colorB = -1;
std::vector<float> frameTweenParameter;
int framesCount = stFrameChildNode[i].GetChildNum();
stExpCocoNode *innerFrameNode = stFrameChildNode[i].GetChildArray();
for (int j = 0; j < framesCount; j++) {
std::string key = innerFrameNode[j].GetName(cocoLoader);
std::string value = innerFrameNode[j].GetValue();
if (key == "frameid") {
frameIndex = valueToInt(value);
}else if(key == "tweenType"){
frameTweenType = valueToInt(value);
}else if (key == "tweenParameter"){
// There are no tweenParameter args in the json file
int tweenParameterCount = innerFrameNode[j].GetChildNum();
stExpCocoNode *tweenParameterArray = innerFrameNode[j].GetChildArray();
for (int k = 0; k < tweenParameterCount; ++k) {
std::string t_key = tweenParameterArray[j].GetName(cocoLoader);
std::string t_value = tweenParameterArray[j].GetValue();
frameTweenParameter.push_back(valueToFloat(t_value));
}
}else if (key == "positionx"){
positionX = valueToFloat(value);
}else if (key == "positiony"){
positionY = valueToFloat(value);
ActionMoveFrame* actionFrame = new ActionMoveFrame();
actionFrame->autorelease();
actionFrame->setEasingType(frameTweenType);
actionFrame->setEasingParameter(frameTweenParameter);
actionFrame->setFrameIndex(frameIndex);
actionFrame->setPosition(Vec2(positionX, positionY));
auto cActionArray = _frameArray.at((int)kKeyframeMove);
cActionArray->pushBack(actionFrame);
}else if(key == "scalex"){
scaleX = valueToFloat(value);
}else if(key == "scaley"){
scaleY = valueToFloat(value);
ActionScaleFrame* actionFrame = new ActionScaleFrame();
actionFrame->autorelease();
actionFrame->setEasingType(frameTweenType);
actionFrame->setEasingParameter(frameTweenParameter);
actionFrame->setFrameIndex(frameIndex);
actionFrame->setScaleX(scaleX);
actionFrame->setScaleY(scaleY);
auto cActionArray = _frameArray.at((int)kKeyframeScale);
cActionArray->pushBack(actionFrame);
}else if (key == "rotation"){
rotation = valueToFloat(value);
ActionRotationFrame* actionFrame = new ActionRotationFrame();
actionFrame->autorelease();
actionFrame->setEasingType(frameTweenType);
actionFrame->setEasingParameter(frameTweenParameter);
actionFrame->setFrameIndex(frameIndex);
actionFrame->setRotation(rotation);
auto cActionArray = _frameArray.at((int)kKeyframeRotate);
cActionArray->pushBack(actionFrame);
}else if (key == "opacity"){
opacity = valueToInt(value);
ActionFadeFrame* actionFrame = new ActionFadeFrame();
actionFrame->autorelease();
actionFrame->setEasingType(frameTweenType);
actionFrame->setEasingParameter(frameTweenParameter);
actionFrame->setFrameIndex(frameIndex);
actionFrame->setOpacity(opacity);
auto cActionArray = _frameArray.at((int)kKeyframeFade);
cActionArray->pushBack(actionFrame);
}else if (key == "colorb"){
colorB = valueToInt(value);
}else if(key == "colorg"){
colorG = valueToInt(value);
}else if(key == "colorr"){
colorR = valueToInt(value);
ActionTintFrame* actionFrame = new ActionTintFrame();
actionFrame->autorelease();
actionFrame->setEasingType(frameTweenType);
actionFrame->setEasingParameter(frameTweenParameter);
actionFrame->setFrameIndex(frameIndex);
actionFrame->setColor(Color3B(colorR,colorG,colorB));
auto cActionArray = _frameArray.at((int)kKeyframeTint);
cActionArray->pushBack(actionFrame);
}
}
}
initActionNodeFromRoot(root);
}
void ActionNode::initActionNodeFromRoot(Ref* root)
{
Node* rootNode = dynamic_cast<Node*>(root);

View File

@ -30,6 +30,8 @@ THE SOFTWARE.
namespace cocostudio {
class CocoLoader;
struct stExpCocoNode;
/**
* @js NA
* @lua NA
@ -149,6 +151,7 @@ public:
/*init properties with a json dictionary*/
virtual void initWithDictionary(const rapidjson::Value& dic, cocos2d::Ref* root);
virtual void initWithBinary(CocoLoader* cocoLoader, stExpCocoNode* pCocoNode, Ref* root);
/**
* Gets if the action is done once time.
@ -157,6 +160,10 @@ public:
*/
virtual bool isActionDoneOnce();
protected:
int valueToInt(const std::string& value);
bool valueToBool(const std::string& value);
float valueToFloat(const std::string& value);
int _currentFrameIndex;
int _destFrameIndex;

View File

@ -24,6 +24,7 @@ THE SOFTWARE.
#include "cocostudio/CCActionObject.h"
#include "cocostudio/DictionaryHelper.h"
#include "cocostudio/CocoLoader.h"
#include "base/CCDirector.h"
#include "base/CCScheduler.h"
@ -127,6 +128,70 @@ void ActionObject::initWithDictionary(const rapidjson::Value& dic, Ref* root)
_fTotalTime = maxLength*_fUnitTime;
}
void ActionObject::initWithBinary(CocoLoader *cocoLoader,
stExpCocoNode *cocoNode,
cocos2d::Ref *root)
{
stExpCocoNode *stChildNode = cocoNode->GetChildArray();
stExpCocoNode *actionNodeList = nullptr;
int count = cocoNode->GetChildNum();
for (int i = 0; i < count; ++i) {
std::string key = stChildNode[i].GetName(cocoLoader);
std::string value = stChildNode[i].GetValue();
if (key == "name") {
setName(value.c_str());
}else if (key == "loop"){
setLoop(valueToBool(value));
}else if(key == "unittime"){
setUnitTime(valueToFloat(value));
}else if (key == "actionnodelist"){
actionNodeList = &stChildNode[i];
}
}
if(nullptr != actionNodeList)
{
int actionNodeCount = actionNodeList->GetChildNum();
stExpCocoNode *actionNodeArray = actionNodeList->GetChildArray();
int maxLength = 0;
for (int i=0; i<actionNodeCount; i++) {
ActionNode* actionNode = new ActionNode();
actionNode->autorelease();
actionNode->initWithBinary(cocoLoader, &actionNodeArray[i] , root);
actionNode->setUnitTime(getUnitTime());
_actionNodeList.pushBack(actionNode);
int length = actionNode->getLastFrameIndex() - actionNode->getFirstFrameIndex();
if(length > maxLength)
maxLength = length;
}
_fTotalTime = maxLength* _fUnitTime;
}
}
int ActionObject::valueToInt(const std::string& value)
{
return atoi(value.c_str());
}
bool ActionObject::valueToBool(const std::string& value)
{
int intValue = valueToInt(value);
if (1 == intValue) {
return true;
}else{
return false;
}
}
float ActionObject::valueToFloat(const std::string& value)
{
return atof(value.c_str());
}
void ActionObject::addActionNode(ActionNode* node)
{
if (node == nullptr)

View File

@ -31,6 +31,9 @@ THE SOFTWARE.
namespace cocostudio {
class CocoLoader;
struct stExpCocoNode;
/**
* @js NA
* @lua NA
@ -161,9 +164,16 @@ public:
/*init properties with a json dictionary*/
void initWithDictionary(const rapidjson::Value& dic, cocos2d::Ref* root);
void initWithBinary(CocoLoader* cocoLoader, stExpCocoNode* pCocoNode, cocos2d::Ref* root);
/*scheduler update function*/
void simulationActionUpdate(float dt);
protected:
int valueToInt(const std::string& value);
bool valueToBool(const std::string& value);
float valueToFloat(const std::string& value);
cocos2d::Vector<ActionNode*> _actionNodeList;
std::string _name;
bool _loop;

View File

@ -35,6 +35,9 @@ THE SOFTWARE.
#include "cocostudio/CCArmatureDefine.h"
#include "cocostudio/CCDatas.h"
#include "cocostudio/CocoLoader.h"
using namespace cocos2d;
@ -192,6 +195,10 @@ void DataReaderHelper::loadData()
{
DataReaderHelper::addDataFromJsonCache(pAsyncStruct->fileContent.c_str(), pDataInfo);
}
else if(pAsyncStruct->configType == CocoStudio_Binary)
{
DataReaderHelper::addDataFromBinaryCache(pAsyncStruct->fileContent.c_str(),pDataInfo);
}
// put the image info into the queue
_dataInfoMutex.lock();
@ -294,7 +301,16 @@ void DataReaderHelper::addDataFromFile(const std::string& filePath)
// Read content from file
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(filePath);
std::string contentStr = FileUtils::getInstance()->getStringFromFile(fullPath);
bool isbinarysrc = str==".csb";
std::string filemode("r");
if(isbinarysrc)
filemode += "b";
ssize_t filesize;
_dataReaderHelper->_getFileMutex.lock();
unsigned char *pBytes = FileUtils::getInstance()->getFileData(filePath, filemode.c_str(), &filesize);
std::string contentStr((const char*)pBytes,filesize);
_dataReaderHelper->_getFileMutex.unlock();
DataInfo dataInfo;
dataInfo.filename = filePathStr;
@ -308,6 +324,12 @@ void DataReaderHelper::addDataFromFile(const std::string& filePath)
{
DataReaderHelper::addDataFromJsonCache(contentStr, &dataInfo);
}
else if(str == ".csb")
{
DataReaderHelper::addDataFromBinaryCache(contentStr.c_str(),&dataInfo);
}
CC_SAFE_DELETE_ARRAY(pBytes);
}
void DataReaderHelper::addDataFromFileAsync(const std::string& imagePath, const std::string& plistPath, const std::string& filePath, Ref *target, SEL_SCHEDULE selector)
@ -391,8 +413,22 @@ void DataReaderHelper::addDataFromFileAsync(const std::string& imagePath, const
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(filePath);
bool isbinaryfilesrc = str==".csb";
std::string filereadmode("r");
if (isbinaryfilesrc) {
filereadmode += "b";
}
ssize_t size;
// XXX fileContent is being leaked
data->fileContent = FileUtils::getInstance()->getStringFromFile(fullPath);
_dataReaderHelper->_getFileMutex.lock();
unsigned char *pBytes = FileUtils::getInstance()->getFileData(fullPath.c_str() , filereadmode.c_str(), &size);
_dataReaderHelper->_getFileMutex.unlock();
Data bytecpy;
bytecpy.copy(pBytes, size);
data->fileContent = std::string((const char*)bytecpy.getBytes(), size);
CC_SAFE_DELETE_ARRAY(pBytes);
if (str == ".xml")
{
@ -402,6 +438,10 @@ void DataReaderHelper::addDataFromFileAsync(const std::string& imagePath, const
{
data->configType = CocoStudio_JSON;
}
else if(str == ".csb")
{
data->configType = CocoStudio_Binary;
}
// add async struct into queue
@ -1368,7 +1408,7 @@ DisplayData *DataReaderHelper::decodeBoneDisplay(const rapidjson::Value& json, D
displayData = new SpriteDisplayData();
const char *name = DICTOOL->getStringValue_json(json, A_NAME);
if(name != NULL)
if(name != nullptr)
{
((SpriteDisplayData *)displayData)->displayName = name;
}
@ -1701,4 +1741,843 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
}
void DataReaderHelper::addDataFromBinaryCache(const char *fileContent, DataInfo *dataInfo)
{
CocoLoader tCocoLoader;
if (tCocoLoader.ReadCocoBinBuff((char*)fileContent))
{
stExpCocoNode *tpRootCocoNode = tCocoLoader.GetRootCocoNode();
rapidjson::Type tType = tpRootCocoNode->GetType(&tCocoLoader);
if (rapidjson::kObjectType == tType)
{
stExpCocoNode *tpChildArray = tpRootCocoNode->GetChildArray();
int nCount = tpRootCocoNode->GetChildNum();
dataInfo->contentScale = 1.0f;
int length = 0;
std::string key;
stExpCocoNode* pDataArray;
for (int i = 0; i < nCount; ++i)
{
key = tpChildArray[i].GetName(&tCocoLoader);
if (key.compare(CONTENT_SCALE) == 0)
{
std::string value = tpChildArray[i].GetValue();
dataInfo->contentScale = atof(value.c_str());
}
else if ( 0 == key.compare(ARMATURE_DATA))
{
pDataArray = tpChildArray[i].GetChildArray();
length = tpChildArray[i].GetChildNum();
ArmatureData * armatureData;
for (int ii = 0; ii < length; ++ii)
{
armatureData = decodeArmature(&tCocoLoader, &pDataArray[ii], dataInfo);
if (dataInfo->asyncStruct)
{
_dataReaderHelper->_addDataMutex.lock();
}
ArmatureDataManager::getInstance()->addArmatureData(armatureData->name.c_str(), armatureData, dataInfo->filename.c_str());
armatureData->release();
if (dataInfo->asyncStruct)
{
_dataReaderHelper->_addDataMutex.unlock();
}
}
}
else if ( 0 == key.compare(ANIMATION_DATA))
{
pDataArray = tpChildArray[i].GetChildArray();
length = tpChildArray[i].GetChildNum();
AnimationData *animationData;
for (int ii = 0; ii < length; ++ii)
{
animationData = decodeAnimation(&tCocoLoader, &pDataArray[ii], dataInfo);
if (dataInfo->asyncStruct)
{
_dataReaderHelper->_addDataMutex.lock();
}
ArmatureDataManager::getInstance()->addAnimationData(animationData->name.c_str(), animationData, dataInfo->filename.c_str());
animationData->release();
if (dataInfo->asyncStruct)
{
_dataReaderHelper->_addDataMutex.unlock();
}
}
}
else if (key.compare(TEXTURE_DATA) == 0)
{
pDataArray = tpChildArray[i].GetChildArray();
length = tpChildArray[i].GetChildNum();
for (int ii = 0; ii < length; ++ii)
{
TextureData *textureData = decodeTexture(&tCocoLoader, &pDataArray[ii]);
if (dataInfo->asyncStruct)
{
_dataReaderHelper->_addDataMutex.lock();
}
ArmatureDataManager::getInstance()->addTextureData(textureData->name.c_str(), textureData, dataInfo->filename.c_str());
textureData->release();
if (dataInfo->asyncStruct)
{
_dataReaderHelper->_addDataMutex.unlock();
}
}
}
}
// Auto losprite file
bool autoLoad = dataInfo->asyncStruct == nullptr ? ArmatureDataManager::getInstance()->isAutoLoadSpriteFile() : dataInfo->asyncStruct->autoLoadSpriteFile;
if (autoLoad)
{
for (int i = 0; i < nCount; ++i)
{
key = tpChildArray[i].GetName(&tCocoLoader);
if( 0 != key.compare(CONFIG_FILE_PATH))
{
continue;
}
length = tpChildArray[i].GetChildNum();
stExpCocoNode *pConfigFilePath = tpChildArray[i].GetChildArray();
for (int ii = 0; ii < length; ii++)
{
const char *path = pConfigFilePath[ii].GetValue();
if (path == nullptr)
{
CCLOG("load CONFIG_FILE_PATH error.");
return;
}
std::string filePath = path;
filePath = filePath.erase(filePath.find_last_of("."));
if (dataInfo->asyncStruct)
{
dataInfo->configFileQueue.push(filePath);
}
else
{
std::string plistPath = filePath + ".plist";
std::string pngPath = filePath + ".png";
ArmatureDataManager::getInstance()->addSpriteFrameFromFile((dataInfo->baseFilePath + plistPath).c_str(), (dataInfo->baseFilePath + pngPath).c_str(), dataInfo->filename.c_str());
}
}
}
}
}
}
}
ArmatureData* DataReaderHelper::decodeArmature(CocoLoader *cocoLoader, stExpCocoNode *cocoNode, DataInfo *dataInfo)
{
ArmatureData *armatureData = new ArmatureData();
armatureData->init();
stExpCocoNode *pAramtureDataArray = cocoNode->GetChildArray();
const char *name = pAramtureDataArray[2].GetValue(); //DICTOOL->getStringValue_json(json, A_NAME);
if(name != nullptr)
{
armatureData->name = name;
}
float version = atof(pAramtureDataArray[1].GetValue());
dataInfo->cocoStudioVersion = armatureData->dataVersion = version; //DICTOOL->getFloatValue_json(json, VERSION, 0.1f);
int length = pAramtureDataArray[3].GetChildNum(); //DICTOOL->getArrayCount_json(json, BONE_DATA, 0);
stExpCocoNode *pBoneChildren = pAramtureDataArray[3].GetChildArray();
stExpCocoNode* child;
for (int i = 0; i < length; i++)
{
//const rapidjson::Value &dic = DICTOOL->getSubDictionary_json(json, BONE_DATA, i); //json[BONE_DATA][i];
child = &pBoneChildren[i];
BoneData *boneData = decodeBone(cocoLoader, child, dataInfo);
armatureData->addBoneData(boneData);
boneData->release();
}
return armatureData;
}
BoneData* DataReaderHelper::decodeBone(CocoLoader *cocoLoader, stExpCocoNode *cocoNode, DataInfo *dataInfo)
{
BoneData *boneData = new BoneData();
boneData->init();
decodeNode(boneData, cocoLoader, cocoNode, dataInfo);
int length = cocoNode->GetChildNum();
stExpCocoNode *pBoneChildren = cocoNode->GetChildArray();
stExpCocoNode* child;
const char *str = nullptr;
std::string key;
for (int i = 0; i < length; ++i)
{
child = &pBoneChildren[i];
key = child->GetName(cocoLoader);
str = child->GetValue();
if (key.compare(A_NAME) == 0)
{
//DICTOOL->getStringValue_json(json, A_NAME);
if(str != nullptr)
{
boneData->name = str;
}
}
else if (key.compare(A_PARENT) == 0)
{
//DICTOOL->getStringValue_json(json, A_PARENT);
if(str != nullptr)
{
boneData->parentName = str;
}
}
else if (key.compare(DISPLAY_DATA) == 0)
{
int count = child->GetChildNum();
stExpCocoNode *pDisplayData = child->GetChildArray();
for (int ii = 0; ii < count; ++ii)
{
DisplayData *displayData = decodeBoneDisplay(cocoLoader, &pDisplayData[ii], dataInfo);
if(displayData == nullptr)
continue;
boneData->addDisplayData(displayData);
displayData->release();
}
}
}
return boneData;
}
DisplayData* DataReaderHelper::decodeBoneDisplay(CocoLoader *cocoLoader, stExpCocoNode *cocoNode, DataInfo *dataInfo)
{
stExpCocoNode* children = cocoNode->GetChildArray();
stExpCocoNode* child = &children[1];
const char *str = nullptr;
std::string key = child->GetName(cocoLoader);
str = child->GetValue();
DisplayData *displayData = nullptr;
if (key.compare(A_DISPLAY_TYPE) == 0)
{
str = child->GetValue();
DisplayType displayType = (DisplayType)(atoi(str));
int length = 0;
switch (displayType)
{
case CS_DISPLAY_SPRITE:
{
displayData = new SpriteDisplayData();
const char *name = children[0].GetValue();
if(name != nullptr)
{
((SpriteDisplayData *)displayData)->displayName = name;
}
stExpCocoNode *pSkinDataArray = children[2].GetChildArray();
if (pSkinDataArray != nullptr)
{
stExpCocoNode *pSkinData = &pSkinDataArray[0];
if (pSkinData != nullptr)
{
SpriteDisplayData *sdd = (SpriteDisplayData *)displayData;
length = pSkinData->GetChildNum();
stExpCocoNode *SkinDataValue = pSkinData->GetChildArray();
for (int i = 0; i < length; ++i)
{
key = SkinDataValue[i].GetName(cocoLoader);
str = SkinDataValue[i].GetValue();
if (key.compare(A_X) == 0)
{
sdd->skinData.x = atof(str) * s_PositionReadScale;
}
else if (key.compare(A_Y) == 0)
{
sdd->skinData.y = atof(str) * s_PositionReadScale;
}
else if (key.compare(A_SCALE_X) == 0)
{
sdd->skinData.scaleX = atof(str);
}
else if (key.compare(A_SCALE_Y) == 0)
{
sdd->skinData.scaleY = atof(str);
}
else if (key.compare(A_SKEW_X) == 0)
{
sdd->skinData.skewX = atof(str);
}
else if (key.compare(A_SKEW_Y) == 0)
{
sdd->skinData.skewY = atof(str);
}
}
sdd->skinData.x *= dataInfo->contentScale;
sdd->skinData.y *= dataInfo->contentScale;
}
}
}
break;
case CS_DISPLAY_ARMATURE:
{
displayData = new ArmatureDisplayData();
const char *name = cocoNode[0].GetValue();
if(name != nullptr)
{
((ArmatureDisplayData *)displayData)->displayName = name;
}
}
break;
case CS_DISPLAY_PARTICLE:
{
displayData = new ParticleDisplayData();
length = cocoNode->GetChildNum();
stExpCocoNode *pDisplayData = cocoNode->GetChildArray();
for (int i = 0; i < length; ++i)
{
key = pDisplayData[i].GetName(cocoLoader);
str = pDisplayData[i].GetValue();
if (key.compare(A_PLIST) == 0)
{
const char *plist = str;
if(plist != nullptr)
{
if (dataInfo->asyncStruct)
{
((ParticleDisplayData *)displayData)->displayName = dataInfo->asyncStruct->baseFilePath + plist;
}
else
{
((ParticleDisplayData *)displayData)->displayName = dataInfo->baseFilePath + plist;
}
}
}
}
}
break;
default:
displayData = new SpriteDisplayData();
break;
}
displayData->displayType = displayType;
}
return displayData;
}
AnimationData* DataReaderHelper::decodeAnimation(CocoLoader *cocoLoader, stExpCocoNode *cocoNode, DataInfo *dataInfo)
{
AnimationData *aniData = new AnimationData();
int length = cocoNode->GetChildNum();
stExpCocoNode *pAnimationData = cocoNode->GetChildArray();
const char *str = nullptr;
std::string key;
stExpCocoNode* child;
MovementData *movementData;
for (int i = 0; i < length; ++i)
{
child = &pAnimationData[i];
key = child->GetName(cocoLoader);
str = child->GetValue();
if (key.compare(A_NAME) == 0)
{
if(str != nullptr)
{
aniData->name = str;
}
}
else if (key.compare(MOVEMENT_DATA) == 0)
{
int movcount = child->GetChildNum();
stExpCocoNode* movArray = child->GetChildArray();
for( int movnum =0; movnum <movcount; movnum++)
{
movementData = decodeMovement(cocoLoader, &movArray[movnum], dataInfo);
aniData->addMovement(movementData);
movementData->release();
}
}
}
return aniData;
}
MovementData* DataReaderHelper::decodeMovement(CocoLoader *cocoLoader, stExpCocoNode *cocoNode, DataInfo *dataInfo)
{
MovementData *movementData = new MovementData();
movementData->scale = 1.0f;
int length = cocoNode->GetChildNum();
stExpCocoNode *pMoveDataArray = cocoNode->GetChildArray();
const char *str = nullptr;
std::string key;
stExpCocoNode* child;
for (int i = 0; i < length; ++i)
{
child = &pMoveDataArray[i];
key = child->GetName(cocoLoader);
str = child->GetValue();
if (key.compare(A_NAME) == 0)
{
if(str != nullptr)
{
movementData->name = str;
}
}
else if (key.compare(A_LOOP) == 0)
{
movementData->loop = true;
if(str != nullptr)
{
if (strcmp("1", str) != 0)
{
movementData->loop = false;
}
}
}
else if (key.compare(A_DURATION_TWEEN) == 0)
{
movementData->durationTween = 0;
if(str != nullptr)
{
movementData->durationTween = atoi(str);
}
}
else if (key.compare(A_DURATION_TO) == 0)
{
movementData->durationTo = 0;
if(str != nullptr)
{
movementData->durationTo = atoi(str);
}
}
else if (key.compare(A_DURATION) == 0)
{
movementData->duration = 0;
if(str != nullptr)
{
movementData->duration = atoi(str);
}
}
else if (key.compare(A_MOVEMENT_SCALE) == 0)
{
movementData->scale = 1.0;
if(str != nullptr)
{
movementData->scale = atof(str);
}
}
else if (key.compare(A_TWEEN_EASING) == 0)
{
movementData->tweenEasing = cocos2d::tweenfunc::Linear;
if(str != nullptr)
{
movementData->tweenEasing = (TweenType)(atoi(str));
}
}
else if (key.compare(MOVEMENT_BONE_DATA) == 0)
{
int count = child->GetChildNum();
stExpCocoNode *pMoveBoneData = child->GetChildArray();
MovementBoneData *movementBoneData;
for (int ii = 0; ii < count; ++ii)
{
movementBoneData = decodeMovementBone(cocoLoader, &pMoveBoneData[ii],dataInfo);
movementData->addMovementBoneData(movementBoneData);
movementBoneData->release();
}
}
}
return movementData;
}
MovementBoneData* DataReaderHelper::decodeMovementBone(CocoLoader *cocoLoader, stExpCocoNode *cocoNode, DataInfo *dataInfo)
{
MovementBoneData *movementBoneData = new MovementBoneData();
movementBoneData->init();
int length = cocoNode->GetChildNum();
stExpCocoNode *pMovementBoneDataArray = cocoNode->GetChildArray();
stExpCocoNode* movebonechild;
const char *str = nullptr;
for (int i = 0; i < length; ++i)
{
movebonechild = &pMovementBoneDataArray[i];
std::string key = movebonechild->GetName(cocoLoader);
str = movebonechild->GetValue();
if (key.compare(A_NAME) == 0)
{
if(str != nullptr)
{
movementBoneData->name = str;
}
}
else if (key.compare(A_MOVEMENT_DELAY) == 0)
{
if(str != nullptr)
{
movementBoneData->delay = atof(str);
}
}
else if (key.compare(FRAME_DATA) == 0)
{
int count =movebonechild->GetChildNum();
stExpCocoNode *pFrameDataArray = movebonechild->GetChildArray();
for (int ii = 0; ii < count; ++ii)
{
FrameData *frameData = decodeFrame(cocoLoader, &pFrameDataArray[ii], dataInfo);
movementBoneData->addFrameData(frameData);
frameData->release();
if (dataInfo->cocoStudioVersion < VERSION_COMBINED)
{
frameData->frameID = movementBoneData->duration;
movementBoneData->duration += frameData->duration;
}
}
}
}
const ssize_t framesizemusone = movementBoneData->frameList.size()-1;
if (dataInfo->cocoStudioVersion < VERSION_CHANGE_ROTATION_RANGE)
{
//! Change rotation range from (-180 -- 180) to (-infinity -- infinity)
cocos2d::Vector<FrameData*> frames =movementBoneData->frameList;
ssize_t imusone =0;
ssize_t i =0;
for (i = framesizemusone; i >= 0; i--)
{
if (i > 0)
{
imusone = i-1;
float difSkewX = frames.at(i)->skewX - frames.at(imusone)->skewX;
float difSkewY = frames.at(i)->skewY - frames.at(imusone)->skewY;
if (difSkewX < -M_PI || difSkewX > M_PI)
{
frames.at(imusone)->skewX = difSkewX < 0 ? frames.at(imusone)->skewX - 2 * M_PI : frames.at(imusone)->skewX + 2 * M_PI;
}
if (difSkewY < -M_PI || difSkewY > M_PI)
{
frames.at(imusone)->skewY = difSkewY < 0 ? frames.at(imusone)->skewY - 2 * M_PI : frames.at(imusone)->skewY + 2 * M_PI;
}
}
}
}
if (dataInfo->cocoStudioVersion < VERSION_COMBINED)
{
if (movementBoneData->frameList.size() > 0)
{
FrameData *frameData = new FrameData();
frameData = movementBoneData->frameList.at(framesizemusone);
movementBoneData->addFrameData(frameData);
frameData->release();
frameData->frameID = movementBoneData->duration;
}
}
return movementBoneData;
}
FrameData* DataReaderHelper::decodeFrame(CocoLoader *cocoLoader, stExpCocoNode *cocoNode, DataInfo *dataInfo)
{
FrameData *frameData = new FrameData();
decodeNode(frameData, cocoLoader, cocoNode, dataInfo);
int length = cocoNode->GetChildNum();
stExpCocoNode *pFrameDataArray = cocoNode->GetChildArray();
const char *str = nullptr;
for (int i = 0; i < length; ++i)
{
std::string key = pFrameDataArray[i].GetName(cocoLoader);
str = pFrameDataArray[i].GetValue();
if (key.compare(A_TWEEN_EASING) == 0)
{
frameData->tweenEasing = cocos2d::tweenfunc::Linear;
if(str != nullptr)
{
frameData->tweenEasing = (TweenType)(atoi(str));
}
}
else if (key.compare(A_DISPLAY_INDEX) == 0)
{
if(str != nullptr)
{
frameData->displayIndex = atoi(str);
}
}
else if (key.compare(A_BLEND_SRC) == 0)
{
if(str != nullptr)
{
frameData->blendFunc.src = (GLenum)(atoi(str));
}
}
else if (key.compare(A_BLEND_DST) == 0)
{
if(str != nullptr)
{
frameData->blendFunc.dst = (GLenum)(atoi(str));
}
}
else if (key.compare(A_TWEEN_FRAME) == 0)
{
frameData->isTween = true;
if(str != nullptr)
{
if (strcmp("1", str) != 0)
{
frameData->isTween = false;
}
}
}
else if (key.compare(A_EVENT) == 0)
{
if(str != nullptr)
{
frameData->strEvent = str;
}
}
else if (key.compare(A_DURATION) == 0)
{
if (dataInfo->cocoStudioVersion < VERSION_COMBINED)
{
frameData->duration = 1;
if(str != nullptr)
{
frameData->duration = atoi(str);
}
}
}
else if (key.compare(A_FRAME_INDEX) == 0)
{
if (dataInfo->cocoStudioVersion >= VERSION_COMBINED)
{
if(str != nullptr)
{
frameData->frameID = atoi(str);
}
}
}
else if (key.compare(A_EASING_PARAM) == 0)
{
int count = pFrameDataArray[i].GetChildNum();
if (count != 0 )
{
frameData->easingParams = new float[count];
stExpCocoNode *pFrameData = pFrameDataArray[i].GetChildArray();
for (int ii = 0; ii < count; ++ii)
{
str = pFrameData[ii].GetValue();
if (str != nullptr)
{
frameData->easingParams[ii] = atof(str);
}
}
}
}
}
return frameData;
}
TextureData* DataReaderHelper::decodeTexture(CocoLoader *cocoLoader, stExpCocoNode *cocoNode)
{
TextureData *textureData = new TextureData();
textureData->init();
if(cocoNode == nullptr)
{
return textureData;
}
int length = cocoNode->GetChildNum();
stExpCocoNode *pTextureDataArray = cocoNode->GetChildArray();
const char *str = nullptr;
for (int i = 0; i < length; ++i)
{
std::string key = pTextureDataArray[i].GetName(cocoLoader);
str = pTextureDataArray[i].GetValue();
if (key.compare(A_NAME) == 0)
{
if(str != nullptr)
{
textureData->name = str;
}
}
else if (key.compare(A_WIDTH) == 0)
{
if(str != nullptr)
{
textureData->width = atof(str);
}
}
else if (key.compare(A_HEIGHT) == 0)
{
if(str != NULL)
{
textureData->height = atof(str);
}
}
else if (key.compare(A_PIVOT_X) == 0)
{
if(str != NULL)
{
textureData->pivotX = atof(str);
}
}
else if (key.compare(A_PIVOT_Y) == 0)
{
if(str != NULL)
{
textureData->pivotY = atof(str);
}
}
else if (key.compare(CONTOUR_DATA) == 0)
{
int count = pTextureDataArray[i].GetChildNum();
stExpCocoNode *pContourArray = pTextureDataArray[i].GetChildArray();
for (int ii = 0; ii < count; ++ii)
{
ContourData *contourData = decodeContour(cocoLoader, &pContourArray[ii]);
textureData->contourDataList.pushBack(contourData);
contourData->release();
}
}
}
return textureData;
}
ContourData* DataReaderHelper::decodeContour(CocoLoader *cocoLoader, stExpCocoNode *cocoNode)
{
ContourData *contourData = new ContourData();
contourData->init();
int length = cocoNode->GetChildNum();
stExpCocoNode *verTexPointArray = cocoNode->GetChildArray();
const char *str = nullptr;
for (int i = 0; i < length; ++i)
{
std::string key = verTexPointArray[i].GetName(cocoLoader);
str = verTexPointArray[i].GetValue();
if (key.compare(VERTEX_POINT) == 0)
{
int count = verTexPointArray[i].GetChildNum();
stExpCocoNode *pVerTexPointArray = verTexPointArray[i].GetChildArray();
stExpCocoNode *pVerTexPoint;
for (int ii = count - 1; ii >= 0; --ii)
{
pVerTexPoint = pVerTexPointArray[ii].GetChildArray();
Vec2 vertex;
vertex.x = atof(pVerTexPoint[0].GetValue());
vertex.y = atof(pVerTexPoint[1].GetValue());
contourData->vertexList.push_back(vertex); }
break;
}
}
return contourData;
}
void DataReaderHelper::decodeNode(BaseData *node, CocoLoader *cocoLoader, stExpCocoNode* cocoNode, DataInfo *dataInfo)
{
int length = cocoNode->GetChildNum();
stExpCocoNode *NodeArray = cocoNode->GetChildArray();
const char *str = nullptr;
bool isVersionL = dataInfo->cocoStudioVersion < VERSION_COLOR_READING;
stExpCocoNode* child;
for (int i = 0; i < length; ++i)
{
child = &NodeArray[i];
std::string key = child->GetName(cocoLoader);
str = child->GetValue();
if (key.compare(A_X) == 0)
{
node->x = atof(str) * dataInfo->contentScale;
}
else if (key.compare(A_Y) == 0)
{
node->y = atof(str) * dataInfo->contentScale;
}
else if (key.compare(A_Z) == 0)
{
node->zOrder = atoi(str);
}
else if (key.compare(A_SKEW_X) == 0)
{
node->skewX = atof(str);
}
else if (key.compare(A_SKEW_Y) == 0)
{
node->skewY = atof(str);
}
else if (key.compare(A_SCALE_X) == 0)
{
node->scaleX = atof(str);
}
else if (key.compare(A_SCALE_Y) == 0)
{
node->scaleY = atof(str);
}
else if (key.compare(COLOR_INFO) == 0)
{
if (!isVersionL)
{
if (child->GetType(cocoLoader) == rapidjson::kObjectType)
{
if(child->GetChildNum() == 4)
{
stExpCocoNode *ChildArray = child->GetChildArray();
node->a = atoi(ChildArray[0].GetValue());
node->r = atoi(ChildArray[1].GetValue());
node->g = atoi(ChildArray[2].GetValue());
node->b = atoi(ChildArray[3].GetValue());
}
}
node->isUseColorInfo = true;
}
}
}
if (isVersionL)
{
int colorcoount = NodeArray[0].GetChildNum();
if(colorcoount>0)
{
if (NodeArray[0].GetType(cocoLoader) == rapidjson::kObjectType)
{
if(NodeArray[0].GetChildNum() == 4)
{
stExpCocoNode *ChildArray = NodeArray[0].GetChildArray();
node->a = atoi(ChildArray[0].GetValue());
node->r = atoi(ChildArray[1].GetValue());
node->g = atoi(ChildArray[2].GetValue());
node->b = atoi(ChildArray[3].GetValue());
}
}
node->isUseColorInfo = true;
}
}
}
}

View File

@ -30,6 +30,9 @@ THE SOFTWARE.
#include "cocostudio/CCArmature.h"
#include "cocostudio/DictionaryHelper.h"
#include "json/document.h"
#include "DictionaryHelper.h"
#include <string>
#include <queue>
#include <list>
@ -43,7 +46,8 @@ namespace tinyxml2
}
namespace cocostudio {
class CocoLoader;
struct stExpCocoNode;
/**
* @js NA
* @lua NA
@ -55,7 +59,8 @@ protected:
enum ConfigType
{
DragonBone_XML,
CocoStudio_JSON
CocoStudio_JSON,
CocoStudio_Binary
};
typedef struct _AsyncStruct
@ -172,6 +177,23 @@ public:
static void decodeNode(BaseData *node, const rapidjson::Value& json, DataInfo *dataInfo);
// for binary decode
public:
static void addDataFromBinaryCache(const char *fileContent, DataInfo *dataInfo = nullptr);
static ArmatureData *decodeArmature(CocoLoader *cocoLoader, stExpCocoNode *pCocoNode, DataInfo *dataInfo);
static BoneData *decodeBone(CocoLoader *cocoLoader, stExpCocoNode *pCocoNode, DataInfo *dataInfo);
static DisplayData *decodeBoneDisplay(CocoLoader *cocoLoader, stExpCocoNode *pCocoNode, DataInfo *dataInfo);
static AnimationData *decodeAnimation(CocoLoader *cocoLoader, stExpCocoNode *pCocoNode, DataInfo *dataInfo);
static MovementData *decodeMovement(CocoLoader *cocoLoader, stExpCocoNode *pCocoNode, DataInfo *dataInfo);
static MovementBoneData *decodeMovementBone(CocoLoader *cocoLoader, stExpCocoNode *pCocoNode, DataInfo *dataInfo);
static FrameData *decodeFrame(CocoLoader *cocoLoader, stExpCocoNode *pCocoNode, DataInfo *dataInfo);
static TextureData *decodeTexture(CocoLoader *cocoLoader, stExpCocoNode *pCocoNode);
static ContourData *decodeContour(CocoLoader *cocoLoader, stExpCocoNode *pCocoNode);
static void decodeNode(BaseData *node, CocoLoader *cocoLoader, stExpCocoNode *pCocoNode, DataInfo *dataInfo);
protected:
void loadData();

File diff suppressed because it is too large Load Diff

View File

@ -30,9 +30,11 @@ THE SOFTWARE.
#include "WidgetReader/WidgetReaderProtocol.h"
#include "base/ObjectFactory.h"
namespace cocostudio {
class CocoLoader;
struct stExpCocoNode;
#define kCCSVersion 1.0
@ -49,6 +51,9 @@ public:
static void destroyInstance();
cocos2d::ui::Widget* widgetFromJsonFile(const char* fileName);
cocos2d::ui::Widget* widgetFromBinaryFile(const char* fileName);
int getVersionInteger(const char* str);
/**
* @js NA
@ -66,7 +71,6 @@ public:
cocos2d::ObjectFactory::Instance ins,
Ref* object,
SEL_ParseEvent callBack);
protected:
GUIReader();
~GUIReader();
@ -89,13 +93,27 @@ class WidgetPropertiesReader : public cocos2d::Ref
{
public:
virtual cocos2d::ui::Widget* createWidget(const rapidjson::Value& dic, const char* fullPath, const char* fileName)=0;
virtual cocos2d::ui::Widget* widgetFromJsonDictionary(const rapidjson::Value& data) = 0;
virtual void setPropsForAllWidgetFromJsonDictionary(WidgetReaderProtocol* reader, cocos2d::ui::Widget* widget, const rapidjson::Value& options) = 0;
virtual void setPropsForAllCustomWidgetFromJsonDictionary(const std::string& classType,
cocos2d::ui::Widget* widget,
const rapidjson::Value& customOptions) = 0;
//add binary parsing
virtual cocos2d::ui::Widget* createWidgetFromBinary(CocoLoader* cocoLoader,stExpCocoNode* pCocoNode, const char* fileName)=0;
virtual cocos2d::ui::Widget* widgetFromBinary(CocoLoader* cocoLoader, stExpCocoNode* pCocoNode) = 0;
virtual void setPropsForAllWidgetFromBinary(WidgetReaderProtocol* reader,
cocos2d::ui::Widget* widget,
CocoLoader* cocoLoader,
stExpCocoNode* pCocoNode) = 0;
protected:
void setAnchorPointForWidget(cocos2d::ui::Widget* widget, const rapidjson::Value&options);
std::string getWidgetReaderClassName(const std::string& classname);
std::string getWidgetReaderClassName(cocos2d::ui::Widget *widget);
std::string getGUIClassName(const std::string& name);
cocos2d::ui::Widget *createGUI(const std::string& classname);
@ -115,7 +133,22 @@ public:
virtual ~WidgetPropertiesReader0250(){};
virtual cocos2d::ui::Widget* createWidget(const rapidjson::Value& dic, const char* fullPath, const char* fileName);
virtual cocos2d::ui::Widget* widgetFromJsonDictionary(const rapidjson::Value& dic);
//added for binary parsing
virtual cocos2d::ui::Widget* createWidgetFromBinary(CocoLoader* cocoLoader,
stExpCocoNode* pCocoNode,
const char* fileName)override{return nullptr;}
virtual cocos2d::ui::Widget* widgetFromBinary(CocoLoader* cocoLoader,
stExpCocoNode* pCocoNode){return nullptr;}
virtual void setPropsForAllWidgetFromBinary(WidgetReaderProtocol* reader,
cocos2d::ui::Widget* widget,
CocoLoader* cocoLoader,
stExpCocoNode* pCocoNode) {}
virtual void setPropsForWidgetFromJsonDictionary(cocos2d::ui::Widget* widget,const rapidjson::Value& options);
virtual void setColorPropsForWidgetFromJsonDictionary(cocos2d::ui::Widget* widget,const rapidjson::Value& options);
@ -146,32 +179,40 @@ public:
WidgetPropertiesReader0300(){};
virtual ~WidgetPropertiesReader0300(){};
virtual cocos2d::ui::Widget* createWidget(const rapidjson::Value& dic, const char* fullPath, const char* fileName);
virtual cocos2d::ui::Widget* createWidget(const rapidjson::Value& dic,
const char* fullPath,
const char* fileName);
//add bin parse support
virtual cocos2d::ui::Widget* createWidgetFromBinary(CocoLoader* cocoLoader,
stExpCocoNode* pCocoNode,
const char* fileName)override;
virtual cocos2d::ui::Widget* widgetFromBinary(CocoLoader* cocoLoader,
stExpCocoNode* pCocoNode);
virtual void setPropsForAllWidgetFromBinary(WidgetReaderProtocol* reader,
cocos2d::ui::Widget* widget,
CocoLoader* cocoLoader,
stExpCocoNode* pCocoNode);
virtual void setPropsForAllCustomWidgetFromBinary(const std::string& classType,
cocos2d::ui::Widget* widget,
CocoLoader* cocoLoader,
stExpCocoNode* pCocoNode) {
//TODO: custom property
}
virtual cocos2d::ui::Widget* widgetFromJsonDictionary(const rapidjson::Value& dic);
virtual void setPropsForWidgetFromJsonDictionary(cocos2d::ui::Widget*,const rapidjson::Value& options);
virtual void setColorPropsForWidgetFromJsonDictionary(cocos2d::ui::Widget* widget,const rapidjson::Value& options);
virtual void setPropsForButtonFromJsonDictionary(cocos2d::ui::Widget* widget,const rapidjson::Value& options);
virtual void setPropsForCheckBoxFromJsonDictionary(cocos2d::ui::Widget* widget,const rapidjson::Value& options);
virtual void setPropsForImageViewFromJsonDictionary(cocos2d::ui::Widget* widget,const rapidjson::Value& options);
virtual void setPropsForLabelFromJsonDictionary(cocos2d::ui::Widget* widget,const rapidjson::Value& options);
virtual void setPropsForLabelAtlasFromJsonDictionary(cocos2d::ui::Widget* widget,const rapidjson::Value& options);
virtual void setPropsForLabelBMFontFromJsonDictionary(cocos2d::ui::Widget* widget,const rapidjson::Value& options);
virtual void setPropsForLoadingBarFromJsonDictionary(cocos2d::ui::Widget* widget,const rapidjson::Value& options);
virtual void setPropsForSliderFromJsonDictionary(cocos2d::ui::Widget* widget,const rapidjson::Value& options);
virtual void setPropsForTextFieldFromJsonDictionary(cocos2d::ui::Widget* widget,const rapidjson::Value& options);
virtual void setPropsForAllWidgetFromJsonDictionary(WidgetReaderProtocol* reader,
cocos2d::ui::Widget* widget,
const rapidjson::Value& options);
virtual void setPropsForLayoutFromJsonDictionary(cocos2d::ui::Widget* widget,const rapidjson::Value& options);
virtual void setPropsForPageViewFromJsonDictionary(cocos2d::ui::Widget* widget,const rapidjson::Value& options);
virtual void setPropsForScrollViewFromJsonDictionary(cocos2d::ui::Widget* widget,const rapidjson::Value& options);
virtual void setPropsForListViewFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options);
virtual void setPropsForAllWidgetFromJsonDictionary(WidgetReaderProtocol* reader, cocos2d::ui::Widget* widget, const rapidjson::Value& options);
virtual void setPropsForAllCustomWidgetFromJsonDictionary(const std::string& classType,
cocos2d::ui::Widget* widget,
const rapidjson::Value& customOptions);
};

View File

@ -25,7 +25,7 @@ THE SOFTWARE.
#include "cocostudio/CocoStudio.h"
#include "ui/CocosGUI.h"
#include "audio/include/SimpleAudioEngine.h"
#include "ObjectFactory.h"
#include "base/ObjectFactory.h"
using namespace cocos2d;
using namespace ui;

View File

@ -33,6 +33,7 @@ set(CS_SRC
TriggerBase.cpp
TriggerMng.cpp
TriggerObj.cpp
CocoLoader.cpp
WidgetReader/WidgetReader.cpp
WidgetReader/ButtonReader/ButtonReader.cpp
WidgetReader/CheckBoxReader/CheckBoxReader.cpp

View File

@ -0,0 +1,196 @@
#include "CocoLoader.h"
using namespace std;
using namespace rapidjson;
namespace cocostudio{
const char* kTypeNames[] = { "Null", "False", "True", "Object", "Array", "String", "Number" };
const char* kObjKeyName[] = { "__type" , "classname" };
char g_Buff[2048];
Type stExpCocoNode::GetType(CocoLoader* pCoco)
{
Type tType = kObjectType;
if(m_ObjIndex >= 0)
{
stExpCocoObjectDesc* tpCocoObjectDesc = pCoco->GetCocoObjectDescArray();
if( m_AttribIndex >= 0 )
{
stExpCocoAttribDesc* tpAttribDescArray = (stExpCocoAttribDesc*) tpCocoObjectDesc[m_ObjIndex].m_pAttribDescArray;
tType = tpAttribDescArray[m_AttribIndex].m_Type;
if(kFalseType == tType || kTrueType == tType)
{
char* szValue = (char*)m_szValue;
if(szValue[0] == '0')
{
return kFalseType;
}
else
{
return kTrueType;
}
}
}
else
{
tType = kObjectType;
}
}
else
{
if(m_AttribIndex >= 0)
{
tType = (Type)m_ChildNum;
if(kFalseType == tType || kTrueType == tType)
{
char* szValue = (char*)m_szValue;
if(szValue[0] == '0')
{
return kFalseType;
}
else
{
return kTrueType;
}
}
}
else
{
tType = kArrayType;
}
}
return tType;
}
char* stExpCocoNode::GetName(CocoLoader* pCoco)
{
char* szName = NULL ;
if(m_ObjIndex >= 0)
{
stExpCocoObjectDesc* tpCocoObjectDesc = pCoco->GetCocoObjectDescArray();
if( m_AttribIndex >= 0 )
{
stExpCocoAttribDesc* tpAttribDescArray = (stExpCocoAttribDesc*) tpCocoObjectDesc[m_ObjIndex].m_pAttribDescArray;
szName = (char*)tpAttribDescArray[m_AttribIndex].m_szName;
}
else
{
char* szValue = (char*)m_szValue;
if(szValue[0])
{
szName = (char*)m_szValue;
}
else
{
szName = (char*)tpCocoObjectDesc[m_ObjIndex].m_szName;
}
}
}
else
{
if(m_AttribIndex >= 0)
{
char* pStringAddr = (char*)pCoco->GetCocoObjectDescArray() + pCoco->GetFileHeader()->m_lStringMemAddr ;
szName = m_ChildArray + pStringAddr;
}
else
{
szName = (char*)m_szValue;
}
}
return szName ;
}
char* stExpCocoNode::GetValue()
{
return (char*)m_szValue;
}
int stExpCocoNode::GetChildNum()
{
return m_ChildNum;
}
stExpCocoNode* stExpCocoNode::GetChildArray()
{
return (stExpCocoNode*)m_ChildArray;
}
void stExpCocoNode::ReBuild(char* cocoNodeAddr,char* pStringMemoryAddr)
{
m_szValue = m_szValue + (uint64_t)pStringMemoryAddr;
if( -1 == m_AttribIndex )
{
if(m_ChildNum > 0)
{
m_ChildArray = m_ChildArray + (uint64_t)cocoNodeAddr;
stExpCocoNode* tpChildArray = (stExpCocoNode*)m_ChildArray;
for(int i = 0 ; i < m_ChildNum ; i++)
{
tpChildArray[i].ReBuild(cocoNodeAddr,pStringMemoryAddr);
}
}
}
}
CocoLoader::CocoLoader()
{
m_pRootNode = NULL;
m_pObjectDescArray = NULL;
}
CocoLoader::~CocoLoader()
{
}
bool CocoLoader::ReadCocoBinBuff(char* pBinBuff)
{
char* pTempBuff = pBinBuff;
m_pFileHeader = (stCocoFileHeader*)pTempBuff;
pTempBuff += sizeof(stCocoFileHeader);
char* pStartAddr = pTempBuff;
m_pObjectDescArray = (stExpCocoObjectDesc*)pStartAddr;
char* pAttrAddr = pStartAddr + m_pFileHeader->m_lAttribMemAddr ;
char* pCocoMemAddr = pStartAddr + m_pFileHeader->m_CocoNodeMemAddr;
char* pStringAddr = pStartAddr + m_pFileHeader->m_lStringMemAddr ;
m_pRootNode = (stExpCocoNode*)pCocoMemAddr;
if(1 == m_pFileHeader->m_nFirstUsed)
{
for(int i = 0 ; i < m_pFileHeader->m_ObjectCount ; i++)
{
m_pObjectDescArray[i].ReBuild(pAttrAddr,pStringAddr) ;
}
m_pRootNode->ReBuild(pCocoMemAddr,pStringAddr);
m_pFileHeader->m_nFirstUsed = 0;
}
return true;
}
stExpCocoObjectDesc* CocoLoader::GetCocoObjectDesc(const char* szObjDesc)
{
for(int i = 0 ; i < m_pFileHeader->m_ObjectCount ; i++)
{
if(0 == strcmp((char*)m_pObjectDescArray[i].m_szName,szObjDesc))
{
return &m_pObjectDescArray[i];
}
}
return NULL;
}
}

View File

@ -0,0 +1,139 @@
/****************************************************************************
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 _COCOLOADER_H
#define _COCOLOADER_H
#include <stdio.h>
#include <vector>
#include <cstdio>
#include <stdint.h>
#include "json/rapidjson.h"
#include "json/document.h"
#pragma pack (4)
namespace cocostudio{
struct stExpCocoAttribDesc
{
rapidjson::Type m_Type;
uint64_t m_szName;
uint64_t m_szDefaultValue;
public:
void ReBuild(char* pStringMemoryAddr)
{
m_szName = m_szName + (uint64_t)pStringMemoryAddr;
m_szDefaultValue = m_szDefaultValue + (uint64_t)pStringMemoryAddr;
}
};
struct stExpCocoObjectDesc
{
uint32_t m_nAttribNum;
uint64_t m_szName;
uint64_t m_pAttribDescArray;
public:
stExpCocoObjectDesc()
{
m_nAttribNum = 0;
m_szName = 0;
m_pAttribDescArray = 0;
}
void ReBuild(char* pAttribMemoryAddr,char* pStringMemoryAddr)
{
m_szName = m_szName + (uint64_t)pStringMemoryAddr;
m_pAttribDescArray = m_pAttribDescArray + (uint64_t)pAttribMemoryAddr;
stExpCocoAttribDesc* tpAttribDescArray = (stExpCocoAttribDesc*)m_pAttribDescArray;
for(uint32_t i = 0 ; i < m_nAttribNum ; i++)
{
tpAttribDescArray[i].ReBuild(pStringMemoryAddr);
}
}
};
class CocoLoader;
struct stExpCocoNode
{
protected:
int32_t m_ObjIndex;
int32_t m_AttribIndex;
uint32_t m_ChildNum;
uint64_t m_szValue;
uint64_t m_ChildArray;
public:
rapidjson::Type GetType(CocoLoader* pCoco);
char* GetName(CocoLoader* pCoco);
char* GetValue();
int GetChildNum();
stExpCocoNode* GetChildArray();
public:
inline void ReBuild(char* cocoNodeAddr,char* pStringMemoryAddr);
void WriteJson(CocoLoader* pCoco, void* pFileName = NULL, int vLayer = 0, bool bEndNode = false, bool bParentNodeIsArray = false);
};
struct stCocoFileHeader
{
char m_FileDesc[32];
char m_Version[32];
uint32_t m_nFirstUsed;
uint32_t m_ObjectCount;
uint64_t m_lAttribMemAddr;
uint64_t m_CocoNodeMemAddr;
uint64_t m_lStringMemAddr;
};
class CocoLoader
{
private:
stCocoFileHeader* m_pFileHeader;
stExpCocoNode* m_pRootNode;
stExpCocoObjectDesc* m_pObjectDescArray;
public:
CocoLoader();
~CocoLoader();
public:
bool ReadCocoBinBuff(char* pBinBuff);
stCocoFileHeader* GetFileHeader(){return m_pFileHeader;}
stExpCocoNode* GetRootCocoNode(){return m_pRootNode;}
stExpCocoObjectDesc* GetCocoObjectDescArray(){return m_pObjectDescArray;}
stExpCocoObjectDesc* GetCocoObjectDesc(const char* szObjDesc);
};
}
#pragma pack ()
#endif

View File

@ -1,202 +0,0 @@
/****************************************************************************
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
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 "ObjectFactory.h"
#include "ui/UIWidget.h"
#include "cocostudio/WidgetReader/WidgetReaderProtocol.h"
using namespace cocos2d;
namespace cocostudio {
ObjectFactory::TInfo::TInfo(void)
:_class("")
,_fun(nullptr)
{
}
ObjectFactory::TInfo::TInfo(const std::string& type, Instance ins)
:_class(type)
,_fun(ins)
{
ObjectFactory::getInstance()->registerType(*this);
}
ObjectFactory::TInfo::TInfo(const TInfo &t)
{
_class = t._class;
_fun = t._fun;
}
ObjectFactory::TInfo::~TInfo(void)
{
_class = "";
_fun = nullptr;
}
ObjectFactory::TInfo& ObjectFactory::TInfo::operator= (const TInfo &t)
{
_class = t._class;
_fun = t._fun;
return *this;
}
ObjectFactory* ObjectFactory::_sharedFactory = nullptr;
ObjectFactory::ObjectFactory(void)
{
}
ObjectFactory::~ObjectFactory(void)
{
_typeMap.clear();
}
ObjectFactory* ObjectFactory::getInstance()
{
if ( nullptr == _sharedFactory)
{
_sharedFactory = new ObjectFactory();
}
return _sharedFactory;
}
void ObjectFactory::destroyInstance()
{
CC_SAFE_DELETE(_sharedFactory);
}
Ref* ObjectFactory::createObject(const std::string &name)
{
Ref *o = nullptr;
do
{
const TInfo t = _typeMap[name];
CC_BREAK_IF(t._fun == nullptr);
o = t._fun();
} while (0);
return o;
}
Component* ObjectFactory::createComponent(const std::string &name)
{
std::string comName;
if (name == "CCSprite" || name == "CCTMXTiledMap" || name == "CCParticleSystemQuad" || name == "CCArmature" || name == "GUIComponent")
{
comName = "ComRender";
}
else if (name == "CCComAudio" || name == "CCBackgroundAudio")
{
comName = "ComAudio";
}
else if (name == "CCComController")
{
comName = "ComController";
}
else if (name == "CCComAttribute")
{
comName = "ComAttribute";
}
else if (name == "CCScene")
{
comName = "Scene";
}
else
{
CCASSERT(false, "Unregistered Component!");
}
Ref *o = NULL;
do
{
const TInfo t = _typeMap[comName];
CC_BREAK_IF(t._fun == NULL);
o = t._fun();
} while (0);
return (Component*)o;
}
ui::Widget* ObjectFactory::createGUI(std::string name)
{
Ref* object = nullptr;
if (name == "Panel")
{
name = "Layout";
}
else if (name == "TextArea")
{
name = "Text";
}
else if (name == "TextButton")
{
name = "Button";
}
else if (name == "Label")
{
name = "Text";
}
else if (name == "LabelAtlas")
{
name = "TextAtlas";
}
else if (name == "LabelBMFont")
{
name = "TextBMFont";
}
do
{
const TInfo t = _typeMap[name];
CC_BREAK_IF(t._fun == NULL);
object = t._fun();
} while (0);
return static_cast<ui::Widget*>(object);
}
WidgetReaderProtocol* ObjectFactory::createWidgetReaderProtocol(std::string name)
{
Ref* object = NULL;
do
{
const TInfo t = _typeMap[name];
CC_BREAK_IF(t._fun == NULL);
object = t._fun();
} while (0);
return dynamic_cast<WidgetReaderProtocol*>(object);
}
void ObjectFactory::registerType(const TInfo &t)
{
_typeMap.insert(std::make_pair(t._class, t));
}
}

View File

@ -1,81 +0,0 @@
/****************************************************************************
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
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 __TRIGGERFACTORY_H__
#define __TRIGGERFACTORY_H__
#include "cocos2d.h"
#include <string>
#include <unordered_map>
namespace cocos2d
{
namespace ui
{
class Widget;
}
}
namespace cocostudio
{
class WidgetReaderProtocol;
}
namespace cocostudio {
class ObjectFactory
{
public:
typedef cocos2d::Ref* (*Instance)(void);
struct TInfo
{
TInfo(void);
TInfo(const std::string& type, Instance ins = NULL);
TInfo(const TInfo &t);
~TInfo(void);
TInfo& operator= (const TInfo &t);
std::string _class;
Instance _fun;
};
typedef std::unordered_map<std::string, TInfo> FactoryMap;
static ObjectFactory* getInstance();
static void destroyInstance();
cocos2d::Ref* createObject(const std::string &name);
cocos2d::Component* createComponent(const std::string &name);
cocos2d::ui::Widget* createGUI(std::string name);
WidgetReaderProtocol* createWidgetReaderProtocol(std::string name);
void registerType(const TInfo &t);
void removeAll();
protected:
ObjectFactory(void);
virtual ~ObjectFactory(void);
private:
static ObjectFactory *_sharedFactory;
FactoryMap _typeMap;
};
}
#endif

View File

@ -2,13 +2,34 @@
#include "ButtonReader.h"
#include "ui/UIButton.h"
#include "cocostudio/CocoLoader.h"
USING_NS_CC;
using namespace ui;
namespace cocostudio
{
static ButtonReader* instanceButtonReader = NULL;
static const char* P_Scale9Enable = "scale9Enable";
static const char* P_NormalData = "normalData";
static const char* P_PressedData = "pressedData";
static const char* P_DisabledData = "disabledData";
static const char* P_Text = "text";
static const char* P_CapInsetsX = "capInsetsX";
static const char* P_CapInsetsY = "capInsetsY";
static const char* P_CapInsetsWidth = "capInsetsWidth";
static const char* P_CapInsetsHeight = "capInsetsHeight";
static const char* P_Scale9Width = "scale9Width";
static const char* P_Scale9Height = "scale9Height";
static const char* P_TextColorR = "textColorR";
static const char* P_TextColorG = "textColorG";
static const char* P_TextColorB = "textColorB";
static const char* P_FontSize = "fontSize";
static const char* P_FontName = "fontName";
static ButtonReader* instanceButtonReader = nullptr;
IMPLEMENT_CLASS_WIDGET_READER_INFO(ButtonReader)
@ -36,78 +57,181 @@ namespace cocostudio
CC_SAFE_DELETE(instanceButtonReader);
}
void ButtonReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *cocoLoader, stExpCocoNode *cocoNode)
{
WidgetReader::setPropsFromBinary(widget, cocoLoader, cocoNode);
Button *button = static_cast<Button*>(widget);
stExpCocoNode *stChildArray = cocoNode->GetChildArray();
this->beginSetBasicProperties(widget);
float capsx = 0.0f, capsy = 0.0, capsWidth = 0.0, capsHeight = 0.0f;
int cri = 255, cgi = 255, cbi = 255;
float scale9Width = 0.0f, scale9Height = 0.0f;
for (int i = 0; i < cocoNode->GetChildNum(); ++i) {
std::string key = stChildArray[i].GetName(cocoLoader);
std::string value = stChildArray[i].GetValue();
// CCLOG("Button: key = %s, value = %d", key.c_str(), i);
//read all basic properties of widget
CC_BASIC_PROPERTY_BINARY_READER
//read all color related properties of widget
CC_COLOR_PROPERTY_BINARY_READER
else if (key == P_Scale9Enable) {
button->setScale9Enabled(valueToBool(value));
}
else if (key == P_NormalData){
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray();
std::string resType = backGroundChildren[2].GetValue();;
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType);
button->loadTextureNormal(backgroundValue, imageFileNameType);
}
else if (key == P_PressedData){
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray();
std::string resType = backGroundChildren[2].GetValue();;
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType);
button->loadTexturePressed(backgroundValue, imageFileNameType);
}
else if (key == P_DisabledData){
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray();
std::string resType = backGroundChildren[2].GetValue();;
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType);
button->loadTextureDisabled(backgroundValue, imageFileNameType);
}else if (key == P_Text){
button->setTitleText(value);
}
else if(key == P_CapInsetsX){
capsx = valueToFloat(value);
}else if(key == P_CapInsetsY){
capsy = valueToFloat(value);
}else if(key == P_CapInsetsWidth){
capsWidth = valueToFloat(value);
}else if(key == P_CapInsetsHeight){
capsHeight = valueToFloat(value);
}else if(key == P_Scale9Width){
scale9Width = valueToFloat(value);
}else if(key == P_Scale9Height){
scale9Height = valueToFloat(value);
}else if(key == P_TextColorR){
cri = valueToInt(value);
}else if(key == P_TextColorG){
cgi = valueToInt(value);
}else if(key == P_TextColorB){
cbi = valueToInt(value);
}else if(key == P_FontSize){
button->setTitleFontSize(valueToFloat(value));
}else if(key == P_FontName){
button->setTitleFontName(value);
}
} //end of for loop
this->endSetBasicProperties(widget);
if (button->isScale9Enabled()) {
button->setCapInsets(Rect(capsx, capsy, capsWidth, capsHeight));
button->setSize(Size(scale9Width, scale9Height));
}
button->setTitleColor(Color3B(cri, cgi, cbi));
}
void ButtonReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
{
WidgetReader::setPropsFromJsonDictionary(widget, options);
Button* button = static_cast<Button*>(widget);
bool scale9Enable = DICTOOL->getBooleanValue_json(options, "scale9Enable");
bool scale9Enable = DICTOOL->getBooleanValue_json(options, P_Scale9Enable);
button->setScale9Enabled(scale9Enable);
const rapidjson::Value& normalDic = DICTOOL->getSubDictionary_json(options, "normalData");
int normalType = DICTOOL->getIntValue_json(normalDic, "resourceType");
std::string normalTexturePath = this->getResourcePath(normalDic, "path", (Widget::TextureResType)normalType);
const rapidjson::Value& normalDic = DICTOOL->getSubDictionary_json(options, P_NormalData);
int normalType = DICTOOL->getIntValue_json(normalDic, P_ResourceType);
std::string normalTexturePath = this->getResourcePath(normalDic, P_Path, (Widget::TextureResType)normalType);
button->loadTextureNormal(normalTexturePath, (Widget::TextureResType)normalType);
const rapidjson::Value& pressedDic = DICTOOL->getSubDictionary_json(options, "pressedData");
int pressedType = DICTOOL->getIntValue_json(pressedDic, "resourceType");
const rapidjson::Value& pressedDic = DICTOOL->getSubDictionary_json(options, P_PressedData);
int pressedType = DICTOOL->getIntValue_json(pressedDic, P_ResourceType);
std::string pressedTexturePath = this->getResourcePath(pressedDic, "path", (Widget::TextureResType)pressedType);
std::string pressedTexturePath = this->getResourcePath(pressedDic, P_Path, (Widget::TextureResType)pressedType);
button->loadTexturePressed(pressedTexturePath, (Widget::TextureResType)pressedType);
const rapidjson::Value& disabledDic = DICTOOL->getSubDictionary_json(options, "disabledData");
int disabledType = DICTOOL->getIntValue_json(disabledDic, "resourceType");
const rapidjson::Value& disabledDic = DICTOOL->getSubDictionary_json(options, P_DisabledData);
int disabledType = DICTOOL->getIntValue_json(disabledDic, P_ResourceType);
std::string disabledTexturePath = this->getResourcePath(disabledDic, "path", (Widget::TextureResType)disabledType);
std::string disabledTexturePath = this->getResourcePath(disabledDic, P_Path, (Widget::TextureResType)disabledType);
button->loadTextureDisabled(disabledTexturePath, (Widget::TextureResType)disabledType);
if (scale9Enable)
{
float cx = DICTOOL->getFloatValue_json(options, "capInsetsX");
float cy = DICTOOL->getFloatValue_json(options, "capInsetsY");
float cw = DICTOOL->getFloatValue_json(options, "capInsetsWidth");
float ch = DICTOOL->getFloatValue_json(options, "capInsetsHeight");
float cx = DICTOOL->getFloatValue_json(options, P_CapInsetsX);
float cy = DICTOOL->getFloatValue_json(options, P_CapInsetsY);
float cw = DICTOOL->getFloatValue_json(options, P_CapInsetsWidth);
float ch = DICTOOL->getFloatValue_json(options, P_CapInsetsHeight);
button->setCapInsets(Rect(cx, cy, cw, ch));
bool sw = DICTOOL->checkObjectExist_json(options, "scale9Width");
bool sh = DICTOOL->checkObjectExist_json(options, "scale9Height");
bool sw = DICTOOL->checkObjectExist_json(options, P_Scale9Width);
bool sh = DICTOOL->checkObjectExist_json(options, P_Scale9Height);
if (sw && sh)
{
float swf = DICTOOL->getFloatValue_json(options, "scale9Width");
float shf = DICTOOL->getFloatValue_json(options, "scale9Height");
float swf = DICTOOL->getFloatValue_json(options, P_Scale9Width);
float shf = DICTOOL->getFloatValue_json(options, P_Scale9Height);
button->setSize(Size(swf, shf));
}
}
bool tt = DICTOOL->checkObjectExist_json(options, "text");
bool tt = DICTOOL->checkObjectExist_json(options, P_Text);
if (tt)
{
const char* text = DICTOOL->getStringValue_json(options, "text");
const char* text = DICTOOL->getStringValue_json(options, P_Text);
if (text)
{
button->setTitleText(text);
}
}
bool cr = DICTOOL->checkObjectExist_json(options, "textColorR");
bool cg = DICTOOL->checkObjectExist_json(options, "textColorG");
bool cb = DICTOOL->checkObjectExist_json(options, "textColorB");
int cri = cr?DICTOOL->getIntValue_json(options, "textColorR"):255;
int cgi = cg?DICTOOL->getIntValue_json(options, "textColorG"):255;
int cbi = cb?DICTOOL->getIntValue_json(options, "textColorB"):255;
bool cr = DICTOOL->checkObjectExist_json(options, P_TextColorR);
bool cg = DICTOOL->checkObjectExist_json(options, P_TextColorG);
bool cb = DICTOOL->checkObjectExist_json(options, P_TextColorB);
int cri = cr?DICTOOL->getIntValue_json(options, P_TextColorR):255;
int cgi = cg?DICTOOL->getIntValue_json(options, P_TextColorG):255;
int cbi = cb?DICTOOL->getIntValue_json(options, P_TextColorB):255;
button->setTitleColor(Color3B(cri,cgi,cbi));
bool fs = DICTOOL->checkObjectExist_json(options, "fontSize");
bool fs = DICTOOL->checkObjectExist_json(options, P_FontSize);
if (fs)
{
button->setTitleFontSize(DICTOOL->getIntValue_json(options, "fontSize"));
button->setTitleFontSize(DICTOOL->getIntValue_json(options, P_FontSize));
}
bool fn = DICTOOL->checkObjectExist_json(options, "fontName");
bool fn = DICTOOL->checkObjectExist_json(options, P_FontName);
if (fn)
{
button->setTitleFontName(DICTOOL->getStringValue_json(options, "fontName"));
button->setTitleFontName(DICTOOL->getStringValue_json(options, P_FontName));
}

View File

@ -42,6 +42,7 @@ namespace cocostudio
virtual void setPropsFromJsonDictionary(cocos2d::ui::Widget* widget,
const rapidjson::Value& options);
virtual void setPropsFromBinary(cocos2d::ui::Widget* widget, CocoLoader* cocoLoader, stExpCocoNode* pCocoNode);
};
}

View File

@ -2,12 +2,19 @@
#include "CheckBoxReader.h"
#include "ui/UICheckBox.h"
#include "cocostudio/CocoLoader.h"
USING_NS_CC;
using namespace ui;
namespace cocostudio
{
static const char* P_BackGroundBoxData = "backGroundBoxData";
static const char* P_BackGroundBoxSelectedData = "backGroundBoxSelectedData";
static const char* P_FrontCrossData = "frontCrossData";
static const char* P_BackGroundBoxDisabledData = "backGroundBoxDisabledData";
static const char* P_FrontCrossDisabledData = "frontCrossDisabledData";
static CheckBoxReader* instanceCheckBoxReader = NULL;
IMPLEMENT_CLASS_WIDGET_READER_INFO(CheckBoxReader)
@ -31,41 +38,113 @@ namespace cocostudio
return instanceCheckBoxReader;
}
void CheckBoxReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *cocoLoader, stExpCocoNode *cocoNode)
{
CheckBox *checkBox = static_cast<CheckBox*>(widget);
this->beginSetBasicProperties(widget);
stExpCocoNode *stChildArray = cocoNode->GetChildArray();
for (int i = 0; i < cocoNode->GetChildNum(); ++i) {
std::string key = stChildArray[i].GetName(cocoLoader);
std::string value = stChildArray[i].GetValue();
// CCLOG("key = %s, index : %d", key.c_str(), i);
//read all basic properties of widget
CC_BASIC_PROPERTY_BINARY_READER
//read all color related properties of widget
CC_COLOR_PROPERTY_BINARY_READER
else if (key == P_BackGroundBoxData){
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray();
std::string resType = backGroundChildren[2].GetValue();;
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType);
checkBox->loadTextureBackGround(backgroundValue, imageFileNameType);
}else if(key == P_BackGroundBoxSelectedData){
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray();
std::string resType = backGroundChildren[2].GetValue();;
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType);
checkBox->loadTextureBackGroundSelected(backgroundValue, imageFileNameType);
}else if(key == P_FrontCrossData){
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray();
std::string resType = backGroundChildren[2].GetValue();;
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType);
checkBox->loadTextureFrontCross(backgroundValue, imageFileNameType);
}else if(key == P_BackGroundBoxDisabledData){
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray();
std::string resType = backGroundChildren[2].GetValue();;
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType);
checkBox->loadTextureBackGroundDisabled(backgroundValue, imageFileNameType);
}else if (key == P_FrontCrossDisabledData){
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray();
std::string resType = backGroundChildren[2].GetValue();;
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType);
checkBox->loadTextureFrontCrossDisabled(backgroundValue, imageFileNameType);
}
// else if (key == "selectedState"){
// checkBox->setSelectedState(valueToBool(value));
// }
}
this->endSetBasicProperties(widget);
}
void CheckBoxReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
{
WidgetReader::setPropsFromJsonDictionary(widget, options);
CheckBox* checkBox = static_cast<CheckBox*>(widget);
//load background image
const rapidjson::Value& backGroundDic = DICTOOL->getSubDictionary_json(options, "backGroundBoxData");
int backGroundType = DICTOOL->getIntValue_json(backGroundDic, "resourceType");
std::string backGroundTexturePath = this->getResourcePath(backGroundDic, "path", (Widget::TextureResType)backGroundType);
const rapidjson::Value& backGroundDic = DICTOOL->getSubDictionary_json(options, P_BackGroundBoxData);
int backGroundType = DICTOOL->getIntValue_json(backGroundDic,P_ResourceType);
std::string backGroundTexturePath = this->getResourcePath(backGroundDic, P_Path, (Widget::TextureResType)backGroundType);
checkBox->loadTextureBackGround(backGroundTexturePath, (Widget::TextureResType)backGroundType);
//load background selected image
const rapidjson::Value& backGroundSelectedDic = DICTOOL->getSubDictionary_json(options, "backGroundBoxSelectedData");
int backGroundSelectedType = DICTOOL->getIntValue_json(backGroundSelectedDic, "resourceType");
std::string backGroundSelectedTexturePath = this->getResourcePath(backGroundSelectedDic, "path", (Widget::TextureResType)backGroundSelectedType);
const rapidjson::Value& backGroundSelectedDic = DICTOOL->getSubDictionary_json(options, P_BackGroundBoxSelectedData);
int backGroundSelectedType = DICTOOL->getIntValue_json(backGroundSelectedDic, P_ResourceType);
std::string backGroundSelectedTexturePath = this->getResourcePath(backGroundSelectedDic, P_Path, (Widget::TextureResType)backGroundSelectedType);
checkBox->loadTextureBackGroundSelected(backGroundSelectedTexturePath, (Widget::TextureResType)backGroundSelectedType);
//load frontCross image
const rapidjson::Value& frontCrossDic = DICTOOL->getSubDictionary_json(options, "frontCrossData");
int frontCrossType = DICTOOL->getIntValue_json(frontCrossDic, "resourceType");
std::string frontCrossFileName = this->getResourcePath(frontCrossDic, "path", (Widget::TextureResType)frontCrossType);
const rapidjson::Value& frontCrossDic = DICTOOL->getSubDictionary_json(options, P_FrontCrossData);
int frontCrossType = DICTOOL->getIntValue_json(frontCrossDic, P_ResourceType);
std::string frontCrossFileName = this->getResourcePath(frontCrossDic, P_Path, (Widget::TextureResType)frontCrossType);
checkBox->loadTextureFrontCross(frontCrossFileName, (Widget::TextureResType)frontCrossType);
//load backGroundBoxDisabledData
const rapidjson::Value& backGroundDisabledDic = DICTOOL->getSubDictionary_json(options, "backGroundBoxDisabledData");
int backGroundDisabledType = DICTOOL->getIntValue_json(backGroundDisabledDic, "resourceType");
std::string backGroundDisabledFileName = this->getResourcePath(backGroundDisabledDic, "path", (Widget::TextureResType)backGroundDisabledType);
const rapidjson::Value& backGroundDisabledDic = DICTOOL->getSubDictionary_json(options, P_BackGroundBoxDisabledData);
int backGroundDisabledType = DICTOOL->getIntValue_json(backGroundDisabledDic, P_ResourceType);
std::string backGroundDisabledFileName = this->getResourcePath(backGroundDisabledDic, P_Path, (Widget::TextureResType)backGroundDisabledType);
checkBox->loadTextureBackGroundDisabled(backGroundDisabledFileName, (Widget::TextureResType)backGroundDisabledType);
///load frontCrossDisabledData
const rapidjson::Value& frontCrossDisabledDic = DICTOOL->getSubDictionary_json(options, "frontCrossDisabledData");
int frontCrossDisabledType = DICTOOL->getIntValue_json(frontCrossDisabledDic, "resourceType");
std::string frontCrossDisabledFileName = this->getResourcePath(frontCrossDisabledDic, "path", (Widget::TextureResType)frontCrossDisabledType);
const rapidjson::Value& frontCrossDisabledDic = DICTOOL->getSubDictionary_json(options, P_FrontCrossDisabledData);
int frontCrossDisabledType = DICTOOL->getIntValue_json(frontCrossDisabledDic, P_ResourceType);
std::string frontCrossDisabledFileName = this->getResourcePath(frontCrossDisabledDic, P_Path, (Widget::TextureResType)frontCrossDisabledType);
checkBox->loadTextureFrontCrossDisabled(frontCrossDisabledFileName, (Widget::TextureResType)frontCrossDisabledType);

View File

@ -41,6 +41,7 @@ namespace cocostudio
static void purge();
virtual void setPropsFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options);
virtual void setPropsFromBinary(cocos2d::ui::Widget* widget, CocoLoader* cocoLoader, stExpCocoNode* pCocoNode);
};
}

View File

@ -2,12 +2,23 @@
#include "ImageViewReader.h"
#include "ui/UIImageView.h"
#include "cocostudio/CocoLoader.h"
USING_NS_CC;
using namespace ui;
namespace cocostudio
{
static const char* P_Scale9Enable = "scale9Enable";
static const char* P_FileNameData = "fileNameData";
static const char* P_CapInsetsX = "capInsetsX";
static const char* P_CapInsetsY = "capInsetsY";
static const char* P_CapInsetsWidth = "capInsetsWidth";
static const char* P_CapInsetsHeight = "capInsetsHeight";
static const char* P_Scale9Width = "scale9Width";
static const char* P_Scale9Height = "scale9Height";
static ImageViewReader* instanceImageViewReader = NULL;
IMPLEMENT_CLASS_WIDGET_READER_INFO(ImageViewReader)
@ -31,6 +42,64 @@ namespace cocostudio
return instanceImageViewReader;
}
void ImageViewReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *cocoLoader, stExpCocoNode *cocoNode)
{
WidgetReader::setPropsFromBinary(widget, cocoLoader, cocoNode);
ImageView* imageView = static_cast<ImageView*>(widget);
this->beginSetBasicProperties(widget);
float capsx = 0.0f, capsy = 0.0, capsWidth = 0.0, capsHeight = 0.0f;
stExpCocoNode *stChildArray = cocoNode->GetChildArray();
for (int i = 0; i < cocoNode->GetChildNum(); ++i) {
std::string key = stChildArray[i].GetName(cocoLoader);
std::string value = stChildArray[i].GetValue();
//read all basic properties of widget
CC_BASIC_PROPERTY_BINARY_READER
//read all color related properties of widget
CC_COLOR_PROPERTY_BINARY_READER
else if (key == P_Scale9Enable) {
imageView->setScale9Enabled(valueToBool(value));
}
else if (key == P_FileNameData){
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray();
std::string resType = backGroundChildren[2].GetValue();;
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType);
imageView->loadTexture(backgroundValue, imageFileNameType);
}
else if(key == P_Scale9Width){
imageView->setContentSize(Size(valueToFloat(value), imageView->getContentSize().height));
}else if(key == P_Scale9Height){
imageView->setContentSize(Size(imageView->getContentSize().width, valueToFloat(value)));
}
else if(key == P_CapInsetsX){
capsx = valueToFloat(value);
}else if(key == P_CapInsetsY){
capsy = valueToFloat(value);
}else if(key == P_CapInsetsWidth){
capsWidth = valueToFloat(value);
}else if(key == P_CapInsetsHeight){
capsHeight = valueToFloat(value);
}
} //end of for loop
if (imageView->isScale9Enabled()) {
imageView->setCapInsets(Rect(capsx, capsy, capsWidth, capsHeight));
}
this->endSetBasicProperties(widget);
}
void ImageViewReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
{
WidgetReader::setPropsFromJsonDictionary(widget, options);
@ -39,36 +108,36 @@ namespace cocostudio
ImageView* imageView = static_cast<ImageView*>(widget);
const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "fileNameData");
int imageFileNameType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType");
std::string imageFileName = this->getResourcePath(imageFileNameDic, "path", (Widget::TextureResType)imageFileNameType);
const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, P_FileNameData);
int imageFileNameType = DICTOOL->getIntValue_json(imageFileNameDic, P_ResourceType);
std::string imageFileName = this->getResourcePath(imageFileNameDic, P_Path, (Widget::TextureResType)imageFileNameType);
imageView->loadTexture(imageFileName, (Widget::TextureResType)imageFileNameType);
bool scale9EnableExist = DICTOOL->checkObjectExist_json(options, "scale9Enable");
bool scale9EnableExist = DICTOOL->checkObjectExist_json(options, P_Scale9Enable);
bool scale9Enable = false;
if (scale9EnableExist)
{
scale9Enable = DICTOOL->getBooleanValue_json(options, "scale9Enable");
scale9Enable = DICTOOL->getBooleanValue_json(options, P_Scale9Enable);
}
imageView->setScale9Enabled(scale9Enable);
if (scale9Enable)
{
bool sw = DICTOOL->checkObjectExist_json(options, "scale9Width");
bool sh = DICTOOL->checkObjectExist_json(options, "scale9Height");
bool sw = DICTOOL->checkObjectExist_json(options, P_Scale9Width);
bool sh = DICTOOL->checkObjectExist_json(options, P_Scale9Height);
if (sw && sh)
{
float swf = DICTOOL->getFloatValue_json(options, "scale9Width");
float shf = DICTOOL->getFloatValue_json(options, "scale9Height");
float swf = DICTOOL->getFloatValue_json(options, P_Scale9Width);
float shf = DICTOOL->getFloatValue_json(options, P_Scale9Height);
imageView->setSize(Size(swf, shf));
}
float cx = DICTOOL->getFloatValue_json(options, "capInsetsX");
float cy = DICTOOL->getFloatValue_json(options, "capInsetsY");
float cw = DICTOOL->getFloatValue_json(options, "capInsetsWidth");
float ch = DICTOOL->getFloatValue_json(options, "capInsetsHeight");
float cx = DICTOOL->getFloatValue_json(options, P_CapInsetsX);
float cy = DICTOOL->getFloatValue_json(options, P_CapInsetsY);
float cw = DICTOOL->getFloatValue_json(options, P_CapInsetsWidth);
float ch = DICTOOL->getFloatValue_json(options, P_CapInsetsHeight);
imageView->setCapInsets(Rect(cx, cy, cw, ch));

View File

@ -41,6 +41,7 @@ namespace cocostudio
static void purge();
virtual void setPropsFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options);
virtual void setPropsFromBinary(cocos2d::ui::Widget* widget, CocoLoader* cocoLoader, stExpCocoNode* pCocoNode);
};
}

View File

@ -2,12 +2,35 @@
#include "LayoutReader.h"
#include "ui/UILayout.h"
#include "cocostudio/CocoLoader.h"
USING_NS_CC;
using namespace ui;
namespace cocostudio
{
static const char* P_CapInsetsX = "capInsetsX";
static const char* P_CapInsetsY = "capInsetsY";
static const char* P_CapInsetsWidth = "capInsetsWidth";
static const char* P_CapInsetsHeight = "capInsetsHeight";
static const char* P_ClipAble = "clipAble";
static const char* P_BackGroundScale9Enable = "backGroundScale9Enable";
static const char* P_BgColorR = "bgColorR";
static const char* P_BgColorG = "bgColorG";
static const char* P_BgColorB = "bgColorB";
static const char* P_BgStartColorR = "bgStartColorR";
static const char* P_BgStartColorG = "bgStartColorG";
static const char* P_BgStartColorB = "bgStartColorB";
static const char* P_BgEndColorR = "bgEndColorR";
static const char* P_BgEndColorG = "bgEndColorG";
static const char* P_BgEndColorB = "bgEndColorB";
static const char* P_VectorX = "vectorX";
static const char* P_VectorY = "vectorY";
static const char* P_BgColorOpacity = "bgColorOpacity";
static const char* P_ColorType = "colorType";
static const char* P_BackGroundImageData = "backGroundImageData";
static const char* P_LayoutType = "layoutType";
static LayoutReader* instanceLayoutReader = NULL;
IMPLEMENT_CLASS_WIDGET_READER_INFO(LayoutReader)
@ -31,6 +54,119 @@ namespace cocostudio
return instanceLayoutReader;
}
void LayoutReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *cocoLoader, stExpCocoNode *cocoNode)
{
WidgetReader::setPropsFromBinary(widget, cocoLoader, cocoNode);
Layout* panel = static_cast<Layout*>(widget);
stExpCocoNode *stChildArray = cocoNode->GetChildArray();
this->beginSetBasicProperties(widget);
int cr=0, cg = 0, cb = 0;
int scr=0, scg=0, scb=0;
int ecr=0, ecg=0, ecb= 0;
float bgcv1 = 0.0f, bgcv2= 0.0f;
float capsx = 0.0f, capsy = 0.0, capsWidth = 0.0, capsHeight = 0.0f;
Layout::Type layoutType;
int bgColorOpacity = panel->getBackGroundColorOpacity();
for (int i = 0; i < cocoNode->GetChildNum(); ++i) {
std::string key = stChildArray[i].GetName(cocoLoader);
std::string value = stChildArray[i].GetValue();
//read all basic properties of widget
CC_BASIC_PROPERTY_BINARY_READER
//read all color related properties of widget
CC_COLOR_PROPERTY_BINARY_READER
else if(key == P_AdaptScreen){
_isAdaptScreen = valueToBool(value);
}
else if( key == P_ClipAble){
panel->setClippingEnabled(valueToBool(value));
}else if(key == P_BackGroundScale9Enable){
panel->setBackGroundImageScale9Enabled(valueToBool(value));
}else if(key == P_BgColorR){
cr = valueToInt(value);
}else if(key == P_BgColorG){
cg = valueToInt(value);
}else if(key == P_BgColorB)
{
cb = valueToInt(value);
}else if(key == P_BgStartColorR){
scr = valueToInt(value);
}else if(key == P_BgStartColorG){
scg = valueToInt(value);
}else if(key == P_BgStartColorB)
{
scb = valueToInt(value);
}
else if(key == P_BgEndColorR){
ecr = valueToInt(value);
}else if(key == P_BgEndColorG){
ecg = valueToInt(value);
}else if(key == P_BgEndColorB)
{
ecb = valueToInt(value);
}else if (key == P_VectorX){
bgcv1 = valueToFloat(value);
}else if(key == P_VectorY){
bgcv2 = valueToFloat(value);
}else if(key == P_BgColorOpacity){
bgColorOpacity = valueToInt(value);
}else if( key == P_ColorType){
panel->setBackGroundColorType(Layout::BackGroundColorType(valueToInt(value)));
}else if (key == P_BackGroundImageData){
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray();
if (backGroundChildren) {
std::string resType = backGroundChildren[2].GetValue();;
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType);
panel->setBackGroundImage(backgroundValue, imageFileNameType);
}
}else if(key == P_CapInsetsX){
capsx = valueToFloat(value);
}else if(key == P_CapInsetsY){
capsy = valueToFloat(value);
}else if(key == P_CapInsetsWidth){
capsWidth = valueToFloat(value);
}else if(key == P_CapInsetsHeight){
capsHeight = valueToFloat(value);
}else if (key == P_LayoutType){
layoutType = (Layout::Type)valueToInt(value);
}
}
panel->setBackGroundColor(Color3B(scr, scg, scb),Color3B(ecr, ecg, ecb));
panel->setBackGroundColor(Color3B(cr, cg, cb));
panel->setBackGroundColorVector(Vec2(bgcv1, bgcv2));
panel->setBackGroundColorOpacity(bgColorOpacity);
panel->setBackGroundImageColor(Color3B(_color.r, _color.g, _color.b));
panel->setBackGroundImageOpacity(_opacity);
if (panel->isBackGroundImageScale9Enabled()) {
panel->setBackGroundImageCapInsets(Rect(capsx, capsy, capsWidth, capsHeight));
}
panel->setLayoutType(layoutType);
this->endSetBasicProperties(widget);
}
void LayoutReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
{
WidgetReader::setPropsFromJsonDictionary(widget, options);
@ -39,7 +175,7 @@ namespace cocostudio
/* adapt screen gui */
float w = 0, h = 0;
bool adaptScrenn = DICTOOL->getBooleanValue_json(options, "adaptScreen");
bool adaptScrenn = DICTOOL->getBooleanValue_json(options, P_AdaptScreen);
if (adaptScrenn)
{
Size screenSize = CCDirector::getInstance()->getWinSize();
@ -48,60 +184,61 @@ namespace cocostudio
}
else
{
w = DICTOOL->getFloatValue_json(options, "width");
h = DICTOOL->getFloatValue_json(options, "height");
w = DICTOOL->getFloatValue_json(options, P_Width);
h = DICTOOL->getFloatValue_json(options, P_Height);
}
panel->setSize(Size(w, h));
panel->setContentSize(Size(w, h));
/**/
panel->setClippingEnabled(DICTOOL->getBooleanValue_json(options, "clipAble"));
panel->setClippingEnabled(DICTOOL->getBooleanValue_json(options, P_ClipAble));
bool backGroundScale9Enable = DICTOOL->getBooleanValue_json(options, "backGroundScale9Enable");
bool backGroundScale9Enable = DICTOOL->getBooleanValue_json(options, P_BackGroundScale9Enable);
panel->setBackGroundImageScale9Enabled(backGroundScale9Enable);
int cr = DICTOOL->getIntValue_json(options, "bgColorR");
int cg = DICTOOL->getIntValue_json(options, "bgColorG");
int cb = DICTOOL->getIntValue_json(options, "bgColorB");
int cr = DICTOOL->getIntValue_json(options, P_BgColorR);
int cg = DICTOOL->getIntValue_json(options, P_BgColorG);
int cb = DICTOOL->getIntValue_json(options, P_BgColorB);
int scr = DICTOOL->getIntValue_json(options, "bgStartColorR");
int scg = DICTOOL->getIntValue_json(options, "bgStartColorG");
int scb = DICTOOL->getIntValue_json(options, "bgStartColorB");
int scr = DICTOOL->getIntValue_json(options, P_BgStartColorR);
int scg = DICTOOL->getIntValue_json(options, P_BgStartColorG);
int scb = DICTOOL->getIntValue_json(options, P_BgStartColorB);
int ecr = DICTOOL->getIntValue_json(options, "bgEndColorR");
int ecg = DICTOOL->getIntValue_json(options, "bgEndColorG");
int ecb = DICTOOL->getIntValue_json(options, "bgEndColorB");
int ecr = DICTOOL->getIntValue_json(options, P_BgEndColorR);
int ecg = DICTOOL->getIntValue_json(options, P_BgEndColorG);
int ecb = DICTOOL->getIntValue_json(options, P_BgEndColorB);
float bgcv1 = DICTOOL->getFloatValue_json(options, "vectorX");
float bgcv2 = DICTOOL->getFloatValue_json(options, "vectorY");
float bgcv1 = DICTOOL->getFloatValue_json(options, P_VectorX);
float bgcv2 = DICTOOL->getFloatValue_json(options, P_VectorY);
panel->setBackGroundColorVector(Vec2(bgcv1, bgcv2));
int co = DICTOOL->getIntValue_json(options, "bgColorOpacity");
int co = DICTOOL->getIntValue_json(options, P_BgColorOpacity);
int colorType = DICTOOL->getIntValue_json(options, "colorType");
int colorType = DICTOOL->getIntValue_json(options, P_ColorType);
panel->setBackGroundColorType(Layout::BackGroundColorType(colorType));
panel->setBackGroundColor(Color3B(scr, scg, scb),Color3B(ecr, ecg, ecb));
panel->setBackGroundColor(Color3B(cr, cg, cb));
panel->setBackGroundColorOpacity(co);
const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "backGroundImageData");
int imageFileNameType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType");
std::string imageFileName = this->getResourcePath(imageFileNameDic, "path", (Widget::TextureResType)imageFileNameType);
const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, P_BackGroundImageData);
int imageFileNameType = DICTOOL->getIntValue_json(imageFileNameDic, P_ResourceType);
std::string imageFileName = this->getResourcePath(imageFileNameDic, P_Path, (Widget::TextureResType)imageFileNameType);
panel->setBackGroundImage(imageFileName, (Widget::TextureResType)imageFileNameType);
if (backGroundScale9Enable)
{
float cx = DICTOOL->getFloatValue_json(options, "capInsetsX");
float cy = DICTOOL->getFloatValue_json(options, "capInsetsY");
float cw = DICTOOL->getFloatValue_json(options, "capInsetsWidth");
float ch = DICTOOL->getFloatValue_json(options, "capInsetsHeight");
float cx = DICTOOL->getFloatValue_json(options, P_CapInsetsX);
float cy = DICTOOL->getFloatValue_json(options, P_CapInsetsY);
float cw = DICTOOL->getFloatValue_json(options, P_CapInsetsWidth);
float ch = DICTOOL->getFloatValue_json(options, P_CapInsetsHeight);
panel->setBackGroundImageCapInsets(Rect(cx, cy, cw, ch));
}
panel->setLayoutType((Layout::Type)DICTOOL->getIntValue_json(options, "layoutType"));
int bgimgcr = DICTOOL->getIntValue_json(options, "colorR");
int bgimgcg = DICTOOL->getIntValue_json(options, "colorG");
int bgimgcb = DICTOOL->getIntValue_json(options, "colorB");
panel->setLayoutType((Layout::Type)DICTOOL->getIntValue_json(options, P_LayoutType));
int bgimgcr = DICTOOL->getIntValue_json(options, P_ColorR);
int bgimgcg = DICTOOL->getIntValue_json(options, P_ColorG);
int bgimgcb = DICTOOL->getIntValue_json(options, P_ColorB);
panel->setBackGroundImageColor(Color3B(bgimgcr, bgimgcg, bgimgcb));

View File

@ -41,6 +41,7 @@ namespace cocostudio
static void purge();
virtual void setPropsFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options);
virtual void setPropsFromBinary(cocos2d::ui::Widget* widget, CocoLoader* cocoLoader, stExpCocoNode* pCocoNode) ;
};
}

View File

@ -2,12 +2,16 @@
#include "ListViewReader.h"
#include "ui/UIListView.h"
#include "cocostudio/CocoLoader.h"
USING_NS_CC;
using namespace ui;
namespace cocostudio
{
static const char* P_Direction = "direction";
static const char* P_ItemMargin = "itemMargin";
static ListViewReader* instanceListViewReader = NULL;
IMPLEMENT_CLASS_WIDGET_READER_INFO(ListViewReader)
@ -31,6 +35,30 @@ namespace cocostudio
return instanceListViewReader;
}
void ListViewReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *cocoLoader, stExpCocoNode* cocoNode)
{
ScrollViewReader::setPropsFromBinary(widget, cocoLoader, cocoNode);
ListView* listView = static_cast<ListView*>(widget);
stExpCocoNode *stChildArray = cocoNode->GetChildArray();
for (int i = 0; i < cocoNode->GetChildNum(); ++i) {
std::string key = stChildArray[i].GetName(cocoLoader);
std::string value = stChildArray[i].GetValue();
if (key == P_Direction) {
listView->setDirection((ScrollView::Direction)valueToInt(value));
}
else if(key == P_Gravity){
listView->setGravity((ListView::Gravity)valueToInt(value));
}else if(key == P_ItemMargin){
listView->setItemsMargin(valueToFloat(value));
}
} //end of for loop
}
void ListViewReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
{
ScrollViewReader::setPropsFromJsonDictionary(widget, options);
@ -38,13 +66,13 @@ namespace cocostudio
ListView* listView = static_cast<ListView*>(widget);
int direction = DICTOOL->getFloatValue_json(options, "direction");
int direction = DICTOOL->getFloatValue_json(options, P_Direction);
listView->setDirection((ScrollView::Direction)direction);
ListView::Gravity gravity = (ListView::Gravity)DICTOOL->getIntValue_json(options, "gravity");
ListView::Gravity gravity = (ListView::Gravity)DICTOOL->getIntValue_json(options, P_Gravity);
listView->setGravity(gravity);
float itemMargin = DICTOOL->getFloatValue_json(options, "itemMargin");
float itemMargin = DICTOOL->getFloatValue_json(options, P_ItemMargin);
listView->setItemsMargin(itemMargin);
}
}

View File

@ -41,6 +41,7 @@ namespace cocostudio
static void purge();
virtual void setPropsFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options);
virtual void setPropsFromBinary(cocos2d::ui::Widget* widget, CocoLoader* cocoLoader, stExpCocoNode* pCocoNode) ;
};
}

View File

@ -2,12 +2,23 @@
#include "LoadingBarReader.h"
#include "ui/UILoadingBar.h"
#include "cocostudio/CocoLoader.h"
USING_NS_CC;
using namespace ui;
using namespace cocostudio;
namespace cocostudio
{
static const char* P_Scale9Enable = "scale9Enable";
static const char* P_CapInsetsX = "capInsetsX";
static const char* P_CapInsetsY = "capInsetsY";
static const char* P_CapInsetsWidth = "capInsetsWidth";
static const char* P_CapInsetsHeight = "capInsetsHeight";
static const char* P_TextureData = "textureData";
static const char* P_Direction = "direction";
static const char* P_Percent = "percent";
static LoadingBarReader* instanceLoadingBar = NULL;
IMPLEMENT_CLASS_WIDGET_READER_INFO(LoadingBarReader)
@ -31,6 +42,64 @@ namespace cocostudio
return instanceLoadingBar;
}
void LoadingBarReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *cocoLoader, stExpCocoNode *cocoNode)
{
WidgetReader::setPropsFromBinary(widget, cocoLoader, cocoNode);
LoadingBar* loadingBar = static_cast<LoadingBar*>(widget);
this->beginSetBasicProperties(widget);
float capsx = 0.0f, capsy = 0.0, capsWidth = 0.0, capsHeight = 0.0f;
int percent = loadingBar->getPercent();
stExpCocoNode *stChildArray = cocoNode->GetChildArray();
for (int i = 0; i < cocoNode->GetChildNum(); ++i) {
std::string key = stChildArray[i].GetName(cocoLoader);
std::string value = stChildArray[i].GetValue();
//read all basic properties of widget
CC_BASIC_PROPERTY_BINARY_READER
//read all color related properties of widget
CC_COLOR_PROPERTY_BINARY_READER
else if (key == P_Scale9Enable) {
loadingBar->setScale9Enabled(valueToBool(value));
}
else if (key == P_TextureData){
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray();
std::string resType = backGroundChildren[2].GetValue();;
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType);
loadingBar->loadTexture(backgroundValue, imageFileNameType);
}
else if(key == P_CapInsetsX){
capsx = valueToFloat(value);
}else if(key == P_CapInsetsY){
capsy = valueToFloat(value);
}else if(key == P_CapInsetsWidth){
capsWidth = valueToFloat(value);
}else if(key == P_CapInsetsHeight){
capsHeight = valueToFloat(value);
}else if(key == P_Direction){
loadingBar->setDirection((LoadingBar::Direction)valueToInt(value));
}else if(key == P_Percent){
percent = valueToInt(value);
}
} //end of for loop
if (loadingBar->isScale9Enabled()) {
loadingBar->setCapInsets(Rect(capsx, capsy, capsWidth, capsHeight));
}
loadingBar->setPercent(percent);
this->endSetBasicProperties(widget);
}
void LoadingBarReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
{
WidgetReader::setPropsFromJsonDictionary(widget, options);
@ -38,33 +107,33 @@ namespace cocostudio
LoadingBar* loadingBar = static_cast<LoadingBar*>(widget);
const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "textureData");
int imageFileNameType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType");
std::string imageFileName = this->getResourcePath(imageFileNameDic, "path", (Widget::TextureResType)imageFileNameType);
const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, P_TextureData);
int imageFileNameType = DICTOOL->getIntValue_json(imageFileNameDic, P_ResourceType);
std::string imageFileName = this->getResourcePath(imageFileNameDic, P_Path, (Widget::TextureResType)imageFileNameType);
loadingBar->loadTexture(imageFileName, (Widget::TextureResType)imageFileNameType);
/* gui mark add load bar scale9 parse */
bool scale9Enable = DICTOOL->getBooleanValue_json(options, "scale9Enable");
bool scale9Enable = DICTOOL->getBooleanValue_json(options, P_Scale9Enable);
loadingBar->setScale9Enabled(scale9Enable);
if (scale9Enable)
{
float cx = DICTOOL->getFloatValue_json(options, "capInsetsX");
float cy = DICTOOL->getFloatValue_json(options, "capInsetsY");
float cw = DICTOOL->getFloatValue_json(options, "capInsetsWidth");
float ch = DICTOOL->getFloatValue_json(options, "capInsetsHeight");
float cx = DICTOOL->getFloatValue_json(options, P_CapInsetsX);
float cy = DICTOOL->getFloatValue_json(options, P_CapInsetsY);
float cw = DICTOOL->getFloatValue_json(options, P_CapInsetsWidth);
float ch = DICTOOL->getFloatValue_json(options, P_CapInsetsHeight);
loadingBar->setCapInsets(Rect(cx, cy, cw, ch));
float width = DICTOOL->getFloatValue_json(options, "width");
float height = DICTOOL->getFloatValue_json(options, "height");
float width = DICTOOL->getFloatValue_json(options, P_Width);
float height = DICTOOL->getFloatValue_json(options, P_Height);
loadingBar->setSize(Size(width, height));
}
/**/
loadingBar->setDirection(LoadingBar::Direction(DICTOOL->getIntValue_json(options, "direction")));
loadingBar->setPercent(DICTOOL->getIntValue_json(options, "percent"));
loadingBar->setDirection(LoadingBar::Direction(DICTOOL->getIntValue_json(options, P_Direction)));
loadingBar->setPercent(DICTOOL->getIntValue_json(options, P_Percent));
WidgetReader::setColorPropsFromJsonDictionary(widget, options);

View File

@ -41,6 +41,7 @@ namespace cocostudio
static void purge();
virtual void setPropsFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options);
virtual void setPropsFromBinary(cocos2d::ui::Widget* widget, CocoLoader* cocoLoader, stExpCocoNode* pCocoNode) ;
};
}

View File

@ -2,13 +2,15 @@
#include "PageViewReader.h"
#include "ui/UIPageView.h"
#include "ui/UILayout.h"
#include "cocostudio/CocoLoader.h"
USING_NS_CC;
using namespace ui;
namespace cocostudio
{
static PageViewReader* instancePageViewReader = NULL;
static PageViewReader* instancePageViewReader = nullptr;
IMPLEMENT_CLASS_WIDGET_READER_INFO(PageViewReader)
@ -31,6 +33,11 @@ namespace cocostudio
return instancePageViewReader;
}
void PageViewReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *cocoLoader, stExpCocoNode *cocoNode)
{
LayoutReader::setPropsFromBinary(widget, cocoLoader, cocoNode);
}
void PageViewReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
{
LayoutReader::setPropsFromJsonDictionary(widget, options);

View File

@ -41,6 +41,8 @@ namespace cocostudio
static void purge();
virtual void setPropsFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options);
virtual void setPropsFromBinary(cocos2d::ui::Widget* widget, CocoLoader* cocoLoader, stExpCocoNode* cocoNode) ;
};
}

View File

@ -2,13 +2,19 @@
#include "ScrollViewReader.h"
#include "ui/UIScrollView.h"
#include "cocostudio/CocoLoader.h"
USING_NS_CC;
using namespace ui;
namespace cocostudio
{
static ScrollViewReader* instanceScrollViewReader = NULL;
static const char* P_InnerWidth = "innerWidth";
static const char* P_InnerHeight = "innerHeight";
static const char* P_Direction = "direction";
static const char* P_BounceEnable = "bounceEnable";
static ScrollViewReader* instanceScrollViewReader = nullptr;
IMPLEMENT_CLASS_WIDGET_READER_INFO(ScrollViewReader)
@ -31,18 +37,47 @@ namespace cocostudio
return instanceScrollViewReader;
}
void ScrollViewReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *cocoLoader, stExpCocoNode* cocoNode)
{
//TODO::need to refactor...
LayoutReader::setPropsFromBinary(widget, cocoLoader, cocoNode);
ScrollView* scrollView = static_cast<ScrollView*>(widget);
stExpCocoNode *stChildArray = cocoNode->GetChildArray();
float innerWidth;
float innerHeight;
for (int i = 0; i < cocoNode->GetChildNum(); ++i) {
std::string key = stChildArray[i].GetName(cocoLoader);
std::string value = stChildArray[i].GetValue();
if (key == P_InnerWidth) {
innerWidth = valueToFloat(value);
}
else if(key == P_InnerHeight){
innerHeight = valueToFloat(value);
}else if(key == P_Direction){
scrollView->setDirection((ScrollView::Direction)valueToInt(value));
}else if(key == P_BounceEnable){
scrollView->setBounceEnabled(valueToBool(value));
}
} //end of for loop
scrollView->setInnerContainerSize(Size(innerWidth, innerHeight));
}
void ScrollViewReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
{
LayoutReader::setPropsFromJsonDictionary(widget, options);
ScrollView* scrollView = static_cast<ScrollView*>(widget);
float innerWidth = DICTOOL->getFloatValue_json(options, "innerWidth");
float innerHeight = DICTOOL->getFloatValue_json(options, "innerHeight");
float innerWidth = DICTOOL->getFloatValue_json(options, P_InnerWidth);
float innerHeight = DICTOOL->getFloatValue_json(options, P_InnerHeight);
scrollView->setInnerContainerSize(Size(innerWidth, innerHeight));
int direction = DICTOOL->getFloatValue_json(options, "direction");
int direction = DICTOOL->getFloatValue_json(options, P_Direction);
scrollView->setDirection((ScrollView::Direction)direction);
scrollView->setBounceEnabled(DICTOOL->getBooleanValue_json(options, "bounceEnable"));
scrollView->setBounceEnabled(DICTOOL->getBooleanValue_json(options, P_BounceEnable));
LayoutReader::setColorPropsFromJsonDictionary(widget, options);

View File

@ -41,6 +41,8 @@ namespace cocostudio
static void purge();
virtual void setPropsFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options);
virtual void setPropsFromBinary(cocos2d::ui::Widget* widget, CocoLoader* cocoLoader, stExpCocoNode* pCocoNode) ;
};
}

View File

@ -2,12 +2,24 @@
#include "SliderReader.h"
#include "ui/UISlider.h"
#include "cocostudio/CocoLoader.h"
USING_NS_CC;
using namespace ui;
namespace cocostudio
{
static const char* P_Scale9Enable = "scale9Enable";
static const char* P_Percent = "percent";
static const char* P_BarFileNameData = "barFileNameData";
static const char* P_Length = "length";
static const char* P_BallNormalData = "ballNormalData";
static const char* P_BallPressedData = "ballPressedData";
static const char* P_BallDisabledData = "ballDisabledData";
static const char* P_ProgressBarData = "progressBarData";
static const char* P_BarFileName = "barFileName";
static SliderReader* instanceSliderReader = NULL;
IMPLEMENT_CLASS_WIDGET_READER_INFO(SliderReader)
@ -31,6 +43,95 @@ namespace cocostudio
return instanceSliderReader;
}
void SliderReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *cocoLoader, stExpCocoNode* cocoNode)
{
this->beginSetBasicProperties(widget);
Slider* slider = static_cast<Slider*>(widget);
float barLength = 0.0f;
int percent = slider->getPercent();
stExpCocoNode *stChildArray = cocoNode->GetChildArray();
for (int i = 0; i < cocoNode->GetChildNum(); ++i) {
std::string key = stChildArray[i].GetName(cocoLoader);
std::string value = stChildArray[i].GetValue();
//read all basic properties of widget
CC_BASIC_PROPERTY_BINARY_READER
//read all color related properties of widget
CC_COLOR_PROPERTY_BINARY_READER
//control custom properties
else if (key == P_Scale9Enable) {
slider->setScale9Enabled(valueToBool(value));
}
else if(key == P_Percent){
percent = valueToInt(value);
}else if(key == P_BarFileNameData){
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray();
std::string resType = backGroundChildren[2].GetValue();;
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType);
slider->loadBarTexture(backgroundValue, imageFileNameType);
}else if(key == P_Length){
barLength = valueToFloat(value);
}else if(key == P_BallNormalData){
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray();
std::string resType = backGroundChildren[2].GetValue();;
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType);
slider->loadSlidBallTextureNormal(backgroundValue, imageFileNameType);
}else if(key == P_BallPressedData){
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray();
std::string resType = backGroundChildren[2].GetValue();;
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType);
slider->loadSlidBallTexturePressed(backgroundValue, imageFileNameType);
}else if(key == P_BallDisabledData){
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray();
std::string resType = backGroundChildren[2].GetValue();;
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType);
slider->loadSlidBallTextureDisabled(backgroundValue, imageFileNameType);
}else if(key == P_ProgressBarData){
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray();
std::string resType = backGroundChildren[2].GetValue();;
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType);
slider->loadProgressBarTexture(backgroundValue, imageFileNameType);
}
} //end of for loop
if (slider->isScale9Enabled()) {
slider->setSize(Size(barLength, slider->getContentSize().height));
}
slider->setPercent(percent);
this->endSetBasicProperties(widget);
}
void SliderReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
{
WidgetReader::setPropsFromJsonDictionary(widget, options);
@ -38,50 +139,50 @@ namespace cocostudio
Slider* slider = static_cast<Slider*>(widget);
bool barTextureScale9Enable = DICTOOL->getBooleanValue_json(options, "scale9Enable");
bool barTextureScale9Enable = DICTOOL->getBooleanValue_json(options, P_Scale9Enable);
slider->setScale9Enabled(barTextureScale9Enable);
slider->setPercent(DICTOOL->getIntValue_json(options, "percent"));
slider->setPercent(DICTOOL->getIntValue_json(options, P_Percent));
bool bt = DICTOOL->checkObjectExist_json(options, "barFileName");
float barLength = DICTOOL->getFloatValue_json(options, "length");
bool bt = DICTOOL->checkObjectExist_json(options, P_BarFileName);
float barLength = DICTOOL->getFloatValue_json(options, P_Length);
if (bt)
{
const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "barFileNameData");
int imageFileNameType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType");
std::string imageFileName = this->getResourcePath(imageFileNameDic, "path", (Widget::TextureResType)imageFileNameType);
const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, P_BarFileNameData);
int imageFileNameType = DICTOOL->getIntValue_json(imageFileNameDic, P_ResourceType);
std::string imageFileName = this->getResourcePath(imageFileNameDic, P_Path, (Widget::TextureResType)imageFileNameType);
slider->loadBarTexture(imageFileName, (Widget::TextureResType)imageFileNameType);
if (barTextureScale9Enable)
{
slider->setSize(Size(barLength, slider->getContentSize().height));
slider->setContentSize(Size(barLength, slider->getContentSize().height));
}
}
//loading normal slider ball texture
const rapidjson::Value& normalDic = DICTOOL->getSubDictionary_json(options, "ballNormalData");
int normalType = DICTOOL->getIntValue_json(normalDic, "resourceType");
std::string imageFileName = this->getResourcePath(normalDic, "path", (Widget::TextureResType)normalType);
const rapidjson::Value& normalDic = DICTOOL->getSubDictionary_json(options, P_BallNormalData);
int normalType = DICTOOL->getIntValue_json(normalDic, P_ResourceType);
std::string imageFileName = this->getResourcePath(normalDic, P_Path, (Widget::TextureResType)normalType);
slider->loadSlidBallTextureNormal(imageFileName, (Widget::TextureResType)normalType);
//loading slider ball press texture
const rapidjson::Value& pressedDic = DICTOOL->getSubDictionary_json(options, "ballPressedData");
int pressedType = DICTOOL->getIntValue_json(pressedDic, "resourceType");
std::string pressedFileName = this->getResourcePath(pressedDic, "path", (Widget::TextureResType)pressedType);
const rapidjson::Value& pressedDic = DICTOOL->getSubDictionary_json(options, P_BallPressedData);
int pressedType = DICTOOL->getIntValue_json(pressedDic, P_ResourceType);
std::string pressedFileName = this->getResourcePath(pressedDic, P_Path, (Widget::TextureResType)pressedType);
slider->loadSlidBallTexturePressed(pressedFileName, (Widget::TextureResType)pressedType);
//loading silder ball disable texture
const rapidjson::Value& disabledDic = DICTOOL->getSubDictionary_json(options, "ballDisabledData");
int disabledType = DICTOOL->getIntValue_json(disabledDic, "resourceType");
std::string disabledFileName = this->getResourcePath(disabledDic, "path", (Widget::TextureResType)disabledType);
const rapidjson::Value& disabledDic = DICTOOL->getSubDictionary_json(options, P_BallDisabledData);
int disabledType = DICTOOL->getIntValue_json(disabledDic, P_ResourceType);
std::string disabledFileName = this->getResourcePath(disabledDic, P_Path, (Widget::TextureResType)disabledType);
slider->loadSlidBallTextureDisabled(disabledFileName, (Widget::TextureResType)disabledType);
//load slider progress texture
const rapidjson::Value& progressBarDic = DICTOOL->getSubDictionary_json(options, "progressBarData");
int progressBarType = DICTOOL->getIntValue_json(progressBarDic, "resourceType");
std::string progressBarFileName = this->getResourcePath(progressBarDic, "path", (Widget::TextureResType)progressBarType);
const rapidjson::Value& progressBarDic = DICTOOL->getSubDictionary_json(options, P_ProgressBarData);
int progressBarType = DICTOOL->getIntValue_json(progressBarDic, P_ResourceType);
std::string progressBarFileName = this->getResourcePath(progressBarDic, P_Path, (Widget::TextureResType)progressBarType);
slider->loadProgressBarTexture(progressBarFileName, (Widget::TextureResType)progressBarType);

View File

@ -41,6 +41,8 @@ namespace cocostudio
static void purge();
virtual void setPropsFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options);
virtual void setPropsFromBinary(cocos2d::ui::Widget* widget, CocoLoader* cocoLoader, stExpCocoNode* pCocoNode) ;
};
}

View File

@ -2,12 +2,22 @@
#include "TextAtlasReader.h"
#include "ui/UITextAtlas.h"
#include "cocostudio/CocoLoader.h"
USING_NS_CC;
using namespace ui;
namespace cocostudio
{
static const char* P_StringValue = "stringValue";
static const char* P_CharMapFileData = "charMapFileData";
static const char* P_ItemWidth = "itemWidth";
static const char* P_ItemHeight = "itemHeight";
static const char* P_StartCharMap = "startCharMap";
static const char* P_CharMapFile = "charMapFile";
static TextAtlasReader* instanceTextAtalsReader = NULL;
IMPLEMENT_CLASS_WIDGET_READER_INFO(TextAtlasReader)
@ -31,6 +41,58 @@ namespace cocostudio
return instanceTextAtalsReader;
}
void TextAtlasReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *cocoLoader, stExpCocoNode *cocoNode)
{
this->beginSetBasicProperties(widget);
TextAtlas* labelAtlas = static_cast<TextAtlas*>(widget);
stExpCocoNode *stChildArray = cocoNode->GetChildArray();
Widget::TextureResType type;
std::string charMapFileName;
std::string stringValue;
std::string startCharMap;
float itemWidth;
float itemHeight;
for (int i = 0; i < cocoNode->GetChildNum(); ++i) {
std::string key = stChildArray[i].GetName(cocoLoader);
std::string value = stChildArray[i].GetValue();
//read all basic properties of widget
CC_BASIC_PROPERTY_BINARY_READER
//read all color related properties of widget
CC_COLOR_PROPERTY_BINARY_READER
else if (key == P_StringValue) {
stringValue = value;
}
else if(key == P_CharMapFileData){
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray();
std::string resType = backGroundChildren[2].GetValue();;
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType);
charMapFileName = backgroundValue;
type = imageFileNameType;
}else if(key == P_ItemWidth){
itemWidth = valueToFloat(value);
}else if(key == P_ItemHeight){
itemHeight = valueToFloat(value);
}else if(key == P_StartCharMap){
startCharMap = value;
}
} //end of for loop
if (type == (Widget::TextureResType)0) {
labelAtlas->setProperty(stringValue, charMapFileName, itemWidth, itemHeight, startCharMap);
}
this->endSetBasicProperties(widget);
}
void TextAtlasReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
{
WidgetReader::setPropsFromJsonDictionary(widget, options);
@ -39,23 +101,23 @@ namespace cocostudio
std::string jsonPath = GUIReader::getInstance()->getFilePath();
TextAtlas* labelAtlas = static_cast<TextAtlas*>(widget);
bool sv = DICTOOL->checkObjectExist_json(options, "stringValue");
bool cmf = DICTOOL->checkObjectExist_json(options, "charMapFile");
bool iw = DICTOOL->checkObjectExist_json(options, "itemWidth");
bool ih = DICTOOL->checkObjectExist_json(options, "itemHeight");
bool scm = DICTOOL->checkObjectExist_json(options, "startCharMap");
bool sv = DICTOOL->checkObjectExist_json(options, P_StringValue);
bool cmf = DICTOOL->checkObjectExist_json(options, P_CharMapFile);
bool iw = DICTOOL->checkObjectExist_json(options, P_ItemWidth);
bool ih = DICTOOL->checkObjectExist_json(options, P_ItemHeight);
bool scm = DICTOOL->checkObjectExist_json(options, P_StartCharMap);
if (sv && cmf && iw && ih && scm)
{
const rapidjson::Value& cmftDic = DICTOOL->getSubDictionary_json(options, "charMapFileData");
int cmfType = DICTOOL->getIntValue_json(cmftDic, "resourceType");
const rapidjson::Value& cmftDic = DICTOOL->getSubDictionary_json(options, P_CharMapFileData);
int cmfType = DICTOOL->getIntValue_json(cmftDic, P_ResourceType);
switch (cmfType)
{
case 0:
{
std::string tp_c = jsonPath;
const char* cmfPath = DICTOOL->getStringValue_json(cmftDic, "path");
const char* cmfPath = DICTOOL->getStringValue_json(cmftDic, P_Path);
const char* cmf_tp = tp_c.append(cmfPath).c_str();
labelAtlas->setProperty(DICTOOL->getStringValue_json(options, "stringValue"),cmf_tp,DICTOOL->getIntValue_json(options, "itemWidth"),DICTOOL->getIntValue_json(options,"itemHeight"), DICTOOL->getStringValue_json(options, "startCharMap"));
labelAtlas->setProperty(DICTOOL->getStringValue_json(options, P_StringValue),cmf_tp,DICTOOL->getIntValue_json(options, P_ItemWidth),DICTOOL->getIntValue_json(options,P_ItemHeight), DICTOOL->getStringValue_json(options, P_StartCharMap));
break;
}
case 1:

View File

@ -40,6 +40,8 @@ namespace cocostudio
static TextAtlasReader* getInstance();
virtual void setPropsFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options);
virtual void setPropsFromBinary(cocos2d::ui::Widget* widget, CocoLoader* cocoLoader, stExpCocoNode* pCocoNode) ;
};
}

View File

@ -2,12 +2,16 @@
#include "TextBMFontReader.h"
#include "ui/UITextBMFont.h"
#include "cocostudio/CocoLoader.h"
USING_NS_CC;
using namespace ui;
namespace cocostudio
{
static const char* P_FileNameData = "fileNameData";
static const char* P_Text = "text";
static TextBMFontReader* instanceTextBMFontReader = NULL;
IMPLEMENT_CLASS_WIDGET_READER_INFO(TextBMFontReader)
@ -31,6 +35,41 @@ namespace cocostudio
return instanceTextBMFontReader;
}
void TextBMFontReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *cocoLoader, stExpCocoNode *cocoNode)
{
this->beginSetBasicProperties(widget);
TextBMFont* labelBMFont = static_cast<TextBMFont*>(widget);
stExpCocoNode *stChildArray = cocoNode->GetChildArray();
for (int i = 0; i < cocoNode->GetChildNum(); ++i) {
std::string key = stChildArray[i].GetName(cocoLoader);
std::string value = stChildArray[i].GetValue();
//read all basic properties of widget
CC_BASIC_PROPERTY_BINARY_READER
//read all color related properties of widget
CC_COLOR_PROPERTY_BINARY_READER
else if(key == P_FileNameData){
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray();
std::string resType = backGroundChildren[2].GetValue();;
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType);
if (imageFileNameType == (Widget::TextureResType)0) {
labelBMFont->setFntFile(backgroundValue);
}
}else if(key == P_Text){
labelBMFont->setString(value);
}
} //end of for loop
this->endSetBasicProperties(widget);
}
void TextBMFontReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
{
WidgetReader::setPropsFromJsonDictionary(widget, options);
@ -40,14 +79,14 @@ namespace cocostudio
TextBMFont* labelBMFont = static_cast<TextBMFont*>(widget);
const rapidjson::Value& cmftDic = DICTOOL->getSubDictionary_json(options, "fileNameData");
int cmfType = DICTOOL->getIntValue_json(cmftDic, "resourceType");
const rapidjson::Value& cmftDic = DICTOOL->getSubDictionary_json(options, P_FileNameData);
int cmfType = DICTOOL->getIntValue_json(cmftDic, P_ResourceType);
switch (cmfType)
{
case 0:
{
std::string tp_c = jsonPath;
const char* cmfPath = DICTOOL->getStringValue_json(cmftDic, "path");
const char* cmfPath = DICTOOL->getStringValue_json(cmftDic, P_Path);
const char* cmf_tp = tp_c.append(cmfPath).c_str();
labelBMFont->setFntFile(cmf_tp);
break;
@ -59,7 +98,7 @@ namespace cocostudio
break;
}
const char* text = DICTOOL->getStringValue_json(options, "text");
const char* text = DICTOOL->getStringValue_json(options, P_Text);
labelBMFont->setString(text);

View File

@ -41,6 +41,8 @@ namespace cocostudio
static void purge();
virtual void setPropsFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options);
virtual void setPropsFromBinary(cocos2d::ui::Widget* widget, CocoLoader* cocoLoader, stExpCocoNode* pCocoNode) ;
};
}

View File

@ -2,6 +2,7 @@
#include "TextFieldReader.h"
#include "ui/UITextField.h"
#include "cocostudio/CocoLoader.h"
USING_NS_CC;
using namespace ui;
@ -10,6 +11,17 @@ namespace cocostudio
{
static TextFieldReader* instanceTextFieldReader = NULL;
static const char* P_PlaceHolder = "placeHolder";
static const char* P_Text = "text";
static const char* P_FontSize = "fontSize";
static const char* P_FontName = "fontName";
static const char* P_TouchSizeWidth = "touchSizeWidth";
static const char* P_TouchSizeHeight = "touchSizeHeight";
static const char* P_MaxLengthEnable = "maxLengthEnable";
static const char* P_MaxLength = "maxLength";
static const char* P_PasswordEnable = "passwordEnable";
static const char* P_PasswordStyleText = "passwordStyleText";
IMPLEMENT_CLASS_WIDGET_READER_INFO(TextFieldReader)
TextFieldReader::TextFieldReader()
@ -31,54 +43,96 @@ namespace cocostudio
return instanceTextFieldReader;
}
void TextFieldReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *cocoLoader, stExpCocoNode* cocoNode)
{
this->beginSetBasicProperties(widget);
TextField* textField = static_cast<TextField*>(widget);
stExpCocoNode *stChildArray = cocoNode->GetChildArray();
for (int i = 0; i < cocoNode->GetChildNum(); ++i) {
std::string key = stChildArray[i].GetName(cocoLoader);
std::string value = stChildArray[i].GetValue();
//read all basic properties of widget
CC_BASIC_PROPERTY_BINARY_READER
//read all color related properties of widget
CC_COLOR_PROPERTY_BINARY_READER
else if(key == P_PlaceHolder){
textField->setPlaceHolder(value);
}else if(key == P_Text){
textField->setText(value);
}else if(key == P_FontSize){
textField->setFontSize(valueToInt(value));
}else if(key == P_FontName){
textField->setFontName(value);
}else if(key == P_TouchSizeWidth){
textField->setTouchSize(Size(valueToFloat(value), textField->getTouchSize().height));
}else if(key == P_TouchSizeHeight){
textField->setTouchSize(Size(textField->getTouchSize().width, valueToFloat(value)));
}else if (key == P_MaxLengthEnable){
textField->setMaxLengthEnabled(valueToBool(value));
}else if(key == P_MaxLength){
textField->setMaxLength(valueToInt(value));
}else if(key == P_PasswordEnable){
textField->setPasswordEnabled(valueToBool(value));
}else if(key == P_PasswordStyleText){
textField->setPasswordStyleText(value.c_str());
}
} //end of for loop
this->endSetBasicProperties(widget);
}
void TextFieldReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
{
WidgetReader::setPropsFromJsonDictionary(widget, options);
TextField* textField = static_cast<TextField*>(widget);
bool ph = DICTOOL->checkObjectExist_json(options, "placeHolder");
bool ph = DICTOOL->checkObjectExist_json(options, P_PlaceHolder);
if (ph)
{
textField->setPlaceHolder(DICTOOL->getStringValue_json(options, "placeHolder"));
textField->setPlaceHolder(DICTOOL->getStringValue_json(options, P_PlaceHolder));
}
textField->setText(DICTOOL->getStringValue_json(options, "text"));
bool fs = DICTOOL->checkObjectExist_json(options, "fontSize");
textField->setText(DICTOOL->getStringValue_json(options, P_Text));
bool fs = DICTOOL->checkObjectExist_json(options, P_FontSize);
if (fs)
{
textField->setFontSize(DICTOOL->getIntValue_json(options, "fontSize"));
textField->setFontSize(DICTOOL->getIntValue_json(options, P_FontSize));
}
bool fn = DICTOOL->checkObjectExist_json(options, "fontName");
bool fn = DICTOOL->checkObjectExist_json(options, P_FontName);
if (fn)
{
textField->setFontName(DICTOOL->getStringValue_json(options, "fontName"));
textField->setFontName(DICTOOL->getStringValue_json(options, P_FontName));
}
bool tsw = DICTOOL->checkObjectExist_json(options, "touchSizeWidth");
bool tsh = DICTOOL->checkObjectExist_json(options, "touchSizeHeight");
bool tsw = DICTOOL->checkObjectExist_json(options, P_TouchSizeWidth);
bool tsh = DICTOOL->checkObjectExist_json(options, P_TouchSizeHeight);
if (tsw && tsh)
{
textField->setTouchSize(Size(DICTOOL->getFloatValue_json(options, "touchSizeWidth"), DICTOOL->getFloatValue_json(options,"touchSizeHeight")));
textField->setTouchSize(Size(DICTOOL->getFloatValue_json(options, P_TouchSizeWidth), DICTOOL->getFloatValue_json(options,P_TouchSizeHeight)));
}
float dw = DICTOOL->getFloatValue_json(options, "width");
float dh = DICTOOL->getFloatValue_json(options, "height");
if (dw > 0.0f || dh > 0.0f)
{
//textField->setSize(Size(dw, dh));
}
bool maxLengthEnable = DICTOOL->getBooleanValue_json(options, "maxLengthEnable");
// float dw = DICTOOL->getFloatValue_json(options, "width");
// float dh = DICTOOL->getFloatValue_json(options, "height");
// if (dw > 0.0f || dh > 0.0f)
// {
// //textField->setSize(Size(dw, dh));
// }
bool maxLengthEnable = DICTOOL->getBooleanValue_json(options, P_MaxLengthEnable);
textField->setMaxLengthEnabled(maxLengthEnable);
if (maxLengthEnable)
{
int maxLength = DICTOOL->getIntValue_json(options, "maxLength");
int maxLength = DICTOOL->getIntValue_json(options, P_MaxLength);
textField->setMaxLength(maxLength);
}
bool passwordEnable = DICTOOL->getBooleanValue_json(options, "passwordEnable");
bool passwordEnable = DICTOOL->getBooleanValue_json(options, P_PasswordEnable);
textField->setPasswordEnabled(passwordEnable);
if (passwordEnable)
{
textField->setPasswordStyleText(DICTOOL->getStringValue_json(options, "passwordStyleText"));
textField->setPasswordStyleText(DICTOOL->getStringValue_json(options, P_PasswordStyleText));
}

View File

@ -41,6 +41,8 @@ namespace cocostudio
static void purge();
virtual void setPropsFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options);
virtual void setPropsFromBinary(cocos2d::ui::Widget* widget, CocoLoader* cocoLoader, stExpCocoNode* pCocoNode) ;
};
}

View File

@ -2,12 +2,22 @@
#include "TextReader.h"
#include "ui/UIText.h"
#include "cocostudio/CocoLoader.h"
USING_NS_CC;
using namespace ui;
namespace cocostudio
{
static const char* P_TouchScaleEnable = "touchScaleEnable";
static const char* P_Text = "text";
static const char* P_FontSize = "fontSize";
static const char* P_FontName = "fontName";
static const char* P_AreaWidth = "areaWidth";
static const char* P_AreaHeight = "areaHeight";
static const char* P_HAlignment = "hAlignment";
static const char* P_VAlignment = "vAlignment";
static TextReader* instanceTextReader = NULL;
IMPLEMENT_CLASS_WIDGET_READER_INFO(TextReader)
@ -31,6 +41,47 @@ namespace cocostudio
return instanceTextReader;
}
void TextReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *cocoLoader, stExpCocoNode *cocoNode)
{
this->beginSetBasicProperties(widget);
stExpCocoNode *stChildArray = cocoNode->GetChildArray();
Text* label = static_cast<Text*>(widget);
for (int i = 0; i < cocoNode->GetChildNum(); ++i) {
std::string key = stChildArray[i].GetName(cocoLoader);
std::string value = stChildArray[i].GetValue();
//read all basic properties of widget
CC_BASIC_PROPERTY_BINARY_READER
//read all color related properties of widget
CC_COLOR_PROPERTY_BINARY_READER
else if (key == P_TouchScaleEnable) {
label->setTouchScaleChangeEnabled(valueToBool(value));
}
else if(key == P_Text){
label->setString(value);
}else if(key == P_FontSize){
label->setFontSize(valueToInt(value));
}else if(key == P_FontName){
label->setFontName(value);
}else if(key == P_AreaWidth){
label->setTextAreaSize(Size(valueToFloat(value), label->getTextAreaSize().height));
}else if(key == P_AreaHeight){
label->setTextAreaSize(Size(label->getTextAreaSize().width, valueToFloat(value)));
}else if(key == P_HAlignment){
label->setTextHorizontalAlignment((TextHAlignment)valueToInt(value));
}else if(key == P_VAlignment){
label->setTextVerticalAlignment((TextVAlignment)valueToInt(value));
}
} //end of for loop
this->endSetBasicProperties(widget);
}
void TextReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
{
WidgetReader::setPropsFromJsonDictionary(widget, options);
@ -39,38 +90,38 @@ namespace cocostudio
std::string jsonPath = GUIReader::getInstance()->getFilePath();
Text* label = static_cast<Text*>(widget);
bool touchScaleChangeAble = DICTOOL->getBooleanValue_json(options, "touchScaleEnable");
bool touchScaleChangeAble = DICTOOL->getBooleanValue_json(options, P_TouchScaleEnable);
label->setTouchScaleChangeEnabled(touchScaleChangeAble);
const char* text = DICTOOL->getStringValue_json(options, "text");
const char* text = DICTOOL->getStringValue_json(options, P_Text);
label->setString(text);
bool fs = DICTOOL->checkObjectExist_json(options, "fontSize");
bool fs = DICTOOL->checkObjectExist_json(options, P_FontSize);
if (fs)
{
label->setFontSize(DICTOOL->getIntValue_json(options, "fontSize"));
label->setFontSize(DICTOOL->getIntValue_json(options, P_FontSize));
}
bool fn = DICTOOL->checkObjectExist_json(options, "fontName");
bool fn = DICTOOL->checkObjectExist_json(options, P_FontName);
if (fn)
{
std::string fontName = DICTOOL->getStringValue_json(options, "fontName");
std::string fontName = DICTOOL->getStringValue_json(options, P_FontName);
std::string fontFilePath = jsonPath.append(fontName);
label->setFontName(fontFilePath);
}
bool aw = DICTOOL->checkObjectExist_json(options, "areaWidth");
bool ah = DICTOOL->checkObjectExist_json(options, "areaHeight");
bool aw = DICTOOL->checkObjectExist_json(options, P_AreaWidth);
bool ah = DICTOOL->checkObjectExist_json(options, P_AreaHeight);
if (aw && ah)
{
Size size = Size(DICTOOL->getFloatValue_json(options, "areaWidth"),DICTOOL->getFloatValue_json(options,"areaHeight"));
Size size = Size(DICTOOL->getFloatValue_json(options, P_AreaWidth),DICTOOL->getFloatValue_json(options,P_AreaHeight));
label->setTextAreaSize(size);
}
bool ha = DICTOOL->checkObjectExist_json(options, "hAlignment");
bool ha = DICTOOL->checkObjectExist_json(options, P_HAlignment);
if (ha)
{
label->setTextHorizontalAlignment((TextHAlignment)DICTOOL->getIntValue_json(options, "hAlignment"));
label->setTextHorizontalAlignment((TextHAlignment)DICTOOL->getIntValue_json(options, P_HAlignment));
}
bool va = DICTOOL->checkObjectExist_json(options, "vAlignment");
bool va = DICTOOL->checkObjectExist_json(options, P_VAlignment);
if (va)
{
label->setTextVerticalAlignment((TextVAlignment)DICTOOL->getIntValue_json(options, "vAlignment"));
label->setTextVerticalAlignment((TextVAlignment)DICTOOL->getIntValue_json(options, P_VAlignment));
}

View File

@ -41,6 +41,8 @@ namespace cocostudio
static void purge();
virtual void setPropsFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options);
virtual void setPropsFromBinary(cocos2d::ui::Widget* widget, CocoLoader* cocoLoader, stExpCocoNode* pCocoNode);
};
}

View File

@ -1,22 +1,98 @@
#include "WidgetReader.h"
#include "cocostudio/CocoLoader.h"
#include "ui/UIButton.h"
USING_NS_CC;
using namespace ui;
namespace cocostudio
{
const char* P_IgnoreSize = "ignoreSize";
const char* P_SizeType = "sizeType";
const char* P_PositionType = "positionType";
const char* P_SizePercentX = "sizePercentX";
const char* P_SizePercentY = "sizePercentY";
const char* P_PositionPercentX = "positionPercentX";
const char* P_PositionPercentY = "positionPercentY";
const char* P_AdaptScreen = "adaptScreen";
const char* P_Width = "width";
const char* P_Height = "height";
const char* P_Tag = "tag";
const char* P_ActionTag = "actiontag";
const char* P_TouchAble = "touchAble";
const char* P_Name = "name";
const char* P_X = "x";
const char* P_Y = "y";
const char* P_ScaleX = "scaleX";
const char* P_ScaleY = "scaleY";
const char* P_Rotation = "rotation";
const char* P_Visbile = "visible";
const char* P_ZOrder = "ZOrder";
const char* P_LayoutParameter = "layoutParameter";
const char* P_Type = "type";
const char* P_Gravity = "gravity";
const char* P_RelativeName = "relativeName";
const char* P_RelativeToName = "relativeToName";
const char* P_Align = "align";
const char* P_MarginLeft = "marginLeft";
const char* P_MarginRight = "marginRight";
const char* P_MarginTop = "marginTop";
const char* P_MarginDown = "marginDown";
const char* P_Opacity = "opacity";
const char* P_ColorR = "colorR";
const char* P_ColorG = "colorG";
const char* P_ColorB = "colorB";
const char* P_FlipX = "flipX";
const char* P_FlipY = "flipY";
const char* P_AnchorPointX = "anchorPointX";
const char* P_AnchorPointY = "anchorPointY";
const char* P_ResourceType = "resourceType";
const char* P_Path = "path";
static WidgetReader* instanceWidgetReader = NULL;
IMPLEMENT_CLASS_WIDGET_READER_INFO(WidgetReader)
WidgetReader::WidgetReader()
:_sizePercentX(0.0f),
_sizePercentY(0.0f),
_isAdaptScreen(false),
_width(0.0f),
_height(0.0f),
_positionPercentX(0.0f),
_positionPercentY(0.0f),
_opacity(255)
{
valueToInt = [=](const std::string& str) -> int{
return atoi(str.c_str());
};
valueToBool = [=](const std::string& str) -> bool{
int intValue = valueToInt(str);
if (1 == intValue) {
return true;
}else{
return false;
}
};
valueToFloat = [=](const std::string& str) -> float{
return atof(str.c_str());
};
}
WidgetReader::~WidgetReader()
{
}
@ -37,21 +113,21 @@ namespace cocostudio
void WidgetReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
{
bool ignoreSizeExsit = DICTOOL->checkObjectExist_json(options, "ignoreSize");
bool ignoreSizeExsit = DICTOOL->checkObjectExist_json(options, P_IgnoreSize);
if (ignoreSizeExsit)
{
widget->ignoreContentAdaptWithSize(DICTOOL->getBooleanValue_json(options, "ignoreSize"));
widget->ignoreContentAdaptWithSize(DICTOOL->getBooleanValue_json(options, P_IgnoreSize));
}
widget->setSizeType((Widget::SizeType)DICTOOL->getIntValue_json(options, "sizeType"));
widget->setPositionType((Widget::PositionType)DICTOOL->getIntValue_json(options, "positionType"));
widget->setSizeType((Widget::SizeType)DICTOOL->getIntValue_json(options, P_SizeType));
widget->setPositionType((Widget::PositionType)DICTOOL->getIntValue_json(options, P_PositionType));
widget->setSizePercent(Vec2(DICTOOL->getFloatValue_json(options, "sizePercentX"), DICTOOL->getFloatValue_json(options, "sizePercentY")));
widget->setPositionPercent(Vec2(DICTOOL->getFloatValue_json(options, "positionPercentX"), DICTOOL->getFloatValue_json(options, "positionPercentY")));
widget->setSizePercent(Vec2(DICTOOL->getFloatValue_json(options, P_SizePercentX), DICTOOL->getFloatValue_json(options, P_SizePercentY)));
widget->setPositionPercent(Vec2(DICTOOL->getFloatValue_json(options, P_PositionPercentX), DICTOOL->getFloatValue_json(options, P_PositionPercentY)));
/* adapt screen */
float w = 0, h = 0;
bool adaptScrenn = DICTOOL->getBooleanValue_json(options, "adaptScreen");
bool adaptScrenn = DICTOOL->getBooleanValue_json(options, P_AdaptScreen);
if (adaptScrenn)
{
Size screenSize = CCDirector::getInstance()->getWinSize();
@ -60,55 +136,49 @@ namespace cocostudio
}
else
{
w = DICTOOL->getFloatValue_json(options, "width");
h = DICTOOL->getFloatValue_json(options, "height");
w = DICTOOL->getFloatValue_json(options, P_Width);
h = DICTOOL->getFloatValue_json(options, P_Height);
}
widget->setSize(Size(w, h));
// before
/*
float w = DICTOOL->getFloatValue_json(options, "width");
float h = DICTOOL->getFloatValue_json(options, "height");
widget->setSize(CCSizeMake(w, h));
*/
/**/
widget->setTag(DICTOOL->getIntValue_json(options, "tag"));
widget->setActionTag(DICTOOL->getIntValue_json(options, "actiontag"));
widget->setTouchEnabled(DICTOOL->getBooleanValue_json(options, "touchAble"));
const char* name = DICTOOL->getStringValue_json(options, "name");
widget->setTag(DICTOOL->getIntValue_json(options, P_Tag));
widget->setActionTag(DICTOOL->getIntValue_json(options, P_ActionTag));
widget->setTouchEnabled(DICTOOL->getBooleanValue_json(options, P_TouchAble));
const char* name = DICTOOL->getStringValue_json(options, P_Name);
const char* widgetName = name?name:"default";
widget->setName(widgetName);
float x = DICTOOL->getFloatValue_json(options, "x");
float y = DICTOOL->getFloatValue_json(options, "y");
float x = DICTOOL->getFloatValue_json(options, P_X);
float y = DICTOOL->getFloatValue_json(options, P_Y);
widget->setPosition(Vec2(x,y));
bool sx = DICTOOL->checkObjectExist_json(options, "scaleX");
bool sx = DICTOOL->checkObjectExist_json(options, P_ScaleX);
if (sx)
{
widget->setScaleX(DICTOOL->getFloatValue_json(options, "scaleX"));
widget->setScaleX(DICTOOL->getFloatValue_json(options, P_ScaleX));
}
bool sy = DICTOOL->checkObjectExist_json(options, "scaleY");
bool sy = DICTOOL->checkObjectExist_json(options, P_ScaleY);
if (sy)
{
widget->setScaleY(DICTOOL->getFloatValue_json(options, "scaleY"));
widget->setScaleY(DICTOOL->getFloatValue_json(options, P_ScaleY));
}
bool rt = DICTOOL->checkObjectExist_json(options, "rotation");
bool rt = DICTOOL->checkObjectExist_json(options, P_Rotation);
if (rt)
{
widget->setRotation(DICTOOL->getFloatValue_json(options, "rotation"));
widget->setRotation(DICTOOL->getFloatValue_json(options, P_Rotation));
}
bool vb = DICTOOL->checkObjectExist_json(options, "visible");
bool vb = DICTOOL->checkObjectExist_json(options, P_Visbile);
if (vb)
{
widget->setVisible(DICTOOL->getBooleanValue_json(options, "visible"));
widget->setVisible(DICTOOL->getBooleanValue_json(options, P_Visbile));
}
int z = DICTOOL->getIntValue_json(options, "ZOrder");
int z = DICTOOL->getIntValue_json(options, P_ZOrder);
widget->setLocalZOrder(z);
bool layout = DICTOOL->checkObjectExist_json(options, "layoutParameter");
bool layout = DICTOOL->checkObjectExist_json(options, P_LayoutParameter);
if (layout)
{
const rapidjson::Value& layoutParameterDic = DICTOOL->getSubDictionary_json(options, "layoutParameter");
int paramType = DICTOOL->getIntValue_json(layoutParameterDic, "type");
const rapidjson::Value& layoutParameterDic = DICTOOL->getSubDictionary_json(options, P_LayoutParameter);
int paramType = DICTOOL->getIntValue_json(layoutParameterDic, P_Type);
LayoutParameter* parameter = nullptr;
switch (paramType)
{
@ -117,7 +187,7 @@ namespace cocostudio
case 1:
{
parameter = LinearLayoutParameter::create();
int gravity = DICTOOL->getIntValue_json(layoutParameterDic, "gravity");
int gravity = DICTOOL->getIntValue_json(layoutParameterDic, P_Gravity);
((LinearLayoutParameter*)parameter)->setGravity((cocos2d::ui::LinearLayoutParameter::LinearGravity)gravity);
break;
}
@ -125,11 +195,11 @@ namespace cocostudio
{
parameter = RelativeLayoutParameter::create();
RelativeLayoutParameter* rParameter = (RelativeLayoutParameter*)parameter;
const char* relativeName = DICTOOL->getStringValue_json(layoutParameterDic, "relativeName");
const char* relativeName = DICTOOL->getStringValue_json(layoutParameterDic, P_RelativeName);
rParameter->setRelativeName(relativeName);
const char* relativeToName = DICTOOL->getStringValue_json(layoutParameterDic, "relativeToName");
const char* relativeToName = DICTOOL->getStringValue_json(layoutParameterDic, P_RelativeToName);
rParameter->setRelativeToWidgetName(relativeToName);
int align = DICTOOL->getIntValue_json(layoutParameterDic, "align");
int align = DICTOOL->getIntValue_json(layoutParameterDic, P_Align);
rParameter->setAlign((cocos2d::ui::RelativeLayoutParameter::RelativeAlign)align);
break;
}
@ -138,10 +208,10 @@ namespace cocostudio
}
if (parameter)
{
float mgl = DICTOOL->getFloatValue_json(layoutParameterDic, "marginLeft");
float mgt = DICTOOL->getFloatValue_json(layoutParameterDic, "marginTop");
float mgr = DICTOOL->getFloatValue_json(layoutParameterDic, "marginRight");
float mgb = DICTOOL->getFloatValue_json(layoutParameterDic, "marginDown");
float mgl = DICTOOL->getFloatValue_json(layoutParameterDic, P_MarginLeft);
float mgt = DICTOOL->getFloatValue_json(layoutParameterDic, P_MarginTop);
float mgr = DICTOOL->getFloatValue_json(layoutParameterDic, P_MarginRight);
float mgb = DICTOOL->getFloatValue_json(layoutParameterDic, P_MarginDown);
parameter->setMargin(Margin(mgl, mgt, mgr, mgb));
widget->setLayoutParameter(parameter);
}
@ -150,27 +220,55 @@ namespace cocostudio
void WidgetReader::setColorPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
{
bool op = DICTOOL->checkObjectExist_json(options, "opacity");
bool op = DICTOOL->checkObjectExist_json(options, P_Opacity);
if (op)
{
widget->setOpacity(DICTOOL->getIntValue_json(options, "opacity"));
widget->setOpacity(DICTOOL->getIntValue_json(options, P_Opacity));
}
bool cr = DICTOOL->checkObjectExist_json(options, "colorR");
bool cg = DICTOOL->checkObjectExist_json(options, "colorG");
bool cb = DICTOOL->checkObjectExist_json(options, "colorB");
int colorR = cr ? DICTOOL->getIntValue_json(options, "colorR") : 255;
int colorG = cg ? DICTOOL->getIntValue_json(options, "colorG") : 255;
int colorB = cb ? DICTOOL->getIntValue_json(options, "colorB") : 255;
bool cr = DICTOOL->checkObjectExist_json(options, P_ColorR);
bool cg = DICTOOL->checkObjectExist_json(options, P_ColorG);
bool cb = DICTOOL->checkObjectExist_json(options, P_ColorB);
int colorR = cr ? DICTOOL->getIntValue_json(options, P_ColorR) : 255;
int colorG = cg ? DICTOOL->getIntValue_json(options, P_ColorG) : 255;
int colorB = cb ? DICTOOL->getIntValue_json(options, P_ColorB) : 255;
widget->setColor(Color3B(colorR, colorG, colorB));
this->setAnchorPointForWidget(widget, options);
bool flipX = DICTOOL->getBooleanValue_json(options, "flipX");
bool flipY = DICTOOL->getBooleanValue_json(options, "flipY");
bool flipX = DICTOOL->getBooleanValue_json(options, P_FlipX);
bool flipY = DICTOOL->getBooleanValue_json(options, P_FlipY);
widget->setFlippedX(flipX);
widget->setFlippedY(flipY);
}
void WidgetReader::beginSetBasicProperties(cocos2d::ui::Widget *widget)
{
_position = widget->getPosition();
//set default color
_color = Color3B(255,255,255);
widget->setColor(_color);
_opacity = widget->getOpacity();
_originalAnchorPoint = widget->getAnchorPoint();
}
void WidgetReader::endSetBasicProperties(Widget *widget)
{
Size screenSize = Director::getInstance()->getWinSize();
widget->setPositionPercent(Vec2(_positionPercentX, _positionPercentY));
widget->setSizePercent(Vec2(_sizePercentX, _sizePercentY));
if (_isAdaptScreen) {
_width = screenSize.width;
_height = screenSize.height;
}
widget->setColor(_color);
widget->setOpacity(_opacity);
//the setSize method will be conflict with scale9Width & scale9Height
widget->setSize(Size(_width, _height));
widget->setPosition(_position);
widget->setAnchorPoint(_originalAnchorPoint);
}
std::string WidgetReader::getResourcePath(const rapidjson::Value &dict,
const std::string &key,
cocos2d::ui::Widget::TextureResType texType)
@ -193,20 +291,47 @@ namespace cocostudio
return imageFileName_tp;
}
std::string WidgetReader::getResourcePath(CocoLoader *cocoLoader, stExpCocoNode *cocoNode, cocos2d::ui::Widget::TextureResType texType)
{
stExpCocoNode *backGroundChildren = cocoNode->GetChildArray();
std::string backgroundValue = backGroundChildren[0].GetValue();
if (backgroundValue.size() < 3) {
return "";
}
std::string binaryPath = GUIReader::getInstance()->getFilePath();
std::string imageFileName_tp;
if (!backgroundValue.empty())
{
if (texType == ui::Widget::TextureResType::LOCAL) {
imageFileName_tp = binaryPath + backgroundValue;
}
else if(texType == ui::Widget::TextureResType::PLIST){
imageFileName_tp = backgroundValue;
}
else{
CCASSERT(0, "invalid TextureResType!!!");
}
}
return imageFileName_tp;
}
void WidgetReader::setAnchorPointForWidget(cocos2d::ui::Widget *widget, const rapidjson::Value &options)
{
bool isAnchorPointXExists = DICTOOL->checkObjectExist_json(options, "anchorPointX");
bool isAnchorPointXExists = DICTOOL->checkObjectExist_json(options, P_AnchorPointX);
float anchorPointXInFile;
if (isAnchorPointXExists) {
anchorPointXInFile = DICTOOL->getFloatValue_json(options, "anchorPointX");
anchorPointXInFile = DICTOOL->getFloatValue_json(options, P_AnchorPointX);
}else{
anchorPointXInFile = widget->getAnchorPoint().x;
}
bool isAnchorPointYExists = DICTOOL->checkObjectExist_json(options, "anchorPointY");
bool isAnchorPointYExists = DICTOOL->checkObjectExist_json(options, P_AnchorPointY);
float anchorPointYInFile;
if (isAnchorPointYExists) {
anchorPointYInFile = DICTOOL->getFloatValue_json(options, "anchorPointY");
anchorPointYInFile = DICTOOL->getFloatValue_json(options, P_AnchorPointY);
}
else{
anchorPointYInFile = widget->getAnchorPoint().y;
@ -216,6 +341,23 @@ namespace cocostudio
widget->setAnchorPoint(Vec2(anchorPointXInFile, anchorPointYInFile));
}
}
void WidgetReader::setPropsFromBinary(cocos2d::ui::Widget *widget, cocostudio::CocoLoader *cocoLoader, cocostudio::stExpCocoNode *cocoNode)
{
stExpCocoNode *stChildArray = cocoNode->GetChildArray();
this->beginSetBasicProperties(widget);
for (int i = 0; i < cocoNode->GetChildNum(); ++i) {
std::string key = stChildArray[i].GetName(cocoLoader);
std::string value = stChildArray[i].GetValue();
CC_BASIC_PROPERTY_BINARY_READER
}
this->endSetBasicProperties(widget);
}
}

View File

@ -26,12 +26,16 @@
#define __TestCpp__WidgetReader__
#include "WidgetReaderProtocol.h"
#include "../CCSGUIReader.h"
#include "cocostudio/CCSGUIReader.h"
#include "ui/GUIDefine.h"
#include "ui/UIWidget.h"
namespace cocostudio
{
class CocoLoader;
struct stExpCocoNode;
class WidgetReader : public cocos2d::Ref, public WidgetReaderProtocol
{
public:
@ -49,13 +53,193 @@ namespace cocostudio
virtual void setColorPropsFromJsonDictionary(cocos2d::ui::Widget* widget,
const rapidjson::Value& options);
virtual void setPropsFromBinary(cocos2d::ui::Widget* widget, CocoLoader* cocoLoader, stExpCocoNode* pCocoNode);
protected:
std::string getResourcePath(const rapidjson::Value& dict,
const std::string& key,
cocos2d::ui::Widget::TextureResType texType);
void setAnchorPointForWidget(cocos2d::ui::Widget* widget, const rapidjson::Value&options);
std::string getResourcePath(CocoLoader* cocoLoader,
stExpCocoNode* pCocoNode,
cocos2d::ui::Widget::TextureResType texType);
void beginSetBasicProperties(cocos2d::ui::Widget *widget);
void endSetBasicProperties(cocos2d::ui::Widget *widget);
std::function<int(const std::string&)> valueToInt;
std::function<bool(const std::string&)> valueToBool;
std::function<float(const std::string&)> valueToFloat;
float _sizePercentX;
float _sizePercentY;
float _positionPercentX;
float _positionPercentY;
float _width ;
float _height;
cocos2d::Color3B _color;
int _opacity;
cocos2d::Vec2 _position;
bool _isAdaptScreen;
cocos2d::Vec2 _originalAnchorPoint;
};
//property const define
extern const char* P_IgnoreSize;
extern const char* P_SizeType;
extern const char* P_PositionType;
extern const char* P_SizePercentX;
extern const char* P_SizePercentY;
extern const char* P_PositionPercentX;
extern const char* P_PositionPercentY;
extern const char* P_AdaptScreen;
extern const char* P_Width;
extern const char* P_Height;
extern const char* P_Tag;
extern const char* P_ActionTag;
extern const char* P_TouchAble;
extern const char* P_Name;
extern const char* P_X;
extern const char* P_Y;
extern const char* P_ScaleX;
extern const char* P_ScaleY;
extern const char* P_Rotation;
extern const char* P_Visbile;
extern const char* P_ZOrder;
extern const char* P_LayoutParameter;
extern const char* P_Type;
extern const char* P_Gravity;
extern const char* P_RelativeName;
extern const char* P_RelativeToName;
extern const char* P_Align;
extern const char* P_MarginLeft;
extern const char* P_MarginRight;
extern const char* P_MarginTop;
extern const char* P_MarginDown;
extern const char* P_Opacity;
extern const char* P_ColorR;
extern const char* P_ColorG;
extern const char* P_ColorB;
extern const char* P_FlipX;
extern const char* P_FlipY;
extern const char* P_AnchorPointX;
extern const char* P_AnchorPointY;
extern const char* P_ResourceType;
extern const char* P_Path;
#define CC_BASIC_PROPERTY_BINARY_READER \
if (key == P_IgnoreSize) { \
widget->ignoreContentAdaptWithSize(valueToBool(value)); \
}else if(key == P_SizeType){ \
widget->setSizeType((Widget::SizeType)valueToInt(value)); \
}else if(key == P_PositionType){ \
widget->setPositionType((Widget::PositionType)valueToInt(value)); \
}else if(key == P_SizePercentX){ \
_sizePercentX = valueToFloat(value); \
}else if(key == P_SizePercentY){ \
_sizePercentY = valueToFloat(value); \
}else if(key == P_PositionPercentX){ \
_positionPercentX = valueToFloat(value); \
}else if(key == P_PositionPercentY){ \
_positionPercentY = valueToFloat(value); \
} \
else if (key == P_Width){ \
_width = valueToFloat(value); \
}else if(key == P_Height){ \
_height = valueToFloat(value); \
}else if(key == P_Tag){ \
widget->setTag(valueToInt(value)); \
}else if(key == P_ActionTag){ \
widget->setActionTag(valueToInt(value)); \
}else if(key == P_TouchAble){ \
widget->setTouchEnabled(valueToBool(value)); \
}else if(key == P_Name){ \
std::string widgetName = value.empty() ? "default" : value; \
widget->setName(widgetName); \
}else if(key == P_X){ \
_position.x = valueToFloat(value); \
}else if(key == P_Y){ \
_position.y = valueToFloat(value); \
}else if(key == P_ScaleX){ \
widget->setScaleX(valueToFloat(value)); \
}else if(key == P_ScaleY){ \
widget->setScaleY(valueToFloat(value)); \
}else if(key == P_Rotation){ \
widget->setRotation(valueToFloat(value)); \
}else if(key == P_Visbile){ \
widget->setVisible(valueToBool(value)); \
}else if(key == P_ZOrder){ \
widget->setZOrder(valueToInt(value)); \
}else if(key == P_LayoutParameter){ \
stExpCocoNode *layoutCocosNode = stChildArray[i].GetChildArray(); \
ui::LinearLayoutParameter *linearParameter = ui::LinearLayoutParameter::create(); \
ui::RelativeLayoutParameter *relativeParameter = ui::RelativeLayoutParameter::create(); \
ui::Margin mg; \
int paramType = -1; \
for (int j = 0; j < stChildArray[i].GetChildNum(); ++j) { \
std::string innerKey = layoutCocosNode[j].GetName(cocoLoader); \
std::string innerValue = layoutCocosNode[j].GetValue(); \
if (innerKey == P_Type) { \
paramType = valueToInt(innerValue); \
}else if(innerKey == P_Gravity){ \
linearParameter->setGravity((cocos2d::ui::LinearLayoutParameter::LinearGravity)valueToInt(innerValue)); \
}else if(innerKey == P_RelativeName){ \
relativeParameter->setRelativeName(innerValue); \
}else if(innerKey == P_RelativeToName){ \
relativeParameter->setRelativeToWidgetName(innerValue); \
}else if(innerKey == P_Align){ \
relativeParameter->setAlign((cocos2d::ui::RelativeLayoutParameter::RelativeAlign)valueToInt(innerValue)); \
}else if(innerKey == P_MarginLeft){ \
mg.left = valueToFloat(innerValue); \
}else if(innerKey == P_MarginTop){ \
mg.top = valueToFloat(innerValue); \
}else if(innerKey == P_MarginRight){ \
mg.right = valueToFloat(innerValue); \
}else if(innerKey == P_MarginDown){ \
mg.bottom = valueToFloat(innerValue); \
} \
} \
linearParameter->setMargin(mg); \
relativeParameter->setMargin(mg); \
switch (paramType) { \
case 1: \
widget->setLayoutParameter(linearParameter); \
break; \
case 2: \
widget->setLayoutParameter(relativeParameter); \
default: \
break;\
}\
}
#define CC_COLOR_PROPERTY_BINARY_READER \
else if (key == P_Opacity) { \
_opacity = valueToInt(value); \
}else if(key == P_ColorR){ \
_color.r = valueToInt(value); \
}else if(key == P_ColorG){ \
_color.g = valueToInt(value); \
}else if(key == P_ColorB) \
{\
_color.b = valueToInt(value);\
}else if(key == P_FlipX){\
widget->setFlippedX(valueToBool(value));\
}else if(key == P_FlipY){\
widget->setFlippedY(valueToBool(value));\
} \
else if(key == P_AnchorPointX){ \
_originalAnchorPoint.x = valueToFloat(value); \
}else if(key == P_AnchorPointY){ \
_originalAnchorPoint.y = valueToFloat(value); \
}
}
#endif /* defined(__TestCpp__WidgetReader__) */

View File

@ -28,6 +28,8 @@
#include "cocos2d.h"
#include "cocostudio/DictionaryHelper.h"
namespace cocos2d
{
namespace ui
@ -38,11 +40,15 @@ namespace cocos2d
namespace cocostudio
{
class CocoLoader;
struct stExpCocoNode;
class WidgetReaderProtocol
{
public:
virtual ~WidgetReaderProtocol() {};
virtual void setPropsFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options) = 0;
virtual void setPropsFromBinary(cocos2d::ui::Widget* widget, CocoLoader* cocoLoader, stExpCocoNode* pCocoNode) = 0;
};
}

View File

@ -46,6 +46,7 @@
<ClCompile Include="..\CCTransformHelp.cpp" />
<ClCompile Include="..\CCTween.cpp" />
<ClCompile Include="..\CCUtilMath.cpp" />
<ClCompile Include="..\CocoLoader.cpp" />
<ClCompile Include="..\DictionaryHelper.cpp" />
<ClCompile Include="..\TriggerBase.cpp" />
<ClCompile Include="..\TriggerMng.cpp" />
@ -113,6 +114,8 @@
<ClInclude Include="..\CCTransformHelp.h" />
<ClInclude Include="..\CCTween.h" />
<ClInclude Include="..\CCUtilMath.h" />
<ClInclude Include="..\CocoLoader.h" />
<ClInclude Include="..\CocoStudio.h" />
<ClInclude Include="..\DictionaryHelper.h" />
<ClInclude Include="..\TriggerBase.h" />
<ClInclude Include="..\TriggerMng.h" />

View File

@ -231,6 +231,9 @@
<ClCompile Include="..\WidgetReader\PageViewReader\PageViewReader.cpp">
<Filter>reader\WidgetReader\PageViewReader</Filter>
</ClCompile>
<ClCompile Include="..\CocoLoader.cpp">
<Filter>json</Filter>
</ClCompile>
<ClCompile Include="..\ActionTimeline\CCNodeReader.cpp">
<Filter>TimelineAction</Filter>
</ClCompile>
@ -428,6 +431,12 @@
<ClInclude Include="..\WidgetReader\PageViewReader\PageViewReader.h">
<Filter>reader\WidgetReader\PageViewReader</Filter>
</ClInclude>
<ClInclude Include="..\CocoLoader.h">
<Filter>json</Filter>
</ClInclude>
<ClInclude Include="..\CocoStudio.h">
<Filter>json</Filter>
</ClInclude>
<ClInclude Include="..\ActionTimeline\CCNodeReader.h">
<Filter>TimelineAction</Filter>
</ClInclude>

View File

@ -198,6 +198,7 @@
<ClCompile Include="..\CCTransformHelp.cpp" />
<ClCompile Include="..\CCTween.cpp" />
<ClCompile Include="..\CCUtilMath.cpp" />
<ClCompile Include="..\CocoLoader.cpp" />
<ClCompile Include="..\DictionaryHelper.cpp" />
<ClCompile Include="..\TriggerBase.cpp" />
<ClCompile Include="..\TriggerMng.cpp" />
@ -271,6 +272,7 @@
<ClInclude Include="..\CCTransformHelp.h" />
<ClInclude Include="..\CCTween.h" />
<ClInclude Include="..\CCUtilMath.h" />
<ClInclude Include="..\CocoLoader.h" />
<ClInclude Include="..\DictionaryHelper.h" />
<ClInclude Include="..\ObjectFactory.h" />
<ClInclude Include="..\TriggerBase.h" />

View File

@ -247,6 +247,9 @@
<ClCompile Include="..\ActionTimeline\CCTimeLine.cpp">
<Filter>TimelineAction</Filter>
</ClCompile>
<ClCompile Include="..\CocoLoader.cpp">
<Filter>json</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\CCComAttribute.h">
@ -451,5 +454,8 @@
<ClInclude Include="..\ActionTimeline\CCTimelineMacro.h">
<Filter>TimelineAction</Filter>
</ClInclude>
<ClInclude Include="..\CocoLoader.h">
<Filter>json</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -66,6 +66,8 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../external/lua/tolua \
$(LOCAL_PATH)/../../editor-support/cocosbuilder \
$(LOCAL_PATH)/../../editor-support/cocostudio \
$(LOCAL_PATH)/../../ui \
$(LOCAL_PATH)/../../2d \
$(LOCAL_PATH)/../../3d \
$(LOCAL_PATH)/auto \
$(LOCAL_PATH)/manual \
$(LOCAL_PATH)/manual/platform/android \

View File

@ -33,6 +33,8 @@ include_directories(
../../editor-support/cocostudio
../../editor-support/spine
../../ui
../../2d
../../3d
../../../external/lua/lua
../../../external/lua/tolua
../../../external/xxtea

View File

@ -22,6 +22,14 @@
-- @param #char char
-- @return ActionObject#ActionObject ret (return value: ccs.ActionObject)
--------------------------------
-- @function [parent=#ActionManagerEx] initWithBinary
-- @param self
-- @param #char char
-- @param #cc.Ref ref
-- @param #ccs.CocoLoader cocoloader
-- @param #ccs.stExpCocoNode stexpcoconode
--------------------------------
-- @function [parent=#ActionManagerEx] releaseActions
-- @param self

View File

@ -60,6 +60,13 @@
-- @param self
-- @return bool#bool ret (return value: bool)
--------------------------------
-- @function [parent=#ActionObject] initWithBinary
-- @param self
-- @param #ccs.CocoLoader cocoloader
-- @param #ccs.stExpCocoNode stexpcoconode
-- @param #cc.Ref ref
--------------------------------
-- @function [parent=#ActionObject] addActionNode
-- @param self

View File

@ -0,0 +1,57 @@
--------------------------------
-- @module Animate3D
-- @extend ActionInterval
--------------------------------
-- @function [parent=#Animate3D] setPlayBack
-- @param self
-- @param #bool bool
--------------------------------
-- @function [parent=#Animate3D] setSpeed
-- @param self
-- @param #float float
--------------------------------
-- @function [parent=#Animate3D] getPlayBack
-- @param self
-- @return bool#bool ret (return value: bool)
--------------------------------
-- @function [parent=#Animate3D] getSpeed
-- @param self
-- @return float#float ret (return value: float)
--------------------------------
-- @function [parent=#Animate3D] create
-- @param self
-- @param #cc.Animation3D animation3d
-- @return Animate3D#Animate3D ret (return value: cc.Animate3D)
--------------------------------
-- @function [parent=#Animate3D] startWithTarget
-- @param self
-- @param #cc.Node node
--------------------------------
-- @function [parent=#Animate3D] step
-- @param self
-- @param #float float
--------------------------------
-- @function [parent=#Animate3D] clone
-- @param self
-- @return Animate3D#Animate3D ret (return value: cc.Animate3D)
--------------------------------
-- @function [parent=#Animate3D] reverse
-- @param self
-- @return Animate3D#Animate3D ret (return value: cc.Animate3D)
--------------------------------
-- @function [parent=#Animate3D] update
-- @param self
-- @param #float float
return nil

View File

@ -0,0 +1,18 @@
--------------------------------
-- @module Animation3D
-- @extend Ref
--------------------------------
-- @function [parent=#Animation3D] getDuration
-- @param self
-- @return float#float ret (return value: float)
--------------------------------
-- @function [parent=#Animation3D] getOrCreate
-- @param self
-- @param #string str
-- @param #string str
-- @return Animation3D#Animation3D ret (return value: cc.Animation3D)
return nil

View File

@ -19,6 +19,12 @@
-- @param self
-- @return string#string ret (return value: string)
--------------------------------
-- @function [parent=#GUIReader] widgetFromBinaryFile
-- @param self
-- @param #char char
-- @return Widget#Widget ret (return value: ccui.Widget)
--------------------------------
-- @function [parent=#GUIReader] getVersionInteger
-- @param self

View File

@ -29,9 +29,9 @@
-- @return Node#Node ret (return value: cc.Node)
--------------------------------
-- @function [parent=#Widget] getSize
-- @function [parent=#Widget] getSizePercent
-- @param self
-- @return size_table#size_table ret (return value: size_table)
-- @return vec2_table#vec2_table ret (return value: vec2_table)
--------------------------------
-- @function [parent=#Widget] setPositionPercent
@ -203,11 +203,6 @@
-- @param self
-- @param #size_table size
--------------------------------
-- @function [parent=#Widget] getSizePercent
-- @param self
-- @return vec2_table#vec2_table ret (return value: vec2_table)
--------------------------------
-- @function [parent=#Widget] getTouchMovePosition
-- @param self
@ -260,11 +255,6 @@
-- @param self
-- @param #ccui.Widget::SizeType sizetype
--------------------------------
-- @function [parent=#Widget] setSize
-- @param self
-- @param #size_table size
--------------------------------
-- @function [parent=#Widget] setBright
-- @param self
@ -295,6 +285,11 @@
-- @param self
-- @param #vec2_table vec2
--------------------------------
-- @function [parent=#Widget] setContentSize
-- @param self
-- @param #size_table size
--------------------------------
-- @function [parent=#Widget] Widget
-- @param self

View File

@ -1221,4 +1221,14 @@
-- @field [parent=#cc] ProtectedNode#ProtectedNode ProtectedNode preloaded module
--------------------------------------------------------
-- the cc Animation3D
-- @field [parent=#cc] Animation3D#Animation3D Animation3D preloaded module
--------------------------------------------------------
-- the cc Animate3D
-- @field [parent=#cc] Animate3D#Animate3D Animate3D preloaded module
return nil

View File

@ -2,6 +2,8 @@
#include "cocos2d.h"
#include "SimpleAudioEngine.h"
#include "CCProtectedNode.h"
#include "CCAnimation3D.h"
#include "CCAnimate3D.h"
#include "tolua_fix.h"
#include "LuaBasicConversions.h"
@ -63993,6 +63995,353 @@ int lua_register_cocos2dx_ProtectedNode(lua_State* tolua_S)
g_typeCast["ProtectedNode"] = "cc.ProtectedNode";
return 1;
}
int lua_cocos2dx_Animation3D_getDuration(lua_State* tolua_S)
{
int argc = 0;
cocos2d::Animation3D* 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.Animation3D",0,&tolua_err)) goto tolua_lerror;
#endif
cobj = (cocos2d::Animation3D*)tolua_tousertype(tolua_S,1,0);
#if COCOS2D_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_Animation3D_getDuration'", nullptr);
return 0;
}
#endif
argc = lua_gettop(tolua_S)-1;
if (argc == 0)
{
if(!ok)
return 0;
double ret = cobj->getDuration();
tolua_pushnumber(tolua_S,(lua_Number)ret);
return 1;
}
CCLOG("%s has wrong number of arguments: %d, was expecting %d \n", "getDuration",argc, 0);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_Animation3D_getDuration'.",&tolua_err);
#endif
return 0;
}
int lua_cocos2dx_Animation3D_getOrCreate(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.Animation3D",0,&tolua_err)) goto tolua_lerror;
#endif
argc = lua_gettop(tolua_S) - 1;
if (argc == 1)
{
std::string arg0;
ok &= luaval_to_std_string(tolua_S, 2,&arg0);
if(!ok)
return 0;
cocos2d::Animation3D* ret = cocos2d::Animation3D::getOrCreate(arg0);
object_to_luaval<cocos2d::Animation3D>(tolua_S, "cc.Animation3D",(cocos2d::Animation3D*)ret);
return 1;
}
if (argc == 2)
{
std::string arg0;
std::string arg1;
ok &= luaval_to_std_string(tolua_S, 2,&arg0);
ok &= luaval_to_std_string(tolua_S, 3,&arg1);
if(!ok)
return 0;
cocos2d::Animation3D* ret = cocos2d::Animation3D::getOrCreate(arg0, arg1);
object_to_luaval<cocos2d::Animation3D>(tolua_S, "cc.Animation3D",(cocos2d::Animation3D*)ret);
return 1;
}
CCLOG("%s has wrong number of arguments: %d, was expecting %d\n ", "getOrCreate",argc, 1);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_Animation3D_getOrCreate'.",&tolua_err);
#endif
return 0;
}
static int lua_cocos2dx_Animation3D_finalize(lua_State* tolua_S)
{
printf("luabindings: finalizing LUA object (Animation3D)");
return 0;
}
int lua_register_cocos2dx_Animation3D(lua_State* tolua_S)
{
tolua_usertype(tolua_S,"cc.Animation3D");
tolua_cclass(tolua_S,"Animation3D","cc.Animation3D","cc.Ref",nullptr);
tolua_beginmodule(tolua_S,"Animation3D");
tolua_function(tolua_S,"getDuration",lua_cocos2dx_Animation3D_getDuration);
tolua_function(tolua_S,"getOrCreate", lua_cocos2dx_Animation3D_getOrCreate);
tolua_endmodule(tolua_S);
std::string typeName = typeid(cocos2d::Animation3D).name();
g_luaType[typeName] = "cc.Animation3D";
g_typeCast["Animation3D"] = "cc.Animation3D";
return 1;
}
int lua_cocos2dx_Animate3D_setPlayBack(lua_State* tolua_S)
{
int argc = 0;
cocos2d::Animate3D* 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.Animate3D",0,&tolua_err)) goto tolua_lerror;
#endif
cobj = (cocos2d::Animate3D*)tolua_tousertype(tolua_S,1,0);
#if COCOS2D_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_Animate3D_setPlayBack'", nullptr);
return 0;
}
#endif
argc = lua_gettop(tolua_S)-1;
if (argc == 1)
{
bool arg0;
ok &= luaval_to_boolean(tolua_S, 2,&arg0);
if(!ok)
return 0;
cobj->setPlayBack(arg0);
return 0;
}
CCLOG("%s has wrong number of arguments: %d, was expecting %d \n", "setPlayBack",argc, 1);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_Animate3D_setPlayBack'.",&tolua_err);
#endif
return 0;
}
int lua_cocos2dx_Animate3D_setSpeed(lua_State* tolua_S)
{
int argc = 0;
cocos2d::Animate3D* 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.Animate3D",0,&tolua_err)) goto tolua_lerror;
#endif
cobj = (cocos2d::Animate3D*)tolua_tousertype(tolua_S,1,0);
#if COCOS2D_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_Animate3D_setSpeed'", nullptr);
return 0;
}
#endif
argc = lua_gettop(tolua_S)-1;
if (argc == 1)
{
double arg0;
ok &= luaval_to_number(tolua_S, 2,&arg0);
if(!ok)
return 0;
cobj->setSpeed(arg0);
return 0;
}
CCLOG("%s has wrong number of arguments: %d, was expecting %d \n", "setSpeed",argc, 1);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_Animate3D_setSpeed'.",&tolua_err);
#endif
return 0;
}
int lua_cocos2dx_Animate3D_getPlayBack(lua_State* tolua_S)
{
int argc = 0;
cocos2d::Animate3D* 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.Animate3D",0,&tolua_err)) goto tolua_lerror;
#endif
cobj = (cocos2d::Animate3D*)tolua_tousertype(tolua_S,1,0);
#if COCOS2D_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_Animate3D_getPlayBack'", nullptr);
return 0;
}
#endif
argc = lua_gettop(tolua_S)-1;
if (argc == 0)
{
if(!ok)
return 0;
bool ret = cobj->getPlayBack();
tolua_pushboolean(tolua_S,(bool)ret);
return 1;
}
CCLOG("%s has wrong number of arguments: %d, was expecting %d \n", "getPlayBack",argc, 0);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_Animate3D_getPlayBack'.",&tolua_err);
#endif
return 0;
}
int lua_cocos2dx_Animate3D_getSpeed(lua_State* tolua_S)
{
int argc = 0;
cocos2d::Animate3D* 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.Animate3D",0,&tolua_err)) goto tolua_lerror;
#endif
cobj = (cocos2d::Animate3D*)tolua_tousertype(tolua_S,1,0);
#if COCOS2D_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_Animate3D_getSpeed'", nullptr);
return 0;
}
#endif
argc = lua_gettop(tolua_S)-1;
if (argc == 0)
{
if(!ok)
return 0;
double ret = cobj->getSpeed();
tolua_pushnumber(tolua_S,(lua_Number)ret);
return 1;
}
CCLOG("%s has wrong number of arguments: %d, was expecting %d \n", "getSpeed",argc, 0);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_Animate3D_getSpeed'.",&tolua_err);
#endif
return 0;
}
int lua_cocos2dx_Animate3D_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,"cc.Animate3D",0,&tolua_err)) goto tolua_lerror;
#endif
argc = lua_gettop(tolua_S) - 1;
if (argc == 1)
{
cocos2d::Animation3D* arg0;
ok &= luaval_to_object<cocos2d::Animation3D>(tolua_S, 2, "cc.Animation3D",&arg0);
if(!ok)
return 0;
cocos2d::Animate3D* ret = cocos2d::Animate3D::create(arg0);
object_to_luaval<cocos2d::Animate3D>(tolua_S, "cc.Animate3D",(cocos2d::Animate3D*)ret);
return 1;
}
CCLOG("%s has wrong number of arguments: %d, was expecting %d\n ", "create",argc, 1);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_Animate3D_create'.",&tolua_err);
#endif
return 0;
}
static int lua_cocos2dx_Animate3D_finalize(lua_State* tolua_S)
{
printf("luabindings: finalizing LUA object (Animate3D)");
return 0;
}
int lua_register_cocos2dx_Animate3D(lua_State* tolua_S)
{
tolua_usertype(tolua_S,"cc.Animate3D");
tolua_cclass(tolua_S,"Animate3D","cc.Animate3D","cc.ActionInterval",nullptr);
tolua_beginmodule(tolua_S,"Animate3D");
tolua_function(tolua_S,"setPlayBack",lua_cocos2dx_Animate3D_setPlayBack);
tolua_function(tolua_S,"setSpeed",lua_cocos2dx_Animate3D_setSpeed);
tolua_function(tolua_S,"getPlayBack",lua_cocos2dx_Animate3D_getPlayBack);
tolua_function(tolua_S,"getSpeed",lua_cocos2dx_Animate3D_getSpeed);
tolua_function(tolua_S,"create", lua_cocos2dx_Animate3D_create);
tolua_endmodule(tolua_S);
std::string typeName = typeid(cocos2d::Animate3D).name();
g_luaType[typeName] = "cc.Animate3D";
g_typeCast["Animate3D"] = "cc.Animate3D";
return 1;
}
TOLUA_API int register_all_cocos2dx(lua_State* tolua_S)
{
tolua_open(tolua_S);
@ -64180,6 +64529,7 @@ TOLUA_API int register_all_cocos2dx(lua_State* tolua_S)
lua_register_cocos2dx_Spawn(tolua_S);
lua_register_cocos2dx_EaseQuarticActionInOut(tolua_S);
lua_register_cocos2dx_GLProgramState(tolua_S);
lua_register_cocos2dx_Animation3D(tolua_S);
lua_register_cocos2dx_PageTurn3D(tolua_S);
lua_register_cocos2dx_TransitionSlideInL(tolua_S);
lua_register_cocos2dx_TransitionSlideInT(tolua_S);
@ -64218,6 +64568,7 @@ TOLUA_API int register_all_cocos2dx(lua_State* tolua_S)
lua_register_cocos2dx_ParticleRain(tolua_S);
lua_register_cocos2dx_Waves(tolua_S);
lua_register_cocos2dx_EaseOut(tolua_S);
lua_register_cocos2dx_Animate3D(tolua_S);
lua_register_cocos2dx_MenuItemFont(tolua_S);
lua_register_cocos2dx_TransitionFadeUp(tolua_S);
lua_register_cocos2dx_EaseSineOut(tolua_S);

View File

@ -1542,6 +1542,15 @@ int register_all_cocos2dx(lua_State* tolua_S);

View File

@ -500,6 +500,58 @@ int lua_cocos2dx_studio_ActionObject_getLoop(lua_State* tolua_S)
return 0;
}
int lua_cocos2dx_studio_ActionObject_initWithBinary(lua_State* tolua_S)
{
int argc = 0;
cocostudio::ActionObject* 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.ActionObject",0,&tolua_err)) goto tolua_lerror;
#endif
cobj = (cocostudio::ActionObject*)tolua_tousertype(tolua_S,1,0);
#if COCOS2D_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_studio_ActionObject_initWithBinary'", nullptr);
return 0;
}
#endif
argc = lua_gettop(tolua_S)-1;
if (argc == 3)
{
cocostudio::CocoLoader* arg0;
cocostudio::stExpCocoNode* arg1;
cocos2d::Ref* arg2;
ok &= luaval_to_object<cocostudio::CocoLoader>(tolua_S, 2, "ccs.CocoLoader",&arg0);
#pragma warning NO CONVERSION TO NATIVE FOR stExpCocoNode*;
ok &= luaval_to_object<cocos2d::Ref>(tolua_S, 4, "cc.Ref",&arg2);
if(!ok)
return 0;
cobj->initWithBinary(arg0, arg1, arg2);
return 0;
}
CCLOG("%s has wrong number of arguments: %d, was expecting %d \n", "initWithBinary",argc, 3);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_studio_ActionObject_initWithBinary'.",&tolua_err);
#endif
return 0;
}
int lua_cocos2dx_studio_ActionObject_addActionNode(lua_State* tolua_S)
{
int argc = 0;
@ -830,6 +882,7 @@ int lua_register_cocos2dx_studio_ActionObject(lua_State* tolua_S)
tolua_function(tolua_S,"getCurrentTime",lua_cocos2dx_studio_ActionObject_getCurrentTime);
tolua_function(tolua_S,"removeActionNode",lua_cocos2dx_studio_ActionObject_removeActionNode);
tolua_function(tolua_S,"getLoop",lua_cocos2dx_studio_ActionObject_getLoop);
tolua_function(tolua_S,"initWithBinary",lua_cocos2dx_studio_ActionObject_initWithBinary);
tolua_function(tolua_S,"addActionNode",lua_cocos2dx_studio_ActionObject_addActionNode);
tolua_function(tolua_S,"getUnitTime",lua_cocos2dx_studio_ActionObject_getUnitTime);
tolua_function(tolua_S,"isPlaying",lua_cocos2dx_studio_ActionObject_isPlaying);
@ -960,6 +1013,61 @@ int lua_cocos2dx_studio_ActionManagerEx_getActionByName(lua_State* tolua_S)
return 0;
}
int lua_cocos2dx_studio_ActionManagerEx_initWithBinary(lua_State* tolua_S)
{
int argc = 0;
cocostudio::ActionManagerEx* 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.ActionManagerEx",0,&tolua_err)) goto tolua_lerror;
#endif
cobj = (cocostudio::ActionManagerEx*)tolua_tousertype(tolua_S,1,0);
#if COCOS2D_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_studio_ActionManagerEx_initWithBinary'", nullptr);
return 0;
}
#endif
argc = lua_gettop(tolua_S)-1;
if (argc == 4)
{
const char* arg0;
cocos2d::Ref* arg1;
cocostudio::CocoLoader* arg2;
cocostudio::stExpCocoNode* arg3;
std::string arg0_tmp; ok &= luaval_to_std_string(tolua_S, 2, &arg0_tmp); arg0 = arg0_tmp.c_str();
ok &= luaval_to_object<cocos2d::Ref>(tolua_S, 3, "cc.Ref",&arg1);
ok &= luaval_to_object<cocostudio::CocoLoader>(tolua_S, 4, "ccs.CocoLoader",&arg2);
#pragma warning NO CONVERSION TO NATIVE FOR stExpCocoNode*;
if(!ok)
return 0;
cobj->initWithBinary(arg0, arg1, arg2, arg3);
return 0;
}
CCLOG("%s has wrong number of arguments: %d, was expecting %d \n", "initWithBinary",argc, 4);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_studio_ActionManagerEx_initWithBinary'.",&tolua_err);
#endif
return 0;
}
int lua_cocos2dx_studio_ActionManagerEx_releaseActions(lua_State* tolua_S)
{
int argc = 0;
@ -1078,6 +1186,7 @@ int lua_register_cocos2dx_studio_ActionManagerEx(lua_State* tolua_S)
tolua_beginmodule(tolua_S,"ActionManagerEx");
tolua_function(tolua_S,"playActionByName",lua_cocos2dx_studio_ActionManagerEx_playActionByName);
tolua_function(tolua_S,"getActionByName",lua_cocos2dx_studio_ActionManagerEx_getActionByName);
tolua_function(tolua_S,"initWithBinary",lua_cocos2dx_studio_ActionManagerEx_initWithBinary);
tolua_function(tolua_S,"releaseActions",lua_cocos2dx_studio_ActionManagerEx_releaseActions);
tolua_function(tolua_S,"destroyInstance", lua_cocos2dx_studio_ActionManagerEx_destroyInstance);
tolua_function(tolua_S,"getInstance", lua_cocos2dx_studio_ActionManagerEx_getInstance);
@ -12155,6 +12264,53 @@ int lua_cocos2dx_studio_GUIReader_getFilePath(lua_State* tolua_S)
return 0;
}
int lua_cocos2dx_studio_GUIReader_widgetFromBinaryFile(lua_State* tolua_S)
{
int argc = 0;
cocostudio::GUIReader* 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.GUIReader",0,&tolua_err)) goto tolua_lerror;
#endif
cobj = (cocostudio::GUIReader*)tolua_tousertype(tolua_S,1,0);
#if COCOS2D_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_studio_GUIReader_widgetFromBinaryFile'", nullptr);
return 0;
}
#endif
argc = lua_gettop(tolua_S)-1;
if (argc == 1)
{
const char* arg0;
std::string arg0_tmp; ok &= luaval_to_std_string(tolua_S, 2, &arg0_tmp); arg0 = arg0_tmp.c_str();
if(!ok)
return 0;
cocos2d::ui::Widget* ret = cobj->widgetFromBinaryFile(arg0);
object_to_luaval<cocos2d::ui::Widget>(tolua_S, "ccui.Widget",(cocos2d::ui::Widget*)ret);
return 1;
}
CCLOG("%s has wrong number of arguments: %d, was expecting %d \n", "widgetFromBinaryFile",argc, 1);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_studio_GUIReader_widgetFromBinaryFile'.",&tolua_err);
#endif
return 0;
}
int lua_cocos2dx_studio_GUIReader_getVersionInteger(lua_State* tolua_S)
{
int argc = 0;
@ -12278,6 +12434,7 @@ int lua_register_cocos2dx_studio_GUIReader(lua_State* tolua_S)
tolua_function(tolua_S,"setFilePath",lua_cocos2dx_studio_GUIReader_setFilePath);
tolua_function(tolua_S,"widgetFromJsonFile",lua_cocos2dx_studio_GUIReader_widgetFromJsonFile);
tolua_function(tolua_S,"getFilePath",lua_cocos2dx_studio_GUIReader_getFilePath);
tolua_function(tolua_S,"widgetFromBinaryFile",lua_cocos2dx_studio_GUIReader_widgetFromBinaryFile);
tolua_function(tolua_S,"getVersionInteger",lua_cocos2dx_studio_GUIReader_getVersionInteger);
tolua_function(tolua_S,"destroyInstance", lua_cocos2dx_studio_GUIReader_destroyInstance);
tolua_function(tolua_S,"getInstance", lua_cocos2dx_studio_GUIReader_getInstance);

View File

@ -305,6 +305,9 @@ int register_all_cocos2dx_studio(lua_State* tolua_S);

View File

@ -1039,7 +1039,7 @@ int lua_cocos2dx_ui_Widget_getVirtualRenderer(lua_State* tolua_S)
return 0;
}
int lua_cocos2dx_ui_Widget_getSize(lua_State* tolua_S)
int lua_cocos2dx_ui_Widget_getSizePercent(lua_State* tolua_S)
{
int argc = 0;
cocos2d::ui::Widget* cobj = nullptr;
@ -1059,7 +1059,7 @@ int lua_cocos2dx_ui_Widget_getSize(lua_State* tolua_S)
#if COCOS2D_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_ui_Widget_getSize'", nullptr);
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_ui_Widget_getSizePercent'", nullptr);
return 0;
}
#endif
@ -1069,16 +1069,16 @@ int lua_cocos2dx_ui_Widget_getSize(lua_State* tolua_S)
{
if(!ok)
return 0;
const cocos2d::Size& ret = cobj->getSize();
size_to_luaval(tolua_S, ret);
const cocos2d::Vec2& ret = cobj->getSizePercent();
vec2_to_luaval(tolua_S, ret);
return 1;
}
CCLOG("%s has wrong number of arguments: %d, was expecting %d \n", "getSize",argc, 0);
CCLOG("%s has wrong number of arguments: %d, was expecting %d \n", "getSizePercent",argc, 0);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_ui_Widget_getSize'.",&tolua_err);
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_ui_Widget_getSizePercent'.",&tolua_err);
#endif
return 0;
@ -2567,50 +2567,6 @@ int lua_cocos2dx_ui_Widget_updateSizeAndPosition(lua_State* tolua_S)
return 0;
}
int lua_cocos2dx_ui_Widget_getSizePercent(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_getSizePercent'", nullptr);
return 0;
}
#endif
argc = lua_gettop(tolua_S)-1;
if (argc == 0)
{
if(!ok)
return 0;
const cocos2d::Vec2& ret = cobj->getSizePercent();
vec2_to_luaval(tolua_S, ret);
return 1;
}
CCLOG("%s has wrong number of arguments: %d, was expecting %d \n", "getSizePercent",argc, 0);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_ui_Widget_getSizePercent'.",&tolua_err);
#endif
return 0;
}
int lua_cocos2dx_ui_Widget_getTouchMovePosition(lua_State* tolua_S)
{
int argc = 0;
@ -3065,52 +3021,6 @@ int lua_cocos2dx_ui_Widget_setSizeType(lua_State* tolua_S)
return 0;
}
int lua_cocos2dx_ui_Widget_setSize(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_setSize'", nullptr);
return 0;
}
#endif
argc = lua_gettop(tolua_S)-1;
if (argc == 1)
{
cocos2d::Size arg0;
ok &= luaval_to_size(tolua_S, 2, &arg0);
if(!ok)
return 0;
cobj->setSize(arg0);
return 0;
}
CCLOG("%s has wrong number of arguments: %d, was expecting %d \n", "setSize",argc, 1);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_ui_Widget_setSize'.",&tolua_err);
#endif
return 0;
}
int lua_cocos2dx_ui_Widget_setBright(lua_State* tolua_S)
{
int argc = 0;
@ -3316,7 +3226,7 @@ int lua_register_cocos2dx_ui_Widget(lua_State* tolua_S)
tolua_function(tolua_S,"setFlippedY",lua_cocos2dx_ui_Widget_setFlippedY);
tolua_function(tolua_S,"setFlippedX",lua_cocos2dx_ui_Widget_setFlippedX);
tolua_function(tolua_S,"getVirtualRenderer",lua_cocos2dx_ui_Widget_getVirtualRenderer);
tolua_function(tolua_S,"getSize",lua_cocos2dx_ui_Widget_getSize);
tolua_function(tolua_S,"getSizePercent",lua_cocos2dx_ui_Widget_getSizePercent);
tolua_function(tolua_S,"setPositionPercent",lua_cocos2dx_ui_Widget_setPositionPercent);
tolua_function(tolua_S,"getLayoutSize",lua_cocos2dx_ui_Widget_getLayoutSize);
tolua_function(tolua_S,"setHighlighted",lua_cocos2dx_ui_Widget_setHighlighted);
@ -3350,7 +3260,6 @@ int lua_register_cocos2dx_ui_Widget(lua_State* tolua_S)
tolua_function(tolua_S,"getCurrentFocusedWidget",lua_cocos2dx_ui_Widget_getCurrentFocusedWidget);
tolua_function(tolua_S,"requestFocus",lua_cocos2dx_ui_Widget_requestFocus);
tolua_function(tolua_S,"updateSizeAndPosition",lua_cocos2dx_ui_Widget_updateSizeAndPosition);
tolua_function(tolua_S,"getSizePercent",lua_cocos2dx_ui_Widget_getSizePercent);
tolua_function(tolua_S,"getTouchMovePosition",lua_cocos2dx_ui_Widget_getTouchMovePosition);
tolua_function(tolua_S,"getSizeType",lua_cocos2dx_ui_Widget_getSizeType);
tolua_function(tolua_S,"addTouchEventListener",lua_cocos2dx_ui_Widget_addTouchEventListener);
@ -3361,7 +3270,6 @@ int lua_register_cocos2dx_ui_Widget(lua_State* tolua_S)
tolua_function(tolua_S,"isFlippedY",lua_cocos2dx_ui_Widget_isFlippedY);
tolua_function(tolua_S,"isClippingParentContainsPoint",lua_cocos2dx_ui_Widget_isClippingParentContainsPoint);
tolua_function(tolua_S,"setSizeType",lua_cocos2dx_ui_Widget_setSizeType);
tolua_function(tolua_S,"setSize",lua_cocos2dx_ui_Widget_setSize);
tolua_function(tolua_S,"setBright",lua_cocos2dx_ui_Widget_setBright);
tolua_function(tolua_S,"isFocusEnabled",lua_cocos2dx_ui_Widget_isFocusEnabled);
tolua_function(tolua_S,"enableDpadNavigation", lua_cocos2dx_ui_Widget_enableDpadNavigation);

View File

@ -384,8 +384,6 @@ int register_all_cocos2dx_ui(lua_State* tolua_S);

View File

@ -445,9 +445,10 @@ static int lua_cocos2dx_ListView_addEventListener(lua_State* L)
#endif
LUA_FUNCTION handler = ( toluafix_ref_function(L,2,0));
self->addEventListener([=](cocos2d::Ref* ref,ListView::EventType eventType){
auto listViewCallback = [=](cocos2d::Ref* ref,ListView::EventType eventType){
handleUIEvent(handler, ref, (int)eventType);
});
};
self->addEventListener((ui::ListView::ccListViewCallback)listViewCallback);
return 0;
}
@ -463,6 +464,57 @@ tolua_lerror:
#endif
}
static int lua_cocos2dx_ListView_addScrollViewEventListener(lua_State* L)
{
if (nullptr == L)
return 0;
int argc = 0;
ListView* self = nullptr;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
if (!tolua_isusertype(L,1,"ccui.ListView",0,&tolua_err)) goto tolua_lerror;
#endif
self = static_cast<ListView*>(tolua_tousertype(L,1,0));
#if COCOS2D_DEBUG >= 1
if (nullptr == self) {
tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_ListView_addScrollViewEventListener'\n", NULL);
return 0;
}
#endif
argc = lua_gettop(L) - 1;
if (1 == argc)
{
#if COCOS2D_DEBUG >= 1
if (!toluafix_isfunction(L,2,"LUA_FUNCTION",0,&tolua_err))
{
goto tolua_lerror;
}
#endif
LUA_FUNCTION handler = ( toluafix_ref_function(L,2,0));
auto scrollViewCallback = [=](cocos2d::Ref* ref, ui::ScrollView::EventType eventType){
handleUIEvent(handler, ref, (int)eventType);
};
self->addEventListener((ui::ScrollView::ccScrollViewCallback)scrollViewCallback);
return 0;
}
CCLOG("'addScrollViewEventListener' function of ListView has wrong number of arguments: %d, was expecting %d\n", argc, 1);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(L,"#ferror in function 'addScrollViewEventListener'.",&tolua_err);
return 0;
#endif
}
static void extendListView(lua_State* L)
{
lua_pushstring(L, "ccui.ListView");
@ -470,6 +522,7 @@ static void extendListView(lua_State* L)
if (lua_istable(L,-1))
{
tolua_function(L, "addEventListener", lua_cocos2dx_ListView_addEventListener);
tolua_function(L, "addScrollViewEventListener", lua_cocos2dx_ListView_addScrollViewEventListener);
}
lua_pop(L, 1);
}

View File

@ -889,7 +889,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
SKIP_INSTALL = YES;
USER_HEADER_SEARCH_PATHS = "$(SRCROOT)/../../../.. $(SRCROOT)/../../.. $(SRCROOT)/../../../base $(SRCROOT)/../../../2d $(SRCROOT)/../../../deprecated $(SRCROOT)/../../../physics $(SRCROOT)/../../../math/kazmath $(SRCROOT)/../../../2d/platform $(SRCROOT)/../../../audio/include $(SRCROOT)/../../../editor-support $(SRCROOT)/../../../editor-support/spine $(SRCROOT)/../../../editor-support/cocostudio $(SRCROOT)/../../../editor-support/cocosbuilder $(SRCROOT)/../../../ui $(SRCROOT)/../../../storage $(SRCROOT)/../../../../extensions $(SRCROOT)/../../../../external $(SRCROOT)/../../../../external/chipmunk/include/chipmunk $(SRCROOT)/../../../../external/lua $(SRCROOT)/../../../../external/lua/luajit/include $(SRCROOT)/../../../../external/lua/tolua";
USER_HEADER_SEARCH_PATHS = "$(SRCROOT)/../../../.. $(SRCROOT)/../../.. $(SRCROOT)/../../../base $(SRCROOT)/../../../3d $(SRCROOT)/../../../2d $(SRCROOT)/../../../deprecated $(SRCROOT)/../../../physics $(SRCROOT)/../../../math/kazmath $(SRCROOT)/../../../2d/platform $(SRCROOT)/../../../audio/include $(SRCROOT)/../../../editor-support $(SRCROOT)/../../../editor-support/spine $(SRCROOT)/../../../editor-support/cocostudio $(SRCROOT)/../../../editor-support/cocosbuilder $(SRCROOT)/../../../ui $(SRCROOT)/../../../storage $(SRCROOT)/../../../../extensions $(SRCROOT)/../../../../external $(SRCROOT)/../../../../external/chipmunk/include/chipmunk $(SRCROOT)/../../../../external/lua $(SRCROOT)/../../../../external/lua/luajit/include $(SRCROOT)/../../../../external/lua/tolua";
};
name = Debug;
};
@ -922,7 +922,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
SKIP_INSTALL = YES;
USER_HEADER_SEARCH_PATHS = "$(SRCROOT)/../../../.. $(SRCROOT)/../../.. $(SRCROOT)/../../../base $(SRCROOT)/../../../2d $(SRCROOT)/../../../deprecated $(SRCROOT)/../../../physics $(SRCROOT)/../../../math/kazmath $(SRCROOT)/../../../2d/platform $(SRCROOT)/../../../audio/include $(SRCROOT)/../../../editor-support $(SRCROOT)/../../../editor-support/spine $(SRCROOT)/../../../editor-support/cocostudio $(SRCROOT)/../../../editor-support/cocosbuilder $(SRCROOT)/../../../ui $(SRCROOT)/../../../storage $(SRCROOT)/../../../../extensions $(SRCROOT)/../../../../external $(SRCROOT)/../../../../external/chipmunk/include/chipmunk $(SRCROOT)/../../../../external/lua $(SRCROOT)/../../../../external/lua/luajit/include $(SRCROOT)/../../../../external/lua/tolua";
USER_HEADER_SEARCH_PATHS = "$(SRCROOT)/../../../.. $(SRCROOT)/../../.. $(SRCROOT)/../../../base $(SRCROOT)/../../../3d $(SRCROOT)/../../../2d $(SRCROOT)/../../../deprecated $(SRCROOT)/../../../physics $(SRCROOT)/../../../math/kazmath $(SRCROOT)/../../../2d/platform $(SRCROOT)/../../../audio/include $(SRCROOT)/../../../editor-support $(SRCROOT)/../../../editor-support/spine $(SRCROOT)/../../../editor-support/cocostudio $(SRCROOT)/../../../editor-support/cocosbuilder $(SRCROOT)/../../../ui $(SRCROOT)/../../../storage $(SRCROOT)/../../../../extensions $(SRCROOT)/../../../../external $(SRCROOT)/../../../../external/chipmunk/include/chipmunk $(SRCROOT)/../../../../external/lua $(SRCROOT)/../../../../external/lua/luajit/include $(SRCROOT)/../../../../external/lua/tolua";
VALIDATE_PRODUCT = YES;
};
name = Release;

View File

@ -188,7 +188,7 @@
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>$(EngineRoot);$(EngineRoot)cocos;$(EngineRoot)cocos\ui;$(EngineRoot)cocos\editor-support;$(EngineRoot)cocos\editor-support\cocostudio;$(EngineRoot)cocos\editor-support\cocosbuilder;$(EngineRoot)cocos\editor-support\spine;$(EngineRoot)cocos\audio\include;$(EngineRoot)extensions;$(EngineRoot)extensions\network;$(EngineRoot)external;$(EngineRoot)external\libwebsockets\win32\include;$(EngineRoot)external\lua\tolua;$(EngineRoot)external\lua\luajit\include;$(EngineRoot)external\lua;$(EngineRoot)cocos\scripting\lua-bindings\auto;$(EngineRoot)cocos\scripting\lua-bindings\manual;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(EngineRoot);$(EngineRoot)cocos;$(EngineRoot)cocos\ui;$(EngineRoot)cocos\editor-support;$(EngineRoot)cocos\editor-support\cocostudio;$(EngineRoot)cocos\editor-support\cocosbuilder;$(EngineRoot)cocos\editor-support\spine;$(EngineRoot)cocos\audio\include;$(EngineRoot)extensions;$(EngineRoot)extensions\network;$(EngineRoot)external;$(EngineRoot)external\libwebsockets\win32\include;$(EngineRoot)external\lua\tolua;$(EngineRoot)external\lua\luajit\include;$(EngineRoot)external\lua;$(EngineRoot)cocos\scripting\lua-bindings\auto;$(EngineRoot)cocos\scripting\lua-bindings\manual;$(EngineRoot)cocos\2d;$(EngineRoot)cocos\3d;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;COCOS2D_DEBUG=1;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>false</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
@ -220,7 +220,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\..\..\external\lua\luajit\prebuilt\win32\*.*" "$
<ClCompile>
<Optimization>MinSpace</Optimization>
<IntrinsicFunctions>true</IntrinsicFunctions>
<AdditionalIncludeDirectories>$(EngineRoot);$(EngineRoot)cocos;$(EngineRoot)cocos\ui;$(EngineRoot)cocos\editor-support;$(EngineRoot)cocos\editor-support\cocostudio;$(EngineRoot)cocos\editor-support\cocosbuilder;$(EngineRoot)cocos\editor-support\spine;$(EngineRoot)cocos\audio\include;$(EngineRoot)extensions;$(EngineRoot)extensions\network;$(EngineRoot)external;$(EngineRoot)external\libwebsockets\win32\include;$(EngineRoot)external\lua\tolua;$(EngineRoot)external\lua\luajit\include;$(EngineRoot)external\lua;$(EngineRoot)cocos\scripting\lua-bindings\auto;$(EngineRoot)cocos\scripting\lua-bindings\manual;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(EngineRoot);$(EngineRoot)cocos;$(EngineRoot)cocos\ui;$(EngineRoot)cocos\editor-support;$(EngineRoot)cocos\editor-support\cocostudio;$(EngineRoot)cocos\editor-support\cocosbuilder;$(EngineRoot)cocos\editor-support\spine;$(EngineRoot)cocos\audio\include;$(EngineRoot)extensions;$(EngineRoot)extensions\network;$(EngineRoot)external;$(EngineRoot)external\libwebsockets\win32\include;$(EngineRoot)external\lua\tolua;$(EngineRoot)external\lua\luajit\include;$(EngineRoot)external\lua;$(EngineRoot)cocos\scripting\lua-bindings\auto;$(EngineRoot)cocos\scripting\lua-bindings\manual;$(EngineRoot)cocos\2d;$(EngineRoot)cocos\3d;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;LIBLUA_EXPORTS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>

View File

@ -56,9 +56,9 @@ _capInsetsDisabled(Rect::ZERO),
_normalTexType(TextureResType::LOCAL),
_pressedTexType(TextureResType::LOCAL),
_disabledTexType(TextureResType::LOCAL),
_normalTextureSize(_size),
_pressedTextureSize(_size),
_disabledTextureSize(_size),
_normalTextureSize(_contentSize),
_pressedTextureSize(_contentSize),
_disabledTextureSize(_contentSize),
_pressedActionEnabled(false),
_titleColor(Color3B::WHITE),
_normalTextureScaleXInSize(1.0f),
@ -615,7 +615,7 @@ void Button::normalTextureScaleChangedWithSize()
{
if (_scale9Enabled)
{
static_cast<extension::Scale9Sprite*>(_buttonNormalRenderer)->setPreferredSize(_size);
static_cast<extension::Scale9Sprite*>(_buttonNormalRenderer)->setPreferredSize(_contentSize);
_normalTextureScaleXInSize = _normalTextureScaleYInSize = 1.0f;
}
else
@ -626,8 +626,8 @@ void Button::normalTextureScaleChangedWithSize()
_buttonNormalRenderer->setScale(1.0f);
return;
}
float scaleX = _size.width / textureSize.width;
float scaleY = _size.height / textureSize.height;
float scaleX = _contentSize.width / textureSize.width;
float scaleY = _contentSize.height / textureSize.height;
_buttonNormalRenderer->setScaleX(scaleX);
_buttonNormalRenderer->setScaleY(scaleY);
_normalTextureScaleXInSize = scaleX;
@ -651,7 +651,7 @@ void Button::pressedTextureScaleChangedWithSize()
{
if (_scale9Enabled)
{
static_cast<extension::Scale9Sprite*>(_buttonClickedRenderer)->setPreferredSize(_size);
static_cast<extension::Scale9Sprite*>(_buttonClickedRenderer)->setPreferredSize(_contentSize);
_pressedTextureScaleXInSize = _pressedTextureScaleYInSize = 1.0f;
}
else
@ -662,8 +662,8 @@ void Button::pressedTextureScaleChangedWithSize()
_buttonClickedRenderer->setScale(1.0f);
return;
}
float scaleX = _size.width / _pressedTextureSize.width;
float scaleY = _size.height / _pressedTextureSize.height;
float scaleX = _contentSize.width / _pressedTextureSize.width;
float scaleY = _contentSize.height / _pressedTextureSize.height;
_buttonClickedRenderer->setScaleX(scaleX);
_buttonClickedRenderer->setScaleY(scaleY);
_pressedTextureScaleXInSize = scaleX;
@ -686,7 +686,7 @@ void Button::disabledTextureScaleChangedWithSize()
{
if (_scale9Enabled)
{
static_cast<extension::Scale9Sprite*>(_buttonDisableRenderer)->setPreferredSize(_size);
static_cast<extension::Scale9Sprite*>(_buttonDisableRenderer)->setPreferredSize(_contentSize);
}
else
{
@ -696,8 +696,8 @@ void Button::disabledTextureScaleChangedWithSize()
_buttonDisableRenderer->setScale(1.0f);
return;
}
float scaleX = _size.width / _disabledTextureSize.width;
float scaleY = _size.height / _disabledTextureSize.height;
float scaleX = _contentSize.width / _disabledTextureSize.width;
float scaleY = _contentSize.height / _disabledTextureSize.height;
_buttonDisableRenderer->setScaleX(scaleX);
_buttonDisableRenderer->setScaleY(scaleY);
}

View File

@ -71,7 +71,6 @@ public:
const std::string& disableImage = "",
TextureResType texType = TextureResType::LOCAL);
/**
* Load textures for button.
*

View File

@ -473,8 +473,8 @@ void CheckBox::backGroundTextureScaleChangedWithSize()
_backGroundBoxRenderer->setScale(1.0f);
return;
}
float scaleX = _size.width / textureSize.width;
float scaleY = _size.height / textureSize.height;
float scaleX = _contentSize.width / textureSize.width;
float scaleY = _contentSize.height / textureSize.height;
_backGroundBoxRenderer->setScaleX(scaleX);
_backGroundBoxRenderer->setScaleY(scaleY);
}
@ -495,8 +495,8 @@ void CheckBox::backGroundSelectedTextureScaleChangedWithSize()
_backGroundSelectedBoxRenderer->setScale(1.0f);
return;
}
float scaleX = _size.width / textureSize.width;
float scaleY = _size.height / textureSize.height;
float scaleX = _contentSize.width / textureSize.width;
float scaleY = _contentSize.height / textureSize.height;
_backGroundSelectedBoxRenderer->setScaleX(scaleX);
_backGroundSelectedBoxRenderer->setScaleY(scaleY);
}
@ -517,8 +517,8 @@ void CheckBox::frontCrossTextureScaleChangedWithSize()
_frontCrossRenderer->setScale(1.0f);
return;
}
float scaleX = _size.width / textureSize.width;
float scaleY = _size.height / textureSize.height;
float scaleX = _contentSize.width / textureSize.width;
float scaleY = _contentSize.height / textureSize.height;
_frontCrossRenderer->setScaleX(scaleX);
_frontCrossRenderer->setScaleY(scaleY);
}
@ -539,8 +539,8 @@ void CheckBox::backGroundDisabledTextureScaleChangedWithSize()
_backGroundBoxDisabledRenderer->setScale(1.0f);
return;
}
float scaleX = _size.width / textureSize.width;
float scaleY = _size.height / textureSize.height;
float scaleX = _contentSize.width / textureSize.width;
float scaleY = _contentSize.height / textureSize.height;
_backGroundBoxDisabledRenderer->setScaleX(scaleX);
_backGroundBoxDisabledRenderer->setScaleY(scaleY);
}
@ -561,8 +561,8 @@ void CheckBox::frontCrossDisabledTextureScaleChangedWithSize()
_frontCrossDisabledRenderer->setScale(1.0f);
return;
}
float scaleX = _size.width / textureSize.width;
float scaleY = _size.height / textureSize.height;
float scaleX = _contentSize.width / textureSize.width;
float scaleY = _contentSize.height / textureSize.height;
_frontCrossDisabledRenderer->setScaleX(scaleX);
_frontCrossDisabledRenderer->setScaleY(scaleY);
}

View File

@ -74,7 +74,7 @@ bool HBox::initWithSize(const Size& size)
{
if (init())
{
setSize(size);
setContentSize(size);
return true;
}
return false;

View File

@ -45,7 +45,7 @@ _capInsets(Rect::ZERO),
_imageRenderer(nullptr),
_textureFile(""),
_imageTexType(TextureResType::LOCAL),
_imageTextureSize(_size),
_imageTextureSize(_contentSize),
_imageRendererAdaptDirty(true)
{
@ -300,7 +300,7 @@ void ImageView::imageTextureScaleChangedWithSize()
{
if (_scale9Enabled)
{
static_cast<extension::Scale9Sprite*>(_imageRenderer)->setPreferredSize(_size);
static_cast<extension::Scale9Sprite*>(_imageRenderer)->setPreferredSize(_contentSize);
}
else
{
@ -310,8 +310,8 @@ void ImageView::imageTextureScaleChangedWithSize()
_imageRenderer->setScale(1.0f);
return;
}
float scaleX = _size.width / textureSize.width;
float scaleY = _size.height / textureSize.height;
float scaleX = _contentSize.width / textureSize.width;
float scaleY = _contentSize.height / textureSize.height;
_imageRenderer->setScaleX(scaleX);
_imageRenderer->setScaleY(scaleY);
}

View File

@ -145,7 +145,7 @@ bool Layout::init()
if (Widget::init())
{
ignoreContentAdaptWithSize(false);
setSize(Size::ZERO);
setContentSize(Size::ZERO);
setAnchorPoint(Vec2::ZERO);
onPassFocusToChild = CC_CALLBACK_2(Layout::findNearestChildWidgetIndex, this);
return true;
@ -429,7 +429,7 @@ void Layout::setClippingEnabled(bool able)
_clippingStencil->onEnter();
}
_clippingStencil->retain();
setStencilClippingSize(_size);
setStencilClippingSize(_contentSize);
}
else
{
@ -469,9 +469,9 @@ void Layout::setStencilClippingSize(const Size &size)
{
Vec2 rect[4];
rect[0] = Vec2::ZERO;
rect[1] = Vec2(_size.width, 0);
rect[2] = Vec2(_size.width, _size.height);
rect[3] = Vec2(0, _size.height);
rect[1] = Vec2(_contentSize.width, 0);
rect[2] = Vec2(_contentSize.width, _contentSize.height);
rect[3] = Vec2(0, _contentSize.height);
Color4F green(0, 1, 0, 1);
_clippingStencil->clear();
_clippingStencil->drawPolygon(rect, 4, green, 0, green);
@ -484,8 +484,8 @@ const Rect& Layout::getClippingRect()
{
Vec2 worldPos = convertToWorldSpace(Vec2::ZERO);
AffineTransform t = getNodeToWorldAffineTransform();
float scissorWidth = _size.width*t.a;
float scissorHeight = _size.height*t.d;
float scissorWidth = _contentSize.width*t.a;
float scissorHeight = _contentSize.height*t.d;
Rect parentClippingRect;
Layout* parent = this;
@ -560,24 +560,24 @@ const Rect& Layout::getClippingRect()
void Layout::onSizeChanged()
{
Widget::onSizeChanged();
setStencilClippingSize(_size);
setStencilClippingSize(_contentSize);
_doLayoutDirty = true;
_clippingRectDirty = true;
if (_backGroundImage)
{
_backGroundImage->setPosition(Vec2(_size.width/2.0f, _size.height/2.0f));
_backGroundImage->setPosition(Vec2(_contentSize.width/2.0f, _contentSize.height/2.0f));
if (_backGroundScale9Enabled && _backGroundImage)
{
static_cast<extension::Scale9Sprite*>(_backGroundImage)->setPreferredSize(_size);
static_cast<extension::Scale9Sprite*>(_backGroundImage)->setPreferredSize(_contentSize);
}
}
if (_colorRender)
{
_colorRender->setContentSize(_size);
_colorRender->setContentSize(_contentSize);
}
if (_gradientRender)
{
_gradientRender->setContentSize(_size);
_gradientRender->setContentSize(_contentSize);
}
}
@ -626,7 +626,7 @@ void Layout::setBackGroundImage(const std::string& fileName,TextureResType texTy
default:
break;
}
bgiScale9->setPreferredSize(_size);
bgiScale9->setPreferredSize(_contentSize);
}
else
{
@ -643,7 +643,7 @@ void Layout::setBackGroundImage(const std::string& fileName,TextureResType texTy
}
}
_backGroundImageTextureSize = _backGroundImage->getContentSize();
_backGroundImage->setPosition(Vec2(_size.width/2.0f, _size.height/2.0f));
_backGroundImage->setPosition(Vec2(_contentSize.width/2.0f, _contentSize.height/2.0f));
updateBackGroundImageRGBA();
}
@ -701,14 +701,14 @@ void Layout::addBackGroundImage()
{
_backGroundImage = extension::Scale9Sprite::create();
addProtectedChild(_backGroundImage, BACKGROUNDIMAGE_Z, -1);
static_cast<extension::Scale9Sprite*>(_backGroundImage)->setPreferredSize(_size);
static_cast<extension::Scale9Sprite*>(_backGroundImage)->setPreferredSize(_contentSize);
}
else
{
_backGroundImage = Sprite::create();
addProtectedChild(_backGroundImage, BACKGROUNDIMAGE_Z, -1);
}
_backGroundImage->setPosition(Vec2(_size.width/2.0f, _size.height/2.0f));
_backGroundImage->setPosition(Vec2(_contentSize.width/2.0f, _contentSize.height/2.0f));
}
void Layout::removeBackGroundImage()
@ -767,14 +767,14 @@ void Layout::setBackGroundColorType(BackGroundColorType type)
break;
case BackGroundColorType::SOLID:
_colorRender = LayerColor::create();
_colorRender->setContentSize(_size);
_colorRender->setContentSize(_contentSize);
_colorRender->setOpacity(_cOpacity);
_colorRender->setColor(_cColor);
addProtectedChild(_colorRender, BCAKGROUNDCOLORRENDERER_Z, -1);
break;
case BackGroundColorType::GRADIENT:
_gradientRender = LayerGradient::create();
_gradientRender->setContentSize(_size);
_gradientRender->setContentSize(_contentSize);
_gradientRender->setOpacity(_cOpacity);
_gradientRender->setStartColor(_gStartColor);
_gradientRender->setEndColor(_gEndColor);
@ -947,7 +947,7 @@ void Layout::requestDoLayout()
Size Layout::getLayoutContentSize()const
{
return this->getSize();
return this->getContentSize();
}
const Vector<Node*>& Layout::getLayoutElements()const
@ -1068,7 +1068,7 @@ Size Layout::getLayoutAccumulatedSize()const
{
widgetCount++;
Margin m = w->getLayoutParameter()->getMargin();
layoutSize = layoutSize + w->getSize() + Size(m.right + m.left, m.top + m.bottom) * 0.5;
layoutSize = layoutSize + w->getContentSize() + Size(m.right + m.left, m.top + m.bottom) * 0.5;
}
}
}
@ -1090,7 +1090,7 @@ Vec2 Layout::getWorldCenterPoint(Widget* widget)const
{
Layout *layout = dynamic_cast<Layout*>(widget);
//FIXEDME: we don't need to calculate the content size of layout anymore
Size widgetSize = layout ? layout->getLayoutAccumulatedSize() : widget->getSize();
Size widgetSize = layout ? layout->getLayoutAccumulatedSize() : widget->getContentSize();
// CCLOG("contnet size : width = %f, height = %f", widgetSize.width, widgetSize.height);
return widget->convertToWorldSpace(Vec2(widgetSize.width/2, widgetSize.height/2));
}

View File

@ -57,7 +57,7 @@ void LinearHorizontalLayoutManager::doLayout(LayoutProtocol* layout)
{
LinearLayoutParameter::LinearGravity childGravity = layoutParameter->getGravity();
Vec2 ap = child->getAnchorPoint();
Size cs = child->getSize();
Size cs = child->getContentSize();
float finalPosX = leftBoundary + (ap.x * cs.width);
float finalPosY = layoutSize.height - (1.0f - ap.y) * cs.height;
switch (childGravity)
@ -206,7 +206,7 @@ Widget* RelativeLayoutManager::getRelativeWidget(Widget* widget)
bool RelativeLayoutManager::caculateFinalPositionWithRelativeWidget(LayoutProtocol *layout)
{
Vec2 ap = _widget->getAnchorPoint();
Size cs = _widget->getSize();
Size cs = _widget->getContentSize();
_finalPositionX = 0.0f;
_finalPositionY = 0.0f;
@ -280,7 +280,7 @@ bool RelativeLayoutManager::caculateFinalPositionWithRelativeWidget(LayoutProtoc
{
return false;
}
Size rbs = relativeWidget->getSize();
Size rbs = relativeWidget->getContentSize();
float locationTop = relativeWidget->getTopBoundary();
_finalPositionY = locationTop + ap.y * cs.height;
@ -320,7 +320,7 @@ bool RelativeLayoutManager::caculateFinalPositionWithRelativeWidget(LayoutProtoc
{
return false;
}
Size rbs = relativeWidget->getSize();
Size rbs = relativeWidget->getContentSize();
float locationLeft = relativeWidget->getLeftBoundary();
_finalPositionX = locationLeft - (1.0f - ap.x) * cs.width;
@ -360,7 +360,7 @@ bool RelativeLayoutManager::caculateFinalPositionWithRelativeWidget(LayoutProtoc
{
return false;
}
Size rbs = relativeWidget->getSize();
Size rbs = relativeWidget->getContentSize();
float locationRight = relativeWidget->getRightBoundary();
_finalPositionX = locationRight + ap.x * cs.width;
@ -400,7 +400,7 @@ bool RelativeLayoutManager::caculateFinalPositionWithRelativeWidget(LayoutProtoc
{
return false;
}
Size rbs = relativeWidget->getSize();
Size rbs = relativeWidget->getContentSize();
float locationBottom = relativeWidget->getBottomBoundary();
_finalPositionY = locationBottom - (1.0f - ap.y) * cs.height;

View File

@ -96,9 +96,9 @@ void ListView::updateInnerContainerSize()
float totalHeight = (length - 1) * _itemsMargin;
for (auto& item : _items)
{
totalHeight += item->getSize().height;
totalHeight += item->getContentSize().height;
}
float finalWidth = _size.width;
float finalWidth = _contentSize.width;
float finalHeight = totalHeight;
setInnerContainerSize(Size(finalWidth, finalHeight));
break;
@ -109,10 +109,10 @@ void ListView::updateInnerContainerSize()
float totalWidth = (length - 1) * _itemsMargin;
for (auto& item : _items)
{
totalWidth += item->getSize().width;
totalWidth += item->getContentSize().width;
}
float finalWidth = totalWidth;
float finalHeight = _size.height;
float finalHeight = _contentSize.height;
setInnerContainerSize(Size(finalWidth, finalHeight));
break;
}
@ -454,6 +454,7 @@ void ListView::addEventListenerListView(Ref *target, SEL_ListViewEvent selector)
_listViewEventSelector = selector;
}
void ListView::addEventListener(const ccListViewCallback& callback)
{
_eventCallback = callback;

View File

@ -174,6 +174,7 @@ public:
CC_DEPRECATED_ATTRIBUTE void addEventListenerListView(Ref* target, SEL_ListViewEvent selector);
void addEventListener(const ccListViewCallback& callback);
using ScrollView::addEventListener;
/**
* Changes scroll direction of scrollview.

View File

@ -317,7 +317,7 @@ void LoadingBar::barRendererScaleChangedWithSize()
}
else
{
_totalLength = _size.width;
_totalLength = _contentSize.width;
if (_scale9Enabled)
{
setScale9Scale();
@ -331,8 +331,8 @@ void LoadingBar::barRendererScaleChangedWithSize()
_barRenderer->setScale(1.0f);
return;
}
float scaleX = _size.width / textureSize.width;
float scaleY = _size.height / textureSize.height;
float scaleX = _contentSize.width / textureSize.width;
float scaleY = _contentSize.height / textureSize.height;
_barRenderer->setScaleX(scaleX);
_barRenderer->setScaleY(scaleY);
}
@ -353,7 +353,7 @@ void LoadingBar::barRendererScaleChangedWithSize()
void LoadingBar::setScale9Scale()
{
float width = (float)(_percent) / 100.0f * _totalLength;
static_cast<extension::Scale9Sprite*>(_barRenderer)->setPreferredSize(Size(width, _size.height));
static_cast<extension::Scale9Sprite*>(_barRenderer)->setPreferredSize(Size(width, _contentSize.height));
}
std::string LoadingBar::getDescription() const

View File

@ -121,7 +121,7 @@ void PageView::addWidgetToPage(Widget *widget, ssize_t pageIdx, bool forceCreate
Layout* PageView::createPage()
{
Layout* newPage = Layout::create();
newPage->setSize(getSize());
newPage->setContentSize(getContentSize());
return newPage;
}
@ -212,23 +212,23 @@ ssize_t PageView::getPageCount()const
float PageView::getPositionXByIndex(ssize_t idx)const
{
return (getSize().width * (idx-_curPageIdx));
return (getContentSize().width * (idx-_curPageIdx));
}
void PageView::onSizeChanged()
{
Layout::onSizeChanged();
_rightBoundary = getSize().width;
_rightBoundary = getContentSize().width;
_doLayoutDirty = true;
}
void PageView::updateAllPagesSize()
{
Size selfSize = getSize();
Size selfSize = getContentSize();
for (auto& page : _pages)
{
page->setSize(selfSize);
page->setContentSize(selfSize);
}
}
@ -247,7 +247,7 @@ void PageView::updateAllPagesPosition()
_curPageIdx = pageCount-1;
}
float pageWidth = getSize().width;
float pageWidth = getContentSize().width;
for (int i=0; i<pageCount; i++)
{
Layout* page = _pages.at(i);
@ -467,7 +467,7 @@ void PageView::handleReleaseLogic(Touch *touch)
Vec2 curPagePos = curPage->getPosition();
ssize_t pageCount = this->getPageCount();
float curPageLocation = curPagePos.x;
float pageWidth = getSize().width;
float pageWidth = getContentSize().width;
float boundary = pageWidth/2.0f;
if (curPageLocation <= -boundary)
{

View File

@ -74,7 +74,7 @@ bool RelativeBox::initWithSize(const Size& size)
{
if (init())
{
setSize(size);
setContentSize(size);
return true;
}
return false;

View File

@ -414,7 +414,7 @@ void RichText::formarRenderers()
nextPosX += l->getContentSize().width;
}
}
_elementRenderersContainer->setContentSize(_size);
_elementRenderersContainer->setContentSize(_contentSize);
delete [] maxHeights;
}
@ -430,13 +430,13 @@ void RichText::formarRenderers()
if (_ignoreSize)
{
Size s = getVirtualRendererSize();
_size = s;
this->setContentSize(s);
}
else
{
_size = _customSize;
this->setContentSize(_customSize);
}
updateContentSizeWithTextureSize(_size);
updateContentSizeWithTextureSize(_contentSize);
_elementRenderersContainer->setPosition(_contentSize.width / 2.0f, _contentSize.height / 2.0f);
}

View File

@ -128,29 +128,29 @@ void ScrollView::initRenderer()
void ScrollView::onSizeChanged()
{
Layout::onSizeChanged();
_topBoundary = _size.height;
_rightBoundary = _size.width;
float bounceBoundaryParameterX = _size.width / 3.0f;
float bounceBoundaryParameterY = _size.height / 3.0f;
_bounceTopBoundary = _size.height - bounceBoundaryParameterY;
_topBoundary = _contentSize.height;
_rightBoundary = _contentSize.width;
float bounceBoundaryParameterX = _contentSize.width / 3.0f;
float bounceBoundaryParameterY = _contentSize.height / 3.0f;
_bounceTopBoundary = _contentSize.height - bounceBoundaryParameterY;
_bounceBottomBoundary = bounceBoundaryParameterY;
_bounceLeftBoundary = bounceBoundaryParameterX;
_bounceRightBoundary = _size.width - bounceBoundaryParameterX;
Size innerSize = _innerContainer->getSize();
_bounceRightBoundary = _contentSize.width - bounceBoundaryParameterX;
Size innerSize = _innerContainer->getContentSize();
float orginInnerSizeWidth = innerSize.width;
float orginInnerSizeHeight = innerSize.height;
float innerSizeWidth = MAX(orginInnerSizeWidth, _size.width);
float innerSizeHeight = MAX(orginInnerSizeHeight, _size.height);
_innerContainer->setSize(Size(innerSizeWidth, innerSizeHeight));
_innerContainer->setPosition(Vec2(0, _size.height - _innerContainer->getSize().height));
float innerSizeWidth = MAX(orginInnerSizeWidth, _contentSize.width);
float innerSizeHeight = MAX(orginInnerSizeHeight, _contentSize.height);
_innerContainer->setContentSize(Size(innerSizeWidth, innerSizeHeight));
_innerContainer->setPosition(Vec2(0, _contentSize.height - _innerContainer->getContentSize().height));
}
void ScrollView::setInnerContainerSize(const Size &size)
{
float innerSizeWidth = _size.width;
float innerSizeHeight = _size.height;
Size originalInnerSize = _innerContainer->getSize();
if (size.width < _size.width)
float innerSizeWidth = _contentSize.width;
float innerSizeHeight = _contentSize.height;
Size originalInnerSize = _innerContainer->getContentSize();
if (size.width < _contentSize.width)
{
CCLOG("Inner width <= scrollview width, it will be force sized!");
}
@ -158,7 +158,7 @@ void ScrollView::setInnerContainerSize(const Size &size)
{
innerSizeWidth = size.width;
}
if (size.height < _size.height)
if (size.height < _contentSize.height)
{
CCLOG("Inner height <= scrollview height, it will be force sized!");
}
@ -166,22 +166,22 @@ void ScrollView::setInnerContainerSize(const Size &size)
{
innerSizeHeight = size.height;
}
_innerContainer->setSize(Size(innerSizeWidth, innerSizeHeight));
_innerContainer->setContentSize(Size(innerSizeWidth, innerSizeHeight));
switch (_direction)
{
case Direction::VERTICAL:
{
Size newInnerSize = _innerContainer->getSize();
Size newInnerSize = _innerContainer->getContentSize();
float offset = originalInnerSize.height - newInnerSize.height;
scrollChildren(0.0f, offset);
break;
}
case Direction::HORIZONTAL:
{
if (_innerContainer->getRightBoundary() <= _size.width)
if (_innerContainer->getRightBoundary() <= _contentSize.width)
{
Size newInnerSize = _innerContainer->getSize();
Size newInnerSize = _innerContainer->getContentSize();
float offset = originalInnerSize.width - newInnerSize.width;
scrollChildren(offset, 0.0f);
}
@ -189,10 +189,10 @@ void ScrollView::setInnerContainerSize(const Size &size)
}
case Direction::BOTH:
{
Size newInnerSize = _innerContainer->getSize();
Size newInnerSize = _innerContainer->getContentSize();
float offsetY = originalInnerSize.height - newInnerSize.height;
float offsetX = 0.0f;
if (_innerContainer->getRightBoundary() <= _size.width)
if (_innerContainer->getRightBoundary() <= _contentSize.width)
{
offsetX = originalInnerSize.width - newInnerSize.width;
}
@ -204,25 +204,29 @@ void ScrollView::setInnerContainerSize(const Size &size)
}
if (_innerContainer->getLeftBoundary() > 0.0f)
{
_innerContainer->setPosition(Vec2(_innerContainer->getAnchorPoint().x * _innerContainer->getSize().width, _innerContainer->getPosition().y));
_innerContainer->setPosition(Vec2(_innerContainer->getAnchorPoint().x * _innerContainer->getContentSize().width,
_innerContainer->getPosition().y));
}
if (_innerContainer->getRightBoundary() < _size.width)
if (_innerContainer->getRightBoundary() < _contentSize.width)
{
_innerContainer->setPosition(Vec2(_size.width - ((1.0f - _innerContainer->getAnchorPoint().x) * _innerContainer->getSize().width), _innerContainer->getPosition().y));
_innerContainer->setPosition(Vec2(_contentSize.width - ((1.0f - _innerContainer->getAnchorPoint().x) * _innerContainer->getContentSize().width),
_innerContainer->getPosition().y));
}
if (_innerContainer->getPosition().y > 0.0f)
{
_innerContainer->setPosition(Vec2(_innerContainer->getPosition().x, _innerContainer->getAnchorPoint().y * _innerContainer->getSize().height));
_innerContainer->setPosition(Vec2(_innerContainer->getPosition().x,
_innerContainer->getAnchorPoint().y * _innerContainer->getContentSize().height));
}
if (_innerContainer->getTopBoundary() < _size.height)
if (_innerContainer->getTopBoundary() < _contentSize.height)
{
_innerContainer->setPosition(Vec2(_innerContainer->getPosition().x, _size.height - (1.0f - _innerContainer->getAnchorPoint().y) * _innerContainer->getSize().height));
_innerContainer->setPosition(Vec2(_innerContainer->getPosition().x,
_contentSize.height - (1.0f - _innerContainer->getAnchorPoint().y) * _innerContainer->getContentSize().height));
}
}
const Size& ScrollView::getInnerContainerSize() const
{
return _innerContainer->getSize();
return _innerContainer->getContentSize();
}
void ScrollView::addChild(Node *child)
@ -359,14 +363,14 @@ bool ScrollView::checkNeedBounce()
{
if (_topBounceNeeded && _leftBounceNeeded)
{
Vec2 scrollVector = Vec2(0.0f, _size.height) - Vec2(_innerContainer->getLeftBoundary(), _innerContainer->getTopBoundary());
Vec2 scrollVector = Vec2(0.0f, _contentSize.height) - Vec2(_innerContainer->getLeftBoundary(), _innerContainer->getTopBoundary());
float orSpeed = scrollVector.getLength()/(0.2f);
_bounceDir = scrollVector.getNormalized();
startBounceChildren(orSpeed);
}
else if (_topBounceNeeded && _rightBounceNeeded)
{
Vec2 scrollVector = Vec2(_size.width, _size.height) - Vec2(_innerContainer->getRightBoundary(), _innerContainer->getTopBoundary());
Vec2 scrollVector = Vec2(_contentSize.width, _contentSize.height) - Vec2(_innerContainer->getRightBoundary(), _innerContainer->getTopBoundary());
float orSpeed = scrollVector.getLength()/(0.2f);
_bounceDir = scrollVector.getNormalized();
startBounceChildren(orSpeed);
@ -380,14 +384,14 @@ bool ScrollView::checkNeedBounce()
}
else if (_bottomBounceNeeded && _rightBounceNeeded)
{
Vec2 scrollVector = Vec2(_size.width, 0.0f) - Vec2(_innerContainer->getRightBoundary(), _innerContainer->getBottomBoundary());
Vec2 scrollVector = Vec2(_contentSize.width, 0.0f) - Vec2(_innerContainer->getRightBoundary(), _innerContainer->getBottomBoundary());
float orSpeed = scrollVector.getLength()/(0.2f);
_bounceDir = scrollVector.getNormalized();
startBounceChildren(orSpeed);
}
else if (_topBounceNeeded)
{
Vec2 scrollVector = Vec2(0.0f, _size.height) - Vec2(0.0f, _innerContainer->getTopBoundary());
Vec2 scrollVector = Vec2(0.0f, _contentSize.height) - Vec2(0.0f, _innerContainer->getTopBoundary());
float orSpeed = scrollVector.getLength()/(0.2f);
_bounceDir = scrollVector.getNormalized();
startBounceChildren(orSpeed);
@ -408,7 +412,7 @@ bool ScrollView::checkNeedBounce()
}
else if (_rightBounceNeeded)
{
Vec2 scrollVector = Vec2(_size.width, 0.0f) - Vec2(_innerContainer->getRightBoundary(), 0.0f);
Vec2 scrollVector = Vec2(_contentSize.width, 0.0f) - Vec2(_innerContainer->getRightBoundary(), 0.0f);
float orSpeed = scrollVector.getLength()/(0.2f);
_bounceDir = scrollVector.getNormalized();
startBounceChildren(orSpeed);
@ -518,23 +522,23 @@ void ScrollView::jumpToDestination(const Vec2 &des)
case Direction::VERTICAL:
if (des.y <= 0)
{
finalOffsetY = MAX(des.y, _size.height - _innerContainer->getSize().height);
finalOffsetY = MAX(des.y, _contentSize.height - _innerContainer->getContentSize().height);
}
break;
case Direction::HORIZONTAL:
if (des.x <= 0)
{
finalOffsetX = MAX(des.x, _size.width - _innerContainer->getSize().width);
finalOffsetX = MAX(des.x, _contentSize.width - _innerContainer->getContentSize().width);
}
break;
case Direction::BOTH:
if (des.y <= 0)
{
finalOffsetY = MAX(des.y, _size.height - _innerContainer->getSize().height);
finalOffsetY = MAX(des.y, _contentSize.height - _innerContainer->getContentSize().height);
}
if (des.x <= 0)
{
finalOffsetX = MAX(des.x, _size.width - _innerContainer->getSize().width);
finalOffsetX = MAX(des.x, _contentSize.width - _innerContainer->getContentSize().width);
}
break;
default:
@ -1217,7 +1221,8 @@ void ScrollView::scrollToBottom(float time, bool attenuated)
void ScrollView::scrollToTop(float time, bool attenuated)
{
startAutoScrollChildrenWithDestination(Vec2(_innerContainer->getPosition().x, _size.height - _innerContainer->getSize().height), time, attenuated);
startAutoScrollChildrenWithDestination(Vec2(_innerContainer->getPosition().x,
_contentSize.height - _innerContainer->getContentSize().height), time, attenuated);
}
void ScrollView::scrollToLeft(float time, bool attenuated)
@ -1227,7 +1232,8 @@ void ScrollView::scrollToLeft(float time, bool attenuated)
void ScrollView::scrollToRight(float time, bool attenuated)
{
startAutoScrollChildrenWithDestination(Vec2(_size.width - _innerContainer->getSize().width, _innerContainer->getPosition().y), time, attenuated);
startAutoScrollChildrenWithDestination(Vec2(_contentSize.width - _innerContainer->getContentSize().width,
_innerContainer->getPosition().y), time, attenuated);
}
void ScrollView::scrollToTopLeft(float time, bool attenuated)
@ -1237,7 +1243,7 @@ void ScrollView::scrollToTopLeft(float time, bool attenuated)
CCLOG("Scroll diretion is not both!");
return;
}
startAutoScrollChildrenWithDestination(Vec2(0.0f, _size.height - _innerContainer->getSize().height), time, attenuated);
startAutoScrollChildrenWithDestination(Vec2(0.0f, _contentSize.height - _innerContainer->getContentSize().height), time, attenuated);
}
void ScrollView::scrollToTopRight(float time, bool attenuated)
@ -1247,7 +1253,8 @@ void ScrollView::scrollToTopRight(float time, bool attenuated)
CCLOG("Scroll diretion is not both!");
return;
}
startAutoScrollChildrenWithDestination(Vec2(_size.width - _innerContainer->getSize().width, _size.height - _innerContainer->getSize().height), time, attenuated);
startAutoScrollChildrenWithDestination(Vec2(_contentSize.width - _innerContainer->getContentSize().width,
_contentSize.height - _innerContainer->getContentSize().height), time, attenuated);
}
void ScrollView::scrollToBottomLeft(float time, bool attenuated)
@ -1267,19 +1274,19 @@ void ScrollView::scrollToBottomRight(float time, bool attenuated)
CCLOG("Scroll diretion is not both!");
return;
}
startAutoScrollChildrenWithDestination(Vec2(_size.width - _innerContainer->getSize().width, 0.0f), time, attenuated);
startAutoScrollChildrenWithDestination(Vec2(_contentSize.width - _innerContainer->getContentSize().width, 0.0f), time, attenuated);
}
void ScrollView::scrollToPercentVertical(float percent, float time, bool attenuated)
{
float minY = _size.height - _innerContainer->getSize().height;
float minY = _contentSize.height - _innerContainer->getContentSize().height;
float h = - minY;
startAutoScrollChildrenWithDestination(Vec2(_innerContainer->getPosition().x, minY + percent * h / 100.0f), time, attenuated);
}
void ScrollView::scrollToPercentHorizontal(float percent, float time, bool attenuated)
{
float w = _innerContainer->getSize().width - _size.width;
float w = _innerContainer->getContentSize().width - _contentSize.width;
startAutoScrollChildrenWithDestination(Vec2(-(percent * w / 100.0f), _innerContainer->getPosition().y), time, attenuated);
}
@ -1289,9 +1296,9 @@ void ScrollView::scrollToPercentBothDirection(const Vec2& percent, float time, b
{
return;
}
float minY = _size.height - _innerContainer->getSize().height;
float minY = _contentSize.height - _innerContainer->getContentSize().height;
float h = - minY;
float w = _innerContainer->getSize().width - _size.width;
float w = _innerContainer->getContentSize().width - _contentSize.width;
startAutoScrollChildrenWithDestination(Vec2(-(percent.x * w / 100.0f), minY + percent.y * h / 100.0f), time, attenuated);
}
@ -1302,7 +1309,8 @@ void ScrollView::jumpToBottom()
void ScrollView::jumpToTop()
{
jumpToDestination(Vec2(_innerContainer->getPosition().x, _size.height - _innerContainer->getSize().height));
jumpToDestination(Vec2(_innerContainer->getPosition().x,
_contentSize.height - _innerContainer->getContentSize().height));
}
void ScrollView::jumpToLeft()
@ -1312,7 +1320,7 @@ void ScrollView::jumpToLeft()
void ScrollView::jumpToRight()
{
jumpToDestination(Vec2(_size.width - _innerContainer->getSize().width, _innerContainer->getPosition().y));
jumpToDestination(Vec2(_contentSize.width - _innerContainer->getContentSize().width, _innerContainer->getPosition().y));
}
void ScrollView::jumpToTopLeft()
@ -1322,7 +1330,7 @@ void ScrollView::jumpToTopLeft()
CCLOG("Scroll diretion is not both!");
return;
}
jumpToDestination(Vec2(0.0f, _size.height - _innerContainer->getSize().height));
jumpToDestination(Vec2(0.0f, _contentSize.height - _innerContainer->getContentSize().height));
}
void ScrollView::jumpToTopRight()
@ -1332,7 +1340,8 @@ void ScrollView::jumpToTopRight()
CCLOG("Scroll diretion is not both!");
return;
}
jumpToDestination(Vec2(_size.width - _innerContainer->getSize().width, _size.height - _innerContainer->getSize().height));
jumpToDestination(Vec2(_contentSize.width - _innerContainer->getContentSize().width,
_contentSize.height - _innerContainer->getContentSize().height));
}
void ScrollView::jumpToBottomLeft()
@ -1352,19 +1361,19 @@ void ScrollView::jumpToBottomRight()
CCLOG("Scroll diretion is not both!");
return;
}
jumpToDestination(Vec2(_size.width - _innerContainer->getSize().width, 0.0f));
jumpToDestination(Vec2(_contentSize.width - _innerContainer->getContentSize().width, 0.0f));
}
void ScrollView::jumpToPercentVertical(float percent)
{
float minY = _size.height - _innerContainer->getSize().height;
float minY = _contentSize.height - _innerContainer->getContentSize().height;
float h = - minY;
jumpToDestination(Vec2(_innerContainer->getPosition().x, minY + percent * h / 100.0f));
}
void ScrollView::jumpToPercentHorizontal(float percent)
{
float w = _innerContainer->getSize().width - _size.width;
float w = _innerContainer->getContentSize().width - _contentSize.width;
jumpToDestination(Vec2(-(percent * w / 100.0f), _innerContainer->getPosition().y));
}
@ -1374,9 +1383,9 @@ void ScrollView::jumpToPercentBothDirection(const Vec2& percent)
{
return;
}
float minY = _size.height - _innerContainer->getSize().height;
float minY = _contentSize.height - _innerContainer->getContentSize().height;
float h = - minY;
float w = _innerContainer->getSize().width - _size.width;
float w = _innerContainer->getContentSize().width - _contentSize.width;
jumpToDestination(Vec2(-(percent.x * w / 100.0f), minY + percent.y * h / 100.0f));
}

View File

@ -251,7 +251,7 @@ public:
* Add call back function called scrollview event triggered
*/
CC_DEPRECATED_ATTRIBUTE void addEventListenerScrollView(Ref* target, SEL_ScrollViewEvent selector);
void addEventListener(const ccScrollViewCallback& callback);
virtual void addEventListener(const ccScrollViewCallback& callback);
//all of these functions are related to innerContainer.
virtual void addChild(Node * child) override;

View File

@ -500,14 +500,14 @@ void Slider::barRendererScaleChangedWithSize()
{
_barRenderer->setScale(1.0f);
_barLength = _size.width;
_barLength = _contentSize.width;
}
else
{
_barLength = _size.width;
_barLength = _contentSize.width;
if (_scale9Enabled)
{
static_cast<extension::Scale9Sprite*>(_barRenderer)->setPreferredSize(_size);
static_cast<extension::Scale9Sprite*>(_barRenderer)->setPreferredSize(_contentSize);
}
else
{
@ -517,8 +517,8 @@ void Slider::barRendererScaleChangedWithSize()
_barRenderer->setScale(1.0f);
return;
}
float bscaleX = _size.width / btextureSize.width;
float bscaleY = _size.height / btextureSize.height;
float bscaleX = _contentSize.width / btextureSize.width;
float bscaleY = _contentSize.height / btextureSize.height;
_barRenderer->setScaleX(bscaleX);
_barRenderer->setScaleY(bscaleY);
}
@ -534,8 +534,8 @@ void Slider::progressBarRendererScaleChangedWithSize()
if (!_scale9Enabled)
{
Size ptextureSize = _progressBarTextureSize;
float pscaleX = _size.width / ptextureSize.width;
float pscaleY = _size.height / ptextureSize.height;
float pscaleX = _contentSize.width / ptextureSize.width;
float pscaleY = _contentSize.height / ptextureSize.height;
_progressBarRenderer->setScaleX(pscaleX);
_progressBarRenderer->setScaleY(pscaleY);
}
@ -544,7 +544,7 @@ void Slider::progressBarRendererScaleChangedWithSize()
{
if (_scale9Enabled)
{
static_cast<extension::Scale9Sprite*>(_progressBarRenderer)->setPreferredSize(_size);
static_cast<extension::Scale9Sprite*>(_progressBarRenderer)->setPreferredSize(_contentSize);
_progressBarTextureSize = _progressBarRenderer->getContentSize();
}
else
@ -555,8 +555,8 @@ void Slider::progressBarRendererScaleChangedWithSize()
_progressBarRenderer->setScale(1.0f);
return;
}
float pscaleX = _size.width / ptextureSize.width;
float pscaleY = _size.height / ptextureSize.height;
float pscaleX = _contentSize.width / ptextureSize.width;
float pscaleY = _contentSize.height / ptextureSize.height;
_progressBarRenderer->setScaleX(pscaleX);
_progressBarRenderer->setScaleY(pscaleY);
}

View File

@ -302,15 +302,15 @@ void Text::labelScaleChangedWithSize()
}
else
{
_labelRenderer->setDimensions(_size.width,_size.height);
_labelRenderer->setDimensions(_contentSize.width,_contentSize.height);
Size textureSize = _labelRenderer->getContentSize();
if (textureSize.width <= 0.0f || textureSize.height <= 0.0f)
{
_labelRenderer->setScale(1.0f);
return;
}
float scaleX = _size.width / textureSize.width;
float scaleY = _size.height / textureSize.height;
float scaleX = _contentSize.width / textureSize.width;
float scaleY = _contentSize.height / textureSize.height;
_labelRenderer->setScaleX(scaleX);
_labelRenderer->setScaleY(scaleY);
_normalScaleValueX = scaleX;

View File

@ -159,8 +159,8 @@ void TextAtlas::labelAtlasScaleChangedWithSize()
_labelAtlasRenderer->setScale(1.0f);
return;
}
float scaleX = _size.width / textureSize.width;
float scaleY = _size.height / textureSize.height;
float scaleX = _contentSize.width / textureSize.width;
float scaleY = _contentSize.height / textureSize.height;
_labelAtlasRenderer->setScaleX(scaleX);
_labelAtlasRenderer->setScaleY(scaleY);
}

View File

@ -155,8 +155,8 @@ void TextBMFont::labelBMFontScaleChangedWithSize()
_labelBMFontRenderer->setScale(1.0f);
return;
}
float scaleX = _size.width / textureSize.width;
float scaleY = _size.height / textureSize.height;
float scaleX = _contentSize.width / textureSize.width;
float scaleY = _contentSize.height / textureSize.height;
_labelBMFontRenderer->setScaleX(scaleX);
_labelBMFontRenderer->setScaleY(scaleY);
}

Some files were not shown because too many files have changed in this diff Show More