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 08d45236..1d409059 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,7 @@ import com.cstav.genshinstrument.client.gui.screens.instrument.partial.note.NoteButton; import com.cstav.genshinstrument.client.gui.screens.instrument.partial.note.label.INoteLabel; import com.cstav.genshinstrument.client.gui.screens.instrument.partial.note.label.NoteLabelSupplier; -import com.cstav.genshinstrument.client.keyMaps.KeyMappings.DrumKeys; +import com.cstav.genshinstrument.client.keyMaps.InstrumentKeyMappings.DrumKeys; import net.minecraft.network.chat.Component; import net.minecraftforge.api.distmarker.Dist; 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 8aaf74d4..ad15ceb7 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,7 +5,7 @@ import com.cstav.genshinstrument.client.gui.screens.instrument.partial.note.label.NoteLabelSupplier; import com.cstav.genshinstrument.client.gui.screens.instrument.partial.notegrid.AbstractGridInstrumentScreen; import com.cstav.genshinstrument.client.gui.screens.instrument.partial.notegrid.NoteGridButton; -import com.cstav.genshinstrument.client.keyMaps.KeyMappings; +import com.cstav.genshinstrument.client.keyMaps.InstrumentKeyMappings; import com.cstav.genshinstrument.util.LabelUtil; import net.minecraft.network.chat.Component; @@ -17,7 +17,7 @@ */ public enum NoteGridLabel implements INoteLabel { KEYBOARD_LAYOUT((note) -> INoteLabel.upperComponent( - KeyMappings.GRID_INSTRUMENT_MAPPINGS[ng(note).column][ng(note).row].getDisplayName() + InstrumentKeyMappings.GRID_INSTRUMENT_MAPPINGS[ng(note).column][ng(note).row].getDisplayName() )), NOTE_NAME((note) -> Component.literal( LabelUtil.getCutNoteName(ng(note)) diff --git a/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/drum/DrumButtonType.java b/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/drum/DrumButtonType.java index efb39332..0615c81b 100644 --- a/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/drum/DrumButtonType.java +++ b/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/drum/DrumButtonType.java @@ -1,8 +1,8 @@ package com.cstav.genshinstrument.client.gui.screens.instrument.drum; import com.cstav.genshinstrument.client.gui.screens.instrument.partial.note.label.INoteLabel; -import com.cstav.genshinstrument.client.keyMaps.KeyMappings; -import com.cstav.genshinstrument.client.keyMaps.KeyMappings.DrumKeys; +import com.cstav.genshinstrument.client.keyMaps.InstrumentKeyMappings; +import com.cstav.genshinstrument.client.keyMaps.InstrumentKeyMappings.DrumKeys; import com.cstav.genshinstrument.sound.ModSounds; import com.cstav.genshinstrument.sound.NoteSound; @@ -35,7 +35,7 @@ public String getTransKey() { // Seperated for server compatibility @OnlyIn(Dist.CLIENT) public DrumKeys getKeys() { - return (this == DON) ? KeyMappings.DON : KeyMappings.KA; + return (this == DON) ? InstrumentKeyMappings.DON : InstrumentKeyMappings.KA; } } \ No newline at end of file diff --git a/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/partial/AbstractInstrumentScreen.java b/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/partial/AbstractInstrumentScreen.java index fd0b2ddf..f9dc5ca5 100644 --- a/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/partial/AbstractInstrumentScreen.java +++ b/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/partial/AbstractInstrumentScreen.java @@ -11,6 +11,7 @@ import com.cstav.genshinstrument.client.gui.screens.instrument.GenshinConsentScreen; import com.cstav.genshinstrument.client.gui.screens.instrument.partial.note.NoteButton; import com.cstav.genshinstrument.client.gui.screens.options.instrument.AbstractInstrumentOptionsScreen; +import com.cstav.genshinstrument.client.keyMaps.InstrumentKeyMappings; import com.cstav.genshinstrument.networking.ModPacketHandler; import com.cstav.genshinstrument.networking.buttonidentifier.NoteButtonIdentifier; import com.cstav.genshinstrument.networking.packet.instrument.CloseInstrumentPacket; @@ -219,9 +220,11 @@ protected AbstractWidget initOptionsButton(final int vertOffset) { } - @Override public boolean keyPressed(int pKeyCode, int pScanCode, int pModifiers) { + if (checkPitchTransposeUp(pKeyCode, pScanCode)) + return true; + final NoteButton note = getNoteByKey(pKeyCode); if (note != null) { @@ -233,6 +236,9 @@ public boolean keyPressed(int pKeyCode, int pScanCode, int pModifiers) { } @Override public boolean keyReleased(int pKeyCode, int pScanCode, int pModifiers) { + if (checkTransposeDown(pKeyCode, pScanCode)) + return true; + unlockFocused(); final NoteButton note = getNoteByKey(pKeyCode); @@ -242,6 +248,37 @@ public boolean keyReleased(int pKeyCode, int pScanCode, int pModifiers) { return super.keyReleased(pKeyCode, pScanCode, pModifiers); } + private boolean pitchChanged; + protected boolean checkPitchTransposeUp(int pKeyCode, int pScanCode) { + if (!pitchChanged && InstrumentKeyMappings.TRANSPOSE_UP_MODIFIER.get().matches(pKeyCode, pScanCode)) { + setPitch(getPitch() + 1); + pitchChanged = true; + return true; + } + if (!pitchChanged && InstrumentKeyMappings.TRANSPOSE_DOWN_MODIFIER.get().matches(pKeyCode, pScanCode)) { + setPitch(getPitch() - 1); + pitchChanged = true; + return true; + } + + return false; + } + protected boolean checkTransposeDown(int pKeyCode, int pScanCode) { + if (pitchChanged && InstrumentKeyMappings.TRANSPOSE_UP_MODIFIER.get().matches(pKeyCode, pScanCode)) { + initPitch(this::setPitch); + pitchChanged = false; + return true; + } + if (pitchChanged && InstrumentKeyMappings.TRANSPOSE_DOWN_MODIFIER.get().matches(pKeyCode, pScanCode)) { + initPitch(this::setPitch); + pitchChanged = false; + return true; + } + + return false; + } + + @Override public boolean mouseReleased(double pMouseX, double pMouseY, int pButton) { unlockFocused(); @@ -272,6 +309,8 @@ public void onOptionsOpen() { setFocused(null); minecraft.pushGuiLayer(optionsScreen); + initPitch(this::setPitch); + isOptionsScreenActive = true; } public void onOptionsClose() { diff --git a/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/partial/notegrid/AbstractGridInstrumentScreen.java b/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/partial/notegrid/AbstractGridInstrumentScreen.java index a6f56034..1468e078 100644 --- a/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/partial/notegrid/AbstractGridInstrumentScreen.java +++ b/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/partial/notegrid/AbstractGridInstrumentScreen.java @@ -10,7 +10,7 @@ import com.cstav.genshinstrument.client.gui.screens.instrument.partial.note.NoteButton; import com.cstav.genshinstrument.client.gui.screens.options.instrument.AbstractInstrumentOptionsScreen; import com.cstav.genshinstrument.client.gui.screens.options.instrument.GridInstrumentOptionsScreen; -import com.cstav.genshinstrument.client.keyMaps.KeyMappings; +import com.cstav.genshinstrument.client.keyMaps.InstrumentKeyMappings; import com.cstav.genshinstrument.networking.buttonidentifier.NoteButtonIdentifier; import com.cstav.genshinstrument.networking.buttonidentifier.NoteGridButtonIdentifier; import com.cstav.genshinstrument.sound.NoteSound; @@ -118,7 +118,7 @@ public NoteGrid initNoteGrid() { public final NoteGrid noteGrid = initNoteGrid(); - private final Map noteMap = noteGrid.genKeyboardMap(KeyMappings.GRID_INSTRUMENT_MAPPINGS); + private final Map noteMap = noteGrid.genKeyboardMap(InstrumentKeyMappings.GRID_INSTRUMENT_MAPPINGS); @Override public Map noteMap() { return noteMap; diff --git a/src/main/java/com/cstav/genshinstrument/client/keyMaps/InstrumentKeyMappings.java b/src/main/java/com/cstav/genshinstrument/client/keyMaps/InstrumentKeyMappings.java new file mode 100644 index 00000000..c6e075fe --- /dev/null +++ b/src/main/java/com/cstav/genshinstrument/client/keyMaps/InstrumentKeyMappings.java @@ -0,0 +1,114 @@ +package com.cstav.genshinstrument.client.keyMaps; + +import org.lwjgl.glfw.GLFW; + +import com.cstav.genshinstrument.GInstrumentMod; +import com.cstav.genshinstrument.client.gui.screens.instrument.partial.AbstractInstrumentScreen; +import com.cstav.genshinstrument.client.gui.screens.instrument.partial.notegrid.AbstractGridInstrumentScreen; +import com.mojang.blaze3d.platform.InputConstants; +import com.mojang.blaze3d.platform.InputConstants.Key; +import com.mojang.blaze3d.platform.InputConstants.Type; + +import net.minecraft.client.KeyMapping; +import net.minecraft.client.Minecraft; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; +import net.minecraftforge.client.event.RegisterKeyMappingsEvent; +import net.minecraftforge.client.settings.IKeyConflictContext; +import net.minecraftforge.common.util.Lazy; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod.EventBusSubscriber; +import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus; + +@OnlyIn(Dist.CLIENT) +@EventBusSubscriber(bus = Bus.MOD, modid = GInstrumentMod.MODID, value = Dist.CLIENT) +public class InstrumentKeyMappings { + public static final String CATEGORY = GInstrumentMod.MODID+".keymaps"; + + public static final IKeyConflictContext INSTRUMENT_KEY_CONFLICT_CONTEXT = new IKeyConflictContext() { + + @SuppressWarnings("resource") + @Override + public boolean isActive() { + return Minecraft.getInstance().screen instanceof AbstractInstrumentScreen; + } + + @Override + public boolean conflicts(IKeyConflictContext other) { + return this == other; + } + + }; + + + public static final Lazy TRANSPOSE_UP_MODIFIER = Lazy.of( + () -> new KeyMapping(CATEGORY+".transpose_up_modifier", + INSTRUMENT_KEY_CONFLICT_CONTEXT, + InputConstants.Type.KEYSYM, + GLFW.GLFW_KEY_RIGHT_SHIFT + , CATEGORY) + ); + public static final Lazy TRANSPOSE_DOWN_MODIFIER = Lazy.of( + () -> new KeyMapping(CATEGORY+".transpose_down_modifier", + INSTRUMENT_KEY_CONFLICT_CONTEXT, + InputConstants.Type.KEYSYM, + GLFW.GLFW_KEY_LEFT_SHIFT + , CATEGORY) + ); + + + @SubscribeEvent + public static void registerKeybinds(final RegisterKeyMappingsEvent event) { + event.register(TRANSPOSE_UP_MODIFIER.get()); + event.register(TRANSPOSE_DOWN_MODIFIER.get()); + } + + + /* --------------- Builtin Keys --------------- */ + + public static final Key[][] GRID_INSTRUMENT_MAPPINGS = createInstrumentMaps(new int[][] { + {81, 87, 69, 82, 84, 89, 85, 73}, + {65, 83, 68, 70, 71, 72, 74, 75}, + {90, 88, 67, 86, 66, 78, 77, 44} + }); + + // Glorious drum + public static final DrumKeys + DON = new DrumKeys(83, 75), + KA = new DrumKeys(65, 76) + ; + + @OnlyIn(Dist.CLIENT) + public static final class DrumKeys { + public final Key left, right; + + private DrumKeys(final int left, final int right) { + this.left = create(left); + this.right = create(right); + } + } + + + + /** + * Creates a grid of keys. + * used by {@link AbstractGridInstrumentScreen} for managing keyboard input. + * @param keyCodes A 2D array representing a key grid. Each cell should correspond to a note. + * @return A 2D key array as described in {@code keyCodes}. + */ + public static Key[][] createInstrumentMaps(final int[][] keyCodes) { + final int rows = keyCodes[0].length, columns = keyCodes.length; + + final Key[][] result = new Key[columns][rows]; + for (int i = 0; i < columns; i++) + for (int j = 0; j < rows; j++) + result[i][j] = create(keyCodes[i][j]); + + return result; + } + + private static Key create(final int keyCode) { + return Type.KEYSYM.getOrCreate(keyCode); + } + +} diff --git a/src/main/java/com/cstav/genshinstrument/client/keyMaps/KeyMappings.java b/src/main/java/com/cstav/genshinstrument/client/keyMaps/KeyMappings.java deleted file mode 100644 index e39de2c8..00000000 --- a/src/main/java/com/cstav/genshinstrument/client/keyMaps/KeyMappings.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.cstav.genshinstrument.client.keyMaps; - -import com.cstav.genshinstrument.client.gui.screens.instrument.partial.notegrid.AbstractGridInstrumentScreen; -import com.mojang.blaze3d.platform.InputConstants.Key; -import com.mojang.blaze3d.platform.InputConstants.Type; - -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; - -// Literally only doing this for key translations -@OnlyIn(Dist.CLIENT) -public class KeyMappings { - - public static final Key[][] GRID_INSTRUMENT_MAPPINGS = createInstrumentMaps(new int[][] { - {81, 87, 69, 82, 84, 89, 85, 73}, - {65, 83, 68, 70, 71, 72, 74, 75}, - {90, 88, 67, 86, 66, 78, 77, 44} - }); - - // Glorious drum - public static final DrumKeys - DON = new DrumKeys(83, 75), - KA = new DrumKeys(65, 76) - ; - - @OnlyIn(Dist.CLIENT) - public static final class DrumKeys { - public final Key left, right; - - private DrumKeys(final int left, final int right) { - this.left = create(left); - this.right = create(right); - } - } - - - - /** - * Creates a grid of keys. - * used by {@link AbstractGridInstrumentScreen} for managing keyboard input. - * @param keyCodes A 2D array representing a key grid. Each cell should correspond to a note. - * @return A 2D key array as described in {@code keyCodes}. - */ - public static Key[][] createInstrumentMaps(final int[][] keyCodes) { - final int rows = keyCodes[0].length, columns = keyCodes.length; - - final Key[][] result = new Key[columns][rows]; - for (int i = 0; i < columns; i++) - for (int j = 0; j < rows; j++) - result[i][j] = create(keyCodes[i][j]); - - return result; - } - - private static Key create(final int keyCode) { - return Type.KEYSYM.getOrCreate(keyCode); - } - -} diff --git a/src/main/resources/assets/genshinstrument/lang/en_us.json b/src/main/resources/assets/genshinstrument/lang/en_us.json index 6f65f596..808a228d 100644 --- a/src/main/resources/assets/genshinstrument/lang/en_us.json +++ b/src/main/resources/assets/genshinstrument/lang/en_us.json @@ -1,4 +1,9 @@ { + "genshinstrument.keymaps": "Instruments GUI", + "genshinstrument.keymaps.transpose_up_modifier": "Transpose Instrument Up", + "genshinstrument.keymaps.transpose_down_modifier": "Transpose Instrument Down", + + "genshinstrument.itemGroup.instruments": "Instruments", "item.genshinstrument.windsong_lyre": "Windsong Lyre", diff --git a/src/main/resources/assets/genshinstrument/lang/he_il.json b/src/main/resources/assets/genshinstrument/lang/he_il.json index 36d928ee..9326ce7a 100644 --- a/src/main/resources/assets/genshinstrument/lang/he_il.json +++ b/src/main/resources/assets/genshinstrument/lang/he_il.json @@ -1,4 +1,9 @@ { + "genshinstrument.keymaps": "כלי נגינה", + "genshinstrument.keymaps.transpose_down_modifier": "המנך גובה צליל", + "genshinstrument.keymaps.transpose_up_modifier": "הגבהה גובה צליל", + + "genshinstrument.itemGroup.instruments": "כלי נגינה", "item.genshinstrument.windsong_lyre": "נבל הרוחות", diff --git a/src/main/resources/assets/genshinstrument/lang/ru_ru.json b/src/main/resources/assets/genshinstrument/lang/ru_ru.json index 6c67276c..7c81da83 100644 --- a/src/main/resources/assets/genshinstrument/lang/ru_ru.json +++ b/src/main/resources/assets/genshinstrument/lang/ru_ru.json @@ -1,4 +1,9 @@ { + "genshinstrument.keymaps": "инструменты", + "genshinstrument.keymaps.transpose_up_modifier": "Повышение высоты инструмента", + "genshinstrument.keymaps.transpose_down_modifier": "Уменьшение высоты инструмента", + + "genshinstrument.itemGroup.instruments": "инструменты", "item.genshinstrument.windsong_lyre": "Лира ветров",