Update opponent info to use PanelComponent
- Use panel component with custom paddings for opponent info - For opponent/opponents opponent names use TitleComponent that is horizontally centered - Use new progress bar with full display mode when needed Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
@@ -26,11 +26,9 @@ package net.runelite.client.plugins.opponentinfo;
|
|||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.FontMetrics;
|
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
import java.text.DecimalFormat;
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -43,42 +41,39 @@ import net.runelite.api.Varbits;
|
|||||||
import net.runelite.client.ui.overlay.Overlay;
|
import net.runelite.client.ui.overlay.Overlay;
|
||||||
import net.runelite.client.ui.overlay.OverlayPosition;
|
import net.runelite.client.ui.overlay.OverlayPosition;
|
||||||
import net.runelite.client.ui.overlay.OverlayPriority;
|
import net.runelite.client.ui.overlay.OverlayPriority;
|
||||||
import net.runelite.client.ui.overlay.components.BackgroundComponent;
|
import net.runelite.client.ui.overlay.components.PanelComponent;
|
||||||
import net.runelite.client.ui.overlay.components.TextComponent;
|
import net.runelite.client.ui.overlay.components.ProgressBarComponent;
|
||||||
|
import net.runelite.client.ui.overlay.components.TitleComponent;
|
||||||
import net.runelite.client.util.Text;
|
import net.runelite.client.util.Text;
|
||||||
|
|
||||||
class OpponentInfoOverlay extends Overlay
|
class OpponentInfoOverlay extends Overlay
|
||||||
{
|
{
|
||||||
private static final int WIDTH = 129;
|
|
||||||
|
|
||||||
private static final int TOP_BORDER = 2;
|
|
||||||
|
|
||||||
private static final int BAR_WIDTH = WIDTH - 4;
|
|
||||||
private static final int BAR_HEIGHT = 16;
|
|
||||||
|
|
||||||
private static final Color HP_GREEN = new Color(0, 146, 54, 230);
|
private static final Color HP_GREEN = new Color(0, 146, 54, 230);
|
||||||
private static final Color HP_RED = new Color(102, 15, 16, 230);
|
private static final Color HP_RED = new Color(102, 15, 16, 230);
|
||||||
private static final Duration WAIT = Duration.ofSeconds(3);
|
private static final Duration WAIT = Duration.ofSeconds(3);
|
||||||
|
|
||||||
private final Client client;
|
private final Client client;
|
||||||
private final NPC[] clientNpcs;
|
private final NPC[] clientNpcs;
|
||||||
|
private final PanelComponent panelComponent = new PanelComponent();
|
||||||
|
private final Map<String, Integer> oppInfoHealth = OpponentInfoPlugin.loadNpcHealth();
|
||||||
|
|
||||||
private Integer lastMaxHealth;
|
private Integer lastMaxHealth;
|
||||||
private DecimalFormat df = new DecimalFormat("0.0");
|
|
||||||
private float lastRatio = 0;
|
private float lastRatio = 0;
|
||||||
private Instant lastTime = Instant.now();
|
private Instant lastTime = Instant.now();
|
||||||
private String opponentName;
|
private String opponentName;
|
||||||
private String opponentsOpponentName;
|
private String opponentsOpponentName;
|
||||||
private Map<String, Integer> oppInfoHealth = OpponentInfoPlugin.loadNpcHealth();
|
|
||||||
private NPC lastOpponent;
|
private NPC lastOpponent;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
OpponentInfoOverlay(Client client)
|
private OpponentInfoOverlay(Client client)
|
||||||
{
|
{
|
||||||
setPosition(OverlayPosition.TOP_LEFT);
|
|
||||||
setPriority(OverlayPriority.HIGH);
|
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.clientNpcs = client.getCachedNPCs();
|
this.clientNpcs = client.getCachedNPCs();
|
||||||
|
setPosition(OverlayPosition.TOP_LEFT);
|
||||||
|
setPriority(OverlayPriority.HIGH);
|
||||||
|
|
||||||
|
panelComponent.setBorder(new Rectangle(2, 2, 2, 2));
|
||||||
|
panelComponent.setGap(new Point(0, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Actor getOpponent()
|
private Actor getOpponent()
|
||||||
@@ -140,77 +135,42 @@ class OpponentInfoOverlay extends Overlay
|
|||||||
return null; //don't draw anything.
|
return null; //don't draw anything.
|
||||||
}
|
}
|
||||||
|
|
||||||
FontMetrics fm = graphics.getFontMetrics();
|
panelComponent.getChildren().clear();
|
||||||
|
|
||||||
int height = TOP_BORDER + fm.getHeight(); // opponent name
|
// Opponent name
|
||||||
|
panelComponent.getChildren().add(TitleComponent.builder()
|
||||||
|
.text(opponentName)
|
||||||
|
.build());
|
||||||
|
|
||||||
|
// Health bar
|
||||||
if (lastRatio >= 0)
|
if (lastRatio >= 0)
|
||||||
{
|
{
|
||||||
height += BAR_HEIGHT + 5;
|
final ProgressBarComponent progressBarComponent = new ProgressBarComponent();
|
||||||
}
|
progressBarComponent.setBackgroundColor(HP_RED);
|
||||||
if (opponentsOpponentName != null)
|
progressBarComponent.setForegroundColor(HP_GREEN);
|
||||||
{
|
|
||||||
height += fm.getHeight() + 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
final BackgroundComponent backgroundComponent = new BackgroundComponent();
|
|
||||||
backgroundComponent.setRectangle(new Rectangle(0, 0, WIDTH, height));
|
|
||||||
backgroundComponent.render(graphics);
|
|
||||||
|
|
||||||
int y = TOP_BORDER + fm.getHeight();
|
|
||||||
|
|
||||||
{
|
|
||||||
int x = (WIDTH - fm.stringWidth(opponentName)) / 2;
|
|
||||||
final TextComponent textComponent = new TextComponent();
|
|
||||||
textComponent.setPosition(new Point(x, y));
|
|
||||||
textComponent.setText(opponentName);
|
|
||||||
textComponent.render(graphics);
|
|
||||||
|
|
||||||
y += 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lastRatio >= 0)
|
|
||||||
{
|
|
||||||
int barWidth = (int) (lastRatio * (float) BAR_WIDTH);
|
|
||||||
|
|
||||||
graphics.setColor(HP_GREEN);
|
|
||||||
graphics.fillRect((WIDTH - BAR_WIDTH) / 2, y, barWidth, BAR_HEIGHT);
|
|
||||||
|
|
||||||
graphics.setColor(HP_RED);
|
|
||||||
graphics.fillRect(((WIDTH - BAR_WIDTH) / 2) + barWidth, y, BAR_WIDTH - barWidth, BAR_HEIGHT);
|
|
||||||
|
|
||||||
String str;
|
|
||||||
|
|
||||||
if (lastMaxHealth != null)
|
if (lastMaxHealth != null)
|
||||||
{
|
{
|
||||||
int currHealth = (int) (lastRatio * lastMaxHealth);
|
progressBarComponent.setLabelDisplayMode(ProgressBarComponent.LabelDisplayMode.FULL);
|
||||||
str = currHealth + "/" + lastMaxHealth;
|
progressBarComponent.setMaximum(lastMaxHealth);
|
||||||
|
progressBarComponent.setValue(lastRatio * lastMaxHealth);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
str = df.format(lastRatio * 100) + "%";
|
progressBarComponent.setValue(lastRatio * 100d);
|
||||||
}
|
}
|
||||||
|
|
||||||
y += BAR_HEIGHT;
|
panelComponent.getChildren().add(progressBarComponent);
|
||||||
|
|
||||||
final TextComponent textComponent1 = new TextComponent();
|
|
||||||
textComponent1.setText(str);
|
|
||||||
textComponent1.setPosition(new Point((WIDTH - fm.stringWidth(str)) / 2, y));
|
|
||||||
textComponent1.render(graphics);
|
|
||||||
|
|
||||||
y += 3;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Opponents opponent
|
||||||
if (opponentsOpponentName != null)
|
if (opponentsOpponentName != null)
|
||||||
{
|
{
|
||||||
y += fm.getHeight();
|
panelComponent.getChildren().add(TitleComponent.builder()
|
||||||
|
.text(opponentsOpponentName)
|
||||||
int x = (WIDTH - fm.stringWidth(opponentsOpponentName)) / 2;
|
.build());
|
||||||
final TextComponent textComponent = new TextComponent();
|
|
||||||
textComponent.setPosition(new Point(x, y));
|
|
||||||
textComponent.setText(opponentsOpponentName);
|
|
||||||
textComponent.render(graphics);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Dimension(WIDTH, height);
|
return panelComponent.render(graphics);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -275,8 +275,7 @@ public class XpGlobesOverlay extends Overlay
|
|||||||
ProgressBarComponent progressBar = new ProgressBarComponent();
|
ProgressBarComponent progressBar = new ProgressBarComponent();
|
||||||
double progress = mouseOverSkill.getSkillProgress(Experience.getXpForLevel(mouseOverSkill.getCurrentLevel()),
|
double progress = mouseOverSkill.getSkillProgress(Experience.getXpForLevel(mouseOverSkill.getCurrentLevel()),
|
||||||
mouseOverSkill.getCurrentXp(), mouseOverSkill.getGoalXp());
|
mouseOverSkill.getCurrentXp(), mouseOverSkill.getGoalXp());
|
||||||
progressBar.setProgress(progress);
|
progressBar.setValue(progress);
|
||||||
|
|
||||||
xpTooltip.getChildren().add(progressBar);
|
xpTooltip.getChildren().add(progressBar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user