Only update ping on UI update
This commit is contained in:
@@ -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) <stonewall@thots.cc.usa>, 2019
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
package net.runelite.client.plugins.freezetimers;
|
package net.runelite.client.plugins.freezetimers;
|
||||||
|
|
||||||
import java.awt.BasicStroke;
|
import java.awt.BasicStroke;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Font;
|
|
||||||
import java.awt.FontMetrics;
|
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Stroke;
|
import java.awt.font.TextLayout;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.*;
|
||||||
import java.util.function.BiConsumer;
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import net.runelite.api.Client;
|
|
||||||
import net.runelite.api.HeadIcon;
|
import net.runelite.api.*;
|
||||||
import net.runelite.api.Player;
|
|
||||||
import net.runelite.api.Point;
|
|
||||||
import net.runelite.client.game.SpriteManager;
|
import net.runelite.client.game.SpriteManager;
|
||||||
import net.runelite.client.ui.FontManager;
|
import net.runelite.client.ui.FontManager;
|
||||||
import net.runelite.client.ui.overlay.Overlay;
|
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;
|
import net.runelite.client.ui.overlay.OverlayUtil;
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
public class FreezeTimersOverlay
|
public class FreezeTimersOverlay extends Overlay
|
||||||
extends Overlay {
|
{
|
||||||
private final FreezeTimersService FreezeTimersService;
|
private final FreezeTimersService FreezeTimersService;
|
||||||
private final FreezeTimersConfig config;
|
private final FreezeTimersConfig config;
|
||||||
private final FreezeTimersPlugin plugin;
|
private final FreezeTimersPlugin plugin;
|
||||||
@@ -32,123 +36,166 @@ public class FreezeTimersOverlay
|
|||||||
private final Client client;
|
private final Client client;
|
||||||
|
|
||||||
@Inject
|
@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.config = config;
|
||||||
this.FreezeTimersService = FreezeTimersService2;
|
this.FreezeTimersService = FreezeTimersService;
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.spriteManager = spriteManager;
|
this.spriteManager = spriteManager;
|
||||||
this.setPosition(OverlayPosition.DYNAMIC);
|
setPosition(OverlayPosition.DYNAMIC);
|
||||||
this.setPriority(OverlayPriority.MED);
|
setPriority(OverlayPriority.MED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dimension render(Graphics2D graphics) {
|
public Dimension render(Graphics2D graphics)
|
||||||
if (!this.config.EnableFreezeTimers()) {
|
{
|
||||||
|
if (!config.EnableFreezeTimers())
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
this.FreezeTimersService.forEachPlayer((player, color) -> this.renderPlayerOverlay(graphics, (Player)player, (Color)color));
|
FreezeTimersService.forEachPlayer((player, color) -> renderPlayerOverlay(graphics, player, color));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renderPlayerOverlay(Graphics2D graphics, Player actor, Color color) {
|
private void renderPlayerOverlay(Graphics2D graphics, Player actor, Color color)
|
||||||
BufferedImage clanchatImage;
|
{
|
||||||
int timer = 0;
|
int timer = 0;
|
||||||
String name = actor.getName();
|
String name = actor.getName();
|
||||||
int freezetype = this.plugin.freezetype(name);
|
int freezetype = plugin.freezetype(name);
|
||||||
boolean frozenoverlay = false;
|
boolean frozenoverlay = false;
|
||||||
int offset = 5;
|
int offset = 5;
|
||||||
long dtime = this.plugin.opponentfreezetime(name);
|
long dtime = plugin.opponentfreezetime(name);
|
||||||
long tbed = plugin.istbed(name);
|
long tbed = plugin.istbed(name);
|
||||||
Point textLocation = null;
|
Point textLocation = null;
|
||||||
HeadIcon headIcon = actor.getOverheadIcon();
|
HeadIcon headIcon = actor.getOverheadIcon();
|
||||||
int freezetime = 0;
|
int freezetime = 0;
|
||||||
if (freezetype == 1 || freezetype == 4) {
|
if (freezetype == 1 || freezetype == 4)
|
||||||
|
{
|
||||||
freezetime = 5000;
|
freezetime = 5000;
|
||||||
} else if (freezetype == 2 || freezetype == 5) {
|
}
|
||||||
|
else if (freezetype == 2 || freezetype == 5)
|
||||||
|
{
|
||||||
freezetime = 10000;
|
freezetime = 10000;
|
||||||
} else if (freezetype == 3 || freezetype == 6) {
|
}
|
||||||
|
else if (freezetype == 3 || freezetype == 6)
|
||||||
|
{
|
||||||
freezetime = 15000;
|
freezetime = 15000;
|
||||||
} else if (freezetype == 7) {
|
}
|
||||||
|
else if (freezetype == 7)
|
||||||
|
{
|
||||||
freezetime = 20000;
|
freezetime = 20000;
|
||||||
} else if (freezetype == 8) {
|
}
|
||||||
|
else if (freezetype == 8)
|
||||||
|
{
|
||||||
freezetime = 2500;
|
freezetime = 2500;
|
||||||
} else if (freezetype == 9) {
|
}
|
||||||
|
else if (freezetype == 9)
|
||||||
|
{
|
||||||
freezetime = 5000;
|
freezetime = 5000;
|
||||||
} else if (freezetype == 10) {
|
}
|
||||||
|
else if (freezetype == 10)
|
||||||
|
{
|
||||||
freezetime = 7500;
|
freezetime = 7500;
|
||||||
}
|
}
|
||||||
|
|
||||||
long currenttime = System.currentTimeMillis();
|
long currenttime = System.currentTimeMillis();
|
||||||
long timediff = currenttime - dtime;
|
long timediff = currenttime - dtime;
|
||||||
timer = (freezetime - (int)timediff) / 1000;
|
timer = (freezetime - (int) timediff) / 1000;
|
||||||
if (timediff < (long)freezetime) {
|
|
||||||
textLocation = actor.getCanvasTextLocation(graphics, String.valueOf(timer), actor.getLogicalHeight() + config.FreezeTimerPos());
|
if (timediff < freezetime)
|
||||||
textLocation = new Point(textLocation.getX(), textLocation.getY() - config.FreezeTimerPos());
|
{
|
||||||
} else if (timediff < (long)(freezetime + 3000)) {
|
// if the freezetimer is still active. . .
|
||||||
timer = Math.abs(timer);
|
textLocation = actor.getCanvasTextLocation(graphics, String.valueOf((timer)), offset);
|
||||||
++timer;
|
textLocation = new Point(textLocation.getX() + 10, textLocation.getY() + 5);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
if (textLocation != null && (clanchatImage = this.plugin.GetFreezeIcon(freezetype - 1)) != null) {
|
else
|
||||||
int width = clanchatImage.getWidth();
|
{
|
||||||
int textHeight = graphics.getFontMetrics().getHeight() - graphics.getFontMetrics().getMaxDescent();
|
if (timediff < freezetime + 3000)
|
||||||
Point imageLocation = new Point(textLocation.getX(), textLocation.getY() - (config.FreezeTimerPos() / 2));
|
{
|
||||||
graphics.setFont(FontManager.getRunescapeFont());
|
timer = Math.abs(timer);
|
||||||
graphics.setStroke(new BasicStroke(3.0f));
|
timer += 1;
|
||||||
if (this.config.spellIcon()) {
|
if (config.refreezeTimer())
|
||||||
frozenoverlay = true;
|
{
|
||||||
graphics.drawOval(imageLocation.getX(), imageLocation.getY(), clanchatImage.getWidth(), clanchatImage.getHeight());
|
textLocation = actor.getCanvasTextLocation(graphics, String.valueOf((timer)), offset);
|
||||||
OverlayUtil.renderImageLocation(graphics, imageLocation, clanchatImage);
|
textLocation = new Point(textLocation.getX() + 10, textLocation.getY() + 5);
|
||||||
OverlayUtil.renderTextLocation(graphics, textLocation, String.valueOf(timer), color);
|
graphics.setFont(FontManager.getRunescapeBoldFont());
|
||||||
} else {
|
if (headIcon != null)
|
||||||
graphics.setColor(Color.cyan);
|
{
|
||||||
graphics.drawOval(textLocation.getX() - 3, textLocation.getY() - 15, clanchatImage.getWidth(), graphics.getFontMetrics().getHeight());
|
textLocation = new Point(textLocation.getX() + 10, textLocation.getY() + 5);
|
||||||
graphics.setColor(Color.blue);
|
}
|
||||||
graphics.fillOval(textLocation.getX() - 3, textLocation.getY() - 15, clanchatImage.getWidth(), graphics.getFontMetrics().getHeight());
|
frozenoverlay = true;
|
||||||
OverlayUtil.renderTextLocation(graphics, textLocation, String.valueOf(timer), Color.WHITE);
|
OverlayUtil.renderTextLocation(graphics, textLocation, String.valueOf((timer)), config.RefreezeTimerColor());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
plugin.deleteopponent(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.TBTimer()) {
|
if (textLocation != null)
|
||||||
if (tbed > 0) {
|
{
|
||||||
int type = plugin.tbtype(name);
|
BufferedImage clanchatImage = plugin.GetFreezeIcon(freezetype - 1);
|
||||||
int tbexpiry;
|
|
||||||
if (type > 0) {
|
if (clanchatImage != null)
|
||||||
if (type == 1) {
|
{
|
||||||
tbexpiry = 300000;
|
int width = clanchatImage.getWidth();
|
||||||
} else if (type == 2) {
|
int textHeight = graphics.getFontMetrics().getHeight() - graphics.getFontMetrics().getMaxDescent();
|
||||||
tbexpiry = 150000;
|
Point imageLocation = new Point(textLocation.getX() - width, ((textLocation.getY() -
|
||||||
} else {
|
graphics.getFontMetrics().getHeight()) + 10));
|
||||||
return;
|
graphics.setFont(FontManager.getRunescapeFont());
|
||||||
}
|
graphics.setStroke(new BasicStroke(3));
|
||||||
long tbtime = currenttime - tbed;
|
|
||||||
int tbtimer = (tbexpiry - (int) tbtime) / 1000;
|
if (config.spellIcon())
|
||||||
if (tbtime < tbexpiry) {
|
{
|
||||||
textLocation = actor.getCanvasTextLocation(graphics, Integer.toString(tbtimer), actor.getLogicalHeight() + config.FreezeTimerPos());
|
frozenoverlay = true;
|
||||||
if (frozenoverlay) {
|
graphics.drawOval(imageLocation.getX(), imageLocation.getY(), clanchatImage.getWidth(),
|
||||||
textLocation = new Point(textLocation.getX() + 40, textLocation.getY() - config.FreezeTimerPos());
|
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 {
|
} 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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -428,6 +428,13 @@ class WorldSwitcherPanel extends PluginPanel
|
|||||||
|
|
||||||
void populate(List<World> worlds)
|
void populate(List<World> worlds)
|
||||||
{
|
{
|
||||||
|
Map<Integer, Integer> pingHistory = new HashMap<>();
|
||||||
|
|
||||||
|
for (WorldTableRow row : rows)
|
||||||
|
{
|
||||||
|
pingHistory.put(row.getWorld().getId(), row.getPing());
|
||||||
|
}
|
||||||
|
|
||||||
rows.clear();
|
rows.clear();
|
||||||
|
|
||||||
for (int i = 0; i < worlds.size(); i++)
|
for (int i = 0; i < worlds.size(); i++)
|
||||||
@@ -450,7 +457,8 @@ class WorldSwitcherPanel extends PluginPanel
|
|||||||
break;
|
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();
|
updateList();
|
||||||
@@ -599,7 +607,7 @@ class WorldSwitcherPanel extends PluginPanel
|
|||||||
/**
|
/**
|
||||||
* Builds a table row, that displays the world's information.
|
* 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,
|
WorldTableRow row = new WorldTableRow(world, current, favorite,
|
||||||
world1 ->
|
world1 ->
|
||||||
|
|||||||
Reference in New Issue
Block a user