diff options
| author | Raven Szewczyk <git@eigenraven.me> | 2024-05-24 19:50:35 +0100 |
|---|---|---|
| committer | Raven Szewczyk <git@eigenraven.me> | 2024-05-24 19:50:35 +0100 |
| commit | 6d1b2216464d4dad449ac6fcfec476832224a55e (patch) | |
| tree | 526a0c15f7056313c80e6c0386e025e9b3f61781 /src/main/java/gtPlusPlus/core/gui | |
| parent | b5d35f40afa606ed1b07061dad82e0521a59c186 (diff) | |
| download | GT5-Unofficial-6d1b2216464d4dad449ac6fcfec476832224a55e.tar.gz GT5-Unofficial-6d1b2216464d4dad449ac6fcfec476832224a55e.tar.bz2 GT5-Unofficial-6d1b2216464d4dad449ac6fcfec476832224a55e.zip | |
Merge addon sources
Diffstat (limited to 'src/main/java/gtPlusPlus/core/gui')
12 files changed, 904 insertions, 0 deletions
diff --git a/src/main/java/gtPlusPlus/core/gui/GUI_Base_Tile_Entity.java b/src/main/java/gtPlusPlus/core/gui/GUI_Base_Tile_Entity.java new file mode 100644 index 0000000000..379827a1db --- /dev/null +++ b/src/main/java/gtPlusPlus/core/gui/GUI_Base_Tile_Entity.java @@ -0,0 +1,14 @@ +package gtPlusPlus.core.gui; + +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.inventory.Container; + +public abstract class GUI_Base_Tile_Entity extends GuiContainer { + + public final Container mContainer; + + public GUI_Base_Tile_Entity(Container aContainer) { + super(aContainer); + mContainer = aContainer; + } +} diff --git a/src/main/java/gtPlusPlus/core/gui/beta/Gui_ID_Registry.java b/src/main/java/gtPlusPlus/core/gui/beta/Gui_ID_Registry.java new file mode 100644 index 0000000000..7da3d1a35c --- /dev/null +++ b/src/main/java/gtPlusPlus/core/gui/beta/Gui_ID_Registry.java @@ -0,0 +1,47 @@ +package gtPlusPlus.core.gui.beta; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import gtPlusPlus.core.interfaces.IGuiManagerMiscUtils; + +public class Gui_ID_Registry { + + private static final Map<Class<? extends IGuiManagerMiscUtils>, MU_GuiId> classMap = new HashMap<>(); + private static final Map<Integer, MU_GuiId> idMap = new HashMap<>(); + private static int nextId = 0; + + static {} + + private static void registerGuiHandlers(final Gui_Types MU_GuiType, + final List<Class<? extends IGuiManagerMiscUtils>> guiHandlerClasses) { + for (final Class<? extends IGuiManagerMiscUtils> tileGuiHandlerClass : guiHandlerClasses) { + final MU_GuiId guiId = new MU_GuiId(nextId++, MU_GuiType, tileGuiHandlerClass); + classMap.put(tileGuiHandlerClass, guiId); + idMap.put(Integer.valueOf(guiId.getId()), guiId); + } + } + + public static MU_GuiId getGuiIdForGuiHandler(final IGuiManagerMiscUtils guiHandler) { + final Class<? extends IGuiManagerMiscUtils> guiHandlerClass = guiHandler.getClass(); + MU_GuiId guiId = classMap.get(guiHandlerClass); + if (guiId == null) { + for (final Map.Entry<Class<? extends IGuiManagerMiscUtils>, MU_GuiId> classGuiIdEntry : classMap + .entrySet()) { + if (((Class<?>) classGuiIdEntry.getKey()).isAssignableFrom(guiHandlerClass)) { + guiId = classGuiIdEntry.getValue(); + break; + } + } + } + if (guiId == null) { + throw new IllegalStateException("No gui ID for gui handler: " + guiHandler); + } + return guiId; + } + + public static MU_GuiId getGuiId(final int id) { + return idMap.get(Integer.valueOf(id)); + } +} diff --git a/src/main/java/gtPlusPlus/core/gui/beta/Gui_Types.java b/src/main/java/gtPlusPlus/core/gui/beta/Gui_Types.java new file mode 100644 index 0000000000..f0bf946b23 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/gui/beta/Gui_Types.java @@ -0,0 +1,10 @@ +package gtPlusPlus.core.gui.beta; + +public enum Gui_Types { + + Item, + Tile, + Entity; + + private Gui_Types() {} +} diff --git a/src/main/java/gtPlusPlus/core/gui/beta/MU_GuiId.java b/src/main/java/gtPlusPlus/core/gui/beta/MU_GuiId.java new file mode 100644 index 0000000000..8b15f5b937 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/gui/beta/MU_GuiId.java @@ -0,0 +1,28 @@ +package gtPlusPlus.core.gui.beta; + +import gtPlusPlus.core.interfaces.IGuiManagerMiscUtils; + +public class MU_GuiId { + + private final int id; + private final Gui_Types MU_GuiType; + private final Class<? extends IGuiManagerMiscUtils> guiHandlerClass; + + MU_GuiId(final int id, final Gui_Types MU_GuiType, final Class<? extends IGuiManagerMiscUtils> guiHandlerClass) { + this.id = id; + this.MU_GuiType = MU_GuiType; + this.guiHandlerClass = guiHandlerClass; + } + + public Gui_Types getGuiType() { + return this.MU_GuiType; + } + + public Class<? extends IGuiManagerMiscUtils> getGuiHandlerClass() { + return this.guiHandlerClass; + } + + public int getId() { + return this.id; + } +} diff --git a/src/main/java/gtPlusPlus/core/gui/machine/GUI_CircuitProgrammer.java b/src/main/java/gtPlusPlus/core/gui/machine/GUI_CircuitProgrammer.java new file mode 100644 index 0000000000..71d3b36470 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/gui/machine/GUI_CircuitProgrammer.java @@ -0,0 +1,46 @@ +package gtPlusPlus.core.gui.machine; + +import static gregtech.api.enums.Mods.GTPlusPlus; + +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.util.ResourceLocation; + +import org.lwjgl.opengl.GL11; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gtPlusPlus.core.container.Container_CircuitProgrammer; +import gtPlusPlus.core.tileentities.general.TileEntityCircuitProgrammer; + +@SideOnly(Side.CLIENT) +public class GUI_CircuitProgrammer extends GuiContainer { + + private static final ResourceLocation craftingTableGuiTextures = new ResourceLocation( + GTPlusPlus.ID, + "textures/gui/CircuitProgrammer.png"); + + public GUI_CircuitProgrammer(final InventoryPlayer player_inventory, final TileEntityCircuitProgrammer te) { + super(new Container_CircuitProgrammer(player_inventory, te)); + } + + @Override + protected void drawGuiContainerForegroundLayer(final int i, final int j) { + super.drawGuiContainerForegroundLayer(i, j); + } + + @Override + protected void drawGuiContainerBackgroundLayer(final float f, final int i, final int j) { + GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + this.mc.renderEngine.bindTexture(craftingTableGuiTextures); + final int x = (this.width - this.xSize) / 2; + final int y = (this.height - this.ySize) / 2; + this.drawTexturedModalRect(x, y, 0, 0, this.xSize, this.ySize); + } + + // This method is called when the Gui is first called! + @Override + public void initGui() { + super.initGui(); + } +} diff --git a/src/main/java/gtPlusPlus/core/gui/machine/GUI_DecayablesChest.java b/src/main/java/gtPlusPlus/core/gui/machine/GUI_DecayablesChest.java new file mode 100644 index 0000000000..60e0f0e67e --- /dev/null +++ b/src/main/java/gtPlusPlus/core/gui/machine/GUI_DecayablesChest.java @@ -0,0 +1,54 @@ +package gtPlusPlus.core.gui.machine; + +import static gregtech.api.enums.Mods.GTPlusPlus; + +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.util.ResourceLocation; + +import org.lwjgl.opengl.GL11; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gtPlusPlus.core.container.Container_DecayablesChest; +import gtPlusPlus.core.tileentities.general.TileEntityDecayablesChest; + +@SideOnly(Side.CLIENT) +public class GUI_DecayablesChest extends GuiContainer { + + private static final ResourceLocation craftingTableGuiTextures = new ResourceLocation( + GTPlusPlus.ID, + "textures/gui/FishTrap.png"); + + public GUI_DecayablesChest(final InventoryPlayer player_inventory, final TileEntityDecayablesChest te) { + super(new Container_DecayablesChest(player_inventory, te)); + } + + @Override + protected void drawGuiContainerForegroundLayer(final int i, final int j) { + + } + + @Override + protected void drawGuiContainerBackgroundLayer(final float f, final int i, final int j) { + GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + this.mc.renderEngine.bindTexture(craftingTableGuiTextures); + final int x = (this.width - this.xSize) / 2; + final int y = (this.height - this.ySize) / 2; + this.drawTexturedModalRect(x, y, 0, 0, this.xSize, this.ySize); + } + + // This method is called when the Gui is first called! + @Override + public void initGui() { + // You have to add this line for the Gui to function properly! + super.initGui(); + + // The parameters of GuiButton are(id, x, y, width, height, text); + // this.buttonList.add(new GuiButton( 1, 367, 132, 18, 18, "X")); + // this.buttonList.add(new GuiButton( 2, 385, 132, 18, 18, "Y")); + // NOTE: the id always has to be different or else it might get called twice or never! + + // Add any other buttons here too! + } +} diff --git a/src/main/java/gtPlusPlus/core/gui/machine/GUI_FishTrap.java b/src/main/java/gtPlusPlus/core/gui/machine/GUI_FishTrap.java new file mode 100644 index 0000000000..d57ef408d0 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/gui/machine/GUI_FishTrap.java @@ -0,0 +1,52 @@ +package gtPlusPlus.core.gui.machine; + +import static gregtech.api.enums.Mods.GTPlusPlus; + +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.util.ResourceLocation; + +import org.lwjgl.opengl.GL11; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gtPlusPlus.core.container.Container_FishTrap; +import gtPlusPlus.core.tileentities.general.TileEntityFishTrap; + +@SideOnly(Side.CLIENT) +public class GUI_FishTrap extends GuiContainer { + + private static final ResourceLocation craftingTableGuiTextures = new ResourceLocation( + GTPlusPlus.ID, + "textures/gui/FishTrap.png"); + + public GUI_FishTrap(final InventoryPlayer player_inventory, final TileEntityFishTrap te) { + super(new Container_FishTrap(player_inventory, te)); + } + + @Override + protected void drawGuiContainerForegroundLayer(final int i, final int j) {} + + @Override + protected void drawGuiContainerBackgroundLayer(final float f, final int i, final int j) { + GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + this.mc.renderEngine.bindTexture(craftingTableGuiTextures); + final int x = (this.width - this.xSize) / 2; + final int y = (this.height - this.ySize) / 2; + this.drawTexturedModalRect(x, y, 0, 0, this.xSize, this.ySize); + } + + // This method is called when the Gui is first called! + @Override + public void initGui() { + // You have to add this line for the Gui to function properly! + super.initGui(); + + // The parameters of GuiButton are(id, x, y, width, height, text); + // this.buttonList.add(new GuiButton( 1, 367, 132, 18, 18, "X")); + // this.buttonList.add(new GuiButton( 2, 385, 132, 18, 18, "Y")); + // NOTE: the id always has to be different or else it might get called twice or never! + + // Add any other buttons here too! + } +} diff --git a/src/main/java/gtPlusPlus/core/gui/machine/GUI_PestKiller.java b/src/main/java/gtPlusPlus/core/gui/machine/GUI_PestKiller.java new file mode 100644 index 0000000000..bed8707fc4 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/gui/machine/GUI_PestKiller.java @@ -0,0 +1,175 @@ +package gtPlusPlus.core.gui.machine; + +import static gregtech.api.enums.Mods.GTPlusPlus; + +import java.awt.Color; + +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.resources.I18n; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.util.IIcon; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.fluids.FluidTank; +import net.minecraftforge.fluids.IFluidTank; + +import org.lwjgl.opengl.GL11; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gtPlusPlus.core.container.Container_PestKiller; +import gtPlusPlus.core.material.MISC_MATERIALS; +import gtPlusPlus.core.tileentities.machines.TileEntityPestKiller; +import gtPlusPlus.core.util.math.MathUtils; + +@SideOnly(Side.CLIENT) +public class GUI_PestKiller extends GuiContainer { + + private static final ResourceLocation craftingTableGuiTextures = new ResourceLocation( + GTPlusPlus.ID, + "textures/gui/PestKiller.png"); + private final TileEntityPestKiller mTileKiller; + + public GUI_PestKiller(final InventoryPlayer player_inventory, final TileEntityPestKiller te) { + super(new Container_PestKiller(player_inventory, te)); + mTileKiller = te; + } + + @Override + protected void drawGuiContainerForegroundLayer(final int i, final int j) { + if (mTileKiller != null) { + this.fontRendererObj.drawString(I18n.format(mTileKiller.getInventoryName(), new Object[0]), 4, 6, 4210752); + drawFluidTank(mTileKiller.getTank(), 134, 35); + } + } + + @Override + protected void drawGuiContainerBackgroundLayer(final float f, final int i, final int j) { + GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + this.mc.renderEngine.bindTexture(craftingTableGuiTextures); + final int x = (this.width - this.xSize) / 2; + final int y = (this.height - this.ySize) / 2; + this.drawTexturedModalRect(x, y, 0, 0, this.xSize, this.ySize); + } + + // This method is called when the Gui is first called! + @Override + public void initGui() { + super.initGui(); + } + + private void drawFluidTank(IFluidTank tank, int x, int y) { + Color startGrad = new Color(50, 50, 50); + Color endGrad = new Color(20, 20, 20); + Container_PestKiller aCont = (Container_PestKiller) this.inventorySlots; + + double aPercentage = 0; + double aDivisor = (100 / 16); + int aFrameHeight = 16; + + boolean didRender = false; + if (aCont != null) { + TileEntityPestKiller aTile = mTileKiller; + if (aTile != null) { + FluidTank aTank = aTile.getTank(); + int aTier = aTile.getTier(); + drawGradientRect(x, y, x + 16, y + 16, startGrad.getRGB(), endGrad.getRGB()); + if (aTier <= 0 || aTier > 2) { + if (aTank != null && aTank.getFluidAmount() > 0) { + aPercentage = MathUtils.findPercentage(aTank.getFluidAmount(), aTank.getCapacity()); + // Logger.INFO("Percent = "+aPercentage); + aFrameHeight = (int) (aPercentage / aDivisor); + // Logger.INFO("Frame Height = "+aFrameHeight); + } + this.fontRendererObj.drawString("Tier: 0", 4, 18, 4210752); + this.fontRendererObj.drawString("Range: 1x1", 4, 30, 4210752); + this.fontRendererObj.drawString("Poison: None", 4, 42, 4210752); + this.fontRendererObj.drawString("Amount: 0", 4, 64, 4210752); + didRender = true; + } else if (aTier == 1) { + if (aTank != null && aTank.getFluidAmount() > 0) { + aPercentage = MathUtils.findPercentage(aTank.getFluidAmount(), aTank.getCapacity()); + // Logger.INFO("Percent = "+aPercentage); + aFrameHeight = (int) (aPercentage / aDivisor); + // Logger.INFO("Frame Height = "+aFrameHeight); + } + startGrad = new Color(240, 50, 240); + endGrad = new Color(130, 30, 130); + drawGradientRect(x, y + (16 - aFrameHeight), x + 16, y + 16, startGrad.getRGB(), endGrad.getRGB()); + this.fontRendererObj.drawString("Tier: 1", 4, 18, 4210752); + this.fontRendererObj.drawString("Range: 5x5", 4, 30, 4210752); + this.fontRendererObj.drawString("Poison: ", 4, 42, 4210752); + this.fontRendererObj.drawString( + "" + aTile.getTank() + .getFluid() + .getLocalizedName(), + 4, + 54, + 4210752); + this.fontRendererObj.drawString( + "Amount: " + aTile.getTank() + .getFluidAmount(), + 4, + 64, + 4210752); + didRender = true; + } else if (aTier == 2) { + if (aTank != null && aTank.getFluidAmount() > 0) { + aPercentage = MathUtils.findPercentage(aTank.getFluidAmount(), aTank.getCapacity()); + // Logger.INFO("Percent = "+aPercentage); + aFrameHeight = (int) (aPercentage / aDivisor); + // Logger.INFO("Frame Height = "+aFrameHeight); + } + short[] aRGB = MISC_MATERIALS.HYDROGEN_CYANIDE.getRGB(); + startGrad = new Color(aRGB[0], aRGB[1], aRGB[2]); + endGrad = new Color(Math.max(aRGB[0], 0), Math.max(aRGB[1], 0), Math.max(aRGB[2], 0)); + drawGradientRect(x, y + (16 - aFrameHeight), x + 16, y + 16, startGrad.getRGB(), endGrad.getRGB()); + this.fontRendererObj.drawString("Tier: 2", 4, 18, 4210752); + this.fontRendererObj.drawString("Range: 9x9", 4, 30, 4210752); + this.fontRendererObj.drawString("Poison: ", 4, 42, 4210752); + this.fontRendererObj.drawString( + "" + aTile.getTank() + .getFluid() + .getLocalizedName(), + 4, + 54, + 4210752); + this.fontRendererObj.drawString( + "Amount: " + aTile.getTank() + .getFluidAmount(), + 4, + 64, + 4210752); + didRender = true; + } + } + } + if (!didRender) { + startGrad = new Color(255, 30, 120); + endGrad = new Color(255, 0, 50); + drawGradientRect(x, y, x + 16, y + 16, startGrad.getRGB(), endGrad.getRGB()); + this.fontRendererObj.drawString("Tier: 0", 4, 18, 4210752); + } + + /* + * FluidStack fluid = tank.getFluid(); TextureManager manager = mc.getTextureManager(); if (fluid != null) { + * manager.bindTexture(manager.getResourceLocation(0)); float amount = fluid.amount; float capacity = + * tank.getCapacity(); float scale = amount / capacity; int fluidTankHeight = 60; int fluidAmount = (int) (scale + * * fluidTankHeight); drawFluid(x, y + fluidTankHeight - fluidAmount, fluid.getFluid().getIcon(fluid), 16, + * fluidAmount); } + */ + } + + private void drawFluid(int x, int y, IIcon icon, int width, int height) { + int i = 0; + int j = 0; + int drawHeight = 0; + int drawWidth = 0; + for (i = 0; i < width; i += 16) { + for (j = 0; j < height; j += 16) { + drawWidth = Math.min(width - i, 16); + drawHeight = Math.min(height - j, 16); + drawTexturedModelRectFromIcon(x + i, y + j, icon, drawWidth, drawHeight); + } + } + } +} diff --git a/src/main/java/gtPlusPlus/core/gui/machine/GUI_ProjectTable.java b/src/main/java/gtPlusPlus/core/gui/machine/GUI_ProjectTable.java new file mode 100644 index 0000000000..3707855641 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/gui/machine/GUI_ProjectTable.java @@ -0,0 +1,58 @@ +package gtPlusPlus.core.gui.machine; + +import static gregtech.api.enums.Mods.GTPlusPlus; + +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.util.ResourceLocation; + +import org.lwjgl.opengl.GL11; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gtPlusPlus.core.container.Container_ProjectTable; +import gtPlusPlus.core.tileentities.machines.TileEntityProjectTable; + +@SideOnly(Side.CLIENT) +public class GUI_ProjectTable extends GuiContainer { + + private static final ResourceLocation craftingTableGuiTextures = new ResourceLocation( + GTPlusPlus.ID, + "textures/gui/ProjectTable.png"); + + public GUI_ProjectTable(final InventoryPlayer player_inventory, final TileEntityProjectTable tile) { + super(new Container_ProjectTable(player_inventory, tile)); + } + + @Override + protected void drawGuiContainerForegroundLayer(final int i, final int j) { + + } + + @Override + protected void drawGuiContainerBackgroundLayer(final float f, final int i, final int j) { + GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + this.mc.renderEngine.bindTexture(craftingTableGuiTextures); + final int x = (this.width - this.xSize) / 2; + final int y = (this.height - this.ySize) / 2; + this.drawTexturedModalRect(x, y, 0, 0, this.xSize, this.ySize); + } + + // This method is called when the Gui is first called! + @Override + public void initGui() { + // You have to add this line for the Gui to function properly! + super.initGui(); + + // The parameters of GuiButton are(id, x, y, width, height, text); + // this.buttonList.add(new GuiButton( 1, 367, 132, 18, 18, "X")); + // this.buttonList.add(new GuiButton( 2, 385, 132, 18, 18, "Y")); + // NOTE: the id always has to be different or else it might get called twice or never! + + // Add any other buttons here too! + } + + @Override + protected void actionPerformed(final GuiButton B) {} +} diff --git a/src/main/java/gtPlusPlus/core/gui/machine/GUI_SuperJukebox.java b/src/main/java/gtPlusPlus/core/gui/machine/GUI_SuperJukebox.java new file mode 100644 index 0000000000..9afa2b4ce1 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/gui/machine/GUI_SuperJukebox.java @@ -0,0 +1,88 @@ +package gtPlusPlus.core.gui.machine; + +import static gregtech.api.enums.Mods.GTPlusPlus; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.util.ResourceLocation; + +import org.lwjgl.opengl.GL11; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gtPlusPlus.core.block.machine.Machine_SuperJukebox.TileEntitySuperJukebox; +import gtPlusPlus.core.container.Container_SuperJukebox; +import gtPlusPlus.core.gui.GUI_Base_Tile_Entity; + +@SideOnly(Side.CLIENT) +public class GUI_SuperJukebox extends GUI_Base_Tile_Entity { + + private static final ResourceLocation craftingTableGuiTextures = new ResourceLocation( + GTPlusPlus.ID, + "textures/gui/SuperJukebox.png"); + private final Container_SuperJukebox mThisContainer; + + public GUI_SuperJukebox(final InventoryPlayer player_inventory, final TileEntitySuperJukebox te) { + super(new Container_SuperJukebox(player_inventory, te)); + mThisContainer = (Container_SuperJukebox) this.mContainer; + } + + // This method is called when the Gui is first called! + @Override + public void initGui() { + super.initGui(); + } + + @Override + protected void drawGuiContainerForegroundLayer(final int par1, final int par2) { + super.drawGuiContainerForegroundLayer(par1, par2); + + boolean a = mThisContainer.isPlaying; + boolean b = mThisContainer.isLooping; + + if (a && b) { + this.fontRendererObj.drawString("[X] [X]", 72, 74, 4210752); + } else if (a && !b) { + this.fontRendererObj.drawString("[X] [ ]", 72, 74, 4210752); + } else if (!a && b) { + this.fontRendererObj.drawString("[ ] [X]", 72, 74, 4210752); + } else { + this.fontRendererObj.drawString("[ ] [ ]", 72, 74, 4210752); + } + + this.drawTooltip(par1, par2); + } + + private void drawTooltip(final int x2, final int y2) { + final int xStart = (this.width - this.xSize) / 2; + final int yStart = (this.height - this.ySize) / 2; + final int x3 = x2 - xStart; + final int y3 = y2 - yStart + 5; + final List<String> list = new ArrayList<>(); + + if (y3 >= 17 && y3 <= 33) { + if (x3 >= 80 && x3 <= 96) { + list.add("Play"); + } + } + if (y3 >= 35 && y3 <= 53) { + if (x3 >= 80 && x3 <= 96) { + list.add("Loop"); + } + } + if (!list.isEmpty()) { + this.drawHoveringText(list, x3, y3, this.fontRendererObj); + } + } + + @Override + protected void drawGuiContainerBackgroundLayer(final float par1, final int par2, final int par3) { + GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + this.mc.renderEngine.bindTexture(craftingTableGuiTextures); + final int x = (this.width - this.xSize) / 2; + final int y = (this.height - this.ySize) / 2; + this.drawTexturedModalRect(x, y, 0, 0, this.xSize, this.ySize); + } +} diff --git a/src/main/java/gtPlusPlus/core/gui/machine/GUI_VolumetricFlaskSetter.java b/src/main/java/gtPlusPlus/core/gui/machine/GUI_VolumetricFlaskSetter.java new file mode 100644 index 0000000000..6595b510c0 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/gui/machine/GUI_VolumetricFlaskSetter.java @@ -0,0 +1,228 @@ +package gtPlusPlus.core.gui.machine; + +import static gregtech.api.enums.Mods.GTPlusPlus; + +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.resources.I18n; +import net.minecraft.util.ResourceLocation; + +import org.lwjgl.input.Keyboard; +import org.lwjgl.opengl.GL11; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.container.Container_VolumetricFlaskSetter; +import gtPlusPlus.core.gui.widget.GuiValueField; +import gtPlusPlus.core.handler.PacketHandler; +import gtPlusPlus.core.network.packet.Packet_VolumetricFlaskGui; +import gtPlusPlus.core.tileentities.general.TileEntityVolumetricFlaskSetter; + +@SideOnly(Side.CLIENT) +public class GUI_VolumetricFlaskSetter extends GuiContainer { + + private static final ResourceLocation mGuiTextures = new ResourceLocation( + GTPlusPlus.ID, + "textures/gui/VolumetricFlaskSetter.png"); + private Container_VolumetricFlaskSetter mContainer; + private boolean mIsOpen = false; + private GuiValueField mText; + private TileEntityVolumetricFlaskSetter mTile; + + public GUI_VolumetricFlaskSetter(Container_VolumetricFlaskSetter aContainer) { + super(aContainer); + mContainer = aContainer; + mTile = mContainer.mTileEntity; + } + + @Override + protected void drawGuiContainerBackgroundLayer(final float f, final int i, final int j) { + GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + this.mc.renderEngine.bindTexture(mGuiTextures); + final int x = (this.width - this.xSize) / 2; + final int y = (this.height - this.ySize) / 2; + this.drawTexturedModalRect(x, y, 0, 0, this.xSize, this.ySize); + } + + @Override + protected void drawGuiContainerForegroundLayer(final int i, final int j) { + super.drawGuiContainerForegroundLayer(i, j); + this.mText.drawTextBox(); + this.fontRendererObj.drawString(I18n.format("container.VolumetricFlaskSetter", new Object[0]), 4, 3, 4210752); + int aYVal = 49; + this.fontRendererObj.drawString(I18n.format("0 = 16l", new Object[0]), 8, aYVal, 4210752); + this.fontRendererObj.drawString(I18n.format("4 = 576l", new Object[0]), 64, aYVal, 4210752); + this.fontRendererObj.drawString(I18n.format("1 = 36l", new Object[0]), 8, aYVal += 8, 4210752); + this.fontRendererObj.drawString(I18n.format("5 = 720l", new Object[0]), 64, aYVal, 4210752); + this.fontRendererObj.drawString(I18n.format("2 = 144l", new Object[0]), 8, aYVal += 8, 4210752); + this.fontRendererObj.drawString(I18n.format("6 = 864l", new Object[0]), 64, aYVal, 4210752); + this.fontRendererObj.drawString(I18n.format("3 = 432l", new Object[0]), 8, aYVal += 8, 4210752); + this.fontRendererObj.drawString(I18n.format("-> = Custom", new Object[0]), 59, aYVal, 4210752); + } + + @Override + public void drawScreen(int par1, int par2, float par3) { + this.drawDefaultBackground(); + super.drawScreen(par1, par2, par3); + } + + protected String getText() { + return this.mText.getText(); + } + + @Override + public void initGui() { + super.initGui(); + // Keyboard.enableRepeatEvents(true); + mIsOpen = true; + this.mText = new GuiValueField( + this.fontRendererObj, + 26, + 31, + this.width / 2 - 62, + this.height / 2 - 52, + 106, + 14, + this); + mText.setMaxStringLength(5); + mText.setEnableBackgroundDrawing(true); + mText.setText("0"); + mText.setFocused(true); + } + + public boolean isNumber(char c) { + boolean isNum = ((c >= 48 && c <= 57) || c == 45); + if (isNum) { + log("Found Digit: " + c + " | char value"); + } else { + switch (c) { + case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' -> { + log("Found Digit: " + c + " | char switch"); + return true; + } + } + } + return isNum; + } + + public boolean isNumber(int c) { + switch (c) { + case Keyboard.KEY_0, Keyboard.KEY_1, Keyboard.KEY_2, Keyboard.KEY_3, Keyboard.KEY_4, Keyboard.KEY_5, Keyboard.KEY_6, Keyboard.KEY_7, Keyboard.KEY_8, Keyboard.KEY_9, Keyboard.KEY_NUMPAD0, Keyboard.KEY_NUMPAD1, Keyboard.KEY_NUMPAD2, Keyboard.KEY_NUMPAD3, Keyboard.KEY_NUMPAD4, Keyboard.KEY_NUMPAD5, Keyboard.KEY_NUMPAD6, Keyboard.KEY_NUMPAD7, Keyboard.KEY_NUMPAD8, Keyboard.KEY_NUMPAD9 -> { + log("Found Digit: " + Keyboard.getKeyName(c) + " | LWJGL Keybinding"); + return true; + } + } + return false; + } + + @Override + protected void keyTyped(char par1, int par2) { + if (mIsOpen) { + log("Pressed " + par1 + " | " + par2); + if (mText.isFocused()) { + log("Text box has focus."); + if (par2 == Keyboard.KEY_RETURN) { + log("Pressed Enter, unfocusing."); + mText.setFocused(false); + } else if (par2 == Keyboard.KEY_BACK) { + log("Pressed Backspace."); + String aCurrentText = getText(); + if (aCurrentText.length() > 0) { + this.mText.setText(aCurrentText.substring(0, aCurrentText.length() - 1)); + if (getText().length() <= 0) { + setText(0); + } + sendUpdateToServer(); + } + } else { + if (isNumber(par2) || isNumber(par1)) { + log("Pressed number."); + if (this.mText.getText() + .equals("0")) { + this.mText.textboxKeyTyped(par1, par2); + sendUpdateToServer(); + } else { + this.mText.textboxKeyTyped(par1, par2); + sendUpdateToServer(); + } + } else { + log("Pressed unused key."); + super.keyTyped(par1, par2); + } + } + } else { + log("Text box not focused."); + super.keyTyped(par1, par2); + } + } else { + log("Gui is not open?"); + } + } + + @Override + protected void mouseClicked(int x, int y, int btn) { + if (mIsOpen) { + log("Clicked."); + this.mText.mouseClicked(x, y, btn); + if (!mText.didClickInTextField(x, y)) { + log("Did not click in text box, passing to super."); + super.mouseClicked(x, y, btn); + } + } else { + log("Gui is not open?"); + } + } + + @Override + public void onGuiClosed() { + mIsOpen = false; + mText.setEnabled(false); + mText.setVisible(false); + super.onGuiClosed(); + // Keyboard.enableRepeatEvents(false); + } + + public int parse(String aValue) { + try { + return Integer.parseInt(getText()); + } catch (NumberFormatException e) { + return 0; + } + } + + public void sendUpdateToServer() { + if (getText().length() > 0) { + PacketHandler.sendToServer(new Packet_VolumetricFlaskGui(mTile, parse(getText()))); + } + } + + public void setText(int aValue) { + this.mText.setText("" + aValue); + } + + @Override + public void updateScreen() { + super.updateScreen(); + // Update Textbox to 0 if Empty + if (getText().length() <= 0) { + this.mText.setText("0"); + sendUpdateToServer(); + } + this.mText.updateCursorCounter(); + + // Check TextBox Value is correct + if (getText().length() > 0) { + int aCustomValue = parse(getText()); + int aTileValue = ((Container_VolumetricFlaskSetter) mContainer).mCustomValue; + if (mContainer != null) { + if (aTileValue != aCustomValue) { + setText(aTileValue); + } + } + } + } + + public void log(String aString) { + Logger.INFO("[Flask-GUI] " + aString); + } +} diff --git a/src/main/java/gtPlusPlus/core/gui/widget/GuiValueField.java b/src/main/java/gtPlusPlus/core/gui/widget/GuiValueField.java new file mode 100644 index 0000000000..698aa1951a --- /dev/null +++ b/src/main/java/gtPlusPlus/core/gui/widget/GuiValueField.java @@ -0,0 +1,104 @@ +package gtPlusPlus.core.gui.widget; + +import java.lang.reflect.Field; + +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.GuiTextField; + +import gtPlusPlus.core.gui.machine.GUI_VolumetricFlaskSetter; +import gtPlusPlus.core.util.reflect.ReflectionUtils; +import gtPlusPlus.preloader.CORE_Preloader; + +public class GuiValueField extends GuiTextField { + + private final FontRenderer mFontRenderer; + private final int mScreenLocationX; + private final int mScreenLocationY; + private final GUI_VolumetricFlaskSetter mGUI; + + public GuiValueField(FontRenderer aFontRenderer, int aX, int aY, int aScreenLocationX, int aScreenLocationY, + int aWidth, int aHeight, GUI_VolumetricFlaskSetter aGUI) { + super(aFontRenderer, aX, aY, aWidth, aHeight); + mFontRenderer = aFontRenderer; + mScreenLocationX = aScreenLocationX; + mScreenLocationY = aScreenLocationY; + mGUI = aGUI; + } + + @Override + public boolean isFocused() { + return super.isFocused(); + } + + public boolean isBackgroundDrawingEnabled() { + Field enableBackgroundDrawing = ReflectionUtils.getField( + GuiTextField.class, + !CORE_Preloader.DEV_ENVIRONMENT ? "field_146215_m" : "enableBackgroundDrawing"); + if (enableBackgroundDrawing != null) { + return ReflectionUtils.getFieldValue(enableBackgroundDrawing, this); + } + return true; + } + + public int getLineScrollOffset() { + Field lineScrollOffset = ReflectionUtils + .getField(GuiTextField.class, !CORE_Preloader.DEV_ENVIRONMENT ? "field_146225_q" : "lineScrollOffset"); + if (lineScrollOffset != null) { + return (int) ReflectionUtils.getFieldValue(lineScrollOffset, this); + } + return 0; + } + + public boolean didClickInTextField(int aX, int aY) { + mGUI.log("Clicked at X:" + aX + ", Y:" + aY); + boolean aDidClick = aX >= this.mScreenLocationX && aX < this.mScreenLocationX + this.width + && aY >= this.mScreenLocationY + && aY < this.mScreenLocationY + this.height; + mGUI.log("Did click in textbox? " + aDidClick); + mGUI.log("Expected Region: X:" + mScreenLocationX + "-" + (this.mScreenLocationX + this.width)); + mGUI.log("Expected Region: Y:" + mScreenLocationY + "-" + (this.mScreenLocationY + this.height)); + return aDidClick; + } + + /** + * Args: x, y, buttonClicked + */ + @Override + public void mouseClicked(int aX, int aY, int aButton) { + boolean aDidClick = didClickInTextField(aX, aY); + + mGUI.log("Did click inside text box? " + aDidClick); + mGUI.log("Focus 1: " + this.isFocused()); + this.setFocused(aDidClick); + mGUI.log("Focus 2: " + this.isFocused()); + if (isFocused()) { + int l = aX - this.mScreenLocationX; + if (isBackgroundDrawingEnabled()) { + l -= 4; + } + if (aButton == 0) { + mGUI.log("Left clicked in text box."); + String s = this.mFontRenderer.trimStringToWidth( + this.getText() + .substring(getLineScrollOffset()), + this.getWidth()); + this.setCursorPosition( + this.mFontRenderer.trimStringToWidth(s, l) + .length() + getLineScrollOffset()); + } else if (aButton == 1) { + mGUI.log("Right clicked in text box."); + mGUI.setText(0); + mGUI.sendUpdateToServer(); + String s = this.mFontRenderer.trimStringToWidth( + this.getText() + .substring(getLineScrollOffset()), + this.getWidth()); + this.setCursorPosition( + this.mFontRenderer.trimStringToWidth(s, l) + .length() + getLineScrollOffset()); + } + } else { + mGUI.log("Clicked, but no focus."); + } + } +} |
