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 DecimalFormat XP_FORMAT = new DecimalFormat("#.#");
|
||||
|
||||
static SpriteManager spriteManager;
|
||||
static ItemManager itemManager;
|
||||
|
||||
private Client client;
|
||||
private SkillData skillData;
|
||||
private List<UIActionSlot> uiActionSlots = new ArrayList<>();
|
||||
private UICalculatorInputArea uiInput;
|
||||
|
||||
private CacheSkillData cacheSkillData = new CacheSkillData();
|
||||
|
||||
private UICombinedActionSlot combinedActionSlot = new UICombinedActionSlot();
|
||||
private ArrayList<UIActionSlot> combinedActionSlots = new ArrayList<>();
|
||||
private final UICalculatorInputArea uiInput;
|
||||
private final Client client;
|
||||
private final SpriteManager spriteManager;
|
||||
private final ItemManager itemManager;
|
||||
private final List<UIActionSlot> uiActionSlots = new ArrayList<>();
|
||||
private final CacheSkillData cacheSkillData = new CacheSkillData();
|
||||
private final UICombinedActionSlot combinedActionSlot;
|
||||
private final ArrayList<UIActionSlot> combinedActionSlots = new ArrayList<>();
|
||||
private final List<JCheckBox> bonusCheckBoxes = new ArrayList<>();
|
||||
|
||||
private SkillData skillData;
|
||||
private int currentLevel = 1;
|
||||
private int currentXP = Experience.getXpForLevel(currentLevel);
|
||||
private int targetLevel = currentLevel + 1;
|
||||
private int targetXP = Experience.getXpForLevel(targetLevel);
|
||||
private float xpFactor = 1.0f;
|
||||
|
||||
SkillCalculator(Client client, UICalculatorInputArea uiInput)
|
||||
SkillCalculator(Client client, UICalculatorInputArea uiInput, SpriteManager spriteManager, ItemManager itemManager)
|
||||
{
|
||||
this.client = client;
|
||||
this.uiInput = uiInput;
|
||||
this.spriteManager = spriteManager;
|
||||
this.itemManager = itemManager;
|
||||
|
||||
combinedActionSlot = new UICombinedActionSlot(spriteManager);
|
||||
|
||||
setLayout(new DynamicGridLayout(0, 1, 0, 5));
|
||||
|
||||
// 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();
|
||||
uiInput.uiFieldTargetLevel.requestFocusInWindow();
|
||||
uiInput.getUiFieldTargetLevel().requestFocusInWindow();
|
||||
});
|
||||
|
||||
uiInput.uiFieldCurrentXP.addActionListener(e ->
|
||||
uiInput.getUiFieldCurrentXP().addActionListener(e ->
|
||||
{
|
||||
onFieldCurrentXPUpdated();
|
||||
uiInput.uiFieldTargetXP.requestFocusInWindow();
|
||||
uiInput.getUiFieldTargetXP().requestFocusInWindow();
|
||||
});
|
||||
|
||||
uiInput.uiFieldTargetLevel.addActionListener(e -> onFieldTargetLevelUpdated());
|
||||
uiInput.uiFieldTargetXP.addActionListener(e -> onFieldTargetXPUpdated());
|
||||
uiInput.getUiFieldTargetLevel().addActionListener(e -> onFieldTargetLevelUpdated());
|
||||
uiInput.getUiFieldTargetXP().addActionListener(e -> onFieldTargetXPUpdated());
|
||||
}
|
||||
|
||||
void openCalculator(CalculatorType calculatorType)
|
||||
@@ -238,7 +239,18 @@ class SkillCalculator extends JPanel
|
||||
// Create new components for the action slots.
|
||||
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.
|
||||
add(slot); // Add component to the panel.
|
||||
|
||||
|
||||
@@ -33,7 +33,9 @@ import javax.swing.ImageIcon;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.client.game.ItemManager;
|
||||
import net.runelite.client.game.SkillIconManager;
|
||||
import net.runelite.client.game.SpriteManager;
|
||||
import net.runelite.client.ui.ColorScheme;
|
||||
import net.runelite.client.ui.PluginPanel;
|
||||
import net.runelite.client.ui.components.materialtabs.MaterialTab;
|
||||
@@ -45,7 +47,7 @@ class SkillCalculatorPanel extends PluginPanel
|
||||
private final SkillIconManager iconManager;
|
||||
private final MaterialTabGroup tabGroup;
|
||||
|
||||
SkillCalculatorPanel(SkillIconManager iconManager, Client client)
|
||||
SkillCalculatorPanel(SkillIconManager iconManager, Client client, SpriteManager spriteManager, ItemManager itemManager)
|
||||
{
|
||||
super();
|
||||
getScrollPane().setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
|
||||
@@ -69,7 +71,7 @@ class SkillCalculatorPanel extends PluginPanel
|
||||
final UICalculatorInputArea uiInput = new UICalculatorInputArea();
|
||||
uiInput.setBorder(new EmptyBorder(15, 0, 15, 0));
|
||||
uiInput.setBackground(ColorScheme.DARK_GRAY_COLOR);
|
||||
uiCalculator = new SkillCalculator(client, uiInput);
|
||||
uiCalculator = new SkillCalculator(client, uiInput, spriteManager, itemManager);
|
||||
|
||||
add(tabGroup, c);
|
||||
c.gridy++;
|
||||
|
||||
@@ -33,9 +33,8 @@ import net.runelite.client.game.SkillIconManager;
|
||||
import net.runelite.client.game.SpriteManager;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
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.NavigationButton;
|
||||
import net.runelite.client.util.ImageUtil;
|
||||
|
||||
@PluginDescriptor(
|
||||
@@ -45,9 +44,6 @@ import net.runelite.client.util.ImageUtil;
|
||||
)
|
||||
public class SkillCalculatorPlugin extends Plugin
|
||||
{
|
||||
@Inject
|
||||
private ClientUI ui;
|
||||
|
||||
@Inject
|
||||
private Client client;
|
||||
|
||||
@@ -64,23 +60,20 @@ public class SkillCalculatorPlugin extends Plugin
|
||||
private ClientToolbar clientToolbar;
|
||||
|
||||
private NavigationButton uiNavigationButton;
|
||||
private SkillCalculatorPanel uiPanel;
|
||||
|
||||
@Override
|
||||
protected void startUp() throws Exception
|
||||
{
|
||||
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()
|
||||
.tooltip("Skill Calculator")
|
||||
.icon(icon)
|
||||
.priority(6)
|
||||
.panel(uiPanel)
|
||||
.build();
|
||||
|
||||
clientToolbar.addNavigation(uiNavigationButton);
|
||||
}
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ class UIActionSlot extends JPanel
|
||||
@Setter(AccessLevel.PACKAGE)
|
||||
private double value = 0;
|
||||
|
||||
UIActionSlot(SkillDataEntry action)
|
||||
UIActionSlot(SkillDataEntry action, JLabel uiIcon)
|
||||
{
|
||||
this.action = action;
|
||||
|
||||
@@ -112,14 +112,6 @@ class UIActionSlot extends JPanel
|
||||
};
|
||||
|
||||
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.setMaximumSize(ICON_SIZE);
|
||||
uiIcon.setPreferredSize(ICON_SIZE);
|
||||
|
||||
@@ -32,16 +32,18 @@ import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import lombok.Getter;
|
||||
import net.runelite.client.ui.ColorScheme;
|
||||
import net.runelite.client.ui.FontManager;
|
||||
import net.runelite.client.ui.components.FlatTextField;
|
||||
|
||||
@Getter
|
||||
class UICalculatorInputArea extends JPanel
|
||||
{
|
||||
JTextField uiFieldCurrentLevel;
|
||||
JTextField uiFieldCurrentXP;
|
||||
JTextField uiFieldTargetLevel;
|
||||
JTextField uiFieldTargetXP;
|
||||
private final JTextField uiFieldCurrentLevel;
|
||||
private final JTextField uiFieldCurrentXP;
|
||||
private final JTextField uiFieldTargetLevel;
|
||||
private final JTextField uiFieldTargetXP;
|
||||
|
||||
UICalculatorInputArea()
|
||||
{
|
||||
|
||||
@@ -34,18 +34,18 @@ import javax.swing.BorderFactory;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import net.runelite.client.game.SpriteManager;
|
||||
import net.runelite.client.ui.ColorScheme;
|
||||
import net.runelite.client.ui.FontManager;
|
||||
import net.runelite.client.ui.components.shadowlabel.JShadowedLabel;
|
||||
|
||||
class UICombinedActionSlot extends JPanel
|
||||
{
|
||||
|
||||
private JShadowedLabel uiLabelActions;
|
||||
private JShadowedLabel uiLabelTitle;
|
||||
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());
|
||||
setBackground(ColorScheme.DARKER_GRAY_COLOR);
|
||||
@@ -53,7 +53,7 @@ class UICombinedActionSlot extends JPanel
|
||||
|
||||
JLabel uiIcon = new JLabel();
|
||||
uiIcon.setBorder(new EmptyBorder(0, 0, 0, 5));
|
||||
SkillCalculator.spriteManager.addSpriteTo(uiIcon, 582, 0);
|
||||
spriteManager.addSpriteTo(uiIcon, 582, 0);
|
||||
|
||||
uiIcon.setMinimumSize(ICON_SIZE);
|
||||
uiIcon.setMaximumSize(ICON_SIZE);
|
||||
|
||||
Reference in New Issue
Block a user