/// <summary> /// Copies a bitmap to the correct file directory. /// </summary> /// <returns>The string of the location of new bitmap relative to the project directory.</returns> /// <exception cref="ArgumentException"></exception> public static string SaveBitmap(ObjectOfAlbertrizal obj, string fileNameAddition) { try { FileDialog dialog = new FileDialog(FileDialog.DialogOptions.Open, "PNG File | *.png"); string fullPath = CopyImageToProjectDirectory(dialog.GetPath(), fileNameAddition, obj); string relativePath = GetRelativePath(fullPath, GameBase.CurrentMapLocation); return(relativePath); } catch (ArgumentNullException) { throw new ArgumentException(); } catch (IOException e) { MessageBoxResult result = MessageBox.Show("File cannot be read or is busy. Try again?", "Error", MessageBoxButton.YesNo, MessageBoxImage.Error); if (result == MessageBoxResult.Yes) { return(SaveBitmap(obj, fileNameAddition)); } else { return(""); } } }
/// <summary> /// ObjectsOfAlbertrizal to string[] /// </summary> /// <param name="value"></param> /// <param name="targetType"></param> /// <param name="parameter"></param> /// <param name="culture"></param> /// <returns></returns> public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { try { List <ObjectOfAlbertrizal> objectsOfAlbertrizal = (value as IEnumerable <ObjectOfAlbertrizal>).Cast <ObjectOfAlbertrizal>().ToList(); return(ObjectOfAlbertrizal.GetNames(objectsOfAlbertrizal)); } catch (ArgumentNullException) { return(""); } }
protected virtual void AvailableObjectsList_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e) { ListBox listBox = (ListBox)sender; if (listBox.SelectedIndex < 0) { return; } ObjectOfAlbertrizal objectOfAlbertrizal = StoredObjects[listBox.SelectedIndex]; TargetObjects.Add(objectOfAlbertrizal); AddedObjectsList.Items.Add(objectOfAlbertrizal); ListChanged(); }
/// <summary> /// Copies an image to the project directory. /// </summary> /// <param name="location">The location of the file.</param> /// <param name="obj">The object being saved.</param> public static string CopyImageToProjectDirectory(string location, string fileNameAddition, ObjectOfAlbertrizal obj) { if (obj.Name == null || obj.Name == "") { MessageBox.Show("Please enter a name for your creation before selecting an image."); throw new ArgumentException("Object must be given a name"); } string basetype = obj.GetType().ToString(); basetype = basetype.Substring(basetype.LastIndexOf(".") + 1); string saveLocation = $"{Path.GetDirectoryName(GameBase.CurrentMapLocation)}\\{basetype}\\{obj.Name}_{fileNameAddition}.png"; Directory.CreateDirectory(Path.GetDirectoryName(saveLocation)); if (File.Exists(saveLocation)) { MessageBoxResult result = MessageBox.Show($"{saveLocation} exists. Overwrite?", "File Exists", MessageBoxButton.YesNo, MessageBoxImage.Warning); if (result == MessageBoxResult.No) { return(saveLocation); } } File.Copy(location, saveLocation, true); return(saveLocation); }