예제 #1
0
파일: Form1.cs 프로젝트: TomasMike/TG
        public static int GetTreeSize(RecipeNodeUC node)
        {
            var nodes = new List <RecipeNodeUC>();

            Action <RecipeNodeUC> a = null;

            a = n =>
            {
                foreach (var item in n.IncomingRecipes)
                {
                    if (!nodes.Contains(item))
                    {
                        nodes.Add(item);
                        a(item);
                    }
                }

                foreach (var item in n.OutGoingRecipes)
                {
                    if (!nodes.Contains(item))
                    {
                        nodes.Add(item);
                        a(item);
                    }
                }
            };

            a(node);
            return(nodes.Count);
        }
예제 #2
0
파일: Form1.cs 프로젝트: TomasMike/TG
        private void Form1_Load(object sender, EventArgs e)
        {
            //be();

            if (false)
            {
                RecipeNodeUC r = new RecipeNodeUC()
                {
                    Recipe = new Recipee()
                    {
                        Inputs = new List <ResourceChunk>()
                        {
                            new ResourceChunk()
                            {
                                Name = "iron-ore", Probability = 1, Quantity = 1
                            }
                        },
                        Outputs = new List <ResourceChunk>()
                        {
                            new ResourceChunk()
                            {
                                Name = "iron-plate", Probability = 1, Quantity = 1
                            }
                        }
                    },
                    Name = "iron-ore-to-iron-plate"
                };
                r.Fill();
                this.Controls.Add(r);
                //r.Size = new Size(50, 50);
            }
            else
            {
                DisplayRecipes();
            }

            return;


            #region MyRegion
            //this.Paint += Form1_Paint;
            //this.AutoSize = true;
            //List<RecipeNode> labels = InitRecipes("Chrome");

            //var choosenResource = Types.Chrome;
            //Stack<RecipeNode> x;
            //switch (choosenResource)
            //{
            //    case Types.Chrome:
            //        x = FindOptimalProductionPath("Chrome","Chromium Ore","Chromium Ingot",1000);
            //        break;
            //    case Types.Zinc:
            //        x = FindOptimalProductionPath("Zinc", "Zinc Ore", "Zinc Ingot", 1000);
            //        break;
            //    default:
            //        break;
            //}

            //if (false)
            //{

            //    var roots = labels.Where(_ => _.IncomingRecipes.Count == 0);

            //    Action<IEnumerable<RecipeNode>> d = null;

            //    d = n =>
            //    {

            //        if (n.Count() == 0)
            //            return;

            //        var controlsAdded = new List<RecipeNodeUC>();
            //        foreach (var item in n)
            //        {
            //            item.AutoSize = true;
            //            item.Fill();

            //            if (item.Recipe.Name == "ble")
            //            {
            //                item.BackColor = Color.Green;
            //            }
            //            if (!flowLayoutPanel1.Controls.Contains(item))
            //            {
            //                flowLayoutPanel1.Controls.Add(item);
            //                controlsAdded.Add(item);
            //            }
            //        }

            //        if (flowLayoutPanel1.Controls.Count > 0)
            //            flowLayoutPanel1.SetFlowBreak(flowLayoutPanel1.Controls[flowLayoutPanel1.Controls.Count - 1], true);


            //        foreach (var item in controlsAdded)
            //        {
            //            d(item.OutGoingRecipes);
            //        }
            //    };

            //    d(roots);

            //}
            //else
            //{
            //    flowLayoutPanel1.Hide();

            //    var t = new TableLayoutPanel();
            //    t.RowCount = 10;
            //    t.ColumnCount = 10;
            //    for (int i = 0; i < 10; i++)
            //    {
            //        //t.RowStyles.Add(new RowStyle(SizeType.Percent, 10));
            //        //t.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 10));
            //        t.RowStyles.Add(new RowStyle(SizeType.AutoSize));
            //        t.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
            //    }

            //    t.Dock = DockStyle.Fill;
            //    t.CellBorderStyle = TableLayoutPanelCellBorderStyle.Outset;


            //    t.BackColor = Color.Beige;
            //    TreeCharter.ChartTree(labels, t);
            //    this.Controls.Add(t);
            //    this.Refresh();

            //}

            //this.flowLayoutPanel1.Paint += Form1_Paint;
            #endregion
        }