Advertisement
Benjamin_Loison

GuiPhone

Jul 12th, 2018
420
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.83 KB | None | 0 0
  1. package fr.altiscraft.benjaminloison.gui;
  2.  
  3. import org.lwjgl.opengl.GL11;
  4.  
  5. import fr.altiscraft.benjaminloison.api.FileAPI;
  6. import fr.altiscraft.benjaminloison.common.AltisCraft;
  7. import fr.altiscraft.benjaminloison.packets.PacketSendMessage;
  8. import net.minecraft.client.Minecraft;
  9. import net.minecraft.client.entity.EntityClientPlayerMP;
  10. import net.minecraft.client.gui.GuiButton;
  11. import net.minecraft.client.gui.GuiScreen;
  12. import net.minecraft.client.gui.GuiTextField;
  13. import net.minecraft.client.resources.I18n;
  14. import net.minecraft.util.ChatComponentText;
  15. import net.minecraft.util.ResourceLocation;
  16.  
  17. public class GuiPhone extends GuiScreen
  18. {
  19.     int guiWidth = 350, guiHeight = 200;
  20.     private GuiTextField message, player;
  21.     boolean back;
  22.  
  23.     public GuiPhone(boolean back)
  24.     {
  25.         this.back = back;
  26.         if(back)
  27.             buttonList.add(new CustomBlackButton(1, (width - guiWidth) / 2 + 2, (height - guiHeight) / 2 + 144, I18n.format("back"), 50, 20));
  28.     }
  29.  
  30.     @Override
  31.     public void drawScreen(int x, int y, float ticks)
  32.     {
  33.         int guiX = (width - guiWidth) / 2, guiY = (height - guiHeight) / 2;
  34.         GL11.glColor4f(1, 1, 1, 1);
  35.         mc.renderEngine.bindTexture(new ResourceLocation(AltisCraft.MODID, "textures/gui/Inventory Background.png"));
  36.         drawTexturedModalRect(guiX, guiY, 0, 0, guiWidth - 3, 15);
  37.         mc.renderEngine.bindTexture(new ResourceLocation(AltisCraft.MODID, "textures/gui/Dark Background.png"));
  38.         drawTexturedModalRect(guiX, guiY + 16, 0, 0, guiWidth - 3, 150);
  39.         fontRendererObj.drawString((I18n.format("item.phone.name")), guiX + 5, guiY + 5, 0xFFFFFF);
  40.         message.drawTextBox();
  41.         player.drawTextBox();
  42.         super.drawScreen(x, y, ticks);
  43.     }
  44.  
  45.     @Override
  46.     public void initGui()
  47.     {
  48.         int guiX = (width - guiWidth) / 2, guiY = (height - guiHeight) / 2;
  49.         buttonList.clear();
  50.         buttonList.add(new CustomBlackButton(0, guiX + 295, guiY + 144, I18n.format("close"), 50, 20));
  51.         buttonList.add(new CustomOrangeButton(2, guiX + 141, guiY + 105, I18n.format("gui.staff"), 60, 20));
  52.         buttonList.add(new CustomOrangeButton(3, guiX + 15, guiY + 80, I18n.format("send"), 60, 20));
  53.         buttonList.add(new CustomOrangeButton(4, guiX + 78, guiY + 80, I18n.format("gui.police"), 60, 20));
  54.         buttonList.add(new CustomOrangeButton(5, guiX + 141, guiY + 80, I18n.format("gui.doctor"), 60, 20));
  55.         buttonList.add(new CustomOrangeButton(6, guiX + 204, guiY + 80, I18n.format("gui.repairman"), 60, 20));
  56.         buttonList.add(new CustomOrangeButton(7, guiX + 267, guiY + 80, I18n.format("gui.transaltis"), 60, 20));
  57.         message = new GuiTextField(fontRendererObj, guiX + 15, guiY + 60, 310, 15);
  58.         message.setMaxStringLength(FileAPI.configNumberInt("message.maximum.length"));
  59.         message.setText(I18n.format("default.message.field"));
  60.         message.setFocused(true);
  61.         player = new GuiTextField(fontRendererObj, guiX + 15, guiY + 107, 120, 15);
  62.         player.setMaxStringLength(FileAPI.configNumberInt("message.maximum.length"));
  63.         player.setText(I18n.format("default.player.field"));
  64.         super.initGui();
  65.     }
  66.  
  67.     protected void keyTyped(char c, int i)
  68.     {
  69.         super.keyTyped(c, i);
  70.         message.textboxKeyTyped(c, i);
  71.         player.textboxKeyTyped(c, i);
  72.     }
  73.  
  74.     protected void mouseClicked(int x, int y, int btn)
  75.     {
  76.         super.mouseClicked(x, y, btn);
  77.         message.mouseClicked(x, y, btn);
  78.         player.mouseClicked(x, y, btn);
  79.     }
  80.  
  81.     @Override
  82.     protected void actionPerformed(GuiButton btn)
  83.     {
  84.         EntityClientPlayerMP thePlayer = Minecraft.getMinecraft().thePlayer;
  85.         int x = thePlayer.getPlayerCoordinates().posX, y = thePlayer.getPlayerCoordinates().posY, z = thePlayer.getPlayerCoordinates().posZ;
  86.         if(btn.id == 0)
  87.             Minecraft.getMinecraft().displayGuiScreen(null);
  88.         else if(btn.id == 1)
  89.             Minecraft.getMinecraft().displayGuiScreen(new GuiInv());
  90.         else if(btn.id > 1)
  91.             if(message.getText().length() >= FileAPI.configNumber("minimum.message.length"))
  92.             {
  93.                 Minecraft.getMinecraft().displayGuiScreen(null);
  94.                 Minecraft.getMinecraft().displayGuiScreen(new GuiPhone(back));
  95.                 if(btn.id == 2)
  96.                 {
  97.                     thePlayer.sendChatMessage("/helpop " + message.getText());
  98.                     thePlayer.addChatComponentMessage(new ChatComponentText(I18n.format("message.has.been.sent")));
  99.                 }
  100.                 else if(btn.id == 3)
  101.                     thePlayer.sendChatMessage("/msg" + " " + player.getText() + " " + message.getText());
  102.                 else if(btn.id == 4)
  103.                     AltisCraft.instance.network.sendToServer(new PacketSendMessage(I18n.format("message.grade", I18n.format("police"), x, y, z, thePlayer.getDisplayName(), message.getText()), "police"));
  104.                 else if(btn.id == 5)
  105.                     AltisCraft.instance.network.sendToServer(new PacketSendMessage(I18n.format("message.grade", I18n.format("doctor"), x, y, z, thePlayer.getDisplayName(), message.getText()), "doctor"));
  106.                 else if(btn.id == 6)
  107.                     AltisCraft.instance.network.sendToServer(new PacketSendMessage(I18n.format("message.grade", I18n.format("repairman"), x, y, z, thePlayer.getDisplayName(), message.getText()), "repairman"));
  108.                 else if(btn.id == 7)
  109.                     AltisCraft.instance.network.sendToServer(new PacketSendMessage(I18n.format("message.grade", I18n.format("transaltis"), x, y, z, thePlayer.getDisplayName(), message.getText()), "transaltis"));
  110.             }
  111.             else
  112.                 thePlayer.addChatComponentMessage(new ChatComponentText(I18n.format("message.must.be.longer.than.minimum.message.length.characters")));
  113.     }
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement