From 12e1de31d6d08c7038db29adb0a9219d6005213d Mon Sep 17 00:00:00 2001 From: James Munson Date: Sat, 20 Apr 2019 13:49:23 -0700 Subject: [PATCH] Only update ping on UI update --- .../freezetimers/FreezeTimersOverlay.java | 227 +++++++++++------- .../worldhopper/WorldSwitcherPanel.java | 12 +- 2 files changed, 147 insertions(+), 92 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/freezetimers/FreezeTimersOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/freezetimers/FreezeTimersOverlay.java index 7f0a5aae81..d0211a5ca1 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/freezetimers/FreezeTimersOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/freezetimers/FreezeTimersOverlay.java @@ -1,20 +1,24 @@ +/* + * Copyright (c) 2019. PKLite - All Rights Reserved + * Unauthorized modification, distribution, or possession of this source file, via any medium is strictly prohibited. + * Proprietary and confidential. Refer to PKLite License file for more information on + * full terms of this copyright and to determine what constitutes authorized use. + * Written by PKLite(ST0NEWALL, others) , 2019 + * + */ + package net.runelite.client.plugins.freezetimers; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Dimension; -import java.awt.Font; -import java.awt.FontMetrics; import java.awt.Graphics2D; -import java.awt.Stroke; -import java.awt.image.BufferedImage; -import java.util.function.BiConsumer; +import java.awt.font.TextLayout; +import java.awt.image.*; import javax.inject.Inject; import javax.inject.Singleton; -import net.runelite.api.Client; -import net.runelite.api.HeadIcon; -import net.runelite.api.Player; -import net.runelite.api.Point; + +import net.runelite.api.*; import net.runelite.client.game.SpriteManager; import net.runelite.client.ui.FontManager; import net.runelite.client.ui.overlay.Overlay; @@ -23,8 +27,8 @@ import net.runelite.client.ui.overlay.OverlayPriority; import net.runelite.client.ui.overlay.OverlayUtil; @Singleton -public class FreezeTimersOverlay - extends Overlay { +public class FreezeTimersOverlay extends Overlay +{ private final FreezeTimersService FreezeTimersService; private final FreezeTimersConfig config; private final FreezeTimersPlugin plugin; @@ -32,123 +36,166 @@ public class FreezeTimersOverlay private final Client client; @Inject - private FreezeTimersOverlay(FreezeTimersConfig config, FreezeTimersService FreezeTimersService2, FreezeTimersPlugin plugin, Client client, SpriteManager spriteManager) { + private FreezeTimersOverlay(FreezeTimersConfig config, FreezeTimersService FreezeTimersService, FreezeTimersPlugin plugin, Client client, SpriteManager spriteManager) + { this.config = config; - this.FreezeTimersService = FreezeTimersService2; + this.FreezeTimersService = FreezeTimersService; this.plugin = plugin; this.client = client; this.spriteManager = spriteManager; - this.setPosition(OverlayPosition.DYNAMIC); - this.setPriority(OverlayPriority.MED); + setPosition(OverlayPosition.DYNAMIC); + setPriority(OverlayPriority.MED); } @Override - public Dimension render(Graphics2D graphics) { - if (!this.config.EnableFreezeTimers()) { + public Dimension render(Graphics2D graphics) + { + if (!config.EnableFreezeTimers()) + { return null; } - this.FreezeTimersService.forEachPlayer((player, color) -> this.renderPlayerOverlay(graphics, (Player)player, (Color)color)); + FreezeTimersService.forEachPlayer((player, color) -> renderPlayerOverlay(graphics, player, color)); return null; } - private void renderPlayerOverlay(Graphics2D graphics, Player actor, Color color) { - BufferedImage clanchatImage; + private void renderPlayerOverlay(Graphics2D graphics, Player actor, Color color) + { int timer = 0; String name = actor.getName(); - int freezetype = this.plugin.freezetype(name); + int freezetype = plugin.freezetype(name); boolean frozenoverlay = false; int offset = 5; - long dtime = this.plugin.opponentfreezetime(name); + long dtime = plugin.opponentfreezetime(name); long tbed = plugin.istbed(name); Point textLocation = null; HeadIcon headIcon = actor.getOverheadIcon(); int freezetime = 0; - if (freezetype == 1 || freezetype == 4) { + if (freezetype == 1 || freezetype == 4) + { freezetime = 5000; - } else if (freezetype == 2 || freezetype == 5) { + } + else if (freezetype == 2 || freezetype == 5) + { freezetime = 10000; - } else if (freezetype == 3 || freezetype == 6) { + } + else if (freezetype == 3 || freezetype == 6) + { freezetime = 15000; - } else if (freezetype == 7) { + } + else if (freezetype == 7) + { freezetime = 20000; - } else if (freezetype == 8) { + } + else if (freezetype == 8) + { freezetime = 2500; - } else if (freezetype == 9) { + } + else if (freezetype == 9) + { freezetime = 5000; - } else if (freezetype == 10) { + } + else if (freezetype == 10) + { freezetime = 7500; } + long currenttime = System.currentTimeMillis(); long timediff = currenttime - dtime; - timer = (freezetime - (int)timediff) / 1000; - if (timediff < (long)freezetime) { - textLocation = actor.getCanvasTextLocation(graphics, String.valueOf(timer), actor.getLogicalHeight() + config.FreezeTimerPos()); - textLocation = new Point(textLocation.getX(), textLocation.getY() - config.FreezeTimerPos()); - } else if (timediff < (long)(freezetime + 3000)) { - timer = Math.abs(timer); - ++timer; - if (this.config.refreezeTimer()) { - textLocation = actor.getCanvasTextLocation(graphics, String.valueOf(timer), actor.getLogicalHeight() + config.FreezeTimerPos()); - textLocation = new Point(textLocation.getX(), textLocation.getY() - config.FreezeTimerPos()); - graphics.setFont(FontManager.getRunescapeBoldFont()); - if (headIcon != null) { - textLocation = new Point(textLocation.getX(), textLocation.getY() - config.FreezeTimerPos()); - } - frozenoverlay = true; - OverlayUtil.renderTextLocation(graphics, textLocation, String.valueOf(timer), this.config.RefreezeTimerColor()); - return; - } - } else { - this.plugin.deleteopponent(name); + timer = (freezetime - (int) timediff) / 1000; + + if (timediff < freezetime) + { + // if the freezetimer is still active. . . + textLocation = actor.getCanvasTextLocation(graphics, String.valueOf((timer)), offset); + textLocation = new Point(textLocation.getX() + 10, textLocation.getY() + 5); } - if (textLocation != null && (clanchatImage = this.plugin.GetFreezeIcon(freezetype - 1)) != null) { - int width = clanchatImage.getWidth(); - int textHeight = graphics.getFontMetrics().getHeight() - graphics.getFontMetrics().getMaxDescent(); - Point imageLocation = new Point(textLocation.getX(), textLocation.getY() - (config.FreezeTimerPos() / 2)); - graphics.setFont(FontManager.getRunescapeFont()); - graphics.setStroke(new BasicStroke(3.0f)); - if (this.config.spellIcon()) { - frozenoverlay = true; - graphics.drawOval(imageLocation.getX(), imageLocation.getY(), clanchatImage.getWidth(), clanchatImage.getHeight()); - OverlayUtil.renderImageLocation(graphics, imageLocation, clanchatImage); - OverlayUtil.renderTextLocation(graphics, textLocation, String.valueOf(timer), color); - } else { - graphics.setColor(Color.cyan); - graphics.drawOval(textLocation.getX() - 3, textLocation.getY() - 15, clanchatImage.getWidth(), graphics.getFontMetrics().getHeight()); - graphics.setColor(Color.blue); - graphics.fillOval(textLocation.getX() - 3, textLocation.getY() - 15, clanchatImage.getWidth(), graphics.getFontMetrics().getHeight()); - OverlayUtil.renderTextLocation(graphics, textLocation, String.valueOf(timer), Color.WHITE); + else + { + if (timediff < freezetime + 3000) + { + timer = Math.abs(timer); + timer += 1; + if (config.refreezeTimer()) + { + textLocation = actor.getCanvasTextLocation(graphics, String.valueOf((timer)), offset); + textLocation = new Point(textLocation.getX() + 10, textLocation.getY() + 5); + graphics.setFont(FontManager.getRunescapeBoldFont()); + if (headIcon != null) + { + textLocation = new Point(textLocation.getX() + 10, textLocation.getY() + 5); + } + frozenoverlay = true; + OverlayUtil.renderTextLocation(graphics, textLocation, String.valueOf((timer)), config.RefreezeTimerColor()); + return; + } + } + else + { + plugin.deleteopponent(name); } } - if (config.TBTimer()) { - if (tbed > 0) { - int type = plugin.tbtype(name); - int tbexpiry; - if (type > 0) { - if (type == 1) { - tbexpiry = 300000; - } else if (type == 2) { - tbexpiry = 150000; - } else { - return; - } - long tbtime = currenttime - tbed; - int tbtimer = (tbexpiry - (int) tbtime) / 1000; - if (tbtime < tbexpiry) { - textLocation = actor.getCanvasTextLocation(graphics, Integer.toString(tbtimer), actor.getLogicalHeight() + config.FreezeTimerPos()); - if (frozenoverlay) { - textLocation = new Point(textLocation.getX() + 40, textLocation.getY() - config.FreezeTimerPos()); + if (textLocation != null) + { + BufferedImage clanchatImage = plugin.GetFreezeIcon(freezetype - 1); + + if (clanchatImage != null) + { + int width = clanchatImage.getWidth(); + int textHeight = graphics.getFontMetrics().getHeight() - graphics.getFontMetrics().getMaxDescent(); + Point imageLocation = new Point(textLocation.getX() - width, ((textLocation.getY() - + graphics.getFontMetrics().getHeight()) + 10)); + graphics.setFont(FontManager.getRunescapeFont()); + graphics.setStroke(new BasicStroke(3)); + + if (config.spellIcon()) + { + frozenoverlay = true; + graphics.drawOval(imageLocation.getX(), imageLocation.getY(), clanchatImage.getWidth(), + clanchatImage.getHeight()); + OverlayUtil.renderImageLocation(graphics, imageLocation, clanchatImage); + OverlayUtil.renderTextLocation(graphics, textLocation, String.valueOf(timer), color); + + } + else + { + graphics.setColor(Color.cyan); + graphics.drawOval(textLocation.getX() - 3, textLocation.getY() - 15, clanchatImage.getWidth(), + graphics.getFontMetrics().getHeight()); + graphics.setColor(Color.blue); + graphics.fillOval(textLocation.getX() - 3, textLocation.getY() - 15, clanchatImage.getWidth(), + graphics.getFontMetrics().getHeight()); + + OverlayUtil.renderTextLocation(graphics, textLocation, String.valueOf(timer), Color.WHITE); + } + } + if (config.TBTimer()) { + if (tbed > 0) { + int type = plugin.tbtype(name); + int tbexpiry; + if (type > 0) { + if (type == 1) { + tbexpiry = 300000; + } else if (type == 2) { + tbexpiry = 150000; } else { - textLocation = new Point(textLocation.getX(), textLocation.getY() - config.FreezeTimerPos()); + return; + } + long tbtime = currenttime - tbed; + int tbtimer = (tbexpiry - (int) tbtime) / 1000; + if (tbtime < tbexpiry) { + textLocation = actor.getCanvasTextLocation(graphics, Integer.toString(tbtimer), actor.getLogicalHeight() + config.FreezeTimerPos()); + if (frozenoverlay) { + textLocation = new Point(textLocation.getX() + 40, textLocation.getY() - config.FreezeTimerPos()); + } else { + textLocation = new Point(textLocation.getX(), textLocation.getY() - config.FreezeTimerPos()); + } + } else { + plugin.deletetb(name); } - } else { - plugin.deletetb(name); } } - } } } -} - +} \ No newline at end of file diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/worldhopper/WorldSwitcherPanel.java b/runelite-client/src/main/java/net/runelite/client/plugins/worldhopper/WorldSwitcherPanel.java index fbe8ecdbaa..28f299ed0e 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/worldhopper/WorldSwitcherPanel.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/worldhopper/WorldSwitcherPanel.java @@ -428,6 +428,13 @@ class WorldSwitcherPanel extends PluginPanel void populate(List worlds) { + Map pingHistory = new HashMap<>(); + + for (WorldTableRow row : rows) + { + pingHistory.put(row.getWorld().getId(), row.getPing()); + } + rows.clear(); for (int i = 0; i < worlds.size(); i++) @@ -450,7 +457,8 @@ class WorldSwitcherPanel extends PluginPanel break; } - rows.add(buildRow(world, i % 2 == 0, world.getId() == plugin.getCurrentWorld() && plugin.getLastWorld() != 0, plugin.isFavorite(world))); + Integer ping = pingHistory.getOrDefault(world.getId(), 0); + rows.add(buildRow(world, i % 2 == 0, world.getId() == plugin.getCurrentWorld() && plugin.getLastWorld() != 0, plugin.isFavorite(world), ping)); } updateList(); @@ -599,7 +607,7 @@ class WorldSwitcherPanel extends PluginPanel /** * Builds a table row, that displays the world's information. */ - private WorldTableRow buildRow(World world, boolean stripe, boolean current, boolean favorite) + private WorldTableRow buildRow(World world, boolean stripe, boolean current, boolean favorite, Integer ping) { WorldTableRow row = new WorldTableRow(world, current, favorite, world1 ->