From bceecad992d90bd8bd7339255c70c33c88204a08 Mon Sep 17 00:00:00 2001 From: StavWasPlayZ Date: Tue, 29 Aug 2023 19:15:28 +0300 Subject: [PATCH 1/2] Add QWERTY layout for drum --- .../genshinstrument/client/ClientUtil.java | 21 +++++++ .../config/enumType/label/DrumNoteLabel.java | 17 ++++-- .../config/enumType/label/NoteGridLabel.java | 61 +++---------------- .../AratakisGreatAndGloriousDrumScreen.java | 10 +-- .../instrument/drum/DrumNoteButton.java | 5 ++ .../partial/note/label/INoteLabel.java | 41 ++++++++++++- .../partial/notegrid/NoteGridButton.java | 7 +++ .../GridInstrumentOptionsScreen.java | 2 +- .../client/keyMaps/InstrumentKeyMappings.java | 4 ++ 9 files changed, 104 insertions(+), 64 deletions(-) diff --git a/src/main/java/com/cstav/genshinstrument/client/ClientUtil.java b/src/main/java/com/cstav/genshinstrument/client/ClientUtil.java index 1e4ac01..2d8b084 100644 --- a/src/main/java/com/cstav/genshinstrument/client/ClientUtil.java +++ b/src/main/java/com/cstav/genshinstrument/client/ClientUtil.java @@ -3,6 +3,8 @@ import java.awt.Color; import java.awt.Point; +import com.cstav.genshinstrument.client.keyMaps.InstrumentKeyMappings; +import com.mojang.blaze3d.platform.InputConstants.Key; import com.mojang.blaze3d.systems.RenderSystem; import net.fabricmc.api.EnvType; @@ -14,6 +16,25 @@ @Environment(EnvType.CLIENT) public class ClientUtil { public static final int GRID_HORZ_PADDING = 4, GRID_VERT_PADDING = 2; + + + private static Boolean onQwerty; + public static boolean isOnQwerty() { + if (onQwerty != null) + return onQwerty; + + + final String qwerty = "QWERTY"; + final Key[] keyRow = InstrumentKeyMappings.GRID_INSTRUMENT_MAPPINGS[0]; + + // Assuming there will be more than 6 entries here + for (int i = 0; i < qwerty.length(); i++) { + if (qwerty.charAt(i) != keyRow[i].getDisplayName().getString(1).charAt(0)) + return onQwerty = false; + } + + return onQwerty = true; + } /** diff --git a/src/main/java/com/cstav/genshinstrument/client/config/enumType/label/DrumNoteLabel.java b/src/main/java/com/cstav/genshinstrument/client/config/enumType/label/DrumNoteLabel.java index c8d630f..5334ced 100644 --- a/src/main/java/com/cstav/genshinstrument/client/config/enumType/label/DrumNoteLabel.java +++ b/src/main/java/com/cstav/genshinstrument/client/config/enumType/label/DrumNoteLabel.java @@ -4,7 +4,6 @@ import com.cstav.genshinstrument.client.gui.screen.instrument.partial.note.NoteButton; import com.cstav.genshinstrument.client.gui.screen.instrument.partial.note.label.INoteLabel; import com.cstav.genshinstrument.client.gui.screen.instrument.partial.note.label.NoteLabelSupplier; -import com.cstav.genshinstrument.client.keyMaps.InstrumentKeyMappings.DrumKeys; import com.cstav.genshinstrument.util.LabelUtil; import net.fabricmc.api.EnvType; @@ -13,12 +12,13 @@ @Environment(EnvType.CLIENT) public enum DrumNoteLabel implements INoteLabel { - KEYBOARD_LAYOUT((note) -> { - final DrumNoteButton dnb = dn(note); - final DrumKeys keys = dnb.btnType.getKeys(); + KEYBOARD_LAYOUT((note) -> + INoteLabel.upperComponent(dn(note).getKey().getDisplayName()) + ), + QWERTY((note) -> + INoteLabel.getQwerty(dn(note).getKey()) + ), - return INoteLabel.upperComponent((dnb.isRight ? keys.right : keys.left).getDisplayName()); - }), DON_KA((note) -> Component.translatable(dn(note).btnType.getTransKey()) ), @@ -36,6 +36,11 @@ private DrumNoteLabel(final NoteLabelSupplier supplier) { labelSupplier = supplier; } + public static INoteLabel[] availableVals() { + return INoteLabel.filterQwerty(values(), QWERTY); + } + + @Override public NoteLabelSupplier getLabelSupplier() { return labelSupplier; diff --git a/src/main/java/com/cstav/genshinstrument/client/config/enumType/label/NoteGridLabel.java b/src/main/java/com/cstav/genshinstrument/client/config/enumType/label/NoteGridLabel.java index 2d2befa..5aa654f 100644 --- a/src/main/java/com/cstav/genshinstrument/client/config/enumType/label/NoteGridLabel.java +++ b/src/main/java/com/cstav/genshinstrument/client/config/enumType/label/NoteGridLabel.java @@ -1,13 +1,10 @@ package com.cstav.genshinstrument.client.config.enumType.label; -import com.cstav.genshinstrument.client.config.ModClientConfigs; import com.cstav.genshinstrument.client.gui.screen.instrument.partial.note.NoteButton; import com.cstav.genshinstrument.client.gui.screen.instrument.partial.note.label.INoteLabel; import com.cstav.genshinstrument.client.gui.screen.instrument.partial.note.label.NoteLabelSupplier; import com.cstav.genshinstrument.client.gui.screen.instrument.partial.notegrid.NoteGridButton; -import com.cstav.genshinstrument.client.keyMaps.InstrumentKeyMappings; import com.cstav.genshinstrument.util.LabelUtil; -import com.mojang.blaze3d.platform.InputConstants.Key; import net.minecraft.network.chat.Component; @@ -18,12 +15,12 @@ */ public enum NoteGridLabel implements INoteLabel { KEYBOARD_LAYOUT((note) -> INoteLabel.upperComponent( - InstrumentKeyMappings.GRID_INSTRUMENT_MAPPINGS[ng(note).column][ng(note).row].getDisplayName() - )), - QWERTY((note) -> Component.translatable( - InstrumentKeyMappings.GRID_INSTRUMENT_MAPPINGS[ng(note).column][ng(note).row].getName() - .substring("key.keyboard.".length()).toUpperCase() + ng(note).getKey().getDisplayName() )), + QWERTY((note) -> + INoteLabel.getQwerty(ng(note).getKey()) + ), + NOTE_NAME((note) -> Component.literal( note.getCutNoteName() )), @@ -32,59 +29,21 @@ public enum NoteGridLabel implements INoteLabel { ), NONE(NoteLabelSupplier.EMPTY); + private final NoteLabelSupplier labelSupplier; private NoteGridLabel(final NoteLabelSupplier labelSupplier) { this.labelSupplier = labelSupplier; } + public static INoteLabel[] availableVals() { + return INoteLabel.filterQwerty(values(), QWERTY); + } + @Override public NoteLabelSupplier getLabelSupplier() { return labelSupplier; } - - - private static Boolean hasQwerty; - private static boolean hasQwerty() { - if (hasQwerty != null) - return hasQwerty; - - - final String qwerty = "QWERTY"; - final Key[] keyRow = InstrumentKeyMappings.GRID_INSTRUMENT_MAPPINGS[0]; - - // Assuming there will be more than 6 entries here - for (int i = 0; i < qwerty.length(); i++) { - if (qwerty.charAt(i) != keyRow[i].getDisplayName().getString(1).charAt(0)) - return hasQwerty = false; - } - - return hasQwerty = true; - } - - - public static NoteGridLabel[] availableVals() { - final NoteGridLabel[] vals = values(); - - // Ignore QWERTY if already using this layout - if (hasQwerty() && (ModClientConfigs.GRID_LABEL_TYPE.get() != QWERTY)) { - final NoteGridLabel[] result = new NoteGridLabel[vals.length - 1]; - - // 2nd index to not go out of bounds - int j = 0; - for (int i = 0; i < vals.length; i++) { - if (vals[i] == QWERTY) - i++; - - result[j] = vals[i]; - j++; - } - - return result; - } - - return vals; - } private static NoteGridButton ng(final NoteButton btn) { diff --git a/src/main/java/com/cstav/genshinstrument/client/gui/screen/instrument/drum/AratakisGreatAndGloriousDrumScreen.java b/src/main/java/com/cstav/genshinstrument/client/gui/screen/instrument/drum/AratakisGreatAndGloriousDrumScreen.java index 6d674b6..99c9372 100644 --- a/src/main/java/com/cstav/genshinstrument/client/gui/screen/instrument/drum/AratakisGreatAndGloriousDrumScreen.java +++ b/src/main/java/com/cstav/genshinstrument/client/gui/screen/instrument/drum/AratakisGreatAndGloriousDrumScreen.java @@ -87,16 +87,16 @@ private LinearLayout createRow(DrumButtonType type, float widthPercent) { Orientation.HORIZONTAL ); - createButton(type, layout, type.getKeys().left, false); - createButton(type, layout, type.getKeys().right, true); + createButton(type, layout, false); + createButton(type, layout, true); return layout; } - private NoteButton createButton(DrumButtonType btnType, LinearLayout container, Key key, boolean isRight) { - final NoteButton btn = new DrumNoteButton(btnType, isRight, this); + private DrumNoteButton createButton(DrumButtonType btnType, LinearLayout container, boolean isRight) { + final DrumNoteButton btn = new DrumNoteButton(btnType, isRight, this); container.addChild(btn); - notes.put(key, btn); + notes.put(btn.getKey(), btn); return btn; } diff --git a/src/main/java/com/cstav/genshinstrument/client/gui/screen/instrument/drum/DrumNoteButton.java b/src/main/java/com/cstav/genshinstrument/client/gui/screen/instrument/drum/DrumNoteButton.java index 1488a07..e55ea98 100644 --- a/src/main/java/com/cstav/genshinstrument/client/gui/screen/instrument/drum/DrumNoteButton.java +++ b/src/main/java/com/cstav/genshinstrument/client/gui/screen/instrument/drum/DrumNoteButton.java @@ -4,6 +4,7 @@ import com.cstav.genshinstrument.client.gui.screen.instrument.partial.note.NoteButton; import com.cstav.genshinstrument.client.gui.screen.instrument.partial.note.NoteButtonRenderer; import com.cstav.genshinstrument.networking.buttonidentifier.DrumNoteIdentifier; +import com.mojang.blaze3d.platform.InputConstants.Key; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @@ -31,6 +32,10 @@ public DrumNoteIdentifier getIdentifier() { return new DrumNoteIdentifier(this); } + public Key getKey() { + return btnType.getKeys().getKey(isRight); + } + @Override protected NoteButtonRenderer initNoteRenderer() { diff --git a/src/main/java/com/cstav/genshinstrument/client/gui/screen/instrument/partial/note/label/INoteLabel.java b/src/main/java/com/cstav/genshinstrument/client/gui/screen/instrument/partial/note/label/INoteLabel.java index 0689139..9a1de26 100644 --- a/src/main/java/com/cstav/genshinstrument/client/gui/screen/instrument/partial/note/label/INoteLabel.java +++ b/src/main/java/com/cstav/genshinstrument/client/gui/screen/instrument/partial/note/label/INoteLabel.java @@ -1,6 +1,10 @@ package com.cstav.genshinstrument.client.gui.screen.instrument.partial.note.label; +import com.cstav.genshinstrument.client.ClientUtil; +import com.cstav.genshinstrument.client.config.ModClientConfigs; +import com.mojang.blaze3d.platform.InputConstants.Key; + import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; @@ -16,8 +20,43 @@ public static MutableComponent upperComponent(final Component component) { return Component.literal(component.getString().toUpperCase()); } + + public static MutableComponent getQwerty(final Key key) { + final String keyName = key.getName(); + return Component.literal( + // The QWERTY key is the last letter of the key name + String.valueOf(keyName.charAt(keyName.length() - 1)).toUpperCase() + ); + } + + /** + * @return All the values of this note label type, filtering QWERTY if already using it. + */ + public static INoteLabel[] filterQwerty(final INoteLabel[] values, final INoteLabel qwerty) { + // Ignore QWERTY if already using this layout + // Or if the user already selected it + if (!ClientUtil.isOnQwerty() || (ModClientConfigs.GRID_LABEL_TYPE.get() == qwerty)) + return values; + + + final INoteLabel[] result = new INoteLabel[values.length - 1]; + + // 2nd index to not go out of bounds + int j = 0; + for (int i = 0; i < values.length; i++) { + if (values[i] == qwerty) + i++; + + result[j] = values[i]; + j++; + } + + return result; + } + + - public NoteLabelSupplier getLabelSupplier(); + public abstract NoteLabelSupplier getLabelSupplier(); /** * @return The translation key of this label */ diff --git a/src/main/java/com/cstav/genshinstrument/client/gui/screen/instrument/partial/notegrid/NoteGridButton.java b/src/main/java/com/cstav/genshinstrument/client/gui/screen/instrument/partial/notegrid/NoteGridButton.java index 477fd6d..84e1364 100644 --- a/src/main/java/com/cstav/genshinstrument/client/gui/screen/instrument/partial/notegrid/NoteGridButton.java +++ b/src/main/java/com/cstav/genshinstrument/client/gui/screen/instrument/partial/notegrid/NoteGridButton.java @@ -3,9 +3,11 @@ import com.cstav.genshinstrument.client.config.ModClientConfigs; import com.cstav.genshinstrument.client.gui.screen.instrument.partial.note.NoteButton; import com.cstav.genshinstrument.client.gui.screen.instrument.partial.note.NoteButtonRenderer; +import com.cstav.genshinstrument.client.keyMaps.InstrumentKeyMappings; import com.cstav.genshinstrument.networking.buttonidentifier.NoteGridButtonIdentifier; import com.cstav.genshinstrument.sound.NoteSound; import com.cstav.genshinstrument.util.LabelUtil; +import com.mojang.blaze3d.platform.InputConstants.Key; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @@ -55,6 +57,11 @@ public static NoteSound getSoundFromArr(AbstractGridInstrumentScreen gridInstrum } + public Key getKey() { + return InstrumentKeyMappings.GRID_INSTRUMENT_MAPPINGS[column][row]; + } + + @Override public NoteGridButtonIdentifier getIdentifier() { return new NoteGridButtonIdentifier(this); diff --git a/src/main/java/com/cstav/genshinstrument/client/gui/screen/options/instrument/GridInstrumentOptionsScreen.java b/src/main/java/com/cstav/genshinstrument/client/gui/screen/options/instrument/GridInstrumentOptionsScreen.java index f17f34d..3baef11 100644 --- a/src/main/java/com/cstav/genshinstrument/client/gui/screen/options/instrument/GridInstrumentOptionsScreen.java +++ b/src/main/java/com/cstav/genshinstrument/client/gui/screen/options/instrument/GridInstrumentOptionsScreen.java @@ -27,7 +27,7 @@ public GridInstrumentOptionsScreen(final Screen lastScreen) { @Override - public NoteGridLabel[] getLabels() { + public INoteLabel[] getLabels() { return NoteGridLabel.availableVals(); } @Override diff --git a/src/main/java/com/cstav/genshinstrument/client/keyMaps/InstrumentKeyMappings.java b/src/main/java/com/cstav/genshinstrument/client/keyMaps/InstrumentKeyMappings.java index 00927ff..2391636 100644 --- a/src/main/java/com/cstav/genshinstrument/client/keyMaps/InstrumentKeyMappings.java +++ b/src/main/java/com/cstav/genshinstrument/client/keyMaps/InstrumentKeyMappings.java @@ -57,6 +57,10 @@ private DrumKeys(final int left, final int right) { this.left = create(left); this.right = create(right); } + + public Key getKey(final boolean isRight) { + return isRight ? right : left; + } } From 80809a2fe05df7b173aafc0f54a08188f19a1e70 Mon Sep 17 00:00:00 2001 From: StavWasPlayZ Date: Tue, 29 Aug 2023 19:35:07 +0300 Subject: [PATCH 2/2] Fix drum QWERTY (generalize filterQwerty method) --- .../client/config/enumType/label/DrumNoteLabel.java | 3 ++- .../client/config/enumType/label/NoteGridLabel.java | 3 ++- .../screen/instrument/partial/note/label/INoteLabel.java | 7 +++---- .../gui/screen/options/instrument/DrumOptionsScren.java | 4 ++-- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/cstav/genshinstrument/client/config/enumType/label/DrumNoteLabel.java b/src/main/java/com/cstav/genshinstrument/client/config/enumType/label/DrumNoteLabel.java index 5334ced..72b78f5 100644 --- a/src/main/java/com/cstav/genshinstrument/client/config/enumType/label/DrumNoteLabel.java +++ b/src/main/java/com/cstav/genshinstrument/client/config/enumType/label/DrumNoteLabel.java @@ -1,5 +1,6 @@ package com.cstav.genshinstrument.client.config.enumType.label; +import com.cstav.genshinstrument.client.config.ModClientConfigs; import com.cstav.genshinstrument.client.gui.screen.instrument.drum.DrumNoteButton; import com.cstav.genshinstrument.client.gui.screen.instrument.partial.note.NoteButton; import com.cstav.genshinstrument.client.gui.screen.instrument.partial.note.label.INoteLabel; @@ -37,7 +38,7 @@ private DrumNoteLabel(final NoteLabelSupplier supplier) { } public static INoteLabel[] availableVals() { - return INoteLabel.filterQwerty(values(), QWERTY); + return INoteLabel.filterQwerty(values(), ModClientConfigs.DRUM_LABEL_TYPE.get(), QWERTY); } diff --git a/src/main/java/com/cstav/genshinstrument/client/config/enumType/label/NoteGridLabel.java b/src/main/java/com/cstav/genshinstrument/client/config/enumType/label/NoteGridLabel.java index 5aa654f..015f494 100644 --- a/src/main/java/com/cstav/genshinstrument/client/config/enumType/label/NoteGridLabel.java +++ b/src/main/java/com/cstav/genshinstrument/client/config/enumType/label/NoteGridLabel.java @@ -1,5 +1,6 @@ package com.cstav.genshinstrument.client.config.enumType.label; +import com.cstav.genshinstrument.client.config.ModClientConfigs; import com.cstav.genshinstrument.client.gui.screen.instrument.partial.note.NoteButton; import com.cstav.genshinstrument.client.gui.screen.instrument.partial.note.label.INoteLabel; import com.cstav.genshinstrument.client.gui.screen.instrument.partial.note.label.NoteLabelSupplier; @@ -36,7 +37,7 @@ private NoteGridLabel(final NoteLabelSupplier labelSupplier) { } public static INoteLabel[] availableVals() { - return INoteLabel.filterQwerty(values(), QWERTY); + return INoteLabel.filterQwerty(values(), ModClientConfigs.GRID_LABEL_TYPE.get(), QWERTY); } diff --git a/src/main/java/com/cstav/genshinstrument/client/gui/screen/instrument/partial/note/label/INoteLabel.java b/src/main/java/com/cstav/genshinstrument/client/gui/screen/instrument/partial/note/label/INoteLabel.java index 9a1de26..6218c6b 100644 --- a/src/main/java/com/cstav/genshinstrument/client/gui/screen/instrument/partial/note/label/INoteLabel.java +++ b/src/main/java/com/cstav/genshinstrument/client/gui/screen/instrument/partial/note/label/INoteLabel.java @@ -2,7 +2,6 @@ import com.cstav.genshinstrument.client.ClientUtil; -import com.cstav.genshinstrument.client.config.ModClientConfigs; import com.mojang.blaze3d.platform.InputConstants.Key; import net.minecraft.network.chat.Component; @@ -32,10 +31,10 @@ public static MutableComponent getQwerty(final Key key) { /** * @return All the values of this note label type, filtering QWERTY if already using it. */ - public static INoteLabel[] filterQwerty(final INoteLabel[] values, final INoteLabel qwerty) { + public static INoteLabel[] filterQwerty(INoteLabel[] values, INoteLabel currentLabel, INoteLabel qwerty) { // Ignore QWERTY if already using this layout // Or if the user already selected it - if (!ClientUtil.isOnQwerty() || (ModClientConfigs.GRID_LABEL_TYPE.get() == qwerty)) + if (!ClientUtil.isOnQwerty() || (currentLabel.equals(qwerty))) return values; @@ -44,7 +43,7 @@ public static INoteLabel[] filterQwerty(final INoteLabel[] values, final INoteLa // 2nd index to not go out of bounds int j = 0; for (int i = 0; i < values.length; i++) { - if (values[i] == qwerty) + if (values[i].equals(qwerty)) i++; result[j] = values[i]; diff --git a/src/main/java/com/cstav/genshinstrument/client/gui/screen/options/instrument/DrumOptionsScren.java b/src/main/java/com/cstav/genshinstrument/client/gui/screen/options/instrument/DrumOptionsScren.java index 4de8163..f33278a 100644 --- a/src/main/java/com/cstav/genshinstrument/client/gui/screen/options/instrument/DrumOptionsScren.java +++ b/src/main/java/com/cstav/genshinstrument/client/gui/screen/options/instrument/DrumOptionsScren.java @@ -25,8 +25,8 @@ protected void saveLabel(INoteLabel newLabel) { } @Override - public DrumNoteLabel[] getLabels() { - return DrumNoteLabel.values(); + public INoteLabel[] getLabels() { + return DrumNoteLabel.availableVals(); } @Override public DrumNoteLabel getCurrentLabel() {