coxhelper: add scaling to infobox (#1295)

* coxhelper: add scaling to infobox, and remove local config caching.

* coxhelper: revert config changes.
This commit is contained in:
Ganom
2019-08-14 21:11:20 -04:00
committed by GitHub
parent dd4986a9dd
commit 03b7254d9b
5 changed files with 55 additions and 97 deletions

View File

@@ -41,7 +41,7 @@ public interface CoxConfig extends Config
{ {
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
public enum FontStyle enum FontStyle
{ {
BOLD("Bold", Font.BOLD), BOLD("Bold", Font.BOLD),
ITALIC("Italic", Font.ITALIC), ITALIC("Italic", Font.ITALIC),
@@ -67,6 +67,7 @@ public interface CoxConfig extends Config
{ {
return new Stub(); return new Stub();
} }
@ConfigItem( @ConfigItem(
position = 2, position = 2,
keyName = "muttadile", keyName = "muttadile",
@@ -207,6 +208,22 @@ public interface CoxConfig extends Config
return true; return true;
} }
@Range(
min = 40,
max = 100
)
@ConfigItem(
position = 11,
keyName = "prayAgainstOlmSize",
name = "Olm Prayer Size",
description = "Change the Size of the Olm Infobox.",
parent = "olmStub"
)
default int prayAgainstOlmSize()
{
return 40;
}
@ConfigItem( @ConfigItem(
position = 12, position = 12,
keyName = "timers", keyName = "timers",

View File

@@ -26,7 +26,6 @@ package net.runelite.client.plugins.coxhelper;
import java.awt.Color; import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
@@ -46,6 +45,7 @@ import net.runelite.client.ui.overlay.components.TitleComponent;
import net.runelite.client.ui.overlay.components.table.TableAlignment; import net.runelite.client.ui.overlay.components.table.TableAlignment;
import net.runelite.client.ui.overlay.components.table.TableComponent; import net.runelite.client.ui.overlay.components.table.TableComponent;
import net.runelite.client.util.ColorUtil; import net.runelite.client.util.ColorUtil;
import net.runelite.client.util.ImageUtil;
@Singleton @Singleton
public class CoxInfoBox extends Overlay public class CoxInfoBox extends Overlay
@@ -65,7 +65,6 @@ public class CoxInfoBox extends Overlay
this.spriteManager = spriteManager; this.spriteManager = spriteManager;
setPosition(OverlayPosition.BOTTOM_RIGHT); setPosition(OverlayPosition.BOTTOM_RIGHT);
setPriority(OverlayPriority.HIGH); setPriority(OverlayPriority.HIGH);
} }
@Override @Override
@@ -85,17 +84,21 @@ public class CoxInfoBox extends Overlay
if (System.currentTimeMillis() < (plugin.getLastPrayTime() + 120000) && plugin.getPrayAgainstOlm() != null) if (System.currentTimeMillis() < (plugin.getLastPrayTime() + 120000) && plugin.getPrayAgainstOlm() != null)
{ {
final int scale = plugin.getPrayAgainstSize();
InfoBoxComponent prayComponent = new InfoBoxComponent(); InfoBoxComponent prayComponent = new InfoBoxComponent();
BufferedImage prayImg = scaleImg(getPrayerImage(plugin.getPrayAgainstOlm())); BufferedImage prayImg = ImageUtil.resizeImage(
getPrayerImage(plugin.getPrayAgainstOlm()), scale, scale
);
prayComponent.setImage(prayImg); prayComponent.setImage(prayImg);
prayComponent.setColor(Color.WHITE); prayComponent.setColor(Color.WHITE);
prayComponent.setBackgroundColor(client.isPrayerActive(prayAgainst.getPrayer()) prayComponent.setBackgroundColor(client.isPrayerActive(prayAgainst.getPrayer())
? ComponentConstants.STANDARD_BACKGROUND_COLOR ? ComponentConstants.STANDARD_BACKGROUND_COLOR
: NOT_ACTIVATED_BACKGROUND_COLOR); : NOT_ACTIVATED_BACKGROUND_COLOR
prayComponent.setPreferredSize(new Dimension(40, 40)); );
prayComponent.setPreferredSize(new Dimension(scale + 4, scale + 4));
prayAgainstPanel.getChildren().add(prayComponent); prayAgainstPanel.getChildren().add(prayComponent);
prayAgainstPanel.setPreferredSize(new Dimension(40, 40)); prayAgainstPanel.setPreferredSize(new Dimension(scale + 4, scale + 4));
prayAgainstPanel.setBorder(new Rectangle(0, 0, 0, 0)); prayAgainstPanel.setBorder(new Rectangle(0, 0, 0, 0));
return prayAgainstPanel.render(graphics); return prayAgainstPanel.render(graphics);
} }
@@ -155,28 +158,8 @@ public class CoxInfoBox extends Overlay
return spriteManager.getSprite(SpriteID.PRAYER_PROTECT_FROM_MELEE, 0); return spriteManager.getSprite(SpriteID.PRAYER_PROTECT_FROM_MELEE, 0);
case RANGED: case RANGED:
return spriteManager.getSprite(SpriteID.PRAYER_PROTECT_FROM_MISSILES, 0); return spriteManager.getSprite(SpriteID.PRAYER_PROTECT_FROM_MISSILES, 0);
default:
return spriteManager.getSprite(SpriteID.BARBARIAN_ASSAULT_EAR_ICON, 0);
} }
return null;
}
private BufferedImage scaleImg(final BufferedImage img)
{
if (img == null)
{
return null;
}
final double width = img.getWidth(null);
final double height = img.getHeight(null);
final double size = 36; // Limit size to 2 as that is minimum size not causing breakage
final double scalex = size / width;
final double scaley = size / height;
final double scale = Math.min(scalex, scaley);
final int newWidth = (int) (width * scale);
final int newHeight = (int) (height * scale);
final BufferedImage scaledImage = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_ARGB);
final Graphics g = scaledImage.createGraphics();
g.drawImage(img, 0, 0, newWidth, newHeight, null);
g.dispose();
return scaledImage;
} }
} }

View File

@@ -39,7 +39,6 @@ import javax.inject.Singleton;
import net.runelite.api.Actor; import net.runelite.api.Actor;
import net.runelite.api.Client; import net.runelite.api.Client;
import net.runelite.api.NPC; import net.runelite.api.NPC;
import net.runelite.api.NPCDefinition;
import net.runelite.api.NpcID; import net.runelite.api.NpcID;
import net.runelite.api.Perspective; import net.runelite.api.Perspective;
import net.runelite.api.Point; import net.runelite.api.Point;
@@ -55,9 +54,7 @@ import net.runelite.client.ui.overlay.OverlayUtil;
@Singleton @Singleton
public class CoxOverlay extends Overlay public class CoxOverlay extends Overlay
{ {
private static final Set<Integer> GAP = ImmutableSet.of( private static final Set<Integer> GAP = ImmutableSet.of(34, 33, 26, 25, 18, 17, 10, 9, 2, 1);
34, 33, 26, 25, 18, 17, 10, 9, 2, 1
);
private final Client client; private final Client client;
private final CoxPlugin plugin; private final CoxPlugin plugin;
@@ -76,13 +73,13 @@ public class CoxOverlay extends Overlay
{ {
for (WorldPoint point : plugin.getOlm_Heal()) for (WorldPoint point : plugin.getOlm_Heal())
{ {
drawTile(graphics, point, plugin.getTpColor(), 2, 150, 50); drawTile(graphics, point, plugin.getTpColor(), 2, 150);
} }
for (WorldPoint point : plugin.getOlm_TP()) for (WorldPoint point : plugin.getOlm_TP())
{ {
client.setHintArrow(point); client.setHintArrow(point);
drawTile(graphics, point, plugin.getTpColor(), 2, 150, 50); drawTile(graphics, point, plugin.getTpColor(), 2, 150);
} }
if (plugin.inRaid()) if (plugin.inRaid())
@@ -105,11 +102,14 @@ public class CoxOverlay extends Overlay
hitSquares = getHitSquares(npcs.getNpc().getWorldLocation(), npcs.getNpcSize(), 1, false); hitSquares = getHitSquares(npcs.getNpc().getWorldLocation(), npcs.getNpcSize(), 1, false);
for (WorldPoint p : hitSquares) for (WorldPoint p : hitSquares)
{ {
drawTile(graphics, p, plugin.getTektonColor(), 0, 0, 50); drawTile(graphics, p, plugin.getTektonColor(), 0, 0);
} }
if (plugin.isTektonTickCounter()) if (plugin.isTektonTickCounter())
{ {
ticksLeft = npcs.getTicksUntilAttack(); ticksLeft = npcs.getTicksUntilAttack();
final int attackTicksleft = plugin.getTektonAttackTicks();
String attacksLeftStr;
Color attackcolor;
if (ticksLeft > 0) if (ticksLeft > 0)
{ {
if (ticksLeft == 1) if (ticksLeft == 1)
@@ -124,12 +124,6 @@ public class CoxOverlay extends Overlay
Point canvasPoint = npcs.getNpc().getCanvasTextLocation(graphics, ticksLeftStr, 0); Point canvasPoint = npcs.getNpc().getCanvasTextLocation(graphics, ticksLeftStr, 0);
renderTextLocation(graphics, ticksLeftStr, plugin.getTextSize(), plugin.getFontStyle().getFont(), color, canvasPoint); renderTextLocation(graphics, ticksLeftStr, plugin.getTextSize(), plugin.getFontStyle().getFont(), color, canvasPoint);
} }
}
if (plugin.isTektonTickCounter())
{
final int attackTicksleft = plugin.getTektonAttackTicks();
String attacksLeftStr;
Color attackcolor;
if (attackTicksleft >= 0 && plugin.isTektonActive()) if (attackTicksleft >= 0 && plugin.isTektonActive())
{ {
if (attackTicksleft <= 1) if (attackTicksleft <= 1)
@@ -160,7 +154,7 @@ public class CoxOverlay extends Overlay
hitSquares = getHitSquares(npcs.getNpc().getWorldLocation(), npcs.getNpcSize(), 1, false); hitSquares = getHitSquares(npcs.getNpc().getWorldLocation(), npcs.getNpcSize(), 1, false);
for (WorldPoint p : hitSquares) for (WorldPoint p : hitSquares)
{ {
drawTile(graphics, p, plugin.getMuttaColor(), 0, 0, 50); drawTile(graphics, p, plugin.getMuttaColor(), 0, 0);
} }
} }
break; break;
@@ -173,7 +167,7 @@ public class CoxOverlay extends Overlay
hitSquares = getHitSquares(npcs.getNpc().getWorldLocation(), npcs.getNpcSize(), 2, true); hitSquares = getHitSquares(npcs.getNpc().getWorldLocation(), npcs.getNpcSize(), 2, true);
for (WorldPoint p : hitSquares) for (WorldPoint p : hitSquares)
{ {
drawTile(graphics, p, plugin.getGuardColor(), 0, 0, 50); drawTile(graphics, p, plugin.getGuardColor(), 0, 0);
} }
} }
if (plugin.isGuardinTickCounter()) if (plugin.isGuardinTickCounter())
@@ -274,7 +268,7 @@ public class CoxOverlay extends Overlay
Point canvasPoint = victim.getPlayer().getCanvasTextLocation(graphics, ticksLeftStr, 0); Point canvasPoint = victim.getPlayer().getCanvasTextLocation(graphics, ticksLeftStr, 0);
renderTextLocation(graphics, ticksLeftStr, plugin.getTextSize(), plugin.getFontStyle().getFont(), tickcolor, canvasPoint); renderTextLocation(graphics, ticksLeftStr, plugin.getTextSize(), plugin.getFontStyle().getFont(), tickcolor, canvasPoint);
} }
renderActorOverlay(graphics, victim.getPlayer(), new Color(193, 255, 245, 255), 2, 100, 10); renderActorOverlay(graphics, victim.getPlayer(), new Color(193, 255, 245, 255));
} }
break; break;
} }
@@ -290,9 +284,9 @@ public class CoxOverlay extends Overlay
{ {
if (boss != null) if (boss != null)
{ {
int tick = plugin.getOlm_TicksUntilAction(); final int tick = plugin.getOlm_TicksUntilAction();
int cycle = plugin.getOlm_ActionCycle(); final int cycle = plugin.getOlm_ActionCycle();
int spec = plugin.getOlm_NextSpec(); final int spec = plugin.getOlm_NextSpec();
final String tickStr = String.valueOf(tick); final String tickStr = String.valueOf(tick);
String cycleStr = "?"; String cycleStr = "?";
switch (cycle) switch (cycle)
@@ -341,7 +335,7 @@ public class CoxOverlay extends Overlay
return null; return null;
} }
private void drawTile(Graphics2D graphics, WorldPoint point, Color color, int strokeWidth, int outlineAlpha, int fillAlpha) private void drawTile(Graphics2D graphics, WorldPoint point, Color color, int strokeWidth, int outlineAlpha)
{ {
WorldPoint playerLocation = client.getLocalPlayer().getWorldLocation(); WorldPoint playerLocation = client.getLocalPlayer().getWorldLocation();
if (point.distanceTo(playerLocation) >= 32) if (point.distanceTo(playerLocation) >= 32)
@@ -363,43 +357,22 @@ public class CoxOverlay extends Overlay
graphics.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), outlineAlpha)); graphics.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), outlineAlpha));
graphics.setStroke(new BasicStroke(strokeWidth)); graphics.setStroke(new BasicStroke(strokeWidth));
graphics.draw(poly); graphics.draw(poly);
graphics.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), fillAlpha)); graphics.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), 50));
graphics.fill(poly); graphics.fill(poly);
} }
private void renderNpcOverlay(Graphics2D graphics, NPC actor, Color color, int outlineWidth, int outlineAlpha, int fillAlpha) private void renderActorOverlay(Graphics2D graphics, Actor actor, Color color)
{ {
int size = 1; final int size = 1;
NPCDefinition composition = actor.getTransformedDefinition(); final LocalPoint lp = actor.getLocalLocation();
if (composition != null) final Polygon tilePoly = Perspective.getCanvasTileAreaPoly(client, lp, size);
{
size = composition.getSize();
}
LocalPoint lp = actor.getLocalLocation();
Polygon tilePoly = Perspective.getCanvasTileAreaPoly(client, lp, size);
if (tilePoly != null) if (tilePoly != null)
{ {
graphics.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), outlineAlpha)); graphics.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), 100));
graphics.setStroke(new BasicStroke(outlineWidth)); graphics.setStroke(new BasicStroke(2));
graphics.draw(tilePoly); graphics.draw(tilePoly);
graphics.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), fillAlpha)); graphics.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), 10));
graphics.fill(tilePoly);
}
}
private void renderActorOverlay(Graphics2D graphics, Actor actor, Color color, int outlineWidth, int outlineAlpha, int fillAlpha)
{
int size = 1;
LocalPoint lp = actor.getLocalLocation();
Polygon tilePoly = Perspective.getCanvasTileAreaPoly(client, lp, size);
if (tilePoly != null)
{
graphics.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), outlineAlpha));
graphics.setStroke(new BasicStroke(outlineWidth));
graphics.draw(tilePoly);
graphics.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), fillAlpha));
graphics.fill(tilePoly); graphics.fill(tilePoly);
} }
} }
@@ -444,8 +417,8 @@ public class CoxOverlay extends Overlay
private List<WorldPoint> getHitSquares(WorldPoint npcLoc, int npcSize, int thickness, boolean includeUnder) private List<WorldPoint> getHitSquares(WorldPoint npcLoc, int npcSize, int thickness, boolean includeUnder)
{ {
List<WorldPoint> little = new WorldArea(npcLoc, npcSize, npcSize).toWorldPointList(); final List<WorldPoint> little = new WorldArea(npcLoc, npcSize, npcSize).toWorldPointList();
List<WorldPoint> big = new WorldArea(npcLoc.getX() - thickness, npcLoc.getY() - thickness, npcSize + (thickness * 2), npcSize + (thickness * 2), npcLoc.getPlane()).toWorldPointList(); final List<WorldPoint> big = new WorldArea(npcLoc.getX() - thickness, npcLoc.getY() - thickness, npcSize + (thickness * 2), npcSize + (thickness * 2), npcLoc.getPlane()).toWorldPointList();
if (!includeUnder) if (!includeUnder)
{ {
big.removeIf(little::contains); big.removeIf(little::contains);

View File

@@ -141,6 +141,7 @@ public class CoxPlugin extends Plugin
private boolean timers; private boolean timers;
private boolean tpOverlay; private boolean tpOverlay;
private boolean olmTick; private boolean olmTick;
private int prayAgainstSize;
private Color muttaColor; private Color muttaColor;
private Color guardColor; private Color guardColor;
private Color tektonColor; private Color tektonColor;
@@ -162,7 +163,6 @@ public class CoxPlugin extends Plugin
{ {
updateConfig(); updateConfig();
addSubscriptions(); addSubscriptions();
overlayManager.add(coxOverlay); overlayManager.add(coxOverlay);
overlayManager.add(coxInfoBox); overlayManager.add(coxInfoBox);
handCripple = false; handCripple = false;
@@ -651,5 +651,6 @@ public class CoxPlugin extends Plugin
this.fontStyle = config.fontStyle(); this.fontStyle = config.fontStyle();
this.textSize = config.textSize(); this.textSize = config.textSize();
this.shadows = config.shadows(); this.shadows = config.shadows();
this.prayAgainstSize = config.prayAgainstOlmSize();
} }
} }

View File

@@ -51,8 +51,6 @@ class NPCContainer
@Setter(AccessLevel.PACKAGE) @Setter(AccessLevel.PACKAGE)
private Actor npcInteracting; private Actor npcInteracting;
@Setter(AccessLevel.PACKAGE) @Setter(AccessLevel.PACKAGE)
private Specials specials;
@Setter(AccessLevel.PACKAGE)
private Attackstyle attackStyle; private Attackstyle attackStyle;
@@ -66,7 +64,6 @@ class NPCContainer
this.ticksUntilAttack = 0; this.ticksUntilAttack = 0;
this.intermissionPeriod = 0; this.intermissionPeriod = 0;
this.attackStyle = Attackstyle.UNKNOWN; this.attackStyle = Attackstyle.UNKNOWN;
this.specials = Specials.UNKNOWN;
final NPCDefinition composition = npc.getTransformedDefinition(); final NPCDefinition composition = npc.getTransformedDefinition();
if (composition != null) if (composition != null)
@@ -75,19 +72,6 @@ class NPCContainer
} }
} }
@AllArgsConstructor
@Getter(AccessLevel.PACKAGE)
public enum Specials
{
PORTALS("Portals"),
LIGHTNING("Lightning"),
CRYSTALS("Crystals"),
HEAL("Heal"),
UNKNOWN("Unknown");
private String name = "";
}
@AllArgsConstructor @AllArgsConstructor
@Getter(AccessLevel.PACKAGE) @Getter(AccessLevel.PACKAGE)
public enum Attackstyle public enum Attackstyle