diff --git a/build/cocos2d_libs.xcodeproj/project.pbxproj b/build/cocos2d_libs.xcodeproj/project.pbxproj index de7df4343d..7eaadceee3 100644 --- a/build/cocos2d_libs.xcodeproj/project.pbxproj +++ b/build/cocos2d_libs.xcodeproj/project.pbxproj @@ -3838,6 +3838,12 @@ 85505F0E1B60E3DB003F2CD4 /* SkeletonNodeReader.h in Headers */ = {isa = PBXBuildFile; fileRef = C50306741B60B5B2001E6D43 /* SkeletonNodeReader.h */; }; 85B3743A1B204B9400C488D6 /* clipper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 85B374381B204B9400C488D6 /* clipper.cpp */; }; 85B3743B1B204B9400C488D6 /* clipper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 85B374381B204B9400C488D6 /* clipper.cpp */; }; + 94A6DF051C7303FD0094AEF7 /* LocalizationManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94A6DF031C7303FD0094AEF7 /* LocalizationManager.cpp */; }; + 94A6DF061C7303FD0094AEF7 /* LocalizationManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 94A6DF041C7303FD0094AEF7 /* LocalizationManager.h */; }; + 94A6DF071C73040D0094AEF7 /* LocalizationManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94A6DF031C7303FD0094AEF7 /* LocalizationManager.cpp */; }; + 94A6DF081C73040E0094AEF7 /* LocalizationManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94A6DF031C7303FD0094AEF7 /* LocalizationManager.cpp */; }; + 94A6DF091C7304120094AEF7 /* LocalizationManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 94A6DF041C7303FD0094AEF7 /* LocalizationManager.h */; }; + 94A6DF0A1C7304120094AEF7 /* LocalizationManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 94A6DF041C7303FD0094AEF7 /* LocalizationManager.h */; }; A045F6D61BA81577005076C7 /* CCTextureCube.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A045F6D41BA81577005076C7 /* CCTextureCube.cpp */; }; A045F6D71BA81577005076C7 /* CCTextureCube.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A045F6D41BA81577005076C7 /* CCTextureCube.cpp */; }; A045F6D81BA81577005076C7 /* CCTextureCube.h in Headers */ = {isa = PBXBuildFile; fileRef = A045F6D51BA81577005076C7 /* CCTextureCube.h */; }; @@ -6717,6 +6723,8 @@ 5E9F61251A3FFE3D0038DE01 /* CCPlane.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCPlane.h; sourceTree = ""; }; 8525E3A11B291E42008EE815 /* clipper.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = clipper.hpp; sourceTree = ""; }; 85B374381B204B9400C488D6 /* clipper.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = clipper.cpp; sourceTree = ""; }; + 94A6DF031C7303FD0094AEF7 /* LocalizationManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LocalizationManager.cpp; sourceTree = ""; }; + 94A6DF041C7303FD0094AEF7 /* LocalizationManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LocalizationManager.h; sourceTree = ""; }; A045F6D41BA81577005076C7 /* CCTextureCube.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCTextureCube.cpp; sourceTree = ""; }; A045F6D51BA81577005076C7 /* CCTextureCube.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCTextureCube.h; sourceTree = ""; }; A045F6DA1BA816A1005076C7 /* CCCameraBackgroundBrush.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCCameraBackgroundBrush.cpp; sourceTree = ""; }; @@ -8510,6 +8518,8 @@ 1A8C5946180E930E00EF57C3 /* cocostudio */ = { isa = PBXGroup; children = ( + 94A6DF031C7303FD0094AEF7 /* LocalizationManager.cpp */, + 94A6DF041C7303FD0094AEF7 /* LocalizationManager.h */, 382384021A259005002C4610 /* CSParseBinary_generated.h */, 182C5CAD1A95961600C30D34 /* CSParse3DBinary_generated.h */, 382384051A25900F002C4610 /* FlatBuffersSerialize.cpp */, @@ -11339,6 +11349,7 @@ 15AE187F19AAD33D00C27E9E /* CCBKeyframe.h in Headers */, B665E2B41AA80A6500DDB1C5 /* CCPUForceField.h in Headers */, 1A570073180BC5A10088DEC7 /* CCActionGrid.h in Headers */, + 94A6DF061C7303FD0094AEF7 /* LocalizationManager.h in Headers */, 15AE1BCC19AAE01E00C27E9E /* CCControlButton.h in Headers */, B6CAB3D71AF9AA1A00B9B856 /* btSolve2LinearConstraint.h in Headers */, C50306771B60B5B2001E6D43 /* CSBoneBinary_generated.h in Headers */, @@ -12267,6 +12278,7 @@ 507B3D3A1C31BDD30067B53E /* CCEventListenerAssetsManagerEx.h in Headers */, 507B3D3B1C31BDD30067B53E /* btGpu3DGridBroadphase.h in Headers */, 507B3D3C1C31BDD30067B53E /* CCAllocatorGlobal.h in Headers */, + 94A6DF0A1C7304120094AEF7 /* LocalizationManager.h in Headers */, 507B3D3D1C31BDD30067B53E /* btSolverConstraint.h in Headers */, 507B3D3E1C31BDD30067B53E /* SpuDoubleBuffer.h in Headers */, 507B3D3F1C31BDD30067B53E /* CCPUScriptCompiler.h in Headers */, @@ -13307,6 +13319,7 @@ 15B3708319EE414C00ABE682 /* CCEventListenerAssetsManagerEx.h in Headers */, B6CAB4361AF9AA1A00B9B856 /* btGpu3DGridBroadphase.h in Headers */, D0FD03521A3B51AA00825BB5 /* CCAllocatorGlobal.h in Headers */, + 94A6DF091C7304120094AEF7 /* LocalizationManager.h in Headers */, B6CAB3DC1AF9AA1A00B9B856 /* btSolverConstraint.h in Headers */, B6CAB4B61AF9AA1A00B9B856 /* SpuDoubleBuffer.h in Headers */, B665E3D11AA80A6600DDB1C5 /* CCPUScriptCompiler.h in Headers */, @@ -14984,6 +14997,7 @@ 1A570354180BD0B00088DEC7 /* ioapi.cpp in Sources */, 15B3707819EE414C00ABE682 /* AssetsManagerEx.cpp in Sources */, 1A570358180BD0B00088DEC7 /* unzip.cpp in Sources */, + 94A6DF051C7303FD0094AEF7 /* LocalizationManager.cpp in Sources */, B665E3861AA80A6500DDB1C5 /* CCPUPathFollowerTranslator.cpp in Sources */, B29A7DCB19EE1B7700872B35 /* Skeleton.c in Sources */, 15AE196E19AAD35700C27E9E /* CCActionTimelineCache.cpp in Sources */, @@ -15829,6 +15843,7 @@ 507B3C141C31BDD30067B53E /* CCPUBoxCollider.cpp in Sources */, 507B3C151C31BDD30067B53E /* CCPUMeshSurfaceEmitter.cpp in Sources */, 507B3C161C31BDD30067B53E /* CCPUOnQuotaObserverTranslator.cpp in Sources */, + 94A6DF081C73040E0094AEF7 /* LocalizationManager.cpp in Sources */, 507B3C171C31BDD30067B53E /* UIPageView.cpp in Sources */, 507B3C181C31BDD30067B53E /* CCComponentContainer.cpp in Sources */, 507B3C191C31BDD30067B53E /* ccCArray.cpp in Sources */, @@ -16674,6 +16689,7 @@ B665E22B1AA80A6500DDB1C5 /* CCPUBoxCollider.cpp in Sources */, B665E3031AA80A6500DDB1C5 /* CCPUMeshSurfaceEmitter.cpp in Sources */, B665E3571AA80A6500DDB1C5 /* CCPUOnQuotaObserverTranslator.cpp in Sources */, + 94A6DF071C73040D0094AEF7 /* LocalizationManager.cpp in Sources */, 15AE1B7619AADA9A00C27E9E /* UIPageView.cpp in Sources */, 1A570311180BCF190088DEC7 /* CCComponentContainer.cpp in Sources */, 50ABBE2C1925AB6F00A911A9 /* ccCArray.cpp in Sources */, diff --git a/cocos/2d/libcocos2d.vcxproj b/cocos/2d/libcocos2d.vcxproj index 729b02e552..5a7e296aee 100644 --- a/cocos/2d/libcocos2d.vcxproj +++ b/cocos/2d/libcocos2d.vcxproj @@ -526,6 +526,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\chipmunk\prebuilt\win32\release-lib\*.* + @@ -1132,6 +1133,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\chipmunk\prebuilt\win32\release-lib\*.* + diff --git a/cocos/2d/libcocos2d.vcxproj.filters b/cocos/2d/libcocos2d.vcxproj.filters index a82dd1f965..e791e55360 100644 --- a/cocos/2d/libcocos2d.vcxproj.filters +++ b/cocos/2d/libcocos2d.vcxproj.filters @@ -1950,6 +1950,9 @@ ui\UIWidgets + + cocostudio\json + @@ -3809,6 +3812,9 @@ ui\UIWidgets + + cocostudio\json + diff --git a/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems b/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems index e132b133a7..0b5bb61ac2 100644 --- a/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems +++ b/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems @@ -399,6 +399,7 @@ + @@ -1014,6 +1015,7 @@ + diff --git a/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems.filters b/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems.filters index bd3b438cf1..eaaa8f32f5 100644 --- a/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems.filters +++ b/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems.filters @@ -1886,6 +1886,9 @@ cocostudio\reader\WidgetReader\TabControlReader + + cocostudio\components + @@ -3604,6 +3607,9 @@ cocostudio\reader\WidgetReader\TabControlReader + + cocostudio\components + diff --git a/cocos/2d/libcocos2d_win10/libcocos2d.vcxproj b/cocos/2d/libcocos2d_win10/libcocos2d.vcxproj index edc25e7396..33ece75dc9 100644 --- a/cocos/2d/libcocos2d_win10/libcocos2d.vcxproj +++ b/cocos/2d/libcocos2d_win10/libcocos2d.vcxproj @@ -509,6 +509,7 @@ + @@ -1127,6 +1128,7 @@ + diff --git a/cocos/2d/libcocos2d_win10/libcocos2d.vcxproj.filters b/cocos/2d/libcocos2d_win10/libcocos2d.vcxproj.filters index 4bfeeae4aa..41db81df9b 100644 --- a/cocos/2d/libcocos2d_win10/libcocos2d.vcxproj.filters +++ b/cocos/2d/libcocos2d_win10/libcocos2d.vcxproj.filters @@ -1,4 +1,4 @@ - + @@ -1978,6 +1978,9 @@ cocostudio\reader\WidgetReader\Light3DReader + + cocostudio\components + @@ -3863,6 +3866,9 @@ cocostudio\reader\WidgetReader\Light3DReader + + cocostudio\components + @@ -4023,4 +4029,4 @@ 3d - + \ No newline at end of file diff --git a/cocos/editor-support/cocostudio/Android.mk b/cocos/editor-support/cocostudio/Android.mk index 94a60a92d0..5a1ed035b6 100644 --- a/cocos/editor-support/cocostudio/Android.mk +++ b/cocos/editor-support/cocostudio/Android.mk @@ -34,6 +34,7 @@ CCComController.cpp \ CCComRender.cpp \ CCInputDelegate.cpp \ DictionaryHelper.cpp \ +LocalizationManager.cpp \ CCSGUIReader.cpp \ CCSSceneReader.cpp \ TriggerBase.cpp \ diff --git a/cocos/editor-support/cocostudio/CMakeLists.txt b/cocos/editor-support/cocostudio/CMakeLists.txt index 5e43854276..418144e198 100644 --- a/cocos/editor-support/cocostudio/CMakeLists.txt +++ b/cocos/editor-support/cocostudio/CMakeLists.txt @@ -39,6 +39,7 @@ set(COCOS_CS_SRC editor-support/cocostudio/CCUtilMath.cpp editor-support/cocostudio/CocoLoader.cpp editor-support/cocostudio/DictionaryHelper.cpp + editor-support/cocostudio/LocalizationManager.cpp editor-support/cocostudio/TriggerBase.cpp editor-support/cocostudio/TriggerMng.cpp editor-support/cocostudio/TriggerObj.cpp diff --git a/cocos/editor-support/cocostudio/CSParseBinary_generated.h b/cocos/editor-support/cocostudio/CSParseBinary_generated.h index 73c1f8da79..e8df4999bb 100644 --- a/cocos/editor-support/cocostudio/CSParseBinary_generated.h +++ b/cocos/editor-support/cocostudio/CSParseBinary_generated.h @@ -1,4 +1,4 @@ -// automatically generated by the FlatBuffers compiler, do not modify +// automatically generated by the FlatBuffers compiler, do not modify #ifndef FLATBUFFERS_GENERATED_CSPARSEBINARY_FLATBUFFERS_H_ #define FLATBUFFERS_GENERATED_CSPARSEBINARY_FLATBUFFERS_H_ @@ -721,21 +721,22 @@ struct ButtonOptions : private flatbuffers::Table { const ResourceData *disabledData() const { return GetPointer(10); } const ResourceData *fontResource() const { return GetPointer(12); } const flatbuffers::String *text() const { return GetPointer(14); } - const flatbuffers::String *fontName() const { return GetPointer(16); } - int32_t fontSize() const { return GetField(18, 0); } - const Color *textColor() const { return GetStruct(20); } - const CapInsets *capInsets() const { return GetStruct(22); } - const FlatSize *scale9Size() const { return GetStruct(24); } - uint8_t scale9Enabled() const { return GetField(26, 0); } - uint8_t displaystate() const { return GetField(28, 1); } - uint8_t outlineEnabled() const { return GetField(30, 0); } - const Color *outlineColor() const { return GetStruct(32); } - int32_t outlineSize() const { return GetField(34, 1); } - uint8_t shadowEnabled() const { return GetField(36, 0); } - const Color *shadowColor() const { return GetStruct(38); } - float shadowOffsetX() const { return GetField(40, 2); } - float shadowOffsetY() const { return GetField(42, -2); } - int32_t shadowBlurRadius() const { return GetField(44, 0); } + uint8_t isLocalized() const { return GetField(16, 0); } + const flatbuffers::String *fontName() const { return GetPointer(18); } + int32_t fontSize() const { return GetField(20, 0); } + const Color *textColor() const { return GetStruct(22); } + const CapInsets *capInsets() const { return GetStruct(24); } + const FlatSize *scale9Size() const { return GetStruct(26); } + uint8_t scale9Enabled() const { return GetField(28, 0); } + uint8_t displaystate() const { return GetField(30, 1); } + uint8_t outlineEnabled() const { return GetField(32, 0); } + const Color *outlineColor() const { return GetStruct(34); } + int32_t outlineSize() const { return GetField(36, 1); } + uint8_t shadowEnabled() const { return GetField(38, 0); } + const Color *shadowColor() const { return GetStruct(40); } + float shadowOffsetX() const { return GetField(42, 2); } + float shadowOffsetY() const { return GetField(44, -2); } + int32_t shadowBlurRadius() const { return GetField(46, 0); } bool Verify(flatbuffers::Verifier &verifier) const { return VerifyTableStart(verifier) && VerifyField(verifier, 4 /* widgetOptions */) && @@ -750,22 +751,23 @@ struct ButtonOptions : private flatbuffers::Table { verifier.VerifyTable(fontResource()) && VerifyField(verifier, 14 /* text */) && verifier.Verify(text()) && - VerifyField(verifier, 16 /* fontName */) && + VerifyField(verifier, 16 /* isLocalized */) && + VerifyField(verifier, 18 /* fontName */) && verifier.Verify(fontName()) && - VerifyField(verifier, 18 /* fontSize */) && - VerifyField(verifier, 20 /* textColor */) && - VerifyField(verifier, 22 /* capInsets */) && - VerifyField(verifier, 24 /* scale9Size */) && - VerifyField(verifier, 26 /* scale9Enabled */) && - VerifyField(verifier, 28 /* displaystate */) && - VerifyField(verifier, 30 /* outlineEnabled */) && - VerifyField(verifier, 32 /* outlineColor */) && - VerifyField(verifier, 34 /* outlineSize */) && - VerifyField(verifier, 36 /* shadowEnabled */) && - VerifyField(verifier, 38 /* shadowColor */) && - VerifyField(verifier, 40 /* shadowOffsetX */) && - VerifyField(verifier, 42 /* shadowOffsetY */) && - VerifyField(verifier, 44 /* shadowBlurRadius */) && + VerifyField(verifier, 20 /* fontSize */) && + VerifyField(verifier, 22 /* textColor */) && + VerifyField(verifier, 24 /* capInsets */) && + VerifyField(verifier, 26 /* scale9Size */) && + VerifyField(verifier, 28 /* scale9Enabled */) && + VerifyField(verifier, 30 /* displaystate */) && + VerifyField(verifier, 32 /* outlineEnabled */) && + VerifyField(verifier, 34 /* outlineColor */) && + VerifyField(verifier, 36 /* outlineSize */) && + VerifyField(verifier, 38 /* shadowEnabled */) && + VerifyField(verifier, 40 /* shadowColor */) && + VerifyField(verifier, 42 /* shadowOffsetX */) && + VerifyField(verifier, 44 /* shadowOffsetY */) && + VerifyField(verifier, 46 /* shadowBlurRadius */) && verifier.EndTable(); } }; @@ -779,25 +781,26 @@ struct ButtonOptionsBuilder { void add_disabledData(flatbuffers::Offset disabledData) { fbb_.AddOffset(10, disabledData); } void add_fontResource(flatbuffers::Offset fontResource) { fbb_.AddOffset(12, fontResource); } void add_text(flatbuffers::Offset text) { fbb_.AddOffset(14, text); } - void add_fontName(flatbuffers::Offset fontName) { fbb_.AddOffset(16, fontName); } - void add_fontSize(int32_t fontSize) { fbb_.AddElement(18, fontSize, 0); } - void add_textColor(const Color *textColor) { fbb_.AddStruct(20, textColor); } - void add_capInsets(const CapInsets *capInsets) { fbb_.AddStruct(22, capInsets); } - void add_scale9Size(const FlatSize *scale9Size) { fbb_.AddStruct(24, scale9Size); } - void add_scale9Enabled(uint8_t scale9Enabled) { fbb_.AddElement(26, scale9Enabled, 0); } - void add_displaystate(uint8_t displaystate) { fbb_.AddElement(28, displaystate, 1); } - void add_outlineEnabled(uint8_t outlineEnabled) { fbb_.AddElement(30, outlineEnabled, 0); } - void add_outlineColor(const Color *outlineColor) { fbb_.AddStruct(32, outlineColor); } - void add_outlineSize(int32_t outlineSize) { fbb_.AddElement(34, outlineSize, 1); } - void add_shadowEnabled(uint8_t shadowEnabled) { fbb_.AddElement(36, shadowEnabled, 0); } - void add_shadowColor(const Color *shadowColor) { fbb_.AddStruct(38, shadowColor); } - void add_shadowOffsetX(float shadowOffsetX) { fbb_.AddElement(40, shadowOffsetX, 2); } - void add_shadowOffsetY(float shadowOffsetY) { fbb_.AddElement(42, shadowOffsetY, -2); } - void add_shadowBlurRadius(int32_t shadowBlurRadius) { fbb_.AddElement(44, shadowBlurRadius, 0); } + void add_isLocalized(uint8_t isLocalized) { fbb_.AddElement(16, isLocalized, 0); } + void add_fontName(flatbuffers::Offset fontName) { fbb_.AddOffset(18, fontName); } + void add_fontSize(int32_t fontSize) { fbb_.AddElement(20, fontSize, 0); } + void add_textColor(const Color *textColor) { fbb_.AddStruct(22, textColor); } + void add_capInsets(const CapInsets *capInsets) { fbb_.AddStruct(24, capInsets); } + void add_scale9Size(const FlatSize *scale9Size) { fbb_.AddStruct(26, scale9Size); } + void add_scale9Enabled(uint8_t scale9Enabled) { fbb_.AddElement(28, scale9Enabled, 0); } + void add_displaystate(uint8_t displaystate) { fbb_.AddElement(30, displaystate, 1); } + void add_outlineEnabled(uint8_t outlineEnabled) { fbb_.AddElement(32, outlineEnabled, 0); } + void add_outlineColor(const Color *outlineColor) { fbb_.AddStruct(34, outlineColor); } + void add_outlineSize(int32_t outlineSize) { fbb_.AddElement(36, outlineSize, 1); } + void add_shadowEnabled(uint8_t shadowEnabled) { fbb_.AddElement(38, shadowEnabled, 0); } + void add_shadowColor(const Color *shadowColor) { fbb_.AddStruct(40, shadowColor); } + void add_shadowOffsetX(float shadowOffsetX) { fbb_.AddElement(42, shadowOffsetX, 2); } + void add_shadowOffsetY(float shadowOffsetY) { fbb_.AddElement(44, shadowOffsetY, -2); } + void add_shadowBlurRadius(int32_t shadowBlurRadius) { fbb_.AddElement(46, shadowBlurRadius, 0); } ButtonOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } ButtonOptionsBuilder &operator=(const ButtonOptionsBuilder &); flatbuffers::Offset Finish() { - auto o = flatbuffers::Offset(fbb_.EndTable(start_, 21)); + auto o = flatbuffers::Offset(fbb_.EndTable(start_, 22)); return o; } }; @@ -809,6 +812,7 @@ inline flatbuffers::Offset CreateButtonOptions(flatbuffers::FlatB flatbuffers::Offset disabledData = 0, flatbuffers::Offset fontResource = 0, flatbuffers::Offset text = 0, + uint8_t isLocalized = 0, flatbuffers::Offset fontName = 0, int32_t fontSize = 0, const Color *textColor = 0, @@ -846,6 +850,7 @@ inline flatbuffers::Offset CreateButtonOptions(flatbuffers::FlatB builder_.add_outlineEnabled(outlineEnabled); builder_.add_displaystate(displaystate); builder_.add_scale9Enabled(scale9Enabled); + builder_.add_isLocalized(isLocalized); return builder_.Finish(); } @@ -1029,6 +1034,7 @@ struct TextBMFontOptions : private flatbuffers::Table { const WidgetOptions *widgetOptions() const { return GetPointer(4); } const ResourceData *fileNameData() const { return GetPointer(6); } const flatbuffers::String *text() const { return GetPointer(8); } + uint8_t isLocalized() const { return GetField(10, 0); } bool Verify(flatbuffers::Verifier &verifier) const { return VerifyTableStart(verifier) && VerifyField(verifier, 4 /* widgetOptions */) && @@ -1037,6 +1043,7 @@ struct TextBMFontOptions : private flatbuffers::Table { verifier.VerifyTable(fileNameData()) && VerifyField(verifier, 8 /* text */) && verifier.Verify(text()) && + VerifyField(verifier, 10 /* isLocalized */) && verifier.EndTable(); } }; @@ -1047,10 +1054,11 @@ struct TextBMFontOptionsBuilder { void add_widgetOptions(flatbuffers::Offset widgetOptions) { fbb_.AddOffset(4, widgetOptions); } void add_fileNameData(flatbuffers::Offset fileNameData) { fbb_.AddOffset(6, fileNameData); } void add_text(flatbuffers::Offset text) { fbb_.AddOffset(8, text); } + void add_isLocalized(uint8_t isLocalized) { fbb_.AddElement(10, isLocalized, 0); } TextBMFontOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } TextBMFontOptionsBuilder &operator=(const TextBMFontOptionsBuilder &); flatbuffers::Offset Finish() { - auto o = flatbuffers::Offset(fbb_.EndTable(start_, 3)); + auto o = flatbuffers::Offset(fbb_.EndTable(start_, 4)); return o; } }; @@ -1058,11 +1066,13 @@ struct TextBMFontOptionsBuilder { inline flatbuffers::Offset CreateTextBMFontOptions(flatbuffers::FlatBufferBuilder &_fbb, flatbuffers::Offset widgetOptions = 0, flatbuffers::Offset fileNameData = 0, - flatbuffers::Offset text = 0) { + flatbuffers::Offset text = 0, + uint8_t isLocalized = 0) { TextBMFontOptionsBuilder builder_(_fbb); builder_.add_text(text); builder_.add_fileNameData(fileNameData); builder_.add_widgetOptions(widgetOptions); + builder_.add_isLocalized(isLocalized); return builder_.Finish(); } @@ -1072,20 +1082,21 @@ struct TextOptions : private flatbuffers::Table { const flatbuffers::String *fontName() const { return GetPointer(8); } int32_t fontSize() const { return GetField(10, 0); } const flatbuffers::String *text() const { return GetPointer(12); } - int32_t areaWidth() const { return GetField(14, 0); } - int32_t areaHeight() const { return GetField(16, 0); } - int32_t hAlignment() const { return GetField(18, 0); } - int32_t vAlignment() const { return GetField(20, 0); } - uint8_t touchScaleEnable() const { return GetField(22, 0); } - uint8_t isCustomSize() const { return GetField(24, 0); } - uint8_t outlineEnabled() const { return GetField(26, 0); } - const Color *outlineColor() const { return GetStruct(28); } - int32_t outlineSize() const { return GetField(30, 1); } - uint8_t shadowEnabled() const { return GetField(32, 0); } - const Color *shadowColor() const { return GetStruct(34); } - float shadowOffsetX() const { return GetField(36, 2); } - float shadowOffsetY() const { return GetField(38, -2); } - int32_t shadowBlurRadius() const { return GetField(40, 0); } + uint8_t isLocalized() const { return GetField(14, 0); } + int32_t areaWidth() const { return GetField(16, 0); } + int32_t areaHeight() const { return GetField(18, 0); } + int32_t hAlignment() const { return GetField(20, 0); } + int32_t vAlignment() const { return GetField(22, 0); } + uint8_t touchScaleEnable() const { return GetField(24, 0); } + uint8_t isCustomSize() const { return GetField(26, 0); } + uint8_t outlineEnabled() const { return GetField(28, 0); } + const Color *outlineColor() const { return GetStruct(30); } + int32_t outlineSize() const { return GetField(32, 1); } + uint8_t shadowEnabled() const { return GetField(34, 0); } + const Color *shadowColor() const { return GetStruct(36); } + float shadowOffsetX() const { return GetField(38, 2); } + float shadowOffsetY() const { return GetField(40, -2); } + int32_t shadowBlurRadius() const { return GetField(42, 0); } bool Verify(flatbuffers::Verifier &verifier) const { return VerifyTableStart(verifier) && VerifyField(verifier, 4 /* widgetOptions */) && @@ -1097,20 +1108,21 @@ struct TextOptions : private flatbuffers::Table { VerifyField(verifier, 10 /* fontSize */) && VerifyField(verifier, 12 /* text */) && verifier.Verify(text()) && - VerifyField(verifier, 14 /* areaWidth */) && - VerifyField(verifier, 16 /* areaHeight */) && - VerifyField(verifier, 18 /* hAlignment */) && - VerifyField(verifier, 20 /* vAlignment */) && - VerifyField(verifier, 22 /* touchScaleEnable */) && - VerifyField(verifier, 24 /* isCustomSize */) && - VerifyField(verifier, 26 /* outlineEnabled */) && - VerifyField(verifier, 28 /* outlineColor */) && - VerifyField(verifier, 30 /* outlineSize */) && - VerifyField(verifier, 32 /* shadowEnabled */) && - VerifyField(verifier, 34 /* shadowColor */) && - VerifyField(verifier, 36 /* shadowOffsetX */) && - VerifyField(verifier, 38 /* shadowOffsetY */) && - VerifyField(verifier, 40 /* shadowBlurRadius */) && + VerifyField(verifier, 14 /* isLocalized */) && + VerifyField(verifier, 16 /* areaWidth */) && + VerifyField(verifier, 18 /* areaHeight */) && + VerifyField(verifier, 20 /* hAlignment */) && + VerifyField(verifier, 22 /* vAlignment */) && + VerifyField(verifier, 24 /* touchScaleEnable */) && + VerifyField(verifier, 26 /* isCustomSize */) && + VerifyField(verifier, 28 /* outlineEnabled */) && + VerifyField(verifier, 30 /* outlineColor */) && + VerifyField(verifier, 32 /* outlineSize */) && + VerifyField(verifier, 34 /* shadowEnabled */) && + VerifyField(verifier, 36 /* shadowColor */) && + VerifyField(verifier, 38 /* shadowOffsetX */) && + VerifyField(verifier, 40 /* shadowOffsetY */) && + VerifyField(verifier, 42 /* shadowBlurRadius */) && verifier.EndTable(); } }; @@ -1123,24 +1135,25 @@ struct TextOptionsBuilder { void add_fontName(flatbuffers::Offset fontName) { fbb_.AddOffset(8, fontName); } void add_fontSize(int32_t fontSize) { fbb_.AddElement(10, fontSize, 0); } void add_text(flatbuffers::Offset text) { fbb_.AddOffset(12, text); } - void add_areaWidth(int32_t areaWidth) { fbb_.AddElement(14, areaWidth, 0); } - void add_areaHeight(int32_t areaHeight) { fbb_.AddElement(16, areaHeight, 0); } - void add_hAlignment(int32_t hAlignment) { fbb_.AddElement(18, hAlignment, 0); } - void add_vAlignment(int32_t vAlignment) { fbb_.AddElement(20, vAlignment, 0); } - void add_touchScaleEnable(uint8_t touchScaleEnable) { fbb_.AddElement(22, touchScaleEnable, 0); } - void add_isCustomSize(uint8_t isCustomSize) { fbb_.AddElement(24, isCustomSize, 0); } - void add_outlineEnabled(uint8_t outlineEnabled) { fbb_.AddElement(26, outlineEnabled, 0); } - void add_outlineColor(const Color *outlineColor) { fbb_.AddStruct(28, outlineColor); } - void add_outlineSize(int32_t outlineSize) { fbb_.AddElement(30, outlineSize, 1); } - void add_shadowEnabled(uint8_t shadowEnabled) { fbb_.AddElement(32, shadowEnabled, 0); } - void add_shadowColor(const Color *shadowColor) { fbb_.AddStruct(34, shadowColor); } - void add_shadowOffsetX(float shadowOffsetX) { fbb_.AddElement(36, shadowOffsetX, 2); } - void add_shadowOffsetY(float shadowOffsetY) { fbb_.AddElement(38, shadowOffsetY, -2); } - void add_shadowBlurRadius(int32_t shadowBlurRadius) { fbb_.AddElement(40, shadowBlurRadius, 0); } + void add_isLocalized(uint8_t isLocalized) { fbb_.AddElement(14, isLocalized, 0); } + void add_areaWidth(int32_t areaWidth) { fbb_.AddElement(16, areaWidth, 0); } + void add_areaHeight(int32_t areaHeight) { fbb_.AddElement(18, areaHeight, 0); } + void add_hAlignment(int32_t hAlignment) { fbb_.AddElement(20, hAlignment, 0); } + void add_vAlignment(int32_t vAlignment) { fbb_.AddElement(22, vAlignment, 0); } + void add_touchScaleEnable(uint8_t touchScaleEnable) { fbb_.AddElement(24, touchScaleEnable, 0); } + void add_isCustomSize(uint8_t isCustomSize) { fbb_.AddElement(26, isCustomSize, 0); } + void add_outlineEnabled(uint8_t outlineEnabled) { fbb_.AddElement(28, outlineEnabled, 0); } + void add_outlineColor(const Color *outlineColor) { fbb_.AddStruct(30, outlineColor); } + void add_outlineSize(int32_t outlineSize) { fbb_.AddElement(32, outlineSize, 1); } + void add_shadowEnabled(uint8_t shadowEnabled) { fbb_.AddElement(34, shadowEnabled, 0); } + void add_shadowColor(const Color *shadowColor) { fbb_.AddStruct(36, shadowColor); } + void add_shadowOffsetX(float shadowOffsetX) { fbb_.AddElement(38, shadowOffsetX, 2); } + void add_shadowOffsetY(float shadowOffsetY) { fbb_.AddElement(40, shadowOffsetY, -2); } + void add_shadowBlurRadius(int32_t shadowBlurRadius) { fbb_.AddElement(42, shadowBlurRadius, 0); } TextOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } TextOptionsBuilder &operator=(const TextOptionsBuilder &); flatbuffers::Offset Finish() { - auto o = flatbuffers::Offset(fbb_.EndTable(start_, 19)); + auto o = flatbuffers::Offset(fbb_.EndTable(start_, 20)); return o; } }; @@ -1151,6 +1164,7 @@ inline flatbuffers::Offset CreateTextOptions(flatbuffers::FlatBuffe flatbuffers::Offset fontName = 0, int32_t fontSize = 0, flatbuffers::Offset text = 0, + uint8_t isLocalized = 0, int32_t areaWidth = 0, int32_t areaHeight = 0, int32_t hAlignment = 0, @@ -1185,6 +1199,7 @@ inline flatbuffers::Offset CreateTextOptions(flatbuffers::FlatBuffe builder_.add_outlineEnabled(outlineEnabled); builder_.add_isCustomSize(isCustomSize); builder_.add_touchScaleEnable(touchScaleEnable); + builder_.add_isLocalized(isLocalized); return builder_.Finish(); } @@ -1194,14 +1209,15 @@ struct TextFieldOptions : private flatbuffers::Table { const flatbuffers::String *fontName() const { return GetPointer(8); } int32_t fontSize() const { return GetField(10, 0); } const flatbuffers::String *text() const { return GetPointer(12); } - const flatbuffers::String *placeHolder() const { return GetPointer(14); } - uint8_t passwordEnabled() const { return GetField(16, 0); } - const flatbuffers::String *passwordStyleText() const { return GetPointer(18); } - uint8_t maxLengthEnabled() const { return GetField(20, 0); } - int32_t maxLength() const { return GetField(22, 0); } - int32_t areaWidth() const { return GetField(24, 0); } - int32_t areaHeight() const { return GetField(26, 0); } - uint8_t isCustomSize() const { return GetField(28, 0); } + uint8_t isLocalized() const { return GetField(14, 0); } + const flatbuffers::String *placeHolder() const { return GetPointer(16); } + uint8_t passwordEnabled() const { return GetField(18, 0); } + const flatbuffers::String *passwordStyleText() const { return GetPointer(20); } + uint8_t maxLengthEnabled() const { return GetField(22, 0); } + int32_t maxLength() const { return GetField(24, 0); } + int32_t areaWidth() const { return GetField(26, 0); } + int32_t areaHeight() const { return GetField(28, 0); } + uint8_t isCustomSize() const { return GetField(30, 0); } bool Verify(flatbuffers::Verifier &verifier) const { return VerifyTableStart(verifier) && VerifyField(verifier, 4 /* widgetOptions */) && @@ -1213,16 +1229,17 @@ struct TextFieldOptions : private flatbuffers::Table { VerifyField(verifier, 10 /* fontSize */) && VerifyField(verifier, 12 /* text */) && verifier.Verify(text()) && - VerifyField(verifier, 14 /* placeHolder */) && + VerifyField(verifier, 14 /* isLocalized */) && + VerifyField(verifier, 16 /* placeHolder */) && verifier.Verify(placeHolder()) && - VerifyField(verifier, 16 /* passwordEnabled */) && - VerifyField(verifier, 18 /* passwordStyleText */) && + VerifyField(verifier, 18 /* passwordEnabled */) && + VerifyField(verifier, 20 /* passwordStyleText */) && verifier.Verify(passwordStyleText()) && - VerifyField(verifier, 20 /* maxLengthEnabled */) && - VerifyField(verifier, 22 /* maxLength */) && - VerifyField(verifier, 24 /* areaWidth */) && - VerifyField(verifier, 26 /* areaHeight */) && - VerifyField(verifier, 28 /* isCustomSize */) && + VerifyField(verifier, 22 /* maxLengthEnabled */) && + VerifyField(verifier, 24 /* maxLength */) && + VerifyField(verifier, 26 /* areaWidth */) && + VerifyField(verifier, 28 /* areaHeight */) && + VerifyField(verifier, 30 /* isCustomSize */) && verifier.EndTable(); } }; @@ -1235,18 +1252,19 @@ struct TextFieldOptionsBuilder { void add_fontName(flatbuffers::Offset fontName) { fbb_.AddOffset(8, fontName); } void add_fontSize(int32_t fontSize) { fbb_.AddElement(10, fontSize, 0); } void add_text(flatbuffers::Offset text) { fbb_.AddOffset(12, text); } - void add_placeHolder(flatbuffers::Offset placeHolder) { fbb_.AddOffset(14, placeHolder); } - void add_passwordEnabled(uint8_t passwordEnabled) { fbb_.AddElement(16, passwordEnabled, 0); } - void add_passwordStyleText(flatbuffers::Offset passwordStyleText) { fbb_.AddOffset(18, passwordStyleText); } - void add_maxLengthEnabled(uint8_t maxLengthEnabled) { fbb_.AddElement(20, maxLengthEnabled, 0); } - void add_maxLength(int32_t maxLength) { fbb_.AddElement(22, maxLength, 0); } - void add_areaWidth(int32_t areaWidth) { fbb_.AddElement(24, areaWidth, 0); } - void add_areaHeight(int32_t areaHeight) { fbb_.AddElement(26, areaHeight, 0); } - void add_isCustomSize(uint8_t isCustomSize) { fbb_.AddElement(28, isCustomSize, 0); } + void add_isLocalized(uint8_t isLocalized) { fbb_.AddElement(14, isLocalized, 0); } + void add_placeHolder(flatbuffers::Offset placeHolder) { fbb_.AddOffset(16, placeHolder); } + void add_passwordEnabled(uint8_t passwordEnabled) { fbb_.AddElement(18, passwordEnabled, 0); } + void add_passwordStyleText(flatbuffers::Offset passwordStyleText) { fbb_.AddOffset(20, passwordStyleText); } + void add_maxLengthEnabled(uint8_t maxLengthEnabled) { fbb_.AddElement(22, maxLengthEnabled, 0); } + void add_maxLength(int32_t maxLength) { fbb_.AddElement(24, maxLength, 0); } + void add_areaWidth(int32_t areaWidth) { fbb_.AddElement(26, areaWidth, 0); } + void add_areaHeight(int32_t areaHeight) { fbb_.AddElement(28, areaHeight, 0); } + void add_isCustomSize(uint8_t isCustomSize) { fbb_.AddElement(30, isCustomSize, 0); } TextFieldOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } TextFieldOptionsBuilder &operator=(const TextFieldOptionsBuilder &); flatbuffers::Offset Finish() { - auto o = flatbuffers::Offset(fbb_.EndTable(start_, 13)); + auto o = flatbuffers::Offset(fbb_.EndTable(start_, 14)); return o; } }; @@ -1257,6 +1275,7 @@ inline flatbuffers::Offset CreateTextFieldOptions(flatbuffers: flatbuffers::Offset fontName = 0, int32_t fontSize = 0, flatbuffers::Offset text = 0, + uint8_t isLocalized = 0, flatbuffers::Offset placeHolder = 0, uint8_t passwordEnabled = 0, flatbuffers::Offset passwordStyleText = 0, @@ -1279,6 +1298,7 @@ inline flatbuffers::Offset CreateTextFieldOptions(flatbuffers: builder_.add_isCustomSize(isCustomSize); builder_.add_maxLengthEnabled(maxLengthEnabled); builder_.add_passwordEnabled(passwordEnabled); + builder_.add_isLocalized(isLocalized); return builder_.Finish(); } diff --git a/cocos/editor-support/cocostudio/FlatBuffersSerialize.cpp b/cocos/editor-support/cocostudio/FlatBuffersSerialize.cpp index 34aee128aa..a09fd0b44d 100644 --- a/cocos/editor-support/cocostudio/FlatBuffersSerialize.cpp +++ b/cocos/editor-support/cocostudio/FlatBuffersSerialize.cpp @@ -1615,8 +1615,10 @@ std::string FlatBuffersSerialize::serializeFlatBuffersWithXMLFileForLanguageData else if (strcmp(languageName.c_str(), childElement->Name()) == 0) { const char* langText = childElement->GetText(); - if (langText) + if (langText && langText[0] != '\0') text = langText; + else + text = key; hasTextReaded = true; } diff --git a/cocos/editor-support/cocostudio/LocalizationManager.cpp b/cocos/editor-support/cocostudio/LocalizationManager.cpp new file mode 100644 index 0000000000..79b42f0067 --- /dev/null +++ b/cocos/editor-support/cocostudio/LocalizationManager.cpp @@ -0,0 +1,168 @@ +#include "LocalizationManager.h" +#include "CCPlatformMacros.h" +#include "platform/CCFileUtils.h" +#include "editor-support/cocostudio/CSLanguageDataBinary_generated.h" + +using namespace cocostudio; +using namespace cocos2d; + +static JsonLocalizationManager* _sharedJsonLocalizationManager = nullptr; + +ILocalizationManager* JsonLocalizationManager::getInstance() +{ + if (!_sharedJsonLocalizationManager) + { + _sharedJsonLocalizationManager = new (std::nothrow) JsonLocalizationManager(); + } + + return _sharedJsonLocalizationManager; +} + +void JsonLocalizationManager::destroyInstance() +{ + if (_sharedJsonLocalizationManager != nullptr) + { + delete _sharedJsonLocalizationManager; + _sharedJsonLocalizationManager = nullptr; + } +} + +JsonLocalizationManager::JsonLocalizationManager() + :languageData(nullptr) +{ +} + +JsonLocalizationManager::~JsonLocalizationManager() +{ + CC_SAFE_DELETE(languageData); +} + +bool JsonLocalizationManager::initLanguageData(std::string file) +{ + bool result = false; + + std::string data = FileUtils::getInstance()->getStringFromFile(file); + if (!data.empty()) + { + if (!languageData) + languageData = new rapidjson::Document; + languageData->Parse(data.c_str()); + if (languageData->IsObject()) + result = true; + else + CC_SAFE_DELETE(languageData); + } + + return result; +} + +std::string JsonLocalizationManager::getLocalizationString(std::string key) +{ + std::string result = key; + + if (languageData && languageData->HasMember(key.c_str()) && + (*languageData)[key.c_str()].IsString()) + result = (*languageData)[key.c_str()].GetString(); + + return result; +} + + + +static BinLocalizationManager* _sharedBinLocalizationManager = nullptr; + +ILocalizationManager* BinLocalizationManager::getInstance() +{ + if (!_sharedBinLocalizationManager) + { + _sharedBinLocalizationManager = new (std::nothrow) BinLocalizationManager(); + } + + return _sharedBinLocalizationManager; +} + +void BinLocalizationManager::destroyInstance() +{ + if (_sharedBinLocalizationManager != nullptr) + { + delete _sharedBinLocalizationManager; + _sharedBinLocalizationManager = nullptr; + } +} + +BinLocalizationManager::BinLocalizationManager() +{ +} + +BinLocalizationManager::~BinLocalizationManager() +{ +} + +bool BinLocalizationManager::initLanguageData(std::string file) +{ + bool result = false; + languageData.clear(); + + Data buf = FileUtils::getInstance()->getDataFromFile(file); + if (!buf.isNull()) + { + auto lanSet = flatbuffers::GetLanguageSet(buf.getBytes()); + if (lanSet && lanSet->languageItems()->size() > 0) + { + result = true; + auto items = lanSet->languageItems(); + int count = items->size(); + for (int i = 0; i < count; i++) + { + auto it = items->Get(i); + std::string key = it->key()->c_str(); + std::string value = it->value()->c_str(); + if (!key.empty()) + languageData[key] = value; + } + } + } + + return result; +} + +std::string BinLocalizationManager::getLocalizationString(std::string key) +{ + std::string result = key; + + if (!languageData.empty()) + { + auto it = languageData.find(key); + if (it != languageData.end()) + result = it->second; + } + + return result; +} + + + +static bool isCurrentBinManager = true; +static ILocalizationManager* _sharedLocalizationManager = nullptr; + +ILocalizationManager* LocalizationHelper::getCurrentManager() +{ + if (!_sharedLocalizationManager) + { + _sharedLocalizationManager = BinLocalizationManager::getInstance(); + isCurrentBinManager = true; + } + + return _sharedLocalizationManager; +} + +void LocalizationHelper::setCurrentManager(ILocalizationManager* manager, bool isBinary) +{ + _sharedLocalizationManager = manager; + isCurrentBinManager = isBinary; +} + +bool LocalizationHelper::isBinManager() +{ + return isCurrentBinManager; +} \ No newline at end of file diff --git a/cocos/editor-support/cocostudio/LocalizationManager.h b/cocos/editor-support/cocostudio/LocalizationManager.h new file mode 100644 index 0000000000..d6973d4370 --- /dev/null +++ b/cocos/editor-support/cocostudio/LocalizationManager.h @@ -0,0 +1,105 @@ +#ifndef __LOCALLIZATION_MANAGER_H__ +#define __LOCALLIZATION_MANAGER_H__ + +#include +#include +#include "json/document.h" +#include "cocostudio/CocosStudioExport.h" + +namespace cocostudio { + /** + *@brief Localization string manager interface template. + */ + class ILocalizationManager + { + public: + virtual bool initLanguageData(std::string file) = 0; + virtual std::string getLocalizationString(std::string key) = 0; + }; + + /** + *@brief Localization string manager for output Json data file by cocostudio localization editor. + * Note: If changed localization data file manually, please make sure the data file save as + * text file format with encoding as 'UTF8 no BOM', otherwise the localization data may + * not been parse successfully. + */ + class CC_STUDIO_DLL JsonLocalizationManager : ILocalizationManager + { + public: + static ILocalizationManager* getInstance(); + static void destroyInstance(); + + public: + /* Init manager with special localize json data file. + * @param file Name of localize file. + * @return If manager initialize success return true. + */ + virtual bool initLanguageData(std::string file); + + /* Get localization string for special key. + * @param key Special key to search in localization data. + * @return If manager find the key in localization data, return value + * set to key, otherwise return key itself. + */ + virtual std::string getLocalizationString(std::string key); + + protected: + JsonLocalizationManager(); + ~JsonLocalizationManager(); + + protected: + rapidjson::Document * languageData; + }; + + class CC_STUDIO_DLL BinLocalizationManager : ILocalizationManager + { + public: + static ILocalizationManager* getInstance(); + static void destroyInstance(); + + /* Init manager with special localize binary data file. + * @param file Name of localize file. + * @return If manager initialize success return true. + */ + virtual bool initLanguageData(std::string file); + + /* Get localization string for special key. + * @param key Special key to search in localization data. + * @return If manager find the key in localization data, return value + * set to key, otherwise return key itself. + */ + virtual std::string getLocalizationString(std::string key); + + protected: + BinLocalizationManager(); + ~BinLocalizationManager(); + + protected: + std::unordered_map languageData; + }; + + class CC_STUDIO_DLL LocalizationHelper + { + public: + /* Get current localization manager. + * @return The instance of current localization manager. + * If the manager hasn't been set, it will return the singleton instance of BinLocalizationManager. + */ + static ILocalizationManager* getCurrentManager(); + + /* Set current localization manager. + * @param manager The instance of current manager. + * @param isBinary Wether the manager is binary localization manager. + * If the param is false, current manager will be set to JsonLocalizationManager. + */ + static void setCurrentManager(ILocalizationManager* manager, bool isBinary); + + /* Get the type of current localization manager. + * @return If current manager is BinLocalizationManager, return true. + * Otherwise return false, that means current manager is JsonLocalizationManager. + */ + static bool isBinManager(); + }; +} + +#endif //__LOCALLIZATION_MANAGER_H__ \ No newline at end of file diff --git a/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp index 6d1a41ebe7..c3289cba02 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp @@ -6,6 +6,7 @@ #include "cocostudio/CocoLoader.h" #include "cocostudio/CSParseBinary_generated.h" #include "cocostudio/FlatBuffersSerialize.h" +#include "cocostudio/LocalizationManager.h" #include "tinyxml2.h" #include "flatbuffers/flatbuffers.h" @@ -253,6 +254,7 @@ namespace cocostudio bool scale9Enabled = false; Rect capInsets; std::string text = ""; + bool isLocalized = false; int fontSize = 14; std::string fontName = ""; cocos2d::Size scale9Size; @@ -316,6 +318,10 @@ namespace cocostudio { text = value; } + else if (name == "IsLocalized") + { + isLocalized = (value == "True") ? true : false; + } else if (name == "FontSize") { fontSize = atoi(value.c_str()); @@ -624,6 +630,7 @@ namespace cocostudio builder->CreateString(fontResourcePlistFile), fontResourceResourceType), builder->CreateString(text), + isLocalized, builder->CreateString(fontName), fontSize, &f_textColor, @@ -824,7 +831,16 @@ namespace cocostudio } std::string titleText = options->text()->c_str(); - button->setTitleText(titleText); + bool isLocalized = options->isLocalized() != 0; + if (isLocalized) + { + ILocalizationManager* lm = LocalizationHelper::getCurrentManager(); + button->setTitleText(lm->getLocalizationString(titleText)); + } + else + { + button->setTitleText(titleText); + } auto textColor = options->textColor(); Color3B titleColor(textColor->r(), textColor->g(), textColor->b()); diff --git a/cocos/editor-support/cocostudio/WidgetReader/TextBMFontReader/TextBMFontReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/TextBMFontReader/TextBMFontReader.cpp index 1bf03ec09d..8207e91b38 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/TextBMFontReader/TextBMFontReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/TextBMFontReader/TextBMFontReader.cpp @@ -6,6 +6,7 @@ #include "ui/UITextBMFont.h" #include "cocostudio/CocoLoader.h" #include "cocostudio/CSParseBinary_generated.h" +#include "cocostudio/LocalizationManager.h" #include "tinyxml2.h" #include "flatbuffers/flatbuffers.h" @@ -124,6 +125,7 @@ namespace cocostudio auto widgetOptions = *(Offset*)(&temp); std::string text = "Fnt Text Label"; + bool isLocalized = false; std::string path = ""; std::string plistFlie = ""; @@ -140,6 +142,10 @@ namespace cocostudio { text = value; } + else if (name == "IsLocalized") + { + isLocalized = (value == "True") ? true : false; + } attribute = attribute->Next(); } @@ -185,7 +191,8 @@ namespace cocostudio builder->CreateString(path), builder->CreateString(plistFlie), resourceType), - builder->CreateString(text)); + builder->CreateString(text), + isLocalized); return *(Offset*)(&options); } @@ -230,7 +237,16 @@ namespace cocostudio } std::string text = options->text()->c_str(); - labelBMFont->setString(text); + bool isLocalized = options->isLocalized() != 0; + if (isLocalized) + { + ILocalizationManager* lm = LocalizationHelper::getCurrentManager(); + labelBMFont->setString(lm->getLocalizationString(text)); + } + else + { + labelBMFont->setString(text); + } auto widgetReader = WidgetReader::getInstance(); widgetReader->setPropsWithFlatBuffers(node, (Table*)options->widgetOptions()); diff --git a/cocos/editor-support/cocostudio/WidgetReader/TextFieldReader/TextFieldReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/TextFieldReader/TextFieldReader.cpp index 95293bd2a5..cf7ffd3a3b 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/TextFieldReader/TextFieldReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/TextFieldReader/TextFieldReader.cpp @@ -5,6 +5,7 @@ #include "ui/UITextField.h" #include "cocostudio/CocoLoader.h" #include "cocostudio/CSParseBinary_generated.h" +#include "cocostudio/LocalizationManager.h" #include "tinyxml2.h" #include "flatbuffers/flatbuffers.h" @@ -164,6 +165,7 @@ namespace cocostudio std::string fontName = ""; int fontSize = 20; std::string text = ""; + bool isLocalized = false; std::string placeHolder = "Text Field"; bool passwordEnabled = false; std::string passwordStyleText = "*"; @@ -189,6 +191,10 @@ namespace cocostudio { text = value; } + else if (name == "IsLocalized") + { + isLocalized = (value == "True") ? true : false; + } else if (name == "FontSize") { fontSize = atoi(value.c_str()); @@ -266,6 +272,7 @@ namespace cocostudio builder->CreateString(fontName), fontSize, builder->CreateString(text), + isLocalized, builder->CreateString(placeHolder), passwordEnabled, builder->CreateString(passwordStyleText), @@ -288,7 +295,16 @@ namespace cocostudio textField->setPlaceHolder(placeholder); std::string text = options->text()->c_str(); - textField->setString(text); + bool isLocalized = options->isLocalized() != 0; + if (isLocalized) + { + ILocalizationManager* lm = LocalizationHelper::getCurrentManager(); + textField->setString(lm->getLocalizationString(text)); + } + else + { + textField->setString(text); + } int fontSize = options->fontSize(); textField->setFontSize(fontSize); diff --git a/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.cpp index 962ad2b66f..e0def35086 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.cpp @@ -5,6 +5,7 @@ #include "ui/UIText.h" #include "cocostudio/CocoLoader.h" #include "cocostudio/CSParseBinary_generated.h" +#include "cocostudio/LocalizationManager.h" #include "tinyxml2.h" #include "flatbuffers/flatbuffers.h" @@ -160,6 +161,7 @@ namespace cocostudio std::string fontName = ""; int fontSize = 20; std::string text = "Text Label"; + bool isLocalized = false; int areaWidth = 0; int areaHeight = 0; int h_alignment = 0; @@ -191,6 +193,10 @@ namespace cocostudio { text = value; } + else if (name == "IsLocalized") + { + isLocalized = (value == "True") ? true : false; + } else if (name == "FontSize") { fontSize = atoi(value.c_str()); @@ -374,6 +380,7 @@ namespace cocostudio builder->CreateString(fontName), fontSize, builder->CreateString(text), + isLocalized, areaWidth, areaHeight, h_alignment, @@ -450,7 +457,16 @@ namespace cocostudio } std::string text = options->text()->c_str(); - label->setString(text); + bool isLocalized = options->isLocalized() != 0; + if (isLocalized) + { + ILocalizationManager* lm = LocalizationHelper::getCurrentManager(); + label->setString(lm->getLocalizationString(text)); + } + else + { + label->setString(text); + } // Save node color before set widget properties auto oldColor = node->getColor(); diff --git a/tests/cpp-empty-test/Classes/AppDelegate.cpp b/tests/cpp-empty-test/Classes/AppDelegate.cpp index 740b147211..de99db9aff 100644 --- a/tests/cpp-empty-test/Classes/AppDelegate.cpp +++ b/tests/cpp-empty-test/Classes/AppDelegate.cpp @@ -6,6 +6,9 @@ #include "HelloWorldScene.h" #include "AppMacros.h" +//Uncomment the following line to use localize manager +//#include "editor-support/cocostudio/LocalizationManager.h" + USING_NS_CC; using namespace std; @@ -71,7 +74,23 @@ bool AppDelegate::applicationDidFinishLaunching() { // set searching path FileUtils::getInstance()->setSearchPaths(searchPath); - + + // Uncomment follow block to use localize manager to set localize strings + + // If you want to load json localize data, use follow block + /* + cocostudio::ILocalizationManager * lm = cocostudio::JsonLocalizationManager::getInstance(); + lm->initLanguageData("your localize file name.lang.json"); + cocostudio::LocalizationHelper::setCurrentManager(lm, false); + */ + + // If you want to load binary localize data, use follow block + /* + cocostudio::ILocalizationManager * lm = cocostudio::BinLocalizationManager::getInstance(); + lm->initLanguageData("your localize file name.lang.csb"); + cocostudio::LocalizationHelper::setCurrentManager(lm, true); + */ + // turn on display FPS director->setDisplayStats(true); diff --git a/tests/cpp-tests/Classes/LabelTest/LabelTestNew.cpp b/tests/cpp-tests/Classes/LabelTest/LabelTestNew.cpp index 7410b5e7c7..1391669611 100644 --- a/tests/cpp-tests/Classes/LabelTest/LabelTestNew.cpp +++ b/tests/cpp-tests/Classes/LabelTest/LabelTestNew.cpp @@ -105,6 +105,8 @@ NewLabelTests::NewLabelTests() ADD_TEST_CASE(LabelUnderlineMultiline); ADD_TEST_CASE(LabelItalics); ADD_TEST_CASE(LabelBold); + + ADD_TEST_CASE(LabelLocalizationTest); }; LabelFNTColorAndOpacity::LabelFNTColorAndOpacity() @@ -3053,3 +3055,109 @@ std::string LabelStrikethrough::subtitle() const return "Strikethrough on TTF and BMfont with multiline"; } +LabelLocalizationTest::LabelLocalizationTest() +{ + _localizationJson = cocostudio::JsonLocalizationManager::getInstance(); + _localizationJson->initLanguageData("configs/en-US.lang.json"); + + _localizationBin = cocostudio::BinLocalizationManager::getInstance(); + _localizationBin->initLanguageData("configs/ENGLISH.lang.csb"); + + const float BUTTON_WIDTH = 100; + float startPosX = 0; + Size winSize = Director::getInstance()->getVisibleSize(); + + // Create a radio button group + auto radioButtonGroup = RadioButtonGroup::create(); + this->addChild(radioButtonGroup); + + // Create the radio buttons + const int NUMBER_OF_BUTTONS = 3; + startPosX = winSize.width / 2.0f - (NUMBER_OF_BUTTONS - 1) * 0.5 * BUTTON_WIDTH - 30; + std::vector labelTypes = { "English", "Chinese", "Japanese" }; + + for (int i = 0; i < NUMBER_OF_BUTTONS; ++i) + { + RadioButton* radioButton = RadioButton::create("cocosui/radio_button_off.png", "cocosui/radio_button_on.png"); + float posX = startPosX + BUTTON_WIDTH * i; + radioButton->setPosition(Vec2(posX, winSize.height / 2.0f + 70)); + radioButton->setScale(1.2f); + radioButton->addEventListener(CC_CALLBACK_2(LabelLocalizationTest::onChangedRadioButtonSelect, this)); + radioButton->setTag(i); + radioButtonGroup->addRadioButton(radioButton); + this->addChild(radioButton); + + auto label = Label::createWithSystemFont(labelTypes.at(i), "Arial", 20); + label->setPosition(radioButton->getPosition() + Vec2(50, 0)); + this->addChild(label); + } + + _label1 = Label::createWithSystemFont(_localizationJson->getLocalizationString("Text Label"), "Arial", 24); + addChild(_label1, 0); + _label1->setPosition(Vec2(winSize.width / 2, winSize.height * 1 / 3)); + + Label * label = Label::createWithSystemFont("From json data :", "Arial", 24); + label->setAnchorPoint(Vec2(0, 0.5)); + addChild(label, 0); + label->setPosition(Vec2(20, winSize.height * 1 / 3 + 24)); + + _label2 = Label::createWithSystemFont(_localizationBin->getLocalizationString("Text Label"), "Arial", 24); + addChild(_label2, 0); + _label2->setPosition(Vec2(winSize.width / 2, winSize.height * 1 / 2)); + + label = Label::createWithSystemFont("From binary data :", "Arial", 24); + label->setAnchorPoint(Vec2(0, 0.5)); + addChild(label, 0); + label->setPosition(Vec2(20, winSize.height * 1 / 2 + 24)); +} + +std::string LabelLocalizationTest::title() const +{ + return "Localization Test"; +} + +std::string LabelLocalizationTest::subtitle() const +{ + return "Change language selected and see label change"; +} + + +void LabelLocalizationTest::onChangedRadioButtonSelect(RadioButton* radioButton, RadioButton::EventType type) +{ + if (radioButton == nullptr) + { + return; + } + + switch (type) + { + case RadioButton::EventType::SELECTED: + { + switch (radioButton->getTag()) { + case 0: + _localizationJson->initLanguageData("configs/en-US.lang.json"); + _label1->setString(_localizationJson->getLocalizationString("Text Label")); + _localizationBin->initLanguageData("configs/ENGLISH.lang.csb"); + _label2->setString(_localizationJson->getLocalizationString("Text Label")); + break; + case 1: + _localizationJson->initLanguageData("configs/zh-CN.lang.json"); + _label1->setString(_localizationJson->getLocalizationString("Text Label")); + _localizationBin->initLanguageData("configs/CHINESE.lang.csb"); + _label2->setString(_localizationJson->getLocalizationString("Text Label")); + break; + case 2: + _localizationJson->initLanguageData("configs/ja-JP.lang.json"); + _label1->setString(_localizationJson->getLocalizationString("Text Label")); + _localizationBin->initLanguageData("configs/JAPANESE.lang.csb"); + _label2->setString(_localizationJson->getLocalizationString("Text Label")); + break; + default: + break; + } + break; + } + default: + break; + } +} diff --git a/tests/cpp-tests/Classes/LabelTest/LabelTestNew.h b/tests/cpp-tests/Classes/LabelTest/LabelTestNew.h index 5374eea23e..779c41b5e9 100644 --- a/tests/cpp-tests/Classes/LabelTest/LabelTestNew.h +++ b/tests/cpp-tests/Classes/LabelTest/LabelTestNew.h @@ -5,6 +5,7 @@ #include "renderer/CCCustomCommand.h" #include "ui/CocosGUI.h" #include "extensions/cocos-ext.h" +#include "editor-support/cocostudio/LocalizationManager.h" DEFINE_TEST_SUITE(NewLabelTests); @@ -842,4 +843,21 @@ public: cocos2d::Label* _label2a; }; +class LabelLocalizationTest : public AtlasDemoNew +{ +public: + CREATE_FUNC(LabelLocalizationTest); + + LabelLocalizationTest(); + void onChangedRadioButtonSelect(cocos2d::ui::RadioButton* radioButton, cocos2d::ui::RadioButton::EventType type); + + virtual std::string title() const override; + virtual std::string subtitle() const override; + + cocos2d::Label* _label1; + cocos2d::Label* _label2; + cocostudio::ILocalizationManager* _localizationJson; + cocostudio::ILocalizationManager* _localizationBin; +}; + #endif diff --git a/tests/cpp-tests/Resources/configs/CHINESE.lang.csb b/tests/cpp-tests/Resources/configs/CHINESE.lang.csb new file mode 100644 index 0000000000..aa6a4eb12f Binary files /dev/null and b/tests/cpp-tests/Resources/configs/CHINESE.lang.csb differ diff --git a/tests/cpp-tests/Resources/configs/ENGLISH.lang.csb b/tests/cpp-tests/Resources/configs/ENGLISH.lang.csb new file mode 100644 index 0000000000..25c21b03a6 Binary files /dev/null and b/tests/cpp-tests/Resources/configs/ENGLISH.lang.csb differ diff --git a/tests/cpp-tests/Resources/configs/JAPANESE.lang.csb b/tests/cpp-tests/Resources/configs/JAPANESE.lang.csb new file mode 100644 index 0000000000..aa403da18f Binary files /dev/null and b/tests/cpp-tests/Resources/configs/JAPANESE.lang.csb differ diff --git a/tests/cpp-tests/Resources/configs/en-US.lang.json b/tests/cpp-tests/Resources/configs/en-US.lang.json new file mode 100644 index 0000000000..2ebcecf8ce --- /dev/null +++ b/tests/cpp-tests/Resources/configs/en-US.lang.json @@ -0,0 +1,3 @@ +{ + "Text Label": "Text Label" +} \ No newline at end of file diff --git a/tests/cpp-tests/Resources/configs/ja-JP.lang.json b/tests/cpp-tests/Resources/configs/ja-JP.lang.json new file mode 100644 index 0000000000..3fbdb28493 --- /dev/null +++ b/tests/cpp-tests/Resources/configs/ja-JP.lang.json @@ -0,0 +1,3 @@ +{ + "Text Label": "テキストラベル" +} \ No newline at end of file diff --git a/tests/cpp-tests/Resources/configs/zh-CN.lang.json b/tests/cpp-tests/Resources/configs/zh-CN.lang.json new file mode 100644 index 0000000000..147e2cb637 --- /dev/null +++ b/tests/cpp-tests/Resources/configs/zh-CN.lang.json @@ -0,0 +1,3 @@ +{ + "Text Label": "文本标签" +} \ No newline at end of file diff --git a/tools/simulator/libsimulator/lib/ProjectConfig/ProjectConfig.cpp b/tools/simulator/libsimulator/lib/ProjectConfig/ProjectConfig.cpp index 5fc21757bf..bd6a1c3233 100644 --- a/tools/simulator/libsimulator/lib/ProjectConfig/ProjectConfig.cpp +++ b/tools/simulator/libsimulator/lib/ProjectConfig/ProjectConfig.cpp @@ -434,6 +434,12 @@ void ProjectConfig::parseCommandLine(const vector &args) setUseLocalScript(false); } } + else if (arg.compare("-language-data-path") == 0) + { + ++it; + if (it == args.end()) break; + setLanguageDataPath(*it); + } ++it; } } @@ -652,6 +658,26 @@ const vector &ProjectConfig::getSearchPath() const return _searchPath; } +void ProjectConfig::setLanguageDataPath(const std::string &filePath) +{ + bool isBinary = true; + string jsonExtension = ".json"; + int exLength = jsonExtension.length(); + if (filePath.length() >= exLength && + (0 == filePath.compare(filePath.length() - exLength, exLength, jsonExtension))) + { + isBinary = false; + } + + cocostudio::ILocalizationManager* lm; + if (isBinary) + lm = cocostudio::BinLocalizationManager::getInstance(); + else + lm = cocostudio::JsonLocalizationManager::getInstance(); + lm->initLanguageData(filePath); + cocostudio::LocalizationHelper::setCurrentManager(lm, isBinary); +} + bool ProjectConfig::isAppMenu() const { return _isAppMenu; diff --git a/tools/simulator/libsimulator/lib/ProjectConfig/ProjectConfig.h b/tools/simulator/libsimulator/lib/ProjectConfig/ProjectConfig.h index da81a921b3..734cca8939 100644 --- a/tools/simulator/libsimulator/lib/ProjectConfig/ProjectConfig.h +++ b/tools/simulator/libsimulator/lib/ProjectConfig/ProjectConfig.h @@ -105,6 +105,7 @@ public: const std::string &getBindAddress() const; void setSearchPath(const vector &args); const vector &getSearchPath() const; + void setLanguageDataPath(const std::string &filePath); bool isUseLocalScript() const; void setUseLocalScript(bool useLocalScript); @@ -138,6 +139,7 @@ private: string _bindAddress; vector _searchPath; bool _useLocalScript; + string _languageDataPath; void normalize(); string replaceProjectDirToMacro(const string &path) const;