aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/cc/polyfrost/oneconfig/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/gui')
-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
4 files changed, 44 insertions, 75 deletions
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);