Skip to content

Commit

Permalink
viper pls help
Browse files Browse the repository at this point in the history
  • Loading branch information
OmgRod committed Jan 17, 2025
1 parent 6c1b873 commit 3322d0f
Show file tree
Hide file tree
Showing 22 changed files with 170 additions and 5 deletions.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
20 changes: 20 additions & 0 deletions src/layers/GYModSettingsPopup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@
#include <Geode/loader/Setting.hpp>

#include "GYModSettingsPopup.hpp"
#include "GYScreenshotPopup.hpp"
#include "Tags.hpp"

using namespace geode::prelude;

void GYModSettingsPopup::screenshotPopup(CCObject* sender) {
log::debug("Screenshot popup for setting {}", sender->getTag());
GYScreenshotPopup::create(sender->getTag())->show();
}

bool GYModSettingsPopup::setup(std::string const& modName, std::string const& modAuthor, std::string const& modID) {
this->setTitle(modName + " by " + modAuthor);

Expand All @@ -30,6 +37,19 @@ bool GYModSettingsPopup::setup(std::string const& modName, std::string const& mo
SettingNode* node;
if (auto sett = Mod::get()->getSetting(key)) {
node = sett->createNode(layerSize.width);
if (sett->getDescription().has_value()) {
auto menu = node->getChildByType<CCMenu*>(0);
auto btn = menu->getChildByType<CCMenuItemSpriteExtra*>(0);

Tags tags;

std::string modifiedKey = key;
std::replace(modifiedKey.begin(), modifiedKey.end(), '/', '-');
log::debug("Modified key: {}", modifiedKey);
node->setTag(tags.getTagFromString(modifiedKey));

btn->setTarget(node, menu_selector(GYModSettingsPopup::screenshotPopup));
}
}
// else {
// node = UnresolvedCustomSettingNode::create(key, Mod::get(), layerSize.width);
Expand Down
1 change: 1 addition & 0 deletions src/layers/GYModSettingsPopup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ using namespace geode::prelude;

class GYModSettingsPopup : public geode::Popup<std::string const&, std::string const&, std::string const&> {
protected:
void screenshotPopup(CCObject* sender);
bool setup(std::string const& modName, std::string const& modAuthor, std::string const& modID) override;

public:
Expand Down
16 changes: 11 additions & 5 deletions src/layers/GYScreenshotPopup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,23 @@
#include <Geode/modify/FLAlertLayer.hpp>
#include <string>

#include "Tags.hpp"

using namespace geode::prelude;

class GYScreenshotPopup : public geode::Popup<std::string const&> {
class GYScreenshotPopup : public geode::Popup<int const&> {
protected:
bool setup(std::string const& layer) override {
bool setup(int const& layer) override {
Tags tags;
auto layerName = tags.getStringFromTag(layer);

auto winSize = CCDirector::sharedDirector()->getWinSize();
this->setTitle(layer);
this->setTitle(layerName);
m_mainLayer->setContentSize({ winSize.width * 0.6f, winSize.height * 0.7f });
m_mainLayer->updateLayout();

auto sprite = CCSprite::create(fmt::format("{}Preview.png"_spr, layer).c_str());
auto sprite = CCSprite::createWithSpriteFrameName(fmt::format("{}Preview.png"_spr, layerName).c_str());
log::debug("Loading sprite: {}", fmt::format("omgrod.geodify/{}Preview.png", layerName));

// Calculate the maximum allowed dimensions for the sprite
auto maxWidth = m_mainLayer->getContentSize().width * 0.75f;
Expand All @@ -37,7 +43,7 @@ class GYScreenshotPopup : public geode::Popup<std::string const&> {
}

public:
static GYScreenshotPopup* create(std::string const& text) {
static GYScreenshotPopup* create(int const& text) {
auto ret = new GYScreenshotPopup();
if (ret->initAnchored(240.f, 160.f, text)) {
ret->autorelease();
Expand Down
138 changes: 138 additions & 0 deletions src/layers/Tags.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
#pragma once

#include <Geode/Geode.hpp>
#include <unordered_map>

using namespace geode::prelude;

class Tags {
public:
// Constructor to initialize the tag-to-string and string-to-tag maps
Tags() {
// Populate the maps directly (no hashing needed)
m_tagMap = {
{"gd-CreatorLayer", 0},
{"gd-EditLevelLayer", 1},
{"gd-GauntletLayer", 2},
{"gd-GauntletSelectLayer", 3},
{"gd-GJGarageLayer", 4},
{"gd-LeaderboardsLayer", 5},
{"gd-LevelAreaInnerLayer", 6},
{"gd-LevelAreaLayer", 7},
{"gd-LevelBrowserLayer", 8},
{"gd-LevelInfoLayer", 9},
{"gd-LevelListLayer", 10},
{"gd-LevelSearchLayer", 11},
{"gd-LevelSelectLayer", 12},
{"gd-LoadingLayer", 13},
{"gd-MenuLayer", 14},
{"gd-PlayLayer", 15},
{"gd-SecretLayer", 16},
{"gd-SecretLayer2", 17},
{"gd-SecretLayer3", 18},
{"gd-SecretLayer4", 19},
{"gd-SecretRewardsLayer", 20},
{"gd-UIPOptionsLayer", 21},
{"gd-UIOptionsLayer", 22},
{"cvolton.betterinfo-CustomCreatorLayer", 23},
{"cvolton.betterinfo-DailyViewLayer", 24},
{"cvolton.betterinfo-LevelSearchViewLayer", 25},
{"cvolton.betterinfo-RewardGroupLayer", 26},
{"cvolton.betterinfo-RewardViewLayer", 27},
{"dankmeme.globed2-GlobedLevelListLayer", 28},
{"dankmeme.globed2-GlobedMenuLayer", 29},
{"dankmeme.globed2-GlobedServersLayer", 30},
{"dankmeme.globed2-GlobedSettingsLayer", 31},
{"geode.loader-ModsLayer", 32},
{"geode.texture-loader-PackSelectLayer", 33},
{"hiimjustin000.integrated_demonlist-IDListLayer", 34},
{"hiimjustin000.integrated_demonlist-IDPackLayer", 35},
{"km7dev.gdps-switcher-ServerSwitchLayer", 36},
{"limegradient.betterachievements-BetterAchievementLayer", 37},
{"minemaker0430.gddp_integration-DPLayer", 38},
{"minemaker0430.gddp_integration-DPListLayer", 39},
{"omgrod.garage_plus-GPFeedbackLayer", 40},
{"omgrod.garage_plus-GPKofiLayer", 41},
{"omgrod.gdstream-StreamLayer", 42},
{"omgrod.gdstream-StreamCreatorLayer", 43},
{"thesillydoggo.newgrounds_explorer-NewgroundsBrowserLayer", 44},
{"uproxide.textures-TextureWorkshopLayer", 45}
};

// Populate the string-to-tag map
m_stringMap = {
{0, "gd-CreatorLayer"},
{1, "gd-EditLevelLayer"},
{2, "gd-GauntletLayer"},
{3, "gd-GauntletSelectLayer"},
{4, "gd-GJGarageLayer"},
{5, "gd-LeaderboardsLayer"},
{6, "gd-LevelAreaInnerLayer"},
{7, "gd-LevelAreaLayer"},
{8, "gd-LevelBrowserLayer"},
{9, "gd-LevelInfoLayer"},
{10, "gd-LevelListLayer"},
{11, "gd-LevelSearchLayer"},
{12, "gd-LevelSelectLayer"},
{13, "gd-LoadingLayer"},
{14, "gd-MenuLayer"},
{15, "gd-PlayLayer"},
{16, "gd-SecretLayer"},
{17, "gd-SecretLayer2"},
{18, "gd-SecretLayer3"},
{19, "gd-SecretLayer4"},
{20, "gd-SecretRewardsLayer"},
{21, "gd-UIPOptionsLayer"},
{22, "gd-UIOptionsLayer"},
{23, "cvolton.betterinfo-CustomCreatorLayer"},
{24, "cvolton.betterinfo-DailyViewLayer"},
{25, "cvolton.betterinfo-LevelSearchViewLayer"},
{26, "cvolton.betterinfo-RewardGroupLayer"},
{27, "cvolton.betterinfo-RewardViewLayer"},
{28, "dankmeme.globed2-GlobedLevelListLayer"},
{29, "dankmeme.globed2-GlobedMenuLayer"},
{30, "dankmeme.globed2-GlobedServersLayer"},
{31, "dankmeme.globed2-GlobedSettingsLayer"},
{32, "geode.loader-ModsLayer"},
{33, "geode.texture-loader-PackSelectLayer"},
{34, "hiimjustin000.integrated_demonlist-IDListLayer"},
{35, "hiimjustin000.integrated_demonlist-IDPackLayer"},
{36, "km7dev.gdps-switcher-ServerSwitchLayer"},
{37, "limegradient.betterachievements-BetterAchievementLayer"},
{38, "minemaker0430.gddp_integration-DPLayer"},
{39, "minemaker0430.gddp_integration-DPListLayer"},
{40, "omgrod.garage_plus-GPFeedbackLayer"},
{41, "omgrod.garage_plus-GPKofiLayer"},
{42, "omgrod.gdstream-StreamLayer"},
{43, "omgrod.gdstream-StreamCreatorLayer"},
{44, "thesillydoggo.newgrounds_explorer-NewgroundsBrowserLayer"},
{45, "uproxide.textures-TextureWorkshopLayer"}
};
}

// Convert a string to a corresponding tag (integer)
int getTagFromString(const std::string& name) {
log::debug("Getting tag from string: {}", name);
auto it = m_tagMap.find(name);
if (it != m_tagMap.end()) {
return it->second;
}
log::error("Unknown tag: {}", name);
return -1;
}

// Convert an integer tag back to the corresponding string
std::string getStringFromTag(int tag) {
log::debug("Getting string from tag: {}", tag);
auto it = m_stringMap.find(tag);
if (it != m_stringMap.end()) {
return it->second;
}
log::error("Unknown tag: {}", tag);
return "unknown";
}

private:
std::unordered_map<std::string, int> m_tagMap; // Direct map for string -> tag
std::unordered_map<int, std::string> m_stringMap; // Direct map for tag -> string
};

0 comments on commit 3322d0f

Please sign in to comment.