Skip to content

Commit

Permalink
Fix #177 whatmod purple color code not working in Chinese
Browse files Browse the repository at this point in the history
  • Loading branch information
kiooeht committed Jan 14, 2019
1 parent 7743252 commit d40d0b7
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -526,3 +526,4 @@ This is a fast forward to v1.6.3 of daviscook477's fork with a few additional ch

#### dev ####
* Steam Rich Presence (kiooeht)
* Fix whatmod purple color code not working in Chinese (kiooeht)
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package basemod.patches.com.megacrit.cardcrawl.helpers.FontHelper;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.evacipated.cardcrawl.modthespire.lib.*;
import com.megacrit.cardcrawl.core.Settings;
import com.megacrit.cardcrawl.helpers.FontHelper;
import javassist.CtBehavior;

@SpirePatch(
clz=FontHelper.class,
method="exampleNonWordWrappedText"
)
public class FixChineseNoPurpleColor
{
@SpireInsertPatch(
locator=Locator.class,
localvars={"word"}
)
public static void Insert(SpriteBatch sb, BitmapFont font, String msg, float x, float y, Color c, float widthMax, @ByRef String[] word)
{
if (word[0].charAt(1) == 'p') {
word[0] = "[#" + Settings.PURPLE_COLOR.toString() + "]" + word[0].substring(2) + "[]";
}
}

private static class Locator extends SpireInsertLocator
{
@Override
public int[] Locate(CtBehavior ctBehavior) throws Exception
{
Matcher matcher = new Matcher.MethodCallMatcher(String.class, "substring");
int[] found = LineFinder.findInOrder(ctBehavior, matcher);
return new int[]{found[0]+1};
}
}
}

0 comments on commit d40d0b7

Please sign in to comment.