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 Jul 20, 2023
2 parents 409d7b9 + 1bc9a1c commit 5ebac7e
Show file tree
Hide file tree
Showing 46 changed files with 1,088 additions and 204 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ parchment_mappings=1.19.4:2023.06.26
loader_version=0.14.21

# Mod Properties
mod_version=2.8
mod_version=3.0
maven_group=com.cstav.genshinstrument
archives_base_name=genshinstrument

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class ModClientConfigs {
public static final EnumValue<NoteGridLabel> GRID_LABEL_TYPE;
public static final EnumValue<InstrumentChannelType> CHANNEL_TYPE;
public static final BooleanValue STOP_MUSIC_ON_PLAY, EMIT_RING_ANIMATION, SHARED_INSTRUMENT,
RENDER_BACKGROUND;
RENDER_BACKGROUND, ACCEPTED_GENSHIN_CONSENT, ACCURATE_ACCIDENTALS;

public static final EnumValue<ZitherSoundType> ZITHER_SOUND_TYPE;
public static final EnumValue<DrumNoteLabel> DRUM_LABEL_TYPE;
Expand All @@ -45,6 +45,9 @@ public class ModClientConfigs {
SHARED_INSTRUMENT = configBuilder.comment("Defines whether you will see others playing on your instrument's screen")
.define("display_other_players", true);
RENDER_BACKGROUND = configBuilder.define("render_background", true);
ACCURATE_ACCIDENTALS = configBuilder.define("accurate_accidentals", true);

ACCEPTED_GENSHIN_CONSENT = configBuilder.define("accepted_genshin_consent", false);


ZITHER_SOUND_TYPE = configBuilder.defineEnum("zither_sound_type", ZitherSoundType.NEW);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,25 @@ public enum NoteGridLabel implements INoteLabel {
KEYBOARD_LAYOUT((note) -> INoteLabel.upperComponent(
KeyMappings.GRID_INSTRUMENT_MAPPINGS[ng(note).column][ng(note).row].getDisplayName()
)),
DO_RE_MI((note) -> Component.translatable(
INoteLabel.TRANSLATABLE_PATH + AbsGridLabels.DO_RE_MI[ng(note).row % gs(note).rows()]
NOTE_NAME((note) -> Component.literal(
AbsGridLabels.getCutNoteName(ng(note))
)),
ABC((note) -> Component.literal(
DO_RE_MI((note) ->
Component.translatable(
INoteLabel.TRANSLATABLE_PATH + AbsGridLabels.DO_RE_MI[ng(note).row % gs(note).rows()]
).append(AbsGridLabels.getCutNoteName(ng(note)).substring(1))
),
ABC_1((note) -> Component.literal(
AbsGridLabels.ABC[ng(note).row] + (gs(note).columns() - ng(note).column)
)),
ABC_2((note) -> Component.literal(
(
(ng(note).column == 0) ? "A" :
(ng(note).column == 1) ? "B" :
"C"
) + (ng(note).row + 1)
)),

NONE(NoteLabelSupplier.EMPTY);


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package com.cstav.genshinstrument.client.gui.screens.instrument;

import java.awt.Color;
import java.util.List;

import com.cstav.genshinstrument.client.config.ModClientConfigs;

import net.minecraft.ChatFormatting;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.multiplayer.WarningScreen;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;

/**
* @implNote <p>
* This screen was heavily inspired by <a href=https://ko-fi.com/s/665c3cc518>Kistu-Lyre+</a>'s Disclaimer screen.
* Please consider supporting them on Ko-fi!
* </p>
* On a personal note, I unfortunately lack any budget to be in position of donating any sum of money to any one person ;-;
*/
public class GenshinConsentScreen extends WarningScreen {

private static final Component TITLE = Component.translatable(
"genshinstrument.genshin_disclaimer.title"
).withStyle(ChatFormatting.BOLD);
// Can't create object field because of constructor
private static final MutableComponent CONTENT = Component.translatable(
"genshinstrument.genshin_disclaimer.content", boldenAll(2)
);
private static final Component NARRATION = TITLE.copy().append("\n").append(CONTENT);

private final Screen previousScreen;

public GenshinConsentScreen(final Screen previousScreen) {
super(TITLE, CONTENT, null, NARRATION);
this.previousScreen = previousScreen;
}


@Override
protected int getLineHeight() {
return 10;
}

private static boolean hasGreeting = false;

@Override
protected void init() {
final Button acknowledgeButton = Button.builder(CommonComponents.GUI_ACKNOWLEDGE, (button) -> {
ModClientConfigs.ACCEPTED_GENSHIN_CONSENT.set(true);
minecraft.setScreen(previousScreen);
}).build();


// Make space for if the button is overlayed atop of the greeting
final int perferredButtonY = 100 + 140, annoyingButtonY = height - acknowledgeButton.getHeight() - 10;

if (annoyingButtonY <= perferredButtonY) {
acknowledgeButton.setPosition(
(width - acknowledgeButton.getWidth()) / 2,
annoyingButtonY
);

if (hasGreeting) {
// i have to eradicate brothers alike UmU
final List<Component> siblings = CONTENT.getSiblings();
for (int i = 0; i < 2; i++)
siblings.remove(siblings.size() - 1);

hasGreeting = false;
}
} else {
acknowledgeButton.setPosition(
(width - acknowledgeButton.getWidth()) / 2,
perferredButtonY
);

if (!hasGreeting) {
CONTENT.append("\n\n\n\n")
.append(Component.translatable("genshinstrument.genshin_disclaimer.content.no_legal"));

hasGreeting = true;
}
}

this.addRenderableWidget(acknowledgeButton);

super.init();
}

@Override
protected void renderTitle(GuiGraphics gui) {
gui.drawCenteredString(font, title, width/2, 30, Color.WHITE.getRGB());
}


private static Component bolden(final int index) {
return Component.translatable("genshinstrument.genshin_disclaimer.bolden"+index).withStyle(ChatFormatting.BOLD);
}
private static Object[] boldenAll(final int amount) {
final Object[] result = new Object[amount];

for (int i = 0; i < amount; i++)
result[i] = bolden(i+1);

return result;
}


@Override
public void onClose() {
super.onClose();
previousScreen.onClose();
}


@Override
protected void initButtons(int idc) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ protected void init() {
layout1.setPosition((width - layout1.getWidth()) / 2, (int)(height * .8f));
layout2.setPosition((width - layout2.getWidth()) / 2, layout1.getY() - layout1.getHeight());

layout1.arrangeElements();
layout2.arrangeElements();


layout1.visitWidgets(this::addRenderableWidget);
layout2.visitWidgets(this::addRenderableWidget);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,21 @@
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;

@Environment(EnvType.CLIENT)
public enum DrumButtonType {
DON(0, ModSounds.GLORIOUS_DRUM[0], "glorious_drum.don", KeyMappings.DON),
KA(1, ModSounds.GLORIOUS_DRUM[1], "glorious_drum.ka", KeyMappings.KA);
DON(0, ModSounds.GLORIOUS_DRUM[0], "glorious_drum.don"),
KA(1, ModSounds.GLORIOUS_DRUM[1], "glorious_drum.ka");

private final DrumKeys keys;
private final String transKey;
private final NoteSound sound;
private final int index;

private DrumButtonType(int index, NoteSound sound, String transKey, DrumKeys keys) {
private DrumButtonType(int index, NoteSound sound, String transKey) {
this.sound = sound;
this.index = index;
this.keys = keys;

this.transKey = INoteLabel.TRANSLATABLE_PATH + transKey;
}

public DrumKeys getKeys() {
return keys;
}
public NoteSound getSound() {
return sound;
}
Expand All @@ -39,4 +33,11 @@ public int getIndex() {
public String getTransKey() {
return transKey;
}


// Seperated for server compatibility
@Environment(EnvType.CLIENT)
public DrumKeys getKeys() {
return (this == DON) ? KeyMappings.DON : KeyMappings.KA;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.cstav.genshinstrument.client.config.ModClientConfigs;
import com.cstav.genshinstrument.client.gui.screens.instrument.partial.note.NoteButton;
import com.cstav.genshinstrument.networking.buttonidentifier.DrumNoteIdentifier;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
Expand All @@ -12,7 +13,7 @@ public class DrumNoteButton extends NoteButton {
public final DrumButtonType btnType;
public final boolean isRight;

public DrumNoteButton(DrumButtonType btnType, boolean isLeft, AratakisGreatAndGloriousDrumScreen drumScreen) {
public DrumNoteButton(DrumButtonType btnType, boolean isRight, AratakisGreatAndGloriousDrumScreen drumScreen) {
super(
btnType.getSound(),
ModClientConfigs.DRUM_LABEL_TYPE.get().getLabelSupplier(),
Expand All @@ -22,7 +23,13 @@ public DrumNoteButton(DrumButtonType btnType, boolean isLeft, AratakisGreatAndGl
);

this.btnType = btnType;
this.isRight = isLeft;
this.isRight = isRight;
}


@Override
public DrumNoteIdentifier getIdentifier() {
return new DrumNoteIdentifier(this);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.awt.Color;
import java.util.Map;
import java.util.NoSuchElementException;

import com.cstav.genshinstrument.GInstrumentMod;
import com.cstav.genshinstrument.client.ClientUtil;
Expand All @@ -11,6 +12,8 @@
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.networking.buttonidentifier.NoteButtonIdentifier;
import com.cstav.genshinstrument.networking.buttonidentifier.NoteGridButtonIdentifier;
import com.mojang.blaze3d.platform.InputConstants.Key;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
Expand Down Expand Up @@ -40,6 +43,33 @@ public int columns() {
public int rows() {
return DEF_ROWS;
}


/**
* <p>
* If the given identifier is of type {@link NoteGridButtonIdentifier},
* uses the optimal method to obtain the described {@link NoteButton}.
* </p>
* Otherwise, uses {@link AbstractInstrumentScreen#getNoteButton the regular linear method}.
* @return The {@link NoteButton} as described by the given identifier
*/
@Override
public NoteButton getNoteButton(final NoteButtonIdentifier noteIdentifier) throws IndexOutOfBoundsException, NoSuchElementException {
if (!(noteIdentifier instanceof NoteGridButtonIdentifier))
return super.getNoteButton(noteIdentifier);

return getNoteButton((NoteGridButtonIdentifier)noteIdentifier);
}
/**
* Gets a {@link NoteButton} based on the location of the note as described by the given identifier.
*/
public NoteButton getNoteButton(final NoteGridButtonIdentifier noteIdentifier) throws IndexOutOfBoundsException {
return getNoteButton(noteIdentifier.row, noteIdentifier.column);
}

public NoteButton getNoteButton(final int row, final int column) throws IndexOutOfBoundsException {
return noteGrid.getNoteButton(row, column);
}


// Abstract implementations
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.cstav.genshinstrument.client.gui.screens.instrument.partial;

import java.util.Map;
import java.util.NoSuchElementException;

import com.cstav.genshinstrument.client.config.ModClientConfigs;
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.networking.ModPacketHandler;
import com.cstav.genshinstrument.networking.buttonidentifier.NoteButtonIdentifier;
import com.cstav.genshinstrument.networking.packets.instrument.CloseInstrumentPacket;
import com.cstav.genshinstrument.sound.NoteSound;
import com.cstav.genshinstrument.util.ModEntityData;
Expand All @@ -25,7 +28,9 @@

@Environment(EnvType.CLIENT)
public abstract class AbstractInstrumentScreen extends Screen {
public static final String[] DEFAULT_NOTE_LAYOUT = new String[] {"C", "D", "E", "F", "G", "A", "B"};


/**
* The set pitch of all note buttons in this screen
*/
Expand Down Expand Up @@ -69,6 +74,38 @@ protected static final InstrumentThemeLoader initThemeLoader(String modId, Strin
*/
public abstract NoteSound[] getSounds();

/**
* @return The layout of the note names accross the instrument's rows.
* @apiNote All built-in instruments' layouts are derived from
* <a href=https://github.com/Specy/genshin-music/blob/19dfe0e2fb8081508bd61dd47289dcb2d89ad5e3/src/Config.ts#L114>
* Genshin Music app configs
* </a>
*/
public String[] noteLayout() {
return DEFAULT_NOTE_LAYOUT;
}

/**
* @return Whether this instrument is derived from Genshin Impact
* @apiNote This value will help the mod determine whether a disclaimer pop-up should appear upon opening this
* instrument.
*/
public boolean isGenshinInstrument() {
return true;
}


/**
* @return The first {@link NoteButton} that matches the description of the given identifier
*/
public NoteButton getNoteButton(final NoteButtonIdentifier noteIdentifier) throws NoSuchElementException {
for (NoteButton note : notesIterable())
if (noteIdentifier.matches(note))
return note;

throw new NoSuchElementException("Could not find a note in "+getClass().getSimpleName()+" based on the given identifier");
}

/**
* @return A map holding an integer key as its keycode and a {@link NoteButton} as its value.
*/
Expand Down Expand Up @@ -123,6 +160,9 @@ public AbstractInstrumentScreen(final InteractionHand hand) {
@Override
protected void init() {
optionsScreen.init(minecraft, width, height);

if (isGenshinInstrument() && !ModClientConfigs.ACCEPTED_GENSHIN_CONSENT.get())
minecraft.setScreen(new GenshinConsentScreen(this));
}
/**
* Initializes a new button responsible for popping up the options menu for this instrument.
Expand Down
Loading

0 comments on commit 5ebac7e

Please sign in to comment.