Added button to remove upgrade, fixed font size. Almost done!

This commit is contained in:
Aidan C. Brady 2014-07-22 22:16:20 -04:00
parent 790cd33f2d
commit 523ec21467
4 changed files with 51 additions and 34 deletions

View file

@ -1,10 +1,8 @@
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;
@ -12,6 +10,7 @@ import mekanism.common.Mekanism;
import mekanism.common.Upgrade;
import mekanism.common.block.BlockMachine.MachineType;
import mekanism.common.inventory.container.ContainerUpgradeManagement;
import mekanism.common.network.PacketRemoveUpgrade.RemoveUpgradeMessage;
import mekanism.common.network.PacketSimpleGui.SimpleGuiMessage;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.MekanismUtils.ResourceType;
@ -47,14 +46,20 @@ public class GuiUpgradeManagement extends GuiMekanism
if(selectedType == null)
{
renderText(MekanismUtils.localize("gui.upgrades.noSelection") + ".", 96, 9, 0.8F);
renderText(MekanismUtils.localize("gui.upgrades.noSelection") + ".", 92, 8, 0.8F, true);
}
else {
int amount = tileEntity.getComponent().getUpgrades(selectedType);
renderText(selectedType.getName() + " " + MekanismUtils.localize("gui.upgrade"), 92, 8, 0.6F, true);
renderText(MekanismUtils.localize("gui.upgrades.amount") + ": " + amount + "/" + selectedType.getMax(), 92, 16, 0.6F, true);
}
int rendered = 0;
for(Upgrade upgrade : tileEntity.getComponent().getSupportedTypes())
{
renderUpgrade(upgrade, 84 + (rendered++*12), 60, 0.8F);
renderUpgrade(upgrade, 80 + (rendered++*12), 58, 0.8F, true);
}
int counter = 0;
@ -65,6 +70,10 @@ public class GuiUpgradeManagement extends GuiMekanism
int yPos = 7 + (counter++*12);
int yRender = 0;
fontRendererObj.drawString(upgrade.getName(), xPos + 12, yPos + 2, 0x404040);
renderUpgrade(upgrade, xPos + 2, yPos + 2, 0.5F, true);
if(xAxis >= xPos && xAxis <= xPos+64 && yAxis >= yPos && yAxis <= yPos+12)
{
func_146283_a(MekanismUtils.splitLines(upgrade.getDescription()), xAxis, yAxis);
@ -74,20 +83,20 @@ public class GuiUpgradeManagement extends GuiMekanism
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
}
private void renderText(String text, int x, int y, float size)
private void renderText(String text, int x, int y, float size, boolean scale)
{
GL11.glPushMatrix();
GL11.glScalef(size, size, size);
fontRendererObj.drawString(text, (int)(x*(1+(1-size))), (int)(y*(1+(1-size))), 0x00CD00);
fontRendererObj.drawString(text, scale ? (int)((1F/size)*x) : x, scale ? (int)((1F/size)*y) : y, 0x00CD00);
GL11.glPopMatrix();
}
private void renderUpgrade(Upgrade type, int x, int y, float size)
private void renderUpgrade(Upgrade type, int x, int y, float size, boolean scale)
{
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))));
itemRender.renderItemAndEffectIntoGUI(fontRendererObj, mc.getTextureManager(), type.getStack(), scale ? (int)((1F/size)*x) : x, scale ? (int)((1F/size)*y) : y);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glPopMatrix();
}
@ -113,6 +122,18 @@ public class GuiUpgradeManagement extends GuiMekanism
drawTexturedModalRect(guiWidth + 6, guiHeight + 6, 176, 14, 14, 14);
}
if(selectedType == null)
{
drawTexturedModalRect(guiWidth + 136, guiHeight + 58, 176 + 14, 24, 12, 12);
}
else if(xAxis >= 136 && xAxis <= 148 && yAxis >= 58 && yAxis <= 70)
{
drawTexturedModalRect(guiWidth + 136, guiHeight + 58, 176 + 14, 0, 12, 12);
}
else {
drawTexturedModalRect(guiWidth + 136, guiHeight + 58, 176 + 14, 12, 12, 12);
}
int displayInt = tileEntity.getComponent().getScaledUpgradeProgress(14);
drawTexturedModalRect(guiWidth + 154, guiHeight + 26, 176, 28, 10, displayInt);
@ -174,6 +195,12 @@ public class GuiUpgradeManagement extends GuiMekanism
Mekanism.packetHandler.sendToServer(new SimpleGuiMessage(Coord4D.get(tile), guiId));
}
if(selectedType != null && xAxis >= 136 && xAxis <= 148 && yAxis >= 58 && yAxis <= 70)
{
SoundHandler.playSound("gui.button.press");
Mekanism.packetHandler.sendToServer(new RemoveUpgradeMessage(Coord4D.get(tile), selectedType.ordinal()));
}
int counter = 0;
for(Upgrade upgrade : getCurrentUpgrades())

View file

@ -2,9 +2,10 @@ package mekanism.common.network;
import io.netty.buffer.ByteBuf;
import mekanism.api.Coord4D;
import mekanism.common.IUpgradeManagement;
import mekanism.common.IUpgradeTile;
import mekanism.common.Mekanism;
import mekanism.common.PacketHandler;
import mekanism.common.Upgrade;
import mekanism.common.network.PacketRemoveUpgrade.RemoveUpgradeMessage;
import mekanism.common.tile.TileEntityBasicBlock;
import net.minecraft.entity.player.EntityPlayer;
@ -22,28 +23,16 @@ public class PacketRemoveUpgrade implements IMessageHandler<RemoveUpgradeMessage
EntityPlayer player = PacketHandler.getPlayer(context);
TileEntity tileEntity = message.coord4D.getTileEntity(player.worldObj);
if(tileEntity instanceof IUpgradeManagement && tileEntity instanceof TileEntityBasicBlock)
if(tileEntity instanceof IUpgradeTile && tileEntity instanceof TileEntityBasicBlock)
{
IUpgradeManagement upgradeTile = (IUpgradeManagement)tileEntity;
IUpgradeTile upgradeTile = (IUpgradeTile)tileEntity;
Upgrade upgrade = Upgrade.values()[message.upgradeType];
if(message.upgradeType == 0)
if(upgradeTile.getComponent().getUpgrades(upgrade) > 0)
{
if(upgradeTile.getSpeedMultiplier() > 0)
if(player.inventory.addItemStackToInventory(upgrade.getStack()))
{
if(player.inventory.addItemStackToInventory(new ItemStack(Mekanism.SpeedUpgrade)))
{
upgradeTile.setSpeedMultiplier(upgradeTile.getSpeedMultiplier()-1);
}
}
}
else if(message.upgradeType == 1)
{
if(upgradeTile.getEnergyMultiplier() > 0)
{
if(player.inventory.addItemStackToInventory(new ItemStack(Mekanism.EnergyUpgrade)))
{
upgradeTile.setEnergyMultiplier(upgradeTile.getEnergyMultiplier()-1);
}
upgradeTile.getComponent().removeUpgrade(upgrade);
}
}
}
@ -55,11 +44,11 @@ public class PacketRemoveUpgrade implements IMessageHandler<RemoveUpgradeMessage
{
public Coord4D coord4D;
public byte upgradeType;
public int upgradeType;
public RemoveUpgradeMessage() {}
public RemoveUpgradeMessage(Coord4D coord, byte type)
public RemoveUpgradeMessage(Coord4D coord, int type)
{
coord4D = coord;
upgradeType = type;
@ -73,7 +62,7 @@ public class PacketRemoveUpgrade implements IMessageHandler<RemoveUpgradeMessage
dataStream.writeInt(coord4D.zCoord);
dataStream.writeInt(coord4D.dimensionId);
dataStream.writeByte(upgradeType);
dataStream.writeInt(upgradeType);
}
@Override
@ -81,7 +70,7 @@ public class PacketRemoveUpgrade implements IMessageHandler<RemoveUpgradeMessage
{
coord4D = new Coord4D(dataStream.readInt(), dataStream.readInt(), dataStream.readInt(), dataStream.readInt());
upgradeType = dataStream.readByte();
upgradeType = dataStream.readInt();
}
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5 KiB

After

Width:  |  Height:  |  Size: 5 KiB

View file

@ -354,10 +354,14 @@ gui.key=Key
gui.id=ID
gui.finished=Finished
gui.well=All is well!
gui.upgrade=Upgrade
gui.upgrades=Upgrades
gui.upgrades.supported=Supported
gui.upgrades.noSelection=No selection
gui.upgrades.amount=Amount
gui.upgrades.max=Max
gui.upgrades.effect=Effect
gui.chemicalInfuser.short=C. Infuser
gui.chemicalDissolutionChamber.short=C. Dissolution Chamber
@ -657,9 +661,6 @@ tile.Generator.BioGenerator.name=Bio-Generator
tile.Generator.AdvancedSolarGenerator.name=Advanced Solar Generator
tile.Generator.WindTurbine.name=Wind Turbine
//Reactor Blocks
tile.Reactor.ReactorController.name=Reactor Controller
//Gui text
gui.heatGenerator.fuel=Fuel
gui.solarGenerator.sun=Sun