From 67a4902d2c12461e7e037de8e12764c1ec8d521f Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Thu, 21 Nov 2024 14:03:29 -0500 Subject: [PATCH] v3.0.0: added support for using '**' to highlight, like in markdown --- .../android/AndroidPlatformSupport.java | 14 +++++++------- .../ui/RenderedTextBlock.java | 6 ++++-- .../desktop/DesktopPlatformSupport.java | 8 ++++---- .../ios/IOSPlatformSupport.java | 8 ++++---- 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/android/src/main/java/com/shatteredpixel/shatteredpixeldungeon/android/AndroidPlatformSupport.java b/android/src/main/java/com/shatteredpixel/shatteredpixeldungeon/android/AndroidPlatformSupport.java index db6dc795b..e128df0af 100644 --- a/android/src/main/java/com/shatteredpixel/shatteredpixeldungeon/android/AndroidPlatformSupport.java +++ b/android/src/main/java/com/shatteredpixel/shatteredpixeldungeon/android/AndroidPlatformSupport.java @@ -286,19 +286,19 @@ public class AndroidPlatformSupport extends PlatformSupport { return basicFontGenerator; } } - - //splits on newlines, underscores, and chinese/japaneses characters + + //splits on newline (for layout), chinese/japanese (for font choice), and '_'/'**' (for highlighting) private Pattern regularsplitter = Pattern.compile( - "(?<=\n)|(?=\n)|(?<=_)|(?=_)|" + + "(?<=\n)|(?=\n)|(?<=_)|(?=_)|(?<=\\*\\*)|(?=\\*\\*)|" + "(?<=\\p{InHiragana})|(?=\\p{InHiragana})|" + "(?<=\\p{InKatakana})|(?=\\p{InKatakana})|" + "(?<=\\p{InCJK_Unified_Ideographs})|(?=\\p{InCJK_Unified_Ideographs})|" + "(?<=\\p{InCJK_Symbols_and_Punctuation})|(?=\\p{InCJK_Symbols_and_Punctuation})|" + "(?<=\\p{InHalfwidth_and_Fullwidth_Forms})|(?=\\p{InHalfwidth_and_Fullwidth_Forms})"); - - //additionally splits on words, so that each word can be arranged individually + + //additionally splits on spaces, so that each word can be laid out individually private Pattern regularsplitterMultiline = Pattern.compile( - "(?<= )|(?= )|(?<=\n)|(?=\n)|(?<=_)|(?=_)|" + + "(?<= )|(?= )|(?<=\n)|(?=\n)|(?<=_)|(?=_)|(?<=\\*\\*)|(?=\\*\\*)|" + "(?<=\\p{InHiragana})|(?=\\p{InHiragana})|" + "(?<=\\p{InKatakana})|(?=\\p{InKatakana})|" + "(?<=\\p{InCJK_Unified_Ideographs})|(?=\\p{InCJK_Unified_Ideographs})|" + @@ -307,7 +307,7 @@ public class AndroidPlatformSupport extends PlatformSupport { //splits on each non-hangul character. Needed for weird android 6.0 font files private Pattern android6KRSplitter = Pattern.compile( - "(?<= )|(?= )|(?<=\n)|(?=\n)|(?<=_)|(?=_)|" + + "(?<= )|(?= )|(?<=\n)|(?=\n)|(?<=_)|(?=_)|(?<=\\*\\*)|(?=\\*\\*)|" + "(?!\\p{InHangul_Syllables})|(?(); boolean highlighting = false; for (String str : tokens){ - - if (str.equals("_") && highlightingEnabled){ + + //if highlighting is enabled, '_' or '**' is used to toggle highlighting on or off + // the actual symbols are not rendered + if ((str.equals("_") || str.equals("**")) && highlightingEnabled){ highlighting = !highlighting; } else if (str.equals("\n")){ words.add(NEWLINE); diff --git a/desktop/src/main/java/com/shatteredpixel/shatteredpixeldungeon/desktop/DesktopPlatformSupport.java b/desktop/src/main/java/com/shatteredpixel/shatteredpixeldungeon/desktop/DesktopPlatformSupport.java index 35575505e..c07c36e63 100644 --- a/desktop/src/main/java/com/shatteredpixel/shatteredpixeldungeon/desktop/DesktopPlatformSupport.java +++ b/desktop/src/main/java/com/shatteredpixel/shatteredpixeldungeon/desktop/DesktopPlatformSupport.java @@ -149,17 +149,17 @@ public class DesktopPlatformSupport extends PlatformSupport { } } - //splits on newlines, underscores, and chinese/japaneses characters + //splits on newline (for layout), chinese/japanese (for font choice), and '_'/'**' (for highlighting) private Pattern regularsplitter = Pattern.compile( - "(?<=\n)|(?=\n)|(?<=_)|(?=_)|" + + "(?<=\n)|(?=\n)|(?<=_)|(?=_)|(?<=\\*\\*)|(?=\\*\\*)|" + "(?<=\\p{InHiragana})|(?=\\p{InHiragana})|" + "(?<=\\p{InKatakana})|(?=\\p{InKatakana})|" + "(?<=\\p{InCJK_Unified_Ideographs})|(?=\\p{InCJK_Unified_Ideographs})|" + "(?<=\\p{InCJK_Symbols_and_Punctuation})|(?=\\p{InCJK_Symbols_and_Punctuation})"); - //additionally splits on words, so that each word can be arranged individually + //additionally splits on spaces, so that each word can be laid out individually private Pattern regularsplitterMultiline = Pattern.compile( - "(?<= )|(?= )|(?<=\n)|(?=\n)|(?<=_)|(?=_)|" + + "(?<= )|(?= )|(?<=\n)|(?=\n)|(?<=_)|(?=_)|(?<=\\*\\*)|(?=\\*\\*)|" + "(?<=\\p{InHiragana})|(?=\\p{InHiragana})|" + "(?<=\\p{InKatakana})|(?=\\p{InKatakana})|" + "(?<=\\p{InCJK_Unified_Ideographs})|(?=\\p{InCJK_Unified_Ideographs})|" + diff --git a/ios/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ios/IOSPlatformSupport.java b/ios/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ios/IOSPlatformSupport.java index 9e3af923c..98e151607 100644 --- a/ios/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ios/IOSPlatformSupport.java +++ b/ios/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ios/IOSPlatformSupport.java @@ -169,17 +169,17 @@ public class IOSPlatformSupport extends PlatformSupport { } } - //splits on newlines, underscores, and chinese/japaneses characters + //splits on newline (for layout), chinese/japanese (for font choice), and '_'/'**' (for highlighting) private Pattern regularsplitter = Pattern.compile( - "(?<=\n)|(?=\n)|(?<=_)|(?=_)|" + + "(?<=\n)|(?=\n)|(?<=_)|(?=_)|(?<=\\*\\*)|(?=\\*\\*)|" + "(?<=\\p{InHiragana})|(?=\\p{InHiragana})|" + "(?<=\\p{InKatakana})|(?=\\p{InKatakana})|" + "(?<=\\p{InCJK_Unified_Ideographs})|(?=\\p{InCJK_Unified_Ideographs})|" + "(?<=\\p{InCJK_Symbols_and_Punctuation})|(?=\\p{InCJK_Symbols_and_Punctuation})"); - //additionally splits on words, so that each word can be arranged individually + //additionally splits on spaces, so that each word can be laid out individually private Pattern regularsplitterMultiline = Pattern.compile( - "(?<= )|(?= )|(?<=\n)|(?=\n)|(?<=_)|(?=_)|" + + "(?<= )|(?= )|(?<=\n)|(?=\n)|(?<=_)|(?=_)|(?<=\\*\\*)|(?=\\*\\*)|" + "(?<=\\p{InHiragana})|(?=\\p{InHiragana})|" + "(?<=\\p{InKatakana})|(?=\\p{InKatakana})|" + "(?<=\\p{InCJK_Unified_Ideographs})|(?=\\p{InCJK_Unified_Ideographs})|" +