Thread: New Hover Buttons

Results 1 to 9 of 9
  1. #1 New Hover Buttons 
    Retard Strength


    Join Date
    Jul 2014
    Posts
    1,805
    Thanks given
    922
    Thanks received
    533
    Rep Power
    546
    Haven't released anything here in a while so decided to release this and maybe a few people will use it.
    Please note that your client may have different naming than mine.



    Spoiler for How to add a hovered button with text over it with the original system, compared to my system:

    Old system:
    Code:
    		addHoverButton(39006, "Tele/SPRITE", 5, 127, 31, "Teleport", 0, 39007, 1);
    		addHoveredButton(39007, "Tele/SPRITE", 6, 127, 31, 39008);
    		addText(39009, "Confirm", tda, 2, 0xffffff, true, true);
    		tab.child(7, 39006, 13, 240);
    		tab.child(8, 39007, 13, 240);
    		tab.child(9, 39009, 76, 249);

    New system:
    Code:
    		hoverButton(39006, "test/SPRITE", 1, 2, "Teleport", 1, 0xffffff, "Confirm");
    		tab.child(7, 39006, 13, 240);






    What you are adding:
    This is a new system for hover buttons for the interface system, there are a few problems with the original system.
    Spoiler for Problems with the original system:

    -Difficult to understand
    -Annoying to use
    -Uses 3 indexes in interfaceCache (or 4 if you want a text over the button)
    -Glitch when the button is in a scroll bar (hovering over it will make the hover part draw outside the scroll area)
    See in the Gif below, when I place my mouse over one of the buttons at the bottom of the scrollbar, the hover button draws outside the scroll area.








    Step 1:
    Open RSInterface.java and add this somewhere:

    Code:
    	public int messageOffsetX;
    	public int messageOffsetY;
    	public int fontType;
    	/**
    	 * @param id - The ID of the Interface (Index in interfaceCache array)
    	 * @param spriteLocation - The directory in the cache where the sprites are
    	 * @param offSprite - The ID of the sprite when the mouse is not over the button
    	 * @param hoverSprite - The ID of the sprite when the mouse is over the button
    	 * @param hoverTooltip - The menu action text for the button (right click)
    	 * @param font - The ID of the font for the text on the button (0 = small, 1 = regular, 2 = bold, 3 = fancy)
    	 * @param color - The color of the text on top of the button
    	 * @param buttonText - The text on top of the button
    	 */
    	public static void hoverButton(int id, String spriteLocation, int offSprite, int hoverSprite, String hoverTooltip, int font, int color, String buttonText) {
    		RSInterface tab = addInterface(id);
    		tab.tooltip = hoverTooltip;
    		tab.atActionType = 1;
    		tab.type = 42;
    		tab.sprite1 = imageLoader(offSprite, spriteLocation);
    		tab.sprite2 = imageLoader(hoverSprite, spriteLocation);
    		tab.width = tab.sprite1.myWidth;
    		tab.height = tab.sprite1.myHeight;
    		tab.messageOffsetX = tab.width / 2;
    		tab.messageOffsetY = (tab.height / 2) + 5;
    		tab.message = buttonText;
    		tab.fontType = font;
    		tab.textColor = color;
    		tab.centerText = true;
    	}
    	/**
    	 * @param id - The ID of the Interface (Index in interfaceCache array)
    	 * @param spriteLocation - The directory in the cache where the sprites are
    	 * @param offSprite - The ID of the sprite when the mouse is not over the button
    	 * @param hoverSprite - The ID of the sprite when the mouse is over the button
    	 * @param hoverTooltip - The menu action text for the button (right click)
    	 * @param font - The ID of the font for the text on the button (0 = small, 1 = regular, 2 = bold, 3 = fancy)
    	 * @param color - The color of the text on top of the button
    	 * @param buttonText - The text on top of the button
    	 * @param msgX - The X position of the text on the button, relative to the position of the button
    	 * @param msgY - The Y position of the text on the button, relative to the position of the button
    	 */
    	public static void hoverButton(int id, String spriteLocation, int offSprite, int hoverSprite, String hoverTooltip, int font, int color, String buttonText, int msgX, int msgY) {
    		RSInterface tab = addInterface(id);
    		tab.tooltip = hoverTooltip;
    		tab.atActionType = 1;
    		tab.type = 42;
    		tab.sprite1 = imageLoader(offSprite, spriteLocation);
    		tab.sprite2 = imageLoader(hoverSprite, spriteLocation);
    		tab.width = tab.sprite1.myWidth;
    		tab.height = tab.sprite1.myHeight;
    		tab.messageOffsetX = msgX;
    		tab.messageOffsetY = msgY;
    		tab.message = buttonText;
    		tab.fontType = font;
    		tab.textColor = color;
    		tab.centerText = false;
    	}
    	public RSFont getFont() {
    		switch (fontType) {
    		case 0: return Client.instance.newSmallFont;
    		case 1: return Client.instance.newRegularFont;
    		case 2: return Client.instance.bold;
    		case 3: return Client.instance.fancy;
    		}
    		return Client.instance.newSmallFont;
    	}





    Step 2:
    Open Client.java and add this somewhere

    Code:
    	private static RSInterface buttonHovered = null;



    Step 3:
    Still in Client.java go to void drawInterface(int j, int k, RSInterface class9, int l)


    Search for this part:
    Code:
    				 else if (class9_1.type == 6) {
    					int k3 = Rasterizer.textureInt1;
    					int j4 = Rasterizer.textureInt2;
    					Rasterizer.textureInt1 = k2 + class9_1.width / 2;
    					Rasterizer.textureInt2 = l2 + class9_1.height / 2;
    					int i5 = Rasterizer.anIntArray1470[class9_1.modelRotation1]
    							* class9_1.modelZoom >> 16;
    					int l5 = Rasterizer.anIntArray1471[class9_1.modelRotation1]
    							* class9_1.modelZoom >> 16;
    					boolean flag2 = interfaceIsSelected(class9_1);
    					int i7;
    					if (flag2)
    						i7 = class9_1.anInt258;
    					else
    						i7 = class9_1.anInt257;
    					Model model;
    					if (i7 == -1) {
    						model = class9_1.method209(-1, -1, flag2);
    					} else {
    						Animation animation = Animation.anims[i7];
    						model = class9_1.method209(
    								animation.anIntArray354[class9_1.anInt246],
    								animation.anIntArray353[class9_1.anInt246],
    								flag2);
    					}
    					if (model != null)
    						model.method482(class9_1.modelRotation2, 0,
    								class9_1.modelRotation1, 0, i5, l5);
    					Rasterizer.textureInt1 = k3;
    					Rasterizer.textureInt2 = j4;
    				}
    Add this after it:
    Code:
     				else if (class9_1.type == 42) {
    					if (buttonHovered == class9_1) {
    						class9_1.sprite2.drawSprite(k2, l2);
    					} else {
    						class9_1.sprite1.drawSprite(k2, l2);
    					}
    					if (class9_1.centerText)
    						class9_1.getFont().drawCenteredString(class9_1.message, k2 + class9_1.messageOffsetX, l2 + class9_1.messageOffsetY, class9_1.textColor, class9_1.shadowColor);
    					else
    						class9_1.getFont().drawString(class9_1.message, k2 + 5 + class9_1.messageOffsetX, l2 + class9_1.messageOffsetY, class9_1.textColor, class9_1.shadowColor);
    				}



    Step 3:
    (Still in Client.java) Now for the last part, we need to make the hovering of the buttons work.


    Find this method:
    Code:
    private void buildInterfaceMenu(int i, RSInterface class9, int k, int l, int i1, int j1) {
    And use your search bar to find this part:
    Code:
         .atActionType == 1
    You should see something like this:
    Code:
    				if (class9_1.atActionType == 1) {
    					if (k >= i2 && i1 >= j2 && k < i2 + class9_1.width && i1 < j2 + class9_1.height) {
    						boolean flag = false;

    add this in there
    Code:
    						if (class9_1.type == 42) {
    							buttonHovered = class9_1;
    						}


    Now Search for:
    Code:
    	private void draw3dScreen() {
    and before the very last bracket at the end of the method
    add this:

    Code:
    	buttonHovered = null;






    Result (Made a simple interface for testing purposes):


    Here's the RSInterface code & sprites for the interface in the gif, in case you want to see how it works.

    Code:
    	public static void testButtons() {
    		RSInterface tab = addInterface(27000);
    		
    		addSprite(27001, 0, "test/SPRITE");
    		
    		tab.totalChildren(2);
    		tab.child(0, 27001, 10, 10);
    		tab.child(1, 27005, 127, 85);
    		
    		RSInterface scroll = addInterface(27005);
    		
    		hoverButton(27006, "test/SPRITE", 1, 2, "Confirm", 1, 0xffffff, "Hello xD");
    		hoverButton(27007, "test/SPRITE", 1, 2, "Confirm", 1, 0xffff00, "Text here");
    		hoverButton(27008, "test/SPRITE", 1, 2, "Confirm", 0, 0x00ffff, "Ima button");
    		hoverButton(27009, "test/SPRITE", 1, 2, "Confirm", 2, 0xffffff, "Kappa");
    		hoverButton(27010, "test/SPRITE", 1, 2, "Confirm", 3, 0xffffff, "Fancy");
    		
    		scroll.totalChildren(5);
    		for (int i = 0; i < 5; ++i) {
    			scroll.child(i, 27006 + i, 6, 6 + (37 * i));
    		}
    		
    		scroll.width = 120;
    		scroll.height = 145;
    		scroll.scrollMax = 300;
    	}
    Sprites:
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  2. #2  
    Donator


    Join Date
    Jan 2010
    Age
    24
    Posts
    3,875
    Thanks given
    241
    Thanks received
    428
    Rep Power
    442
    Good job not a fan of it, looks better with normal button sprites. also mabye its better fixing the proper system in the client instead of creating a new type.
    Reply With Quote  
     

  3. #3  
    Member Market Banned Market Banned

    Join Date
    Jan 2017
    Posts
    88
    Thanks given
    119
    Thanks received
    39
    Rep Power
    16
    Brilliant stuff keith.
    Reply With Quote  
     

  4. #4  
    Retard Strength


    Join Date
    Jul 2014
    Posts
    1,805
    Thanks given
    922
    Thanks received
    533
    Rep Power
    546
    Quote Originally Posted by Nighel View Post
    Good job not a fan of it, looks better with normal button sprites. also mabye its better fixing the proper system in the client instead of creating a new type.
    U can use ur own sprites m8, those are just shits i made in 5 seconds on paint.

    Plus the old system is shite, so might as well make a new type.
    Reply With Quote  
     

  5. #5  
    Donator


    Join Date
    Jan 2010
    Age
    24
    Posts
    3,875
    Thanks given
    241
    Thanks received
    428
    Rep Power
    442
    Quote Originally Posted by Hitten View Post
    U can use ur own sprites m8, those are just shits i made in 5 seconds on paint.

    Plus the old system is shite, so might as well make a new type.
    My bad looked like you made those boxes with the client itself
    Reply With Quote  
     

  6. Thankful user:


  7. #6  
    Donator

    Join Date
    Feb 2018
    Posts
    56
    Thanks given
    21
    Thanks received
    9
    Rep Power
    11
    Quote Originally Posted by Nighel View Post
    My bad looked like you made those boxes with the client itself
    Even if he did, you could still adjust the color/ect yourself :P

    Nice snippet mate!
    Reply With Quote  
     

  8. #7  
    Banned
    Join Date
    Dec 2017
    Posts
    48
    Thanks given
    47
    Thanks received
    29
    Rep Power
    0
    Quote Originally Posted by Hitten View Post
    U can use ur own sprites m8, those are just shits i made in 5 seconds on paint.

    Plus the old system is shite, so might as well make a new type.
    Cool you could have done this better tho this is what i have for the same result apart from the text drawing (Going to add that now I've seen yours )

    Code:
    	public static void addButton(int id, int sid,int sid2, String tooltip) {
    		Widget tab = interfaceCache[id] = new Widget();
    		tab.id = id;
    		tab.parent = id;
    		tab.type = 90;
    		tab.optionType = 1;
    		tab.contentType = 0;
    		tab.opacity = (byte) 0;
    		tab.hoverType = 52;
    		tab.disabledSprite = Client.spriteCache.lookup(sid);
    		tab.enabledSprite = Client.spriteCache.lookup(sid);
    		tab.customhoverbutton = sid2;
    		tab.width = tab.disabledSprite.myWidth;
    		tab.height = tab.enabledSprite.myHeight;
    		tab.tooltip = tooltip;
    	}
    and for the type

    Code:
    } else if (child.type == 90) {
    						Sprite sprite;
    						if (interfaceIsSelected(child)) {
    							sprite = child.enabledSprite;
    						} else {
    							sprite = child.disabledSprite;
    						}
    						sprite.drawHoverSprite(_x, _y,spriteCache.lookup(child.customhoverbutton));
    As you can see the system is a lot smaller
    Reply With Quote  
     

  9. Thankful user:


  10. #8  
    Registered Member
    Join Date
    Sep 2011
    Posts
    29
    Thanks given
    1
    Thanks received
    1
    Rep Power
    11
    It still didn't work mate



    Code:
    
            hoverButton(51015, "/Interfaces/SlayerHelmet/BUTTONS", 1, 2, "Revert Colour", 1, 0xffffff, "");
    Reply With Quote  
     

  11. #9  
    Registered Member

    Join Date
    Aug 2017
    Posts
    365
    Thanks given
    273
    Thanks received
    129
    Rep Power
    141
    a bit overkill for an easy fix in the original code, abt time someone released a fix for this tho lol, nice
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

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

Similar Threads

  1. Replies: 27
    Last Post: 05-11-2013, 10:06 AM
  2. [NON]Remove the "New User" Button!
    By Wiffles in forum Tutorials
    Replies: 22
    Last Post: 08-05-2010, 09:07 AM
  3. Hovering button appearing in wrong place
    By The Myth in forum Help
    Replies: 2
    Last Post: 03-28-2010, 09:44 PM
  4. new jframe button
    By Robin Spud in forum Requests
    Replies: 1
    Last Post: 01-30-2009, 02:42 AM
  5. New chatbox buttons(click areas + writing)
    By razvanx in forum Tutorials
    Replies: 8
    Last Post: 06-22-2008, 11:36 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •