2015-06-12 19:12:06 +02:00
|
|
|
package ellpeck.actuallyadditions.inventory.gui;
|
2015-03-19 21:27:56 +01:00
|
|
|
|
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
2015-06-12 19:12:06 +02:00
|
|
|
import ellpeck.actuallyadditions.inventory.ContainerInputter;
|
2015-03-19 21:27:56 +01:00
|
|
|
import ellpeck.actuallyadditions.network.PacketHandler;
|
2015-06-12 19:12:06 +02:00
|
|
|
import ellpeck.actuallyadditions.network.gui.PacketGuiButton;
|
2015-03-19 21:27:56 +01:00
|
|
|
import ellpeck.actuallyadditions.tile.TileEntityBase;
|
|
|
|
import ellpeck.actuallyadditions.tile.TileEntityInputter;
|
2015-03-29 15:29:05 +02:00
|
|
|
import ellpeck.actuallyadditions.util.AssetUtil;
|
|
|
|
import ellpeck.actuallyadditions.util.ModUtil;
|
2015-06-12 19:12:06 +02:00
|
|
|
import ellpeck.actuallyadditions.util.StringUtil;
|
2015-03-19 21:27:56 +01:00
|
|
|
import net.minecraft.client.Minecraft;
|
|
|
|
import net.minecraft.client.gui.FontRenderer;
|
|
|
|
import net.minecraft.client.gui.GuiButton;
|
|
|
|
import net.minecraft.client.gui.inventory.GuiContainer;
|
|
|
|
import net.minecraft.client.renderer.OpenGlHelper;
|
|
|
|
import net.minecraft.entity.player.InventoryPlayer;
|
|
|
|
import net.minecraft.util.ResourceLocation;
|
|
|
|
import net.minecraft.util.StatCollector;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import org.lwjgl.opengl.GL11;
|
|
|
|
|
2015-06-12 19:12:06 +02:00
|
|
|
import java.util.Collections;
|
|
|
|
|
2015-03-19 21:27:56 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public class GuiInputter extends GuiContainer{
|
|
|
|
|
2015-03-29 15:29:05 +02:00
|
|
|
private static final ResourceLocation resLoc = AssetUtil.getGuiLocation("guiInputter");
|
2015-04-04 05:20:19 +02:00
|
|
|
private static final ResourceLocation resLocAdvanced = AssetUtil.getGuiLocation("guiInputterAdvanced");
|
|
|
|
|
2015-03-19 21:27:56 +01:00
|
|
|
private TileEntityInputter tileInputter;
|
|
|
|
|
|
|
|
private int x;
|
|
|
|
private int y;
|
|
|
|
private int z;
|
|
|
|
private World world;
|
|
|
|
|
|
|
|
private SmallerButton buttonSlotPutP;
|
|
|
|
private SmallerButton buttonSlotPullP;
|
|
|
|
private SmallerButton buttonSlotPutM;
|
|
|
|
private SmallerButton buttonSlotPullM;
|
|
|
|
|
2015-06-12 19:12:06 +02:00
|
|
|
private SmallerButton whitelistPut;
|
|
|
|
private SmallerButton whitelistPull;
|
|
|
|
|
2015-04-04 05:20:19 +02:00
|
|
|
private boolean isAdvanced;
|
|
|
|
|
2015-06-12 19:12:06 +02:00
|
|
|
public static final int OFFSET_ADVANCED = 35;
|
|
|
|
|
2015-03-19 21:27:56 +01:00
|
|
|
public static final String[] sideString = new String[]{
|
2015-03-29 15:29:05 +02:00
|
|
|
StatCollector.translateToLocal("info." + ModUtil.MOD_ID_LOWER + ".gui.disabled"),
|
|
|
|
StatCollector.translateToLocal("info." + ModUtil.MOD_ID_LOWER + ".gui.up"),
|
|
|
|
StatCollector.translateToLocal("info." + ModUtil.MOD_ID_LOWER + ".gui.down"),
|
|
|
|
StatCollector.translateToLocal("info." + ModUtil.MOD_ID_LOWER + ".gui.north"),
|
|
|
|
StatCollector.translateToLocal("info." + ModUtil.MOD_ID_LOWER + ".gui.east"),
|
|
|
|
StatCollector.translateToLocal("info." + ModUtil.MOD_ID_LOWER + ".gui.south"),
|
|
|
|
StatCollector.translateToLocal("info." + ModUtil.MOD_ID_LOWER + ".gui.west")};
|
2015-03-19 21:27:56 +01:00
|
|
|
|
2015-04-04 05:20:19 +02:00
|
|
|
public GuiInputter(InventoryPlayer inventory, TileEntityBase tile, int x, int y, int z, World world, boolean isAdvanced){
|
|
|
|
super(new ContainerInputter(inventory, tile, isAdvanced));
|
2015-03-19 21:27:56 +01:00
|
|
|
this.tileInputter = (TileEntityInputter)tile;
|
|
|
|
this.x = x;
|
|
|
|
this.y = y;
|
|
|
|
this.z = z;
|
|
|
|
this.world = world;
|
|
|
|
this.xSize = 176;
|
2015-06-12 19:12:06 +02:00
|
|
|
this.ySize = 93+86 + (isAdvanced ? 12+OFFSET_ADVANCED : 0);
|
2015-04-04 05:20:19 +02:00
|
|
|
this.isAdvanced = isAdvanced;
|
2015-03-19 21:27:56 +01:00
|
|
|
}
|
|
|
|
|
2015-04-19 01:50:02 +02:00
|
|
|
@Override
|
|
|
|
public void drawGuiContainerForegroundLayer(int x, int y){
|
2015-05-20 22:39:43 +02:00
|
|
|
AssetUtil.displayNameString(this.fontRendererObj, xSize, -10, this.tileInputter.getInventoryName());
|
2015-04-19 01:50:02 +02:00
|
|
|
}
|
|
|
|
|
2015-03-19 21:27:56 +01:00
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@Override
|
|
|
|
public void initGui(){
|
|
|
|
super.initGui();
|
|
|
|
|
2015-06-12 19:12:06 +02:00
|
|
|
SmallerButton buttonSidePutP = new SmallerButton(0, guiLeft + 155, guiTop + 43 + (isAdvanced ? 12+OFFSET_ADVANCED : 0), ">");
|
|
|
|
SmallerButton buttonSidePutM = new SmallerButton(1, guiLeft + 90, guiTop + 43 + (isAdvanced ? 12+OFFSET_ADVANCED : 0), "<");
|
|
|
|
buttonSlotPutP = new SmallerButton(2, guiLeft+ 155, guiTop + 64 + (isAdvanced ? 12+OFFSET_ADVANCED : 0), "+");
|
|
|
|
buttonSlotPutM = new SmallerButton(3, guiLeft + 90, guiTop + 64 + (isAdvanced ? 12+OFFSET_ADVANCED : 0), "-");
|
|
|
|
|
|
|
|
SmallerButton buttonSidePullP = new SmallerButton(4, guiLeft + 70, guiTop + 43 + (isAdvanced ? 12+OFFSET_ADVANCED : 0), ">");
|
|
|
|
SmallerButton buttonSidePullM = new SmallerButton(5, guiLeft + 5, guiTop + 43 + (isAdvanced ? 12+OFFSET_ADVANCED : 0), "<");
|
|
|
|
buttonSlotPullP = new SmallerButton(6, guiLeft + 70, guiTop + 64 + (isAdvanced ? 12+OFFSET_ADVANCED : 0), "+");
|
|
|
|
buttonSlotPullM = new SmallerButton(7, guiLeft + 5, guiTop + 64 + (isAdvanced ? 12+OFFSET_ADVANCED : 0), "-");
|
2015-03-19 21:27:56 +01:00
|
|
|
|
2015-06-12 19:12:06 +02:00
|
|
|
whitelistPull = new SmallerButton(TileEntityInputter.WHITELIST_PULL_BUTTON_ID, guiLeft+3, guiTop+16, "");
|
|
|
|
whitelistPut = new SmallerButton(TileEntityInputter.WHITELIST_PUT_BUTTON_ID, guiLeft+157, guiTop+16, "");
|
2015-03-19 21:27:56 +01:00
|
|
|
|
|
|
|
this.buttonList.add(buttonSidePutP);
|
|
|
|
this.buttonList.add(buttonSlotPutP);
|
|
|
|
this.buttonList.add(buttonSidePullP);
|
|
|
|
this.buttonList.add(buttonSlotPullP);
|
|
|
|
this.buttonList.add(buttonSidePutM);
|
|
|
|
this.buttonList.add(buttonSlotPutM);
|
|
|
|
this.buttonList.add(buttonSidePullM);
|
|
|
|
this.buttonList.add(buttonSlotPullM);
|
2015-06-12 19:12:06 +02:00
|
|
|
if(this.isAdvanced){
|
|
|
|
this.buttonList.add(whitelistPut);
|
|
|
|
this.buttonList.add(whitelistPull);
|
|
|
|
}
|
2015-03-19 21:27:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void drawGuiContainerBackgroundLayer(float f, int x, int y){
|
|
|
|
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
|
|
|
|
2015-03-29 15:29:05 +02:00
|
|
|
this.mc.getTextureManager().bindTexture(AssetUtil.GUI_INVENTORY_LOCATION);
|
2015-06-12 19:12:06 +02:00
|
|
|
this.drawTexturedModalRect(this.guiLeft, this.guiTop+93 + (isAdvanced ? 12+OFFSET_ADVANCED : 0), 0, 0, 176, 86);
|
2015-03-19 21:27:56 +01:00
|
|
|
|
2015-04-04 05:20:19 +02:00
|
|
|
this.mc.getTextureManager().bindTexture(this.isAdvanced ? resLocAdvanced : resLoc);
|
2015-06-12 19:12:06 +02:00
|
|
|
this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, 176, 93 + (isAdvanced ? 12+OFFSET_ADVANCED : 0));
|
2015-03-19 21:27:56 +01:00
|
|
|
|
2015-06-12 19:12:06 +02:00
|
|
|
this.fontRendererObj.drawString(StatCollector.translateToLocal("info." + ModUtil.MOD_ID_LOWER + ".gui.pull"), guiLeft + 22 + 3, guiTop + 32 + (isAdvanced ? 12+OFFSET_ADVANCED : 0), 4210752);
|
|
|
|
this.fontRendererObj.drawString(StatCollector.translateToLocal("info." + ModUtil.MOD_ID_LOWER + ".gui.put"), guiLeft + 107 + 3, guiTop + 32 + (isAdvanced ? 12+OFFSET_ADVANCED : 0), 4210752);
|
2015-03-19 21:27:56 +01:00
|
|
|
|
2015-06-12 19:12:06 +02:00
|
|
|
this.fontRendererObj.drawString(sideString[tileInputter.sideToPull+1], guiLeft + 24 + 1, guiTop + 45 + 3 + (isAdvanced ? 12+36 : 0), 4210752);
|
|
|
|
this.fontRendererObj.drawString(StatCollector.translateToLocal("info." + ModUtil.MOD_ID_LOWER + ".gui.slot") + " " + (tileInputter.slotToPut == -1 ? StatCollector.translateToLocal("info." + ModUtil.MOD_ID_LOWER + ".gui.all") : tileInputter.slotToPull).toString(), guiLeft + 24 + 3, guiTop + 66 + 3 + (isAdvanced ? 12+OFFSET_ADVANCED : 0), StringUtil.DECIMAL_COLOR_GRAY_TEXT);
|
2015-03-19 21:27:56 +01:00
|
|
|
|
2015-06-12 19:12:06 +02:00
|
|
|
this.fontRendererObj.drawString(sideString[tileInputter.sideToPut+1], guiLeft + 109 + 1, guiTop + 45 + 3 + (isAdvanced ? 12+36 : 0), 4210752);
|
|
|
|
this.fontRendererObj.drawString(StatCollector.translateToLocal("info." + ModUtil.MOD_ID_LOWER + ".gui.slot") + " " + (tileInputter.slotToPut == -1 ? StatCollector.translateToLocal("info." + ModUtil.MOD_ID_LOWER + ".gui.all") : tileInputter.slotToPut).toString(), guiLeft + 109 + 3, guiTop + 66 + 3 + (isAdvanced ? 12+OFFSET_ADVANCED : 0), StringUtil.DECIMAL_COLOR_GRAY_TEXT);
|
2015-03-19 21:27:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void drawScreen(int x, int y, float f){
|
|
|
|
super.drawScreen(x, y, f);
|
|
|
|
|
|
|
|
this.buttonSlotPullP.enabled = this.tileInputter.placeToPullSlotAmount > 0;
|
|
|
|
this.buttonSlotPullM.enabled = this.tileInputter.placeToPullSlotAmount > 0;
|
|
|
|
|
|
|
|
this.buttonSlotPutP.enabled = this.tileInputter.placeToPutSlotAmount > 0;
|
|
|
|
this.buttonSlotPutM.enabled = this.tileInputter.placeToPutSlotAmount > 0;
|
2015-06-12 19:12:06 +02:00
|
|
|
|
|
|
|
this.whitelistPull.displayString = this.tileInputter.isPullWhitelist ? "O" : "X";
|
|
|
|
this.whitelistPut.displayString = this.tileInputter.isPutWhitelist ? "O" : "X";
|
|
|
|
|
|
|
|
if(this.isAdvanced){
|
|
|
|
String text1 = this.tileInputter.isPullWhitelist ? StatCollector.translateToLocal("info."+ModUtil.MOD_ID_LOWER+".gui.whitelist") : StatCollector.translateToLocal("info."+ModUtil.MOD_ID_LOWER+".gui.blacklist");
|
|
|
|
if(x >= guiLeft+3 && y >= guiTop+16 && x <= guiLeft+18 && y <= guiTop+31){
|
|
|
|
this.func_146283_a(Collections.singletonList(text1), x, y);
|
|
|
|
}
|
|
|
|
String text2 = this.tileInputter.isPutWhitelist ? StatCollector.translateToLocal("info."+ModUtil.MOD_ID_LOWER+".gui.whitelist") : StatCollector.translateToLocal("info."+ModUtil.MOD_ID_LOWER+".gui.blacklist");
|
|
|
|
if(x >= guiLeft+157 && y >= guiTop+16 && x <= guiLeft+172 && y <= guiTop+31){
|
|
|
|
this.func_146283_a(Collections.singletonList(text2), x, y);
|
|
|
|
}
|
|
|
|
}
|
2015-03-19 21:27:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void actionPerformed(GuiButton button){
|
2015-06-12 19:12:06 +02:00
|
|
|
PacketHandler.theNetwork.sendToServer(new PacketGuiButton(x, y, z, world, button.id, Minecraft.getMinecraft().thePlayer));
|
2015-03-19 21:27:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public class SmallerButton extends GuiButton{
|
|
|
|
|
2015-03-29 15:29:05 +02:00
|
|
|
private final ResourceLocation resLoc = AssetUtil.getGuiLocation("guiInputter");
|
2015-03-19 21:27:56 +01:00
|
|
|
|
|
|
|
public SmallerButton(int id, int x, int y, String display){
|
|
|
|
super(id, x, y, 16, 16, display);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void drawButton(Minecraft mc, int x, int y){
|
|
|
|
if (this.visible){
|
|
|
|
FontRenderer renderer = mc.fontRenderer;
|
|
|
|
mc.getTextureManager().bindTexture(resLoc);
|
|
|
|
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
|
|
|
this.field_146123_n = x >= this.xPosition && y >= this.yPosition && x < this.xPosition + this.width && y < this.yPosition + this.height;
|
|
|
|
int k = this.getHoverState(this.field_146123_n);
|
|
|
|
GL11.glEnable(GL11.GL_BLEND);
|
|
|
|
OpenGlHelper.glBlendFunc(770, 771, 1, 0);
|
|
|
|
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
this.drawTexturedModalRect(this.xPosition, this.yPosition, 176, k*16, 16, 16);
|
|
|
|
this.mouseDragged(mc, x, y);
|
|
|
|
|
|
|
|
int color = 14737632;
|
|
|
|
if (packedFGColour != 0) color = packedFGColour;
|
|
|
|
else if (!this.enabled) color = 10526880;
|
|
|
|
else if (this.field_146123_n) color = 16777120;
|
|
|
|
|
2015-03-20 18:58:31 +01:00
|
|
|
this.drawCenteredString(renderer, this.displayString, this.xPosition + this.width / 2, this.yPosition + (this.height-8) / 2, color);
|
2015-03-19 21:27:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|