client: add hiscore plugin

This commit is contained in:
Adam
2017-02-13 19:31:11 -05:00
parent 1cb085af13
commit 6c6d87cc11
34 changed files with 380 additions and 10 deletions

View File

@@ -67,7 +67,6 @@ public class RuneLite
public void start() throws Exception
{
gui = new ClientUI();
gui.setVisible(true);
pluginManager = new PluginManager(this);
pluginManager.loadAll();
@@ -95,6 +94,11 @@ public class RuneLite
return runelite;
}
public ClientUI getGui()
{
return gui;
}
public PluginManager getPluginManager()
{
return pluginManager;

View File

@@ -31,6 +31,7 @@ import java.util.List;
import net.runelite.client.RuneLite;
import net.runelite.client.plugins.boosts.Boosts;
import net.runelite.client.plugins.fpsinfo.FPS;
import net.runelite.client.plugins.hiscore.Hiscore;
import net.runelite.client.plugins.opponentinfo.OpponentInfo;
public class PluginManager
@@ -48,6 +49,7 @@ public class PluginManager
load(new Boosts());
load(new OpponentInfo());
load(new FPS());
load(new Hiscore());
}
private void load(Plugin plugin)

View File

@@ -0,0 +1,57 @@
/*
* Copyright (c) 2017, Adam <Adam@sigterm.info>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.client.plugins.hiscore;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import net.runelite.client.RuneLite;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.ui.ClientUI;
import net.runelite.client.ui.overlay.Overlay;
public class Hiscore extends Plugin implements ActionListener
{
private final HiscorePanel hiscorePanel = new HiscorePanel();
private final ClientUI ui = RuneLite.getRunelite().getGui();
public Hiscore()
{
ui.getNavigationPanel().getHiscores().addActionListener(this);
}
@Override
public Overlay getOverlay()
{
return null;
}
@Override
public void actionPerformed(ActionEvent e)
{
ui.setPluginPanel(hiscorePanel);
ui.expand();
}
}

View File

@@ -0,0 +1,202 @@
/*
* Copyright (c) 2017, Adam <Adam@sigterm.info>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.client.plugins.hiscore;
import com.google.common.base.Strings;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.io.IOException;
import java.net.URISyntaxException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import net.runelite.api.Skill;
import net.runelite.client.ui.PluginPanel;
import net.runelite.http.api.hiscore.HiscoreClient;
import net.runelite.http.api.hiscore.HiscoreResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class HiscorePanel extends PluginPanel
{
private static final Logger logger = LoggerFactory.getLogger(HiscorePanel.class);
private JTextField input;
private JButton lookupButton;
private final JLabel attackLabel = new JLabel("--");
private final JLabel defenceLabel = new JLabel("--");
private final JLabel strengthLabel = new JLabel("--");
private final JLabel hitpointsLabel = new JLabel("--");
private final JLabel rangedLabel = new JLabel("--");
private final JLabel prayerLabel = new JLabel("--");
private final JLabel magicLabel = new JLabel("--");
private final JLabel cookingLabel = new JLabel("--");
private final JLabel woodcuttingLabel = new JLabel("--");
private final JLabel fletchingLabel = new JLabel("--");
private final JLabel fishingLabel = new JLabel("--");
private final JLabel firemakingLabel = new JLabel("--");
private final JLabel craftingLabel = new JLabel("--");
private final JLabel smithingLabel = new JLabel("--");
private final JLabel miningLabel = new JLabel("--");
private final JLabel herbloreLabel = new JLabel("--");
private final JLabel agilityLabel = new JLabel("--");
private final JLabel thievingLabel = new JLabel("--");
private final JLabel slayerLabel = new JLabel("--");
private final JLabel farmingLabel = new JLabel("--");
private final JLabel runecraftLabel = new JLabel("--");
private final JLabel hunterLabel = new JLabel("--");
private final JLabel constructionLabel = new JLabel("--");
private GridLayout stats;
private final HiscoreClient client = new HiscoreClient();
public HiscorePanel()
{
setMinimumSize(new Dimension(PANEL_WIDTH, PANEL_HEIGHT));
setPreferredSize(new Dimension(PANEL_WIDTH, PANEL_HEIGHT));
setSize(PANEL_WIDTH, PANEL_HEIGHT);
setVisible(true);
input = new JTextField();
input.setColumns(16);
add(input);
lookupButton = new JButton("Lookup");
add(lookupButton);
lookupButton.addActionListener((ActionEvent e) ->
{
lookup();
});
JPanel statsPanel = new JPanel();
stats = new GridLayout(8, 3);
statsPanel.setLayout(stats);
try
{
statsPanel.add(makeSkillPanel(Skill.ATTACK, attackLabel));
statsPanel.add(makeSkillPanel(Skill.DEFENCE, defenceLabel));
statsPanel.add(makeSkillPanel(Skill.STRENGTH, strengthLabel));
statsPanel.add(makeSkillPanel(Skill.HITPOINTS, hitpointsLabel));
statsPanel.add(makeSkillPanel(Skill.RANGED, rangedLabel));
statsPanel.add(makeSkillPanel(Skill.PRAYER, prayerLabel));
statsPanel.add(makeSkillPanel(Skill.MAGIC, magicLabel));
statsPanel.add(makeSkillPanel(Skill.COOKING, cookingLabel));
statsPanel.add(makeSkillPanel(Skill.WOODCUTTING, woodcuttingLabel));
statsPanel.add(makeSkillPanel(Skill.FLETCHING, fletchingLabel));
statsPanel.add(makeSkillPanel(Skill.FISHING, fishingLabel));
statsPanel.add(makeSkillPanel(Skill.FIREMAKING, firemakingLabel));
statsPanel.add(makeSkillPanel(Skill.CRAFTING, craftingLabel));
statsPanel.add(makeSkillPanel(Skill.SMITHING, smithingLabel));
statsPanel.add(makeSkillPanel(Skill.MINING, miningLabel));
statsPanel.add(makeSkillPanel(Skill.HERBLORE, herbloreLabel));
statsPanel.add(makeSkillPanel(Skill.AGILITY, agilityLabel));
statsPanel.add(makeSkillPanel(Skill.THIEVING, thievingLabel));
statsPanel.add(makeSkillPanel(Skill.SLAYER, slayerLabel));
statsPanel.add(makeSkillPanel(Skill.FARMING, farmingLabel));
statsPanel.add(makeSkillPanel(Skill.RUNECRAFT, runecraftLabel));
statsPanel.add(makeSkillPanel(Skill.HUNTER, hunterLabel));
statsPanel.add(makeSkillPanel(Skill.CONSTRUCTION, constructionLabel));
}
catch (IOException ex)
{
logger.warn(null, ex);
}
add(statsPanel);
}
private JPanel makeSkillPanel(Skill skill, JLabel levelLabel) throws IOException
{
JPanel iconLevel = new JPanel();
String skillIcon = "/skill_icons/" + skill.getName().toLowerCase() + ".png";
logger.debug("Loading skill icon from {}", skillIcon);
JLabel icon = new JLabel(new ImageIcon(ImageIO.read(HiscorePanel.class.getResourceAsStream(skillIcon))));
iconLevel.add(icon);
iconLevel.add(levelLabel);
return iconLevel;
}
private void lookup()
{
String lookup = input.getText();
if (Strings.isNullOrEmpty(lookup))
{
return;
}
HiscoreResult result;
try
{
result = client.lookup(lookup);
}
catch (IOException | URISyntaxException ex)
{
logger.warn(null, ex);
return;
}
setLabel(attackLabel, result.getAttack());
setLabel(defenceLabel, result.getDefence());
setLabel(strengthLabel, result.getStrength());
setLabel(hitpointsLabel, result.getHitpoints());
setLabel(rangedLabel, result.getRanged());
setLabel(prayerLabel, result.getPrayer());
setLabel(magicLabel, result.getMagic());
setLabel(cookingLabel, result.getCooking());
setLabel(woodcuttingLabel, result.getWoodcutting());
setLabel(fletchingLabel, result.getFletching());
setLabel(fishingLabel, result.getFishing());
setLabel(firemakingLabel, result.getFiremaking());
setLabel(craftingLabel, result.getCrafting());
setLabel(smithingLabel, result.getSmithing());
setLabel(miningLabel, result.getMining());
setLabel(herbloreLabel, result.getHerblore());
setLabel(agilityLabel, result.getAgility());
setLabel(thievingLabel, result.getThieving());
setLabel(slayerLabel, result.getSlayer());
setLabel(farmingLabel, result.getFarming());
setLabel(runecraftLabel, result.getRunecraft());
setLabel(hunterLabel, result.getHunter());
setLabel(constructionLabel, result.getConstruction());
}
private void setLabel(JLabel label, net.runelite.http.api.hiscore.Skill skill)
{
label.setText("" + skill.getLevel());
}
}

View File

@@ -22,23 +22,25 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.client.ui;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.FlowLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
public final class ClientUI extends JFrame
{
private JPanel container;
private ClientPanel panel;
private NavigationPanel navigationPanel;
private PluginPanel pluginPanel;
private boolean expanded;
public ClientUI() throws Exception
{
@@ -46,10 +48,10 @@ public final class ClientUI extends JFrame
pack();
setTitle("RuneLite");
setLocationRelativeTo(getOwner());
setMinimumSize(getSize());
setResizable(true);
setVisible(true);
}
private void init() throws Exception
{
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
@@ -62,7 +64,7 @@ public final class ClientUI extends JFrame
checkExit();
}
});
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
try
{
@@ -72,17 +74,60 @@ public final class ClientUI extends JFrame
{
}
container = new JPanel();
container.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
panel = new ClientPanel();
add(panel);
container.add(panel);
navigationPanel = new NavigationPanel();
container.add(navigationPanel);
add(container);
}
public void expand()
{
if (!expanded)
{
container.add(pluginPanel, null, 1);
container.revalidate();
this.setSize(this.getWidth() + PluginPanel.PANEL_WIDTH, this.getHeight());
expanded = true;
}
else
{
container.remove(1);
container.revalidate();
this.setSize(this.getWidth() - PluginPanel.PANEL_WIDTH, this.getHeight());
expanded = false;
}
}
private void checkExit()
{
int result = JOptionPane.showConfirmDialog(this, "Are you sure you want to exit?", "Exit", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
if (result == JOptionPane.OK_OPTION)
{
System.exit(0);
}
}
public NavigationPanel getNavigationPanel()
{
return navigationPanel;
}
public PluginPanel getPluginPanel()
{
return pluginPanel;
}
public void setPluginPanel(PluginPanel pluginPanel)
{
this.pluginPanel = pluginPanel;
}
}

View File

@@ -0,0 +1,42 @@
package net.runelite.client.ui;
import java.awt.Dimension;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JPanel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class NavigationPanel extends JPanel
{
private static final Logger logger = LoggerFactory.getLogger(NavigationPanel.class);
private static final int PANEL_WIDTH = 20, PANEL_HEIGHT = 503;
private final JButton hiscores = new JButton();
public NavigationPanel()
{
setSize(new Dimension(PANEL_WIDTH, PANEL_HEIGHT));
setMinimumSize(new Dimension(PANEL_WIDTH, PANEL_HEIGHT));
setPreferredSize(new Dimension(PANEL_WIDTH, PANEL_HEIGHT));
try
{
hiscores.setIcon(new ImageIcon(ImageIO.read(getClass().getResourceAsStream("/net/runelite/client/plugins/hiscore/hiscore.gif"))));
}
catch (IOException ex)
{
logger.warn(null, ex);
}
add(hiscores);
}
public JButton getHiscores()
{
return hiscores;
}
}

View File

@@ -0,0 +1,8 @@
package net.runelite.client.ui;
import javax.swing.JPanel;
public class PluginPanel extends JPanel
{
public static final int PANEL_WIDTH = 225, PANEL_HEIGHT = 503;
}

View File

@@ -41,6 +41,11 @@ public class OverlayRenderer
{
Overlay overlay = plugin.getOverlay();
if (overlay == null)
{
continue;
}
switch (overlay.getPosition())
{
case TOP_RIGHT: