private void AssignConnectors(DialogueEntry entry, Conversation conversation, HashSet<string> alreadyConnected, HashSet<int> entriesVisited, int level)
        {
            // Sanity check to prevent infinite recursion:
            if (level > 10000) return;

            // Set non-connectors:
            foreach (Link link in entry.outgoingLinks) {
                if (link.originConversationID == link.destinationConversationID) {
                    string destination = string.Format("{0}.{1}", link.destinationConversationID, link.destinationDialogueID);
                    if (alreadyConnected.Contains(destination)) {
                        link.isConnector = true;
                    } else {
                        link.isConnector = false;
                        alreadyConnected.Add(destination);
                    }
                }
            }

            // Then process each child:
            foreach (Link link in entry.outgoingLinks) {
                if (link.originConversationID == link.destinationConversationID) {
                    if (!entriesVisited.Contains(link.destinationDialogueID)) {
                        entriesVisited.Add(link.destinationDialogueID);
                        var childEntry = conversation.GetDialogueEntry(link.destinationDialogueID);
                        if (childEntry != null) {
                            AssignConnectors(childEntry, conversation, alreadyConnected, entriesVisited, level + 1);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
    public void AddConversationToList()
    {
        dialogueEntry = DialogueManager.CurrentConversationState.subtitle.dialogueEntry;
        conversationID = dialogueEntry.conversationID;
        dialogueEntryID = dialogueEntry.id;

        DroppedConversationsIDs.Add(conversationID);
        DroppedDialogueIDs.Add(dialogueEntryID);
    }
 private bool ContainsSearchString(DialogueEntry entry)
 {
     foreach (var field in entry.fields) {
         if (ContainsSearchStringCaseInsensitive(field.value)) return true;
     }
     if (ContainsSearchStringCaseInsensitive(entry.conditionsString)) return true;
     if (ContainsSearchStringCaseInsensitive(entry.userScript)) return true;
     return false;
 }
Ejemplo n.º 4
0
        private DialogueNode BuildDialogueNode(DialogueEntry entry, Link originLink, int level, List <DialogueEntry> visited)
        {
            if (entry == null)
            {
                return(null);
            }
            bool wasEntryAlreadyVisited = visited.Contains(entry);

            if (!wasEntryAlreadyVisited)
            {
                visited.Add(entry);
            }

            // Create this node:
            float    indent     = DialogueEntryIndent * level;
            bool     isLeaf     = (entry.outgoingLinks.Count == 0);
            bool     hasFoldout = !(isLeaf || wasEntryAlreadyVisited);
            GUIStyle guiStyle   = wasEntryAlreadyVisited ? grayGUIStyle
                                : isLeaf?GetDialogueEntryLeafStyle(entry) : GetDialogueEntryStyle(entry);

            DialogueNode node = new DialogueNode(entry, originLink, guiStyle, indent, !wasEntryAlreadyVisited, hasFoldout);

            if (!dialogueEntryFoldouts.ContainsKey(entry.id))
            {
                dialogueEntryFoldouts[entry.id] = true;
            }

            // Add children:
            if (!wasEntryAlreadyVisited)
            {
                foreach (Link link in entry.outgoingLinks)
                {
                    node.children.Add(BuildDialogueNode(currentConversation.GetDialogueEntry(link.destinationDialogueID), link, level + 1, visited));
                }
            }
            return(node);
        }
Ejemplo n.º 5
0
    /// <summary>
    /// Resets all values to start values.
    /// </summary>
    /// <param name="other"></param>
    public override void ResetValues()
    {
        base.ResetValues();

        // General battle things
        escapeButtonEnabled = true;

        // Tutorial stuff
        isTutorial          = false;
        backgroundHintLeft  = null;
        backgroundHintRight = null;
        removeSide          = RemoveSide.NONE;
        playerInvincible    = false;
        useSlowTime         = true;

        // Background
        backgroundLeft  = null;
        backgroundRight = null;

        // Enemies
        randomizeEnemies = false;
        numberOfEnemies  = 1;
        enemyTypes       = new List <EnemyEntry>();

        // Player stuff
        useSpecificKanji = true;
        equippedKanji    = new Kanji[Constants.MAX_EQUIPPED_KANJI];

        // After match values
        nextLocation   = NextLocation.OVERWORLD;
        changePosition = false;
        playerArea     = Constants.OverworldArea.DEFAULT;
        playerPosition = new Vector2();
        nextDialogue   = null;
        nextBattle     = null;
    }
Ejemplo n.º 6
0
    public override bool Act(DialogueScene scene, DialogueJsonItem data)
    {
        DialogueEntry de = (DialogueEntry)data.entry;

        switch (de.nextLocation)
        {
        case BattleEntry.NextLocation.OVERWORLD:
            scene.paused.value = false;
            if (de.changePosition)
            {
                if (de.nextArea != Constants.OverworldArea.DEFAULT)
                {
                    scene.playerArea.value = (int)de.nextArea;
                }
                scene.playerPosX.value = de.playerPosition.x;
                scene.playerPosY.value = de.playerPosition.y;
            }
            scene.currentArea.value = scene.playerArea.value;
            scene.mapChangeEvent.Invoke();
            break;

        case BattleEntry.NextLocation.DIALOGUE:
            scene.currentArea.value  = (int)Constants.SCENE_INDEXES.DIALOGUE;
            scene.dialogueUuid.value = de.nextEntry.uuid;
            scene.mapChangeEvent.Invoke();
            break;

        case BattleEntry.NextLocation.BATTLE:
            scene.currentArea.value = (int)Constants.SCENE_INDEXES.BATTLE;
            scene.battleUuid.value  = de.nextEntry.uuid;
            scene.mapChangeEvent.Invoke();
            break;
        }

        return(false);
    }
Ejemplo n.º 7
0
        private void ShowNodeContextMenu(DialogueEntry entry)
        {
            GenericMenu contextMenu = new GenericMenu();

            contextMenu.AddItem(new GUIContent("Create Child Node"), false, AddChildCallback, entry);
            contextMenu.AddItem(new GUIContent("Make Link"), false, MakeLinkCallback, entry);
            if ((multinodeSelection.nodes.Count > 1) && (multinodeSelection.nodes.Contains(entry)))
            {
                contextMenu.AddItem(new GUIContent("Duplicate"), false, DuplicateMultipleEntriesCallback, entry);
                contextMenu.AddItem(new GUIContent("Delete"), false, DeleteMultipleEntriesCallback, entry);
            }
            else if (entry == startEntry)
            {
                contextMenu.AddDisabledItem(new GUIContent("Duplicate"));
                contextMenu.AddDisabledItem(new GUIContent("Delete"));
            }
            else
            {
                contextMenu.AddItem(new GUIContent("Duplicate"), false, DuplicateEntryCallback, entry);
                contextMenu.AddItem(new GUIContent("Delete"), false, DeleteEntryCallback, entry);
            }
            contextMenu.AddItem(new GUIContent("Arrange Nodes"), false, ArrangeNodesCallback, entry);
            contextMenu.ShowAsContext();
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Creates a new Dialogue System conversation from an articy dialogue. This also adds the
 /// conversation's mandatory first dialogue entry, "START".
 /// </summary>
 /// <returns>
 /// The new conversation.
 /// </returns>
 /// <param name='articyDialogue'>
 /// Articy dialogue.
 /// </param>
 private Conversation CreateNewConversation(ArticyData.Dialogue articyDialogue)
 {
     if (articyDialogue != null)
     {
         conversationID++;
         Conversation conversation = template.CreateConversation(conversationID, articyDialogue.displayName.DefaultText);
         Field.SetValue(conversation.fields, ArticyIdFieldTitle, articyDialogue.id, FieldType.Text);
         Field.SetValue(conversation.fields, "Description", articyDialogue.text.DefaultText, FieldType.Text);
         conversation.ActorID      = FindActorIdFromArticyDialogue(articyDialogue, 0);
         conversation.ConversantID = FindActorIdFromArticyDialogue(articyDialogue, 1);
         DialogueEntry startEntry = template.CreateDialogueEntry(StartEntryID, conversationID, "START");
         Field.SetValue(startEntry.fields, ArticyIdFieldTitle, articyDialogue.id, FieldType.Text);
         ConvertPins(startEntry, articyDialogue.pins);
         startEntry.outgoingLinks = new List <Link>();
         Field.SetValue(startEntry.fields, "Sequence", "None()", FieldType.Text);
         conversation.dialogueEntries.Add(startEntry);
         database.conversations.Add(conversation);
         return(conversation);
     }
     else
     {
         return(null);
     }
 }
Ejemplo n.º 9
0
        private void DrawEntryNode(DialogueEntry entry)
        {
            bool isSelected = multinodeSelection.nodes.Contains(entry);

            Styles.Color nodeColor = (entry.id == 0) ? Styles.Color.Orange
                                : database.IsPlayerID(entry.ActorID) ? Styles.Color.Blue : Styles.Color.Gray;
            if (entry == currentRuntimeEntry)
            {
                nodeColor = Styles.Color.Green;
            }
            string nodeLabel = GetDialogueEntryNodeText(entry);

            if (showActorNames)
            {
                GUIStyle nodeStyle = new GUIStyle(Styles.GetNodeStyle("node", nodeColor, isSelected));
                nodeStyle.padding.top    = 23;
                nodeStyle.padding.bottom = 0;
                GUI.Box(entry.canvasRect, nodeLabel, nodeStyle);
            }
            else
            {
                GUI.Box(entry.canvasRect, nodeLabel, Styles.GetNodeStyle("node", nodeColor, isSelected));
            }
        }
 private string GetDialogueEntryText(DialogueEntry entry)
 {
     if (entry == null) return string.Empty;
     if (!dialogueEntryText.ContainsKey(entry.id) || (dialogueEntryText[entry.id] == null)) {
         dialogueEntryText[entry.id] = BuildDialogueEntryText(entry);
     }
     return dialogueEntryText[entry.id];
 }
 private void ResetConversationSection()
 {
     SetCurrentConversation(null); //currentConversation = null;
     conversationFieldsFoldout = false;
     actorField = null;
     conversantField = null;
     areParticipantsValid = false;
     startEntry = null;
     ResetDialogueTreeSection();
     ResetConversationNodeSection();
 }
Ejemplo n.º 12
0
        private bool DrawDialogueEntryLinks(
            DialogueEntry entry,
            ref Link linkToDelete,
            ref DialogueEntry entryToLinkFrom,
            ref DialogueEntry entryToLinkTo,
            ref bool linkToAnotherConversation)
        {
            if (currentConversation == null)
            {
                return(false);
            }

            EditorGUI.BeginChangeCheck();

            List <GUIContent> destinationList = new List <GUIContent>();

            destinationList.Add(new GUIContent("(Link To)", string.Empty));
            foreach (DialogueEntry destinationEntry in currentConversation.dialogueEntries)
            {
                if (destinationEntry != entry)
                {
                    destinationList.Add(new GUIContent(string.Format("[{0}] {1}", destinationEntry.id, GetDialogueEntryText(destinationEntry)), string.Empty));
                }
            }
            destinationList.Add(new GUIContent("(Another Conversation)", string.Empty));
            destinationList.Add(new GUIContent("(New Entry)", string.Empty));
            int destinationIndex = EditorGUILayout.Popup(new GUIContent("Links To:", "Add a link to another entry. Select (New Entry) to create and link to a new entry."), 0, destinationList.ToArray());

            if (destinationIndex > 0)
            {
                entryToLinkFrom = entry;
                if (destinationIndex == destinationList.Count - 1)                   // (New Entry)
                {
                    entryToLinkTo             = null;
                    linkToAnotherConversation = false;
                }
                else if (destinationIndex == destinationList.Count - 2)                     // (Another Conversation)
                {
                    entryToLinkTo             = null;
                    linkToAnotherConversation = true;
                }
                else
                {
                    int destinationID = AssetListIndexToID(destinationIndex, destinationList.ToArray());
                    entryToLinkTo = currentConversation.dialogueEntries.Find(e => e.id == destinationID);
                    if (entryToLinkTo == null)
                    {
                        entryToLinkFrom = null;
                        Debug.LogError(string.Format("{0}: Couldn't find destination dialogue entry in database.", DialogueDebug.Prefix));
                    }
                }
                EditorGUILayout.EndHorizontal();
                return(false);
            }
            int linkIndexToMoveUp   = -1;
            int linkIndexToMoveDown = -1;

            if ((entry != null) && (entry.outgoingLinks != null))
            {
                for (int linkIndex = 0; linkIndex < entry.outgoingLinks.Count; linkIndex++)
                {
                    Link link = entry.outgoingLinks[linkIndex];
                    EditorGUILayout.BeginHorizontal();

                    if (link.destinationConversationID == currentConversation.id)
                    {
                        // Is a link to an entry in the current conversation, so handle normally:
                        DialogueEntry linkEntry = database.GetDialogueEntry(link);
                        if (linkEntry != null)
                        {
                            string linkText = (linkEntry == null) ? string.Empty
                                                                : (linkEntry.isGroup ? GetDialogueEntryText(linkEntry) : linkEntry.ResponseButtonText);
                            GUIStyle linkButtonStyle = GetLinkButtonStyle(linkEntry);
                            if (GUILayout.Button(linkText, linkButtonStyle))
                            {
                                currentEntry = database.GetDialogueEntry(link);
                                EditorGUILayout.EndHorizontal();
                                return(false);
                            }
                        }
                    }
                    else
                    {
                        // Cross-conversation link:
                        link.destinationConversationID = DrawConversationsPopup(link.destinationConversationID);
                        link.destinationDialogueID     = DrawCrossConversationEntriesPopup(link.destinationConversationID, link.destinationDialogueID);
                    }

                    EditorGUI.BeginDisabledGroup(linkIndex == 0);
                    if (GUILayout.Button(new GUIContent("↑", "Move up"), EditorStyles.miniButton, GUILayout.Width(22)))
                    {
                        linkIndexToMoveUp = linkIndex;
                    }
                    EditorGUI.EndDisabledGroup();
                    EditorGUI.BeginDisabledGroup(linkIndex == entry.outgoingLinks.Count - 1);
                    if (GUILayout.Button(new GUIContent("↓", "Move down"), EditorStyles.miniButton, GUILayout.Width(22)))
                    {
                        linkIndexToMoveDown = linkIndex;
                    }
                    EditorGUI.EndDisabledGroup();
                    link.priority = (ConditionPriority)EditorGUILayout.Popup((int)link.priority, priorityStrings, GUILayout.Width(100));
                    bool deleted = GUILayout.Button(new GUIContent(" ", "Delete link."), "OL Minus", GUILayout.Width(16));
                    if (deleted)
                    {
                        linkToDelete = link;
                    }
                    EditorGUILayout.EndHorizontal();
                }
            }

            if (linkIndexToMoveUp != -1)
            {
                MoveLink(entry, linkIndexToMoveUp, -1);
            }
            if (linkIndexToMoveDown != -1)
            {
                MoveLink(entry, linkIndexToMoveDown, 1);
            }

            bool changed = EditorGUI.EndChangeCheck();

            if (changed)
            {
                SetDatabaseDirty();
            }
            return(changed);
        }
        private Field DrawConversationParticipant(GUIContent fieldTitle, Field participantField)
        {
            EditorGUILayout.BeginHorizontal();
            if (participantField == null) participantField = LookupConversationParticipantField(fieldTitle.text);

            string originalValue = participantField.value;
            DrawField(participantField, false);
            if (!string.Equals(originalValue, participantField.value)) {
                int newParticipantID = Tools.StringToInt(participantField.value);
                UpdateConversationParticipant(Tools.StringToInt(originalValue), newParticipantID);
                startEntry = GetOrCreateFirstDialogueEntry();
                if (string.Equals(fieldTitle.text, "Actor")) {
                    if (startEntry != null) startEntry.ActorID = newParticipantID;
                    actorID = newParticipantID;
                } else {
                    if (startEntry != null) startEntry.ConversantID = newParticipantID;
                    conversantID = newParticipantID;
                }
                areParticipantsValid = false;
                ResetDialogueEntryText();
            }
            EditorGUILayout.EndHorizontal();
            return participantField;
        }
        private DialogueNode BuildDialogueNode(DialogueEntry entry, Link originLink, int level, List<DialogueEntry> visited)
        {
            if (entry == null) return null;
            bool wasEntryAlreadyVisited = visited.Contains(entry);
            if (!wasEntryAlreadyVisited) visited.Add(entry);

            // Create this node:
            float indent = DialogueEntryIndent * level;
            bool isLeaf = (entry.outgoingLinks.Count == 0);
            bool hasFoldout = !(isLeaf || wasEntryAlreadyVisited);
            GUIStyle guiStyle = wasEntryAlreadyVisited ? grayGUIStyle
                : isLeaf ? GetDialogueEntryLeafStyle(entry) : GetDialogueEntryStyle(entry);
            DialogueNode node = new DialogueNode(entry, originLink, guiStyle, indent, !wasEntryAlreadyVisited, hasFoldout);
            if (!dialogueEntryFoldouts.ContainsKey(entry.id)) dialogueEntryFoldouts[entry.id] = true;

            // Add children:
            if (!wasEntryAlreadyVisited) {
                foreach (Link link in entry.outgoingLinks) {
                    if (link.destinationConversationID == currentConversation.id) { // Only show connection if within same conv.
                        node.children.Add(BuildDialogueNode(currentConversation.GetDialogueEntry(link.destinationDialogueID), link, level + 1, visited));
                    }
                }
            }
            return node;
        }
Ejemplo n.º 15
0
        private void DrawDialogueNode(
            DialogueNode node,
            Link originLink,
            ref Link linkToDelete,
            ref DialogueEntry entryToLinkFrom,
            ref DialogueEntry entryToLinkTo,
            ref bool linkToAnotherConversation)
        {
            if (node == null)
            {
                return;
            }

            // Setup:
            bool deleted = false;

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label(string.Empty, GUILayout.Width(node.indent));
            if (node.isEditable)
            {
                // Draw foldout if applicable:
                if (node.hasFoldout && node.entry != null)
                {
                    Rect rect = EditorGUILayout.GetControlRect(false, GUILayout.Width(FoldoutRectWidth));
                    dialogueEntryFoldouts[node.entry.id] = EditorGUI.Foldout(rect, dialogueEntryFoldouts[node.entry.id], string.Empty);
                }

                // Draw label/button to edit:
                if (GUILayout.Button(GetDialogueEntryText(node.entry), node.guiStyle))
                {
                    GUIUtility.keyboardControl = 0;
                    currentEntry = (currentEntry != node.entry) ? node.entry : null;
                    ResetLuaWizards();
                    ResetDialogueTreeCurrentEntryParticipants();
                }

                // Draw delete-node button:
                GUI.enabled = (originLink != null);
                deleted     = GUILayout.Button(new GUIContent(" ", "Delete entry."), "OL Minus", GUILayout.Width(16));
                if (deleted)
                {
                    linkToDelete = originLink;
                }
                GUI.enabled = true;
            }
            else
            {
                // Draw uneditable node:
                EditorGUILayout.LabelField(GetDialogueEntryText(node.entry), node.guiStyle);
                GUI.enabled = false;
                GUILayout.Button(" ", "OL Minus", GUILayout.Width(16));
                GUI.enabled = true;
            }
            EditorGUILayout.EndHorizontal();

            // Draw contents if this is the currently-selected entry:
            if (!deleted && (node.entry == currentEntry) && node.isEditable)
            {
                DrawDialogueEntryContents(currentEntry, ref linkToDelete, ref entryToLinkFrom, ref entryToLinkTo, ref linkToAnotherConversation);
            }

            // Draw children:
            if (!deleted && node.hasFoldout && (node.entry != null) && dialogueEntryFoldouts[node.entry.id])
            {
                foreach (var child in node.children)
                {
                    if (child != null)
                    {
                        DrawDialogueNode(child, child.originLink, ref linkToDelete, ref entryToLinkFrom, ref entryToLinkTo, ref linkToAnotherConversation);
                    }
                }
            }
        }
Ejemplo n.º 16
0
        private bool LinkExists(DialogueEntry origin, DialogueEntry destination)
        {
            Link link = origin.outgoingLinks.Find(x => x.destinationDialogueID == destination.id);

            return(link != null);
        }
Ejemplo n.º 17
0
 private void ConvertLocalizableText(DialogueEntry entry, string baseFieldTitle, ArticyData.LocalizableText localizableText)
 {
     foreach (KeyValuePair<string, string> kvp in localizableText.localizedString) {
         if (string.IsNullOrEmpty(kvp.Key)) {
             Field.SetValue(entry.fields, baseFieldTitle, RemoveFormattingTags(kvp.Value), FieldType.Text);
         } else {
             string localizedTitle = string.Format("{0} {1}", baseFieldTitle, kvp.Key);
             Field.SetValue(entry.fields, localizedTitle, RemoveFormattingTags(kvp.Value), FieldType.Localization);
         }
     }
 }
 private void DrawOrphans(ref DialogueEntry entryToDelete)
 {
     EditorWindowTools.StartIndentedSection();
     entryToDelete = null;
     foreach (var node in orphans) {
         EditorGUILayout.BeginHorizontal();
         EditorGUILayout.LabelField(GetDialogueEntryText(node.entry), node.guiStyle);
         bool deleted = GUILayout.Button(new GUIContent(" ", "Delete entry."), "OL Minus", GUILayout.Width(16));
         if (deleted) entryToDelete = node.entry;
         EditorGUILayout.EndHorizontal();
     }
     EditorWindowTools.EndIndentedSection();
 }
 private GUIStyle GetDialogueEntryLeafStyle(DialogueEntry entry)
 {
     return ((entry != null) && database.IsPlayerID(entry.ActorID)) ? pcLineLeafGUIStyle : npcLineLeafGUIStyle;
 }
        private void DrawDialogueNode(
			DialogueNode node,
			Link originLink, 
			ref Link linkToDelete, 
			ref DialogueEntry entryToLinkFrom, 
			ref DialogueEntry entryToLinkTo,
			ref bool linkToAnotherConversation)
        {
            if (node == null) return;

            // Setup:
            bool deleted = false;

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label(string.Empty, GUILayout.Width(node.indent));
            if (node.isEditable) {

                // Draw foldout if applicable:
                if (node.hasFoldout && node.entry != null) {
                    Rect rect = EditorGUILayout.GetControlRect(false, GUILayout.Width(FoldoutRectWidth));
                    dialogueEntryFoldouts[node.entry.id] = EditorGUI.Foldout(rect, dialogueEntryFoldouts[node.entry.id], string.Empty);
                }

                // Draw label/button to edit:
                if (GUILayout.Button(GetDialogueEntryText(node.entry), node.guiStyle)) {
                    GUIUtility.keyboardControl = 0;
                    currentEntry = (currentEntry != node.entry) ? node.entry : null;
                    ResetLuaWizards();
                    ResetDialogueTreeCurrentEntryParticipants();
                }

                // Draw delete-node button:
                GUI.enabled = (originLink != null);
                deleted = GUILayout.Button(new GUIContent(" ", "Delete entry."), "OL Minus", GUILayout.Width(16));
                if (deleted) linkToDelete = originLink;
                GUI.enabled = true;
            } else {

                // Draw uneditable node:
                EditorGUILayout.LabelField(GetDialogueEntryText(node.entry), node.guiStyle);
                GUI.enabled = false;
                GUILayout.Button(" ", "OL Minus", GUILayout.Width(16));
                GUI.enabled = true;
            }
            EditorGUILayout.EndHorizontal();

            // Draw contents if this is the currently-selected entry:
            if (!deleted && (node.entry == currentEntry) && node.isEditable) {
                DrawDialogueEntryContents(currentEntry, ref linkToDelete, ref entryToLinkFrom, ref entryToLinkTo, ref linkToAnotherConversation);
            }

            // Draw children:
            if (!deleted && node.hasFoldout && (node.entry != null) && dialogueEntryFoldouts[node.entry.id]) {
                foreach (var child in node.children) {
                    if (child != null) {
                        DrawDialogueNode(child, child.originLink, ref linkToDelete, ref entryToLinkFrom, ref entryToLinkTo, ref linkToAnotherConversation);
                    }
                }
            }
        }
        private void DrawDialogueEntryParticipants(DialogueEntry entry)
        {
            // Make sure we have references to the actor and conversant fields:
            VerifyParticipantField(entry, "Actor", ref currentEntryActor);
            VerifyParticipantField(entry, "Conversant", ref currentEntryConversant);

            // If actor and conversant are unassigned, use conversation's values:
            if (IsActorIDUnassigned(currentEntryActor)) currentEntryActor.value = currentConversation.ActorID.ToString();
            if (IsActorIDUnassigned(currentEntryConversant)) currentEntryConversant.value = currentConversation.ConversantID.ToString();;

            // Participant IDs:
            DrawParticipantField(currentEntryActor, "Speaker of this entry.");
            DrawParticipantField(currentEntryConversant, "Listener.");
        }
        private bool DrawDialogueEntryLinks(
			DialogueEntry entry,
			ref Link linkToDelete, 
			ref DialogueEntry entryToLinkFrom, 
			ref DialogueEntry entryToLinkTo,
			ref bool linkToAnotherConversation)
        {
            if (currentConversation == null) return false;

            EditorGUI.BeginChangeCheck();

            List<GUIContent> destinationList = new List<GUIContent>();
            destinationList.Add(new GUIContent("(Link To)", string.Empty));
            foreach (DialogueEntry destinationEntry in currentConversation.dialogueEntries) {
                if (destinationEntry != entry) destinationList.Add(new GUIContent(string.Format("[{0}] {1}", destinationEntry.id, GetDialogueEntryText(destinationEntry)), string.Empty));
            }
            destinationList.Add(new GUIContent("(Another Conversation)", string.Empty));
            destinationList.Add(new GUIContent("(New Entry)", string.Empty));
            int destinationIndex = EditorGUILayout.Popup(new GUIContent("Links To:", "Add a link to another entry. Select (New Entry) to create and link to a new entry."), 0, destinationList.ToArray());
            if (destinationIndex > 0) {
                entryToLinkFrom = entry;
                if (destinationIndex == destinationList.Count - 1) { // (New Entry)
                    entryToLinkTo = null;
                    linkToAnotherConversation = false;
                } else if (destinationIndex == destinationList.Count - 2) { // (Another Conversation)
                    entryToLinkTo = null;
                    linkToAnotherConversation = true;
                } else {
                    int destinationID = AssetListIndexToID(destinationIndex, destinationList.ToArray());
                    entryToLinkTo = currentConversation.dialogueEntries.Find(e => e.id == destinationID);
                    if (entryToLinkTo == null) {
                        entryToLinkFrom = null;
                        Debug.LogError(string.Format("{0}: Couldn't find destination dialogue entry in database.", DialogueDebug.Prefix));
                    }
                }
                EditorGUILayout.EndHorizontal();
                return false;
            }
            int linkIndexToMoveUp = -1;
            int linkIndexToMoveDown = -1;
            if ((entry != null) && (entry.outgoingLinks != null)) {
                for (int linkIndex = 0; linkIndex < entry.outgoingLinks.Count; linkIndex++) {
                    Link link = entry.outgoingLinks[linkIndex];
                    EditorGUILayout.BeginHorizontal();

                    if (link.destinationConversationID == currentConversation.id) {

                        // Is a link to an entry in the current conversation, so handle normally:
                        DialogueEntry linkEntry = database.GetDialogueEntry(link);
                        if (linkEntry != null) {
                            string linkText = (linkEntry == null) ? string.Empty
                                : (linkEntry.isGroup ? GetDialogueEntryText(linkEntry) : linkEntry.ResponseButtonText);
                            GUIStyle linkButtonStyle = GetLinkButtonStyle(linkEntry);
                            if (GUILayout.Button(linkText, linkButtonStyle)) {
                                currentEntry = database.GetDialogueEntry(link);
                                EditorGUILayout.EndHorizontal();
                                return false;
                            }
                        }
                    } else {

                        // Cross-conversation link:
                        link.destinationConversationID = DrawConversationsPopup(link.destinationConversationID);
                        link.destinationDialogueID = DrawCrossConversationEntriesPopup(link.destinationConversationID, link.destinationDialogueID);
                    }

                    EditorGUI.BeginDisabledGroup(linkIndex == 0);
                    if (GUILayout.Button(new GUIContent("↑", "Move up"), EditorStyles.miniButton, GUILayout.Width(22))) linkIndexToMoveUp = linkIndex;
                    EditorGUI.EndDisabledGroup();
                    EditorGUI.BeginDisabledGroup(linkIndex == entry.outgoingLinks.Count - 1);
                    if (GUILayout.Button(new GUIContent("↓", "Move down"), EditorStyles.miniButton, GUILayout.Width(22))) linkIndexToMoveDown = linkIndex;
                    EditorGUI.EndDisabledGroup();
                    link.priority = (ConditionPriority) EditorGUILayout.Popup((int) link.priority, priorityStrings, GUILayout.Width(100));
                    bool deleted = GUILayout.Button(new GUIContent(" ", "Delete link."), "OL Minus", GUILayout.Width(16));
                    if (deleted) linkToDelete = link;
                    EditorGUILayout.EndHorizontal();
                }
            }

            if (linkIndexToMoveUp != -1) MoveLink(entry, linkIndexToMoveUp, -1);
            if (linkIndexToMoveDown != -1) MoveLink(entry, linkIndexToMoveDown, 1);

            bool changed = EditorGUI.EndChangeCheck();
            if (changed) SetDatabaseDirty();
            return changed;
        }
        private void DrawDialogueEntryContents(
			DialogueEntry entry,
			ref Link linkToDelete, 
			ref DialogueEntry entryToLinkFrom, 
			ref DialogueEntry entryToLinkTo,
			ref bool linkToAnotherConversation)
        {
            EditorGUILayout.BeginVertical("button");

            bool changed = DrawDialogueEntryFieldContents();

            // Links:
            changed = DrawDialogueEntryLinks(entry, ref linkToDelete, ref entryToLinkFrom, ref entryToLinkTo, ref linkToAnotherConversation) || changed;

            EditorGUILayout.EndVertical();

            if (changed) {
                ResetDialogueEntryText(entry);
                SetDatabaseDirty();
            }
        }
 private void CreateLink(DialogueEntry source, DialogueEntry destination)
 {
     if ((source != null) && (destination != null)) {
         Link link = new Link();
         link.originConversationID = currentConversation.id;
         link.originDialogueID = source.id;
         link.destinationConversationID = currentConversation.id;
         link.destinationDialogueID = destination.id;
         source.outgoingLinks.Add(link);
     }
 }
Ejemplo n.º 25
0
    public override void CopyValues(ScrObjLibraryEntry other)
    {
        base.CopyValues(other);
        MapEntry map = (MapEntry)other;

        sizeX     = map.sizeX;
        sizeY     = map.sizeY;
        mapSprite = map.mapSprite;

        mapDescription = map.mapDescription;

        winCondition  = map.winCondition;
        loseCondition = map.loseCondition;
        turnLimit     = map.turnLimit;

        skipBattlePrep = map.skipBattlePrep;
        preDialogue    = map.preDialogue;
        introDialogue  = map.introDialogue;
        endDialogue    = map.endDialogue;

        mapMusic = map.mapMusic;

        spawnPoints1 = new List <Position>();
        for (int i = 0; i < map.spawnPoints1.Count; i++)
        {
            spawnPoints1.Add(map.spawnPoints1[i]);
        }
        spawnPoints2 = new List <Position>();
        for (int i = 0; i < map.spawnPoints2.Count; i++)
        {
            spawnPoints2.Add(map.spawnPoints2[i]);
        }
        forcedCharacters = new List <CharEntry>();
        for (int i = 0; i < map.forcedCharacters.Count; i++)
        {
            forcedCharacters.Add(map.forcedCharacters[i]);
        }
        lockedCharacters = new List <CharEntry>();
        for (int i = 0; i < map.lockedCharacters.Count; i++)
        {
            lockedCharacters.Add(map.lockedCharacters[i]);
        }

        enemies = new List <SpawnData>();
        for (int i = 0; i < map.enemies.Count; i++)
        {
            enemies.Add(map.enemies[i]);
        }
        allies = new List <SpawnData>();
        for (int i = 0; i < map.allies.Count; i++)
        {
            allies.Add(map.allies[i]);
        }
        reinforcements = new List <SpawnData>();
        for (int i = 0; i < map.reinforcements.Count; i++)
        {
            reinforcements.Add(map.reinforcements[i]);
        }

        interactions = new List <InteractPosition>();
        for (int i = 0; i < map.interactions.Count; i++)
        {
            interactions.Add(map.interactions[i]);
        }

        triggerIds = new List <TriggerTuple>();
        for (int i = 0; i < map.triggerIds.Count; i++)
        {
            triggerIds.Add(map.triggerIds[i]);
        }
        triggerAreas = new List <TriggerArea>();
        for (int i = 0; i < map.triggerAreas.Count; i++)
        {
            triggerAreas.Add(map.triggerAreas[i]);
        }
        turnEvents = new List <TurnEvent>();
        for (int i = 0; i < map.turnEvents.Count; i++)
        {
            turnEvents.Add(map.turnEvents[i]);
        }
    }
 private string BuildDialogueEntryNodeText(DialogueEntry entry)
 {
     string text = entry.MenuText;
     if (string.IsNullOrEmpty(text)) text = entry.DialogueText;
     if (string.IsNullOrEmpty(text)) text = entry.Title;
     if (entry.isGroup) text = "{group} " + text;
     if (text.Contains("\n")) text = text.Replace("\n", string.Empty);
     int extraLength = 0;
     if (showActorNames) {
         string actorName = GetActorNameByID(entry.ActorID);
         if (actorName != null) extraLength = actorName.Length;
         text = string.Format("{0}:\n{1}", actorName, text);
     } else if (entry.ActorID != currentConversation.ActorID && (entry.ActorID != currentConversation.ConversantID)) {
         text = string.Format("{0}: {1}", GetActorNameByID(entry.ActorID), text);
     }
     if (!string.IsNullOrEmpty(entry.conditionsString)) text += " [condition]";
     if (!string.IsNullOrEmpty(entry.userScript)) text += " {script}";
     if ((entry.outgoingLinks == null) || (entry.outgoingLinks.Count == 0)) text += " [END]";
     return text.Substring(0, Mathf.Min(text.Length, MaxNodeTextLength + extraLength));
 }
 private GUIStyle GetLinkButtonStyle(DialogueEntry entry)
 {
     return ((entry != null) && database.IsPlayerID(entry.ActorID)) ? pcLinkButtonGUIStyle : npcLinkButtonGUIStyle;
 }
 private string BuildDialogueEntryText(DialogueEntry entry)
 {
     string text = entry.MenuText;
     if (string.IsNullOrEmpty(text)) text = entry.DialogueText;
     if (string.IsNullOrEmpty(text)) text = entry.Title;
     if (entry.isGroup) text = "{group} " + text;
     if (text.Contains("\n")) text = text.Replace("\n", string.Empty);
     string speaker = GetActorNameByID(entry.ActorID);
     text = string.Format("[{0}] {1}: {2}", entry.id, speaker, text);
     if (!string.IsNullOrEmpty(entry.conditionsString)) text += " [condition]";
     if (!string.IsNullOrEmpty(entry.userScript)) text += " {script}";
     if ((entry.outgoingLinks == null) || (entry.outgoingLinks.Count == 0)) text += " [END]";
     return text;
 }
Ejemplo n.º 29
0
    public void GenerateDamageActions()
    {
        TacticsMove attacker = attackerTile.value.currentCharacter;
        TacticsMove defender = defenderTile.value.currentCharacter;

        dialogue = null;
        if (defender == null)
        {
            showBattleAnim    = false;
            _currentCharacter = attacker;
            actions.Clear();
            actions.Add(new BattleAction(AttackSide.LEFT, BattleAction.Type.DAMAGE, attacker, defenderTile.value.blockMove));
            Debug.Log("BLOCK FIGHT!!");
        }
        else
        {
            showBattleAnim = useBattleAnimations.value;
            // Add battle init boosts
            attacker.ActivateSkills(SkillActivation.INITCOMBAT, defender);
            attacker.ActivateSkills(SkillActivation.PRECOMBAT, defender);
            defender.ActivateSkills(SkillActivation.COUNTER, attacker);
            defender.ActivateSkills(SkillActivation.PRECOMBAT, attacker);

            _currentCharacter = attacker;
            InventoryTuple atkTup = attacker.GetEquippedWeapon(ItemCategory.WEAPON);
            InventoryTuple defTup = defender.GetEquippedWeapon(ItemCategory.WEAPON);
            actions.Clear();
            actions.Add(new BattleAction(AttackSide.LEFT, BattleAction.Type.DAMAGE, attacker, defender));
            int range = Mathf.Abs(attacker.posx - defender.posx) + Mathf.Abs(attacker.posy - defender.posy);
            if (!string.IsNullOrEmpty(defTup.uuid) && defTup.currentCharges > 0 && defender.GetEquippedWeapon(ItemCategory.WEAPON).InRange(range))
            {
                actions.Add(new BattleAction(AttackSide.RIGHT, BattleAction.Type.DAMAGE, defender, attacker));
            }
            //Compare speeds
            int spdDiff = actions[0].GetSpeedDifference();
            if (spdDiff >= doublingSpeed.value)
            {
                if (atkTup.currentCharges > 1)
                {
                    actions.Add(new BattleAction(AttackSide.LEFT, BattleAction.Type.DAMAGE, attacker, defender));
                }
            }
            else if (spdDiff <= -doublingSpeed.value)
            {
                if (!string.IsNullOrEmpty(defTup.uuid) && defTup.currentCharges > 0 && defender.GetEquippedWeapon(ItemCategory.WEAPON).InRange(range))
                {
                    actions.Add(new BattleAction(AttackSide.RIGHT, BattleAction.Type.DAMAGE, defender, attacker));
                }
            }

            TacticsMove quoter    = (attacker.faction == Faction.ENEMY) ? attacker : defender;
            CharEntry   triggerer = (attacker.faction == Faction.ENEMY) ? defender.stats.charData : attacker.stats.charData;
            FightQuote  bestFind  = null;
            for (int q = 0; q < quoter.fightQuotes.Count; q++)
            {
                if (quoter.fightQuotes[q].triggerer == null)
                {
                    if (bestFind == null)
                    {
                        bestFind = quoter.fightQuotes[q];
                    }
                }
                else if (quoter.fightQuotes[q].triggerer == triggerer)
                {
                    bestFind = quoter.fightQuotes[q];
                    break;
                }
            }
            if (bestFind != null && !bestFind.activated)
            {
                dialogue           = bestFind.quote;
                bestFind.activated = true;
            }
        }
    }
 private void LinkToAnotherConversation(DialogueEntry source)
 {
     Link link = new Link();
     link.originConversationID = currentConversation.id;
     link.originDialogueID = source.id;
     link.destinationConversationID = -1;
     link.destinationDialogueID = -1;
     source.outgoingLinks.Add(link);
 }
Ejemplo n.º 31
0
 private GUIStyle GetLinkButtonStyle(DialogueEntry entry)
 {
     return(((entry != null) && database.IsPlayerID(entry.ActorID)) ? pcLinkButtonGUIStyle : npcLinkButtonGUIStyle);
 }
 private void LinkToNewEntry(DialogueEntry source)
 {
     if (source != null) {
         DialogueEntry newEntry = CreateNewDialogueEntry("New Dialogue Entry");
         newEntry.ActorID = source.ConversantID;
         newEntry.ConversantID = (source.ActorID == source.ConversantID) ? database.playerID : source.ActorID;
         Link link = new Link();
         link.originConversationID = currentConversation.id;
         link.originDialogueID = source.id;
         link.destinationConversationID = currentConversation.id;
         link.destinationDialogueID = newEntry.id;
         source.outgoingLinks.Add(link);
         currentEntry = newEntry;
     }
 }
Ejemplo n.º 33
0
        public bool DrawDialogueEntryFieldContents()
        {
            if (currentEntry == null)
            {
                return(false);
            }

            EditorGUI.BeginChangeCheck();

            DialogueEntry entry = currentEntry;

            EditorGUI.BeginDisabledGroup(entry == startEntry || entry.id == 0);
            entry.id = StringToInt(EditorGUILayout.TextField(new GUIContent("ID", "Internal ID. Change at your own risk."), entry.id.ToString()), entry.id);

            // Title:
            entry.Title = EditorGUILayout.TextField(new GUIContent("Title", "Optional title for your reference only."), entry.Title);
            EditorGUI.EndDisabledGroup();

            DrawDialogueEntryParticipants(entry);

            // Is this a group or regular entry:
            entry.isGroup = EditorGUILayout.Toggle(new GUIContent("Group", "Tick to organize children as a group."), entry.isGroup);

            if (!entry.isGroup)
            {
                // Menu text (including localized if defined in template):
                EditorGUILayout.LabelField(new GUIContent("Menu Text", "Response menu text (e.g., short paraphrase). If blank, uses Dialogue Text"));
                entry.DefaultMenuText = EditorGUILayout.TextArea(entry.DefaultMenuText);
                DrawLocalizedVersions(entry.fields, "Menu Text {0}", false, FieldType.Text);

                // Dialogue text (including localized):
                EditorGUILayout.LabelField(new GUIContent("Dialogue Text", "Line spoken by actor. If blank, uses Menu Text."));
                entry.DefaultDialogueText = EditorGUILayout.TextArea(entry.DefaultDialogueText);
                DrawLocalizedVersions(entry.fields, "{0}", true, FieldType.Localization);

                // Sequence (including localized if defined):
                EditorGUILayout.LabelField(new GUIContent("Sequence", "Cutscene played when speaking this entry. If set, overrides Dialogue Manager's Default Sequence"));
                entry.DefaultSequence = EditorGUILayout.TextArea(entry.DefaultSequence);
                DrawLocalizedVersions(entry.fields, "Sequence {0}", false, FieldType.Text);

                // Response Menu Sequence:
                bool hasResponseMenuSequence = entry.HasResponseMenuSequence();
                if (hasResponseMenuSequence)
                {
                    EditorGUILayout.LabelField(new GUIContent("Response Menu Sequence", "Cutscene played during response menu following this entry."));
                    entry.DefaultResponseMenuSequence = EditorGUILayout.TextArea(entry.DefaultResponseMenuSequence);
                    DrawLocalizedVersions(entry.fields, "Response Menu Sequence {0}", false, FieldType.Text);
                }
                else
                {
                    hasResponseMenuSequence = EditorGUILayout.ToggleLeft(new GUIContent("Add Response Menu Sequence", "Tick to add a cutscene that plays during the response menu that follows this entry."), false);
                    if (hasResponseMenuSequence)
                    {
                        entry.DefaultResponseMenuSequence = string.Empty;
                    }
                }
            }

            // Conditions and Script:
            int falseConditionIndex = EditorGUILayout.Popup("False Condition Action", GetFalseConditionIndex(entry.falseConditionAction), falseConditionActionStrings);

            entry.falseConditionAction = falseConditionActionStrings[falseConditionIndex];

            // Conditions:
            luaConditionWizard.database = database;
            entry.conditionsString      = luaConditionWizard.Draw(new GUIContent("Conditions", "Optional Lua statement that must be true to use this entry."), entry.conditionsString);

            //--- Was: (prior to putting LuaConditionWizard in a separate class)
            //EditorGUILayout.BeginHorizontal();
            //EditorGUILayout.LabelField(new GUIContent("Conditions", "Optional Lua statement that must be true to use this entry."));
            //if (GUILayout.Button(new GUIContent("...", "Open Conditions wizard."), EditorStyles.miniButton, GUILayout.Width(22))) {
            //	ToggleConditionsWizard(entry);
            //}
            //EditorGUILayout.EndHorizontal();
            //if (IsConditionsWizardOpen(entry)) DrawConditionsWizard();
            //entry.conditionsString = EditorGUILayout.TextArea(entry.conditionsString);

            // Script:
            luaScriptWizard.database = database;
            entry.userScript         = luaScriptWizard.Draw(new GUIContent("Script", "Optional Lua code to run when entry is spoken."), entry.userScript);

            //--- Was: (prior to putting LuaScriptWizard in a separate class)
            //EditorGUILayout.BeginHorizontal();
            //EditorGUILayout.LabelField(new GUIContent("Script", "Optional Lua code to run when entry is spoken."));
            //if (GUILayout.Button(new GUIContent("...", "Open Script wizard."), EditorStyles.miniButton, GUILayout.Width(22))) {
            //	ToggleScriptWizard(entry);
            //}
            //EditorGUILayout.EndHorizontal();
            //if (IsScriptWizardOpen(entry)) DrawScriptWizard();
            //entry.userScript = EditorGUILayout.TextArea(entry.userScript);*/

            // Notes:
            Field notes = Field.Lookup(entry.fields, "Notes");

            if (notes != null)
            {
                EditorGUILayout.LabelField("Notes");
                notes.value = EditorGUILayout.TextArea(notes.value);
            }

            // All Fields foldout:
            EditorGUILayout.BeginHorizontal();
            entryFieldsFoldout = EditorGUILayout.Foldout(entryFieldsFoldout, "All Fields");
            if (entryFieldsFoldout)
            {
                GUILayout.FlexibleSpace();
                if (GUILayout.Button(new GUIContent("Template", "Add any missing fields from the template."), EditorStyles.miniButton, GUILayout.Width(60)))
                {
                    ApplyDialogueEntryTemplate(entry.fields);
                }
                if (GUILayout.Button(new GUIContent("Copy", "Copy these fields to the clipboard."), EditorStyles.miniButton, GUILayout.Width(60)))
                {
                    CopyFields(entry.fields);
                }
                EditorGUI.BeginDisabledGroup(clipboardFields == null);
                if (GUILayout.Button(new GUIContent("Paste", "Paste the clipboard into these fields."), EditorStyles.miniButton, GUILayout.Width(60)))
                {
                    PasteFields(entry.fields);
                }
                EditorGUI.EndDisabledGroup();
            }
            EditorGUILayout.EndHorizontal();
            if (entryFieldsFoldout)
            {
                DrawFieldsSection(entry.fields);
            }

            bool changed = EditorGUI.EndChangeCheck();

            if (changed)
            {
                SetDatabaseDirty();
            }
            return(changed);
        }
 private void MoveLink(DialogueEntry entry, int linkIndex, int direction)
 {
     if ((entry != null) && (0 <= linkIndex && linkIndex < entry.outgoingLinks.Count)) {
         int newIndex = Mathf.Clamp(linkIndex + direction, 0, entry.outgoingLinks.Count - 1);
         Link link = entry.outgoingLinks[linkIndex];
         entry.outgoingLinks.RemoveAt(linkIndex);
         entry.outgoingLinks.Insert(newIndex, link);
     }
 }
Ejemplo n.º 35
0
        private void ImportLocalizationFiles()
        {
            try
            {
                conversationIDCache.Clear();
                lastCachedConversation = null;
                var numLanguages = localizationLanguages.languages.Count;
                for (int i = 0; i < numLanguages; i++)
                {
                    var progress           = (float)i / (float)numLanguages;
                    var language           = localizationLanguages.languages[i];
                    var alsoImportMainText = localizationLanguages.importMainTextIndex == i;
                    if (EditorUtility.DisplayCancelableProgressBar("Importing Localization CSV", "Importing CSV files for " + language, progress))
                    {
                        return;
                    }

                    // Read dialogue CSV file:
                    var filename = localizationLanguages.outputFolder + "/Dialogue_" + language + ".csv";
                    var lines    = ReadCSV(filename);
                    CombineMultilineCSVSourceLines(lines);
                    for (int j = 2; j < lines.Count; j++)
                    {
                        var columns = GetCSVColumnsFromLine(lines[j]);
                        if (columns.Count < 7)
                        {
                            Debug.LogError(filename + ":" + (j + 1) + " Invalid line: " + lines[j]);
                        }
                        else
                        {
                            // Peel key field value off front if exporting key fields:
                            string keyFieldValue = null;
                            if (exportLocalizationKeyField)
                            {
                                keyFieldValue = columns[0];
                                columns.RemoveAt(0);
                            }

                            // Get conversation ID:
                            int conversationID = 0;
                            if (exportLocalizationConversationTitle)
                            {
                                var conversationTitle = columns[0];
                                if (!conversationIDCache.ContainsKey(conversationTitle))
                                {
                                    var conversation = database.GetConversation(columns[0]);
                                    if (conversation == null)
                                    {
                                        Debug.LogError(filename + ":" + (j + 1) + " Database doesn't contain conversation '" + columns[0] + "'.");
                                        continue;
                                    }
                                    conversationIDCache[conversationTitle] = conversation.id;
                                }
                                conversationID = conversationIDCache[conversationTitle];
                            }
                            else
                            {
                                conversationID = Tools.StringToInt(columns[0]);
                            }

                            var entryID = Tools.StringToInt(columns[1]);
                            //columns[2] is Actor. Ignore it.
                            DialogueEntry entry = null;
                            if (exportLocalizationKeyField)
                            {
                                // Find entry by key field:
                                if (lastCachedConversation == null || lastCachedConversation.id != conversationID)
                                {
                                    lastCachedConversation = database.GetConversation(conversationID);
                                }
                                entry = lastCachedConversation.dialogueEntries.Find(x => Field.LookupValue(x.fields, localizationKeyField) == keyFieldValue);
                            }
                            else
                            {
                                // Find entry by ID:
                                entry = database.GetDialogueEntry(conversationID, entryID);
                                if (entry == null)
                                {
                                    Debug.LogError(filename + ":" + (j + 1) + " Database doesn't contain conversation " + conversationID + " dialogue entry " + entryID);
                                }
                            }

                            // If we found the entry, update its fields:
                            if (entry != null)
                            {
                                Field.SetValue(entry.fields, language, columns[4], FieldType.Localization);
                                Field.SetValue(entry.fields, "Menu Text " + language, columns[6], FieldType.Localization);

                                // Check if we also need to import updated main text.
                                if (alsoImportMainText)
                                {
                                    entry.DialogueText = columns[3];
                                    entry.MenuText     = columns[5];
                                }
                            }
                        }
                    }

                    // Read quests CSV file:
                    filename = localizationLanguages.outputFolder + "/Quests_" + language + ".csv";
                    if (File.Exists(filename))
                    {
                        lines = ReadCSV(filename);
                        CombineMultilineCSVSourceLines(lines);
                        for (int j = 2; j < lines.Count; j++)
                        {
                            var columns = GetCSVColumnsFromLine(lines[j]);
                            if (columns.Count < 11)
                            {
                                Debug.LogError(filename + ":" + (j + 1) + " Invalid line: " + lines[j]);
                            }
                            else
                            {
                                var quest = database.GetItem(columns[0]);
                                if (quest == null)
                                {
                                    // Skip if quest is not present.
                                }
                                else
                                {
                                    var displayName           = columns[1];
                                    var translatedDisplayName = columns[2];
                                    if (!string.IsNullOrEmpty(translatedDisplayName))
                                    {
                                        if (!quest.FieldExists("Display Name"))
                                        {
                                            Field.SetValue(quest.fields, "Display Name", displayName);
                                        }
                                        Field.SetValue(quest.fields, "Display Name " + language, translatedDisplayName, FieldType.Localization);
                                    }
                                    var group           = columns[3];
                                    var translatedGroup = columns[4];
                                    var needToAddGroup  = !quest.FieldExists("Group") && (!string.IsNullOrEmpty(group) || !string.IsNullOrEmpty(translatedGroup));
                                    if (quest.FieldExists("Group") && string.IsNullOrEmpty(quest.LookupValue("Group")) && !string.IsNullOrEmpty(group))
                                    {
                                        needToAddGroup = true;
                                    }
                                    if (needToAddGroup)
                                    {
                                        Field.SetValue(quest.fields, "Group", group);
                                    }
                                    if (quest.FieldExists("Group"))
                                    {
                                        Field.SetValue(quest.fields, "Group " + language, translatedGroup, FieldType.Localization);
                                    }
                                    Field.SetValue(quest.fields, "Description " + language, columns[6], FieldType.Localization);
                                    Field.SetValue(quest.fields, "Success Description " + language, columns[8], FieldType.Localization);
                                    Field.SetValue(quest.fields, "Failure Description " + language, columns[10], FieldType.Localization);
                                    var entryCount = quest.LookupInt("Entry Count");
                                    for (int k = 0; k < entryCount; k++)
                                    {
                                        Field.SetValue(quest.fields, "Entry " + (k + 1) + " " + language, columns[12 + 2 * k], FieldType.Localization);
                                    }
                                    if (alsoImportMainText)
                                    {
                                        if (quest.FieldExists("Display Name"))
                                        {
                                            Field.SetValue(quest.fields, "Display Name", displayName);
                                        }
                                        if (quest.FieldExists("Group"))
                                        {
                                            Field.SetValue(quest.fields, "Group", group, FieldType.Text);
                                        }
                                        Field.SetValue(quest.fields, "Description", columns[5], FieldType.Text);
                                        Field.SetValue(quest.fields, "Success Description", columns[7], FieldType.Text);
                                        Field.SetValue(quest.fields, "Failure Description", columns[9], FieldType.Text);
                                        for (int k = 0; k < entryCount; k++)
                                        {
                                            Field.SetValue(quest.fields, "Entry " + (k + 1), columns[11 + 2 * k], FieldType.Text);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            finally
            {
                EditorUtility.ClearProgressBar();
            }
            EditorUtility.DisplayDialog("Imported Localization CSV", "The CSV files have been imported back into your dialogue database.", "OK");
        }
 private void ResetCurrentEntry()
 {
     currentEntry = null;
     ResetConditionsWizard();
     ResetScriptWizard();
     ResetDialogueTreeCurrentEntryParticipants();
 }
 private void OpenConversation(Conversation conversation)
 {
     ResetConversationSection();
     SetCurrentConversation(conversation); //currentConversation = conversation;
     startEntry = GetOrCreateFirstDialogueEntry();
     if (showNodeEditor) CheckNodeArrangement();
 }
 private void ResetDialogueTreeSection()
 {
     dialogueTreeFoldout = false;
     orphansFoldout = false;
     ResetDialogueEntryText();
     dialogueEntryFoldouts.Clear();
     ResetDialogueTree();
     currentEntry = null;
     ResetLuaWizards();
 }
 private void VerifyParticipantField(DialogueEntry entry, string fieldTitle, ref Field participantField)
 {
     if (participantField == null) participantField = Field.Lookup(entry.fields, fieldTitle);
     if (participantField == null) {
         participantField = new Field(fieldTitle, string.Empty, FieldType.Actor);
         entry.fields.Add(participantField);
     }
 }
 public DialogueNode(DialogueEntry entry, Link originLink, GUIStyle guiStyle, float indent, bool isEditable, bool hasFoldout)
 {
     this.entry = entry;
     this.originLink = originLink;
     this.guiStyle = guiStyle;
     this.indent = indent;
     this.isEditable = isEditable;
     this.hasFoldout = hasFoldout;
     this.children = new List<DialogueNode>();
 }
Ejemplo n.º 41
0
        private void HandleNodeEvents(DialogueEntry entry)
        {
            switch (UnityEngine.Event.current.type)
            {
            case EventType.mouseDown:
                if (entry.canvasRect.Contains(UnityEngine.Event.current.mousePosition))
                {
                    if (IsRightMouseButtonEvent())
                    {
                        currentEntry = entry;
                        ShowNodeContextMenu(entry);
                        UnityEngine.Event.current.Use();
                    }
                    else if (UnityEngine.Event.current.button == LeftMouseButton)
                    {
                        newSelectedLink = null;
                        if (isMakingLink)
                        {
                            FinishMakingLink();
                        }
                        else
                        {
                            nodeToDrag = entry;
                            dragged    = false;
                            if (!IsShiftDown() && ((multinodeSelection.nodes.Count <= 1) || !multinodeSelection.nodes.Contains(entry)))
                            {
                                SetCurrentEntry(entry);
                            }
                        }
                        UnityEngine.Event.current.Use();
                    }
                }
                break;

            case EventType.mouseUp:
                if (UnityEngine.Event.current.button == LeftMouseButton)
                {
                    if (!isMakingLink && entry.canvasRect.Contains(UnityEngine.Event.current.mousePosition))
                    {
                        newSelectedLink = null;
                        if (isLassoing)
                        {
                            FinishLasso();
                        }
                        else if (IsShiftDown())
                        {
                            if (multinodeSelection.nodes.Contains(entry))
                            {
                                RemoveEntryFromSelection(entry);
                            }
                            else
                            {
                                AddEntryToSelection(entry);
                            }
                        }
                        else
                        {
                            if (!(dragged && (multinodeSelection.nodes.Count > 1)))
                            {
                                SetCurrentEntry(entry);
                            }
                        }
                        nodeToDrag = null;
                        dragged    = false;
                        UnityEngine.Event.current.Use();
                    }
                }
                break;

            case EventType.mouseDrag:
                if ((entry == nodeToDrag))
                {
                    dragged = true;
                    //if (IsControlDown() && IsAltDown()) {
                    //	DragNodes(currentConversation.dialogueEntries);
                    //} else {
                    DragNodes(multinodeSelection.nodes);
                    //foreach (DialogueEntry dragEntry in multinodeSelection.nodes) {
                    //	dragEntry.canvasRect.x += Event.current.delta.x;
                    //	dragEntry.canvasRect.x = Mathf.Max(1f, dragEntry.canvasRect.x);
                    //	dragEntry.canvasRect.y += Event.current.delta.y;
                    //	dragEntry.canvasRect.y = Mathf.Max(1f, dragEntry.canvasRect.y);
                    //}
                    //}
                    UnityEngine.Event.current.Use();
                }
                break;
            }
            if (isMakingLink && UnityEngine.Event.current.isMouse)
            {
                if (entry.canvasRect.Contains(UnityEngine.Event.current.mousePosition))
                {
                    linkTargetEntry = entry;
                }
            }
        }
        private void CreateEntries(Conversation conversation)
        {
            visitedIDs.Clear();
            DialogueEntry currentEntry = conversation.dialogueEntries[0];

            while (currentEntry.outgoingLinks.Count > 0 || branchPoints.Count > 0)
            {
                currentEntry = GetNextEntry(currentEntry);

                if (branchPoints.Count > 0 && (IsDeadEnd(currentEntry) || IsPickUpPoint(currentEntry)))
                {
                    if (currentEntry != null && IsDeadEnd(currentEntry))
                    {
                        TokenizeEntry(currentEntry);
                    }

                    BranchPoint bp = branchPoints[branchPoints.Count - 1];

                    TokenizeBranchName(bp.branchNodes[0]);
                    bp.branchNodes.RemoveAt(0);
                    builder.AppendLine();

                    if (bp.branchNodes.Count > 0)
                    {
                        currentEntry = bp.branchNodes[0];
                        TokenizeBranchName(bp.branchNodes[0]);
                    }
                    else
                    {
                        branchPoints.Remove(bp);

                        while (branchPoints.Count > 0)
                        {
                            BranchPoint parentBranch = branchPoints[branchPoints.Count - 1];
                            TokenizeBranchName(parentBranch.branchNodes[0]);
                            parentBranch.branchNodes.RemoveAt(0);

                            if (parentBranch.branchNodes.Count > 0)
                            {
                                currentEntry = parentBranch.branchNodes[0];
                                builder.AppendLine();
                                TokenizeBranchName(parentBranch.branchNodes[0]);
                                break;
                            }
                            else
                            {
                                branchPoints.Remove(parentBranch);
                            }
                        }
                    }
                }

                if (currentEntry != null)
                {
                    if (!HasAlreadyBeenVisited(currentEntry))
                    {
                        TokenizeEntry(currentEntry);
                    }
                    else if (currentEntry.outgoingLinks.Count > 0)
                    {
                        AddRecursiveErrorWarning();
                        break;
                    }
                }
                else
                {
                    break;
                }
            }
        }
Ejemplo n.º 43
0
 private void MakeLinkCallback(object o)
 {
     linkSourceEntry = o as DialogueEntry;
     isMakingLink    = (linkSourceEntry != null);
 }
Ejemplo n.º 44
0
    public DialogueHandler dialogueHandler;     // The handler of the currently active dialogue

    public DialogueOption(DialogueHandler dialogueHandler, string displayText = "Ok", List <DialogueEvent> events = null, DialogueEntry nextDialogueEntry = null,
                          List <DialogueCondition> conditions = null, bool selectOnEnterPressed = false)
    {
        this.displayText          = displayText;
        this.events               = events;
        this.nextDialogueEntry    = nextDialogueEntry;
        this.conditions           = conditions;
        this.selectOnEnterPressed = selectOnEnterPressed;
        this.dialogueHandler      = dialogueHandler;
    }
Ejemplo n.º 45
0
    public void RefreshDialogue(string newNodeID, bool showResponse)
    {
        //if loading a new node, first create a dialogue entry for it and push into
        //the stack.



        if (newNodeID != "")
        {
            //create dialogue entry
            //Debug.Log("new node ID " + newNodeID);
            DialogueNode node = GameManager.Inst.DBManager.DBHandlerDialogue.GetDialogueNode(newNodeID);

            if (showResponse)
            {
                DialogueResponse response = EvaluateResponse(node.Responses);
                if (response != null)
                {
                    DialogueEntry entry = CreateDialogueEntry(GetSpeakerName(), ParseDialogueText(response.Text), false);

                    _entries.Push(entry);

                    //check if response has an event
                    if (response.Events != null && response.Events.Count > 0)
                    {
                        foreach (string e in response.Events)
                        {
                            if (GameManager.Inst.QuestManager.Scripts.ContainsKey(e))
                            {
                                StoryEventScript script = GameManager.Inst.QuestManager.Scripts[e];
                                script.Trigger(new object[] {});
                            }
                        }
                    }
                }
            }

            //create dialogue options relevant to this node
            foreach (Topic option in node.Options)
            {
                if (EvaluateTopicConditions(option.Conditions))
                {
                    DialogueOptionEntry optionEntry = new DialogueOptionEntry();

                    GameObject o = GameObject.Instantiate(Resources.Load("TopicEntry")) as GameObject;
                    optionEntry.Text      = o.GetComponent <UILabel>();
                    optionEntry.Text.text = option.Title;
                    TopicReference reference = o.GetComponent <TopicReference>();
                    reference.Topic = option;
                    UIButton button = o.GetComponent <UIButton>();
                    button.onClick.Add(new EventDelegate(this, "OnSelectTopic"));

                    _options.Add(optionEntry);
                }
            }
        }

        //create topics entry
        Character    target = GameManager.Inst.PlayerControl.SelectedPC.MyAI.BlackBoard.InteractTarget;
        List <Topic> topics = GameManager.Inst.DBManager.DBHandlerDialogue.GetNPCTopics(target, null);

        foreach (Topic topic in topics)
        {
            //if we are not at root node then don't show info topics
            if (topic.Type == TopicType.Info && _currentNodeID != _rootNode)
            {
                continue;
            }

            //if topic is not known to player, don't show it

            if (topic.Type == TopicType.Info && !GameManager.Inst.PlayerProgress.IsTopicDiscovered(topic.ID))
            {
                continue;
            }


            TopicEntry entry = new TopicEntry();

            GameObject o = GameObject.Instantiate(Resources.Load("TopicEntry")) as GameObject;
            entry.Text      = o.GetComponent <UILabel>();
            entry.Text.text = topic.Title;
            TopicReference reference = o.GetComponent <TopicReference>();
            reference.Topic = topic;
            UIButton button = o.GetComponent <UIButton>();
            button.onClick.Add(new EventDelegate(this, "OnSelectTopic"));
            BoxCollider2D collider = o.GetComponent <BoxCollider2D>();
            collider.size = new Vector2(collider.size.x, 27);
            entry.Type    = topic.Type;

            _topics.Add(entry);
        }

        //now make a copy of the stack, and start popping entries out of it, and arrange them under the dialog panel
        Stack <DialogueEntry> copy = new Stack <DialogueEntry>(_entries.Reverse());
        float currentY             = -260;

        _totalHeight = 0;
        int i = 0;

        while (copy.Count > 0)
        {
            DialogueEntry entry = copy.Pop();
            entry.SpeakerName.transform.parent = DialogueEntryAnchor.transform;
            entry.SpeakerName.MakePixelPerfect();
            entry.Text.transform.parent = DialogueEntryAnchor.transform;
            entry.Text.MakePixelPerfect();

            float height = Mathf.Max(entry.SpeakerName.height * 1f, entry.Text.height * 1f);


            entry.SpeakerName.transform.localPosition = new Vector3(-150, currentY + height, 0);
            entry.Text.transform.localPosition        = new Vector3(22, currentY + height, 0);



            currentY      = currentY + height + 15;
            _totalHeight += (height + 15);


            if (_totalHeight < 400)
            {
                DialogueEntryAnchor.localPosition = new Vector3(-210, 0 - _totalHeight, 0);
                _dialogueAnchorTarget             = new Vector3(-210, 175 - _totalHeight, 0);
            }
            else
            {
                DialogueEntryAnchor.localPosition = new Vector3(-210, -220, 0);
                _dialogueAnchorTarget             = new Vector3(-210, -175, 0);
            }


            i++;
        }
        //now re-add collider to fix collider size

        NGUITools.AddWidgetCollider(DialogueScroll.gameObject);

        /*
         * if(_intro != null)
         * {
         *      _intro.transform.parent = DialogueEntryAnchor.transform;
         *      _intro.MakePixelPerfect();
         *      _intro.transform.localPosition = new Vector3(-150, currentY + _intro.height, 0);
         * }
         */

        //arrange topic entries
        currentY = 200;
        TopicScroll.ResetPosition();
        foreach (TopicEntry entry in _topics)
        {
            entry.Text.transform.parent = TopicAnchor.transform;
            entry.Text.MakePixelPerfect();


            entry.Text.transform.localPosition = new Vector3(0, currentY, 0);

            currentY = currentY - entry.Text.height;



            if (entry.Text.text == "Goodbye")
            {
                currentY = currentY - 15;
            }

            if (entry.Type != TopicType.Info)
            {
                entry.Text.color = new Color(0.5f, 0.5f, 0.8f);
            }
        }

        //now re-add collider to fix collider size
        //NGUITools.AddWidgetCollider(TopicScroll.gameObject, false);

        float currentX = -128;

        foreach (DialogueOptionEntry entry in _options)
        {
            entry.Text.transform.parent = DialogueOptionScroll.transform;
            entry.Text.MakePixelPerfect();
            entry.Text.width = entry.Text.text.Length * 15;
            entry.Text.transform.localPosition = new Vector3(currentX, 78, 0);

            BoxCollider2D collider = entry.Text.GetComponent <BoxCollider2D>();
            collider.size = new Vector2(collider.size.x, 27);

            currentX = currentX + entry.Text.width + 20;
        }
    }
Ejemplo n.º 46
0
 public AddChoiceCommand(CommandExecutor cmdExec, NodeViewModel node, ImpObservableCollection <ConnectorViewModel> outgoingConnectors, DialogueEntry entry, Dialogue dialogue, string content)
 {
     _cmdExec = cmdExec;
     _cmd     = new NodeViewModel.AddChoiceUndoableCommand(_cmdExec, node, outgoingConnectors, entry, dialogue, content);
 }
Ejemplo n.º 47
0
 public DialogueHub(ScrObjLibraryVariable bkg, ScrObjLibraryVariable chars, ScrObjLibraryVariable dialogue, DialogueEntry de)
 {
     backgroundLibrary = bkg;
     characterLibrary  = chars;
     dialogueLibrary   = dialogue;
     dialogueValues    = de;
     currentState      = GameObject.FindObjectOfType <DialogueScene>();
     dvc = GameObject.FindObjectOfType <DialogueVisualContainer>();
 }
Ejemplo n.º 48
0
 public AddChoiceUndoableCommand(CommandExecutor cmdExec, NodeViewModel node, ImpObservableCollection <ConnectorViewModel> outgoingConnectors, DialogueEntry entry, Dialogue dialogue, string content)
 {
     _outgoingConnectors = outgoingConnectors;
     _dialogue           = dialogue;
     _dialogueEntry      = entry;
     _content            = content;
     _node    = node;
     _cmdExec = cmdExec;
 }
Ejemplo n.º 49
0
 /// <summary>
 /// Converts input pins as a dialogue entry's Conditions, and output pins as User Script.
 /// </summary>
 /// <param name='entry'>
 /// Entry.
 /// </param>
 /// <param name='pins'>
 /// Pins.
 /// </param>
 private void ConvertPins(DialogueEntry entry, List<ArticyData.Pin> pins)
 {
     foreach (ArticyData.Pin pin in pins) {
         switch (pin.semantic) {
         case ArticyData.SemanticType.Input:
             entry.conditionsString = AddToConditions(entry.conditionsString, ConvertExpression(pin.expression));
             break;
         case ArticyData.SemanticType.Output:
             entry.userScript = AddToUserScript(entry.userScript, ConvertExpression(pin.expression));
             break;
         default:
             Debug.LogWarning(string.Format("{0}: Unexpected semantic type {1} for pin {2}.", DialogueDebug.Prefix, pin.semantic, pin.id));
             break;
         }
     }
 }
Ejemplo n.º 50
0
 private void AddTextToDialogueEntry(List<LocalString> text, DialogueEntry dialogueEntry, EntryType entryType)
 {
     foreach (var localString in text) {
         if (localString.LanguageID == DefaultLanguageID) {
             dialogueEntry.DefaultDialogueText = ProcessText(localString.value);
         } else {
             string dialogueTextFieldName = LanguageIDToLanguageName(localString.languageId);
             string menuTextFieldName = string.Format("Menu Text {0}", dialogueTextFieldName);
             string localizedFieldName = (entryType == EntryType.Entry) ? dialogueTextFieldName : menuTextFieldName;
             Field.SetValue(dialogueEntry.fields, localizedFieldName, ProcessText(localString.value), FieldType.Localization);
             if (!string.IsNullOrEmpty(localString.value)) {
                 activeLanguages[dialogueTextFieldName] = true;
                 activeLanguages[menuTextFieldName] = true;
             }
         }
     }
 }
Ejemplo n.º 51
0
        static void ExtractConversations(DialogueDatabase database, ref DT2.TranslationDatabase output)
        {
            //extract English conversations
            foreach (var conversation in database.conversations)
            {
                //create conversation entry and assign helper title
                DT2.Conversation conversationEntry = new DT2.Conversation();
                conversationEntry.title = conversation.Title;

                //get conversation root
                DialogueEntry rootEntry = conversation.GetFirstDialogueEntry();
                ResolveLeads(rootEntry, conversation, ref conversationEntry.roots);

                //detect special conversation types
                if (Field.LookupValue(conversation.fields, "subtask_title_01") != null)
                {
                    conversationEntry.type = "journal";
                }
                else if (Field.LookupValue(conversation.fields, "orbSoundVolume") != null)
                {
                    conversationEntry.type = "orb";
                }
                else if (conversation.Title.ToLower().Contains("barks"))
                {
                    conversationEntry.type = "barks";
                }

                //obtain conversation metadata
                foreach (var field in conversation.fields)
                {
                    //skip empty entries
                    if (String.IsNullOrWhiteSpace(field.value))
                    {
                        continue;
                    }

                    //skip irrelevant fields
                    string articyId = Field.LookupValue(conversation.fields, "Articy Id");
                    string id       = EncodeConvesationId(articyId, field.title);
                    if (id == null)
                    {
                        continue;
                    }

                    //update conversation metadata
                    conversationEntry.metadata[id] = field.value;
                }

                //obtain conversation dialogue entry list
                foreach (var entry in conversation.dialogueEntries)
                {
                    //create dialogue entry
                    DT2.DialogueEntry dialogueEntry = new DT2.DialogueEntry();
                    string            entryId       = Field.LookupValue(entry.fields, "Articy Id");

                    //obtain translatable fields
                    foreach (var field in entry.fields)
                    {
                        //skip emprt or irrelevant fields
                        if (string.IsNullOrWhiteSpace(field.value))
                        {
                            continue;
                        }
                        string fieldId = EncodeDialogueId(entryId, field.title);
                        if (fieldId == null)
                        {
                            continue;
                        }

                        dialogueEntry.fields[fieldId] = field.value;
                    }

                    //skip empty entries
                    if (dialogueEntry.fields.Count == 0)
                    {
                        continue;
                    }

                    //find where the entry leads to
                    dialogueEntry.actor = database.GetActor(entry.ActorID).Name;
                    ResolveLeads(entry, conversation, ref dialogueEntry.leadsTo);
                    conversationEntry.entries[entryId] = dialogueEntry;
                }

                //add conversation to list, skip empty dialogues
                if (conversationEntry.type != "dialogue" || conversationEntry.entries.Count != 0)
                {
                    output.conversations.Add(conversationEntry);
                }
            }
        }
Ejemplo n.º 52
0
        private void AddConversationsToDatabase()
        {
            BackupDatabase();

            foreach (ParsedConversation parsedConversation in parsedConversations)
            {
                if (!parsedConversation.IsSelected)
                {
                    continue;
                }

                Conversation conversationToAdd = null;
                bool         replace           = false;

                foreach (Conversation databaseConversation in database.conversations)
                {
                    if (databaseConversation.id == parsedConversation.id)
                    {
                        conversationToAdd = databaseConversation;
                        replace           = true;
                        break;
                    }
                }

                if (replace)
                {
                    conversationToAdd.ActorID      = database.GetActor(parsedConversation.actor).id;
                    conversationToAdd.ConversantID = database.GetActor(parsedConversation.conversant).id;

                    conversationToAdd.dialogueEntries.Clear();
                    CreateStartNode(conversationToAdd);

                    conversationToAdd.Title = parsedConversation.title;

                    conversationToAdd.Description = parsedConversation.description;
                }
                else
                {
                    conversationToAdd = CreateConversation(parsedConversation.id, parsedConversation.title, parsedConversation.actor, parsedConversation.conversant, parsedConversation.description);
                }

                string actor      = database.GetActor(conversationToAdd.ActorID).Name;
                string conversant = database.GetActor(conversationToAdd.ConversantID).Name;

                string lastSpeaker = actor;

                foreach (ParsedDialogueEntry node in parsedConversation.nodes)
                {
                    if (lastSpeaker != node.actorName)
                    {
                        conversant = lastSpeaker;
                    }

                    DialogueEntry newEntry = CreateDialogueEntry(node, parsedConversation.id, database.GetActor(conversant).id);

                    lastSpeaker = node.actorName;


                    conversationToAdd.dialogueEntries.Add(newEntry);

                    foreach (Link link in parsedConversation.links)
                    {
                        if (link.originDialogueID == node.id)
                        {
                            newEntry.outgoingLinks.Insert(0, link);                            //Add(link);
                        }
                    }
                }

                //Add a link from the Start entry
                conversationToAdd.dialogueEntries[0].outgoingLinks.Add(parsedConversation.links[0]);

                if (!replace)
                {
                    database.AddConversation(conversationToAdd);
                }
            }
        }
Ejemplo n.º 53
0
    private IEnumerator ActionLoop()
    {
        state = State.ACTION;

        for (int i = 0; i < actions.Count; i++)
        {
            BattleAction act = actions[i];
            if (act.type == BattleAction.Type.DAMAGE && act.attacker.inventory.GetFirstUsableItemTuple(ItemCategory.WEAPON).currentCharges <= 0)
            {
                continue;                 //Broken weapon
            }
            if (act.type != BattleAction.Type.DAMAGE && act.attacker.inventory.GetFirstUsableItemTuple(ItemCategory.SUPPORT).currentCharges <= 0)
            {
                continue;                 //Broken staff
            }

            yield return(new WaitForSeconds(1f * currentGameSpeed.value));

            BattleAnimator.AnimationInfo animationInfo = new BattleAnimator.AnimationInfo();

            // Deal damage
            bool isCrit = false;
            if (act.type == BattleAction.Type.DAMAGE)
            {
                int damage = act.AttemptAttack(useTrueHit.value);
                if (damage != -1 && act.AttemptCrit())
                {
                    damage = (int)(damage * BattleCalc.CRIT_MODIFIER);
                    isCrit = true;
                }
                act.defender.TakeDamage(damage, isCrit);
                BattleAnimator.HitType hitType = (damage < 0) ? BattleAnimator.HitType.MISS : (isCrit) ? BattleAnimator.HitType.CRIT : BattleAnimator.HitType.NORMAL;
                animationInfo.side       = act.side;
                animationInfo.weaponType = act.weaponAtk.weaponType;
                animationInfo.hitType    = hitType;
                animationInfo.leathal    = !act.defender.IsAlive();
                animationInfo.damage     = damage;

                if (damage > 0)
                {
                    if (act.side == AttackSide.LEFT)
                    {
                        _attackerDealtDamage = true;
                    }
                    else
                    {
                        _defenderDealtDamage = true;
                    }
                }

                act.attacker.inventory.ReduceItemCharge(ItemCategory.WEAPON);
            }
            else
            {
                // Heal or buff
                if (act.staffAtk.weaponType == WeaponType.MEDKIT)
                {
                    int health = act.GetHeals();
                    act.defender.TakeHeals(health);
                    //StartCoroutine(DamageDisplay(act.leftSide, health, false, false));
                }
                else if (act.staffAtk.weaponType == WeaponType.BARRIER)
                {
                    act.defender.ReceiveBuff(act.attacker.GetEquippedWeapon(ItemCategory.SUPPORT).boost, true, true);
                }
                act.attacker.inventory.ReduceItemCharge(ItemCategory.SUPPORT);
                _attackerDealtDamage = true;
            }

            //Animate!!
            waitForAnimation = true;
            battleAnimator.PlayAttack(animationInfo);
            while (waitForAnimation)
            {
                yield return(null);
            }

            //Check Death
            // Debug.Log("Check death");
            if (!act.defender.IsAlive())
            {
                yield return(new WaitForSeconds(1f * currentGameSpeed.value));

                if (act.defender.stats.charData.deathQuote != null)
                {
                    Debug.Log("Death quote");
                    state = State.DEATH;
                    dialogueMode.value    = (int)DialogueMode.QUOTE;
                    currentDialogue.value = dialogue = act.defender.stats.charData.deathQuote;
                    showDialogueEvent.Invoke();
                    lockControls.value = false;

                    while (state == State.DEATH)
                    {
                        yield return(null);
                    }
                }
                break;
            }
        }

        //Handle exp
        yield return(StartCoroutine(ShowExpGain()));

        //Broken weapons
        yield return(StartCoroutine(HandleBrokenWeapons()));

        //Drop Items
        if (!actions[0].attacker.IsAlive() && actions[0].attacker.faction == Faction.ENEMY)
        {
            yield return(StartCoroutine(DropItems(actions[0].attacker, actions[0].defender)));
        }
        else if (!actions[0].defender.IsAlive() && actions[0].defender.faction == Faction.ENEMY)
        {
            yield return(StartCoroutine(DropItems(actions[0].defender, actions[0].attacker)));
        }

        //Give debuffs
        if (actions[0].type == BattleAction.Type.DAMAGE)
        {
            actions[0].attacker.ActivateSkills(SkillActivation.POSTCOMBAT, actions[0].defender);
            actions[0].defender.ActivateSkills(SkillActivation.POSTCOMBAT, actions[0].attacker);
            actions[0].defender.stats.fatigueAmount = Mathf.Min(actions[0].defender.fatigueCap, actions[0].defender.stats.fatigueAmount + 1);
        }

        //Clean up
        state = State.INIT;
        currentAction.value = ActionMode.NONE;
        battleAnimator.CleanupScene();
        battleAnimationObject.SetActive(false);
        uiCanvas.SetActive(true);
        actions[0].attacker.EndSkills(SkillActivation.INITCOMBAT, actions[0].defender);
        actions[0].attacker.EndSkills(SkillActivation.PRECOMBAT, actions[0].defender);
        actions[0].defender.EndSkills(SkillActivation.PRECOMBAT, actions[0].attacker);
        actions.Clear();
        if (currentTurn.value == Faction.PLAYER)
        {
            lockControls.value = false;
        }
        _currentCharacter.End();
        _currentCharacter = null;

        yield return(new WaitForSeconds(0.5f * currentGameSpeed.value));

        //Music
        stopTransitionMusicEvent.Invoke();

        //Send game finished
        battleFinishedEvent.Invoke();
    }
Ejemplo n.º 54
0
    public void OnSelectTopic()
    {
        UIButton selectedButton = UIButton.current;

        Topic selectedTopic = selectedButton.GetComponent <TopicReference>().Topic;
        //Debug.Log("clicked " + selectedButton.GetComponent<TopicReference>().Topic.Type);

        string playerName = GameManager.Inst.PlayerProgress.PlayerFirstName;

        if (selectedTopic.Type == TopicType.Info && selectedTopic.Response != null && selectedTopic.Response != "")
        {
            //we have an immediate response.
            DialogueEntry request = CreateDialogueEntry(playerName, selectedTopic.Title, true);
            _entries.Push(request);

            string        parsedResponse = ParseDialogueText(selectedTopic.Response);
            DialogueEntry entry          = CreateDialogueEntry(GetSpeakerName(), parsedResponse, false);
            _entries.Push(entry);
            ClearTopics();
            RefreshDialogue(_currentNodeID, false);
        }
        else if (selectedTopic.Type == TopicType.Info && selectedTopic.NextNode != null && selectedTopic.NextNode != "")
        {
            //we are going to a new node
            //check if there's request text
            if (selectedTopic.Request != null && selectedTopic.Request != "")
            {
                DialogueEntry entry = CreateDialogueEntry(playerName, selectedTopic.Request, true);
                _entries.Push(entry);
            }
            else
            {
                DialogueEntry entry = CreateDialogueEntry(playerName, selectedTopic.Title, true);
                _entries.Push(entry);
            }

            ClearTopics();
            _currentNodeID = selectedTopic.NextNode;
            RefreshDialogue(selectedTopic.NextNode, true);
        }
        else if (selectedTopic.Type == TopicType.Return)
        {
            //back to root node

            DialogueEntry entry = CreateDialogueEntry(playerName, "Let's talk about something else.", true);
            _entries.Push(entry);

            ClearTopics();
            _currentNodeID = _rootNode;
            RefreshDialogue(_rootNode, true);
        }
        else if (selectedTopic.Type == TopicType.Exit)
        {
            ClearDialogue();
            ClearTopics();
            Hide();
        }
        else if (selectedTopic.Type == TopicType.Trade)
        {
            ClearDialogue();
            ClearTopics();
            Hide();
            UIEventHandler.Instance.TriggerTrading();
        }
    }
Ejemplo n.º 55
0
        private void MarkEntryScripts(Struct structEntry, DialogueEntry dialogueEntry, string dlgName)
        {
            string actionScript = structEntry.Script;
            string questUpdate = structEntry.Quest;
            bool hasActionScript = !string.IsNullOrEmpty(actionScript);
            bool hasQuestUpdate = !string.IsNullOrEmpty(questUpdate);
            if (hasActionScript || hasQuestUpdate) {
                if (prefs.ScriptHandlingType == ScriptHandlingType.CustomLuaFunction) {
                    dialogueEntry.userScript = string.Empty;
                    if (hasActionScript) {
                        dialogueEntry.userScript = string.Format("NWScript(\"{0}\")", actionScript);
                    }
                    if (hasQuestUpdate) {
                        if (hasActionScript) dialogueEntry.userScript += "; ";
                        dialogueEntry.userScript += string.Format("Item[\"{0}\"].Entry_{0}_State", DialogueLua.StringToTableIndex(questUpdate), structEntry.QuestEntry);

                    }
                } else {
                    dialogueEntry.userScript = string.Format("{0}{1} {2}", "--", actionScript, questUpdate);
                }
                if (reportQuestsAndScriptsFlag) {
                    Debug.LogWarning(string.Format("{0}: '{1}' entry {2} {3}: {4} {5} -> {6}", DialogueDebug.Prefix, dlgName, structEntry.id, GetTextSnippet(dialogueEntry), actionScript, questUpdate, dialogueEntry.userScript));
                }
            }
        }
Ejemplo n.º 56
0
 private void OnEnable()
 {
     dialogueEntry = (DialogueEntry)dialogueLibrary.GetEntry(dialogueUuid.value);
 }
Ejemplo n.º 57
0
 private string GetTextSnippet(DialogueEntry dialogueEntry)
 {
     try {
         string dialogueText = dialogueEntry.DialogueText ?? string.Empty;
         return (dialogueText.Length <= MaxSnippetLength)
             ? string.Format("(\"{0}\")", dialogueText)
             : string.Format("(\"{0}...\")", dialogueText.Substring(0, MaxSnippetLength));
     } catch (System.Exception) {
         return null;
     }
 }
Ejemplo n.º 58
0
 private GUIStyle GetDialogueEntryLeafStyle(DialogueEntry entry)
 {
     return(((entry != null) && database.IsPlayerID(entry.ActorID)) ? pcLineLeafGUIStyle : npcLineLeafGUIStyle);
 }
Ejemplo n.º 59
0
        public NetworkViewModel(CommandExecutor cmdExe, Dialogue dialogue)
        {
            _dialogue = dialogue;
            _cmdExec = cmdExe;

            if (_dialogue == null)
            {
                Debug.Assert(false);
                return;
            }

            var entryToModel = new Dictionary<DialogueEntry, NodeViewModel>();

            for (int i = 0; i < _dialogue.NumEntries; ++i)
            {
                DialogueEntry entry = _dialogue.Entry(i);
                if (entry != null)
                {
                    var model = new NodeViewModel(cmdExe, entry, _dialogue, this);
                    Nodes.Add(model);

                    entryToModel.Add(entry, model);
                }
            }

            for (int i = 0; i < _dialogue.NumChoices; ++i)
            {
                DialogueChoice choice = _dialogue.Choice(i);
                if (choice != null)
                {
                    var connection = new ConnectionViewModel(cmdExe, choice);
                    Connections.Add(connection);

                    if (choice.SourceEntry != null && choice.DestinationEntry != null)
                    {
                        NodeViewModel srcNode = entryToModel[choice.SourceEntry];
                        foreach (ConnectorViewModel connector in srcNode.OutgoingConnectors)
                        {
                            if (connector.DialogueChoice.Equals(choice))
                            {
                                connection.SourceConnector = connector;
                                break;
                            }
                        }

                        NodeViewModel dstNode = entryToModel[choice.DestinationEntry];
                        connection.DestConnector = dstNode.IncomingConnector;
                    }
                }
            }

            for (int i = 0; i < _dialogue.NumParticipants; ++i)
            {
                Participant participant = _dialogue.Participant(i);
                if (participant != null)
                {
                    var model = new ParticipantViewModel(cmdExe, participant, _dialogue);
                    Participants.Add(model);
                }
            }
        }
Ejemplo n.º 60
0
    private void GenerateActionsFromFrame(DialogueEntry entry)
    {
        Debug.Log("Generating actions...");

        Frame previousFrame = new Frame();
        Frame currentFrame  = entry.frames[0];

        entry.actions = new List <DialogueActionData>();
        DialogueActionData data = null;
        bool change             = false;

        // //Start frame
        // data = new DialogueActionData();
        // data.type = DActionType.START_SCENE;
        // data.entries.Add(currentFrame.background);
        // data.entries.Add(currentFrame.bkgMusic);
        // for (int i = 0; i < 4; i++) {
        //  int index = indexList[i];
        //  data.entries.Add(currentFrame.characters[i]);
        //  data.values.Add(currentFrame.poses[i]);
        // }
        // entry.actions.Add(data);

        //Start actions
        data      = new DialogueActionData();
        data.type = DActionType.SET_MUSIC;
        data.entries.Add(currentFrame.bkgMusic);
        entry.actions.Add(data);
        data      = new DialogueActionData();
        data.type = DActionType.SET_CHARS;
        for (int i = 0; i < 4; i++)
        {
            int index = indexList[i];
            data.entries.Add(currentFrame.characters[index]);
            data.values.Add(currentFrame.poses[index]);
        }
        entry.actions.Add(data);
        data      = new DialogueActionData();
        data.type = DActionType.SET_BKG;
        data.entries.Add(currentFrame.background);
        entry.actions.Add(data);

        previousFrame.background = currentFrame.background;
        previousFrame.bkgMusic   = currentFrame.bkgMusic;
        previousFrame.characters = currentFrame.characters;
        previousFrame.poses      = currentFrame.poses;

        //The other frames
        int pos = 0;

        while (pos < entry.frames.Count)
        {
            currentFrame = entry.frames[pos];

            //Background
            if (!ScrObjLibraryEntry.CompareEqual(previousFrame.background, currentFrame.background))
            {
                data      = new DialogueActionData();
                data.type = DActionType.SET_BKG;
                data.entries.Add(currentFrame.background);
                entry.actions.Add(data);
            }

            //Characters and poses
            change    = false;
            data      = new DialogueActionData();
            data.type = DActionType.SET_CHARS;
            for (int i = 0; i < 4; i++)
            {
                if (!ScrObjLibraryEntry.CompareEqual(previousFrame.characters[i], currentFrame.characters[i]) || previousFrame.poses[i] != currentFrame.poses[i])
                {
                    change = true;
                }
                int index = indexList[i];
                data.entries.Add(currentFrame.characters[index]);
                data.values.Add(currentFrame.poses[index]);
            }
            if (change)
            {
                entry.actions.Add(data);
            }

            //Background music
            if (currentFrame.bkgMusic != null)
            {
                data      = new DialogueActionData();
                data.type = DActionType.SET_MUSIC;
                data.entries.Add(currentFrame.bkgMusic);
                entry.actions.Add(data);
            }

            //Talking and text
            change = false;
            data   = new DialogueActionData();
            if (!ScrObjLibraryEntry.CompareEqual(previousFrame.talkingChar, currentFrame.talkingChar) || previousFrame.talkingPose != currentFrame.talkingPose)
            {
                change = true;
            }
            data.values.Add((currentFrame.talkingIndex != -1) ? reverseIndexList[currentFrame.talkingIndex] : -1);

            if (previousFrame.talkingName != currentFrame.talkingName)
            {
                change = true;
            }
            data.text.Add(currentFrame.talkingName);

            if (previousFrame.dialogueText != currentFrame.dialogueText)
            {
                change = true;
            }
            data.type = DActionType.SET_TEXT;
            data.text.Add(currentFrame.dialogueText);
            data.autoContinue = false;
            data.boolValue    = true;

            if (change)
            {
                entry.actions.Add(data);
            }

            previousFrame = entry.frames[pos];
            pos++;
        }

        //End Dialogue
        data              = new DialogueActionData();
        data.type         = DActionType.END_SCENE;
        data.autoContinue = false;
        data.entries.Add(entry.dialogueEntry);
        data.entries.Add(entry.battleEntry);
        data.values.Add((int)entry.nextLocation);
        data.values.Add((entry.changePosition) ? 1 : 0);
        data.values.Add((int)entry.nextArea);
        data.values.Add((int)entry.playerPosition.x);
        data.values.Add((int)entry.playerPosition.y);
        entry.actions.Add(data);

        InstansiateDialogue();
    }