diff --git a/src/shared/config.cpp b/src/shared/config.cpp index af5c779..992fedd 100644 --- a/src/shared/config.cpp +++ b/src/shared/config.cpp @@ -25,6 +25,7 @@ namespace openhack::config { setIfEmpty("menu.rainbow.saturation", 65.0f); setIfEmpty("menu.rainbow.value", 65.0f); setIfEmpty("menu.checkForUpdates", true); + setIfEmpty("menu.animateOpacity", false); setIfEmpty("keybinds.ingame", false); } diff --git a/src/shared/gui/animation/move_action.cpp b/src/shared/gui/animation/move_action.cpp index 5f26c52..ee2fe48 100644 --- a/src/shared/gui/animation/move_action.cpp +++ b/src/shared/gui/animation/move_action.cpp @@ -40,6 +40,10 @@ namespace openhack::gui::animation { m_target->y = m_start.y + current.y; } + double MoveAction::getProgress() { + return m_easing(m_totalTime / m_duration); + } + bool MoveAction::isFinished() const { return m_totalTime >= m_duration; } diff --git a/src/shared/gui/animation/move_action.hpp b/src/shared/gui/animation/move_action.hpp index babd266..7805b5a 100644 --- a/src/shared/gui/animation/move_action.hpp +++ b/src/shared/gui/animation/move_action.hpp @@ -21,6 +21,10 @@ namespace openhack::gui::animation { /// @param deltaTime How much time passed since last update in seconds void update(double deltaTime); + /// @brief Get current progress of the animation + /// @return Progress in range [0, 1] (note that it can be out of this range if the animation is overshooting) + [[nodiscard]] double getProgress(); + /// @brief Check whether animation has finished /// @return True if it has finished [[nodiscard]] bool isFinished() const; diff --git a/src/shared/gui/themes/megahack/megahack.cpp b/src/shared/gui/themes/megahack/megahack.cpp index dec2bed..5b246d9 100644 --- a/src/shared/gui/themes/megahack/megahack.cpp +++ b/src/shared/gui/themes/megahack/megahack.cpp @@ -103,6 +103,7 @@ namespace openhack::gui { color = config::get("menu.color.primary"); } + color.a *= ImGui::GetStyle().Alpha; auto scale = config::getGlobal("UIScale"); ImGui::GetWindowDrawList()->AddLine( @@ -156,6 +157,7 @@ namespace openhack::gui { auto scale = config::getGlobal("UIScale"); + textColor.a *= ImGui::GetStyle().Alpha; ImGui::GetWindowDrawList()->AddRectFilled( ImVec2(ImGui::GetItemRectMax().x - 5 * scale, ImGui::GetItemRectMin().y + 1 * scale), ImVec2(ImGui::GetItemRectMax().x - 2 * scale, ImGui::GetItemRectMax().y - 1 * scale), @@ -203,11 +205,13 @@ namespace openhack::gui { auto right = ImGui::GetItemRectMax().x - (6 * scale); auto side = bottom - top; auto left = right - side; + auto triangleColor = config::get("menu.color.textDisabled"); + triangleColor.a *= ImGui::GetStyle().Alpha; ImGui::GetWindowDrawList()->AddTriangleFilled( ImVec2(right, top), ImVec2(left, bottom), ImVec2(right, bottom), - config::get("menu.color.textDisabled")); + triangleColor); std::string popupName = std::string("##") + label; if (openPopup) @@ -277,6 +281,7 @@ namespace openhack::gui { auto right = ImGui::GetItemRectMax().x - (6 * scale); auto side = bottom - top; auto left = right - side; + color.a *= ImGui::GetStyle().Alpha; ImGui::GetWindowDrawList()->AddTriangleFilled( ImVec2(right, top), ImVec2(left, bottom), diff --git a/src/shared/menu/menu.cpp b/src/shared/menu/menu.cpp index 5fe618e..1b6f6f4 100644 --- a/src/shared/menu/menu.cpp +++ b/src/shared/menu/menu.cpp @@ -18,6 +18,7 @@ void markdownOpenLink(ImGui::MarkdownLinkCallbackData data) { openhack::utils::o namespace openhack::menu { bool isOpened = false; bool isInitialized = false; + bool isAnimating = false; std::vector windows; std::vector moveActions; @@ -90,6 +91,8 @@ namespace openhack::menu { // Update cursor state updateCursorState(); + + isAnimating = true; } bool isOpen() { return isOpened; } @@ -204,6 +207,7 @@ namespace openhack::menu { gui::animation::EASING_COUNT); gui::combo("Easing Mode", "menu.easingMode", gui::animation::EASING_MODE_NAMES, 3); gui::width(); + gui::checkbox("Animate Opacity", "menu.animateOpacity"); }); // TODO: Implement blur properly @@ -284,6 +288,7 @@ namespace openhack::menu { switch (firstRunState) { case 0: gui::setStyles(); + ImGui::GetStyle().Alpha = 0.0f; for (auto &window: windows) { window.draw(); } @@ -297,6 +302,7 @@ namespace openhack::menu { auto target = randomWindowPosition(window); window.setDrawPosition(target); } + ImGui::GetStyle().Alpha = 1.0f; firstRunState = 2; return; default: @@ -366,6 +372,14 @@ namespace openhack::menu { action->update(utils::getDeltaTime()); } + // Change opacity of the menu to the latest action progress + if (isAnimating && !moveActions.empty() && config::get("menu.animateOpacity", false)) { + auto lastAction = moveActions.back(); + auto progress = std::clamp(lastAction->getProgress(), 0.0, 1.0); + if (!isOpened) progress = 1.0 - progress; + ImGui::GetStyle().Alpha = static_cast(progress); + } + // Update embedded hacks for (auto &hack: hacks::getEmbeddedHacks()) { hack->update(); @@ -384,6 +398,11 @@ namespace openhack::menu { }), moveActions.end()); + // Reset animation flag if there are no more actions + if (moveActions.empty()) { + isAnimating = false; + } + if (!isVisible()) return;