Simple xp tracker mode toggle (#789)
This commit is contained in:
@@ -28,6 +28,9 @@ package net.runelite.client.plugins.xptracker;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -79,12 +82,13 @@ class XpInfoBox extends JPanel
|
||||
/* The tracker's wrapping container */
|
||||
private final JPanel container = new JPanel();
|
||||
|
||||
/* Contains the skill icon and the stats panel */
|
||||
private final JPanel headerPanel = new JPanel();
|
||||
/* Contains the skill icon */
|
||||
private final JPanel skillWrapper = new JPanel();
|
||||
|
||||
/* Contains all the skill information (exp gained, per hour, etc) */
|
||||
private final JPanel statsPanel = new JPanel();
|
||||
|
||||
private final JPanel progressWrapper = new JPanel();
|
||||
private final ProgressBar progressBar = new ProgressBar();
|
||||
|
||||
private final JLabel expGained = new JLabel();
|
||||
@@ -98,6 +102,14 @@ class XpInfoBox extends JPanel
|
||||
|
||||
private boolean paused = false;
|
||||
|
||||
private Style style = Style.FULL;
|
||||
|
||||
private enum Style
|
||||
{
|
||||
FULL,
|
||||
SIMPLE
|
||||
}
|
||||
|
||||
XpInfoBox(XpTrackerPlugin xpTrackerPlugin, XpTrackerConfig xpTrackerConfig, Client client, JPanel panel, Skill skill, SkillIconManager iconManager)
|
||||
{
|
||||
this.xpTrackerConfig = xpTrackerConfig;
|
||||
@@ -134,6 +146,10 @@ class XpInfoBox extends JPanel
|
||||
popupMenu.add(pauseSkill);
|
||||
popupMenu.add(canvasItem);
|
||||
|
||||
skillWrapper.setBackground(ColorScheme.DARKER_GRAY_COLOR);
|
||||
skillWrapper.setLayout(new BorderLayout());
|
||||
skillWrapper.setBorder(new EmptyBorder(0, 5, 0, 0));
|
||||
|
||||
canvasItem.addActionListener(e ->
|
||||
{
|
||||
if (canvasItem.getText().equals(REMOVE_STATE))
|
||||
@@ -151,14 +167,13 @@ class XpInfoBox extends JPanel
|
||||
JLabel skillIcon = new JLabel(new ImageIcon(iconManager.getSkillImage(skill)));
|
||||
skillIcon.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
skillIcon.setVerticalAlignment(SwingConstants.CENTER);
|
||||
skillIcon.setPreferredSize(new Dimension(35, 35));
|
||||
skillIcon.setPreferredSize(new Dimension(30, 30));
|
||||
|
||||
headerPanel.setBackground(ColorScheme.DARKER_GRAY_COLOR);
|
||||
headerPanel.setLayout(new BorderLayout());
|
||||
skillWrapper.add(skillIcon, BorderLayout.NORTH);
|
||||
|
||||
statsPanel.setLayout(new DynamicGridLayout(2, 2));
|
||||
statsPanel.setBackground(ColorScheme.DARKER_GRAY_COLOR);
|
||||
statsPanel.setBorder(new EmptyBorder(9, 2, 9, 2));
|
||||
statsPanel.setBorder(new EmptyBorder(6, 5, 0, 2));
|
||||
|
||||
expGained.setFont(FontManager.getRunescapeSmallFont());
|
||||
expHour.setFont(FontManager.getRunescapeSmallFont());
|
||||
@@ -170,13 +185,8 @@ class XpInfoBox extends JPanel
|
||||
statsPanel.add(expHour);
|
||||
statsPanel.add(actionsLeft);
|
||||
|
||||
headerPanel.add(skillIcon, BorderLayout.WEST);
|
||||
headerPanel.add(statsPanel, BorderLayout.CENTER);
|
||||
|
||||
JPanel progressWrapper = new JPanel();
|
||||
progressWrapper.setBackground(ColorScheme.DARKER_GRAY_COLOR);
|
||||
progressWrapper.setLayout(new BorderLayout());
|
||||
progressWrapper.setBorder(new EmptyBorder(0, 7, 7, 7));
|
||||
|
||||
progressBar.setMaximumValue(100);
|
||||
progressBar.setBackground(new Color(61, 56, 49));
|
||||
@@ -185,15 +195,48 @@ class XpInfoBox extends JPanel
|
||||
|
||||
progressWrapper.add(progressBar, BorderLayout.NORTH);
|
||||
|
||||
container.add(headerPanel, BorderLayout.NORTH);
|
||||
container.add(progressWrapper, BorderLayout.SOUTH);
|
||||
|
||||
container.setComponentPopupMenu(popupMenu);
|
||||
progressBar.setComponentPopupMenu(popupMenu);
|
||||
|
||||
MouseListener mouseListener = new MouseAdapter()
|
||||
{
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e)
|
||||
{
|
||||
if (SwingUtilities.isLeftMouseButton(e))
|
||||
{
|
||||
toggleStyle();
|
||||
}
|
||||
}
|
||||
};
|
||||
container.addMouseListener(mouseListener);
|
||||
progressBar.addMouseListener(mouseListener);
|
||||
|
||||
add(container, BorderLayout.NORTH);
|
||||
}
|
||||
|
||||
void setStyle(Style style)
|
||||
{
|
||||
container.removeAll();
|
||||
|
||||
if (style == Style.SIMPLE)
|
||||
{
|
||||
progressWrapper.setBorder(new EmptyBorder(7, 7, 7, 7));
|
||||
container.add(skillWrapper, BorderLayout.WEST);
|
||||
container.add(progressWrapper, BorderLayout.CENTER);
|
||||
}
|
||||
else
|
||||
{
|
||||
progressWrapper.setBorder(new EmptyBorder(4, 7, 7, 7));
|
||||
container.add(skillWrapper, BorderLayout.WEST);
|
||||
container.add(statsPanel, BorderLayout.CENTER);
|
||||
container.add(progressWrapper, BorderLayout.SOUTH);
|
||||
}
|
||||
|
||||
panel.revalidate();
|
||||
this.style = style;
|
||||
}
|
||||
|
||||
void reset()
|
||||
{
|
||||
canvasItem.setText(ADD_STATE);
|
||||
@@ -214,7 +257,7 @@ class XpInfoBox extends JPanel
|
||||
if (getParent() != panel)
|
||||
{
|
||||
panel.add(this);
|
||||
panel.revalidate();
|
||||
setStyle(style);
|
||||
}
|
||||
|
||||
paused = skillPaused;
|
||||
@@ -284,6 +327,18 @@ class XpInfoBox extends JPanel
|
||||
expHour.setText(htmlLabel("XP/Hour: ", xpSnapshotSingle.getXpPerHour()));
|
||||
}
|
||||
|
||||
private void toggleStyle()
|
||||
{
|
||||
if (style == Style.FULL)
|
||||
{
|
||||
setStyle(Style.SIMPLE);
|
||||
}
|
||||
else
|
||||
{
|
||||
setStyle(Style.FULL);
|
||||
}
|
||||
}
|
||||
|
||||
static String htmlLabel(String key, int value)
|
||||
{
|
||||
String valueStr = StackFormatter.quantityToRSDecimalStack(value, true);
|
||||
|
||||
Reference in New Issue
Block a user