コード例 #1
0
        private static ChoiceStep EvaluateChoiceNode(ChoiceNode node, List <Character> characters)
        {
            var choices   = node.choices;
            var character = GetCharacter(node.speaker_id, characters);

            return(new ChoiceStep(choices, character));
        }
コード例 #2
0
    private void CreateNodes()
    {
        foreach (var nodeData in containerCache.baseNodesData)
        {
            switch (nodeData.nodeType)
            {
            case NodeType.StartNode:
                var startNode = new BaseNode(nodeData.nodeType, targetGraphView, nodeData.position, nodeData.guid);
                targetGraphView.AddElement(startNode);
                break;

            case NodeType.DialogueNode:
                DialogueNodeData dialogueData = containerCache.dialogueNodesData.Find(x => x.guid == nodeData.guid);
                var dialogueNode = new DialogueNode(targetGraphView, nodeData, dialogueData);
                targetGraphView.AddElement(dialogueNode);
                break;

            case NodeType.ChoiceNode:
                ChoiceNodeData choiceData = containerCache.choiceNodesData.Find(x => x.guid == nodeData.guid);
                var            nodePorts  = containerCache.nodeLinks.Where(x => x.thisNodeGuid == nodeData.guid).ToList();
                var            choiceNode = new ChoiceNode(targetGraphView, nodeData, choiceData, nodePorts);
                targetGraphView.AddElement(choiceNode);
                break;

            case NodeType.EndNode:
                var endNode = new BaseNode(nodeData.nodeType, targetGraphView, nodeData.position, nodeData.guid);
                targetGraphView.AddElement(endNode);
                break;
            }
        }
    }
コード例 #3
0
                public override GlobNode StartLevel()
                {
                    ChoiceNode node = new ChoiceNode(this);

                    _nodes.Add(node);
                    return(node);
                }
コード例 #4
0
    private static void HandleNode(Node node)
    {
        DialogueNode dialogueNode = node as DialogueNode;

        if (dialogueNode != null)
        {
            Debug.Log(string.Format("{0} says: {1}", dialogueNode.Speaker, dialogueNode.Text));
            return;
        }

        ChoiceNode choiceNode = node as ChoiceNode;

        if (choiceNode != null)
        {
            string output = "Available Options:";
            for (int i = 0; i < choiceNode.BranchCount; i++)
            {
                Branch branch = choiceNode.GetBranch(i);
                if (branch.IsAvailable)
                {
                    output += string.Format("\nOption {0}: {1}", i + 1, branch.DialogueNode.Text);
                }
            }

            Debug.Log(output);
        }
    }
コード例 #5
0
    void PlayNode()
    {
        UpdateEvents();

        Type nodeType = currentNode.GetType();

        if (nodeType == typeof(TextNode))
        {
            TextNode tNode = currentNode as TextNode;
            UIManager.instance.ShowText(tNode);
        }

        if (nodeType == typeof(BranchNode))
        {
            BranchNode bNode = currentNode as BranchNode;
            currentNode = bNode.GetNextNode();
            PlayNode();
        }

        if (nodeType == typeof(ChoiceNode))
        {
            ChoiceNode  cNode          = currentNode as ChoiceNode;
            List <Node> availableNodes = cNode.GetValidNodes();

            UIManager.instance.ShowPlayerOptions(availableNodes);
        }

        if (nodeType == typeof(CustomNode))
        {
            PlayCustomNode();
        }
    }
コード例 #6
0
    protected void copy(ChoiceNode nodeToCopy)
    {
        base.copy(nodeToCopy);

        choices        = nodeToCopy.choices;
        nextNodeIdList = nodeToCopy.nextNodeIdList;
    }
コード例 #7
0
        public override ParseResult Apply(Dictionary <int, INodeContainer> containers)
        {
            ChoiceNode <string> choiceNode = (ChoiceNode <string>)Node;

            try
            {
                foreach (string argument in ParseData.Arguments)
                {
                    int index = Convert.ToInt32(argument);

                    if (!containers.ContainsKey(index))
                    {
                        return(ParseResult.Failure.Derive(ParseData.LineNumber, ParseData.Line, String.Format("Invalid index argument \"{0}\"", index)));
                    }

                    choiceNode.AddChoice(containers[index].Node);
                }

                return(ParseResult.Success);
            }
            catch (FormatException)
            {
                return(ParseResult.Failure.Derive(ParseData.LineNumber, ParseData.Line, "Failed to cast argument to an integer"));
            }
        }
コード例 #8
0
    public virtual void SetPrevious(ChoiceNode previous, Vector2 clickPos, int idChoice)
    {
        SetPrevious(previous, clickPos);

        previous.nextNodeIdList[idChoice] = id;
        previous.nextNodeList[idChoice]   = this;
    }
コード例 #9
0
    public IEnumerator VisitChoice(ChoiceNode node)
    {
        ReadOnlyCollection <LineNode> options = node.GetPossibleResponses();

        for (int i = 0; i < options.Count; ++i)
        {
            LineNode option     = options[i];
            Button   butt       = Object.Instantiate(choiceButtonPrefab, choiceRect);
            Text     choiceText = butt.GetComponentInChildren <Text>();
            choiceText.text = option.text;
            butt.onClick.AddListener(() => SelectOption(option));
        }
        choiceRect.gameObject.SetActive(true);

        yield return(new WaitWhile(() => choice == null));

        node.SetResponse(choice);

        choice = null;
        // TODO - reuse buttons; just disable and re-enable
        for (int i = 0; i < choiceRect.childCount; ++i)
        {
            Object.Destroy(choiceRect.GetChild(i).gameObject);
        }
        choiceRect.gameObject.SetActive(false);
    }
コード例 #10
0
ファイル: Glob.cs プロジェクト: tdeb-embeans/mCleaner
                internal override GlobNode StartLevel()
                {
                    var node = new ChoiceNode(this);

                    nodes.Add(node);
                    return(node);
                }
コード例 #11
0
ファイル: Glob.cs プロジェクト: decay88/Phantom
                internal override GlobNode /*!*/ StartLevel()
                {
                    ChoiceNode node = new ChoiceNode(this);

                    _nodes.Add(node);
                    return(node);
                }
コード例 #12
0
        private void HandleChoiceNode(ChoiceNode choiceNode)
        {
            if (choiceNode == null)
            {
                return;
            }

            _currentChoiceNode = choiceNode;

            _waiting = true;

            _normalSubtitlesObject.SetActive(false);
            _choicesObject.SetActive(true);
            _choiceSubtitleText.gameObject.SetActive(true);

            var branches = choiceNode.GetAvailableBranches();

            for (int i = 0; i < branches.Count; i++)
            {
                Branch     branch       = branches[i];
                GameObject choiceButton = Instantiate(_choiceButtonPrefab, _choiceContent);

                //Assign text to the button that can be clicked in the format of
                // "1. Option to pick"
                Text text = choiceButton.GetComponentInChildren <Text>();
                if (text != null)
                {
                    //Regex Magic - stolen from StackOverflow
                    //string choiceText = Regex.Match(_previousDialogueNode.Text, @"\[([^]]*)\]").Groups[1].Value;

                    string choiceText = branch.DialogueNode.Text;
                    if (choiceText.StartsWith("["))
                    {
                        string[] groups = choiceText.Split('[', ']', '\n', '\t');
                        if (groups.Length >= 4)
                        {
                            choiceText = groups[1];
                        }
                    }
                    text.text = string.Format("{0}. {1}", i + 1, choiceText);
                }

                //Assign click command
                Button button = choiceButton.GetComponentInChildren <Button>();
                if (button == null)
                {
                    continue;
                }

                int capturedIndex = i;
                button.onClick.AddListener(() => { PickBranch(choiceNode, capturedIndex); });
            }

            if (_previousDialogueNode != null)
            {
                _choiceSubtitleText.text = _previousDialogueNode.Text;
            }
        }
コード例 #13
0
ファイル: ExternalEnv.cs プロジェクト: whztt07/ai_bird
    public override BirdAction choose_action(int[] state)
    {
        ChoiceNode node = new ChoiceNode();

        node.state = state;
        //Debug.Log("state: " + state);
        Send(node);
        return(BirdAction.NONE);
    }
コード例 #14
0
        private void OnEnable()
        {
            this.node = this.target as ChoiceNode;

            if (this.node == null)
            {
                Debug.LogError("Inspector assigned to wrong type");
            }
        }
コード例 #15
0
 private void PickBranch(int index)
 {
     if (index < 0 || index >= _currentChoiceNode.AvailableBranchCount)
     {
         return;
     }
     PickBranch(_currentChoiceNode, index);
     _currentChoiceNode = null;
 }
コード例 #16
0
    public void Initialization()
    {
        var sut = new ChoiceNode();

        sut.Default.Should().BeNull();
        sut.TimeLimit.Should().BeNull();
        sut.RandomOrder.Should().BeFalse();
        sut.Options.Should().NotBeNull().And.BeEmpty();
        ((IChoiceNode)sut).Options.Should().BeSameAs(sut.Options);
    }
コード例 #17
0
        /// <summary>
        /// returns the amount of time left on the choice node to use for display;
        /// returns 0 if not currently on ChoiceNode or time is not being used
        /// </summary>
        public float GetChoiceTime()
        {
            if (!(currentNode is ChoiceNode))
            {
                return(0);
            }
            ChoiceNode n = (ChoiceNode)currentNode;

            return(n.timed? n.timerLength - n.TotalTime : 0);
        }
コード例 #18
0
        private RegexNode ParseRegex()
        {
            var result = ParseSequence();

            while (Accept(RegexTokenSubType.Choice))
            {
                result = new ChoiceNode(result, ParseSequence());
            }
            return(result);
        }
コード例 #19
0
    public string Choice     = ""; //the text displayed for the choice

    public override Node Create(Vector2 pos)
    {
        ChoiceNode node = CreateInstance <ChoiceNode>();

        node.rect = new Rect(pos.x, pos.y, 200, 160);
        node.name = "Choice Node";

        node.CreateInput("Previous", "Default", NodeSide.Top);
        node.CreateOutput("Next", "Default", NodeSide.Bottom);

        return(node);
    }
コード例 #20
0
    ChoiceNode ParseChoice(XmlNode choiceNode)
    {
        ChoiceNode choice = new ChoiceNode();

        foreach (XmlNode child in choiceNode.ChildNodes)
        {
            switch (child.Name)
            {
            case "text":
                choice.ButtonText = child.InnerText;
                break;

            case "desc":
                choice.Description = child.InnerText;
                break;

            case "target":
                string[] coords = child.InnerText.Split(new char[] { ':' });
                choice.Target = new Vector2(Int32.Parse(coords[0]), Int32.Parse(coords[1]));
                break;

            case "hpchange":
                choice.HPChange = Int32.Parse(child.InnerText);
                break;

            case "manachange":
                choice.ManaChange = Int32.Parse(child.InnerText);
                break;

            case "staminachange":
                choice.StaminaChange = Int32.Parse(child.InnerText);
                break;

            case "foodchange":
                choice.FoodChange = Int32.Parse(child.InnerText);
                break;

            case "waterchange":
                choice.WaterChange = Int32.Parse(child.InnerText);
                break;

            case "techchange":
                choice.TechnologyChange = Int32.Parse(child.InnerText);
                break;

            case "requirements":
                choice.Requirements = child.InnerText;
                break;
            }
        }

        return(choice);
    }
コード例 #21
0
ファイル: ExternalEnv.cs プロジェクト: shiyongde/bird
 public override bool choose_action(int state)
 {
     if (init)
     {
         ChoiceNode node = new ChoiceNode();
         node.state = state;
         string res = Send(node, true);
         Debug.Log("res choice:" + res);
         return(res.ToLower().Equals("pad"));
     }
     return(false);
 }
コード例 #22
0
    public void ExecuteChoice(ChoiceNode choice)
    {
        HitPoints  += choice.HPChange;
        Mana       += choice.ManaChange;
        Stamina    += choice.StaminaChange;
        Food       += choice.FoodChange;
        Water      += choice.WaterChange;
        Technology += choice.TechnologyChange;

        SetCurrentNode((int)choice.Target.x, (int)choice.Target.y);

        UpdateBars();
    }
コード例 #23
0
        private void HandleNextNode()
        {
            if (_dialogueGraph == null)
            {
                return;
            }
            //Node current = _dialogueGraph.Flow.CurrentNode;
            _current = _dialogueGraph.Flow.NextNode();

            //Ugly
            DialogueNode dialogueNode = _current as DialogueNode;

            if (dialogueNode != null)
            {
                HandleDialogueNode(dialogueNode);
                return;
            }

            ConditionNode conditionNode = _current as ConditionNode;

            if (conditionNode != null)
            {
                _waiting = false;
                return;
            }

            ChoiceNode choiceNode = _current as ChoiceNode;

            if (choiceNode != null)
            {
                HandleChoiceNode(choiceNode);
                return;
            }

            EndNode endNode = _current as EndNode;

            if (endNode != null)
            {
                HandleEndNode(endNode);
                return;
            }

            //StartNode startNode = current as StartNode;
            //if (startNode != null)
            //{
            //    throw new InvalidOperationException();
            //}
        }
コード例 #24
0
        private IEnumerator ChoiceBox(ChoiceNode node)
        {
            Typer.Play(node.Dialogue, node.ErasePrevious);
            Typer.SetIndicator(true);
            while (!Typer.IsFinished())
            {
                yield return(null);

                if (ContinueInput || isSkipping)
                {
                    isSkipping = true;
                    Typer.ForceFinish();
                    break;
                }
            }

            isSkipping = false;

            List <string> textChoices = new List <string>();

            foreach (var choice in node.choices)
            {
                textChoices.Add(choice.text);
            }

            Typer.SetIndicator(false);
            ChoiceButtons.Show(textChoices);

            int index;

            while (!ChoiceButtons.GetChoosen(out index))
            {
                yield return(null);
            }
            Debug.Log(index);



            Debug.Log(node.Dialogue);
            Debug.Log(node.choices[index].text);
            node.SetChoice(index);
            isNodeWorking = false;

            //Create the box after the box gets the choice
            //With thie choice the index will be set in the dialoguegraph and we can just graph.Continue;
        }
コード例 #25
0
    public void OnPasteElementsOption(string a, string b)
    {
        if (nodeCopyCache.Count == 0)
        {
            return;
        }

        var graphContainer = GraphSaveUtility.GetInstance(targetGraphView).GetNodesContainer();

        foreach (var node in nodeCopyCache)
        {
            var baseNode = (BaseNode)node;
            var nodeData = baseNode.CopyData(false);

            // Offset pasted node
            nodeData.position.y += baseNode.GetPosition().height + nodePasteOffset;

            switch (nodeData.nodeType)
            {
            case NodeType.DialogueNode:
                var dialogueNodeOriginal      = node as DialogueNode;
                DialogueNodeData dialogueData = dialogueNodeOriginal.CopyData();
                var dialogueNode = new DialogueNode(targetGraphView, nodeData, dialogueData);
                targetGraphView.AddElement(dialogueNode);
                break;

            case NodeType.ChoiceNode:
                var            choiceNodeOriginal = node as ChoiceNode;
                ChoiceNodeData choiceData         = choiceNodeOriginal.CopyData();
                var            choicePorts        = graphContainer.nodeLinks.ToList().Where(x => x.thisNodeGuid == nodeData.guid).ToList();
                var            choiceNode         = new ChoiceNode(targetGraphView, nodeData, choiceData, choicePorts);
                targetGraphView.AddElement(choiceNode);
                break;

            case NodeType.EndNode:
                var endNode = new BaseNode(nodeData.nodeType, targetGraphView, nodeData.position, nodeData.guid);
                targetGraphView.AddElement(endNode);
                break;
            }
        }
    }
コード例 #26
0
    public void DisplayChoices(ChoiceNode node)
    {
        choicesShown = true;

        idChoice = -1;

        characName.text = "";
        sentence.text   = "";

        choicesObject.SetActive(true);

        for (int i = 0; i < node.nbChoice; i++)
        {
            choicesButtons [i].gameObject.SetActive(true);
            choicesTexts [i].text = node.choices [i];

            nextNodeIds[i] = node.nextNodeIdList[i];
        }
        for (int i = node.nbChoice; i < choicesButtons.Length; i++)
        {
            choicesButtons [i].gameObject.SetActive(false);
        }
    }
コード例 #27
0
    private void RenderSpecificNodeData(Node n)
    {
        ChoiceNode cNode = n as ChoiceNode;

        if (cNode)
        {
            RenderChoiceNode(cNode);
            return;
        }

        TextNode tNode = n as TextNode;

        if (tNode)
        {
            RenderTextNode(tNode);
            return;
        }

        BranchNode bNode = n as BranchNode;

        if (bNode)
        {
            RenderBranchNode(bNode);
            return;
        }

        CustomNode cmNode = n as CustomNode;

        if (cmNode)
        {
            RenderCustomNode(cmNode);
            return;
        }

        throw new Exception("Uknown type");
    }
コード例 #28
0
    private void RenderChoiceNode(ChoiceNode cNode)
    {
        EditorGUILayout.LabelField("Choice Node", EditorStyles.boldLabel);

        cNode.id = EditorGUILayout.TextField("node id", cNode.id);

        for (int i = 0; i < cNode.options.Count; i++)
        {
            ChoiceNodeOption cno       = cNode.options[i];
            Condition        condition = cno.condition;

            using (new GUILayout.HorizontalScope())
            {
                cno.nodeId            = EditorGUILayout.TextField("Option node id", cno.nodeId);
                cno.condition.eventId = EditorGUILayout.TextField("Trigger id", cno.condition.eventId);
                cno.condition.type    = (Condition.ConditionType)EditorGUILayout.EnumPopup("Condition type:", cno.condition.type);
            }
        }

        if (GUILayout.Button("Add choice"))
        {
            cNode.options.Add(new ChoiceNodeOption("node id"));
        }
    }
コード例 #29
0
            /**
             * Gets the next speaker from a choice node
             */
            public Pawn GetNextSpeaker(ChoiceNode node, int outputIndex)
            {
                if(outputIndex < node.outputs.Length)
                {
                    Node nextNode = this.GetNode(node.outputs[outputIndex].nodeId);

                    if(nextNode is SpeakNode)
                    {
                        return (Pawn)(nextNode as SpeakNode).speaker.Value;
                    }
                    else
                    {
                        return null;
                    }
                }

                return null;
            }
コード例 #30
0
 public ChoiceNodeContainer(ParseData parseData) : base(parseData)
 {
     Node = new ChoiceNode <string>(parseData.Source, parseData.Value);
 }
コード例 #31
0
 private void PickBranch(ChoiceNode choiceNode, int index)
 {
     choiceNode.PickBranch(choiceNode.GetAvailableBranches()[index]);
     DestroyBranchObjects();
     _waiting = false;
 }
コード例 #32
0
ファイル: Glob.cs プロジェクト: atczyc/ironruby
 internal override GlobNode/*!*/ StartLevel() {
     ChoiceNode node = new ChoiceNode(this);
     _nodes.Add(node);
     return node;
 }
コード例 #33
0
ファイル: Glob.cs プロジェクト: MicroHealthLLC/mCleaner
 internal override GlobNode StartLevel()
 {
     var node = new ChoiceNode(this);
     nodes.Add(node);
     return node;
 }
コード例 #34
0
ファイル: GlobMatcher.cs プロジェクト: yodamaster/docfx
 public override GlobNode StartLevel()
 {
     ChoiceNode node = new ChoiceNode(this);
     _nodes.Add(node);
     return node;
 }