Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extra flavor text to relic #100

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
import com.megacrit.cardcrawl.localization.CardStrings;
import com.megacrit.cardcrawl.localization.LocalizedStrings;
import com.megacrit.cardcrawl.localization.PotionStrings;
import com.megacrit.cardcrawl.localization.RelicStrings;
import com.megacrit.cardcrawl.potions.AbstractPotion;
import com.megacrit.cardcrawl.relics.AbstractRelic;
import com.megacrit.cardcrawl.screens.SingleCardViewPopup;
import javassist.CtBehavior;

Expand Down Expand Up @@ -115,6 +117,20 @@ public static class PowerTipFlavorFields {
public static SpireField<Texture> boxBot = new SpireField<>(() -> null);
}

@SpirePatch2(
clz = AbstractRelic.class,
method = SpirePatch.CLASS
)
public static class RelicExtraFlavorFields {
public static SpireField<String> text = new SpireField<>(() -> null);
public static SpireField<Color> boxColor = new SpireField<>(Color.WHITE::cpy);
public static SpireField<Color> textColor = new SpireField<>(Color.BLACK::cpy);
public static SpireField<FlavorText.boxType> flavorBoxType = new SpireField<>(() -> FlavorText.boxType.WHITE);
public static SpireField<Texture> boxTop = new SpireField<>(() -> null);
public static SpireField<Texture> boxMid = new SpireField<>(() -> null);
public static SpireField<Texture> boxBot = new SpireField<>(() -> null);
}

@SpirePatch(
clz = CardStrings.class,
method = SpirePatch.CLASS
Expand All @@ -133,6 +149,15 @@ public static class PotionStringsFlavorField {
public static SpireField<String> flavor = new SpireField<>(() -> null);
}

@SpirePatch(
clz = RelicStrings.class,
method = SpirePatch.CLASS
)
public static class RelicStringsExtraFlavorField {
@SerializedName("EXTRA_FLAVOR")
public static SpireField<String> extraFlavor = new SpireField<>(() -> null);
}

@SpirePatch2(
clz = AbstractCard.class,
method = SpirePatch.CONSTRUCTOR,
Expand Down Expand Up @@ -175,6 +200,32 @@ public static void postfix(AbstractPotion __instance) {
}
}

@SpirePatch2(
clz = AbstractRelic.class,
method = SpirePatch.CONSTRUCTOR,
paramtypez = {String.class, String.class, AbstractRelic.RelicTier.class, AbstractRelic.LandingSound.class}
)
public static class FlavorIntoRelicStrings {
@SpireInsertPatch(
locator = Locator.class
)
public static void postfix(AbstractRelic __instance) {
RelicStrings relicStrings = CardCrawlGame.languagePack.getRelicStrings(__instance.relicId);
if (relicStrings == null || RelicStringsExtraFlavorField.extraFlavor.get(relicStrings) == null ||
RelicStringsExtraFlavorField.extraFlavor.get(relicStrings).isEmpty())
return;

RelicExtraFlavorFields.text.set(__instance, RelicStringsExtraFlavorField.extraFlavor.get(relicStrings));
}

private static class Locator extends SpireInsertLocator {
public int[] Locate(CtBehavior ctMethodToPatch) throws Exception {
Matcher finalMatcher = new Matcher.MethodCallMatcher(AbstractRelic.class, "initializeTips");
return LineFinder.findInOrder(ctMethodToPatch, new ArrayList<>(), finalMatcher);
}
}
}

@SpirePatch2(
clz = SingleCardViewPopup.class,
method = "renderTips"
Expand Down Expand Up @@ -233,6 +284,33 @@ public static void Prefix(AbstractPotion __instance) {
}
}

@SpirePatch2(
clz = AbstractRelic.class,
method = "renderTip"
)
public static class PassRelicTooltip {
@SpirePrefixPatch
public static SpireReturn<Void> Prefix(AbstractRelic __instance) {
if (__instance.tips.stream().anyMatch(tip -> tip.header.equals(HEADER_STRING)))
return SpireReturn.Continue();

if (RelicExtraFlavorFields.text.get(__instance) == null || RelicExtraFlavorFields.text.get(__instance) == null ||
RelicExtraFlavorFields.text.get(__instance).isEmpty())
return SpireReturn.Continue();

PowerTip tip = new PowerTip(HEADER_STRING, RelicExtraFlavorFields.text.get(__instance));
FlavorText.PowerTipFlavorFields.textColor.set(tip, RelicExtraFlavorFields.textColor.get(__instance));
FlavorText.PowerTipFlavorFields.boxColor.set(tip, RelicExtraFlavorFields.boxColor.get(__instance));
FlavorText.PowerTipFlavorFields.flavorBoxType.set(tip, RelicExtraFlavorFields.flavorBoxType.get(__instance));
FlavorText.PowerTipFlavorFields.boxBot.set(tip, RelicExtraFlavorFields.boxBot.get(__instance));
FlavorText.PowerTipFlavorFields.boxMid.set(tip, RelicExtraFlavorFields.boxMid.get(__instance));
FlavorText.PowerTipFlavorFields.boxTop.set(tip, RelicExtraFlavorFields.boxTop.get(__instance));
__instance.tips.add(tip);

return SpireReturn.Continue();
}
}

@SpirePatch2(
clz = TipHelper.class,
method = "renderPowerTips"
Expand Down