forked from Traincraft/Traincraft
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A simple seat picking GUI, and the networking for it, that allows you to choose which seat you are sitting in. Everything with more than 1 seat gets the button to open this GUI. More improvements to this are coming in the following commits
- Loading branch information
1 parent
12916d6
commit 8248101
Showing
6 changed files
with
290 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
package ebf.tim.gui; | ||
|
||
import ebf.tim.TrainsInMotion; | ||
import ebf.tim.api.SkinRegistry; | ||
import ebf.tim.api.TransportSkin; | ||
import ebf.tim.entities.EntitySeat; | ||
import ebf.tim.entities.GenericRailTransport; | ||
import ebf.tim.networking.PacketPaint; | ||
import ebf.tim.networking.PacketSeatUpdate; | ||
import ebf.tim.utility.ClientProxy; | ||
import ebf.tim.utility.ClientUtil; | ||
import ebf.tim.utility.CommonUtil; | ||
import ebf.tim.utility.EventManager; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.entity.AbstractClientPlayer; | ||
import net.minecraft.client.gui.FontRenderer; | ||
import net.minecraft.client.gui.GuiScreen; | ||
import net.minecraft.client.gui.ScaledResolution; | ||
import net.minecraft.client.renderer.RenderHelper; | ||
import net.minecraft.entity.EntityLivingBase; | ||
import net.minecraft.entity.player.EntityPlayer; | ||
import net.minecraft.util.ResourceLocation; | ||
import org.lwjgl.input.Keyboard; | ||
import org.lwjgl.opengl.GL11; | ||
import org.lwjgl.util.glu.Project; | ||
|
||
import java.util.*; | ||
|
||
|
||
/** | ||
* <h1>Transport GUI</h1> | ||
* used to draw the GUI for choosing a seat while in a piece of rollingstock (get here from a button in the normal UI). | ||
* @author broscolotos | ||
*/ | ||
public class GUISeatManager extends GUIPaintBucket { | ||
|
||
public ArrayList<Integer> filledSeatIDs = new ArrayList<>(); | ||
public EntitySeat currentSeat; | ||
public GUISeatManager(GenericRailTransport transport) { | ||
super(transport); | ||
} | ||
|
||
@Override | ||
public void initGui() { | ||
if(entity !=null && entity.getRiderOffsets().length > 0) { | ||
|
||
} | ||
} | ||
@Override | ||
public void updateScreen() {} | ||
|
||
public static int percentTop(int value){return (int)(guiTop*(value*0.01f));} | ||
public static int percentLeft(int value){return (int)(guiLeft*(value*0.01f));} | ||
|
||
@Override | ||
public void drawScreen(int parWidth, int parHeight, float p_73863_3_) { | ||
this.drawDefaultBackground(); | ||
super.drawScreen(parWidth, parHeight, p_73863_3_); | ||
guiLeft=new ScaledResolution(Minecraft.getMinecraft(), Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight).getScaledWidth(); | ||
guiTop=new ScaledResolution(Minecraft.getMinecraft(), Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight).getScaledHeight(); | ||
|
||
if (entity.getRiderOffsets().length==0 || entity.getRiderOffsets() == null){ | ||
return; | ||
} | ||
for(EntitySeat seat : entity.seats) { | ||
if (seat.getPassenger() != null) { | ||
if (seat.getPassenger() == Minecraft.getMinecraft().thePlayer) { | ||
currentSeat = seat; | ||
} | ||
filledSeatIDs.add(seat.getEntityId()); | ||
} | ||
} | ||
if(filledSeatIDs.size() == entity.seats.size()) { //remove after GUI is sorted out | ||
return; | ||
} | ||
switch(guiScreen) { | ||
case 0:{guiSeatManager();defineButtons();break;} | ||
} | ||
} | ||
@Override | ||
public boolean doesGuiPauseGame() {return false;} | ||
@Override | ||
public void defineButtons(){ | ||
switch (guiScreen){ | ||
case 0:{ | ||
buttonList =new ArrayList(); | ||
//this is for debugging. After its all sorted we will have a GUI with all of the seats laid out on a grid | ||
int column = 0; | ||
int activeRow = 0; | ||
for (int i=0;i<entity.getRiderOffsets().length; i++) { | ||
if (percentTop(25)+(28*activeRow+1)>percentTop(60)) { | ||
column++; | ||
activeRow=0; | ||
} | ||
|
||
if (entity.seats.get(i).getPassenger() instanceof EntityPlayer) { | ||
//mc.getTextureManager().bindTexture(((AbstractClientPlayer) entity.riddenByEntity).getLocationSkin()); | ||
buttonList.add( | ||
new GUIButton(percentLeft(50)-240+(column*120), percentTop(25)+(28*activeRow+1), fontRendererObj.getStringWidth(entity.seats.get(i).getPassenger().getCommandSenderName())+7,20,entity.seats.get(i).getPassenger().getCommandSenderName()) { | ||
@Override | ||
public String getHoverText() { | ||
return "Seat is currently occupied"; | ||
} | ||
@Override | ||
public void onClick() {} | ||
@Override | ||
public FontRenderer getFont(){return fontRendererObj;} | ||
} | ||
); | ||
} else { //TODO: add an else if for things that aren't players. this becomes important for stuff like stock cars or putting villagers in player seats | ||
buttonList.add( | ||
new GUIButton( percentLeft(50)-240+(column*120), percentTop(25)+(28*activeRow+1), fontRendererObj.getStringWidth("Empty Seat")+6,20,"Empty Seat") { | ||
@Override | ||
public String getHoverText() { | ||
return "Seat is currently Empty"; | ||
} | ||
@Override | ||
public void onClick() { | ||
/*int nextIndex = 0; | ||
if (entity.seats.indexOf(currentSeat) == 0) { | ||
nextIndex = entity.seats.size()-1; | ||
} else { | ||
nextIndex = entity.seats.indexOf(currentSeat)-1; | ||
}*/ | ||
; | ||
EntityLivingBase passenger = currentSeat.getPassenger(); | ||
/* currentSeat.removePassenger(passenger); | ||
entity.seats.get(buttonList.indexOf(this)).addPassenger(passenger); | ||
currentSeat = entity.seats.get(buttonList.indexOf(this));*/ | ||
TrainsInMotion.updateChannel.sendToServer(new PacketSeatUpdate(entity.getEntityId(),passenger.getEntityId(),entity.seats.indexOf(currentSeat),buttonList.indexOf(this))); | ||
//currentSeat = entity.seats.get(buttonList.indexOf(this)); | ||
//TODO: need a way to tell the server that the player and previous EntitySeat need updated. | ||
|
||
} | ||
@Override | ||
public FontRenderer getFont(){return fontRendererObj;} | ||
} | ||
); | ||
} | ||
activeRow++; | ||
} | ||
break; | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
public void guiSeatManager(){ | ||
mc.getTextureManager().bindTexture(ClientUtil.vanillaInventory); | ||
GL11.glDisable(GL11.GL_LIGHTING); | ||
GL11.glPushMatrix(); | ||
int rows=0; | ||
//draw the character backgrounds. | ||
//make a loop that will make a new row every 5 items | ||
for (int i=0;i<entity.getRiderOffsets().length; i++) { | ||
if (i/(rows+1) >=5*(rows+1)){ | ||
rows++; | ||
} | ||
ClientUtil.drawTexturedRect(guiLeft + 106 + (30*(i-(rows * 5))), guiTop + 30+(30*rows), 54, 51, 27, 27, 20, 20); | ||
} | ||
//make a new loop that does the same as above but binds the character's face rather than the inventory slot background. | ||
for (int i=0;i<entity.getRiderOffsets().length; i++) { | ||
if (i/(rows+1) >=5*(rows+1)){ | ||
rows++; | ||
} | ||
if (i==0 && entity.riddenByEntity instanceof AbstractClientPlayer){ | ||
mc.getTextureManager().bindTexture(((AbstractClientPlayer) entity.riddenByEntity).getLocationSkin()); | ||
ClientUtil.drawTexturedRect(guiLeft + 108 + (30*(i-(rows * 5))), guiTop + 32+(30*rows), 30, 70, 23, 23, 36, 56); | ||
} else if (i>0 && entity.seats.get(i-1).riddenByEntity instanceof AbstractClientPlayer){ | ||
mc.getTextureManager().bindTexture(((AbstractClientPlayer) entity.seats.get(i-1).riddenByEntity).getLocationSkin()); | ||
ClientUtil.drawTexturedRect(guiLeft + 108 + (30*(i-(rows * 5))), guiTop + 32+(30*rows), 30, 70, 23, 23, 36, 56); | ||
} | ||
} | ||
GL11.glPopMatrix(); | ||
GL11.glEnable(GL11.GL_LIGHTING); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package ebf.tim.networking; | ||
|
||
import cpw.mods.fml.common.network.NetworkRegistry; | ||
import cpw.mods.fml.common.network.simpleimpl.IMessage; | ||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; | ||
import cpw.mods.fml.common.network.simpleimpl.MessageContext; | ||
import cpw.mods.fml.relauncher.Side; | ||
import ebf.tim.TrainsInMotion; | ||
import ebf.tim.entities.EntitySeat; | ||
import ebf.tim.entities.GenericRailTransport; | ||
import io.netty.buffer.ByteBuf; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.entity.Entity; | ||
/** | ||
* <h1>Seat Packet</h1> | ||
* bi-directional packet for managing seat changes while in a piece of stock. | ||
* @author broscolotos | ||
* @author 02Skaplan | ||
*/ | ||
public class PacketSeatUpdate implements IMessage { | ||
/**the ID of the entity to dismount from*/ | ||
private int rollingStockId, playerId, oldSeatIndex, newSeatIndex; | ||
|
||
public PacketSeatUpdate() {} | ||
public PacketSeatUpdate(int rollingStockId, int playerId, int oldSeatIndex, int newSeatIndex) { | ||
this.rollingStockId = rollingStockId; | ||
this.playerId = playerId; | ||
this.oldSeatIndex = oldSeatIndex; | ||
this.newSeatIndex = newSeatIndex; | ||
} | ||
/**reads the packet on server to get the variables from the Byte Buffer*/ | ||
@Override | ||
public void fromBytes(ByteBuf bbuf) { | ||
rollingStockId= bbuf.readInt(); | ||
playerId=bbuf.readInt(); | ||
oldSeatIndex=bbuf.readInt(); | ||
newSeatIndex=bbuf.readInt(); | ||
} | ||
/**puts the variables into a Byte Buffer so they can be sent to server*/ | ||
@Override | ||
public void toBytes(ByteBuf bbuf) { | ||
bbuf.writeInt(rollingStockId); | ||
bbuf.writeInt(playerId); | ||
bbuf.writeInt(oldSeatIndex); | ||
bbuf.writeInt(newSeatIndex); | ||
} | ||
|
||
public static class Handler implements IMessageHandler<PacketSeatUpdate,IMessage> { | ||
@Override public IMessage onMessage(PacketSeatUpdate message, MessageContext ctx) { | ||
GenericRailTransport rollingStockEntity; | ||
Entity playerEntity; | ||
EntitySeat oldSeat; | ||
EntitySeat newSeat; | ||
if (ctx.side == Side.SERVER) { | ||
rollingStockEntity = (GenericRailTransport) ctx.getServerHandler().playerEntity.worldObj.getEntityByID(message.rollingStockId); | ||
playerEntity = ctx.getServerHandler().playerEntity.worldObj.getEntityByID(message.playerId); | ||
|
||
} else { | ||
rollingStockEntity = (GenericRailTransport) Minecraft.getMinecraft().theWorld.getEntityByID(message.rollingStockId); | ||
playerEntity = Minecraft.getMinecraft().theWorld.getEntityByID(message.playerId); | ||
} | ||
oldSeat = rollingStockEntity.seats.get(message.oldSeatIndex); | ||
newSeat = rollingStockEntity.seats.get(message.newSeatIndex); | ||
newSeat.addPassenger(playerEntity); | ||
oldSeat.removePassenger(playerEntity); | ||
playerEntity.mountEntity(newSeat); | ||
if (ctx.side == Side.SERVER) { | ||
TrainsInMotion.updateChannel.sendToAllAround(new PacketSeatUpdate(message.rollingStockId,message.playerId,message.oldSeatIndex,message.newSeatIndex), | ||
new NetworkRegistry.TargetPoint(playerEntity.dimension,rollingStockEntity.posX,rollingStockEntity.posY,rollingStockEntity.posZ,256D)); | ||
} | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters