Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 36 additions & 5 deletions src/DevTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <Geode/loader/Log.hpp>
#include <Geode/loader/Mod.hpp>
#include "ImGui.hpp"
#include "nodes/DragButton.hpp"

template<>
struct matjson::Serialize<Settings> {
Expand All @@ -35,6 +34,7 @@ struct matjson::Serialize<Settings> {
assign(value["button_y"], s.buttonPos.y);
assign(value["button_editor"], s.buttonInEditor);
assign(value["button_game"], s.buttonInGame);
assign(value["button_enabled"], s.buttonEnabled);
assign(value["tree_drag_reorder"], s.treeDragReorder);

return Ok(s);
Expand All @@ -57,6 +57,7 @@ struct matjson::Serialize<Settings> {
{ "button_y", settings.buttonPos.y },
{ "button_editor", settings.buttonInEditor },
{ "button_game", settings.buttonInGame },
{ "button_enabled", settings.buttonEnabled },
{ "tree_drag_reorder", settings.treeDragReorder }
});
}
Expand All @@ -70,11 +71,9 @@ DevTools* DevTools::get() {
}

void DevTools::loadSettings() { m_settings = Mod::get()->getSavedValue<Settings>("settings"); }
void DevTools::saveSettings() {
m_settings.buttonPos = DragButton::get()->getPosition();
Mod::get()->setSavedValue("settings", m_settings);
}
void DevTools::saveSettings() { Mod::get()->setSavedValue("settings", m_settings); }
Settings DevTools::getSettings() { return m_settings; }
void DevTools::setBallPosition(CCPoint pos) { m_settings.buttonPos = std::move(pos); }

bool DevTools::shouldPopGame() const {
return m_visible && m_settings.GDInWindow;
Expand Down Expand Up @@ -116,6 +115,38 @@ void DevTools::addCustomCallback(std::function<void(CCNode*)> callback) {
m_customCallbacks.push_back(std::move(callback));
}

DragButton* DevTools::getDragButton() {
return m_dragButton;
}

void DevTools::setupDragButton() {
auto spr = CircleButtonSprite::createWithSprite("devtools.png"_spr, 1, CircleBaseColor::Green, CircleBaseSize::MediumAlt);
spr->setScale(.8f);
m_dragButton = DragButton::create(spr, [this](){
this->toggle();
});
m_dragButton->setPosition(m_settings.buttonPos);
m_dragButton->setZOrder(10000);
m_dragButton->setID("devtools-button"_spr);
SceneManager::get()->keepAcrossScenes(m_dragButton);
}

void DevTools::removeDragButton() {
if (m_dragButton) {
SceneManager::get()->forget(m_dragButton);
m_dragButton->removeFromParent();
m_dragButton = nullptr;
}
}

bool DevTools::isButtonEnabled() {
#ifdef GEODE_IS_MOBILE
return true;
#else
return m_settings.buttonEnabled;
#endif
}

// Scroll when dragging empty space
void mobileScrollBehavior() {
auto* ctx = ImGui::GetCurrentContext();
Expand Down
10 changes: 10 additions & 0 deletions src/DevTools.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <Geode/loader/Loader.hpp>
#include <Geode/loader/ModMetadata.hpp>

#include "nodes/DragButton.hpp"

using namespace geode::prelude;

enum class HighlightMode {
Expand All @@ -32,6 +34,7 @@ struct Settings {
CCPoint buttonPos = {50, 50};
bool buttonInEditor = false;
bool buttonInGame = false;
bool buttonEnabled = false;
bool treeDragReorder = false;
};

Expand All @@ -57,6 +60,7 @@ class DevTools {
std::string m_searchQuery;
std::string m_prevQuery;
std::unordered_map<CCNode*, bool> m_nodeOpen;
DragButton* m_dragButton = nullptr;

void setupFonts();
void setupPlatform();
Expand Down Expand Up @@ -103,6 +107,7 @@ class DevTools {
void loadSettings();
void saveSettings();
Settings getSettings();
void setBallPosition(CCPoint pos);
bool shouldUseGDWindow() const;

bool shouldPopGame() const;
Expand All @@ -118,6 +123,11 @@ class DevTools {

void addCustomCallback(std::function<void(CCNode*)> callback);

DragButton* getDragButton();
void setupDragButton();
void removeDragButton();
bool isButtonEnabled();

void sceneChanged();

void render(GLRenderCtx* ctx);
Expand Down
9 changes: 3 additions & 6 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,18 @@ class $modify(CCKeyboardDispatcher) {
}
};

#ifdef GEODE_IS_MOBILE

#include <Geode/loader/GameEvent.hpp>
$execute {
new EventListener<GameEventFilter>(+[](GameEvent*) {
DragButton::get();
if (DevTools::get()->isButtonEnabled()) DevTools::get()->setupDragButton();
}, GameEventFilter(GameEventType::Loaded));
}

#include <Geode/modify/CCScene.hpp>
class $modify(CCScene) {
int getHighestChildZ() {
auto btn = DragButton::get();
auto btn = DevTools::get()->getDragButton();
if (!btn) return CCScene::getHighestChildZ();
int z = btn->getZOrder();
btn->setZOrder(-1);
int ret = CCScene::getHighestChildZ();
Expand All @@ -54,8 +53,6 @@ class $modify(CCScene) {
}
};

#endif

class $modify(GameToolbox) {
static void preVisitWithClippingRect(CCNode* node, CCRect clipRect) {
if (!node->isVisible() || !DevTools::get()->isVisible())
Expand Down
25 changes: 5 additions & 20 deletions src/nodes/DragButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "../DevTools.hpp"

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

using namespace geode::prelude;

Expand All @@ -15,7 +16,7 @@ bool DragButton::init(CCNode* node, std::function<void()> onPress) {
this->setContentSize(node->getScaledContentSize());
this->addChildAtPosition(node, Anchor::Center, CCPoint{0, 0});
}
this->m_onPress = onPress;
this->m_onPress = std::move(onPress);
return true;
}

Expand Down Expand Up @@ -59,7 +60,7 @@ void DragButton::registerWithTouchDispatcher() {

DragButton* DragButton::create(CCNode* node, std::function<void ()> onPress) {
auto ret = new DragButton;
if (ret->init(node, onPress)) {
if (ret->init(node, std::move(onPress))) {
ret->autorelease();
return ret;
}
Expand All @@ -84,22 +85,6 @@ void DragButton::setPosition(cocos2d::CCPoint const& pos_) {
auto pos = pos_;
pos.x = std::clamp(pos.x, pad, winSize.width - pad);
pos.y = std::clamp(pos.y, pad, winSize.height - pad);
DevTools::get()->setBallPosition(pos);
CCNode::setPosition(pos);
}

DragButton* DragButton::get() {
static DragButton* instance = nullptr;
if (!instance) {
auto spr = CircleButtonSprite::createWithSprite("devtools.png"_spr, 1, CircleBaseColor::Green, CircleBaseSize::MediumAlt);
spr->setScale(.8f);
instance = DragButton::create(spr, [](){
DevTools::get()->toggle();
});
instance->setPosition(DevTools::get()->getSettings().buttonPos);
instance->setZOrder(10000);
instance->setID("devtools-button"_spr);
CCScene::get()->addChild(instance);
SceneManager::get()->keepAcrossScenes(instance);
}
return instance;
}
}
2 changes: 0 additions & 2 deletions src/nodes/DragButton.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include "Geode/cocos/base_nodes/CCNode.h"
#include "Geode/cocos/layers_scenes_transitions_nodes/CCLayer.h"
#include "Geode/cocos/touch_dispatcher/CCTouchDelegateProtocol.h"

class DragButton : public cocos2d::CCLayer {
protected:
Expand All @@ -20,7 +19,6 @@ class DragButton : public cocos2d::CCLayer {
void update(float dt) override;
public:
static DragButton* create(cocos2d::CCNode* node, std::function<void()> onPress);
static DragButton* get();

void setPosition(cocos2d::CCPoint const& position) override;
};
27 changes: 19 additions & 8 deletions src/pages/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,20 +161,30 @@ void DevTools::drawSettings() {
static_cast<int>(frameSize.width / ratio),
static_cast<int>(frameSize.height / ratio)
);
#else
ImGui::Checkbox("Button In Editor", &m_settings.buttonInEditor);
if (ImGui::IsItemHovered()) {
ImGui::SetTooltip(
"Shows the mobile button in the editor."
);
if (ImGui::Checkbox("Button Enabled", &m_settings.buttonEnabled)) {
if (m_settings.buttonEnabled) setupDragButton();
else removeDragButton();
}
ImGui::Checkbox("Button In Game", &m_settings.buttonInGame);
if (ImGui::IsItemHovered()) {
ImGui::SetTooltip(
"Shows the mobile button in levels."
"Shows the mobile button."
);
}
#endif
if (isButtonEnabled()) {
ImGui::Checkbox("Button In Editor", &m_settings.buttonInEditor);
if (ImGui::IsItemHovered()) {
ImGui::SetTooltip(
"Shows the mobile button in the editor."
);
}
ImGui::Checkbox("Button In Game", &m_settings.buttonInGame);
if (ImGui::IsItemHovered()) {
ImGui::SetTooltip(
"Shows the mobile button in levels."
);
}
}

#if 0
static Ref<CCSet> PAUSED_TARGETS = nullptr;
Expand Down Expand Up @@ -261,3 +271,4 @@ void DevTools::drawSettings() {
}
}
};*/