Skip to content

Commit

Permalink
Merge branch 'EclipseMenu:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Rustring authored Jul 19, 2024
2 parents 8514313 + 0eb4920 commit fd33e27
Show file tree
Hide file tree
Showing 15 changed files with 754 additions and 120 deletions.
3 changes: 2 additions & 1 deletion mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"files": [
"resources/Blur/*.glsl",
"resources/Rubik-Regular.ttf",
"resources/Themes/*.json"
"resources/Themes/*.json",
"resources/Themes/*.zip"
],
"sprites": [
"resources/ECLIPSE-android.png"
Expand Down
3 changes: 2 additions & 1 deletion resources/Themes/basic.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"colors": [],
"floats": []
"floats": [],
"options": {}
}
9 changes: 0 additions & 9 deletions resources/Themes/megahack.json

This file was deleted.

Binary file added resources/Themes/megahack.zip
Binary file not shown.
16 changes: 11 additions & 5 deletions src/hacks/Bot/PracticeFix.cpp → src/hacks/Level/PracticeFix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@

using namespace geode::prelude;

namespace eclipse::Hacks::Bot {
namespace eclipse::Hacks::Level {

class PracticeFix : public hack::Hack {
public:
static bool shouldEnable() {
return config::get<bool>("bot.practicefix", false) || config::get<int>("bot.state", 0) == 1;
}

private:
void init() override {
auto tab = gui::MenuTab::find("Bot");
auto tab = gui::MenuTab::find("Level");
tab->addToggle("Practice Fix", "bot.practicefix")
->setDescription("Properly saves the player's velocity when respawning from a checkpoint.");
->setDescription("Properly saves and restores the player's data when respawning from a checkpoint.");
}

[[nodiscard]] bool isCheating() override { return false; }
Expand Down Expand Up @@ -447,7 +453,7 @@ namespace eclipse::Hacks::Bot {
void loadFromCheckpoint(CheckpointObject* checkpoint) {
FixPlayLayer* playLayer = static_cast<FixPlayLayer*>(FixPlayLayer::get());

if (config::get<bool>("bot.practicefix", false) && playLayer->m_fields->m_checkpoints.contains(checkpoint)) {
if (PracticeFix::shouldEnable() && playLayer->m_fields->m_checkpoints.contains(checkpoint)) {
PlayLayer::loadFromCheckpoint(checkpoint);

CheckpointData& data = playLayer->m_fields->m_checkpoints[checkpoint];
Expand Down Expand Up @@ -480,7 +486,7 @@ namespace eclipse::Hacks::Bot {
auto result = CheckpointObject::init();
#endif

if (!config::get<bool>("bot.practicefix", false))
if (!PracticeFix::shouldEnable())
return result;

FixPlayLayer* playLayer = static_cast<FixPlayLayer*>(FixPlayLayer::get());
Expand Down
3 changes: 0 additions & 3 deletions src/hacks/Level/ShowHitboxes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,6 @@ namespace eclipse::hacks::Level {
void updateEditor(float dt) {
LevelEditorLayer::updateEditor(dt);

if (config::get<bool>("level.showhitboxes", false))
LevelEditorLayer::updateDebugDraw();

forceDraw(this, true);
}
};
Expand Down
8 changes: 5 additions & 3 deletions src/hacks/Recorder/Recorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,10 @@ namespace eclipse::hacks::Recorder {

tab->addButton("Start Recording")->callback(start);
tab->addButton("Stop Recording")->callback([] {
stop();
stopAudio();
if(s_recorder.isRecording())
stop();
if(s_recorder.isRecordingAudio())
stopAudio();
});

config::setIfEmpty("recorder.fps", 60.f);
Expand All @@ -138,7 +140,7 @@ namespace eclipse::hacks::Recorder {
tab->addInputText("Args", "recorder.args");
tab->addInputText("Extra Args", "recorder.extraargs");
tab->addInputText("Video Args", "recorder.videoargs");

tab->addLabel("Presets");
tab->addButton("CPU")->callback([] {
config::set<int>("recorder.codec", 0);
Expand Down
2 changes: 1 addition & 1 deletion src/modules/gui/color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ namespace eclipse::gui {
}

void from_json(const nlohmann::json &j, Color &e) {
e = Color::fromString(j.get<std::string>().c_str());
e = Color::fromString(j.get<std::string>());
}
}
38 changes: 36 additions & 2 deletions src/modules/gui/color.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

namespace eclipse::gui {
struct Color {
// Define default colors
static const Color WHITE;
static const Color BLACK;
static const Color RED;
Expand All @@ -26,6 +25,33 @@ namespace eclipse::gui {

Color(float r, float g, float b, float a = 1.0f) : r(r), g(g), b(b), a(a) {}

Color(const Color &other) : r(other.r), g(other.g), b(other.b), a(other.a) {}

Color(Color &&other) noexcept : r(other.r), g(other.g), b(other.b), a(other.a) {
other.r = other.g = other.b = 0;
other.a = 1.0f;
}

Color& operator=(const Color &other) {
if (this == &other) return *this;
r = other.r;
g = other.g;
b = other.b;
a = other.a;
return *this;
}

Color& operator=(Color &&other) noexcept {
if (this == &other) return *this;
r = other.r;
g = other.g;
b = other.b;
a = other.a;
other.r = other.g = other.b = 0;
other.a = 1.0f;
return *this;
}

/// @brief Converts the color to ImVec4
operator ImVec4() const {
return {r, g, b, a};
Expand All @@ -36,6 +62,14 @@ namespace eclipse::gui {
return ImGui::ColorConvertFloat4ToU32(ImVec4(r, g, b, a));
}

Color& operator=(const ImVec4 &col2) {
r = col2.x;
g = col2.y;
b = col2.z;
a = col2.w;
return *this;
}

operator cocos2d::ccColor4F() const {
return {r, g, b, a};
}
Expand Down Expand Up @@ -109,6 +143,7 @@ namespace eclipse::gui {
v2 = (float) ((color >> 16) & 0xFF) / 255.0f;
v3 = (float) ((color >> 8) & 0xFF) / 255.0f;
v4 = (float) (color & 0xFF) / 255.0f;

switch (type) {
default:
return {v1, v2, v3, v4};
Expand Down Expand Up @@ -172,5 +207,4 @@ namespace eclipse::gui {

void to_json(nlohmann::json &j, const Color &e);
void from_json(const nlohmann::json &j, Color &e);

}
93 changes: 3 additions & 90 deletions src/modules/gui/gui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,101 +588,14 @@ namespace eclipse::gui {
/// @brief Get if the menu is toggled.
[[nodiscard]] bool isToggled() { return m_isToggled; }

/// @brief Get the layout's component style.
[[nodiscard]] Style* getStyle() { return m_style; }

protected:
bool m_isToggled;
Style* m_style;
};

class Theme {
public:
explicit Theme(const std::filesystem::path& path, Layout* lay) {
loadFromFile(path);
m_layout = lay;
}

/// @brief Load the theme.
void loadFromFile(const std::filesystem::path& path) {
std::ifstream ifs(path.c_str());
nlohmann::json jf = nlohmann::json::parse(ifs);
if (jf.contains("colors")) {
std::map<int, Color> m = jf.at("colors").get<std::map<int, Color>>();
for (auto[k, v] : m) {
m_colors[k] = v;
}
}
if (jf.contains("floats")) {
std::map<int, float> m2 = jf.at("floats").get<std::map<int, float>>();
for (auto[k, v] : m2) {
m_floats[k] = v;
}
}
}

/// @brief Save the theme to a file.
void saveToFile(const std::filesystem::path& path) {
nlohmann::json j;
for (auto[k, v] : m_colors) {
j["colors"][k] = v;
}
for (auto[k, v] : m_floats) {
j["floats"][k] = v;
}
std::ofstream file(path.c_str());
file << j;
}

/// @brief Set up the UI.
virtual void setup() {
auto &style = ImGui::GetStyle();
auto &colors = style.Colors;

for (auto[k, v] : m_colors) {
colors[static_cast<ImGuiCol_>(k)] = v;
}
for (auto[k, v] : m_floats) {
switch (k) {
case 1:
style.WindowRounding = v;
break;
case 2:
style.FrameRounding = v;
break;
case 3:
style.PopupRounding = v;
break;
case 4:
style.IndentSpacing = v;
break;
case 5:
style.ScrollbarSize = v;
break;
case 6:
style.ScrollbarRounding = v;
break;
case 7:
style.GrabMinSize = v;
break;
case 8:
style.GrabRounding = v;
break;
case 9:
style.WindowBorderSize = v;
break;
}
}
}

/// @brief Get the layout of the theme.
[[nodiscard]] Layout* getLayout() { return m_layout; }

private:
Layout* m_layout;
std::map<int, Color> m_colors;
std::map<int, float> m_floats;
std::map<int, ImVec2> m_vecs;
// plus like colors and settings that the user can change (also theme saving to file)
};

/// @brief Abstract class, that wraps all UI function calls.
class Engine {
public:
Expand Down
10 changes: 8 additions & 2 deletions src/modules/gui/imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <modules/gui/color.hpp>

#include "layouts/window/window.hpp"
#include "styles/default.hpp"
#include "styles/megahack.hpp"

namespace eclipse::gui::imgui {

Expand Down Expand Up @@ -57,7 +57,13 @@ namespace eclipse::gui::imgui {

Theme* ImGuiEngine::getTheme() {
// TODO: change this for theme picker
if (!m_theme) m_theme = new Theme(geode::Mod::get()->getResourcesDir() / "basic.json", (new WindowLayout())->setStyle(new DefaultStyle()));
if (!m_theme) {
if(std::filesystem::exists(geode::Mod::get()->getSaveDir() / "themes" / "megahack.json"))
m_theme = new Theme(geode::Mod::get()->getSaveDir() / "themes" / "megahack.json");
else
m_theme = new Theme(geode::Mod::get()->getResourcesDir() / "megahack.zip");
}

return m_theme;
}
}
1 change: 1 addition & 0 deletions src/modules/gui/imgui.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once
#include <modules/gui/gui.hpp>
#include "theme.hpp"

namespace eclipse::gui::imgui {

Expand Down
Loading

0 comments on commit fd33e27

Please sign in to comment.