/** * @brief Add dialog to queue with optional parameters. * @param a_dialogInfo is the dialog info item to add into the queue. * @param a_isPriority allows the dialog info item to skip to the front of the queue (e.g. death messages) * */ public void AddToQueue(DialogInfo a_dialogInfo, bool a_isPriority = false) { // Figure out final dialog string from type (if given) switch (a_dialogInfo.dialogType) { case TECF.eDialogType.INTRO: a_dialogInfo.SetDialog(BattleManager.Instance.introTxt + " " + a_dialogInfo.strData); break; case TECF.eDialogType.ATTACKING: a_dialogInfo.SetDialog(a_dialogInfo.senderEntity.EntityName + " " + BattleManager.Instance.attackTxt); break; case TECF.eDialogType.CRITICAL_HIT: a_dialogInfo.SetDialog(BattleManager.Instance.critTxt); break; case TECF.eDialogType.FAINTED: string faintTxt = (a_dialogInfo.senderEntity.EntityType == eEntityType.ENEMY) ? BattleManager.Instance.enemyDeathTxt : BattleManager.Instance.partyDeathTxt; a_dialogInfo.SetDialog(a_dialogInfo.senderEntity.EntityName + " " + faintTxt); break; case TECF.eDialogType.MISS: a_dialogInfo.SetDialog(BattleManager.Instance.missTxt); break; case TECF.eDialogType.DODGED: a_dialogInfo.SetDialog(a_dialogInfo.targetEntity.EntityName + " " + BattleManager.Instance.dodgeTxt); break; case TECF.eDialogType.DAMAGED: a_dialogInfo.SetDialog(a_dialogInfo.strData + " " + BattleManager.Instance.dmgTxt + " " + a_dialogInfo.targetEntity.EntityName); break; default: a_dialogInfo.SetDialog(a_dialogInfo.strData); break; } // Not priority, add to end of queue if (a_isPriority == false) { DialogQueue.Add(a_dialogInfo); } // Is priority, add to start of queue else { DialogQueue.Insert(0, a_dialogInfo); } }
bool IsDialogValid(DialogInfo a_dialog) { // Check if dialog type is combat if (a_dialog.dialogType > TECF.eDialogType.COMBAT && a_dialog.dialogType < TECF.eDialogType.COMBAT_END) { // Null check if (a_dialog.senderEntity == null || a_dialog.targetEntity == null) { return(false); } // Unconscious check if (a_dialog.senderEntity.CurrentStatus == eStatusEffect.UNCONSCIOUS || a_dialog.targetEntity.CurrentStatus == eStatusEffect.UNCONSCIOUS) { return(false); } } return(true); }
/** * @brief Go through all lines of dialog that are currently in the queue, including optional end line functions and delays * @param a_funcOnComplete is the optional function to run once all the dialog has been run through. * */ IEnumerator RunThroughDialog(UnityAction a_funcOnComplete = null) { IsWriting = true; while (DialogQueue.Count != 0) { // Get dialog line info DialogInfo dialogInfo = DialogQueue[0]; DialogQueue.RemoveAt(0); // Validate that dialog is still valid or else skip if (!IsDialogValid(dialogInfo)) { continue; } // Optional start callback dialogInfo.startDialogFunc?.Invoke(); // Gradually display text ref_dialogTxt.text = ""; foreach (char letter in dialogInfo.GetDialog().ToCharArray()) { yield return(new WaitForSeconds(charDelay)); ref_dialogTxt.text += letter; } // Optional delay (or use base delay) yield return(new WaitForSeconds((dialogInfo.endDialogFuncDelay == 0f) ? lineDelay : dialogInfo.endDialogFuncDelay)); // Optional end callback dialogInfo.endDialogFunc?.Invoke(); } // Optional dialog end callback a_funcOnComplete?.Invoke(); IsWriting = false; }