void UserControl_Loaded(object sender, RoutedEventArgs e) { Region = (Region)DataContext; foreach (var unit in MainWindow.Instance.Mission.AllUnits) { UnitIcon.PlaceSimplifiedUnit(canvas, unit); } foreach (var area in Region.Areas) { if (area is Cylinder) { var cylinder = (Cylinder)area; AddCylinder(cylinder); } else if (area is RectangularArea) { AddRectangle((RectangularArea)area); } else { throw new Exception("Unexpected Area"); } } }
void UserControl_Loaded(object sender, RoutedEventArgs e) { condition = (UnitsAreInAreaCondition)MainWindow.Instance.CurrentLogic; playerList.BindCollection(condition.Players); groupsList.BindCollection(condition.Groups); foreach (var unit in MainWindow.Instance.Mission.AllUnits) { UnitIcon.PlaceSimplifiedUnit(canvas, unit); } foreach (var area in condition.Areas) { if (area is Cylinder) { var cylinder = (Cylinder)area; AddCylinder(cylinder); } else if (area is RectangularArea) { AddRectangle((RectangularArea)area); } else { throw new Exception("Unexpected Area"); } } }
void MarkerPointCanvas_Loaded(object sender, RoutedEventArgs e) { var currentLogic = MainWindow.Instance.CurrentLogic; if (currentLogic is MarkerPointAction) { var flagPole = new Ellipse { Height = 20, Width = 20, Stroke = Brushes.Red, StrokeThickness = 5 }; var action = (MarkerPointAction)currentLogic; var markerCanvas = (Canvas)e.Source; markerCanvas.Children.Add(flagPole); foreach (var unit in MainWindow.Instance.Mission.AllUnits) { UnitIcon.PlaceSimplifiedUnit(markerCanvas, unit); } Action refreshPosition = delegate { Canvas.SetLeft(flagPole, action.X - flagPole.Width / 2); Canvas.SetTop(flagPole, action.Y - flagPole.Height / 2); }; refreshPosition(); markerCanvas.MouseDown += (s, ea) => { var mousePos = ea.GetPosition(markerCanvas); action.X = mousePos.X; action.Y = mousePos.Y; refreshPosition(); }; markerCanvas.Unloaded += (s, ea) => markerCanvas.Children.Clear(); } else if (currentLogic is SetCameraPointTargetAction) { var camera = new Ellipse { Height = 20, Width = 20, Stroke = Brushes.Red, StrokeThickness = 5 }; var action = (SetCameraPointTargetAction)currentLogic; var markerCanvas = (Canvas)e.Source; markerCanvas.Children.Add(camera); foreach (var unit in MainWindow.Instance.Mission.AllUnits) { UnitIcon.PlaceSimplifiedUnit(markerCanvas, unit); } Action refreshPosition = delegate { Canvas.SetLeft(camera, action.X - camera.Width / 2); Canvas.SetTop(camera, action.Y - camera.Height / 2); }; refreshPosition(); markerCanvas.MouseDown += (s, ea) => { var mousePos = ea.GetPosition(markerCanvas); action.X = mousePos.X; action.Y = mousePos.Y; refreshPosition(); }; } }
void RemoveUnitIcon(UnitIcon unitIcon) { BindingOperations.ClearBinding(unitIcon, Canvas.LeftProperty); BindingOperations.ClearBinding(unitIcon, Canvas.TopProperty); unitIcon.MouseDown -= unitIcon_MouseDown; unitIcon.UnitRequestedDelete -= unitIcon_UnitRequestedDelete; unitIcon.UnitRequestedSetGroups -= unitIcon_UnitRequestedSetGroups; unitIcon.UnitRequestedSetOwner -= unitIcon_UnitRequestedSetOwner; unitCanvas.Children.Remove(unitIcon); unitIcons.Remove(unitIcon); }
void PlaceUnitIcon(UnitStartInfo unit) { var unitIcon = new UnitIcon(); unitIcon.DataContext = unit; unitIcon.Bind(Canvas.LeftProperty, unit, "X", BindingMode.OneWay, new TranslateConverter(), -8); unitIcon.Bind(Canvas.TopProperty, unit, "Y", BindingMode.OneWay, new TranslateConverter(), -8); unitIcon.MouseDown += unitIcon_MouseDown; unitIcon.MouseUp += unitIcon_MouseUp; unitIcon.UnitRequestedDelete += unitIcon_UnitRequestedDelete; unitIcon.UnitRequestedSetGroups += unitIcon_UnitRequestedSetGroups; unitIcon.UnitRequestedSetOwner += unitIcon_UnitRequestedSetOwner; unitCanvas.Children.Add(unitIcon); unitIcons.Add(unitIcon); }
void CreateUnitsPane_Loaded(object sender, RoutedEventArgs e) { action = (CreateUnitsAction)MainWindow.Instance.CurrentLogic; var missionUnits = MainWindow.Instance.Mission.AllUnits.ToArray(); var triggerUnits = action.Units.ToArray(); foreach (var unit in missionUnits) { if (triggerUnits.Contains(unit)) { PlaceUnitIcon(unit); } else { UnitIcon.PlaceSimplifiedUnit(unitCanvas, unit, true); } } }
private void UserControl_Loaded(object sender, RoutedEventArgs e) { action = (GiveOrdersAction)MainWindow.Instance.CurrentLogic; trigger = MainWindow.Instance.Mission.FindLogicOwner(action); var missionUnits = MainWindow.Instance.Mission.AllUnits.ToArray(); var triggerUnits = trigger.AllUnits.ToArray(); foreach (var unit in missionUnits) { UnitIcon.PlaceSimplifiedUnit(canvas, unit, !triggerUnits.Contains(unit)); } UpdateLines(); action.Groups.CollectionChanged += (s, ea) => UpdateLines(); trigger.Logic.CollectionChanged += (s, ea) => UpdateLines(); NotifyCollectionChangedEventHandler handler = (s, ea) => UpdateLines(); action.Orders.CollectionChanged += handler; canvas.Unloaded += (s, ea) => action.Orders.CollectionChanged -= handler; }