Beispiel #1
0
    // ********************************************************************
    // Function:	StartConversation()
    // Purpose:		Determines a conversation to use and starts it
    // ********************************************************************
    public void StartConversation()
    {
        // Determine correct conversation
        if (m_conversations.Count == 0)
        {
            Debug.LogError("No conversations loaded!");
        }
        for (int i = 0; i < m_conversations.Count; ++i)
        {
            if (m_conversations[i].autoload && m_conversations[i].MeetsRequirements(ProfileManager.profile))
            {
                m_currentConversation = m_conversations[i];
                Debug.Log("Conversation loaded: " + m_currentConversation.id);
                break;
            }
        }
        if (m_currentConversation == null) // Can't load any conversation!
        {
            Debug.LogError("Don't meet requirements for any conversations!");
            return;
        }

        // Initialize stuff for new conversation
        m_currentFrame = m_currentConversation.frames[m_currentConversation.startingFrame];

        DisplayFrame();
    }
Beispiel #2
0
        // ********************************************************************


        // ********************************************************************
        #region Constructors
        // ********************************************************************
        public DialoguePanelData(DialogueConversation _conversation,
                                 PanelState _startingState         = PanelState.HIDDEN,
                                 PanelLimitOverride _limitOverride = PanelLimitOverride.REPLACE)
            : base(_startingState, _limitOverride)
        {
            conversation = _conversation;
        }
Beispiel #3
0
        // ********************************************************************
        #endregion
        // ********************************************************************


        // ********************************************************************
        #region Private Functions
        // ********************************************************************
        private void ConversationSeen(DialogueConversation _conversation)
        {
            if (!m_invert && _conversation.name == m_conversationID)
            {
                AddProgress();
                Trigger();
            }
        }
Beispiel #4
0
 public void StartDialogue(DialogueConversation conversation, GameObject target)
 {
     this.target         = target;
     this.conversation   = conversation;
     currentConversation = 0;
     if (!initialised)
     {
         Init();
         initialised = true;
     }
     gui.SetActive(true);
     cam.SetActive(true);
     RenderNextFrame();
     isRunning = true;
 }
Beispiel #5
0
        // ****************************************************************
        #region Editor Methods
        // ****************************************************************
        public override void OnInspectorGUI()
        {
            DialogueConversation conversation = (DialogueConversation)target;
            SerializedObject     serialized   = new SerializedObject(conversation);

            serialized.Update();

            GUIStyle style;
            Color    oldColor;

            // default - just draw objects
            SerializedProperty property = serialized.GetIterator();

            property.NextVisible(true);
            do
            {
                if (property.name == "frames")
                {
                    for (int i = 0; i < conversation.frames.Count; ++i)
                    {
                        if (conversation.frames[i] != null)
                        {
                            conversation.frames[i].DrawUI();
                        }
                    }
                }
                else
                {
                    EditorGUILayout.PropertyField(property, !property.hasVisibleChildren || property.isExpanded);
                }
            } while (property.NextVisible(false));

            style           = new GUIStyle();
            style.alignment = TextAnchor.MiddleRight;
            EditorGUILayout.BeginHorizontal(style);
            GUILayout.FlexibleSpace();
            oldColor            = GUI.backgroundColor;
            GUI.backgroundColor = Color.green;
            if (GUILayout.Button("+", GUILayout.Width(30)))
            {
                conversation.AddNewFrameAt(conversation.frames.Count);
            }
            GUI.backgroundColor = oldColor;
            EditorGUILayout.EndHorizontal();

            serialized.ApplyModifiedProperties();
        }
Beispiel #6
0
        // ********************************************************************
        private void FollowLink(DialogueFrame _linkedFrame)
        {
            LogManager.Log("DialoguePanel: FollowLink " + _linkedFrame.name,
                           LogCategory.UI,
                           LogSeverity.LOG,
                           "Dialogue",
                           gameObject);

            if (_linkedFrame.conversation != m_currentConversation)
            {
                m_currentConversation = _linkedFrame.conversation;
            }

            m_currentFrame = _linkedFrame;

            StartCoroutine(DisplayFrame());
        }
Beispiel #7
0
        // ********************************************************************


        // ********************************************************************
        #region Panel Methods
        // ********************************************************************
        protected override void _Initialise(PanelData _data)
        {
            DialoguePanelData castData = _data as DialoguePanelData;

            if (castData != null)
            {
                LogManager.Log("DialoguePanel _Initialise with conversation " + castData.conversation.name,
                               LogCategory.UI,
                               LogSeverity.LOG,
                               "Dialogue",
                               gameObject);
                m_currentConversation = castData.conversation;
            }
            m_previousCursor = InputManager.cursor;
            Events.Raise(new ChangeCursorEvent("TalkingCursor"));
            m_player = ReInput.players.GetPlayer(0);
        }
Beispiel #8
0
    public override void OnInspectorGUI()
    {
        //base.OnInspectorGUI();

        DialogueConversation conversation = (DialogueConversation)target;

        if (conversation.Lines == null)
        {
            conversation.Lines = new List <DialogueElement>();
        }

        int deleteIndex = -1;

        for (int i = 0; i < conversation.Lines.Count; i++)
        {
            EditorGUILayout.BeginHorizontal();

            if (GUILayout.Button("X", GUILayout.Width(30f)))
            {
                deleteIndex = i;
            }

            //EditorGUILayout.LabelField();
            conversation.Lines[i].Speaker = EditorGUILayout.TextField(i + ") Speaker:", conversation.Lines[i].Speaker);

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.LabelField("Text:");
            conversation.Lines[i].Text = EditorGUILayout.TextField("", conversation.Lines[i].Text);

            EditorGUILayout.Space();
        }

        if (deleteIndex != -1)
        {
            conversation.Lines.RemoveAt(deleteIndex);
        }

        if (GUILayout.Button("Add"))
        {
            conversation.Lines.Add(new DialogueElement());
        }
    }
Beispiel #9
0
    private void FollowLink(string _linkedConv, string _linkedFrame)
    {
        Debug.Log("Following link to conv: " + _linkedConv + " frame: " + _linkedFrame);
        if (_linkedConv != null && _linkedConv != "")
        {
            m_currentConversation = m_conversationsMap[_linkedConv];
            m_currentFrame        = m_currentConversation.frames[m_currentConversation.startingFrame];
        }

        if (_linkedFrame != null && _linkedFrame != "")
        {
            m_currentFrame = m_currentConversation.frames[_linkedFrame];
        }

        DisplayFrame();

        if (m_waitingForChoiceInput)
        {
            m_waitingForChoiceInput = false;
            StartCoroutine(HideChoices(true));
        }
    }
Beispiel #10
0
    // ********************************************************************
    // Function:	LoadDialogue()
    // Purpose:		Loads a set of DialogueConversations
    // ********************************************************************
    public void LoadDialogue(TextAsset _dialogueFile)
    {
        string jsonString = _dialogueFile.text;

        Debug.Log("JSON String loaded: " + jsonString);

        if (jsonString != "")
        {
            Dictionary <string, object> N = Json.Deserialize(jsonString) as Dictionary <string, object>;

            if (N.ContainsKey("conversations"))
            {
                List <object> cList = N["conversations"] as List <object>;

                foreach (object cEntry in cList)
                {
                    DialogueConversation conversation = DialogueConversation.Load(cEntry as Dictionary <string, object>);

                    m_conversationsMap[conversation.id] = conversation;
                    m_conversations.Add(conversation);
                }
            }
        }
    }
Beispiel #11
0
 public void SetConvo(DialogueConversation convo)
 {
     currentConverstaion = convo;
     convo.lineIndex     = 0;
     reachedEnd          = false;
 }
Beispiel #12
0
    public static DialogueConversation Load(Dictionary <string, object> JSON, DialogueConversation defaults = null)
    {
        DialogueConversation newObject;

        if (defaults == null)
        {
            newObject = new DialogueConversation();
        }
        else
        {
            newObject = defaults.MemberwiseClone() as DialogueConversation;
        }

        if (JSON.ContainsKey("id"))
        {
            newObject.id = JSON["id"] as string;
        }
        if (JSON.ContainsKey("autoload"))
        {
            newObject.autoload = bool.Parse(JSON["autoload"].ToString());
        }

        // Defaults
        if (JSON.ContainsKey("allowSkip"))
        {
            newObject.allowSkip = bool.Parse(JSON["allowSkip"].ToString());
        }
        if (JSON.ContainsKey("waitForInput"))
        {
            newObject.waitForInput = bool.Parse(JSON["waitForInput"].ToString());
        }
        if (JSON.ContainsKey("portraitSettings"))
        {
            newObject.portraitSettings = DialoguePortraitSettings.Load(JSON["portraitSettings"] as Dictionary <string, object>, newObject.portraitSettings);
        }
        if (JSON.ContainsKey("textSettings"))
        {
            newObject.textSettings = DialogueTextSettings.Load(JSON["textSettings"] as Dictionary <string, object>, newObject.textSettings);
        }

        // Requirements
        if (JSON.ContainsKey("requirements"))
        {
            newObject.requirements = new List <DialogueRequirement>();
            List <object> rList = JSON["requirements"] as List <object>;
            foreach (object rEntry in rList)
            {
                DialogueRequirement newRequirement = DialogueRequirement.Load(rEntry as Dictionary <string, object>);
                newObject.requirements.Add(newRequirement);
            }
        }

        // Frames
        if (JSON.ContainsKey("startingFrame"))
        {
            newObject.startingFrame = JSON["startingFrame"] as string;
        }
        if (JSON.ContainsKey("frames"))
        {
            newObject.frames = new Dictionary <string, DialogueFrame>();

            DialogueFrame defaultFrame = new DialogueFrame();
            defaultFrame.portraitSettings = newObject.portraitSettings;
            defaultFrame.textSettings     = newObject.textSettings;
            defaultFrame.allowSkip        = newObject.allowSkip;
            defaultFrame.waitForInput     = newObject.waitForInput;

            DialogueFrame lastFrame           = null;
            bool          lastFrameLinkNeeded = false;

            List <object> fList = JSON["frames"] as List <object>;
            foreach (object fEntry in fList)
            {
                DialogueFrame newFrame = DialogueFrame.Load(fEntry as Dictionary <string, object>, defaultFrame);
                newObject.frames[newFrame.id] = newFrame;

                if (lastFrameLinkNeeded)
                {
                    DialogueLink link = new DialogueLink();
                    link.linkedFrame = newFrame.id;
                    lastFrame.links  = new List <DialogueLink>();
                    lastFrame.links.Add(link);
                    Debug.Log("Frame " + lastFrame.id + " linked to frame " + newFrame.id);
                }

                lastFrameLinkNeeded = (!newFrame.endOnThisFrame && (newFrame.links == null || newFrame.links.Count == 0));
                lastFrame           = newFrame;

                if (newObject.startingFrame == null || newObject.startingFrame == "")
                {
                    newObject.startingFrame = newFrame.id;
                }
            }

            if (lastFrameLinkNeeded)
            {
                lastFrame.endOnThisFrame = true;
            }
            Debug.Log("Conversation " + newObject.id + " loaded " + newObject.frames.Count + " frames");
            Debug.Log("Starting frame: " + newObject.startingFrame);
        }

        if (newObject.portraitSettings == null)
        {
            Debug.LogError("portraitSettings is null in DialogueConversation");
        }
        if (newObject.textSettings == null)
        {
            Debug.LogError("textSettings is null in DialogueConversation");
        }

        return(newObject);
    }