예제 #1
0
    public void RunDialog(DialogCharacter character)
    {
        this.currDialog = character;
        if (PlayerPrefs.GetString("language") == "pt-BR")
        {
            this._story = new Story(inkAssetPortuguese.text);
        }
        else if (PlayerPrefs.GetString("language") == "en")
        {
            this._story = new Story(inkAssetEnglish.text);
        }
        else
        {
            Debug.Break();
            Debug.LogError("This should not be happening.");
            this._story = new Story(inkAssetPortuguese.text);
        }

        if (savedJson != "")
        {
            this._story.state.LoadJson(savedJson);
        }

        this._story.ChoosePathString(character.dialogID);

        Toggle(true);
        StartCoroutine(Text());
    }
예제 #2
0
    private Vector3 GetNamePositiion(DialogCharacter character)
    {
        var result = character.NamePositiion;

        result.y = _nameCharacterObject.transform.position.y;
        return(result);
    }
예제 #3
0
 public DialogLabel(string id, List <object> block)
 {
     this.id    = id;
     this.block = new List <object>(block);
     characters = new Dictionary <string, DialogCharacter>()
     {
         { "R", new DialogCharacter("R", "Rubus") },
         { "H", new DialogCharacter("H", "Hedera") },
         { "S", new DialogCharacter("S", "Sternella") },
         { "A", new DialogCharacter("A", "Agelaius") },
         { "O", new DialogCharacter("O", "Oxx") },
         { "B", new DialogCharacter("B", "Bark") },
         { "Z", new DialogCharacter("Z", "Riddance") },
     };
     labels = new Dictionary <string, DialogLabel>();
     flags  = new Dictionary <string, bool>();
     // find all characters and labels
     // parse them to the characters list and labels list
     for (int i = 0; i < this.block.Count; i++)
     {
         // check for character statement
         if (CheckStatement(this.block[i], "character"))
         {
             DialogCharacter c = DialogCharacter.Load(this.block[i]);
             if (c == null)
             {
                 throw new DialogError($"Invalid DialogCharacter.\nYAML: {Reserialize(this.block[i])}");
             }
             if (characters.ContainsKey(c.id))
             {
                 throw new DialogError($"Duplicate DialogCharacter '{c.id}'.\nYAML: {Reserialize(this.block[i])}");
             }
             characters[c.id] = c;
             // remove
             this.block.RemoveAt(i);
             i--;
             continue;
         }
         // check for label statement
         if (CheckStatement(this.block[i], "label"))
         {
             DialogLabel l = Load(this.block[i]);
             if (l == null)
             {
                 throw new DialogError($"Invalid DialogLabel.\nYAML: {Reserialize(this.block[i])}");
             }
             if (labels.ContainsKey(l.id))
             {
                 throw new DialogError($"Duplicate DialogLabel '{l.id}'.\nYAML: {Reserialize(this.block[i])}");
             }
             labels[l.id] = l;
             l.parent     = this;
             // remove
             this.block.RemoveAt(i);
             i--;
             continue;
         }
     }
 }
예제 #4
0
    IEnumerator Text()
    {
        container.SetActive(true);
        if (animator)
        {
            animator.SetBool("active", true);
        }

        while (_story.canContinue)
        {
            string str = _story.Continue();
            this.printCompleted = false;

            // start typing
            typer.TypeText(str, 0.02f);
            if (animator)
            {
                animator.SetBool("idle", false);
            }

            // typing ends when player tries to skip it, or if the print was completed naturally
            yield return(new WaitForEndOfFrame());

            yield return(new WaitUntil(() => this.dialogKeyPressed || this.printCompleted));

            this.dialogKeyPressed = false;

            typer.Skip();
            if (animator)
            {
                animator.SetBool("idle", true);
            }

            // end this line after player confirmation
            yield return(new WaitForEndOfFrame());

            yield return(new WaitUntil(() => this.dialogKeyPressed));

            this.dialogKeyPressed = false;
        }

        if (animator)
        {
            animator.SetBool("active", false);
        }
        container.SetActive(false);

        savedJson           = _story.state.ToJson();
        this.printCompleted = false;
        this.currDialog     = null;
        Toggle(false);
    }
예제 #5
0
        // should probably change it for constructor
        public void Initialize(ActorToCreate actorToCreate)
        {
            character    = actorToCreate.Character;
            currentState = actorToCreate.InitialState;
            transitions  = actorToCreate.Transitions;

            Canvas parentCanvas = GetComponentInParent <Canvas>();

            _parentCanvasRectTransform = parentCanvas.GetComponent <RectTransform>();

            _rectTransform = gameObject.AddComponent <RectTransform>();

            _stage = transform.GetComponent <StageForActors>();

            _image        = gameObject.AddComponent <Image>();
            _image.sprite = character.BodySprite;
            _image.SetNativeSize();
            SetImageScale();

            gameObject.name = character.name + " Actor";

            Move(currentState.relativePosition);
        }
예제 #6
0
    public void Init(ConversationNode node)
    {
        _actualNode = node;
        DialogCharacter character = DialogController.GetCharacterWithId(node.CharacterId);

        Portrait.sprite = character.Portrait;
        DialogController.SetActiveBox(this);

        if (node.IsEndNode)
        {
            EndDialogue();
        }

        if (node.Answers != null && node.Answers.Count > 0)
        {
            _isAnswerNode = true;
            InitAnswerButtons(node);
        }
        else
        {
            _isAnswerNode = false;
            InitSpeech(node);
        }
    }
예제 #7
0
        private void ButtonAddClick(object sender, EventArgs e)
        {
            var text = _comboCharacters.Text;
            if (text != null)
                text = text.Trim();

            if(!string.IsNullOrEmpty(text))
            {
                if(!_listCharacters.Items.Cast<ListViewItem>().Any(c=>((DialogCharacter)c.Tag).Name==text))
                {
                    var ch = new DialogCharacter(_dialog) {Name = text};

                    AddCharacter(ch);

                    if(_comboCharacters.SelectedIndex<0)
                        _comboCharacters.Items.Add(text);
                }
            }
        }
예제 #8
0
 private void AddCharacter(DialogCharacter ch)
 {
     var item = _listCharacters.Items.Add(new ListViewItem(ch.Name));
     item.Tag = ch;
     item.Checked = ch.IsPlayer;
 }
예제 #9
0
        public DialogCharacter AddCharacter(string name)
        {
            DialogCharacter baseCh;
            if (!ParentContainer.TryGetCharacter(name, out baseCh))
                baseCh = ParentContainer.AddCharacter(name);

            var ch = new DialogCharacter(baseCh, this);
            DialogCharacters.Add(ch);
            return ch;
        }
예제 #10
0
        internal void ReadXml(XElement xDialog, Func<int,DialogCharacter> characterSelector)
        {
            string name;
            if(xDialog.TryGetAttribute("name",out name))
                Name = name;

            XElement characterProperties = xDialog.Element("characterProperties"),
                     graph = xDialog.Element("graph"), chatactersNode = xDialog.Element("characters");

            Dictionary<int, string> propertyMap;
            if (characterProperties != null)
                propertyMap = _attributeCollection.ReadXml(characterProperties, new List<string> { "IsPlayer" });
            else
                propertyMap = new Dictionary<int, string>();

            var tmpCharacters = new Dictionary<int, DialogCharacter>();
            if(chatactersNode!=null)
            {
                foreach(var ch in chatactersNode.Elements("character"))
                {
                    int id;
                    if(!ch.TryGetAttribute("id",out id))
                        continue;

                    var baseChar = characterSelector(id);
                    var character = new DialogCharacter(baseChar, this);

                    character.ReadProperties(ch, propId => propertyMap[propId]);

                    tmpCharacters.Add(character.Id, character);
                    DialogCharacters.Add(character);
                }
            }

            if (graph != null)
            {
                XElement xNodes = graph.Element("nodes"), xLinks = graph.Element("links");
                var nodeDefaultLinks = new Dictionary<int, int>();

                if (xNodes != null)
                {
                    foreach (var xNode in xNodes.Elements())
                    {
                        int id;
                        if (!xNode.TryGetAttribute("id", out id))
                            continue;

                        int defaultLink;
                        if (xNode.TryGetAttribute("defaultLink", out defaultLink))
                            nodeDefaultLinks.Add(id, defaultLink);

                        DialogGraphNodeBase node = null;
                        switch (xNode.Name.LocalName)
                        {
                            case "node":
                                var n = new PhraseDialogGraphNode();
                                int charId;
                                if (xNode.TryGetAttribute("characterId", out charId))
                                    n.Character = tmpCharacters[charId].Name;

                                n.Phrase = xNode.Value;
                                node = n;
                                break;
                            case "empty":
                                node = new EmptyDialogGraphNode();
                                break;
                            case "answer":
                                node = new AnswerCollectionDialogGraphNode();
                                break;
                        }

                        if (node != null)
                        {
                            node.Id = id;
                            _graph.ForceInsertNode(node);
                        }
                    }
                }

                if(xLinks!=null)
                {
                    foreach(var xLink in xLinks.Elements("link"))
                    {
                        int from, to;
                        if (!xLink.TryGetAttribute("from", out from) || !xLink.TryGetAttribute("to", out to))
                            continue;

                        var link = Graph.Link(from, to);
                        int fromNodeDefault;
                        if(nodeDefaultLinks.TryGetValue(to,out fromNodeDefault) && fromNodeDefault==from)
                        {
                            var node = _graph.GetNode(to);
                            node.DefaultLinkHere = link;
                        }
                    }
                }
            }
        }
예제 #11
0
 public bool TryGetCharacter(string name, out DialogCharacter character)
 {
     character = DialogCharacters.FirstOrDefault(c => c.Name == name);
     return character != null;
 }
예제 #12
0
 public bool IsActiveCharacter(DialogCharacter ch)
 {
     return Graph.AnyNode<PhraseDialogGraphNode>(node => node.Character == ch.Name);
 }
예제 #13
0
 public void CallDialog(DialogCharacter tarChar, DialogCharacter recievingChar, int initalDialogState = 0)
 {
     Char1 = tarChar;
     Char2 = recievingChar;
     SetUpDialog(initalDialogState);
 }
예제 #14
0
 private void ShowCharacterName(CharacterData data, DialogCharacter character)
 {
     _nameCharacterObject.SetActive(true);
     _nameCharacterObject.transform.position = GetNamePositiion(character);
     _nameCharacterText.text = _providerTexts[data.NameID];
 }