Skip to content

Commit

Permalink
Merge branch 'dev' into 1.19.4
Browse files Browse the repository at this point in the history
  • Loading branch information
StavWasPlayZ committed Aug 29, 2023
2 parents cb62393 + 80809a2 commit cb99d01
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 65 deletions.
21 changes: 21 additions & 0 deletions src/main/java/com/cstav/genshinstrument/client/ClientUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}


/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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())
),
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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()
)),
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -31,6 +32,10 @@ public DrumNoteIdentifier getIdentifier() {
return new DrumNoteIdentifier(this);
}

public Key getKey() {
return btnType.getKeys().getKey(isRight);
}


@Override
protected NoteButtonRenderer initNoteRenderer() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public GridInstrumentOptionsScreen(final Screen lastScreen) {


@Override
public NoteGridLabel[] getLabels() {
public INoteLabel[] getLabels() {
return NoteGridLabel.availableVals();
}
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}


Expand Down

0 comments on commit cb99d01

Please sign in to comment.