コード例 #1
0
ファイル: NodeElement.cs プロジェクト: Stonemuzzle/Foreman
        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))));
            }
        }
コード例 #2
0
        public void Update()
        {
            foreach (AssemblerIconElement element in SubElements.OfType <AssemblerIconElement>().ToList())
            {
                if (!AssemblerList.Keys.Contains(element.DisplayedMachine))
                {
                    SubElements.Remove(element);
                }
            }

            foreach (var kvp in AssemblerList)
            {
                if (!SubElements.OfType <AssemblerIconElement>().Any(aie => aie.DisplayedMachine == kvp.Key))
                {
                    SubElements.Add(new AssemblerIconElement(kvp.Key, kvp.Value, Parent));
                }
            }

            int y          = (int)(Height / Math.Ceiling(AssemblerList.Count / 2d));
            int widthOver2 = this.Width / 2;

            int i = 0;

            foreach (AssemblerIconElement element in SubElements.OfType <AssemblerIconElement>())
            {
                element.DisplayedNumber = AssemblerList[element.DisplayedMachine];

                if (i % 2 == 0)
                {
                    element.X = widthOver2 - element.Width;
                }
                else
                {
                    element.X = widthOver2;
                }
                element.Y = (int)Math.Floor(i / 2d) * y;

                if (AssemblerList.Count == 1)
                {
                    element.X = (Width - element.Width) / 2;
                }
                else if (i == AssemblerList.Count - 1 && AssemblerList.Count % 2 != 0)
                {
                    element.X = widthOver2 - (element.Width / 2);
                }

                i++;
            }
        }
コード例 #3
0
ファイル: NodeElement.cs プロジェクト: Stonemuzzle/Foreman
 public override bool ContainsPoint(Point point)
 {
     if (new Rectangle(0, 0, Width, Height).Contains(point.X, point.Y))
     {
         return(true);
     }
     foreach (ItemTab tab in SubElements.OfType <ItemTab>())
     {
         if (tab.bounds.Contains(point))
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #4
0
ファイル: NodeElement.cs プロジェクト: Stonemuzzle/Foreman
        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();
                }
            }
        }
コード例 #5
0
ファイル: NodeElement.cs プロジェクト: Stonemuzzle/Foreman
        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);
                }
            }
        }
コード例 #6
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);
            }
        }