diff --git a/src/main/java/com/cstav/genshinstrument/client/ClientUtil.java b/src/main/java/com/cstav/genshinstrument/client/ClientUtil.java index bb0c019..525fa3f 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; @@ -16,6 +18,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..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,10 +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.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; 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 +13,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 +37,11 @@ private DrumNoteLabel(final NoteLabelSupplier supplier) { labelSupplier = supplier; } + public static INoteLabel[] availableVals() { + return INoteLabel.filterQwerty(values(), ModClientConfigs.DRUM_LABEL_TYPE.get(), 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..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 @@ -5,9 +5,7 @@ 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 +16,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 +30,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(), ModClientConfigs.GRID_LABEL_TYPE.get(), 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..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 @@ -1,6 +1,9 @@ package com.cstav.genshinstrument.client.gui.screen.instrument.partial.note.label; +import com.cstav.genshinstrument.client.ClientUtil; +import com.mojang.blaze3d.platform.InputConstants.Key; + import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; @@ -16,8 +19,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(INoteLabel[] values, INoteLabel currentLabel, INoteLabel qwerty) { + // Ignore QWERTY if already using this layout + // Or if the user already selected it + if (!ClientUtil.isOnQwerty() || (currentLabel.equals(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].equals(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/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() { 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; + } }