Thread: Status Bars

Results 1 to 8 of 8
  1. #1 Status Bars 
    Banned


    Join Date
    Jul 2020
    Posts
    157
    Thanks given
    100
    Thanks received
    166
    Rep Power
    0
    What you are adding:

    Attached image

    I know this has been done before in other clients and maybe released but here is my version of it. Please Constructive criticism only


    Make a class called StatusBars and inside it put this code

    Code:
    /*
     * Copyright (c) 2020, Mark_ <https://www.rune-server.ee/members/mark_/>
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions are met:
     *
     * 1. Redistributions of source code must retain the above copyright notice, this
     *    list of conditions and the following disclaimer.
     * 2. Redistributions in binary form must reproduce the above copyright notice,
     *    this list of conditions and the following disclaimer in the documentation
     *    and/or other materials provided with the distribution.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
     * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
     * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
     * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     */
    
    
    package io.wrath.draw.game;
    
    import io.wrath.Client;
    import io.wrath.Configuration;
    import io.wrath.cache.graphics.SpriteCache;
    import io.wrath.draw.Rasterizer2D;
    
    import java.util.HashMap;
    import java.util.Map;
    
    public class StatusBars {
    
        public Restore restore = Restore.NONE;
    
        public enum Restore {
    
            NONE(0,0,BarType.PRAYER),
            PRAYER_3(139,40,BarType.PRAYER);
    
            private final int item;
            private final int restore;
            private final BarType type;
    
            public int getItem() {
                return item;
            }
    
            public int getRestore() {
                return restore;
            }
    
            public BarType getType() {
                return type;
            }
    
            Restore(int item, int restore,BarType type) {
                this.item = item;
                this.restore = restore;
                this.type = type;
            }
    
            private static final Map<Integer, Restore> restoreMap = new HashMap<>();
    
            static {
                for (Restore restore : values()) {
                    restoreMap.put(restore.item, restore);
                }
            }
    
            public static Restore get(int item) {
                return restoreMap.getOrDefault(item,NONE);
            }
    
        }
    
        public enum BarType {
            HP(0x7F230E,0xFF7006,0x0009100,0x004100,9),
            PRAYER(0x2D9491,0x3970BA,10);
    
            private final int normal;
            private final int heal;
            private int poisoned;
            private int venom;
            private final int icon;
    
            public int getNormal() {
                return normal;
            }
    
            public int getHeal() {
                return heal;
            }
    
            public int getPoisoned() {
                return poisoned;
            }
    
            public int getVenom() {
                return venom;
            }
    
            public int getIcon() {
                return icon;
            }
    
            BarType(int normal, int heal, int icon) {
                this.normal = normal;
                this.heal = heal;
                this.icon = icon;
            }
    
            BarType(int normal, int heal,int poisoned,int venom,int icon) {
                this.normal = normal;
                this.heal = heal;
                this.poisoned = poisoned;
                this.venom = venom;
                this.icon = icon;
            }
        }
    
        public void drawStatusBars(int xOffset,int yOffset) {
            if(!Configuration.statusBars) {
                return;
            }
    
            int hpColor = 0;
            int prayerColor = BarType.PRAYER.getNormal();
    
            if (Client.instance.poisonType == 0) {
                hpColor = BarType.HP.getNormal();
            } else if (Client.instance.poisonType == 1) {
                hpColor = BarType.HP.getPoisoned();
            } else if (Client.instance.poisonType == 2) {
                hpColor = BarType.HP.getVenom();
            }
    
    
            renderStatusBars(xOffset,yOffset,BarType.HP,hpColor);
            renderStatusBars(xOffset,yOffset,BarType.PRAYER,prayerColor);
        }
    
        public void renderStatusBars(int xOffset,int  yOffset,BarType type, int backgroundColor) {
            int hitpoints = Client.instance.currentStats[3];
            int prayer = Client.instance.currentStats[5];
            int percent = getPercent(getPercent(type,0),250);
    
    
            Rasterizer2D.drawBoxOutline(xOffset + 11 + getBarOffsetX(type), 42 + yOffset, 20, 250, 0x000000);
    
            Rasterizer2D.drawTransparentBox(xOffset + 11 + getBarOffsetX(type), 42 + yOffset, 20, 250 , 0x000000,130);
    
            Rasterizer2D.drawTransparentBox(xOffset + 12 + getBarOffsetX(type), 242 - percent + 50 + yOffset , 18, percent , backgroundColor,135);
    
            if(restore.type == type && restore != Restore.NONE) {
                Rasterizer2D.drawTransparentBox(xOffset + 12 + getBarOffsetX(type), 242 - getPercent(getPercent(type,restore.restore),250) + 50 + yOffset, 18, getPercent(getPercent(type,restore.restore),250) , type.getHeal(),140);
            }
    
            if(getPercent(type,0) < 20) {
                if(Client.tick % 20 < 10) {
                    SpriteCache.lookup(type.getIcon()).drawSprite(xOffset + 12 + getBarOffsetX(type), 50 + yOffset);
                }
            } else {
                SpriteCache.lookup(type.getIcon()).drawSprite(xOffset + 12 + getBarOffsetX(type), 50 + yOffset);
            }
    
            Client.instance.newSmallFont.drawCenteredString(type == BarType.HP ? hitpoints + "" : prayer + "", xOffset + 21 + getBarOffsetX(type), 80 + yOffset,0xFFFFFF, 1);
        }
    
    
        public int getBarOffsetX(BarType type) {
            if(type == BarType.HP) {
                return Client.frameMode == Client.ScreenMode.RESIZABLE ? - 5 : 0;
            } else if(type == BarType.PRAYER) {
                return  Client.frameMode == Client.ScreenMode.RESIZABLE ? 210 + - 6 : 210;
            }
            return 0;
        }
    
        public static int getPercent(int current,int pixels) {
            return  (int) ((pixels) * .01 * current);
        }
    
        public int getPercent(BarType type, int extra) {
            if(type == BarType.HP) {
                int level = Client.instance.currentStats[3] + extra;
                int max = Client.instance.maximumLevels[3];
                double percent = level / (double) max;
                return  level > 99 ? 100 : (int) (percent * 100);
            } else if(type == BarType.PRAYER) {
                int level = Client.instance.currentStats[5] + extra;
                int max = Client.instance.maximumLevels[5];
                double percent = level / (double) max;
                return level > 99 ? 100 : (int) (percent * 100);
            }
            return 0;
        }
    
        public void setConsume(Restore restore) {
            this.restore = restore;
        }
    
    }

    Things to lookout for:

    • Wrong sprite ids this is set in the enum BarType
    • You may want to seprate the enum classes i just kept it in here for the sake of making the code have less classes
    • You may need to change
      Code:
       if (Client.instance.poisonType == ...) {
      to use your system to see the hp state or just remove it


    Client:

    First add this anywhere

    Code:
    	private StatusBars bars = new StatusBars();
    Second find drawTabArea under where it draws the menu add the following

    Code:
    bars.drawStatusBars(xOffset,yOffset);
    it should look like this

    Attached image

    Next find
    Code:
    if (childInterface.inventoryItemId[k2] > 0) {
    in your buildInterface under where it gets the item data add this

    Code:
    bars.setConsume(StatusBars.Restore.get(itemDef.id));

    If you notice any issues or want a new feature feel free to post a comment and ill do when i get some time
    Reply With Quote  
     

  2. Thankful users:


  3. #2  
    Donator

    Kid Buu's Avatar
    Join Date
    Aug 2017
    Posts
    433
    Thanks given
    182
    Thanks received
    227
    Rep Power
    424
    Thanks for the contribution.
    Attached image
    Reply With Quote  
     

  4. #3  
    Banned

    Join Date
    Jun 2019
    Posts
    203
    Thanks given
    99
    Thanks received
    44
    Rep Power
    0
    Thanks.
    Reply With Quote  
     

  5. #4  
    Registered Member
    rebecca's Avatar
    Join Date
    Aug 2017
    Posts
    1,071
    Thanks given
    862
    Thanks received
    915
    Rep Power
    5000
    good contribution
    Reply With Quote  
     

  6. #5  
    Celestial - Founder
    Classic's Avatar
    Join Date
    Nov 2014
    Posts
    233
    Thanks given
    119
    Thanks received
    47
    Rep Power
    39
    Thank you!
    Reply With Quote  
     

  7. #6  
    Donator
    RuneAd's Avatar
    Join Date
    Nov 2014
    Posts
    144
    Thanks given
    108
    Thanks received
    48
    Rep Power
    69
    Thanks for giving this out to the community
    Reply With Quote  
     

  8. #7  
    Registered Member
    Join Date
    Sep 2020
    Posts
    57
    Thanks given
    83
    Thanks received
    23
    Rep Power
    49
    Nice release
    Reply With Quote  
     

  9. #8  
    Extreme Donator


    Join Date
    Dec 2016
    Posts
    383
    Thanks given
    99
    Thanks received
    66
    Rep Power
    340
    thanks for this !
    Reply With Quote  
     

  10. Thankful user:



Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Server Status Bar
    By HcoJustin in forum Website Development
    Replies: 4
    Last Post: 08-09-2010, 01:10 AM
  2. Changing Loading Bar color & Flames color!
    By Ninja Cat in forum Tutorials
    Replies: 14
    Last Post: 12-22-2008, 11:54 AM
  3. Replies: 34
    Last Post: 10-31-2007, 09:09 PM
  4. Packet 36 - Interface button Status
    By uber killer in forum Tutorials
    Replies: 9
    Last Post: 07-31-2007, 04:33 AM
  5. My First User Bar!
    By Lumby in forum Showcase
    Replies: 4
    Last Post: 05-31-2007, 05:47 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •