Remove config calls from fps overlay (#708)
This commit is contained in:
@@ -45,6 +45,7 @@ public class FpsDrawListener implements Runnable
|
||||
private static final int SAMPLE_SIZE = 4;
|
||||
|
||||
private final FpsConfig config;
|
||||
private final FpsPlugin plugin;
|
||||
|
||||
private long targetDelay = 0;
|
||||
|
||||
@@ -58,9 +59,10 @@ public class FpsDrawListener implements Runnable
|
||||
private long sleepDelay = 0;
|
||||
|
||||
@Inject
|
||||
private FpsDrawListener(FpsConfig config)
|
||||
private FpsDrawListener(FpsConfig config, FpsPlugin plugin)
|
||||
{
|
||||
this.config = config;
|
||||
this.plugin = plugin;
|
||||
reloadConfig();
|
||||
}
|
||||
|
||||
@@ -83,8 +85,8 @@ public class FpsDrawListener implements Runnable
|
||||
|
||||
private boolean isEnforced()
|
||||
{
|
||||
return FpsLimitMode.ALWAYS == config.limitMode()
|
||||
|| (FpsLimitMode.UNFOCUSED == config.limitMode() && !isFocused);
|
||||
return FpsLimitMode.ALWAYS == plugin.getLimitMode()
|
||||
|| (FpsLimitMode.UNFOCUSED == plugin.getLimitMode() && !isFocused);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -50,7 +50,6 @@ import net.runelite.client.ui.overlay.OverlayUtil;
|
||||
public class FpsOverlay extends Overlay
|
||||
{
|
||||
// Local dependencies
|
||||
private final FpsConfig config;
|
||||
private final Client client;
|
||||
private final FpsPlugin plugin;
|
||||
|
||||
@@ -58,9 +57,8 @@ public class FpsOverlay extends Overlay
|
||||
private boolean isFocused = true;
|
||||
|
||||
@Inject
|
||||
private FpsOverlay(FpsPlugin plugin, FpsConfig config, Client client)
|
||||
private FpsOverlay(FpsPlugin plugin, Client client)
|
||||
{
|
||||
this.config = config;
|
||||
this.client = client;
|
||||
this.plugin = plugin;
|
||||
setLayer(OverlayLayer.ABOVE_WIDGETS);
|
||||
@@ -75,8 +73,8 @@ public class FpsOverlay extends Overlay
|
||||
|
||||
private boolean isEnforced()
|
||||
{
|
||||
return FpsLimitMode.ALWAYS == config.limitMode()
|
||||
|| (FpsLimitMode.UNFOCUSED == config.limitMode() && !isFocused);
|
||||
return FpsLimitMode.ALWAYS == plugin.getLimitMode()
|
||||
|| (FpsLimitMode.UNFOCUSED == plugin.getLimitMode() && !isFocused);
|
||||
}
|
||||
|
||||
private Color getFpsValueColor()
|
||||
@@ -110,7 +108,7 @@ public class FpsOverlay extends Overlay
|
||||
@Override
|
||||
public Dimension render(Graphics2D graphics)
|
||||
{
|
||||
if (!config.drawFps() && !config.drawPing())
|
||||
if (!plugin.isDrawFps() && !plugin.isDrawPing())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@@ -121,7 +119,7 @@ public class FpsOverlay extends Overlay
|
||||
|
||||
int baseYOffset = (fontMetrics.getAscent() - fontMetrics.getDescent()) + 1;
|
||||
|
||||
if (config.drawFps())
|
||||
if (plugin.isDrawFps())
|
||||
{
|
||||
final String fpsText = String.format("%d FPS", client.getFPS());
|
||||
final int textWidth = fontMetrics.stringWidth(fpsText);
|
||||
@@ -132,7 +130,7 @@ public class FpsOverlay extends Overlay
|
||||
baseYOffset += 11;
|
||||
}
|
||||
|
||||
if (config.drawPing())
|
||||
if (plugin.isDrawPing())
|
||||
{
|
||||
final String pingText = String.format("%dms", plugin.getPing());
|
||||
final int textWidth = fontMetrics.stringWidth(pingText);
|
||||
|
||||
@@ -29,6 +29,7 @@ import com.google.inject.Provides;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.GameState;
|
||||
@@ -90,6 +91,15 @@ public class FpsPlugin extends Plugin
|
||||
|
||||
private final ScheduledExecutorService pingExecutorService = new ExecutorServiceExceptionLogger(Executors.newSingleThreadScheduledExecutor());
|
||||
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
private FpsLimitMode limitMode;
|
||||
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
private boolean drawFps;
|
||||
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
private boolean drawPing;
|
||||
|
||||
@Provides
|
||||
FpsConfig provideConfig(ConfigManager configManager)
|
||||
{
|
||||
@@ -102,6 +112,10 @@ public class FpsPlugin extends Plugin
|
||||
if (event.getGroup().equals(CONFIG_GROUP_KEY))
|
||||
{
|
||||
drawListener.reloadConfig();
|
||||
|
||||
limitMode = fpsConfig.limitMode();
|
||||
drawFps = fpsConfig.drawFps();
|
||||
drawPing = fpsConfig.drawPing();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,6 +129,9 @@ public class FpsPlugin extends Plugin
|
||||
@Override
|
||||
protected void startUp() throws Exception
|
||||
{
|
||||
limitMode = fpsConfig.limitMode();
|
||||
drawFps = fpsConfig.drawFps();
|
||||
drawPing = fpsConfig.drawPing();
|
||||
overlayManager.add(overlay);
|
||||
drawManager.registerEveryFrameListener(drawListener);
|
||||
drawListener.reloadConfig();
|
||||
@@ -131,7 +148,7 @@ public class FpsPlugin extends Plugin
|
||||
|
||||
private void getPingToCurrentWorld()
|
||||
{
|
||||
if (client.getGameState().equals(GameState.LOGGED_IN) && fpsConfig.drawPing())
|
||||
if (client.getGameState().equals(GameState.LOGGED_IN) && drawPing)
|
||||
{
|
||||
ping = Ping.ping(String.format("oldschool%d.runescape.com", client.getWorld() - 300));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user