示例#1
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();
        }
示例#2
0
        void HandleItemDropping(object sender, DragEventArgs e)
        {
            if (GhostDragElement != null)
            {
                if (e.Data.GetDataPresent(typeof(HashSet <Item>)))
                {
                    foreach (Item item in GhostDragElement.Items)
                    {
                        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 itemPassthroughOption = new ItemChooserControl(item, "Create pass-through node", item.FriendlyName);

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

                        var chooserPanel = new ChooserPanel(optionList, this);

                        Point location = GhostDragElement.Location;

                        chooserPanel.Show(c =>
                        {
                            if (c != null)
                            {
                                if (c == itemSupplyOption)
                                {
                                    newElement = new NodeElement(SupplyNode.Create(item, this.Graph), this);
                                }
                                else if (c is RecipeChooserControl)
                                {
                                    newElement = new NodeElement(RecipeNode.Create((c as RecipeChooserControl).DisplayedRecipe, this.Graph), this);
                                }
                                else if (c == itemPassthroughOption)
                                {
                                    newElement = new NodeElement(PassthroughNode.Create(item, this.Graph), this);
                                }
                                else if (c == itemOutputOption)
                                {
                                    newElement = new NodeElement(ConsumerNode.Create(item, this.Graph), this);
                                }
                                else
                                {
                                    Trace.Fail("No handler for selected item");
                                }

                                Graph.UpdateNodeValues();
                                newElement.Update();
                                newElement.Location = Point.Add(location, new Size(-newElement.Width / 2, -newElement.Height / 2));
                            }
                        });
                    }
                }
                else if (e.Data.GetDataPresent(typeof(HashSet <Recipe>)))
                {
                    foreach (Recipe recipe in GhostDragElement.Recipes)
                    {
                        NodeElement newElement = new NodeElement(RecipeNode.Create(recipe, Graph), this);
                        Graph.UpdateNodeValues();
                        newElement.Update();
                        newElement.Location = Point.Add(GhostDragElement.Location, new Size(-newElement.Width / 2, -newElement.Height / 2));
                    }
                }

                GhostDragElement.Dispose();
            }
        }