void canvas_PreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            var planet = e.Source as PlanetDrawing;

            if (e.ChangedButton == MouseButton.Right && planet != null)
            {
                var diag = new PlanetDialog(planet, galaxyDrawing.Maps, galaxyDrawing.StructureTypes);
                diag.ShowDialog();
                e.Handled = true;
            }
            else
            {
                if (Mode == ToolMode.Delete && !isDragging)
                {
                    startPoint = e.GetPosition(canvas);
                    canvas.CaptureMouse();
                    isDragging   = true;
                    selectionBox = new Rectangle
                    {
                        Height          = 0,
                        Width           = 0,
                        Stroke          = Brushes.LightGreen,
                        StrokeThickness = 1,
                        StrokeDashArray = new DoubleCollection(new[] { 2.0, })
                    };
                    Canvas.SetLeft(selectionBox, startPoint.X);
                    Canvas.SetTop(selectionBox, startPoint.Y);
                    canvas.Children.Add(selectionBox);
                    e.Handled = true;
                }
                else if (planet != null)
                {
                    if (!isDragging)
                    {
                        startPoint = e.GetPosition(canvas);
                        canvas.CaptureMouse();
                        isDragging            = true;
                        selectedPlanet        = planet;
                        planet.IsHighlighted  = true;
                        selectedPlanetOrigins = planet.Position;
                        if (Mode == ToolMode.Draw)
                        {
                            dragLine = new Line
                            {
                                Stroke          = Brushes.LightGreen,
                                StrokeThickness = 1.5,
                                X1 = selectedPlanetOrigins.X,
                                Y1 = selectedPlanetOrigins.Y,
                                X2 = startPoint.X,
                                Y2 = startPoint.Y,
                                SnapsToDevicePixels = true,
                                StrokeEndLineCap    = PenLineCap.Round
                            };
                            canvas.Children.Add(dragLine);
                        }
                    }
                    e.Handled = true;
                }
            }
        }
Exemplo n.º 2
0
        public PlanetDialog(PlanetDrawing pd, IEnumerable <Resource> maps, IEnumerable <StructureType> structureTypes)
        {
            this.pd     = pd;
            this.planet = pd.Planet;
            InitializeComponent();
            lbName.Text = planet.Name;
            maps        = maps.OrderBy(x => x.MetadataName);
            foreach (var mn in maps)
            {
                cbMaps.Items.Add(new ComboBoxItem()
                {
                    Content = mn.InternalName, Tag = mn.ResourceID, IsSelected = mn.ResourceID == this.planet.MapResourceID
                });
            }
            if (this.planet.MapResourceID == null)
            {
                cbMaps.SelectedIndex = new Random().Next(cbMaps.Items.Count);
            }

            foreach (var s in structureTypes)
            {
                lbStructures.Items.Add(new ListBoxItem()
                {
                    Content = s.Name, Tag = s.StructureTypeID, IsSelected = planet.PlanetStructures.Any(y => y.StructureTypeID == s.StructureTypeID)
                });
            }
        }
Exemplo n.º 3
0
 public LinkDrawing(PlanetDrawing planet1, PlanetDrawing planet2)
 {
     Planet1 = planet1;
     Planet2 = planet2;
     {
         SetBinding(X1Property, new Binding("Planet1.Position.X")
         {
             Source = this
         });
         SetBinding(Y1Property, new Binding("Planet1.Position.Y")
         {
             Source = this
         });
         SetBinding(X2Property, new Binding("Planet2.Position.X")
         {
             Source = this
         });
         SetBinding(Y2Property, new Binding("Planet2.Position.Y")
         {
             Source = this
         });
     }
     Stroke          = Brushes.LightBlue;
     StrokeThickness = 1;
 }
		public PlanetDrawing AddPlanet(Point pos, string name)
		{
			var d = new PlanetDrawing(pos, name);
			PlanetDrawings.Add(d);
			canvas.Children.Add(d);
			Panel.SetZIndex(d, 1);
			GalaxyUpdated();
			return d;
		}
		public void AddLink(PlanetDrawing planet1, PlanetDrawing planet2)
		{
			if (planet1 == planet2 && LinkDrawings.Any(l => (l.Planet1 == planet1 && l.Planet2 == planet2) || (l.Planet2 == planet1 && l.Planet1 == planet2))) return;
			var d = new LinkDrawing(planet1, planet2);
			LinkDrawings.Add(d);
			canvas.Children.Add(d);
			Panel.SetZIndex(d, 2);
			GalaxyUpdated();
		}
Exemplo n.º 6
0
        public PlanetDrawing AddPlanet(Point pos, string name)
        {
            var d = new PlanetDrawing(pos, name);

            PlanetDrawings.Add(d);
            canvas.Children.Add(d);
            Panel.SetZIndex(d, 1);
            GalaxyUpdated();
            return(d);
        }
Exemplo n.º 7
0
        public void RemovePlanet(PlanetDrawing planet)
        {
            var links = LinkDrawings.FindAll(l => l.Planet1 == planet || l.Planet2 == planet);

            links.ForEach(l => LinkDrawings.Remove(l));
            links.ForEach(canvas.Children.Remove);
            PlanetDrawings.Remove(planet);
            canvas.Children.Remove(planet);
            GalaxyUpdated();
        }
Exemplo n.º 8
0
        public void AddLink(PlanetDrawing planet1, PlanetDrawing planet2)
        {
            if (planet1 == planet2 && LinkDrawings.Any(l => (l.Planet1 == planet1 && l.Planet2 == planet2) || (l.Planet2 == planet1 && l.Planet1 == planet2)))
            {
                return;
            }
            var d = new LinkDrawing(planet1, planet2);

            LinkDrawings.Add(d);
            canvas.Children.Add(d);
            Panel.SetZIndex(d, 2);
            GalaxyUpdated();
        }
		public PlanetDialog(PlanetDrawing pd, IEnumerable<Resource> maps, IEnumerable<StructureType> structureTypes)
		{
			this.pd = pd;
			this.planet = pd.Planet;
			InitializeComponent();
			lbName.Text = planet.Name;
            maps = maps.OrderBy(x => x.MetadataName);
			foreach (var mn in maps) cbMaps.Items.Add(new ComboBoxItem() { Content = mn.InternalName, Tag = mn.ResourceID, IsSelected = mn.ResourceID == this.planet.MapResourceID });

			foreach (var s in structureTypes)
			{
				lbStructures.Items.Add(new ListBoxItem() {Content =  s.Name, Tag = s.StructureTypeID, IsSelected = planet.PlanetStructures.Any(y=>y.StructureTypeID==s.StructureTypeID) });
			}
		}
Exemplo n.º 10
0
 public LinkDrawing(PlanetDrawing planet1, PlanetDrawing planet2)
  {
      Planet1 = planet1;
      Planet2 = planet2;
      {
          SetBinding(X1Property, new Binding("Planet1.Position.X") { Source = this });
          SetBinding(Y1Property, new Binding("Planet1.Position.Y") { Source = this });
          SetBinding(X2Property, new Binding("Planet2.Position.X") { Source = this });
          SetBinding(Y2Property, new Binding("Planet2.Position.Y") { Source = this });
      }
     Stroke = Brushes.LightBlue;
     StrokeThickness = 1;
  }
		public void RemovePlanet(PlanetDrawing planet)
		{
			var links = LinkDrawings.FindAll(l => l.Planet1 == planet || l.Planet2 == planet);
			links.ForEach(l => LinkDrawings.Remove(l));
			links.ForEach(canvas.Children.Remove);
			PlanetDrawings.Remove(planet);
			canvas.Children.Remove(planet);
			GalaxyUpdated();
		}
 void canvas_PreviewMouseDown(object sender, MouseButtonEventArgs e)
 {
     var planet = e.Source as PlanetDrawing;
     if (Mode == ToolMode.Delete && !isDragging) {
         startPoint = e.GetPosition(canvas);
         canvas.CaptureMouse();
         isDragging = true;
         selectionBox = new Rectangle
         {
             Height = 0,
             Width = 0,
             Stroke = Brushes.LightGreen,
             StrokeThickness = 1,
             StrokeDashArray = new DoubleCollection(new[] { 2.0, })
         };
         Canvas.SetLeft(selectionBox, startPoint.X);
         Canvas.SetTop(selectionBox, startPoint.Y);
         canvas.Children.Add(selectionBox);
         e.Handled = true;
     } else if (planet != null) {
         if (!isDragging) {
             startPoint = e.GetPosition(canvas);
             canvas.CaptureMouse();
             isDragging = true;
             selectedPlanet = planet;
             planet.IsHighlighted = true;
             selectedPlanetOrigins = planet.Position;
             if (Mode == ToolMode.Draw) {
                 dragLine = new Line
                 {
                     Stroke = Brushes.LightGreen,
                     StrokeThickness = 1.5,
                     X1 = selectedPlanetOrigins.X,
                     Y1 = selectedPlanetOrigins.Y,
                     X2 = startPoint.X,
                     Y2 = startPoint.Y,
                     SnapsToDevicePixels = true,
                     StrokeEndLineCap = PenLineCap.Round
                 };
                 canvas.Children.Add(dragLine);
             }
         }
         e.Handled = true;
     }
 }