2015-08-29 14:33:25 +02:00
|
|
|
/*
|
2016-05-16 22:52:27 +02:00
|
|
|
* This file ("GuiSmileyCloud.java") is part of the Actually Additions mod for Minecraft.
|
2015-08-29 14:33:25 +02:00
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
2016-05-16 22:52:27 +02:00
|
|
|
* http://ellpeck.de/actaddlicense
|
2015-08-29 14:33:25 +02:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2017-01-01 16:23:26 +01:00
|
|
|
* © 2015-2017 Ellpeck
|
2015-08-29 14:33:25 +02:00
|
|
|
*/
|
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
package de.ellpeck.actuallyadditions.mod.inventory.gui;
|
2015-08-23 23:41:46 +02:00
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.inventory.ContainerSmileyCloud;
|
2016-06-15 16:43:59 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.network.PacketClientToServer;
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.network.PacketHandler;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.tile.TileEntitySmileyCloud;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
|
2015-08-23 23:41:46 +02:00
|
|
|
import net.minecraft.client.Minecraft;
|
|
|
|
import net.minecraft.client.gui.GuiTextField;
|
2016-01-08 15:21:05 +01:00
|
|
|
import net.minecraft.client.renderer.GlStateManager;
|
2016-06-15 16:43:59 +02:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2015-08-23 23:41:46 +02:00
|
|
|
import net.minecraft.util.ResourceLocation;
|
2016-03-18 23:47:22 +01:00
|
|
|
import net.minecraft.util.text.TextFormatting;
|
2015-08-23 23:41:46 +02:00
|
|
|
import net.minecraft.world.World;
|
2016-01-07 18:20:59 +01:00
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
2015-08-23 23:41:46 +02:00
|
|
|
import org.lwjgl.input.Keyboard;
|
|
|
|
|
2016-01-08 08:10:55 +01:00
|
|
|
import java.io.IOException;
|
|
|
|
|
2015-08-23 23:41:46 +02:00
|
|
|
@SideOnly(Side.CLIENT)
|
2017-06-17 00:48:49 +02:00
|
|
|
public class GuiSmileyCloud extends GuiWtfMojang{
|
2015-08-23 23:41:46 +02:00
|
|
|
|
2016-11-19 23:12:22 +01:00
|
|
|
private static final ResourceLocation RES_LOC = AssetUtil.getGuiLocation("gui_smiley_cloud");
|
2015-08-23 23:41:46 +02:00
|
|
|
|
2016-05-19 20:05:12 +02:00
|
|
|
private final int x;
|
|
|
|
private final int y;
|
|
|
|
private final int z;
|
|
|
|
private final World world;
|
|
|
|
private final TileEntitySmileyCloud cloud;
|
2016-06-01 00:39:35 +02:00
|
|
|
private GuiTextField nameField;
|
2015-08-23 23:41:46 +02:00
|
|
|
|
|
|
|
public GuiSmileyCloud(TileEntityBase tile, int x, int y, int z, World world){
|
|
|
|
super(new ContainerSmileyCloud());
|
|
|
|
this.cloud = (TileEntitySmileyCloud)tile;
|
|
|
|
this.x = x;
|
|
|
|
this.y = y;
|
|
|
|
this.z = z;
|
|
|
|
this.world = world;
|
|
|
|
this.xSize = 124;
|
|
|
|
this.ySize = 20;
|
|
|
|
}
|
|
|
|
|
2015-10-03 10:19:40 +02:00
|
|
|
@Override
|
|
|
|
public void initGui(){
|
|
|
|
super.initGui();
|
|
|
|
|
2017-06-29 18:30:02 +02:00
|
|
|
this.nameField = new GuiTextField(4000, this.fontRenderer, this.guiLeft+5, this.guiTop+6, 114, 8);
|
2015-10-03 10:19:40 +02:00
|
|
|
this.nameField.setMaxStringLength(20);
|
|
|
|
this.nameField.setEnableBackgroundDrawing(false);
|
|
|
|
this.nameField.setFocused(true);
|
|
|
|
}
|
|
|
|
|
2015-08-23 23:41:46 +02:00
|
|
|
@Override
|
|
|
|
public void drawGuiContainerForegroundLayer(int x, int y){
|
2016-05-02 17:46:53 +02:00
|
|
|
String name = this.cloud.name == null || this.cloud.name.isEmpty() ? "" : TextFormatting.GOLD+this.cloud.name+TextFormatting.RESET+" "+StringUtil.localize("info."+ModUtil.MOD_ID+".gui.the")+" ";
|
2016-04-20 21:39:03 +02:00
|
|
|
String localizedName = name+StringUtil.localize("container."+ModUtil.MOD_ID+".cloud.name");
|
2017-06-29 18:30:02 +02:00
|
|
|
this.fontRenderer.drawString(localizedName, this.xSize/2-this.fontRenderer.getStringWidth(localizedName)/2, -10, StringUtil.DECIMAL_COLOR_WHITE);
|
2015-08-23 23:41:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-10-03 10:19:40 +02:00
|
|
|
public void drawGuiContainerBackgroundLayer(float f, int x, int y){
|
2016-01-08 15:21:05 +01:00
|
|
|
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
2015-08-23 23:41:46 +02:00
|
|
|
|
2016-06-17 23:50:38 +02:00
|
|
|
this.mc.getTextureManager().bindTexture(RES_LOC);
|
2015-10-03 10:19:40 +02:00
|
|
|
this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);
|
2015-08-23 23:41:46 +02:00
|
|
|
|
2015-10-03 10:19:40 +02:00
|
|
|
this.nameField.drawTextBox();
|
2015-08-23 23:41:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-01-08 08:10:55 +01:00
|
|
|
protected void mouseClicked(int par1, int par2, int par3) throws IOException{
|
2015-08-23 23:41:46 +02:00
|
|
|
this.nameField.mouseClicked(par1, par2, par3);
|
|
|
|
super.mouseClicked(par1, par2, par3);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-01-08 08:10:55 +01:00
|
|
|
public void keyTyped(char theChar, int key) throws IOException{
|
2015-08-23 23:41:46 +02:00
|
|
|
if(key != 1 && this.nameField.isFocused()){
|
|
|
|
if(key == Keyboard.KEY_RETURN || key == Keyboard.KEY_NUMPADENTER){
|
|
|
|
this.setVariable(this.nameField);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
this.nameField.textboxKeyTyped(theChar, key);
|
|
|
|
}
|
|
|
|
}
|
2015-10-02 16:48:01 +02:00
|
|
|
else{
|
|
|
|
super.keyTyped(theChar, key);
|
|
|
|
}
|
2015-08-23 23:41:46 +02:00
|
|
|
}
|
|
|
|
|
2015-10-03 10:19:40 +02:00
|
|
|
@Override
|
|
|
|
public void updateScreen(){
|
|
|
|
super.updateScreen();
|
|
|
|
this.nameField.updateCursorCounter();
|
|
|
|
}
|
|
|
|
|
2015-08-23 23:41:46 +02:00
|
|
|
public void setVariable(GuiTextField field){
|
|
|
|
this.sendPacket(field.getText(), 0);
|
|
|
|
field.setText("");
|
|
|
|
}
|
|
|
|
|
|
|
|
private void sendPacket(String text, int textID){
|
2016-06-15 16:43:59 +02:00
|
|
|
NBTTagCompound compound = new NBTTagCompound();
|
|
|
|
compound.setInteger("X", this.x);
|
|
|
|
compound.setInteger("Y", this.y);
|
|
|
|
compound.setInteger("Z", this.z);
|
|
|
|
compound.setInteger("WorldID", this.world.provider.getDimension());
|
2016-11-26 21:32:27 +01:00
|
|
|
compound.setInteger("PlayerID", Minecraft.getMinecraft().player.getEntityId());
|
2016-06-15 16:43:59 +02:00
|
|
|
compound.setInteger("TextID", textID);
|
|
|
|
compound.setString("Text", text);
|
2016-07-25 22:38:37 +02:00
|
|
|
PacketHandler.theNetwork.sendToServer(new PacketClientToServer(compound, PacketHandler.GUI_STRING_TO_TILE_HANDLER));
|
2015-08-23 23:41:46 +02:00
|
|
|
}
|
|
|
|
}
|