From 7db06d5303dd71c5b1074c6d207bf7cd605ef2ca Mon Sep 17 00:00:00 2001 From: Ashton <38200084+Alphalaneous@users.noreply.github.com> Date: Wed, 6 Mar 2024 21:10:11 -0500 Subject: [PATCH] wstringless on android --- src/ui/hooks/MenuLayer.h | 13 ++++++++++ src/utils/Utils.h | 55 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/src/ui/hooks/MenuLayer.h b/src/ui/hooks/MenuLayer.h index 3acabfd..2f9c98f 100644 --- a/src/ui/hooks/MenuLayer.h +++ b/src/ui/hooks/MenuLayer.h @@ -129,9 +129,22 @@ class $modify(MyMenuLayer, MenuLayer) { this->addChild(creatorName); creatorName->setID("copyright-text"_spr); + #ifdef GEODE_IS_WINDOWS + std::wstring text = Utils::getSplashText(); MinecraftLabel* splashText = MinecraftLabel::create(text, "minecraft.fnt"_spr); + + #endif + + #ifdef GEODE_IS_ANDROID + + std::string text = Utils::getSplashText(); + + MinecraftLabel* splashText = MinecraftLabel::create(text, "minecraft.fnt"_spr); + + #endif + splashText->setColor({255,255,0}); splashText->setPosition({title->getContentSize().width,(title->getContentSize().height) /2}); splashText->setZOrder(3); diff --git a/src/utils/Utils.h b/src/utils/Utils.h index bf67417..67e823d 100644 --- a/src/utils/Utils.h +++ b/src/utils/Utils.h @@ -87,6 +87,8 @@ class Utils { return dirt; } + #ifdef GEODE_IS_WINDOWS + static std::vector splitString(const std::wstring& str, const std::wstring& delimiter) { std::vector strings; @@ -103,6 +105,28 @@ class Utils { return strings; } + #endif + + #ifdef GEODE_IS_ANDROID + + static std::vector splitString(const std::string& str, const std::string& delimiter) { + std::vector strings; + + std::string::size_type pos = 0; + std::string::size_type prev = 0; + while ((pos = str.find(delimiter, prev)) != std::string::npos) + { + strings.push_back(str.substr(prev, pos - prev)); + prev = pos + delimiter.size(); + } + + strings.push_back(str.substr(prev)); + + return strings; + } + + #endif + static int random(int min, int max) { std::random_device dev; std::mt19937 rng(dev()); @@ -122,6 +146,8 @@ class Utils { return result; } + #ifdef GEODE_IS_WINDOWS + inline static std::vector splashSplit; inline static bool hasBeenGenerated = false; @@ -144,4 +170,33 @@ class Utils { return newSplash; } + + #endif + + #ifdef GEODE_IS_ANDROID + + inline static std::vector splashSplit; + inline static bool hasBeenGenerated = false; + + static std::string getSplashText(){ + if(!hasBeenGenerated){ + ghc::filesystem::path path = Mod::get()->getResourcesDir().append("splashes.txt"); + + std::ifstream input(path.string()); + std::stringstream buffer; + buffer << input.rdbuf(); + input.close(); + + std::string splashText = buffer.str(); + + splashSplit = Utils::splitString(splashText, L"\n"); + hasBeenGenerated = true; + } + + std::string newSplash = splashSplit.at(random(0, splashSplit.size()-1)); + + return newSplash; + } + + #endif }; \ No newline at end of file