mirror of https://github.com/axmolengine/axmol.git
Combine Studio change for 2d components
This commit is contained in:
parent
0682832ed7
commit
c40a2a3301
|
@ -481,4 +481,11 @@ void Camera::setBackgroundBrush(CameraBackgroundBrush* clearBrush)
|
|||
_clearBrush = clearBrush;
|
||||
}
|
||||
|
||||
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
|
||||
bool Camera::isBrushValid()
|
||||
{
|
||||
return _clearBrush != nullptr && _clearBrush->isValid();
|
||||
}
|
||||
#endif
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -58,6 +58,12 @@ enum class CameraFlag
|
|||
USER6 = 1 << 6,
|
||||
USER7 = 1 << 7,
|
||||
USER8 = 1 << 8,
|
||||
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
|
||||
SkyBox = 1 << 10,
|
||||
DEFAULTCAMERA = DEFAULT | SkyBox,
|
||||
PIXEL = 1 << 13,
|
||||
FRONT = 1 << 14,
|
||||
#endif
|
||||
};
|
||||
/**
|
||||
* Defines a camera .
|
||||
|
@ -272,6 +278,10 @@ public:
|
|||
|
||||
virtual void visit(Renderer* renderer, const Mat4 &parentTransform, uint32_t parentFlags) override;
|
||||
|
||||
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
|
||||
bool isBrushValid();
|
||||
#endif
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
Camera();
|
||||
~Camera();
|
||||
|
|
|
@ -232,6 +232,10 @@ CameraBackgroundSkyBoxBrush::CameraBackgroundSkyBoxBrush()
|
|||
, _vertexBuffer(0)
|
||||
, _indexBuffer(0)
|
||||
, _texture(nullptr)
|
||||
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
|
||||
, _actived(false)
|
||||
, _textureValid(false)
|
||||
#endif
|
||||
{
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
|
||||
_backToForegroundListener = EventListenerCustom::create(EVENT_RENDERER_RECREATED,
|
||||
|
@ -296,6 +300,11 @@ CameraBackgroundSkyBoxBrush* CameraBackgroundSkyBoxBrush::create()
|
|||
|
||||
void CameraBackgroundSkyBoxBrush::drawBackground(Camera* camera)
|
||||
{
|
||||
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
|
||||
if (!_actived)
|
||||
return;
|
||||
#endif
|
||||
|
||||
Mat4 cameraModelMat = camera->getNodeToWorldTransform();
|
||||
|
||||
Vec4 color(1.f, 1.f, 1.f, 1.f);
|
||||
|
@ -427,4 +436,25 @@ void CameraBackgroundSkyBoxBrush::setTexture(TextureCube* texture)
|
|||
_glProgramState->setUniformTexture("u_Env", _texture);
|
||||
}
|
||||
|
||||
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
|
||||
bool CameraBackgroundSkyBoxBrush::isActived()
|
||||
{
|
||||
return _actived;
|
||||
}
|
||||
void CameraBackgroundSkyBoxBrush::setActived(bool actived)
|
||||
{
|
||||
_actived = actived;
|
||||
}
|
||||
|
||||
void CameraBackgroundSkyBoxBrush::setTextureValid(bool valid)
|
||||
{
|
||||
_textureValid = valid;
|
||||
}
|
||||
|
||||
bool CameraBackgroundSkyBoxBrush::isValid()
|
||||
{
|
||||
return _actived;
|
||||
}
|
||||
#endif
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -104,6 +104,10 @@ public:
|
|||
*/
|
||||
virtual void drawBackground(Camera* camera) {}
|
||||
|
||||
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
|
||||
virtual bool isValid() { return true; }
|
||||
#endif
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS :
|
||||
CameraBackgroundBrush();
|
||||
virtual ~CameraBackgroundBrush();
|
||||
|
@ -237,6 +241,13 @@ public:
|
|||
*/
|
||||
virtual void drawBackground(Camera* camera) override;
|
||||
|
||||
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
|
||||
bool isActived();
|
||||
void setActived(bool actived);
|
||||
virtual void setTextureValid(bool valid);
|
||||
virtual bool isValid()override;
|
||||
#endif
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS :
|
||||
CameraBackgroundSkyBoxBrush();
|
||||
virtual ~CameraBackgroundSkyBoxBrush();
|
||||
|
@ -258,6 +269,12 @@ protected:
|
|||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
|
||||
EventListenerCustom* _backToForegroundListener;
|
||||
#endif
|
||||
|
||||
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
|
||||
private:
|
||||
bool _actived;
|
||||
bool _textureValid;
|
||||
#endif
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -53,10 +53,17 @@ void ClippingRectangleNode::onBeforeVisitScissor()
|
|||
|
||||
const Point pos = convertToWorldSpace(Point(_clippingRegion.origin.x, _clippingRegion.origin.y));
|
||||
GLView* glView = Director::getInstance()->getOpenGLView();
|
||||
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
|
||||
glView->setScissorInPoints(pos.x * scaleX,
|
||||
pos.y * scaleY,
|
||||
_clippingRegion.size.width * scaleX,
|
||||
_clippingRegion.size.height * scaleY);
|
||||
#else
|
||||
glView->setScissorInPoints(pos.x,
|
||||
pos.y,
|
||||
_clippingRegion.size.width * scaleX,
|
||||
_clippingRegion.size.height * scaleY);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -104,7 +104,11 @@ static inline Tex2F __t(const Vec2 &v)
|
|||
|
||||
// implementation of DrawNode
|
||||
|
||||
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
|
||||
static const int DEFAULT_LINE_WIDTH = 1;
|
||||
#else
|
||||
static const int DEFAULT_LINE_WIDTH = 2;
|
||||
#endif
|
||||
|
||||
DrawNode::DrawNode()
|
||||
: _vao(0)
|
||||
|
@ -126,6 +130,9 @@ DrawNode::DrawNode()
|
|||
, _dirtyGLPoint(false)
|
||||
, _dirtyGLLine(false)
|
||||
, _lineWidth(DEFAULT_LINE_WIDTH)
|
||||
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
|
||||
, _lineSmoothEnable(false)
|
||||
#endif
|
||||
{
|
||||
_blendFunc = BlendFunc::ALPHA_PREMULTIPLIED;
|
||||
}
|
||||
|
@ -398,6 +405,14 @@ void DrawNode::onDrawGLLine(const Mat4 &transform, uint32_t flags)
|
|||
// texcood
|
||||
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORD, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, texCoords));
|
||||
}
|
||||
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
|
||||
//如果开启线抗锯齿,如参考线绘制, 则先关闭多重采样
|
||||
if (this->_lineSmoothEnable == false)
|
||||
{
|
||||
glDisable(GL_MULTISAMPLE);
|
||||
glDisable(GL_LINE_SMOOTH);
|
||||
}
|
||||
#endif
|
||||
glLineWidth(_lineWidth);
|
||||
glDrawArrays(GL_LINES, 0, _bufferCountGLLine);
|
||||
|
||||
|
@ -407,8 +422,14 @@ void DrawNode::onDrawGLLine(const Mat4 &transform, uint32_t flags)
|
|||
}
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
|
||||
CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1,_bufferCountGLLine);
|
||||
|
||||
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
|
||||
//如果开启线抗锯齿, 如参考线绘制, 绘制完成开启多重采样
|
||||
if (this->_lineSmoothEnable == true)
|
||||
glEnable(GL_MULTISAMPLE);
|
||||
#endif
|
||||
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
}
|
||||
|
||||
|
@ -946,4 +967,21 @@ void DrawNode::setLineWidth(int lineWidth)
|
|||
_lineWidth = lineWidth;
|
||||
}
|
||||
|
||||
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
|
||||
void DrawNode::csSetLineSmooth(bool enable)
|
||||
{
|
||||
this->_lineSmoothEnable = enable;
|
||||
}
|
||||
|
||||
bool DrawNode::csIsLineSmooth()
|
||||
{
|
||||
return this->_lineSmoothEnable;
|
||||
}
|
||||
|
||||
float DrawNode::csGetLineWidth()
|
||||
{
|
||||
return this->_lineWidth;
|
||||
}
|
||||
#endif
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -313,6 +313,14 @@ public:
|
|||
|
||||
void setLineWidth(int lineWidth);
|
||||
|
||||
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
|
||||
void csSetLineSmooth(bool enable);
|
||||
|
||||
bool csIsLineSmooth();
|
||||
|
||||
float csGetLineWidth();
|
||||
#endif
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
DrawNode();
|
||||
virtual ~DrawNode();
|
||||
|
@ -355,6 +363,10 @@ protected:
|
|||
|
||||
int _lineWidth;
|
||||
|
||||
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
|
||||
bool _lineSmoothEnable;
|
||||
#endif
|
||||
|
||||
private:
|
||||
CC_DISALLOW_COPY_AND_ASSIGN(DrawNode);
|
||||
};
|
||||
|
|
|
@ -238,4 +238,44 @@ bool FontAtlasCache::releaseFontAtlas(FontAtlas *atlas)
|
|||
return false;
|
||||
}
|
||||
|
||||
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
|
||||
void FontAtlasCache::reloadFontAtlasFNT(const std::string& fontFileName, const Vec2& imageOffset/* = Vec2::ZERO*/)
|
||||
{
|
||||
std::string atlasName = generateFontName(fontFileName, 0, false);
|
||||
auto it = _atlasMap.find(atlasName);
|
||||
|
||||
if (it != _atlasMap.end())
|
||||
{
|
||||
CC_SAFE_RELEASE_NULL(it->second);
|
||||
_atlasMap.erase(it);
|
||||
}
|
||||
FontFNT::reloadBMFontResource(fontFileName);
|
||||
auto font = FontFNT::create(fontFileName, imageOffset);
|
||||
if (font)
|
||||
{
|
||||
auto tempAtlas = font->createFontAtlas();
|
||||
if (tempAtlas)
|
||||
{
|
||||
_atlasMap[atlasName] = tempAtlas;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void FontAtlasCache::unloadFontAtlasTTF(const std::string& fontFileName)
|
||||
{
|
||||
auto item = _atlasMap.begin();
|
||||
while (item != _atlasMap.end())
|
||||
{
|
||||
if (item->first.find(fontFileName) >= 0)
|
||||
{
|
||||
CC_SAFE_RELEASE_NULL(item->second);
|
||||
item = _atlasMap.erase(item);
|
||||
}
|
||||
else
|
||||
item++;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -54,6 +54,11 @@ public:
|
|||
*/
|
||||
static void purgeCachedData();
|
||||
|
||||
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
|
||||
static void reloadFontAtlasFNT(const std::string& fontFileName, const Vec2& imageOffset = Vec2::ZERO);
|
||||
static void unloadFontAtlasTTF(const std::string& fontFileName);
|
||||
#endif
|
||||
|
||||
private:
|
||||
static std::string generateFontName(const std::string& fontFileName, float size, bool useDistanceField);
|
||||
static std::unordered_map<std::string, FontAtlas *> _atlasMap;
|
||||
|
|
|
@ -783,5 +783,27 @@ FontAtlas * FontFNT::createFontAtlas()
|
|||
return tempAtlas;
|
||||
}
|
||||
|
||||
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
|
||||
void FontFNT::reloadBMFontResource(const std::string& fntFilePath)
|
||||
{
|
||||
if (s_configurations == nullptr)
|
||||
{
|
||||
s_configurations = new (std::nothrow) Map<std::string, BMFontConfiguration*>();
|
||||
}
|
||||
|
||||
BMFontConfiguration *ret = s_configurations->at(fntFilePath);
|
||||
if (ret != nullptr)
|
||||
{
|
||||
s_configurations->erase(fntFilePath);
|
||||
}
|
||||
ret = BMFontConfiguration::create(fntFilePath.c_str());
|
||||
if (ret)
|
||||
{
|
||||
s_configurations->insert(fntFilePath, ret);
|
||||
TextureCache::getInstance()->reloadTexture(ret->getAtlasName());
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -47,6 +47,10 @@ public:
|
|||
virtual int* getHorizontalKerningForTextUTF16(const std::u16string& text, int &outNumLetters) const override;
|
||||
virtual FontAtlas *createFontAtlas() override;
|
||||
|
||||
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
|
||||
static void reloadBMFontResource(const std::string& fntFilePath);
|
||||
#endif
|
||||
|
||||
protected:
|
||||
|
||||
FontFNT(BMFontConfiguration *theContfig, const Vec2& imageOffset = Vec2::ZERO);
|
||||
|
|
|
@ -634,4 +634,18 @@ const char* FontFreeType::getGlyphCollection() const
|
|||
return glyphCollection;
|
||||
}
|
||||
|
||||
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
|
||||
void FontFreeType::releaseFont(const std::string &fontName)
|
||||
{
|
||||
auto item = s_cacheFontData.begin();
|
||||
while (s_cacheFontData.end() != item)
|
||||
{
|
||||
if (item->first.find(fontName) >= 0)
|
||||
item = s_cacheFontData.erase(item);
|
||||
else
|
||||
item++;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -74,6 +74,11 @@ public:
|
|||
|
||||
virtual FontAtlas* createFontAtlas() override;
|
||||
virtual int getFontMaxHeight() const override { return _lineHeight; }
|
||||
|
||||
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
|
||||
static void releaseFont(const std::string &fontName);
|
||||
#endif
|
||||
|
||||
private:
|
||||
static const char* _glyphASCII;
|
||||
static const char* _glyphNEHE;
|
||||
|
|
|
@ -38,6 +38,10 @@
|
|||
#include "2d/CCComponentContainer.h"
|
||||
#include "2d/CCComponent.h"
|
||||
|
||||
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
|
||||
#include "CocosStudioExtension.h"
|
||||
#endif
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class GridBase;
|
||||
|
|
|
@ -1332,5 +1332,14 @@ void ParticleSystem::setScaleY(float newScaleY)
|
|||
Node::setScaleY(newScaleY);
|
||||
}
|
||||
|
||||
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
|
||||
ResouceData ParticleSystem::csGetRenderFile()
|
||||
{
|
||||
ResouceData rData;
|
||||
rData.type = 0;
|
||||
rData.file = _plistFile;
|
||||
return rData;
|
||||
}
|
||||
#endif
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -761,6 +761,10 @@ public:
|
|||
*/
|
||||
virtual const BlendFunc &getBlendFunc() const override;
|
||||
|
||||
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
|
||||
ResouceData csGetRenderFile();
|
||||
#endif
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
/**
|
||||
* @js ctor
|
||||
|
|
|
@ -109,7 +109,11 @@ public:
|
|||
* @param renderer The renderer use to render the scene.
|
||||
* @js NA
|
||||
*/
|
||||
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
|
||||
virtual void render(Renderer* renderer);
|
||||
#else
|
||||
void render(Renderer* renderer);
|
||||
#endif
|
||||
|
||||
/** override function */
|
||||
virtual void removeAllChildren() override;
|
||||
|
|
|
@ -164,7 +164,15 @@ bool Sprite::initWithTexture(Texture2D *texture, const Rect& rect)
|
|||
|
||||
bool Sprite::initWithFile(const std::string& filename)
|
||||
{
|
||||
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
|
||||
if (filename.empty())
|
||||
return false;
|
||||
|
||||
_fileName = filename;
|
||||
_fileType = 0;
|
||||
#else
|
||||
CCASSERT(filename.size()>0, "Invalid filename for sprite");
|
||||
#endif
|
||||
|
||||
Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(filename);
|
||||
if (texture)
|
||||
|
@ -184,6 +192,11 @@ bool Sprite::initWithFile(const std::string &filename, const Rect& rect)
|
|||
{
|
||||
CCASSERT(filename.size()>0, "Invalid filename");
|
||||
|
||||
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
|
||||
_fileName = filename;
|
||||
_fileType = 0;
|
||||
#endif
|
||||
|
||||
Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(filename);
|
||||
if (texture)
|
||||
{
|
||||
|
@ -200,6 +213,11 @@ bool Sprite::initWithSpriteFrameName(const std::string& spriteFrameName)
|
|||
{
|
||||
CCASSERT(spriteFrameName.size() > 0, "Invalid spriteFrameName");
|
||||
|
||||
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
|
||||
_fileName = spriteFrameName;
|
||||
_fileType = 1;
|
||||
#endif
|
||||
|
||||
SpriteFrame *frame = SpriteFrameCache::getInstance()->getSpriteFrameByName(spriteFrameName);
|
||||
return initWithSpriteFrame(frame);
|
||||
}
|
||||
|
@ -1145,4 +1163,19 @@ void Sprite::setPolygonInfo(const PolygonInfo& info)
|
|||
_polyInfo = info;
|
||||
}
|
||||
|
||||
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
|
||||
void Sprite::setOffsetPosFromCenter(Vec2 offsetFromCenter)
|
||||
{
|
||||
_unflippedOffsetPositionFromCenter = offsetFromCenter;
|
||||
}
|
||||
|
||||
ResouceData Sprite::csGetRenderFile()
|
||||
{
|
||||
ResouceData rData;
|
||||
rData.type = (int)_fileType;
|
||||
rData.file = _fileName;
|
||||
return rData;
|
||||
}
|
||||
#endif
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -461,6 +461,11 @@ public:
|
|||
virtual bool isOpacityModifyRGB() const override;
|
||||
/// @}
|
||||
|
||||
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
|
||||
ResouceData csGetRenderFile();
|
||||
void setOffsetPosFromCenter(Vec2 offsetFromCenter);
|
||||
#endif
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS :
|
||||
/**
|
||||
* @js ctor
|
||||
|
@ -634,6 +639,12 @@ protected:
|
|||
bool _flippedY; /// Whether the sprite is flipped vertically or not
|
||||
|
||||
bool _insideBounds; /// whether or not the sprite was inside bounds the previous frame
|
||||
|
||||
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
|
||||
std::string _fileName;
|
||||
int _fileType;
|
||||
#endif
|
||||
|
||||
private:
|
||||
CC_DISALLOW_COPY_AND_ASSIGN(Sprite);
|
||||
};
|
||||
|
|
|
@ -150,6 +150,10 @@ void SpriteFrameCache::addSpriteFramesWithDictionary(ValueMap& dictionary, Textu
|
|||
Version 3 with TexturePacker 4.0 polygon mesh packing
|
||||
*/
|
||||
|
||||
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
|
||||
if (dictionary["frames"].getType() != cocos2d::Value::Type::MAP)
|
||||
return;
|
||||
#endif
|
||||
|
||||
ValueMap& framesDict = dictionary["frames"].asValueMap();
|
||||
int format = 0;
|
||||
|
@ -493,6 +497,11 @@ void SpriteFrameCache::removeSpriteFramesFromFileContent(const std::string& plis
|
|||
|
||||
void SpriteFrameCache::removeSpriteFramesFromDictionary(ValueMap& dictionary)
|
||||
{
|
||||
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
|
||||
if (dictionary["frames"].getType() != cocos2d::Value::Type::MAP)
|
||||
return;
|
||||
#endif
|
||||
|
||||
ValueMap framesDict = dictionary["frames"].asValueMap();
|
||||
std::vector<std::string> keysToRemove;
|
||||
|
||||
|
@ -543,4 +552,179 @@ SpriteFrame* SpriteFrameCache::getSpriteFrameByName(const std::string& name)
|
|||
return frame;
|
||||
}
|
||||
|
||||
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
|
||||
void SpriteFrameCache::reloadSpriteFramesWithDictionary(ValueMap& dictionary, Texture2D *texture)
|
||||
{
|
||||
ValueMap& framesDict = dictionary["frames"].asValueMap();
|
||||
int format = 0;
|
||||
|
||||
// get the format
|
||||
if (dictionary.find("metadata") != dictionary.end())
|
||||
{
|
||||
ValueMap& metadataDict = dictionary["metadata"].asValueMap();
|
||||
format = metadataDict["format"].asInt();
|
||||
}
|
||||
|
||||
// check the format
|
||||
CCASSERT(format >= 0 && format <= 3, "format is not supported for SpriteFrameCache addSpriteFramesWithDictionary:textureFilename:");
|
||||
|
||||
for (auto iter = framesDict.begin(); iter != framesDict.end(); ++iter)
|
||||
{
|
||||
ValueMap& frameDict = iter->second.asValueMap();
|
||||
std::string spriteFrameName = iter->first;
|
||||
|
||||
auto it = _spriteFrames.find(spriteFrameName);
|
||||
if (it != _spriteFrames.end())
|
||||
{
|
||||
_spriteFrames.erase(it);
|
||||
}
|
||||
|
||||
SpriteFrame* spriteFrame = nullptr;
|
||||
|
||||
if (format == 0)
|
||||
{
|
||||
float x = frameDict["x"].asFloat();
|
||||
float y = frameDict["y"].asFloat();
|
||||
float w = frameDict["width"].asFloat();
|
||||
float h = frameDict["height"].asFloat();
|
||||
float ox = frameDict["offsetX"].asFloat();
|
||||
float oy = frameDict["offsetY"].asFloat();
|
||||
int ow = frameDict["originalWidth"].asInt();
|
||||
int oh = frameDict["originalHeight"].asInt();
|
||||
// check ow/oh
|
||||
if (!ow || !oh)
|
||||
{
|
||||
CCLOGWARN("cocos2d: WARNING: originalWidth/Height not found on the SpriteFrame. AnchorPoint won't work as expected. Regenrate the .plist");
|
||||
}
|
||||
// abs ow/oh
|
||||
ow = abs(ow);
|
||||
oh = abs(oh);
|
||||
// create frame
|
||||
spriteFrame = SpriteFrame::createWithTexture(texture,
|
||||
Rect(x, y, w, h),
|
||||
false,
|
||||
Vec2(ox, oy),
|
||||
Size((float)ow, (float)oh)
|
||||
);
|
||||
}
|
||||
else if (format == 1 || format == 2)
|
||||
{
|
||||
Rect frame = RectFromString(frameDict["frame"].asString());
|
||||
bool rotated = false;
|
||||
|
||||
// rotation
|
||||
if (format == 2)
|
||||
{
|
||||
rotated = frameDict["rotated"].asBool();
|
||||
}
|
||||
|
||||
Vec2 offset = PointFromString(frameDict["offset"].asString());
|
||||
Size sourceSize = SizeFromString(frameDict["sourceSize"].asString());
|
||||
|
||||
// create frame
|
||||
spriteFrame = SpriteFrame::createWithTexture(texture,
|
||||
frame,
|
||||
rotated,
|
||||
offset,
|
||||
sourceSize
|
||||
);
|
||||
}
|
||||
else if (format == 3)
|
||||
{
|
||||
// get values
|
||||
Size spriteSize = SizeFromString(frameDict["spriteSize"].asString());
|
||||
Vec2 spriteOffset = PointFromString(frameDict["spriteOffset"].asString());
|
||||
Size spriteSourceSize = SizeFromString(frameDict["spriteSourceSize"].asString());
|
||||
Rect textureRect = RectFromString(frameDict["textureRect"].asString());
|
||||
bool textureRotated = frameDict["textureRotated"].asBool();
|
||||
|
||||
// get aliases
|
||||
ValueVector& aliases = frameDict["aliases"].asValueVector();
|
||||
|
||||
for (const auto &value : aliases) {
|
||||
std::string oneAlias = value.asString();
|
||||
if (_spriteFramesAliases.find(oneAlias) != _spriteFramesAliases.end())
|
||||
{
|
||||
CCLOGWARN("cocos2d: WARNING: an alias with name %s already exists", oneAlias.c_str());
|
||||
}
|
||||
|
||||
_spriteFramesAliases[oneAlias] = Value(spriteFrameName);
|
||||
}
|
||||
|
||||
// create frame
|
||||
spriteFrame = SpriteFrame::createWithTexture(texture,
|
||||
Rect(textureRect.origin.x, textureRect.origin.y, spriteSize.width, spriteSize.height),
|
||||
textureRotated,
|
||||
spriteOffset,
|
||||
spriteSourceSize);
|
||||
}
|
||||
|
||||
// add sprite frame
|
||||
_spriteFrames.insert(spriteFrameName, spriteFrame);
|
||||
}
|
||||
}
|
||||
|
||||
bool SpriteFrameCache::reloadTexture(const std::string& plist)
|
||||
{
|
||||
CCASSERT(plist.size()>0, "plist filename should not be nullptr");
|
||||
|
||||
auto it = _loadedFileNames->find(plist);
|
||||
if (it != _loadedFileNames->end()) {
|
||||
_loadedFileNames->erase(it);
|
||||
}
|
||||
else
|
||||
{
|
||||
//If one plist has't be loaded, we don't load it here.
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(plist);
|
||||
ValueMap dict = FileUtils::getInstance()->getValueMapFromFile(fullPath);
|
||||
|
||||
string texturePath("");
|
||||
|
||||
if (dict.find("metadata") != dict.end())
|
||||
{
|
||||
ValueMap& metadataDict = dict["metadata"].asValueMap();
|
||||
// try to read texture file name from meta data
|
||||
texturePath = metadataDict["textureFileName"].asString();
|
||||
}
|
||||
|
||||
if (!texturePath.empty())
|
||||
{
|
||||
// build texture path relative to plist file
|
||||
texturePath = FileUtils::getInstance()->fullPathFromRelativeFile(texturePath.c_str(), plist);
|
||||
}
|
||||
else
|
||||
{
|
||||
// build texture path by replacing file extension
|
||||
texturePath = plist;
|
||||
|
||||
// remove .xxx
|
||||
size_t startPos = texturePath.find_last_of(".");
|
||||
texturePath = texturePath.erase(startPos);
|
||||
|
||||
// append .png
|
||||
texturePath = texturePath.append(".png");
|
||||
|
||||
CCLOG("cocos2d: SpriteFrameCache: Trying to use file %s as texture", texturePath.c_str());
|
||||
}
|
||||
|
||||
Texture2D *texture = nullptr;
|
||||
if (Director::getInstance()->getTextureCache()->reloadTexture(texturePath.c_str()))
|
||||
texture = Director::getInstance()->getTextureCache()->getTextureForKey(texturePath);
|
||||
|
||||
if (texture)
|
||||
{
|
||||
reloadSpriteFramesWithDictionary(dict, texture);
|
||||
_loadedFileNames->insert(plist);
|
||||
}
|
||||
else
|
||||
{
|
||||
CCLOG("cocos2d: SpriteFrameCache: Couldn't load texture");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -236,6 +236,10 @@ public:
|
|||
/** @deprecated use getSpriteFrameByName() instead */
|
||||
CC_DEPRECATED_ATTRIBUTE SpriteFrame* spriteFrameByName(const std::string&name) { return getSpriteFrameByName(name); }
|
||||
|
||||
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
|
||||
bool reloadTexture(const std::string& plist);
|
||||
#endif
|
||||
|
||||
protected:
|
||||
// MARMALADE: Made this protected not private, as deriving from this class is pretty useful
|
||||
SpriteFrameCache(){}
|
||||
|
@ -260,6 +264,10 @@ protected:
|
|||
const std::vector<int> &triangleIndices,
|
||||
PolygonInfo &polygonInfo);
|
||||
|
||||
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
|
||||
void reloadSpriteFramesWithDictionary(ValueMap& dictionary, Texture2D *texture);
|
||||
#endif
|
||||
|
||||
Map<std::string, SpriteFrame*> _spriteFrames;
|
||||
ValueMap _spriteFramesAliases;
|
||||
std::set<std::string>* _loadedFileNames;
|
||||
|
|
|
@ -62,6 +62,10 @@ bool TMXTiledMap::initWithTMXFile(const std::string& tmxFile)
|
|||
{
|
||||
CCASSERT(tmxFile.size()>0, "TMXTiledMap: tmx file should not be empty");
|
||||
|
||||
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
|
||||
_tmxFile = tmxFile;
|
||||
#endif
|
||||
|
||||
setContentSize(Size::ZERO);
|
||||
|
||||
TMXMapInfo *mapInfo = TMXMapInfo::create(tmxFile);
|
||||
|
@ -78,6 +82,10 @@ bool TMXTiledMap::initWithTMXFile(const std::string& tmxFile)
|
|||
|
||||
bool TMXTiledMap::initWithXML(const std::string& tmxString, const std::string& resourcePath)
|
||||
{
|
||||
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
|
||||
_tmxFile = tmxString;
|
||||
#endif
|
||||
|
||||
setContentSize(Size::ZERO);
|
||||
|
||||
TMXMapInfo *mapInfo = TMXMapInfo::createWithXML(tmxString, resourcePath);
|
||||
|
@ -91,6 +99,10 @@ bool TMXTiledMap::initWithXML(const std::string& tmxString, const std::string& r
|
|||
TMXTiledMap::TMXTiledMap()
|
||||
:_mapSize(Size::ZERO)
|
||||
,_tileSize(Size::ZERO)
|
||||
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
|
||||
,_tmxFile("")
|
||||
, _tmxLayerNum(0)
|
||||
#endif
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -179,12 +191,15 @@ void TMXTiledMap::buildWithMapInfo(TMXMapInfo* mapInfo)
|
|||
for (const auto &layerInfo : layers) {
|
||||
if (layerInfo->_visible) {
|
||||
TMXLayer *child = parseLayer(layerInfo, mapInfo);
|
||||
//为编辑器修改,节省一次循环
|
||||
//addChild(child, idx, idx);
|
||||
if (child == nullptr) {
|
||||
idx++;
|
||||
continue;
|
||||
}
|
||||
addChild(child, idx, idx);
|
||||
|
||||
addChild(child, 0, idx);
|
||||
child->setOrderOfArrival(idx);
|
||||
child->setTag(TMXLayerTag);
|
||||
// update content size with the max size
|
||||
const Size& childSize = child->getContentSize();
|
||||
Size currentSize = this->getContentSize();
|
||||
|
@ -195,6 +210,9 @@ void TMXTiledMap::buildWithMapInfo(TMXMapInfo* mapInfo)
|
|||
idx++;
|
||||
}
|
||||
}
|
||||
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
|
||||
_tmxLayerNum = idx;
|
||||
#endif
|
||||
}
|
||||
|
||||
// public
|
||||
|
@ -270,5 +288,19 @@ std::string TMXTiledMap::getDescription() const
|
|||
return StringUtils::format("<TMXTiledMap | Tag = %d, Layers = %d", _tag, static_cast<int>(_children.size()));
|
||||
}
|
||||
|
||||
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
|
||||
int TMXTiledMap::getLayerNum()
|
||||
{
|
||||
return _tmxLayerNum;
|
||||
}
|
||||
|
||||
ResouceData TMXTiledMap::csGetRenderFile()
|
||||
{
|
||||
ResouceData rData;
|
||||
rData.type = 0;
|
||||
rData.file = _tmxFile;
|
||||
return rData;
|
||||
}
|
||||
#endif
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -252,6 +252,11 @@ public:
|
|||
*/
|
||||
virtual std::string getDescription() const override;
|
||||
|
||||
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
|
||||
ResouceData csGetRenderFile();
|
||||
int getLayerNum();
|
||||
#endif
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
/**
|
||||
* @js ctor
|
||||
|
@ -288,6 +293,12 @@ protected:
|
|||
//! tile properties
|
||||
ValueMapIntKey _tileProperties;
|
||||
|
||||
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
|
||||
std::string _tmxFile;
|
||||
int _tmxLayerNum;
|
||||
static const int TMXLayerTag = 32768;
|
||||
#endif
|
||||
|
||||
private:
|
||||
CC_DISALLOW_COPY_AND_ASSIGN(TMXTiledMap);
|
||||
|
||||
|
|
|
@ -266,6 +266,9 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
|
|||
std::string externalTilesetFilename = attributeDict["source"].asString();
|
||||
if (externalTilesetFilename != "")
|
||||
{
|
||||
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
|
||||
_externalTilesetFilename = externalTilesetFilename;
|
||||
#endif
|
||||
// Tileset file will be relative to the map file. So we need to convert it to an absolute path
|
||||
if (_TMXFileName.find_last_of("/") != string::npos)
|
||||
{
|
||||
|
@ -388,7 +391,9 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
|
|||
|
||||
// build full path
|
||||
std::string imagename = attributeDict["source"].asString();
|
||||
|
||||
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
|
||||
tileset->_originSourceImage = imagename;
|
||||
#endif
|
||||
if (_TMXFileName.find_last_of("/") != string::npos)
|
||||
{
|
||||
string dir = _TMXFileName.substr(0, _TMXFileName.find_last_of("/") + 1);
|
||||
|
|
|
@ -139,6 +139,10 @@ public:
|
|||
std::string _sourceImage;
|
||||
//! size in pixels of the image
|
||||
Size _imageSize;
|
||||
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
|
||||
std::string _sourceImage;
|
||||
std::string _originSourceImage;
|
||||
#endif
|
||||
public:
|
||||
/**
|
||||
* @js ctor
|
||||
|
@ -279,6 +283,9 @@ public:
|
|||
inline void setCurrentString(const std::string& currentString){ _currentString = currentString; }
|
||||
inline const std::string& getTMXFileName() const { return _TMXFileName; }
|
||||
inline void setTMXFileName(const std::string& fileName){ _TMXFileName = fileName; }
|
||||
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
|
||||
inline const std::string& getExternalTilesetFileName(){ return _externalTilesetFilename; }
|
||||
#endif
|
||||
|
||||
protected:
|
||||
void internalInit(const std::string& tmxFileName, const std::string& resourcePath);
|
||||
|
@ -318,6 +325,9 @@ protected:
|
|||
ValueMapIntKey _tileProperties;
|
||||
int _currentFirstGID;
|
||||
bool _recordFirstGID;
|
||||
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
|
||||
std::string _externalTilesetFilename;
|
||||
#endif
|
||||
};
|
||||
|
||||
// end of tilemap_parallax_nodes group
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
#include "CocosStudioExtension.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
NodeExtension::NodeExtension()
|
||||
{
|
||||
}
|
||||
|
||||
NodeExtension::~NodeExtension()
|
||||
{
|
||||
}
|
||||
|
||||
NS_CC_END
|
|
@ -0,0 +1,44 @@
|
|||
|
||||
#ifndef __COCOSSTUDIOEXTENSION_H__
|
||||
#define __COCOSSTUDIOEXTENSION_H__
|
||||
|
||||
#include "math/CCAffineTransform.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
struct CC_DLL ResouceData
|
||||
{
|
||||
int type;
|
||||
std::string file;
|
||||
std::string plist;
|
||||
|
||||
ResouceData()
|
||||
{
|
||||
type = 0;
|
||||
file = "";
|
||||
plist = "";
|
||||
}
|
||||
|
||||
ResouceData(int iType, std::string sFile, std::string sPlist)
|
||||
{
|
||||
type = iType;
|
||||
file = sFile;
|
||||
plist = sPlist;
|
||||
}
|
||||
};
|
||||
|
||||
class CC_DLL NodeExtension
|
||||
{
|
||||
public:
|
||||
NodeExtension();
|
||||
~NodeExtension();
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
|
||||
NS_CC_END
|
||||
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue