Added config and favorites
This commit is contained in:
parent
f8de065ce3
commit
839283a8fa
11
build.gradle
11
build.gradle
@ -7,11 +7,8 @@ version = project.mod_version
|
||||
group = project.maven_group
|
||||
|
||||
repositories {
|
||||
// Add repositories to retrieve artifacts from in here.
|
||||
// You should only use this when depending on other mods because
|
||||
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
|
||||
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
|
||||
// for more information about repositories.
|
||||
maven { url "https://maven.shedaniel.me/" }
|
||||
maven { url "https://maven.terraformersmc.com/" }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@ -22,6 +19,10 @@ dependencies {
|
||||
|
||||
// Fabric API. This is technically optional, but you probably want it anyway.
|
||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
||||
|
||||
modApi("me.shedaniel.cloth:cloth-config-fabric:7.0.65") {
|
||||
exclude(group: "net.fabricmc.fabric-api")
|
||||
}
|
||||
}
|
||||
|
||||
processResources {
|
||||
|
16
src/main/java/semmiedev/disc_jockey/Config.java
Normal file
16
src/main/java/semmiedev/disc_jockey/Config.java
Normal file
@ -0,0 +1,16 @@
|
||||
package semmiedev.disc_jockey;
|
||||
|
||||
import me.shedaniel.autoconfig.ConfigData;
|
||||
import me.shedaniel.autoconfig.annotation.ConfigEntry;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@me.shedaniel.autoconfig.annotation.Config(name = Main.MOD_ID)
|
||||
public class Config implements ConfigData {
|
||||
@ConfigEntry.Gui.Tooltip
|
||||
public boolean monoNoteBlocks;
|
||||
public boolean hideWarning;
|
||||
|
||||
@ConfigEntry.Gui.Excluded
|
||||
public ArrayList<String> favorites = new ArrayList<>();
|
||||
}
|
@ -1,7 +1,9 @@
|
||||
package semmiedev.disc_jockey;
|
||||
|
||||
import me.shedaniel.autoconfig.AutoConfig;
|
||||
import me.shedaniel.autoconfig.ConfigHolder;
|
||||
import me.shedaniel.autoconfig.serializer.JanksonConfigSerializer;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
|
||||
import net.fabricmc.fabric.api.client.networking.v1.ClientLoginConnectionEvents;
|
||||
@ -31,9 +33,15 @@ public class Main implements ClientModInitializer {
|
||||
public static final SongPlayer SONG_PLAYER = new SongPlayer();
|
||||
|
||||
public static File songsFolder;
|
||||
public static Config config;
|
||||
public static ConfigHolder<Config> configHolder;
|
||||
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
// TODO: 5/31/2022 Add a note block mono mode, making all note block sounds play as mono instead of as stereo\
|
||||
configHolder = AutoConfig.register(Config.class, JanksonConfigSerializer::new);
|
||||
config = configHolder.getConfig();
|
||||
|
||||
songsFolder = new File(FabricLoader.getInstance().getConfigDir()+File.separator+MOD_ID+File.separator+"songs");
|
||||
if (!songsFolder.isDirectory()) songsFolder.mkdirs();
|
||||
|
||||
@ -63,13 +71,16 @@ public class Main implements ClientModInitializer {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
ClientTickEvents.START_WORLD_TICK.register(world -> {
|
||||
for (ClientTickEvents.StartWorldTick listener : TICK_LISTENERS) listener.onStartTick(world);
|
||||
});
|
||||
|
||||
ClientLoginConnectionEvents.DISCONNECT.register((handler, client) -> {
|
||||
PREVIEWER.stop();
|
||||
SONG_PLAYER.stop();
|
||||
});
|
||||
|
||||
HudRenderCallback.EVENT.register(BlocksOverlay::render);
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import net.minecraft.text.Text;
|
||||
import semmiedev.disc_jockey.gui.SongListWidget;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -63,7 +62,8 @@ public class SongLoader {
|
||||
}
|
||||
|
||||
song.displayName = song.name.replaceAll("\\s", "").isEmpty() ? song.fileName : song.name+" ("+song.fileName+")";
|
||||
song.entry = new SongListWidget.SongEntry(song.displayName, SONGS.size());
|
||||
song.entry = new SongListWidget.SongEntry(song, SONGS.size());
|
||||
song.entry.favorite = Main.config.favorites.contains(song.fileName);
|
||||
song.searchableFileName = song.fileName.toLowerCase().replaceAll("\\s", "");
|
||||
song.searchableName = song.name.toLowerCase().replaceAll("\\s", "");
|
||||
|
||||
@ -106,6 +106,8 @@ public class SongLoader {
|
||||
}
|
||||
}
|
||||
for (Song song : SONGS) SONG_SUGGESTIONS.add(song.displayName);
|
||||
Main.config.favorites.removeIf(favorite -> SongLoader.SONGS.stream().map(song -> song.fileName).noneMatch(favorite::equals));
|
||||
|
||||
SystemToast.add(MinecraftClient.getInstance().getToastManager(), SystemToast.Type.PACK_LOAD_FAILURE, Main.NAME, Text.translatable(Main.MOD_ID+".loading_done"));
|
||||
loadingSongs = false;
|
||||
}).start();
|
||||
|
@ -2,13 +2,13 @@ package semmiedev.disc_jockey.gui;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.ingame.CraftingScreen;
|
||||
import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
|
||||
import net.minecraft.client.gui.widget.EntryListWidget;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.util.Identifier;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import semmiedev.disc_jockey.Main;
|
||||
import semmiedev.disc_jockey.Song;
|
||||
|
||||
public class SongListWidget extends EntryListWidget<SongListWidget.SongEntry> {
|
||||
public SongListWidget(MinecraftClient client, int width, int height, int top, int bottom, int itemHeight) {
|
||||
@ -42,17 +42,17 @@ public class SongListWidget extends EntryListWidget<SongListWidget.SongEntry> {
|
||||
private static final Identifier ICONS = new Identifier(Main.MOD_ID, "textures/gui/icons.png");
|
||||
|
||||
public final int index;
|
||||
public final Song song;
|
||||
|
||||
public boolean selected, favorite;
|
||||
public SongListWidget songListWidget;
|
||||
|
||||
private final String name;
|
||||
private final MinecraftClient client = MinecraftClient.getInstance();
|
||||
|
||||
private int x, y, entryWidth, entryHeight;
|
||||
|
||||
public SongEntry(String name, int index) {
|
||||
this.name = name;
|
||||
public SongEntry(Song song, int index) {
|
||||
this.song = song;
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
@ -65,7 +65,7 @@ public class SongListWidget extends EntryListWidget<SongListWidget.SongEntry> {
|
||||
fill(matrices, x + 1, y + 1, x + entryWidth - 1, y + entryHeight - 1, 0x000000);
|
||||
}
|
||||
|
||||
drawCenteredText(matrices, client.textRenderer, name, x + entryWidth / 2, y + 5, selected ? 0xFFFFFF : 0x808080);
|
||||
drawCenteredText(matrices, client.textRenderer, song.displayName, x + entryWidth / 2, y + 5, selected ? 0xFFFFFF : 0x808080);
|
||||
|
||||
RenderSystem.setShaderTexture(0, ICONS);
|
||||
drawTexture(matrices, x + 2, y + 2, (favorite ? 26 : 0) + (isOverFavoriteButton(mouseX, mouseY) ? 13 : 0), 0, 13, 12, 52, 12);
|
||||
@ -75,6 +75,11 @@ public class SongListWidget extends EntryListWidget<SongListWidget.SongEntry> {
|
||||
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||
if (isOverFavoriteButton(mouseX, mouseY)) {
|
||||
favorite = !favorite;
|
||||
if (favorite) {
|
||||
Main.config.favorites.add(song.fileName);
|
||||
} else {
|
||||
Main.config.favorites.remove(song.fileName);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
songListWidget.setSelected(this);
|
||||
|
@ -51,7 +51,7 @@ public class DiscJockeyScreen extends Screen {
|
||||
} else {
|
||||
SongListWidget.SongEntry entry = songListWidget.getSelectedOrNull();
|
||||
if (entry != null) {
|
||||
Main.SONG_PLAYER.start(SongLoader.SONGS.get(entry.index));
|
||||
Main.SONG_PLAYER.start(entry.song);
|
||||
client.setScreen(null);
|
||||
}
|
||||
}
|
||||
@ -63,7 +63,7 @@ public class DiscJockeyScreen extends Screen {
|
||||
Main.PREVIEWER.stop();
|
||||
} else {
|
||||
SongListWidget.SongEntry entry = songListWidget.getSelectedOrNull();
|
||||
if (entry != null) Main.PREVIEWER.start(SongLoader.SONGS.get(entry.index));
|
||||
if (entry != null) Main.PREVIEWER.start(entry.song);
|
||||
}
|
||||
});
|
||||
addDrawableChild(previewButton);
|
||||
@ -73,13 +73,12 @@ public class DiscJockeyScreen extends Screen {
|
||||
SongListWidget.SongEntry entry = songListWidget.getSelectedOrNull();
|
||||
if (entry != null) {
|
||||
client.setScreen(null);
|
||||
Song song = SongLoader.SONGS.get(entry.index);
|
||||
|
||||
BlocksOverlay.itemStacks = new ItemStack[0];
|
||||
BlocksOverlay.amounts = new int[0];
|
||||
BlocksOverlay.amountOfNoteBlocks = song.uniqueNotes.size();
|
||||
BlocksOverlay.amountOfNoteBlocks = entry.song.uniqueNotes.size();
|
||||
|
||||
for (Note note : song.uniqueNotes) {
|
||||
for (Note note : entry.song.uniqueNotes) {
|
||||
ItemStack itemStack = Note.INSTRUMENT_BLOCKS.get(note.instrument).asItem().getDefaultStack();
|
||||
int index = -1;
|
||||
|
||||
@ -151,4 +150,10 @@ public class DiscJockeyScreen extends Screen {
|
||||
public boolean shouldPause() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
super.close();
|
||||
new Thread(() -> Main.configHolder.save()).start();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user