Add ntermediate progress markers for xptracker plugin (#6895)

Closes #6863
This commit is contained in:
Jakob Ankarhem
2018-12-24 11:42:46 +01:00
committed by Tomas Slusny
parent b6406c30a5
commit 10a3c4139e
5 changed files with 55 additions and 5 deletions

View File

@@ -30,6 +30,8 @@ import java.awt.Color;
import java.awt.Dimension;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
@@ -88,10 +90,13 @@ class XpInfoBox extends JPanel
private final JLabel actionsLeft = new JLabel();
private final JMenuItem pauseSkill = new JMenuItem("Pause");
private final XpTrackerConfig xpTrackerConfig;
private boolean paused = false;
XpInfoBox(XpTrackerPlugin xpTrackerPlugin, Client client, JPanel panel, Skill skill, SkillIconManager iconManager) throws IOException
XpInfoBox(XpTrackerPlugin xpTrackerPlugin, XpTrackerConfig xpTrackerConfig, Client client, JPanel panel, Skill skill, SkillIconManager iconManager) throws IOException
{
this.xpTrackerConfig = xpTrackerConfig;
this.panel = panel;
this.skill = skill;
@@ -207,6 +212,24 @@ class XpInfoBox extends JPanel
? "200M"
: "Lvl. " + xpSnapshotSingle.getEndLevel());
// Add intermediate level positions to progressBar
final List<Double> positions = new ArrayList<>();
if (xpTrackerConfig.showIntermediateLevels() && xpSnapshotSingle.getEndLevel() - xpSnapshotSingle.getStartLevel() > 1)
{
for (int level = xpSnapshotSingle.getStartLevel() + 1; level < xpSnapshotSingle.getEndLevel(); level++)
{
double relativeStartExperience = Experience.getXpForLevel(level) - xpSnapshotSingle.getStartGoalXp();
double relativeEndExperience = xpSnapshotSingle.getEndGoalXp() - xpSnapshotSingle.getStartGoalXp();
positions.add(relativeStartExperience / relativeEndExperience);
}
progressBar.setPositions(positions);
}
else
{
progressBar.setPositions(positions);
}
progressBar.setToolTipText(String.format(
HTML_TOOL_TIP_TEMPLATE,
xpSnapshotSingle.getActionsInSession(),

View File

@@ -63,7 +63,7 @@ class XpPanel extends PluginPanel
/* This displays the "No exp gained" text */
private final PluginErrorPanel errorPanel = new PluginErrorPanel();
XpPanel(XpTrackerPlugin xpTrackerPlugin, Client client, SkillIconManager iconManager)
XpPanel(XpTrackerPlugin xpTrackerPlugin, XpTrackerConfig xpTrackerConfig, Client client, SkillIconManager iconManager)
{
super();
@@ -143,7 +143,7 @@ class XpPanel extends PluginPanel
{
break;
}
infoBoxes.put(skill, new XpInfoBox(xpTrackerPlugin, client, infoBoxPanel, skill, iconManager));
infoBoxes.put(skill, new XpInfoBox(xpTrackerPlugin, xpTrackerConfig, client, infoBoxPanel, skill, iconManager));
}
}
catch (IOException e)

View File

@@ -55,6 +55,17 @@ public interface XpTrackerConfig extends Config
@ConfigItem(
position = 2,
keyName = "intermediateLevelMarkers",
name = "Show intermediate level markers",
description = "Marks intermediate levels on the progressbar"
)
default boolean showIntermediateLevels()
{
return false;
}
@ConfigItem(
position = 3,
keyName = "pauseSkillAfter",
name = "Auto pause after",
description = "Configures how many minutes passes before pausing a skill while in game and there's no XP, 0 means disabled"

View File

@@ -118,7 +118,7 @@ public class XpTrackerPlugin extends Plugin
@Override
protected void startUp() throws Exception
{
xpPanel = new XpPanel(this, client, skillIconManager);
xpPanel = new XpPanel(this, xpTrackerConfig, client, skillIconManager);
final BufferedImage icon = ImageUtil.getResourceStreamFromClass(getClass(), "/skill_icons/overall.png");

View File

@@ -28,6 +28,8 @@ import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;
@@ -46,6 +48,9 @@ public class ProgressBar extends DimmableJPanel
@Setter
private int value;
@Setter
private List<Double> positions = new ArrayList<>();
private final JLabel leftLabel = new JShadowedLabel();
private final JLabel rightLabel = new JShadowedLabel();
private final JLabel centerLabel = new JShadowedLabel();
@@ -89,6 +94,17 @@ public class ProgressBar extends DimmableJPanel
super.paint(g);
g.setColor(getForeground());
g.fillRect(0, 0, topWidth, 16);
g.setColor(getForeground().darker());
for (final Double position : positions)
{
final int xCord = (int) (getSize().width * (position));
if (xCord > topWidth)
{
g.fillRect(xCord, 0, 1, 16);
}
}
super.paintComponents(g);
}
@@ -142,4 +158,4 @@ public class ProgressBar extends DimmableJPanel
return (value * 100) / maximumValue;
}
}
}