Example #1
0
 /**
  * Draws a progress bar using the co-ordinates, dimensions and skill provided. This also displays
  * current level in the skill, percent till the next level & exp needed to reach the next level
  *
  * @param g An instance of Graphics to paintType to.
  * @param skill The number of the skill wanting to display. E.g Skills.MAGIC
  * @param x The "x" co-ordinate.
  * @param y The "y" co-ordinate.
  * @param w The width of the progress bar.
  * @param h The height of the progress bar.
  * @param hover If you want extra info to be displayed (Usually for when the skill is "Hovered")
  * @author Rudday, UberMouse
  */
 public void drawProgressBar(Graphics g, int skill, int x, int y, int w, int h, boolean hover) {
   Graphics2D g2 = (Graphics2D) g;
   Paint p = g2.getPaint();
   GradientPaint grad1 =
       new GradientPaint(x, y, scheme.firstGradient1, x, y + h + 3, scheme.firstGradient2);
   GradientPaint grad2 =
       new GradientPaint(x, y, scheme.secondGradient1, x, y + h + 3, scheme.secondGradient2);
   g2.setPaint(grad1);
   g2.fillRect(x, y, w, h);
   g2.setPaint(grad2);
   g2.fillRect(x, y, (int) (w * (UberSkills.getPercentToNextLevel(skill) / 100.0)), h);
   g2.setColor(scheme.text);
   g2.drawRect(x, y, w, h);
   g2.setFont(new Font("Arial", 0, 9));
   String progress =
       UberSkills.getPercentToNextLevel(skill)
           + "% to "
           + ((UberSkills.getRealLevel(skill) + 1 <= 120)
               ? UberSkills.getRealLevel(skill) + 1
               : 120)
           + " "
           + name
           + " | "
           + UberSkills.getExpToNextLevel(skill)
           + " XPTL";
   g2.drawString(
       progress,
       x + ((w - (g.getFontMetrics().stringWidth(progress))) / 2),
       (int) (y + ((g.getFontMetrics().getHeight() / 2) + (h / 4) * 1.75)));
   g2.setPaint(p);
   if (hover) {
     g2.setColor(scheme.hover);
     g2.fillRect(x, y - (height + 2), width, height);
     g2.setColor(scheme.text);
     g2.drawRect(x, y - (height + 2), width, height);
     progress =
         "TTL: "
             + skillInfo.timeToLevel()
             + " XPG: "
             + skillInfo.xpGained()
             + " XPPH: "
             + skillInfo.xpPH()
             + " LG: "
             + skillInfo.levelsGained();
     g2.drawString(
         progress,
         x + ((w - (g.getFontMetrics().stringWidth(progress))) / 2),
         (int) ((y - (height + 2)) + ((g.getFontMetrics().getHeight() / 2) + (h / 4) * 1.75)));
   }
 }
Example #2
0
  public boolean paint(Graphics graphics) {
    if (!Game.isLoggedIn()) return false;
    try {
      Graphics2D g = (Graphics2D) graphics;
      PComponent clayout = null;
      try {
        clayout =
            new PColumnLayout(
                227,
                404,
                infoColumnValues,
                infoColumnData,
                new Font("Arial", 0, 9),
                PColumnLayout.ColorScheme.WHITE);
      } catch (Exception e) {
        e.printStackTrace();
      }
      getFrame("options").removeComponent(firstLayout);
      getFrame("options").removeComponent(secondLayout);
      int secondColx = -1;
      int bestLength = -1;
      firstColumn.clear();
      secondColumn.clear();
      if (checkBoxes.size() <= 6) firstColumn.putAll(checkBoxes);
      else {
        for (int i = 0; i < checkBoxes.size(); i++) {
          if (i <= 5) {
            String text;
            Iterator it = checkBoxes.keySet().iterator();
            for (int j = 0; j < i; j++) it.next();
            text = (String) it.next();
            int length = SwingUtilities.computeStringWidth(g.getFontMetrics(g.getFont()), text);
            if (length > bestLength) bestLength = length;
            firstColumn.put(text, checkBoxes.get(text));
          } else {
            String text;
            Iterator it = checkBoxes.keySet().iterator();
            for (int j = 0; j < i; j++) it.next();
            text = (String) it.next();
            secondColumn.put(text, checkBoxes.get(text));
          }
        }
      }
      secondColx = 8 + bestLength;
      firstLayout =
          new PCheckBoxLayout(
              8,
              407,
              firstColumn
                  .keySet()
                  .toArray(new String[(firstColumn.size() > 6) ? 6 : firstColumn.size()]),
              firstColumn
                  .values()
                  .toArray(new PCheckBox[(firstColumn.size() > 6) ? 6 : firstColumn.size()]),
              new Font("Arial", 0, 11),
              PCheckBoxLayout.ColorScheme.WHITE);
      secondLayout =
          new PCheckBoxLayout(
              secondColx + 12,
              407,
              secondColumn
                  .keySet()
                  .toArray(new String[(secondColumn.size() > 6) ? 6 : secondColumn.size()]),
              secondColumn
                  .values()
                  .toArray(new PCheckBox[(secondColumn.size() > 6) ? 6 : secondColumn.size()]),
              new Font("Arial", 0, 11),
              PCheckBoxLayout.ColorScheme.WHITE);
      getFrame("options").addComponent(firstLayout);
      getFrame("options").addComponent(secondLayout);
      if (showPaint) {
        Paint p = g.getPaint();
        g.setPaint(
            new GradientPaint(
                0, 1000, new Color(55, 55, 55, 240), 512, 472, new Color(15, 15, 15, 240)));
        g.fillRect(7, 396, 505, 128);
        final Point loc = Mouse.getLocation();
        if (Mouse.isPressed()) {
          g.fillOval(loc.x - 5, loc.y - 5, 10, 10);
          g.drawOval(loc.x - 5, loc.y - 5, 10, 10);
        }
        g.drawLine(0, loc.y + 1, 766, loc.y + 1);
        g.drawLine(0, loc.y - 1, 766, loc.y - 1);
        g.drawLine(loc.x + 1, 0, loc.x + 1, 505);
        g.drawLine(loc.x - 1, 0, loc.x - 1, 505);
        g.setPaint(p);
      }
      if (clayout != null) getFrame("info").addComponent(clayout);
      PaintController.onRepaint(graphics);
      if (clayout != null) getFrame("info").removeComponent(clayout);
      if (!showPaint) return false;
      String infoTxt = name + " - " + "v" + version;
      g.drawString(
          infoTxt,
          510 - SwingUtilities.computeStringWidth(g.getFontMetrics(g.getFont()), infoTxt),
          468);

      int offset = 0;
      for (Skill skill : skills) {
        if (skill.xpGained() > 0) {
          PSkill skillComp =
              new PSkill(8, 397 + offset, skill.getSkill(), PSkill.ColorScheme.GRAPHITE);
          if (!getFrame("info").containsComponent(skillComp)) {
            getFrame("info").addComponent(skillComp);
          }
          offset += 20;
        }
      }

      // == Mouse ==
      if (Mouse.isPressed()) {
        g.setColor(new Color(255, 252, 0, 150));

        g.setColor(new Color(255, 252, 0, 100));
      } else {
        g.setColor(new Color(255, 252, 0, 50));
      }

      g.setColor(new Color(0, 0, 0, 50));

      // == End mouse ==
    } catch (Exception ignored) {
      // if (Utils.isDevMode())
      //    ignored.printStackTrace();
    }
    return true;
  }