info boxes: associate plugins to infoboxes
associate plugins to infoboxes and allow the infobox manager to sort boxes by plugin descriptor name to stop all infoboxes mixing together
This commit is contained in:
@@ -29,6 +29,7 @@ import java.awt.image.BufferedImage;
|
||||
import lombok.Getter;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.Skill;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
import net.runelite.client.ui.overlay.infobox.InfoBox;
|
||||
|
||||
public class BoostIndicator extends InfoBox
|
||||
@@ -39,9 +40,9 @@ public class BoostIndicator extends InfoBox
|
||||
@Getter
|
||||
private final Skill skill;
|
||||
|
||||
public BoostIndicator(Skill skill, BufferedImage image, Client client, BoostsConfig config)
|
||||
public BoostIndicator(Skill skill, BufferedImage image, Plugin plugin, Client client, BoostsConfig config)
|
||||
{
|
||||
super(image);
|
||||
super(image, plugin);
|
||||
this.config = config;
|
||||
this.client = client;
|
||||
this.skill = skill;
|
||||
|
||||
@@ -96,7 +96,7 @@ class BoostsOverlay extends Overlay
|
||||
{
|
||||
if (indicator == null)
|
||||
{
|
||||
indicator = new BoostIndicator(skill, iconManager.getSkillImage(skill), client, config);
|
||||
indicator = new BoostIndicator(skill, iconManager.getSkillImage(skill), plugin, client, config);
|
||||
indicators[skill.ordinal()] = indicator;
|
||||
}
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ public class BossTimersPlugin extends Plugin
|
||||
|
||||
log.debug("Creating spawn timer for {} ({} seconds)", actor.getName(), boss.getSpawnTime());
|
||||
|
||||
RespawnTimer timer = new RespawnTimer(boss, itemManager.getImage(boss.getItemSpriteId()));
|
||||
RespawnTimer timer = new RespawnTimer(boss, itemManager.getImage(boss.getItemSpriteId()), this);
|
||||
timer.setTooltip(boss.getName());
|
||||
infoBoxManager.addInfoBox(timer);
|
||||
}
|
||||
|
||||
@@ -26,15 +26,16 @@ package net.runelite.client.plugins.bosstimer;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
import net.runelite.client.ui.overlay.infobox.Timer;
|
||||
|
||||
class RespawnTimer extends Timer
|
||||
{
|
||||
private final Boss boss;
|
||||
|
||||
public RespawnTimer(Boss boss, BufferedImage bossImage)
|
||||
public RespawnTimer(Boss boss, BufferedImage bossImage, Plugin plugin)
|
||||
{
|
||||
super(boss.getSpawnTime().toMillis(), ChronoUnit.MILLIS, bossImage);
|
||||
super(boss.getSpawnTime().toMillis(), ChronoUnit.MILLIS, bossImage, plugin);
|
||||
this.boss = boss;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ public class CannonCounter extends Counter
|
||||
|
||||
public CannonCounter(BufferedImage img, CannonPlugin plugin)
|
||||
{
|
||||
super(img, String.valueOf(plugin.getCballsLeft()));
|
||||
super(img, plugin, String.valueOf(plugin.getCballsLeft()));
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ public class KingdomCounter extends Counter
|
||||
|
||||
public KingdomCounter(BufferedImage image, KingdomPlugin plugin)
|
||||
{
|
||||
super(image, String.valueOf(plugin.getFavor()));
|
||||
super(image, plugin, String.valueOf(plugin.getFavor()));
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ import java.awt.Color;
|
||||
import java.awt.image.BufferedImage;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
import net.runelite.client.ui.overlay.infobox.Counter;
|
||||
|
||||
public class AbsorptionCounter extends Counter
|
||||
@@ -46,9 +47,9 @@ public class AbsorptionCounter extends Counter
|
||||
@Setter
|
||||
private Color belowThresholdColor = Color.RED;
|
||||
|
||||
public AbsorptionCounter(BufferedImage image, int absorption, int threshold)
|
||||
public AbsorptionCounter(BufferedImage image, Plugin plugin, int absorption, int threshold)
|
||||
{
|
||||
super(image, "");
|
||||
super(image, plugin, "");
|
||||
this.threshold = threshold;
|
||||
setAbsorption(absorption);
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ class NightmareZoneOverlay extends Overlay
|
||||
|
||||
private void addAbsorptionCounter(int startValue)
|
||||
{
|
||||
absorptionCounter = new AbsorptionCounter(itemManager.getImage(ItemID.ABSORPTION_4), startValue, config.absorptionThreshold());
|
||||
absorptionCounter = new AbsorptionCounter(itemManager.getImage(ItemID.ABSORPTION_4), plugin, startValue, config.absorptionThreshold());
|
||||
absorptionCounter.setAboveThresholdColor(config.absorptionColorAboveThreshold());
|
||||
absorptionCounter.setBelowThresholdColor(config.absorptionColorBelowThreshold());
|
||||
infoBoxManager.addInfoBox(absorptionCounter);
|
||||
|
||||
@@ -257,7 +257,7 @@ public class RaidsPlugin extends Plugin
|
||||
|
||||
if (config.raidsTimer() && message.startsWith(RAID_START_MESSAGE))
|
||||
{
|
||||
timer = new RaidsTimer(getRaidsIcon(), Instant.now());
|
||||
timer = new RaidsTimer(getRaidsIcon(), this, Instant.now());
|
||||
infoBoxManager.addInfoBox(timer);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ import java.time.Instant;
|
||||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import lombok.Setter;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
import net.runelite.client.ui.overlay.infobox.InfoBox;
|
||||
|
||||
public class RaidsTimer extends InfoBox
|
||||
@@ -45,9 +46,9 @@ public class RaidsTimer extends InfoBox
|
||||
@Setter
|
||||
private boolean stopped;
|
||||
|
||||
public RaidsTimer(BufferedImage image, Instant startTime)
|
||||
public RaidsTimer(BufferedImage image, Plugin plugin, Instant startTime)
|
||||
{
|
||||
super(image);
|
||||
super(image, plugin);
|
||||
this.startTime = startTime;
|
||||
floorTime = startTime;
|
||||
stopped = false;
|
||||
|
||||
@@ -361,7 +361,7 @@ public class SlayerPlugin extends Plugin
|
||||
}
|
||||
|
||||
BufferedImage taskImg = itemManager.getImage(itemSpriteId);
|
||||
counter = new TaskCounter(taskImg, amount);
|
||||
counter = new TaskCounter(taskImg, this, amount);
|
||||
counter.setTooltip(String.format("<col=ff7700>%s</br><col=ffff00>Pts:</col> %s</br><col=ffff00>Streak:</col> %s",
|
||||
capsString(taskName), points, streak));
|
||||
|
||||
|
||||
@@ -24,14 +24,15 @@
|
||||
*/
|
||||
package net.runelite.client.plugins.slayer;
|
||||
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
import net.runelite.client.ui.overlay.infobox.Counter;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class TaskCounter extends Counter
|
||||
{
|
||||
public TaskCounter(BufferedImage img, int amount)
|
||||
public TaskCounter(BufferedImage img, Plugin plugin, int amount)
|
||||
{
|
||||
super(img, String.valueOf(amount));
|
||||
super(img, plugin, String.valueOf(amount));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,15 +25,16 @@
|
||||
package net.runelite.client.plugins.timers;
|
||||
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
import net.runelite.client.ui.overlay.infobox.Timer;
|
||||
|
||||
public class TimerTimer extends Timer
|
||||
{
|
||||
private final GameTimer timer;
|
||||
|
||||
public TimerTimer(GameTimer timer)
|
||||
public TimerTimer(GameTimer timer, Plugin plugin)
|
||||
{
|
||||
super(timer.getDuration().toMillis(), ChronoUnit.MILLIS, timer.getImage());
|
||||
super(timer.getDuration().toMillis(), ChronoUnit.MILLIS, timer.getImage(), plugin);
|
||||
this.timer = timer;
|
||||
}
|
||||
|
||||
|
||||
@@ -450,7 +450,7 @@ public class TimersPlugin extends Plugin
|
||||
{
|
||||
removeGameTimer(timer);
|
||||
|
||||
TimerTimer t = new TimerTimer(timer);
|
||||
TimerTimer t = new TimerTimer(timer, this);
|
||||
t.setTooltip(timer.getDescription());
|
||||
infoBoxManager.addInfoBox(t);
|
||||
}
|
||||
|
||||
@@ -26,14 +26,15 @@ package net.runelite.client.ui.overlay.infobox;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.image.BufferedImage;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
|
||||
public class Counter extends InfoBox
|
||||
{
|
||||
private String text;
|
||||
|
||||
public Counter(BufferedImage image, String text)
|
||||
public Counter(BufferedImage image, Plugin plugin, String text)
|
||||
{
|
||||
super(image);
|
||||
super(image, plugin);
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,16 +26,22 @@ package net.runelite.client.ui.overlay.infobox;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.image.BufferedImage;
|
||||
import lombok.Getter;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
|
||||
public abstract class InfoBox
|
||||
{
|
||||
private final BufferedImage image;
|
||||
|
||||
@Getter
|
||||
private final Plugin plugin;
|
||||
|
||||
private String tooltip;
|
||||
|
||||
public InfoBox(BufferedImage image)
|
||||
public InfoBox(BufferedImage image, Plugin plugin)
|
||||
{
|
||||
this.image = image;
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public BufferedImage getImage()
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
package net.runelite.client.ui.overlay.infobox;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ComparisonChain;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
@@ -32,6 +33,7 @@ import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
import javax.inject.Singleton;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.runelite.client.plugins.PluginDescriptor;
|
||||
|
||||
@Singleton
|
||||
@Slf4j
|
||||
@@ -44,18 +46,24 @@ public class InfoBoxManager
|
||||
Preconditions.checkNotNull(infoBox);
|
||||
log.debug("Adding InfoBox {}", infoBox);
|
||||
infoBoxes.add(infoBox);
|
||||
|
||||
refreshInfoBoxes();
|
||||
}
|
||||
|
||||
public void removeInfoBox(InfoBox infoBox)
|
||||
{
|
||||
log.debug("Removing InfoBox {}", infoBox);
|
||||
infoBoxes.remove(infoBox);
|
||||
|
||||
refreshInfoBoxes();
|
||||
}
|
||||
|
||||
public void removeIf(Predicate<InfoBox> filter)
|
||||
{
|
||||
log.debug("Removing InfoBoxs for filter {}", filter);
|
||||
log.debug("Removing InfoBoxes for filter {}", filter);
|
||||
infoBoxes.removeIf(filter);
|
||||
|
||||
refreshInfoBoxes();
|
||||
}
|
||||
|
||||
public List<InfoBox> getInfoBoxes()
|
||||
@@ -65,6 +73,7 @@ public class InfoBoxManager
|
||||
|
||||
public void cull()
|
||||
{
|
||||
boolean culled = false;
|
||||
for (Iterator<InfoBox> it = infoBoxes.iterator(); it.hasNext();)
|
||||
{
|
||||
InfoBox box = it.next();
|
||||
@@ -73,7 +82,21 @@ public class InfoBoxManager
|
||||
{
|
||||
log.debug("Culling InfoBox {}", box);
|
||||
it.remove();
|
||||
culled = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (culled)
|
||||
{
|
||||
refreshInfoBoxes();
|
||||
}
|
||||
}
|
||||
|
||||
private void refreshInfoBoxes()
|
||||
{
|
||||
Collections.sort(infoBoxes, (b1, b2) -> ComparisonChain
|
||||
.start()
|
||||
.compare(b1.getPlugin().getClass().getAnnotation(PluginDescriptor.class).name(), b2.getPlugin().getClass().getAnnotation(PluginDescriptor.class).name())
|
||||
.result());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import java.awt.image.BufferedImage;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
|
||||
public class Timer extends InfoBox
|
||||
{
|
||||
@@ -37,9 +38,9 @@ public class Timer extends InfoBox
|
||||
private final Instant endTime;
|
||||
private final Duration duration;
|
||||
|
||||
public Timer(long period, ChronoUnit unit, BufferedImage image)
|
||||
public Timer(long period, ChronoUnit unit, BufferedImage image, Plugin plugin)
|
||||
{
|
||||
super(image);
|
||||
super(image, plugin);
|
||||
|
||||
Preconditions.checkArgument(period > 0, "negative period!");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user