Cleanup skill calculator
Remove terrible code Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
@@ -55,48 +55,49 @@ class SkillCalculator extends JPanel
|
|||||||
private static final int MAX_XP = 200_000_000;
|
private static final int MAX_XP = 200_000_000;
|
||||||
private static final DecimalFormat XP_FORMAT = new DecimalFormat("#.#");
|
private static final DecimalFormat XP_FORMAT = new DecimalFormat("#.#");
|
||||||
|
|
||||||
static SpriteManager spriteManager;
|
private final UICalculatorInputArea uiInput;
|
||||||
static ItemManager itemManager;
|
private final Client client;
|
||||||
|
private final SpriteManager spriteManager;
|
||||||
private Client client;
|
private final ItemManager itemManager;
|
||||||
private SkillData skillData;
|
private final List<UIActionSlot> uiActionSlots = new ArrayList<>();
|
||||||
private List<UIActionSlot> uiActionSlots = new ArrayList<>();
|
private final CacheSkillData cacheSkillData = new CacheSkillData();
|
||||||
private UICalculatorInputArea uiInput;
|
private final UICombinedActionSlot combinedActionSlot;
|
||||||
|
private final ArrayList<UIActionSlot> combinedActionSlots = new ArrayList<>();
|
||||||
private CacheSkillData cacheSkillData = new CacheSkillData();
|
|
||||||
|
|
||||||
private UICombinedActionSlot combinedActionSlot = new UICombinedActionSlot();
|
|
||||||
private ArrayList<UIActionSlot> combinedActionSlots = new ArrayList<>();
|
|
||||||
private final List<JCheckBox> bonusCheckBoxes = new ArrayList<>();
|
private final List<JCheckBox> bonusCheckBoxes = new ArrayList<>();
|
||||||
|
|
||||||
|
private SkillData skillData;
|
||||||
private int currentLevel = 1;
|
private int currentLevel = 1;
|
||||||
private int currentXP = Experience.getXpForLevel(currentLevel);
|
private int currentXP = Experience.getXpForLevel(currentLevel);
|
||||||
private int targetLevel = currentLevel + 1;
|
private int targetLevel = currentLevel + 1;
|
||||||
private int targetXP = Experience.getXpForLevel(targetLevel);
|
private int targetXP = Experience.getXpForLevel(targetLevel);
|
||||||
private float xpFactor = 1.0f;
|
private float xpFactor = 1.0f;
|
||||||
|
|
||||||
SkillCalculator(Client client, UICalculatorInputArea uiInput)
|
SkillCalculator(Client client, UICalculatorInputArea uiInput, SpriteManager spriteManager, ItemManager itemManager)
|
||||||
{
|
{
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.uiInput = uiInput;
|
this.uiInput = uiInput;
|
||||||
|
this.spriteManager = spriteManager;
|
||||||
|
this.itemManager = itemManager;
|
||||||
|
|
||||||
|
combinedActionSlot = new UICombinedActionSlot(spriteManager);
|
||||||
|
|
||||||
setLayout(new DynamicGridLayout(0, 1, 0, 5));
|
setLayout(new DynamicGridLayout(0, 1, 0, 5));
|
||||||
|
|
||||||
// Register listeners on the input fields and then move on to the next related text field
|
// Register listeners on the input fields and then move on to the next related text field
|
||||||
uiInput.uiFieldCurrentLevel.addActionListener(e ->
|
uiInput.getUiFieldCurrentLevel().addActionListener(e ->
|
||||||
{
|
{
|
||||||
onFieldCurrentLevelUpdated();
|
onFieldCurrentLevelUpdated();
|
||||||
uiInput.uiFieldTargetLevel.requestFocusInWindow();
|
uiInput.getUiFieldTargetLevel().requestFocusInWindow();
|
||||||
});
|
});
|
||||||
|
|
||||||
uiInput.uiFieldCurrentXP.addActionListener(e ->
|
uiInput.getUiFieldCurrentXP().addActionListener(e ->
|
||||||
{
|
{
|
||||||
onFieldCurrentXPUpdated();
|
onFieldCurrentXPUpdated();
|
||||||
uiInput.uiFieldTargetXP.requestFocusInWindow();
|
uiInput.getUiFieldTargetXP().requestFocusInWindow();
|
||||||
});
|
});
|
||||||
|
|
||||||
uiInput.uiFieldTargetLevel.addActionListener(e -> onFieldTargetLevelUpdated());
|
uiInput.getUiFieldTargetLevel().addActionListener(e -> onFieldTargetLevelUpdated());
|
||||||
uiInput.uiFieldTargetXP.addActionListener(e -> onFieldTargetXPUpdated());
|
uiInput.getUiFieldTargetXP().addActionListener(e -> onFieldTargetXPUpdated());
|
||||||
}
|
}
|
||||||
|
|
||||||
void openCalculator(CalculatorType calculatorType)
|
void openCalculator(CalculatorType calculatorType)
|
||||||
@@ -238,7 +239,18 @@ class SkillCalculator extends JPanel
|
|||||||
// Create new components for the action slots.
|
// Create new components for the action slots.
|
||||||
for (SkillDataEntry action : skillData.getActions())
|
for (SkillDataEntry action : skillData.getActions())
|
||||||
{
|
{
|
||||||
UIActionSlot slot = new UIActionSlot(action);
|
JLabel uiIcon = new JLabel();
|
||||||
|
|
||||||
|
if (action.getIcon() != null)
|
||||||
|
{
|
||||||
|
itemManager.getImage(action.getIcon()).addTo(uiIcon);
|
||||||
|
}
|
||||||
|
else if (action.getSprite() != null)
|
||||||
|
{
|
||||||
|
spriteManager.addSpriteTo(uiIcon, action.getSprite(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
UIActionSlot slot = new UIActionSlot(action, uiIcon);
|
||||||
uiActionSlots.add(slot); // Keep our own reference.
|
uiActionSlots.add(slot); // Keep our own reference.
|
||||||
add(slot); // Add component to the panel.
|
add(slot); // Add component to the panel.
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,9 @@ import javax.swing.ImageIcon;
|
|||||||
import javax.swing.JScrollPane;
|
import javax.swing.JScrollPane;
|
||||||
import javax.swing.border.EmptyBorder;
|
import javax.swing.border.EmptyBorder;
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
|
import net.runelite.client.game.ItemManager;
|
||||||
import net.runelite.client.game.SkillIconManager;
|
import net.runelite.client.game.SkillIconManager;
|
||||||
|
import net.runelite.client.game.SpriteManager;
|
||||||
import net.runelite.client.ui.ColorScheme;
|
import net.runelite.client.ui.ColorScheme;
|
||||||
import net.runelite.client.ui.PluginPanel;
|
import net.runelite.client.ui.PluginPanel;
|
||||||
import net.runelite.client.ui.components.materialtabs.MaterialTab;
|
import net.runelite.client.ui.components.materialtabs.MaterialTab;
|
||||||
@@ -45,7 +47,7 @@ class SkillCalculatorPanel extends PluginPanel
|
|||||||
private final SkillIconManager iconManager;
|
private final SkillIconManager iconManager;
|
||||||
private final MaterialTabGroup tabGroup;
|
private final MaterialTabGroup tabGroup;
|
||||||
|
|
||||||
SkillCalculatorPanel(SkillIconManager iconManager, Client client)
|
SkillCalculatorPanel(SkillIconManager iconManager, Client client, SpriteManager spriteManager, ItemManager itemManager)
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
getScrollPane().setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
|
getScrollPane().setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
|
||||||
@@ -69,7 +71,7 @@ class SkillCalculatorPanel extends PluginPanel
|
|||||||
final UICalculatorInputArea uiInput = new UICalculatorInputArea();
|
final UICalculatorInputArea uiInput = new UICalculatorInputArea();
|
||||||
uiInput.setBorder(new EmptyBorder(15, 0, 15, 0));
|
uiInput.setBorder(new EmptyBorder(15, 0, 15, 0));
|
||||||
uiInput.setBackground(ColorScheme.DARK_GRAY_COLOR);
|
uiInput.setBackground(ColorScheme.DARK_GRAY_COLOR);
|
||||||
uiCalculator = new SkillCalculator(client, uiInput);
|
uiCalculator = new SkillCalculator(client, uiInput, spriteManager, itemManager);
|
||||||
|
|
||||||
add(tabGroup, c);
|
add(tabGroup, c);
|
||||||
c.gridy++;
|
c.gridy++;
|
||||||
|
|||||||
@@ -33,9 +33,8 @@ import net.runelite.client.game.SkillIconManager;
|
|||||||
import net.runelite.client.game.SpriteManager;
|
import net.runelite.client.game.SpriteManager;
|
||||||
import net.runelite.client.plugins.Plugin;
|
import net.runelite.client.plugins.Plugin;
|
||||||
import net.runelite.client.plugins.PluginDescriptor;
|
import net.runelite.client.plugins.PluginDescriptor;
|
||||||
import net.runelite.client.ui.ClientUI;
|
|
||||||
import net.runelite.client.ui.NavigationButton;
|
|
||||||
import net.runelite.client.ui.ClientToolbar;
|
import net.runelite.client.ui.ClientToolbar;
|
||||||
|
import net.runelite.client.ui.NavigationButton;
|
||||||
import net.runelite.client.util.ImageUtil;
|
import net.runelite.client.util.ImageUtil;
|
||||||
|
|
||||||
@PluginDescriptor(
|
@PluginDescriptor(
|
||||||
@@ -45,9 +44,6 @@ import net.runelite.client.util.ImageUtil;
|
|||||||
)
|
)
|
||||||
public class SkillCalculatorPlugin extends Plugin
|
public class SkillCalculatorPlugin extends Plugin
|
||||||
{
|
{
|
||||||
@Inject
|
|
||||||
private ClientUI ui;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private Client client;
|
private Client client;
|
||||||
|
|
||||||
@@ -64,23 +60,20 @@ public class SkillCalculatorPlugin extends Plugin
|
|||||||
private ClientToolbar clientToolbar;
|
private ClientToolbar clientToolbar;
|
||||||
|
|
||||||
private NavigationButton uiNavigationButton;
|
private NavigationButton uiNavigationButton;
|
||||||
private SkillCalculatorPanel uiPanel;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void startUp() throws Exception
|
protected void startUp() throws Exception
|
||||||
{
|
{
|
||||||
final BufferedImage icon = ImageUtil.getResourceStreamFromClass(getClass(), "calc.png");
|
final BufferedImage icon = ImageUtil.getResourceStreamFromClass(getClass(), "calc.png");
|
||||||
|
final SkillCalculatorPanel uiPanel = new SkillCalculatorPanel(skillIconManager, client, spriteManager, itemManager);
|
||||||
|
|
||||||
SkillCalculator.spriteManager = spriteManager;
|
|
||||||
SkillCalculator.itemManager = itemManager;
|
|
||||||
|
|
||||||
uiPanel = new SkillCalculatorPanel(skillIconManager, client);
|
|
||||||
uiNavigationButton = NavigationButton.builder()
|
uiNavigationButton = NavigationButton.builder()
|
||||||
.tooltip("Skill Calculator")
|
.tooltip("Skill Calculator")
|
||||||
.icon(icon)
|
.icon(icon)
|
||||||
.priority(6)
|
.priority(6)
|
||||||
.panel(uiPanel)
|
.panel(uiPanel)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
clientToolbar.addNavigation(uiNavigationButton);
|
clientToolbar.addNavigation(uiNavigationButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ class UIActionSlot extends JPanel
|
|||||||
@Setter(AccessLevel.PACKAGE)
|
@Setter(AccessLevel.PACKAGE)
|
||||||
private double value = 0;
|
private double value = 0;
|
||||||
|
|
||||||
UIActionSlot(SkillDataEntry action)
|
UIActionSlot(SkillDataEntry action, JLabel uiIcon)
|
||||||
{
|
{
|
||||||
this.action = action;
|
this.action = action;
|
||||||
|
|
||||||
@@ -112,14 +112,6 @@ class UIActionSlot extends JPanel
|
|||||||
};
|
};
|
||||||
|
|
||||||
addMouseListener(hoverListener);
|
addMouseListener(hoverListener);
|
||||||
|
|
||||||
JLabel uiIcon = new JLabel();
|
|
||||||
|
|
||||||
if (action.getIcon() != null)
|
|
||||||
SkillCalculator.itemManager.getImage(action.getIcon()).addTo(uiIcon);
|
|
||||||
else if (action.getSprite() != null)
|
|
||||||
SkillCalculator.spriteManager.addSpriteTo(uiIcon, action.getSprite(), 0);
|
|
||||||
|
|
||||||
uiIcon.setMinimumSize(ICON_SIZE);
|
uiIcon.setMinimumSize(ICON_SIZE);
|
||||||
uiIcon.setMaximumSize(ICON_SIZE);
|
uiIcon.setMaximumSize(ICON_SIZE);
|
||||||
uiIcon.setPreferredSize(ICON_SIZE);
|
uiIcon.setPreferredSize(ICON_SIZE);
|
||||||
|
|||||||
@@ -32,16 +32,18 @@ import javax.swing.JLabel;
|
|||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JTextField;
|
import javax.swing.JTextField;
|
||||||
import javax.swing.border.EmptyBorder;
|
import javax.swing.border.EmptyBorder;
|
||||||
|
import lombok.Getter;
|
||||||
import net.runelite.client.ui.ColorScheme;
|
import net.runelite.client.ui.ColorScheme;
|
||||||
import net.runelite.client.ui.FontManager;
|
import net.runelite.client.ui.FontManager;
|
||||||
import net.runelite.client.ui.components.FlatTextField;
|
import net.runelite.client.ui.components.FlatTextField;
|
||||||
|
|
||||||
|
@Getter
|
||||||
class UICalculatorInputArea extends JPanel
|
class UICalculatorInputArea extends JPanel
|
||||||
{
|
{
|
||||||
JTextField uiFieldCurrentLevel;
|
private final JTextField uiFieldCurrentLevel;
|
||||||
JTextField uiFieldCurrentXP;
|
private final JTextField uiFieldCurrentXP;
|
||||||
JTextField uiFieldTargetLevel;
|
private final JTextField uiFieldTargetLevel;
|
||||||
JTextField uiFieldTargetXP;
|
private final JTextField uiFieldTargetXP;
|
||||||
|
|
||||||
UICalculatorInputArea()
|
UICalculatorInputArea()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -34,18 +34,18 @@ import javax.swing.BorderFactory;
|
|||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.border.EmptyBorder;
|
import javax.swing.border.EmptyBorder;
|
||||||
|
import net.runelite.client.game.SpriteManager;
|
||||||
import net.runelite.client.ui.ColorScheme;
|
import net.runelite.client.ui.ColorScheme;
|
||||||
import net.runelite.client.ui.FontManager;
|
import net.runelite.client.ui.FontManager;
|
||||||
import net.runelite.client.ui.components.shadowlabel.JShadowedLabel;
|
import net.runelite.client.ui.components.shadowlabel.JShadowedLabel;
|
||||||
|
|
||||||
class UICombinedActionSlot extends JPanel
|
class UICombinedActionSlot extends JPanel
|
||||||
{
|
{
|
||||||
|
|
||||||
private JShadowedLabel uiLabelActions;
|
|
||||||
private JShadowedLabel uiLabelTitle;
|
|
||||||
private static final Dimension ICON_SIZE = new Dimension(32, 32);
|
private static final Dimension ICON_SIZE = new Dimension(32, 32);
|
||||||
|
private final JShadowedLabel uiLabelActions;
|
||||||
|
private final JShadowedLabel uiLabelTitle;
|
||||||
|
|
||||||
UICombinedActionSlot()
|
UICombinedActionSlot(SpriteManager spriteManager)
|
||||||
{
|
{
|
||||||
setLayout(new BorderLayout());
|
setLayout(new BorderLayout());
|
||||||
setBackground(ColorScheme.DARKER_GRAY_COLOR);
|
setBackground(ColorScheme.DARKER_GRAY_COLOR);
|
||||||
@@ -53,7 +53,7 @@ class UICombinedActionSlot extends JPanel
|
|||||||
|
|
||||||
JLabel uiIcon = new JLabel();
|
JLabel uiIcon = new JLabel();
|
||||||
uiIcon.setBorder(new EmptyBorder(0, 0, 0, 5));
|
uiIcon.setBorder(new EmptyBorder(0, 0, 0, 5));
|
||||||
SkillCalculator.spriteManager.addSpriteTo(uiIcon, 582, 0);
|
spriteManager.addSpriteTo(uiIcon, 582, 0);
|
||||||
|
|
||||||
uiIcon.setMinimumSize(ICON_SIZE);
|
uiIcon.setMinimumSize(ICON_SIZE);
|
||||||
uiIcon.setMaximumSize(ICON_SIZE);
|
uiIcon.setMaximumSize(ICON_SIZE);
|
||||||
|
|||||||
Reference in New Issue
Block a user