private ContextMenu ConnectRecipeMenu(ItemNode from) { ContextMenu cm = new ContextMenu(); List <Recipe> recipes; if (from.input) { recipes = rh.GetRecipesProducing(from.recipeItem.item.Name); } else { recipes = rh.GetRecipesUsing(from.recipeItem.item.Name); } foreach (Recipe r in recipes) { MenuItem mi = new MenuItem(); mi.Icon = new Image { Source = new BitmapImage(new Uri(r.Outputs[0].item.ImageSource, UriKind.Relative)) }; TextBlock tb = new TextBlock(); string str = string.Join(" + ", r.inputs.Select(ri => $"{ri.item.Name}({ri.count})")); str += " => "; str += string.Join(" + ", r.Outputs.Select(ri => $"{ri.item.Name}({ri.count})")); tb.Text = str; mi.Header = tb; mi.Click += delegate(object sender, RoutedEventArgs e) { RecipeContextMenu_Click(sender, e, r, new Point(ConnectionLine.X2, ConnectionLine.Y2), from); }; cm.Items.Add(mi); } return(cm); }
public void StartLineDraw(ItemNode from) { drawLine = true; ItemBeingConnected = from; ConnectionLine = new Line(); ConnectionLine.Stroke = Brushes.Black; Canvas.SetZIndex(ConnectionLine, -1); canvas.Children.Add(ConnectionLine); }
public void DeleteConnections(ItemNode inode) { for (int i = 0; i < connections.Count(); i++) { if (connections[i].from == inode || connections[i].to == inode) { canvas.Children.Remove(connections[i].line); connections.Remove(connections[i]); } } }
public static List <ItemNode> GetConnected(ItemNode from) { List <ItemNode> connected = new List <ItemNode>(); foreach (Connection c in ((MainWindow)Application.Current.MainWindow).connections) { if (c.from == from) { connected.Add(c.to); } if (c.to == from) { connected.Add(c.from); } } return(connected); }
public Connection(ItemNode _from, ItemNode _to, Line _line, Canvas canvas) { from = _from; to = _to; line = _line; line.Stroke = Brushes.Black; Canvas.SetZIndex(line, -1); Point p = from.TranslatePoint(new Point(0, 0), canvas); line.X1 = p.X + 25; line.Y1 = p.Y + 25; Point pp = to.TranslatePoint(new Point(0, 0), canvas); line.X2 = pp.X + 25; line.Y2 = pp.Y + 25; canvas.Children.Add(line); }
public RecipeNode(Recipe _recipe, Canvas _canvas, Double _zoom) { InitializeComponent(); recipe = _recipe; canvas = _canvas; zoom = _zoom; foreach (RecipeItem item in recipe.inputs) { ItemNode inode = new ItemNode(item, true); inPanel.Children.Add(inode); } foreach (RecipeItem item in recipe.Outputs) { ItemNode inode = new ItemNode(item, false); outPanel.Children.Add(inode); } recipeText.Text = recipe.name; ((MainWindow)Application.Current.MainWindow).UpdateLines(); }
private void RecipeContextMenu_Click(object sender, RoutedEventArgs e, Recipe recipe, Point pos, ItemNode from) { RecipeNode rn = new RecipeNode(recipe, canvas, zoom); canvas.Children.Add(rn); Canvas.SetLeft(rn, pos.X - 125); Canvas.SetTop(rn, pos.Y - 75); foreach (ItemNode to in rn.inPanel.Children) { if (to.recipeItem.item.Name == from.recipeItem.item.Name) { connections.Add(new Connection(from, to, new Line(), canvas)); } } foreach (ItemNode to in rn.outPanel.Children) { if (to.recipeItem.item.Name == from.recipeItem.item.Name) { connections.Add(new Connection(from, to, new Line(), canvas)); } } UpdateLines(); UpdateRates(); }