Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/gui-rewrite' into integration
Browse files Browse the repository at this point in the history
  • Loading branch information
cam72cam committed Sep 12, 2023
2 parents b193d6e + e7ef714 commit 565900b
Show file tree
Hide file tree
Showing 78 changed files with 1,374 additions and 900 deletions.
21 changes: 15 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,7 @@ 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<>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ public void postRender(EntityMoveableRollingStock entity, RenderState state, flo
return true;
});

ClientEvents.TICK.subscribe(GuiBuilder::onClientTick);

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

ClientPartDragging.register();
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 @@ -325,6 +327,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 @@ -349,6 +352,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 @@ -504,6 +510,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 @@ -512,6 +523,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 @@ -525,8 +541,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 @@ -102,7 +102,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 @@ -162,7 +162,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
Loading

0 comments on commit 565900b

Please sign in to comment.