Skip to content

Commit

Permalink
Merge pull request mekanism#1852 from pwestling/add_decrement_telepor…
Browse files Browse the repository at this point in the history
…ter_digit

add right click decrement functionality to teleporter digits
  • Loading branch information
unpairedbracket committed Sep 24, 2014
2 parents 212ae4d + bb12d91 commit 0c5fa1b
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 86 deletions.
68 changes: 31 additions & 37 deletions src/main/java/mekanism/client/gui/GuiPortableTeleporter.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package mekanism.client.gui;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import mekanism.client.sound.SoundHandler;
import mekanism.common.Mekanism;
import mekanism.common.item.ItemPortableTeleporter;
Expand All @@ -11,12 +13,8 @@
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;

import org.lwjgl.opengl.GL11;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
public class GuiPortableTeleporter extends GuiScreen
{
Expand Down Expand Up @@ -49,23 +47,23 @@ public void drawScreen(int mouseX, int mouseY, float partialTick)

mc.renderEngine.bindTexture(MekanismUtils.getResource(ResourceType.GUI, "GuiPortableTeleporter.png"));
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
int guiWidth = (width - xSize) / 2;
int guiHeight = (height - ySize) / 2;
int guiWidth = (width-xSize)/2;
int guiHeight = (height-ySize)/2;
drawTexturedModalRect(guiWidth, guiHeight, 0, 0, xSize, ySize);

int displayInt;

displayInt = getYAxisForNumber(((ItemPortableTeleporter)itemStack.getItem()).getDigit(itemStack, 0));
drawTexturedModalRect(guiWidth + 23, guiHeight + 44, 176, displayInt, 13, 13);
drawTexturedModalRect(guiWidth+23, guiHeight+44, 176, displayInt, 13, 13);

displayInt = getYAxisForNumber(((ItemPortableTeleporter)itemStack.getItem()).getDigit(itemStack, 1));
drawTexturedModalRect(guiWidth + 62, guiHeight + 44, 176, displayInt, 13, 13);
drawTexturedModalRect(guiWidth+62, guiHeight+44, 176, displayInt, 13, 13);

displayInt = getYAxisForNumber(((ItemPortableTeleporter)itemStack.getItem()).getDigit(itemStack, 2));
drawTexturedModalRect(guiWidth + 101, guiHeight + 44, 176, displayInt, 13, 13);
drawTexturedModalRect(guiWidth+101, guiHeight+44, 176, displayInt, 13, 13);

displayInt = getYAxisForNumber(((ItemPortableTeleporter)itemStack.getItem()).getDigit(itemStack, 3));
drawTexturedModalRect(guiWidth + 140, guiHeight + 44, 176, displayInt, 13, 13);
drawTexturedModalRect(guiWidth+140, guiHeight+44, 176, displayInt, 13, 13);

ItemPortableTeleporter item = (ItemPortableTeleporter)itemStack.getItem();

Expand Down Expand Up @@ -93,43 +91,39 @@ protected void mouseClicked(int mouseX, int mouseY, int button)
{
super.mouseClicked(mouseX, mouseY, button);

int xAxis = (mouseX - (width - xSize) / 2);
int yAxis = (mouseY - (height - ySize) / 2);
int xAxis = (mouseX-(width-xSize)/2);
int yAxis = (mouseY-(height-ySize)/2);

handleButtonClick(xAxis, yAxis, button, 0, 23, 37, 44, 58);
handleButtonClick(xAxis, yAxis, button, 1, 62, 76, 44, 58);
handleButtonClick(xAxis, yAxis, button, 2, 101, 115, 44, 58);
handleButtonClick(xAxis, yAxis, button, 3, 140, 154, 44, 58);
}

if(xAxis > 23 && xAxis < 37 && yAxis > 44 && yAxis < 58)
private void handleButtonClick(int xAxis, int yAxis, int mouseButton, int clickedButtonIndex, int xmin, int xmax, int ymin, int ymax)
{
if(xAxis > xmin && xAxis < xmax && yAxis > ymin && yAxis < ymax)
{
Mekanism.packetHandler.sendToServer(new DigitUpdateMessage(0, getIncrementedNumber(((ItemPortableTeleporter)itemStack.getItem()).getDigit(itemStack, 0))));
((ItemPortableTeleporter)itemStack.getItem()).setDigit(itemStack, 0, getIncrementedNumber(((ItemPortableTeleporter)itemStack.getItem()).getDigit(itemStack, 0)));
int currentDigit = ((ItemPortableTeleporter)itemStack.getItem()).getDigit(itemStack, clickedButtonIndex);
int updatedDigit = getUpdatedNumber(currentDigit, mouseButton);
Mekanism.packetHandler.sendToServer(new DigitUpdateMessage(clickedButtonIndex, updatedDigit));
((ItemPortableTeleporter)itemStack.getItem()).setDigit(itemStack, clickedButtonIndex, updatedDigit);
SoundHandler.playSound("gui.button.press");
}
else if(xAxis > 62 && xAxis < 76 && yAxis > 44 && yAxis < 58)
{
Mekanism.packetHandler.sendToServer(new DigitUpdateMessage(1, getIncrementedNumber(((ItemPortableTeleporter)itemStack.getItem()).getDigit(itemStack, 1))));
((ItemPortableTeleporter)itemStack.getItem()).setDigit(itemStack, 1, getIncrementedNumber(((ItemPortableTeleporter)itemStack.getItem()).getDigit(itemStack, 1)));
SoundHandler.playSound("gui.button.press");
}
else if(xAxis > 101 && xAxis < 115 && yAxis > 44 && yAxis < 58)
}

public int getUpdatedNumber(int i, int mouseButton)
{
if(mouseButton == 1) //right click
{
Mekanism.packetHandler.sendToServer(new DigitUpdateMessage(2, getIncrementedNumber(((ItemPortableTeleporter)itemStack.getItem()).getDigit(itemStack, 2))));
((ItemPortableTeleporter)itemStack.getItem()).setDigit(itemStack, 2, getIncrementedNumber(((ItemPortableTeleporter)itemStack.getItem()).getDigit(itemStack, 2)));
SoundHandler.playSound("gui.button.press");
return (i-1+10)%10; //add 10 to ensure postive result
}
else if(xAxis > 140 && xAxis < 154 && yAxis > 44 && yAxis < 58)
else
{
Mekanism.packetHandler.sendToServer(new DigitUpdateMessage(3, getIncrementedNumber(((ItemPortableTeleporter)itemStack.getItem()).getDigit(itemStack, 3))));
((ItemPortableTeleporter)itemStack.getItem()).setDigit(itemStack, 3, getIncrementedNumber(((ItemPortableTeleporter)itemStack.getItem()).getDigit(itemStack, 3)));
SoundHandler.playSound("gui.button.press");
return (i+1)%10;
}
}

public int getIncrementedNumber(int i)
{
if(i < 9) i++;
else if(i == 9) i=0;

return i;
}

public int getYAxisForNumber(int i)
{
return i*13;
Expand Down
118 changes: 69 additions & 49 deletions src/main/java/mekanism/client/gui/GuiTeleporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.util.ArrayList;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import mekanism.api.Coord4D;
import mekanism.client.gui.GuiSlot.SlotOverlay;
import mekanism.client.gui.GuiSlot.SlotType;
Expand All @@ -13,12 +15,8 @@
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.MekanismUtils.ResourceType;
import net.minecraft.entity.player.InventoryPlayer;

import org.lwjgl.opengl.GL11;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
public class GuiTeleporter extends GuiMekanism
{
Expand All @@ -36,11 +34,11 @@ public GuiTeleporter(InventoryPlayer inventory, TileEntityTeleporter tentity)
@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
{
int xAxis = (mouseX - (width - xSize) / 2);
int yAxis = (mouseY - (height - ySize) / 2);
int xAxis = (mouseX-(width-xSize)/2);
int yAxis = (mouseY-(height-ySize)/2);

fontRendererObj.drawString(tileEntity.getInventoryName(), 45, 6, 0x404040);
fontRendererObj.drawString(MekanismUtils.localize("container.inventory"), 8, (ySize - 96) + 2, 0x404040);
fontRendererObj.drawString(MekanismUtils.localize("container.inventory"), 8, (ySize-96)+2, 0x404040);
fontRendererObj.drawString(tileEntity.getStatusDisplay(), 66, 19, 0x00CD00);

if(xAxis >= 165 && xAxis <= 169 && yAxis >= 17 && yAxis <= 69)
Expand All @@ -56,89 +54,111 @@ protected void mouseClicked(int x, int y, int button)
{
super.mouseClicked(x, y, button);

int xAxis = (x - (width - xSize) / 2);
int yAxis = (y - (height - ySize) / 2);
int xAxis = (x-(width-xSize)/2);
int yAxis = (y-(height-ySize)/2);

ArrayList data = new ArrayList();
handleButtonClick(xAxis, yAxis, button, 23, 37, 44, 58, 0);
handleButtonClick(xAxis, yAxis, button, 62, 76, 44, 58, 1);
handleButtonClick(xAxis, yAxis, button, 101, 115, 44, 58, 2);
handleButtonClick(xAxis, yAxis, button, 140, 154, 44, 58, 3);
}

if(xAxis > 23 && xAxis < 37 && yAxis > 44 && yAxis < 58)
private void handleButtonClick(int xAxis, int yAxis, int mouseButton, int xmin, int xmax, int ymin, int ymax, int buttonIndex)
{
if(xAxis > xmin && xAxis < xmax && yAxis > ymin && yAxis < ymax)
{
data.add(0);
data.add(getIncrementedNumber(tileEntity.code.digitOne));
ArrayList data = new ArrayList();

int incrementedNumber = getUpdatedNumber(getButtonValue(buttonIndex), mouseButton);

data.add(buttonIndex);
data.add(incrementedNumber);

Mekanism.packetHandler.sendToServer(new TileEntityMessage(Coord4D.get(tileEntity), data));
tileEntity.code.digitOne = getIncrementedNumber(tileEntity.code.digitOne);
SoundHandler.playSound("gui.button.press");
setButton(buttonIndex, incrementedNumber);
SoundHandler.playSound("gui.button.press");
}
else if(xAxis > 62 && xAxis < 76 && yAxis > 44 && yAxis < 58)
{
data.add(1);
data.add(getIncrementedNumber(tileEntity.code.digitTwo));
}

Mekanism.packetHandler.sendToServer(new TileEntityMessage(Coord4D.get(tileEntity), data));
tileEntity.code.digitTwo = getIncrementedNumber(tileEntity.code.digitTwo);
SoundHandler.playSound("gui.button.press");
public void setButton(int index, int number)
{
if(index == 0)
{
tileEntity.code.digitOne = number;
}
else if(xAxis > 101 && xAxis < 115 && yAxis > 44 && yAxis < 58)
if(index == 1)
{
data.add(2);
data.add(getIncrementedNumber(tileEntity.code.digitThree));

Mekanism.packetHandler.sendToServer(new TileEntityMessage(Coord4D.get(tileEntity), data));
tileEntity.code.digitThree = getIncrementedNumber(tileEntity.code.digitThree);
SoundHandler.playSound("gui.button.press");
tileEntity.code.digitTwo = number;
}
if(index == 2)
{
tileEntity.code.digitThree = number;
}
else if(xAxis > 140 && xAxis < 154 && yAxis > 44 && yAxis < 58)
if(index == 3)
{
data.add(3);
data.add(getIncrementedNumber(tileEntity.code.digitFour));
tileEntity.code.digitFour = number;
}
}

Mekanism.packetHandler.sendToServer(new TileEntityMessage(Coord4D.get(tileEntity), data));
tileEntity.code.digitFour = getIncrementedNumber(tileEntity.code.digitFour);
SoundHandler.playSound("gui.button.press");
public int getButtonValue(int index)
{
if(index == 0)
{
return tileEntity.code.digitOne;
}
if(index == 1)
{
return tileEntity.code.digitTwo;
}
if(index == 2)
{
return tileEntity.code.digitThree;
}
if(index == 3)
{
return tileEntity.code.digitFour;
}
return 0;//should never happen
}

@Override
protected void drawGuiContainerBackgroundLayer(float partialTick, int mouseX, int mouseY)
{
mc.renderEngine.bindTexture(MekanismUtils.getResource(ResourceType.GUI, "GuiTeleporter.png"));
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
int guiWidth = (width - xSize) / 2;
int guiHeight = (height - ySize) / 2;
int guiWidth = (width-xSize)/2;
int guiHeight = (height-ySize)/2;
drawTexturedModalRect(guiWidth, guiHeight, 0, 0, xSize, ySize);
int displayInt;

displayInt = tileEntity.getScaledEnergyLevel(52);
drawTexturedModalRect(guiWidth + 165, guiHeight + 17 + 52 - displayInt, 176 + 13, 52 - displayInt, 4, displayInt);
drawTexturedModalRect(guiWidth+165, guiHeight+17+52-displayInt, 176+13, 52-displayInt, 4, displayInt);

displayInt = getYAxisForNumber(tileEntity.code.digitOne);
drawTexturedModalRect(guiWidth + 23, guiHeight + 44, 176, displayInt, 13, 13);
drawTexturedModalRect(guiWidth+23, guiHeight+44, 176, displayInt, 13, 13);

displayInt = getYAxisForNumber(tileEntity.code.digitTwo);
drawTexturedModalRect(guiWidth + 62, guiHeight + 44, 176, displayInt, 13, 13);
drawTexturedModalRect(guiWidth+62, guiHeight+44, 176, displayInt, 13, 13);

displayInt = getYAxisForNumber(tileEntity.code.digitThree);
drawTexturedModalRect(guiWidth + 101, guiHeight + 44, 176, displayInt, 13, 13);
drawTexturedModalRect(guiWidth+101, guiHeight+44, 176, displayInt, 13, 13);

displayInt = getYAxisForNumber(tileEntity.code.digitFour);
drawTexturedModalRect(guiWidth + 140, guiHeight + 44, 176, displayInt, 13, 13);
drawTexturedModalRect(guiWidth+140, guiHeight+44, 176, displayInt, 13, 13);

super.drawGuiContainerBackgroundLayer(partialTick, mouseX, mouseY);
}

public int getIncrementedNumber(int i)
public int getUpdatedNumber(int i, int mouseButton)
{
if(i < 9)
if(mouseButton == 1) //right click
{
i++;
return (i-1+10)%10; //add 10 to ensure postive result
}
else if(i == 9)
else
{
i = 0;
return (i+1)%10;
}

return i;
}

public int getYAxisForNumber(int i)
Expand Down

0 comments on commit 0c5fa1b

Please sign in to comment.