Cleanup new slayer task ui
This commit is contained in:
@@ -239,8 +239,6 @@ public class SlayerPlugin extends Plugin
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
clientToolbar.addNavigation(navButton);
|
clientToolbar.addNavigation(navButton);
|
||||||
System.out.println("=================================");
|
|
||||||
System.out.println("added slayer nav button");
|
|
||||||
|
|
||||||
if (client.getGameState() == GameState.LOGGED_IN
|
if (client.getGameState() == GameState.LOGGED_IN
|
||||||
&& config.amount() != -1
|
&& config.amount() != -1
|
||||||
@@ -284,7 +282,7 @@ public class SlayerPlugin extends Plugin
|
|||||||
case HOPPING:
|
case HOPPING:
|
||||||
case LOGGING_IN:
|
case LOGGING_IN:
|
||||||
cachedXp = 0;
|
cachedXp = 0;
|
||||||
currentTask = new TaskData(0, 0,0, 0, "", "", true);
|
currentTask = new TaskData(0, 0, 0,0, 0, "", "", true);
|
||||||
loginFlag = true;
|
loginFlag = true;
|
||||||
highlightedTargets.clear();
|
highlightedTargets.clear();
|
||||||
break;
|
break;
|
||||||
@@ -560,6 +558,8 @@ public class SlayerPlugin extends Plugin
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int delta = slayerExp - cachedXp;
|
||||||
|
currentTask.setElapsedXp(currentTask.getElapsedXp() + delta);
|
||||||
killedOne();
|
killedOne();
|
||||||
cachedXp = slayerExp;
|
cachedXp = slayerExp;
|
||||||
}
|
}
|
||||||
@@ -689,6 +689,7 @@ public class SlayerPlugin extends Plugin
|
|||||||
{
|
{
|
||||||
currentTask = new TaskData(isNewAssignment ? 0 : currentTask.getElapsedTime(),
|
currentTask = new TaskData(isNewAssignment ? 0 : currentTask.getElapsedTime(),
|
||||||
isNewAssignment ? 0 : currentTask.getElapsedKills(),
|
isNewAssignment ? 0 : currentTask.getElapsedKills(),
|
||||||
|
isNewAssignment ? 0 : currentTask.getElapsedXp(),
|
||||||
amt, initAmt, location, name,
|
amt, initAmt, location, name,
|
||||||
isNewAssignment ? true : currentTask.isPaused());
|
isNewAssignment ? true : currentTask.isPaused());
|
||||||
panel.updateCurrentTask(true, currentTask.isPaused(), currentTask, isNewAssignment);
|
panel.updateCurrentTask(true, currentTask.isPaused(), currentTask, isNewAssignment);
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import net.runelite.client.ui.FontManager;
|
|||||||
import net.runelite.client.ui.PluginPanel;
|
import net.runelite.client.ui.PluginPanel;
|
||||||
import net.runelite.client.ui.components.PluginErrorPanel;
|
import net.runelite.client.ui.components.PluginErrorPanel;
|
||||||
import net.runelite.client.util.ColorUtil;
|
import net.runelite.client.util.ColorUtil;
|
||||||
|
import net.runelite.client.util.ImageUtil;
|
||||||
import net.runelite.client.util.StackFormatter;
|
import net.runelite.client.util.StackFormatter;
|
||||||
|
|
||||||
public class SlayerTaskPanel extends PluginPanel
|
public class SlayerTaskPanel extends PluginPanel
|
||||||
@@ -37,6 +38,9 @@ public class SlayerTaskPanel extends PluginPanel
|
|||||||
"<html><body style='color:%s'>%s<span style='color:white'>%02d:%02d:%02d</span></body></html>";
|
"<html><body style='color:%s'>%s<span style='color:white'>%02d:%02d:%02d</span></body></html>";
|
||||||
|
|
||||||
|
|
||||||
|
private static final ImageIcon PAUSE, PAUSE_FADED, PAUSE_HOVER;
|
||||||
|
private static final ImageIcon PLAY, PLAY_FADED, PLAY_HOVER;
|
||||||
|
|
||||||
// TODO: set some kind of maximum for the amount of tasks to be tracked in a session
|
// TODO: set some kind of maximum for the amount of tasks to be tracked in a session
|
||||||
private static final int MAX_TASK_BOXES = 50;
|
private static final int MAX_TASK_BOXES = 50;
|
||||||
|
|
||||||
@@ -62,6 +66,20 @@ public class SlayerTaskPanel extends PluginPanel
|
|||||||
|
|
||||||
private SlayerPlugin slayerPlugin;
|
private SlayerPlugin slayerPlugin;
|
||||||
|
|
||||||
|
static
|
||||||
|
{
|
||||||
|
final BufferedImage pauseImg = ImageUtil.getResourceStreamFromClass(SlayerPlugin.class, "pause_icon.png");
|
||||||
|
final BufferedImage playImg = ImageUtil.getResourceStreamFromClass(SlayerPlugin.class, "play_icon.png");
|
||||||
|
|
||||||
|
PAUSE = new ImageIcon(pauseImg);
|
||||||
|
PAUSE_FADED = new ImageIcon(ImageUtil.alphaOffset(pauseImg, -180));
|
||||||
|
PAUSE_HOVER = new ImageIcon(ImageUtil.alphaOffset(pauseImg, -220));
|
||||||
|
|
||||||
|
PLAY = new ImageIcon(playImg);
|
||||||
|
PLAY_FADED = new ImageIcon(ImageUtil.alphaOffset(playImg, -180));
|
||||||
|
PLAY_HOVER = new ImageIcon(ImageUtil.alphaOffset(playImg, -220));
|
||||||
|
}
|
||||||
|
|
||||||
public SlayerTaskPanel(SlayerPlugin slayerPlugin)
|
public SlayerTaskPanel(SlayerPlugin slayerPlugin)
|
||||||
{
|
{
|
||||||
this.slayerPlugin = slayerPlugin;
|
this.slayerPlugin = slayerPlugin;
|
||||||
@@ -75,34 +93,93 @@ public class SlayerTaskPanel extends PluginPanel
|
|||||||
layoutPanel.setLayout(new BoxLayout(layoutPanel, BoxLayout.Y_AXIS));
|
layoutPanel.setLayout(new BoxLayout(layoutPanel, BoxLayout.Y_AXIS));
|
||||||
add(layoutPanel, BorderLayout.NORTH);
|
add(layoutPanel, BorderLayout.NORTH);
|
||||||
|
|
||||||
actionsContainer.setLayout(new GridLayout(1, 2, 10, 0));
|
actionsContainer.setLayout(new BorderLayout());
|
||||||
actionsContainer.setBackground(ColorScheme.DARKER_GRAY_COLOR);
|
actionsContainer.setBackground(ColorScheme.DARKER_GRAY_COLOR);
|
||||||
actionsContainer.setPreferredSize(new Dimension(0, 30));
|
actionsContainer.setPreferredSize(new Dimension(0, 30));
|
||||||
actionsContainer.setBorder(new EmptyBorder(5, 5, 5, 10));
|
actionsContainer.setBorder(new EmptyBorder(5, 5, 5, 10));
|
||||||
actionsContainer.setVisible(false);
|
actionsContainer.setVisible(false);
|
||||||
|
|
||||||
playBtn.setText("->");
|
final JPanel controlsPanel = new JPanel(new GridLayout(1, 2, 10, 0));
|
||||||
|
controlsPanel.setBackground(ColorScheme.DARKER_GRAY_COLOR);
|
||||||
|
|
||||||
|
playBtn.setIcon(PLAY);
|
||||||
playBtn.setToolTipText("Resume the current slayer task");
|
playBtn.setToolTipText("Resume the current slayer task");
|
||||||
playBtn.addMouseListener(new MouseAdapter() {
|
playBtn.addMouseListener(new MouseAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void mousePressed(MouseEvent mouseEvent)
|
public void mousePressed(MouseEvent mouseEvent)
|
||||||
{
|
{
|
||||||
slayerPlugin.setPaused(false);
|
slayerPlugin.setPaused(false);
|
||||||
|
changePauseState(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseExited(MouseEvent mouseEvent)
|
||||||
|
{
|
||||||
|
boolean paused = true;
|
||||||
|
TaskData currentTask = slayerPlugin.getCurrentTask();
|
||||||
|
if (currentTask != null)
|
||||||
|
{
|
||||||
|
paused = currentTask.isPaused();
|
||||||
|
}
|
||||||
|
playBtn.setIcon(paused ? PLAY_FADED : PLAY);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseEntered(MouseEvent mouseEvent)
|
||||||
|
{
|
||||||
|
boolean paused = true;
|
||||||
|
TaskData currentTask = slayerPlugin.getCurrentTask();
|
||||||
|
if (currentTask != null)
|
||||||
|
{
|
||||||
|
paused = currentTask.isPaused();
|
||||||
|
}
|
||||||
|
playBtn.setIcon(paused ? PLAY_HOVER : PLAY);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
pauseBtn.setText("||");
|
pauseBtn.setIcon(PAUSE);
|
||||||
pauseBtn.setToolTipText("Pause the current slayer task");
|
pauseBtn.setToolTipText("Pause the current slayer task");
|
||||||
pauseBtn.addMouseListener(new MouseAdapter() {
|
pauseBtn.addMouseListener(new MouseAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void mousePressed(MouseEvent mouseEvent)
|
public void mousePressed(MouseEvent mouseEvent)
|
||||||
{
|
{
|
||||||
slayerPlugin.setPaused(true);
|
slayerPlugin.setPaused(true);
|
||||||
|
changePauseState(true);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void mouseExited(MouseEvent mouseEvent)
|
||||||
|
{
|
||||||
|
boolean paused = true;
|
||||||
|
TaskData currentTask = slayerPlugin.getCurrentTask();
|
||||||
|
if (currentTask != null)
|
||||||
|
{
|
||||||
|
paused = currentTask.isPaused();
|
||||||
|
}
|
||||||
|
pauseBtn.setIcon(paused ? PAUSE : PAUSE_FADED);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseEntered(MouseEvent mouseEvent)
|
||||||
|
{
|
||||||
|
boolean paused = true;
|
||||||
|
TaskData currentTask = slayerPlugin.getCurrentTask();
|
||||||
|
if (currentTask != null)
|
||||||
|
{
|
||||||
|
paused = currentTask.isPaused();
|
||||||
|
}
|
||||||
|
pauseBtn.setIcon(paused ? PAUSE : PAUSE_HOVER);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
actionsContainer.add(playBtn);
|
controlsPanel.add(playBtn);
|
||||||
actionsContainer.add(pauseBtn);
|
controlsPanel.add(pauseBtn);
|
||||||
|
|
||||||
|
actionsContainer.add(controlsPanel, BorderLayout.EAST);
|
||||||
|
changePauseState(true);
|
||||||
|
if (slayerPlugin.getCurrentTask() != null)
|
||||||
|
{
|
||||||
|
changePauseState(slayerPlugin.getCurrentTask().isPaused());
|
||||||
|
}
|
||||||
|
|
||||||
// Create panel that will contain overall data
|
// Create panel that will contain overall data
|
||||||
overallPanel.setBorder(new EmptyBorder(8, 10, 8, 10));
|
overallPanel.setBorder(new EmptyBorder(8, 10, 8, 10));
|
||||||
@@ -138,6 +215,12 @@ public class SlayerTaskPanel extends PluginPanel
|
|||||||
overallIcon.setIcon(new ImageIcon(img));
|
overallIcon.setIcon(new ImageIcon(img));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void changePauseState(boolean paused)
|
||||||
|
{
|
||||||
|
playBtn.setIcon(paused ? PLAY_FADED : PLAY);
|
||||||
|
pauseBtn.setIcon(paused ? PAUSE : PAUSE_FADED);
|
||||||
|
}
|
||||||
|
|
||||||
private void updateOverall()
|
private void updateOverall()
|
||||||
{
|
{
|
||||||
int overallKills = 0;
|
int overallKills = 0;
|
||||||
@@ -181,7 +264,6 @@ public class SlayerTaskPanel extends PluginPanel
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
System.out.println("empty task sent so ending current task");
|
|
||||||
TaskBox current = tasks.get(0);
|
TaskBox current = tasks.get(0);
|
||||||
// current task has ended so it should be paused
|
// current task has ended so it should be paused
|
||||||
current.update(true, true, current.getTaskData());
|
current.update(true, true, current.getTaskData());
|
||||||
@@ -190,8 +272,6 @@ public class SlayerTaskPanel extends PluginPanel
|
|||||||
|
|
||||||
if (tasks.isEmpty() || isNewAssignment)
|
if (tasks.isEmpty() || isNewAssignment)
|
||||||
{
|
{
|
||||||
System.out.println("new task is set");
|
|
||||||
|
|
||||||
// new task so append it to the front of the list
|
// new task so append it to the front of the list
|
||||||
SwingUtilities.invokeLater(() -> {
|
SwingUtilities.invokeLater(() -> {
|
||||||
TaskBox newBox = buildBox(slayerPlugin, tasksContainer, newData);
|
TaskBox newBox = buildBox(slayerPlugin, tasksContainer, newData);
|
||||||
@@ -204,10 +284,6 @@ public class SlayerTaskPanel extends PluginPanel
|
|||||||
// if here there is a current task so check if the current task matches
|
// if here there is a current task so check if the current task matches
|
||||||
// the update being sent
|
// the update being sent
|
||||||
TaskBox current = tasks.get(0);
|
TaskBox current = tasks.get(0);
|
||||||
System.out.println("current task: " + current.getTaskData().getTaskName() + " " +
|
|
||||||
current.getTaskData().getTaskLocation() + " " + current.getTaskData().getInitialAmount());
|
|
||||||
System.out.println("new task: " + newData.getTaskName() + " " + newData.getTaskLocation() +
|
|
||||||
" " + newData.getInitialAmount());
|
|
||||||
if (!current.getTaskData().getTaskName().equals(newData.getTaskName()) ||
|
if (!current.getTaskData().getTaskName().equals(newData.getTaskName()) ||
|
||||||
!current.getTaskData().getTaskLocation().equals(newData.getTaskLocation()) ||
|
!current.getTaskData().getTaskLocation().equals(newData.getTaskLocation()) ||
|
||||||
current.getTaskData().getInitialAmount() != newData.getInitialAmount())
|
current.getTaskData().getInitialAmount() != newData.getInitialAmount())
|
||||||
@@ -215,7 +291,6 @@ public class SlayerTaskPanel extends PluginPanel
|
|||||||
// current task does not match the update being sent so the current task
|
// current task does not match the update being sent so the current task
|
||||||
// must have been outdated - this is necessarily true because if a true
|
// must have been outdated - this is necessarily true because if a true
|
||||||
// new task was sent it would have set the isNewAssignment flag
|
// new task was sent it would have set the isNewAssignment flag
|
||||||
System.out.println("task does not match must create new match");
|
|
||||||
|
|
||||||
// so this previous task is invalid so delete it then add in the new actually
|
// so this previous task is invalid so delete it then add in the new actually
|
||||||
// correct task
|
// correct task
|
||||||
@@ -229,16 +304,13 @@ public class SlayerTaskPanel extends PluginPanel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("simply updating task");
|
|
||||||
System.out.println("task panel size = " + tasks.size());
|
|
||||||
System.out.println("task elapsed time " + tasks.get(0).getTaskData().getElapsedTime());
|
|
||||||
System.out.println("task elapsed kills " + tasks.get(0).getTaskData().getElapsedKills());
|
|
||||||
// not an empty assignment or a new assignment so just update the current assignment
|
// not an empty assignment or a new assignment so just update the current assignment
|
||||||
TaskBox current = tasks.get(0);
|
TaskBox current = tasks.get(0);
|
||||||
current.update(updated, paused, newData);
|
current.update(updated, paused, newData);
|
||||||
|
|
||||||
// update the overall stats once this task stats are updated
|
// update the overall stats once this task stats are updated
|
||||||
updateOverall();
|
updateOverall();
|
||||||
|
changePauseState(paused);
|
||||||
}
|
}
|
||||||
|
|
||||||
static String htmlLabel(String key, long timeMillis)
|
static String htmlLabel(String key, long timeMillis)
|
||||||
|
|||||||
@@ -61,6 +61,8 @@ public class TaskBox extends JPanel
|
|||||||
private final JLabel remainingDuration = new JLabel();
|
private final JLabel remainingDuration = new JLabel();
|
||||||
private final JLabel currentKills = new JLabel();
|
private final JLabel currentKills = new JLabel();
|
||||||
private final JLabel remainingKills = new JLabel();
|
private final JLabel remainingKills = new JLabel();
|
||||||
|
private final JLabel currentXp = new JLabel();
|
||||||
|
private final JLabel remainingXp = new JLabel();
|
||||||
|
|
||||||
private boolean paused = false;
|
private boolean paused = false;
|
||||||
|
|
||||||
@@ -84,7 +86,7 @@ public class TaskBox extends JPanel
|
|||||||
headerPanel.setBackground(ColorScheme.DARKER_GRAY_COLOR);
|
headerPanel.setBackground(ColorScheme.DARKER_GRAY_COLOR);
|
||||||
headerPanel.setLayout(new BorderLayout());
|
headerPanel.setLayout(new BorderLayout());
|
||||||
|
|
||||||
statsPanel.setLayout(new DynamicGridLayout(2, 2));
|
statsPanel.setLayout(new DynamicGridLayout(3, 2));
|
||||||
statsPanel.setBackground(ColorScheme.DARKER_GRAY_COLOR);
|
statsPanel.setBackground(ColorScheme.DARKER_GRAY_COLOR);
|
||||||
statsPanel.setBorder(new EmptyBorder(9, 2, 9, 2));
|
statsPanel.setBorder(new EmptyBorder(9, 2, 9, 2));
|
||||||
|
|
||||||
@@ -92,11 +94,15 @@ public class TaskBox extends JPanel
|
|||||||
remainingDuration.setFont(FontManager.getRunescapeSmallFont());
|
remainingDuration.setFont(FontManager.getRunescapeSmallFont());
|
||||||
currentKills.setFont(FontManager.getRunescapeSmallFont());
|
currentKills.setFont(FontManager.getRunescapeSmallFont());
|
||||||
remainingKills.setFont(FontManager.getRunescapeSmallFont());
|
remainingKills.setFont(FontManager.getRunescapeSmallFont());
|
||||||
|
currentXp.setFont(FontManager.getRunescapeSmallFont());
|
||||||
|
remainingXp.setFont(FontManager.getRunescapeSmallFont());
|
||||||
|
|
||||||
statsPanel.add(currentDuration);
|
statsPanel.add(currentDuration);
|
||||||
statsPanel.add(currentKills);
|
|
||||||
statsPanel.add(remainingDuration);
|
statsPanel.add(remainingDuration);
|
||||||
|
statsPanel.add(currentKills);
|
||||||
statsPanel.add(remainingKills);
|
statsPanel.add(remainingKills);
|
||||||
|
statsPanel.add(currentXp);
|
||||||
|
statsPanel.add(remainingXp);
|
||||||
|
|
||||||
headerPanel.add(taskIcon, BorderLayout.WEST);
|
headerPanel.add(taskIcon, BorderLayout.WEST);
|
||||||
headerPanel.add(statsPanel, BorderLayout.CENTER);
|
headerPanel.add(statsPanel, BorderLayout.CENTER);
|
||||||
@@ -159,19 +165,25 @@ public class TaskBox extends JPanel
|
|||||||
{
|
{
|
||||||
if (getParent() != panel)
|
if (getParent() != panel)
|
||||||
{
|
{
|
||||||
panel.add(this);
|
panel.add(this, 0);
|
||||||
panel.revalidate();
|
panel.revalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update data
|
// Update data
|
||||||
taskData.setElapsedKills(newData.getElapsedKills());
|
taskData.setElapsedKills(newData.getElapsedKills());
|
||||||
taskData.setAmount(newData.getAmount());
|
taskData.setAmount(newData.getAmount());
|
||||||
|
taskData.setElapsedXp(newData.getElapsedXp());
|
||||||
|
|
||||||
// Update information labels
|
// Update information labels
|
||||||
int kills = taskData.getInitialAmount() - taskData.getAmount();
|
int kills = taskData.getInitialAmount() - taskData.getAmount();
|
||||||
currentKills.setText(htmlLabel("Elapsed Kills: ", taskData.getElapsedKills()));
|
currentKills.setText(htmlLabel("Elapsed Kills: ", taskData.getElapsedKills()));
|
||||||
remainingKills.setText(htmlLabel("Remaining Kills: ", taskData.getAmount()));
|
remainingKills.setText(htmlLabel("Remaining Kills: ", taskData.getAmount()));
|
||||||
|
|
||||||
|
currentXp.setText(htmlLabel("Elapsed Xp: ", taskData.getElapsedXp()));
|
||||||
|
double xpPerKill = ((double) taskData.getElapsedXp()) / ((double) taskData.getElapsedKills());
|
||||||
|
double xpLeft = xpPerKill * taskData.getAmount();
|
||||||
|
remainingXp.setText(htmlLabel("Remaining Xp: ", (int) xpLeft));
|
||||||
|
|
||||||
// Update progress bar
|
// Update progress bar
|
||||||
double percentComplete = ((double) kills) / ((double) taskData.getInitialAmount());
|
double percentComplete = ((double) kills) / ((double) taskData.getInitialAmount());
|
||||||
progressBar.setValue((int) (percentComplete * 100));
|
progressBar.setValue((int) (percentComplete * 100));
|
||||||
@@ -225,8 +237,8 @@ public class TaskBox extends JPanel
|
|||||||
|
|
||||||
// Update duration separately, every time (not only when there's an update)
|
// Update duration separately, every time (not only when there's an update)
|
||||||
taskData.setElapsedTime(newData.getElapsedTime());
|
taskData.setElapsedTime(newData.getElapsedTime());
|
||||||
currentDuration.setText(htmlLabel("Elapsed Time: ", taskData.getElapsedTime()));
|
currentDuration.setText(htmlLabel("Elapsed Time:<br/>", taskData.getElapsedTime()));
|
||||||
remainingDuration.setText(htmlLabel("Remaining Time: ", estimateRemainingTime(taskData)));
|
remainingDuration.setText(htmlLabel("Remaining Time:<br/>", estimateRemainingTime(taskData)));
|
||||||
|
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ public class TaskData
|
|||||||
{
|
{
|
||||||
private long elapsedTime;
|
private long elapsedTime;
|
||||||
private int elapsedKills;
|
private int elapsedKills;
|
||||||
|
private int elapsedXp;
|
||||||
private int amount, initialAmount;
|
private int amount, initialAmount;
|
||||||
private String taskLocation;
|
private String taskLocation;
|
||||||
private String taskName;
|
private String taskName;
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 189 B |
Binary file not shown.
|
After Width: | Height: | Size: 217 B |
Reference in New Issue
Block a user