Skip to content

Commit

Permalink
Slopes and SeatGUI progress
Browse files Browse the repository at this point in the history
 - SeatGUI is mostly working; some odd things do happen when you use it when not in the control seat.
 - renamed some stuff in the main TC track movement method to make it a bit easier for new people to jump in and know what's happening.
 - reworked the slope acceleration to actually do something; two different "modes", one for consists with a locomotive and one for free-rolling rollingstock.
  • Loading branch information
broscolotos committed Aug 3, 2024
1 parent ee0af67 commit 073ea6b
Show file tree
Hide file tree
Showing 15 changed files with 384 additions and 161 deletions.
1 change: 0 additions & 1 deletion src/main/java/ebf/tim/gui/GUIButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public void drawButton(Minecraft mc, int mouseX, int mouseY){
/** draws the button*/
public void drawButton(int mouseX, int mouseY) {
GL11.glPushMatrix();
RenderHelper.enableStandardItemLighting();
TextureManager.bindTexture(buttonTextures);
if(getColor()!=null){
GL11.glColor4f(getColor()[0]*0.00392156862f, getColor()[1]*0.00392156862f, getColor()[2]*0.00392156862f, 1.0F);
Expand Down
25 changes: 20 additions & 5 deletions src/main/java/ebf/tim/gui/GUISeatManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.AbstractClientPlayer;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.entity.player.EntityPlayer;
Expand Down Expand Up @@ -39,10 +40,13 @@ public class GUISeatManager extends GuiScreen {
public GUISeatManager(EntityRollingStock transport) {
entity=transport;
}
public GUISeatManager(EntityPlayer player, EntityRollingStock transport) {
entity=transport;
}

@Override
public void initGui() {
if(entity !=null && entity.getRiderOffsets().length > 0) {
if (entity != null && entity.getRiderOffsets().length > 0) {

}
}
Expand All @@ -65,7 +69,7 @@ public void drawScreen(int parWidth, int parHeight, float p_73863_3_) {
}
for(EntitySeat seat : entity.seats) {
if (seat.getPassenger() != null) {
if (seat.getPassenger() == Minecraft.getMinecraft().thePlayer) {
if (seat.getPassenger() instanceof EntityPlayer && ((EntityPlayer)seat.getPassenger()).getDisplayName() == mc.thePlayer.getDisplayName()) {
currentSeat = seat;
}
filledSeatIDs.add(seat.getEntityId());
Expand All @@ -77,6 +81,11 @@ public void drawScreen(int parWidth, int parHeight, float p_73863_3_) {
switch(guiScreen) {
case 0:{defineButtons();guiSeatManager();break;}
}
for(Object guiButton: buttonList) {
if (guiButton instanceof GUIButton) {
((GUIButton)guiButton).drawText(parWidth-(int)guiLeft,parHeight-(int)guiTop);
}
}
}
@Override
public boolean doesGuiPauseGame() {return false;}
Expand Down Expand Up @@ -134,8 +143,6 @@ public void onClick() {
if (lastClickTick+5 < entity.ticksExisted) {
Traincraft.updateChannel.sendToServer(new PacketSeatUpdate(entity.getEntityId(),currentSeat.getPassenger().getEntityId(),entity.seats.indexOf(currentSeat),buttonList.indexOf(this),entity.dimension));
lastClickTick = entity.ticksExisted;
} else {
System.out.println("Too fast");
}
}
@Override
Expand Down Expand Up @@ -165,7 +172,12 @@ public void onClick() {
}
}


@Override
protected void actionPerformed(GuiButton guibutton) {
if (guibutton instanceof GUIButton) {
((GUIButton) guibutton).onClick();
}
}


public void guiSeatManager(){
Expand All @@ -180,6 +192,9 @@ public void guiSeatManager(){
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);
} else if (seat.getPassenger() instanceof EntityPlayer) {
mc.getTextureManager().bindTexture(Minecraft.getMinecraft().thePlayer.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();
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/train/client/core/ClientProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.registry.VillagerRegistry;
import ebf.tim.entities.EntitySeat;
import ebf.tim.gui.GUISeatManager;
import javazoom.jl.decoder.JavaLayerUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.SoundCategory;
Expand Down Expand Up @@ -382,7 +383,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.SEAT_GUI):
return entity1 != null ? new GUISeatManager(player, (EntityRollingStock) entity1) : null;
default:
return null;
}
Expand Down Expand Up @@ -466,4 +468,9 @@ public void registerKeyBindingHandler() {
public void setHook() {
JavaLayerUtils.setHook(new JLayerHook(Minecraft.getMinecraft()));
}

@Override
public void seatGUI(EntityPlayer player, EntityRollingStock transport) {
Minecraft.getMinecraft().displayGuiScreen(new GUISeatManager(transport));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ else if (item.getTrackType() == EnumTracks.VERY_LONG_STRAIGHT || item.getTrackTy
turnSize = "medium";
} else if (item.getTrackType() == EnumTracks.LARGE_PARALLEL_CURVE || item.getTrackType() == EnumTracks.EMBEDDED_LARGE_PARALLEL_CURVE) {
turnSize = "large";
} else if (item.getTrackType() == EnumTracks.S_CURVE_20x2) {
turnSize = "20x2";
}

if (item.getTrackOrientation(facing, MathHelper.wrapAngleTo180_float(player.rotationYaw)).equals("left")) {
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/train/client/gui/GuiForney.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package train.client.gui;

import ebf.tim.gui.GUIButton;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.Entity;
Expand Down Expand Up @@ -30,10 +32,13 @@ public class GuiForney extends GuiContainer {
private int buttonPosX = 0;
private int buttonPosY = 0;

private InventoryPlayer player;
private GUIButton buttonSeatManager;

public GuiForney(InventoryPlayer inventoryplayer, Entity entityminecart) {
super(new InventoryForney(inventoryplayer, (Locomotive) entityminecart));
loco = (Locomotive) entityminecart;
player = inventoryplayer;
}

@Override
Expand Down Expand Up @@ -81,6 +86,36 @@ public void initGui() {
} else {
this.buttonList.add(this.buttonLock = new GuiButton(3, buttonPosX + 130, buttonPosY - 10, 43, 10, "Locked"));
}
if (loco.seats.size() > 1) {
this.buttonList.add(this.buttonSeatManager = new GUIButton(buttonPosX + 124,buttonPosY - 20, 51,10, "Seats") {
@Override
public String getHoverText() {
return "gui.seats";
}

@Override
public int[] getColor(){
return null;
}

@Override
public void onClick() {
Traincraft.proxy.seatGUI(player.player,loco);
}

@Override
public FontRenderer getFont(){return fontRendererObj;}
});
}
}

@Override
public void drawScreen(int mouseX, int mouseY, float par3) {
for(Object guiButton: buttonList) {
if (guiButton instanceof GUIButton) {
((GUIButton)guiButton).drawText(mouseX-(int)guiLeft,mouseY-(int)guiTop);
}
}
}

@Override
Expand Down Expand Up @@ -119,6 +154,8 @@ protected void actionPerformed(GuiButton guibutton) {
} else if (loco.riddenByEntity != null && loco.riddenByEntity instanceof EntityPlayer) {
((EntityPlayer) loco.riddenByEntity).addChatMessage(new ChatComponentText("You are not the owner"));
}
} else if (guibutton instanceof GUIButton) {
((GUIButton)guibutton).onClick();
}
}

Expand Down
37 changes: 37 additions & 0 deletions src/main/java/train/client/gui/GuiFreight.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package train.client.gui;

import ebf.tim.gui.GUIButton;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.Entity;
Expand All @@ -26,6 +28,7 @@ public class GuiFreight extends GuiContainer {
private float yaw;
private float roll;
private boolean rollDown;
private GUIButton buttonSeatManager;
private GuiButton buttonLock;

public GuiFreight(EntityPlayer player, InventoryPlayer inventoryplayer, Entity entityminecart) {
Expand Down Expand Up @@ -54,6 +57,27 @@ public void initGui() {
} else {
this.buttonList.add(this.buttonLock = new GuiButton(3, buttonPosX + 130, buttonPosY - 10, 43, 10, "Locked"));
}
if (freight.seats.size() > 1) {
this.buttonList.add(this.buttonSeatManager = new GUIButton(buttonPosX + 124,buttonPosY - 20, 51,10, "Seats") {
@Override
public String getHoverText() {
return "gui.seats";
}

@Override
public int[] getColor(){
return null;
}

@Override
public void onClick() {
Traincraft.proxy.seatGUI(player,freight);
}

@Override
public FontRenderer getFont(){return fontRendererObj;}
});
}
}

@Override
Expand Down Expand Up @@ -91,6 +115,8 @@ protected void actionPerformed(GuiButton guibutton) {
} else if (player != null) {
player.addChatMessage(new ChatComponentText("You are not the owner"));
}
} else if (guibutton instanceof GUIButton) {
((GUIButton)guibutton).onClick();
}
}

Expand Down Expand Up @@ -130,6 +156,17 @@ public boolean intersectsWith(int mouseX, int mouseY) {
return (mouseX >= j + 124 && mouseX <= j + 174 && mouseY >= k - 10 && mouseY <= k);
}



@Override
public void drawScreen(int mouseX, int mouseY, float par3) {
for(Object guiButton: buttonList) {
if (guiButton instanceof GUIButton) {
((GUIButton)guiButton).drawText(mouseX-(int)guiLeft,mouseY-(int)guiTop);
}
}
super.drawScreen(mouseX,mouseY,par3);
}
@Override
protected void drawGuiContainerForegroundLayer(int i, int j) {
GL11.glDisable(GL11.GL_LIGHTING);
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/train/client/gui/GuiLoco2.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package train.client.gui;

import ebf.tim.gui.GUIButton;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.Entity;
Expand Down Expand Up @@ -30,10 +32,14 @@ public class GuiLoco2 extends GuiContainer {
private int buttonPosX = 0;
private int buttonPosY = 0;

private InventoryPlayer player;
private GUIButton buttonSeatManager;


public GuiLoco2(InventoryPlayer inventoryplayer, Entity entityminecart) {
super(new InventoryLoco(inventoryplayer, (Locomotive) entityminecart));
loco = (Locomotive) entityminecart;
player = inventoryplayer;
}

@Override
Expand Down Expand Up @@ -89,6 +95,27 @@ public void initGui() {
this.buttonList.add(this.buttonLock = new GuiButton(4, buttonPosX + 108, buttonPosY - 22, 67, 12, "Start Engine"));
}
}
if (loco.seats.size() > 1) {
this.buttonList.add(this.buttonSeatManager = new GUIButton(buttonPosX + 108, buttonPosY - 20, 67,10, "Seats") {
@Override
public String getHoverText() {
return "gui.seats";
}

@Override
public int[] getColor(){
return null;
}

@Override
public void onClick() {
Traincraft.proxy.seatGUI(player.player,loco);
}

@Override
public FontRenderer getFont(){return fontRendererObj;}
});
}
}

@Override
Expand Down Expand Up @@ -150,6 +177,8 @@ protected void actionPerformed(GuiButton guibutton) {
loco.isLocoTurnedOn = true;
guibutton.displayString = "Stop Engine";
}
} else if (guibutton instanceof GUIButton) {
((GUIButton)guibutton).onClick();
}
}

Expand Down Expand Up @@ -234,6 +263,11 @@ public void drawScreen(int mouseX, int mouseY, float par3) {
}
}
}
for(Object guiButton: buttonList) {
if (guiButton instanceof GUIButton) {
((GUIButton)guiButton).drawText(mouseX-(int)guiLeft,mouseY-(int)guiTop);
}
}
}

@Override
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/train/client/gui/GuiTender.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package train.client.gui;

import ebf.tim.gui.GUIButton;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.Entity;
Expand All @@ -25,6 +27,8 @@ public class GuiTender extends GuiContainer {
private final EntityPlayer player;
private GuiButton buttonLock;

private GUIButton buttonSeatManager;

public GuiTender(EntityPlayer player, InventoryPlayer inventoryplayer, Entity entityminecart) {
super(new InventoryTender(inventoryplayer, (Tender) entityminecart));

Expand All @@ -45,6 +49,27 @@ public void initGui() {
} else {
this.buttonList.add(this.buttonLock = new GuiButton(3, var1 + 130, var2 - 10, 43, 10, "Locked"));
}
if (tender.seats.size() > 1) {
this.buttonList.add(this.buttonSeatManager = new GUIButton((int)guiLeft+166,(int)guiTop+166, 18,18) {
@Override
public String getHoverText() {
return "gui.seats";
}

@Override
public int[] getColor(){
return null;
}

@Override
public void onClick() {
Traincraft.proxy.seatGUI(player,tender);
}

@Override
public FontRenderer getFont(){return fontRendererObj;}
});
}
}

@Override
Expand Down Expand Up @@ -85,6 +110,8 @@ protected void actionPerformed(GuiButton guibutton) {
} else if (player != null) {
player.addChatMessage(new ChatComponentText("You are not the owner"));
}
} else if (guibutton instanceof GUIButton) {
((GUIButton)guibutton).onClick();
}
}

Expand Down
Loading

0 comments on commit 073ea6b

Please sign in to comment.