Skip to content

Commit

Permalink
run energy: fix orb text flickering
Browse files Browse the repository at this point in the history
It is possible a clientscript can update the energy in between the last
game tick and the current frame, causing the text to flicker between run
energy and our replacement. This just sets the text before each frame.
  • Loading branch information
Adam- committed Jan 7, 2022
1 parent ab082fc commit b593a51
Showing 1 changed file with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@
import net.runelite.api.Skill;
import net.runelite.api.Varbits;
import net.runelite.api.coords.WorldPoint;
import net.runelite.client.events.ConfigChanged;
import net.runelite.api.events.BeforeRender;
import net.runelite.api.events.GameTick;
import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetInfo;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.events.ConfigChanged;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.ui.overlay.OverlayManager;
Expand Down Expand Up @@ -138,6 +139,7 @@ private enum GracefulEquipmentSlot

private boolean localPlayerRunningToDestination;
private WorldPoint prevLocalPlayerLocation;
private String runTimeRemaining;

@Provides
RunEnergyConfig getConfig(ConfigManager configManager)
Expand Down Expand Up @@ -170,9 +172,15 @@ public void onGameTick(GameTick event)

prevLocalPlayerLocation = client.getLocalPlayer().getWorldLocation();

if (energyConfig.replaceOrbText())
runTimeRemaining = energyConfig.replaceOrbText() ? getEstimatedRunTimeRemaining(true) : null;
}

@Subscribe
public void onBeforeRender(BeforeRender beforeRender)
{
if (runTimeRemaining != null)
{
setRunOrbText(getEstimatedRunTimeRemaining(true));
setRunOrbText(runTimeRemaining);
}
}

Expand Down Expand Up @@ -218,14 +226,13 @@ String getEstimatedRunTimeRemaining(boolean inSeconds)
// Return the text
if (inSeconds)
{
return Integer.toString((int) Math.floor(secondsLeft)) + "s";
return (int) Math.floor(secondsLeft) + "s";
}
else
{
final int minutes = (int) Math.floor(secondsLeft / 60.0);
final int seconds = (int) Math.floor(secondsLeft - (minutes * 60.0));

return Integer.toString(minutes) + ":" + StringUtils.leftPad(Integer.toString(seconds), 2, "0");
return minutes + ":" + StringUtils.leftPad(Integer.toString(seconds), 2, "0");
}
}

Expand Down

0 comments on commit b593a51

Please sign in to comment.