Equinox

EquinoxLunarPlanker.java

Mar 12th, 2011
931
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 62.57 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.Dimension;
  3. import java.awt.Font;
  4. import java.awt.Graphics;
  5. import java.awt.Graphics2D;
  6. import java.awt.Image;
  7. import java.awt.Point;
  8. import java.awt.Rectangle;
  9. import java.awt.event.MouseEvent;
  10. import java.awt.event.MouseListener;
  11. import java.awt.event.MouseMotionListener;
  12. import java.awt.font.FontRenderContext;
  13. import java.awt.geom.AffineTransform;
  14. import java.awt.geom.RoundRectangle2D;
  15. import java.awt.image.BufferedImage;
  16. import java.io.File;
  17. import java.io.IOException;
  18. import java.lang.reflect.Method;
  19. import java.net.MalformedURLException;
  20. import java.net.URL;
  21. import java.text.DecimalFormat;
  22. import java.util.ArrayList;
  23. import java.util.HashMap;
  24. import java.util.List;
  25. import java.util.Map;
  26. import java.util.logging.Logger;
  27.  
  28. import javax.imageio.ImageIO;
  29. import javax.swing.JOptionPane;
  30.  
  31. import org.rsbot.event.listeners.PaintListener;
  32. import org.rsbot.script.Script;
  33. import org.rsbot.script.ScriptManifest;
  34. import org.rsbot.script.methods.Equipment;
  35. import org.rsbot.script.methods.Game;
  36. import org.rsbot.script.methods.GrandExchange.GEItem;
  37. import org.rsbot.script.methods.Magic;
  38. import org.rsbot.script.methods.Skills;
  39. import org.rsbot.script.wrappers.RSComponent;
  40. import org.rsbot.script.wrappers.RSInterface;
  41. import org.rsbot.script.wrappers.RSItem;
  42. import org.rsbot.util.GlobalConfiguration;
  43.  
  44. @ScriptManifest(authors = { "Equinox_" }, version = 1.01, name = "Equinox_ Lunar Planker", description = "Uses the lunar spell plank-make to create planks.")
  45. public class EquinoxLunarPlanker extends Script implements MouseListener,
  46.         MouseMotionListener, PaintListener {
  47.     PaintInterface Paint;
  48.     ModifiedDrawMouse drawMouse = new ModifiedDrawMouse();
  49.  
  50.     final String baseURL = "http://equinox-scripts.web44.net/scripts/natcrafter";
  51.     final double VERSION = getClass().getAnnotation(ScriptManifest.class)
  52.             .version();
  53.     final String author = PaintFormatter.formatList(getClass().getAnnotation(
  54.             ScriptManifest.class).authors());
  55.     final String name = PaintFormatter.properCaseAll(getClass().getAnnotation(
  56.             ScriptManifest.class).name());
  57.  
  58.     // Logs And Planks
  59.     static final int MLog = 6332;
  60.     static final int MPlank = 8782;
  61.     static final int MCost = 1095;
  62.     static final int TLog = 6333;
  63.     static final int TPlank = 8780;
  64.     static final int TCost = 350;
  65.     static final int OLog = 1521;
  66.     static final int OPlank = 8778;
  67.     static final int OCost = 175;
  68.     static final int RLog = 1511;
  69.     static final int RPlank = 960;
  70.     static final int RCost = 70;
  71.  
  72.     static final int NatRune = 561;
  73.     static final int AstralRune = 9075;
  74.     static final int EarthRune = 557;
  75.     static int PlankID;
  76.     static int LogID;
  77.     static int coinsPerPlank;
  78.  
  79.     int Coins = 995;
  80.     int logCount = 0;
  81.     int plankCount = 0;
  82.     boolean spellSelected = false;
  83.     Rectangle spell = null;
  84.     Rectangle[] invItems;
  85.     int nextSlot;
  86.     public boolean hasEarthStaff = false;
  87.  
  88.     int tabTries = 5;
  89.     int invTries = 0;
  90.     int mageTries = 0;
  91.  
  92.     enum State {
  93.         Cast, Select, Bank, Revert_Magic, Wait
  94.     }
  95.  
  96.     public RSComponent getSpell(int spell) {
  97.         if (game.getCurrentTab() != Game.TAB_MAGIC) {
  98.             game.openTab(Game.TAB_MAGIC);
  99.             for (int i = 0; i < 100; i++) {
  100.                 sleep(20);
  101.                 if (game.getCurrentTab() == Game.TAB_MAGIC) {
  102.                     break;
  103.                 }
  104.             }
  105.             sleep(random(150, 250));
  106.         }
  107.         if (game.getCurrentTab() == Game.TAB_MAGIC) {
  108.             RSInterface inter = magic.getInterface();
  109.             if (inter != null) {
  110.                 RSComponent comp = inter.getComponent(spell);
  111.                 return comp;
  112.             }
  113.         }
  114.         return null;
  115.     }
  116.  
  117.     public boolean onStart() {
  118.         RSItem logI = inventory.getItem(RLog, OLog, TLog, MLog);
  119.         if (logI == null) {
  120.             log.severe("You must start with a Regular, Oak, Teak, or Mahogany log in your inventory!");
  121.             return false;
  122.         }
  123.         switch (logI.getID()) {
  124.         case MLog:
  125.             LogID = MLog;
  126.             coinsPerPlank = MCost;
  127.             PlankID = MPlank;
  128.             break;
  129.         case TLog:
  130.             LogID = TLog;
  131.             coinsPerPlank = TCost;
  132.             PlankID = TPlank;
  133.             break;
  134.         case OLog:
  135.             LogID = OLog;
  136.             coinsPerPlank = OCost;
  137.             PlankID = OPlank;
  138.             break;
  139.         case RLog:
  140.             LogID = RLog;
  141.             coinsPerPlank = RCost;
  142.             PlankID = RPlank;
  143.             break;
  144.         default:
  145.             return false;
  146.         }
  147.         RSItem wep = equipment.getItem(Equipment.WEAPON);
  148.         if (wep != null)
  149.             hasEarthStaff = (wep.getName().toLowerCase().contains("staff") && (wep
  150.                     .getName().toLowerCase().contains("earth") || wep.getName()
  151.                     .toLowerCase().contains("mud")));
  152.         if (!(inventory.containsAll(AstralRune, NatRune))) {
  153.             log.severe("You must start with Astral Runes and Nature Runes in inventory!");
  154.             return false;
  155.         }
  156.         if (!(hasEarthStaff || inventory.contains(EarthRune))) {
  157.             log.severe("You must start with either an Earth-Type staff equipped or Earth Runes in inventory");
  158.             return false;
  159.         }
  160.  
  161.         Paint = new PaintInterface(this, log, Skills.MAGIC);
  162.         new DataLoader(this);
  163.         logCount = inventory.getCount(LogID);
  164.         plankCount = inventory.getCount(PlankID);
  165.         Paint.startAstrals = inventory.getCount(true, AstralRune);
  166.         Paint.startCoins = inventory.getCount(true, Coins);
  167.         Paint.startEarths = inventory.getCount(true, EarthRune);
  168.         Paint.startNatures = inventory.getCount(true, NatRune);
  169.  
  170.         RSComponent invIface = inventory.getInterface();
  171.         if (invIface != null)
  172.             if (invIface.isValid()) {
  173.                 invItems = new Rectangle[invIface.getComponents().length];
  174.                 for (int i = 0; i < invItems.length; i++)
  175.                     invItems[i] = (Rectangle) invIface.getComponent(i)
  176.                             .getArea().clone();
  177.             }
  178.  
  179.         spell = getSpell(Magic.SPELL_PLANK_MAKE).getArea();
  180.         return true;
  181.     }
  182.  
  183.     State getState() {
  184.         if (game.getCurrentTab() == Game.TAB_INVENTORY)
  185.             if (inventory.isItemSelected())
  186.                 return State.Revert_Magic;
  187.         // "The Abbyssal Services Department apologizes...."
  188.         if (interfaces.canContinue())
  189.             interfaces.clickContinue();
  190.         if (logCount <= 0)
  191.             return State.Bank;
  192.         if (!spellSelected)
  193.             return State.Cast;
  194.         if (spellSelected)
  195.             return State.Select;
  196.         if (logCount <= 0)
  197.             return State.Bank;
  198.         return State.Wait;
  199.     }
  200.  
  201.     void updateInv() {
  202.         logCount = inventory.getCount(LogID);
  203.         if (inventory.getCount(PlankID) > plankCount)
  204.             Paint.planksMade += inventory.getCount(PlankID) - plankCount;
  205.         plankCount = inventory.getCount(PlankID);
  206.         // if (inventory.getCount(true,Coins) < coinsPerPlank)
  207.         // stopScript(true);
  208.         Paint.usedAstrals = inventory.getCount(true, AstralRune)
  209.                 - Paint.startAstrals;
  210.         Paint.usedNatures = inventory.getCount(true, NatRune)
  211.                 - Paint.startNatures;
  212.         Paint.usedEarths = inventory.getCount(true, EarthRune)
  213.                 - Paint.startEarths;
  214.         Paint.usedCoins = inventory.getCount(true, Coins) - Paint.startCoins;
  215.  
  216.         Paint.castsLeft = Math.min(inventory.getCount(true, AstralRune) / 2,
  217.                 inventory.getCount(true, NatRune));
  218.         if (!hasEarthStaff)
  219.             Paint.castsLeft = Math.min(Paint.castsLeft,
  220.                     inventory.getCount(true, EarthRune) / 15);
  221.         Paint.coinsLeft = inventory.getCount(true, Coins) / coinsPerPlank;
  222.     }
  223.  
  224.     public int loop() {
  225.         mouse.setSpeed(random(4, 6));
  226.         if (game.getCurrentTab() == Game.TAB_INVENTORY)
  227.             updateInv();
  228.  
  229.         try {
  230.             switch (getState()) {
  231.             case Cast:
  232.                 if (game.getCurrentTab() == Game.TAB_MAGIC && !spellSelected) {
  233.                     if (magic.castSpell(Magic.SPELL_PLANK_MAKE))
  234.                         spellSelected = true;
  235.                     mageTries = 0;
  236.                 } else if (mageTries >= tabTries)
  237.                     game.openTab(Game.TAB_MAGIC);
  238.                 else
  239.                     mageTries++;
  240.                 break;
  241.             case Revert_Magic:
  242.                 game.openTab(Game.TAB_MAGIC);
  243.                 break;
  244.             case Select:
  245.                 if (game.getCurrentTab() == Game.TAB_INVENTORY && spellSelected) {
  246.                     if (getNextLog().doClick(true)) {
  247.                         spellSelected = false;
  248.                         logCount--;
  249.                         plankCount++;
  250.                         invTries = 0;
  251.                         if (spell != null)
  252.                             mouse.move(new Point(spell.x
  253.                                     + random(3, spell.width - 3), spell.y
  254.                                     + random(3, spell.height - 3)));
  255.                     }
  256.                 } else if (invTries >= tabTries)
  257.                     game.openTab(Game.TAB_INVENTORY);
  258.                 else
  259.                     invTries++;
  260.                 break;
  261.             case Bank:
  262.                 if (logCount <= 0) {
  263.                     if (!bank.isOpen())
  264.                         bank.open();
  265.                     if (inventory.getCount() != inventory.getCount(AstralRune,
  266.                             NatRune, Coins))
  267.                         bank.depositAllExcept(AstralRune, NatRune, Coins,
  268.                                 EarthRune);
  269.                     sleep(500);
  270.                     Paint.logsLeft = bank.getCount(LogID);
  271.                     bank.withdraw(LogID, 0);
  272.                 }
  273.                 updateInv();
  274.                 bank.close();
  275.                 if (game.getCurrentTab() != Game.TAB_MAGIC) {
  276.                     game.openTab(Game.TAB_MAGIC);
  277.                     for (int i = 0; i < 100; i++) {
  278.                         sleep(20);
  279.                         if (game.getCurrentTab() == Game.TAB_MAGIC) {
  280.                             break;
  281.                         }
  282.                     }
  283.                     sleep(random(150, 250));
  284.                 }
  285.                 spellSelected = false;
  286.                 nextSlot = 0;
  287.                 break;
  288.             }
  289.         } catch (Exception e) {
  290.         }
  291.         return 250;
  292.     }
  293.  
  294.     public void onRepaint(Graphics render) {
  295.         Graphics2D g = (Graphics2D) render;
  296.         g.setColor(Color.GREEN);
  297.         g.draw(spell);
  298.  
  299.         g.setColor(Color.RED);
  300.         if (invItems != null)
  301.             if (nextSlot >= 0 && nextSlot < invItems.length)
  302.                 g.draw(invItems[nextSlot]);
  303.  
  304.         drawMouse.onRepaint(render);
  305.         if (Paint != null)
  306.             Paint.render(g);
  307.     }
  308.  
  309.     public RSItem getNextLog() {
  310.         RSItem[] inv = inventory.getItems();
  311.         // Checks for a plank, then a log, then a plank. Obvious skip.
  312.         for (int i = 1; i < inv.length - 1; i++) {
  313.             RSItem left = inv[i - 1];
  314.             RSItem right = inv[i + 1];
  315.             RSItem thisItem = inv[i];
  316.             if (left != null && right != null && thisItem != null
  317.                     && right.getID() == PlankID && left.getID() == PlankID
  318.                     && thisItem.getID() == LogID) {
  319.                 nextSlot = i + 1;
  320.                 return thisItem;
  321.             }
  322.         }
  323.         while (nextSlot < inv.length) {
  324.             if (nextSlot >= inv.length)
  325.                 nextSlot = 0;
  326.             else if (nextSlot < 0)
  327.                 nextSlot = 0;
  328.  
  329.             if (inv[nextSlot] == null || inv[nextSlot].getID() != LogID) {
  330.                 nextSlot++;
  331.                 continue;
  332.             } else {
  333.                 // all good
  334.                 nextSlot++;
  335.                 return inv[nextSlot - 1];
  336.             }
  337.         }
  338.         nextSlot = -1;
  339.         return null;
  340.     }
  341.  
  342.     /**
  343.      * Used to format data into more conventional formats
  344.      *
  345.      * @author Equinox_
  346.      *
  347.      */
  348.     public static class PaintFormatter {
  349.         /**
  350.          * Converts the first letter of every word to uppercase, and the rest
  351.          * lowercase.
  352.          *
  353.          * @param s
  354.          *            The input String
  355.          * @return the properly formatted string
  356.          */
  357.         public static String properCaseAll(String s) {
  358.             String[] words = s.split(" ");
  359.             String result = "";
  360.             for (int i = 0; i < words.length; i++) {
  361.                 String f = words[i].substring(0, 1).toUpperCase();
  362.                 words[i] = f + words[i].substring(1).toLowerCase();
  363.                 result += " " + words[i];
  364.             }
  365.             return result.substring(1);
  366.         }
  367.  
  368.         /**
  369.          * Capitalizes the first letter of every sentence, with every other
  370.          * letter lowercase.
  371.          *
  372.          * @param s
  373.          *            The input string
  374.          * @return The properly formatted String
  375.          */
  376.         public static String properCaseFirst(String s) {
  377.             String[] sentences = new String[] { s };
  378.             if (s.contains("."))
  379.                 sentences = s.split(".");
  380.             String result = "";
  381.             for (int i = 0; i < sentences.length; i++) {
  382.                 String f = sentences[i].substring(0, 1).toUpperCase();
  383.                 sentences[i] = f + sentences[i].substring(1).toLowerCase();
  384.                 result += " " + sentences[i];
  385.             }
  386.             return result.substring(1);
  387.         }
  388.  
  389.         /**
  390.          * Formats time to DD:HH:MM:SS:MSMS with days and millis optional
  391.          *
  392.          * @param timeMillis
  393.          *            long milliseconds of time
  394.          * @param sep
  395.          *            String seperation character
  396.          * @param millisInc
  397.          *            boolean include milliseconds
  398.          * @return
  399.          */
  400.         public static String getFormattedTime(final long timeMillis,
  401.                 String sep, boolean millisInc) {
  402.             long millis = timeMillis;
  403.             final long days = millis / (24 * 1000 * 60 * 60);
  404.             millis -= days * (24 * 1000 * 60 * 60);
  405.             final long hours = millis / (1000 * 60 * 60);
  406.             millis -= hours * 1000 * 60 * 60;
  407.             final long minutes = millis / (1000 * 60);
  408.             millis -= minutes * 1000 * 60;
  409.             final long _seconds = millis / 1000;
  410.             millis -= _seconds * 1000;
  411.             String dayString = String.valueOf(days);
  412.             String hoursString = String.valueOf(hours);
  413.             String minutesString = String.valueOf(minutes);
  414.             String secondsString = String.valueOf(_seconds);
  415.             if (hours < 10) {
  416.                 hoursString = 0 + hoursString;
  417.             }
  418.             if (minutes < 10) {
  419.                 minutesString = 0 + minutesString;
  420.             }
  421.             if (_seconds < 10) {
  422.                 secondsString = 0 + secondsString;
  423.             }
  424.             String s = "";
  425.             if (days > 0)
  426.                 s = dayString + sep;
  427.             s += hoursString + sep + minutesString + sep + secondsString;
  428.             if (millisInc)
  429.                 s += sep + String.valueOf(millis);
  430.             return s;
  431.         }
  432.  
  433.         /**
  434.          * Converts the milliseconds to DD:HH:MM:SS with the days optional.
  435.          *
  436.          * @param timeMillis
  437.          *            the number of milliseconds
  438.          * @return the properly formatted time as a String
  439.          */
  440.         public static String getFormattedTime(final long timeMillis) {
  441.             return getFormattedTime(timeMillis, ":", false);
  442.         }
  443.  
  444.         /**
  445.          * Formats a specified amount into thousands, millions or billions, then
  446.          * adds the proper suffix
  447.          *
  448.          * @param money
  449.          *            the amount of money
  450.          * @return the formatted string
  451.          */
  452.         public static String getFormattedMoney(long money) {
  453.             /*
  454.              * String suffix = ""; int t = 1; if (money >= 10000) { t *= 1000;
  455.              * suffix = "K"; } if (money / t > 10000) { t *= 1000; suffix = "M";
  456.              * } if (money / t > 10000) { t *= 1000; suffix = "B"; } return
  457.              * String.valueOf((money / t)) + suffix;
  458.              */
  459.             return new DecimalFormat("###,###,###,###,###,###").format(money);
  460.         }
  461.  
  462.         /**
  463.          * Converts an array of strings into one string, using commas and 'and' <br>
  464.          * <br>
  465.          * Examples: <br>
  466.          * {"option1"} returns "option1"<br>
  467.          * {"option1","option2"} returns "option1 and option2"<br>
  468.          * {"op1","op2","op3"} returns "op1, op2, and op3"<br>
  469.          * <br>
  470.          *
  471.          * @param list
  472.          *            The array of strings making up the list.
  473.          * @return The properly formatted string
  474.          */
  475.         public static String formatList(String[] list) {
  476.             String s = "";
  477.             if (list != null)
  478.                 if (list.length == 2) {
  479.                     s = list[0] + " and " + list[1];
  480.                 } else if (list.length > 2) {
  481.                     for (int i = 0; i < list.length - 1; i++)
  482.                         s += list[i] + ", ";
  483.                     s += "and " + list[list.length - 1];
  484.                 } else if (list.length == 1)
  485.                     s = list[0];
  486.             return s;
  487.         }
  488.     }
  489.  
  490.     /**
  491.      * A class used to represent the paint interface for this script
  492.      *
  493.      * @author Equinox_
  494.      *
  495.      */
  496.     public class PaintInterface {
  497.         // Constant
  498.         public final int[] SKILL_INTERFACES = { Skills.INTERFACE_ATTACK,
  499.                 Skills.INTERFACE_DEFENSE, Skills.INTERFACE_STRENGTH,
  500.                 Skills.INTERFACE_CONSTITUTION, Skills.INTERFACE_RANGE,
  501.                 Skills.INTERFACE_PRAYER, Skills.INTERFACE_MAGIC,
  502.                 Skills.INTERFACE_COOKING, Skills.INTERFACE_WOODCUTTING,
  503.                 Skills.INTERFACE_FLETCHING, Skills.INTERFACE_FISHING,
  504.                 Skills.INTERFACE_FIREMAKING, Skills.INTERFACE_CRAFTING,
  505.                 Skills.INTERFACE_SMITHING, Skills.INTERFACE_MINING,
  506.                 Skills.INTERFACE_HERBLORE, Skills.INTERFACE_AGILITY,
  507.                 Skills.INTERFACE_THIEVING, Skills.INTERFACE_SLAYER,
  508.                 Skills.INTERFACE_FARMING, Skills.INTERFACE_RUNECRAFTING,
  509.                 Skills.INTERFACE_HUNTER, Skills.INTERFACE_CONSTRUCTION,
  510.                 Skills.INTERFACE_SUMMONING, Skills.INTERFACE_DUNGEONEERING };
  511.  
  512.         // Paint data
  513.         public long startTime = 0;
  514.         public int startLevel;
  515.         public int startExp;
  516.         public int startCoins;
  517.         public int startAstrals;
  518.         public int startEarths;
  519.         public int startNatures;
  520.  
  521.         // Used info
  522.         public int usedCoins;
  523.         public int usedAstrals;
  524.         public int usedEarths;
  525.         public int usedNatures;
  526.  
  527.         // Price info
  528.         public int coinsPrice;
  529.         public int astralPrice;
  530.         public int earthPrice;
  531.         public int naturePrice;
  532.         public int plankPrice;
  533.         public int logPrice;
  534.  
  535.         // Remaining info
  536.         public int castsLeft;
  537.         public int logsLeft;
  538.         public int coinsLeft;
  539.  
  540.         // Goal
  541.         public int goalExp;
  542.         public int goalLevel;
  543.  
  544.         public int planksMade;
  545.  
  546.         // Images
  547.         public Map<String, Image> icons = new HashMap<String, Image>();
  548.  
  549.         public void putImage(String name, Image img) {
  550.             icons.put(name.toLowerCase(), img);
  551.         }
  552.  
  553.         public Image getImage(String name) {
  554.             if (icons.containsKey(name.toLowerCase()))
  555.                 return icons.get(name.toLowerCase());
  556.             return null;
  557.         }
  558.  
  559.         public FontRenderContext frc = new FontRenderContext(
  560.                 new AffineTransform(), false, false);
  561.  
  562.         public PaintStyle style = new PaintStyle();
  563.         public Point mouseLoc = new Point(0, 0);
  564.  
  565.         final EquinoxLunarPlanker planker;
  566.         final Logger log;
  567.         int SkillID = -1;
  568.         public Menu paintMenu;
  569.  
  570.         /**
  571.          * Constructs a PaintInterface using the provided parent and logger
  572.          * object and no skill progress bars
  573.          *
  574.          * @param planker
  575.          *            the parent NatCrafter
  576.          * @param log
  577.          *            the Logger object
  578.          */
  579.         public PaintInterface(EquinoxLunarPlanker planker, Logger log) {
  580.             this(planker, log, -1);
  581.         }
  582.  
  583.         /**
  584.          * Constructs a PaintInterface with the provided EquinoxLunarPlanker
  585.          * instance, Logger instance, and SkillID
  586.          *
  587.          * @param planker
  588.          *            EquinoxLunarPlanker
  589.          * @param log
  590.          *            Logger
  591.          * @param SkillID
  592.          *            int
  593.          */
  594.         public PaintInterface(EquinoxLunarPlanker planker, Logger log,
  595.                 int SkillID) {
  596.             this.planker = planker;
  597.             this.log = log;
  598.             this.SkillID = SkillID;
  599.             if (SkillID >= 0 && SkillID < Skills.SKILL_NAMES.length) {
  600.                 startExp = skills.getCurrentExp(SkillID);
  601.                 startTime = System.currentTimeMillis();
  602.                 startLevel = skills.getCurrentLevel(SkillID);
  603.                 setUpGoal();
  604.             }
  605.             init();
  606.         }
  607.  
  608.         /**
  609.          * Initializes paintMenu
  610.          */
  611.         public void init() {
  612.             RSComponent screen = interfaces.get(548).getComponent(3);
  613.             Point bottomRight = new Point(screen.getAbsoluteX()
  614.                     + screen.getWidth(), screen.getAbsoluteY()
  615.                     + screen.getHeight());
  616.             paintMenu = new Menu(this, bottomRight, Anchor.DOWN_RIGHT);
  617.             paintMenu.setFlowType(FlowType.HORIZONTAL);
  618.             paintMenu.addMouseListener(new MouseListen() {
  619.                 void MouseAction(MouseEvent e) {
  620.                     if (e.getID() == MouseEvent.MOUSE_CLICKED)
  621.                         paintMenu.toggleShowAll();
  622.                 }
  623.             });
  624.             if (SkillID >= 0 && SkillID < Skills.SKILL_NAMES.length) {
  625.                 MenuProgressBar progressBar = new MenuProgressBar("nextlvl",
  626.                         paintMenu, new GetPercent() {
  627.                             int getPercent() {
  628.                                 return skills.getPercentToNextLevel(SkillID);
  629.                             }
  630.                         }, "Next Level", new GetPopup() {
  631.                             MenuPopUp getPopUp() {
  632.                                 long millis = Math.abs(System
  633.                                         .currentTimeMillis() - startTime);
  634.                                 if (millis <= 0)
  635.                                     millis = 1;
  636.                                 long expGained = skills.getCurrentExp(SkillID)
  637.                                         - startExp;
  638.                                 long expPerHour = (expGained * 3600000l)
  639.                                         / millis;
  640.                                 String TTL = "";
  641.                                 int TTLunf = (int) ((expPerHour > 0) ? (((float) skills
  642.                                         .getExpToNextLevel(SkillID))
  643.                                         / ((float) expPerHour) * 3600000f) : 0);
  644.                                 if (TTLunf != 0)
  645.                                     TTL = PaintFormatter
  646.                                             .getFormattedTime(TTLunf);
  647.                                 else
  648.                                     TTL = "No exp gained";
  649.                                 String[] lines = new String[4];
  650.                                 lines[0] = "Exp gained: "
  651.                                         + PaintFormatter
  652.                                                 .getFormattedMoney(expGained);
  653.                                 lines[1] = "Exp per Hour: "
  654.                                         + PaintFormatter
  655.                                                 .getFormattedMoney(expPerHour);
  656.                                 lines[2] = "Exp 'till level: "
  657.                                         + PaintFormatter.getFormattedMoney(skills
  658.                                                 .getExpToNextLevel(SkillID));
  659.                                 lines[3] = "Time 'till level: " + TTL;
  660.                                 return new MenuPopUp(lines, "nextlevel");
  661.                             }
  662.  
  663.                         });
  664.                 paintMenu.add(progressBar);
  665.  
  666.                 if (goalExp > skills.getCurrentExp(SkillID)) {
  667.                     MenuProgressBar goalBar = new MenuProgressBar("goal",
  668.                             paintMenu, new GetPercent() {
  669.                                 int getPercent() {
  670.                                     float expTillGoalStart = goalExp - startExp;
  671.                                     double expGained = skills
  672.                                             .getCurrentExp(SkillID) - startExp;
  673.                                     double result = expGained
  674.                                             / expTillGoalStart;
  675.                                     if (result > 1)
  676.                                         result = 1;
  677.                                     if (result < 0)
  678.                                         result = 0;
  679.                                     return (int) (result * 100);
  680.                                 }
  681.                             }, "Goal", new GetPopup() {
  682.                                 MenuPopUp getPopUp() {
  683.                                     long millis = Math.abs(System
  684.                                             .currentTimeMillis() - startTime);
  685.                                     if (millis <= 0)
  686.                                         millis = 1;
  687.                                     long expGained = skills
  688.                                             .getCurrentExp(SkillID) - startExp;
  689.                                     long expPerHour = (expGained * 3600000l)
  690.                                             / millis;
  691.                                     int expTillGoal = goalExp
  692.                                             - skills.getCurrentExp(SkillID);
  693.                                     String TTG = "";
  694.                                     int TTGunf = (int) ((expPerHour > 0) ? (((float) expTillGoal)
  695.                                             / ((float) expPerHour) * 3600000f)
  696.                                             : 0);
  697.                                     if (TTGunf != 0)
  698.                                         TTG = PaintFormatter
  699.                                                 .getFormattedTime(TTGunf);
  700.                                     else
  701.                                         TTG = "No exp gained";
  702.                                     String[] lines = new String[goalLevel > 0 ? 6
  703.                                             : 5];
  704.                                     int off = goalLevel > 0 ? 1 : 0;
  705.                                     if (goalLevel > 0)
  706.                                         lines[0] = "Goal Level: " + goalLevel;
  707.                                     lines[0 + off] = "Goal Exp: "
  708.                                             + PaintFormatter
  709.                                                     .getFormattedMoney(goalExp);
  710.                                     lines[1 + off] = "Exp gained: "
  711.                                             + PaintFormatter
  712.                                                     .getFormattedMoney(expGained);
  713.                                     lines[2 + off] = "Exp per Hour: "
  714.                                             + PaintFormatter
  715.                                                     .getFormattedMoney(expPerHour);
  716.                                     lines[3 + off] = "Exp 'till goal: "
  717.                                             + PaintFormatter
  718.                                                     .getFormattedMoney(expTillGoal);
  719.                                     lines[4 + off] = "Time 'till goal: " + TTG;
  720.                                     return new MenuPopUp(lines, "goalbar");
  721.                                 }
  722.  
  723.                             });
  724.                     paintMenu.add(goalBar);
  725.                 }
  726.             }
  727.  
  728.             // Actual buttons:
  729.             MenuButton planks = new MenuButton("planks", paintMenu,
  730.                     "plankicon", new GetPopup() {
  731.                         MenuPopUp getPopUp() {
  732.                             long millis = Math.abs(System.currentTimeMillis()
  733.                                     - startTime);
  734.                             if (millis <= 0)
  735.                                 millis = 1;
  736.                             int planksPerHour = (int) ((planksMade * 3600000l) / millis);
  737.                             int costPerCastR = 2 * astralPrice + naturePrice
  738.                                     + (hasEarthStaff ? 0 : 15 * earthPrice);
  739.                             int costPerCastLC = logPrice + coinsPerPlank;
  740.                             int costPerCast = costPerCastLC + costPerCastR;
  741.                             int profit = (plankPrice - costPerCast)
  742.                                     * planksMade;
  743.                             int profitPhour = (int) ((profit * 3600000l) / millis);
  744.                             int totalCastsLeft = Math.min(
  745.                                     Math.min(logsLeft, castsLeft), coinsLeft);
  746.                             String[] lines = new String[totalCastsLeft > 0 ? 9
  747.                                     : 7];
  748.                             lines[0] = "Planks made: " + planksMade;
  749.                             lines[1] = "Planks per hour: " + planksPerHour;
  750.                             lines[2] = "Cost per cast: " + costPerCast;
  751.                             lines[3] = "Price of plank: " + plankPrice;
  752.                             lines[4] = "Profit per cast: "
  753.                                     + (costPerCast - plankPrice);
  754.                             lines[5] = "Profit: "
  755.                                     + PaintFormatter.getFormattedMoney(profit);
  756.                             lines[6] = "Profit per hour: " + profitPhour;
  757.                             if (totalCastsLeft > 0) {
  758.                                 String timeTillCastsOut = PaintFormatter
  759.                                         .getFormattedTime((long) (((double) totalCastsLeft) / (((double) planksMade) / ((double) millis))));
  760.                                 lines[7] = "Casts remaining: " + totalCastsLeft;
  761.                                 lines[8] = "No materials in: "
  762.                                         + timeTillCastsOut;
  763.                             }
  764.  
  765.                             return new MenuPopUp(lines, "planks");
  766.  
  767.                         }
  768.                     });
  769.             paintMenu.add(planks);
  770.  
  771.             MenuButton home = new MenuButton("home", paintMenu, "homeicon",
  772.                     new GetPopup() {
  773.                         MenuPopUp getPopUp() {
  774.                             long millis = Math.abs(System.currentTimeMillis()
  775.                                     - startTime);
  776.                             if (millis <= 0)
  777.                                 millis = 1;
  778.                             String[] lines = new String[5];
  779.                             lines[0] = planker.name;
  780.                             lines[1] = "By: " + planker.author;
  781.                             lines[2] = "Version " + planker.VERSION;
  782.                             lines[3] = "Runtime: "
  783.                                     + PaintFormatter.getFormattedTime(millis);
  784.                             lines[4] = PaintFormatter.properCaseAll(planker
  785.                                     .getState().name().replace("_", " "));
  786.                             return new MenuPopUp(lines, "home");
  787.                         }
  788.                     });
  789.             paintMenu.add(home);
  790.  
  791.             MenuButton tools = new MenuButton("tools", paintMenu, "toolsicon",
  792.                     new GetPopup() {
  793.                         MenuPopUp getPopUp() {
  794.                             MenuPopUp popUp = new MenuPopUp(new String[] {
  795.                                     "Save proggie", "Reload data" }, "tools");
  796.                             popUp.addLineListener(new LineListener() {
  797.                                 void fireEvent(MouseEvent e, String line) {
  798.                                     line = line.toLowerCase().trim();
  799.                                     if (e.getID() == MouseEvent.MOUSE_CLICKED) {
  800.                                         if (line.contains("save proggie"))
  801.                                             paintMenu.saveProggie();
  802.                                         else if (line.contains("reload data"))
  803.                                             new DataLoader(planker);
  804.                                     }
  805.                                 }
  806.  
  807.                                 boolean hasAction(String line) {
  808.                                     line = line.toLowerCase().trim();
  809.                                     return (line.contains("save proggie"))
  810.                                             || (line.contains("reload data"));
  811.                                 }
  812.                             });
  813.                             return popUp;
  814.                         }
  815.                     });
  816.             paintMenu.add(tools);
  817.  
  818.             paintMenu.compile();
  819.         }
  820.  
  821.         /**
  822.          * Gets the current Goal for the setSkill, or sets all goal variables to
  823.          * -1 if there is no goal
  824.          */
  825.         public void setUpGoal() {
  826.             try {
  827.                 for (byte b = 0; b < 10; b++)
  828.                     if (game.getCurrentTab() != Game.TAB_STATS) {
  829.                         game.openTab(Game.TAB_STATS);
  830.                         sleep(1000);
  831.                     } else
  832.                         break;
  833.  
  834.                 RSInterface stats = interfaces.get(320);
  835.                 if (stats != null && stats.isValid()) {
  836.                     RSComponent mage = stats
  837.                             .getComponent(SKILL_INTERFACES[SkillID]);
  838.                     if (mage != null && mage.isValid()
  839.                             && mage.getArea() != null) {
  840.                         mouse.move((int) mage.getArea().getCenterX(),
  841.                                 (int) mage.getArea().getCenterY());
  842.                         sleep(500, 750);
  843.                         // Now we see what the popup is doing
  844.                         RSComponent pop = stats.getComponent(202);
  845.                         if (pop != null && pop.isValid()) {
  846.                             RSComponent def = pop.getComponent(5);
  847.                             if (def != null && def.isValid()) {
  848.                                 if (def.getText().trim()
  849.                                         .equalsIgnoreCase("Target XP:")) {
  850.                                     RSComponent goalXP = pop.getComponent(6);
  851.                                     if (goalXP != null && goalXP.isValid()) {
  852.                                         goalExp = Integer.valueOf(goalXP
  853.                                                 .getText().replace(",", "")
  854.                                                 .trim());
  855.                                         goalLevel = -1;
  856.                                     }
  857.                                 } else {
  858.                                     // Proceed
  859.                                     RSComponent currExp = pop.getComponent(4);
  860.                                     RSComponent goalRemainder = pop
  861.                                             .getComponent(12);
  862.                                     RSComponent goalLvl = pop.getComponent(10);
  863.                                     if (currExp != null && currExp.isValid()
  864.                                             && goalRemainder != null
  865.                                             && goalRemainder.isValid()
  866.                                             && goalLvl != null
  867.                                             && goalLvl.isValid()) {
  868.                                         goalExp = Integer.valueOf(currExp
  869.                                                 .getText().replace(",", "")
  870.                                                 .trim())
  871.                                                 + Integer.valueOf(goalRemainder
  872.                                                         .getText()
  873.                                                         .replace(",", "")
  874.                                                         .trim());
  875.                                         goalLevel = Integer.valueOf(goalLvl
  876.                                                 .getText().replace(",", "")
  877.                                                 .trim());
  878.                                     }
  879.                                 }
  880.                                 log.info("Target level: "
  881.                                         + (goalLevel > 0 ? goalLevel : "None"));
  882.                                 log.info("Target exp: "
  883.                                         + (goalExp > 0 ? goalExp : "None"));
  884.                                 return;
  885.                             }
  886.                         }
  887.                     }
  888.                 }
  889.             } catch (Exception e) {
  890.             }
  891.             goalExp = -1;
  892.             goalLevel = -1;
  893.         }
  894.  
  895.         /**
  896.          * Renders the current paint to the given graphics context.
  897.          *
  898.          * @param g
  899.          *            as the Graphics2D object to render to
  900.          */
  901.         public void render(Graphics2D g) {
  902.             paintMenu.render(g, mouseLoc);
  903.             int mouseX = mouseLoc.x;
  904.             int mouseY = mouseLoc.y;
  905.             g.setColor(Color.RED);
  906.             g.drawLine(mouseX - 5, mouseY - 5, mouseX + 5, mouseY + 5);
  907.             g.drawLine(mouseX - 5, mouseY + 5, mouseX + 5, mouseY - 5);
  908.         }
  909.  
  910.         /**
  911.          * Fires a MouseEvent in the paintMenu
  912.          *
  913.          * @param e
  914.          *            MouseEvent
  915.          */
  916.         public void fireMouseEvent(MouseEvent e) {
  917.             if (paintMenu.getBoundsFull().contains(e.getPoint()))
  918.                 paintMenu.fireMouseEvent(e);
  919.         }
  920.  
  921.         /**
  922.          * Represents a Menu on a PaintInterface
  923.          *
  924.          * @author Equinox_
  925.          *
  926.          */
  927.         public class Menu {
  928.             final int padding = 1;
  929.             Point location;
  930.             PaintInterface parent;
  931.             PaintStyle style;
  932.             List<MenuItem> components = new ArrayList<MenuItem>();
  933.             final Anchor anchor;
  934.             boolean showAllPopups;
  935.             MenuPopUp visiblePopup = null;
  936.             List<MouseListen> mouseListeners;
  937.             LineListener defaultLineListener;
  938.             private FlowType flowType = FlowType.HORIZONTAL;
  939.             public Dimension bounds;
  940.  
  941.             /**
  942.              * Constructs a Menu using the provided PaintInterface, Location,
  943.              * Anchor, and the GameScreen as the bounds
  944.              *
  945.              * @param parent
  946.              *            PaintInterface
  947.              * @param location
  948.              *            Point
  949.              * @param anchor
  950.              *            Anchor
  951.              */
  952.             public Menu(PaintInterface parent, Point location, Anchor anchor) {
  953.                 this.parent = parent;
  954.                 this.style = parent.style;
  955.                 this.location = location;
  956.                 this.anchor = anchor;
  957.  
  958.                 // Setup dimension
  959.                 Rectangle r = interfaces.get(548).getComponent(3).getArea();
  960.                 bounds = new Dimension(r.width, r.height);
  961.             }
  962.  
  963.             /**
  964.              * Sets the FlowType and recompiles the menu
  965.              *
  966.              * @param flowType
  967.              *            FlowType
  968.              */
  969.             public void setFlowType(FlowType flowType) {
  970.                 this.flowType = flowType;
  971.                 this.compile();
  972.             }
  973.  
  974.             /**
  975.              * Gets the FlowType
  976.              *
  977.              * @return FlowType
  978.              */
  979.             public FlowType getFlowType() {
  980.                 return flowType;
  981.             }
  982.  
  983.             /**
  984.              * Toggles the showAllPopups state
  985.              * */
  986.             public void toggleShowAll() {
  987.                 showAllPopups = !showAllPopups;
  988.             }
  989.  
  990.             /**
  991.              * Constructs a menu using the provided parent and location,
  992.              * assuming Anchor.UP_LEFT
  993.              *
  994.              * @param parent
  995.              *            PaintInterface
  996.              * @param location
  997.              *            Point
  998.              */
  999.             public Menu(PaintInterface parent, Point location) {
  1000.                 this(parent, location, Anchor.UP_LEFT);
  1001.             }
  1002.  
  1003.             /**
  1004.              * Adds the specified menu item
  1005.              *
  1006.              * @param i
  1007.              *            MenuItem
  1008.              */
  1009.             public void add(MenuItem i) {
  1010.                 i.setIndex(components.size());
  1011.                 components.add(i);
  1012.                 compile();
  1013.             }
  1014.  
  1015.             /**
  1016.              * Compiles this menu
  1017.              */
  1018.             public void compile() {
  1019.                 for (int i = 0; i < components.size(); i++)
  1020.                     components.get(i).compile();
  1021.             }
  1022.  
  1023.             /**
  1024.              * Gets position x based on the menu's anchor
  1025.              *
  1026.              * @return int
  1027.              */
  1028.             public int getAbsX() {
  1029.                 if (anchor.name().contains("LEFT"))
  1030.                     return location.x;
  1031.                 else
  1032.                     return location.x - getWidth();
  1033.             }
  1034.  
  1035.             /**
  1036.              * Gets position y based on the menu's anchor
  1037.              *
  1038.              * @return int
  1039.              */
  1040.             public int getAbsY() {
  1041.                 if (anchor.name().contains("UP"))
  1042.                     return location.y;
  1043.                 else
  1044.                     return location.y - getHeight();
  1045.             }
  1046.  
  1047.             /**
  1048.              * Gets the maximum width of this menu using the menu's FlowType
  1049.              *
  1050.              * @return int
  1051.              */
  1052.             public int getWidth() {
  1053.                 if (flowType.equals(FlowType.HORIZONTAL)) {
  1054.                     int width = padding * components.size();
  1055.                     for (MenuItem m : components)
  1056.                         if (m.bounds != null)
  1057.                             width += m.bounds.width;
  1058.                     return width + padding;
  1059.                 } else {
  1060.                     int max = Integer.MIN_VALUE;
  1061.                     for (MenuItem m : components)
  1062.                         if (m.bounds != null)
  1063.                             if (max < m.bounds.width)
  1064.                                 max = (int) m.bounds.width;
  1065.                     return max + (2 * padding);
  1066.                 }
  1067.             }
  1068.  
  1069.             /**
  1070.              * Gets the maximum height of this menu based of FlowType
  1071.              *
  1072.              * @return int
  1073.              */
  1074.             public int getHeight() {
  1075.                 if (flowType.equals(FlowType.HORIZONTAL)) {
  1076.                     int max = Integer.MIN_VALUE;
  1077.                     for (MenuItem m : components)
  1078.                         if (m.bounds != null)
  1079.                             if (max < m.bounds.height)
  1080.                                 max = (int) m.bounds.height;
  1081.                     return max + (2 * padding);
  1082.                 } else {
  1083.                     int height = padding * components.size();
  1084.                     for (MenuItem m : components)
  1085.                         if (m.bounds != null)
  1086.                             height += m.bounds.height;
  1087.                     return height + padding;
  1088.                 }
  1089.             }
  1090.  
  1091.             /**
  1092.              * Gets the current bounds of this menu, with rounded corners if
  1093.              * specified
  1094.              *
  1095.              * @param rounded
  1096.              *            boolean
  1097.              * @return RoundRectangle2D.Float
  1098.              */
  1099.             public RoundRectangle2D.Float getArea(boolean rounded) {
  1100.                 float round = rounded ? style.roundCorner : 0;
  1101.                 return new RoundRectangle2D.Float(getAbsX(), getAbsY(),
  1102.                         getWidth(), getHeight(), round, round);
  1103.             }
  1104.  
  1105.             public Rectangle getBoundsFull() {
  1106.                 RoundRectangle2D r1 = getArea(false);
  1107.                 RoundRectangle2D r2 = visiblePopup != null ? visiblePopup.bkg
  1108.                         : getArea(false);
  1109.                 int x = (int) Math.min(r1.getX(), r2.getX());
  1110.                 int y = (int) Math.min(r1.getY(), r2.getY());
  1111.                 int width = (int) Math.max(r1.getX() + r1.getWidth(), r2.getX()
  1112.                         + r2.getWidth())
  1113.                         - x;
  1114.                 int height = (int) Math.max(r1.getX() + r1.getHeight(),
  1115.                         r2.getX() + r2.getHeight())
  1116.                         - y;
  1117.                 return new Rectangle(x, y, width, height);
  1118.             }
  1119.  
  1120.             /**
  1121.              * Renders the menu to the specified Graphics object using the
  1122.              * provided mouse location for any popups
  1123.              *
  1124.              * @param g
  1125.              *            Graphics2D
  1126.              * @param mouseLoc
  1127.              *            Point
  1128.              */
  1129.             public void render(Graphics2D g, Point mouseLoc) {
  1130.                 g.setColor(style.bgColor);
  1131.                 g.fill(getArea(true));
  1132.                 MenuPopUp overPopup = null;
  1133.                 for (MenuItem m : components) {
  1134.                     m.render(g);
  1135.                     MenuPopUp p = m.getPopUp();
  1136.                     if (p != null) {
  1137.                         if (m.bounds.contains(mouseLoc)
  1138.                                 || (m.getPopUp().name
  1139.                                         .equalsIgnoreCase(visiblePopup != null ? visiblePopup.name
  1140.                                                 : "") && rectangleContainsApprox(
  1141.                                         visiblePopup.bkg, mouseLoc)))
  1142.                             overPopup = m.getPopUp();
  1143.                     }
  1144.                 }
  1145.                 if (showAllPopups)
  1146.                     getAllPopups(true).render(g);
  1147.                 else if (overPopup != null) {
  1148.                     overPopup.render(g);
  1149.                 }
  1150.                 visiblePopup = overPopup;
  1151.             }
  1152.  
  1153.             /**
  1154.              * Check if the specified point is within sqrt(2) of the Rectangle
  1155.              *
  1156.              * @param r
  1157.              *            RoundRectangle2D
  1158.              * @param p
  1159.              *            Point
  1160.              * @return boolean contains
  1161.              */
  1162.             public boolean rectangleContainsApprox(RoundRectangle2D r, Point p) {
  1163.                 for (int oX = -1; oX <= 1; oX++)
  1164.                     for (int oY = -1; oY <= 1; oY++)
  1165.                         if (r.contains(new Point(p.x + oX, p.y + oY)))
  1166.                             return true;
  1167.                 return false;
  1168.             }
  1169.  
  1170.             /**
  1171.              * Gets all popups in frontToBack or backToFront order and excluding
  1172.              * specified names
  1173.              *
  1174.              * @param rightToLeft
  1175.              *            boolean
  1176.              * @param excludeItems
  1177.              *            String...
  1178.              * @return MenuPopUp
  1179.              */
  1180.             public MenuPopUp getAllPopups(boolean backToFront,
  1181.                     String... excludeItems) {
  1182.                 List<String> lines = new ArrayList<String>();
  1183.                 if (components.size() > 0)
  1184.                     if (backToFront)
  1185.                         for (int i = components.size() - 1; i >= 0; i--) {
  1186.                             boolean ignored = false;
  1187.                             for (String subS : excludeItems)
  1188.                                 if (components.get(i).name
  1189.                                         .equalsIgnoreCase(subS))
  1190.                                     ignored = true;
  1191.                             if (!ignored) {
  1192.                                 MenuPopUp sub = components.get(i).getPopUp();
  1193.                                 if (sub != null)
  1194.                                     for (String line : sub.lines)
  1195.                                         if (!containsLine(lines, line))
  1196.                                             lines.add(line);
  1197.                             }
  1198.                         }
  1199.                     else
  1200.                         for (int i = 0; i < components.size(); i++) {
  1201.                             boolean ignored = false;
  1202.                             for (String subS : excludeItems)
  1203.                                 if (components.get(i).name
  1204.                                         .equalsIgnoreCase(subS))
  1205.                                     ignored = true;
  1206.                             if (!ignored) {
  1207.                                 MenuPopUp sub = components.get(i).getPopUp();
  1208.                                 if (sub != null)
  1209.                                     for (String line : sub.lines)
  1210.                                         if (!containsLine(lines, line))
  1211.                                             lines.add(line);
  1212.                             }
  1213.                         }
  1214.  
  1215.                 String[] linesArr = new String[lines.size()];
  1216.                 for (int i = 0; i < lines.size(); i++)
  1217.                     linesArr[i] = lines.get(i);
  1218.                 MenuPopUp p = new MenuPopUp(linesArr, "allpopups");
  1219.                 p.setParent(components.get(components.size() - 1));
  1220.                 return p;
  1221.             }
  1222.  
  1223.             /**
  1224.              * Checks if the specified array contains the specified line, just
  1225.              * the tag, not the data if possible
  1226.              *
  1227.              * @param lines
  1228.              *            List of Strings
  1229.              * @param line
  1230.              *            String
  1231.              * @return boolean contains
  1232.              */
  1233.             public boolean containsLine(List<String> lines, String line) {
  1234.                 for (String s : lines)
  1235.                     if (s.contains(":") && line.contains(":")) {
  1236.                         if (s.split(":")[0]
  1237.                                 .equalsIgnoreCase(line.split(":")[0]))
  1238.                             return true;
  1239.                     } else if (s.equalsIgnoreCase(line))
  1240.                         return true;
  1241.                 return false;
  1242.             }
  1243.  
  1244.             /**
  1245.              * Gets a proggie as a BufferedImage
  1246.              *
  1247.              * @return BufferedImage proggie
  1248.              */
  1249.             public BufferedImage getProggie() {
  1250.                 String[] lines = getAllPopups(true, "tools").lines;
  1251.                 Color color = style.FONT_COLOR;
  1252.                 Font font = style.FONT;
  1253.                 float line_height = font.getLineMetrics(lines[0], Paint.frc)
  1254.                         .getHeight();
  1255.                 int width = 0;
  1256.                 for (String line : lines)
  1257.                     if (font.getStringBounds(line, Paint.frc).getWidth() > width)
  1258.                         width = (int) font.getStringBounds(line, Paint.frc)
  1259.                                 .getWidth();
  1260.  
  1261.                 int height = (int) (lines.length * line_height);
  1262.  
  1263.                 width += style.roundCorner + 2;
  1264.                 height += style.roundCorner + 2;
  1265.  
  1266.                 RoundRectangle2D.Float bkg = new RoundRectangle2D.Float(0, 0,
  1267.                         width, height,
  1268.                         style.roundCorner > 0 ? style.roundCorner + 1 : 0,
  1269.                         style.roundCorner > 0 ? style.roundCorner + 1 : 0);
  1270.                 RoundRectangle2D.Float fg = new RoundRectangle2D.Float(
  1271.                         (float) bkg.getX() + 1, (float) bkg.getY() + 1,
  1272.                         width - 2, height - 2, style.roundCorner,
  1273.                         style.roundCorner);
  1274.                 Rectangle txtBounds = new Rectangle(
  1275.                         (int) (fg.getX() + (style.roundCorner / 2)),
  1276.                         (int) (fg.getY() + (style.roundCorner / 2)),
  1277.                         (int) (width - style.roundCorner - 2), (int) (height
  1278.                                 - style.roundCorner - 2));
  1279.                 BufferedImage bImg = new BufferedImage(width, height,
  1280.                         BufferedImage.TYPE_INT_ARGB);
  1281.                 Graphics2D g = (Graphics2D) bImg.getGraphics();
  1282.                 g.setColor(style.bgColor);
  1283.                 g.fill(bkg);
  1284.                 g.setColor(style.fgColor);
  1285.                 g.fill(fg);
  1286.                 g.setFont(font);
  1287.                 g.setColor(color);
  1288.                 for (int i = 0; i < lines.length; i++)
  1289.                     g.drawString(lines[i], txtBounds.x,
  1290.                             ((i + 1) * (line_height)) + txtBounds.y);
  1291.                 return bImg;
  1292.             }
  1293.  
  1294.             /**
  1295.              * Saves a progress report to the Screenshots directory
  1296.              */
  1297.             public void saveProggie() {
  1298.                 String name = planker.name
  1299.                         + "_"
  1300.                         + PaintFormatter.getFormattedTime(
  1301.                                 System.currentTimeMillis() - Paint.startTime,
  1302.                                 "-", true);
  1303.                 final File dir = new File(
  1304.                         GlobalConfiguration.Paths.getScreenshotsDirectory());
  1305.                 if (dir.isDirectory() || dir.mkdirs()) {
  1306.                     try {
  1307.                         int ext = 0;
  1308.                         while (new File(dir, name
  1309.                                 + (ext > 0 ? ("(" + ext + ")") : "") + ".png")
  1310.                                 .exists())
  1311.                             ext++;
  1312.  
  1313.                         ImageIO.write(Paint.paintMenu.getProggie(), "png",
  1314.                                 new File(dir, name
  1315.                                         + (ext > 0 ? ("(" + ext + ")") : "")));
  1316.                         log.info("Saved proggie!");
  1317.                         log.info(new File(dir, name
  1318.                                 + (ext > 0 ? ("(" + ext + ")") : "") + ".png")
  1319.                                 .getAbsolutePath());
  1320.                     } catch (IOException e) {
  1321.                         log.severe("Failed to save proggie!");
  1322.                     }
  1323.                 }
  1324.             }
  1325.  
  1326.             /**
  1327.              * Adds the specified mouse listener
  1328.              *
  1329.              * @param listen
  1330.              *            MouseListen
  1331.              */
  1332.             public void addMouseListener(MouseListen listen) {
  1333.                 if (mouseListeners == null)
  1334.                     mouseListeners = new ArrayList<MouseListen>();
  1335.                 mouseListeners.add(listen);
  1336.             }
  1337.  
  1338.             /**
  1339.              * Sets the default line listener
  1340.              *
  1341.              * @param listen
  1342.              *            LineListener
  1343.              */
  1344.             public void setDefaultLineListener(LineListener listen) {
  1345.                 defaultLineListener = listen;
  1346.             }
  1347.  
  1348.             /**
  1349.              * Fires the MouseEvent in all containing children and this
  1350.              *
  1351.              * @param e
  1352.              *            MouseEvent
  1353.              */
  1354.             public void fireMouseEvent(MouseEvent e) {
  1355.                 if (getArea(true).contains(e.getPoint()))
  1356.                     if (mouseListeners != null)
  1357.                         for (MouseListen m : mouseListeners)
  1358.                             m.MouseAction(e);
  1359.                 for (MenuItem m : components)
  1360.                     if (m.bounds != null)
  1361.                         if (m.bounds.contains(e.getPoint()))
  1362.                             m.fireMouseEvent(e);
  1363.                 if (visiblePopup != null)
  1364.                     visiblePopup.fireMouseEvent(e);
  1365.  
  1366.             }
  1367.         }
  1368.  
  1369.         /**
  1370.          * Represents a class containing the method for getting the popup
  1371.          *
  1372.          * @author Equinox_
  1373.          *
  1374.          */
  1375.         public abstract class GetPopup {
  1376.             abstract MenuPopUp getPopUp();
  1377.         }
  1378.  
  1379.         /**
  1380.          * Represents a modified MouseListener used in MenuEvents
  1381.          *
  1382.          * @author Equinox_
  1383.          *
  1384.          */
  1385.         public abstract class MouseListen {
  1386.             abstract void MouseAction(MouseEvent e);
  1387.         }
  1388.  
  1389.         /**
  1390.          * An abstract class representing MenuItems
  1391.          *
  1392.          * @author Equinox_
  1393.          *
  1394.          */
  1395.         public abstract class MenuItem {
  1396.             final GetPopup getPopup;
  1397.             Menu parent;
  1398.             RoundRectangle2D.Float bounds;
  1399.             int index;
  1400.             final int width;
  1401.             final int height;
  1402.             List<MouseListen> mouseListeners;
  1403.             final String name;
  1404.  
  1405.             /**
  1406.              * Constructs a MenuItem with the given name, parent, getPopup
  1407.              * method, width and height
  1408.              *
  1409.              * @param name
  1410.              *            String
  1411.              * @param parent
  1412.              *            Menu
  1413.              * @param getPopup
  1414.              *            GetPopup
  1415.              * @param width
  1416.              *            int
  1417.              * @param height
  1418.              *            int
  1419.              */
  1420.             public MenuItem(String name, Menu parent, GetPopup getPopup,
  1421.                     int width, int height) {
  1422.                 this.name = name;
  1423.                 this.height = height;
  1424.                 this.width = width;
  1425.                 this.getPopup = getPopup;
  1426.                 this.parent = parent;
  1427.                 this.bounds = new RoundRectangle2D.Float(0, 0, width, height,
  1428.                         parent.style.roundCorner, parent.style.roundCorner);
  1429.             }
  1430.  
  1431.             /**
  1432.              * Constructs a MenuItem with the given name, parent, width and
  1433.              * height
  1434.              *
  1435.              * @param name
  1436.              *            String
  1437.              * @param parent
  1438.              *            Menu
  1439.              * @param width
  1440.              *            int
  1441.              * @param height
  1442.              *            int
  1443.              */
  1444.             public MenuItem(String name, Menu parent, int width, int height) {
  1445.                 this(name, parent, null, width, height);
  1446.             }
  1447.  
  1448.             /**
  1449.              * sets this item's index
  1450.              *
  1451.              * @param idx
  1452.              *            int
  1453.              */
  1454.             public void setIndex(int idx) {
  1455.                 this.index = idx;
  1456.             }
  1457.  
  1458.             /**
  1459.              * renders this item to the given Graphics2D
  1460.              *
  1461.              * @param g
  1462.              *            Graphics2D
  1463.              */
  1464.             abstract void render(Graphics2D g);
  1465.  
  1466.             /**
  1467.              * Compiles this item
  1468.              */
  1469.             public void compile() {
  1470.                 this.bounds = new RoundRectangle2D.Float(0, 0, width, height,
  1471.                         parent.style.roundCorner, parent.style.roundCorner);
  1472.                 bounds.x = getX();
  1473.                 bounds.y = getY();
  1474.             }
  1475.  
  1476.             /**
  1477.              * Gets the offset from upper left of parent depending on parent's
  1478.              * FlowType
  1479.              *
  1480.              * @return int offsetY
  1481.              */
  1482.             public int getOffX() {
  1483.                 if (parent.getFlowType().equals(FlowType.HORIZONTAL)) {
  1484.                     int x = 1;
  1485.                     for (int i = 0; i < index; i++)
  1486.                         x += 1 + parent.components.get(i).bounds.width;
  1487.  
  1488.                     return x;
  1489.                 }
  1490.                 if (parent.getWidth() > bounds.width)
  1491.                     return (int) (parent.getWidth() / 2 - bounds.width / 2);
  1492.                 return 1;
  1493.             }
  1494.  
  1495.             /**
  1496.              * Gets the offset from upper left of parent depending on parent's
  1497.              * FlowType
  1498.              *
  1499.              * @return int offsetX
  1500.              */
  1501.             public int getOffY() {
  1502.                 if (parent.getFlowType().equals(FlowType.VERTICAL)) {
  1503.                     int y = 1;
  1504.                     for (int i = 0; i < index; i++)
  1505.                         y += 1 + parent.components.get(i).bounds.height;
  1506.  
  1507.                     return y;
  1508.                 }
  1509.                 return 1;
  1510.             }
  1511.  
  1512.             /**
  1513.              * Gets the absolute x
  1514.              *
  1515.              * @return int absolute x
  1516.              */
  1517.             public int getX() {
  1518.                 int x = getOffX() + parent.getAbsX();
  1519.                 return x;
  1520.             }
  1521.  
  1522.             /**
  1523.              * Gets the absolute y
  1524.              *
  1525.              * @return int absolute y
  1526.              */
  1527.             public int getY() {
  1528.                 int y = getOffY() + parent.getAbsY();
  1529.                 return y;
  1530.             }
  1531.  
  1532.             /**
  1533.              * Gets this item's popup
  1534.              *
  1535.              * @return MenuPopUp
  1536.              */
  1537.             public MenuPopUp getPopUp() {
  1538.                 if (getPopup != null) {
  1539.                     MenuPopUp m = getPopup.getPopUp();
  1540.                     m.setParent(this);
  1541.                     if (parent.defaultLineListener != null)
  1542.                         m.addLineListener(parent.defaultLineListener);
  1543.                     return m;
  1544.                 }
  1545.                 return null;
  1546.             }
  1547.  
  1548.             /**
  1549.              * Adds a mouselistener
  1550.              *
  1551.              * @param listen
  1552.              *            MouseListen
  1553.              */
  1554.             public void addMouseListener(MouseListen listen) {
  1555.                 if (mouseListeners == null)
  1556.                     mouseListeners = new ArrayList<MouseListen>();
  1557.                 mouseListeners.add(listen);
  1558.             }
  1559.  
  1560.             /**
  1561.              * Sends the mouse event to all of this item's listeners
  1562.              *
  1563.              * @param e
  1564.              *            MouseEvent
  1565.              */
  1566.             public void fireMouseEvent(MouseEvent e) {
  1567.                 if (mouseListeners != null && mouseListeners.size() > 0)
  1568.                     for (MouseListen m : mouseListeners)
  1569.                         m.MouseAction(e);
  1570.             }
  1571.         }
  1572.  
  1573.         /**
  1574.          * A class representing a mouse over button on the parent menu
  1575.          *
  1576.          * @author Equinox_
  1577.          *
  1578.          */
  1579.         public class MenuButton extends MenuItem {
  1580.             final static int width = 30;
  1581.             final static int height = 30;
  1582.  
  1583.             String imageIcon;
  1584.  
  1585.             /**
  1586.              * Constructs a button using the specified name, parent, imageIcon,
  1587.              * and getPopup method.
  1588.              *
  1589.              * @param name
  1590.              *            String
  1591.              * @param parent
  1592.              *            Menu
  1593.              * @param imageIcon
  1594.              *            String
  1595.              * @param getPopUp
  1596.              *            GetPopup
  1597.              */
  1598.             public MenuButton(String name, Menu parent, String imageIcon,
  1599.                     GetPopup getPopUp) {
  1600.                 super(name, parent, getPopUp, width, height);
  1601.                 this.imageIcon = imageIcon.toLowerCase();
  1602.             }
  1603.  
  1604.             /**
  1605.              * Constructs a button using the specified name, parent, and
  1606.              * imageIcon
  1607.              *
  1608.              * @param name
  1609.              *            String
  1610.              * @param parent
  1611.              *            Menu
  1612.              * @param imageIcon
  1613.              *            String
  1614.              */
  1615.             public MenuButton(String name, Menu parent, String imageIcon) {
  1616.                 this(name, parent, imageIcon, null);
  1617.             }
  1618.  
  1619.             /**
  1620.              * Constructs a button using the specified name and parent
  1621.              *
  1622.              * @param name
  1623.              *            String
  1624.              * @param parent
  1625.              *            Menu
  1626.              */
  1627.             public MenuButton(String name, Menu parent) {
  1628.                 this(name, parent, "", null);
  1629.             }
  1630.  
  1631.             /**
  1632.              * Renders this MenuButton to the given Graphics2D context
  1633.              */
  1634.             public void render(Graphics2D g) {
  1635.                 // Compiling
  1636.                 if (parent.parent.icons.containsKey(imageIcon))
  1637.                     if (parent.parent.icons.get(imageIcon) != null)
  1638.                         if (!parent.parent.icons.containsKey("Button-"
  1639.                                 + imageIcon)) {
  1640.                             // Scale the image
  1641.                             int width = (int) (bounds.width - (parent.style.roundCorner));
  1642.                             int height = (int) (bounds.height - (parent.style.roundCorner));
  1643.                             int hints = Image.SCALE_FAST;
  1644.                             parent.parent.icons.put(
  1645.                                     "Button-" + imageIcon,
  1646.                                     parent.parent.icons.get(imageIcon)
  1647.                                             .getScaledInstance(width, height,
  1648.                                                     hints));
  1649.                         }
  1650.  
  1651.                 g.setColor(parent.style.fgColor);
  1652.                 g.fill(bounds);
  1653.                 if (parent.parent.icons.containsKey("Button-" + imageIcon))
  1654.                     if (parent.parent.icons.get("Button-" + imageIcon) != null)
  1655.                         g.drawImage(
  1656.                                 parent.parent.icons.get("Button-" + imageIcon),
  1657.                                 (int) (bounds.x + (parent.style.roundCorner / 2)),
  1658.                                 (int) (bounds.y + (parent.style.roundCorner / 2)),
  1659.                                 null);
  1660.             }
  1661.         }
  1662.  
  1663.         /**
  1664.          * A class representing a progress bar in a menu
  1665.          *
  1666.          * @author Equinox_
  1667.          *
  1668.          */
  1669.         public class MenuProgressBar extends MenuItem {
  1670.             final static int width = 100;
  1671.             final static int height = 30;
  1672.  
  1673.             final GetPercent getPercent;
  1674.             RoundRectangle2D.Float percent;
  1675.             Point textLoc;
  1676.             String prefix;
  1677.  
  1678.             /**
  1679.              * Constructs a MenuProgress bar using the specified name, parent,
  1680.              * getPercent method, text prefix, and getPopup method
  1681.              *
  1682.              * @param name
  1683.              *            String
  1684.              * @param parent
  1685.              *            Menu
  1686.              * @param getPercent
  1687.              *            GetPercent
  1688.              * @param prefix
  1689.              *            String
  1690.              * @param getPopup
  1691.              *            GetPopup
  1692.              */
  1693.             public MenuProgressBar(String name, Menu parent,
  1694.                     GetPercent getPercent, String prefix, GetPopup getPopup) {
  1695.                 super(name, parent, getPopup, width, height);
  1696.                 this.getPercent = getPercent;
  1697.                 this.prefix = prefix;
  1698.             }
  1699.  
  1700.             /**
  1701.              * Renders this progress bar to the given Graphics context
  1702.              */
  1703.             public void render(Graphics2D g) {
  1704.                 percent.width = getPercent.getPercent();
  1705.                 g.setColor(parent.style.progressBarBG);
  1706.                 g.fill(bounds);
  1707.                 g.setColor(parent.style.progressBarFG);
  1708.                 g.fill(percent);
  1709.                 String perct = String.valueOf(getPercent.getPercent());
  1710.                 if (perct.length() < 2)
  1711.                     perct = "0" + perct;
  1712.                 g.setFont(style.FONT);
  1713.                 g.setColor(style.FONT_COLOR);
  1714.                 g.drawString(prefix + ": " + perct + "%", textLoc.x, textLoc.y);
  1715.             }
  1716.  
  1717.             /**
  1718.              * Compiles this progress bar
  1719.              */
  1720.             public void compile() {
  1721.                 super.compile();
  1722.                 percent = new RoundRectangle2D.Float(bounds.x, bounds.y,
  1723.                         getPercent.getPercent(), bounds.height,
  1724.                         bounds.arcwidth, bounds.archeight);
  1725.                 textLoc = new Point();
  1726.                 textLoc.x = (int) bounds.getCenterX();
  1727.                 textLoc.y = (int) bounds.getCenterY();
  1728.                 textLoc.y += parent.style.FONT.getLineMetrics(prefix + ": 00%",
  1729.                         parent.parent.frc).getHeight() / 2f;
  1730.                 textLoc.x -= parent.style.FONT.getStringBounds(
  1731.                         prefix + ": 00%", parent.parent.frc).getWidth() / 2f;
  1732.             }
  1733.         }
  1734.  
  1735.         /**
  1736.          * Class representing the method for getting the current percentile for
  1737.          * a progress bar
  1738.          *
  1739.          * @author Equinox_
  1740.          *
  1741.          */
  1742.         public abstract class GetPercent {
  1743.             abstract int getPercent();
  1744.         }
  1745.  
  1746.         /**
  1747.          * Class representing the LineListeners in popups
  1748.          *
  1749.          * @author Equinox_
  1750.          *
  1751.          */
  1752.         public abstract class LineListener {
  1753.             abstract void fireEvent(MouseEvent e, String line);
  1754.  
  1755.             abstract boolean hasAction(String line);
  1756.         }
  1757.  
  1758.         /**
  1759.          * A class representing the popups in the paint interface
  1760.          *
  1761.          * @author Equinox_
  1762.          *
  1763.          */
  1764.         public class MenuPopUp {
  1765.             private Font font;
  1766.             private Color color;
  1767.             private PaintStyle style;
  1768.             private RoundRectangle2D bkg;
  1769.             public RoundRectangle2D fg;
  1770.             public Rectangle txtBounds;
  1771.             public MenuItem parent;
  1772.             public final String name;
  1773.             public String[] lines;
  1774.             int width;
  1775.             int height;
  1776.             List<LineListener> lineListeners;
  1777.  
  1778.             /**
  1779.              * Creates a popup using the provided array of strings making up the
  1780.              * lines and name
  1781.              *
  1782.              * @param lines
  1783.              *            as String[]
  1784.              * @param name
  1785.              *            as String
  1786.              */
  1787.             public MenuPopUp(String[] lines, String name) {
  1788.                 this.name = name;
  1789.                 this.lines = lines;
  1790.             }
  1791.  
  1792.             /**
  1793.              * Set this popup's parent and compiles locations
  1794.              *
  1795.              * @param parent
  1796.              *            MenuItem
  1797.              */
  1798.             public void setParent(MenuItem parent) {
  1799.                 this.parent = parent;
  1800.                 this.style = parent.parent.style;
  1801.                 // Calc dimensions
  1802.                 color = name.equals("tools") ? style.TOOLS_FONT_COLOR
  1803.                         : style.FONT_COLOR;
  1804.                 font = name.equals("tools") ? style.TOOLS_FONT : style.FONT;
  1805.                 float line_height = font.getLineMetrics(lines[0], Paint.frc)
  1806.                         .getHeight();
  1807.                 width = 0;
  1808.                 for (String line : lines)
  1809.                     if (font.getStringBounds(line, Paint.frc).getWidth() > width)
  1810.                         width = (int) font.getStringBounds(line, Paint.frc)
  1811.                                 .getWidth();
  1812.  
  1813.                 height = (int) (lines.length * line_height);
  1814.  
  1815.                 width += style.roundCorner + 2;
  1816.                 height += style.roundCorner + 2;
  1817.  
  1818.                 int halfPadding = (parent.parent.padding / 2);
  1819.                 if (halfPadding < 1 && halfPadding != 0)
  1820.                     halfPadding = 1;
  1821.                 int x = 0;
  1822.                 int y = 0;
  1823.                 if (parent.parent.getFlowType().equals(FlowType.HORIZONTAL)) {
  1824.                     if (parent.bounds.y - height - parent.parent.padding > 0) {
  1825.                         // Above
  1826.                         x = (int) (parent.bounds.x - width
  1827.                                 + parent.bounds.width + halfPadding);
  1828.                         if (x < 0)
  1829.                             x = (int) (parent.bounds.x - halfPadding);
  1830.                         y = (int) (parent.parent.getAbsY() - height);
  1831.                     } else {
  1832.                         // Below
  1833.                         x = (int) (parent.bounds.x - halfPadding);
  1834.                         if (x + width > parent.parent.bounds.width)
  1835.                             x = (int) (parent.bounds.x - halfPadding - width);
  1836.                         y = (int) (parent.parent.getAbsY() + parent.parent
  1837.                                 .getHeight());
  1838.                     }
  1839.                 } else {
  1840.                     // Vertical
  1841.                     if (parent.bounds.x - width - parent.parent.padding > 0) {
  1842.                         // Left
  1843.                         x = (int) (parent.parent.getAbsX() - width);
  1844.                         if (parent.bounds.y - height + halfPadding
  1845.                                 + parent.bounds.height > 0)
  1846.                             y = (int) (parent.bounds.y - height + halfPadding + parent.bounds.height);
  1847.                         else
  1848.                             y = (int) (parent.bounds.y - halfPadding);
  1849.                     } else {
  1850.                         // Right
  1851.                         x = (int) (parent.parent.getAbsX() + parent.parent
  1852.                                 .getWidth());
  1853.                         if (parent.bounds.y - height + halfPadding
  1854.                                 + parent.bounds.height > 0)
  1855.                             y = (int) (parent.bounds.y - height + halfPadding + parent.bounds.height);
  1856.                         else
  1857.                             y = (int) (parent.bounds.y - halfPadding);
  1858.                     }
  1859.                 }
  1860.                 bkg = new RoundRectangle2D.Float(x, y, width, height,
  1861.                         style.roundCorner > 0 ? style.roundCorner + 1 : 0,
  1862.                         style.roundCorner > 0 ? style.roundCorner + 1 : 0);
  1863.                 fg = new RoundRectangle2D.Float((float) bkg.getX() + 1,
  1864.                         (float) bkg.getY() + 1, width - 2, height - 2,
  1865.                         style.roundCorner, style.roundCorner);
  1866.                 txtBounds = new Rectangle(
  1867.                         (int) (fg.getX() + (style.roundCorner / 2)),
  1868.                         (int) (fg.getY() + (style.roundCorner / 2)),
  1869.                         (int) (width - style.roundCorner - 2), (int) (height
  1870.                                 - style.roundCorner - 2));
  1871.             }
  1872.  
  1873.             /**
  1874.              * Paints this popup to using the provided Graphics2D in relation to
  1875.              * it's parent PaintInterface
  1876.              *
  1877.              * @param g
  1878.              *            as Graphics2D
  1879.              */
  1880.             public void render(Graphics2D g) {
  1881.                 g.setColor(style.bgColor);
  1882.                 g.fill(bkg);
  1883.                 g.setColor(style.fgColor);
  1884.                 g.fill(fg);
  1885.  
  1886.                 float line_height = (txtBounds.height - 4) / lines.length;
  1887.  
  1888.                 g.setFont(font);
  1889.                 g.setColor(color);
  1890.                 for (int i = 0; i < lines.length; i++) {
  1891.                     if (new Rectangle(txtBounds.x,
  1892.                             (int) ((i * (line_height)) + txtBounds.y),
  1893.                             txtBounds.width, (int) line_height)
  1894.                             .contains(parent.parent.parent.mouseLoc)
  1895.                             && hasAction(lines[i])) {
  1896.                         g.setColor(style.highlightColor);
  1897.                         g.fill(new Rectangle(txtBounds.x,
  1898.                                 (int) ((i * (line_height)) + 2 + txtBounds.y),
  1899.                                 txtBounds.width, (int) line_height));
  1900.                     }
  1901.                     g.setColor(color);
  1902.                     g.drawString(lines[i], txtBounds.x,
  1903.                             ((i + 1) * (line_height)) + txtBounds.y);
  1904.                 }
  1905.             }
  1906.  
  1907.             boolean hasAction(String line) {
  1908.                 if (lineListeners != null)
  1909.                     for (LineListener l : lineListeners)
  1910.                         if (l.hasAction(line))
  1911.                             return true;
  1912.                 return false;
  1913.             }
  1914.  
  1915.             /**
  1916.              * Adds the specified line listener
  1917.              *
  1918.              * @param l
  1919.              *            LineListener
  1920.              */
  1921.             public void addLineListener(LineListener l) {
  1922.                 if (lineListeners == null)
  1923.                     lineListeners = new ArrayList<LineListener>();
  1924.                 this.lineListeners.add(l);
  1925.             }
  1926.  
  1927.             /**
  1928.              * fires the specified mouse event using this popup's line listeners
  1929.              *
  1930.              * @param e
  1931.              *            MouseEvent
  1932.              */
  1933.             public void fireMouseEvent(MouseEvent e) {
  1934.                 if (!bkg.contains(e.getPoint()) || lineListeners == null
  1935.                         || lineListeners.size() == 0)
  1936.                     return;
  1937.  
  1938.                 int line_height = (txtBounds.height - 4) / lines.length;
  1939.  
  1940.                 for (int i = 0; i < lines.length; i++) {
  1941.                     Rectangle stringRect = new Rectangle(txtBounds.x,
  1942.                             (i * (line_height)) + txtBounds.y, txtBounds.width,
  1943.                             line_height);
  1944.                     if (stringRect.contains(e.getPoint())) {
  1945.                         for (LineListener lineListener : lineListeners)
  1946.                             lineListener.fireEvent(e, lines[i]);
  1947.                         return;
  1948.                     }
  1949.                 }
  1950.             }
  1951.         }
  1952.  
  1953.     }
  1954.  
  1955.     /**
  1956.      * Used for specifing the way a menu is layed out.
  1957.      *
  1958.      * @author Equinox_
  1959.      *
  1960.      */
  1961.     private enum FlowType {
  1962.         VERTICAL, HORIZONTAL
  1963.     }
  1964.  
  1965.     /**
  1966.      * Used for anchoring the menu bar
  1967.      *
  1968.      * @author Equinox_
  1969.      *
  1970.      */
  1971.     private enum Anchor {
  1972.         UP_LEFT, UP_RIGHT, DOWN_RIGHT, DOWN_LEFT
  1973.     }
  1974.  
  1975.     /**
  1976.      * Used to style the paint
  1977.      *
  1978.      * @author Equinox_
  1979.      *
  1980.      */
  1981.     public static class PaintStyle {
  1982.         public final Color FONT_COLOR = Color.BLACK;
  1983.         public final Font FONT = new Font("Arial", 1, 10)
  1984.                 .deriveFont(Font.PLAIN);
  1985.  
  1986.         public final Font TOOLS_FONT = new Font("Arial", 1, 14)
  1987.                 .deriveFont(Font.PLAIN);
  1988.         public final Color TOOLS_FONT_COLOR = Color.BLACK;
  1989.  
  1990.         public final float roundCorner = 10f;
  1991.         public final Color progressBarFG = new Color(0f, 1f, 0f, 1f);
  1992.         public final Color progressBarBG = new Color(.3f, .3f, .3f, 1f);
  1993.         public final Color bgColor = new Color(0f, 0f, 0f, 0.75f);
  1994.         final Color fgColor = new Color(.3f, .3f, .3f, 1f);
  1995.         final Color highlightColor = new Color(1f, 0f, 0f, 0.05f);
  1996.     }
  1997.  
  1998.     /**
  1999.      * Modified Copy of DrawMouse
  2000.      */
  2001.     public class ModifiedDrawMouse {
  2002.         private MouseTrailing mouseTrailing = new MouseTrailing();
  2003.         private ArrayList<Mouses> Click = new ArrayList<Mouses>();
  2004.         private long clickLifeTime = 1500;
  2005.  
  2006.         public void onRepaint(final Graphics render) {
  2007.             if (mouse != null) {
  2008.                 Point Location = mouse.getLocation();
  2009.                 if (mouse.isPressed())
  2010.                     if (Click.size() <= 5)
  2011.                         Click.add(new Mouses(System.currentTimeMillis(),
  2012.                                 Location));
  2013.                 mouseTrailing.draw((Graphics2D) render, Color.WHITE);
  2014.                 render.setColor(Color.GREEN);
  2015.                 render.drawLine(Location.x - 5, Location.y, Location.x + 5,
  2016.                         Location.y);
  2017.                 render.drawLine(Location.x, Location.y - 5, Location.x,
  2018.                         Location.y + 5);
  2019.                 if (Click.size() > 1)
  2020.                     for (Mouses click : Click) {
  2021.                         if (mouse.isPressed())
  2022.                             if (Click.size() <= 10)
  2023.                                 Click.add(new Mouses(
  2024.                                         System.currentTimeMillis(), Location));
  2025.                         float i = ((float) (click.getTime() + clickLifeTime - System
  2026.                                 .currentTimeMillis()) / (float) clickLifeTime) + 0.25f;
  2027.                         if (i > 0) {
  2028.                             render.setColor(new Color(1, 0, 0, i > 1 ? 1 : i));
  2029.                             render.drawLine(click.getLocation().x - 5,
  2030.                                     click.getLocation().y,
  2031.                                     click.getLocation().x + 5,
  2032.                                     click.getLocation().y);
  2033.                             render.drawLine(click.getLocation().x,
  2034.                                     click.getLocation().y - 5,
  2035.                                     click.getLocation().x,
  2036.                                     click.getLocation().y + 5);
  2037.                         } else if (System.currentTimeMillis() - click.getTime() >= 1000) {
  2038.                             Click.remove(click);
  2039.                         }
  2040.                     }
  2041.  
  2042.             }
  2043.         }
  2044.  
  2045.         /**
  2046.          * @author Baheer (Doout).
  2047.          */
  2048.         public class MouseTrailing {
  2049.             private int LifeTime = 1500;
  2050.             private ArrayList<Mouses> Info = new ArrayList<Mouses>();
  2051.  
  2052.             private void getLocation() {
  2053.                 Point m = mouse.getLocation();
  2054.                 if (Add(m)) {
  2055.                     Info.add(new Mouses(System.currentTimeMillis(), m));
  2056.                 }
  2057.             }
  2058.  
  2059.             public boolean Add(Point p) {
  2060.                 for (Mouses Trailing : Info)
  2061.                     if (Trailing.getLocation().equals(p))
  2062.                         return false;
  2063.                 return true;
  2064.             }
  2065.  
  2066.             public void draw(Graphics2D g, Color c) {
  2067.                 getLocation();
  2068.                 if (Info.size() > 1)
  2069.                     for (int t = 1; t < Info.size(); t++) {
  2070.                         Mouses Trailing1 = Info.get(t);
  2071.                         Mouses Trailing2 = Info.get(t - 1);
  2072.                         float i = (float) (Trailing1.getTime() + LifeTime - System
  2073.                                 .currentTimeMillis()) / (float) LifeTime;
  2074.                         if (i > 0) {
  2075.                             g.setColor(new Color(c.getRed() / 255f, c
  2076.                                     .getGreen() / 255f, c.getBlue() / 255f, (c
  2077.                                     .getAlpha() / 255f) * i));
  2078.                             g.drawLine(Trailing1.getLocation().x,
  2079.                                     Trailing1.getLocation().y,
  2080.                                     Trailing2.getLocation().x,
  2081.                                     Trailing2.getLocation().y);
  2082.                         }
  2083.                     }
  2084.                 if (Info.size() > 1) {
  2085.                     if (System.currentTimeMillis() > Info.get(0).getTime()
  2086.                             + LifeTime) {
  2087.                         Info.remove(0);
  2088.                     }
  2089.                 }
  2090.             }
  2091.  
  2092.         }
  2093.  
  2094.         private class Mouses {
  2095.             private long Time;
  2096.             private Point Location;
  2097.  
  2098.             public Mouses(long time, Point loc) {
  2099.                 Time = time;
  2100.                 Location = loc;
  2101.             }
  2102.  
  2103.             public long getTime() {
  2104.                 return Time;
  2105.             }
  2106.  
  2107.             public Point getLocation() {
  2108.                 return Location;
  2109.             }
  2110.         }
  2111.     }
  2112.  
  2113.     public void mouseDragged(MouseEvent arg0) {
  2114.         Paint.mouseLoc = arg0.getPoint();
  2115.     }
  2116.  
  2117.     public void mouseMoved(MouseEvent arg0) {
  2118.         Paint.mouseLoc = arg0.getPoint();
  2119.     }
  2120.  
  2121.     public void mouseClicked(MouseEvent arg0) {
  2122.         Paint.fireMouseEvent(arg0);
  2123.     }
  2124.  
  2125.     public void mouseEntered(MouseEvent arg0) {
  2126.  
  2127.     }
  2128.  
  2129.     public void mouseExited(MouseEvent arg0) {
  2130.  
  2131.     }
  2132.  
  2133.     public void mousePressed(MouseEvent arg0) {
  2134.  
  2135.     }
  2136.  
  2137.     public void mouseReleased(MouseEvent arg0) {
  2138.     }
  2139.  
  2140.     /**
  2141.      * Loads script data as the actual script runs. Useful for images that are
  2142.      * non-essential.
  2143.      *
  2144.      * @author Equinox_
  2145.      *
  2146.      */
  2147.     public static class DataLoader extends Thread {
  2148.         EquinoxLunarPlanker planker;
  2149.  
  2150.         /**
  2151.          * Creates a dataloader using the specified EquinoxLunarPlanker instance
  2152.          *
  2153.          * @param planker
  2154.          */
  2155.         public DataLoader(EquinoxLunarPlanker planker) {
  2156.             super("Data Loader");
  2157.             this.planker = planker;
  2158.             this.start();
  2159.         }
  2160.  
  2161.         /**
  2162.          * Gets the icon for a specified image in the runescape online database.
  2163.          *
  2164.          * @param id
  2165.          *            as int
  2166.          * @return Image
  2167.          * @throws MalformedURLException
  2168.          * @throws IOException
  2169.          */
  2170.         public Image getItemImage(int id) throws MalformedURLException,
  2171.                 IOException {
  2172.             return ImageIO.read(new URL(
  2173.                     "http://services.runescape.com/m=itemdb_rs/3290_obj_sprite.gif?id="
  2174.                             + id));
  2175.         }
  2176.  
  2177.         public void run() {
  2178.             try {
  2179.                 if (JOptionPane.NO_OPTION == JOptionPane.showConfirmDialog(
  2180.                         null, "Would you like to load some images?",
  2181.                         "Equinox_ Data Loader", JOptionPane.YES_NO_OPTION))
  2182.                     throw new Exception();
  2183.  
  2184.                 long before = System.currentTimeMillis();
  2185.                 planker.Paint.putImage(
  2186.                         "homeicon",
  2187.                         ImageIO.read(new URL(planker.baseURL
  2188.                                 + "/images/houseIcon.png")));
  2189.                 planker.log("Loaded home image in "
  2190.                         + PaintFormatter.getFormattedTime(System
  2191.                                 .currentTimeMillis() - before));
  2192.                 before = System.currentTimeMillis();
  2193.                 planker.Paint.putImage("plankicon", getItemImage(PlankID));
  2194.                 planker.log("Loaded plank icon in "
  2195.                         + PaintFormatter.getFormattedTime(System
  2196.                                 .currentTimeMillis() - before));
  2197.                 before = System.currentTimeMillis();
  2198.                 planker.Paint.putImage(
  2199.                         "toolsicon",
  2200.                         ImageIO.read(new URL(planker.baseURL
  2201.                                 + "/images/tools.png")));
  2202.                 planker.log("Loaded tools icon in "
  2203.                         + PaintFormatter.getFormattedTime(System
  2204.                                 .currentTimeMillis() - before));
  2205.             } catch (Exception e) {
  2206.                 planker.log("Failed to load images");
  2207.             }
  2208.             loadGE();
  2209.         }
  2210.  
  2211.         /**
  2212.          * Loads the GE Item prices
  2213.          */
  2214.         void loadGE() {
  2215.             planker.Paint.astralPrice = planker.getItemPrice(AstralRune);
  2216.             planker.Paint.earthPrice = planker.getItemPrice(EarthRune);
  2217.             planker.Paint.naturePrice = planker.getItemPrice(NatRune);
  2218.             planker.Paint.plankPrice = planker.getItemPrice(PlankID);
  2219.             planker.Paint.logPrice = planker.getItemPrice(LogID);
  2220.         }
  2221.     }
  2222.  
  2223.     /**
  2224.      * gets the item price based on class. Works with all versions of
  2225.      * grandExchange.class
  2226.      *
  2227.      * @param item
  2228.      *            the GEItem to get the price from
  2229.      * @return int the price
  2230.      *
  2231.      * @author Equinox_
  2232.      */
  2233.     public int getItemPrice(int id) {
  2234.         GEItem item = grandExchange.lookup(id);
  2235.         if (item != null) {
  2236.             int price = 0;
  2237.             for (Method m : item.getClass().getMethods())
  2238.                 if (m.getName().equals("getGuidePrice")
  2239.                         || m.getName().equals("getMinPrice"))
  2240.                     try {
  2241.                         price = (Integer) (m.invoke(item));
  2242.                         break;
  2243.                     } catch (Exception e) {
  2244.                     }
  2245.             log.info("Price of " + item.getName() + ": " + price);
  2246.             return price;
  2247.         }
  2248.         return 0;
  2249.     }
  2250.  
  2251. }
Advertisement
Add Comment
Please, Sign In to add comment