Merge pull request #3317 from Kruithne/skill-calculator

Skill Calculator: Orange indicator for actions that will become available before target.
This commit is contained in:
Adam
2018-05-27 18:42:23 -04:00
committed by GitHub
2 changed files with 61 additions and 24 deletions

View File

@@ -52,6 +52,12 @@ import net.runelite.client.ui.FontManager;
class SkillCalculator extends JPanel 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 Client client;
private SkillData skillData; private SkillData skillData;
private List<UIActionSlot> uiActionSlots = new ArrayList<>(); private List<UIActionSlot> uiActionSlots = new ArrayList<>();
@@ -59,9 +65,6 @@ class SkillCalculator extends JPanel
private CacheSkillData cacheSkillData = new CacheSkillData(); private CacheSkillData cacheSkillData = new CacheSkillData();
static SpriteManager spriteManager;
static ItemManager itemManager;
private UICombinedActionSlot combinedActionSlot = new UICombinedActionSlot(); private UICombinedActionSlot combinedActionSlot = new UICombinedActionSlot();
private ArrayList<UIActionSlot> combinedActionSlots = new ArrayList<>(); private ArrayList<UIActionSlot> combinedActionSlots = new ArrayList<>();
@@ -71,10 +74,6 @@ class SkillCalculator extends JPanel
private int targetXP = Experience.getXpForLevel(targetLevel); private int targetXP = Experience.getXpForLevel(targetLevel);
private float xpFactor = 1.0f; private float xpFactor = 1.0f;
private static int MAX_XP = Experience.getXpForLevel(Experience.MAX_VIRT_LEVEL);
private static DecimalFormat XP_FORMAT = new DecimalFormat("#.#");
SkillCalculator(Client client, UICalculatorInputArea uiInput) SkillCalculator(Client client, UICalculatorInputArea uiInput)
{ {
this.client = client; this.client = client;
@@ -152,7 +151,7 @@ class SkillCalculator extends JPanel
double xp = 0; double xp = 0;
for (UIActionSlot slot : combinedActionSlots) for (UIActionSlot slot : combinedActionSlots)
xp += slot.value; xp += slot.getValue();
if (neededXP > 0) if (neededXP > 0)
actionCount = (int) Math.ceil(neededXP / xp); actionCount = (int) Math.ceil(neededXP / xp);
@@ -217,12 +216,12 @@ class SkillCalculator extends JPanel
if (!e.isShiftDown()) if (!e.isShiftDown())
clearCombinedSlots(); clearCombinedSlots();
if (slot.isSelected) if (slot.isSelected())
combinedActionSlots.remove(slot); combinedActionSlots.remove(slot);
else else
combinedActionSlots.add(slot); combinedActionSlots.add(slot);
slot.setSelected(!slot.isSelected); slot.setSelected(!slot.isSelected());
updateCombinedAction(); updateCombinedAction();
} }
}); });
@@ -239,14 +238,16 @@ class SkillCalculator extends JPanel
{ {
int actionCount = 0; int actionCount = 0;
int neededXP = targetXP - currentXP; int neededXP = targetXP - currentXP;
double xp = (slot.action.isIgnoreBonus()) ? slot.action.getXp() : slot.action.getXp() * xpFactor; SkillDataEntry action = slot.getAction();
double xp = (action.isIgnoreBonus()) ? action.getXp() : action.getXp() * xpFactor;
if (neededXP > 0) if (neededXP > 0)
actionCount = (int) Math.ceil(neededXP / xp); actionCount = (int) Math.ceil(neededXP / xp);
slot.setText("Lvl. " + slot.action.getLevel() + " (" + formatXPActionString(xp, actionCount, "exp) - ")); slot.setText("Lvl. " + action.getLevel() + " (" + formatXPActionString(xp, actionCount, "exp) - "));
slot.setAvailable(currentLevel >= slot.action.getLevel()); slot.setAvailable(currentLevel >= action.getLevel());
slot.value = xp; slot.setOverlapping(action.getLevel() < targetLevel);
slot.setValue((int) xp);
} }
} }

View File

@@ -39,6 +39,9 @@ import javax.swing.JPanel;
import javax.swing.border.Border; import javax.swing.border.Border;
import javax.swing.border.CompoundBorder; import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder; import javax.swing.border.EmptyBorder;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import net.runelite.client.plugins.skillcalculator.beans.SkillDataEntry; import net.runelite.client.plugins.skillcalculator.beans.SkillDataEntry;
import net.runelite.client.ui.ColorScheme; import net.runelite.client.ui.ColorScheme;
import net.runelite.client.ui.FontManager; import net.runelite.client.ui.FontManager;
@@ -54,15 +57,30 @@ class UIActionSlot extends JPanel
BorderFactory.createMatteBorder(0, 4, 0, 0, (ColorScheme.PROGRESS_ERROR_COLOR).darker()), BorderFactory.createMatteBorder(0, 4, 0, 0, (ColorScheme.PROGRESS_ERROR_COLOR).darker()),
BorderFactory.createEmptyBorder(7, 12, 7, 7)); BorderFactory.createEmptyBorder(7, 12, 7, 7));
SkillDataEntry action; private static final Border ORANGE_BORDER = new CompoundBorder(
private JShadowedLabel uiLabelActions; BorderFactory.createMatteBorder(0, 4, 0, 0, (ColorScheme.PROGRESS_INPROGRESS_COLOR).darker()),
BorderFactory.createEmptyBorder(7, 12, 7, 7));
private static final Dimension ICON_SIZE = new Dimension(32, 32); private static final Dimension ICON_SIZE = new Dimension(32, 32);
@Getter(AccessLevel.PACKAGE)
private final SkillDataEntry action;
private final JShadowedLabel uiLabelActions;
private final JPanel uiInfo; private final JPanel uiInfo;
boolean isAvailable = false; @Getter(AccessLevel.PACKAGE)
boolean isSelected = false; private boolean isAvailable;
double value = 0; @Getter(AccessLevel.PACKAGE)
private boolean isSelected;
@Getter(AccessLevel.PACKAGE)
private boolean isOverlapping;
@Getter(AccessLevel.PACKAGE)
@Setter(AccessLevel.PACKAGE)
private int value = 0;
UIActionSlot(SkillDataEntry action) UIActionSlot(SkillDataEntry action)
{ {
@@ -128,13 +146,19 @@ class UIActionSlot extends JPanel
void setSelected(boolean selected) void setSelected(boolean selected)
{ {
isSelected = selected; isSelected = selected;
updateBackground(); this.updateBackground();
} }
void setAvailable(boolean available) void setAvailable(boolean available)
{ {
isAvailable = available; isAvailable = available;
updateBackground(); this.updateBackground();
}
void setOverlapping(boolean overlapping)
{
isOverlapping = overlapping;
this.updateBackground();
} }
void setText(String text) void setText(String text)
@@ -144,8 +168,20 @@ class UIActionSlot extends JPanel
private void updateBackground() private void updateBackground()
{ {
setBorder(isAvailable ? GREEN_BORDER : RED_BORDER); if (isAvailable)
setBackground(isSelected ? ColorScheme.DARKER_GRAY_HOVER_COLOR.brighter() : ColorScheme.DARKER_GRAY_COLOR); {
this.setBorder(GREEN_BORDER);
}
else if (isOverlapping)
{
this.setBorder(ORANGE_BORDER);
}
else
{
this.setBorder(RED_BORDER);
}
setBackground(this.isSelected() ? ColorScheme.DARKER_GRAY_HOVER_COLOR.brighter() : ColorScheme.DARKER_GRAY_COLOR);
} }
@Override @Override