diff --git a/source/funkin/backend/FunkinText.hx b/source/funkin/backend/FunkinText.hx index a3c8c473..7c7bea8f 100644 --- a/source/funkin/backend/FunkinText.hx +++ b/source/funkin/backend/FunkinText.hx @@ -1,11 +1,19 @@ package funkin.backend; +import funkin.backend.utils.TranslationUtil.IFormatInfo; import flixel.util.FlxColor; import flixel.text.FlxText; class FunkinText extends FlxText { - public function new(X:Float = 0, Y:Float = 0, FieldWidth:Float = 0, ?Text:String, Size:Int = 16, Border:Bool = true, ?TranslationID:String, ?TranslParameters:Array) { - super(X, Y, FieldWidth, TranslationUtil.get(Text, TranslationID, TranslParameters), Size); + public var langStrID:String = null; + private var langFormat:IFormatInfo; + + public function new(X:Float = 0, Y:Float = 0, FieldWidth:Float = 0, ?Text:String, Size:Int = 16, Border:Bool = true, ?LangStrID:String, ?Parameters:Array) { + langStrID = LangStrID; + langFormat = TranslationUtil.getUnformatted(Text, LangStrID); + + // Should still default to the normal string if the translation is not found + super(X, Y, FieldWidth, getFormattedText(Parameters), Size); setFormat(Paths.font("vcr.ttf"), Size, FlxColor.WHITE); if (Border) { borderStyle = OUTLINE; @@ -13,4 +21,10 @@ class FunkinText extends FlxText { borderColor = 0xFF000000; } } + + public inline function resetLang(Parameters:Array) + return this.text = getFormattedText(Parameters); + + private inline function getFormattedText(Parameters:Array) + return langFormat.format(Parameters); } \ No newline at end of file diff --git a/source/funkin/backend/utils/TranslationUtil.hx b/source/funkin/backend/utils/TranslationUtil.hx index b2afbdf8..333d94ff 100644 --- a/source/funkin/backend/utils/TranslationUtil.hx +++ b/source/funkin/backend/utils/TranslationUtil.hx @@ -98,13 +98,16 @@ class TranslationUtil * * If `id` is `null` then it's gonna search using `defString`. */ - public static function get(defString:String, ?id:String, ?params:Array):String + public static inline function get(defString:String, ?id:String, ?params:Array):String + return getUnformatted(defString, id).format(params); + + public static function getUnformatted(defString:String, ?id:String):IFormatInfo { #if TRANSLATIONS_SUPPORT if (id == null) id = defString; - if (stringMap.exists(id)) return stringMap.get(id).format(params); + if (stringMap.exists(id)) return stringMap.get(id); #end - return FormatUtil.get(defString).format(params); + return FormatUtil.get(defString); } /** diff --git a/source/funkin/game/PlayState.hx b/source/funkin/game/PlayState.hx index e213ae11..9a09d6ff 100644 --- a/source/funkin/game/PlayState.hx +++ b/source/funkin/game/PlayState.hx @@ -720,9 +720,9 @@ class PlayState extends MusicBeatState add(icon); } - scoreTxt = new FunkinText(healthBarBG.x + 50, healthBarBG.y + 30, Std.int(healthBarBG.width - 100), "Score:0", 16); + scoreTxt = new FunkinText(healthBarBG.x + 50, healthBarBG.y + 30, Std.int(healthBarBG.width - 100), "Score:{0}", 16, "score", [songScore]); missesTxt = new FunkinText(healthBarBG.x + 50, healthBarBG.y + 30, Std.int(healthBarBG.width - 100), "Misses:0", 16); - accuracyTxt = new FunkinText(healthBarBG.x + 50, healthBarBG.y + 30, Std.int(healthBarBG.width - 100), "Accuracy:-% (N/A)", 16); + accuracyTxt = new FunkinText(healthBarBG.x + 50, healthBarBG.y + 30, Std.int(healthBarBG.width - 100), "Accuracy:{0} - {1}", 16, "accuracy", ["-%", "(N/A)"]); accuracyTxt.addFormat(accFormat, 0, 1); for(text in [scoreTxt, missesTxt, accuracyTxt]) { @@ -1189,7 +1189,7 @@ class PlayState extends MusicBeatState } function updateRatingStuff() { - scoreTxt.text = 'Score:$songScore'; + scoreTxt.resetLang([songScore]); missesTxt.text = '${comboBreaks ? "Combo Breaks" : "Misses"}:$misses'; if (curRating == null) @@ -1197,7 +1197,7 @@ class PlayState extends MusicBeatState @:privateAccess { accFormat.format.color = curRating.color; - accuracyTxt.text = 'Accuracy:${accuracy < 0 ? "-%" : '${CoolUtil.quantize(accuracy * 100, 100)}%'} - ${curRating.rating}'; + accuracyTxt.resetLang([accuracy < 0 ? "-%" : '${CoolUtil.quantize(accuracy * 100, 100)}%', curRating.rating]); accuracyTxt._formatRanges[0].range.start = accuracyTxt.text.length - curRating.rating.length; accuracyTxt._formatRanges[0].range.end = accuracyTxt.text.length; @@ -1913,7 +1913,7 @@ class ComboRating { public function new(percent:Float, rating:String, color:FlxColor) { this.percent = percent; - this.rating = rating; + this.rating = TranslationUtil.get(rating, 'rating_$rating'); this.color = color; } }