From 6e521284becfa391dc4f43571f5b669eb07049be Mon Sep 17 00:00:00 2001 From: TheSillyDoggo Date: Wed, 11 Dec 2024 18:53:18 +1100 Subject: [PATCH] This was a triumph. im making a note here, huge success --- mod.json | 2 +- resources/{lang => }/ja-JP.json | 0 resources/translations | 2 +- src/Client/Client.cpp | 18 +++ src/Client/Client.h | 1 + src/Layers/LanguageSelectNode.cpp | 110 ++++++++++++++ src/Layers/LanguageSelectNode.hpp | 27 ++++ src/Layers/SillyBaseLayer.cpp | 5 +- src/Layers/TranslationCreditsLayer.cpp | 196 +++++++++++++++++++++---- src/Layers/TranslationCreditsLayer.hpp | 9 +- src/UI/CategoryTabSprite.cpp | 2 +- src/UI/CategoryTabSprite.hpp | 3 +- src/UI/TransLabelBMFont.cpp | 13 ++ src/UI/TransLabelBMFont.hpp | 4 + src/Utils/TranslationManager.cpp | 15 ++ src/Utils/TranslationManager.hpp | 5 + 16 files changed, 373 insertions(+), 39 deletions(-) rename resources/{lang => }/ja-JP.json (100%) create mode 100644 src/Layers/LanguageSelectNode.cpp create mode 100644 src/Layers/LanguageSelectNode.hpp diff --git a/mod.json b/mod.json index 35bfa75c..4823731a 100644 --- a/mod.json +++ b/mod.json @@ -25,7 +25,7 @@ "resources/*.wav", "resources/*.md", "resources/*.ini", - "resources/langs/*.json" + "resources/translations/langs/*.json" ], "sprites": [ "resources/sprites/*.png" diff --git a/resources/lang/ja-JP.json b/resources/ja-JP.json similarity index 100% rename from resources/lang/ja-JP.json rename to resources/ja-JP.json diff --git a/resources/translations b/resources/translations index d19b7ea4..68bd79ae 160000 --- a/resources/translations +++ b/resources/translations @@ -1 +1 @@ -Subproject commit d19b7ea498f4c14098db0b191f9de98796469512 +Subproject commit 68bd79ae4dabf28653769ceed8c545ae5b3883ad diff --git a/src/Client/Client.cpp b/src/Client/Client.cpp index ea5389cd..94aba023 100644 --- a/src/Client/Client.cpp +++ b/src/Client/Client.cpp @@ -2,6 +2,7 @@ #include "../Utils/LaunchArgs.hpp" #include "../Utils/TranslationManager.hpp" #include +#include Client* Client::get() { @@ -181,6 +182,23 @@ void Client::setLanguage(std::string langFile) Mod::get()->setSavedValue("loaded-translation", langFile); } +std::vector Client::getLanguages() +{ + std::vector files; + + for (auto file : std::filesystem::directory_iterator(Mod::get()->getResourcesDir())) + { + auto p = file.path().filename(); + + if (p.has_extension() && p.extension().string() == ".json") + { + files.push_back(file); + } + } + + return files; +} + 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 d0cad8f9..8ba8e241 100644 --- a/src/Client/Client.h +++ b/src/Client/Client.h @@ -67,6 +67,7 @@ class Client void setUIScale(float scale); void setLanguage(std::string langFile); + std::vector getLanguages(); //[[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/LanguageSelectNode.cpp b/src/Layers/LanguageSelectNode.cpp new file mode 100644 index 00000000..0c55bebd --- /dev/null +++ b/src/Layers/LanguageSelectNode.cpp @@ -0,0 +1,110 @@ +#include "LanguageSelectNode.hpp" +#include "../Utils/UnspeedhackedAction.hpp" + +bool LanguageSelectNode::init() +{ + if (!CCNode::init()) + return false; + + this->setContentSize(CCDirector::get()->getWinSize()); + this->setAnchorPoint(CCPointZero); + this->setKeypadEnabled(true); + + auto colBG = CCLayerColor::create(ccc4(0, 0, 0, 0)); + colBG->ignoreAnchorPointForPosition(false); + colBG->setAnchorPoint(ccp(1, 1)); + colBG->runAction(CCFadeTo::create(0.5f, 100)); + + node = CCMenu::create(); + node->ignoreAnchorPointForPosition(false); + node->setContentSize(CCPointZero); + node->setScale(0); + node->runAction(UnspeedhackedAction::create(CCEaseElasticOut::create(CCScaleTo::create(0.5f, 1), 0.6f))); + + auto leftBtn = CCMenuItemSpriteExtra::create(CCSprite::createWithSpriteFrameName("GJ_arrow_01_001.png"), this, menu_selector(LanguageSelectNode::onLeft)); + leftBtn->setZOrder(420); + node->addChildAtPosition(leftBtn, Anchor::BottomLeft, ccp(-190, 0)); + + auto rightBtn = CCMenuItemSpriteExtra::create(CCSprite::createWithSpriteFrameName("GJ_arrow_01_001.png"), this, menu_selector(LanguageSelectNode::onRight)); + rightBtn->getNormalImage()->setScaleX(-1); + rightBtn->setZOrder(420); + node->addChildAtPosition(rightBtn, Anchor::BottomLeft, ccp(190, 0)); + + node->setTouchPriority(-999999); + + goToPage(0); + + this->addChild(colBG); + this->addChildAtPosition(node, Anchor::Center); + return true; +} + +void LanguageSelectNode::goToPage(int page) +{ + this->page = page; + + if (layer) + { + layer->removeFromParent(); + layer = nullptr; + } + + auto langs = Client::get()->getLanguages(); + + if (page == 0) + layer = TranslationCreditsLayer::create(matjson::parse("{ \"display_name_english\": \"Default\", \"display_name_native\": \"English\", \"contributors\": [] }").unwrapOr("{}"), "none"); + else + layer = TranslationCreditsLayer::create(file::readJson(langs[page - 1]).unwrap(), langs[page - 1]); + + layer->setPosition(CCDirector::get()->getWinSize() * -0.5f); + layer->stopAllActions(); + layer->setOpacity(0); + layer->setKeypadEnabled(false); + layer->setKeyboardEnabled(false); + + layer->baseLayer->stopActionByTag(69); + layer->baseLayer->setScale(1); + + layer->ok->setTarget(this, menu_selector(LanguageSelectNode::onSubmit)); + + node->addChild(layer, 420); +} + +void LanguageSelectNode::onLeft(CCObject* sender) +{ + page--; + + if (page < 0) + page = Client::get()->getLanguages().size(); + + goToPage(page); +} + +void LanguageSelectNode::onRight(CCObject* sender) +{ + page++; + + if (page > Client::get()->getLanguages().size()) + page = 0; + + goToPage(page); +} + +void LanguageSelectNode::onSubmit(CCObject* sender) +{ + keyBackClicked(); +} + +void LanguageSelectNode::keyBackClicked() +{ + this->removeFromParent(); +} + +LanguageSelectNode* LanguageSelectNode::addToScene() +{ + auto pRet = LanguageSelectNode::create(); + + CCScene::get()->addChild(pRet, 99999); + + return pRet; +} \ No newline at end of file diff --git a/src/Layers/LanguageSelectNode.hpp b/src/Layers/LanguageSelectNode.hpp new file mode 100644 index 00000000..a037cc2a --- /dev/null +++ b/src/Layers/LanguageSelectNode.hpp @@ -0,0 +1,27 @@ +#pragma once + +#include +#include "TranslationCreditsLayer.hpp" + +using namespace geode::prelude; + +class LanguageSelectNode : public CCLayer +{ + public: + CCMenu* node; + TranslationCreditsLayer* layer; + int page = 0; + + bool init(); + + void goToPage(int page); + + virtual void keyBackClicked(); + void onSubmit(CCObject* sender); + + void onLeft(CCObject* sender); + void onRight(CCObject* sender); + + CREATE_FUNC(LanguageSelectNode); + static LanguageSelectNode* addToScene(); +}; \ No newline at end of file diff --git a/src/Layers/SillyBaseLayer.cpp b/src/Layers/SillyBaseLayer.cpp index c17df903..bce08194 100644 --- a/src/Layers/SillyBaseLayer.cpp +++ b/src/Layers/SillyBaseLayer.cpp @@ -43,8 +43,11 @@ bool SillyBaseLayer::setup() if (animate) { + auto action = UnspeedhackedAction::create(CCEaseElasticOut::create(CCScaleTo::create(0.5f, 1), 0.6f)); + action->setTag(69); + l->setScale(0); - l->runAction(UnspeedhackedAction::create(CCEaseElasticOut::create(CCScaleTo::create(0.5f, 1), 0.6f))); + l->runAction(action); } this->addChild(l); diff --git a/src/Layers/TranslationCreditsLayer.cpp b/src/Layers/TranslationCreditsLayer.cpp index 3c8085dd..2531119f 100644 --- a/src/Layers/TranslationCreditsLayer.cpp +++ b/src/Layers/TranslationCreditsLayer.cpp @@ -1,6 +1,7 @@ #include "TranslationCreditsLayer.hpp" #include #include "../UI/PlayerDeathAnimation.hpp" +#include "../Utils/TranslationManager.hpp" void TranslationCreditsLayer::customSetup() { @@ -65,45 +66,48 @@ void TranslationCreditsLayer::customSetup() creditsMenu->setLayout(AxisLayout::create()->setGrowCrossAxis(true)->setCrossAxisAlignment(AxisAlignment::Start)); creditsMenu->setZOrder(6); - for (auto contributor : language["contributors"].asArray().unwrap()) + if (path != "none") { - auto plr = PlayerObject::create(contributor["icon-id"].asUInt().unwrapOr(1), 2, nullptr, this, false); + for (auto contributor : language["contributors"].asArray().unwrap()) + { + auto plr = PlayerObject::create(contributor["icon-id"].asUInt().unwrapOr(1), 2, nullptr, this, false); - plr->setColor(GameManager::get()->colorForIdx(contributor["primary-col"].asInt().unwrapOr(0))); - plr->setSecondColor(GameManager::get()->colorForIdx(contributor["secondary-col"].asInt().unwrapOr(0))); + plr->setColor(GameManager::get()->colorForIdx(contributor["primary-col"].asInt().unwrapOr(0))); + plr->setSecondColor(GameManager::get()->colorForIdx(contributor["secondary-col"].asInt().unwrapOr(0))); - if (contributor["glow-enabled"].asBool().unwrapOr(false)) - { - plr->enableCustomGlowColor(GameManager::get()->colorForIdx(contributor["glow-col"].asInt().unwrapOr(0))); - plr->updateGlowColor(); - } + if (contributor["glow-enabled"].asBool().unwrapOr(false)) + { + plr->enableCustomGlowColor(GameManager::get()->colorForIdx(contributor["glow-col"].asInt().unwrapOr(0))); + plr->updateGlowColor(); + } - plr->togglePlatformerMode(true); - plr->m_regularTrail->setVisible(false); + plr->togglePlatformerMode(true); + plr->m_regularTrail->setVisible(false); - auto plrBtn = CCMenuItemSpriteExtra::create(plr, this, menu_selector(TranslationCreditsLayer::onKill)); - plrBtn->setContentSize(ccp(30, 30)); - plr->setPosition(plrBtn->getContentSize() / 2); + auto plrBtn = CCMenuItemSpriteExtra::create(plr, this, menu_selector(TranslationCreditsLayer::onKill)); + plrBtn->setContentSize(ccp(30, 30)); + plr->setPosition(plrBtn->getContentSize() / 2); - plrBtn->setPosition(ccp((as(rand()) / as(RAND_MAX) * 2 - 1) * 120, 190)); - plrBtn->runAction(CCEaseBounceOut::create(CCMoveTo::create(1, ccp(plrBtn->getPositionX(), 0)))); - plrBtn->setTag(contributor["death-effect-id"].asUInt().unwrapOr(1)); + plrBtn->setPosition(ccp((as(rand()) / as(RAND_MAX) * 2 - 1) * 120, 190)); + plrBtn->runAction(CCEaseBounceOut::create(CCMoveTo::create(1, ccp(plrBtn->getPositionX(), 0)))); + plrBtn->setTag(contributor["death-effect-id"].asUInt().unwrapOr(1)); - plrBtn->m_scaleMultiplier = 0.8f; + plrBtn->m_scaleMultiplier = 0.8f; - gameNode->addChild(plrBtn); + gameNode->addChild(plrBtn); - auto lbl = CCLabelBMFont::create(contributor["username"].asString().unwrapOr("Error").c_str(), "goldFont.fnt"); - lbl->limitLabelWidth(130, 1, 0); - float s = lbl->getScale(); - - auto btn = CCMenuItemSpriteExtra::create(lbl, this, menu_selector(TranslationCreditsLayer::onPlayerProfile)); - btn->setTag(contributor["account-id"].asUInt().unwrapOr(0)); + auto lbl = CCLabelBMFont::create(contributor["username"].asString().unwrapOr("Error").c_str(), "goldFont.fnt"); + lbl->limitLabelWidth(130, 1, 0); + float s = lbl->getScale(); + + auto btn = CCMenuItemSpriteExtra::create(lbl, this, menu_selector(TranslationCreditsLayer::onPlayerProfile)); + btn->setTag(contributor["account-id"].asUInt().unwrapOr(0)); - lbl->setScale(0); - lbl->runAction(CCEaseElasticOut::create(CCScaleTo::create(1.25f, s))); + lbl->setScale(0); + lbl->runAction(CCEaseElasticOut::create(CCScaleTo::create(1.25f, s))); - creditsMenu->addChild(btn); + creditsMenu->addChild(btn); + } } creditsMenu->updateLayout(); @@ -111,7 +115,45 @@ void TranslationCreditsLayer::customSetup() clip->addChild(gameNode); baseLayer->addChildAtPosition(creditsMenu, Anchor::Top, ccp(0, -45)); + bool used = TranslationManager::get()->getLoadedLanguage() == language["display_name_english"]; + + if (path == "none") + used = !TranslationManager::get()->isLanguageLoaded(); + + sprUse = ButtonSprite::create(used ? "Used" : "Use", "goldFont.fnt", used ? "GJ_button_05.png" : "GJ_button_01.png"); + btnUse = CCMenuItemSpriteExtra::create(sprUse, this, menu_selector(TranslationCreditsLayer::onUse)); + btnUse->setEnabled(!used); + + ok->setPositionX(ok->getPositionX() - btnUse->getScaledContentWidth() / 2); + btnUse->setPosition(ccp(ok->getPositionX() + btnUse->getScaledContentWidth(), ok->getPositionY())); + ok->setZOrder(420); + baseLayer->addChild(btnUse, 69); +} + +void TranslationCreditsLayer::onUse(CCObject* sender) +{ + if (path == "none") + Client::get()->setLanguage("none"); + else + Client::get()->setLanguage(path.filename().string()); + + ok->setPositionX(ok->getPositionX() + btnUse->getScaledContentWidth() / 2); + btnUse->removeFromParent(); + + bool used = TranslationManager::get()->getLoadedLanguage() == language["display_name_english"]; + + if (path == "none") + used = !TranslationManager::get()->isLanguageLoaded(); + + sprUse = ButtonSprite::create(used ? "Used" : "Use", "goldFont.fnt", used ? "GJ_button_05.png" : "GJ_button_01.png"); + btnUse = CCMenuItemSpriteExtra::create(sprUse, this, menu_selector(TranslationCreditsLayer::onUse)); + btnUse->setEnabled(!used); + + ok->setPositionX(ok->getPositionX() - btnUse->getScaledContentWidth() / 2); + btnUse->setPosition(ccp(ok->getPositionX() + btnUse->getScaledContentWidth(), ok->getPositionY())); + + baseLayer->addChild(btnUse, 69); } void TranslationCreditsLayer::onPlayerProfile(CCObject* sender) @@ -139,11 +181,12 @@ void TranslationCreditsLayer::onKill(CCObject* sender) } } -TranslationCreditsLayer* TranslationCreditsLayer::create(matjson::Value language) +TranslationCreditsLayer* TranslationCreditsLayer::create(matjson::Value language, std::filesystem::path path) { auto pRet = new TranslationCreditsLayer(); pRet->language = language; + pRet->path = path; if (pRet && pRet->initWithSizeAndName(ccp(330, 280), "")) { @@ -155,20 +198,91 @@ TranslationCreditsLayer* TranslationCreditsLayer::create(matjson::Value language return nullptr; } -TranslationCreditsLayer* TranslationCreditsLayer::addToScene(matjson::Value language) +TranslationCreditsLayer* TranslationCreditsLayer::addToScene(matjson::Value language, std::filesystem::path path) { - auto pRet = TranslationCreditsLayer::create(language); + auto pRet = TranslationCreditsLayer::create(language, path); CCScene::get()->addChild(pRet, 99999); return pRet; } +#include "LanguageSelectNode.hpp" + class $modify (MeowMenuLayer, MenuLayer) { void onMeow(CCObject*) { - TranslationCreditsLayer::addToScene(file::readJson(Mod::get()->getResourcesDir() / "ja-JP.json").unwrap()); + TranslationCreditsLayer::addToScene(file::readJson(Mod::get()->getResourcesDir() / "de-DE.json").unwrap(), Mod::get()->getResourcesDir() / "de-DE.json"); + } + + void onNyaa(CCObject*) + { + TranslationCreditsLayer::addToScene(matjson::parse("{ \"display_name_english\": \"Default\", \"display_name_native\": \"English\", \"contributors\": [] }").unwrapOr("{}"), "none"); + } + + void onCatgirl(CCObject*) + { + log::info("1: {}, 2: {}", TranslationManager::get()->isLanguageLoaded(), TranslationManager::get()->getLoadedLanguage()); + } + + void onFemboy(CCObject*) + { + LanguageSelectNode::addToScene(); + } + + void onMrrow(CCObject*) + { + matjson::Value obj; + + obj["display_name_english"] = "TODO"; + obj["display_name_native"] = "TODO"; + obj["contributors"] = obj.array(); + + matjson::Value strings; + + for (auto window : Client::get()->windows) + { + strings[window->name] = ""; + } + + for (auto window : Client::get()->windows) + { + for (auto mod : window->modules) + { + strings[mod->name] = ""; + + for (auto option : mod->options) + { + if (!option) + continue; + + strings[option->name] = ""; + } + } + } + + /* + for (auto window : Client::get()->windows) + { + for (auto mod : window->modules) + { + strings[mod->description] = ""; + + for (auto option : mod->options) + { + if (!option) + continue; + + strings[option->description] = ""; + } + } + } + */ + + obj["strings"] = strings; + + log::info("a:\n{}", obj.dump()); } bool init() @@ -181,8 +295,26 @@ class $modify (MeowMenuLayer, MenuLayer) btn->setPosition(ccp(100, 100)); menu->addChild(btn); + auto btn2 = CCMenuItemSpriteExtra::create(CCSprite::createWithSpriteFrameName("GJ_epicCoin3_001.png"), this, menu_selector(MeowMenuLayer::onMrrow)); + btn2->setPosition(ccp(50, -50)); + menu->addChild(btn2); + + auto btn3 = CCMenuItemSpriteExtra::create(CCSprite::createWithSpriteFrameName("GJ_editHSVBtn2_001.png"), this, menu_selector(MeowMenuLayer::onNyaa)); + btn3->setPosition(ccp(100, 50)); + menu->addChild(btn3); + + auto btn4 = CCMenuItemSpriteExtra::create(CCSprite::createWithSpriteFrameName("GJ_like2Btn_001.png"), this, menu_selector(MeowMenuLayer::onCatgirl)); + btn4->setPosition(ccp(100, 0)); + menu->addChild(btn4); + + auto btn5 = CCMenuItemSpriteExtra::create(CCSprite::createWithSpriteFrameName("label_of_001.png"), this, menu_selector(MeowMenuLayer::onFemboy)); + btn5->setPosition(ccp(150, -50)); + menu->addChild(btn5); + this->addChild(menu, 6935434); + Client::get()->getLanguages(); + return true; } }; \ No newline at end of file diff --git a/src/Layers/TranslationCreditsLayer.hpp b/src/Layers/TranslationCreditsLayer.hpp index ceab243d..1e2e658f 100644 --- a/src/Layers/TranslationCreditsLayer.hpp +++ b/src/Layers/TranslationCreditsLayer.hpp @@ -12,14 +12,19 @@ class TranslationCreditsLayer : public SillyBaseLayer { public: matjson::Value language; + std::filesystem::path path; GJGroundLayer* ground; CCSprite* background; + ButtonSprite* sprUse; + CCMenuItemSpriteExtra* btnUse; virtual void customSetup(); void onPlayerProfile(CCObject* sender); void onKill(CCObject* sender); - static TranslationCreditsLayer* create(matjson::Value language); - static TranslationCreditsLayer* addToScene(matjson::Value language); + void onUse(CCObject* sender); + + static TranslationCreditsLayer* create(matjson::Value language, std::filesystem::path path); + static TranslationCreditsLayer* addToScene(matjson::Value language, std::filesystem::path path); }; \ No newline at end of file diff --git a/src/UI/CategoryTabSprite.cpp b/src/UI/CategoryTabSprite.cpp index e036b001..4acf3479 100644 --- a/src/UI/CategoryTabSprite.cpp +++ b/src/UI/CategoryTabSprite.cpp @@ -36,7 +36,7 @@ bool CategoryTabSprite::init(CategoryTabType type, std::string name, std::string } } - label = CCLabelBMFont::create(name.c_str(), "bigFont.fnt"); + label = TransLabelBMFont::create(name.c_str(), "bigFont.fnt"); this->addChildAtPosition(background, Anchor::Center); this->addChildAtPosition(outline, Anchor::Center); diff --git a/src/UI/CategoryTabSprite.hpp b/src/UI/CategoryTabSprite.hpp index 58db64d4..d27c5ac1 100644 --- a/src/UI/CategoryTabSprite.hpp +++ b/src/UI/CategoryTabSprite.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include "TransLabelBMFont.hpp" using namespace geode::prelude; @@ -22,7 +23,7 @@ class CategoryTabSprite : public CCNode public: CCScale9Sprite* outline; CCScale9Sprite* background; - CCLabelBMFont* label; + TransLabelBMFont* label; CCSprite* sprite; static CategoryTabSprite* create(CategoryTabType type, std::string name = "", std::string icon = ""); diff --git a/src/UI/TransLabelBMFont.cpp b/src/UI/TransLabelBMFont.cpp index 7916ac73..d3cf5453 100644 --- a/src/UI/TransLabelBMFont.cpp +++ b/src/UI/TransLabelBMFont.cpp @@ -15,6 +15,8 @@ bool TransLabelBMFont::init(std::string text, std::string font) label = CCLabelBMFont::create(text.c_str(), font.c_str()); ttf = CCLabelTTF::create("", "Arial.ttf", 27.5f); + this->setAnchorPoint(ccp(0.5f, 0.5f)); + label->setAnchorPoint(ccp(0, 0)); ttf->setAnchorPoint(ccp(0, 0)); @@ -59,6 +61,17 @@ void TransLabelBMFont::setOpacity(int opacity) ttf->setOpacity(opacity); } +void TransLabelBMFont::setColor(ccColor3B colour) +{ + label->setColor(colour); + ttf->setColor(colour); +} + +std::string TransLabelBMFont::getString() +{ + return text; +} + TransLabelBMFont* TransLabelBMFont::create(std::string text, std::string font) { auto pRet = new TransLabelBMFont(); diff --git a/src/UI/TransLabelBMFont.hpp b/src/UI/TransLabelBMFont.hpp index fb4db359..84e14583 100644 --- a/src/UI/TransLabelBMFont.hpp +++ b/src/UI/TransLabelBMFont.hpp @@ -20,6 +20,10 @@ class TransLabelBMFont : public CCNode void limitLabelWidth(float width, float defaultScale, float minScale); void setOpacity(int opacity); + void setColor(ccColor3B colour); + + std::string getString(); + void updateTTFVisible(); static TransLabelBMFont* create(std::string text, std::string font); diff --git a/src/Utils/TranslationManager.cpp b/src/Utils/TranslationManager.cpp index 9ce6cbd6..5159a8bc 100644 --- a/src/Utils/TranslationManager.cpp +++ b/src/Utils/TranslationManager.cpp @@ -13,6 +13,8 @@ TranslationManager* TranslationManager::get() void TranslationManager::unloadTranslation() { translatedTexts = {}; + currentLanguage = ""; + languageLoaded = false; } void TranslationManager::loadTranslationFromJson(matjson::Value object) @@ -31,6 +33,19 @@ void TranslationManager::loadTranslationFromJson(matjson::Value object) translatedTexts.emplace(value.getKey().value(), value.asString().unwrapOr("Unknown unwrap error :c")); } } + + languageLoaded = true; + currentLanguage = object["display_name_english"].asString().unwrapOr("ERROR"); +} + +std::string TranslationManager::getLoadedLanguage() +{ + return currentLanguage; +} + +bool TranslationManager::isLanguageLoaded() +{ + return languageLoaded; } std::string TranslationManager::getTranslatedString(std::string engText) diff --git a/src/Utils/TranslationManager.hpp b/src/Utils/TranslationManager.hpp index 10ae399c..b81ca27e 100644 --- a/src/Utils/TranslationManager.hpp +++ b/src/Utils/TranslationManager.hpp @@ -8,6 +8,8 @@ class TranslationManager { private: std::unordered_map translatedTexts; + std::string currentLanguage; + bool languageLoaded = false; public: static TranslationManager* get(); @@ -15,4 +17,7 @@ class TranslationManager void unloadTranslation(); void loadTranslationFromJson(matjson::Value object); std::string getTranslatedString(std::string engText); + + bool isLanguageLoaded(); + std::string getLoadedLanguage(); }; \ No newline at end of file