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