Gui cleanup (#74)

* Update dependencies for dev environment to have latest versions
* Fix depreated method usage for JEI
* Add Deprecated annotation to methods overriding a deprecated method
* Fix various Deprecated method calls
* Slightly clean up gui code based on IntelliJ inspections
* Remove some unused variables/calculations from the gui code
* Remove some unused variables/calculations from the generator gui code
* Create a bit of hierarchy for Gui's that keep track of TileEntities
* Cleanup Gui Element having majority of variables as public
* Cleanup some duplicate math
* Store tile entity type in a less duplicated manner
* Cleanup Gui ResourceLocation handling. Makes it easier to read the code
* Switch adding to a method
* Switch remaining GUI variables to private/protected
* Partially cleanup Gui Filter code
* Cleanup some of the Chemical Gui Code
* Fix missing a few files in last commit
* Improve handling of Tile Entities in GUIs
This commit is contained in:
Richard Freimer authored and Dave Smith committed 2019-03-19 16:10:57 -06:00
1 parent 56831edb3e
commit cd5fe2040b
151 files changed
+3057 -4549

No files matched your search

@@ -29,53 +29,46 @@ import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11;
@SideOnly(Side.CLIENT)
public class GuiFactory extends GuiMekanism {
public TileEntityFactory tileEntity;
public GuiFactory(InventoryPlayer inventory, TileEntityFactory tentity) {
super(tentity, new ContainerFactory(inventory, tentity));
tileEntity = tentity;
public class GuiFactory extends GuiMekanismTile<TileEntityFactory> {
public GuiFactory(InventoryPlayer inventory, TileEntityFactory tile) {
super(tile, new ContainerFactory(inventory, tile));
ySize += 11;
guiElements.add(new GuiRedstoneControl(this, tileEntity, tileEntity.tier.guiLocation));
guiElements.add(new GuiSecurityTab(this, tileEntity, tileEntity.tier.guiLocation));
guiElements.add(new GuiUpgradeTab(this, tileEntity, tileEntity.tier.guiLocation));
guiElements.add(new GuiRecipeType(this, tileEntity, tileEntity.tier.guiLocation));
guiElements.add(new GuiSideConfigurationTab(this, tileEntity, tileEntity.tier.guiLocation));
guiElements.add(new GuiTransporterConfigTab(this, 34, tileEntity, tileEntity.tier.guiLocation));
guiElements.add(new GuiSortingTab(this, tileEntity, tileEntity.tier.guiLocation));
guiElements.add(new GuiEnergyInfo(() ->
{
ResourceLocation resource = tileEntity.tier.guiLocation;
addGuiElement(new GuiRedstoneControl(this, tileEntity, resource));
addGuiElement(new GuiSecurityTab(this, tileEntity, resource));
addGuiElement(new GuiUpgradeTab(this, tileEntity, resource));
addGuiElement(new GuiRecipeType(this, tileEntity, resource));
addGuiElement(new GuiSideConfigurationTab(this, tileEntity, resource));
addGuiElement(new GuiTransporterConfigTab(this, 34, tileEntity, resource));
addGuiElement(new GuiSortingTab(this, tileEntity, resource));
addGuiElement(new GuiEnergyInfo(() -> {
String multiplier = MekanismUtils.getEnergyDisplay(tileEntity.lastUsage);
return Arrays.asList(LangUtils.localize("gui.using") + ": " + multiplier + "/t",
LangUtils.localize("gui.needed") + ": " + MekanismUtils
.getEnergyDisplay(tileEntity.getMaxEnergy() - tileEntity.getEnergy()));
}, this, tileEntity.tier.guiLocation));
}, this, resource));
}
@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
int xAxis = (mouseX - (width - xSize) / 2);
int yAxis = (mouseY - (height - ySize) / 2);
fontRenderer
.drawString(tileEntity.getName(), (xSize / 2) - (fontRenderer.getStringWidth(tileEntity.getName()) / 2),
4, 0x404040);
fontRenderer.drawString(LangUtils.localize("container.inventory"), 8, (ySize - 93) + 2, 0x404040);
int xAxis = (mouseX - (width - xSize) / 2);
int yAxis = (mouseY - (height - ySize) / 2);
if (xAxis >= 165 && xAxis <= 169 && yAxis >= 17 && yAxis <= 69) {
drawHoveringText(MekanismUtils.getEnergyDisplay(tileEntity.getEnergy(), tileEntity.getMaxEnergy()), xAxis,
yAxis);
}
if (xAxis >= 8 && xAxis <= 168 && yAxis >= 78 && yAxis <= 83) {
if (tileEntity.getRecipeType().getFuelType() == MachineFuelType.ADVANCED) {
drawHoveringText(
@@ -87,34 +80,23 @@ public class GuiFactory extends GuiMekanism {
+ tileEntity.infuseStored.amount : LangUtils.localize("gui.empty"), xAxis, yAxis);
}
}
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
}
@Override
protected void drawGuiContainerBackgroundLayer(float partialTick, int mouseX, int mouseY) {
mc.renderEngine.bindTexture(tileEntity.tier.guiLocation);
mc.renderEngine.bindTexture(getGuiLocation());
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
int guiWidth = (width - xSize) / 2;
int guiHeight = (height - ySize) / 2;
drawTexturedModalRect(guiWidth, guiHeight, 0, 0, xSize, ySize);
int xAxis = mouseX - guiWidth;
int yAxis = mouseY - guiHeight;
int displayInt;
displayInt = tileEntity.getScaledEnergyLevel(52);
int displayInt = tileEntity.getScaledEnergyLevel(52);
drawTexturedModalRect(guiWidth + 165, guiHeight + 17 + 52 - displayInt, 176, 52 - displayInt, 4, displayInt);
int xOffset = tileEntity.tier == FactoryTier.BASIC ? 59 : (tileEntity.tier == FactoryTier.ADVANCED ?
39 : 33);
int xDistance = tileEntity.tier == FactoryTier.BASIC ? 38 : (tileEntity.tier == FactoryTier.ADVANCED ?
26 : 19);
int xOffset = tileEntity.tier == FactoryTier.BASIC ? 59 : (tileEntity.tier == FactoryTier.ADVANCED ? 39 : 33);
int xDistance = tileEntity.tier == FactoryTier.BASIC ? 38 : (tileEntity.tier == FactoryTier.ADVANCED ? 26 : 19);
for (int i = 0; i < tileEntity.tier.processes; i++) {
int xPos = xOffset + (i * xDistance);
displayInt = tileEntity.getScaledProgress(20, i);
drawTexturedModalRect(guiWidth + xPos, guiHeight + 33, 176, 52, 8, displayInt);
}
@@ -137,40 +119,37 @@ public class GuiFactory extends GuiMekanism {
displayGauge(8, 78, tileEntity.getScaledInfuseLevel(160), 5, tileEntity.infuseStored.type.sprite);
}
}
super.drawGuiContainerBackgroundLayer(partialTick, mouseX, mouseY);
}
public void displayGauge(int xPos, int yPos, int sizeX, int sizeY, TextureAtlasSprite icon) {
if (icon == null) {
return;
if (icon != null) {
int guiWidth = (width - xSize) / 2;
int guiHeight = (height - ySize) / 2;
mc.renderEngine.bindTexture(MekanismRenderer.getBlocksTexture());
drawTexturedModalRect(guiWidth + xPos, guiHeight + yPos, icon, sizeX, sizeY);
}
int guiWidth = (width - xSize) / 2;
int guiHeight = (height - ySize) / 2;
mc.renderEngine.bindTexture(MekanismRenderer.getBlocksTexture());
drawTexturedModalRect(guiWidth + xPos, guiHeight + yPos, icon, sizeX, sizeY);
}
@Override
protected void mouseClicked(int x, int y, int button) throws IOException {
super.mouseClicked(x, y, button);
if (button == 0 || Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
int xAxis = (x - (width - xSize) / 2);
int yAxis = (y - (height - ySize) / 2);
if (xAxis > 8 && xAxis < 168 && yAxis > 78 && yAxis < 83) {
ItemStack stack = mc.player.inventory.getItemStack();
if (!stack.isEmpty() && stack.getItem() instanceof ItemGaugeDropper) {
TileNetworkList data = TileNetworkList.withContents(1);
Mekanism.packetHandler.sendToServer(new TileEntityMessage(Coord4D.get(tileEntity), data));
SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK);
}
}
}
}
}
@Override
protected ResourceLocation getGuiLocation() {
return tileEntity.tier.guiLocation;
}
}