diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 00ae35f..2a0fe00 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -44,11 +44,6 @@ jobs: cd example-mod16-forge chmod +x gradlew ./gradlew build - - name: Build ExampleMod8-Fabric - run: | - cd example-mod8-fabric - chmod +x gradlew - ./gradlew build - name: Build ExampleMod8-Forge run: | cd example-mod8-forge diff --git a/.github/workflows/mc17.yml b/.github/workflows/mc17.yml index df917b0..0e7fb12 100644 --- a/.github/workflows/mc17.yml +++ b/.github/workflows/mc17.yml @@ -27,11 +27,21 @@ jobs: ${{ runner.os }}-gradle- - name: Grant execute permission for gradlew run: chmod +x gradlew - - name: Build with Gradle + - name: Build PanelStudio-MC17 run: | cd panelstudio-mc17 chmod +x gradlew ./gradlew build + - name: Build PanelStudio-MC19 + run: | + cd panelstudio-mc19 + chmod +x gradlew + ./gradlew build + - name: Build ExampleMod8-Fabric + run: | + cd example-mod8-fabric + chmod +x gradlew + ./gradlew build - name: Build ExampleMod17 run: | cd example-mod17 @@ -42,6 +52,11 @@ jobs: cd example-mod18 chmod +x gradlew ./gradlew build + - name: Build ExampleMod19 + run: | + cd example-mod19 + chmod +x gradlew + ./gradlew build - name: Upload package uses: actions/upload-artifact@v2 with: diff --git a/LICENSE b/LICENSE index 3940f8d..10c6417 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020,2021 lukflug +Copyright (c) 2020,2021,2022 lukflug and contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 0e57713..f06f28e 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ In addition to the core PanelStudio library, there are the PanelStudio-MC suppor | panelstudio-mc8-fabric | example-mod8-fabric | Legacy Fabric 1.8.9 | | panelstudio-mc8-forge | example-mod8-forge | Minecraft Forge 1.8.9 | | panelstudio-mc17 | example-mod17 & example-mod18 | FabricMC 1.17.1 & 1.18.2 | +| panelstudio-mc19 | example-mod19 | FabricMC 1.19.2 | Minecraft versions or APIs not in this table can also be used with PanelStudio, but the small PanelStudio-MC library has to be ported, which shouldn't be hard in most cases. @@ -19,6 +20,7 @@ Minecraft versions or APIs not in this table can also be used with PanelStudio, * Thanks to NirvanaNevermind for making the original port of PanelStudio-MC to Fabric 1.8.9! * Thanks to Go_Hoosiers (aka. GooberTown or IUDevman) for designing the original PanelStudio logo! * Thanks to Chomp for making a pull request to change the readme, I guess. +* Thanks to Diliard for porting PanelStudio-MC to Fabric 1.19.2! ## Features * Everything is flexible and can be extended. diff --git a/example-mod16-fabric/gradle.properties b/example-mod16-fabric/gradle.properties index 6f51b03..015f420 100644 --- a/example-mod16-fabric/gradle.properties +++ b/example-mod16-fabric/gradle.properties @@ -2,7 +2,7 @@ org.gradle.jvmargs = -Xmx2500m version = 0.2.1 versionmc = 0.2.0 -loomVersion = 0.7.34 +loomVersion = 0.7.35 minecraft16fabric = 1.16.5 mappings16fabric = 1.16.5+build.10 loader16fabric = 0.13.3 diff --git a/example-mod16-forge/gradle.properties b/example-mod16-forge/gradle.properties index ab3f0c0..e63b572 100644 --- a/example-mod16-forge/gradle.properties +++ b/example-mod16-forge/gradle.properties @@ -2,6 +2,6 @@ org.gradle.jvmargs = -Xmx2500m version = 0.2.1 versionmc = 0.2.0 -forgeGradle5 = 5.1.31 +forgeGradle5 = 5.1.56 mappings16forge = 20210309-1.16.5 -minecraft16forge = 1.16.5-36.2.20 +minecraft16forge = 1.16.5-36.2.34 diff --git a/example-mod17/build.gradle b/example-mod17/build.gradle index 4975722..079c045 100644 --- a/example-mod17/build.gradle +++ b/example-mod17/build.gradle @@ -51,7 +51,7 @@ processResources { shadowJar { classifier = "dev" configurations = [project.configurations.shadow] - relocate "com.lukflug.panelstudio","com.lukflug.panelstudio_0_2_2" + relocate "com.lukflug.panelstudio","com.lukflug.panelstudio_0_2_3" } remapJar { diff --git a/example-mod17/gradle.properties b/example-mod17/gradle.properties index 243600b..a40aef2 100644 --- a/example-mod17/gradle.properties +++ b/example-mod17/gradle.properties @@ -1,9 +1,9 @@ org.gradle.jvmargs = -Xmx2500m version = 0.2.1 -versionmc = 0.2.2 +versionmc = 0.2.3 -loomVersion = 0.12.1 +loomVersion = 1.0.11 minecraft17 = 1.17.1 mappings17 = 1.17.1+build.65 -loader17 = 0.13.3 +loader17 = 0.14.10 api17 = 0.46.1+1.17 diff --git a/example-mod18/build.gradle b/example-mod18/build.gradle index 55fa5e8..bb5d25b 100644 --- a/example-mod18/build.gradle +++ b/example-mod18/build.gradle @@ -51,7 +51,7 @@ processResources { shadowJar { classifier = "dev" configurations = [project.configurations.shadow] - relocate "com.lukflug.panelstudio","com.lukflug.panelstudio_0_2_2" + relocate "com.lukflug.panelstudio","com.lukflug.panelstudio_0_2_3" } remapJar { diff --git a/example-mod18/gradle.properties b/example-mod18/gradle.properties index 5d62380..c10cfbb 100644 --- a/example-mod18/gradle.properties +++ b/example-mod18/gradle.properties @@ -1,9 +1,9 @@ org.gradle.jvmargs = -Xmx2500m version = 0.2.1 -versionmc = 0.2.2 +versionmc = 0.2.3 -loomVersion = 0.12.1 +loomVersion = 1.0.11 minecraft18 = 1.18.2 -mappings18 = 1.18.2+build.2 -loader18 = 0.13.3 -api18 = 0.47.10+1.18.2 +mappings18 = 1.18.2+build.4 +loader18 = 0.14.10 +api18 = 0.48.0+1.18.2 diff --git a/example-mod19/build.gradle b/example-mod19/build.gradle new file mode 100644 index 0000000..53de1bb --- /dev/null +++ b/example-mod19/build.gradle @@ -0,0 +1,63 @@ + +buildscript { + repositories { + gradlePluginPortal() + maven { + name = "Fabric" + url = "https://maven.fabricmc.net/" + } + flatDir { + dirs 'libs' + } + } + dependencies { + classpath "net.fabricmc:fabric-loom:${loomVersion}" + classpath "gradle.plugin.com.github.jengelman.gradle.plugins:shadow:7.0.0" + } +} + +apply plugin: "fabric-loom" +apply plugin: "com.github.johnrengelman.shadow" + +configurations { + shadow + modImplementation.extendsFrom shadow +} + +repositories { + maven { + name = "lukflug" + url = "https://lukflug.github.io/maven/" + } +} + + +loom { +} + +dependencies { + minecraft "com.mojang:minecraft:${minecraft19}" + mappings "net.fabricmc:yarn:${mappings19}:v2" + modImplementation "net.fabricmc:fabric-loader:${loader19}" + modImplementation "net.fabricmc.fabric-api:fabric-api:${api19}" + shadow "com.lukflug:panelstudio:${version}" + shadow "com.lukflug:panelstudio-mc19:${versionmc}" +} + +processResources { + inputs.property "version", project.version + filesMatching("fabric.mod.json") { + expand "version": project.version + } +} + +shadowJar { + classifier = "dev" + configurations = [project.configurations.shadow] + relocate "com.lukflug.panelstudio","com.lukflug.panelstudio_0_2_3" +} + +remapJar { + dependsOn shadowJar + inputFile = shadowJar.archiveFile +} diff --git a/example-mod19/gradle.properties b/example-mod19/gradle.properties new file mode 100644 index 0000000..9e37102 --- /dev/null +++ b/example-mod19/gradle.properties @@ -0,0 +1,9 @@ +org.gradle.jvmargs = -Xmx2500m +version = 0.2.1 +versionmc = 0.2.3 + +loomVersion = 1.0.11 +minecraft19 = 1.19.2 +mappings19 = 1.19.2+build.28 +loader19 = 0.14.10 +api19 = 0.64.0+1.19.2 diff --git a/example-mod19/gradle/wrapper/gradle-wrapper.jar b/example-mod19/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..f3d88b1 Binary files /dev/null and b/example-mod19/gradle/wrapper/gradle-wrapper.jar differ diff --git a/example-mod19/gradle/wrapper/gradle-wrapper.properties b/example-mod19/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..41dfb87 --- /dev/null +++ b/example-mod19/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/example-mod19/gradlew b/example-mod19/gradlew new file mode 100644 index 0000000..2fe81a7 --- /dev/null +++ b/example-mod19/gradlew @@ -0,0 +1,183 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/example-mod19/gradlew.bat b/example-mod19/gradlew.bat new file mode 100644 index 0000000..62bd9b9 --- /dev/null +++ b/example-mod19/gradlew.bat @@ -0,0 +1,103 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/example-mod19/settings.gradle b/example-mod19/settings.gradle new file mode 100644 index 0000000..e69de29 diff --git a/example-mod19/src/main/java/com/lukflug/examplemod19/ClickGUI.java b/example-mod19/src/main/java/com/lukflug/examplemod19/ClickGUI.java new file mode 100644 index 0000000..a08846c --- /dev/null +++ b/example-mod19/src/main/java/com/lukflug/examplemod19/ClickGUI.java @@ -0,0 +1,495 @@ +package com.lukflug.examplemod19; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Point; +import java.awt.Rectangle; +import java.util.EnumMap; +import java.util.Map; +import java.util.concurrent.atomic.AtomicReference; +import java.util.function.BiFunction; +import java.util.function.Function; +import java.util.function.IntFunction; +import java.util.function.IntPredicate; +import java.util.function.Supplier; + +import org.lwjgl.glfw.GLFW; + +import com.lukflug.examplemod19.module.Category; +import com.lukflug.examplemod19.module.ClickGUIModule; +import com.lukflug.examplemod19.module.ClickGUIModule.Theme; +import com.lukflug.examplemod19.module.HUDEditorModule; +import com.lukflug.examplemod19.module.LogoModule; +import com.lukflug.examplemod19.module.TabGUIModule; +import com.lukflug.examplemod19.module.WatermarkModule; +import com.lukflug.examplemod19.setting.BooleanSetting; +import com.lukflug.examplemod19.setting.ColorSetting; +import com.lukflug.examplemod19.setting.IntegerSetting; +import com.lukflug.panelstudio.base.Animation; +import com.lukflug.panelstudio.base.Context; +import com.lukflug.panelstudio.base.IBoolean; +import com.lukflug.panelstudio.base.IInterface; +import com.lukflug.panelstudio.base.IToggleable; +import com.lukflug.panelstudio.base.SettingsAnimation; +import com.lukflug.panelstudio.base.SimpleToggleable; +import com.lukflug.panelstudio.component.IComponent; +import com.lukflug.panelstudio.component.IFixedComponent; +import com.lukflug.panelstudio.component.IResizable; +import com.lukflug.panelstudio.component.IScrollSize; +import com.lukflug.panelstudio.container.IContainer; +import com.lukflug.panelstudio.hud.HUDGUI; +import com.lukflug.panelstudio.layout.CSGOLayout; +import com.lukflug.panelstudio.layout.ChildUtil.ChildMode; +import com.lukflug.panelstudio.layout.ComponentGenerator; +import com.lukflug.panelstudio.layout.IComponentAdder; +import com.lukflug.panelstudio.layout.IComponentGenerator; +import com.lukflug.panelstudio.layout.ILayout; +import com.lukflug.panelstudio.layout.PanelAdder; +import com.lukflug.panelstudio.layout.PanelLayout; +import com.lukflug.panelstudio.layout.SearchableLayout; +import com.lukflug.panelstudio.layout.SinglePanelAdder; +import com.lukflug.panelstudio.layout.StackedPanelAdder; +import com.lukflug.panelstudio.mc19.MinecraftHUDGUI; +import com.lukflug.panelstudio.popup.CenteredPositioner; +import com.lukflug.panelstudio.popup.IPopupPositioner; +import com.lukflug.panelstudio.popup.MousePositioner; +import com.lukflug.panelstudio.popup.PanelPositioner; +import com.lukflug.panelstudio.popup.PopupTuple; +import com.lukflug.panelstudio.setting.IBooleanSetting; +import com.lukflug.panelstudio.setting.IClient; +import com.lukflug.panelstudio.setting.IColorSetting; +import com.lukflug.panelstudio.setting.IEnumSetting; +import com.lukflug.panelstudio.setting.INumberSetting; +import com.lukflug.panelstudio.setting.Labeled; +import com.lukflug.panelstudio.theme.ClearTheme; +import com.lukflug.panelstudio.theme.GameSenseTheme; +import com.lukflug.panelstudio.theme.IColorScheme; +import com.lukflug.panelstudio.theme.ITheme; +import com.lukflug.panelstudio.theme.IThemeMultiplexer; +import com.lukflug.panelstudio.theme.ImpactTheme; +import com.lukflug.panelstudio.theme.OptimizedTheme; +import com.lukflug.panelstudio.theme.RainbowTheme; +import com.lukflug.panelstudio.theme.ThemeTuple; +import com.lukflug.panelstudio.theme.Windows31Theme; +import com.lukflug.panelstudio.widget.ColorPickerComponent; +import com.lukflug.panelstudio.widget.CycleSwitch; +import com.lukflug.panelstudio.widget.DropDownList; +import com.lukflug.panelstudio.widget.ITextFieldKeys; +import com.lukflug.panelstudio.widget.Spinner; +import com.lukflug.panelstudio.widget.ToggleSwitch; + +import net.minecraft.util.Formatting; + +public class ClickGUI extends MinecraftHUDGUI { + private final GUIInterface inter; + private final HUDGUI gui; + public static final int WIDTH=120,HEIGHT=12,DISTANCE=6,BORDER=2; + + public ClickGUI() { + // Getting client structure ... + IClient client=Category.getClient(); + /* Set to false to disable horizontal clipping, this may cause graphical glitches, + * but will let you see long text, even if it is too long to fit in the panel. */ + inter=new GUIInterface(true) { + @Override + protected String getResourcePrefix() { + return "examplemod:"; + } + }; + // Instantiating theme ... + ITheme theme=new OptimizedTheme(new ThemeSelector(inter)); + // Instantiating GUI ... + IToggleable guiToggle=new SimpleToggleable(false); + IToggleable hudToggle=new SimpleToggleable(false) { + @Override + public boolean isOn() { + return guiToggle.isOn()?HUDEditorModule.showHUD.isOn():super.isOn(); + } + }; + gui=new HUDGUI(inter,theme.getDescriptionRenderer(),(IPopupPositioner)new MousePositioner(new Point(10,10)),guiToggle,hudToggle); + // Creating animation ... + Supplier animation=()->new SettingsAnimation(()->ClickGUIModule.animationSpeed.getValue(),()->inter.getTime()); + // Populating HUD ... + gui.addHUDComponent(TabGUIModule.getComponent(client,new IContainer() { + @Override + public boolean addComponent (IFixedComponent component) { + return gui.addHUDComponent(component,()->true); + } + + @Override + public boolean addComponent (IFixedComponent component, IBoolean visible) { + return gui.addHUDComponent(component,visible); + } + + @Override + public boolean removeComponent (IFixedComponent component) { + return gui.removeComponent(component); + } + },animation),TabGUIModule.getToggle(),animation.get(),theme,BORDER); + gui.addHUDComponent(WatermarkModule.getComponent(),WatermarkModule.getToggle(),animation.get(),theme,BORDER); + gui.addHUDComponent(LogoModule.getComponent(inter),LogoModule.getToggle(),animation.get(),theme,BORDER); + + // Creating popup types ... + BiFunction scrollHeight=(context,componentHeight)->Math.min(componentHeight,Math.max(HEIGHT*4,ClickGUI.this.height-context.getPos().y-HEIGHT)); + PopupTuple popupType=new PopupTuple(new PanelPositioner(new Point(0,0)),false,new IScrollSize() { + @Override + public int getScrollHeight (Context context, int componentHeight) { + return scrollHeight.apply(context,componentHeight); + } + }); + PopupTuple colorPopup=new PopupTuple(new CenteredPositioner(()->new Rectangle(new Point(0,0),inter.getWindowSize())),true,new IScrollSize() { + @Override + public int getScrollHeight (Context context, int componentHeight) { + return scrollHeight.apply(context,componentHeight); + } + }); + // Defining resize behavior ... + IntFunction resizable=width->new IResizable() { + Dimension size=new Dimension(width,320); + + @Override + public Dimension getSize() { + return new Dimension(size); + } + + @Override + public void setSize (Dimension size) { + this.size.width=size.width; + this.size.height=size.height; + if (size.width<75) this.size.width=75; + if (size.height<50) this.size.height=50; + } + }; + // Defining scroll behavior ... + Function resizableHeight=size->new IScrollSize() { + @Override + public int getScrollHeight (Context context, int componentHeight) { + return size.getSize().height; + } + }; + // Defining function keys ... + IntPredicate keybindKey=scancode->scancode==GLFW.GLFW_KEY_DELETE; + IntPredicate charFilter=character->{ + return character>=' '; + }; + ITextFieldKeys keys=new ITextFieldKeys() { + @Override + public boolean isBackspaceKey (int scancode) { + return scancode==GLFW.GLFW_KEY_BACKSPACE; + } + + @Override + public boolean isDeleteKey (int scancode) { + return scancode==GLFW.GLFW_KEY_DELETE; + } + + @Override + public boolean isInsertKey (int scancode) { + return scancode==GLFW.GLFW_KEY_INSERT; + } + + @Override + public boolean isLeftKey (int scancode) { + return scancode==GLFW.GLFW_KEY_LEFT; + } + + @Override + public boolean isRightKey (int scancode) { + return scancode==GLFW.GLFW_KEY_RIGHT; + } + + @Override + public boolean isHomeKey (int scancode) { + return scancode==GLFW.GLFW_KEY_HOME; + } + + @Override + public boolean isEndKey (int scancode) { + return scancode==GLFW.GLFW_KEY_END; + } + + @Override + public boolean isCopyKey (int scancode) { + return scancode==GLFW.GLFW_KEY_C; + } + + @Override + public boolean isPasteKey (int scancode) { + return scancode==GLFW.GLFW_KEY_V; + } + + @Override + public boolean isCutKey (int scancode) { + return scancode==GLFW.GLFW_KEY_X; + } + + @Override + public boolean isAllKey (int scancode) { + return scancode==GLFW.GLFW_KEY_A; + } + }; + + // Normal generator + IComponentGenerator generator=new ComponentGenerator(keybindKey,charFilter,keys); + // Use cycle switches instead of buttons + IComponentGenerator cycleGenerator=new ComponentGenerator(keybindKey,charFilter,keys) { + @Override + public IComponent getEnumComponent (IEnumSetting setting, Supplier animation, IComponentAdder adder, ThemeTuple theme, int colorLevel, boolean isContainer) { + return new CycleSwitch(setting,theme.getCycleSwitchRenderer(isContainer)); + } + }; + // Use all the fancy widgets with text boxes + IComponentGenerator csgoGenerator=new ComponentGenerator(keybindKey,charFilter,keys) { + @Override + public IComponent getBooleanComponent (IBooleanSetting setting, Supplier animation, IComponentAdder adder, ThemeTuple theme, int colorLevel, boolean isContainer) { + return new ToggleSwitch(setting,theme.getToggleSwitchRenderer(isContainer)); + } + + @Override + public IComponent getEnumComponent (IEnumSetting setting, Supplier animation, IComponentAdder adder, ThemeTuple theme, int colorLevel, boolean isContainer) { + return new DropDownList(setting,theme,isContainer,false,keys,new IScrollSize(){},adder::addPopup) { + @Override + protected Animation getAnimation() { + return animation.get(); + } + + @Override + public boolean allowCharacter (char character) { + return charFilter.test(character); + } + + @Override + protected boolean isUpKey (int key) { + return key==GLFW.GLFW_KEY_UP; + } + + @Override + protected boolean isDownKey (int key) { + return key==GLFW.GLFW_KEY_DOWN; + } + + @Override + protected boolean isEnterKey (int key) { + return key==GLFW.GLFW_KEY_ENTER; + } + }; + } + + @Override + public IComponent getNumberComponent (INumberSetting setting, Supplier animation, IComponentAdder adder, ThemeTuple theme, int colorLevel, boolean isContainer) { + return new Spinner(setting,theme,isContainer,true,keys); + } + + @Override + public IComponent getColorComponent (IColorSetting setting, Supplier animation, IComponentAdder adder, ThemeTuple theme, int colorLevel, boolean isContainer) { + return new ColorPickerComponent(setting,new ThemeTuple(theme.theme,theme.logicalLevel,colorLevel)); + } + }; + + // Classic Panel + IComponentAdder classicPanelAdder=new PanelAdder(gui,false,()->ClickGUIModule.layout.getValue()==ClickGUIModule.Layout.ClassicPanel,title->"classicPanel_"+title) { + @Override + protected IResizable getResizable (int width) { + return resizable.apply(width); + } + + @Override + protected IScrollSize getScrollSize (IResizable size) { + return resizableHeight.apply(size); + } + }; + ILayout classicPanelLayout=new PanelLayout(WIDTH,new Point(DISTANCE,DISTANCE),(WIDTH+DISTANCE)/2,HEIGHT+DISTANCE,animation,level->ChildMode.DOWN,level->ChildMode.DOWN,popupType); + classicPanelLayout.populateGUI(classicPanelAdder,generator,client,theme); + // Pop-up Panel + IComponentAdder popupPanelAdder=new PanelAdder(gui,false,()->ClickGUIModule.layout.getValue()==ClickGUIModule.Layout.PopupPanel,title->"popupPanel_"+title) { + @Override + protected IResizable getResizable (int width) { + return resizable.apply(width); + } + + @Override + protected IScrollSize getScrollSize (IResizable size) { + return resizableHeight.apply(size); + } + }; + ILayout popupPanelLayout=new PanelLayout(WIDTH,new Point(DISTANCE,DISTANCE),(WIDTH+DISTANCE)/2,HEIGHT+DISTANCE,animation,level->ChildMode.POPUP,level->ChildMode.DOWN,popupType); + popupPanelLayout.populateGUI(popupPanelAdder,generator,client,theme); + // Draggable Panel + IComponentAdder draggablePanelAdder=new PanelAdder(gui,false,()->ClickGUIModule.layout.getValue()==ClickGUIModule.Layout.DraggablePanel,title->"draggablePanel_"+title) { + @Override + protected IResizable getResizable (int width) { + return resizable.apply(width); + } + + @Override + protected IScrollSize getScrollSize (IResizable size) { + return resizableHeight.apply(size); + } + }; + ILayout draggablePanelLayout=new PanelLayout(WIDTH,new Point(DISTANCE,DISTANCE),(WIDTH+DISTANCE)/2,HEIGHT+DISTANCE,animation,level->level==0?ChildMode.DRAG_POPUP:ChildMode.DOWN,level->ChildMode.DOWN,popupType); + draggablePanelLayout.populateGUI(draggablePanelAdder,generator,client,theme); + // Single Panel + IComponentAdder singlePanelAdder=new SinglePanelAdder(gui,new Labeled("Example Menu",null,()->true),theme,new Point(10,10),WIDTH*Category.values().length,animation,()->ClickGUIModule.layout.getValue()==ClickGUIModule.Layout.SinglePanel,"singlePanel") { + @Override + protected IResizable getResizable (int width) { + return resizable.apply(width); + } + + @Override + protected IScrollSize getScrollSize (IResizable size) { + return resizableHeight.apply(size); + } + }; + ILayout singlePanelLayout=new PanelLayout(WIDTH,new Point(DISTANCE,DISTANCE),(WIDTH+DISTANCE)/2,HEIGHT+DISTANCE,animation,level->ChildMode.DOWN,level->ChildMode.DOWN,popupType); + singlePanelLayout.populateGUI(singlePanelAdder,generator,client,theme); + // Panel Menu + IComponentAdder panelMenuAdder=new StackedPanelAdder(gui,new Labeled("Example Menu",null,()->true),theme,new Point(10,10),WIDTH,animation,ChildMode.POPUP,new PanelPositioner(new Point(0,0)),()->ClickGUIModule.layout.getValue()==ClickGUIModule.Layout.PanelMenu,"panelMenu"); + ILayout panelMenuLayout=new PanelLayout(WIDTH,new Point(DISTANCE,DISTANCE),(WIDTH+DISTANCE)/2,HEIGHT+DISTANCE,animation,level->ChildMode.POPUP,level->ChildMode.POPUP,popupType); + panelMenuLayout.populateGUI(panelMenuAdder,generator,client,theme); + // Color Panel + IComponentAdder colorPanelAdder=new PanelAdder(gui,false,()->ClickGUIModule.layout.getValue()==ClickGUIModule.Layout.ColorPanel,title->"colorPanel_"+title) { + @Override + protected IResizable getResizable (int width) { + return resizable.apply(width); + } + + @Override + protected IScrollSize getScrollSize (IResizable size) { + return resizableHeight.apply(size); + } + }; + ILayout colorPanelLayout=new PanelLayout(WIDTH,new Point(DISTANCE,DISTANCE),(WIDTH+DISTANCE)/2,HEIGHT+DISTANCE,animation,level->ChildMode.DOWN,level->ChildMode.POPUP,colorPopup); + colorPanelLayout.populateGUI(colorPanelAdder,cycleGenerator,client,theme); + // Horizontal CSGO + AtomicReference horizontalResizable=new AtomicReference(null); + IComponentAdder horizontalCSGOAdder=new PanelAdder(gui,true,()->ClickGUIModule.layout.getValue()==ClickGUIModule.Layout.CSGOHorizontal,title->"horizontalCSGO_"+title) { + @Override + protected IResizable getResizable (int width) { + horizontalResizable.set(resizable.apply(width)); + return horizontalResizable.get(); + } + }; + ILayout horizontalCSGOLayout=new CSGOLayout(new Labeled("Example",null,()->true),new Point(100,100),480,WIDTH,animation,"Enabled",true,true,2,ChildMode.POPUP,colorPopup) { + @Override + public int getScrollHeight (Context context, int componentHeight) { + return resizableHeight.apply(horizontalResizable.get()).getScrollHeight(null,height); + } + }; + horizontalCSGOLayout.populateGUI(horizontalCSGOAdder,csgoGenerator,client,theme); + // Vertical CSGO + AtomicReference verticalResizable=new AtomicReference(null); + IComponentAdder verticalCSGOAdder=new PanelAdder(gui,true,()->ClickGUIModule.layout.getValue()==ClickGUIModule.Layout.CSGOVertical,title->"verticalCSGO_"+title) { + @Override + protected IResizable getResizable (int width) { + verticalResizable.set(resizable.apply(width)); + return verticalResizable.get(); + } + }; + ILayout verticalCSGOLayout=new CSGOLayout(new Labeled("Example",null,()->true),new Point(100,100),480,WIDTH,animation,"Enabled",false,true,2,ChildMode.POPUP,colorPopup) { + @Override + public int getScrollHeight (Context context, int componentHeight) { + return resizableHeight.apply(verticalResizable.get()).getScrollHeight(null,height); + } + }; + verticalCSGOLayout.populateGUI(verticalCSGOAdder,csgoGenerator,client,theme); + // Category CSGO + AtomicReference categoryResizable=new AtomicReference(null); + IComponentAdder categoryCSGOAdder=new PanelAdder(gui,true,()->ClickGUIModule.layout.getValue()==ClickGUIModule.Layout.CSGOCategory,title->"categoryCSGO_"+title) { + @Override + protected IResizable getResizable (int width) { + categoryResizable.set(resizable.apply(width)); + return categoryResizable.get(); + } + }; + ILayout categoryCSGOLayout=new CSGOLayout(new Labeled("Example",null,()->true),new Point(100,100),480,WIDTH,animation,"Enabled",false,false,2,ChildMode.POPUP,colorPopup) { + @Override + public int getScrollHeight (Context context, int componentHeight) { + return resizableHeight.apply(categoryResizable.get()).getScrollHeight(null,height); + } + }; + categoryCSGOLayout.populateGUI(categoryCSGOAdder,csgoGenerator,client,theme); + // Searchable CSGO + AtomicReference searchableResizable=new AtomicReference(null); + IComponentAdder searchableCSGOAdder=new PanelAdder(gui,true,()->ClickGUIModule.layout.getValue()==ClickGUIModule.Layout.SearchableCSGO,title->"searchableCSGO_"+title) { + @Override + protected IResizable getResizable (int width) { + searchableResizable.set(resizable.apply(width)); + return searchableResizable.get(); + } + }; + ILayout searchableCSGOLayout=new SearchableLayout(new Labeled("Example",null,()->true),new Labeled("Search",null,()->true),new Point(100,100),480,WIDTH,animation,"Enabled",2,ChildMode.POPUP,colorPopup,(a,b)->a.getDisplayName().compareTo(b.getDisplayName()),charFilter,keys) { + @Override + public int getScrollHeight (Context context, int componentHeight) { + return resizableHeight.apply(searchableResizable.get()).getScrollHeight(null,height); + } + }; + searchableCSGOLayout.populateGUI(searchableCSGOAdder,csgoGenerator,client,theme); + } + + @Override + protected HUDGUI getGUI() { + return gui; + } + + @Override + protected GUIInterface getInterface() { + return inter; + } + + @Override + protected int getScrollSpeed() { + return ClickGUIModule.scrollSpeed.getValue(); + } + + + private class ThemeSelector implements IThemeMultiplexer { + protected Map themes=new EnumMap(ClickGUIModule.Theme.class); + + public ThemeSelector (IInterface inter) { + BooleanSetting clearGradient=new BooleanSetting("Gradient","gradient","Whether the title bars should have a gradient.",()->ClickGUIModule.theme.getValue()==Theme.Clear,true); + BooleanSetting ignoreDisabled=new BooleanSetting("Ignore Disabled","ignoreDisabled","Have the rainbow drawn for disabled containers.",()->ClickGUIModule.theme.getValue()==Theme.Rainbow,false); + BooleanSetting buttonRainbow=new BooleanSetting("Button Rainbow","buttonRainbow","Have a separate rainbow for each component.",()->ClickGUIModule.theme.getValue()==Theme.Rainbow,false); + IntegerSetting rainbowGradient=new IntegerSetting("Rainbow Gradient","rainbowGradient","How fast the rainbow should repeat.",()->ClickGUIModule.theme.getValue()==Theme.Rainbow,150,50,300); + ClickGUIModule.theme.subSettings.add(clearGradient); + ClickGUIModule.theme.subSettings.add(ignoreDisabled); + ClickGUIModule.theme.subSettings.add(buttonRainbow); + ClickGUIModule.theme.subSettings.add(rainbowGradient); + addTheme(Theme.Clear,new ClearTheme(new ThemeScheme(Theme.Clear),()->clearGradient.getValue(),9,3,1,": "+Formatting.GRAY)); + addTheme(Theme.GameSense,new GameSenseTheme(new ThemeScheme(Theme.GameSense),9,4,5,": "+Formatting.GRAY)); + addTheme(Theme.Rainbow,new RainbowTheme(new ThemeScheme(Theme.Rainbow),()->ignoreDisabled.getValue(),()->buttonRainbow.getValue(),()->rainbowGradient.getValue(),9,3,": "+Formatting.GRAY)); + addTheme(Theme.Windows31,new Windows31Theme(new ThemeScheme(Theme.Windows31),9,2,9,": "+Formatting.DARK_GRAY)); + addTheme(Theme.Impact,new ImpactTheme(new ThemeScheme(Theme.Impact),9,4)); + } + + @Override + public ITheme getTheme() { + return themes.getOrDefault(ClickGUIModule.theme.getValue(),themes.get(Theme.GameSense)); + } + + private void addTheme (Theme key, ITheme value) { + themes.put(key,new OptimizedTheme(value)); + value.loadAssets(inter); + } + + + private class ThemeScheme implements IColorScheme { + private final Theme themeValue; + private final String themeName; + + public ThemeScheme (Theme themeValue) { + this.themeValue=themeValue; + this.themeName=themeValue.toString().toLowerCase(); + } + + @Override + public void createSetting (ITheme theme, String name, String description, boolean hasAlpha, boolean allowsRainbow, Color color, boolean rainbow) { + ClickGUIModule.theme.subSettings.add(new ColorSetting(name,themeName+"-"+name,description,()->ClickGUIModule.theme.getValue()==themeValue,hasAlpha,allowsRainbow,color,rainbow)); + } + + @Override + public Color getColor (String name) { + return ((ColorSetting)ClickGUIModule.theme.subSettings.stream().filter(setting->setting.configName.equals(themeName+"-"+name)).findFirst().orElse(null)).getValue(); + } + } + } +} diff --git a/example-mod19/src/main/java/com/lukflug/examplemod19/ExampleMod.java b/example-mod19/src/main/java/com/lukflug/examplemod19/ExampleMod.java new file mode 100644 index 0000000..664f721 --- /dev/null +++ b/example-mod19/src/main/java/com/lukflug/examplemod19/ExampleMod.java @@ -0,0 +1,49 @@ +package com.lukflug.examplemod19; + +import org.lwjgl.glfw.GLFW; + +import com.lukflug.examplemod19.module.Category; +import com.lukflug.examplemod19.module.ClickGUIModule; +import com.lukflug.examplemod19.module.HUDEditorModule; +import com.lukflug.examplemod19.module.LogoModule; +import com.lukflug.examplemod19.module.TabGUIModule; +import com.lukflug.examplemod19.module.WatermarkModule; + +import net.fabricmc.api.ModInitializer; +import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; +import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback; +import net.minecraft.client.MinecraftClient; + +public class ExampleMod implements ModInitializer { + private static ClickGUI gui; + private boolean inited=false; + private final boolean keys[]=new boolean[266]; + + @Override + public void onInitialize() { + Category.init(); + Category.OTHER.modules.add(new ClickGUIModule()); + Category.OTHER.modules.add(new HUDEditorModule()); + Category.HUD.modules.add(new TabGUIModule()); + Category.HUD.modules.add(new WatermarkModule()); + Category.HUD.modules.add(new LogoModule()); + ClientTickEvents.END_CLIENT_TICK.register(client -> { + if (!inited) { + for (int i=32;igui.render()); + inited=true; + } + for (int i=32;i modules=new ArrayList(); + public static Random random=new Random(); + + private Category (String displayName) { + this.displayName=displayName; + } + + public static void init() { + for (Category category: Category.values()) { + int count=random.nextInt(6)+5; + for (int i=0;i getModules() { + return modules.stream().map(module->module); + } + + public static IClient getClient() { + return new IClient() { + @Override + public Stream getCategories() { + return Arrays.stream(Category.values()); + } + }; + } + + public static Module generateRandomModule() { + Module module=new Module(generateRandomName(5,10),generateRandomName(10,20),()->true,random.nextInt(2)==0); + int count=random.nextInt(6)+5; + for (int i=0;i generateRandomSetting() { + String displayName=generateRandomName(5,10); + String description=generateRandomName(10,20); + int type=random.nextInt(6); + int min=random.nextInt(50),max=random.nextInt(50)+50; + boolean alpha=random.nextInt(2)==0; + boolean rainbow=random.nextInt(2)==0; + Color color=new Color(random.nextInt(256),random.nextInt(256),random.nextInt(256),alpha?random.nextInt(256):255); + switch (type) { + case 0: + return new BooleanSetting(displayName,displayName,description,()->true,random.nextInt(2)==0); + case 1: + return new ColorSetting(displayName,displayName,description,()->true,alpha,rainbow,color,rainbow?random.nextInt(2)==0:false); + case 2: + return new DoubleSetting(displayName,displayName,description,()->true,min,max,random.nextDouble()*(max-min)+min); + case 4: + return new IntegerSetting(displayName,displayName,description,()->true,min,max,random.nextInt(max-min+1)+min); + default: + return new StringSetting(displayName,displayName,description,()->true,generateRandomName(5,10)); + } + }; + + public static String generateRandomName (int min, int max) { + int length=random.nextInt(max-min+1)+min; + String s=""; + for (int i=0;i colorModel=new EnumSetting("Color Model","colorModel","Whether to use RGB or HSB.",()->true,ColorModel.RGB,ColorModel.class); + public static final IntegerSetting rainbowSpeed=new IntegerSetting("Rainbow Speed","rainbowSpeed","The speed of the color hue cycling.",()->true,1,100,32); + public static final IntegerSetting scrollSpeed=new IntegerSetting("Scroll Speed","scrollSpeed","The speed of scrolling.",()->true,0,20,10); + public static final IntegerSetting animationSpeed=new IntegerSetting("Animation Speed","animationSpeed","The speed of GUI animations.",()->true,0,1000,200); + public static final EnumSetting theme=new EnumSetting("Theme","theme","What theme to use.",()->true,Theme.GameSense,Theme.class); + public static final EnumSetting layout=new EnumSetting("Layout","layout","What layout to use.",()->true,Layout.ClassicPanel,Layout.class); + public static final KeybindSetting keybind=new KeybindSetting("Keybind","keybind","The key to toggle the module.",()->true,GLFW.GLFW_KEY_O); + + public ClickGUIModule() { + super("ClickGUI","Module containing ClickGUI settings.",()->true,false); + settings.add(colorModel); + settings.add(rainbowSpeed); + settings.add(scrollSpeed); + settings.add(animationSpeed); + settings.add(theme); + settings.add(layout); + settings.add(keybind); + } + + public enum ColorModel { + RGB,HSB; + } + + public enum Theme { + Clear,GameSense,Rainbow,Windows31,Impact; + } + + public enum Layout { + ClassicPanel,PopupPanel,DraggablePanel,SinglePanel,PanelMenu,ColorPanel,CSGOHorizontal,CSGOVertical,CSGOCategory,SearchableCSGO; + } +} diff --git a/example-mod19/src/main/java/com/lukflug/examplemod19/module/HUDEditorModule.java b/example-mod19/src/main/java/com/lukflug/examplemod19/module/HUDEditorModule.java new file mode 100644 index 0000000..ee9fca0 --- /dev/null +++ b/example-mod19/src/main/java/com/lukflug/examplemod19/module/HUDEditorModule.java @@ -0,0 +1,17 @@ +package com.lukflug.examplemod19.module; + +import org.lwjgl.glfw.GLFW; + +import com.lukflug.examplemod19.setting.BooleanSetting; +import com.lukflug.examplemod19.setting.KeybindSetting; + +public class HUDEditorModule extends Module { + public static final BooleanSetting showHUD=new BooleanSetting("Show HUD Panels","showHUD","Whether to show the HUD panels in the ClickGUI.",()->true,true); + public static final KeybindSetting keybind=new KeybindSetting("Keybind","keybind","The key to toggle the module.",()->true,GLFW.GLFW_KEY_P); + + public HUDEditorModule() { + super("HUDEditor","Module containing HUDEditor settings.",()->true,false); + settings.add(showHUD); + settings.add(keybind); + } +} diff --git a/example-mod19/src/main/java/com/lukflug/examplemod19/module/LogoModule.java b/example-mod19/src/main/java/com/lukflug/examplemod19/module/LogoModule.java new file mode 100644 index 0000000..bfc1dac --- /dev/null +++ b/example-mod19/src/main/java/com/lukflug/examplemod19/module/LogoModule.java @@ -0,0 +1,49 @@ +package com.lukflug.examplemod19.module; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Point; + +import com.lukflug.examplemod19.setting.BooleanSetting; +import com.lukflug.examplemod19.setting.ColorSetting; +import com.lukflug.examplemod19.setting.IntegerSetting; +import com.lukflug.panelstudio.base.Context; +import com.lukflug.panelstudio.base.IInterface; +import com.lukflug.panelstudio.base.IToggleable; +import com.lukflug.panelstudio.component.IFixedComponent; +import com.lukflug.panelstudio.hud.HUDComponent; + +public class LogoModule extends Module { + private static LogoModule instance; + private static final IntegerSetting rotation=new IntegerSetting("Image Rotation","rotation","How to rotate the image.",()->true,0,3,0); + private static final BooleanSetting parity=new BooleanSetting("Flip Image","parity","Whether to flip the image or not.",()->true,false); + private static final ColorSetting color=new ColorSetting("Logo Color","color","The color to modulate the logo with.",()->true,true,true,new Color(255,255,255,128),true); + + public LogoModule() { + super("Logo","Module that displays the PanelStudio icon on HUD.",()->true,true); + instance=this; + settings.add(rotation); + settings.add(parity); + settings.add(color); + } + + public static IFixedComponent getComponent (IInterface inter) { + int image=inter.loadImage("panelstudio.png"); + return new HUDComponent(()->"Logo",new Point(300,300),"logo") { + @Override + public void render (Context context) { + super.render(context); + context.getInterface().drawImage(context.getRect(),rotation.getValue(),parity.getValue(),image,color.getValue()); + } + + @Override + public Dimension getSize (IInterface inter) { + return new Dimension(141,61); + } + }; + } + + public static IToggleable getToggle() { + return instance.isEnabled(); + } +} diff --git a/example-mod19/src/main/java/com/lukflug/examplemod19/module/Module.java b/example-mod19/src/main/java/com/lukflug/examplemod19/module/Module.java new file mode 100644 index 0000000..c4c7d28 --- /dev/null +++ b/example-mod19/src/main/java/com/lukflug/examplemod19/module/Module.java @@ -0,0 +1,62 @@ +package com.lukflug.examplemod19.module; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Stream; + +import com.lukflug.examplemod19.setting.Setting; +import com.lukflug.panelstudio.base.IBoolean; +import com.lukflug.panelstudio.base.IToggleable; +import com.lukflug.panelstudio.setting.IModule; +import com.lukflug.panelstudio.setting.ISetting; + +public class Module implements IModule { + public final String displayName,description; + public final IBoolean visible; + public final List> settings=new ArrayList>(); + public final boolean toggleable; + private boolean enabled=false; + + public Module (String displayName, String description, IBoolean visible, boolean toggleable) { + this.displayName=displayName; + this.description=description; + this.visible=visible; + this.toggleable=toggleable; + } + + @Override + public String getDisplayName() { + return displayName; + } + + @Override + public String getDescription() { + return description; + } + + @Override + public IBoolean isVisible() { + return visible; + } + + @Override + public IToggleable isEnabled() { + if (!toggleable) return null; + return new IToggleable() { + @Override + public boolean isOn() { + return enabled; + } + + @Override + public void toggle() { + enabled=!enabled; + } + }; + } + + @Override + public Stream> getSettings() { + return settings.stream().filter(setting->setting instanceof ISetting).sorted((a,b)->a.displayName.compareTo(b.displayName)).map(setting->(ISetting)setting); + } +} diff --git a/example-mod19/src/main/java/com/lukflug/examplemod19/module/TabGUIModule.java b/example-mod19/src/main/java/com/lukflug/examplemod19/module/TabGUIModule.java new file mode 100644 index 0000000..cc5bb8e --- /dev/null +++ b/example-mod19/src/main/java/com/lukflug/examplemod19/module/TabGUIModule.java @@ -0,0 +1,49 @@ +package com.lukflug.examplemod19.module; + +import java.awt.Color; +import java.awt.Point; +import java.util.function.Supplier; + +import org.lwjgl.glfw.GLFW; + +import com.lukflug.examplemod19.setting.ColorSetting; +import com.lukflug.panelstudio.base.Animation; +import com.lukflug.panelstudio.base.IToggleable; +import com.lukflug.panelstudio.component.IFixedComponent; +import com.lukflug.panelstudio.container.IContainer; +import com.lukflug.panelstudio.setting.IClient; +import com.lukflug.panelstudio.tabgui.ITabGUITheme; +import com.lukflug.panelstudio.tabgui.StandardTheme; +import com.lukflug.panelstudio.tabgui.TabGUI; +import com.lukflug.panelstudio.theme.IColorScheme; +import com.lukflug.panelstudio.theme.ITheme; + +public class TabGUIModule extends Module { + private static TabGUIModule instance; + private static ITabGUITheme theme; + + public TabGUIModule() { + super("TabGUI","HUD module that lets toggle modules.",()->true,true); + instance=this; + theme=new StandardTheme(new IColorScheme() { + @Override + public void createSetting(ITheme theme, String name, String description, boolean hasAlpha, boolean allowsRainbow, Color color, boolean rainbow) { + ColorSetting setting=new ColorSetting(name,name,description,()->true,allowsRainbow,hasAlpha,color,rainbow); + instance.settings.add(setting); + } + + @Override + public Color getColor (String name) { + return (Color)instance.settings.stream().filter(setting->setting.configName.equals(name)).findFirst().orElse(null).getValue(); + } + },75,9,2,5); + } + + public static IFixedComponent getComponent (IClient client, IContainer container, Supplier animation) { + return new TabGUI(()->"TabGUI",client,theme,container,animation,key->key==GLFW.GLFW_KEY_UP,key->key==GLFW.GLFW_KEY_DOWN,key->key==GLFW.GLFW_KEY_ENTER||key==GLFW.GLFW_KEY_RIGHT,key->key==GLFW.GLFW_KEY_LEFT,new Point(10,10),"tabGUI").getWrappedComponent(); + } + + public static IToggleable getToggle() { + return instance.isEnabled(); + } +} diff --git a/example-mod19/src/main/java/com/lukflug/examplemod19/module/WatermarkModule.java b/example-mod19/src/main/java/com/lukflug/examplemod19/module/WatermarkModule.java new file mode 100644 index 0000000..233a605 --- /dev/null +++ b/example-mod19/src/main/java/com/lukflug/examplemod19/module/WatermarkModule.java @@ -0,0 +1,68 @@ +package com.lukflug.examplemod19.module; + +import java.awt.Color; +import java.awt.Point; + +import com.lukflug.examplemod19.setting.BooleanSetting; +import com.lukflug.examplemod19.setting.ColorSetting; +import com.lukflug.examplemod19.setting.StringSetting; +import com.lukflug.panelstudio.base.IToggleable; +import com.lukflug.panelstudio.component.IFixedComponent; +import com.lukflug.panelstudio.hud.HUDList; +import com.lukflug.panelstudio.hud.ListComponent; + +public class WatermarkModule extends Module { + private static WatermarkModule instance; + private static final ColorSetting color=new ColorSetting("Text Color","color","The color of the displayed text.",()->true,false,true,new Color(0,0,255),false); + private static final BooleanSetting sortUp=new BooleanSetting("Sort Up","sortUp","Whether to align the text from the bottom up.",()->true,false); + private static final BooleanSetting sortRight=new BooleanSetting("Sort Right","sortRight","Whether to align the text from right to left.",()->true,false); + private static final StringSetting line1=new StringSetting("First Line","line1","The first line of text.",()->true,"PanelStudio"); + private static final StringSetting line2=new StringSetting("Second Line","line2","The second line of text.",()->true,"Example Mod"); + private static final StringSetting line3=new StringSetting("Third Line","line3","The third line of text.",()->true,"made by lukflug"); + + public WatermarkModule() { + super("Watermark","Module that displays text on HUD.",()->true,true); + instance=this; + settings.add(color); + settings.add(sortUp); + settings.add(sortRight); + settings.add(line1); + settings.add(line2); + settings.add(line3); + } + + public static IFixedComponent getComponent() { + return new ListComponent(()->"Watermark",new Point(300,10),"watermark",new HUDList() { + @Override + public int getSize() { + return 3; + } + + @Override + public String getItem(int index) { + if (index==0) return line1.getValue(); + else if (index==1) return line2.getValue(); + else return line3.getValue(); + } + + @Override + public Color getItemColor(int index) { + return color.getValue(); + } + + @Override + public boolean sortUp() { + return sortUp.getValue(); + } + + @Override + public boolean sortRight() { + return sortRight.getValue(); + } + },9,2); + } + + public static IToggleable getToggle() { + return instance.isEnabled(); + } +} diff --git a/example-mod19/src/main/java/com/lukflug/examplemod19/setting/BooleanSetting.java b/example-mod19/src/main/java/com/lukflug/examplemod19/setting/BooleanSetting.java new file mode 100644 index 0000000..5566261 --- /dev/null +++ b/example-mod19/src/main/java/com/lukflug/examplemod19/setting/BooleanSetting.java @@ -0,0 +1,20 @@ +package com.lukflug.examplemod19.setting; + +import com.lukflug.panelstudio.base.IBoolean; +import com.lukflug.panelstudio.setting.IBooleanSetting; + +public class BooleanSetting extends Setting implements IBooleanSetting { + public BooleanSetting (String displayName, String configName, String description, IBoolean visible, Boolean value) { + super(displayName,configName,description,visible,value); + } + + @Override + public void toggle() { + setValue(!getValue()); + } + + @Override + public boolean isOn() { + return getValue(); + } +} diff --git a/example-mod19/src/main/java/com/lukflug/examplemod19/setting/ColorSetting.java b/example-mod19/src/main/java/com/lukflug/examplemod19/setting/ColorSetting.java new file mode 100644 index 0000000..6d0934a --- /dev/null +++ b/example-mod19/src/main/java/com/lukflug/examplemod19/setting/ColorSetting.java @@ -0,0 +1,60 @@ +package com.lukflug.examplemod19.setting; + +import java.awt.Color; + +import com.lukflug.examplemod19.module.ClickGUIModule; +import com.lukflug.examplemod19.module.ClickGUIModule.ColorModel; +import com.lukflug.panelstudio.base.IBoolean; +import com.lukflug.panelstudio.setting.IColorSetting; +import com.lukflug.panelstudio.theme.ITheme; + +public class ColorSetting extends Setting implements IColorSetting { + public final boolean hasAlpha,allowsRainbow; + private boolean rainbow; + + public ColorSetting (String displayName, String configName, String description, IBoolean visible, boolean hasAlpha, boolean allowsRainbow, Color value, boolean rainbow) { + super(displayName,configName,description,visible,value); + this.hasAlpha=hasAlpha; + this.allowsRainbow=allowsRainbow; + this.rainbow=rainbow; + } + + @Override + public Color getValue() { + if (rainbow) { + int speed=ClickGUIModule.rainbowSpeed.getValue(); + return ITheme.combineColors(Color.getHSBColor((System.currentTimeMillis()%(360*speed))/(float)(360*speed),1,1),super.getValue()); + } + else return super.getValue(); + } + + @Override + public Color getColor() { + return super.getValue(); + } + + @Override + public boolean getRainbow() { + return rainbow; + } + + @Override + public void setRainbow (boolean rainbow) { + this.rainbow=rainbow; + } + + @Override + public boolean hasAlpha() { + return hasAlpha; + } + + @Override + public boolean allowsRainbow() { + return allowsRainbow; + } + + @Override + public boolean hasHSBModel() { + return ClickGUIModule.colorModel.getValue()==ColorModel.HSB; + } +} diff --git a/example-mod19/src/main/java/com/lukflug/examplemod19/setting/DoubleSetting.java b/example-mod19/src/main/java/com/lukflug/examplemod19/setting/DoubleSetting.java new file mode 100644 index 0000000..afda057 --- /dev/null +++ b/example-mod19/src/main/java/com/lukflug/examplemod19/setting/DoubleSetting.java @@ -0,0 +1,39 @@ +package com.lukflug.examplemod19.setting; + +import com.lukflug.panelstudio.base.IBoolean; +import com.lukflug.panelstudio.setting.INumberSetting; + +public class DoubleSetting extends Setting implements INumberSetting { + public final double min,max; + + public DoubleSetting (String displayName, String configName, String description, IBoolean visible, double min, double max, double value) { + super(displayName,configName,description,visible,value); + this.min=min; + this.max=max; + } + + @Override + public double getNumber() { + return getValue(); + } + + @Override + public void setNumber (double value) { + setValue(value); + } + + @Override + public double getMaximumValue() { + return max; + } + + @Override + public double getMinimumValue() { + return min; + } + + @Override + public int getPrecision() { + return 2; + } +} diff --git a/example-mod19/src/main/java/com/lukflug/examplemod19/setting/EnumSetting.java b/example-mod19/src/main/java/com/lukflug/examplemod19/setting/EnumSetting.java new file mode 100644 index 0000000..bebe4d5 --- /dev/null +++ b/example-mod19/src/main/java/com/lukflug/examplemod19/setting/EnumSetting.java @@ -0,0 +1,61 @@ +package com.lukflug.examplemod19.setting; + +import java.util.Arrays; + +import com.lukflug.panelstudio.base.IBoolean; +import com.lukflug.panelstudio.setting.IEnumSetting; +import com.lukflug.panelstudio.setting.ILabeled; + +public class EnumSetting> extends Setting implements IEnumSetting { + private final Class settingClass; + private final ILabeled[] array; + + public EnumSetting (String displayName, String configName, String description, IBoolean visible, E value, Class settingClass) { + super(displayName,configName,description,visible,value); + this.settingClass=settingClass; + array=Arrays.stream(settingClass.getEnumConstants()).map(v->{ + return new ILabeled() { + @Override + public String getDisplayName() { + return v.toString(); + } + }; + }).toArray(ILabeled[]::new); + } + + @Override + public void increment() { + E[] array=settingClass.getEnumConstants(); + int index=getValue().ordinal()+1; + if (index>=array.length) index=0; + setValue(array[index]); + } + + @Override + public void decrement() { + E[] array=settingClass.getEnumConstants(); + int index=getValue().ordinal()-1; + if (index<0) index=array.length-1; + setValue(array[index]); + } + + @Override + public String getValueName() { + return getValue().toString(); + } + + @Override + public int getValueIndex() { + return getValue().ordinal(); + } + + @Override + public void setValueIndex(int index) { + setValue(settingClass.getEnumConstants()[index]); + } + + @Override + public ILabeled[] getAllowedValues() { + return array; + } +} diff --git a/example-mod19/src/main/java/com/lukflug/examplemod19/setting/IntegerSetting.java b/example-mod19/src/main/java/com/lukflug/examplemod19/setting/IntegerSetting.java new file mode 100644 index 0000000..822e260 --- /dev/null +++ b/example-mod19/src/main/java/com/lukflug/examplemod19/setting/IntegerSetting.java @@ -0,0 +1,39 @@ +package com.lukflug.examplemod19.setting; + +import com.lukflug.panelstudio.base.IBoolean; +import com.lukflug.panelstudio.setting.INumberSetting; + +public class IntegerSetting extends Setting implements INumberSetting { + public final int min,max; + + public IntegerSetting (String displayName, String configName, String description, IBoolean visible, int min, int max, int value) { + super(displayName,configName,description,visible,value); + this.min=min; + this.max=max; + } + + @Override + public double getNumber() { + return getValue(); + } + + @Override + public void setNumber (double value) { + setValue((int)Math.round(value)); + } + + @Override + public double getMaximumValue() { + return max; + } + + @Override + public double getMinimumValue() { + return min; + } + + @Override + public int getPrecision() { + return 0; + } +} diff --git a/example-mod19/src/main/java/com/lukflug/examplemod19/setting/KeybindSetting.java b/example-mod19/src/main/java/com/lukflug/examplemod19/setting/KeybindSetting.java new file mode 100644 index 0000000..8dcdb78 --- /dev/null +++ b/example-mod19/src/main/java/com/lukflug/examplemod19/setting/KeybindSetting.java @@ -0,0 +1,31 @@ +package com.lukflug.examplemod19.setting; + +import com.lukflug.panelstudio.base.IBoolean; +import com.lukflug.panelstudio.setting.IKeybindSetting; + +import net.minecraft.client.util.InputUtil; +import net.minecraft.text.TranslatableTextContent; + +public class KeybindSetting extends Setting implements IKeybindSetting { + public KeybindSetting (String displayName, String configName, String description, IBoolean visible, Integer value) { + super(displayName,configName,description,visible,value); + } + + @Override + public int getKey() { + return getValue(); + } + + @Override + public void setKey (int key) { + setValue(key); + } + + @Override + public String getKeyName() { + String translationKey=InputUtil.Type.KEYSYM.createFromCode(getKey()).getTranslationKey(); + String translation=new TranslatableTextContent(translationKey).toString(); + if (!translation.equals(translationKey)) return translation; + return InputUtil.Type.KEYSYM.createFromCode(getKey()).getLocalizedText().getString(); + } +} diff --git a/example-mod19/src/main/java/com/lukflug/examplemod19/setting/Setting.java b/example-mod19/src/main/java/com/lukflug/examplemod19/setting/Setting.java new file mode 100644 index 0000000..e3ffacd --- /dev/null +++ b/example-mod19/src/main/java/com/lukflug/examplemod19/setting/Setting.java @@ -0,0 +1,52 @@ +package com.lukflug.examplemod19.setting; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Stream; + +import com.lukflug.panelstudio.base.IBoolean; +import com.lukflug.panelstudio.setting.ILabeled; +import com.lukflug.panelstudio.setting.ISetting; + +public abstract class Setting implements ILabeled { + public final String displayName,configName,description; + public final IBoolean visible; + public final List> subSettings=new ArrayList>(); + private T value; + + public Setting (String displayName, String configName, String description, IBoolean visible, T value) { + this.displayName=displayName; + this.configName=configName; + this.description=description; + this.visible=visible; + this.value=value; + } + + public T getValue() { + return value; + } + + public void setValue (T value) { + this.value=value; + } + + @Override + public String getDisplayName() { + return displayName; + } + + @Override + public String getDescription() { + return description; + } + + @Override + public IBoolean isVisible() { + return visible; + } + + public Stream> getSubSettings() { + if (subSettings.size()==0) return null; + return subSettings.stream().filter(setting->setting instanceof ISetting).sorted((a,b)->a.displayName.compareTo(b.displayName)).map(setting->(ISetting)setting); + } +} diff --git a/example-mod19/src/main/java/com/lukflug/examplemod19/setting/StringSetting.java b/example-mod19/src/main/java/com/lukflug/examplemod19/setting/StringSetting.java new file mode 100644 index 0000000..3a75342 --- /dev/null +++ b/example-mod19/src/main/java/com/lukflug/examplemod19/setting/StringSetting.java @@ -0,0 +1,10 @@ +package com.lukflug.examplemod19.setting; + +import com.lukflug.panelstudio.base.IBoolean; +import com.lukflug.panelstudio.setting.IStringSetting; + +public class StringSetting extends Setting implements IStringSetting { + public StringSetting (String displayName, String configName, String description, IBoolean visible, String value) { + super(displayName,configName,description,visible,value); + } +} diff --git a/example-mod19/src/main/resources/assets/examplemod/panelstudio.png b/example-mod19/src/main/resources/assets/examplemod/panelstudio.png new file mode 100644 index 0000000..5cf536a Binary files /dev/null and b/example-mod19/src/main/resources/assets/examplemod/panelstudio.png differ diff --git a/example-mod19/src/main/resources/fabric.mod.json b/example-mod19/src/main/resources/fabric.mod.json new file mode 100644 index 0000000..79ee2ff --- /dev/null +++ b/example-mod19/src/main/resources/fabric.mod.json @@ -0,0 +1,23 @@ +{ + "schemaVersion": 1, + "id": "example-mod18", + "version": "${version}", + "name": "PanelStudio-MC19 Example Mod", + "description": "An example mod for PanelStudio-MC19.", + "authors": ["lukflug"], + "contact": { + "homepage": "https://lukflug.github.io", + "sources": "https://github.com/lukflug/PanelStudio" + }, + "license": "MIT", + "icon": "assets/examplemod/panelstudio.png", + "environment": "*", + "entrypoints": { + "main": ["com.lukflug.examplemod19.ExampleMod"] + }, + "depends": { + "fabric": "*", + "fabricloader": ">=0.7.4", + "minecraft": "1.19.x" + } +} diff --git a/example-mod8-fabric/build.gradle b/example-mod8-fabric/build.gradle index 40afd68..92b8f1c 100644 --- a/example-mod8-fabric/build.gradle +++ b/example-mod8-fabric/build.gradle @@ -37,19 +37,16 @@ repositories { } } - -minecraft { - intermediaryUrl = { - return "https://maven.legacyfabric.net/net/fabricmc/intermediary/" + it + "/intermediary-" + it + "-v2.jar"; - } +loom { + setIntermediaryUrl('https://maven.legacyfabric.net/net/legacyfabric/intermediary/%1$s/intermediary-%1$s-v2.jar'); } dependencies { minecraft "com.mojang:minecraft:${minecraft8fabric}" - mappings "net.fabricmc:yarn:${mappings8fabric}:v2" + mappings "net.legacyfabric:yarn:${mappings8fabric}:v2" modImplementation "net.fabricmc:fabric-loader:${loader8fabric}" modImplementation("net.legacyfabric.legacy-fabric-api:legacy-fabric-api:${api8fabric}") { - exclude module: "fabric-loader-1.8.9" + exclude module: "legacy-fabric-entity-events-v1" } shadow "com.lukflug:panelstudio:${version}" shadow "com.lukflug:panelstudio-mc8-fabric:${versionmc}" diff --git a/example-mod8-fabric/gradle.properties b/example-mod8-fabric/gradle.properties index 469beeb..5092bd8 100644 --- a/example-mod8-fabric/gradle.properties +++ b/example-mod8-fabric/gradle.properties @@ -2,8 +2,8 @@ org.gradle.jvmargs = -Xmx2500m version = 0.2.1 versionmc = 0.2.2 -loomVersion = 0.7.33 +loomVersion = 1.0.11 minecraft8fabric = 1.8.9 -mappings8fabric = 1.8.9+build.202202110257 -loader8fabric = 0.13.3 -api8fabric = 1.2.2+1.8.9 +mappings8fabric = 1.8.9+build.421 +loader8fabric = 0.14.10 +api8fabric = 1.8.0+1.8.9 diff --git a/example-mod8-fabric/gradle/wrapper/gradle-wrapper.properties b/example-mod8-fabric/gradle/wrapper/gradle-wrapper.properties index 69a9715..00e33ed 100644 --- a/example-mod8-fabric/gradle/wrapper/gradle-wrapper.properties +++ b/example-mod8-fabric/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradle.properties b/gradle.properties index cac1f56..1a53439 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,19 +1,19 @@ org.gradle.jvmargs = -Xmx2500m -version = 0.2.2 +version = 0.2.3 forgeGradle3 = 3.0.195 mappings12 = 39-1.12 minecraft12 = 1.12.2-14.23.5.2859 -loomVersion = 0.7.33 +loomVersion = 0.7.35 minecraft16fabric = 1.16.5 mappings16fabric = 1.16.5+build.10 mappings16forge = 20210309-1.16.5 -minecraft16forge = 1.16.5-36.2.20 +minecraft16forge = 1.16.5-36.2.34 minecraft8fabric = 1.8.9 -mappings8fabric = 1.8.9+build.202202110257 +mappings8fabric = 1.8.9+build.421 forgeGradle2 = 2.1.3 mappings8forge = stable_22 diff --git a/panelstudio-mc17/build.gradle b/panelstudio-mc17/build.gradle index 4739709..911c43f 100644 --- a/panelstudio-mc17/build.gradle +++ b/panelstudio-mc17/build.gradle @@ -22,10 +22,6 @@ repositories { } } -loom { - remapArchives=false -} - dependencies { minecraft "com.mojang:minecraft:${minecraft17}" mappings "net.fabricmc:yarn:${mappings17}:v2" diff --git a/panelstudio-mc17/gradle.properties b/panelstudio-mc17/gradle.properties index 363890c..6135a27 100644 --- a/panelstudio-mc17/gradle.properties +++ b/panelstudio-mc17/gradle.properties @@ -1,7 +1,9 @@ org.gradle.jvmargs = -Xmx2500m -version = 0.2.2 +version = 0.2.3 coreVersion = 0.2.1 -loomVersion = 0.12.1 +loomVersion = 1.0.11 minecraft17 = 1.17.1 mappings17 = 1.17.1+build.65 + +fabric.loom.dontRemap = true diff --git a/panelstudio-mc19/build.gradle b/panelstudio-mc19/build.gradle new file mode 100644 index 0000000..9c84da4 --- /dev/null +++ b/panelstudio-mc19/build.gradle @@ -0,0 +1,79 @@ + +buildscript { + repositories { + jcenter() + maven { + name = "Fabric" + url = "https://maven.fabricmc.net/" + } + } + dependencies { + classpath "net.fabricmc:fabric-loom:${loomVersion}" + } +} + +apply plugin: "fabric-loom" +apply plugin: "maven-publish" + +repositories { + maven { + name = "lukflug" + url = "https://lukflug.github.io/maven/" + } +} + +dependencies { + minecraft "com.mojang:minecraft:${minecraft19}" + mappings "net.fabricmc:yarn:${mappings19}:v2" + annotationProcessor "org.ow2.asm:asm:9.0" + annotationProcessor "org.ow2.asm:asm-analysis:9.0" + annotationProcessor "org.ow2.asm:asm-commons:9.0" + annotationProcessor "org.ow2.asm:asm-tree:9.0" + annotationProcessor "org.ow2.asm:asm-util:9.0" + implementation "com.lukflug:panelstudio:${coreVersion}" +} + +processResources { + inputs.property "version", project.version + filesMatching("fabric.mod.json") { + expand "version": project.version + } +} + +task sourcesJar(type: Jar) { + from sourceSets.main.allJava + classifier = "sources" +} + +publishing { + publications { + mavenJava(MavenPublication) { + groupId "com.lukflug" + artifact jar { + classifier "" + } + artifact sourcesJar + pom { + name = "PanelStudio-MC19" + description = "A supplement to PanelStudio designed for FabricMC 1.19.x" + url = "https://github.com/lukflug/PanelStudio" + licenses { + license { + name = "MIT License" + url = "https://raw.githubusercontent.com/lukflug/PanelStudio/main/LICENSE" + } + } + developers { + developer { + id = "lukflug" + } + } + } + } + } + repositories { + maven { + url = "${projectDir}/../../lukflug.github.io/maven" + } + } +} diff --git a/panelstudio-mc19/gradle.properties b/panelstudio-mc19/gradle.properties new file mode 100644 index 0000000..02c94f6 --- /dev/null +++ b/panelstudio-mc19/gradle.properties @@ -0,0 +1,9 @@ +org.gradle.jvmargs = -Xmx2500m +version = 0.2.3 +coreVersion = 0.2.1 + +loomVersion = 1.0.11 +minecraft19 = 1.19.2 +mappings19 = 1.19.2+build.28 + +fabric.loom.dontRemap = true diff --git a/panelstudio-mc19/gradle/wrapper/gradle-wrapper.jar b/panelstudio-mc19/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..f3d88b1 Binary files /dev/null and b/panelstudio-mc19/gradle/wrapper/gradle-wrapper.jar differ diff --git a/panelstudio-mc19/gradle/wrapper/gradle-wrapper.properties b/panelstudio-mc19/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..41dfb87 --- /dev/null +++ b/panelstudio-mc19/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/panelstudio-mc19/gradlew b/panelstudio-mc19/gradlew new file mode 100644 index 0000000..2fe81a7 --- /dev/null +++ b/panelstudio-mc19/gradlew @@ -0,0 +1,183 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/panelstudio-mc19/gradlew.bat b/panelstudio-mc19/gradlew.bat new file mode 100644 index 0000000..62bd9b9 --- /dev/null +++ b/panelstudio-mc19/gradlew.bat @@ -0,0 +1,103 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/panelstudio-mc19/settings.gradle b/panelstudio-mc19/settings.gradle new file mode 100644 index 0000000..e69de29 diff --git a/panelstudio-mc19/src/main/java/com/lukflug/panelstudio/mc19/GLInterface.java b/panelstudio-mc19/src/main/java/com/lukflug/panelstudio/mc19/GLInterface.java new file mode 100644 index 0000000..ff9e70b --- /dev/null +++ b/panelstudio-mc19/src/main/java/com/lukflug/panelstudio/mc19/GLInterface.java @@ -0,0 +1,346 @@ +package com.lukflug.panelstudio.mc19; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.io.InputStream; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.FloatBuffer; +import java.nio.IntBuffer; +import java.util.Stack; + +import javax.imageio.ImageIO; + +import org.lwjgl.opengl.GL11; + +import com.lukflug.panelstudio.base.IInterface; +import com.mojang.blaze3d.platform.GlStateManager; +import com.mojang.blaze3d.platform.TextureUtil; +import com.mojang.blaze3d.systems.RenderSystem; + +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.render.BufferBuilder; +import net.minecraft.client.render.GameRenderer; +import net.minecraft.client.render.Tessellator; +import net.minecraft.client.render.VertexFormat.DrawMode; +import net.minecraft.client.render.VertexFormats; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.util.Identifier; +import net.minecraft.util.math.Matrix4f; + +/** + * Implementation of {@link IInterface} for OpenGL in Minecraft. + * @author lukflug, Diliard + */ +public abstract class GLInterface implements IInterface { + /** + * Clipping rectangle stack. + */ + private final Stack clipRect=new Stack(); + /** + * Stored projection matrix. + */ + private Matrix4f projection=null; + /** + * Boolean indicating whether to clip in the horizontal direction. + */ + protected boolean clipX; + + /** + * Constructor. + * @param clipX whether to clip in the horizontal direction + */ + public GLInterface (boolean clipX) { + this.clipX=clipX; + } + + @Override + public Dimension getWindowSize() { + return new Dimension((int)Math.ceil(getScreenWidth()),(int)Math.ceil(getScreenHeight())); + } + + @SuppressWarnings("resource") + @Override + public void drawString (Point pos, int height, String s, Color c) { + MatrixStack modelview=RenderSystem.getModelViewStack(); + modelview.push(); + modelview.translate(pos.x,pos.y,0); + float scale=height/(float)MinecraftClient.getInstance().textRenderer.fontHeight; + modelview.scale(scale,scale,1); + RenderSystem.applyModelViewMatrix(); + end(false); + MinecraftClient.getInstance().textRenderer.drawWithShadow(getMatrixStack(),s,0,0,c.getRGB()); + begin(false); + modelview.pop(); + RenderSystem.applyModelViewMatrix(); + } + + @SuppressWarnings("resource") + @Override + public int getFontWidth (int height, String s) { + double scale=height/(double)MinecraftClient.getInstance().textRenderer.fontHeight; + return (int)Math.round(MinecraftClient.getInstance().textRenderer.getWidth(s)*scale); + } + + @Override + public void fillTriangle (Point pos1, Point pos2, Point pos3, Color c1, Color c2, Color c3) { + RenderSystem.setShader(GameRenderer::getPositionColorShader); + Tessellator tessellator = Tessellator.getInstance(); + BufferBuilder bufferbuilder = tessellator.getBuffer(); + bufferbuilder.begin(DrawMode.TRIANGLES,VertexFormats.POSITION_COLOR); + bufferbuilder.vertex(pos1.x,pos1.y,getZLevel()).color(c1.getRed()/255.0f,c1.getGreen()/255.0f,c1.getBlue()/255.0f,c1.getAlpha()/255.0f).next(); + bufferbuilder.vertex(pos2.x,pos2.y,getZLevel()).color(c2.getRed()/255.0f,c2.getGreen()/255.0f,c2.getBlue()/255.0f,c2.getAlpha()/255.0f).next(); + bufferbuilder.vertex(pos3.x,pos3.y,getZLevel()).color(c3.getRed()/255.0f,c3.getGreen()/255.0f,c3.getBlue()/255.0f,c3.getAlpha()/255.0f).next(); + tessellator.draw(); + } + + @Override + public void drawLine (Point a, Point b, Color c1, Color c2) { + RenderSystem.setShader(GameRenderer::getRenderTypeLinesShader); + float normalx=b.x-a.x,normaly=b.y-a.y; + float scale=(float)Math.sqrt(normalx*normalx+normaly*normaly); + normalx/=scale; + normaly/=scale; + Tessellator tessellator = Tessellator.getInstance(); + BufferBuilder bufferbuilder = tessellator.getBuffer(); + bufferbuilder.begin(DrawMode.LINES,VertexFormats.LINES); + bufferbuilder.vertex(a.x*256/255f,a.y*256/255f,getZLevel()).color(c1.getRed()/255.0f,c1.getGreen()/255.0f,c1.getBlue()/255.0f,c1.getAlpha()/255.0f).normal(normalx,normaly,0).next(); + bufferbuilder.vertex(b.x*256/255f,b.y*256/255f,getZLevel()).color(c2.getRed()/255.0f,c2.getGreen()/255.0f,c2.getBlue()/255.0f,c2.getAlpha()/255.0f).normal(normalx,normaly,0).next(); + tessellator.draw(); + } + + @Override + public void fillRect (Rectangle r, Color c1, Color c2, Color c3, Color c4) { + RenderSystem.setShader(GameRenderer::getPositionColorShader); + Tessellator tessellator = Tessellator.getInstance(); + BufferBuilder bufferbuilder = tessellator.getBuffer(); + bufferbuilder.begin(DrawMode.QUADS, VertexFormats.POSITION_COLOR); + bufferbuilder.vertex(r.x,r.y+r.height,getZLevel()).color(c4.getRed()/255.0f,c4.getGreen()/255.0f,c4.getBlue()/255.0f,c4.getAlpha()/255.0f).next(); + bufferbuilder.vertex(r.x+r.width,r.y+r.height,getZLevel()).color(c3.getRed()/255.0f,c3.getGreen()/255.0f,c3.getBlue()/255.0f,c3.getAlpha()/255.0f).next(); + bufferbuilder.vertex(r.x+r.width,r.y,getZLevel()).color(c2.getRed()/255.0f,c2.getGreen()/255.0f,c2.getBlue()/255.0f,c2.getAlpha()/255.0f).next(); + bufferbuilder.vertex(r.x,r.y,getZLevel()).color(c1.getRed()/255.0f,c1.getGreen()/255.0f,c1.getBlue()/255.0f,c1.getAlpha()/255.0f).next(); + tessellator.draw(); + } + + @Override + public void drawRect (Rectangle r, Color c1, Color c2, Color c3, Color c4) { + drawLine(new Point(r.x,r.y+r.height),new Point(r.x+r.width,r.y+r.height),c4,c3); + drawLine(new Point(r.x+r.width,r.y+r.height),new Point(r.x+r.width,r.y),c3,c2); + drawLine(new Point(r.x+r.width,r.y),new Point(r.x,r.y),c2,c1); + drawLine(new Point(r.x,r.y),new Point(r.x,r.y+r.height),c1,c4); + } + + @Override + public synchronized int loadImage (String name) { + try { + Identifier rl=new Identifier(getResourcePrefix()+name); + //InputStream stream = MinecraftClient.getInstance().getResourceManager().getResource(rl).getInputStream(); + InputStream stream = MinecraftClient.getInstance().getResourceManager().getResource(rl).get().getInputStream(); + BufferedImage image=ImageIO.read(stream); + int texture=TextureUtil.generateTextureId(); + RenderSystem.bindTextureForSetup(texture); + int width=image.getWidth(),height=image.getHeight(); + IntBuffer buffer=ByteBuffer.allocateDirect(4*width*height).order(ByteOrder.nativeOrder()).asIntBuffer(); + buffer.put(image.getRGB(0,0,width,height,null,0,width)); + buffer.flip(); + TextureUtil.initTexture(buffer,width,height); + return texture; + } catch (IOException e) { + e.printStackTrace(); + return 0; + } + } + + @Override + public void drawImage (Rectangle r, int rotation, boolean parity, int image, Color color) { + if (image==0) return; + int texCoords[][]={{0,1},{1,1},{1,0},{0,0}}; + for (int i=0;ix1 && y2>y1) { + Rectangle rect=new Rectangle(x1,y1,x2-x1,y2-y1); + scissor(rect); + clipRect.push(rect); + } else { + scissor(null); + clipRect.push(null); + } + } + } + } + + @Override + public void restore() { + if (!clipRect.isEmpty()) { + clipRect.pop(); + if (clipRect.isEmpty()) GL11.glDisable(GL11.GL_SCISSOR_TEST); + else scissor(clipRect.peek()); + } + } + + /** + * Utility function to convert screen pixel coordinates to PanelStudio GUI coordinates. + * @param p the screen coordinates + * @return the corresponding GUI coordinates + */ + public Point screenToGui (Point p) { + int resX=getWindowSize().width; + int resY=getWindowSize().height; + return new Point(p.x*resX/MinecraftClient.getInstance().getWindow().getWidth(),resY-p.y*resY/MinecraftClient.getInstance().getWindow().getHeight()-1); + } + + /** + * Utility function to convert PanelStudio GUI coordinates to screen pixel coordinates. + * @param p the GUI coordinates + * @return the corresponding screen coordinates + */ + public Point guiToScreen (Point p) { + double resX=getScreenWidth(); + double resY=getScreenHeight(); + return new Point((int)Math.round(p.x*MinecraftClient.getInstance().getWindow().getWidth()/resX),(int)Math.round((resY-p.y)*MinecraftClient.getInstance().getWindow().getHeight()/resY)); + } + + /** + * Get the current screen width. + * @return the screen width + */ + protected double getScreenWidth() { + return MinecraftClient.getInstance().getWindow().getScaledWidth(); + } + + /** + * Get the current screen height. + * @return the screen height + */ + protected double getScreenHeight() { + return MinecraftClient.getInstance().getWindow().getScaledHeight(); + } + + /** + * Set OpenGL to the state used by the rendering methods. + * Should be called before rendering. + * @param matrix whether to set up the modelview matrix + */ + public void begin (boolean matrix) { + if (matrix) { + projection=RenderSystem.getProjectionMatrix().copy(); + float array[]={2/(float)getScreenWidth(),0,0,-1, 0,-2/(float)getScreenHeight(),0,1, 0,0,-1/3000f,0, 0,0,0,1}; + FloatBuffer buffer=FloatBuffer.allocate(16).put(array).flip(); + RenderSystem.getProjectionMatrix().readRowMajor(buffer); + MatrixStack modelview=RenderSystem.getModelViewStack(); + modelview.push(); + modelview.loadIdentity(); + RenderSystem.applyModelViewMatrix(); + } + RenderSystem.enableBlend(); + RenderSystem.disableTexture(); + RenderSystem.disableCull(); + RenderSystem.lineWidth(2); + RenderSystem.blendFuncSeparate(GL11.GL_SRC_ALPHA,GL11.GL_ONE_MINUS_SRC_ALPHA,GL11.GL_ONE,GL11.GL_ZERO); + } + + /** + * Restore OpenGL to the state expected by Minecraft. + * Should be called after rendering. + * @param matrix whether to restore the modelview matrix + */ + public void end (boolean matrix) { + RenderSystem.enableCull(); + RenderSystem.enableTexture(); + RenderSystem.disableBlend(); + if (matrix) { + RenderSystem.getModelViewStack().pop(); + RenderSystem.applyModelViewMatrix(); + RenderSystem.getProjectionMatrix().load(projection); + projection=null; + } + } + + /** + * Get the z-coordinate to render everything. + * @return the z-level + */ + protected abstract float getZLevel(); + + /** + * Get the matrix stack to be used. + * @return the current matrix stack + */ + protected abstract MatrixStack getMatrixStack(); + + /** + * Get the Minecraft resource location string. + * @return the resource prefix + */ + protected abstract String getResourcePrefix(); +} diff --git a/panelstudio-mc19/src/main/java/com/lukflug/panelstudio/mc19/MinecraftGUI.java b/panelstudio-mc19/src/main/java/com/lukflug/panelstudio/mc19/MinecraftGUI.java new file mode 100644 index 0000000..a051793 --- /dev/null +++ b/panelstudio-mc19/src/main/java/com/lukflug/panelstudio/mc19/MinecraftGUI.java @@ -0,0 +1,229 @@ +package com.lukflug.panelstudio.mc19; + +import java.awt.Point; + +import net.minecraft.text.Text; +import org.lwjgl.glfw.GLFW; + +import com.lukflug.panelstudio.base.IInterface; +import com.lukflug.panelstudio.container.GUI; + +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.util.math.MatrixStack; + +/** + * Implementation of Minecraft's {@link Screen} that renders a PanelStudio GUI. + * @author lukflug, Diliard + */ +public abstract class MinecraftGUI extends Screen { + /** + * The current mouse position. + */ + private Point mouse=new Point(); + /** + * Current left mouse button state. + */ + private boolean lButton=false; + /** + * Current right mouse button state. + */ + private boolean rButton=false; + /** + * Current GLFW modifier bits. + */ + private int modifiers=0; + /** + * Last rendering time. + */ + private long lastTime; + /** + * Saved matrix stack; + */ + protected MatrixStack matrixStack=null; + + /** + * Constructor. + */ + public MinecraftGUI() { + super(Text.literal("PanelStudio GUI")); + } + + /** + * Displays the GUI. + */ + public void enterGUI() { + MinecraftClient.getInstance().setScreen(this); + } + + /** + * Closes the GUI. + */ + public void exitGUI() { + MinecraftClient.getInstance().setScreen(null); + } + + /** + * Renders the GUI. + */ + protected void renderGUI() { + lastTime=System.currentTimeMillis(); + getInterface().begin(true); + getGUI().render(); + getInterface().end(true); + } + + @Override + public void init() { + getGUI().enter(); + } + + @Override + public void removed() { + getGUI().exit(); + } + + @Override + public void render (MatrixStack matrices, int mouseX, int mouseY, float partialTicks) { + matrixStack=matrices; + mouse=new Point((int)Math.round(mouseX),(int)Math.round(mouseY)); + renderGUI(); + } + + @Override + public boolean mouseScrolled (double mouseX, double mouseY, double scroll) { + if (!super.mouseScrolled(mouseX,mouseY,scroll)) { + mouse=new Point((int)Math.round(mouseX),(int)Math.round(mouseY)); + if (scroll!=0) { + if (scroll>0) getGUI().handleScroll(-getScrollSpeed()); + else getGUI().handleScroll(getScrollSpeed()); + } + } + return true; + } + + @Override + public boolean mouseClicked (double mouseX, double mouseY, int clickedButton) { + if (!super.mouseReleased(mouseX,mouseY,clickedButton)) { + mouse=new Point((int)Math.round(mouseX),(int)Math.round(mouseY)); + switch (clickedButton) { + case IInterface.LBUTTON: { lButton = true; break; } + case IInterface.RBUTTON: { rButton = true; break; } + } + getGUI().handleButton(clickedButton); + } + return true; + } + + @Override + public boolean mouseReleased (double mouseX, double mouseY, int releaseButton) { + if (!super.mouseReleased(mouseX,mouseY,releaseButton)) { + mouse=new Point((int)Math.round(mouseX),(int)Math.round(mouseY)); + switch (releaseButton) { + case IInterface.LBUTTON: { lButton = false; break; } + case IInterface.RBUTTON: { rButton = false; break; } + } + getGUI().handleButton(releaseButton); + } + return true; + } + + @Override + public boolean keyPressed (int keyCode, int scanCode, int modifiers) { + this.modifiers=modifiers; + if (keyCode==GLFW.GLFW_KEY_ESCAPE) exitGUI(); + else getGUI().handleKey(keyCode); + return true; + } + + @Override + public boolean charTyped (char chr, int modifiers) { + this.modifiers=modifiers; + getGUI().handleChar(chr); + return true; + } + + @Override + public boolean shouldPause() { + return false; + } + + /** + * Get the {@link GUI} to be rendered. + * @return current GUI + */ + protected abstract GUI getGUI(); + + /** + * Get current {@link GUIInterface}. + * @return the current interface + */ + protected abstract GUIInterface getInterface(); + + /** + * Get current scroll speed. + * @return the scroll speed + */ + protected abstract int getScrollSpeed(); + + + /** + * Implementation of {@link GLInterface} to be used with {@link MinecraftGUI} + * @author lukflug + */ + public abstract class GUIInterface extends GLInterface { + /** + * Constructor. + * @param clipX whether to clip in the horizontal direction + */ + public GUIInterface (boolean clipX) { + super(clipX); + } + + @Override + public boolean getModifier (int modifier) { + switch (modifier) { + case SHIFT: + return (modifiers&GLFW.GLFW_MOD_SHIFT)!=0; + case CTRL: + return (modifiers&GLFW.GLFW_MOD_CONTROL)!=0; + case ALT: + return (modifiers&GLFW.GLFW_MOD_ALT)!=0; + case SUPER: + return (modifiers&GLFW.GLFW_MOD_SUPER)!=0; + } + return false; + } + + @Override + public long getTime() { + return lastTime; + } + + @Override + public boolean getButton (int button) { + switch (button) { + case IInterface.LBUTTON: + return lButton; + case IInterface.RBUTTON: + return rButton; + } + return false; + } + + @Override + public Point getMouse() { + return new Point(mouse); + } + + @Override + protected float getZLevel() { + return getZOffset(); + } + + @Override + protected MatrixStack getMatrixStack() { + return matrixStack; + } + } +} diff --git a/panelstudio-mc19/src/main/java/com/lukflug/panelstudio/mc19/MinecraftHUDGUI.java b/panelstudio-mc19/src/main/java/com/lukflug/panelstudio/mc19/MinecraftHUDGUI.java new file mode 100644 index 0000000..1380d49 --- /dev/null +++ b/panelstudio-mc19/src/main/java/com/lukflug/panelstudio/mc19/MinecraftHUDGUI.java @@ -0,0 +1,73 @@ +package com.lukflug.panelstudio.mc19; + +import org.lwjgl.glfw.GLFW; + +import com.lukflug.panelstudio.container.GUI; +import com.lukflug.panelstudio.hud.HUDGUI; + +/** + * An extension of {@link MinecraftGUI} for HUD editors. + * @author lukflug + */ +public abstract class MinecraftHUDGUI extends MinecraftGUI { + /** + * Whether {@link GUI#enter()} has been called. + */ + private boolean guiOpened=false; + + @Override + public void enterGUI() { + if (!getGUI().getGUIVisibility().isOn()) getGUI().getGUIVisibility().toggle(); + if (!getGUI().getHUDVisibility().isOn()) getGUI().getHUDVisibility().toggle(); + super.enterGUI(); + } + + @Override + public void exitGUI() { + if (getGUI().getGUIVisibility().isOn()) getGUI().getGUIVisibility().toggle(); + if (getGUI().getHUDVisibility().isOn()) getGUI().getHUDVisibility().toggle(); + super.exitGUI(); + } + + /** + * Open the HUD editor. + */ + public void enterHUDEditor() { + if (getGUI().getGUIVisibility().isOn()) getGUI().getGUIVisibility().toggle(); + if (!getGUI().getHUDVisibility().isOn()) getGUI().getHUDVisibility().toggle(); + super.enterGUI(); + } + + @Override + public void init() { + } + + @Override + public void removed() { + } + + @Override + protected void renderGUI() { + if (!guiOpened) getGUI().enter(); + guiOpened=true; + super.renderGUI(); + } + + /** + * Render function to be called even when the GUI is closed. + */ + public void render() { + if (!getGUI().getGUIVisibility().isOn() && !getGUI().getHUDVisibility().isOn()) renderGUI(); + } + + /** + * Key event function to be called when the GUI is closed. + * @param scancode the key scancode + */ + public void handleKeyEvent (int scancode) { + if (scancode!=GLFW.GLFW_KEY_ESCAPE && !getGUI().getGUIVisibility().isOn() && !getGUI().getGUIVisibility().isOn()) getGUI().handleKey(scancode); + } + + @Override + protected abstract HUDGUI getGUI(); +} diff --git a/panelstudio-mc19/src/main/java/com/lukflug/panelstudio/mc19/package-info.java b/panelstudio-mc19/src/main/java/com/lukflug/panelstudio/mc19/package-info.java new file mode 100644 index 0000000..2cb68bb --- /dev/null +++ b/panelstudio-mc19/src/main/java/com/lukflug/panelstudio/mc19/package-info.java @@ -0,0 +1,6 @@ +/** + * PanelStudio-MC utility functions designed for FabricMC 1.19.x. + * This library only depends on the Fabric Yarn mappings and not on the Fabric Mod Loader or the Fabric API. + * @author lukflug, Diliard + */ +package com.lukflug.panelstudio.mc19; diff --git a/panelstudio-mc19/src/main/resources/fabric.mod.json b/panelstudio-mc19/src/main/resources/fabric.mod.json new file mode 100644 index 0000000..d6c5f22 --- /dev/null +++ b/panelstudio-mc19/src/main/resources/fabric.mod.json @@ -0,0 +1,17 @@ +{ + "schemaVersion": 1, + "id": "panelstudio", + "version": "${version}", + "name": "PanelStudio-MC19", + "description": "A supplement to PanelStudio designed for FabricMC 1.19.x.", + "authors": ["lukflug, Diliard"], + "contact": { + "homepage": "https://lukflug.github.io", + "sources": "https://github.com/lukflug/PanelStudio" + }, + "license": "MIT", + "environment": "*", + "depends": { + "minecraft": ["1.19.x"] + } +} diff --git a/panelstudio-mc8-fabric/build.gradle b/panelstudio-mc8-fabric/build.gradle index 2129dca..2a7995f 100644 --- a/panelstudio-mc8-fabric/build.gradle +++ b/panelstudio-mc8-fabric/build.gradle @@ -31,7 +31,7 @@ minecraft { dependencies { minecraft "com.mojang:minecraft:${minecraft8fabric}" - mappings "net.fabricmc:yarn:${mappings8fabric}:v2" + mappings "net.legacyfabric:yarn:${mappings8fabric}:v2" annotationProcessor "org.ow2.asm:asm:9.0" annotationProcessor "org.ow2.asm:asm-analysis:9.0" annotationProcessor "org.ow2.asm:asm-commons:9.0"