Merge pull request #832 from Unmoon/boosts-next-change
Boosts plugin: Add "Next change"
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Adam <Adam@sigterm.info>
|
||||
* 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.api.events;
|
||||
|
||||
import lombok.Data;
|
||||
import net.runelite.api.Skill;
|
||||
|
||||
@Data
|
||||
public class BoostedLevelChanged
|
||||
{
|
||||
private Skill skill;
|
||||
}
|
||||
@@ -24,9 +24,9 @@
|
||||
*/
|
||||
package net.runelite.client.plugins.boosts;
|
||||
|
||||
import net.runelite.client.config.Config;
|
||||
import net.runelite.client.config.ConfigGroup;
|
||||
import net.runelite.client.config.ConfigItem;
|
||||
import net.runelite.client.config.Config;
|
||||
|
||||
@ConfigGroup(
|
||||
keyName = "boosts",
|
||||
@@ -38,7 +38,8 @@ public interface BoostsConfig extends Config
|
||||
@ConfigItem(
|
||||
keyName = "enableSkill",
|
||||
name = "Enable Skill Boosts",
|
||||
description = "Configures whether or not to display skill boost information"
|
||||
description = "Configures whether or not to display skill boost information",
|
||||
position = 1
|
||||
)
|
||||
default boolean enableSkill()
|
||||
{
|
||||
@@ -48,7 +49,8 @@ public interface BoostsConfig extends Config
|
||||
@ConfigItem(
|
||||
keyName = "relativeBoost",
|
||||
name = "Use Relative Boosts",
|
||||
description = "Configures whether or not relative boost is used"
|
||||
description = "Configures whether or not relative boost is used",
|
||||
position = 2
|
||||
)
|
||||
default boolean useRelativeBoost()
|
||||
{
|
||||
@@ -58,10 +60,22 @@ public interface BoostsConfig extends Config
|
||||
@ConfigItem(
|
||||
keyName = "displayIndicators",
|
||||
name = "Display as indicators",
|
||||
description = "Configures whether or not to display the boost as indicators"
|
||||
description = "Configures whether or not to display the boost as indicators",
|
||||
position = 3
|
||||
)
|
||||
default boolean displayIndicators()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "displayNextChange",
|
||||
name = "Display next change",
|
||||
description = "Configures whether or not to display when the next stat change will be",
|
||||
position = 4
|
||||
)
|
||||
default boolean displayNextChange()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,9 +28,10 @@ import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import javax.inject.Inject;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.Skill;
|
||||
import net.runelite.client.game.SkillIconManager;
|
||||
@@ -40,7 +41,6 @@ import net.runelite.client.ui.overlay.OverlayPriority;
|
||||
import net.runelite.client.ui.overlay.components.PanelComponent;
|
||||
import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
|
||||
|
||||
@Slf4j
|
||||
class BoostsOverlay extends Overlay
|
||||
{
|
||||
@Getter
|
||||
@@ -72,6 +72,7 @@ class BoostsOverlay extends Overlay
|
||||
public Dimension render(Graphics2D graphics, Point parent)
|
||||
{
|
||||
panelComponent = new PanelComponent();
|
||||
boolean overlayActive = false;
|
||||
|
||||
for (Skill skill : plugin.getShownSkills())
|
||||
{
|
||||
@@ -90,6 +91,8 @@ class BoostsOverlay extends Overlay
|
||||
continue;
|
||||
}
|
||||
|
||||
overlayActive = true;
|
||||
|
||||
if (config.displayIndicators())
|
||||
{
|
||||
if (indicator == null)
|
||||
@@ -135,7 +138,22 @@ class BoostsOverlay extends Overlay
|
||||
}
|
||||
}
|
||||
|
||||
return config.displayIndicators() ? null : panelComponent.render(graphics, parent);
|
||||
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, parent);
|
||||
}
|
||||
|
||||
private Color getTextColor(int boost)
|
||||
|
||||
@@ -27,10 +27,14 @@ 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.time.Instant;
|
||||
import java.util.Arrays;
|
||||
import javax.inject.Inject;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.runelite.api.Client;
|
||||
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.plugins.Plugin;
|
||||
@@ -41,6 +45,7 @@ import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
|
||||
@PluginDescriptor(
|
||||
name = "Boosts Information"
|
||||
)
|
||||
@Slf4j
|
||||
public class BoostsPlugin extends Plugin
|
||||
{
|
||||
private static final Skill[] COMBAT = new Skill[]
|
||||
@@ -54,6 +59,14 @@ public class BoostsPlugin extends Plugin
|
||||
Skill.SLAYER, Skill.FARMING, Skill.CONSTRUCTION, Skill.HUNTER
|
||||
};
|
||||
|
||||
private final int[] lastSkillLevels = new int[Skill.values().length - 1];
|
||||
|
||||
@Getter
|
||||
private Instant lastChange;
|
||||
|
||||
@Inject
|
||||
private Client client;
|
||||
|
||||
@Inject
|
||||
private InfoBoxManager infoBoxManager;
|
||||
|
||||
@@ -82,6 +95,7 @@ public class BoostsPlugin extends Plugin
|
||||
protected void startUp()
|
||||
{
|
||||
updateShownSkills(config.enableSkill());
|
||||
Arrays.fill(lastSkillLevels, -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -103,6 +117,30 @@ public class BoostsPlugin extends Plugin
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
void onBoostedLevelChange(BoostedLevelChanged boostedLevelChanged)
|
||||
{
|
||||
Skill skill = boostedLevelChanged.getSkill();
|
||||
|
||||
// Ignore changes to hitpoints or prayer
|
||||
if (skill == Skill.HITPOINTS || skill == Skill.PRAYER)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int skillIdx = skill.ordinal();
|
||||
int last = lastSkillLevels[skillIdx];
|
||||
int cur = client.getBoostedSkillLevel(skill);
|
||||
|
||||
// Check if stat goes +1 or -2
|
||||
if (cur == last + 1 || cur == last - 1)
|
||||
{
|
||||
log.debug("Skill {} healed", skill);
|
||||
lastChange = Instant.now();
|
||||
}
|
||||
lastSkillLevels[skillIdx] = cur;
|
||||
}
|
||||
|
||||
private void updateShownSkills(boolean showSkillingSkills)
|
||||
{
|
||||
if (showSkillingSkills)
|
||||
|
||||
@@ -56,6 +56,7 @@ import net.runelite.api.Varbits;
|
||||
import net.runelite.api.WidgetNode;
|
||||
import net.runelite.api.coords.LocalPoint;
|
||||
import net.runelite.api.events.DraggingWidgetChanged;
|
||||
import net.runelite.api.events.BoostedLevelChanged;
|
||||
import net.runelite.api.events.ExperienceChanged;
|
||||
import net.runelite.api.events.GameStateChanged;
|
||||
import net.runelite.api.events.GrandExchangeOfferChanged;
|
||||
@@ -542,6 +543,21 @@ public abstract class RSClientMixin implements RSClient
|
||||
}
|
||||
}
|
||||
|
||||
@FieldHook("boostedSkillLevels")
|
||||
@Inject
|
||||
public static void boostedSkillLevelsChanged(int idx)
|
||||
{
|
||||
Skill[] skills = Skill.values();
|
||||
|
||||
if (idx >= 0 && idx < skills.length - 1)
|
||||
{
|
||||
Skill updatedSkill = skills[idx];
|
||||
BoostedLevelChanged boostedLevelChanged = new BoostedLevelChanged();
|
||||
boostedLevelChanged.setSkill(updatedSkill);
|
||||
eventBus.post(boostedLevelChanged);
|
||||
}
|
||||
}
|
||||
|
||||
@FieldHook("mapRegions")
|
||||
@Inject
|
||||
public static void mapRegionsChanged(int idx)
|
||||
|
||||
Reference in New Issue
Block a user