Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/train/client/core/ClientProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,8 @@ public Object getClientGuiElement(int ID, EntityPlayer player, World world, int
return entity1 != null ? new GuiFixedOverlay(player, (EntityRollingStock) entity1) : null;
case (GuiIDs.DYNAMIC_OVERLAY):
return entity1 != null ? new GuiDynamicOverlay(player, (EntityRollingStock) entity1) : null;
case (GuiIDs.LOCK_MENU):
return entity1 != null ? new GuiLockMenu(player, ((EntityRollingStock) entity1)) : null;
case (GuiIDs.SEAT_GUI):
return entity1 != null ? new GUISeatManager(player, (EntityRollingStock) entity1) : null;
default:
Expand Down
148 changes: 148 additions & 0 deletions src/main/java/train/client/gui/GuiButtonLockMenu.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
package train.client.gui;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import train.common.library.Info;

/**
* @author 02skaplan
* <p>Class for buttons used for the lock menu.</p>
*/
@SideOnly(Side.CLIENT)
class GuiButtonLockMenu extends GuiButton {
enum Type {
LOCKED,
UNLOCKED,
CLOSE,
REMOVE,
BREAKACCESSON,
BREAKACCESSOFF,
SAVETOALL,
ARROWUP,
ARROWDOWN,
COPY,
PASTE
}
enum Texture {
ACTIVE,
INACTIVE
}
/**
* if the button has to be drawn drawButton is more than just draw, it makes the button exists or not too
*/
public boolean showButton;
/**
* Starting x-value on texture.
*/
private int u;
/**
* Starting y-value on texture.
*/
private int v = 0;
private int TEXTURE_WIDTH;
private int TEXTURE_HEIGHT;
private Texture texture;
private Type type;

public GuiButtonLockMenu(int buttonID, int x, int y, int xSize, int ySize, Type type) {
super(buttonID, x, y, xSize, ySize, "");
this.setType(type, Texture.INACTIVE);
}

/**
* Draws this button to the screen.
*/
@Override
public void drawButton(Minecraft mc, int par2, int par3) {
if (this.visible && showButton) {
if (par2 >= this.xPosition && par3 >= this.yPosition && par2 < this.xPosition + this.width && par3 < this.yPosition + this.height) { // If mouse is hovering over...
this.setType(this.type, Texture.ACTIVE);
} else {
this.setType(this.type, Texture.INACTIVE);
}
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
RenderHelper.enableGUIStandardItemLighting();
GL11.glPushMatrix();
mc.renderEngine.bindTexture(new ResourceLocation(Info.resourceLocation, Info.guiPrefix + "gui_lockmenu.png"));
this.drawTexturedModalRect(this.xPosition, this.yPosition, u, v, TEXTURE_WIDTH, TEXTURE_HEIGHT);
RenderHelper.disableStandardItemLighting();
GL11.glPopMatrix();
}
}
public void setType(Type type, Texture texture) {
this.type = type;
this.texture = texture;
switch (type) {
case LOCKED:
case UNLOCKED:
case CLOSE:
case REMOVE:
if (texture == Texture.INACTIVE)
v = 0;
else
v = 25;
if (type == Type.LOCKED || type == Type.UNLOCKED) {
TEXTURE_WIDTH = 17;
TEXTURE_HEIGHT = 25;
if (type == Type.LOCKED)
u = 176;
else
u = 193;
} else {
TEXTURE_WIDTH = 17;
TEXTURE_HEIGHT = 17;
if (type == Type.CLOSE)
u = 210;
else
u = 227;
}
break;
case BREAKACCESSON:
case BREAKACCESSOFF:
case SAVETOALL:
TEXTURE_WIDTH = 17;
TEXTURE_HEIGHT = 17;
if (texture == Texture.INACTIVE)
v = 50;
else
v = 75;
if (type == Type.BREAKACCESSON)
u = 193;
else if (type == Type.BREAKACCESSOFF)
u = 210;
else
u = 227;
break;
case ARROWUP:
case ARROWDOWN:
case COPY:
case PASTE:
if (texture == Texture.INACTIVE)
v = 92;
else
v = 117;
if (type == Type.ARROWUP || type == Type.ARROWDOWN) {
TEXTURE_WIDTH = 7;
TEXTURE_HEIGHT = 22;
if (type == Type.ARROWUP)
u = 176;
else
u = 192;
} else {
TEXTURE_WIDTH = 17;
TEXTURE_HEIGHT = 17;
if (type == Type.COPY)
u = 210;
else
u = 227;
}
}
}
public Texture getTexture() { return this.texture; }
public Type getType() { return this.type; }
}
70 changes: 39 additions & 31 deletions src/main/java/train/client/gui/GuiFreight.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import train.common.api.Freight;
import train.common.core.network.PacketSetTrainLockedToClient;
import train.common.inventory.InventoryFreight;
import train.common.library.GuiIDs;
import train.common.library.Info;

import java.util.List;
Expand Down Expand Up @@ -54,8 +55,15 @@ public void initGui() {

if (!freight.getTrainLockedFromPacket()) {
this.buttonList.add(this.buttonLock = new GuiButton(3, buttonPosX + 124, buttonPosY - 10, 51, 10, "Unlocked"));
} else {
this.buttonList.add(this.buttonLock = new GuiButton(3, buttonPosX + 130, buttonPosY - 10, 43, 10, "Locked"));
}
else {
if (freight.getTrainOwner().equalsIgnoreCase(player.getDisplayName()))
this.buttonList.add(this.buttonLock = new GuiButton(3, buttonPosX + 130, buttonPosY - 10, 43, 10, "Locked"));
else if (freight.isPlayerTrusted(player.getDisplayName()))
if (freight.isPlayerTrustedToBreak(player.getDisplayName()))
this.buttonList.add(this.buttonLock = new GuiButton(3, buttonPosX + 125, buttonPosY - 10, 48, 10, "Trusted+"));
else
this.buttonList.add(this.buttonLock = new GuiButton(3, buttonPosX + 128, buttonPosY - 10, 45, 10, "Trusted"));
}
if (freight.seats.size() > 1) {
this.buttonList.add(this.buttonSeatManager = new GUIButton(buttonPosX + 124,buttonPosY - 20, 51,10, "Seats") {
Expand Down Expand Up @@ -84,35 +92,32 @@ public void onClick() {
protected void actionPerformed(GuiButton guibutton) {
if (guibutton.id == 3) {
if (player != null && player.getCommandSenderName().equalsIgnoreCase(freight.getTrainOwner())) {
AxisAlignedBB box = freight.boundingBox.expand(5, 5, 5);
List lis3 = freight.worldObj.getEntitiesWithinAABBExcludingEntity(freight, box);

if (!freight.getTrainLockedFromPacket()) {
if (lis3 != null && !lis3.isEmpty()) {
for (Object entity : lis3) {
if (entity instanceof EntityPlayer) {
Traincraft.lockChannel.sendToServer(new PacketSetTrainLockedToClient(true, freight.getEntityId()));
}
}
}

if (!freight.getTrainLockedFromPacket() && !isShiftKeyDown()) {
freight.locked = true;
guibutton.displayString = "Locked";
} else {
if (lis3 != null && !lis3.isEmpty()) {
for (Object entity : lis3) {
if (entity instanceof EntityPlayer) {
Traincraft.lockChannel.sendToServer(new PacketSetTrainLockedToClient(false, freight.getEntityId()));
this.initGui();
} else if (!isShiftKeyDown()) {
freight.locked = false;
guibutton.displayString = "Unlocked";
this.initGui();
}
AxisAlignedBB box = freight.boundingBox.expand(5, 5, 5);
List lis3 = freight.worldObj.getEntitiesWithinAABBExcludingEntity(freight, box);
if (lis3 != null && !lis3.isEmpty()) {
for (Object entity : lis3) {
if (entity instanceof EntityPlayer) {
if (!isShiftKeyDown()) {
Traincraft.lockChannel.sendToServer(new PacketSetTrainLockedToClient(freight.locked, freight.getTrustedList(), freight.getEntityId(), false));
} else {
this.mc.thePlayer.closeScreen();
player.openGui(Traincraft.instance, GuiIDs.LOCK_MENU, player.getEntityWorld(), freight.getEntityId(), -1, (int) freight.posZ);
return;
}
}
}

freight.locked = false;
guibutton.displayString = "Unlocked";
}

this.initGui();
} else if (player != null) {
}
else if (player != null && player instanceof EntityPlayer) {
player.addChatMessage(new ChatComponentText("You are not the owner"));
}
} else if (guibutton instanceof GUIButton) {
Expand All @@ -124,12 +129,15 @@ protected void actionPerformed(GuiButton guibutton) {
protected void drawCreativeTabHoveringText(String str, int t, int g) {
String state = "";
if (freight.getTrainLockedFromPacket()) {
state = "Locked";
}

if (!freight.getTrainLockedFromPacket()) {
state = "Unlocked";
}
if (freight.getTrainOwner().equalsIgnoreCase(player.getDisplayName()))
state = "Locked";
else if (freight.isPlayerTrusted(player.getDisplayName()))
if (freight.isPlayerTrustedToBreak(player.getDisplayName()))
state = "Trusted Access+";
else
state = "Trusted Access";
} else
state = "Unlocked";

int textWidth = fontRendererObj.getStringWidth("the GUI, change speed, destroy it.");
int startX = 90;
Expand Down
42 changes: 42 additions & 0 deletions src/main/java/train/client/gui/GuiLockMenu.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package train.client.gui;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.entity.player.EntityPlayer;
import train.common.Traincraft;
import train.common.api.EntityRollingStock;
import train.common.core.network.PacketSetTrainLockedToClient;

/**
* @author 02skaplan
* <p>Lock and Trusted Players Menu</p>
* <p>Allows players to lock and unlock a piece of rolling stock and add & remove trusted individuals from using the rolling stock.</p>
*/
@SideOnly(Side.CLIENT)
public class GuiLockMenu extends GuiLockMenuAbstract {
private final EntityRollingStock rollingStock;

/**
* @author 02skaplan
*/
public GuiLockMenu(EntityPlayer editingPlayer, EntityRollingStock rollingStock) {
super(editingPlayer);
this.rollingStock = rollingStock;
currentTrustees.addAll(rollingStock.getTrustedList());
}

@Override
public boolean getLocked() {
return rollingStock.getTrainLockedFromPacket();
}

@Override
public void setLocked(boolean locked) {
rollingStock.setTrainLockedFromPacket(locked);
}

@Override
public void sendUpdatePacket(boolean propagate) {
Traincraft.lockChannel.sendToServer(new PacketSetTrainLockedToClient(rollingStock.locked, exportTrustedPlayers(), rollingStock.getEntityId(), propagate));
}
}
Loading