Equinox

EquinoxLunarPlanker.java

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