From 31ed6d97a921bbef3d954d503f6fef3a52d77453 Mon Sep 17 00:00:00 2001 From: halx99 Date: Thu, 11 Nov 2021 18:04:38 +0800 Subject: [PATCH] Fix fairygui compilation --- extensions/fairygui/UIPackage.cpp | 9 ++++++--- extensions/fairygui/display/BitmapFont.h | 18 ++++++++++++++++-- extensions/fairygui/display/FUILabel.cpp | 2 +- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/extensions/fairygui/UIPackage.cpp b/extensions/fairygui/UIPackage.cpp index a4dd4ad0a3..52e276b429 100644 --- a/extensions/fairygui/UIPackage.cpp +++ b/extensions/fairygui/UIPackage.cpp @@ -768,9 +768,12 @@ void UIPackage::loadMovieClip(PackageItem* item) void UIPackage::loadFont(PackageItem* item) { item->bitmapFont = BitmapFont::create(); - FontAtlas* fontAtlas = new FontAtlas(*item->bitmapFont); - item->bitmapFont->_fontAtlas = fontAtlas; - + auto bitmapFont = item->bitmapFont; +#if defined(ADXE_VERSION) + auto fontAtlas = bitmapFont->resetFontAtlas(bitmapFont->newFontAtlas()); +#else + auto fontAtlas = bitmapFont->resetFontAtlas(bitmapFont->createFontAtlas()); +#endif ByteBuffer* buffer = item->rawData; buffer->seek(0, 0); diff --git a/extensions/fairygui/display/BitmapFont.h b/extensions/fairygui/display/BitmapFont.h index d86892cc87..5db4d6f8ba 100644 --- a/extensions/fairygui/display/BitmapFont.h +++ b/extensions/fairygui/display/BitmapFont.h @@ -16,8 +16,22 @@ public: static BitmapFont* create(); virtual int* getHorizontalKerningForTextUTF32(const std::u32string& text, int &outNumLetters) const override; - virtual cocos2d::FontAtlas *createFontAtlas() override { return _fontAtlas; } - void releaseAtlas() { _fontAtlas->release(); } +# if defined(ADXE_VERSION) + virtual cocos2d::FontAtlas* newFontAtlas() override { return new cocos2d::FontAtlas(this); } +#else + virtual cocos2d::FontAtlas* createFontAtlas() override { return new cocos2d::FontAtlas(*this); } +#endif + cocos2d::FontAtlas* resetFontAtlas(cocos2d::FontAtlas* fontAtlas) + { + if (_fontAtlas != fontAtlas) + { + CC_SAFE_RELEASE(_fontAtlas); + _fontAtlas = fontAtlas; + } + return _fontAtlas; + } + cocos2d::FontAtlas* getFontAtlas() const { return _fontAtlas; } + void releaseAtlas() { resetFontAtlas(nullptr); } void setFontSize(float fontSize) {} int getOriginalFontSize()const { return _originalFontSize; } bool isResizable() { return _resizable; } diff --git a/extensions/fairygui/display/FUILabel.cpp b/extensions/fairygui/display/FUILabel.cpp index 59b7d81352..66331998bf 100644 --- a/extensions/fairygui/display/FUILabel.cpp +++ b/extensions/fairygui/display/FUILabel.cpp @@ -143,7 +143,7 @@ bool FUILabel::setBMFontFilePath(const std::string& bmfontFilePath, const Vec2& _bmFontCanTint = bmFont->canTint(); _currentLabelType = LabelType::BMFONT; - setFontAtlas(bmFont->createFontAtlas()); + setFontAtlas(bmFont->getFontAtlas()); return true; }