From 6d29f58ebdfc4d60d95b0187cc6f08937ea22147 Mon Sep 17 00:00:00 2001 From: coolGi Date: Fri, 17 Mar 2023 22:29:28 +1030 Subject: [PATCH] Fixed up more things to do with JavaFX, and added some extra stuff for the MinecraftScreen --- build.gradle | 29 ++++++++++++------- .../common/wrappers/gui/GetConfigScreen.java | 19 +++++++----- .../common/wrappers/gui/MinecraftScreen.java | 15 ++++++++-- gradle.properties | 2 +- 4 files changed, 44 insertions(+), 21 deletions(-) diff --git a/build.gradle b/build.gradle index 5efdd2bd0..64f32c55f 100644 --- a/build.gradle +++ b/build.gradle @@ -99,14 +99,13 @@ subprojects { p -> // Apply plugins apply plugin: "java" + apply plugin: "com.github.johnrengelman.shadow" + apply plugin: "org.openjfx.javafxplugin" if (isMinecraftSubProject) apply plugin: "systems.manifold.manifold-gradle-plugin" - apply plugin: "com.github.johnrengelman.shadow" -// apply plugin: "org.spongepowered.gradle.vanilla" // Provides minecraft libraries - if (p == project(":core")) { + if (p == project(":core")) apply plugin: "application" - apply plugin: "org.openjfx.javafxplugin" - } +// apply plugin: "org.spongepowered.gradle.vanilla" // Provides minecraft libraries // Set the manifold version (may not be required tough) @@ -139,11 +138,11 @@ subprojects { p -> application { mainClass.set("com.seibel.lod.core.jar.JarMain") } - - javafx { - version = "19" - modules = ["javafx.controls"] - } + } + // Remember, to shadow it you need to add it in the dependency part + javafx { + version = "${rootProject.javafx_version}" + modules = ["javafx.swing", "javafx.controls", "javafx.graphics"] } dependencies { @@ -177,6 +176,16 @@ subprojects { p -> // SVG shadowMe("com.formdev:svgSalamander:${rootProject.svgSalamander_version}") + + // JavaFX/OpenJFX + // Remember, you also need to define jfx modules in its own jfx thing + // This part of the code is just to shadow the libraries + // FIXME: This doesnt work, find a workaround + shadowMe("org.openjfx:javafx:${rootProject.javafx_version}") + shadowMe("org.openjfx:javafx-base:${rootProject.javafx_version}") + shadowMe("org.openjfx:javafx-swing:${rootProject.javafx_version}") + shadowMe("org.openjfx:javafx-controls:${rootProject.javafx_version}") + shadowMe("org.openjfx:javafx-graphics:${rootProject.javafx_version}") diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/gui/GetConfigScreen.java b/common/src/main/java/com/seibel/lod/common/wrappers/gui/GetConfigScreen.java index 39452465f..871ad0579 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/gui/GetConfigScreen.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/gui/GetConfigScreen.java @@ -2,22 +2,25 @@ package com.seibel.lod.common.wrappers.gui; import com.seibel.lod.core.ModInfo; import com.seibel.lod.core.config.ConfigBase; -import com.seibel.lod.core.config.gui.ConfigScreen; +import com.seibel.lod.core.config.gui.JavaFXConfigScreen; +import com.seibel.lod.core.config.gui.OpenGLConfigScreen; import net.minecraft.client.gui.screens.Screen; public class GetConfigScreen { public static type useScreen = type.Classic; public static enum type { Classic, - OpenGL; + @Deprecated + OpenGL, // This was jsut an attempt, it didnt work out and we are going to change to javafx soon + JavaFX; } public static Screen getScreen(Screen parent) { - if (useScreen == type.Classic) { - return ClassicConfigGUI.getScreen(ConfigBase.INSTANCE, parent, "client"); - } else if (useScreen == type.OpenGL) { - return MinecraftScreen.getScreen(parent, new ConfigScreen(), ModInfo.ID + ".title"); - } - return null; + return switch (useScreen) { + case Classic -> ClassicConfigGUI.getScreen(ConfigBase.INSTANCE, parent, "client"); + case OpenGL -> MinecraftScreen.getScreen(parent, new OpenGLConfigScreen(), ModInfo.ID + ".title"); + case JavaFX -> MinecraftScreen.getScreen(parent, new JavaFXConfigScreen(), ModInfo.ID + ".title"); + default -> null; + }; } } \ No newline at end of file diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/gui/MinecraftScreen.java b/common/src/main/java/com/seibel/lod/common/wrappers/gui/MinecraftScreen.java index a7bc9e154..67e068b63 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/gui/MinecraftScreen.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/gui/MinecraftScreen.java @@ -5,7 +5,9 @@ import com.seibel.lod.core.config.gui.AbstractScreen; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.components.ContainerObjectSelectionList; import net.minecraft.client.gui.screens.Screen; +import org.jetbrains.annotations.NotNull; +import java.nio.file.Path; import java.util.*; public class MinecraftScreen { @@ -53,8 +55,6 @@ public class MinecraftScreen { this.renderBackground(matrices); // Render background this.list.render(matrices, mouseX, mouseY, delta); // Renders the items in the render list (currently only used to tint background darker) - screen.width = this.width; // Is there a way to only call this when the window changes the size - screen.height = this.height; // Is there a way to only call this when the window changes the size screen.mouseX = mouseX; screen.mouseY = mouseY; screen.render(delta); // Render everything on the main screen @@ -62,6 +62,12 @@ public class MinecraftScreen { super.render(matrices, mouseX, mouseY, delta); // Render the vanilla stuff (currently only used for the background and tint) } + @Override + public void resize(Minecraft mc, int width, int height) { + screen.width = this.width; + screen.height = this.height; + } + @Override public void tick() { screen.tick(); @@ -75,6 +81,11 @@ public class MinecraftScreen { Objects.requireNonNull(minecraft).setScreen(this.parent); // Goto the parent screen } + @Override + public void onFilesDrop(@NotNull List files) { + screen.onFilesDrop(files); + } + // For checking if it should close when you press the escape key @Override public boolean shouldCloseOnEsc() { diff --git a/gradle.properties b/gradle.properties index d36440e95..99826eb34 100644 --- a/gradle.properties +++ b/gradle.properties @@ -19,7 +19,7 @@ mod_discord=https://discord.gg/xAB8G4cENx manifold_version=2023.1.0 toml_version=3.6.4 nightconfig_version=3.6.6 -flatlaf_version=2.3 +javafx_version=19 svgSalamander_version=1.1.3 log4j_version=2.19.0