A big load of work on the new upgrade GUI

This commit is contained in:
Aidan C. Brady committed 2014-07-22 20:37:53 -04:00
1 parent 99482d8fd0
commit 6470f69569
6 files changed
+157 -5

No files matched your search

@@ -1,17 +1,21 @@
package mekanism.client.gui;
import java.util.Arrays;
import java.util.Set;
import mekanism.api.Coord4D;
import mekanism.api.EnumColor;
import mekanism.client.render.MekanismRenderer;
import mekanism.client.sound.SoundHandler;
import mekanism.common.IUpgradeTile;
import mekanism.common.Mekanism;
import mekanism.common.Upgrade;
import mekanism.common.block.BlockMachine.MachineType;
import mekanism.common.inventory.container.ContainerUpgradeManagement;
import mekanism.common.network.PacketSimpleGui.SimpleGuiMessage;
import mekanism.common.tile.TileEntityContainerBlock;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.MekanismUtils.ResourceType;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.tileentity.TileEntity;
import org.lwjgl.opengl.GL11;
@@ -24,6 +28,8 @@ public class GuiUpgradeManagement extends GuiMekanism
{
public IUpgradeTile tileEntity;
public Upgrade selectedType;
public GuiUpgradeManagement(InventoryPlayer inventory, IUpgradeTile tile)
{
super(new ContainerUpgradeManagement(inventory, tile));
@@ -33,10 +39,58 @@ public class GuiUpgradeManagement extends GuiMekanism
@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
{
int xAxis = (mouseX - (width - xSize) / 2);
int yAxis = (mouseY - (height - ySize) / 2);
fontRendererObj.drawString(MekanismUtils.localize("container.inventory"), 8, (ySize - 96) + 2, 0x404040);
fontRendererObj.drawString(MekanismUtils.localize("gui.upgrades.supported") + ":", 26, 60, 0x404040);
if(selectedType == null)
{
renderText(MekanismUtils.localize("gui.upgrades.noSelection") + ".", 96, 9, 0.8F);
}
int rendered = 0;
for(Upgrade upgrade : tileEntity.getComponent().getSupportedTypes())
{
renderUpgrade(upgrade, 84 + (rendered++*12), 60, 0.8F);
}
int counter = 0;
for(Upgrade upgrade : getCurrentUpgrades())
{
int xPos = 25;
int yPos = 7 + (counter++*12);
int yRender = 0;
if(xAxis >= xPos && xAxis <= xPos+64 && yAxis >= yPos && yAxis <= yPos+12)
{
func_146283_a(MekanismUtils.splitLines(upgrade.getDescription()), xAxis, yAxis);
}
}
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
}
private void renderText(String text, int x, int y, float size)
{
GL11.glPushMatrix();
GL11.glScalef(size, size, size);
fontRendererObj.drawString(text, (int)(x*(1+(1-size))), (int)(y*(1+(1-size))), 0x00CD00);
GL11.glPopMatrix();
}
private void renderUpgrade(Upgrade type, int x, int y, float size)
{
GL11.glPushMatrix();
GL11.glScalef(size, size, size);
GL11.glEnable(GL11.GL_LIGHTING);
itemRender.renderItemAndEffectIntoGUI(fontRendererObj, mc.getTextureManager(), type.getStack(), (int)(x*(1+(1-size))), (int)(y*(1+(1-size))));
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glPopMatrix();
}
@Override
protected void drawGuiContainerBackgroundLayer(float partialTick, int mouseX, int mouseY)
@@ -61,10 +115,46 @@ public class GuiUpgradeManagement extends GuiMekanism
int displayInt = tileEntity.getComponent().getScaledUpgradeProgress(14);
drawTexturedModalRect(guiWidth + 154, guiHeight + 26, 176, 28, 10, displayInt);
if(selectedType != null && tileEntity.getComponent().getUpgrades(selectedType) == 0)
{
selectedType = null;
}
int rendered = 0;
for(Upgrade upgrade : getCurrentUpgrades())
{
int xPos = 25;
int yPos = 7 + (rendered++*12);
int yRender = 0;
if(upgrade == selectedType)
{
yRender = 166 + 24;
}
else if(xAxis >= xPos && xAxis <= xPos+64 && yAxis >= yPos && yAxis <= yPos+12)
{
yRender = 166;
}
else {
yRender = 166 + 12;
}
MekanismRenderer.color(upgrade.getColor(), 1.0F, 2.5F);
drawTexturedModalRect(guiWidth + xPos, guiHeight + yPos, 0, yRender, 64, 12);
MekanismRenderer.resetColor();
}
super.drawGuiContainerBackgroundLayer(partialTick, mouseX, mouseY);
}
/* Here for scrolling in the future */
private Set<Upgrade> getCurrentUpgrades()
{
return tileEntity.getComponent().getInstalledTypes();
}
@Override
protected void mouseClicked(int mouseX, int mouseY, int button)
{
@@ -83,6 +173,21 @@ public class GuiUpgradeManagement extends GuiMekanism
SoundHandler.playSound("gui.button.press");
Mekanism.packetHandler.sendToServer(new SimpleGuiMessage(Coord4D.get(tile), guiId));
}
int counter = 0;
for(Upgrade upgrade : getCurrentUpgrades())
{
int xPos = 25;
int yPos = 7 + (counter++*12);
int yRender = 0;
if(xAxis >= xPos && xAxis <= xPos+64 && yAxis >= yPos && yAxis <= yPos+12)
{
selectedType = upgrade;
break;
}
}
}
}
}
@@ -5,6 +5,7 @@ import java.util.Map;
import mekanism.api.EnumColor;
import mekanism.common.util.MekanismUtils;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraftforge.common.util.Constants.NBT;
@@ -51,6 +52,19 @@ public enum Upgrade
return getMax() > 1;
}
public ItemStack getStack()
{
switch(this)
{
case SPEED:
return new ItemStack(Mekanism.SpeedUpgrade);
case ENERGY:
return new ItemStack(Mekanism.EnergyUpgrade);
}
return null;
}
public static Map<Upgrade, Integer> buildMap(NBTTagCompound nbtTags)
{
Map<Upgrade, Integer> upgrades = new HashMap<Upgrade, Integer>();
@@ -1,7 +1,17 @@
package mekanism.common.item;
import java.util.List;
import org.lwjgl.input.Keyboard;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import mekanism.api.EnumColor;
import mekanism.common.IUpgradeItem;
import mekanism.common.Upgrade;
import mekanism.common.util.LangUtils;
import mekanism.common.util.MekanismUtils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
public class ItemUpgrade extends ItemMekanism implements IUpgradeItem
@@ -11,10 +21,22 @@ public class ItemUpgrade extends ItemMekanism implements IUpgradeItem
public ItemUpgrade(Upgrade type)
{
upgrade = type;
setMaxStackSize(type.getMax());
}
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack itemstack, EntityPlayer entityplayer, List list, boolean flag)
{
if(!Keyboard.isKeyDown(Keyboard.KEY_LSHIFT))
{
list.add(MekanismUtils.localize("tooltip.hold") + " " + EnumColor.AQUA + "shift" + EnumColor.GREY + " " + MekanismUtils.localize("tooltip.forDetails"));
}
else {
list.addAll(MekanismUtils.splitLines(getUpgradeType(itemstack).getDescription()));
}
}
@Override
public Upgrade getUpgradeType(ItemStack stack)
{
@@ -13,7 +13,6 @@ import mekanism.common.IUpgradeItem;
import mekanism.common.Upgrade;
import mekanism.common.tile.TileEntityContainerBlock;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
public class TileComponentUpgrade implements ITileComponent
{
@@ -138,6 +137,16 @@ public class TileComponentUpgrade implements ITileComponent
{
return supported.contains(upgrade);
}
public Set<Upgrade> getInstalledTypes()
{
return upgrades.keySet();
}
public Set<Upgrade> getSupportedTypes()
{
return supported;
}
@Override
public void read(ByteBuf dataStream)