diff --git a/common/src/main/java/eu/midnightdust/midnightcontrols/client/gui/virtualkeyboard/KeyInfo.java b/common/src/main/java/eu/midnightdust/midnightcontrols/client/gui/virtualkeyboard/KeyInfo.java deleted file mode 100644 index 513a5e4..0000000 --- a/common/src/main/java/eu/midnightdust/midnightcontrols/client/gui/virtualkeyboard/KeyInfo.java +++ /dev/null @@ -1,16 +0,0 @@ -package eu.midnightdust.midnightcontrols.client.gui.virtualkeyboard; - -public record KeyInfo(String keySymbol, String displayText, double widthFactor) { - // Convenience constructor for standard width keys - KeyInfo(String keySymbol, double widthFactor) { - this(keySymbol, keySymbol, widthFactor); - } - - KeyInfo(String keySymbol) { - this(keySymbol, 1.0); - } - - KeyInfo(String keySymbol, String displayText) { - this(keySymbol, displayText, 1.0); - } -} diff --git a/common/src/main/java/eu/midnightdust/midnightcontrols/client/gui/virtualkeyboard/KeyboardLayout.java b/common/src/main/java/eu/midnightdust/midnightcontrols/client/gui/virtualkeyboard/KeyboardLayout.java index ccaa4d3..69732a6 100644 --- a/common/src/main/java/eu/midnightdust/midnightcontrols/client/gui/virtualkeyboard/KeyboardLayout.java +++ b/common/src/main/java/eu/midnightdust/midnightcontrols/client/gui/virtualkeyboard/KeyboardLayout.java @@ -8,52 +8,52 @@ public class KeyboardLayout { public static KeyboardLayout QWERTY = new KeyboardLayout(createQwertyLetterLayout(), createSymbolLayout()); - private final List> letters; - private final List> symbols; + private final List> letters; + private final List> symbols; - private KeyboardLayout(List> letters, List> symbols) { + private KeyboardLayout(List> letters, List> symbols) { this.letters = letters; this.symbols = symbols; } - public List> getLetters() { + public List> getLetters() { return letters; } - public List> getSymbols() { + public List> getSymbols() { return symbols; } - private static List> createQwertyLetterLayout() { - List> letters = new ArrayList<>(); + private static List> createQwertyLetterLayout() { + List> letters = new ArrayList<>(); letters.add(Arrays.asList( - new KeyInfo("q"), new KeyInfo("w"), new KeyInfo("e"), new KeyInfo("r"), new KeyInfo("t"), - new KeyInfo("y"), new KeyInfo("u"), new KeyInfo("i"), new KeyInfo("o"), new KeyInfo("p") + "q", "w", "e", "r", "t", + "y", "u", "i", "o", "p" )); letters.add(Arrays.asList( - new KeyInfo("a"), new KeyInfo("s"), new KeyInfo("d"), new KeyInfo("f"), new KeyInfo("g"), - new KeyInfo("h"), new KeyInfo("j"), new KeyInfo("k"), new KeyInfo("l") + "a", "s", "d", "f", "g", + "h", "j", "k", "l" )); letters.add(Arrays.asList( - new KeyInfo("z"), new KeyInfo("x"), new KeyInfo("c"), new KeyInfo("v"), - new KeyInfo("b"), new KeyInfo("n"), new KeyInfo("m") + "z", "x", "c", "v", + "b", "n", "m" )); return letters; } - private static List> createSymbolLayout() { - List> symbols = new ArrayList<>(); + private static List> createSymbolLayout() { + List> symbols = new ArrayList<>(); symbols.add(Arrays.asList( - new KeyInfo("1"), new KeyInfo("2"), new KeyInfo("3"), new KeyInfo("4"), new KeyInfo("5"), - new KeyInfo("6"), new KeyInfo("7"), new KeyInfo("8"), new KeyInfo("9"), new KeyInfo("0") + "1", "2", "3", "4", "5", + "6", "7", "8", "9", "0" )); symbols.add(Arrays.asList( - new KeyInfo("@"), new KeyInfo("#"), new KeyInfo("$"), new KeyInfo("%"), new KeyInfo("&"), - new KeyInfo("*"), new KeyInfo("-"), new KeyInfo("+"), new KeyInfo("("), new KeyInfo(")") + "@", "#", "$", "%", "&", + "*", "-", "+", "(", ")" )); symbols.add(Arrays.asList( - new KeyInfo("!"), new KeyInfo("\""), new KeyInfo("'"), new KeyInfo(":"), new KeyInfo(";"), - new KeyInfo(","), new KeyInfo("."), new KeyInfo("?"), new KeyInfo("/") + "!", "\"", "'", ":", ";", + ",", ".", "?", "/" )); return symbols; } diff --git a/common/src/main/java/eu/midnightdust/midnightcontrols/client/gui/virtualkeyboard/VirtualKeyboardScreen.java b/common/src/main/java/eu/midnightdust/midnightcontrols/client/gui/virtualkeyboard/VirtualKeyboardScreen.java index 00d5557..9b1d036 100644 --- a/common/src/main/java/eu/midnightdust/midnightcontrols/client/gui/virtualkeyboard/VirtualKeyboardScreen.java +++ b/common/src/main/java/eu/midnightdust/midnightcontrols/client/gui/virtualkeyboard/VirtualKeyboardScreen.java @@ -74,7 +74,6 @@ public class VirtualKeyboardScreen extends SpruceScreen { @Override public void render(DrawContext drawContext, int mouseX, int mouseY, float delta) { this.renderBackground(drawContext, mouseX, mouseY, delta); - drawContext.drawCenteredTextWithShadow(this.textRenderer, this.title, this.width / 2, 15, 0xFFFFFF); super.render(drawContext, mouseX, mouseY, delta); } @@ -96,10 +95,10 @@ public class VirtualKeyboardScreen extends SpruceScreen { this.remove(this.keyboardContainer); } - var keys = getActiveKeyLayout(); - var keyboardContainer = createKeyboardContainer(keys); + var layoutKeys = getActiveKeyLayout(); + var keyboardContainer = createKeyboardContainer(layoutKeys); - addLetterRows(keyboardContainer, keys); + addLayoutRows(keyboardContainer, layoutKeys); addFunctionKeys(keyboardContainer); addBottomRow(keyboardContainer); @@ -107,7 +106,7 @@ public class VirtualKeyboardScreen extends SpruceScreen { this.addDrawableChild(this.keyboardContainer); } - private SpruceContainerWidget createKeyboardContainer(List> layoutKeys) { + private SpruceContainerWidget createKeyboardContainer(List> layoutKeys) { int containerWidth = this.width; int totalKeyboardHeight = calculateKeyboardHeight(layoutKeys); int keyboardY = this.bufferDisplayArea.getY() + this.bufferDisplayArea.getHeight() + VERTICAL_SPACING * 2; @@ -141,44 +140,42 @@ public class VirtualKeyboardScreen extends SpruceScreen { return bufferDisplay; } - private int calculateKeyboardHeight(List> keyRows) { + private int calculateKeyboardHeight(List> keyRows) { return keyRows.size() * (KEY_HEIGHT + VERTICAL_SPACING) + (KEY_HEIGHT + VERTICAL_SPACING) + // space for bottom row CONTAINER_PADDING * 2; // top and bottom padding } - private void addLetterRows(SpruceContainerWidget container, List> keyRows) { + private void addLayoutRows(SpruceContainerWidget container, List> keyLayoutRows) { int currentY = CONTAINER_PADDING; - for (List row : keyRows) { + for (List row : keyLayoutRows) { int rowWidth = calculateRowWidth(row); // center row int currentX = (container.getWidth() - rowWidth) / 2; - for (KeyInfo keyInfo : row) { - int keyWidth = (int) (STANDARD_KEY_WIDTH * keyInfo.widthFactor()); - String displayText = getKeyDisplayText(keyInfo); + for (String key : row) { + String displayText = (this.capsMode && !this.symbolMode) ? key.toUpperCase() : key; container.addChild( new SpruceButtonWidget( Position.of(currentX, currentY), - keyWidth, + STANDARD_KEY_WIDTH, KEY_HEIGHT, Text.literal(displayText), btn -> handleKeyPress(displayText) ) ); - currentX += keyWidth + HORIZONTAL_SPACING; + currentX += STANDARD_KEY_WIDTH + HORIZONTAL_SPACING; } currentY += KEY_HEIGHT + VERTICAL_SPACING; } } - private int calculateRowWidth(List row) { + private int calculateRowWidth(List row) { int rowWidth = 0; for (int i = 0; i < row.size(); i++) { - rowWidth += (int) (STANDARD_KEY_WIDTH * row.get(i).widthFactor()); if (i < row.size() - 1) { rowWidth += HORIZONTAL_SPACING; } @@ -187,7 +184,7 @@ public class VirtualKeyboardScreen extends SpruceScreen { } private void addFunctionKeys(SpruceContainerWidget container) { - List firstRow = getActiveKeyLayout().get(0); + List firstRow = getActiveKeyLayout().get(0); int firstRowWidth = calculateRowWidth(firstRow); // position backspace at the right of the first row @@ -207,7 +204,7 @@ public class VirtualKeyboardScreen extends SpruceScreen { if (this.newLineSupport) { // position newline at the right of the second row - List secondRow = getActiveKeyLayout().get(1); + List secondRow = getActiveKeyLayout().get(1); int newlineWidth = (int) (STANDARD_KEY_WIDTH * 1.5); int secondRowWidth = calculateRowWidth(secondRow); int newlineX = (container.getWidth() + secondRowWidth) / 2 + HORIZONTAL_SPACING; @@ -284,15 +281,7 @@ public class VirtualKeyboardScreen extends SpruceScreen { } } - private String getKeyDisplayText(KeyInfo keyInfo) { - if(this.capsMode && !this.symbolMode) { - return keyInfo.displayText().toUpperCase(); - } - - return keyInfo.displayText(); - } - - private List> getActiveKeyLayout() { + private List> getActiveKeyLayout() { return this.symbolMode ? this.layout.getSymbols() : this.layout.getLetters(); }