From 1092f5b2eb0ebe6669922a6a4f945f5255b3c153 Mon Sep 17 00:00:00 2001 From: RhenaudTheLukark Date: Sun, 11 Feb 2024 17:17:02 +0100 Subject: [PATCH] [Fix] Monster texts sometimes skipping a line --- Assets/Scripts/Battle/GameOverBehavior.cs | 4 +- Assets/Scripts/Battle/UIController.cs | 44 ++++++++++--------- .../Scripts/Lua/CLRBindings/LuaTextManager.cs | 13 ++---- .../Lua/CLRBindings/Overworld/LuaGeneralOW.cs | 4 +- Assets/Scripts/Overworld/EventManager.cs | 5 +-- Assets/Scripts/Overworld/IntroManager.cs | 2 +- Assets/Scripts/Overworld/ItemBoxUI.cs | 4 +- Assets/Scripts/Overworld/PlayerOverworld.cs | 10 ++--- Assets/Scripts/Overworld/ShopScript.cs | 2 +- Assets/Scripts/Text/TextManager.cs | 41 ++++++++--------- 10 files changed, 60 insertions(+), 69 deletions(-) diff --git a/Assets/Scripts/Battle/GameOverBehavior.cs b/Assets/Scripts/Battle/GameOverBehavior.cs index 6ff43252d..b2002a4a2 100644 --- a/Assets/Scripts/Battle/GameOverBehavior.cs +++ b/Assets/Scripts/Battle/GameOverBehavior.cs @@ -89,7 +89,7 @@ public void ResetGameOver() { internalTimer = 0.0f; internalTimerRevive = 0.0f; gameOverFadeTimer = 0.0f; - gameOverTxt.textQueue = null; + gameOverTxt.HideTextObject(); started = false; done = false; exiting = false; @@ -391,7 +391,7 @@ private void Update () { heartShardRelocs[i].y -= 100f * Time.deltaTime; } - if (gameOverTxt.textQueue == null) return; + if (!gameOverTxt.isactive) return; if (!exiting && gameOverTxt.AllLinesComplete() && gameOverTxt.LineCount() != 0) { exiting = true; gameOverFadeTimer = 1.0f; diff --git a/Assets/Scripts/Battle/UIController.cs b/Assets/Scripts/Battle/UIController.cs index d3a4208d3..f74cba68b 100644 --- a/Assets/Scripts/Battle/UIController.cs +++ b/Assets/Scripts/Battle/UIController.cs @@ -311,7 +311,7 @@ public void SwitchState(string newState, bool first = false) { LuaTextManager sbTextMan = enemy.bubbleObject.GetComponentInChildren(); if (!sbTextMan) continue; - sbTextMan.DestroyChars(); + sbTextMan.HideTextObject(); } } else if (state == "ATTACKING") FightUIController.instance.HideAttackingUI(); @@ -579,6 +579,9 @@ private void Awake() { private void UpdateMonsterDialogue() { bool allGood = true; for (int i = 0; i < monsterDialogues.Length; i++) { + if (monsterDialogues[i] == null || !monsterDialogues[i].isactive) + continue; + if (monsterDialogues[i].CanAutoSkipAll()) { for (int j = 0; j < monsterDialogues.Length; j++) readyToNextLine[encounter.enemies.IndexOf(monsterDialogueEnemy[j])] = true; @@ -621,10 +624,10 @@ public void DoNextMonsterDialogue(bool singleLineAll = false, int index = -1) { monsterDialogueEnemy[index].UpdateBubble(index); someTextsHaveLinesLeft = true; } else { - monsterDialogues[index].DestroyChars(); + monsterDialogues[index].HideTextObject(); monsterDialogueEnemy[index].HideBubble(); - foreach (LuaTextManager textManager in monsterDialogues) - if (textManager.HasNext()) + foreach (LuaTextManager mgr in monsterDialogues) + if (mgr != null && mgr.isactive && mgr.HasNext()) someTextsHaveLinesLeft = true; } } else if (!singleLineAll) { @@ -633,11 +636,11 @@ public void DoNextMonsterDialogue(bool singleLineAll = false, int index = -1) { if (!enemy.bubbleObject) continue; LuaTextManager sbTextMan = enemy.bubbleObject.GetComponentInChildren(); - if (!sbTextMan) + if (!sbTextMan || !sbTextMan.isactive) continue; if (sbTextMan.AllLinesComplete() && sbTextMan.LineCount() != 0 || (!sbTextMan.HasNext() && readyToNextLine[encounter.enemies.IndexOf(monsterDialogueEnemy[i])])) { - sbTextMan.DestroyChars(); + sbTextMan.HideTextObject(); enemy.HideBubble(); continue; } @@ -648,7 +651,7 @@ public void DoNextMonsterDialogue(bool singleLineAll = false, int index = -1) { sbTextMan.NextLineText(); enemy.UpdateBubble(i); } else { - sbTextMan.DestroyChars(); + sbTextMan.HideTextObject(); enemy.HideBubble(); continue; } @@ -664,7 +667,7 @@ public void DoNextMonsterDialogue(bool singleLineAll = false, int index = -1) { if (!sbTextMan) continue; - sbTextMan.DestroyChars(); + sbTextMan.HideTextObject(); enemy.HideBubble(); } @@ -943,11 +946,12 @@ private void HandleAction() { break; case "ENEMYDIALOGUE": - bool singleLineAll = monsterDialogues.Where(mgr => mgr != null).All(mgr => mgr.LineCount() <= 1 && mgr.CanSkip()); + bool singleLineAll = monsterDialogues.Where(mgr => mgr != null && mgr.isactive).All(mgr => mgr.LineCount() <= 1 && mgr.CanSkip()); if (singleLineAll) { - foreach (TextManager mgr in monsterDialogues) - mgr.DoSkipFromPlayer(); - mainTextManager.nextMonsterDialogueOnce = true; + foreach (LuaTextManager mgr in monsterDialogues) + if (mgr != null && mgr.isactive) + mgr.DoSkipFromPlayer(); + DoNextMonsterDialogue(true); } else if (!ArenaManager.instance.isResizeInProgress()) { bool readyToSkip = readyToNextLine.All(b => b); if (readyToSkip) @@ -1013,10 +1017,7 @@ private void HandleArrows() { if (xMov == 0) break; - int oldActionIndex = (int)action; action = FindAvailableAction(left ? -1 : 1); - int actionIndex = (int)action; - SetPlayerOnAction(action); PlaySound(AudioClipRegistry.GetSound("menumove")); @@ -1083,7 +1084,9 @@ private void HandleCancel() { bool singleLineAll = true; bool cannotSkip = false; // why two booleans for the same result? 'cause they're different conditions - foreach (TextManager mgr in monsterDialogues) { + foreach (LuaTextManager mgr in monsterDialogues) { + if (mgr != null && !mgr.isactive) + continue; if (!mgr.CanSkip()) cannotSkip = true; @@ -1094,8 +1097,9 @@ private void HandleCancel() { if (cannotSkip || singleLineAll) break; - foreach (TextManager mgr in monsterDialogues) - mgr.DoSkipFromPlayer(); + foreach (LuaTextManager mgr in monsterDialogues) + if (mgr != null && mgr.isactive) + mgr.DoSkipFromPlayer(); break; case "ACTMENU": @@ -1403,8 +1407,8 @@ private void Update() { SwitchState(stateAfterDialogs); if (state == "ENEMYDIALOGUE") { - if (monsterDialogues.All(mgr => mgr.CanAutoSkipThis())) DoNextMonsterDialogue(); - else UpdateMonsterDialogue(); + if (monsterDialogues.Where(mgr => mgr != null && mgr.isactive).All(mgr => mgr.CanAutoSkipThis())) DoNextMonsterDialogue(); + else UpdateMonsterDialogue(); } if (state == "DEFENDING") { diff --git a/Assets/Scripts/Lua/CLRBindings/LuaTextManager.cs b/Assets/Scripts/Lua/CLRBindings/LuaTextManager.cs index e6297f736..5d119d043 100644 --- a/Assets/Scripts/Lua/CLRBindings/LuaTextManager.cs +++ b/Assets/Scripts/Lua/CLRBindings/LuaTextManager.cs @@ -8,7 +8,6 @@ public class LuaTextManager : TextManager { private GameObject container; private bool removed; - private bool hidden; private GameObject containerBubble; private RectTransform speechThing; private RectTransform speechThingShadow; @@ -63,8 +62,8 @@ public bool adjustTextDisplay { } } - public bool isactive { - get { return !removed && !hidden; } + public override bool isactive { + get { return base.isactive && !removed; } } // The rotation of the text object @@ -104,7 +103,7 @@ protected override void Update() { if (hidden) return; base.Update(); - if (!isactive || textQueue == null || textQueue.Length == 0) return; + if (!isactive) return; //Next line/EOF check switch (progress) { case ProgressMode.MANUAL: { @@ -140,11 +139,6 @@ public void DestroyText() { removed = true; } - [MoonSharpHidden] public void HideTextObject() { - DestroyChars(); - hidden = true; - } - private void ResizeBubble() { float effectiveBubbleHeight = bubbleHeight != -1 ? bubbleHeight < 16 ? 40 : bubbleHeight + 24 : UnitaleUtil.CalcTextHeight(this) < 16 ? 40 : UnitaleUtil.CalcTextHeight(this) + 24; containerBubble.transform.GetComponent().sizeDelta = new Vector2(textMaxWidth + 20, effectiveBubbleHeight); //To set the borders @@ -495,7 +489,6 @@ public bool allLinesComplete { public void SetText(DynValue text, bool resetLateStart = true) { CheckExists(); - hidden = false; // Disable late start if SetText is used on the same frame the text is created if (resetLateStart) diff --git a/Assets/Scripts/Lua/CLRBindings/Overworld/LuaGeneralOW.cs b/Assets/Scripts/Lua/CLRBindings/Overworld/LuaGeneralOW.cs index ba42996ef..390145f99 100644 --- a/Assets/Scripts/Lua/CLRBindings/Overworld/LuaGeneralOW.cs +++ b/Assets/Scripts/Lua/CLRBindings/Overworld/LuaGeneralOW.cs @@ -124,8 +124,8 @@ [CYFEventFunction] public void EndDialog() { if (textmgr != null && textmgr.GetComponent().color.a != 0) { // Clean up text manager textmgr.SetTextFrameAlpha(0); - textmgr.textQueue = new TextMessage[] { }; - textmgr.DestroyChars(); + textmgr.SetTextQueue(new TextMessage[] { }); + textmgr.HideTextObject(); // Clean up SetChoice if applicable if (EventManager.instance.script != null && EventManager.instance.script == textmgr.caller) { diff --git a/Assets/Scripts/Overworld/EventManager.cs b/Assets/Scripts/Overworld/EventManager.cs index 99eb87a0a..abe9ad0ad 100644 --- a/Assets/Scripts/Overworld/EventManager.cs +++ b/Assets/Scripts/Overworld/EventManager.cs @@ -1050,8 +1050,7 @@ public static void GetMapState(MapInfos mi, string id) { /// public void EndEvent() { PlayerOverworld.instance.textmgr.SetTextFrameAlpha(0); - PlayerOverworld.instance.textmgr.textQueue = new TextMessage[] { }; - PlayerOverworld.instance.textmgr.DestroyChars(); + PlayerOverworld.instance.textmgr.SetTextQueue(new TextMessage[] { }); PlayerOverworld.instance.PlayerNoMove = false; PlayerOverworld.instance.UIPos = 0; ScriptRunning = false; @@ -1811,7 +1810,7 @@ private IEnumerator ISave(object[] args) { // Hides the save dialogue box if (end) { PlayerOverworld.instance.utHeart.color = new Color(c.r, c.g, c.b, 0); - txtName.DestroyChars(); txtLevel.DestroyChars(); txtTime.DestroyChars(); txtMap.DestroyChars(); txtSave.DestroyChars(); txtReturn.DestroyChars(); + txtName.HideTextObject(); txtLevel.HideTextObject(); txtTime.HideTextObject(); txtMap.HideTextObject(); txtSave.HideTextObject(); txtReturn.HideTextObject(); GameObject.Find("save_border_outer").GetComponent().color = new Color(1, 1, 1, 0); GameObject.Find("save_interior").GetComponent().color = new Color(0, 0, 0, 0); script.Call("CYFEventNextCommand"); diff --git a/Assets/Scripts/Overworld/IntroManager.cs b/Assets/Scripts/Overworld/IntroManager.cs index 4a4f1e9f4..4b6d0d47c 100644 --- a/Assets/Scripts/Overworld/IntroManager.cs +++ b/Assets/Scripts/Overworld/IntroManager.cs @@ -82,7 +82,7 @@ private void Update () { //Check end of intro if (text.AllLinesComplete()) { fadeMusic = true; - text.DestroyChars(); + text.HideTextObject(); } else { img.sprite = SpriteRegistry.Get("Intro/" + imagePaths[++currentIndex]); img.SetNativeSize(); diff --git a/Assets/Scripts/Overworld/ItemBoxUI.cs b/Assets/Scripts/Overworld/ItemBoxUI.cs index c7648cd9a..234429448 100644 --- a/Assets/Scripts/Overworld/ItemBoxUI.cs +++ b/Assets/Scripts/Overworld/ItemBoxUI.cs @@ -149,14 +149,14 @@ private void RefreshDisplay() { private void DestroySelf() { while (inventory.Count > 0) { - inventory[0].DestroyChars(); + inventory[0].HideTextObject(); Destroy(inventory[0].gameObject); inventory.RemoveAt(0); inventorySprites[0].Remove(); inventorySprites.RemoveAt(0); } while (boxContents.Count > 0) { - boxContents[0].DestroyChars(); + boxContents[0].HideTextObject(); Destroy(boxContents[0].gameObject); boxContents.RemoveAt(0); boxContentsSprites[0].Remove(); diff --git a/Assets/Scripts/Overworld/PlayerOverworld.cs b/Assets/Scripts/Overworld/PlayerOverworld.cs index b36b1e1a7..2e53637f5 100644 --- a/Assets/Scripts/Overworld/PlayerOverworld.cs +++ b/Assets/Scripts/Overworld/PlayerOverworld.cs @@ -203,7 +203,7 @@ private void NextText() { EventManager.instance.passPressOnce = true; textmgr.transform.parent.parent.SetAsFirstSibling(); textmgr.SetTextQueue(null); - textmgr.DestroyChars(); + textmgr.HideTextObject(); textmgr.SetHorizontalSpacing(textmgr.font.CharSpacing); textmgr.SetVerticalSpacing(); textmgr.SetTextFrameAlpha(0); @@ -748,7 +748,7 @@ public static IEnumerator LaunchMenu() { GameObject.Find("utHeartMenu").transform.localPosition = new Vector3(-48, 143 - 32 * index, GameObject.Find("utHeartMenu").transform.position.z); } else if (GlobalControls.input.Cancel == ButtonState.PRESSED) { instance.menuRunning[0] = false; - for (int i = 7; i <= 17; i++) txtmgrs[i].DestroyChars(); + for (int i = 7; i <= 17; i++) txtmgrs[i].HideTextObject(); GameObject.Find("Mugshot").GetComponent().color = new Color(1, 1, 1, 0); GameObject.Find("textframe_border_outer").GetComponent().color = new Color(1, 1, 1, 0); GameObject.Find("textframe_interior").GetComponent().color = new Color(0, 0, 0, 0); @@ -783,7 +783,7 @@ public static IEnumerator LaunchMenu() { instance.menuRunning[1] = false; } else if (GlobalControls.input.Confirm == ButtonState.PRESSED) { instance.uiAudio.PlayOneShot(AudioClipRegistry.GetSound("menuconfirm")); - for (int i = 7; i <= 17; i++) txtmgrs[i].DestroyChars(); + for (int i = 7; i <= 17; i++) txtmgrs[i].HideTextObject(); GameObject.Find("item_border_outer").GetComponent().color = new Color(1, 1, 1, 0); GameObject.Find("item_interior").GetComponent().color = new Color(0, 0, 0, 0); GameObject.Find("utHeartMenu").GetComponent().color = new Color(c.r, c.g, c.b, 0); @@ -871,7 +871,7 @@ public static IEnumerator LaunchMenu() { GameObject.Find("utHeartMenu").GetComponent().color = new Color(c.r, c.g, c.b, 1); instance.uiAudio.PlayOneShot(AudioClipRegistry.GetSound("menuconfirm")); instance.menuRunning[0] = false; - for (int i = 18; i <= 27; i++) txtmgrs[i].DestroyChars(); + for (int i = 18; i <= 27; i++) txtmgrs[i].HideTextObject(); GameObject.Find("Mugshot").GetComponent().color = new Color(1, 1, 1, 0); GameObject.Find("textframe_border_outer").GetComponent().color = new Color(1, 1, 1, 0); GameObject.Find("textframe_interior").GetComponent().color = new Color(0, 0, 0, 0); @@ -905,7 +905,7 @@ private static bool CloseMenu(bool endOfInText = false) { if (tf.GetComponent()) tf.gameObject.GetComponent().color = new Color(tf.gameObject.GetComponent().color.r, tf.gameObject.GetComponent().color.b, tf.gameObject.GetComponent().color.g, 0); - if (tf.GetComponent()) tf.gameObject.GetComponent().DestroyChars(); + if (tf.GetComponent()) tf.gameObject.GetComponent().HideTextObject(); } instance.menuRunning = new[] { false, false, !endOfInText, true, true }; GameObject.Find("Mugshot").GetComponent().color = new Color(1, 1, 1, 0); diff --git a/Assets/Scripts/Overworld/ShopScript.cs b/Assets/Scripts/Overworld/ShopScript.cs index 15281b8b4..9a144ec07 100644 --- a/Assets/Scripts/Overworld/ShopScript.cs +++ b/Assets/Scripts/Overworld/ShopScript.cs @@ -494,7 +494,7 @@ private void TextInputManager() { else if (script.GetVar("returndir").Number > 8 || script.GetVar("returndir").Number < 2 || script.GetVar("returndir").Number % 2 == 1) throw new CYFException("The variable \"returndir\" must be either 2 (Down), 4 (Left), 6 (Right) or 8 (Up)."); - tmBigTalk.DestroyChars(); + tmBigTalk.HideTextObject(); tp = Instantiate(Resources.Load("Prefabs/TP On-the-fly")); tp.sceneName = script.GetVar("returnscene").String; diff --git a/Assets/Scripts/Text/TextManager.cs b/Assets/Scripts/Text/TextManager.cs index b87352247..55c5f6b51 100644 --- a/Assets/Scripts/Text/TextManager.cs +++ b/Assets/Scripts/Text/TextManager.cs @@ -47,7 +47,6 @@ public LetterData(int index, Image image, Sprite sprite, Vector2 position, bool public int currentReferenceCharacter; private bool currentSkippable = true; private bool decoratedTextOffset; - [MoonSharpHidden] public bool nextMonsterDialogueOnce, wasStated; private RectTransform self; private float currentX; @@ -95,6 +94,8 @@ public LetterData(int index, Image image, Sprite sprite, Vector2 position, bool public int columnShift = 265; public int columnNumber = 2; + protected bool hidden = true; + // The rotation of the text public float rotation { get { return transform.eulerAngles.z; } @@ -107,7 +108,7 @@ public float rotation { [MoonSharpHidden] public ScriptWrapper caller; - [MoonSharpHidden] public TextMessage[] textQueue = null; + [MoonSharpHidden] public TextMessage[] textQueue { get; protected set; } //public string[] mugshotsPath; //public bool overworld; [MoonSharpHidden] public bool skipNowIfBlocked = false; @@ -123,7 +124,6 @@ public TextManager() { currentCharacter = 0; currentReferenceCharacter = 0; decoratedTextOffset = false; - wasStated = false; instantActive = false; instantCommand = false; autoSkipAll = false; @@ -237,6 +237,7 @@ [MoonSharpHidden] public void SetTextQueue(TextMessage[] newTextQueue) { SetMugshot(DynValue.NewNil()); SetMugshotShift(oldLineHasMugshot); } + hidden = newTextQueue.Length == 0; textQueue = newTextQueue; currentLine = 0; ShowLine(0); @@ -396,7 +397,7 @@ protected void ShowLine(int line) { } else { if (transform.parent.GetComponent().color.a == 1) SetTextFrameAlpha(0); - DestroyChars(); + HideTextObject(); } } @@ -486,14 +487,20 @@ public void SetEffect(string effect, float intensity = -1, float step = 0) { } } - [MoonSharpHidden] public void DestroyChars() { + [MoonSharpHidden] protected void DestroyChars() { foreach (Transform child in gameObject.transform) { if (child.GetComponent() == null && child.GetComponent() == null) continue; LuaSpriteController.GetOrCreate(child.gameObject).Remove(); } + textEffect = null; letters.Clear(); } + [MoonSharpHidden] public void HideTextObject() { + DestroyChars(); + hidden = true; + } + private void SpawnTextSpaceTest(int i, string currentText, out string currentText2) { currentText2 = currentText; bool decorated = textQueue[currentLine].Decorated; @@ -804,7 +811,6 @@ private bool CheckCommand() { string command = UnitaleUtil.ParseCommandInline(textQueue[currentLine].Text, ref currentCharacter); if (command != null) { currentCharacter++; // we're not in a continuable loop so move to the character after the ] manually - wasStated = false; DynValue commandDV = DynValue.NewString(command); InUpdateControlCommand(commandDV, currentCharacter); @@ -816,19 +822,7 @@ private bool CheckCommand() { } protected virtual void Update() { - if (!UnitaleUtil.IsOverworld && nextMonsterDialogueOnce) { - bool test = true; - foreach (LuaTextManager mgr in UIController.instance.monsterDialogues) { - if (!mgr.IsFinished()) - test = false; - } - if (test) { - nextMonsterDialogueOnce = false; - if (!wasStated) - UIController.instance.DoNextMonsterDialogue(true); - wasStated = false; - } - } else if (mugshot != null && mugshotList != null) + if (mugshot != null && mugshotList != null) if (UnitaleUtil.IsOverworld && mugshot.alpha != 0 && mugshotList.Length > 1) { if (!mugshot.animcomplete && (letterTimer < 0 || LineComplete())) { mugshot.StopAnimation(); @@ -837,7 +831,7 @@ protected virtual void Update() { mugshot.SetAnimation(mugshotList, mugshotTimer); } - if (textQueue == null || textQueue.Length == 0 || textQueue[currentLine] == null || paused || lateStartWaiting) + if (!isactive || textQueue[currentLine] == null || paused || lateStartWaiting) return; if (textEffect != null) @@ -1181,9 +1175,6 @@ private void InUpdateControlCommand(DynValue command, int index = 0) { caller.Call(args[0], argsbis, true); } else if (caller != null) caller.Call(cmds[1], null, true); - - if (cmds[1] == "State") - wasStated = true; } catch (InterpreterException ex) { UnitaleUtil.DisplayLuaError(caller.scriptname, UnitaleUtil.FormatErrorSource(ex.DecoratedMessage, ex.Message) + ex.Message); } break; @@ -1376,4 +1367,8 @@ private float CreateNumber(string str) { return -number; return number; } + + public virtual bool isactive { + get { return !hidden; } + } } \ No newline at end of file