void GenerateItems() { ActiveItem = null; SolvedItems.Clear(); this.isLoading = true; AllowSaveActions = false; IEnumerable <MapPathInfo> pathInfos = this.puzzleGenerator.GeneratePathInfos(); ObservableCollection <MapItem> items = new ObservableCollection <MapItem>(); foreach (MapPathInfo pathInfo in pathInfos) { MapPath copiedPath = (MapPath)pathInfo.Path.Clone(); copiedPath.Attributes.Add(new MapItemAttribute() { Name = "RealLocation", Type = typeof(GeoPoint), Value = pathInfo.RealLocation }); Vector delta = CoordPointToScreenPoint(pathInfo.GameCenter) - CoordPointToScreenPoint(pathInfo.RealCenter); ActiveItems = new ObservableCollection <MapItem>() { copiedPath }; TranslateItemsCommand.Execute(delta); items.Add(copiedPath); } Items = items; ZoomToRegion.Execute(new object[] { new GeoPoint(15, -180), new GeoPoint(-62, -45), 0.05 }); AllowSaveActions = true; this.isLoading = false; }
public void OnItemEdited(IEnumerable <MapItem> items) { if (this.isLoading || this.isEditing) { return; } foreach (MapPath item in items) { GeoPoint realLocation = (GeoPoint)item.Attributes["RealLocation"].Value; GeoPoint currentLocation = GetItemLocation(item); Point desiredLocation = CoordPointToScreenPoint(realLocation); Point actualLocation = CoordPointToScreenPoint(currentLocation); if (CalculateDistance(desiredLocation, actualLocation) < 20) { item.CanMove = false; Vector delta = desiredLocation - actualLocation; ActiveItems = new ObservableCollection <MapItem>() { item }; this.isEditing = true; TranslateItemsCommand.Execute(delta); this.isEditing = false; MoveItemToSolveLayer(item); ClearSavedActionsCommand.Execute(null); } } }