forked from daviscook477/BaseMod
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a way to color dropdown menus (daviscook477#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
- Loading branch information
1 parent
71fd51e
commit 88e7d83
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
...basemod/patches/com/megacrit/cardcrawl/screens/options/DropdownMenu/DropdownColoring.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Integer, Color>> function = new SpireField<Function<Integer, Color>>(() ->((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; | ||
} | ||
} | ||
} | ||
} |