Skip to content

Commit

Permalink
This was a triumph. im making a note here, huge success
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSillyDoggo committed Dec 11, 2024
1 parent e3bfdff commit 6e52128
Show file tree
Hide file tree
Showing 16 changed files with 373 additions and 39 deletions.
2 changes: 1 addition & 1 deletion mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"resources/*.wav",
"resources/*.md",
"resources/*.ini",
"resources/langs/*.json"
"resources/translations/langs/*.json"
],
"sprites": [
"resources/sprites/*.png"
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion resources/translations
18 changes: 18 additions & 0 deletions src/Client/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "../Utils/LaunchArgs.hpp"
#include "../Utils/TranslationManager.hpp"
#include <Geode/modify/CCEGLView.hpp>
#include <regex>

Client* Client::get()
{
Expand Down Expand Up @@ -181,6 +182,23 @@ void Client::setLanguage(std::string langFile)
Mod::get()->setSavedValue<std::string>("loaded-translation", langFile);
}

std::vector<std::filesystem::path> Client::getLanguages()
{
std::vector<std::filesystem::path> 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");
Expand Down
1 change: 1 addition & 0 deletions src/Client/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class Client
void setUIScale(float scale);

void setLanguage(std::string langFile);
std::vector<std::filesystem::path> getLanguages();

//[[deprecated("GetModuleEnabled has been deprecated due to lag, please rember to cache the module :3")]]
static bool GetModuleEnabled(std::string id)
Expand Down
110 changes: 110 additions & 0 deletions src/Layers/LanguageSelectNode.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
27 changes: 27 additions & 0 deletions src/Layers/LanguageSelectNode.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once

#include <Geode/Geode.hpp>
#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();
};
5 changes: 4 additions & 1 deletion src/Layers/SillyBaseLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 6e52128

Please sign in to comment.