Esempio n. 1
0
        public override void MouseUp(Point location, MouseButtons button)
        {
            ItemTab clickedTab = null;

            foreach (ItemTab tab in SubElements.OfType <ItemTab>())
            {
                if (tab.bounds.Contains(location))
                {
                    clickedTab = tab;
                }
            }

            if (button == MouseButtons.Left)
            {
                if (clickedTab != null && clickedTab.Type == LinkType.Input && DisplayedNode is ConsumerNode)
                {
                    beginEditingInputAmount(clickedTab.Item);
                }
            }
            else if (button == MouseButtons.Right)
            {
                rightClickMenu.MenuItems.Clear();
                rightClickMenu.MenuItems.Add(new MenuItem("Delete node",
                                                          new EventHandler((o, e) =>
                {
                    Parent.DeleteNode(this);
                })));
                rightClickMenu.Show(Parent, Parent.GraphToScreen(Point.Add(location, new Size(X, Y))));
            }
        }
Esempio n. 2
0
        public int GetItemTabXHeuristic(ItemTab tab)
        {
            int total = 0;

            if (tab.Type == LinkType.Input)
            {
                foreach (NodeLink link in DisplayedNode.InputLinks.Where(l => l.Item == tab.Item))
                {
                    NodeElement node = Parent.GetElementForNode(link.Supplier);
                    Point       diff = Point.Subtract(new Point(node.Location.X + node.Width / 2, node.Location.Y + node.Height / 2), new Size(Location.X + Width / 2, Location.Y + Height / 2));
                    diff.Y = Math.Max(0, diff.Y);
                    total += Convert.ToInt32(Math.Atan2(diff.X, diff.Y) * 1000);
                }
            }
            else
            {
                foreach (NodeLink link in DisplayedNode.OutputLinks.Where(l => l.Item == tab.Item))
                {
                    NodeElement node = Parent.GetElementForNode(link.Consumer);
                    Point       diff = Point.Subtract(new Point(node.Location.X + node.Width / 2, -node.Location.Y + -node.Height / 2), new Size(Location.X + Width / 2, -Location.Y + -Height / 2));
                    diff.Y = Math.Max(0, diff.Y);
                    total += Convert.ToInt32(Math.Atan2(diff.X, diff.Y) * 1000);
                }
            }
            return(total);
        }
Esempio n. 3
0
        public Point GetInputLineConnectionPoint(Item item)
        {
            if (!inputTabs.Any())
            {
                return(new Point(X + Width / 2, Y + Height));
            }
            ItemTab tab = inputTabs.First(it => it.Item == item);

            return(new Point(X + tab.X + tab.Width / 2, Y + tab.Y + tab.Height));
        }
Esempio n. 4
0
        public Point GetOutputLineConnectionPoint(Item item)
        {
            if (!outputTabs.Any())
            {
                return(new Point(X + Width / 2, Y));
            }
            ItemTab tab = outputTabs.First(it => it.Item == item);

            return(new Point(X + tab.X + tab.Width / 2, Y + tab.Y));
        }
Esempio n. 5
0
        public NodeElement(ProductionNode node, ProductionGraphViewer parent) : base(parent)
        {
            Width  = 100;
            Height = 90;

            DisplayedNode = node;

            if (DisplayedNode.GetType() == typeof(ConsumerNode))
            {
                backgroundColour = supplyColour;
            }
            else if (DisplayedNode.GetType() == typeof(SupplyNode))
            {
                backgroundColour = consumerColour;
            }
            else
            {
                backgroundColour = recipeColour;
            }
            backgroundBrush = new SolidBrush(backgroundColour);

            foreach (Item item in node.Inputs)
            {
                ItemTab newTab = new ItemTab(item, LinkType.Input, Parent);
                SubElements.Add(newTab);
                inputTabs.Add(newTab);
            }
            foreach (Item item in node.Outputs)
            {
                ItemTab newTab = new ItemTab(item, LinkType.Output, Parent);
                SubElements.Add(newTab);
                outputTabs.Add(newTab);
            }

            if (DisplayedNode is RecipeNode || DisplayedNode is SupplyNode)
            {
                assemblerBox = new AssemblerBox(Parent);
                SubElements.Add(assemblerBox);
                assemblerBox.Height = assemblerBox.Width = 50;
            }

            centreFormat.Alignment = centreFormat.LineAlignment = StringAlignment.Center;
        }
Esempio n. 6
0
		public NodeElement(ProductionNode node, ProductionGraphViewer parent) : base(parent)
		{
			Width = 100;
			Height = 90;

			DisplayedNode = node;

			if (DisplayedNode.GetType() == typeof(ConsumerNode))
			{
				backgroundColour = supplyColour;
			}
			else if (DisplayedNode.GetType() == typeof(SupplyNode))
			{
				backgroundColour = consumerColour;
			}
			else
			{
				backgroundColour = recipeColour;
			}
			backgroundBrush = new SolidBrush(backgroundColour);

			foreach (Item item in node.Inputs)
			{
				ItemTab newTab = new ItemTab(item, LinkType.Input, Parent);
				SubElements.Add(newTab);
				inputTabs.Add(newTab);
			}
			foreach (Item item in node.Outputs)
			{
				ItemTab newTab = new ItemTab(item, LinkType.Output, Parent);
				SubElements.Add(newTab);
				outputTabs.Add(newTab);
			}

			if (DisplayedNode is RecipeNode || DisplayedNode is SupplyNode)
			{
				assemblerBox = new AssemblerBox(Parent);
				SubElements.Add(assemblerBox); 
				assemblerBox.Height = assemblerBox.Width = 50;
			}

			centreFormat.Alignment = centreFormat.LineAlignment = StringAlignment.Center;
		}
Esempio n. 7
0
        public override void Dragged(Point location)
        {
            ItemTab draggedTab = null;

            foreach (ItemTab tab in SubElements.OfType <ItemTab>())
            {
                if (tab.bounds.Contains(new Point(DragOffsetX, DragOffsetY)))
                {
                    draggedTab = tab;
                }
            }

            if (draggedTab != null)
            {
                DraggedLinkElement newLink = new DraggedLinkElement(Parent, this, draggedTab.Type, draggedTab.Item);
                if (draggedTab.Type == LinkType.Input)
                {
                    newLink.ConsumerElement = this;
                }
                else
                {
                    newLink.SupplierElement = this;
                }
                Parent.DraggedElement = newLink;
            }
            else
            {
                X += location.X - DragOffsetX;
                Y += location.Y - DragOffsetY;

                foreach (ProductionNode node in DisplayedNode.InputLinks.Select <NodeLink, ProductionNode>(l => l.Supplier))
                {
                    Parent.GetElementForNode(node).UpdateTabOrder();
                }
                foreach (ProductionNode node in DisplayedNode.OutputLinks.Select <NodeLink, ProductionNode>(l => l.Consumer))
                {
                    Parent.GetElementForNode(node).UpdateTabOrder();
                }
            }
        }
Esempio n. 8
0
        public override void MouseMoved(Point location)
        {
            if (editorBox == null)
            {
                ItemTab mousedTab = null;
                foreach (ItemTab tab in SubElements.OfType <ItemTab>())
                {
                    if (tab.bounds.Contains(location))
                    {
                        mousedTab = tab;
                    }
                }

                TooltipInfo tti = new TooltipInfo();
                if (mousedTab != null)
                {
                    tti.Text = mousedTab.Item.FriendlyName;
                    if (mousedTab.Type == LinkType.Input)
                    {
                        if (DisplayedNode is ConsumerNode)
                        {
                            tti.Text += "\nClick to edit desired amount";
                        }
                        tti.Text          += "\nDrag to create a new connection";
                        tti.Direction      = Direction.Up;
                        tti.ScreenLocation = Parent.GraphToScreen(GetInputLineConnectionPoint(mousedTab.Item));
                    }
                    else
                    {
                        tti.Text           = mousedTab.Item.FriendlyName;
                        tti.Text          += "\nDrag to create a new connection";
                        tti.Direction      = Direction.Down;
                        tti.ScreenLocation = Parent.GraphToScreen(GetOutputLineConnectionPoint(mousedTab.Item));
                    }
                    Parent.AddTooltip(tti);
                }
                else if (DisplayedNode is RecipeNode)
                {
                    tti.Direction      = Direction.Left;
                    tti.ScreenLocation = Parent.GraphToScreen(Point.Add(Location, new Size(Width, Height / 2)));
                    tti.Text           = String.Format("Recipe: {0}", (DisplayedNode as RecipeNode).BaseRecipe.FriendlyName);
                    tti.Text          += String.Format("\n--Base Time: {0}s", (DisplayedNode as RecipeNode).BaseRecipe.Time);
                    tti.Text          += String.Format("\n--Base Ingredients:");
                    foreach (var kvp in (DisplayedNode as RecipeNode).BaseRecipe.Ingredients)
                    {
                        tti.Text += String.Format("\n----{0} ({1})", kvp.Key.FriendlyName, kvp.Value.ToString());
                    }
                    tti.Text += String.Format("\n--Base Results:");
                    foreach (var kvp in (DisplayedNode as RecipeNode).BaseRecipe.Results)
                    {
                        tti.Text += String.Format("\n----{0} ({1})", kvp.Key.FriendlyName, kvp.Value.ToString());
                    }
                    if (Parent.ShowAssemblers)
                    {
                        tti.Text += String.Format("\n\nAssemblers:");
                        foreach (var kvp in assemblerBox.AssemblerList)
                        {
                            tti.Text += String.Format("\n----{0} ({1})", kvp.Key.assembler.FriendlyName, kvp.Value.ToString());
                            foreach (var Module in kvp.Key.modules)
                            {
                                tti.Text += String.Format("\n------{0}", Module.FriendlyName);
                            }
                        }
                    }
                    Parent.AddTooltip(tti);
                }
            }
        }
Esempio n. 9
0
		public int GetItemTabXHeuristic(ItemTab tab)
		{
			int total = 0;
			if (tab.Type == LinkType.Input)
			{
				foreach (NodeLink link in DisplayedNode.InputLinks.Where(l => l.Item == tab.Item))
				{
					NodeElement node = Parent.GetElementForNode(link.Supplier);
					Point diff = Point.Subtract(new Point(node.Location.X + node.Width / 2, node.Location.Y + node.Height / 2), new Size(Location.X + Width / 2, Location.Y + Height / 2));
					diff.Y = Math.Max(0, diff.Y);
					total += Convert.ToInt32(Math.Atan2(diff.X, diff.Y) * 1000);
				}
			}
			else
			{
				foreach (NodeLink link in DisplayedNode.OutputLinks.Where(l => l.Item == tab.Item))
				{
					NodeElement node = Parent.GetElementForNode(link.Consumer);
					Point diff = Point.Subtract(new Point(node.Location.X + node.Width / 2, -node.Location.Y + -node.Height / 2), new Size(Location.X + Width / 2, -Location.Y + -Height / 2));
					diff.Y = Math.Max(0, diff.Y);
					total += Convert.ToInt32(Math.Atan2(diff.X, diff.Y) * 1000);
				}
			}
			return total;
		}
Esempio n. 10
0
        public NodeElement(ProductionNode node, ProductionGraphViewer parent) : base(parent)
        {
            Width  = 100;
            Height = 90;

            DisplayedNode = node;

            Color backgroundColour = missingColour;
            Color textColour       = darkTextColour;

            if (DisplayedNode is ConsumerNode)
            {
                backgroundColour = outputColour;

                if (((ConsumerNode)DisplayedNode).ConsumedItem.IsMissingItem)
                {
                    backgroundColour = missingColour;
                }
            }
            else if (DisplayedNode is SupplyNode)
            {
                backgroundColour = supplyColour;
                if (((SupplyNode)DisplayedNode).SuppliedItem.IsMissingItem)
                {
                    backgroundColour = missingColour;
                }
            }
            else if (DisplayedNode is RecipeNode)
            {
                backgroundColour = recipeColour;
                if (((RecipeNode)DisplayedNode).BaseRecipe.IsMissingRecipe)
                {
                    backgroundColour = missingColour;
                }
            }
            else if (DisplayedNode is PassthroughNode)
            {
                backgroundColour = passthroughColour;
                if (((PassthroughNode)DisplayedNode).PassedItem.IsMissingItem)
                {
                    backgroundColour = missingColour;
                }
            }
            else
            {
                Trace.Fail("No branch for node: " + DisplayedNode.ToString());
            }
            backgroundBrush = new SolidBrush(backgroundColour);
            textBrush       = new SolidBrush(textColour);

            foreach (Item item in node.Inputs)
            {
                ItemTab newTab = new ItemTab(item, LinkType.Input, Parent);
                SubElements.Add(newTab);
                inputTabs.Add(newTab);
            }
            foreach (Item item in node.Outputs)
            {
                ItemTab newTab = new ItemTab(item, LinkType.Output, Parent);
                SubElements.Add(newTab);
                outputTabs.Add(newTab);
            }

            if (DisplayedNode is RecipeNode || DisplayedNode is SupplyNode)
            {
                assemblerBox = new AssemblerBox(Parent);
                SubElements.Add(assemblerBox);
                assemblerBox.Height = assemblerBox.Width = 50;
            }

            centreFormat.Alignment = centreFormat.LineAlignment = StringAlignment.Center;
        }
Esempio n. 11
0
        public override void MouseMoved(Point location)
        {
            ItemTab mousedTab = null;

            foreach (ItemTab tab in SubElements.OfType <ItemTab>())
            {
                if (tab.bounds.Contains(location))
                {
                    mousedTab = tab;
                }
            }

            if (tooltipsEnabled)
            {
                TooltipInfo tti = new TooltipInfo();
                if (mousedTab != null)
                {
                    tti.Text = mousedTab.Item.FriendlyName;
                    if (mousedTab.Type == LinkType.Input)
                    {
                        tti.Text          += "\nDrag to create a new connection";
                        tti.Direction      = Direction.Up;
                        tti.ScreenLocation = Parent.GraphToScreen(GetInputLineConnectionPoint(mousedTab.Item));
                    }
                    else
                    {
                        tti.Text           = mousedTab.Item.FriendlyName;
                        tti.Text          += "\nDrag to create a new connection";
                        tti.Direction      = Direction.Down;
                        tti.ScreenLocation = Parent.GraphToScreen(GetOutputLineConnectionPoint(mousedTab.Item));
                    }
                    Parent.AddTooltip(tti);
                }
                else if (DisplayedNode is RecipeNode)
                {
                    tti.Direction      = Direction.Left;
                    tti.ScreenLocation = Parent.GraphToScreen(Point.Add(Location, new Size(Width, Height / 2)));
                    tti.Text           = String.Format("Recipe: {0}", (DisplayedNode as RecipeNode).BaseRecipe.FriendlyName);
                    tti.Text          += String.Format("\n--Base Time: {0}s", (DisplayedNode as RecipeNode).BaseRecipe.Time);
                    tti.Text          += String.Format("\n--Base Ingredients:");
                    foreach (var kvp in (DisplayedNode as RecipeNode).BaseRecipe.Ingredients)
                    {
                        tti.Text += String.Format("\n----{0} ({1})", kvp.Key.FriendlyName, kvp.Value.ToString());
                    }
                    tti.Text += String.Format("\n--Base Results:");
                    foreach (var kvp in (DisplayedNode as RecipeNode).BaseRecipe.Results)
                    {
                        tti.Text += String.Format("\n----{0} ({1})", kvp.Key.FriendlyName, kvp.Value.ToString());
                    }
                    if (Parent.ShowAssemblers)
                    {
                        tti.Text += String.Format("\n\nAssemblers:");
                        foreach (var kvp in assemblerBox.AssemblerList)
                        {
                            tti.Text += String.Format("\n----{0} ({1})", kvp.Key.assembler.FriendlyName, kvp.Value.ToString());
                            foreach (var Module in kvp.Key.modules.Where(m => m != null))
                            {
                                tti.Text += String.Format("\n------{0}", Module.FriendlyName);
                            }
                        }
                    }

                    if (Parent.Graph.SelectedAmountType == AmountType.FixedAmount)
                    {
                        tti.Text += String.Format("\n\nCurrent iterations: {0}", DisplayedNode.actualRate);
                    }
                    else
                    {
                        tti.Text += String.Format("\n\nCurrent Rate: {0}/{1}",
                                                  Parent.Graph.SelectedUnit == RateUnit.PerMinute ? DisplayedNode.actualRate / 60 : DisplayedNode.actualRate,
                                                  Parent.Graph.SelectedUnit == RateUnit.PerMinute ? "m" : "s");
                    }
                    Parent.AddTooltip(tti);
                }

                TooltipInfo helpToolTipInfo = new TooltipInfo();
                helpToolTipInfo.Text           = "Left click on this node to edit how fast it runs\nRight click to delete it";
                helpToolTipInfo.Direction      = Direction.None;
                helpToolTipInfo.ScreenLocation = new Point(10, 10);
                Parent.AddTooltip(helpToolTipInfo);
            }
        }