From 3178575f74dc68718b1608faeda5f93947f6a563 Mon Sep 17 00:00:00 2001 From: FriendlyFire Date: Sat, 28 Sep 2024 21:24:55 -0400 Subject: [PATCH] All wheel options now queue, they just hide the queue unless the action fails to occur for too long --- src/MountWheel.cpp | 2 +- src/Wheel.cpp | 77 +++++++++++++++++++++++----------------------- 2 files changed, 39 insertions(+), 40 deletions(-) diff --git a/src/MountWheel.cpp b/src/MountWheel.cpp index 171c439..0b6596d 100644 --- a/src/MountWheel.cpp +++ b/src/MountWheel.cpp @@ -49,7 +49,7 @@ void MountWheel::OnUpdate() // If we mounted up while we had a mount queued, we don't want to try mounting again, that'd dismount us instead! if (conditionalDelay_.element.index() != 0 && MumbleLink::i().currentMount() != MumbleLink::MountType::None) - ResetConditionallyDelayed(true); + ResetConditionallyDelayed(!conditionalDelay_.hidden); } glm::vec4 MountWheel::GetMountColorFromType(MountType m) diff --git a/src/Wheel.cpp b/src/Wheel.cpp index d8aa10a..3f336f3 100644 --- a/src/Wheel.cpp +++ b/src/Wheel.cpp @@ -460,20 +460,34 @@ void Wheel::OnUpdate() auto& cd = conditionalDelay_; if (OptHasValue(cd.element)) { - if (cd.immediate) + const auto currentTime = TimeInMilliseconds(); + if (currentTime > cd.time + maximumConditionalWaitTimeOption_.value() * 1000ull) + ResetConditionallyDelayed(true, currentTime); + else { - if (std::holds_alternative(cd.element) || CanActivate(std::get(cd.element))) + if (cd.immediate) { - auto kb = GetKeybindFromOpt(cd.element); - if (kb) - Input::i().SendKeybind(kb->keyCombo(), std::nullopt); - ResetConditionallyDelayed(false); + if (cd.time <= currentTime && (std::holds_alternative(cd.element) || CanActivate(std::get(cd.element)))) + { + auto kb = GetKeybindFromOpt(cd.element); + if (kb) + Input::i().SendKeybind(kb->keyCombo(), std::nullopt); + + if (clearConditionalDelayOnSend_) + ResetConditionallyDelayed(false, currentTime); + else + { + if (cd.testPasses) + { + cd.time = currentTime + 1000; + cd.testPasses = false; + } + else + cd.hidden = cd.immediate = false; + } + } } - } - else - { - const auto currentTime = TimeInMilliseconds(); - if (currentTime <= cd.time + maximumConditionalWaitTimeOption_.value() * 1000ull) + else { if (std::holds_alternative(cd.element) || CanActivate(std::get(cd.element))) { @@ -486,14 +500,14 @@ void Wheel::OnUpdate() Input::i().SendKeybind(kb->keyCombo(), std::nullopt); if (clearConditionalDelayOnSend_) ResetConditionallyDelayed(true, currentTime); + else + cd.testPassesTime = currentTime + 3000 - conditionalDelayDelayOption_.value(); // At most retry once every 3 seconds } cd.testPasses = true; } else cd.testPasses = false; } - else - ResetConditionallyDelayed(true, currentTime); } } } @@ -1096,37 +1110,22 @@ void Wheel::SendKeybindOrDelay(OptKeybindWheelElement kbwe, std::optional return; } - auto cs = MumbleLink::i().currentState(); + auto cs = MumbleLink::i().currentState(); // We're not checking WvW here; no reason to enqueue an action that would require a map change to execute - if (bool shouldAlwaysDelay = CustomDelayCheck(kbwe); shouldAlwaysDelay || (std::holds_alternative(kbwe) && !std::get(kbwe)->isUsable(cs))) - { - if (mousePos) - Log::i().Print(Severity::Debug, "Moving cursor to position ({}, {}) and delaying keybind.", mousePos->x, mousePos->y); - else - Log::i().Print(Severity::Debug, "Delaying keybind."); - Input::i().SendKeybind({}, mousePos); + bool shouldAlwaysDelay = CustomDelayCheck(kbwe); + bool shouldDelay = shouldAlwaysDelay || (enableQueuingOption_.value() && std::holds_alternative(kbwe) && !std::get(kbwe)->isUsable(cs)); - if (shouldAlwaysDelay || enableQueuingOption_.value()) - { - auto& cd = conditionalDelay_; - cd.element = kbwe; - cd.time = TimeInMilliseconds(); - cd.testPasses = false; - } - } + if (mousePos) + Log::i().Print(Severity::Debug, "Moving cursor to position ({}, {}) and queuing keybind.", mousePos->x, mousePos->y); else - { - if (mousePos) - Log::i().Print(Severity::Debug, "Moving cursor to position ({}, {}) and sending keybind.", mousePos->x, mousePos->y); - else - Log::i().Print(Severity::Debug, "Sending keybind."); + Log::i().Print(Severity::Debug, "Queuing keybind."); + Input::i().SendKeybind({}, mousePos); - Input::i().KeyUpActive(); - auto kb = GetKeybindFromOpt(kbwe); - if (kb) - Input::i().SendKeybind(kb->keyCombo(), mousePos); - } + auto& cd = conditionalDelay_; + cd.element = kbwe; + cd.time = TimeInMilliseconds(); + cd.testPasses = cd.immediate = cd.hidden = !shouldDelay; } void Wheel::ResetConditionallyDelayed(bool withFadeOut, mstime currentTime)