private void ImportImagesMethod(bool bigImage) { Cursor = new Avalonia.Input.Cursor(Avalonia.Input.StandardCursorType.Wait); Utility.XOffsetBefore = 0; Utility.YOffsetBefore = 0; var filewithoutgm1ending = vm.File.FileHeader.Name.Replace(".gm1", ""); if (!bigImage) { var files = Directory.GetFiles(vm.UserConfig.WorkFolderPath + "\\" + filewithoutgm1ending + "\\Images", "*.png", SearchOption.TopDirectoryOnly); //sort because 11 is before 2 files = files.OrderBy(x => x.Length).ThenBy(x => x).ToArray <String>(); int counter = 1; foreach (var file in files) { var filename = Path.GetFileName(file); if (filename.Equals("Image" + counter + ".png")) { Avalonia.Media.Imaging.Bitmap image = new Avalonia.Media.Imaging.Bitmap(file); vm.TGXImages[counter - 1].Source = image; vm.TGXImages[counter - 1].MaxWidth = image.PixelSize.Width; vm.TGXImages[counter - 1].MaxHeight = image.PixelSize.Height; counter++; var fileindex = int.Parse(filename.Replace("Image", "").Replace(".png", "")) - 1; int width = 0, height = 0; var list = Utility.LoadImage(file, ref width, ref height, vm.File.ImagesTGX[fileindex].AnimatedColor, 1, vm.File.FileHeader.IDataType); if (list.Count == 0) { return; } LoadNewDataForGm1File(fileindex, list, width, height); } } } else { int maxwidth = 650; int fileindex = 0; int offsety = 0; int maxheight = 0; int offsetx = 0; int actualwidth = 0; int counter = 0; if (((GM1FileHeader.DataType)vm.File.FileHeader.IDataType == GM1FileHeader.DataType.TilesObject)) { foreach (var image in vm.File.TilesImages) { int width = image.Width; int height = image.Height - ((GM1FileHeader.DataType)vm.File.FileHeader.IDataType == GM1FileHeader.DataType.NOCompression ? 7 : 0); actualwidth += width; if (maxwidth <= actualwidth) { offsety += maxheight; actualwidth = width; maxheight = 0; offsetx = 0; } if (maxheight < height) { maxheight = height; } var list = Utility.LoadImage(vm.UserConfig.WorkFolderPath + "\\" + filewithoutgm1ending + "\\BigImage\\" + filewithoutgm1ending + ".png", ref width, ref height, vm.File.ImagesTGX[fileindex].AnimatedColor, 1, vm.File.FileHeader.IDataType, offsetx, offsety); if (list.Count == 0) { continue; } width = image.Width; height = image.Height; LoadNewDataForGm1File(fileindex, list, width, height); fileindex++; offsetx += width; Avalonia.Media.Imaging.Bitmap newimage = Utility.LoadImageAsBitmap(vm.UserConfig.WorkFolderPath + "\\" + filewithoutgm1ending + "\\BigImage\\" + filewithoutgm1ending + ".png", ref width, ref height, offsetx, offsety); vm.TGXImages[counter].Source = newimage; vm.TGXImages[counter].MaxWidth = newimage.PixelSize.Width; vm.TGXImages[counter].MaxHeight = newimage.PixelSize.Height; counter++; } } else { foreach (var image in vm.File.ImagesTGX) { int width = image.Width; int height = image.Height - ((GM1FileHeader.DataType)vm.File.FileHeader.IDataType == GM1FileHeader.DataType.NOCompression ? 7 : 0); actualwidth += width; if (maxwidth <= actualwidth) { offsety += maxheight; actualwidth = width; maxheight = 0; offsetx = 0; } if (maxheight < height) { maxheight = height; } int oldOffsetx = offsetx; int oldOffsety = offsety; var list = Utility.LoadImage(vm.UserConfig.WorkFolderPath + "\\" + filewithoutgm1ending + "\\BigImage\\" + filewithoutgm1ending + ".png", ref width, ref height, vm.File.ImagesTGX[fileindex].AnimatedColor, 1, vm.File.FileHeader.IDataType, offsetx, offsety); if (list.Count == 0) { continue; } width = image.Width; height = image.Height - ((GM1FileHeader.DataType)vm.File.FileHeader.IDataType == GM1FileHeader.DataType.NOCompression ? 7 : 0); LoadNewDataForGm1File(fileindex, list, width, height); fileindex++; offsetx += width; Avalonia.Media.Imaging.Bitmap newimage = Utility.LoadImageAsBitmap(vm.UserConfig.WorkFolderPath + "\\" + filewithoutgm1ending + "\\BigImage\\" + filewithoutgm1ending + ".png", ref width, ref height, oldOffsetx, oldOffsety); vm.TGXImages[counter].Source = newimage; vm.TGXImages[counter].MaxWidth = newimage.PixelSize.Width; vm.TGXImages[counter].MaxHeight = newimage.PixelSize.Height; counter++; } } } if ((GM1FileHeader.DataType)vm.File.FileHeader.IDataType == GM1FileHeader.DataType.TilesObject) { vm.File.SetNewTileList(); } if (vm.File.ImagesTGX.Count > 0) { vm.File.ImagesTGX[0].SizeinByteArray = (uint)vm.File.ImagesTGX[0].ImgFileAsBytearray.Length; } uint zaehler = 0; for (int i = 1; i < vm.File.ImagesTGX.Count; i++) { zaehler += vm.File.ImagesTGX[i - 1].SizeinByteArray; vm.File.ImagesTGX[i].OffsetinByteArray = zaehler; vm.File.ImagesTGX[i].SizeinByteArray = (uint)vm.File.ImagesTGX[i].ImgFileAsBytearray.Length; } //datasize neu setzten uint newDataSize = vm.File.ImagesTGX[vm.File.ImagesTGX.Count - 1].OffsetinByteArray + vm.File.ImagesTGX[vm.File.ImagesTGX.Count - 1].SizeinByteArray;; vm.File.FileHeader.IDataSize = newDataSize; Cursor = new Avalonia.Input.Cursor(Avalonia.Input.StandardCursorType.Arrow); }
private void CreatenewGM1(object sender, EventArgs e) { if (Logger.Loggeractiv) { Logger.Log("\n>>CreatenewGM1 start"); } Cursor = new Avalonia.Input.Cursor(Avalonia.Input.StandardCursorType.Wait); var filewithoutgm1ending = vm.File.FileHeader.Name.Replace(".gm1", ""); if (!Directory.Exists(vm.UserConfig.WorkFolderPath + "\\" + filewithoutgm1ending)) { Directory.CreateDirectory(vm.UserConfig.WorkFolderPath + "\\" + filewithoutgm1ending); } if (!File.Exists(vm.UserConfig.WorkFolderPath + "\\" + filewithoutgm1ending + "\\" + filewithoutgm1ending + "Save.gm1")) { File.Copy(vm.UserConfig.CrusaderPath + "\\" + vm.File.FileHeader.Name, vm.UserConfig.WorkFolderPath + "\\" + filewithoutgm1ending + "\\" + filewithoutgm1ending + "Save.gm1"); } var array = vm.File.GetNewGM1Bytes(); Utility.ByteArraytoFile(vm.UserConfig.CrusaderPath + "\\" + vm.File.FileHeader.Name, array); File.Copy(vm.UserConfig.CrusaderPath + "\\" + vm.File.FileHeader.Name, vm.UserConfig.WorkFolderPath + "\\" + filewithoutgm1ending + "\\" + filewithoutgm1ending + "Modded.gm1", true); Cursor = new Avalonia.Input.Cursor(Avalonia.Input.StandardCursorType.Arrow); if (Logger.Loggeractiv) { Logger.Log("\n>>CreatenewGM1 end"); } }
private void ExportColortable(object sender, RoutedEventArgs e) { if (Logger.Loggeractiv) { Logger.Log("\n>>ExportColortable start"); } Cursor = new Avalonia.Input.Cursor(Avalonia.Input.StandardCursorType.Wait); int colorTable = 1; var filewithoutgm1ending = vm.File.FileHeader.Name.Replace(".gm1", ""); if (!Directory.Exists(vm.UserConfig.WorkFolderPath + "\\" + filewithoutgm1ending + "\\Colortables")) { Directory.CreateDirectory(vm.UserConfig.WorkFolderPath + "\\" + filewithoutgm1ending + "\\Colortables"); } foreach (var bitmap in vm.File.Palette.Bitmaps) { bitmap.Save(vm.UserConfig.WorkFolderPath + "\\" + filewithoutgm1ending + "\\Colortables\\ColorTable" + colorTable + ".png"); colorTable++; } if (vm.UserConfig.OpenFolderAfterExport) { Process.Start("explorer.exe", vm.UserConfig.WorkFolderPath + "\\" + filewithoutgm1ending + "\\Colortables"); } vm.LoadWorkfolderFiles(); Cursor = new Avalonia.Input.Cursor(Avalonia.Input.StandardCursorType.Arrow); if (Logger.Loggeractiv) { Logger.Log("\n>>ExportColortable end"); } }
private void ExportImagesMethod(bool bigImage) { Cursor = new Avalonia.Input.Cursor(Avalonia.Input.StandardCursorType.Wait); int img = 1; var filewithoutgm1ending = vm.File.FileHeader.Name.Replace(".gm1", ""); if (!Directory.Exists(vm.UserConfig.WorkFolderPath + "\\" + filewithoutgm1ending + ((!bigImage) ?"\\Images": "\\BigImage"))) { Directory.CreateDirectory(vm.UserConfig.WorkFolderPath + "\\" + filewithoutgm1ending + ((!bigImage) ? "\\Images" : "\\BigImage")); } if ((GM1FileHeader.DataType)vm.File.FileHeader.IDataType == GM1FileHeader.DataType.TilesObject) { if (!bigImage) { foreach (var image in vm.File.TilesImages) { image.TileImage.Save(vm.UserConfig.WorkFolderPath + "\\" + filewithoutgm1ending + "\\Images\\Image" + img + ".png"); img++; } } else { Utility.CreateBigImage(vm.File.TilesImages).Save(vm.UserConfig.WorkFolderPath + "\\" + filewithoutgm1ending + "\\BigImage\\" + filewithoutgm1ending + ".png"); } } else { if (!bigImage) { foreach (var image in vm.File.ImagesTGX) { image.Bitmap.Save(vm.UserConfig.WorkFolderPath + "\\" + filewithoutgm1ending + "\\Images\\Image" + img + ".png"); img++; } } else { Utility.CreateBigImage(vm.File.ImagesTGX).Save(vm.UserConfig.WorkFolderPath + "\\" + filewithoutgm1ending + "\\BigImage\\" + filewithoutgm1ending + ".png");; } } if (vm.UserConfig.OpenFolderAfterExport) { Process.Start("explorer.exe", vm.UserConfig.WorkFolderPath + "\\" + filewithoutgm1ending + ((bigImage)?"\\BigImage": "\\Images")); } vm.LoadWorkfolderFiles(); Cursor = new Avalonia.Input.Cursor(Avalonia.Input.StandardCursorType.Arrow); }
private void LoadGm1File(string listboxItemBefore) { if (Logger.Loggeractiv) { Logger.Log("LoadGm1File"); } Cursor = new Avalonia.Input.Cursor(Avalonia.Input.StandardCursorType.Wait); try { vm.TgxButtonExportEnabled = false; vm.TgxButtonImportEnabled = false; vm.ReplaceWithSaveFileTgx = false; if (vm.DecodeData(listboxItemBefore, this)) { Utility.datatype = (GM1FileHeader.DataType)vm.File.FileHeader.IDataType; vm.Filetype = Utility.GetText("Datatype") + ((GM1FileHeader.DataType)vm.File.FileHeader.IDataType); if (vm.File.Palette == null) { vm.ImportButtonEnabled = true; vm.ColorButtonsEnabled = false; vm.OrginalStrongholdAnimationButtonEnabled = false; vm.ActuellColorTable = null; } else { vm.OrginalStrongholdAnimationButtonEnabled = true; vm.ColorButtonsEnabled = true; vm.ImportButtonEnabled = true; } vm.ButtonsEnabled = true; var filewithoutgm1ending = listboxItemBefore.Replace(".gm1", ""); if (!File.Exists(vm.UserConfig.WorkFolderPath + "\\" + filewithoutgm1ending + "\\" + filewithoutgm1ending + "Save.gm1")) { vm.ReplaceWithSaveFile = false; } else { vm.ReplaceWithSaveFile = true; } } } catch (Exception e) { if (Logger.Loggeractiv) { Logger.Log("Exception:\n" + e.Message); } MessageBoxWindow messageBox = new MessageBoxWindow(MessageBoxWindow.MessageTyp.Info, "Something went wrong: pls add a issue on the Github Page\n\nError:\n" + e.Message); messageBox.Show(); } Cursor = new Avalonia.Input.Cursor(Avalonia.Input.StandardCursorType.Arrow); }
private void LoadTgxFile(string listboxItemBefore) { if (Logger.Loggeractiv) { Logger.Log("LoadGfxFile"); } Cursor = new Avalonia.Input.Cursor(Avalonia.Input.StandardCursorType.Wait); try { vm.ColorButtonsEnabled = false; vm.OrginalStrongholdAnimationButtonEnabled = false; vm.ActuellColorTable = null; vm.ReplaceWithSaveFile = false; vm.ButtonsEnabled = false; vm.ImportButtonEnabled = false; vm.TgxButtonExportEnabled = true; vm.ReplaceWithSaveFileTgx = false; vm.DecodeTgxData(listboxItemBefore, this); var filewithouttgxending = listboxItemBefore.Replace(".tgx", ""); if (File.Exists(vm.UserConfig.WorkFolderPath + "\\" + filewithouttgxending + "\\" + filewithouttgxending + ".png")) { vm.TgxButtonImportEnabled = true; } if (!File.Exists(vm.UserConfig.WorkFolderPath + "\\" + filewithouttgxending + "\\" + filewithouttgxending + "Save.tgx")) { vm.ReplaceWithSaveFileTgx = false; } else { vm.ReplaceWithSaveFileTgx = true; } } catch (Exception e) { if (Logger.Loggeractiv) { Logger.Log("Exception:\n" + e.Message); } MessageBoxWindow messageBox = new MessageBoxWindow(MessageBoxWindow.MessageTyp.Info, "Something went wrong: pls add a issue on the Github Page\n\nError:\n" + e.Message); messageBox.Show(); } Cursor = new Avalonia.Input.Cursor(Avalonia.Input.StandardCursorType.Arrow); }
private void ExportOrginalStrongholdAnimation(object sender, RoutedEventArgs e) { if (Logger.Loggeractiv) { Logger.Log("\n>>ExportOrginalStrongholdAnimation start"); } Cursor = new Avalonia.Input.Cursor(Avalonia.Input.StandardCursorType.Wait); var filewithoutgm1ending = vm.File.FileHeader.Name.Replace(".gm1", ""); vm.File.Palette.ActualPalette = 0; vm.File.DecodeGm1File(vm.File.FileArray, vm.File.FileHeader.Name); for (int i = 0; i < 10; i++) { if (!Directory.Exists(vm.UserConfig.WorkFolderPath + "\\" + filewithoutgm1ending + "\\OrginalAnimationPalette" + (i + 1))) { Directory.CreateDirectory(vm.UserConfig.WorkFolderPath + "\\" + filewithoutgm1ending + "\\OrginalAnimationPalette" + (i + 1)); } int img = 1; foreach (var image in vm.File.ImagesTGX) { image.Bitmap.Save(vm.UserConfig.WorkFolderPath + "\\" + filewithoutgm1ending + "\\OrginalAnimationPalette" + (i + 1) + "\\OrginalAnimationImg" + img + ".png"); img++; } vm.ChangePalette(1); } if (vm.UserConfig.OpenFolderAfterExport) { Process.Start("explorer.exe", vm.UserConfig.WorkFolderPath + "\\" + filewithoutgm1ending); } vm.LoadWorkfolderFiles(); Cursor = new Avalonia.Input.Cursor(Avalonia.Input.StandardCursorType.Arrow); if (Logger.Loggeractiv) { Logger.Log("\n>>ExportOrginalStrongholdAnimation end"); } }
private void ImportColortable(object sender, RoutedEventArgs e) { if (Logger.Loggeractiv) { Logger.Log("\n>>ImportColortable start"); } Cursor = new Avalonia.Input.Cursor(Avalonia.Input.StandardCursorType.Wait); var filewithoutgm1ending = vm.File.FileHeader.Name.Replace(".gm1", ""); var files = Directory.GetFiles(vm.UserConfig.WorkFolderPath + "\\" + filewithoutgm1ending + "\\Colortables", "*.png"); foreach (var file in files) { var filename = Path.GetFileName(file); if (filename.StartsWith("ColorTable")) { int width = 0, height = 0; var fileindex = int.Parse(filename.Replace("ColorTable", "").Replace(".png", "")) - 1; var list = Utility.LoadImage(file, ref width, ref height, 1, Palette.pixelSize, vm.File.FileHeader.IDataType); if (list.Count == 0) { return; } vm.File.Palette.SetPaleteUInt(fileindex, list.ToArray()); var bitmap = vm.File.Palette.GetBitmap(fileindex, Palette.pixelSize); vm.File.Palette.Bitmaps[fileindex] = bitmap; vm.GeneratePaletteAndImgNew(); vm.File.Palette.Bitmaps[fileindex] = bitmap; } } Cursor = new Avalonia.Input.Cursor(Avalonia.Input.StandardCursorType.Arrow); vm.ActuellColorTable = vm.File.Palette.Bitmaps[vm.File.Palette.ActualPalette]; if (Logger.Loggeractiv) { Logger.Log("\n>>ImportColortable end"); } }
private void ImportOrginalStrongholdAnimation(object sender, RoutedEventArgs e) { if (Logger.Loggeractiv) { Logger.Log("\n>>ImportOrginalStrongholdAnimation start"); } Cursor = new Avalonia.Input.Cursor(Avalonia.Input.StandardCursorType.Wait); var filewithoutgm1ending = vm.File.FileHeader.Name.Replace(".gm1", ""); var files = Directory.GetFiles(vm.UserConfig.WorkFolderPath + "\\" + filewithoutgm1ending + "\\OrginalAnimationPalette1", "*.png", SearchOption.TopDirectoryOnly); //sort because 11 is before 2 files = files.OrderBy(x => x.Length).ThenBy(x => x).ToArray <String>(); int counter = 1; foreach (var file in files) { var filename = Path.GetFileName(file); if (filename.Equals("OrginalAnimationImg" + counter + ".png")) { int width = 0, height = 0; var list = Utility.LoadImage(file, ref width, ref height, vm.File.ImagesTGX[counter - 1].AnimatedColor, 1, vm.File.FileHeader.IDataType); if (list.Count == 0) { return; } List <ushort>[] colorsImages = new List <ushort> [9]; colorsImages[0] = Utility.LoadImage(vm.UserConfig.WorkFolderPath + "\\" + filewithoutgm1ending + "\\OrginalAnimationPalette" + 2 + "\\OrginalAnimationImg" + counter + ".png", ref width, ref height, vm.File.ImagesTGX[counter - 1].AnimatedColor, 1, vm.File.FileHeader.IDataType); colorsImages[1] = Utility.LoadImage(vm.UserConfig.WorkFolderPath + "\\" + filewithoutgm1ending + "\\OrginalAnimationPalette" + 3 + "\\OrginalAnimationImg" + counter + ".png", ref width, ref height, vm.File.ImagesTGX[counter - 1].AnimatedColor, 1, vm.File.FileHeader.IDataType); colorsImages[2] = Utility.LoadImage(vm.UserConfig.WorkFolderPath + "\\" + filewithoutgm1ending + "\\OrginalAnimationPalette" + 4 + "\\OrginalAnimationImg" + counter + ".png", ref width, ref height, vm.File.ImagesTGX[counter - 1].AnimatedColor, 1, vm.File.FileHeader.IDataType); colorsImages[3] = Utility.LoadImage(vm.UserConfig.WorkFolderPath + "\\" + filewithoutgm1ending + "\\OrginalAnimationPalette" + 5 + "\\OrginalAnimationImg" + counter + ".png", ref width, ref height, vm.File.ImagesTGX[counter - 1].AnimatedColor, 1, vm.File.FileHeader.IDataType); colorsImages[4] = Utility.LoadImage(vm.UserConfig.WorkFolderPath + "\\" + filewithoutgm1ending + "\\OrginalAnimationPalette" + 6 + "\\OrginalAnimationImg" + counter + ".png", ref width, ref height, vm.File.ImagesTGX[counter - 1].AnimatedColor, 1, vm.File.FileHeader.IDataType); colorsImages[5] = Utility.LoadImage(vm.UserConfig.WorkFolderPath + "\\" + filewithoutgm1ending + "\\OrginalAnimationPalette" + 7 + "\\OrginalAnimationImg" + counter + ".png", ref width, ref height, vm.File.ImagesTGX[counter - 1].AnimatedColor, 1, vm.File.FileHeader.IDataType); colorsImages[6] = Utility.LoadImage(vm.UserConfig.WorkFolderPath + "\\" + filewithoutgm1ending + "\\OrginalAnimationPalette" + 8 + "\\OrginalAnimationImg" + counter + ".png", ref width, ref height, vm.File.ImagesTGX[counter - 1].AnimatedColor, 1, vm.File.FileHeader.IDataType); colorsImages[7] = Utility.LoadImage(vm.UserConfig.WorkFolderPath + "\\" + filewithoutgm1ending + "\\OrginalAnimationPalette" + 9 + "\\OrginalAnimationImg" + counter + ".png", ref width, ref height, vm.File.ImagesTGX[counter - 1].AnimatedColor, 1, vm.File.FileHeader.IDataType); colorsImages[8] = Utility.LoadImage(vm.UserConfig.WorkFolderPath + "\\" + filewithoutgm1ending + "\\OrginalAnimationPalette" + 10 + "\\OrginalAnimationImg" + counter + ".png", ref width, ref height, vm.File.ImagesTGX[counter - 1].AnimatedColor, 1, vm.File.FileHeader.IDataType); vm.File.ImagesTGX[counter - 1].ConvertImageWithPaletteToByteArray(list, width, height, vm.File.Palette, colorsImages); vm.File.ImagesTGX[counter - 1].Width = (ushort)width; vm.File.ImagesTGX[counter - 1].Height = (ushort)height; counter++; } } if (vm.File.ImagesTGX.Count > 0) { vm.File.ImagesTGX[0].SizeinByteArray = (uint)vm.File.ImagesTGX[0].ImgFileAsBytearray.Length; } uint zaehler = 0; for (int i = 1; i < vm.File.ImagesTGX.Count; i++) { zaehler += vm.File.ImagesTGX[i - 1].SizeinByteArray; vm.File.ImagesTGX[i].OffsetinByteArray = zaehler; vm.File.ImagesTGX[i].SizeinByteArray = (uint)vm.File.ImagesTGX[i].ImgFileAsBytearray.Length; } //datasize neu setzten uint newDataSize = vm.File.ImagesTGX[vm.File.ImagesTGX.Count - 1].OffsetinByteArray + vm.File.ImagesTGX[vm.File.ImagesTGX.Count - 1].SizeinByteArray;; Cursor = new Avalonia.Input.Cursor(Avalonia.Input.StandardCursorType.Arrow); if (Logger.Loggeractiv) { Logger.Log("\n>>ImportOrginalStrongholdAnimation end"); } }
private void Button_ClickPalleteplus(object sender, RoutedEventArgs e) { Cursor = new Avalonia.Input.Cursor(Avalonia.Input.StandardCursorType.Wait); vm.ChangePalette(1); Cursor = new Avalonia.Input.Cursor(Avalonia.Input.StandardCursorType.Arrow); }