diff options
author | Juuxel <6596629+Juuxel@users.noreply.github.com> | 2021-06-27 11:49:18 +0300 |
---|---|---|
committer | Juuxel <6596629+Juuxel@users.noreply.github.com> | 2021-06-27 11:49:18 +0300 |
commit | 18314110acf492a5355dd97a9c481a6d05f37fc6 (patch) | |
tree | eb0bd8dad91c0cbb2863059c98055100968c0b45 /src | |
parent | 9b16647ea9e11ff947efad58b23343d7a8208eb9 (diff) | |
download | LibGui-18314110acf492a5355dd97a9c481a6d05f37fc6.tar.gz LibGui-18314110acf492a5355dd97a9c481a6d05f37fc6.tar.bz2 LibGui-18314110acf492a5355dd97a9c481a6d05f37fc6.zip |
Clean up by using enhanced switch
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java | 76 | ||||
-rw-r--r-- | src/main/java/io/github/cottonmc/cotton/gui/widget/WBar.java | 15 |
2 files changed, 43 insertions, 48 deletions
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java b/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java index 30c3295..c1d17e0 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java @@ -350,23 +350,22 @@ public class ScreenDrawing { * @param color the text color */ public static void drawString(MatrixStack matrices, String s, HorizontalAlignment align, int x, int y, int width, int color) { - switch(align) { - case LEFT: { + switch (align) { + case LEFT -> { MinecraftClient.getInstance().textRenderer.draw(matrices, s, x, y, color); } - break; - case CENTER: { + + case CENTER -> { int wid = MinecraftClient.getInstance().textRenderer.getWidth(s); - int l = (width/2) - (wid/2); - MinecraftClient.getInstance().textRenderer.draw(matrices, s, x+l, y, color); + int l = (width / 2) - (wid / 2); + MinecraftClient.getInstance().textRenderer.draw(matrices, s, x + l, y, color); } - break; - case RIGHT: { + + case RIGHT -> { int wid = MinecraftClient.getInstance().textRenderer.getWidth(s); int l = width - wid; - MinecraftClient.getInstance().textRenderer.draw(matrices, s, x+l, y, color); + MinecraftClient.getInstance().textRenderer.draw(matrices, s, x + l, y, color); } - break; } } @@ -383,23 +382,22 @@ public class ScreenDrawing { * @since 1.9.0 */ public static void drawString(MatrixStack matrices, OrderedText text, HorizontalAlignment align, int x, int y, int width, int color) { - switch(align) { - case LEFT: { + switch (align) { + case LEFT -> { MinecraftClient.getInstance().textRenderer.draw(matrices, text, x, y, color); } - break; - case CENTER: { + + case CENTER -> { int wid = MinecraftClient.getInstance().textRenderer.getWidth(text); - int l = (width/2) - (wid/2); - MinecraftClient.getInstance().textRenderer.draw(matrices, text, x+l, y, color); + int l = (width / 2) - (wid / 2); + MinecraftClient.getInstance().textRenderer.draw(matrices, text, x + l, y, color); } - break; - case RIGHT: { + + case RIGHT -> { int wid = MinecraftClient.getInstance().textRenderer.getWidth(text); int l = width - wid; - MinecraftClient.getInstance().textRenderer.draw(matrices, text, x+l, y, color); + MinecraftClient.getInstance().textRenderer.draw(matrices, text, x + l, y, color); } - break; } } @@ -415,23 +413,22 @@ public class ScreenDrawing { * @param color the text color */ public static void drawStringWithShadow(MatrixStack matrices, String s, HorizontalAlignment align, int x, int y, int width, int color) { - switch(align) { - case LEFT: { + switch (align) { + case LEFT -> { MinecraftClient.getInstance().textRenderer.drawWithShadow(matrices, s, x, y, color); } - break; - case CENTER: { + + case CENTER -> { int wid = MinecraftClient.getInstance().textRenderer.getWidth(s); - int l = (width/2) - (wid/2); - MinecraftClient.getInstance().textRenderer.drawWithShadow(matrices, s, x+l, y, color); + int l = (width / 2) - (wid / 2); + MinecraftClient.getInstance().textRenderer.drawWithShadow(matrices, s, x + l, y, color); } - break; - case RIGHT: { + + case RIGHT -> { int wid = MinecraftClient.getInstance().textRenderer.getWidth(s); int l = width - wid; - MinecraftClient.getInstance().textRenderer.drawWithShadow(matrices, s, x+l, y, color); + MinecraftClient.getInstance().textRenderer.drawWithShadow(matrices, s, x + l, y, color); } - break; } } @@ -447,23 +444,22 @@ public class ScreenDrawing { * @param color the text color */ public static void drawStringWithShadow(MatrixStack matrices, OrderedText text, HorizontalAlignment align, int x, int y, int width, int color) { - switch(align) { - case LEFT: { + switch (align) { + case LEFT -> { MinecraftClient.getInstance().textRenderer.drawWithShadow(matrices, text, x, y, color); } - break; - case CENTER: { + + case CENTER -> { int wid = MinecraftClient.getInstance().textRenderer.getWidth(text); - int l = (width/2) - (wid/2); - MinecraftClient.getInstance().textRenderer.drawWithShadow(matrices, text, x+l, y, color); + int l = (width / 2) - (wid / 2); + MinecraftClient.getInstance().textRenderer.drawWithShadow(matrices, text, x + l, y, color); } - break; - case RIGHT: { + + case RIGHT -> { int wid = MinecraftClient.getInstance().textRenderer.getWidth(text); int l = width - wid; - MinecraftClient.getInstance().textRenderer.drawWithShadow(matrices, text, x+l, y, color); + MinecraftClient.getInstance().textRenderer.drawWithShadow(matrices, text, x + l, y, color); } - break; } } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WBar.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WBar.java index 13ff5e1..a35ead8 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WBar.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WBar.java @@ -159,7 +159,7 @@ public class WBar extends WWidget { if (barSize <= 0) return; switch (direction) { //anonymous blocks in this switch statement are to sandbox variables - case UP: { + case UP -> { int left = x; int top = y + getHeight(); top -= barSize; @@ -168,25 +168,25 @@ public class WBar extends WWidget { } else { ScreenDrawing.coloredRect(matrices, left, top, getWidth(), barSize, ScreenDrawing.colorAtOpacity(0xFFFFFF, 0.5f)); } - break; } - case RIGHT: { + + case RIGHT -> { if (bar != null) { ScreenDrawing.texturedRect(matrices, x, y, barSize, getHeight(), bar.image(), bar.u1(), bar.v1(), MathHelper.lerp(percent, bar.u1(), bar.u2()), bar.v2(), 0xFFFFFFFF); } else { ScreenDrawing.coloredRect(matrices, x, y, barSize, getHeight(), ScreenDrawing.colorAtOpacity(0xFFFFFF, 0.5f)); } - break; } - case DOWN: { + + case DOWN -> { if (bar != null) { ScreenDrawing.texturedRect(matrices, x, y, getWidth(), barSize, bar.image(), bar.u1(), bar.v1(), bar.u2(), MathHelper.lerp(percent, bar.v1(), bar.v2()), 0xFFFFFFFF); } else { ScreenDrawing.coloredRect(matrices, x, y, getWidth(), barSize, ScreenDrawing.colorAtOpacity(0xFFFFFF, 0.5f)); } - break; } - case LEFT: { + + case LEFT -> { int left = x + getWidth(); int top = y; left -= barSize; @@ -195,7 +195,6 @@ public class WBar extends WWidget { } else { ScreenDrawing.coloredRect(matrices, left, top, barSize, getHeight(), ScreenDrawing.colorAtOpacity(0xFFFFFF, 0.5f)); } - break; } } } |