Skip to content

Commit

Permalink
i dont belong anywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSillyDoggo committed Dec 14, 2024
1 parent 4f269c8 commit 1503652
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 10 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.7.7

- Added **Localization / Translations**!!!

# 1.7.6

- Fixed level creator appearing as blank in labels for official levels
Expand Down
3 changes: 2 additions & 1 deletion src/Client/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "Dropdown.h"
#include "Client.h"
#include "../UI/TransLabelBMFont.hpp"
#include "../UI/TransAlertLayer.hpp"

void Module::drawImGui()
{
Expand Down Expand Up @@ -85,7 +86,7 @@ void Module::onInfoAndroid(CCObject* sender)
if (!dat)
return;

auto al = FLAlertLayer::create(dat->name.c_str(), dat->description.c_str(), "OK");
auto al = TransAlertLayer::create(dat->name.c_str(), dat->description.c_str(), "OK");
al->show();
}

Expand Down
3 changes: 2 additions & 1 deletion src/Client/Types/ColourPickModule.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include "ColourPickModule.hpp"
#include "../../UI/TransLabelBMFont.hpp"

void ColourModule::makeAndroid(CCNode* menu, CCPoint pos)
{
auto label = CCLabelBMFont::create(name.c_str(), "bigFont.fnt");
auto label = TransLabelBMFont::create(name.c_str(), "bigFont.fnt");
label->setAnchorPoint(ccp(0, 0.5f));
label->setScale(0.575f);
label->setPosition(pos + ccp(-15, 0));
Expand Down
3 changes: 2 additions & 1 deletion src/Client/Types/InputModule.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "InputModule.hpp"
#include <imgui-cocos.hpp>
#include "../../UI/TransLabelBMFont.hpp"

InputModule* mod;

Expand Down Expand Up @@ -40,7 +41,7 @@ void InputModule::drawImGui()

void InputModule::makeAndroid(CCNode* menu, CCPoint pos)
{
auto label = CCLabelBMFont::create(name.c_str(), "bigFont.fnt");
auto label = TransLabelBMFont::create(name.c_str(), "bigFont.fnt");
label->setAnchorPoint(ccp(0, 0.5f));
label->setScale(0.575f);
label->setPosition(pos - ccp(10, 0));
Expand Down
21 changes: 18 additions & 3 deletions src/Layers/LanguageSelectNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,30 @@ bool LanguageSelectNode::init()
if (!TranslationManager::get()->isLanguageLoaded())
goToPage(0);
else
{

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

this->addChild(colBG);
this->addChildAtPosition(node, Anchor::Center);
return true;
}

void LanguageSelectNode::goToPage(std::string fileName)
{
auto langs = Client::get()->getLanguages();

int i = 1;

for (auto lang : langs)
{
if (lang.filename() == fileName)
return goToPage(i);

i++;
}

goToPage(0);
}

void LanguageSelectNode::goToPage(int page)
{
this->page = page;
Expand Down
1 change: 1 addition & 0 deletions src/Layers/LanguageSelectNode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class LanguageSelectNode : public CCLayer
bool init();

void goToPage(int page);
void goToPage(std::string fileName);

virtual void keyBackClicked();
void onSubmit(CCObject* sender);
Expand Down
3 changes: 2 additions & 1 deletion src/Layers/ModuleOptionsLayer.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "ModuleOptionsLayer.h"
#include "../UI/TransAlertLayer.hpp"

ModuleOptionsLayer* ModuleOptionsLayer::create(Module* module)
{
Expand Down Expand Up @@ -49,6 +50,6 @@ void ModuleOptionsLayer::customSetup()

void ModuleOptionsLayer::onInfoButton(CCObject*)
{
auto al = FLAlertLayer::create(mod->name.c_str(), mod->description.c_str(), "OK");
auto al = TransAlertLayer::create(mod->name.c_str(), mod->description.c_str(), "OK");
al->show();
}
2 changes: 1 addition & 1 deletion src/Layers/SillyBaseLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ bool SillyBaseLayer::setup()

l->addChildAtPosition(bg, Anchor::Center);

title = CCLabelBMFont::create(_title.c_str(), "bigFont.fnt");
title = TransLabelBMFont::create(_title.c_str(), "bigFont.fnt");
title->setPosition(l->getContentSize() / 2 + ccp(0, (l->getContentSize().height / 2) - 15));
title->setScale(0.6f);
l->addChild(title);
Expand Down
3 changes: 2 additions & 1 deletion src/Layers/SillyBaseLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "../Client/Client.h"
#include "../UI/BlurLayer.hpp"
#include "../UI/QOLModMenuBG.hpp"
#include "../UI/TransLabelBMFont.hpp"

using namespace geode::prelude;

Expand All @@ -16,7 +17,7 @@ class SillyBaseLayer : public geode::Popup<>
CCPoint size = CCPointZero;
BlurLayer* blur = nullptr;
std::string _title;
CCLabelBMFont* title;
TransLabelBMFont* title;
bool createWithOK;
bool animate;
bool noBlur;
Expand Down
70 changes: 70 additions & 0 deletions src/UI/TransAlertLayer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include "TransAlertLayer.hpp"
#include "TransLabelBMFont.hpp"
#include "../Utils/TranslationManager.hpp"

bool TransAlertLayer::init(char const* title, const gd::string& desc, char const* btn)
{
std::string desc2 = TranslationManager::get()->getTranslatedString(desc);

if (!FLAlertLayer::init(nullptr, title, desc2, btn, nullptr, 300.0f, false, 320, 1.0f))
return false;

auto label = CCLabelBMFont::create("", "bigFont.fnt");

bool useTtf = false;

for (auto letter : desc2)
{
if (!label->getConfiguration()->getCharacterSet()->contains(as<int>(letter)))
{
useTtf = true;
break;
}
}

auto titleL = TransLabelBMFont::create(std::string(title), "goldFont.fnt");
titleL->setAnchorPoint(ccp(0.5f, 1));
titleL->setPosition(m_mainLayer->getChildByType<CCLabelBMFont>(0)->getPosition());
titleL->setScale(m_mainLayer->getChildByType<CCLabelBMFont>(0)->getScale());

m_mainLayer->getChildByType<CCLabelBMFont>(0)->setVisible(false);

m_mainLayer->addChild(titleL, 420);

if (useTtf)
{
m_mainLayer->getChildByType<TextArea>(0)->setVisible(false);

auto node = CCNode::create();
node->setPosition(CCDirector::get()->getWinSize() / 2);
node->setAnchorPoint(ccp(0.5f, 0.5f));
node->setContentWidth(260);

for (auto word : utils::string::split(desc2, " "))
{
auto lbl = TransLabelBMFont::create(fmt::format("{} ", word), "chatFont.fnt");

node->addChild(lbl);
}

node->setLayout(AxisLayout::create()->setAutoScale(false)->setGrowCrossAxis(true)->setGap(0));

m_mainLayer->addChild(node, 69);
}

return true;
}

TransAlertLayer* TransAlertLayer::create(char const* title, const gd::string& desc, char const* btn)
{
auto pRet = new TransAlertLayer();

if (pRet && pRet->init(title, desc, btn))
{
pRet->autorelease();
return pRet;
}

CC_SAFE_DELETE(pRet);
return nullptr;
}
13 changes: 13 additions & 0 deletions src/UI/TransAlertLayer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include <Geode/Geode.hpp>

using namespace geode::prelude;

class TransAlertLayer : public FLAlertLayer
{
public:
bool init(char const* title, const gd::string& desc, char const* btn);

static TransAlertLayer* create(char const* title, const gd::string& desc, char const* btn);
};
11 changes: 10 additions & 1 deletion src/UI/TransLabelBMFont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ bool TransLabelBMFont::init(std::string text, std::string font)
this->font = text;

label = CCLabelBMFont::create(text.c_str(), font.c_str());
ttf = CCLabelTTF::create("", "Arial.ttf", 27.5f);
ttf = CCLabelTTF::create("", "Arial.ttf", label->getContentHeight());

this->setAnchorPoint(ccp(0.5f, 0.5f));

Expand Down Expand Up @@ -46,6 +46,8 @@ void TransLabelBMFont::updateTTFVisible()
}
}

label->setString(text.c_str());

if (useTtf)
ttf->setString(text.c_str());

Expand All @@ -72,6 +74,13 @@ std::string TransLabelBMFont::getString()
return text;
}

void TransLabelBMFont::setString(const char* str)
{
this->text = str;

updateTTFVisible();
}

TransLabelBMFont* TransLabelBMFont::create(std::string text, std::string font)
{
auto pRet = new TransLabelBMFont();
Expand Down
1 change: 1 addition & 0 deletions src/UI/TransLabelBMFont.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class TransLabelBMFont : public CCNode
void setOpacity(int opacity);
void setColor(ccColor3B colour);

void setString(const char* str);
std::string getString();

void updateTTFVisible();
Expand Down

0 comments on commit 1503652

Please sign in to comment.