diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/skillcalculator/SkillCalculator.java b/runelite-client/src/main/java/net/runelite/client/plugins/skillcalculator/SkillCalculator.java index 5218a1ac44..2caa3b78e5 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/skillcalculator/SkillCalculator.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/skillcalculator/SkillCalculator.java @@ -1,5 +1,6 @@ /* * Copyright (c) 2018, Kruithne + * Copyright (c) 2018, Psikoi * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -25,6 +26,8 @@ package net.runelite.client.plugins.skillcalculator; import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dimension; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.text.DecimalFormat; @@ -32,6 +35,7 @@ import java.text.NumberFormat; import java.util.ArrayList; import java.util.List; import javax.swing.BorderFactory; +import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JCheckBox; import javax.swing.JLabel; @@ -43,6 +47,8 @@ import net.runelite.client.game.SpriteManager; import net.runelite.client.plugins.skillcalculator.beans.SkillData; import net.runelite.client.plugins.skillcalculator.beans.SkillDataBonus; import net.runelite.client.plugins.skillcalculator.beans.SkillDataEntry; +import net.runelite.client.ui.ColorScheme; +import net.runelite.client.ui.FontManager; class SkillCalculator extends JPanel { @@ -75,11 +81,20 @@ class SkillCalculator extends JPanel this.uiInput = uiInput; setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); - setBorder(BorderFactory.createLineBorder(getBackground().brighter())); - // Register listeners on the input fields.. - uiInput.uiFieldCurrentLevel.addActionListener(e -> onFieldCurrentLevelUpdated()); - uiInput.uiFieldCurrentXP.addActionListener(e -> onFieldCurrentXPUpdated()); + // Register listeners on the input fields and then move on to the next related text field + uiInput.uiFieldCurrentLevel.addActionListener(e -> + { + onFieldCurrentLevelUpdated(); + uiInput.uiFieldTargetLevel.requestFocusInWindow(); + }); + + uiInput.uiFieldCurrentXP.addActionListener(e -> + { + onFieldCurrentXPUpdated(); + uiInput.uiFieldTargetXP.requestFocusInWindow(); + }); + uiInput.uiFieldTargetLevel.addActionListener(e -> onFieldTargetLevelUpdated()); uiInput.uiFieldTargetXP.addActionListener(e -> onFieldTargetXPUpdated()); } @@ -110,6 +125,8 @@ class SkillCalculator extends JPanel // Create action slots for the skill actions. renderActionSlots(); + add(Box.createRigidArea(new Dimension(0, 15))); + // Update the input fields. updateInputFields(); } @@ -142,7 +159,7 @@ class SkillCalculator extends JPanel if (neededXP > 0) actionCount = (int) Math.ceil(neededXP / xp); - combinedActionSlot.setText(formatXPActionString(xp, actionCount)); + combinedActionSlot.setText(formatXPActionString(xp, actionCount, "exp - ")); } private void clearCombinedSlots() @@ -163,15 +180,21 @@ class SkillCalculator extends JPanel JLabel uiLabel = new JLabel(bonus.name); JCheckBox uiCheckbox = new JCheckBox(); - // Adding an empty 8-pixel border on the left gives us nice padding. - uiOption.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0)); + uiLabel.setForeground(Color.WHITE); + uiLabel.setFont(FontManager.getRunescapeSmallFont()); + + uiOption.setBorder(BorderFactory.createEmptyBorder(3, 7, 3, 0)); + uiOption.setBackground(ColorScheme.DARKER_GRAY_COLOR); // Adjust XP bonus depending on check-state of the boxes. uiCheckbox.addActionListener(e -> adjustXPBonus(uiCheckbox.isSelected(), bonus.value)); + uiCheckbox.setBackground(ColorScheme.MEDIUM_GRAY_COLOR); uiOption.add(uiLabel, BorderLayout.WEST); uiOption.add(uiCheckbox, BorderLayout.EAST); + add(uiOption); + add(Box.createRigidArea(new Dimension(0, 5))); } } } @@ -186,6 +209,8 @@ class SkillCalculator extends JPanel { UIActionSlot slot = new UIActionSlot(action); uiActionSlots.add(slot); // Keep our own reference. + + add(Box.createRigidArea(new Dimension(0, 5))); add(slot); // Add component to the panel. slot.addMouseListener(new MouseAdapter() @@ -223,15 +248,15 @@ class SkillCalculator extends JPanel if (neededXP > 0) actionCount = (int) Math.ceil(neededXP / xp); - slot.setText(formatXPActionString(xp, actionCount)); + slot.setText("Lvl. " + slot.action.level + " (" + formatXPActionString(xp, actionCount, "exp) - ")); slot.setAvailable(currentLevel >= slot.action.level); slot.value = xp; } } - private String formatXPActionString(double xp, int actionCount) + private String formatXPActionString(double xp, int actionCount, String expExpression) { - return XP_FORMAT.format(xp) + "xp - " + NumberFormat.getIntegerInstance().format(actionCount) + (actionCount > 1 ? " actions" : " action"); + return XP_FORMAT.format(xp) + expExpression + NumberFormat.getIntegerInstance().format(actionCount) + (actionCount > 1 ? " actions" : " action"); } private void updateInputFields() diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/skillcalculator/SkillCalculatorPanel.java b/runelite-client/src/main/java/net/runelite/client/plugins/skillcalculator/SkillCalculatorPanel.java index b0e520a33e..06b75a8417 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/skillcalculator/SkillCalculatorPanel.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/skillcalculator/SkillCalculatorPanel.java @@ -1,5 +1,6 @@ /* * Copyright (c) 2018, Kruithne + * Copyright (c) 2018, Psikoi * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -25,96 +26,108 @@ package net.runelite.client.plugins.skillcalculator; -import java.awt.Dimension; +import java.awt.Color; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; -import java.awt.Insets; -import java.awt.image.BufferedImage; -import javax.swing.BorderFactory; -import javax.swing.Box; -import javax.swing.BoxLayout; +import java.awt.GridLayout; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; import javax.swing.ImageIcon; -import javax.swing.JButton; -import javax.swing.JPanel; +import javax.swing.JLabel; +import javax.swing.JScrollPane; +import javax.swing.SwingConstants; +import javax.swing.border.EmptyBorder; import net.runelite.api.Client; import net.runelite.client.game.SkillIconManager; import net.runelite.client.ui.ColorScheme; import net.runelite.client.ui.PluginPanel; +import net.runelite.client.ui.components.materialtabs.MaterialTab; +import net.runelite.client.ui.components.materialtabs.MaterialTabGroup; class SkillCalculatorPanel extends PluginPanel { - private JButton activeButton; - private int uiButtonIndex = 0; private final SkillCalculator uiCalculator; private final SkillIconManager iconManager; - private final JPanel uiButtonGrid = new JPanel(); - private final GridBagLayout uiButtonGridLayout = new GridBagLayout(); - private final GridBagConstraints uiButtonGridConstraints = new GridBagConstraints(); + private final MaterialTabGroup tabGroup; + + private final MouseListener tabHoverListener; SkillCalculatorPanel(SkillIconManager iconManager, Client client) { super(); + getScrollPane().setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); + + tabHoverListener = new MouseAdapter() + { + @Override + public void mouseEntered(MouseEvent e) + { + MaterialTab tab = (MaterialTab) e.getSource(); + tab.setBackground(ColorScheme.DARKER_GRAY_HOVER_COLOR); + } + + @Override + public void mouseExited(MouseEvent e) + { + MaterialTab tab = (MaterialTab) e.getSource(); + tab.setBackground(ColorScheme.DARKER_GRAY_COLOR); + } + }; + this.iconManager = iconManager; - BoxLayout layout = new BoxLayout(this, BoxLayout.Y_AXIS); - setLayout(layout); + setBorder(new EmptyBorder(10, 10, 0, 10)); + setLayout(new GridBagLayout()); - uiButtonGridConstraints.fill = GridBagConstraints.BOTH; - uiButtonGridConstraints.weightx = 1; - uiButtonGridConstraints.ipady = 12; - uiButtonGridConstraints.insets = new Insets(2, 2, 2, 2); + GridBagConstraints c = new GridBagConstraints(); + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.gridx = 0; + c.gridy = 0; + + tabGroup = new MaterialTabGroup(); + tabGroup.setLayout(new GridLayout(0, 6, 7, 7)); - uiButtonGrid.setLayout(uiButtonGridLayout); - uiButtonGrid.setBackground(ColorScheme.DARK_GRAY_COLOR); - uiButtonGrid.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3)); addCalculatorButtons(); final UICalculatorInputArea uiInput = new UICalculatorInputArea(); + uiInput.setBorder(new EmptyBorder(15, 0, 15, 0)); uiInput.setBackground(ColorScheme.DARK_GRAY_COLOR); uiCalculator = new SkillCalculator(client, uiInput); - add(uiButtonGrid); - add(Box.createRigidArea(new Dimension(0, 8))); - add(uiInput); - add(Box.createRigidArea(new Dimension(0, 14))); - add(uiCalculator); + JLabel title = new JLabel("Skilling Calculator"); + title.setBorder(new EmptyBorder(0, 1, 8, 0)); + title.setForeground(Color.WHITE); + + add(title, c); + c.gridy++; + + add(tabGroup, c); + c.gridy++; + + add(uiInput, c); + c.gridy++; + + add(uiCalculator, c); + c.gridy++; } private void addCalculatorButtons() { for (CalculatorType calculatorType : CalculatorType.values()) { - final JButton uiButton = new JButton(); - final BufferedImage icon = iconManager.getSkillImage(calculatorType.getSkill()); - uiButton.addActionListener(e -> openCalculator(calculatorType, uiButton)); + MaterialTab tab = new MaterialTab("", tabGroup, null); + tab.setOpaque(true); + tab.setVerticalAlignment(SwingConstants.CENTER); + tab.setHorizontalAlignment(SwingConstants.CENTER); + tab.setBackground(ColorScheme.DARKER_GRAY_COLOR); + tab.setIcon(new ImageIcon(iconManager.getSkillImage(calculatorType.getSkill(), true))); + tab.setOnSelectEvent(() -> uiCalculator.openCalculator(calculatorType)); + tab.addMouseListener(tabHoverListener); - uiButton.setIcon(new ImageIcon(icon)); - uiButton.setToolTipText(calculatorType.getSkill().getName()); - uiButton.setFocusPainted(false); - - uiButtonGridConstraints.gridx = uiButtonIndex % 4; - uiButtonGridLayout.setConstraints(uiButton, uiButtonGridConstraints); - uiButtonGrid.add(uiButton); - uiButtonIndex++; + tabGroup.addTab(tab); } } - - private void openCalculator(CalculatorType calculatorType, JButton button) - { - // Remove highlight from existing button.. - if (activeButton != null) - activeButton.setSelected(false); - - // Set the new button as selected.. - button.setSelected(true); - activeButton = button; - - // Invoke the calculator component.. - uiCalculator.openCalculator(calculatorType); - - // Refresh rendering.. - revalidate(); - repaint(); - } } \ No newline at end of file diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/skillcalculator/UIActionSlot.java b/runelite-client/src/main/java/net/runelite/client/plugins/skillcalculator/UIActionSlot.java index 75abc211a7..e3939210e7 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/skillcalculator/UIActionSlot.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/skillcalculator/UIActionSlot.java @@ -1,5 +1,6 @@ /* * Copyright (c) 2018, Kruithne + * Copyright (c) 2018, Psikoi * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -29,15 +30,30 @@ import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.GridLayout; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; import javax.swing.BorderFactory; import javax.swing.JLabel; import javax.swing.JPanel; +import javax.swing.border.Border; +import javax.swing.border.CompoundBorder; +import javax.swing.border.EmptyBorder; import net.runelite.client.plugins.skillcalculator.beans.SkillDataEntry; +import net.runelite.client.ui.ColorScheme; import net.runelite.client.ui.FontManager; import net.runelite.client.ui.components.shadowlabel.JShadowedLabel; class UIActionSlot extends JPanel { + private static final Border GREEN_BORDER = new CompoundBorder( + BorderFactory.createMatteBorder(0, 4, 0, 0, (ColorScheme.PROGRESS_COMPLETE_COLOR).darker()), + BorderFactory.createEmptyBorder(7, 12, 7, 7)); + + private static final Border RED_BORDER = new CompoundBorder( + BorderFactory.createMatteBorder(0, 4, 0, 0, (ColorScheme.PROGRESS_ERROR_COLOR).darker()), + BorderFactory.createEmptyBorder(7, 12, 7, 7)); + SkillDataEntry action; private JShadowedLabel uiLabelActions; private static final Dimension ICON_SIZE = new Dimension(32, 32); @@ -52,11 +68,32 @@ class UIActionSlot extends JPanel { this.action = action; - BorderLayout layout = new BorderLayout(); - layout.setHgap(8); - setLayout(layout); + setLayout(new BorderLayout()); + setBorder(RED_BORDER); + setBackground(ColorScheme.DARKER_GRAY_COLOR); - setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); + MouseListener hoverListener = new MouseAdapter() + { + @Override + public void mouseEntered(MouseEvent mouseEvent) + { + if (!isSelected) + { + setBackground(ColorScheme.DARKER_GRAY_HOVER_COLOR); + } + } + + @Override + public void mouseExited(MouseEvent mouseEvent) + { + if (!isSelected) + { + updateBackground(); + } + } + }; + + addMouseListener(hoverListener); JLabel uiIcon = new JLabel(); @@ -69,17 +106,22 @@ class UIActionSlot extends JPanel uiIcon.setMaximumSize(ICON_SIZE); uiIcon.setPreferredSize(ICON_SIZE); uiIcon.setHorizontalAlignment(JLabel.CENTER); - add(uiIcon, BorderLayout.LINE_START); uiInfo = new JPanel(new GridLayout(2, 1)); + uiInfo.setBackground(ColorScheme.DARKER_GRAY_COLOR); + uiInfo.setBorder(new EmptyBorder(0, 5, 0, 0)); JShadowedLabel uiLabelName = new JShadowedLabel(action.name); - uiInfo.add(uiLabelName); + uiLabelName.setForeground(Color.WHITE); uiLabelActions = new JShadowedLabel("Unknown"); uiLabelActions.setFont(FontManager.getRunescapeSmallFont()); + uiLabelActions.setForeground(ColorScheme.LIGHT_GRAY_COLOR); + + uiInfo.add(uiLabelName); uiInfo.add(uiLabelActions); + add(uiIcon, BorderLayout.LINE_START); add(uiInfo, BorderLayout.CENTER); } @@ -102,11 +144,17 @@ class UIActionSlot extends JPanel private void updateBackground() { - if (isSelected) - this.setBackground(isAvailable ? Color.GREEN : Color.RED); - else - this.setBackground(isAvailable ? Color.GREEN.darker() : Color.RED.darker()); + setBorder(isAvailable ? GREEN_BORDER : RED_BORDER); + setBackground(isSelected ? ColorScheme.DARKER_GRAY_HOVER_COLOR.brighter() : ColorScheme.DARKER_GRAY_COLOR); + } - uiInfo.setBackground(getBackground()); + @Override + public void setBackground(Color color) + { + super.setBackground(color); + if (uiInfo != null) + { + uiInfo.setBackground(color); + } } } \ No newline at end of file diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/skillcalculator/UICalculatorInputArea.java b/runelite-client/src/main/java/net/runelite/client/plugins/skillcalculator/UICalculatorInputArea.java index c845cc522e..99a370001d 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/skillcalculator/UICalculatorInputArea.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/skillcalculator/UICalculatorInputArea.java @@ -1,5 +1,6 @@ /* * Copyright (c) 2018, Kruithne + * Copyright (c) 2018, Psikoi * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,21 +25,19 @@ */ package net.runelite.client.plugins.skillcalculator; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Insets; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.GridLayout; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; +import javax.swing.border.EmptyBorder; +import net.runelite.client.ui.ColorScheme; +import net.runelite.client.ui.FontManager; +import net.runelite.client.ui.components.FlatTextField; class UICalculatorInputArea extends JPanel { - private final GridBagLayout uiLayout; - private final GridBagConstraints uiConstraints; - - private int gridX = 0; - private int gridY = 0; - JTextField uiFieldCurrentLevel; JTextField uiFieldCurrentXP; JTextField uiFieldTargetLevel; @@ -46,15 +45,11 @@ class UICalculatorInputArea extends JPanel UICalculatorInputArea() { - uiLayout = new GridBagLayout(); - uiConstraints = new GridBagConstraints(); - uiConstraints.insets = new Insets(3, 9, 3, 9); - setLayout(uiLayout); - + setLayout(new GridLayout(2, 2, 7, 7)); uiFieldCurrentLevel = addComponent("Current Level"); - uiFieldCurrentXP = addComponent("Current XP"); + uiFieldCurrentXP = addComponent("Current Experience"); uiFieldTargetLevel = addComponent("Target Level"); - uiFieldTargetXP = addComponent("Target XP"); + uiFieldTargetXP = addComponent("Target Experience"); } int getCurrentLevelInput() @@ -116,26 +111,25 @@ class UICalculatorInputArea extends JPanel private JTextField addComponent(String label) { + final JPanel container = new JPanel(); + container.setLayout(new BorderLayout()); + final JLabel uiLabel = new JLabel(label); - final JTextField uiField = new JTextField(6); + final FlatTextField uiInput = new FlatTextField(); - uiConstraints.gridx = gridX; - uiConstraints.gridy = gridY; + uiInput.setBackground(ColorScheme.DARKER_GRAY_COLOR); + uiInput.setHoverBackgroundColor(ColorScheme.DARK_GRAY_HOVER_COLOR); + uiInput.setBorder(new EmptyBorder(5, 7, 5, 7)); - uiLayout.setConstraints(uiLabel, uiConstraints); - add(uiLabel); + uiLabel.setFont(FontManager.getRunescapeSmallFont()); + uiLabel.setBorder(new EmptyBorder(0, 0, 4, 0)); + uiLabel.setForeground(Color.WHITE); - uiConstraints.gridy++; - uiLayout.setConstraints(uiField, uiConstraints); - add(uiField); + container.add(uiLabel, BorderLayout.NORTH); + container.add(uiInput, BorderLayout.CENTER); - gridX++; - if (gridX % 2 == 0) - { - gridY += 2; - gridX = 0; - } + add(container); - return uiField; + return uiInput.getTextField(); } } \ No newline at end of file diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/skillcalculator/UICombinedActionSlot.java b/runelite-client/src/main/java/net/runelite/client/plugins/skillcalculator/UICombinedActionSlot.java index e09d566940..f8333bfb50 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/skillcalculator/UICombinedActionSlot.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/skillcalculator/UICombinedActionSlot.java @@ -1,5 +1,6 @@ /* * Copyright (c) 2018, Kruithne + * Copyright (c) 2018, Psikoi * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -32,6 +33,8 @@ import java.awt.GridLayout; import javax.swing.BorderFactory; import javax.swing.JLabel; import javax.swing.JPanel; +import javax.swing.border.EmptyBorder; +import net.runelite.client.ui.ColorScheme; import net.runelite.client.ui.FontManager; import net.runelite.client.ui.components.shadowlabel.JShadowedLabel; @@ -44,13 +47,12 @@ class UICombinedActionSlot extends JPanel UICombinedActionSlot() { - BorderLayout layout = new BorderLayout(); - layout.setHgap(8); - setLayout(layout); - - setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); + setLayout(new BorderLayout()); + setBackground(ColorScheme.DARKER_GRAY_COLOR); + setBorder(BorderFactory.createEmptyBorder(7, 7, 7, 7)); JLabel uiIcon = new JLabel(); + uiIcon.setBorder(new EmptyBorder(0, 0, 0, 5)); SkillCalculator.spriteManager.addSpriteTo(uiIcon, 582, 0); uiIcon.setMinimumSize(ICON_SIZE); @@ -60,16 +62,18 @@ class UICombinedActionSlot extends JPanel add(uiIcon, BorderLayout.LINE_START); JPanel uiInfo = new JPanel(new GridLayout(2, 1)); - uiInfo.setBackground(Color.ORANGE); + uiInfo.setBackground(ColorScheme.DARKER_GRAY_COLOR); uiLabelTitle = new JShadowedLabel("No Action Selected"); - uiInfo.add(uiLabelTitle); + uiLabelTitle.setForeground(Color.WHITE); uiLabelActions = new JShadowedLabel("Shift-click to select multiple"); uiLabelActions.setFont(FontManager.getRunescapeSmallFont()); + uiLabelActions.setForeground(ColorScheme.LIGHT_GRAY_COLOR); + + uiInfo.add(uiLabelTitle); uiInfo.add(uiLabelActions); - setBackground(Color.orange); add(uiInfo, BorderLayout.CENTER); } diff --git a/runelite-client/src/main/java/net/runelite/client/ui/ColorScheme.java b/runelite-client/src/main/java/net/runelite/client/ui/ColorScheme.java index bec0c4f052..8cee06d0ca 100644 --- a/runelite-client/src/main/java/net/runelite/client/ui/ColorScheme.java +++ b/runelite-client/src/main/java/net/runelite/client/ui/ColorScheme.java @@ -41,6 +41,8 @@ public class ColorScheme public static final Color DARK_GRAY_COLOR = new Color(40, 40, 40); public static final Color MEDIUM_GRAY_COLOR = new Color(77, 77, 77); public static final Color LIGHT_GRAY_COLOR = new Color(165, 165, 165); + + public static final Color DARKER_GRAY_HOVER_COLOR = new Color(60, 60 , 60); public static final Color DARK_GRAY_HOVER_COLOR = new Color(35, 35, 35); /* The color for the green progress bar (used in ge offers, farming tracker, etc)*/