private void DisplayPlayer(Actor actor, List <ConversationItem> connectedItems)
        {
            Image_Player.sprite   = actor.Image;
            Text_Actor_Label.text = actor.Name;

            RemoveAllResponseButtons();

            if (connectedItems.Count > 1)
            {
                SetContinueButtonState(actor, mCurrentConversationItem, connectedItems.Count);

                Text_Player.text = "";

                foreach (var conversationItem in connectedItems)
                {
                    Button newButton = Instantiate <Button>(mResponseButton, ResponsePanel);
                    newButton.onClick.AddListener(delegate { OnResponseButtonClick(conversationItem); });

                    Text text = newButton.transform.Find("Text").GetComponent <Text>();
                    text.text = conversationItem.Text;
                }
            }
            else
            {
                mCurrentConversationItem = connectedItems[0];

                SetContinueButtonState(actor, mCurrentConversationItem, connectedItems.Count);

                Text_Player.text = mCurrentConversationItem.Text;
            }
        }
        public void ConversationStep()
        {
            ConversationItem item = mCurrentConversation.GetFirstConnectedItem(mCurrentConversationItem);

            if (item == null)
            {
                // No more items, stop conversation
                StopConversation();
            }
            else
            {
                Actor actor = Database.GetActor(item.ActorId);

                if (actor.ActorType == EActorType.NPC)
                {
                    mCurrentConversationItem = item;
                    OnConversationItemChanged(mCurrentConversationItem);
                    DisplayNPC(actor, item);
                }
                else
                {
                    DisplayPlayer(actor, mCurrentConversation.GetConnectedItems(mCurrentConversationItem));
                }

                mTimeRemaining = Database.ContinueConversationTime;

                if (CanContinueOrStop && mTimeRemaining > 0)
                {
                    InvokeRepeating("StartContinueTimer", 0.0f, 1.0f);
                }
            }
        }
Example #3
0
        public async Task SendMessage()
        {
            var item = new ConversationItem
            {
                Input = this.txtInput.Text,
                Id    = this.Id
            };

            Action setOpacityNone = () =>
            {
                this.viewText.Alpha = 0;
            };

            Action <object> setOpacityFull = (o) =>
            {
                this.OpacityFull();
            };


            UIViewPropertyAnimator propertyAnimatorOpacityNone = new UIViewPropertyAnimator(2, UIViewAnimationCurve.EaseInOut, setOpacityNone);

            //propertyAnimatorOpacityNone.StartAnimation();

            var Response = await this.ViewModel.SendMessage(item);

            //TimerCallback abortPositionDelegate = new TimerCallback(setOpacityFull);
            //Timer abortPosition = new Timer(abortPositionDelegate, null, 3000, Timeout.Infinite);

            this.apiResponse   = Response;
            this.txtTitle.Text = this.apiResponse.Replace("[", "").Replace("]", "").Replace("\",\"", Environment.NewLine).Replace("\"", "");
            this.txtInput.Text = "";
        }
        public static List <ConversationItem> GetUserChannels(Guid profile_id, string profile_type)
        {
            var conversation_items = new List <ConversationItem>();

            //get all the appointments of the person
            if (profile_type == "client")
            {
                var profile = _context.mp_profile.FirstOrDefault(e => e.id == profile_id);
                var ids     = _context.mp_appointment.Where(e => e.client_id == profile_id).Select(e => e.clinician_id).Distinct();
                //get all the clinicians
                var clinicians = _context.mp_clinician.Where(e => ids.Contains(e.id)).ToList();

                foreach (var clinician in clinicians)
                {
                    var conversation = _context.mp_conversation.Where(e => (e.from == clinician.user_id && e.to == profile.user_id) || (e.from == profile.user_id && e.to == clinician.user_id)).OrderBy(e => e.created_at).FirstOrDefault();

                    var conversation_item = new ConversationItem
                    {
                        person_id = clinician.id,
                        name      = string.Format("{0} {1}", clinician.last_name, clinician.first_name),
                        user_id   = clinician.user_id
                    };

                    if (conversation != null)
                    {
                        conversation_item.message = conversation.message;
                    }

                    conversation_items.Add(conversation_item);
                }
            }
            else if (profile_type == "clinician")
            {
                var profile = _context.mp_clinician.FirstOrDefault(e => e.id == profile_id);
                var ids     = _context.mp_appointment.Where(e => e.clinician_id == profile_id).Select(e => e.client_id).Distinct();
                //get all the clinicians
                var clients = _context.mp_clinician.Where(e => ids.Contains(e.id));

                foreach (var client in clients)
                {
                    var conversation = _context.mp_conversation.LastOrDefault(e => (e.from == client.user_id && e.to == profile.user_id) || (e.from == profile.user_id && e.to == client.user_id));

                    var conversation_item = new ConversationItem
                    {
                        person_id = client.id,
                        name      = string.Format("{0} {1}", client.last_name, client.first_name),
                        user_id   = client.user_id
                    };

                    if (conversation != null)
                    {
                        conversation_item.message = conversation.message;
                    }

                    conversation_items.Add(conversation_item);
                }
            }

            return(conversation_items);
        }
Example #5
0
    public ConversationItem Add(string who, string what, BoxType boxType)
    {
        var result = new ConversationItem(who, what, boxType);

        Items.Add(result);
        return(result);
    }
Example #6
0
    IEnumerator RunConversation(int id)
    {
        OnScreenText.SetActive(true);

        while (true)
        {
            ConversationItem item = ConversationFactory.Instance.ItemForID(currentID);
            yield return(StartCoroutine("RunConversationItem", item));

            if (item.responseIDs == null)
            {
                // Conversation is over
                currentCompletionHandler(true);
                break;
            }

            if (item.responseIDs.Length == 1)
            {
                currentID = item.responseIDs[0];
                continue;
            }

            // Show the conversation responses and wait until we start the next conversation
            conversationPanel = (GameObject)Instantiate(conversationPanelPrefab);
            conversationPanel.transform.SetParent(transform);

            ConversationPanel panel = conversationPanel.GetComponent <ConversationPanel>();
            panel.SetResponses(this, item);

            break;
        }

        OnScreenText.SetActive(false);
    }
 private void OnConversationItemChanged(ConversationItem item)
 {
     if (ConversationItemChanged != null)
     {
         ConversationItemChanged(this, new ConversationItemEventArgs(mCurrentConversationItem));
     }
 }
Example #8
0
    public void CreateItem(object obj)
    {
        Vector2          mousePosition = (Vector2)obj;
        ConversationItem item          = new ConversationItem(mousePosition, 200, 30, "Default Text");

        dialogData.conversation.Items.Add(item);
        item.Text = dialogData.conversation.Items.Count - 1 + ". is your ID";
    }
        public void OnResponseButtonClick(ConversationItem item)
        {
            mCurrentConversationItem = item;

            OnConversationItemChanged(mCurrentConversationItem);

            ConversationStep();
        }
Example #10
0
    public void Init(ConversationItem item)
    {
        this.item = item;

        this.sentenceAnSpanish = item.Text;
        sentenceText.text      = sentenceAnSpanish;

        this.sentenceAnPolish = item.Text;
    }
Example #11
0
    public void CreateEdge(object obj)
    {
        ConversationItem parent = (ConversationItem)obj;

        currentEdge = new Edge(parent);

        dialogData.conversation.Edges.Add(currentEdge);
        makingEdge = true;
    }
Example #12
0
    public void ContinueConversation(ConversationItem item)
    {
        currentID = item.id;

        if (conversationPanel != null)
        {
            Destroy(conversationPanel);
        }
        StartCoroutine("RunConversation", item.id);
    }
        private void DisplayNPC(Actor actor, ConversationItem item)
        {
            Text_Actor_Label.text = actor.Name + ":";

            RemoveAllResponseButtons();

            SetContinueButtonState(actor, item, 1);

            Text_NPC.text = item.Text;

            Image_NPC.sprite = actor.Image;
        }
Example #14
0
    IEnumerator RunConversationItem(ConversationItem item)
    {
        // Display the player's lines
        int index = 0;

        if (item.playerDialog != null)
        {
            while (index < item.playerDialog.Length)
            {
                textComponent.text = item.playerDialog[index];
                PositionText(playerObject);
                index++;

                yield return(new WaitForSeconds(2));
            }
        }

        if (item.characterDialog == null)
        {
            // No character dialog is finished
            return(true);
        }

        index = 0;
        while (index < item.characterDialog.Length)
        {
            textComponent.text = item.characterDialog[index];
            PositionText(currentPeer);

            index++;

            yield return(new WaitForSeconds(2));
        }

        if (item.actions != null)
        {
            controller.RunActions(item.actions, currentPeer);
        }

        /*
         * // Process any actions this item may have
         * if (item.actions != null) {
         *      foreach (ConversationAction action in item.actions) {
         *              if (action.type == ConversationAction.ActionType.RemoveItem) {
         *                      foreach (string o in action.objects) {
         *                              inventory.RemoveItem(o);
         *                      }
         *              }
         *      }
         * }
         */
    }
Example #15
0
    public void ChangeItemType(object obj)
    {
        ConversationItem item = (ConversationItem)obj;

        if (item.type == ConversationItem.ItemType.Answer)
        {
            item.type = ConversationItem.ItemType.Sentence;
        }
        else if (item.type == ConversationItem.ItemType.Sentence)
        {
            item.type = ConversationItem.ItemType.Answer;
        }
    }
Example #16
0
    public List <ConversationItem> FindItemChilds(ConversationItem parent)
    {
        List <ConversationItem> children = new List <ConversationItem>();

        foreach (var edge in Edges)
        {
            if (edge.FromId == parent.ID)
            {
                children.Add(FindItem(edge.ToId));
            }
        }

        return(children);
    }
Example #17
0
 private void UpdateChatList()
 {
     if (flpConversations.InvokeRequired)
     {
         Invoke(new UpdateChatListDelegate(UpdateChatList));
         return;
     }
     flpConversations.Controls.Clear();
     _connection.GetConversations().Sort(new DateComparator());
     foreach (var con in _connection.GetConversations().ToList())
     {
         var c = new ConversationItem(con);
         c.ClickItem += _clickConItem;
         flpConversations.Controls.Add(c);
     }
 }
        void OnAddItem(Vector2 mousePosition)
        {
            Actor actor = mDatabase.GetFirstActor();

            if (actor != null)
            {
                ConversationItem node = new ConversationItem(mousePosition,
                                                             "Item " + (mConversation.Items.Count), actor.Id);

                mConversation.Items.Add(node);
            }
            else
            {
                Debug.LogWarning("UTalk: Please add actors to the conversation database!");
            }
        }
        private void OpenContextMenuForNode(ConversationItem node, Vector2 mousePosition, bool isRoot)
        {
            GenericMenu genericMenu = new GenericMenu();

            if (!isRoot)
            {
                // avoid deleting the root node
                genericMenu.AddItem(new GUIContent("Delete Item"),
                                    false, () => OnDeleteItem(node));
            }

            genericMenu.AddItem(new GUIContent("Create Item Connection"),
                                false, () => OnCreateConnection(node));

            genericMenu.ShowAsContext();
        }
        private void SetContinueButtonState(Actor actor, ConversationItem item, int itemCount)
        {
            bool active = (actor.ActorType == EActorType.NPC);

            if (actor.ActorType == EActorType.Player)
            {
                active = itemCount == 1;
            }

            if (active)
            {
                active = mCurrentConversation.GetConnectedItems(item).Count > 0;
            }

            Continue_Button.gameObject.SetActive(active);
        }
Example #21
0
    public void SetResponses(TextController textController, ConversationItem item)
    {
        GameObject playerObject = GameObject.Find("Player");

        controller = textController;

        responses = new ConversationItem[item.responseIDs.Length];

        for (int i = 0; i < item.responseIDs.Length; i++)
        {
            responses[i] = ConversationFactory.Instance.ItemForID(item.responseIDs[i]);
        }

        // Process dependancies
        if (item.dependancies != null)
        {
            foreach (ConversationDependancy dependancy in item.dependancies)
            {
                if (dependancy.Check())
                {
                    foreach (ConversationAction action in dependancy.actions)
                    {
                        if (action.type == ConversationAction.ActionType.ReplaceResponses)
                        {
                            responses = new ConversationItem[action.objects.Length];

                            for (int i = 0; i < action.objects.Length; i++)
                            {
                                int id = Convert.ToInt32(action.objects[i]);
                                responses[i] = ConversationFactory.Instance.ItemForID(id);
                            }
                        }
                    }
                    break;
                }
            }
        }

        for (int i = 0; i < 3 && i < responses.Length; i++)
        {
            GameObject slot = dialogSlots[i];
            Text       text = slot.GetComponentInChildren <Text>() as Text;
            text.text = responses[i].playerDialog[0];
        }
    }
Example #22
0
 private void UpdateChatMessages()
 {
     if (flpChat.InvokeRequired)
     {
         Invoke(new UpdateChatMessagesDelegate(UpdateChatMessages));
         return;
     }
     flpChat.Controls.Clear();
     foreach (var message in _connection.ActiveConversation.GetMessages())
     {
         var conversationItem = new ConversationItem(message);
         if (message.GetAuthor().Equals(_username))
         {
             conversationItem.Margin = new Padding(375, 0, 0, 0);
         }
         flpChat.Controls.Add(conversationItem);
     }
 }
        private bool InitConversation(string name)
        {
            mCurrentConversation = Database.GetConversation(name);

            if (mCurrentConversation == null)
            {
                Debug.LogErrorFormat("Conversation {0} could not be found", name);
                return(false);
            }

            if (mCurrentConversation.Items.Count == 0)
            {
                Debug.LogErrorFormat("Conversation {0} has no items", name);
                return(false);
            }

            mCurrentConversationItem = mCurrentConversation.Items[0];
            return(true);
        }
    private void DrawItemMenu(Event currentEvent, ConversationItem item)
    {
        GenericMenu menu = new GenericMenu();

        menu.AddItem(new GUIContent("Edytuj"), false, itemController.EditItem, item);
        menu.AddSeparator("");

        menu.AddItem(new GUIContent("Stwóż połącznie"), false, edgeController.CreateEdge, item);
        menu.AddItem(new GUIContent("Zniszcz powyższe połącznia"), false, edgeController.DestroyAboveEdges, item);
        menu.AddItem(new GUIContent("Zniszcz poniższe połączenia"), false, edgeController.DestroyBelowEdges, item);
        menu.AddSeparator("");

        bool mySentence = Convert.ToBoolean((int)item.type);

        menu.AddItem(new GUIContent("Właściciel zdania/Ty"), mySentence, itemController.ChangeItemType, item);
        menu.AddItem(new GUIContent("Właściciel zdania/Przyjaciel"), !mySentence, itemController.ChangeItemType, item);
        menu.AddItem(new GUIContent("ID: " + item.ID), false, null);

        menu.ShowAsContext();
        currentEvent.Use();
    }
Example #25
0
    public void DestroyAboveEdges(object obj)
    {
        ConversationItem item          = (ConversationItem)obj;
        List <Edge>      edgesToRemove = new List <Edge>();

        foreach (var edge in dialogData.conversation.Edges)
        {
            if (dialogData.conversation.FindEdgeByToID(edge.ToId).ToId == item.ID)
            {
                edgesToRemove.Add(edge);
            }
        }

        foreach (var edgeToRemove in edgesToRemove)
        {
            if (edgesToRemove.Count > 0)
            {
                dialogData.conversation.Edges.Remove(edgeToRemove);
            }
        }
    }
        public override void ServerSide(List <Common.Connections.Connection> ServerConnections, Common.Connections.Connection ThisConnection)
        {
            DBAccess.ConversationDataContext ConversationList = new Common.DBAccess.ConversationDataContext();
            ConversationItem tmpConversation = new ConversationItem();

            //SETUP THE CONVERSTAION FOR THE DATABASE
            tmpConversation.DateCreated      = DateTime.Now;
            tmpConversation.ConversationGUID = this.ConversationID;

            //ADD ALL THE MEMBERS TO THE CONVERSATION VIA LINQ
            tmpConversation.ConversationMembers.AddRange((from a in this.ConversationMembers.Distinct() select new ConversationMember {
                UserID = a
            }));

            //ADD THE CONVERSATION ITEM TO THE DB CONNECTION AND UPDATE IT
            ConversationList.ConversationItems.InsertOnSubmit(tmpConversation);
            ConversationList.SubmitChanges();

            //SEND THIS MESSAGE BACK TO THE CLIENT SO THEY WILL CREATE A CONVERSATION WINDOW
            Send(ThisConnection);
        }
Example #27
0
    public void ReplyToSim(ConversationItem item)
    {
        Instance.RemoweAnswers();
        dialogPart++;

        List <ConversationItem> newItem = conversation.FindItemChilds(item);

        if (newItem.Count > 1)
        {
            Debug.LogError(item.ID + " have more than one child!");
        }
        else if (newItem.Count == 0)
        {
            DialogController.Instance.ShowDialogs();
            LevelManager.Instance.ShowMissions();
            dialogPart = 0;
            Translator.Disable();
        }
        else
        {
            SetDialogPart(newItem[0]);
        }
    }
Example #28
0
    public void SetDialogPart(ConversationItem item)
    {
        components.botText.text = item.Text;// dialogPart[part].sentense;
        if (item.videoClip != null)
        {
            components.viodePlayer.clip              = item.videoClip;
            components.viodePlayer.loopPointReached += EndReached;
        }
        if (item.audioClip != null)
        {
            components.audioSource.clip = item.audioClip;
            components.audioSource.Play();
        }

        List <ConversationItem> children = conversation.FindItemChilds(item);

        for (int j = 0; j < children.Count; j++)
        {
            GameObject prefab   = Resources.Load <GameObject>("Sentence");
            GameObject sentence = Instantiate(prefab, components.sentencesContent);
            sentence.GetComponent <Sentence>().Init(children[j]);
            dialogAnswers.Add(sentence.GetComponent <Sentence>());
        }
    }
Example #29
0
 public void AddItemForID(int id, ConversationItem item)
 {
     IDToConversation[id] = item;
 }
Example #30
0
        /// <summary>
        /// Using the string of say parameters before the ':',
        /// set the current character, position and portrait if provided.
        /// </summary>
        /// <param name="sayParams">The list of say parameters</param>
        protected virtual ConversationItem CreateConversationItem(string[] sayParams, string text, Character currentCharacter)
        {
            var item = new ConversationItem();

            // Populate the story text to be written
            item.Text = text;

            if (sayParams == null || sayParams.Length == 0)
            {
                // Text only, no params - early out.
                return item;
            }

            // try to find the character param first, since we need to get its portrait
            int characterIndex = -1;
            if (characters == null)
            {
                PopulateCharacterCache();
            }

            for (int i = 0; item.Character == null && i < sayParams.Length; i++)
            {
                for (int j = 0; j < characters.Length; j++)
                {
                    if (characters[j].NameStartsWith(sayParams[i]))
                    {
                        characterIndex = i;
                        item.Character = characters[j];
                        break;
                    }
                }
            }

            // Assume last used character if none is specified now
            if (item.Character == null)
            {
                item.Character = currentCharacter;
            }

            // Check if there's a Hide parameter
            int hideIndex = -1;
            if (item.Character != null)
            {
                for (int i = 0; i < sayParams.Length; i++)
                {
                    if (i != characterIndex &&
                        string.Compare(sayParams[i], "hide", true) == 0 )
                    {
                        hideIndex = i;
                        item.Hide = true;
                        break;
                    }
                }
            }
                
            // Next see if we can find a portrait for this character
            int portraitIndex = -1;
            if (item.Character != null)
            {
                for (int i = 0; i < sayParams.Length; i++)
                {
                    if (item.Portrait == null && 
                        item.Character != null &&
                        i != characterIndex && 
                        i != hideIndex) 
                    {
                        Sprite s = item.Character.GetPortrait(sayParams[i]);
                        if (s != null)
                        {
                            portraitIndex = i;
                            item.Portrait = s;
                            break;
                        }
                    }
                }
            }

            // Next check if there's a position parameter
            Stage stage = Stage.GetActiveStage();
            if (stage != null)
            {
                for (int i = 0; i < sayParams.Length; i++)
                {
                    if (i != characterIndex &&
                        i != portraitIndex &&
                        i != hideIndex)
                    {
                        RectTransform r = stage.GetPosition(sayParams[i]);
                        if (r != null)
                        {
                            item.Position = r;
                            break;
                        }
                    }
                }
            }

            return item;
        }
Example #31
0
    public void DialogSlot3Clicked()
    {
        ConversationItem item = responses[2];

        controller.ContinueConversation(item);
    }
Example #32
0
        public Conversation(ConversationItem[] lines)
        {
            spokenLines = lines;

            currentLineNumber = lines.OrderBy(ci => ci.Ordinal).FirstOrDefault().Ordinal;
        }