Skip to content

Commit

Permalink
Merge pull request #1392 from TeamOpenIndustry/gui-rewrite
Browse files Browse the repository at this point in the history
WIP: New stock user interfaces
  • Loading branch information
cam72cam authored Dec 5, 2023
2 parents 9adca9d + fae9b9a commit bea12a3
Show file tree
Hide file tree
Showing 49 changed files with 1,404 additions and 1,135 deletions.
25 changes: 19 additions & 6 deletions src/main/java/cam72cam/immersiverailroading/ConfigGraphics.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package cam72cam.immersiverailroading;

import cam72cam.immersiverailroading.library.PressureDisplayType;
import cam72cam.immersiverailroading.library.SpeedDisplayType;
import cam72cam.immersiverailroading.library.TemperatureDisplayType;
import cam72cam.immersiverailroading.library.ValveGearConfig;
import cam72cam.mod.config.ConfigFile.Comment;
import cam72cam.mod.config.ConfigFile.Name;
import cam72cam.mod.render.OptiFine;

import java.util.HashMap;
import java.util.Map;

import static cam72cam.mod.config.ConfigFile.*;

@Comment("Configuration File")
@Name("general")
@File("immersiverailroading_graphics.cfg")
public class ConfigGraphics {
@Comment( "Place to draw the Train GUI as a % from the left of the screen" )
public static int GUIPositionHorizontal = 2;

@Comment( "Place to draw the Train GUI as a % from the top of the screen" )
public static int GUIPositionVertical = 95;

@Comment("Enable Particles")
public static boolean particlesEnabled = true;

Expand All @@ -26,6 +26,12 @@ public class ConfigGraphics {
@Comment( "What unit to use for speedometer. (kmh, mph or ms)" )
public static SpeedDisplayType speedUnit = SpeedDisplayType.kmh;

@Comment("What units to display pressure in (psi, bar)")
public static PressureDisplayType pressureUnit = PressureDisplayType.psi;

@Comment("What units to display pressure in (psi, bar)")
public static TemperatureDisplayType temperatureUnit = TemperatureDisplayType.celcius;

@Comment( "How long to keep textures in memory after they have left the screen (higher numbers = smoother game play, lower numbers = less GPU memory used)")
@Range(min = 0, max = 100)
public static int textureCacheSeconds = 30;
Expand All @@ -52,4 +58,11 @@ public class ConfigGraphics {
@Comment("How likely a piece of stock is to sway (1 == always, 10 == infrequent)")
@Range(min = 0, max = 10)
public static int StockSwayChance = 1;

@Comment("Settings used in the stock user interfaces")
public static Map<String, Float> settings = new HashMap<>();

@Comment("Mouse Scroll Speed (negative values invert it)")
@Range(min = -10, max = 10)
public static float ScrollSpeed = 1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import cam72cam.immersiverailroading.multiblock.*;
import cam72cam.immersiverailroading.net.*;
import cam72cam.immersiverailroading.registry.DefinitionManager;
import cam72cam.immersiverailroading.registry.EntityRollingStockDefinition;
import cam72cam.immersiverailroading.render.SmokeParticle;
import cam72cam.immersiverailroading.render.block.RailBaseModel;
import cam72cam.immersiverailroading.render.item.*;
Expand Down Expand Up @@ -221,6 +222,9 @@ public void postRender(EntityMoveableRollingStock entity, RenderState state, flo
return true;
});

ClientEvents.TICK.subscribe(GuiBuilder::onClientTick);
ClientEvents.TICK.subscribe(EntityRollingStockDefinition.ControlSoundsDefinition::cleanupStoppedSounds);

Particles.SMOKE = Particle.register(SmokeParticle::new, SmokeParticle::renderAll);

ClientPartDragging.register();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cam72cam.immersiverailroading.entity;

import cam72cam.immersiverailroading.ConfigGraphics;
import cam72cam.immersiverailroading.model.part.Control;
import cam72cam.immersiverailroading.model.part.Interactable;
import cam72cam.immersiverailroading.model.part.Seat;
Expand Down Expand Up @@ -31,9 +32,25 @@ public static void register() {
ClientPartDragging dragger = new ClientPartDragging();
Mouse.registerDragHandler(dragger::capture);
ClientEvents.TICK.subscribe(dragger::tick);
ClientEvents.SCROLL.subscribe(dragger::scroll);
Packet.register(DragPacket::new, PacketDirection.ClientToServer);
}

private boolean scroll(double scroll) {
if (MinecraftClient.isReady() && targetInteractable != null) {
if (targetInteractable instanceof Control) {
float value = targetStock.getControlPosition((Control<?>) targetInteractable);
// Same as GuiBuilder
value += scroll / -50 * ConfigGraphics.ScrollSpeed;
targetStock.setControlPosition((Control<?>) targetInteractable, value);
targetStock.onDragRelease((Control<?>) targetInteractable);
new DragPacket(targetStock, (Control<?>) targetInteractable, true, value, true).sendToServer();
return false;
}
}
return true;
}

private boolean capture(Player.Hand hand) {
if (hand == Player.Hand.SECONDARY && MinecraftClient.isReady() && !MinecraftClient.getPlayer().isCrouching() && targetInteractable != null) {
if (targetInteractable instanceof Control) {
Expand Down Expand Up @@ -78,6 +95,13 @@ protected void handle() {
if (!stock.playerCanDrag(getPlayer(), control)) {
return;
}
if (start && released) {
stock.onDragStart(control);
stock.onDrag(control, newValue);
stock.onDragRelease(control);
return;
}

if (start) {
stock.onDragStart(control);
} else if (released) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ public ClickResult onClick(Player player, Player.Hand hand) {
}

public void setTexture(String variant) {
this.texture = variant;
if (getDefinition().textureNames.containsKey(variant)) {
this.texture = variant;
}
}

@Override
Expand Down
30 changes: 27 additions & 3 deletions src/main/java/cam72cam/immersiverailroading/entity/Locomotive.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ public abstract class Locomotive extends FreightTank {
@TagField("HORN")
protected int hornTime = 0;

public static final UUID AUTOMATED_PLAYER = new UUID(0, 0);
@TagSync
@TagField(value = "HORN_PLAYER", mapper = StrictTagMapper.class)
protected UUID hornPlayer = null;
@TagSync
@TagField(value = "HORN_PULL")
public float hornPull;

@TagSync
@TagField("BELL")
Expand Down Expand Up @@ -327,6 +329,7 @@ public void onTick() {
if (getWorld().isServer) {
sync.setInterval(5);
for (Control<?> control : getDefinition().getModel().getControls()) {
// Logic duplicated in Readouts#setValue
if (!getDefinition().isLinearBrakeControl() && control.part.type == ModelComponentType.TRAIN_BRAKE_X) {
setTrainBrake(Math.max(0, Math.min(1, getTrainBrake() + (getControlPosition(control) - 0.5f) / 8)));
}
Expand All @@ -351,6 +354,9 @@ public void onTick() {
} else if (hornPlayer != null) {
hornPlayer = null;
}
if (hornTime == 0) {
hornPull = 0;
}
OptionalDouble control = this.getDefinition().getModel().getControls().stream()
.filter(x -> x.part.type == ModelComponentType.BELL_CONTROL_X)
.mapToDouble(this::getControlPosition)
Expand Down Expand Up @@ -514,6 +520,11 @@ private void setRealReverser(float newReverser){
}

public void setHorn(int val, UUID uuid) {
if (uuid == null) {
// Legacy API
hornPull = 1;
}

if (hornPlayer == null && uuid != null) {
hornPlayer = uuid;
}
Expand All @@ -522,6 +533,11 @@ public void setHorn(int val, UUID uuid) {
}
}

public void setHorn(int time, float value) {
hornTime = time;
hornPull = value;
}

public int getHornTime() {
return hornTime;
}
Expand All @@ -535,8 +551,16 @@ public Entity getHornPlayer() {
return null;
}

public boolean isAutomatedHorn() {
return AUTOMATED_PLAYER.equals(hornPlayer);
public float getHornPull() {
if (getHornPlayer() != null) {
return (getHornPlayer().getRotationPitch() + 90) / 180;
}
double control = this.getDefinition().getModel().getControls().stream()
.filter(x -> x.part.type == ModelComponentType.WHISTLE_CONTROL_X)
.mapToDouble(this::getControlPosition)
.max().orElse(0);

return Math.max((float)control, hornPull);
}

@Deprecated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public double getAppliedTractiveEffort(Speed speed) {

// Cap the max "effective" reverser. At high speeds having a fully open reverser just damages equipment
double reverser = getReverser();
double reverserCap = 0.5;
double reverserCap = 0.25;
double maxReverser = 1 - Math.abs(getCurrentSpeed().metric()) / getDefinition().getMaxSpeed(gauge).metric() * reverserCap;

// This should probably be tuned...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public boolean equals(Object o) {
couplerEngagedRear == other.couplerEngagedRear &&
Math.abs(tractiveEffortFactors - other.tractiveEffortFactors) < 0.01 &&
Math.abs(massKg - other.massKg)/massKg < 0.01 &&
(desiredBrakePressure == null || Math.abs(desiredBrakePressure - other.desiredBrakePressure) < 0.1) &&
(desiredBrakePressure == null || Math.abs(desiredBrakePressure - other.desiredBrakePressure) < 0.001) &&
Math.abs(independentBrakePosition - other.independentBrakePosition) < 0.01;
}
return false;
Expand Down
15 changes: 7 additions & 8 deletions src/main/java/cam72cam/immersiverailroading/gui/TrackGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
import cam72cam.immersiverailroading.net.ItemRailUpdatePacket;
import cam72cam.immersiverailroading.registry.DefinitionManager;
import cam72cam.immersiverailroading.registry.TrackDefinition;
import cam72cam.immersiverailroading.render.rail.RailBaseRender;
import cam72cam.immersiverailroading.render.rail.RailBuilderRender;
import cam72cam.immersiverailroading.render.rail.RailRender;
import cam72cam.immersiverailroading.tile.TileRailPreview;
import cam72cam.immersiverailroading.track.BuilderTurnTable;
import cam72cam.immersiverailroading.track.TrackBase;
Expand Down Expand Up @@ -358,9 +357,9 @@ public void draw(IScreenBuilder builder, RenderState state) {
state.rotate(90, 1, 0, 0);
state.scale(-scale, scale, scale);
state.translate(0, 0, 1);
RailBuilderRender.renderRailBuilder(info, MinecraftClient.getPlayer().getWorld(), state);
RailRender.get(info).renderRailModel(state);
state.translate(-0.5, 0, -0.5);
RailBaseRender.draw(info, MinecraftClient.getPlayer().getWorld(), state);
RailRender.get(info).renderRailBase(state);
return;
}

Expand Down Expand Up @@ -404,9 +403,9 @@ public void draw(IScreenBuilder builder, RenderState state) {
state.rotate(frame/2.0, 0, 1, 0);
state.translate(0, 0, -1);

RailBuilderRender.renderRailBuilder(info, MinecraftClient.getPlayer().getWorld(), state);
RailRender.get(info).renderRailModel(state);
state.translate(-0.5, 0, -0.5);
RailBaseRender.draw(info, MinecraftClient.getPlayer().getWorld(), state);
RailRender.get(info).renderRailBase(state);

if (!info.settings.railBedFill.isEmpty()) {
StandardModel model = new StandardModel();
Expand Down Expand Up @@ -465,9 +464,9 @@ public void draw(IScreenBuilder builder, RenderState state) {
if (settings.type == TrackItems.CUSTOM) {
state.translate(-length / 2.0, 0, 0);
}
RailBuilderRender.renderRailBuilder(info, MinecraftClient.getPlayer().getWorld(), state);
RailRender.get(info).renderRailModel(state);
state.translate(-0.5, 0, -0.5);
RailBaseRender.draw(info, MinecraftClient.getPlayer().getWorld(), state);
RailRender.get(info).renderRailBase(state);
if (!info.settings.railBedFill.isEmpty()) {
StandardModel model = new StandardModel();
for (TrackBase base : info.getBuilder(MinecraftClient.getPlayer().getWorld()).getTracksForRender()) {
Expand Down
Loading

0 comments on commit bea12a3

Please sign in to comment.