From 5fc3418466c6958766df2b842c9f7fe01697cb47 Mon Sep 17 00:00:00 2001 From: broscolotos Date: Fri, 8 Sep 2023 22:49:00 -0500 Subject: [PATCH] Seat Manager Stage 2 improvements to GUI centering. added player head indicator for a visual of who is in the seat in addition to the player name as the button. only known issue with it right now is *sometimes* the packets randomly get a nullpointer and I haven't found out where/how yet. Soon:tm:. --- src/main/java/ebf/tim/gui/GUISeatManager.java | 102 +++++++++--------- 1 file changed, 49 insertions(+), 53 deletions(-) diff --git a/src/main/java/ebf/tim/gui/GUISeatManager.java b/src/main/java/ebf/tim/gui/GUISeatManager.java index e7c1ce5dd..3ab8eae34 100644 --- a/src/main/java/ebf/tim/gui/GUISeatManager.java +++ b/src/main/java/ebf/tim/gui/GUISeatManager.java @@ -1,29 +1,18 @@ 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 javax.vecmath.Vector2f; import java.util.*; @@ -36,6 +25,8 @@ public class GUISeatManager extends GUIPaintBucket { public ArrayList filledSeatIDs = new ArrayList<>(); public EntitySeat currentSeat; + + public ArrayList locations; public GUISeatManager(GenericRailTransport transport) { super(transport); } @@ -56,6 +47,7 @@ public void updateScreen() {} public void drawScreen(int parWidth, int parHeight, float p_73863_3_) { this.drawDefaultBackground(); super.drawScreen(parWidth, parHeight, p_73863_3_); + locations = new ArrayList<>(); guiLeft=new ScaledResolution(Minecraft.getMinecraft(), Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight).getScaledWidth(); guiTop=new ScaledResolution(Minecraft.getMinecraft(), Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight).getScaledHeight(); @@ -74,7 +66,7 @@ public void drawScreen(int parWidth, int parHeight, float p_73863_3_) { return; } switch(guiScreen) { - case 0:{guiSeatManager();defineButtons();break;} + case 0:{defineButtons();guiSeatManager();break;} } } @Override @@ -84,19 +76,33 @@ 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;ipercentTop(60)) { + if (percentTop(25) + (28 * activeRow + 1) - 10 > percentTop(60)) { + column++; + activeRow = 0; + } + activeRow++; + } + int totalColumns = column; + column = 0; + activeRow =0; + for (int i=0;ipercentTop(60)) { column++; activeRow=0; } - + int width = fontRendererObj.getStringWidth("Empty Seat") + 6; if (entity.seats.get(i).getPassenger() instanceof EntityPlayer) { - //mc.getTextureManager().bindTexture(((AbstractClientPlayer) entity.riddenByEntity).getLocationSkin()); + + if (fontRendererObj.getStringWidth(entity.seats.get(i).getPassenger().getCommandSenderName()) > width) { + width = fontRendererObj.getStringWidth(entity.seats.get(i).getPassenger().getCommandSenderName()) + 7; + if(width%2 !=0) + width++; + } 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()) { + new GUIButton(percentLeft(50)-60-(totalColumns/2)+(column*120)-(width/2), percentTop(25)+(28*activeRow+1)-11, width,20,entity.seats.get(i).getPassenger().getCommandSenderName()) { @Override public String getHoverText() { return "Seat is currently occupied"; @@ -109,27 +115,14 @@ public void onClick() {} ); } 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") { + new GUIButton( percentLeft(50)-60-(totalColumns/2)+(column*120)-(width/2), percentTop(25)+(28*activeRow+1)-11, width,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. + TrainsInMotion.updateChannel.sendToServer(new PacketSeatUpdate(entity.getEntityId(),currentSeat.getPassenger().getEntityId(),entity.seats.indexOf(currentSeat),buttonList.indexOf(this))); } @Override @@ -137,8 +130,23 @@ public void onClick() { } ); } + locations.add(new Vector2f(percentLeft(50)-88-(totalColumns/2)+(column*120)-(width/2),percentTop(25)+(28*activeRow+1)-13)); activeRow++; } + buttonList.add( + new GUIButton( percentLeft(50)-((fontRendererObj.getStringWidth("Close")+7)/2), percentTop(75)-10, fontRendererObj.getStringWidth("Close")+7,20,"Close") { + @Override + public String getHoverText() { + return "Close Inventory"; + } + @Override + public void onClick() { + mc.displayGuiScreen(null); + } + @Override + public FontRenderer getFont(){return fontRendererObj;} + } + ); break; } } @@ -148,29 +156,17 @@ public void onClick() { 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=5*(rows+1)){ - rows++; - } - ClientUtil.drawTexturedRect(guiLeft + 106 + (30*(i-(rows * 5))), guiTop + 30+(30*rows), 54, 51, 27, 27, 20, 20); + mc.getTextureManager().bindTexture(ClientUtil.vanillaInventory); + for(Vector2f pos : locations) { + ClientUtil.drawTexturedRect(pos.x-3, pos.y-3, 54, 51, 30, 30, 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=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); + + for(EntitySeat seat: entity.seats) { + if (seat.getPassenger() instanceof AbstractClientPlayer) { + mc.getTextureManager().bindTexture(((AbstractClientPlayer) seat.getPassenger()).getLocationSkin()); + ClientUtil.drawTexturedRect(locations.get(entity.seats.indexOf(seat)).x, locations.get(entity.seats.indexOf(seat)).y, 32, 64, 24, 24, 32, 64); } } GL11.glPopMatrix();