From 88e7d8358e059e26539d0b470e7e5dd38dab972a Mon Sep 17 00:00:00 2001 From: Pandemonium14 <104149087+Pandemonium14@users.noreply.github.com> Date: Tue, 18 Apr 2023 08:04:29 +0200 Subject: [PATCH] Add a way to color dropdown menus (#383) * Added a method to Card Modifiers that allows adding tooltips to cards directly * Added a way to change the colors of dropdown rows using a function of the index --- .../DropdownMenu/DropdownColoring.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 mod/src/main/java/basemod/patches/com/megacrit/cardcrawl/screens/options/DropdownMenu/DropdownColoring.java diff --git a/mod/src/main/java/basemod/patches/com/megacrit/cardcrawl/screens/options/DropdownMenu/DropdownColoring.java b/mod/src/main/java/basemod/patches/com/megacrit/cardcrawl/screens/options/DropdownMenu/DropdownColoring.java new file mode 100644 index 00000000..e074f1e3 --- /dev/null +++ b/mod/src/main/java/basemod/patches/com/megacrit/cardcrawl/screens/options/DropdownMenu/DropdownColoring.java @@ -0,0 +1,40 @@ +package basemod.patches.com.megacrit.cardcrawl.screens.options.DropdownMenu; + +import basemod.ReflectionHacks; +import com.badlogic.gdx.graphics.Color; +import com.evacipated.cardcrawl.modthespire.lib.*; +import com.megacrit.cardcrawl.helpers.Hitbox; +import com.megacrit.cardcrawl.screens.options.DropdownMenu; +import javassist.CtBehavior; + +import java.util.ArrayList; +import java.util.function.Function; + +public class DropdownColoring { + + @SpirePatch2(clz = DropdownMenu.class, method = SpirePatch.CLASS) + public static class RowToColor { + public static SpireField> function = new SpireField>(() ->((index) -> null)); + } + + @SpirePatch2(cls = "com.megacrit.cardcrawl.screens.options.DropdownMenu$DropdownRow", method = "renderRow") + public static class Patch { + + private static class Locator extends SpireInsertLocator { + @Override + public int[] Locate(CtBehavior ctMethodToPatch) throws Exception { + Matcher finalMatcher = new Matcher.FieldAccessMatcher(Hitbox.class, "hovered"); + return LineFinder.findAllInOrder(ctMethodToPatch, new ArrayList<>(), finalMatcher); + } + } + + @SpireInsertPatch(locator = Locator.class, localvars = {"renderTextColor"}) + public static void changeColor(Object __instance, @ByRef Color[] renderTextColor, int ___index) { + DropdownMenu dropdown = ReflectionHacks.getPrivate(__instance, __instance.getClass(), "this$0"); + Color newColor = RowToColor.function.get(dropdown).apply(___index); + if (newColor != null) { + renderTextColor[0] = newColor; + } + } + } +}