diff --git a/.github/workflows/mc17.yml b/.github/workflows/mc17.yml index 6cf1490..df917b0 100644 --- a/.github/workflows/mc17.yml +++ b/.github/workflows/mc17.yml @@ -37,6 +37,11 @@ jobs: cd example-mod17 chmod +x gradlew ./gradlew build + - name: Build ExampleMod18 + run: | + cd example-mod18 + chmod +x gradlew + ./gradlew build - name: Upload package uses: actions/upload-artifact@v2 with: diff --git a/README.md b/README.md index 2e73ecb..8e063bf 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ In addition to the core PanelStudio library, there are the PanelStudio-MC suppor | panelstudio-mc16-forge | example-mod16-forge | Minecraft Forge 1.16.5 | | 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 | FabricMC 1.17.1 | +| panelstudio-mc17 | example-mod17 & example-mod18 | FabricMC 1.17.x & 1.18.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. diff --git a/example-mod17/build.gradle b/example-mod17/build.gradle index bd2e478..c02039b 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_1" + relocate "com.lukflug.panelstudio","com.lukflug.panelstudio_0_2_2" } remapJar.dependsOn(shadowJar) diff --git a/example-mod17/gradle.properties b/example-mod17/gradle.properties index bb02066..243600b 100644 --- a/example-mod17/gradle.properties +++ b/example-mod17/gradle.properties @@ -1,6 +1,6 @@ org.gradle.jvmargs = -Xmx2500m version = 0.2.1 -versionmc = 0.2.0 +versionmc = 0.2.2 loomVersion = 0.12.1 minecraft17 = 1.17.1 diff --git a/example-mod18/build.gradle b/example-mod18/build.gradle new file mode 100644 index 0000000..033beae --- /dev/null +++ b/example-mod18/build.gradle @@ -0,0 +1,57 @@ + +buildscript { + repositories { + gradlePluginPortal() + maven { + name = "Fabric" + url = "https://maven.fabricmc.net/" + } + } + 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:${minecraft18}" + mappings "net.fabricmc:yarn:${mappings18}:v2" + modImplementation "net.fabricmc:fabric-loader:${loader18}" + modImplementation "net.fabricmc.fabric-api:fabric-api:${api18}" + shadow "com.lukflug:panelstudio:${version}" + shadow("com.lukflug:panelstudio-mc17:${versionmc}") {changing = true} +} + +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_2" +} + +remapJar.dependsOn(shadowJar) diff --git a/example-mod18/gradle.properties b/example-mod18/gradle.properties new file mode 100644 index 0000000..a2cd8ab --- /dev/null +++ b/example-mod18/gradle.properties @@ -0,0 +1,9 @@ +org.gradle.jvmargs = -Xmx2500m +version = 0.2.1 +versionmc = 0.2.2 + +loomVersion = 0.12.1 +minecraft18 = 1.18.2 +mappings18 = 1.18.2+build.2 +loader18 = 0.13.3 +api18 = 0.47.9+1.18.2 diff --git a/example-mod18/gradle/wrapper/gradle-wrapper.jar b/example-mod18/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..f3d88b1 Binary files /dev/null and b/example-mod18/gradle/wrapper/gradle-wrapper.jar differ diff --git a/example-mod18/gradle/wrapper/gradle-wrapper.properties b/example-mod18/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..41dfb87 --- /dev/null +++ b/example-mod18/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-mod18/gradlew b/example-mod18/gradlew new file mode 100644 index 0000000..2fe81a7 --- /dev/null +++ b/example-mod18/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-mod18/gradlew.bat b/example-mod18/gradlew.bat new file mode 100644 index 0000000..62bd9b9 --- /dev/null +++ b/example-mod18/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-mod18/settings.gradle b/example-mod18/settings.gradle new file mode 100644 index 0000000..e69de29 diff --git a/example-mod18/src/main/java/com/lukflug/examplemod18/ClickGUI.java b/example-mod18/src/main/java/com/lukflug/examplemod18/ClickGUI.java new file mode 100644 index 0000000..dcb2d2f --- /dev/null +++ b/example-mod18/src/main/java/com/lukflug/examplemod18/ClickGUI.java @@ -0,0 +1,495 @@ +package com.lukflug.examplemod18; + +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.examplemod18.module.Category; +import com.lukflug.examplemod18.module.ClickGUIModule; +import com.lukflug.examplemod18.module.ClickGUIModule.Theme; +import com.lukflug.examplemod18.module.HUDEditorModule; +import com.lukflug.examplemod18.module.LogoModule; +import com.lukflug.examplemod18.module.TabGUIModule; +import com.lukflug.examplemod18.module.WatermarkModule; +import com.lukflug.examplemod18.setting.BooleanSetting; +import com.lukflug.examplemod18.setting.ColorSetting; +import com.lukflug.examplemod18.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.mc17.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-mod18/src/main/java/com/lukflug/examplemod18/ExampleMod.java b/example-mod18/src/main/java/com/lukflug/examplemod18/ExampleMod.java new file mode 100644 index 0000000..7bde2a8 --- /dev/null +++ b/example-mod18/src/main/java/com/lukflug/examplemod18/ExampleMod.java @@ -0,0 +1,49 @@ +package com.lukflug.examplemod18; + +import org.lwjgl.glfw.GLFW; + +import com.lukflug.examplemod18.module.Category; +import com.lukflug.examplemod18.module.ClickGUIModule; +import com.lukflug.examplemod18.module.HUDEditorModule; +import com.lukflug.examplemod18.module.LogoModule; +import com.lukflug.examplemod18.module.TabGUIModule; +import com.lukflug.examplemod18.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-mod18/src/main/java/com/lukflug/examplemod18/module/HUDEditorModule.java b/example-mod18/src/main/java/com/lukflug/examplemod18/module/HUDEditorModule.java new file mode 100644 index 0000000..7900a75 --- /dev/null +++ b/example-mod18/src/main/java/com/lukflug/examplemod18/module/HUDEditorModule.java @@ -0,0 +1,17 @@ +package com.lukflug.examplemod18.module; + +import org.lwjgl.glfw.GLFW; + +import com.lukflug.examplemod18.setting.BooleanSetting; +import com.lukflug.examplemod18.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-mod18/src/main/java/com/lukflug/examplemod18/module/LogoModule.java b/example-mod18/src/main/java/com/lukflug/examplemod18/module/LogoModule.java new file mode 100644 index 0000000..7740fc7 --- /dev/null +++ b/example-mod18/src/main/java/com/lukflug/examplemod18/module/LogoModule.java @@ -0,0 +1,49 @@ +package com.lukflug.examplemod18.module; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Point; + +import com.lukflug.examplemod18.setting.BooleanSetting; +import com.lukflug.examplemod18.setting.ColorSetting; +import com.lukflug.examplemod18.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-mod18/src/main/java/com/lukflug/examplemod18/module/Module.java b/example-mod18/src/main/java/com/lukflug/examplemod18/module/Module.java new file mode 100644 index 0000000..cd15da6 --- /dev/null +++ b/example-mod18/src/main/java/com/lukflug/examplemod18/module/Module.java @@ -0,0 +1,62 @@ +package com.lukflug.examplemod18.module; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Stream; + +import com.lukflug.examplemod18.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-mod18/src/main/java/com/lukflug/examplemod18/module/TabGUIModule.java b/example-mod18/src/main/java/com/lukflug/examplemod18/module/TabGUIModule.java new file mode 100644 index 0000000..decce0b --- /dev/null +++ b/example-mod18/src/main/java/com/lukflug/examplemod18/module/TabGUIModule.java @@ -0,0 +1,49 @@ +package com.lukflug.examplemod18.module; + +import java.awt.Color; +import java.awt.Point; +import java.util.function.Supplier; + +import org.lwjgl.glfw.GLFW; + +import com.lukflug.examplemod18.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-mod18/src/main/java/com/lukflug/examplemod18/module/WatermarkModule.java b/example-mod18/src/main/java/com/lukflug/examplemod18/module/WatermarkModule.java new file mode 100644 index 0000000..13c0d89 --- /dev/null +++ b/example-mod18/src/main/java/com/lukflug/examplemod18/module/WatermarkModule.java @@ -0,0 +1,68 @@ +package com.lukflug.examplemod18.module; + +import java.awt.Color; +import java.awt.Point; + +import com.lukflug.examplemod18.setting.BooleanSetting; +import com.lukflug.examplemod18.setting.ColorSetting; +import com.lukflug.examplemod18.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-mod18/src/main/java/com/lukflug/examplemod18/setting/BooleanSetting.java b/example-mod18/src/main/java/com/lukflug/examplemod18/setting/BooleanSetting.java new file mode 100644 index 0000000..1662555 --- /dev/null +++ b/example-mod18/src/main/java/com/lukflug/examplemod18/setting/BooleanSetting.java @@ -0,0 +1,20 @@ +package com.lukflug.examplemod18.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-mod18/src/main/java/com/lukflug/examplemod18/setting/ColorSetting.java b/example-mod18/src/main/java/com/lukflug/examplemod18/setting/ColorSetting.java new file mode 100644 index 0000000..803fce3 --- /dev/null +++ b/example-mod18/src/main/java/com/lukflug/examplemod18/setting/ColorSetting.java @@ -0,0 +1,60 @@ +package com.lukflug.examplemod18.setting; + +import java.awt.Color; + +import com.lukflug.examplemod18.module.ClickGUIModule; +import com.lukflug.examplemod18.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-mod18/src/main/java/com/lukflug/examplemod18/setting/DoubleSetting.java b/example-mod18/src/main/java/com/lukflug/examplemod18/setting/DoubleSetting.java new file mode 100644 index 0000000..dde98a6 --- /dev/null +++ b/example-mod18/src/main/java/com/lukflug/examplemod18/setting/DoubleSetting.java @@ -0,0 +1,39 @@ +package com.lukflug.examplemod18.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-mod18/src/main/java/com/lukflug/examplemod18/setting/EnumSetting.java b/example-mod18/src/main/java/com/lukflug/examplemod18/setting/EnumSetting.java new file mode 100644 index 0000000..ecc1c3c --- /dev/null +++ b/example-mod18/src/main/java/com/lukflug/examplemod18/setting/EnumSetting.java @@ -0,0 +1,61 @@ +package com.lukflug.examplemod18.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-mod18/src/main/java/com/lukflug/examplemod18/setting/IntegerSetting.java b/example-mod18/src/main/java/com/lukflug/examplemod18/setting/IntegerSetting.java new file mode 100644 index 0000000..ee203d1 --- /dev/null +++ b/example-mod18/src/main/java/com/lukflug/examplemod18/setting/IntegerSetting.java @@ -0,0 +1,39 @@ +package com.lukflug.examplemod18.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-mod18/src/main/java/com/lukflug/examplemod18/setting/KeybindSetting.java b/example-mod18/src/main/java/com/lukflug/examplemod18/setting/KeybindSetting.java new file mode 100644 index 0000000..bcba234 --- /dev/null +++ b/example-mod18/src/main/java/com/lukflug/examplemod18/setting/KeybindSetting.java @@ -0,0 +1,31 @@ +package com.lukflug.examplemod18.setting; + +import com.lukflug.panelstudio.base.IBoolean; +import com.lukflug.panelstudio.setting.IKeybindSetting; + +import net.minecraft.client.util.InputUtil; +import net.minecraft.text.TranslatableText; + +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 TranslatableText(translationKey).getString(); + if (!translation.equals(translationKey)) return translation; + return InputUtil.Type.KEYSYM.createFromCode(getKey()).getLocalizedText().getString(); + } +} diff --git a/example-mod18/src/main/java/com/lukflug/examplemod18/setting/Setting.java b/example-mod18/src/main/java/com/lukflug/examplemod18/setting/Setting.java new file mode 100644 index 0000000..1de0213 --- /dev/null +++ b/example-mod18/src/main/java/com/lukflug/examplemod18/setting/Setting.java @@ -0,0 +1,52 @@ +package com.lukflug.examplemod18.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-mod18/src/main/java/com/lukflug/examplemod18/setting/StringSetting.java b/example-mod18/src/main/java/com/lukflug/examplemod18/setting/StringSetting.java new file mode 100644 index 0000000..42c944f --- /dev/null +++ b/example-mod18/src/main/java/com/lukflug/examplemod18/setting/StringSetting.java @@ -0,0 +1,10 @@ +package com.lukflug.examplemod18.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-mod18/src/main/resources/assets/examplemod/panelstudio.png b/example-mod18/src/main/resources/assets/examplemod/panelstudio.png new file mode 100644 index 0000000..5cf536a Binary files /dev/null and b/example-mod18/src/main/resources/assets/examplemod/panelstudio.png differ diff --git a/example-mod18/src/main/resources/fabric.mod.json b/example-mod18/src/main/resources/fabric.mod.json new file mode 100644 index 0000000..f0a24c8 --- /dev/null +++ b/example-mod18/src/main/resources/fabric.mod.json @@ -0,0 +1,23 @@ +{ + "schemaVersion": 1, + "id": "example-mod18", + "version": "${version}", + "name": "PanelStudio-MC17 Example Mod", + "description": "An example mod for PanelStudio-MC17.", + "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.examplemod18.ExampleMod"] + }, + "depends": { + "fabric": "*", + "fabricloader": ">=0.7.4", + "minecraft": "1.18.x" + } +} diff --git a/example-mod8-fabric/build.gradle b/example-mod8-fabric/build.gradle index 01a13f1..40afd68 100644 --- a/example-mod8-fabric/build.gradle +++ b/example-mod8-fabric/build.gradle @@ -65,7 +65,7 @@ processResources { shadowJar { classifier = "dev" configurations = [project.configurations.shadow] - relocate "com.lukflug.panelstudio","com.lukflug.panelstudio_0_2_1" + relocate "com.lukflug.panelstudio","com.lukflug.panelstudio_0_2_2" } remapJar.dependsOn(shadowJar) diff --git a/example-mod8-fabric/gradle.properties b/example-mod8-fabric/gradle.properties index 08851d7..469beeb 100644 --- a/example-mod8-fabric/gradle.properties +++ b/example-mod8-fabric/gradle.properties @@ -1,6 +1,6 @@ org.gradle.jvmargs = -Xmx2500m version = 0.2.1 -versionmc = 0.2.0 +versionmc = 0.2.2 loomVersion = 0.7.33 minecraft8fabric = 1.8.9 diff --git a/panelstudio-mc17/build.gradle b/panelstudio-mc17/build.gradle index eb0ebaa..4739709 100644 --- a/panelstudio-mc17/build.gradle +++ b/panelstudio-mc17/build.gradle @@ -59,7 +59,7 @@ publishing { artifact sourcesJar pom { name = "PanelStudio-MC17" - description = "A supplement to PanelStudio designed for FabricMC 1.17.x." + description = "A supplement to PanelStudio designed for FabricMC 1.17.x and 1.18.x." url = "https://github.com/lukflug/PanelStudio" licenses { license { diff --git a/panelstudio-mc17/src/main/resources/fabric.mod.json b/panelstudio-mc17/src/main/resources/fabric.mod.json index ed373e1..10fd49c 100644 --- a/panelstudio-mc17/src/main/resources/fabric.mod.json +++ b/panelstudio-mc17/src/main/resources/fabric.mod.json @@ -3,7 +3,7 @@ "id": "panelstudio", "version": "${version}", "name": "PanelStudio-MC17", - "description": "A supplement to PanelStudio designed for FabricMC 1.17.x.", + "description": "A supplement to PanelStudio designed for FabricMC 1.17.x and 1.18.x.", "authors": ["lukflug"], "contact": { "homepage": "https://lukflug.github.io", @@ -12,6 +12,6 @@ "license": "MIT", "environment": "*", "depends": { - "minecraft": "1.17.x" + "minecraft": ["1.17.x","1.18.x"] } }