Merge pull request #1206 from sethtroll/addoverallindicator

boosts plugin: Add stat change indicator
This commit is contained in:
Adam
2018-04-26 20:42:25 -04:00
committed by GitHub
3 changed files with 107 additions and 18 deletions

View File

@@ -27,7 +27,6 @@ package net.runelite.client.plugins.boosts;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.time.Duration;
import java.time.Instant;
import javax.inject.Inject;
import lombok.Getter;
@@ -57,6 +56,8 @@ class BoostsOverlay extends Overlay
private PanelComponent panelComponent;
private boolean overlayActive;
@Inject
BoostsOverlay(Client client, BoostsConfig config, InfoBoxManager infoBoxManager)
{
@@ -71,7 +72,26 @@ class BoostsOverlay extends Overlay
public Dimension render(Graphics2D graphics)
{
panelComponent = new PanelComponent();
boolean overlayActive = false;
Instant lastChange = plugin.getLastChange();
if (!config.displayIndicators()
&& config.displayNextChange()
&& lastChange != null
&& overlayActive)
{
int nextChange = plugin.getChangeTime();
if (nextChange > 0)
{
panelComponent.getLines().add(new PanelComponent.Line(
"Next change in",
Color.WHITE,
String.valueOf(nextChange),
Color.WHITE
));
}
}
overlayActive = false;
for (Skill skill : plugin.getShownSkills())
{
@@ -137,21 +157,6 @@ class BoostsOverlay extends Overlay
}
}
Instant lastChange = plugin.getLastChange();
if (config.displayNextChange() && lastChange != null && overlayActive)
{
int nextChange = 60 - (int)Duration.between(lastChange, Instant.now()).getSeconds();
if (nextChange > 0)
{
panelComponent.getLines().add(new PanelComponent.Line(
"Next change in",
Color.WHITE,
String.valueOf(nextChange),
Color.WHITE
));
}
}
return panelComponent.getLines().isEmpty() ? null : panelComponent.render(graphics);
}

View File

@@ -27,7 +27,10 @@ package net.runelite.client.plugins.boosts;
import com.google.common.collect.ObjectArrays;
import com.google.common.eventbus.Subscribe;
import com.google.inject.Provides;
import java.awt.image.BufferedImage;
import java.time.Duration;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.Arrays;
import javax.inject.Inject;
import lombok.Getter;
@@ -37,6 +40,7 @@ import net.runelite.api.Skill;
import net.runelite.api.events.BoostedLevelChanged;
import net.runelite.api.events.ConfigChanged;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.game.SkillIconManager;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.ui.overlay.Overlay;
@@ -76,9 +80,16 @@ public class BoostsPlugin extends Plugin
@Inject
private BoostsConfig config;
@Inject
private SkillIconManager skillIconManager;
@Getter
private Skill[] shownSkills;
private StatChangeIndicator statChangeIndicator;
private BufferedImage overallIcon;
@Provides
BoostsConfig provideConfig(ConfigManager configManager)
{
@@ -96,17 +107,29 @@ public class BoostsPlugin extends Plugin
{
updateShownSkills(config.enableSkill());
Arrays.fill(lastSkillLevels, -1);
overallIcon = skillIconManager.getSkillImage(Skill.OVERALL);
}
@Override
protected void shutDown() throws Exception
{
infoBoxManager.removeIf(t -> t instanceof BoostIndicator);
infoBoxManager.removeIf(t -> t instanceof BoostIndicator || t instanceof StatChangeIndicator);
}
@Subscribe
public void onConfigChanged(ConfigChanged event)
{
if (!event.getGroup().equals("boosts"))
{
return;
}
if (event.getKey().equals("displayIndicators") || event.getKey().equals("displayNextChange"))
{
addStatChangeIndicator();
return;
}
Skill[] old = shownSkills;
updateShownSkills(config.enableSkill());
@@ -137,6 +160,7 @@ public class BoostsPlugin extends Plugin
{
log.debug("Skill {} healed", skill);
lastChange = Instant.now();
addStatChangeIndicator();
}
lastSkillLevels[skillIdx] = cur;
}
@@ -152,4 +176,23 @@ public class BoostsPlugin extends Plugin
shownSkills = COMBAT;
}
}
public void addStatChangeIndicator()
{
infoBoxManager.removeInfoBox(statChangeIndicator);
statChangeIndicator = null;
if (lastChange != null
&& config.displayIndicators()
&& config.displayNextChange())
{
statChangeIndicator = new StatChangeIndicator(getChangeTime(), ChronoUnit.SECONDS, overallIcon, this);
infoBoxManager.addInfoBox(statChangeIndicator);
}
}
public int getChangeTime()
{
return 60 - (int) Duration.between(lastChange, Instant.now()).getSeconds();
}
}

View File

@@ -0,0 +1,41 @@
/*
* 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.plugins.boosts;
import java.awt.image.BufferedImage;
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 StatChangeIndicator extends Timer
{
public StatChangeIndicator(long period, ChronoUnit unit, BufferedImage image, Plugin plugin)
{
super(period, unit, image, plugin);
setPriority(InfoBoxPriority.MED);
setTooltip("Next stat change");
}
}