Advertisement
SnubMansters

GuiNameDog

Jun 16th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.65 KB | None | 0 0
  1. package com.github.copiousdogs.client.gui;
  2.  
  3. import net.minecraft.client.gui.GuiButton;
  4. import net.minecraft.client.gui.GuiScreen;
  5. import net.minecraft.client.gui.GuiTextField;
  6. import net.minecraft.client.resources.I18n;
  7. import net.minecraft.util.ResourceLocation;
  8.  
  9. import org.lwjgl.input.Keyboard;
  10. import org.lwjgl.opengl.GL11;
  11.  
  12. import com.github.copiousdogs.entity.EntityDog;
  13. import com.github.copiousdogs.lib.Reference;
  14.  
  15. import cpw.mods.fml.common.FMLCommonHandler;
  16. import cpw.mods.fml.relauncher.Side;
  17.  
  18. public class GuiNameDog extends GuiScreen {
  19.  
  20.     private EntityDog dog;
  21.     private GuiTextField nameField;
  22.    
  23.     public GuiNameDog(EntityDog dog) {
  24.        
  25.         this.dog = dog;
  26.     }
  27.    
  28.     @Override
  29.     public void initGui() {
  30.        
  31.         Keyboard.enableRepeatEvents(true);
  32.         this.buttonList.clear();
  33.         this.buttonList.add(new GuiButton(0, this.width / 2 - 50, this.height / 2 + 15, 100, 20, I18n.format("gui.copiousdogs.done", new Object[0])));
  34.         nameField = new GuiTextField(this.fontRendererObj, this.width / 2 - 100, this.height / 2 - 10, 200, 20);
  35.         nameField.setFocused(true);
  36.         nameField.setText("");
  37.     }
  38.    
  39.     @Override
  40.     protected void actionPerformed(GuiButton button) {
  41.        
  42.         if (button.id == 0) {
  43.            
  44.             String comp = nameField.getText().replaceAll("\\s", "");
  45.            
  46.             if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT)
  47.             {
  48.                 if (comp != "") {
  49.                     dog.setDogname(nameField.getText());
  50.                 }
  51.             }
  52.            
  53.             this.mc.displayGuiScreen(null);
  54.             dog.doname();
  55.         }
  56.     }
  57.    
  58.     @Override
  59.     public void drawBackground(int p_146278_1_) {
  60.        
  61.         GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  62.         this.mc.getTextureManager().bindTexture(new ResourceLocation(Reference.MOD_ID + ":textures/gui/name_dog.png"));
  63.         int k = (this.width - 232) / 2;
  64.         int l = (this.height - 86) / 2;
  65.         this.drawTexturedModalRect(k, l, 0, 0, 232, 86);
  66.     }
  67.    
  68.     @Override
  69.     public void drawScreen(int p_73863_1_, int p_73863_2_, float p_73863_3_) {
  70.  
  71.         this.drawBackground(0);
  72.        
  73.         String s = I18n.format("gui.copiousdogs.namedog", new Object[0]);
  74.         this.fontRendererObj.drawString(s, (this.width - this.fontRendererObj.getStringWidth(s)) / 2, this.height / 2 - 30, 4210752);
  75.        
  76.         nameField.drawTextBox();
  77.        
  78.         super.drawScreen(p_73863_1_, p_73863_2_, p_73863_3_);
  79.     }
  80.    
  81.     @Override
  82.     protected void keyTyped(char c, int i) {
  83.        
  84.         if (nameField.isFocused()) {
  85.            
  86.             nameField.textboxKeyTyped(c, i);
  87.         }
  88.        
  89.         if (i == Keyboard.KEY_ESCAPE) {
  90.            
  91.             this.mc.displayGuiScreen(null);
  92.         }
  93.     }
  94.    
  95.     @Override
  96.     public boolean doesGuiPauseGame() {
  97.        
  98.         return true;
  99.     }
  100.    
  101.     @Override
  102.     public void onGuiClosed() {
  103.        
  104.         Keyboard.enableRepeatEvents(false);
  105.     }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement