Skip to content

Commit

Permalink
keybinds
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSillyDoggo committed Aug 20, 2024
1 parent e5e8e4b commit 281d794
Show file tree
Hide file tree
Showing 19 changed files with 439 additions and 142 deletions.
2 changes: 1 addition & 1 deletion about.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ QOLMod is The **Best** Free Mod Menu, It has a user friendly interface with over

# How to use.
On Windows / Mac:
- Press **Tab**, **F12**, or **Insert** on your keyboard
- Press **Tab** or **Insert** on your keyboard
- The keybinds for opening the mod menu can be changed in the Mod Settings

On Android:
Expand Down
8 changes: 8 additions & 0 deletions src/Client/AndroidUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ bool AndroidUI::setup()
backMenu->setPositionY(CCDirector::get()->getWinSize().height);
backMenu->setID("back-menu");

backMenu->addChild(CCMenuItemSpriteExtra::create(ButtonSprite::create("Button that turns you into a catboy", 1), this, menu_selector(AndroidUI::onKeybinds)));
as<CCNode*>(backMenu->getChildren()->objectAtIndex(0))->setPosition(ccp(280, -100));

auto backSpr = CCSprite::createWithSpriteFrameName("GJ_arrow_03_001.png");

#ifdef GEODE_IS_APPLE
Expand Down Expand Up @@ -495,6 +498,11 @@ AndroidUI* AndroidUI::addToScene()
return pRet;
}

void AndroidUI::onKeybinds(CCObject*)
{
ManageKeybindsLayer::addToScene();
}

AndroidUI::~AndroidUI()
{
instance = nullptr;
Expand Down
4 changes: 3 additions & 1 deletion src/Client/AndroidUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "../Utils/defines.hpp"
#include "idkwhattocallthis.hpp"
#include "../UI/CategoryTabSprite.hpp"
#include "../Layers/ManageKeybindsLayer.hpp"

using namespace geode::prelude;

Expand All @@ -29,8 +30,9 @@ class AndroidUI : public geode::Popup<>, TextInputDelegate
void goToPage(int p, bool transition = false);

void onClose(CCObject* sender);

void onKeybinds(CCObject*);
void onPressTab(CCObject* sender);

void updateTabs();

virtual bool setup();
Expand Down
52 changes: 52 additions & 0 deletions src/Client/Client.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include "Client.h"

Client* Client::get()
{
return instance;
}

bool Client::handleKeybinds(enumKeyCodes key, bool isDown, bool isRepeatedKey)
{
if (!isDown || key == enumKeyCodes::KEY_Unknown)
return false;

bool shouldPropogate = true;

for (auto window : windows)
{
for (auto module : window->modules)
{
if (isRepeatedKey ? module->keybind.canRepeat : true)
{
bool shouldSend = true;

if (module->keybind.key == enumKeyCodes::KEY_Unknown)
shouldSend = false;

if (module->keybind.shift && !CCKeyboardDispatcher::get()->getShiftKeyPressed())
shouldSend = false;

if (module->keybind.control && !CCKeyboardDispatcher::get()->getControlKeyPressed())
shouldSend = false;

if (module->keybind.alt && !CCKeyboardDispatcher::get()->getAltKeyPressed())
shouldSend = false;

if (module->keybind.command && !CCKeyboardDispatcher::get()->getCommandKeyPressed())
shouldSend = false;

if (shouldSend)
{
module->onToggleAndroid(nullptr);

log::info("toggled: {}", module->id);

if (!shouldPropogate)
return true;
}
}
}
}

return false;
}
4 changes: 4 additions & 0 deletions src/Client/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ class Client
mod = Mod::get();
}

static Client* get();

bool handleKeybinds(enumKeyCodes key, bool isDown, bool isRepeatedKey);

//[[deprecated("GetModuleEnabled has been deprecated due to lag, please rember to cache the module :3")]]
static bool GetModuleEnabled(std::string id)
{
Expand Down
14 changes: 14 additions & 0 deletions src/Client/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,20 @@ void Module::onInfoAndroid(CCObject* sender)

void Module::onToggleAndroid(CCObject* sender)
{
if (!sender)
{
enabled = !enabled;
save();
onChange();

if (enabled)
enableHooks();
else
disableHooks();

return;
}

auto dat = static_cast<Module*>(static_cast<CCNode*>(sender)->getUserData());

if (dat->isInComp)
Expand Down
5 changes: 5 additions & 0 deletions src/Client/Module.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "DrawUtils.h"
#include <Geode/ui/TextInput.hpp>
#include "../UI/UIComponent.hpp"
#include "../Keybinds/KeyStruct.hpp"

using namespace geode::prelude;

Expand Down Expand Up @@ -41,6 +42,8 @@ class Module : public UIComponent
bool onceAlert;
bool isInComp;

KeyStruct keybind;

bool vAlert;

bool def;
Expand Down Expand Up @@ -113,10 +116,12 @@ class Module : public UIComponent
virtual void save()
{
geode::prelude::Mod::get()->setSavedValue<bool>(id + "_enabled", enabled);
keybind.saveToModule(id);
}

virtual void load()
{
keybind = KeyStruct::loadFromModule(id);
enabled = geode::prelude::Mod::get()->getSavedValue<bool>(id + "_enabled", def);
save();
}
Expand Down
30 changes: 0 additions & 30 deletions src/FrameStepper.cpp

This file was deleted.

10 changes: 0 additions & 10 deletions src/FrameStepper.h

This file was deleted.

27 changes: 27 additions & 0 deletions src/Keybinds/KeyStruct.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "KeyStruct.hpp"

using namespace geode::prelude;

KeyStruct KeyStruct::loadFromModule(std::string id)
{
KeyStruct key;

key.key = as<enumKeyCodes>(Mod::get()->getSavedValue<int>(fmt::format("{}_bind-key", id), -1));
key.shift = Mod::get()->getSavedValue<bool>(fmt::format("{}_bind-shift", id), key.shift);
key.alt = Mod::get()->getSavedValue<bool>(fmt::format("{}_bind-alt", id), key.alt);
key.canRepeat = Mod::get()->getSavedValue<bool>(fmt::format("{}_bind-can-repeat", id), key.canRepeat);
key.command = Mod::get()->getSavedValue<bool>(fmt::format("{}_bind-cmd", id), key.command);
key.control = Mod::get()->getSavedValue<bool>(fmt::format("{}_bind-ctrl", id), key.control);

return key;
}

void KeyStruct::saveToModule(std::string id)
{
Mod::get()->setSavedValue<int >(fmt::format("{}_bind-key" , id), as<int>(key));
Mod::get()->setSavedValue<bool>(fmt::format("{}_bind-shift" , id), shift);
Mod::get()->setSavedValue<bool>(fmt::format("{}_bind-alt" , id), alt);
Mod::get()->setSavedValue<bool>(fmt::format("{}_bind-can-repeat", id), canRepeat);
Mod::get()->setSavedValue<bool>(fmt::format("{}_bind-cmd" , id), command);
Mod::get()->setSavedValue<bool>(fmt::format("{}_bind-ctrl" , id), control);
}
19 changes: 19 additions & 0 deletions src/Keybinds/KeyStruct.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include <Geode/Geode.hpp>

struct KeyStruct
{
public:
// Modifiers
bool control;
bool alt;
bool shift;
bool command;

cocos2d::enumKeyCodes key = cocos2d::enumKeyCodes::KEY_Unknown;
bool canRepeat = true;

static KeyStruct loadFromModule(std::string id);
void saveToModule(std::string id);
};
2 changes: 1 addition & 1 deletion src/Keybinds/RecordKeyPopup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ bool RecordKeyPopup::init(SEL_MenuHandler obj)
CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, -500, true);

auto bg = CCScale9Sprite::create("square02_small.png");
bg->setOpacity(100);
bg->setOpacity(200);
bg->setContentSize(ccp(245, 70));
bg->setPosition(CCDirector::get()->getWinSize() / 2);
this->addChild(bg);
Expand Down
Loading

0 comments on commit 281d794

Please sign in to comment.