public MapWindow(User u) { InitializeComponent(); currentUser = u; map = u.getUserMap(); map.mw = this; if (map.PlacedLandmarks.Count > 0) { foreach (Landmark l in map.PlacedLandmarks) { Landmark ll = new Landmark(l.ID, l.Name, l.Description, l.Type, l.Tags, l.Climate, l.TStatus, l.Revenue, l.DoD, l.imagePath, l.EE, l.HAB, l.URB, l.position); LandmarkView sp = new LandmarkView(l.ID, l.position, l.imagePath); sp.Background = Brushes.White; Rectangle r = new Rectangle(); r.Width = 50; r.Height = 50; r.Stroke = Brushes.Black; r.StrokeThickness = 1; ImageBrush ib = new ImageBrush(); try { ib.ImageSource = new BitmapImage(new Uri(l.imagePath, UriKind.RelativeOrAbsolute)); } catch (Exception e) { ib.ImageSource = new BitmapImage(new Uri(@"./../../Images/missing_pic.jpg", UriKind.Relative)); } finally { r.Fill = ib; sp.Width = 54; sp.Height = 54; sp.MouseLeftButtonUp += map.doRightClick; sp.MouseLeftButtonDown += startDrag; r.MouseLeftButtonUp += map.doRightClick; r.MouseLeftButtonDown += startDrag; Goal.Children.Add(sp); Goal.Children.Add(r); tempLandmarks.Add(l); Canvas.SetLeft(sp, l.position.X - 2 /*+ (tbt.Width/2)*/); Canvas.SetTop(sp, l.position.Y - 2 /*+ (tbt.Height/2)*/); Canvas.SetLeft(r, sp.Position.X); Canvas.SetTop(r, sp.Position.Y); } } } notSaved = false; }
public ListTagsWindow(Map map) { InitializeComponent(); this.map = map; this.lw = null; tempLandmarks = new List <Landmark>(); foreach (Landmark l in this.map.getLandmarks()) { Landmark ll = new Landmark(l.ID, l.Name, l.Description, l.Type, l.Tags, l.Climate, l.TStatus, l.Revenue, l.DoD, l.imagePath, l.EE, l.HAB, l.URB, l.position); tempLandmarks.Add(ll); } ExistTags = map.getTags(); existAllTags = new ObservableCollection <Tag>(map.getTags()); MyTags = null; myAllTags = null; this.DataContext = this; }
private void Double_OnClick(object sender, MouseButtonEventArgs e) { if (lw == null) { lw = new LandmarkWindow(m, this); lw.Show(); Landmark l = (Landmark)dgrLandmarks.SelectedItem; lw.tempPosition = l.position; copy = l; lw.ID_Field.Text = l.ID; lw.Name_Field.Text = l.Name; lw.Description_Field.Text = l.Description; lw.ChosenType = l.Type; if (l.Type != null) { lw.Chosen_landmark_type.Text = l.Type.TypeView; } else { lw.Chosen_landmark_type.Text = ""; } lw.Climate_Field.SelectedItem = l.Climate; lw.TouristStatus_Field.SelectedItem = l.TStatus; lw.AnnualRevenue_Field.Text = l.Revenue.ToString(); lw.DateDiscovery.SelectedDate = DateTime.Parse(l.DoD); lw.Tags_Field.Text = l.TagView; lw.tags = l.getTags(); lw.Image_Path = l.imagePath; lw.Eco.IsChecked = l.EE; lw.Danger.IsChecked = l.HAB; lw.Habitated.IsChecked = l.URB; } else { lw.Topmost = true; // important lw.Topmost = false; // important lw.Focus(); // important } }
private void Delete_OnClick(object sender, RoutedEventArgs e) { Landmark l = (Landmark)dgrLandmarks.SelectedItem; if (l == null) { MessageBox.Show("Please select one of the landmarks.", "Selection Error", MessageBoxButton.OK, MessageBoxImage.Error); } else { AvailableLandmarks.Remove(l); AllLandmarks.Remove(l); foreach (var v in ancestor.tempLandmarks) { if (v.ID.Equals(l.ID)) { ancestor.tempLandmarks.Remove(v); foreach (var w in ancestor.Goal.Children) { LandmarkView lw = w as LandmarkView; if (lw != null) { if (lw.LandmarkId.Equals(l.ID)) { ancestor.Goal.Children.Remove(lw); break; } } } break; } } notSaved = true; } }
private void Grid_MouseMove(object sender, MouseEventArgs e) { Point mousePos = e.GetPosition(null); Vector diff = startPoint - mousePos; if (e.LeftButton == MouseButtonState.Pressed && (Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance || Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance)) { // Get the dragged ListViewItem Landmark l = (Landmark)((DataGrid)sender).SelectedItem; DataGridRow dgr = new DataGridRow(); dgr.Item = l; // Find the data behind the ListViewItem Landmark ll = new Landmark(l.ID, l.Name, l.Description, l.Type, l.Tags, l.Climate, l.TStatus, l.Revenue, l.DoD, l.imagePath, l.EE, l.HAB, l.URB, l.position); // Initialize the drag & drop operation DataObject dragData = new DataObject("landmark", ll); DragDrop.DoDragDrop(dgr, dragData, DragDropEffects.Move); } }
public ListTypesWindow(Map map) { InitializeComponent(); notSaved = false; this.map = map; tempLandmarks = new List <Landmark>(); foreach (Landmark l in this.map.getLandmarks()) { Landmark ll = new Landmark(l.ID, l.Name, l.Description, l.Type, l.Tags, l.Climate, l.TStatus, l.Revenue, l.DoD, l.imagePath, l.EE, l.HAB, l.URB, l.position); tempLandmarks.Add(ll); } this.lw = null; ptypes = new ObservableCollection <LandmarkType>(); ltypes = new ObservableCollection <LandmarkType>(); foreach (var t in this.map.getLandmarkTypes()) { ptypes.Add(t); ltypes.Add(t); } this.Select.IsEnabled = false; this.DataContext = this; }
private void OK_Click(object sender, RoutedEventArgs e) { if (!ID_Field.Text.Equals("") && !Name_Field.Text.Equals("") && DateDiscovery.SelectedDate != null && ChosenType != null) { List <Tag> ttags = tags.ToList <Tag>(); if (tempPosition == null) { l = new Landmark(ID_Field.Text, Name_Field.Text, Description_Field.Text, ChosenType, ttags, Climate_Field.SelectedValue.ToString(), TouristStatus_Field.SelectedValue.ToString(), Double.Parse(AnnualRevenue_Field.Text), DateDiscovery.SelectedDate.Value.Date.ToShortDateString(), _image, (bool)Eco.IsChecked, (bool)Danger.IsChecked, (bool)Habitated.IsChecked, new Point(-100, -100)); } else { l = new Landmark(ID_Field.Text, Name_Field.Text, Description_Field.Text, ChosenType, ttags, Climate_Field.SelectedValue.ToString(), TouristStatus_Field.SelectedValue.ToString(), Double.Parse(AnnualRevenue_Field.Text), DateDiscovery.SelectedDate.Value.Date.ToShortDateString(), _image, (bool)Eco.IsChecked, (bool)Danger.IsChecked, (bool)Habitated.IsChecked, (Point)tempPosition); } if (llw != null) { if (llw.AddALandmark(l)) { if (ltw1 != null) { ltw1.Close(); } if (ltw != null) { ltw.Close(); } LandmarkListWindow.notSaved = true; llw.Search.Text = ""; doNotShow = true; this.Close(); } else { MessageBox.Show("Landmark with entered code already exists. \nPlease try again.", "Landmark Error", MessageBoxButton.OK, MessageBoxImage.Error); } } else { if (map.addLandmark(l)) { if (ltw1 != null) { ltw1.Close(); } if (ltw != null) { ltw.Close(); } MapWindow.notSaved = true; doNotShow = true; this.Close(); } else { MessageBox.Show("Landmark with entered code already exists. \nPlease try again.", "Landmark Error", MessageBoxButton.OK, MessageBoxImage.Error); } } } else { MessageBox.Show("Please enter ID, name and select date of \ndiscovery and landmark type for your landmark", "Landmark Data Error", MessageBoxButton.OK, MessageBoxImage.Warning); } }
private void Goal_Drop(object sender, DragEventArgs e) { ToolBarTray tbt = e.Data.GetData("toolBarTray") as ToolBarTray; Point blockPos = e.GetPosition(Goal); if (tbt == null) { Landmark l = e.Data.GetData("landmark") as Landmark; l.position = blockPos; LandmarkView sp = new LandmarkView(l.ID, blockPos, l.imagePath); sp.Background = Brushes.White; Rectangle r = new Rectangle(); r.Width = 50; r.Height = 50; r.Stroke = Brushes.Black; r.StrokeThickness = 1; ImageBrush ib = new ImageBrush(); try { ib.ImageSource = new BitmapImage(new Uri(l.imagePath, UriKind.RelativeOrAbsolute)); } catch (Exception ee) { ib.ImageSource = new BitmapImage(new Uri(@"./../../Images/missing_pic.jpg", UriKind.Relative)); } finally { r.Fill = ib; sp.Width = 54; sp.Height = 54; Point foundPos = new Point(-100, -100); foreach (var v in Goal.Children) { var w = v as LandmarkView; if (w != null) { if (w.LandmarkId.Equals(sp.LandmarkId)) { Goal.Children.Remove(w); foundPos = new Point(w.Position.X, w.Position.Y); break; } } } if (foundPos != null) { foreach (var v in Goal.Children) { var w = v as Rectangle; if (w != null) { double x = Canvas.GetLeft(w); double y = Canvas.GetTop(w); if (x == foundPos.X && y == foundPos.Y) { Goal.Children.Remove(w); break; } } } } if (mapDragAddHandlers) { sp.MouseLeftButtonUp += map.doRightClick; sp.MouseLeftButtonDown += startDrag; r.MouseLeftButtonUp += map.doRightClick; r.MouseLeftButtonDown += startDrag; } Goal.Children.Add(sp); Goal.Children.Add(r); Canvas.SetLeft(sp, blockPos.X - 2 /*+ (tbt.Width/2)*/); Canvas.SetTop(sp, blockPos.Y - 2 /*+ (tbt.Height/2)*/); Canvas.SetLeft(r, blockPos.X); Canvas.SetTop(r, blockPos.Y); /* map.addLandmarkView(sp/*, tempLandmarks);*/ if (!mapDragAddHandlers) { foreach (var v in tempLandmarks) { //landmark je postavljen if (l.ID.Equals(v.ID)) { tempLandmarks.Remove(v); break; } } tempLandmarks.Add(l); LandmarkListWindow.notSaved = true; } else { foreach (var v in map.PlacedLandmarks) { //landmark je postavljen if (l.ID.Equals(v.ID)) { map.PlacedLandmarks.Remove(v); break; } } SelectedLandmark = null; mapDragAddHandlers = false; map.PlacedLandmarks.Add(l); notSaved = true; } } return; } Canvas.SetLeft(tbt, blockPos.X /*+ (tbt.Width/2)*/); Canvas.SetTop(tbt, blockPos.Y /*+ (tbt.Height/2)*/); unlocked = false; }
public bool AddALandmark(Landmark l) { Search.Text = ""; bool found = false; if (copy == null) { foreach (var tt in AvailableLandmarks) { if (tt.Equals(l)) { found = true; break; } } if (!found) { AvailableLandmarks.Add(l); AllLandmarks.Add(l); return(true); } return(false); } if (!copy.Equals(l)) { AvailableLandmarks.Remove(copy); AvailableLandmarks.Add(l); } bool Exists = false; for (int i = 0; i < ancestor.tempLandmarks.Count; i++)//each (var v in ancestor.tempLandmarks) { var v = ancestor.tempLandmarks[i]; if (v.ID.Equals(copy.ID)) { ancestor.tempLandmarks.Remove(v); Exists = true; for (int j = 0; j < ancestor.Goal.Children.Count; j++)//(var w in ancestor.Goal.Children) { LandmarkView vv = ancestor.Goal.Children[j] as LandmarkView; if (vv != null) { if (vv.LandmarkId.Equals(copy.ID)) { ancestor.Goal.Children.Remove(vv); ancestor.removeRectangle(vv.Position); LandmarkView sp = new LandmarkView(l.ID, l.position, l.imagePath); sp.Background = Brushes.White; Rectangle r = new Rectangle(); r.Width = 50; r.Height = 50; r.Stroke = Brushes.Black; r.StrokeThickness = 1; ImageBrush ib = new ImageBrush(); ib.ImageSource = new BitmapImage(new Uri(l.imagePath, UriKind.RelativeOrAbsolute)); r.Fill = ib; sp.Width = 54; sp.Height = 54; ancestor.Goal.Children.Add(sp); ancestor.Goal.Children.Add(r); //sp.MouseLeftButtonUp += ancestor.map.doRightClick; //r.MouseLeftButtonUp += ancestor.map.doRightClick; Canvas.SetLeft(sp, sp.Position.X - 2 /*+ (tbt.Width/2)*/); Canvas.SetTop(sp, sp.Position.Y - 2 /*+ (tbt.Height/2)*/); Canvas.SetLeft(r, sp.Position.X); Canvas.SetTop(r, sp.Position.Y); break; } } } break; } } if (Exists) { ancestor.tempLandmarks.Add(l); } return(true); }