public ConversationLink(Conversation conversation, FlowChartLink link) { Conversation = conversation; Link = link; }
private static Command ReadInput(FlowChartNode node, out FlowChartLink pickedLink) { int accumulator = 0; int pickedLine = -1; int numDialogueLines = node.Links.Count + node.ChildIDs.Count; Command command = Command.None; do { ConsoleKeyInfo keyInfo = Console.ReadKey(true); if (keyInfo.Key == ConsoleKey.Escape) { command = Command.QuitProgram; } else if (keyInfo.Key == ConsoleKey.Backspace || keyInfo.Key == ConsoleKey.Subtract) { if (accumulator == 0) { command = Command.Rewind; } else { accumulator /= 10; Console.SetCursorPosition(Console.CursorLeft - 1, Console.CursorTop); Console.Write(' '); Console.SetCursorPosition(Console.CursorLeft - 1, Console.CursorTop); } } else if (keyInfo.Key == ConsoleKey.Enter) { if (numDialogueLines == 1) { accumulator = 1; } if (1 <= accumulator && accumulator <= numDialogueLines) { pickedLine = accumulator - 1; command = Command.PickLine; } else { if (numDialogueLines > 0) { Console.WriteLine("Valid range: {0} .. {1}\n", 1, numDialogueLines); } else { command = Command.Confirm; } Debug.Assert(accumulator == 0); } } else if ('0' <= keyInfo.KeyChar && keyInfo.KeyChar <= '9') { int total = 10 * accumulator + (keyInfo.KeyChar - '0'); if (0 < total && total <= numDialogueLines) { Console.Write(keyInfo.KeyChar); accumulator = total; // pick dialogue line number if unambiguous if (10 * accumulator > numDialogueLines) { pickedLine = accumulator - 1; command = Command.PickLine; } } } else if (keyInfo.Key == ConsoleKey.Spacebar) { command = Command.ToggleAudio; } } while (command == Command.None); if (pickedLine < node.Links.Count) { pickedLink = (pickedLine == -1 ? null : node.Links[pickedLine]); } else { pickedLink = new FlowChartLink(node.NodeID, node.ChildIDs[pickedLine - node.Links.Count]); } return(command); }
private static void PrintNode(Conversation conversation, FlowChartLink parentLink, bool playAudio) { FlowChartNode node = conversation.Nodes[parentLink.ToNodeID]; var dialogueNode = node as DialogueNode; bool keepParentBrief = (parentLink.PointsToGhost && dialogueNode != null && dialogueNode.IsQuestionNode); FlowChartNode briefNode = (keepParentBrief ? conversation.Nodes[parentLink.FromNodeID] : node); Console.WriteLine("{0}", briefNode.GetBrief()); FileInfo audioFile = ResourceLocator.FindVocalization(conversation.Tag, briefNode.NodeID); if (audioFile != null) { Console.Write("[audio] "); } StringTable.Entry text = conversation.FindText(briefNode.NodeID); if (text != null) { Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("{0}", text.Format()); Console.ForegroundColor = ConsoleColor.Gray; } Console.WriteLine("\n\n"); if (node.Links.Count + node.ChildIDs.Count == 0) { if (node is TriggerConversationNode) { Console.WriteLine("(End. Hit BACKSPACE to rewind or ENTER to load target conversation)"); } else if (node.ContainerNodeID != -1) { Console.WriteLine("(Hit BACKSPACE to rewind into container node)"); } else { Console.WriteLine("(End. Hit BACKSPACE to rewind)"); } } else { for (int i = 0; i < node.Links.Count + node.ChildIDs.Count; i++) { FlowChartNode targetNode; bool pointsToGhost = false; if (i < node.Links.Count) { FlowChartLink link = node.Links[i]; pointsToGhost = link.PointsToGhost; targetNode = conversation.FindNode(link.ToNodeID); Console.Write("({0}) {1} -> {2}", i + 1, link.GetBrief(), targetNode.GetBrief()); } else { targetNode = conversation.FindNode(node.ChildIDs[i - node.Links.Count]); Console.Write("({0}) [ child ] -> {1}", i + 1, targetNode.GetBrief()); } if (targetNode is PlayerResponseNode && targetNode.Links.Count == 1) { Console.WriteLine(" -> {0}", conversation.FindNode(targetNode.Links[0].ToNodeID).GetBrief()); } else { Console.WriteLine(); } string condition = targetNode.Conditionals.Format(); if (condition.Length > 0) { Console.WriteLine(" if : {0}", condition); } foreach (var script in targetNode.OnEnterScripts) { Console.WriteLine(" on enter : {0}", script.Format()); } foreach (var script in targetNode.OnExitScripts) { Console.WriteLine(" on exit : {0}", script.Format()); } foreach (var script in targetNode.OnUpdateScripts) { Console.WriteLine(" on update : {0}", script.Format()); } if (!pointsToGhost) { Console.ForegroundColor = ConsoleColor.White; } if (node.Links.Count + node.ChildIDs.Count == 1) { Console.WriteLine("[continue]"); } else { if (ResourceLocator.FindVocalization(conversation.Tag, targetNode.NodeID) != null) { Console.Write("[audio] "); } text = conversation.FindText(targetNode.NodeID); Console.WriteLine(text.Format()); } if (!pointsToGhost) { Console.ForegroundColor = ConsoleColor.Gray; } Console.WriteLine("\n"); } } if ((audioFile != null) && playAudio && (briefNode == node)) { AudioServer.Play(audioFile); } }