Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSillyDoggo committed Dec 10, 2024
1 parent fc69386 commit e3bfdff
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 20 deletions.
5 changes: 4 additions & 1 deletion resources/langs/ja-JP.json → resources/lang/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@
"glow-col": 12,
"death-effect-id": 3
}
]
],
"strings": {
"Noclip": "ノークリップ"
}
}
Binary file added resources/sprites/banner-mask.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions src/Client/Client.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
#include "Client.h"
#include "../Utils/LaunchArgs.hpp"
#include "../Utils/TranslationManager.hpp"
#include <Geode/modify/CCEGLView.hpp>

Client* Client::get()
{
return instance;
}

Client::Client()
{
mod = Mod::get();

setLanguage(Mod::get()->getSavedValue<std::string>("loaded-translation", "none"));
}

bool Client::handleKeybinds(enumKeyCodes key, bool isDown, bool isRepeatedKey)
{
if (!isDown || key == enumKeyCodes::KEY_Unknown)
Expand Down Expand Up @@ -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<std::string>("loaded-translation", langFile);
}

void Client::sortWindows(bool instant)
{
float offset = ini->getKeyValueFloat("Offsets::WindowDistance", "15");
Expand Down
7 changes: 3 additions & 4 deletions src/Client/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ class Client
SimpleINI* ini = nullptr;
ImVec2 widgetSize = ImVec2(215, 25);

Client()
{
mod = Mod::get();
}
Client();

static Client* get();

Expand All @@ -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)
{
Expand Down
23 changes: 13 additions & 10 deletions src/Layers/TranslationCreditsLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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));
Expand All @@ -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())
{
Expand Down Expand Up @@ -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);
}
Expand Down
3 changes: 0 additions & 3 deletions src/UI/TransLabelBMFont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions src/UI/TransLabelBMFont.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using namespace geode::prelude;

// they call this my gender
class TransLabelBMFont : public CCNode
{
private:
Expand Down
14 changes: 12 additions & 2 deletions src/Utils/TranslationManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand Down
1 change: 1 addition & 0 deletions src/Utils/TranslationManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class TranslationManager
public:
static TranslationManager* get();

void unloadTranslation();
void loadTranslationFromJson(matjson::Value object);
std::string getTranslatedString(std::string engText);
};

0 comments on commit e3bfdff

Please sign in to comment.