Skip to content

Commit

Permalink
Pitch up/down with left/right shift
Browse files Browse the repository at this point in the history
  • Loading branch information
StavWasPlayZ committed Aug 7, 2023
1 parent e444e29 commit 540b9be
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 2 deletions.
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.KeyMappings;
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 (checkPitchInstrumentUp(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 (checkPitchInstrumentDown(pKeyCode, pScanCode))
return true;

unlockFocused();

final NoteButton note = getNoteByKey(pKeyCode);
Expand All @@ -242,6 +248,42 @@ public boolean keyReleased(int pKeyCode, int pScanCode, int pModifiers) {
return super.keyReleased(pKeyCode, pScanCode, pModifiers);
}

private boolean pitchChanged;
protected boolean checkPitchInstrumentUp(int pKeyCode, int pScanCode) {
if (!pitchChanged && KeyMappings.PITCH_UP_MODIFIER.get().matches(pKeyCode, pScanCode)) {
pitchInstrumentUp(true);
return true;
}
if (!pitchChanged && KeyMappings.PITCH_DOWN_MODIFIER.get().matches(pKeyCode, pScanCode)) {
pitchInstrumentDown(true);
return true;
}

return false;
}
protected boolean checkPitchInstrumentDown(int pKeyCode, int pScanCode) {
if (pitchChanged && KeyMappings.PITCH_UP_MODIFIER.get().matches(pKeyCode, pScanCode)) {
pitchInstrumentDown(false);
return true;
}
if (pitchChanged && KeyMappings.PITCH_DOWN_MODIFIER.get().matches(pKeyCode, pScanCode)) {
pitchInstrumentUp(false);
return true;
}

return false;
}

private void pitchInstrumentUp(final boolean pressed) {
setPitch(getPitch() + 1);
pitchChanged = pressed;
}
private void pitchInstrumentDown(final boolean pressed) {
setPitch(getPitch() - 1);
pitchChanged = pressed;
}


@Override
public boolean mouseReleased(double pMouseX, double pMouseY, int pButton) {
unlockFocused();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,71 @@
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;

// Literally only doing this for key translations
@OnlyIn(Dist.CLIENT)
@EventBusSubscriber(bus = Bus.MOD, modid = GInstrumentMod.MODID, value = Dist.CLIENT)
public class KeyMappings {
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> PITCH_UP_MODIFIER = Lazy.of(
() -> new KeyMapping(CATEGORY+".pitch_up_modifier",
INSTRUMENT_KEY_CONFLICT_CONTEXT,
InputConstants.Type.KEYSYM,
GLFW.GLFW_KEY_RIGHT_SHIFT
, CATEGORY)
);
public static final Lazy<KeyMapping> PITCH_DOWN_MODIFIER = Lazy.of(
() -> new KeyMapping(CATEGORY+".pitch_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(PITCH_UP_MODIFIER.get());
event.register(PITCH_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},
Expand Down
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.pitch_down_modifier": "Pitch Instrument Down",
"genshinstrument.keymaps.pitch_up_modifier": "Pitch Instrument Up",


"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.pitch_down_modifier": "המנך גובה צליל",
"genshinstrument.keymaps.pitch_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.pitch_down_modifier": "Уменьшение высоты инструмента",
"genshinstrument.keymaps.pitch_up_modifier": "Повышение высоты инструмента",


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

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

0 comments on commit 540b9be

Please sign in to comment.