Facebook
From Toxic Wolf, 4 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 269
  1. import java.util.ArrayList;
  2.  
  3. import java.util.List;
  4.  
  5.  
  6.  
  7. import org.apache.logging.log4j.core.appender.rolling.helper.Action;
  8.  
  9.  
  10.  
  11. import net.minecraft.client.Minecraft;
  12.  
  13. import net.minecraft.client.gui.FontRenderer;
  14.  
  15. import net.minecraft.client.gui.GuiButton;
  16.  
  17.  
  18.  
  19. public class CustomButton extends GuiButton {
  20.  
  21.  
  22.  
  23.         private List<ButtonAction> actions;
  24.  
  25.        
  26.  
  27.         public void drawBorderedRect(int x, int y, int x1, int y1, int size, int borderC, int insideC) {
  28.  
  29.                 drawRect(x + size, y + size, x1 - size, y1 - size, insideC);
  30.  
  31.                 drawRect(x + size, y + size, x1, y, borderC);
  32.  
  33.                 drawRect(x, y, x + size, y1, borderC);
  34.  
  35.                 drawRect(x1, y1, x1 - size, y + size, borderC);
  36.  
  37.                 drawRect(x, y1 - size, x1, y1, borderC);
  38.  
  39.         }
  40.  
  41.  
  42.  
  43.         public CustomButton(int id, int x, int y, String s) {
  44.  
  45.                 this(id, x, y, 200, 20, s);
  46.  
  47.         }
  48.  
  49.  
  50.  
  51.         public CustomButton(int id, int x, int y, int l, int i1, String s) {
  52.  
  53.                 super(id, x, y, l, i1, s);
  54.  
  55.                 actions = new ArrayList<>();
  56.  
  57.         }
  58.  
  59.        
  60.  
  61.         public void press(){
  62.  
  63.                 for(ButtonAction action : actions) {
  64.  
  65.                         action.execute();
  66.  
  67.                 }
  68.  
  69.         }
  70.  
  71.        
  72.  
  73.         public void addAction(ButtonAction action) {
  74.  
  75.                 actions.add(action);
  76.  
  77.         }
  78.  
  79.  
  80.  
  81.         protected int getHoverState(boolean flag) {
  82.  
  83.                 byte byte0 = 1;
  84.  
  85.                 if (!enabled) {
  86.  
  87.                         byte0 = 0;
  88.  
  89.                 } else if (flag) {
  90.  
  91.                         byte0 = 2;
  92.  
  93.                 }
  94.  
  95.                 return byte0;
  96.  
  97.         }
  98.  
  99.  
  100.  
  101.         public void drawButton(Minecraft mc, int mx, int my) {
  102.  
  103.                 if(!visible){
  104.  
  105.                         return;
  106.  
  107.                 }
  108.  
  109.                 FontRenderer fontrenderer = mc.fontRendererObj;
  110.  
  111.                 boolean flag = mx >= xPosition && my >= yPosition && mx < xPosition + width && my < yPosition + height; // Flag,
  112.  
  113.                 // button
  114.  
  115.                 if (flag) { // Hover Action
  116.  
  117.                         drawBorderedRect(xPosition, yPosition, xPosition + width, yPosition + height, 1, 0xFF000000, 0x80000000);
  118.  
  119.                         drawCenteredString(fontrenderer, displayString, xPosition + width / 2, yPosition + (height - 8) / 2,
  120.  
  121.                                         0xff666666);
  122.  
  123.                 } else { // Normal
  124.  
  125.                         drawBorderedRect(xPosition, yPosition, xPosition + width, yPosition + height, 1, 0x900d0d0d, 0x90262626);
  126.  
  127.                         drawCenteredString(fontrenderer, displayString, xPosition + width / 2, yPosition + (height - 8) / 2,
  128.  
  129.                                         0xFFCCCCCC);
  130.  
  131.                 }
  132.  
  133.         }
  134.  
  135.  
  136.  
  137. }