Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

Commit

Permalink
fix menu being visible for one frame + animations
Browse files Browse the repository at this point in the history
after adding a fix to relocate the windows, they were being rendered for one frame, which is now fixed.
also added abillity to toggle opacity animation for open/close toggle
  • Loading branch information
Prevter committed Mar 24, 2024
1 parent a64fbc1 commit c178d6e
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/shared/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
4 changes: 4 additions & 0 deletions src/shared/gui/animation/move_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 4 additions & 0 deletions src/shared/gui/animation/move_action.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion src/shared/gui/themes/megahack/megahack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ namespace openhack::gui {
color = config::get<Color>("menu.color.primary");
}

color.a *= ImGui::GetStyle().Alpha;
auto scale = config::getGlobal<float>("UIScale");

ImGui::GetWindowDrawList()->AddLine(
Expand Down Expand Up @@ -156,6 +157,7 @@ namespace openhack::gui {

auto scale = config::getGlobal<float>("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),
Expand Down Expand Up @@ -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<Color>("menu.color.textDisabled");
triangleColor.a *= ImGui::GetStyle().Alpha;
ImGui::GetWindowDrawList()->AddTriangleFilled(
ImVec2(right, top),
ImVec2(left, bottom),
ImVec2(right, bottom),
config::get<Color>("menu.color.textDisabled"));
triangleColor);

std::string popupName = std::string("##") + label;
if (openPopup)
Expand Down Expand Up @@ -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),
Expand Down
19 changes: 19 additions & 0 deletions src/shared/menu/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<gui::Window> windows;
std::vector<gui::animation::MoveAction *> moveActions;

Expand Down Expand Up @@ -90,6 +91,8 @@ namespace openhack::menu {

// Update cursor state
updateCursorState();

isAnimating = true;
}

bool isOpen() { return isOpened; }
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -284,6 +288,7 @@ namespace openhack::menu {
switch (firstRunState) {
case 0:
gui::setStyles();
ImGui::GetStyle().Alpha = 0.0f;
for (auto &window: windows) {
window.draw();
}
Expand All @@ -297,6 +302,7 @@ namespace openhack::menu {
auto target = randomWindowPosition(window);
window.setDrawPosition(target);
}
ImGui::GetStyle().Alpha = 1.0f;
firstRunState = 2;
return;
default:
Expand Down Expand Up @@ -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<bool>("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<float>(progress);
}

// Update embedded hacks
for (auto &hack: hacks::getEmbeddedHacks()) {
hack->update();
Expand All @@ -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;

Expand Down

2 comments on commit c178d6e

@Askar4iklol
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please .geode version

@Askar4iklol
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i found geode version thanks

Please sign in to comment.