client: change Counter infobox to store count as an integer

This commit is contained in:
Adam
2019-02-19 09:44:59 -05:00
parent 643950d4dc
commit 06d4adc5e4
10 changed files with 50 additions and 53 deletions

View File

@@ -26,15 +26,15 @@ package net.runelite.client.plugins.cannon;
import java.awt.Color; import java.awt.Color;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import net.runelite.client.ui.overlay.infobox.Counter; import net.runelite.client.ui.overlay.infobox.InfoBox;
public class CannonCounter extends Counter public class CannonCounter extends InfoBox
{ {
private final CannonPlugin plugin; private final CannonPlugin plugin;
public CannonCounter(BufferedImage img, CannonPlugin plugin) public CannonCounter(BufferedImage img, CannonPlugin plugin)
{ {
super(img, plugin, String.valueOf(plugin.getCballsLeft())); super(img, plugin);
this.plugin = plugin; this.plugin = plugin;
} }

View File

@@ -34,7 +34,7 @@ public class KingdomCounter extends Counter
public KingdomCounter(BufferedImage image, KingdomPlugin plugin) public KingdomCounter(BufferedImage image, KingdomPlugin plugin)
{ {
super(image, plugin, String.valueOf(plugin.getFavor())); super(image, plugin, plugin.getFavor());
this.plugin = plugin; this.plugin = plugin;
} }

View File

@@ -31,22 +31,15 @@ import net.runelite.client.ui.overlay.infobox.Counter;
public class GraveyardCounter extends Counter public class GraveyardCounter extends Counter
{ {
private int count;
public GraveyardCounter(BufferedImage image, Plugin plugin) public GraveyardCounter(BufferedImage image, Plugin plugin)
{ {
super(image, plugin, "0"); super(image, plugin, 0);
}
public void setCount(int count)
{
this.count = count;
this.setText(String.valueOf(count));
} }
@Override @Override
public Color getTextColor() public Color getTextColor()
{ {
int count = getCount();
if (count >= GraveyardRoom.MIN_SCORE) if (count >= GraveyardRoom.MIN_SCORE)
{ {
return Color.GREEN; return Color.GREEN;

View File

@@ -33,8 +33,6 @@ import net.runelite.client.ui.overlay.infobox.Counter;
public class AbsorptionCounter extends Counter public class AbsorptionCounter extends Counter
{ {
private int absorption;
@Getter @Getter
@Setter @Setter
private int threshold; private int threshold;
@@ -49,20 +47,19 @@ public class AbsorptionCounter extends Counter
public AbsorptionCounter(BufferedImage image, Plugin plugin, int absorption, int threshold) public AbsorptionCounter(BufferedImage image, Plugin plugin, int absorption, int threshold)
{ {
super(image, plugin, ""); super(image, plugin, absorption);
this.threshold = threshold; this.threshold = threshold;
setAbsorption(absorption);
} }
public void setAbsorption(int absorption) public void setAbsorption(int absorption)
{ {
this.absorption = absorption; setCount(absorption);
setText(String.valueOf(absorption));
} }
@Override @Override
public Color getTextColor() public Color getTextColor()
{ {
int absorption = getCount();
if (absorption >= threshold) if (absorption >= threshold)
{ {
return aboveThresholdColor; return aboveThresholdColor;
@@ -76,6 +73,7 @@ public class AbsorptionCounter extends Counter
@Override @Override
public String getTooltip() public String getTooltip()
{ {
int absorption = getCount();
return "Absorption: " + absorption; return "Absorption: " + absorption;
} }
} }

View File

@@ -24,25 +24,32 @@
*/ */
package net.runelite.client.plugins.prayer; package net.runelite.client.plugins.prayer;
import java.awt.Color;
import lombok.Getter; import lombok.Getter;
import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.Plugin;
import net.runelite.client.ui.overlay.infobox.Counter; import net.runelite.client.ui.overlay.infobox.InfoBox;
class PrayerCounter extends Counter class PrayerCounter extends InfoBox
{ {
@Getter @Getter
private final PrayerType prayerType; private final PrayerType prayerType;
PrayerCounter(Plugin plugin, PrayerType prayerType) PrayerCounter(Plugin plugin, PrayerType prayerType)
{ {
super(null, plugin, ""); super(null, plugin);
this.prayerType = prayerType; this.prayerType = prayerType;
} }
@Override @Override
public String toString() public String getText()
{ {
return "Counter{" + "prayer=" + prayerType.getName() + '}'; return null;
}
@Override
public Color getTextColor()
{
return null;
} }
@Override @Override

View File

@@ -580,7 +580,7 @@ public class SlayerPlugin extends Plugin
// add and update counter, set timer // add and update counter, set timer
addCounter(); addCounter();
counter.setText(String.valueOf(amount)); counter.setCount(amount);
infoTimer = Instant.now(); infoTimer = Instant.now();
} }

View File

@@ -33,6 +33,6 @@ public class TaskCounter extends Counter
{ {
public TaskCounter(BufferedImage img, Plugin plugin, int amount) public TaskCounter(BufferedImage img, Plugin plugin, int amount)
{ {
super(img, plugin, String.valueOf(amount)); super(img, plugin, amount);
} }
} }

View File

@@ -29,30 +29,24 @@ import net.runelite.client.ui.overlay.infobox.Counter;
class SpecialCounter extends Counter class SpecialCounter extends Counter
{ {
private int hitValue;
private SpecialWeapon weapon; private SpecialWeapon weapon;
SpecialCounter(BufferedImage image, SpecialCounterPlugin plugin, int hitValue, SpecialWeapon weapon) SpecialCounter(BufferedImage image, SpecialCounterPlugin plugin, int hitValue, SpecialWeapon weapon)
{ {
super(image, plugin, null); super(image, plugin, hitValue);
this.weapon = weapon; this.weapon = weapon;
this.hitValue = hitValue;
} }
void addHits(double hit) void addHits(double hit)
{ {
this.hitValue += hit; int count = getCount();
} setCount(count + (int) hit);
@Override
public String getText()
{
return Integer.toString(hitValue);
} }
@Override @Override
public String getTooltip() public String getTooltip()
{ {
int hitValue = getCount();
if (!weapon.isDamage()) if (!weapon.isDamage())
{ {
if (hitValue == 1) if (hitValue == 1)

View File

@@ -26,33 +26,28 @@ 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 lombok.Setter;
import lombok.ToString;
import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.Plugin;
@ToString
public class Counter extends InfoBox public class Counter extends InfoBox
{ {
private String text; @Getter
@Setter
private int count;
public Counter(BufferedImage image, Plugin plugin, String text) public Counter(BufferedImage image, Plugin plugin, int count)
{ {
super(image, plugin); super(image, plugin);
this.text = text; this.count = count;
}
@Override
public String toString()
{
return "Counter{" + "text=" + text + '}';
} }
@Override @Override
public String getText() public String getText()
{ {
return text; return Integer.toString(count);
}
public void setText(String text)
{
this.text = text;
} }
@Override @Override

View File

@@ -26,6 +26,7 @@
package net.runelite.client.ui.overlay.infobox; package net.runelite.client.ui.overlay.infobox;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Point; import java.awt.Point;
@@ -94,10 +95,19 @@ public class InfoBoxOverlay extends Overlay
continue; continue;
} }
final String text = box.getText();
final Color color = box.getTextColor();
final InfoBoxComponent infoBoxComponent = new InfoBoxComponent(); final InfoBoxComponent infoBoxComponent = new InfoBoxComponent();
infoBoxComponent.setColor(box.getTextColor()); if (!Strings.isNullOrEmpty(text))
{
infoBoxComponent.setText(text);
}
if (color != null)
{
infoBoxComponent.setColor(color);
}
infoBoxComponent.setImage(box.getScaledImage()); infoBoxComponent.setImage(box.getScaledImage());
infoBoxComponent.setText(box.getText());
infoBoxComponent.setTooltip(box.getTooltip()); infoBoxComponent.setTooltip(box.getTooltip());
panelComponent.getChildren().add(infoBoxComponent); panelComponent.getChildren().add(infoBoxComponent);
} }