Skip to content

Commit

Permalink
Implement option to select original vs advanced guis
Browse files Browse the repository at this point in the history
  • Loading branch information
cam72cam committed Oct 4, 2023
1 parent 4f10519 commit d73991a
Show file tree
Hide file tree
Showing 11 changed files with 734 additions and 358 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public class GuiBuilder {
private final Vertical screen_y;

private final Identifier image;
private final int imageWidth;
private final int imageHeight;
private final int width;
private final int height;

private final String text;
private final float textHeight;
Expand Down Expand Up @@ -130,17 +130,6 @@ protected GuiBuilder(DataBlock data) throws IOException {
this.screen_x = Horizontal.from(data.getValue("screen_x").asString());
this.screen_y = Vertical.from(data.getValue("screen_y").asString());

// Image stuff
this.image = data.getValue("image").asIdentifier(null);
if (image != null) {
BufferedImage tmp = ImageIO.read(this.image.getResourceStream());
imageWidth = tmp.getWidth();
imageHeight = tmp.getHeight();
} else {
imageWidth = 0;
imageHeight = 0;
}

// Text stuff
DataBlock txt = data.getBlock("text");
if (txt != null) {
Expand All @@ -151,6 +140,20 @@ protected GuiBuilder(DataBlock data) throws IOException {
textHeight = 0;
}

// Image stuff
this.image = data.getValue("image").asIdentifier(null);
if (image != null) {
BufferedImage tmp = ImageIO.read(this.image.getResourceStream());
width = tmp.getWidth();
height = tmp.getHeight();
} else if (text != null) {
width = (int) (textHeight/4 * text.length()); // Guesstimate
height = (int) textHeight;
} else {
width = 0;
height = 0;
}

// Controls
String readout = data.getValue("readout").asString();
this.readout = readout != null ? Readouts.valueOf(readout.toUpperCase(Locale.ROOT)) : null;
Expand Down Expand Up @@ -329,9 +332,9 @@ private void render(EntityRollingStock stock, RenderState state, int maxx, int m
if (image != null) {
DirectDraw draw = new DirectDraw();
draw.vertex(0, 0, 0).uv(0, 0);
draw.vertex(0, imageHeight, 0).uv(0, 1);
draw.vertex(imageWidth, imageHeight, 0).uv(1, 1);
draw.vertex(imageWidth, 0, 0).uv(1, 0);
draw.vertex(0, height, 0).uv(0, 1);
draw.vertex(width, height, 0).uv(1, 1);
draw.vertex(width, 0, 0).uv(1, 0);
draw.draw(state.clone()
.texture(Texture.wrap(image))
.alpha_test(false)
Expand Down Expand Up @@ -374,7 +377,7 @@ private GuiBuilder find(EntityRollingStock stock, Matrix4 matrix, int maxx, int
}
}

if (image != null && interactable()) {
if (interactable() && (image != null || text != null)) {
if (control == null && setting == null && texture_variant == null) {
if (readout == null) {
return null;
Expand All @@ -397,10 +400,10 @@ private GuiBuilder find(EntityRollingStock stock, Matrix4 matrix, int maxx, int
}
}
int border = 2;
Vec3d cornerA = matrix.apply(new Vec3d(-border, -border, 0));
Vec3d cornerB = matrix.apply(new Vec3d(-border, imageHeight + border, 0));
Vec3d cornerC = matrix.apply(new Vec3d(imageWidth + border, -border, 0));
Vec3d cornerD = matrix.apply(new Vec3d(imageWidth + border, imageHeight + border, 0));
Vec3d cornerA = matrix.apply(new Vec3d((image == null ? -width : 0)-border, -border, 0));
Vec3d cornerB = matrix.apply(new Vec3d((image == null ? -width : 0)-border, height + border, 0));
Vec3d cornerC = matrix.apply(new Vec3d(width + border, -border, 0));
Vec3d cornerD = matrix.apply(new Vec3d(width + border, height + border, 0));

Polygon poly = new Polygon(
new int[]{(int) cornerA.x, (int) cornerB.x, (int) cornerC.x, (int) cornerD.x},
Expand Down Expand Up @@ -455,7 +458,7 @@ private void onMouseMove(EntityRollingStock stock, Matrix4 matrix, GuiBuilder ta
temp.scale(scalex != null ? scalex * checkValue : 1, scaley != null ? scaley * checkValue : 1, 1);
}

Vec3d checkMiddle = temp.apply(new Vec3d(imageWidth/2f, imageHeight/2f, 0));
Vec3d checkMiddle = temp.apply(new Vec3d(width /2f, height /2f, 0));
double delta = checkMiddle.distanceTo(new Vec3d(x, y, 0));
if (delta < closestDelta) {
closestDelta = delta;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,80 +1,89 @@
element:
# left panel
x = 10
y = -95
image = "immersiverailroading:gui/overlay_handcar.png"
element:
# ind brake
x = 17
y = 74
image = "immersiverailroading:gui/indicator.png"
readout = "INDEPENDENT_BRAKE"
translate =
x = 0
y = -50
element:
# brake pressure
x = 11
y = 74
image = "immersiverailroading:gui/indicator.png"
readout = "BRAKE_PRESSURE"
translate =
x = 0
y = -50
color =
0.0 = "0xDDa22020"
element:
# train brake
x = 11
y = 74
image = "immersiverailroading:gui/indicator.png"
readout = "TRAIN_BRAKE"
translate =
x = 0
y = -50
element:
# throttle
x = 32
y = 74
image = "immersiverailroading:gui/indicator.png"
readout = "THROTTLE"
translate =
x = 0
y = -50
element:
# reverser
x = 38
y = 74
image = "immersiverailroading:gui/indicator.png"
readout = "REVERSER"
translate =
x = 0
y = -50
element:
# speed readout
text =
value = "stat.speed"
height = 6
x = 30
y = 8
element:
# top labels
y = 19
element:
x = 20
text =
value = "label.brake"
height = 4
element:
x = 38
text =
value = "label.throttle"
height = 4
import: "immersiverailroading:gui/default/common/settings.caml"

element:
import: "immersiverailroading:gui/default/common/opacity.caml"
element:
# bottom labels
y = 78
import: "immersiverailroading:gui/default/common/scale.caml"
screen_x = LEFT
screen_y = BOTTOM
element:
x = 38
text =
value = "label.reverser"
height = 4
# left panel
x = 10
y = -95
image = "immersiverailroading:gui/overlay_handcar.png"
element:
# ind brake
x = 17
y = 74
image = "immersiverailroading:gui/indicator.png"
readout = "INDEPENDENT_BRAKE"
translate =
x = 0
y = -50
element:
# brake pressure
x = 11
y = 74
image = "immersiverailroading:gui/indicator.png"
readout = "BRAKE_PRESSURE"
translate =
x = 0
y = -50
color =
0.0 = "0xDDa22020"
element:
# train brake
x = 11
y = 74
image = "immersiverailroading:gui/indicator.png"
readout = "TRAIN_BRAKE"
translate =
x = 0
y = -50
element:
# throttle
x = 32
y = 74
image = "immersiverailroading:gui/indicator.png"
readout = "THROTTLE"
translate =
x = 0
y = -50
element:
# reverser
x = 38
y = 74
image = "immersiverailroading:gui/indicator.png"
readout = "REVERSER"
translate =
x = 0
y = -50
element:
# speed readout
text =
value = "stat.speed"
height = 6
x = 30
y = 8
element:
# top labels
y = 19
element:
x = 20
text =
value = "label.brake"
height = 4
element:
x = 38
text =
value = "label.throttle"
height = 4
element:
# bottom labels
y = 78
element:
x = 38
text =
value = "label.reverser"
height = 4
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,28 @@ element:

translate =
x = 200

element:
x = 25
y = 90

element:
text =
value = "Original GUI"
height = 6
setting = "legacy_gui"
toggle = true
color =
0.0 = "0xFFFFFFFF"
1.0 = "0xFF999999"
element:
x = 50
setting = "legacy_gui"
text =
value = "Advanced GUI"
height = 6
toggle = true
invert = true
color =
0.0 = "0xFFFFFFFF"
1.0 = "0xFF999999"
Loading

0 comments on commit d73991a

Please sign in to comment.