Example #1
0
        private void GenerateGraph(bool reset = false)
        {
            gr.Clear();
            foreach (var d in Story.Dialogs)
            {
                gr.AddVertex(new DialogVertex(d));
            }

            foreach (var v in gr.Vertices)
            {
                foreach (var o in v.Dialog.Options)
                {
                    if (!o.TargetID.IsNullOrEmpty())
                    {
                        gr.AddEdge(new DialogEdge(v, gr.Vertices.First(x => x.Dialog.ID == o.TargetID))
                        {
                            DialogOption = o
                        });
                    }
                }
            }

            if (graph.LogicCore == null)
            {
                var LogicCore = new GXLogicCoreExample()
                {
                    Graph = gr
                };
                LogicCore.DefaultLayoutAlgorithm       = LayoutAlgorithmTypeEnum.Tree;
                LogicCore.DefaultLayoutAlgorithmParams =
                    LogicCore.AlgorithmFactory.CreateLayoutParameters(LayoutAlgorithmTypeEnum.Tree);
                ((SimpleTreeLayoutParameters)LogicCore.DefaultLayoutAlgorithmParams).Direction = LayoutDirection.LeftToRight;
                //LogicCore.DefaultOverlapRemovalAlgorithm = OverlapRemovalAlgorithmTypeEnum.OneWayFSA;
                //LogicCore.DefaultOverlapRemovalAlgorithmParams = LogicCore.AlgorithmFactory.CreateOverlapRemovalParameters(OverlapRemovalAlgorithmTypeEnum.OneWayFSA);
                //LogicCore.DefaultOverlapRemovalAlgorithmParams.HorizontalGap = 50;
                //LogicCore.DefaultOverlapRemovalAlgorithmParams.VerticalGap = 50;
                LogicCore.DefaultEdgeRoutingAlgorithm = EdgeRoutingAlgorithmTypeEnum.None;
                LogicCore.AsyncAlgorithmCompute       = false;
                LogicCore.EdgeCurvingEnabled          = true;
                LogicCore.EnableParallelEdges         = true;
                LogicCore.ParallelEdgeDistance        = 10;

                graph.LogicCore = LogicCore;
            }

            graph.GenerateGraph(true, true);
            if (!reset && path.Length > 0 && File.Exists(path.Replace(".apstp", ".apmap")))
            {
                System.Xml.Serialization.XmlSerializer xml = new System.Xml.Serialization.XmlSerializer(typeof(List <GraphPos>));
                try
                {
                    using (var fs = File.OpenRead(path.Replace(".apstp", ".apmap")))
                        pos = xml.Deserialize(fs) as List <GraphPos>;
                    Relayout(false);
                }
                catch { }
            }
            graph.ShowAllEdgesLabels(false);
            graph.SetVerticesDrag(true, true);
            graph.SetEdgesDashStyle(EdgeDashStyle.Dash);
            foreach (var v in graph.VertexList)
            {
                v.Value.Background = v.Key.Dialog.Tag == null ? Brushes.LightGray : new SolidColorBrush(v.Key.Dialog.Tag.Color.ToMediaColor());
            }
        }