Skip to content

Commit

Permalink
Merge branch 'dev' into 1.20-v2
Browse files Browse the repository at this point in the history
  • Loading branch information
StavWasPlayZ committed Aug 7, 2023
2 parents 89567cd + fc3e342 commit 06f0bbe
Show file tree
Hide file tree
Showing 10 changed files with 177 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand All @@ -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();
Expand Down Expand Up @@ -272,6 +309,8 @@ public void onOptionsOpen() {
setFocused(null);
minecraft.pushGuiLayer(optionsScreen);

initPitch(this::setPitch);

isOptionsScreenActive = true;
}
public void onOptionsClose() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -118,7 +118,7 @@ public NoteGrid initNoteGrid() {

public final NoteGrid noteGrid = initNoteGrid();

private final Map<Key, NoteButton> noteMap = noteGrid.genKeyboardMap(KeyMappings.GRID_INSTRUMENT_MAPPINGS);
private final Map<Key, NoteButton> noteMap = noteGrid.genKeyboardMap(InstrumentKeyMappings.GRID_INSTRUMENT_MAPPINGS);
@Override
public Map<Key, NoteButton> noteMap() {
return noteMap;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<KeyMapping> 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<KeyMapping> 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);
}

}

This file was deleted.

5 changes: 5 additions & 0 deletions src/main/resources/assets/genshinstrument/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/assets/genshinstrument/lang/he_il.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{
"genshinstrument.keymaps": "כלי נגינה",
"genshinstrument.keymaps.transpose_down_modifier": "המנך גובה צליל",
"genshinstrument.keymaps.transpose_up_modifier": "הגבהה גובה צליל",


"genshinstrument.itemGroup.instruments": "כלי נגינה",

"item.genshinstrument.windsong_lyre": "נבל הרוחות",
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/assets/genshinstrument/lang/ru_ru.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{
"genshinstrument.keymaps": "инструменты",
"genshinstrument.keymaps.transpose_up_modifier": "Повышение высоты инструмента",
"genshinstrument.keymaps.transpose_down_modifier": "Уменьшение высоты инструмента",


"genshinstrument.itemGroup.instruments": "инструменты",

"item.genshinstrument.windsong_lyre": "Лира ветров",
Expand Down

0 comments on commit 06f0bbe

Please sign in to comment.