Guest User

Gui Class

a guest
Feb 28th, 2016
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.38 KB | None | 0 0
  1. public class GUICPU extends GuiContainer {
  2.  
  3.     public static final ResourceLocation texturegui = new ResourceLocation("programmaticraft:textures/gui/guicpu.png");
  4.     private TileEntityCPU te;
  5.     private GuiButton doneBtn;
  6.     private GuiButton cancelBtn;
  7.     private GuiTextField terminalBox1;
  8.     private GuiTextField terminalBox2;
  9.     private GuiTextField terminalBox3;
  10.     private GuiTextField terminalBox4;
  11.     private GuiTextField terminalBox5;
  12.     private GuiTextField terminalBox6;
  13.     private GuiTextField terminalBox7;
  14.     private GuiTextField terminalBox8;
  15.     private GuiTextField terminalBox9;
  16.     private int xSize;
  17.     private int ySize;
  18.     private BlockPos pos;
  19.    
  20.     public GUICPU(Container con, BlockPos pos, TileEntityCPU tile) {
  21.         super(con);
  22.         this.xSize = 209;
  23.         this.ySize = 232;
  24.         this.pos = pos;
  25.         this.te = (TileEntityCPU) tile;
  26.         System.out.println(this.pos);
  27.         System.out.println(this.te);
  28.         }  
  29.    
  30.     protected void mouseClicked(int x, int y, int btn) throws IOException {
  31.         super.mouseClicked(x, y, btn);
  32.         this.terminalBox1.mouseClicked(x, y, btn);
  33.         this.terminalBox2.mouseClicked(x, y, btn);
  34.         this.terminalBox3.mouseClicked(x, y, btn);
  35.         this.terminalBox4.mouseClicked(x, y, btn);
  36.         this.terminalBox5.mouseClicked(x, y, btn);
  37.         this.terminalBox6.mouseClicked(x, y, btn);
  38.         this.terminalBox7.mouseClicked(x, y, btn);
  39.         this.terminalBox8.mouseClicked(x, y, btn);
  40.         this.terminalBox9.mouseClicked(x, y, btn);
  41.     }
  42.    
  43.     public void onGuiClosed()
  44.     {
  45.         Keyboard.enableRepeatEvents(false);
  46.     }
  47.    
  48.     public void initGui()
  49.     {
  50.         Keyboard.enableRepeatEvents(true);
  51.         this.buttonList.clear();
  52.         System.out.println(this.te.stringList);
  53.         this.buttonList.add(this.doneBtn = new GuiButton(0, this.width / 2 - 90, this.height / 4 + 170, 81, 20, I18n.format("gui.done", new Object[0])));
  54.         this.buttonList.add(this.cancelBtn = new GuiButton(1, this.width / 2 - 9, this.height / 4 + 170, 81, 20, I18n.format("gui.cancel", new Object[0])));
  55.         this.fontRendererObj.drawString("Code Editor" , (this.width / 2) - (this.xSize / 2) + 5, (this.height / 2) - (this.ySize / 2) - 10, 4210752);
  56.         this.terminalBox1 = new GuiTextField(2, this.fontRendererObj, this.width / 2 - 150, this.height / 2 - this.ySize/2 - 40, 150, 20);
  57.         this.terminalBox1.setMaxStringLength(200);
  58.         this.terminalBox1.setFocused(true);
  59.         this.terminalBox1.setText(( this.te.getLine(0)));
  60.         this.terminalBox2 = new GuiTextField(3, this.fontRendererObj, this.width / 2 - 150, this.height / 2- this.ySize/2- 20, 150, 20);
  61.         this.terminalBox2.setMaxStringLength(200);
  62.         this.terminalBox2.setFocused(false);
  63.         this.terminalBox2.setText(( this.te.getLine(1)));
  64.         this.terminalBox3 = new GuiTextField(4, this.fontRendererObj, this.width / 2 - 150, this.height / 2- this.ySize/2 - 0, 150, 20);
  65.         this.terminalBox3.setMaxStringLength(200);
  66.         this.terminalBox3.setFocused(false);
  67.         this.terminalBox3.setText(( this.te.getLine(2)));
  68.         this.terminalBox4 = new GuiTextField(5, this.fontRendererObj, this.width / 2 - 150, this.height / 2- this.ySize/2 + 20, 150, 20);
  69.         this.terminalBox4.setMaxStringLength(200);
  70.         this.terminalBox4.setFocused(false);
  71.         this.terminalBox4.setText(( this.te.getLine(3)));
  72.         this.terminalBox5 = new GuiTextField(6, this.fontRendererObj, this.width / 2 - 150, this.height / 2 - this.ySize/2+ 40, 150, 20);
  73.         this.terminalBox5.setMaxStringLength(200);
  74.         this.terminalBox5.setFocused(false);
  75.         this.terminalBox5.setText(( this.te.getLine(4)));
  76.         this.terminalBox6 = new GuiTextField(7, this.fontRendererObj, this.width / 2 - 150, this.height / 2- this.ySize/2 + 60, 150, 20);
  77.         this.terminalBox6.setMaxStringLength(200);
  78.         this.terminalBox6.setFocused(false);
  79.         this.terminalBox6.setText(( this.te.getLine(5)));
  80.         this.terminalBox7 = new GuiTextField(8, this.fontRendererObj, this.width / 2 - 150, this.height / 2- this.ySize/2 + 80, 150, 20);
  81.         this.terminalBox7.setMaxStringLength(200);
  82.         this.terminalBox7.setFocused(false);
  83.         this.terminalBox7.setText(( this.te.getLine(6)));
  84.         this.terminalBox8 = new GuiTextField(9, this.fontRendererObj, this.width / 2 - 150, this.height / 2- this.ySize/2 + 100, 150, 20);
  85.         this.terminalBox8.setMaxStringLength(200);
  86.         this.terminalBox8.setFocused(false);
  87.         this.terminalBox8.setText(( this.te.getLine(7)));
  88.         this.terminalBox9 = new GuiTextField(10, this.fontRendererObj, this.width / 2 - 150, this.height / 2- this.ySize/2 + 120, 150, 20);
  89.         this.terminalBox9.setMaxStringLength(200);
  90.         this.terminalBox9.setFocused(false);
  91.         this.terminalBox9.setText(( this.te.getLine(8)));
  92.        
  93.     }
  94.    
  95.     protected void actionPerformed(GuiButton button) throws IOException
  96.     {
  97.         if (button.enabled)
  98.         {
  99.             if (button.id == 1)
  100.             {
  101.                 this.mc.displayGuiScreen((GuiScreen)null);
  102.             }
  103.             else if (button.id == 0)
  104.             {
  105.                 PacketBuffer buffer = new PacketBuffer(Unpooled.buffer());
  106.                 this.te.setLine(this.terminalBox1.getText(), 0);
  107.                 this.te.setLine(this.terminalBox2.getText(), 1);
  108.                 this.te.setLine(this.terminalBox3.getText(), 2);
  109.                 this.te.setLine(this.terminalBox4.getText(), 3);
  110.                 this.te.setLine(this.terminalBox5.getText(), 4);
  111.                 this.te.setLine(this.terminalBox6.getText(), 5);
  112.                 this.te.setLine(this.terminalBox7.getText(), 6);
  113.                 this.te.setLine(this.terminalBox8.getText(), 7);
  114.                 this.te.setLine(this.terminalBox9.getText(), 8);
  115.                 System.out.println(this.te.stringList);
  116.                
  117.                 for (int i = 0; i < 9; )    {
  118.                     switch (i) {
  119.                     case 0: {
  120.                         Main.network.sendToServer(new PacketCPU(this.terminalBox1.getText(), buffer)); break;}
  121.                     case 1: {
  122.                         Main.network.sendToServer(new PacketCPU(this.terminalBox2.getText(), buffer)); break;}
  123.                     case 2: {
  124.                         Main.network.sendToServer(new PacketCPU(this.terminalBox3.getText(), buffer)); break;}
  125.                     case 3: {
  126.                         Main.network.sendToServer(new PacketCPU(this.terminalBox4.getText(), buffer)); break;}
  127.                     case 4: {
  128.                         Main.network.sendToServer(new PacketCPU(this.terminalBox5.getText(), buffer)); break;}
  129.                     case 5: {
  130.                         Main.network.sendToServer(new PacketCPU(this.terminalBox6.getText(), buffer)); break;}
  131.                     case 6: {
  132.                         Main.network.sendToServer(new PacketCPU(this.terminalBox7.getText(), buffer)); break;}
  133.                     case 7: {
  134.                         Main.network.sendToServer(new PacketCPU(this.terminalBox8.getText(), buffer)); break;}
  135.                     case 8: {
  136.                         Main.network.sendToServer(new PacketCPU(this.terminalBox9.getText(), buffer)); break;}
  137.                     }
  138.                     System.out.println(buffer);
  139.                     i++;
  140.                 }
  141.                 this.mc.displayGuiScreen((GuiScreen)null);
  142.  
  143.                
  144.             }
  145.            
  146.         }
  147.     }
  148.    
  149.     protected void keyTyped(char par1, int par2) throws IOException
  150.     {
  151.         this.terminalBox1.textboxKeyTyped(par1, par2);
  152.         this.terminalBox2.textboxKeyTyped(par1, par2);
  153.         this.terminalBox3.textboxKeyTyped(par1, par2);
  154.         this.terminalBox4.textboxKeyTyped(par1, par2);
  155.         this.terminalBox5.textboxKeyTyped(par1, par2);
  156.         this.terminalBox6.textboxKeyTyped(par1, par2);
  157.         this.terminalBox7.textboxKeyTyped(par1, par2);
  158.         this.terminalBox8.textboxKeyTyped(par1, par2);
  159.         this.terminalBox9.textboxKeyTyped(par1, par2);
  160.         if(!( par2 == Keyboard.KEY_E))super.keyTyped(par1, par2);
  161.     }
  162.    
  163.     public void updateScreen()
  164.     {
  165.         super.updateScreen();
  166.         this.terminalBox1.updateCursorCounter();
  167.         this.terminalBox2.updateCursorCounter();
  168.         this.terminalBox3.updateCursorCounter();
  169.         this.terminalBox4.updateCursorCounter();
  170.         this.terminalBox5.updateCursorCounter();
  171.         this.terminalBox6.updateCursorCounter();
  172.         this.terminalBox7.updateCursorCounter();
  173.         this.terminalBox8.updateCursorCounter();
  174.         this.terminalBox9.updateCursorCounter();
  175.     }
  176.  
  177.     @Override
  178.     protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
  179.         GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f);
  180.         this.mc.getTextureManager().bindTexture(texturegui);
  181.         int i = (this.width - this.xSize) / 2;
  182.         int j = (this.height - this.ySize) / 2;
  183.         this.drawTexturedModalRect(i, j, 0, 0, this.xSize, this.ySize);
  184.        
  185.     }
  186.     @Override
  187.     protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
  188.  
  189.         this.terminalBox1.drawTextBox();
  190.         this.terminalBox2.drawTextBox();
  191.         this.terminalBox3.drawTextBox();
  192.         this.terminalBox4.drawTextBox();
  193.         this.terminalBox5.drawTextBox();
  194.         this.terminalBox6.drawTextBox();
  195.         this.terminalBox7.drawTextBox();
  196.         this.terminalBox8.drawTextBox();
  197.         this.terminalBox9.drawTextBox();
  198.     }
  199.    
  200.     @Override
  201.     public boolean doesGuiPauseGame() {
  202.         return false;
  203.     }
  204.  
  205. }
Advertisement
Add Comment
Please, Sign In to add comment