Don't like ads? PRO users don't see any ads ;-)
Guest

GuiConsole.java

By: a guest on Jun 27th, 2012  |  syntax: Java  |  size: 8.70 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. package net.minecraft.src;
  2.  
  3. import java.lang.reflect.Method;
  4. import java.net.URI;
  5. import java.util.*;
  6.  
  7. import jm.hack.Var;
  8. import net.minecraft.client.Minecraft;
  9. import org.lwjgl.input.Keyboard;
  10. import org.lwjgl.input.Mouse;
  11.  
  12. public class GuiConsole extends GuiScreen
  13. {
  14.     private String field_50062_b;
  15.     private int field_50063_c;
  16.     private boolean field_50060_d;
  17.     private String field_50061_e;
  18.     private String field_50059_f;
  19.     private int field_50067_h;
  20.     private List field_50068_i;
  21.     private URI field_50065_j;
  22.     protected GuiTextField field_50064_a;
  23.     private String field_50066_k;
  24.  
  25.     public GuiConsole()
  26.     {
  27.         field_50062_b = "";
  28.         field_50063_c = -1;
  29.         field_50060_d = false;
  30.         field_50061_e = "";
  31.         field_50059_f = "";
  32.         field_50067_h = 0;
  33.         field_50068_i = new ArrayList();
  34.         field_50065_j = null;
  35.         field_50066_k = "";
  36.     }
  37.  
  38.     public GuiConsole(String par1Str)
  39.     {
  40.         field_50062_b = "";
  41.         field_50063_c = -1;
  42.         field_50060_d = false;
  43.         field_50061_e = "";
  44.         field_50059_f = "";
  45.         field_50067_h = 0;
  46.         field_50068_i = new ArrayList();
  47.         field_50065_j = null;
  48.         field_50066_k = "";
  49.         field_50066_k = par1Str;
  50.     }
  51.  
  52.     /**
  53.      * Adds the buttons (and other controls) to the screen in question.
  54.      */
  55.     public void initGui()
  56.     {
  57.         Keyboard.enableRepeatEvents(true);
  58.         field_50063_c = mc.ingameGUI.func_50013_c().size();
  59.         field_50064_a = new GuiTextField(fontRenderer, 4, height - 12, width - 4, 12);
  60.         field_50064_a.setMaxStringLength(100);
  61.         field_50064_a.func_50027_a(false);
  62.         field_50064_a.func_50033_b(true);
  63.         field_50064_a.setText(field_50066_k);
  64.         field_50064_a.func_50026_c(false);
  65.     }
  66.  
  67.     /**
  68.      * Called when the screen is unloaded. Used to disable keyboard repeat events
  69.      */
  70.     public void onGuiClosed()
  71.     {
  72.         Keyboard.enableRepeatEvents(false);
  73.         mc.ingameGUI.func_50014_d();
  74.     }
  75.  
  76.     /**
  77.      * Called from the main game loop to update the screen.
  78.      */
  79.     public void updateScreen()
  80.     {
  81.         field_50064_a.updateCursorCounter();
  82.     }
  83.  
  84.     /**
  85.      * Fired when a key is typed. This is the equivalent of KeyListener.keyTyped(KeyEvent e).
  86.      */
  87.     protected void keyTyped(char par1, int par2)
  88.     {  
  89.         if (par2 == 15)
  90.         {
  91.             completePlayerName();
  92.         }
  93.         else
  94.         {
  95.             field_50060_d = false;
  96.         }
  97.  
  98.         if (par2 == 1)
  99.         {
  100.             mc.displayGuiScreen(null);
  101.         }
  102.         else if (par2 == 28)
  103.         {
  104.             String s = field_50064_a.getText().trim();
  105.             /**ADD TOGGLES HERE*/
  106.             if(s.startsWith("test")){
  107.                 Var.test=!Var.test;
  108.             }
  109.             if(s.startsWith("xray")){
  110.                 Var.xray =!Var.xray;
  111.             }
  112.             mc.displayGuiScreen(null);
  113.             return;
  114.         }
  115.         else if (par2 == 200)
  116.         {
  117.             func_50058_a(-1);
  118.         }
  119.         else if (par2 == 208)
  120.         {
  121.             func_50058_a(1);
  122.         }
  123.         else if (par2 == 201)
  124.         {
  125.             mc.ingameGUI.func_50011_a(19);
  126.         }
  127.         else if (par2 == 209)
  128.         {
  129.             mc.ingameGUI.func_50011_a(-19);
  130.         }
  131.         else
  132.         {
  133.             field_50064_a.func_50037_a(par1, par2);
  134.         }
  135.     }
  136.  
  137.     /**
  138.      * Handles mouse input.
  139.      */
  140.     public void handleMouseInput()
  141.     {
  142.         super.handleMouseInput();
  143.         int i = Mouse.getEventDWheel();
  144.  
  145.         if (i != 0)
  146.         {
  147.             if (i > 1)
  148.             {
  149.                 i = 1;
  150.             }
  151.  
  152.             if (i < -1)
  153.             {
  154.                 i = -1;
  155.             }
  156.  
  157.             if (!func_50049_m())
  158.             {
  159.                 i *= 7;
  160.             }
  161.  
  162.             mc.ingameGUI.func_50011_a(i);
  163.         }
  164.     }
  165.  
  166.     /**
  167.      * Called when the mouse is clicked.
  168.      */
  169.     protected void mouseClicked(int par1, int par2, int par3)
  170.     {
  171.         if (par3 == 0)
  172.         {
  173.             ChatClickData chatclickdata = mc.ingameGUI.func_50012_a(Mouse.getX(), Mouse.getY());
  174.  
  175.             if (chatclickdata != null)
  176.             {
  177.                 URI uri = chatclickdata.func_50089_b();
  178.  
  179.                 if (uri != null)
  180.                 {
  181.                     field_50065_j = uri;
  182.                     return;
  183.                 }
  184.             }
  185.         }
  186.  
  187.         field_50064_a.mouseClicked(par1, par2, par3);
  188.         super.mouseClicked(par1, par2, par3);
  189.     }
  190.  
  191.     public void confirmClicked(boolean par1, int par2)
  192.     {
  193.         if (par2 == 0)
  194.         {
  195.             if (par1)
  196.             {
  197.                 try
  198.                 {
  199.                     Class class1 = Class.forName("java.awt.Desktop");
  200.                     Object obj = class1.getMethod("getDesktop", new Class[0]).invoke(null, new Object[0]);
  201.                     class1.getMethod("browse", new Class[]
  202.                             {
  203.                                 java.net.URI.class
  204.                             }).invoke(obj, new Object[]
  205.                                     {
  206.                                         field_50065_j
  207.                                     });
  208.                 }
  209.                 catch (Throwable throwable)
  210.                 {
  211.                     throwable.printStackTrace();
  212.                 }
  213.             }
  214.  
  215.             field_50065_j = null;
  216.             mc.displayGuiScreen(this);
  217.         }
  218.     }
  219.  
  220.     /**
  221.      * Autocompletes player name
  222.      */
  223.     public void completePlayerName()
  224.     {
  225.         if (field_50060_d)
  226.         {
  227.             field_50064_a.func_50021_a(-1);
  228.  
  229.             if (field_50067_h >= field_50068_i.size())
  230.             {
  231.                 field_50067_h = 0;
  232.             }
  233.         }
  234.         else
  235.         {
  236.             int i = field_50064_a.func_50028_c(-1);
  237.  
  238.             if (field_50064_a.func_50035_h() - i < 1)
  239.             {
  240.                 return;
  241.             }
  242.  
  243.             field_50068_i.clear();
  244.             field_50061_e = field_50064_a.getText().substring(i);
  245.             field_50059_f = field_50061_e.toLowerCase();
  246.             Iterator iterator = ((EntityClientPlayerMP)mc.thePlayer).sendQueue.playerNames.iterator();
  247.  
  248.             do
  249.             {
  250.                 if (!iterator.hasNext())
  251.                 {
  252.                     break;
  253.                 }
  254.  
  255.                 GuiPlayerInfo guiplayerinfo = (GuiPlayerInfo)iterator.next();
  256.  
  257.                 if (guiplayerinfo.nameStartsWith(field_50059_f))
  258.                 {
  259.                     field_50068_i.add(guiplayerinfo);
  260.                 }
  261.             }
  262.             while (true);
  263.  
  264.             if (field_50068_i.size() == 0)
  265.             {
  266.                 return;
  267.             }
  268.  
  269.             field_50060_d = true;
  270.             field_50067_h = 0;
  271.             field_50064_a.func_50020_b(i - field_50064_a.func_50035_h());
  272.         }
  273.  
  274.         if (field_50068_i.size() > 1)
  275.         {
  276.             StringBuilder stringbuilder = new StringBuilder();
  277.             GuiPlayerInfo guiplayerinfo1;
  278.  
  279.             for (Iterator iterator1 = field_50068_i.iterator(); iterator1.hasNext(); stringbuilder.append(guiplayerinfo1.name))
  280.             {
  281.                 guiplayerinfo1 = (GuiPlayerInfo)iterator1.next();
  282.  
  283.                 if (stringbuilder.length() > 0)
  284.                 {
  285.                     stringbuilder.append(", ");
  286.                 }
  287.             }
  288.  
  289.             mc.ingameGUI.addChatMessage(stringbuilder.toString());
  290.         }
  291.  
  292.         field_50064_a.func_50031_b(((GuiPlayerInfo)field_50068_i.get(field_50067_h++)).name);
  293.     }
  294.  
  295.     public void func_50058_a(int par1)
  296.     {
  297.         int i = field_50063_c + par1;
  298.         int j = mc.ingameGUI.func_50013_c().size();
  299.  
  300.         if (i < 0)
  301.         {
  302.             i = 0;
  303.         }
  304.  
  305.         if (i > j)
  306.         {
  307.             i = j;
  308.         }
  309.  
  310.         if (i == field_50063_c)
  311.         {
  312.             return;
  313.         }
  314.  
  315.         if (i == j)
  316.         {
  317.             field_50063_c = j;
  318.             field_50064_a.setText(field_50062_b);
  319.             return;
  320.         }
  321.  
  322.         if (field_50063_c == j)
  323.         {
  324.             field_50062_b = field_50064_a.getText();
  325.         }
  326.  
  327.         field_50064_a.setText((String)mc.ingameGUI.func_50013_c().get(i));
  328.         field_50063_c = i;
  329.     }
  330.  
  331.     /**
  332.      * Draws the screen and all the components in it.
  333.      */
  334.     public void drawScreen(int par1, int par2, float par3)
  335.     {
  336.         drawRect(2, height - 14, width - 2, height - 2, 0x80000000);
  337.         drawRect(0,height-16,width,height,0x90000000);
  338.         field_50064_a.drawTextBox();
  339.         super.drawScreen(par1, par2, par3);
  340.     }
  341. }