Skip to content

Commit

Permalink
Merge branch 'gui-rewrite' into nordale
Browse files Browse the repository at this point in the history
  • Loading branch information
cam72cam committed Oct 9, 2023
2 parents 79d2673 + e49acbb commit dbed691
Show file tree
Hide file tree
Showing 14 changed files with 788 additions and 361 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/branch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Immersive Railroading Build Pipeline

on:
push:
branches-ignore:
- 'master'

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
branch: [1.12.2-forge, 1.16.5-forge]
steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: keyscan
run: mkdir -p ~/.ssh/ && ssh-keyscan -t rsa teamopenindustry.cc >> ~/.ssh/known_hosts
- name: Install deps
run: sudo apt install -y pngquant findutils xvfb
- name: Setup Universal Mod Core (and helpers)
env:
BRANCH: ${{ matrix.branch }}
run: java -jar UMCSetup.jar ${BRANCH} https
- name: Gradle compile
run: ./gradlew classes
- name: Process images
run: find src/main/resources/assets/immersiverailroading/ | grep png | xargs -I foo pngquant -s1 -f --ext .png foo
- name: Run Data (optionalish)
run: xvfb-run --auto-servernum ./gradlew runData || xvfb-run --auto-servernum ./gradlew runData || true
- name: Gradle build
run: ./gradlew build
- name: Gradle publish
env:
MAVENCI_PASS: ${{ secrets.MAVENCI_PASS }}
run: ./gradlew publish
- uses: actions/upload-artifact@v2
with:
name: Immersive Railroading ${{matrix.branch}}
path: build/libs/ImmersiveRailroading-${{matrix.branch}}-*
5 changes: 4 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: Immersive Railroading Build Pipeline

on: [push]
on:
push:
branches:
- 'master'

jobs:
build:
Expand Down
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
Expand Up @@ -111,8 +111,13 @@ public double getRollDegrees() {
}

public void removed() {
clackFront.stop();
clackRear.stop();
// These should never be null, but for some reason they are
if (clackFront != null) {
clackFront.stop();
}
if (clackRear != null) {
clackRear.stop();
}
}
}

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 dbed691

Please sign in to comment.