From 4fa9294fddb15b5433ceaae3e3f9b061afff96cd Mon Sep 17 00:00:00 2001 From: 25Pi25 <67805443+25Pi25@users.noreply.github.com> Date: Sun, 14 Jan 2024 09:24:32 -0500 Subject: [PATCH] Added newline breaks in Second Contact (#620) --- .../Games/FirstContact/FirstContact.cs | 63 +++++++++++++------ 1 file changed, 44 insertions(+), 19 deletions(-) diff --git a/Assets/Scripts/Games/FirstContact/FirstContact.cs b/Assets/Scripts/Games/FirstContact/FirstContact.cs index 86afdc46..ac30aede 100644 --- a/Assets/Scripts/Games/FirstContact/FirstContact.cs +++ b/Assets/Scripts/Games/FirstContact/FirstContact.cs @@ -37,6 +37,7 @@ namespace HeavenStudio.Games.Loaders { new Param("spaceNum", new EntityTypes.Integer(0, 12, 0), "Amount of spaces", "Spaces to add before the untranslated icon"), new Param("dotdotdot", false, "Has ellipses?", "Will the man symbol be proceeded by a <...>?"), + new Param("newline", false, "New line?", "Should this text start a new line?"), new Param("dialogue", "", "Dialogue", "What should this sound translate to?") }, priority = 1 @@ -79,9 +80,9 @@ namespace HeavenStudio.Games.Loaders } } }, - new List() {"ctr", "repeat"}, + new List() { "ctr", "repeat" }, "ctrinterpreter", "en", - new List() {} + new List() { } ); } } @@ -130,7 +131,7 @@ namespace HeavenStudio.Games string onOutDialogue = "YOU SUCK AT CHARTING"; string callDiagBuffer = ""; string respDiagBuffer = ""; - List callDiagList = new List(); + List<(string, bool)> callDiagList = new(); int callDiagIndex = 0; private struct QueuedInterval { @@ -416,7 +417,7 @@ namespace HeavenStudio.Games var input = inputs[i]; double relativeBeat = input.beat - intervalBeat; ScheduleInput(beat, length + relativeBeat, InputAction_Press, AlienTapping, AlienOnMiss, AlienEmpty); - callDiagList.Add(input["dialogue"]); + callDiagList.Add((input["dialogue"], input["newline"])); } BeatAction.New(this, new List() { @@ -427,9 +428,9 @@ namespace HeavenStudio.Games alienTextbox.SetActive(false); alien.Play("alien_point", 0, 0); }), - new BeatAction.Action(beat + (length / 2), delegate - { - alien.Play("alien_idle", 0, 0); + new BeatAction.Action(beat + (length / 2), delegate + { + alien.Play("alien_idle", 0, 0); }) }); } @@ -481,26 +482,45 @@ namespace HeavenStudio.Games alienText.text = callDiagBuffer; } + string GetMessageFromCallDialogue(int callDiagIndex = 0) + { + StringBuilder sb = new StringBuilder(); + for (int i = callDiagIndex; i < callDiagList.Count; i++) + { + (string s, bool showNewline) = callDiagList[i]; + if (showNewline && callDiagIndex != i) + { + break; + } + sb.Append(s); + } + return sb.ToString(); + } + void UpdateTranslateTextbox() { if (callDiagIndex == 0 && !hasMissed && !noHitOnce) { - // shift the textbox to centre the message - StringBuilder sb = new StringBuilder(); - foreach (string s in callDiagList) - { - sb.Append(s); - } - string fullMsg = sb.ToString(); - - // many hardcoded values there'll be a better way to do this - Vector2 size = translateText.GetPreferredValues(fullMsg, 10.95f, 2); - translateText.rectTransform.anchoredPosition = new Vector2(Mathf.Max((10.95f/2f) + (-size.x / 2 - 0.25f), -0.25f), Mathf.Max((2.11f / 2f) + (-size.y / 2) + 0.2f, 0.2f)); + ResetTranslateTextbox(); } translateText.text = respDiagBuffer; translateFailText.text = respDiagBuffer; } + void ResetTranslateTextbox(bool destroyText = false) + { + // shift the textbox to centre the message + string message = GetMessageFromCallDialogue(callDiagIndex); + // many hardcoded values there'll be a better way to do this + Vector2 size = translateText.GetPreferredValues(message, 10.95f, 2); + translateText.rectTransform.anchoredPosition = new Vector2(Mathf.Max((10.95f / 2f) + (-size.x / 2 - 0.25f), -0.25f), Mathf.Max((2.11f / 2f) + (-size.y / 2) + 0.2f, 0.2f)); + if (destroyText) + { + respDiagBuffer = ""; + translateText.text = ""; + } + } + public void MissionControlDisplay(double beat, bool stay, float length) { missionControl.SetActive(true); @@ -599,7 +619,12 @@ namespace HeavenStudio.Games } else { - respDiagBuffer += callDiagList[callDiagIndex]; + (string dialogue, bool showNewline) = callDiagList[callDiagIndex]; + if (showNewline) + { + ResetTranslateTextbox(true); + } + respDiagBuffer += dialogue; translateTextbox.SetActive(true); UpdateTranslateTextbox(); callDiagIndex++;