Esempio n. 1
0
		void DoClick(MouseEventArgs e)
		{
			var locationF = new PointF((float)e.Location.X/PictureBox.Width, (float)e.Location.Y/PictureBox.Height);
			var b = MainForm.Instance.lastClicked;
			if (b == null || b == MainForm.Instance.btn_SelectPlanet) {
				if (!GalaxyMap.Instance.PlanetDrawings.Any()) {
					return;
				}
				var planetDrawing = locationF.FindClosest(GalaxyMap.Instance.PlanetDrawings);
				selectedPlanetDrawing = planetDrawing;
				Redraw();
				if (planetDrawing.Map == null) {
					return;
				}
				var myPlanet = planetDrawing.Planet.OwnerName == Program.AuthInfo.Login;
				new PlanetInfoForm(
					planetDrawing, myPlanet && !GalaxyMap.Instance.Galaxy.GetPlayer(Program.AuthInfo.Login).HasChangedMap, myPlanet).
					Show();
				return;
			}
			if (b == MainForm.Instance.btn_AddPlanet) {
				AddPlanet(locationF);
			} else if (b == MainForm.Instance.btn_RemovePlanet) {
				RemovePlanet(locationF);
			} else if (b == MainForm.Instance.btn_AddLink) {
				AddLink(locationF);
			} else if (b == MainForm.Instance.btn_RemoveLink) {
				RemoveLink(locationF);
			}
			GalaxyMap.Instance.Galaxy.CheckIntegrity();
		}
Esempio n. 2
0
		void RemoveLink(PointF locationF)
		{
			var g = GalaxyMap.Instance.Galaxy;
			if (g.Planets.Count < 2) {
				return;
			}
			if (selectedPlanetDrawing == null) {
				selectedPlanetDrawing = locationF.FindClosest(GalaxyMap.Instance.PlanetDrawings);
				Redraw();
			} else {
				var planetDrawing = locationF.FindClosest(GalaxyMap.Instance.PlanetDrawings);
				var link =
					GalaxyMap.Instance.Galaxy.Links.SingleOrDefault(
						l => g.GetPlanets(l).Contains(planetDrawing.Planet) && g.GetPlanets(l).Contains(selectedPlanetDrawing.Planet));
				if (link != null) {
					g.Links.Remove(link);
				}
				selectedPlanetDrawing = null;
				Redraw();
			}
		}
Esempio n. 3
0
		void AddLink(PointF locationF)
		{
			if (GalaxyMap.Instance.PlanetDrawings.Count < 2) {
				return;
			}
			if (selectedPlanetDrawing == null) {
				selectedPlanetDrawing = locationF.FindClosest(GalaxyMap.Instance.PlanetDrawings);
				Redraw();
			} else {
				var planetDrawing = locationF.FindClosest(GalaxyMap.Instance.PlanetDrawings);
				if (
					!GalaxyMap.Instance.Galaxy.Links.Any(
					 	l =>
					 	GalaxyMap.Instance.Galaxy.GetPlanets(l).Contains(planetDrawing.Planet) &&
					 	GalaxyMap.Instance.Galaxy.GetPlanets(l).Contains(selectedPlanetDrawing.Planet))) {
					var link = new Link(selectedPlanetDrawing.Planet.ID, planetDrawing.Planet.ID);
					GalaxyMap.Instance.Galaxy.Links.Add(link);
					selectedPlanetDrawing = null;
					Redraw();
				}
			}
		}
Esempio n. 4
0
		void RemovePlanet(PointF locationF)
		{
			if (!GalaxyMap.Instance.PlanetDrawings.Any()) {
				return;
			}
			var planetDrawing = locationF.FindClosest(GalaxyMap.Instance.PlanetDrawings);
			if (DialogResult.Yes ==
			    MessageBox.Show(
			    	"Do you want to delete planet " + planetDrawing.Planet.Name ?? "Unnamed" + "?",
			    	"Confirm Delete",
			    	MessageBoxButtons.YesNo)) {
				GalaxyMap.Instance.Galaxy.Planets.Remove(planetDrawing.Planet);
				GalaxyMap.Instance.PlanetDrawings.Remove(planetDrawing);
				GalaxyMap.Instance.Galaxy.Links.RemoveAll(l => l.PlanetIDs.Contains(planetDrawing.Planet.ID));
			    selectedPlanetDrawing = null;
			    Program.MainForm.Text = GalaxyMap.Instance.Galaxy.Planets.Count().ToString();
				Redraw();
			}
		}