From ea1e2d3d8370dbde0494591a6e39f62972ff3fa6 Mon Sep 17 00:00:00 2001 From: = Date: Sat, 3 Aug 2024 23:55:14 +0800 Subject: [PATCH] smooth toggles --- .../Engine/Elements/Control/Toggle/Toggle.cpp | 99 +----- src/Client/Module/Modules/Module.cpp | 280 ++++++++++++++++ src/Client/Module/Modules/Module.hpp | 298 ++---------------- 3 files changed, 315 insertions(+), 362 deletions(-) diff --git a/src/Client/GUI/Engine/Elements/Control/Toggle/Toggle.cpp b/src/Client/GUI/Engine/Elements/Control/Toggle/Toggle.cpp index ece5efe9..46e0198a 100644 --- a/src/Client/GUI/Engine/Elements/Control/Toggle/Toggle.cpp +++ b/src/Client/GUI/Engine/Elements/Control/Toggle/Toggle.cpp @@ -37,81 +37,10 @@ #define colors_secondary7_rgb clickgui->settings.getSettingByName("colors_secondary7_rgb")->value bool FlarialGUI::Toggle(int index, float x, float y, bool isEnabled) { - - D2D1_COLOR_F disabledColor = colors_primary3_rgb ? rgbColor : colors_primary3; - D2D1_COLOR_F enabledColor = colors_primary1_rgb ? rgbColor : colors_primary1; - D2D1_COLOR_F circleColor = colors_primary2_rgb ? rgbColor : colors_primary2; - - disabledColor.a = o_colors_primary3; - enabledColor.a = o_colors_primary1; - circleColor.a = o_colors_primary2; - - if (shouldAdditionalY) { - - for (int i = 0; i < highestAddIndexes + 1; i++) { - if (FlarialGUI::DropDownMenus[i].isActive && i <= additionalIndex) { - y += additionalY[i]; - } - } - } - - const bool isAdditionalY = shouldAdditionalY; - float rectWidth = Constraints::RelativeConstraint(0.062, "height", true); - float rectHeight = Constraints::RelativeConstraint(0.03, "height", true); - - Vec2 round = Constraints::RoundingConstraint(30, 30); - - if (isAdditionalY) UnSetIsInAdditionalYMode(); - - if (isEnabled) { - toggleColors[index] = FlarialGUI::LerpColor(toggleColors[index], enabledColor, 0.10f * FlarialGUI::frameFactor); - } else { - toggleColors[index] = FlarialGUI::LerpColor(toggleColors[index], disabledColor, - 0.10f * FlarialGUI::frameFactor); - } - - FlarialGUI::RoundedRect(x, y, toggleColors[index], rectWidth, rectHeight, round.x, round.x); - - // the circle (I KNOW IM USING A RECT LOL) - - float circleWidth = Constraints::RelativeConstraint(0.0202, "height", true); - float circleHeight = Constraints::RelativeConstraint(0.02, "height", true); - - - float ySpacing = Constraints::SpacingConstraint(0.2, circleHeight); - float xSpacing = Constraints::SpacingConstraint(0.2, circleWidth); - round = Constraints::RoundingConstraint(23, 23); - - float enabledSpacing; - - if (isEnabled) { - FadeEffect::ApplyFadeInEffect(2.4f * FlarialGUI::frameFactor, Constraints::SpacingConstraint(1.6, circleWidth), - FlarialGUI::toggleSpacings[index]); - enabledSpacing = FlarialGUI::toggleSpacings[index]; - if (enabledSpacing > Constraints::SpacingConstraint(1.6, circleWidth)) - enabledSpacing = Constraints::SpacingConstraint(1.6, circleWidth); - } else { - FadeEffect::ApplyFadeOutEffect(2.4f * FlarialGUI::frameFactor, FlarialGUI::toggleSpacings[index]); - enabledSpacing = FlarialGUI::toggleSpacings[index]; - } - - FlarialGUI::RoundedRect(x + xSpacing + enabledSpacing, y + ySpacing, circleColor, circleWidth, circleHeight, - round.x, round.x); - - if (isAdditionalY) SetIsInAdditionalYMode(); - - if (isInScrollView) y += FlarialGUI::scrollpos; - if (CursorInRect(x, y, rectWidth, rectHeight) && MC::mouseButton == MouseButton::Left && !MC::held && - (!activeColorPickerWindows || index == 123)) { - MC::mouseButton = MouseButton::None; - return true; - } - - return false; + return FlarialGUI::Toggle(index, x, y, isEnabled, false); } bool FlarialGUI::Toggle(int index, float x, float y, bool isEnabled, bool rgb) { - D2D1_COLOR_F disabledColor = colors_primary3; D2D1_COLOR_F enabledColor = colors_primary1; D2D1_COLOR_F circleColor = colors_primary2; @@ -121,7 +50,6 @@ bool FlarialGUI::Toggle(int index, float x, float y, bool isEnabled, bool rgb) { circleColor.a = o_colors_primary2; if (shouldAdditionalY) { - for (int i = 0; i < highestAddIndexes + 1; i++) { if (FlarialGUI::DropDownMenus[i].isActive && i <= additionalIndex) { y += additionalY[i]; @@ -130,8 +58,10 @@ bool FlarialGUI::Toggle(int index, float x, float y, bool isEnabled, bool rgb) { } const bool isAdditionalY = shouldAdditionalY; - float rectWidth = Constraints::RelativeConstraint(0.062, "height", true); - float rectHeight = Constraints::RelativeConstraint(0.03, "height", true); + float rectWidth = Constraints::RelativeConstraint(0.058, "height", true); + float rectHeight = Constraints::RelativeConstraint(0.027, "height", true); + + y -= rectHeight / 2.0f; Vec2 round = Constraints::RoundingConstraint(30, 30); @@ -140,32 +70,31 @@ bool FlarialGUI::Toggle(int index, float x, float y, bool isEnabled, bool rgb) { if (isEnabled) { toggleColors[index] = FlarialGUI::LerpColor(toggleColors[index], enabledColor, 0.10f * FlarialGUI::frameFactor); } else { - toggleColors[index] = FlarialGUI::LerpColor(toggleColors[index], disabledColor, - 0.10f * FlarialGUI::frameFactor); + toggleColors[index] = FlarialGUI::LerpColor(toggleColors[index], disabledColor, 0.10f * FlarialGUI::frameFactor); } FlarialGUI::RoundedRect(x, y, rgb ? rgbColor : toggleColors[index], rectWidth, rectHeight, round.x, round.x); // the circle (I KNOW IM USING A RECT LOL) - float circleWidth = Constraints::RelativeConstraint(0.0202, "height", true); - float circleHeight = Constraints::RelativeConstraint(0.02, "height", true); - + float circleWidth = Constraints::SpacingConstraint(0.7, rectHeight); + float circleHeight = Constraints::SpacingConstraint(0.7, rectHeight); - float ySpacing = Constraints::SpacingConstraint(0.2205f, circleHeight); + float ySpacing = Constraints::SpacingConstraint(0.2f, circleHeight); float xSpacing = Constraints::SpacingConstraint(0.2f, circleWidth); round = Constraints::RoundingConstraint(23, 23); float enabledSpacing; if (isEnabled) { - FadeEffect::ApplyFadeInEffect(2.4f * FlarialGUI::frameFactor, Constraints::SpacingConstraint(1.6, circleWidth), - FlarialGUI::toggleSpacings[index]); + FlarialGUI::lerp(FlarialGUI::toggleSpacings[index], Constraints::SpacingConstraint(1.6, circleWidth), 0.25f * FlarialGUI::frameFactor); + //FadeEffect::ApplyFadeInEffect(2.4f * FlarialGUI::frameFactor, Constraints::SpacingConstraint(1.6, circleWidth),FlarialGUI::toggleSpacings[index]); enabledSpacing = FlarialGUI::toggleSpacings[index]; if (enabledSpacing > Constraints::SpacingConstraint(1.6, circleWidth)) - enabledSpacing = Constraints::SpacingConstraint(1.6, circleWidth); + enabledSpacing = Constraints::SpacingConstraint(1.6, circleWidth); } else { - FadeEffect::ApplyFadeOutEffect(2.4f * FlarialGUI::frameFactor, FlarialGUI::toggleSpacings[index]); + FlarialGUI::lerp(FlarialGUI::toggleSpacings[index], 0.0f, 0.25f * FlarialGUI::frameFactor); + //FadeEffect::ApplyFadeOutEffect(2.4f * FlarialGUI::frameFactor, FlarialGUI::toggleSpacings[index]); enabledSpacing = FlarialGUI::toggleSpacings[index]; } diff --git a/src/Client/Module/Modules/Module.cpp b/src/Client/Module/Modules/Module.cpp index eeeb6525..b59ca04c 100644 --- a/src/Client/Module/Modules/Module.cpp +++ b/src/Client/Module/Modules/Module.cpp @@ -186,3 +186,283 @@ void Module::normalRender(int index, std::string &value) { FlarialGUI::UnsetWindowRect(); } +void Module::resetPadding() { + padding = 0; + toggleIndex = 0; + dropdownIndex = 0; + sliderIndex = 0; + colorPickerIndex = 0; + keybindIndex = 0; + textboxIndex = 0; +} + +void Module::addToggle(std::string text, std::string subtext, bool& value) { + float x = Constraints::PercentageConstraint(0.019, "left"); + float elementX = Constraints::PercentageConstraint(0.119f, "right"); + float y = Constraints::PercentageConstraint(0.10, "top") + padding; + + if (FlarialGUI::Toggle(toggleIndex, elementX, y, value, false)) value = !value; + + float textX = x; + float textY = y; // For some reason, if you do not do this minus, the spacing is way bigger than expected. + float subtextY; + float fontSize = Constraints::RelativeConstraint(0.155f, "height", true); + float fontSize2 = Constraints::RelativeConstraint(0.132f, "height", true); + + if (!subtext.empty()) { + subtextY = textY; + textY -= Constraints::RelativeConstraint(0.009f, "height", true); + subtextY += Constraints::RelativeConstraint(0.009f, "height", true); + } + else { + textY += Constraints::RelativeConstraint(0.0015f, "height", true); + } + + FlarialGUI::FlarialTextWithFont(textX, textY, FlarialGUI::to_wide(text).c_str(), 200, 0, DWRITE_TEXT_ALIGNMENT_LEADING, fontSize, DWRITE_FONT_WEIGHT_MEDIUM, false); + if (!subtext.empty()) FlarialGUI::FlarialTextWithFont(textX, subtextY, FlarialGUI::to_wide(subtext).c_str(), 200, 0, DWRITE_TEXT_ALIGNMENT_LEADING, fontSize2, DWRITE_FONT_WEIGHT_MEDIUM, FlarialGUI::HexToColorF("473b3d"), false); + + + padding += Constraints::RelativeConstraint(0.05f, "height", true); + toggleIndex++; +} + +void Module::loadDefaults() { + settings.reset(); + setup(); +} + +void Module::saveSettings() const { + try { + std::ofstream outputFile(settingspath); + if (outputFile.is_open()) { + std::string jsonString = settings.ToJson(); + outputFile << jsonString; + outputFile.close(); + } + else { + Logger::error("Failed to open file. Maybe it doesn't exist?: " + settingspath); + } + } + catch (const std::exception& ex) { + Logger::error(ex.what()); + } +} + +void Module::loadSettings() { + std::ifstream inputFile(settingspath); + std::stringstream ss; + + if (inputFile.is_open()) { + ss << inputFile.rdbuf(); + inputFile.close(); + } + else { + Logger::error("File could not be opened. Maybe it doesn't exist?: " + settingspath); + return; + } + + std::string settingstring = ss.str(); + settings.FromJson(settingstring); +} + +void Module::checkSettingsFile() const { + + if (!std::filesystem::exists(settingspath)) { + + std::filesystem::path filePath(settingspath); + std::filesystem::create_directories(filePath.parent_path()); + + HANDLE fileHandle = CreateFileA(settingspath.c_str(), GENERIC_WRITE | GENERIC_READ, + FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, + OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); + + if (fileHandle == INVALID_HANDLE_VALUE) { + Logger::error("Failed to create file: " + settingspath); + return; + } + + CloseHandle(fileHandle); + } +} + +void Module::toggle() { + bool& enabled = settings.getSettingByName("enabled")->value; + enabled = !enabled; + if (enabled) { + onEnable(); + } + else { + onDisable(); + } +} + +void Module::setup() { + defaultConfig(); + Module::defaultConfig(); + onSetup(); + // TODO: might call on enable twice + if (settings.getSettingByName("enabled")->value) + onEnable(); +} + +void Module::onSetup() { } + +// TODO: rename to Enable/Disable? +void Module::onEnable() { + settings.getSettingByName("enabled")->value = true; + saveSettings(); +} + +void Module::onDisable() { + active = false; + if (!terminating) { + settings.getSettingByName("enabled")->value = false; + } + saveSettings(); +} + +void Module::terminate() { + terminating = true; + onDisable(); + active = false; + settings.getSettingByName("enabled")->value = false; +} + +// TODO: find all getSettingByName("enabled")->value and replace!!! +bool Module::isEnabled() { + return settings.getSettingByName("enabled")->value; +} + +void Module::setEnabled(bool enabled) { + settings.getSettingByName("enabled")->value = enabled; +} + +void Module::setKeybind(const std::string& newKeybind) { + auto key = settings.getSettingByName("keybind"); + if (key == nullptr) + settings.addSetting("keybind", newKeybind); +} + +std::string& Module::getKeybind() { + auto key = settings.getSettingByName("keybind"); + if (key == nullptr) + settings.addSetting("keybind", defaultKeybind); + return settings.getSettingByName("keybind")->value; +} + +void Module::defaultConfig() { + + getKeybind(); + + if (settings.getSettingByName("enabled") == nullptr) { + settings.addSetting("enabled", false); + } + + if (settings.getSettingByName("percentageX") == nullptr) { + settings.addSetting("percentageX", 0.0f); + settings.addSetting("percentageY", 0.0f); + } + + if (settings.getSettingByName("border") == nullptr) { + settings.addSetting("border", false); + settings.addSetting("borderWidth", 1.0f); + } + + if (settings.getSettingByName("reversepaddingx") == nullptr) + settings.addSetting("reversepaddingx", false); + if (settings.getSettingByName("reversepaddingy") == nullptr) + settings.addSetting("reversepaddingy", false); + if (settings.getSettingByName("padx") == nullptr) settings.addSetting("padx", 0.0f); + if (settings.getSettingByName("pady") == nullptr) settings.addSetting("pady", 0.0f); + if (settings.getSettingByName("rectwidth") == nullptr) settings.addSetting("rectwidth", 1.0f); + if (settings.getSettingByName("rectheight") == nullptr) settings.addSetting("rectheight", 1.0f); + if (settings.getSettingByName("responsivewidth") == nullptr) + settings.addSetting("responsivewidth", false); + if (settings.getSettingByName("textalignment") == nullptr) + settings.addSetting("textalignment", (std::string)"Center"); + + if (settings.getSettingByName("rounding") == nullptr) settings.addSetting("rounding", 32.0f); + + if (settings.getSettingByName("bgColor") == nullptr) { + settings.addSetting("bgColor", (std::string)"000000"); + settings.addSetting("textColor", (std::string)"fafafa"); + settings.addSetting("borderColor", (std::string)"000000"); + } + + if (settings.getSettingByName("bgOpacity") == nullptr) { + settings.addSetting("bgOpacity", 0.55f); + settings.addSetting("textOpacity", 1.0f); + settings.addSetting("borderOpacity", 1.0f); + } + + if (settings.getSettingByName("bgRGB") == nullptr) { + settings.addSetting("bgRGB", false); + settings.addSetting("textRGB", false); + settings.addSetting("borderRGB", false); + } + + if (settings.getSettingByName("uiscale") == nullptr) { + + settings.addSetting("uiscale", 0.65f); + } + + if (settings.getSettingByName("rotation") == nullptr) { + settings.addSetting("rotation", 0.0f); + } + + if (settings.getSettingByName("BlurEffect") == nullptr) { + settings.addSetting("BlurEffect", false); + } + +} + +bool Module::isKeybind(const std::array& keys) { + + std::vector keyCodes = Utils::getStringAsKeys(getKeybind()); + + for (int keyCode : keyCodes) { + if (!keys[keyCode]) { + // Key is not being held down + return false; + } + } + // TODO: in menu should also mean in Edit Mode, when edit mode all modules set to active(visible? add visible setting (for TAB)) + if (name != "ClickGUI") + if (FlarialGUI::inMenu) return false; + if (SDK::currentScreen == "chat_screen") return false; + bool allInactive = std::ranges::all_of(FlarialGUI::TextBoxes, [](const TextBoxStruct& i) { + return !i.isActive; + }); + // All keys in the keybind are being held down + return allInactive; +} + +[[nodiscard]] bool Module::isAdditionalKeybind(const std::array& keys, const std::string& bind) const { + std::vector keyCodes = Utils::getStringAsKeys(bind); + + for (int keyCode : keyCodes) { + if (!keys[keyCode]) { + + // Key is not being held down + return false; + } + } + if (name != "ClickGUI") + if (FlarialGUI::inMenu) return false; + if (SDK::currentScreen == "chat_screen") return false; + bool allInactive = std::ranges::all_of(FlarialGUI::TextBoxes, [](const TextBoxStruct& i) { + return !i.isActive; + }); + // All keys in the keybind are being held down + return allInactive; +} + +bool Module::isKeyPartOfKeybind(int keyCode) { + std::vector keyCodes = Utils::getStringAsKeys(getKeybind()); + return std::find(keyCodes.begin(), keyCodes.end(), keyCode) != keyCodes.end(); +} + +bool Module::isKeyPartOfAdditionalKeybind(int keyCode, const std::string& bind) { + std::vector keyCodes = Utils::getStringAsKeys(bind); + return std::find(keyCodes.begin(), keyCodes.end(), keyCode) != keyCodes.end(); +} \ No newline at end of file diff --git a/src/Client/Module/Modules/Module.hpp b/src/Client/Module/Modules/Module.hpp index e5a4ca25..965e961b 100644 --- a/src/Client/Module/Modules/Module.hpp +++ b/src/Client/Module/Modules/Module.hpp @@ -47,283 +47,27 @@ class Module { int keybindIndex = 0; int colorPickerIndex = 0; - virtual void loadDefaults() { - settings.reset(); - setup(); - } - - void saveSettings() const { - try { - std::ofstream outputFile(settingspath); - if (outputFile.is_open()) { - std::string jsonString = settings.ToJson(); - outputFile << jsonString; - outputFile.close(); - } else { - Logger::error("Failed to open file. Maybe it doesn't exist?: " + settingspath); - } - } catch (const std::exception &ex) { - Logger::error(ex.what()); - } - } - - void loadSettings() { - std::ifstream inputFile(settingspath); - std::stringstream ss; - - if (inputFile.is_open()) { - ss << inputFile.rdbuf(); - inputFile.close(); - } else { - Logger::error("File could not be opened. Maybe it doesn't exist?: " + settingspath); - return; - } - - std::string settingstring = ss.str(); - settings.FromJson(settingstring); - } - - void checkSettingsFile() const { - - if (!std::filesystem::exists(settingspath)) { - - std::filesystem::path filePath(settingspath); - std::filesystem::create_directories(filePath.parent_path()); - - HANDLE fileHandle = CreateFileA(settingspath.c_str(), GENERIC_WRITE | GENERIC_READ, - FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, - OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); - - if (fileHandle == INVALID_HANDLE_VALUE) { - Logger::error("Failed to create file: " + settingspath); - return; - } - - CloseHandle(fileHandle); - } - } - - virtual void toggle() { - bool &enabled = settings.getSettingByName("enabled")->value; - enabled = !enabled; - if (enabled) { - onEnable(); - } else { - onDisable(); - } - } - - virtual void setup() { - defaultConfig(); - Module::defaultConfig(); - onSetup(); - // TODO: might call on enable twice - if(settings.getSettingByName("enabled")->value) - onEnable(); - } - - virtual void onSetup() { } - - // TODO: rename to Enable/Disable? - virtual void onEnable() { - settings.getSettingByName("enabled")->value = true; - saveSettings(); - } - - virtual void onDisable() { - active = false; - if(!terminating) { - settings.getSettingByName("enabled")->value = false; - } - saveSettings(); - } - - virtual void terminate() { - terminating = true; - onDisable(); - active = false; - settings.getSettingByName("enabled")->value = false; - } - - // TODO: find all getSettingByName("enabled")->value and replace!!! - bool isEnabled() { - return settings.getSettingByName("enabled")->value; - } - - void setEnabled(bool enabled) { - settings.getSettingByName("enabled")->value = enabled; - } - - void setKeybind(const std::string& newKeybind) { - auto key = settings.getSettingByName("keybind"); - if(key == nullptr) - settings.addSetting("keybind", newKeybind); - } - - std::string& getKeybind() { - auto key = settings.getSettingByName("keybind"); - if(key == nullptr) - settings.addSetting("keybind", defaultKeybind); - return settings.getSettingByName("keybind")->value; - } - - virtual void defaultConfig() { - - getKeybind(); - - if (settings.getSettingByName("enabled") == nullptr) { - settings.addSetting("enabled", false); - } - - if (settings.getSettingByName("percentageX") == nullptr) { - settings.addSetting("percentageX", 0.0f); - settings.addSetting("percentageY", 0.0f); - } - - if (settings.getSettingByName("border") == nullptr) { - settings.addSetting("border", false); - settings.addSetting("borderWidth", 1.0f); - } - - if (settings.getSettingByName("reversepaddingx") == nullptr) - settings.addSetting("reversepaddingx", false); - if (settings.getSettingByName("reversepaddingy") == nullptr) - settings.addSetting("reversepaddingy", false); - if (settings.getSettingByName("padx") == nullptr) settings.addSetting("padx", 0.0f); - if (settings.getSettingByName("pady") == nullptr) settings.addSetting("pady", 0.0f); - if (settings.getSettingByName("rectwidth") == nullptr) settings.addSetting("rectwidth", 1.0f); - if (settings.getSettingByName("rectheight") == nullptr) settings.addSetting("rectheight", 1.0f); - if (settings.getSettingByName("responsivewidth") == nullptr) - settings.addSetting("responsivewidth", false); - if (settings.getSettingByName("textalignment") == nullptr) - settings.addSetting("textalignment", (std::string) "Center"); - - if (settings.getSettingByName("rounding") == nullptr) settings.addSetting("rounding", 32.0f); - - if (settings.getSettingByName("bgColor") == nullptr) { - settings.addSetting("bgColor", (std::string) "000000"); - settings.addSetting("textColor", (std::string) "fafafa"); - settings.addSetting("borderColor", (std::string) "000000"); - } - - if (settings.getSettingByName("bgOpacity") == nullptr) { - settings.addSetting("bgOpacity", 0.55f); - settings.addSetting("textOpacity", 1.0f); - settings.addSetting("borderOpacity", 1.0f); - } - - if (settings.getSettingByName("bgRGB") == nullptr) { - settings.addSetting("bgRGB", false); - settings.addSetting("textRGB", false); - settings.addSetting("borderRGB", false); - } - - if (settings.getSettingByName("uiscale") == nullptr) { - - settings.addSetting("uiscale", 0.65f); - } - - if (settings.getSettingByName("rotation") == nullptr) { - settings.addSetting("rotation", 0.0f); - } - - if (settings.getSettingByName("BlurEffect") == nullptr) { - settings.addSetting("BlurEffect", false); - } - - } - - void resetPadding () { - padding = 0; - toggleIndex = 0; - dropdownIndex = 0; - sliderIndex = 0; - colorPickerIndex = 0; - keybindIndex = 0; - textboxIndex = 0; - } - - void addToggle(std::string text, std::string subtext, bool& value) { - - float x = Constraints::PercentageConstraint(0.019, "left"); - float elementX = Constraints::PercentageConstraint(0.119f, "right"); - float y = Constraints::PercentageConstraint(0.10, "top") + padding; - - if(FlarialGUI::Toggle(toggleIndex, elementX, y, value, false)) value = !value; - - float textX = x; - float textY = y - Constraints::RelativeConstraint(0.087f, "height", true); // For some reason, if you do not do this minus, the spacing is way bigger than expected. - float subtextY; - float fontSize = Constraints::RelativeConstraint(0.132f, "height", true); - - if(!subtext.empty()) { - subtextY = textY; - textY -= Constraints::RelativeConstraint(0.009f, "height", true); - subtextY += Constraints::RelativeConstraint(0.009f, "height", true); - } else { - textY += Constraints::RelativeConstraint(0.0015f, "height", true); - } - - FlarialGUI::FlarialTextWithFont(textX, textY, FlarialGUI::to_wide(text).c_str(), 200, 200, DWRITE_TEXT_ALIGNMENT_LEADING, fontSize, DWRITE_FONT_WEIGHT_MEDIUM, false); - if(!subtext.empty()) FlarialGUI::FlarialTextWithFont(textX, subtextY, FlarialGUI::to_wide(subtext).c_str(), 200, 200, DWRITE_TEXT_ALIGNMENT_LEADING, fontSize, DWRITE_FONT_WEIGHT_MEDIUM, FlarialGUI::HexToColorF("473b3d"), false); - - - padding += Constraints::RelativeConstraint(0.05f, "height", true); - toggleIndex++; - } - + void resetPadding(); + void addToggle(std::string text, std::string subtext, bool& value); + virtual void loadDefaults(); + void saveSettings() const; + void loadSettings(); + void checkSettingsFile() const; + virtual void toggle(); + virtual void setup(); + virtual void onSetup(); + virtual void onEnable(); + virtual void onDisable(); + virtual void terminate(); + bool isEnabled(); + void setEnabled(bool enabled); + void setKeybind(const std::string& newKeybind); + std::string& getKeybind(); + virtual void defaultConfig(); virtual void settingsRender() {} - - bool isKeybind(const std::array &keys) { - - std::vector keyCodes = Utils::getStringAsKeys(getKeybind()); - - for (int keyCode: keyCodes) { - if (!keys[keyCode]) { - // Key is not being held down - return false; - } - } - // TODO: in menu should also mean in Edit Mode, when edit mode all modules set to active(visible? add visible setting (for TAB)) - if(name!="ClickGUI") - if (FlarialGUI::inMenu) return false; - if (SDK::currentScreen == "chat_screen") return false; - bool allInactive = std::ranges::all_of(FlarialGUI::TextBoxes, [](const TextBoxStruct& i) { - return !i.isActive; - }); - // All keys in the keybind are being held down - return allInactive; - } - - [[nodiscard]] bool isAdditionalKeybind(const std::array &keys, const std::string& bind) const { - std::vector keyCodes = Utils::getStringAsKeys(bind); - - for (int keyCode: keyCodes) { - if (!keys[keyCode]) { - - // Key is not being held down - return false; - } - } - if(name!="ClickGUI") - if (FlarialGUI::inMenu) return false; - if (SDK::currentScreen == "chat_screen") return false; - bool allInactive = std::ranges::all_of(FlarialGUI::TextBoxes, [](const TextBoxStruct& i) { - return !i.isActive; - }); - // All keys in the keybind are being held down - return allInactive; - } - - bool isKeyPartOfKeybind(int keyCode) { - std::vector keyCodes = Utils::getStringAsKeys(getKeybind()); - return std::find(keyCodes.begin(), keyCodes.end(), keyCode) != keyCodes.end(); - } - - static bool isKeyPartOfAdditionalKeybind(int keyCode, const std::string& bind) { - std::vector keyCodes = Utils::getStringAsKeys(bind); - return std::find(keyCodes.begin(), keyCodes.end(), keyCode) != keyCodes.end(); - } - + bool isKeybind(const std::array& keys); + [[nodiscard]] bool isAdditionalKeybind(const std::array& keys, const std::string& bind) const; + bool isKeyPartOfKeybind(int keyCode); + static bool isKeyPartOfAdditionalKeybind(int keyCode, const std::string& bind); virtual void normalRender(int index, std::string& value); }; \ No newline at end of file