aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/data/Mod.java14
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java75
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java1
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/pages/ModsPage.java37
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java6
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java27
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/internal/config/OneConfigConfig.java1
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/internal/config/core/ConfigCore.java16
8 files changed, 72 insertions, 105 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/data/Mod.java b/src/main/java/cc/polyfrost/oneconfig/config/data/Mod.java
index ca931b7..bb3cccc 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/data/Mod.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/data/Mod.java
@@ -3,16 +3,17 @@ package cc.polyfrost.oneconfig.config.data;
import cc.polyfrost.oneconfig.config.Config;
import cc.polyfrost.oneconfig.config.elements.OptionPage;
import cc.polyfrost.oneconfig.config.migration.Migrator;
+import cc.polyfrost.oneconfig.internal.config.OneConfigConfig;
+import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-public class Mod {
+public class Mod implements Comparable<Mod> {
public final String name;
public final ModType modType;
public final String modIcon;
public final Migrator migrator;
public final OptionPage defaultPage;
public Config config;
- public boolean isShortCut = false;
/**
* @param name Friendly name of the mod
@@ -53,4 +54,13 @@ public class Mod {
public Mod(String name, ModType modType) {
this(name, modType, null, null);
}
+
+ @Override
+ public int compareTo(@NotNull Mod mod) {
+ int result = name.compareTo(mod.name);
+ //if (mod.modType != ModType.THIRD_PARTY) result *= 10;
+ //if (OneConfigConfig.favoriteMods.contains(name)) result *= 100;
+ System.out.println(name + " " + mod.name + " " + result);
+ return result;
+ }
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java
index 7da1352..2938c41 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java
@@ -1,44 +1,45 @@
package cc.polyfrost.oneconfig.gui.elements;
-import cc.polyfrost.oneconfig.internal.OneConfig;
-import cc.polyfrost.oneconfig.internal.assets.Colors;
import cc.polyfrost.oneconfig.config.data.Mod;
import cc.polyfrost.oneconfig.gui.OneConfigGui;
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.internal.OneConfig;
+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.core.ConfigCore;
import cc.polyfrost.oneconfig.renderer.RenderManager;
import cc.polyfrost.oneconfig.renderer.font.Fonts;
-import cc.polyfrost.oneconfig.internal.assets.SVGs;
import cc.polyfrost.oneconfig.renderer.scissor.Scissor;
import cc.polyfrost.oneconfig.renderer.scissor.ScissorManager;
import cc.polyfrost.oneconfig.utils.InputUtils;
import cc.polyfrost.oneconfig.utils.color.ColorPalette;
import cc.polyfrost.oneconfig.utils.color.ColorUtils;
-import cc.polyfrost.oneconfig.libs.universal.wrappers.UPlayer;
-import net.minecraftforge.client.ClientCommandHandler;
-import net.minecraftforge.fml.common.ModMetadata;
import org.jetbrains.annotations.NotNull;
import org.lwjgl.input.Mouse;
-import java.util.ArrayList;
-
public class ModCard extends BasicElement {
private final Mod modData;
private final BasicButton favoriteButton = new BasicButton(32, 32, SVGs.HEART_OUTLINE, BasicButton.ALIGNMENT_CENTER, ColorPalette.TERTIARY);
private final ColorAnimation colorFrame = new ColorAnimation(ColorPalette.SECONDARY);
- private final ColorAnimation colorToggle = new ColorAnimation(ColorPalette.PRIMARY);
+ private final ColorAnimation colorToggle;
private boolean active, disabled, favorite;
private boolean isHoveredMain = false;
+ private final ModsPage page;
- public ModCard(@NotNull Mod mod, boolean active, boolean disabled, boolean favorite) {
+ public ModCard(@NotNull Mod mod, boolean active, boolean disabled, boolean favorite, ModsPage page) {
super(244, 119, false);
this.modData = mod;
this.active = active;
toggled = active;
+ colorToggle = new ColorAnimation(active ? ColorPalette.PRIMARY : ColorPalette.SECONDARY);
this.disabled = disabled;
this.favorite = favorite;
favoriteButton.setToggled(favorite);
toggled = active;
+ this.page = page;
}
@Override
@@ -62,6 +63,13 @@ public class ModCard extends BasicElement {
}
favoriteButton.draw(vg, x + 212, y + 87);
favorite = favoriteButton.isToggled();
+ if (favoriteButton.isClicked()) {
+ if (favorite) OneConfigConfig.favoriteMods.add(modData.name);
+ else OneConfigConfig.favoriteMods.remove(modData.name);
+ ConfigCore.sortMods();
+ page.reloadMods();
+ OneConfig.config.save();
+ }
Scissor scissor2 = ScissorManager.scissor(vg, x, y + 87, width - 32, 32);
RenderManager.drawText(vg, cleanName, x + 12, y + 103, ColorUtils.setAlpha(Colors.WHITE, (int) (colorToggle.getAlpha() * 255)), 14f, Fonts.MEDIUM);
ScissorManager.resetScissor(vg, scissor2);
@@ -75,50 +83,19 @@ public class ModCard extends BasicElement {
if (clicked && !isHoveredSecondary && active) toggled = true;
if (!active & disabled) toggled = false;
- active = toggled;
- colorToggle.setPalette(active ? ColorPalette.PRIMARY : ColorPalette.SECONDARY);
+ if (active != toggled) {
+ active = toggled;
+ colorToggle.setPalette(active ? ColorPalette.PRIMARY : ColorPalette.SECONDARY);
+ modData.config.enabled = active;
+ modData.config.save();
+ }
RenderManager.setAlpha(vg, 1f);
ScissorManager.resetScissor(vg, scissor);
}
public void onClick() {
- if (isHoveredMain) {
- for (Mod data : OneConfig.loadedMods) {
- if (!data.isShortCut) {
- if (data.name.equalsIgnoreCase(modData.name)) {
- OneConfigGui.INSTANCE.openPage(new ModConfigPage(data.defaultPage));
- return;
- }
- }
- }
- for (ModMetadata mod : OneConfig.loadedOtherMods) {
- if (mod.name.equalsIgnoreCase(modData.name)) {
- ArrayList<String> possibleCommands = new ArrayList<>();
- possibleCommands.add(mod.name.toLowerCase().replace(" ", ""));
- possibleCommands.add(mod.modId.toLowerCase().replaceAll("[ -_]", ""));
- if (mod.name.split(" ").length > 1) {
- StringBuilder result = new StringBuilder();
- for (String word : mod.name.split(" ")) {
- if (word.length() == 0) continue;
- result.append(word.charAt(0));
- }
- possibleCommands.add(result.toString().toLowerCase());
- }
- for (String command : ClientCommandHandler.instance.getCommands().keySet()) {
- if (possibleCommands.contains(command)) {
- try {
- ClientCommandHandler.instance.getCommands().get(command).processCommand(UPlayer.getPlayer(), new String[]{});
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- break;
- }
- }
- return;
- }
-
- }
- }
+ if (isHoveredMain)
+ OneConfigGui.INSTANCE.openPage(new ModConfigPage(modData.defaultPage));
}
public Mod getModData() {
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java b/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java
index fb04dc2..c3e472a 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java
@@ -58,7 +58,6 @@ public class ModConfigPage extends Page {
@Override
public int drawStatic(long vg, int x, int y) {
- // Category buttons
if (categories.size() <= 1) return 0;
int buttonX = x + 16;
for (BasicButton button : categories) {
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModsPage.java b/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModsPage.java
index eff9b35..75a9f8e 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModsPage.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModsPage.java
@@ -1,31 +1,29 @@
package cc.polyfrost.oneconfig.gui.pages;
-import cc.polyfrost.oneconfig.internal.OneConfig;
-import cc.polyfrost.oneconfig.internal.assets.Colors;
import cc.polyfrost.oneconfig.config.data.Mod;
import cc.polyfrost.oneconfig.config.data.ModType;
import cc.polyfrost.oneconfig.gui.OneConfigGui;
import cc.polyfrost.oneconfig.gui.elements.BasicButton;
import cc.polyfrost.oneconfig.gui.elements.ModCard;
+import cc.polyfrost.oneconfig.internal.assets.Colors;
import cc.polyfrost.oneconfig.internal.config.OneConfigConfig;
+import cc.polyfrost.oneconfig.internal.config.core.ConfigCore;
import cc.polyfrost.oneconfig.renderer.RenderManager;
import cc.polyfrost.oneconfig.renderer.font.Fonts;
import cc.polyfrost.oneconfig.utils.color.ColorPalette;
import java.util.ArrayList;
-import java.util.List;
+import java.util.Iterator;
public class ModsPage extends Page {
- private final List<ModCard> modCards = new ArrayList<>();
- private final List<BasicButton> modCategories = new ArrayList<>();
+ private final ArrayList<ModCard> modCards = new ArrayList<>();
+ private final ArrayList<BasicButton> modCategories = new ArrayList<>();
private int size;
public ModsPage() {
super("Mods");
- for (Mod modData : OneConfig.loadedMods) {
- modCards.add(OneConfigConfig.favoriteMods.contains(modData.name) ? 0 : modCards.size(), new ModCard(modData, modData.config == null || modData.config.enabled, false, OneConfigConfig.favoriteMods.contains(modData.name)));
- }
+ reloadMods();
modCategories.add(new BasicButton(64, 32, "All", BasicButton.ALIGNMENT_CENTER, ColorPalette.SECONDARY));
modCategories.add(new BasicButton(80, 32, "Combat", BasicButton.ALIGNMENT_CENTER, ColorPalette.SECONDARY));
modCategories.add(new BasicButton(64, 32, "HUD", BasicButton.ALIGNMENT_CENTER, ColorPalette.SECONDARY));
@@ -45,7 +43,8 @@ public class ModsPage extends Page {
String filter = OneConfigGui.INSTANCE == null ? "" : OneConfigGui.INSTANCE.getSearchValue().toLowerCase().trim();
int iX = x + 16;
int iY = y + 72;
- for (ModCard modCard : modCards) {
+ ArrayList<ModCard> finalModCards = new ArrayList<>(modCards);
+ for (ModCard modCard : finalModCards) {
if (inSelection(modCard) && (filter.equals("") || modCard.getModData().name.toLowerCase().contains(filter))) {
modCard.draw(vg, iX, iY);
iX += 260;
@@ -81,21 +80,15 @@ public class ModsPage extends Page {
}
}
- @Override
- public void finishUpAndClose() {
- OneConfigConfig.favoriteMods.clear();
- for (ModCard modCard : modCards) {
- if (modCard.isFavorite()) OneConfigConfig.favoriteMods.add(modCard.getModData().name);
- if (modCard.getModData().config != null && modCard.getModData().config.enabled != modCard.isActive()) {
- modCard.getModData().config.enabled = modCard.isActive();
- modCard.getModData().config.save();
- }
- }
- OneConfig.config.save();
+ private boolean inSelection(ModCard modCard) {
+ return modCategories.get(0).isToggled() || (modCategories.get(1).isToggled() && modCard.getModData().modType == ModType.PVP) || (modCategories.get(2).isToggled() && modCard.getModData().modType == ModType.HUD) || (modCategories.get(3).isToggled() && modCard.getModData().modType == ModType.UTIL_QOL) || (modCategories.get(4).isToggled() && modCard.getModData().modType == ModType.HYPIXEL) || (modCategories.get(5).isToggled() && modCard.getModData().modType == ModType.SKYBLOCK) || (modCategories.get(6).isToggled() && modCard.getModData().modType == ModType.THIRD_PARTY);
}
- private boolean inSelection(ModCard modCard) {
- return modCategories.get(0).isToggled() && (OneConfigConfig.allShowShortCut || !modCard.getModData().isShortCut) || (modCategories.get(1).isToggled() && modCard.getModData().modType == ModType.PVP) || (modCategories.get(2).isToggled() && modCard.getModData().modType == ModType.HUD) || (modCategories.get(3).isToggled() && modCard.getModData().modType == ModType.UTIL_QOL) || (modCategories.get(4).isToggled() && modCard.getModData().modType == ModType.HYPIXEL) || (modCategories.get(5).isToggled() && modCard.getModData().modType == ModType.SKYBLOCK) || (modCategories.get(6).isToggled() && modCard.getModData().modType == ModType.THIRD_PARTY);
+ public void reloadMods() {
+ modCards.clear();
+ for (Mod modData : ConfigCore.oneConfigMods) {
+ modCards.add(new ModCard(modData, modData.config == null || modData.config.enabled, false, OneConfigConfig.favoriteMods.contains(modData.name), this));
+ }
}
@Override
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java b/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java
index fdc69bf..5ce6561 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java
@@ -50,7 +50,7 @@ public abstract class Page {
float scroll = scrollAnimation == null ? scrollTarget : scrollAnimation.get();
final float scrollBarLength = (728f / maxScroll) * 728f;
Scissor scissor = ScissorManager.scissor(vg, x, y + scissorOffset, x + 1056, y + 728 - scissorOffset);
- //Scissor inputScissor = InputUtils.blockInputArea(x, y, x + 1056, y + scissorOffset);
+ Scissor inputScissor = InputUtils.blockInputArea(x, y,1056, scissorOffset);
int dWheel = Mouse.getDWheel();
if (dWheel != 0) {
scrollTarget += dWheel;
@@ -64,7 +64,7 @@ public abstract class Page {
if (maxScroll <= 728) {
draw(vg, x, y);
ScissorManager.resetScissor(vg, scissor);
- //InputUtils.stopBlock(inputScissor);
+ InputUtils.stopBlock(inputScissor);
return;
}
draw(vg, x, (int) (y + scroll));
@@ -73,7 +73,7 @@ public abstract class Page {
}
ScissorManager.resetScissor(vg, scissor);
- //InputUtils.stopBlock(inputScissor);
+ InputUtils.stopBlock(inputScissor);
if (!(scrollBarLength > 727f)) {
final float scrollBarY = (scroll / maxScroll) * 720f;
final boolean isMouseDown = Mouse.isButtonDown(0);
diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java b/src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java
index efc4324..13e34ff 100644
--- a/src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java
+++ b/src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java
@@ -1,7 +1,5 @@
package cc.polyfrost.oneconfig.internal;
-import cc.polyfrost.oneconfig.config.data.Mod;
-import cc.polyfrost.oneconfig.config.data.ModType;
import cc.polyfrost.oneconfig.events.EventManager;
import cc.polyfrost.oneconfig.internal.command.OneConfigCommand;
import cc.polyfrost.oneconfig.internal.config.OneConfigConfig;
@@ -13,17 +11,10 @@ import cc.polyfrost.oneconfig.internal.hud.HudCore;
import cc.polyfrost.oneconfig.utils.commands.CommandManager;
import cc.polyfrost.oneconfig.utils.gui.GuiUtils;
import cc.polyfrost.oneconfig.utils.hypixel.HypixelUtils;
-import net.minecraftforge.fml.common.DummyModContainer;
-import net.minecraftforge.fml.common.Loader;
-import net.minecraftforge.fml.common.ModContainer;
-import net.minecraftforge.fml.common.ModMetadata;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.File;
-import java.util.ArrayList;
-import java.util.LinkedHashSet;
-import java.util.List;
/**
* The main class of OneConfig.
@@ -31,8 +22,6 @@ import java.util.List;
@net.minecraftforge.fml.common.Mod(modid = "@ID@", name = "@NAME@", version = "@VER@")
public class OneConfig {
public static final File oneConfigDir = new File("./OneConfig");
- public static final List<Mod> loadedMods = new ArrayList<>();
- public static final List<ModMetadata> loadedOtherMods = new ArrayList<>();
public static final Logger LOGGER = LogManager.getLogger("@NAME@");
public static OneConfigConfig config;
public static Preferences preferences;
@@ -75,24 +64,10 @@ public class OneConfig {
EventManager.INSTANCE.register(new HudCore());
EventManager.INSTANCE.register(HypixelUtils.INSTANCE);
EventManager.INSTANCE.register(KeyBindHandler.INSTANCE);
- reloadModsList();
+ ConfigCore.sortMods();
initialized = true;
}
- public static void reloadModsList() {
- loadedMods.addAll(ConfigCore.oneConfigMods);
- LinkedHashSet<Mod> modData = new LinkedHashSet<>(ConfigCore.oneConfigMods);
- for (ModContainer mod : Loader.instance().getActiveModList()) {
- ModMetadata metadata = mod.getMetadata();
- loadedOtherMods.add(metadata);
- String imageName = Loader.instance().activeModContainer() == null || Loader.instance().activeModContainer().getMetadata().logoFile.trim().equals("") ? null : "/" + Loader.instance().activeModContainer().getMetadata().logoFile;
- Mod newMod = new Mod(metadata.name, ModType.THIRD_PARTY, imageName);
- newMod.isShortCut = true;
- if (mod instanceof DummyModContainer || newMod.name.equals("OneConfig")) continue;
- if (modData.add(newMod)) loadedMods.add(newMod);
- }
- }
-
/** Returns weather this is an obfuscated environment, using a check for obfuscated name of net.minecraft.world.World.class.
* @return true if this is an obfuscated environment, which is normal for Minecraft or false if not. */
public static boolean isObfuscated() {
diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/config/OneConfigConfig.java b/src/main/java/cc/polyfrost/oneconfig/internal/config/OneConfigConfig.java
index 1986e9e..96fde65 100644
--- a/src/main/java/cc/polyfrost/oneconfig/internal/config/OneConfigConfig.java
+++ b/src/main/java/cc/polyfrost/oneconfig/internal/config/OneConfigConfig.java
@@ -22,7 +22,6 @@ public class OneConfigConfig extends InternalConfig {
public static ArrayList<String> favoriteMods = new ArrayList<>();
public static ArrayList<OneColor> favoriteColors = new ArrayList<>();
public static ArrayList<OneColor> recentColors = new ArrayList<>();
- public static boolean allShowShortCut = false;
public static boolean australia = false;
public OneConfigConfig() {
diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/config/core/ConfigCore.java b/src/main/java/cc/polyfrost/oneconfig/internal/config/core/ConfigCore.java
index a1084a1..6b88afa 100644
--- a/src/main/java/cc/polyfrost/oneconfig/internal/config/core/ConfigCore.java
+++ b/src/main/java/cc/polyfrost/oneconfig/internal/config/core/ConfigCore.java
@@ -1,12 +1,16 @@
package cc.polyfrost.oneconfig.internal.config.core;
import cc.polyfrost.oneconfig.config.data.Mod;
+import cc.polyfrost.oneconfig.config.data.ModType;
+import cc.polyfrost.oneconfig.internal.config.OneConfigConfig;
import cc.polyfrost.oneconfig.internal.hud.HudCore;
import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
public class ConfigCore {
- public static ArrayList<Mod> oneConfigMods = new ArrayList<>();
+ public static List<Mod> oneConfigMods = new ArrayList<>();
public static void saveAll() {
for (Mod modData : oneConfigMods) {
@@ -22,5 +26,15 @@ public class ConfigCore {
for (Mod modData : data) {
modData.config.init(modData);
}
+ sortMods();
+ }
+
+ public static void sortMods() {
+ ArrayList<Mod> mods = new ArrayList<>(oneConfigMods);
+ oneConfigMods = mods.stream().filter((mod -> OneConfigConfig.favoriteMods.contains(mod.name))).sorted().collect(Collectors.toList());
+ mods.removeAll(oneConfigMods);
+ oneConfigMods.addAll(mods.stream().filter(mod -> mod.modType != ModType.THIRD_PARTY).sorted().collect(Collectors.toList()));
+ mods.removeAll(oneConfigMods);
+ oneConfigMods.addAll(mods.stream().sorted().collect(Collectors.toList()));
}
}