Skip to content

Commit

Permalink
Merge pull request #336 from Polyfrost/develop-v0
Browse files Browse the repository at this point in the history
Co-authored-by: ev chang <wyvestbusiness@gmail.com>
Co-authored-by: nextdayy <79922345+nextdayy@users.noreply.github.com>
Co-authored-by: ImToggle <98242902+ImToggle@users.noreply.github.com>
  • Loading branch information
3 people authored May 5, 2024
2 parents 652de2d + d151497 commit b87aa54
Show file tree
Hide file tree
Showing 17 changed files with 565 additions and 81 deletions.
24 changes: 22 additions & 2 deletions api/OneConfig.api
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ public abstract interface annotation class cc/polyfrost/oneconfig/config/annotat
public abstract fun subcategory ()Ljava/lang/String;
}

public abstract interface annotation class cc/polyfrost/oneconfig/config/annotations/SubConfig : java/lang/annotation/Annotation {
}

public abstract interface annotation class cc/polyfrost/oneconfig/config/annotations/Switch : java/lang/annotation/Annotation {
public abstract fun category ()Ljava/lang/String;
public abstract fun description ()Ljava/lang/String;
Expand Down Expand Up @@ -284,7 +287,6 @@ public class cc/polyfrost/oneconfig/config/data/Mod : java/lang/Comparable {
public fun <init> (Ljava/lang/String;Lcc/polyfrost/oneconfig/config/data/ModType;Ljava/lang/String;Lcc/polyfrost/oneconfig/config/migration/Migrator;)V
public fun compareTo (Lcc/polyfrost/oneconfig/config/data/Mod;)I
public synthetic fun compareTo (Ljava/lang/Object;)I
public fun equals (Ljava/lang/Object;)Z
}

public final class cc/polyfrost/oneconfig/config/data/ModType : java/lang/Enum {
Expand Down Expand Up @@ -381,6 +383,13 @@ public class cc/polyfrost/oneconfig/config/elements/OptionSubcategory {
public fun getName ()Ljava/lang/String;
}

public class cc/polyfrost/oneconfig/config/elements/SubConfig : cc/polyfrost/oneconfig/config/Config {
public fun <init> (Ljava/lang/String;Ljava/lang/String;)V
public fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
public fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Z)V
public fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZZ)V
}

public class cc/polyfrost/oneconfig/config/gson/InstanceSupplier : com/google/gson/InstanceCreator {
public fun <init> (Ljava/lang/Object;)V
public fun createInstance (Ljava/lang/reflect/Type;)Ljava/lang/Object;
Expand Down Expand Up @@ -1034,6 +1043,7 @@ public class cc/polyfrost/oneconfig/gui/pages/ModConfigPage : cc/polyfrost/oneco
}

public class cc/polyfrost/oneconfig/gui/pages/ModsPage : cc/polyfrost/oneconfig/gui/pages/Page {
public final field modCards Ljava/util/ArrayList;
public fun <init> ()V
public fun draw (JIILcc/polyfrost/oneconfig/utils/InputHandler;)V
public fun drawStatic (JIILcc/polyfrost/oneconfig/utils/InputHandler;)I
Expand All @@ -1047,7 +1057,7 @@ public abstract class cc/polyfrost/oneconfig/gui/pages/Page {
protected field scroll F
protected field scrollAnimation Lcc/polyfrost/oneconfig/gui/animations/Animation;
protected field scrollTarget F
protected final field title Ljava/lang/String;
protected field title Ljava/lang/String;
public fun <init> (Ljava/lang/String;)V
public abstract fun draw (JIILcc/polyfrost/oneconfig/utils/InputHandler;)V
public fun drawStatic (JIILcc/polyfrost/oneconfig/utils/InputHandler;)I
Expand All @@ -1057,6 +1067,16 @@ public abstract class cc/polyfrost/oneconfig/gui/pages/Page {
public fun isBase ()Z
public fun keyTyped (CI)V
public fun scrollWithDraw (JIILcc/polyfrost/oneconfig/utils/InputHandler;)V
public fun setTitle (Ljava/lang/String;)V
}

public class cc/polyfrost/oneconfig/gui/pages/SubModsPage : cc/polyfrost/oneconfig/gui/pages/ModsPage {
public field parentMod Lcc/polyfrost/oneconfig/config/data/Mod;
public fun <init> (Lcc/polyfrost/oneconfig/config/data/Mod;)V
public fun draw (JIILcc/polyfrost/oneconfig/utils/InputHandler;)V
public fun drawStatic (JIILcc/polyfrost/oneconfig/utils/InputHandler;)I
public fun getMaxScrollHeight ()I
public fun isBase ()Z
}

public abstract class cc/polyfrost/oneconfig/hud/BasicHud : cc/polyfrost/oneconfig/hud/Hud {
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pluginManagement {
gradlePluginPortal()
maven("https://repo.polyfrost.org/releases")
}
val pgtVersion = "0.4.1"
val pgtVersion = "0.5.0"
plugins {
id("org.polyfrost.multi-version.root") version pgtVersion
id("org.polyfrost.defaults") version pgtVersion
Expand Down
22 changes: 20 additions & 2 deletions src/main/java/cc/polyfrost/oneconfig/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@
import cc.polyfrost.oneconfig.config.annotations.CustomOption;
import cc.polyfrost.oneconfig.config.annotations.HUD;
import cc.polyfrost.oneconfig.config.annotations.Page;
import cc.polyfrost.oneconfig.config.annotations.SubConfig;
import cc.polyfrost.oneconfig.config.core.ConfigUtils;
import cc.polyfrost.oneconfig.config.core.OneKeyBind;
import cc.polyfrost.oneconfig.config.data.Mod;
import cc.polyfrost.oneconfig.config.data.ModType;
import cc.polyfrost.oneconfig.config.data.PageLocation;
import cc.polyfrost.oneconfig.config.elements.BasicOption;
import cc.polyfrost.oneconfig.config.elements.OptionPage;
Expand All @@ -45,6 +47,7 @@
import cc.polyfrost.oneconfig.gui.elements.config.ConfigPageButton;
import cc.polyfrost.oneconfig.gui.pages.ModConfigPage;
import cc.polyfrost.oneconfig.hud.HUDUtils;
import cc.polyfrost.oneconfig.internal.config.SubMainConfig;
import cc.polyfrost.oneconfig.internal.config.annotations.Option;
import cc.polyfrost.oneconfig.internal.config.core.ConfigCore;
import cc.polyfrost.oneconfig.internal.config.core.KeyBindHandler;
Expand All @@ -69,7 +72,9 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.function.Supplier;

@SuppressWarnings({"unused", "ResultOfMethodCallIgnored"})
Expand Down Expand Up @@ -230,6 +235,7 @@ protected final void generateOptionList(Object instance, Class<?> targetClass, O
if (superclass != Object.class) {
generateOptionList(instance, superclass, page, mod, migrate);
}
List<Mod> subMods = new ArrayList<>();

String pagePath = page.equals(mod.defaultPage) ? "" : page.name + ".";
for (Field field : targetClass.getDeclaredFields()) {
Expand Down Expand Up @@ -260,6 +266,11 @@ protected final void generateOptionList(Object instance, Class<?> targetClass, O
else subcategory.bottomButtons.add(button);
} else if (field.isAnnotationPresent(HUD.class)) {
HUDUtils.addHudOptions(page, field, instance, this);
} else if (field.isAnnotationPresent(SubConfig.class)) {
if (page != mod.defaultPage) continue;
Config config = (Config) ConfigUtils.getField(field, instance);
if (config == null) continue;
subMods.add(config.mod);
}
}
for (Method method : targetClass.getDeclaredMethods()) {
Expand All @@ -270,6 +281,13 @@ protected final void generateOptionList(Object instance, Class<?> targetClass, O
optionNames.put(optionName, option);
}
}
if (!subMods.isEmpty()) {
if (!optionNames.isEmpty()) {
subMods.add(new SubMainConfig().mod);
}
ConfigCore.subMods.put(this.mod, subMods);
}

logger.trace("Finished generating option list for {} (targetting={})", mod.name, targetClass.getName());
}

Expand Down Expand Up @@ -463,8 +481,8 @@ public static Mod register(Mod mod) {
/**
* Literally does nothing.
* <p>
* As configs HAVE to be initialized before your mod loader's post-init, instances need to be created before that.
* Hence, this method exists so config instances which are located in the actual class instead of the main mod class can be created.
* As configs HAVE to be initialized before your mod loader's post-init, instances need to be created before that.
* Hence, this method exists so config instances which are located in the actual class instead of the main mod class can be created.
* </p>
* For example:
* <pre>{@code
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* This file is part of OneConfig.
* OneConfig - Next Generation Config Library for Minecraft: Java Edition
* Copyright (C) 2021~2023 Polyfrost.
* <https://polyfrost.cc> <https://github.com/Polyfrost/>
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* OneConfig is licensed under the terms of version 3 of the GNU Lesser
* General Public License as published by the Free Software Foundation, AND
* under the Additional Terms Applicable to OneConfig, as published by Polyfrost,
* either version 1.0 of the Additional Terms, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License. If not, see <https://www.gnu.org/licenses/>. You should
* have also received a copy of the Additional Terms Applicable
* to OneConfig, as published by Polyfrost. If not, see
* <https://polyfrost.cc/legal/oneconfig/additional-terms>
*/

package cc.polyfrost.oneconfig.config.annotations;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface SubConfig {
}
20 changes: 11 additions & 9 deletions src/main/java/cc/polyfrost/oneconfig/config/data/Mod.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Objects;

public class Mod implements Comparable<Mod> {
@NotNull
public final String name;
Expand Down Expand Up @@ -116,13 +118,13 @@ public int compareTo(@NotNull Mod mod) {
return name.compareTo(mod.name);
}

@Override
public boolean equals(Object obj) {
if (obj == null) return false;
if (obj == this) return true;
if (obj instanceof Mod) {
Mod mod = (Mod) obj;
return name.equals(mod.name);
} else return false;
}
// @Override
// public boolean equals(Object obj) {
// if (obj == null) return false;
// if (obj == this) return true;
// if (obj instanceof Mod) {
// Mod mod = (Mod) obj;
// return name.equals(mod.name) && config == mod.config;
// } else return false;
// }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* This file is part of OneConfig.
* OneConfig - Next Generation Config Library for Minecraft: Java Edition
* Copyright (C) 2021~2023 Polyfrost.
* <https://polyfrost.cc> <https://github.com/Polyfrost/>
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* OneConfig is licensed under the terms of version 3 of the GNU Lesser
* General Public License as published by the Free Software Foundation, AND
* under the Additional Terms Applicable to OneConfig, as published by Polyfrost,
* either version 1.0 of the Additional Terms, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License. If not, see <https://www.gnu.org/licenses/>. You should
* have also received a copy of the Additional Terms Applicable
* to OneConfig, as published by Polyfrost. If not, see
* <https://polyfrost.cc/legal/oneconfig/additional-terms>
*/

package cc.polyfrost.oneconfig.config.elements;

import cc.polyfrost.oneconfig.config.Config;
import cc.polyfrost.oneconfig.config.data.Mod;
import cc.polyfrost.oneconfig.config.data.ModType;

public class SubConfig extends Config {

public SubConfig(String name, String configFile, String icon, boolean enabled, boolean canToggle) {
super(new Mod(name, ModType.UTIL_QOL, icon), configFile, enabled, canToggle);
initialize();
}

public SubConfig(String name, String configFile, String icon, boolean enabled) {
this(name, configFile, icon, enabled, true);
}

public SubConfig(String name, String configFile, String icon) {
this(name, configFile, icon, true, true);
}

public SubConfig(String name, String configFile) {
this(name, configFile, null, true, true);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import cc.polyfrost.oneconfig.config.annotations.Exclude;
import cc.polyfrost.oneconfig.config.annotations.HypixelKey;
import cc.polyfrost.oneconfig.config.annotations.NonProfileSpecific;
import cc.polyfrost.oneconfig.config.annotations.SubConfig;
import cc.polyfrost.oneconfig.gui.pages.Page;
import com.google.gson.ExclusionStrategy;
import com.google.gson.FieldAttributes;
Expand All @@ -46,6 +47,7 @@ public boolean shouldSkipField(FieldAttributes f) {
if (f.getDeclaredClass().isAssignableFrom(Runnable.class)) return true;
if (f.getAnnotation(NonProfileSpecific.class) != null) return true;
if (f.getAnnotation(HypixelKey.class) != null) return true;
if (f.getAnnotation(SubConfig.class) != null) return true;
Exclude exclude = f.getAnnotation(Exclude.class);
return exclude != null;
}
Expand Down
18 changes: 17 additions & 1 deletion src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@
import cc.polyfrost.oneconfig.gui.animations.ColorAnimation;
import cc.polyfrost.oneconfig.gui.pages.ModConfigPage;
import cc.polyfrost.oneconfig.gui.pages.ModsPage;
import cc.polyfrost.oneconfig.gui.pages.Page;
import cc.polyfrost.oneconfig.gui.pages.SubModsPage;
import cc.polyfrost.oneconfig.internal.assets.Colors;
import cc.polyfrost.oneconfig.internal.assets.SVGs;
import cc.polyfrost.oneconfig.internal.config.OneConfigConfig;
import cc.polyfrost.oneconfig.internal.config.SubMainConfig;
import cc.polyfrost.oneconfig.internal.config.compatibility.forge.ForgeCompat;
import cc.polyfrost.oneconfig.internal.config.core.ConfigCore;
import cc.polyfrost.oneconfig.platform.Platform;
Expand Down Expand Up @@ -146,10 +149,23 @@ public void onClick() {
return;
}
}
OneConfigGui.INSTANCE.openPage(new ModConfigPage(modData.defaultPage));

if (modData.config instanceof SubMainConfig) {
Page page = new ModConfigPage(ConfigCore.getParentMod(modData).defaultPage);
page.setTitle("Settings");
open(page);
} else if (ConfigCore.subMods.get(modData) != null) {
open(new SubModsPage(modData));
} else {
open(new ModConfigPage(modData.defaultPage));
}
}
}

private static void open(Page page) {
OneConfigGui.INSTANCE.openPage(page);
}

public Mod getModData() {
return modData;
}
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/cc/polyfrost/oneconfig/gui/pages/ModsPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import cc.polyfrost.oneconfig.config.data.Mod;
import cc.polyfrost.oneconfig.config.data.ModType;
import cc.polyfrost.oneconfig.config.elements.SubConfig;
import cc.polyfrost.oneconfig.gui.OneConfigGui;
import cc.polyfrost.oneconfig.gui.elements.BasicButton;
import cc.polyfrost.oneconfig.gui.elements.ModCard;
Expand All @@ -44,7 +45,7 @@

public class ModsPage extends Page {

private final ArrayList<ModCard> modCards = new ArrayList<>();
public final ArrayList<ModCard> modCards = new ArrayList<>();
private final ArrayList<BasicButton> modCategories = new ArrayList<>();
private int size;

Expand Down Expand Up @@ -114,8 +115,15 @@ private boolean inSelection(ModCard modCard) {
public void reloadMods() {
modCards.clear();
for (Mod modData : ConfigCore.mods) {
if (this instanceof SubModsPage) {
Mod parentMod = ((SubModsPage) this).parentMod;
if (parentMod != null && !ConfigCore.subMods.get(parentMod).contains(modData)) continue;
} else {
if (modData.config instanceof SubConfig) continue;
}
modCards.add(new ModCard(modData, modData.config == null || modData.config.enabled, false, OneConfigConfig.favoriteMods.contains(modData.name), this));
}
ConfigCore.sortMods();
}

@Override
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
* A page is a 1056x728 rectangle of the GUI. It is the main content of the gui, and can be switched back and forwards easily. All the content of OneConfig is in a page.
*/
public abstract class Page {
protected final String title;
protected String title;
protected Animation scrollAnimation;
private final ColorAnimation colorAnimation = new ColorAnimation(new ColorPalette(Colors.TRANSPARENT, Colors.GRAY_400_60, Colors.GRAY_400_60), 200);
protected float scrollTarget;
Expand Down Expand Up @@ -135,6 +135,10 @@ public void scrollWithDraw(long vg, int x, int y, InputHandler inputHandler) {
}
}

public void setTitle(String title) {
this.title = title;
}

public String getTitle() {
return title;
}
Expand Down
Loading

0 comments on commit b87aa54

Please sign in to comment.