Skip to content

Commit

Permalink
All wheel options now queue, they just hide the queue unless the acti…
Browse files Browse the repository at this point in the history
…on fails to occur for too long
  • Loading branch information
Friendly0Fire committed Sep 29, 2024
1 parent 95453aa commit 3178575
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 40 deletions.
2 changes: 1 addition & 1 deletion src/MountWheel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
77 changes: 38 additions & 39 deletions src/Wheel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Keybind*>(cd.element) || CanActivate(std::get<WheelElement*>(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<Keybind*>(cd.element) || CanActivate(std::get<WheelElement*>(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<Keybind*>(cd.element) || CanActivate(std::get<WheelElement*>(cd.element)))
{
Expand All @@ -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);
}
}
}
Expand Down Expand Up @@ -1096,37 +1110,22 @@ void Wheel::SendKeybindOrDelay(OptKeybindWheelElement kbwe, std::optional<Point>
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<WheelElement*>(kbwe) && !std::get<WheelElement*>(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<WheelElement*>(kbwe) && !std::get<WheelElement*>(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)
Expand Down

0 comments on commit 3178575

Please sign in to comment.