示例#1
0
        private void AddItemButton_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem lvItem in ItemListView.SelectedItems)
            {
                Item        item       = (Item)lvItem.Tag;
                NodeElement newElement = null;

                var itemSupplyOption = new ItemChooserControl(item, "Create infinite supply node", item.FriendlyName);
                var itemOutputOption = new ItemChooserControl(item, "Create output node", item.FriendlyName);

                var optionList = new List <ChooserControl>();
                optionList.Add(itemOutputOption);
                foreach (Recipe recipe in DataCache.Recipes.Values.Where(r => r.Enabled))
                {
                    if (recipe.Results.ContainsKey(item))
                    {
                        optionList.Add(new RecipeChooserControl(recipe, String.Format("Create '{0}' recipe node", recipe.FriendlyName), recipe.FriendlyName));
                    }
                }
                optionList.Add(itemSupplyOption);

                foreach (Recipe recipe in DataCache.Recipes.Values.Where(r => r.Enabled))
                {
                    if (recipe.Ingredients.ContainsKey(item))
                    {
                        optionList.Add(new RecipeChooserControl(recipe, String.Format("Create '{0}' recipe node", recipe.FriendlyName), recipe.FriendlyName));
                    }
                }

                var chooserPanel = new ChooserPanel(optionList, GraphViewer);

                Point location = GraphViewer.ScreenToGraph(new Point(GraphViewer.Width / 2, GraphViewer.Height / 2));

                chooserPanel.Show(c =>
                {
                    if (c != null)
                    {
                        if (c == itemSupplyOption)
                        {
                            newElement = new NodeElement(SupplyNode.Create(item, GraphViewer.Graph), GraphViewer);
                        }
                        else if (c is RecipeChooserControl)
                        {
                            newElement = new NodeElement(RecipeNode.Create((c as RecipeChooserControl).DisplayedRecipe, GraphViewer.Graph), GraphViewer);
                        }
                        else if (c == itemOutputOption)
                        {
                            newElement = new NodeElement(ConsumerNode.Create(item, GraphViewer.Graph), GraphViewer);
                        }

                        newElement.Update();
                        newElement.Location = Point.Add(location, new Size(-newElement.Width / 2, -newElement.Height / 2));
                    }
                });
            }

            GraphViewer.Graph.UpdateNodeValues();
        }
示例#2
0
        private void AddRecipeButton_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem lvItem in RecipeListView.SelectedItems)
            {
                Point location = GraphViewer.ScreenToGraph(new Point(GraphViewer.Width / 2, GraphViewer.Height / 2));

                NodeElement newElement = new NodeElement(RecipeNode.Create((Recipe)lvItem.Tag, GraphViewer.Graph), GraphViewer);
                newElement.Update();
                newElement.Location = Point.Add(location, new Size(-newElement.Width / 2, -newElement.Height / 2));
            }

            GraphViewer.Graph.UpdateNodeValues();
        }