diff --git a/resources/langs/ja-JP.json b/resources/lang/ja-JP.json similarity index 85% rename from resources/langs/ja-JP.json rename to resources/lang/ja-JP.json index c247ccc6..e6502220 100644 --- a/resources/langs/ja-JP.json +++ b/resources/lang/ja-JP.json @@ -12,5 +12,8 @@ "glow-col": 12, "death-effect-id": 3 } - ] + ], + "strings": { + "Noclip": "ノークリップ" + } } \ No newline at end of file diff --git a/resources/sprites/banner-mask.png b/resources/sprites/banner-mask.png new file mode 100644 index 00000000..895ff540 Binary files /dev/null and b/resources/sprites/banner-mask.png differ diff --git a/src/Client/Client.cpp b/src/Client/Client.cpp index fb3efdf6..ea5389cd 100644 --- a/src/Client/Client.cpp +++ b/src/Client/Client.cpp @@ -1,5 +1,6 @@ #include "Client.h" #include "../Utils/LaunchArgs.hpp" +#include "../Utils/TranslationManager.hpp" #include Client* Client::get() @@ -7,6 +8,13 @@ Client* Client::get() return instance; } +Client::Client() +{ + mod = Mod::get(); + + setLanguage(Mod::get()->getSavedValue("loaded-translation", "none")); +} + bool Client::handleKeybinds(enumKeyCodes key, bool isDown, bool isRepeatedKey) { if (!isDown || key == enumKeyCodes::KEY_Unknown) @@ -157,6 +165,22 @@ void Client::drawImGui() } } +void Client::setLanguage(std::string langFile) +{ + auto path = Mod::get()->getResourcesDir() / langFile; + + if (std::filesystem::exists(path)) + { + TranslationManager::get()->loadTranslationFromJson(file::readJson(path).unwrapOr("{ }")); + } + else + { + TranslationManager::get()->unloadTranslation(); + } + + Mod::get()->setSavedValue("loaded-translation", langFile); +} + void Client::sortWindows(bool instant) { float offset = ini->getKeyValueFloat("Offsets::WindowDistance", "15"); diff --git a/src/Client/Client.h b/src/Client/Client.h index 64089a97..d0cad8f9 100644 --- a/src/Client/Client.h +++ b/src/Client/Client.h @@ -48,10 +48,7 @@ class Client SimpleINI* ini = nullptr; ImVec2 widgetSize = ImVec2(215, 25); - Client() - { - mod = Mod::get(); - } + Client(); static Client* get(); @@ -69,6 +66,8 @@ class Client void setUIScale(float scale); + void setLanguage(std::string langFile); + //[[deprecated("GetModuleEnabled has been deprecated due to lag, please rember to cache the module :3")]] static bool GetModuleEnabled(std::string id) { diff --git a/src/Layers/TranslationCreditsLayer.cpp b/src/Layers/TranslationCreditsLayer.cpp index 1f3548b9..3c8085dd 100644 --- a/src/Layers/TranslationCreditsLayer.cpp +++ b/src/Layers/TranslationCreditsLayer.cpp @@ -17,18 +17,15 @@ void TranslationCreditsLayer::customSetup() langNode->setLayout(AxisLayout::create()->setGap(20)); - auto stencil = CCScale9Sprite::create("GJ_square01.png"); - stencil->setContentSize(size + ccp(0, -30)); - stencil->setAnchorPoint(ccp(0.5f, 0)); - - auto stencilTop = CCLayerColor::create(ccc4(255, 255, 255, 255), size.x, 30); - stencilTop->setAnchorPoint(ccp(0.5f, 1)); - stencilTop->ignoreAnchorPointForPosition(false); - stencil->addChildAtPosition(stencilTop, Anchor::Top); + auto stencil = CCScale9Sprite::create("banner-mask.png"_spr); + stencil->setContentSize(size + ccp(0, -32)); + stencil->setAnchorPoint(ccp(0.5f, 1)); + stencil->setScaleY(-1); auto clip = CCClippingNode::create(stencil); clip->setAlphaThreshold(0.03f); clip->setAnchorPoint(ccp(0.5f, 0)); + clip->setZOrder(3); auto clipOutline = CCScale9Sprite::create("GJ_square07.png"); clipOutline->setContentSize(size); @@ -48,9 +45,14 @@ void TranslationCreditsLayer::customSetup() clip->addChild(background, -2); clip->addChild(ground, -1); - baseLayer->addChildAtPosition(langNode, Anchor::Top, ccp(0, -16)); + baseLayer->addChildAtPosition(langNode, Anchor::Top, ccp(0, -18)); baseLayer->addChildAtPosition(clip, Anchor::Bottom); + auto clipLine = CCLayerColor::create(ccc4(255, 255, 255, 255), size.x, 30); + clipLine->setAnchorPoint(ccp(0.5f, 1)); + clipLine->ignoreAnchorPointForPosition(false); + baseLayer->addChildAtPosition(clipLine, Anchor::Bottom, ccp(0, stencil->getContentHeight() + 1.5f)); + auto gameNode = CCMenu::create(); gameNode->ignoreAnchorPointForPosition(false); gameNode->setContentSize(ccp(0, 0)); @@ -61,6 +63,7 @@ void TranslationCreditsLayer::customSetup() creditsMenu->setContentWidth(320); creditsMenu->setAnchorPoint(ccp(0.5f, 1)); creditsMenu->setLayout(AxisLayout::create()->setGrowCrossAxis(true)->setCrossAxisAlignment(AxisAlignment::Start)); + creditsMenu->setZOrder(6); for (auto contributor : language["contributors"].asArray().unwrap()) { @@ -106,7 +109,7 @@ void TranslationCreditsLayer::customSetup() creditsMenu->updateLayout(); clip->addChild(gameNode); - baseLayer->addChildAtPosition(creditsMenu, Anchor::Top, ccp(0, -42.5f)); + baseLayer->addChildAtPosition(creditsMenu, Anchor::Top, ccp(0, -45)); ok->setZOrder(420); } diff --git a/src/UI/TransLabelBMFont.cpp b/src/UI/TransLabelBMFont.cpp index c9f257bc..7916ac73 100644 --- a/src/UI/TransLabelBMFont.cpp +++ b/src/UI/TransLabelBMFont.cpp @@ -9,9 +9,6 @@ bool TransLabelBMFont::init(std::string text, std::string font) text = TranslationManager::get()->getTranslatedString(text); - if (text == "Noclip") - text = "ノークリップ"; - this->text = text; this->font = text; diff --git a/src/UI/TransLabelBMFont.hpp b/src/UI/TransLabelBMFont.hpp index bd4cda5c..fb4db359 100644 --- a/src/UI/TransLabelBMFont.hpp +++ b/src/UI/TransLabelBMFont.hpp @@ -4,6 +4,7 @@ using namespace geode::prelude; +// they call this my gender class TransLabelBMFont : public CCNode { private: diff --git a/src/Utils/TranslationManager.cpp b/src/Utils/TranslationManager.cpp index 235d1aae..9ce6cbd6 100644 --- a/src/Utils/TranslationManager.cpp +++ b/src/Utils/TranslationManager.cpp @@ -10,11 +10,21 @@ TranslationManager* TranslationManager::get() return instance; } -void TranslationManager::loadTranslationFromJson(matjson::Value object) +void TranslationManager::unloadTranslation() { translatedTexts = {}; +} + +void TranslationManager::loadTranslationFromJson(matjson::Value object) +{ + unloadTranslation(); + + if (!object.contains("strings")) + return; + + auto strings = object["strings"]; - for (auto value : object) + for (auto value : strings) { if (value.isString() && value.getKey().has_value()) { diff --git a/src/Utils/TranslationManager.hpp b/src/Utils/TranslationManager.hpp index 55ad78d6..10ae399c 100644 --- a/src/Utils/TranslationManager.hpp +++ b/src/Utils/TranslationManager.hpp @@ -12,6 +12,7 @@ class TranslationManager public: static TranslationManager* get(); + void unloadTranslation(); void loadTranslationFromJson(matjson::Value object); std::string getTranslatedString(std::string engText); }; \ No newline at end of file