1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Resource Skill Progress Bars - Clean, Simple & Sexy

Discussion in 'Tutorials & Resources' started by Baddest Man on Earth, Dec 11, 2014.

  1. Baddest Man on Earth

    Joined:
    Nov 26, 2014
    Messages:
    616
    Likes Received:
    246
    [​IMG]

    Use, modify as you like.

    Gimme me some credit.

    Code (Text):
    1. package com.wadiyan.runemate.util;
    2.  
    3. import com.runemate.game.api.hybrid.local.Skill;
    4.  
    5. import java.awt.*;
    6. import java.text.DecimalFormat;
    7. import java.text.NumberFormat;
    8. import java.util.concurrent.TimeUnit;
    9.  
    10. /**
    11. * @author: Supreme Leader
    12. */
    13. public class ExpTracker {
    14.  
    15.     private final Skill skill;
    16.     private final long startTime;
    17.     private final int startExp;
    18.     private final Color borderColor, backgroundColor, foregroundColor, textColor;
    19.  
    20.     private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("#.0");
    21.     private static final Font FONT = new Font("Arial", Font.PLAIN, 11);
    22.  
    23.     public ExpTracker (final Skill skill, final Color borderColor, final Color backgroundColor, final Color foregroundColor, final Color textColor) {
    24.         this.skill = skill;
    25.         this.startTime = System.currentTimeMillis();
    26.         this.startExp = skill.getExperience();
    27.         this.borderColor = borderColor;
    28.         this.backgroundColor = backgroundColor;
    29.         this.foregroundColor = foregroundColor;
    30.         this.textColor = textColor;
    31.     }
    32.  
    33.     public int getExpGained () {
    34.         return skill.getExperience() - startExp;
    35.     }
    36.  
    37.     public int getExpPerHour () {
    38.         return perHour(getExpGained());
    39.     }
    40.  
    41.     public long getTimeToNextLevel () {
    42.         return (long) (skill.getExperienceToNextLevel() * 3600000D / getExpPerHour());
    43.     }
    44.  
    45.     private int getBarWidth () {
    46.         double tnl = (100 - skill.getPercentTowardsNextLevel()) * 0.01;
    47.         return (int) (tnl * 250);
    48.     }
    49.  
    50.     private String getFormattedExpPerHour () {
    51.         double expPerHour = (double) getExpPerHour() / 1000;
    52.         return DECIMAL_FORMAT.format(expPerHour) + "K";
    53.     }
    54.  
    55.     private String getProgressBarInfo () {
    56.         String info = skill.name() + ": " + formatNumber(getExpGained()) + " (" + getFormattedExpPerHour()
    57.                 + " P/H) - " + formatTime(getTimeToNextLevel());
    58.         return info;
    59.     }
    60.  
    61.     public void drawProgressBar (Graphics2D g, int x, int y) {
    62.         g.setStroke(new BasicStroke(2));
    63.         g.setColor(backgroundColor);
    64.         g.fillRect(x, y, 250, 20);
    65.         g.setColor(foregroundColor);
    66.         g.fillRect(x, y, getBarWidth() ,20);
    67.         g.setColor(borderColor);
    68.         g.drawRect(x, y, 250, 20);
    69.         g.setColor(textColor);
    70.         g.setFont(FONT);
    71.         FontMetrics fontMetrics = g.getFontMetrics(FONT);
    72.         String info = getProgressBarInfo();
    73.         int textX = 125 - (fontMetrics.stringWidth(info)/2);
    74.         g.drawString(info, x + textX, y + 15);
    75.     }
    76.  
    77.     private int perHour(int val) {
    78.         return (int) ((val) * 3600000D / (System.currentTimeMillis() - startTime));
    79.     }
    80.  
    81.     private String formatTime(long time) {
    82.         String hms = String.format(
    83.                 "%02d:%02d:%02d",
    84.                 TimeUnit.MILLISECONDS.toHours(time),
    85.                 TimeUnit.MILLISECONDS.toMinutes(time)
    86.                         - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS
    87.                         .toHours(time)),
    88.                 TimeUnit.MILLISECONDS.toSeconds(time)
    89.                         - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS
    90.                         .toMinutes(time)));
    91.         return hms;
    92.     }
    93.  
    94.     private String formatNumber(int i) {
    95.         return NumberFormat.getIntegerInstance().format(i);
    96.     }
    97.  
    98. }
    99.  
    Code (Text):
    1. package com.wadiyan.runemate.util;
    2.  
    3.  
    4.  
    5. import java.awt.*;
    6. import java.util.ArrayList;
    7.  
    8. /**
    9. * @author: Supreme Leader
    10. */
    11. public class ExpTrackerContainer {
    12.  
    13.     private final ArrayList<ExpTracker> trackers;
    14.  
    15.     public ExpTrackerContainer () {
    16.         trackers = new ArrayList<ExpTracker>();
    17.     }
    18.  
    19.     public ExpTrackerContainer (ExpTracker... skills) {
    20.         this();
    21.         add(skills);
    22.     }
    23.  
    24.     public void add(ExpTracker... skills) {
    25.         for (ExpTracker skill: skills) {
    26.             if (!trackers.contains(skill)) {
    27.                 trackers.add(skill);
    28.             }
    29.         }
    30.     }
    31.  
    32.     public void remove(ExpTracker... skills) {
    33.         for (ExpTracker skill: skills) {
    34.             if (trackers.contains(skill)){
    35.                 trackers.remove(skill);
    36.             }
    37.         }
    38.     }
    39.  
    40.     public void draw (Graphics2D g, int x, int y) {
    41.         int pos = 0;
    42.         for (ExpTracker tracker: trackers) {
    43.             if (tracker.getExpPerHour() > 1000) {
    44.                 tracker.drawProgressBar(g, x, y + (pos* 20));
    45.                 pos++;
    46.             }
    47.         }
    48.     }
    49. }
    50.  
    Implementation:
    Code (Text):
    1. package com.wadiyan.runemate.scripts.fighter;
    2.  
    3. import com.runemate.game.api.client.paint.PaintListener;
    4. import com.runemate.game.api.hybrid.local.Skill;
    5. import com.runemate.game.api.script.framework.LoopingScript;
    6. import com.wadiyan.runemate.util.ExpTracker;
    7. import com.wadiyan.runemate.util.ExpTrackerContainer;
    8.  
    9. import java.awt.*;
    10.  
    11. /**
    12. * @author: Supreme Leader
    13. */
    14. public class SupremeFighter extends LoopingScript implements PaintListener{
    15.  
    16.     ExpTracker constiution, magic;
    17.     ExpTrackerContainer expTrackerContainer;
    18.  
    19.     @Override
    20.     public void onStart (String [] args) {
    21.         getEventDispatcher().addListener(this);
    22.         constiution = new ExpTracker(Skill.CONSTITUTION, Color.BLACK, new Color(0, 0, 0, 150), new Color(65, 4, 9), Color.WHITE);
    23.         magic = new ExpTracker(Skill.MAGIC, Color.BLACK, new Color(0,0,0, 150), new Color(0, 6, 73), Color.WHITE);
    24.         expTrackerContainer = new ExpTrackerContainer(magic, constiution);
    25.     }
    26.  
    27.     @Override
    28.     public void onLoop() {
    29.  
    30.     }
    31.  
    32.     @Override
    33.     public void onPaint(Graphics2D g) {
    34.         if (expTrackerContainer != null) {
    35.             expTrackerContainer.draw(g, 0, 0);
    36.         }
    37.     }
    38.  
    39. }
    40.  
     
    #1 Baddest Man on Earth, Dec 11, 2014
    Last edited: Dec 12, 2014
  2. Exia

    Joined:
    Nov 3, 2013
    Messages:
    609
    Likes Received:
    259
    Drop the outlines, lighten the background and add a bit more height and it will fit the theme of the client perfectly.
     
  3. Baddest Man on Earth

    Joined:
    Nov 26, 2014
    Messages:
    616
    Likes Received:
    246
    I'm lazy.
     

Share This Page

Loading...