void OrderMouseUp(object sender, MouseButtonEventArgs eventArgs) { if (eventArgs.ChangedButton == MouseButton.Right) { OrderIcon icon = (OrderIcon)eventArgs.Source; IOrder order = (IOrder)icon.DataContext; action.Orders.Remove(order); } }
void UpdateLines() { foreach (var child in canvas.Children.Cast <UIElement>().Where(e => !(e is Border)).ToArray()) { canvas.Children.Remove(child); } foreach (var order in action.Orders.OfType <Positionable>()) { var icon = new OrderIcon(); icon.DataContext = order; icon.Bind(Canvas.LeftProperty, order, "X", BindingMode.OneWay, new TranslateConverter(), -4); icon.Bind(Canvas.TopProperty, order, "Y", BindingMode.OneWay, new TranslateConverter(), -2); Canvas.SetZIndex(icon, 10); canvas.Children.Add(icon); icon.MouseDown += OrderMouseDown; icon.MouseUp += OrderMouseUp; } var firstPositionable = action.Orders.OfType <Positionable>().FirstOrDefault(); if (firstPositionable == null) { return; } var createUnitsActions = trigger.Logic.OfType <CreateUnitsAction>(); var previousActions = createUnitsActions.Where(a => trigger.Logic.IndexOf(a) < trigger.Logic.IndexOf(action)); var previousUnits = previousActions.SelectMany(a => a.Units).ToArray(); var firstUnits = action.Groups.Any() ? previousUnits.Where(u => u.Groups.Any(t => action.Groups.Contains(t))) : previousUnits; foreach (var unit in firstUnits) { NewBoundLine(unit, firstPositionable); } // draw lines from all affected units to the first order var positionables = action.Orders.OfType <Positionable>().ToArray(); // draw lines between the orders for (var i = 0; i + 1 < positionables.Length; i++) { NewBoundLine(positionables[i], positionables[i + 1]); } }