Merge pull request #1040 from sethtroll/addinfoboxpriority

Info Boxes: Group boxes by plugin, sort by priority
This commit is contained in:
Adam
2018-03-24 14:19:52 -04:00
committed by GitHub
19 changed files with 107 additions and 26 deletions

View File

@@ -29,7 +29,9 @@ 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;
import net.runelite.client.ui.overlay.infobox.InfoBoxPriority;
public class BoostIndicator extends InfoBox
{
@@ -39,13 +41,14 @@ 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;
setTooltip(skill.getName() + " boost");
setPriority(InfoBoxPriority.HIGH);
}
@Override

View File

@@ -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;
}

View File

@@ -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);
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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;

View File

@@ -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));

View File

@@ -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));
}
}

View File

@@ -25,16 +25,19 @@
package net.runelite.client.plugins.timers;
import java.time.temporal.ChronoUnit;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.ui.overlay.infobox.InfoBoxPriority;
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;
setPriority(InfoBoxPriority.MED);
}
public GameTimer getTimer()

View File

@@ -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);
}

View File

@@ -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;
}

View File

@@ -26,16 +26,28 @@ package net.runelite.client.ui.overlay.infobox;
import java.awt.Color;
import java.awt.image.BufferedImage;
import lombok.Getter;
import lombok.Setter;
import net.runelite.client.plugins.Plugin;
public abstract class InfoBox
{
private final BufferedImage image;
@Getter
private final Plugin plugin;
@Getter
@Setter
private InfoBoxPriority priority;
private String tooltip;
public InfoBox(BufferedImage image)
public InfoBox(BufferedImage image, Plugin plugin)
{
this.image = image;
this.plugin = plugin;
setPriority(InfoBoxPriority.NONE);
}
public BufferedImage getImage()

View File

@@ -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,22 @@ 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.getPriority(), b2.getPriority())
.compare(b1.getPlugin().getClass().getAnnotation(PluginDescriptor.class).name(), b2.getPlugin().getClass().getAnnotation(PluginDescriptor.class).name())
.result());
}
}

View File

@@ -0,0 +1,33 @@
/*
* Copyright (c) 2018, Seth <http://github.com/sethtroll>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.client.ui.overlay.infobox;
public enum InfoBoxPriority
{
HIGH,
MED,
NONE,
LOW
}

View File

@@ -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!");