public void Clear()
 {
     LinkDrawings.Clear();
     PlanetDrawings.Clear();
     canvas.Children.Clear();
     GalaxyUpdated();
 }
Esempio n. 2
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);
        }
Esempio n. 3
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();
        }
Esempio n. 4
0
 public void Clear()
 {
     if (LinkDrawings != null)
     {
         LinkDrawings.Clear();
     }
     if (PlanetDrawings != null)
     {
         PlanetDrawings.Clear();
     }
     canvas.Children.Clear();
     GalaxyUpdated();
 }
        public void GalaxyUpdated()
        {
            //if (WarningList != null) {
            //    WarningList.ItemsSource = galaxy.GetWarnings().Select(w => new ListBoxItem {IsEnabled = false, Content = w}).ToArray();
            //}
            if (WarningList == null)
            {
                return;
            }
            WarningList.Items.Clear();
            var planetCounts = PlanetDrawings.ToDictionary(p => p, p => 0);

            foreach (var l in LinkDrawings)
            {
                planetCounts[l.Planet1]++;
                planetCounts[l.Planet2]++;
            }
            if (MapCount < PlanetCount)
            {
                WarningList.Items.Add(new ListBoxItem {
                    Background = Brushes.Red, Content = String.Format("More planets than maps ({0} > {1})", PlanetCount, MapCount)
                });
            }
            foreach (var kvp in planetCounts)
            {
                if (kvp.Value == 0)
                {
                    var item = new ListBoxItem {
                        Background = Brushes.Red, Content = (kvp.Key.PlanetName ?? "Planet") + " has no link"
                    };
                    WarningList.Items.Add(item);
                    var planet = kvp.Key;
                    item.MouseUp += (s, e) => planet.Grow();
                }
                else if (kvp.Value == 2)
                {
                    var item = new ListBoxItem {
                        Content = (kvp.Key.PlanetName ?? "Planet") + " has only two links"
                    };
                    var planet = kvp.Key;
                    item.MouseUp += (s, e) => planet.Grow();
                    WarningList.Items.Add(item);
                }
            }
            WarningList.Items.Refresh();
            PropertyChanged(this, new PropertyChangedEventArgs("PlanetCount"));
        }
        public Galaxy ToGalaxy()
        {
            var gal       = new Galaxy();
            int id        = 0;
            var planetIDs = PlanetDrawings.ToDictionary(
                d => d,
                d =>
            {
                var temp = id++;
                return(temp);
            });

            gal.Planets = PlanetDrawings.Select(
                d => new Planet(planetIDs[d],
                                (float)(Canvas.GetLeft(d) / imageSource.Width),
                                (float)(Canvas.GetTop(d) / imageSource.Height))).ToList();
            gal.Links    = LinkDrawings.Select(d => new Link(planetIDs[d.Planet1], planetIDs[d.Planet2])).ToList();
            gal.MapNames = ToLines(MapNames).ToList();
            return(gal);
        }
Esempio n. 7
0
        public void GalaxyUpdated()
        {
            //if (WarningList != null) {
            //    WarningList.ItemsSource = galaxy.GetWarnings().Select(w => new ListBoxItem {IsEnabled = false, Content = w}).ToArray();
            //}
            if (WarningList == null)
            {
                return;
            }
            WarningList.Items.Clear();
            var planetCounts = PlanetDrawings.ToDictionary(p => p, p => 0);

            foreach (var l in LinkDrawings)
            {
                planetCounts[l.Planet1]++;
                planetCounts[l.Planet2]++;
            }
            if (MapCount < PlanetCount)
            {
                WarningList.Items.Add(new ListBoxItem
                {
                    Background = Brushes.Red, Content = String.Format("More planets than maps ({0} > {1})", PlanetCount, MapCount)
                });
            }
            foreach (var kvp in planetCounts)
            {
                if (kvp.Value == 0)
                {
                    var item = new ListBoxItem {
                        Background = Brushes.Red, Content = (kvp.Key.Planet.Name ?? "Planet") + " has no link"
                    };
                    WarningList.Items.Add(item);
                    var planet = kvp.Key;
                    item.MouseUp += (s, e) => planet.Grow();
                }
            }


            foreach (var dupMap in PlanetDrawings.GroupBy(x => x.Planet.MapResourceID).Where(x => x.Count() > 1))
            {
                var         p = dupMap.First();
                ListBoxItem item;
                if (p.Planet.MapResourceID == null)
                {
                    item = new ListBoxItem {
                        Background = Brushes.Red, Content = string.Format("{0} has no map", (p.Planet.Name ?? "Planet"))
                    }
                }
                ;
                else if (p.Planet.Resource == null)
                {
                    item = new ListBoxItem {
                        Background = Brushes.Red, Content = string.Format("{0} has duplicate map", (p.Planet.Name ?? "Planet"))
                    }
                }
                ;
                else
                {
                    item = new ListBoxItem {
                        Background = Brushes.Red, Content = string.Format("{0} has duplicate map ({1})", (p.Planet.Name ?? "Planet"), p.Planet.Resource.InternalName)
                    }
                };
                var planet = p;
                item.MouseUp += (s, e) => planet.Grow();
                WarningList.Items.Add(item);
            }


            foreach (var p in PlanetDrawings.Where(x => x.Planet.PlanetStructures == null || !x.Planet.PlanetStructures.Any()))
            {
                var item = new ListBoxItem {
                    Content = (p.Planet.Name ?? "Planet") + " has no structures"
                };
                var planet = p;
                item.MouseUp += (s, e) => planet.Grow();
                WarningList.Items.Add(item);
            }
            WarningList.Items.Refresh();
            PropertyChanged(this, new PropertyChangedEventArgs("PlanetCount"));
            PropertyChanged(this, new PropertyChangedEventArgs("MapCount"));
        }