예제 #1
0
        private void modulesButton_Click(object sender, EventArgs e)
        {
            var optionList    = new List <ChooserControl>();
            var fastestOption = new ItemChooserControl(null, "Best", "Best");

            optionList.Add(fastestOption);

            var noneOption = new ItemChooserControl(null, "None", "None");

            optionList.Add(noneOption);

            var productivityOption = new ItemChooserControl(null, "Most Productive", "Most Productive");

            optionList.Add(productivityOption);

            var recipeNode = (BaseNode as RecipeNode);
            var recipe     = recipeNode.BaseRecipe;

            var allowedModules = DataCache.Modules.Values
                                 .Where(a => a.Enabled)
                                 .Where(a => a.AllowedIn(recipe));

            foreach (var module in allowedModules.OrderBy(a => a.FriendlyName))
            {
                var item = DataCache.Items.Values.SingleOrDefault(i => i.Name == module.Name);
                optionList.Add(new ItemChooserControl(item, module.FriendlyName, module.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 == fastestOption)
                    {
                        (BaseNode as RecipeNode).NodeModules = ModuleSelector.Fastest;
                    }
                    else if (c == noneOption)
                    {
                        (BaseNode as RecipeNode).NodeModules = ModuleSelector.None;
                    }
                    else if (c == productivityOption)
                    {
                        (BaseNode as RecipeNode).NodeModules = ModuleSelector.Productive;
                    }
                    else
                    {
                        var module = DataCache.Modules.Single(a => a.Key == c.DisplayText).Value;
                        (BaseNode as RecipeNode).NodeModules = ModuleSelector.Specific(module);
                    }
                    updateAssemblerButtons();
                    GraphViewer.Graph.UpdateNodeValues();
                    GraphViewer.UpdateNodes();
                }
            });
        }
예제 #2
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();
        }
예제 #3
0
        private void assemblerButton_Click(object sender, EventArgs e)
        {
            var optionList = new List <ChooserControl>();
            var bestOption = new ItemChooserControl(null, "Best", "Best");

            optionList.Add(bestOption);

            var recipeNode = (BaseNode as RecipeNode);
            var recipe     = recipeNode.BaseRecipe;

            var allowedAssemblers = DataCache.Assemblers.Values
                                    .Where(a => a.Enabled)
                                    .Where(a => a.Categories.Contains(recipe.Category))
                                    .Where(a => a.MaxIngredients >= recipe.Ingredients.Count);

            foreach (var assembler in allowedAssemblers.OrderBy(a => a.FriendlyName))
            {
                var item = DataCache.Items.Values.SingleOrDefault(i => i.Name == assembler.Name);
                optionList.Add(new ItemChooserControl(item, assembler.FriendlyName, assembler.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 == bestOption)
                    {
                        (BaseNode as RecipeNode).Assembler = null;
                    }
                    else
                    {
                        var assembler = DataCache.Assemblers.Single(a => a.Key == c.DisplayText).Value;
                        (BaseNode as RecipeNode).Assembler = assembler;
                    }
                    updateAssemblerButtons();
                    GraphViewer.Graph.UpdateNodeValues();
                    GraphViewer.UpdateNodes();
                }
            });
        }
예제 #4
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();
            }
        }
예제 #5
0
        private void EndDrag(Point location)
        {
            if (SupplierElement != null && ConsumerElement != null)
            {
                if (StartConnectionType == LinkType.Input)
                {
                    NodeLink.Create(SupplierElement.DisplayedNode, ConsumerElement.DisplayedNode, Item);
                }
                else
                {
                    NodeLink.Create(SupplierElement.DisplayedNode, ConsumerElement.DisplayedNode, Item);
                }
            }
            else if (StartConnectionType == LinkType.Output && ConsumerElement == null)
            {
                List <ChooserControl> recipeOptionList = new List <ChooserControl>();

                var itemOutputOption      = new ItemChooserControl(Item, "Create output node", Item.FriendlyName);
                var itemPassthroughOption = new ItemChooserControl(Item, "Create pass-through node", Item.FriendlyName);

                recipeOptionList.Add(itemOutputOption);
                recipeOptionList.Add(itemPassthroughOption);

                foreach (Recipe recipe in DataCache.Recipes.Values.Where(r => r.Ingredients.Keys.Contains(Item) && r.Enabled && r.Category != "incinerator" && r.Category != "incineration"))
                {
                    recipeOptionList.Add(new RecipeChooserControl(recipe, "Use recipe " + recipe.FriendlyName, recipe.FriendlyName));
                }

                var chooserPanel = new ChooserPanel(recipeOptionList, Parent);
                chooserPanel.Show(c =>
                {
                    if (c != null)
                    {
                        NodeElement newElement = null;
                        if (c is RecipeChooserControl)
                        {
                            Recipe selectedRecipe = (c as RecipeChooserControl).DisplayedRecipe;
                            newElement            = new NodeElement(RecipeNode.Create(selectedRecipe, Parent.Graph), Parent);
                        }
                        else if (c == itemOutputOption)
                        {
                            Item selectedItem = (c as ItemChooserControl).DisplayedItem;
                            newElement        = new NodeElement(ConsumerNode.Create(selectedItem, Parent.Graph), Parent);
                            (newElement.DisplayedNode as ConsumerNode).rateType = RateType.Auto;
                        }
                        else if (c == itemPassthroughOption)
                        {
                            Item selectedItem = (c as ItemChooserControl).DisplayedItem;
                            newElement        = new NodeElement(PassthroughNode.Create(selectedItem, Parent.Graph), Parent);
                            (newElement.DisplayedNode as PassthroughNode).rateType = RateType.Auto;
                        }
                        else
                        {
                            Trace.Fail("Unhandled option: " + c.ToString());
                        }

                        newElement.Update();
                        newElement.Location = Point.Add(location, new Size(-newElement.Width / 2, -newElement.Height / 2));
                        new LinkElement(Parent, NodeLink.Create(SupplierElement.DisplayedNode, newElement.DisplayedNode, Item));
                    }

                    Parent.Graph.UpdateNodeValues();
                    Parent.AddRemoveElements();
                    Parent.UpdateNodes();
                });
            }
            else if (StartConnectionType == LinkType.Input && SupplierElement == null)
            {
                List <ChooserControl> recipeOptionList = new List <ChooserControl>();

                var itemSupplyOption      = new ItemChooserControl(Item, "Create infinite supply node", Item.FriendlyName);
                var itemPassthroughOption = new ItemChooserControl(Item, "Create pass-through node", Item.FriendlyName);

                recipeOptionList.Add(itemSupplyOption);
                recipeOptionList.Add(itemPassthroughOption);

                foreach (Recipe recipe in DataCache.Recipes.Values.Where(r => r.Results.Keys.Contains(Item) && r.Enabled && r.Category != "incinerator" && r.Category != "incineration"))
                {
                    if (recipe.Category != "incinerator" && recipe.Category != "incineration")
                    {
                        recipeOptionList.Add(new RecipeChooserControl(recipe, "Use recipe " + recipe.FriendlyName, recipe.FriendlyName));
                    }
                }

                var chooserPanel = new ChooserPanel(recipeOptionList, Parent);

                chooserPanel.Show(c =>
                {
                    if (c != null)
                    {
                        NodeElement newElement = null;
                        if (c is RecipeChooserControl)
                        {
                            Recipe selectedRecipe = (c as RecipeChooserControl).DisplayedRecipe;
                            newElement            = new NodeElement(RecipeNode.Create(selectedRecipe, Parent.Graph), Parent);
                        }
                        else if (c == itemSupplyOption)
                        {
                            Item selectedItem = (c as ItemChooserControl).DisplayedItem;
                            newElement        = new NodeElement(SupplyNode.Create(selectedItem, Parent.Graph), Parent);
                        }
                        else if (c == itemPassthroughOption)
                        {
                            Item selectedItem = (c as ItemChooserControl).DisplayedItem;
                            newElement        = new NodeElement(PassthroughNode.Create(selectedItem, Parent.Graph), Parent);
                            (newElement.DisplayedNode as PassthroughNode).rateType = RateType.Auto;
                        }
                        else
                        {
                            Trace.Fail("Unhandled option: " + c.ToString());
                        }
                        newElement.Update();
                        newElement.Location = Point.Add(location, new Size(-newElement.Width / 2, -newElement.Height / 2));
                        new LinkElement(Parent, NodeLink.Create(newElement.DisplayedNode, ConsumerElement.DisplayedNode, Item));
                    }

                    Parent.Graph.UpdateNodeValues();
                    Parent.AddRemoveElements();
                    Parent.UpdateNodes();
                });
            }

            Parent.Graph.UpdateNodeValues();
            Parent.AddRemoveElements();
            Parent.UpdateNodes();
            Dispose();
        }