Skip to content

Commit

Permalink
thank you prevter
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSillyDoggo committed Dec 4, 2024
1 parent 10a57f3 commit 83d4bde
Show file tree
Hide file tree
Showing 14 changed files with 372 additions and 75 deletions.
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 1.7.6

- Fixed lag (thanks @prevter)
- Added **Label Import / Export to file buttons**

# 1.7.5

- Fixed December Menu Snow not working
Expand Down
2 changes: 1 addition & 1 deletion mod.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"geode": "4.0.1",
"version": "v1.7.5",
"version": "v1.7.6",
"gd": {
"win": "2.2074",
"android": "2.2074",
Expand Down
78 changes: 36 additions & 42 deletions src/Client/Windows/IconEffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ccColor3B EffectUI::getColourForSelected(int mode, bool player2) // bri`ish
int sel = 0;
float v = ColourUtility::va;

v *= Mod::get()->getSavedValue<float>(fmt::format("icon-effect-speed_{}", mode), 1);
v *= speeds[mode];

switch (mode)
{
Expand All @@ -30,30 +30,23 @@ ccColor3B EffectUI::getColourForSelected(int mode, bool player2) // bri`ish
break;
}

if (mode == 0)
{
if (sel == 0)
return GameManager::get()->colorForIdx(GameManager::get()->m_playerColor.value());
}
else if (mode == 1)
{
if (sel == 0)
return GameManager::get()->colorForIdx(GameManager::get()->m_playerColor2.value());
}
else if (mode == 2)
{
if (sel == 0)
return GameManager::get()->colorForIdx(GameManager::get()->m_playerGlowColor.value());
}
else if (mode == 3)
{
if (sel == 0)
return GameManager::get()->colorForIdx(Mod::get()->getSavedValue<bool>("same-dual") ? GameManager::get()->m_playerColor2.value() : (player2 ? GameManager::get()->m_playerColor.value() : GameManager::get()->m_playerColor2.value()));
}
else
auto gameManager = GameManager::get();

if (sel == 0)
{
if (sel == 0)
return GameManager::get()->colorForIdx(Mod::get()->getSavedValue<bool>("same-dual") ? GameManager::get()->m_playerColor.value() : (player2 ? GameManager::get()->m_playerColor2.value() : GameManager::get()->m_playerColor.value()));
switch (mode)
{
case 0:
return gameManager->colorForIdx(gameManager->m_playerColor.value());
case 1:
return gameManager->colorForIdx(gameManager->m_playerColor2.value());
case 2:
return gameManager->colorForIdx(gameManager->m_playerGlowColor.value());
case 3:
return gameManager->colorForIdx(sameDual ? gameManager->m_playerColor2.value() : (player2 ? gameManager->m_playerColor.value() : gameManager->m_playerColor2.value()));
default:
return gameManager->colorForIdx(sameDual ? gameManager->m_playerColor.value() : (player2 ? gameManager->m_playerColor2.value() : gameManager->m_playerColor.value()));
}
}

if (sel == 1)
Expand All @@ -64,16 +57,11 @@ ccColor3B EffectUI::getColourForSelected(int mode, bool player2) // bri`ish

if (sel == 3)
{
std::stringstream fadeIn;
fadeIn << "fadeColour1";
fadeIn << mode;

std::stringstream fadeOut;
fadeOut << "fadeColour2";
fadeOut << mode;
auto fadeIn = fmt::format("fadeColour1{}", mode);
auto fadeOut = fmt::format("fadeColour2{}", mode);

ccColor3B in = Mod::get()->getSavedValue<ccColor3B>(fadeIn.str(), {0, 0, 0});
ccColor3B out = Mod::get()->getSavedValue<ccColor3B>(fadeOut.str(), {255, 255, 255});
ccColor3B in = Mod::get()->getSavedValue<ccColor3B>(fadeIn, {0, 0, 0});
ccColor3B out = Mod::get()->getSavedValue<ccColor3B>(fadeOut, {255, 255, 255});

return ColourUtility::lerpColour(in, out, (sinf(v * 3) + 1) / 2);
//fade
Expand All @@ -87,7 +75,7 @@ ccColor3B EffectUI::getColourForSelected(int mode, bool player2) // bri`ish
return {0, 0, 0};
}

std::vector<std::string> mods =
constexpr std::array mods =
{
"rooot.custom-gamemode-colors",
"gdemerald.custom_icon_colors",
Expand Down Expand Up @@ -139,16 +127,27 @@ void EffectUI::updateValues()
glow = Mod::get()->getSavedValue<int>(fmt::format("selColour{}", 2), 0);
trail = Mod::get()->getSavedValue<int>(fmt::format("selColour{}", 3), 0);
waveTrail = Mod::get()->getSavedValue<int>(fmt::format("selColour{}", 4), 0);

sameDual = Mod::get()->getSavedValue<bool>("same-dual");

// cache values for performance
for (int i = 0; i < 5; i++)
{
speeds[i] = Mod::get()->getSavedValue<float>(fmt::format("icon-effect-speed_{}", i), 1);
}
}

class $modify (GJBaseGameLayer)
{
virtual void update(float p0)
{
auto plr1 = EffectUI::getColourForSelected(0);
auto plr2 = EffectUI::getColourForSelected(1);

if (m_player1)
{
m_player1->setColor(EffectUI::getColourForSelected(0));
m_player1->setSecondColor(EffectUI::getColourForSelected(1));
m_player1->setColor(plr1);
m_player1->setSecondColor(plr2);
m_player1->m_glowColor = EffectUI::getColourForSelected(2);
m_player1->updateGlowColor();
m_player1->m_regularTrail->setColor(EffectUI::getColourForSelected(3));
Expand All @@ -157,7 +156,7 @@ class $modify (GJBaseGameLayer)

if (m_player2)
{
if (!Mod::get()->getSavedValue<bool>("same-dual"))
if (!EffectUI::sameDual)
{
m_player2->setColor(EffectUI::getColourForSelected(1, true));
m_player2->setSecondColor(EffectUI::getColourForSelected(0, true));
Expand All @@ -176,9 +175,6 @@ class $modify (GJBaseGameLayer)
m_player2->m_waveTrail->setColor(EffectUI::getColourForSelected(4, true));
}

auto plr1 = EffectUI::getColourForSelected(0, false);
auto plr2 = EffectUI::getColourForSelected(1, false);

if (m_effectManager)
{
if (auto action = m_effectManager->getColorAction(1005))
Expand Down Expand Up @@ -216,6 +212,4 @@ class $modify (MenuLayer)
$execute
{
EffectUI::updateValues();

log::info("b");
};
42 changes: 23 additions & 19 deletions src/Client/Windows/IconEffects.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class EffectUI : public CCNode
static inline int trail = 0;
static inline int waveTrail = 0;

static inline std::array<float, 5> speeds = {1, 1, 1, 1, 1};
static inline bool sameDual = false;

static inline Hook* _hook = nullptr;

static bool getIncompatibleModLoaded();
Expand All @@ -44,30 +47,34 @@ class EffectUI : public CCNode

void update(float delta)
{
auto color1 = getColourForSelected(0);
auto color2 = getColourForSelected(1);
auto glow = getColourForSelected(2);

for (size_t i = 0; i < players.size(); i++)
{
players[i]->setColor(getColourForSelected(0));
players[i]->setSecondColor(getColourForSelected(1));
players[i]->setColor(color1);
players[i]->setSecondColor(color2);

players[i]->enableCustomGlowColor(getColourForSelected(2));
players[i]->enableCustomGlowColor(glow);
players[i]->m_hasGlowOutline = GameManager::get()->m_playerGlow;
players[i]->updateColors();
}

for (size_t i = 0; i < players2.size(); i++)
{
if (Mod::get()->getSavedValue<bool>("same-dual"))
if (sameDual)
{
players2[i]->setColor(getColourForSelected(0));
players2[i]->setSecondColor(getColourForSelected(1));
players2[i]->setColor(color1);
players2[i]->setSecondColor(color2);
}
else
{
players2[i]->setColor(getColourForSelected(1));
players2[i]->setSecondColor(getColourForSelected(0));
players2[i]->setColor(color2);
players2[i]->setSecondColor(color1);
}

players2[i]->enableCustomGlowColor(getColourForSelected(2));
players2[i]->enableCustomGlowColor(glow);
players2[i]->m_hasGlowOutline = GameManager::get()->m_playerGlow;
players2[i]->updateColors();
}
Expand All @@ -90,16 +97,11 @@ class EffectUI : public CCNode

for (size_t i = 0; i < fades.size(); i++)
{
std::stringstream fadeIn;
fadeIn << "fadeColour1";
fadeIn << i;

std::stringstream fadeOut;
fadeOut << "fadeColour2";
fadeOut << i;
auto fadeIn = fmt::format("fadeColour1{}", i);
auto fadeOut = fmt::format("fadeColour2{}", i);

ccColor3B in = Mod::get()->getSavedValue<ccColor3B>(fadeIn.str(), {0, 0, 0});
ccColor3B out = Mod::get()->getSavedValue<ccColor3B>(fadeOut.str(), {255, 255, 255});
ccColor3B in = Mod::get()->getSavedValue<ccColor3B>(fadeIn, {0, 0, 0});
ccColor3B out = Mod::get()->getSavedValue<ccColor3B>(fadeOut, {255, 255, 255});

float v = ColourUtility::va;
v *= Mod::get()->getSavedValue<float>(fmt::format("icon-effect-speed_{}", i), 1);
Expand Down Expand Up @@ -163,7 +165,9 @@ class IconEffects : public Window

void changeDual(CCObject*)
{
Mod::get()->setSavedValue<bool>("same-dual", !Mod::get()->getSavedValue<bool>("same-dual"));
bool sameDual = !Mod::get()->getSavedValue<bool>("same-dual");
Mod::get()->setSavedValue<bool>("same-dual", sameDual);
EffectUI::sameDual = sameDual;
}

void updateSelections()
Expand Down
67 changes: 67 additions & 0 deletions src/Client/Windows/Labels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include "../../Layers/EditLabelPopup.hpp"
#include "../../Layers/EditSafeZonePopup.hpp"
#include "../../Labels/LabelLayer.hpp"
#include "../AndroidUI.h"
#include "../../DragDrop.hpp"

#define BUTTON_WIDTH 200

Expand Down Expand Up @@ -79,6 +81,12 @@ void Labels::cocosCreate(CCMenu* menu)
safeBtn->setPosition(ccp(240, 15));
safeBtn->getNormalImage()->setScale(0.5f);

// ButtonSprite * create(const char *caption, int width, bool absolute, const char *font, const char *texture, float height, float scale)
auto importBtn = CCMenuItemSpriteExtra::create(ButtonSprite::create("Import From File", 100, false, "bigFont.fnt", "GJ_button_05.png", 30, 1.0f), this, menu_selector(Labels::onImportFromFile));
importBtn->setPosition(safeBtn->getPosition() + ccp(55, 0));
importBtn->getNormalImage()->setScale(0.7f);
safeZoneMenu->addChild(importBtn);

safeZoneMenu->addChild(safeBtn);
menu->addChild(safeZoneMenu);

Expand Down Expand Up @@ -576,4 +584,63 @@ void Labels::loadFromPrevSave()
Labels* Labels::get()
{
return instance;
}

void Labels::onImportFromFile(CCObject* sender)
{
file::FilePickOptions options;

file::FilePickOptions::Filter filter;
filter.description = "QOLMod Label";
filter.files = { "*.qollbl" };

options.filters.push_back(filter);

file::pickMany(options).listen([this](Result<std::vector<std::filesystem::path>>* path)
{
if (path->isOk())
{
auto paths = path->unwrap();

for (auto path : paths)
{
importFromFile(path);
}
}
});
}

void Labels::importFromFile(std::filesystem::path path)
{
auto res = file::readJson(path);

if (res.isOk())
{
auto mod = LabelModule::createFromObject(res.unwrap());
mod->name = fmt::format("{} ({})", mod->name, path.filename().string());

modules.push_back(mod);

save();

if (AndroidUI::get())
refreshList();

FLAlertLayer::create("Success!", "<cg>Successfully</c> imported <cc>label</c>!", "Yay!")->show();
}
else
{
FLAlertLayer::create("Failure!", fmt::format("<cr>Failed</c> to import <cc>label</c>.\n<cl>{}</c>", res.unwrapErr()), "OK")->show();
}
}

$on_mod(Loaded)
{
DragDrop::get()->addListener("import-labels"_spr, [](std::vector<std::string> paths)
{
for (auto path : paths)
{
Labels::get()->importFromFile(path);
}
});
}
3 changes: 3 additions & 0 deletions src/Client/Windows/Labels.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,7 @@ class Labels : public Window
void onMoveLabelUp(CCObject* sender);
void onMoveLabelDown(CCObject* sender);
void onToggleVisible(CCObject* sender);
void onImportFromFile(CCObject* sender);

void importFromFile(std::filesystem::path path);
};
Loading

0 comments on commit 83d4bde

Please sign in to comment.