Skip to content

Commit

Permalink
Add support for custom tooltips linked to card text icons (kiooeht#70)
Browse files Browse the repository at this point in the history
* Icons can add tooltips to cards now

Vex did this commit

* Specific keyword support
  • Loading branch information
DarkVexon authored Dec 24, 2022
1 parent ec6329a commit 8a4ecaf
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package com.evacipated.cardcrawl.mod.stslib.icons;

import basemod.helpers.TooltipInfo;
import basemod.patches.com.megacrit.cardcrawl.cards.AbstractCard.ShrinkLongDescription;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion;
import com.evacipated.cardcrawl.mod.stslib.Keyword;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.core.Settings;

import java.util.ArrayList;
import java.util.List;

public abstract class AbstractCustomIcon {
public static final int RENDER_CONSTANT = 24;
public static final String CODE_ENDING = "Icon]";
Expand Down Expand Up @@ -39,6 +44,14 @@ public float getCardRenderScale(AbstractCard card) {
return getRenderScale() * ShrinkLongDescription.Scale.descriptionScale.get(card);
}

public List<TooltipInfo> getCustomTooltips() {
return new ArrayList<>();
}

public List<String> keywordLinks() {
return new ArrayList<>();
}

public void render(SpriteBatch sb, float drawX, float drawY, float offsetX, float offsetY, float scale, float angle) {
Color backup = sb.getColor();
sb.setColor(new Color(1.0F, 1.0F, 1.0F, backup.a));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.evacipated.cardcrawl.mod.stslib.icons;

import com.megacrit.cardcrawl.cards.AbstractCard;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;

Expand All @@ -17,4 +20,14 @@ public static AbstractCustomIcon getIcon(String key) {
public static Collection<AbstractCustomIcon> getAllIcons() {
return icons.values();
}

public static ArrayList<AbstractCustomIcon> iconsOnCard(AbstractCard card) {
ArrayList<AbstractCustomIcon> icons = new ArrayList<>();
for (AbstractCustomIcon i : getAllIcons()) {
if (card.rawDescription.contains(i.cardCode())) {
icons.add(i);
}
}
return icons;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.evacipated.cardcrawl.mod.stslib.patches;

import basemod.BaseMod;
import basemod.abstracts.CustomCard;
import basemod.helpers.TooltipInfo;
import basemod.patches.com.megacrit.cardcrawl.cards.AbstractCard.RenderCardDescriptors;
Expand All @@ -9,6 +10,8 @@
import com.evacipated.cardcrawl.mod.stslib.blockmods.BlockModifierManager;
import com.evacipated.cardcrawl.mod.stslib.damagemods.AbstractDamageModifier;
import com.evacipated.cardcrawl.mod.stslib.damagemods.DamageModifierManager;
import com.evacipated.cardcrawl.mod.stslib.icons.AbstractCustomIcon;
import com.evacipated.cardcrawl.mod.stslib.icons.CustomIconHelper;
import com.evacipated.cardcrawl.mod.stslib.powers.interfaces.DamageModApplyingPower;
import com.evacipated.cardcrawl.modthespire.lib.*;
import com.megacrit.cardcrawl.cards.AbstractCard;
Expand Down Expand Up @@ -38,6 +41,18 @@ public static void part1(AbstractCard ___card, @ByRef List<TooltipInfo>[] toolti
tooltips[0].addAll(mod.getCustomTooltips());
}
}
for (AbstractCustomIcon icon : CustomIconHelper.iconsOnCard(___card)) {
if (icon.keywordLinks() != null) {
for (String s : icon.keywordLinks()) {
if (!___card.rawDescription.toLowerCase().contains(s)) {
tooltips[0].add(new TooltipInfo(BaseMod.getKeywordTitle(s), BaseMod.getKeywordDescription(s)));
}
}
}
if (icon.getCustomTooltips() != null) {
tooltips[0].addAll(icon.getCustomTooltips());
}
}
if (AbstractDungeon.player != null && RenderElementsOnCardPatches.validLocation(___card)) {
for (AbstractPower p : AbstractDungeon.player.powers) {
if (p instanceof DamageModApplyingPower && ((DamageModApplyingPower) p).shouldPushMods(null, ___card, DamageModifierManager.modifiers(___card))) {
Expand All @@ -50,6 +65,7 @@ public static void part1(AbstractCard ___card, @ByRef List<TooltipInfo>[] toolti
}
}
}

private static class Locator1 extends SpireInsertLocator {
@Override
public int[] Locate(CtBehavior ctMethodToPatch) throws Exception {
Expand All @@ -69,6 +85,18 @@ public static void part2(AbstractCard ___card, @ByRef List<TooltipInfo>[] toolti
for (AbstractBlockModifier mod : BlockModifierManager.modifiers(___card)) {
tooltips[0].addAll(mod.getCustomTooltips());
}
for (AbstractCustomIcon icon : CustomIconHelper.iconsOnCard(___card)) {
if (icon.keywordLinks() != null) {
for (String s : icon.keywordLinks()) {
if (!___card.rawDescription.toLowerCase().contains(s)) {
tooltips[0].add(new TooltipInfo(BaseMod.getKeywordTitle(s), BaseMod.getKeywordDescription(s)));
}
}
}
if (icon.getCustomTooltips() != null) {
tooltips[0].addAll(icon.getCustomTooltips());
}
}
if (AbstractDungeon.player != null && RenderElementsOnCardPatches.validLocation(___card)) {
for (AbstractPower p : AbstractDungeon.player.powers) {
if (p instanceof DamageModApplyingPower && ((DamageModApplyingPower) p).shouldPushMods(null, ___card, DamageModifierManager.modifiers(___card))) {
Expand All @@ -81,14 +109,15 @@ public static void part2(AbstractCard ___card, @ByRef List<TooltipInfo>[] toolti
}
}
}

private static class Locator2 extends SpireInsertLocator {
@Override
public int[] Locate(CtBehavior ctMethodToPatch) throws Exception {
Matcher finalMatcher = new Matcher.MethodCallMatcher(List.class, "iterator");
int[] tmp = LineFinder.findAllInOrder(ctMethodToPatch, finalMatcher);
int[] ret = new int[1];
for (int value : tmp) {
ret[0] = value-1;
ret[0] = value - 1;
}
return ret;
}
Expand All @@ -113,6 +142,20 @@ public static void pls(AbstractCard acard, ArrayList<PowerTip>[] t) {
}
}
}
for (AbstractCustomIcon icon : CustomIconHelper.iconsOnCard(acard)) {
if (icon.keywordLinks() != null) {
for (String s : icon.keywordLinks()) {
if (!acard.rawDescription.toLowerCase().contains(s)) {
t[0].add(new TooltipInfo(BaseMod.getKeywordTitle(s), BaseMod.getKeywordDescription(s)).toPowerTip());
}
}
}
if (icon.getCustomTooltips() != null) {
for (TooltipInfo tip : icon.getCustomTooltips()) {
t[0].add(tip.toPowerTip());
}
}
}
if (AbstractDungeon.player != null && RenderElementsOnCardPatches.validLocation(acard)) {
for (AbstractPower p : AbstractDungeon.player.powers) {
if (p instanceof DamageModApplyingPower && ((DamageModApplyingPower) p).shouldPushMods(null, acard, DamageModifierManager.modifiers(acard))) {
Expand Down Expand Up @@ -144,6 +187,7 @@ public static void pls(AbstractCard __instance, SpriteBatch sb, float x, float y
}
}
}

private static class Locator extends SpireInsertLocator {
@Override
public int[] Locate(CtBehavior ctMethodToPatch) throws Exception {
Expand All @@ -168,6 +212,7 @@ public static void pls(AbstractCard __instance, SpriteBatch sb, String[] text, @
}
}
}

private static class Locator extends SpireInsertLocator {
@Override
public int[] Locate(CtBehavior ctMethodToPatch) throws Exception {
Expand All @@ -192,6 +237,7 @@ public static void pls(AbstractCard ___card, @ByRef List<String>[] descriptors)
}
}
}

private static class Locator extends SpireInsertLocator {
@Override
public int[] Locate(CtBehavior ctMethodToPatch) throws Exception {
Expand Down

0 comments on commit 8a4ecaf

Please sign in to comment.