Skip to content

Commit

Permalink
[Fix] Monster texts sometimes skipping a line
Browse files Browse the repository at this point in the history
  • Loading branch information
RhenaudTheLukark committed Feb 11, 2024
1 parent 85ded0f commit 1092f5b
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 69 deletions.
4 changes: 2 additions & 2 deletions Assets/Scripts/Battle/GameOverBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
44 changes: 24 additions & 20 deletions Assets/Scripts/Battle/UIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ public void SwitchState(string newState, bool first = false) {
LuaTextManager sbTextMan = enemy.bubbleObject.GetComponentInChildren<LuaTextManager>();
if (!sbTextMan)
continue;
sbTextMan.DestroyChars();
sbTextMan.HideTextObject();
}
} else if (state == "ATTACKING")
FightUIController.instance.HideAttackingUI();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -633,11 +636,11 @@ public void DoNextMonsterDialogue(bool singleLineAll = false, int index = -1) {
if (!enemy.bubbleObject)
continue;
LuaTextManager sbTextMan = enemy.bubbleObject.GetComponentInChildren<LuaTextManager>();
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;
}
Expand All @@ -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;
}
Expand All @@ -664,7 +667,7 @@ public void DoNextMonsterDialogue(bool singleLineAll = false, int index = -1) {
if (!sbTextMan)
continue;

sbTextMan.DestroyChars();
sbTextMan.HideTextObject();
enemy.HideBubble();
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"));
Expand Down Expand Up @@ -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;

Expand All @@ -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":
Expand Down Expand Up @@ -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") {
Expand Down
13 changes: 3 additions & 10 deletions Assets/Scripts/Lua/CLRBindings/LuaTextManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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<RectTransform>().sizeDelta = new Vector2(textMaxWidth + 20, effectiveBubbleHeight); //To set the borders
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions Assets/Scripts/Lua/CLRBindings/Overworld/LuaGeneralOW.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ [CYFEventFunction] public void EndDialog() {
if (textmgr != null && textmgr.GetComponent<UnityEngine.UI.Image>().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) {
Expand Down
5 changes: 2 additions & 3 deletions Assets/Scripts/Overworld/EventManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1050,8 +1050,7 @@ public static void GetMapState(MapInfos mi, string id) {
/// </summary>
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;
Expand Down Expand Up @@ -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<Image>().color = new Color(1, 1, 1, 0);
GameObject.Find("save_interior").GetComponent<Image>().color = new Color(0, 0, 0, 0);
script.Call("CYFEventNextCommand");
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Overworld/IntroManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions Assets/Scripts/Overworld/ItemBoxUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
10 changes: 5 additions & 5 deletions Assets/Scripts/Overworld/PlayerOverworld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<Image>().color = new Color(1, 1, 1, 0);
GameObject.Find("textframe_border_outer").GetComponent<Image>().color = new Color(1, 1, 1, 0);
GameObject.Find("textframe_interior").GetComponent<Image>().color = new Color(0, 0, 0, 0);
Expand Down Expand Up @@ -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<Image>().color = new Color(1, 1, 1, 0);
GameObject.Find("item_interior").GetComponent<Image>().color = new Color(0, 0, 0, 0);
GameObject.Find("utHeartMenu").GetComponent<Image>().color = new Color(c.r, c.g, c.b, 0);
Expand Down Expand Up @@ -871,7 +871,7 @@ public static IEnumerator LaunchMenu() {
GameObject.Find("utHeartMenu").GetComponent<Image>().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<Image>().color = new Color(1, 1, 1, 0);
GameObject.Find("textframe_border_outer").GetComponent<Image>().color = new Color(1, 1, 1, 0);
GameObject.Find("textframe_interior").GetComponent<Image>().color = new Color(0, 0, 0, 0);
Expand Down Expand Up @@ -905,7 +905,7 @@ private static bool CloseMenu(bool endOfInText = false) {
if (tf.GetComponent<Image>()) tf.gameObject.GetComponent<Image>().color = new Color(tf.gameObject.GetComponent<Image>().color.r,
tf.gameObject.GetComponent<Image>().color.b,
tf.gameObject.GetComponent<Image>().color.g, 0);
if (tf.GetComponent<TextManager>()) tf.gameObject.GetComponent<TextManager>().DestroyChars();
if (tf.GetComponent<TextManager>()) tf.gameObject.GetComponent<TextManager>().HideTextObject();
}
instance.menuRunning = new[] { false, false, !endOfInText, true, true };
GameObject.Find("Mugshot").GetComponent<Image>().color = new Color(1, 1, 1, 0);
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Overworld/ShopScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TPHandler>("Prefabs/TP On-the-fly"));
tp.sceneName = script.GetVar("returnscene").String;
Expand Down
Loading

0 comments on commit 1092f5b

Please sign in to comment.