MidnightLib 1.5.5

- Fixed button always being visible
- Various visual improvements
This commit is contained in:
Martin Prokoph
2024-05-04 17:59:06 +02:00
parent 64ccaf6195
commit d75d34d675
9 changed files with 91 additions and 39 deletions

View File

@@ -1,6 +1,7 @@
plugins { plugins {
id "architectury-plugin" version "3.4-SNAPSHOT" id "architectury-plugin" version "3.4-SNAPSHOT"
id "dev.architectury.loom" version "1.6-SNAPSHOT" apply false id "dev.architectury.loom" version "1.6-SNAPSHOT" apply false
id "me.shedaniel.unified-publishing" version "0.1.+" apply false
} }
architectury { architectury {
@@ -36,7 +37,22 @@ allprojects {
tasks.withType(JavaCompile) { tasks.withType(JavaCompile) {
options.encoding = "UTF-8" options.encoding = "UTF-8"
options.release = 17 options.release = 21
}
ext {
releaseChangelog = {
def changes = new StringBuilder()
changes << "## MidnightLib v$project.version for $project.minecraft_version\n[View the changelog](https://www.github.com/TeamMidnightDust/MidnightLib/commits/)"
def proc = "git log --max-count=1 --pretty=format:%s".execute()
proc.in.eachLine { line ->
def processedLine = line.toString()
if (!processedLine.contains("New translations") && !processedLine.contains("Merge") && !processedLine.contains("branch")) {
changes << "\n- ${processedLine.capitalize()}"
}
}
proc.waitFor()
return changes.toString()
}
} }
java { java {

View File

@@ -26,23 +26,24 @@ public class MixinOptionsScreen extends Screen {
@Unique TextIconButtonWidget button = TextIconButtonWidget.builder(Text.translatable("midnightlib.overview.title"), ( @Unique TextIconButtonWidget button = TextIconButtonWidget.builder(Text.translatable("midnightlib.overview.title"), (
buttonWidget) -> Objects.requireNonNull(client).setScreen(new MidnightConfigOverviewScreen(this)), true) buttonWidget) -> Objects.requireNonNull(client).setScreen(new MidnightConfigOverviewScreen(this)), true)
.texture(new Identifier("midnightlib","icon/midnightlib"), 16, 16).dimension(20, 20).build(); .texture(new Identifier("midnightlib","icon/midnightlib"), 16, 16).dimension(20, 20).build();
@Unique boolean shouldShowButton = MidnightLibConfig.config_screen_list.equals(MidnightLibConfig.ConfigButton.TRUE) || (MidnightLibConfig.config_screen_list.equals(MidnightLibConfig.ConfigButton.MODMENU) && !PlatformFunctions.isModLoaded("modmenu"));
protected MixinOptionsScreen(Text title) {super(title);} protected MixinOptionsScreen(Text title) {super(title);}
@Inject(at = @At("HEAD"), method = "init") @Inject(at = @At("HEAD"), method = "init")
public void midnightlib$onInit(CallbackInfo ci) { public void midnightlib$onInit(CallbackInfo ci) {
this.midnightlib$setupButton(); if (shouldShowButton) {
this.addDrawableChild(button); this.midnightlib$setupButton();
this.addDrawableChild(button);
}
} }
@Override @Override
public void resize(MinecraftClient client, int width, int height) { public void resize(MinecraftClient client, int width, int height) {
super.resize(client, width, height); super.resize(client, width, height);
this.midnightlib$setupButton(); if (shouldShowButton) this.midnightlib$setupButton();
} }
@Unique @Unique
public void midnightlib$setupButton() { public void midnightlib$setupButton() {
if (MidnightLibConfig.config_screen_list.equals(MidnightLibConfig.ConfigButton.TRUE) || (MidnightLibConfig.config_screen_list.equals(MidnightLibConfig.ConfigButton.MODMENU) && !PlatformFunctions.isModLoaded("modmenu"))) { button.setPosition(layout.getWidth() / 2 + 158, layout.getY() + layout.getFooterHeight() - 4);
button.setPosition(layout.getWidth() / 2 + 158, layout.getY() + layout.getFooterHeight() - 4);
}
} }
} }

View File

@@ -26,7 +26,7 @@ public class MidnightConfigOverviewScreen extends Screen {
protected void init() { protected void init() {
this.addDrawableChild(ButtonWidget.builder(ScreenTexts.DONE, (button) -> Objects.requireNonNull(client).setScreen(parent)).dimensions(this.width / 2 - 100, this.height - 26, 200, 20).build()); this.addDrawableChild(ButtonWidget.builder(ScreenTexts.DONE, (button) -> Objects.requireNonNull(client).setScreen(parent)).dimensions(this.width / 2 - 100, this.height - 26, 200, 20).build());
this.list = new MidnightConfig.MidnightConfigListWidget(this.client, this.width, this.height - 64, 24, 25); this.list = new MidnightConfig.MidnightConfigListWidget(this.client, this.width, this.height - 57, 24, 25);
this.addSelectableChild(this.list); this.addSelectableChild(this.list);
List<String> sortedMods = new ArrayList<>(MidnightConfig.configClass.keySet()); List<String> sortedMods = new ArrayList<>(MidnightConfig.configClass.keySet());
Collections.sort(sortedMods); Collections.sort(sortedMods);

View File

@@ -5,6 +5,7 @@ import com.google.gson.ExclusionStrategy;
import com.google.gson.FieldAttributes; import com.google.gson.FieldAttributes;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import com.mojang.blaze3d.systems.RenderSystem;
import eu.midnightdust.lib.util.PlatformFunctions; import eu.midnightdust.lib.util.PlatformFunctions;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
@@ -167,7 +168,7 @@ public abstract class MidnightConfig {
info.value = isNumber? value : s; info.value = isNumber? value : s;
else if (inLimits) { else if (inLimits) {
if (((List<String>) info.value).size() == info.index) ((List<String>) info.value).add(""); if (((List<String>) info.value).size() == info.index) ((List<String>) info.value).add("");
((List<String>) info.value).set(info.index, Arrays.stream(info.tempValue.replace("[", "").replace("]", "").split(", ")).toList().get(0)); ((List<String>) info.value).set(info.index, Arrays.stream(info.tempValue.replace("[", "").replace("]", "").split(", ")).toList().getFirst());
} }
if (info.field.getAnnotation(Entry.class).isColor()) { if (info.field.getAnnotation(Entry.class).isColor()) {
@@ -303,7 +304,7 @@ public abstract class MidnightConfig {
Objects.requireNonNull(client).setScreen(parent); Objects.requireNonNull(client).setScreen(parent);
}).dimensions(this.width / 2 + 4, this.height - 26, 150, 20).build()); }).dimensions(this.width / 2 + 4, this.height - 26, 150, 20).build());
this.list = new MidnightConfigListWidget(this.client, this.width, this.height - 64, 24, 25); this.list = new MidnightConfigListWidget(this.client, this.width, this.height - 57, 24, 25);
this.addSelectableChild(this.list); this.addSelectableChild(this.list);
fillList(); fillList();
@@ -383,17 +384,30 @@ public abstract class MidnightConfig {
super.render(context,mouseX,mouseY,delta); super.render(context,mouseX,mouseY,delta);
this.list.render(context, mouseX, mouseY, delta); this.list.render(context, mouseX, mouseY, delta);
if (tabs.size() < 2) context.drawCenteredTextWithShadow(textRenderer, title, width / 2, 10, 0xFFFFFF); if (tabs.size() < 2)
context.drawCenteredTextWithShadow(textRenderer, title, width / 2, 10, 0xFFFFFF);
list.renderHeaderSeperator = tabs.size() < 2;
} }
} }
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public static class MidnightConfigListWidget extends ElementListWidget<ButtonEntry> { public static class MidnightConfigListWidget extends ElementListWidget<ButtonEntry> {
boolean renderHeaderSeperator = true;
public MidnightConfigListWidget(MinecraftClient client, int width, int height, int y, int itemHeight) { public MidnightConfigListWidget(MinecraftClient client, int width, int height, int y, int itemHeight) {
super(client, width, height, y, itemHeight); super(client, width, height, y, itemHeight);
} }
@Override @Override
public int getScrollbarX() { return this.width -7; } public int getScrollbarX() { return this.width -7; }
@Override
protected void drawHeaderAndFooterSeparators(DrawContext context) {
if (renderHeaderSeperator) super.drawHeaderAndFooterSeparators(context);
else {
RenderSystem.enableBlend();
context.drawTexture(this.client.world == null ? Screen.FOOTER_SEPARATOR_TEXTURE : Screen.INWORLD_FOOTER_SEPARATOR_TEXTURE, this.getX(), this.getBottom(), 0.0F, 0.0F, this.getWidth(), 2, 32, 2);
RenderSystem.disableBlend();
}
}
public void addButton(List<ClickableWidget> buttons, Text text, EntryInfo info) { public void addButton(List<ClickableWidget> buttons, Text text, EntryInfo info) {
this.addEntry(new ButtonEntry(buttons, text, info)); this.addEntry(new ButtonEntry(buttons, text, info));
} }
@@ -406,20 +420,22 @@ public abstract class MidnightConfig {
public final List<ClickableWidget> buttons; public final List<ClickableWidget> buttons;
private final Text text; private final Text text;
public final EntryInfo info; public final EntryInfo info;
public boolean centered = false;
public static final Map<ClickableWidget, Text> buttonsWithText = new HashMap<>(); public static final Map<ClickableWidget, Text> buttonsWithText = new HashMap<>();
private ButtonEntry(List<ClickableWidget> buttons, Text text, EntryInfo info) { public ButtonEntry(List<ClickableWidget> buttons, Text text, EntryInfo info) {
if (!buttons.isEmpty()) buttonsWithText.put(buttons.get(0),text); if (!buttons.isEmpty()) buttonsWithText.put(buttons.getFirst(),text);
this.buttons = buttons; this.buttons = buttons;
this.text = text; this.text = text;
this.info = info; this.info = info;
if (info != null) this.centered = info.centered;
} }
public void render(DrawContext context, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) { public void render(DrawContext context, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) {
buttons.forEach(b -> { b.setY(y); b.render(context, mouseX, mouseY, tickDelta); }); buttons.forEach(b -> { b.setY(y); b.render(context, mouseX, mouseY, tickDelta); });
if (text != null && (!text.getString().contains("spacer") || !buttons.isEmpty())) { if (text != null && (!text.getString().contains("spacer") || !buttons.isEmpty())) {
int wrappedY = y; int wrappedY = y;
for(Iterator<OrderedText> textIterator = textRenderer.wrapLines(text, (buttons.size() > 1 ? buttons.get(1).getX()-24 : MinecraftClient.getInstance().getWindow().getScaledWidth() - 24)).iterator(); textIterator.hasNext(); wrappedY += 9) { for(Iterator<OrderedText> textIterator = textRenderer.wrapLines(text, (buttons.size() > 1 ? buttons.get(1).getX()-24 : MinecraftClient.getInstance().getWindow().getScaledWidth() - 24)).iterator(); textIterator.hasNext(); wrappedY += 9) {
context.drawTextWithShadow(textRenderer, textIterator.next(), (info.centered) ? (MinecraftClient.getInstance().getWindow().getScaledWidth() / 2 - (textRenderer.getWidth(text) / 2)) : 12, wrappedY + 5, 0xFFFFFF); context.drawTextWithShadow(textRenderer, textIterator.next(), (centered) ? (MinecraftClient.getInstance().getWindow().getScaledWidth() / 2 - (textRenderer.getWidth(text) / 2)) : 12, wrappedY + 5, 0xFFFFFF);
} }
} }
} }

View File

@@ -1,5 +1,6 @@
plugins { plugins {
id "com.github.johnrengelman.shadow" version "7.1.2" id "com.github.johnrengelman.shadow" version "7.1.2"
id "me.shedaniel.unified-publishing"
} }
repositories { repositories {
maven { url "https://maven.terraformersmc.com/releases" } maven { url "https://maven.terraformersmc.com/releases" }
@@ -63,16 +64,38 @@ components.java {
} }
} }
publishing { unifiedPublishing {
publications { project {
mavenFabric(MavenPublication) { displayName = "MidnightLib v$project.version - Fabric $project.minecraft_version"
artifactId = archives_base_name + "-" + project.name releaseType = "$project.release_type"
from components.java changelog = releaseChangelog()
gameVersions = []
gameLoaders = ["fabric","quilt"]
mainPublication remapJar
relations {
depends {
curseforge = "fabric-api"
modrinth = "fabric-api"
}
}
var CURSEFORGE_TOKEN = project.findProperty("CURSEFORGE_TOKEN") ?: System.getenv("CURSEFORGE_TOKEN")
if (CURSEFORGE_TOKEN != null) {
curseforge {
token = CURSEFORGE_TOKEN
id = rootProject.curseforge_id
gameVersions.addAll "Java 21", project.minecraft_version
}
}
var MODRINTH_TOKEN = project.findProperty("MODRINTH_TOKEN") ?: System.getenv("MODRINTH_TOKEN")
if (MODRINTH_TOKEN != null) {
modrinth {
token = MODRINTH_TOKEN
id = rootProject.modrinth_id
version = "$project.version-$project.name"
gameVersions.addAll project.minecraft_version
}
} }
} }
// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
repositories {
// Add repositories to publish to here.
}
} }

View File

@@ -1,17 +1,20 @@
org.gradle.jvmargs=-Xmx4096M org.gradle.jvmargs=-Xmx4096M
minecraft_version=1.20.5-rc2 minecraft_version=1.20.6
yarn_mappings=1.20.5-rc2+build.2 yarn_mappings=1.20.6+build.1
enabled_platforms=fabric enabled_platforms=fabric
archives_base_name=midnightlib archives_base_name=midnightlib
mod_version=1.5.4 mod_version=1.5.5
maven_group=eu.midnightdust maven_group=eu.midnightdust
release_type=release
curseforge_id=488090
modrinth_id=codAaoxh
fabric_loader_version=0.15.10 fabric_loader_version=0.15.11
fabric_api_version=0.97.4+1.20.5 fabric_api_version=0.97.8+1.20.6
neoforge_version=20.4.12-beta neoforge_version=20.6.30-beta
quilt_loader_version=0.19.0-beta.18 quilt_loader_version=0.19.0-beta.18
quilt_fabric_api_version=7.0.1+0.83.0-1.20 quilt_fabric_api_version=7.0.1+0.83.0-1.20

View File

@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

View File

@@ -23,6 +23,6 @@ public class PlatformFunctionsImpl {
return ModList.get().isLoaded(modid); return ModList.get().isLoaded(modid);
} }
public static void registerCommand(LiteralArgumentBuilder<ServerCommandSource> command) { public static void registerCommand(LiteralArgumentBuilder<ServerCommandSource> command) {
// Ignored here, see MidnightLibServerEvents#registerCommands // Ignored here, see MidnightLibNeoForge#registerCommands
} }
} }

View File

@@ -38,13 +38,6 @@ public class MidnightLibNeoForge {
}); });
} }
} }
@Mod.EventBusSubscriber(modid = "midnightlib", value = Dist.CLIENT)
public static class MidnightLibClientEvents {
@SubscribeEvent
public static void afterInitScreen(ScreenEvent.Init.Post event) {
MidnightConfigOverviewScreen.addButtonToOptionsScreen(event.getScreen(), event.getScreen().getMinecraft());
}
}
@Mod.EventBusSubscriber(modid = "midnightlib", value = Dist.DEDICATED_SERVER) @Mod.EventBusSubscriber(modid = "midnightlib", value = Dist.DEDICATED_SERVER)
public static class MidnightLibServerEvents { public static class MidnightLibServerEvents {