Skip to content

Commit 55c5fe8

Browse files
committed
Option to change exported images naming convention.
1 parent ef2f955 commit 55c5fe8

21 files changed

Lines changed: 191 additions & 50 deletions

UoFiddler.Controls/Classes/Options.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,18 @@ public static class Options
4242
/// </summary>
4343
public static bool DarkMode { get; set; }
4444

45+
/// <summary>
46+
/// When true, exported image filenames embed the ID in hexadecimal form (e.g. "Item 0x00FF.png").
47+
/// When false, decimal form is used. Runtime flag set from AppSettings at startup.
48+
/// </summary>
49+
public static bool ExportFilenameInHex { get; set; } = true;
50+
51+
/// <summary>
52+
/// When <see cref="ExportFilenameInHex"/> is false, controls whether decimal IDs are zero-padded
53+
/// to 5 digits ("00255") or written without padding ("255"). Runtime flag set from AppSettings.
54+
/// </summary>
55+
public static bool ExportFilenameDecimalPadded { get; set; } = true;
56+
4557
/// <summary>
4658
/// Defines the cmd to Send Client to Loc
4759
/// </summary>

UoFiddler.Controls/Classes/Utils.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,23 @@ public static bool ConvertStringToInt(string text, out int result)
6464
return int.TryParse(text, NumberStyles.Integer, null, out result);
6565
}
6666

67+
/// <summary>
68+
/// Formats an ID for inclusion in an exported filename, honoring the user's
69+
/// hex/decimal preference in <see cref="Options.ExportFilenameInHex"/> and
70+
/// <see cref="Options.ExportFilenameDecimalPadded"/>.
71+
/// </summary>
72+
public static string FormatExportId(int id)
73+
{
74+
if (Options.ExportFilenameInHex)
75+
{
76+
return $"0x{id:X4}";
77+
}
78+
79+
return Options.ExportFilenameDecimalPadded
80+
? id.ToString("D5")
81+
: id.ToString();
82+
}
83+
6784
public static unsafe Bitmap ConvertBmp(Bitmap bmp)
6885
{
6986
BitmapData bd = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format16bppArgb1555);

UoFiddler.Controls/Forms/AnimationEditForm.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,7 +1191,7 @@ private void OnClickExportToVD(object sender, EventArgs e)
11911191
}
11921192

11931193
string path = Options.OutputPath;
1194-
string fileName = Path.Combine(path, $"anim{_fileType}_0x{_currentBody:X}.vd");
1194+
string fileName = Path.Combine(path, $"anim{_fileType}_{Utils.FormatExportId(_currentBody)}.vd");
11951195
AnimationEdit.ExportToVD(_fileType, _currentBody, fileName);
11961196

11971197
FileSavedDialog.Show(FindForm(), Options.OutputPath, "Animation saved successfully.");
@@ -2240,7 +2240,7 @@ private void OnClickExportAllToVD(object sender, EventArgs e)
22402240
continue;
22412241
}
22422242

2243-
string fileName = Path.Combine(dialog.SelectedPath, $"anim{_fileType}_0x{index:X}.vd");
2243+
string fileName = Path.Combine(dialog.SelectedPath, $"anim{_fileType}_{Utils.FormatExportId(index)}.vd");
22442244
AnimationEdit.ExportToVD(_fileType, index, fileName);
22452245
}
22462246

UoFiddler.Controls/Forms/ItemDetailForm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ private void SaveImage(ImageFormat imageFormat)
246246
}
247247

248248
string fileExtension = Utils.GetFileExtensionFor(imageFormat);
249-
string fileName = Path.Combine(Options.OutputPath, $"Item 0x{_index:X}.{fileExtension}");
249+
string fileName = Path.Combine(Options.OutputPath, $"Item {Utils.FormatExportId(_index)}.{fileExtension}");
250250

251251
using (Bitmap bit = new Bitmap(Art.GetStatic(_index).Width, Art.GetStatic(_index).Height))
252252
{

UoFiddler.Controls/UserControls/AnimDataControl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ private void OnClick_ExportAsGif(object sender, EventArgs e)
679679
{
680680
if (_selAnimdataEntry != null)
681681
{
682-
var outputFile = Path.Combine(Options.OutputPath, $"AnimData 0x{_currentSelect:X}.gif");
682+
var outputFile = Path.Combine(Options.OutputPath, $"AnimData {Utils.FormatExportId(_currentSelect)}.gif");
683683
MainPictureBox.Frames.ToGif(outputFile, delay: 150, showFrameBounds: MainPictureBox.ShowFrameBounds);
684684
MessageBox.Show($"Saved to {outputFile}");
685685
}

UoFiddler.Controls/UserControls/AnimationListControl.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ private void ExtractImage(ImageFormat imageFormat)
872872
}
873873

874874
string fileExtension = Utils.GetFileExtensionFor(imageFormat);
875-
string fileName = Path.Combine(Options.OutputPath, $"{what} {_currentSelect}.{fileExtension}");
875+
string fileName = Path.Combine(Options.OutputPath, $"{what} {Utils.FormatExportId(_currentSelect)}.{fileExtension}");
876876

877877
Bitmap sourceBitmap = MainPictureBox.CurrentFrame?.Bitmap;
878878

@@ -926,7 +926,7 @@ private void ExportAnimationFrames(ImageFormat imageFormat)
926926
}
927927

928928
string fileExtension = Utils.GetFileExtensionFor(imageFormat);
929-
string fileName = Path.Combine(Options.OutputPath, $"{what} {_currentSelect}");
929+
string fileName = Path.Combine(Options.OutputPath, $"{what} {Utils.FormatExportId(_currentSelect)}");
930930

931931
for (int i = 0; i < MainPictureBox.Frames?.Count; ++i)
932932
{
@@ -981,7 +981,7 @@ private void ExportSingleFrame(ImageFormat imageFormat)
981981
}
982982

983983
string fileExtension = Utils.GetFileExtensionFor(imageFormat);
984-
string fileName = Path.Combine(Options.OutputPath, $"{what} {_currentSelect}");
984+
string fileName = Path.Combine(Options.OutputPath, $"{what} {Utils.FormatExportId(_currentSelect)}");
985985

986986
Bitmap bit = MainPictureBox.Frames[(int)listView1.SelectedItems[0].Tag].Bitmap;
987987
using (Bitmap newBitmap = new Bitmap(bit.Width, bit.Height))

UoFiddler.Controls/UserControls/FontsControl.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ private void OnClickExport(object sender, EventArgs e)
209209
string path = Options.OutputPath;
210210
string fileType = (int)treeView.SelectedNode.Parent.Tag == 1 ? "Unicode" : "ASCII";
211211
string fileName = (int)treeView.SelectedNode.Parent.Tag == 1
212-
? Path.Combine(path, $"{fileType} {(int)treeView.SelectedNode.Tag} 0x{FontsTileView.SelectedIndices[0]:X}.tiff")
213-
: Path.Combine(path, $"{fileType} {(int)treeView.SelectedNode.Tag} 0x{_fonts[FontsTileView.SelectedIndices[0]] + AsciiFontOffset:X}.tiff");
212+
? Path.Combine(path, $"{fileType} {(int)treeView.SelectedNode.Tag} {Utils.FormatExportId(FontsTileView.SelectedIndices[0])}.tiff")
213+
: Path.Combine(path, $"{fileType} {(int)treeView.SelectedNode.Tag} {Utils.FormatExportId(_fonts[FontsTileView.SelectedIndices[0]] + AsciiFontOffset)}.tiff");
214214

215215
if ((int)treeView.SelectedNode.Parent.Tag == 1)
216216
{

UoFiddler.Controls/UserControls/GumpControl.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ private void Extract_Image_ClickPng(object sender, EventArgs e)
734734
private static void ExportGumpImage(int index, ImageFormat imageFormat)
735735
{
736736
string fileExtension = Utils.GetFileExtensionFor(imageFormat);
737-
string fileName = Path.Combine(Options.OutputPath, $"Gump 0x{index:X4}.{fileExtension}");
737+
string fileName = Path.Combine(Options.OutputPath, $"Gump {Utils.FormatExportId(index)}.{fileExtension}");
738738

739739
using (Bitmap bit = new Bitmap(Gumps.GetGump(index)))
740740
{
@@ -792,7 +792,7 @@ private void ExportAllGumps(ImageFormat imageFormat)
792792
continue;
793793
}
794794

795-
string fileName = Path.Combine(dialog.SelectedPath, $"Gump 0x{index:X4}.{fileExtension}");
795+
string fileName = Path.Combine(dialog.SelectedPath, $"Gump {Utils.FormatExportId(index)}.{fileExtension}");
796796
var gump = Gumps.GetGump(index);
797797
if (gump is null)
798798
{

UoFiddler.Controls/UserControls/ItemsControl.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ private static void ExportItemImage(int index, ImageFormat imageFormat)
746746
}
747747

748748
string fileExtension = Utils.GetFileExtensionFor(imageFormat);
749-
string fileName = Path.Combine(Options.OutputPath, $"Item 0x{index:X4}.{fileExtension}");
749+
string fileName = Path.Combine(Options.OutputPath, $"Item {Utils.FormatExportId(index)}.{fileExtension}");
750750

751751
using (Bitmap bit = new Bitmap(Art.GetStatic(index)))
752752
{
@@ -821,7 +821,7 @@ private void ExportAllItemImages(ImageFormat imageFormat)
821821
continue;
822822
}
823823

824-
string fileName = Path.Combine(dialog.SelectedPath, $"Item 0x{index:X4}.{fileExtension}");
824+
string fileName = Path.Combine(dialog.SelectedPath, $"Item {Utils.FormatExportId(index)}.{fileExtension}");
825825
var artBitmap = Art.GetStatic(index);
826826
if (artBitmap is null)
827827
{

UoFiddler.Controls/UserControls/LandTilesControl.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ private static void ExportLandTileImage(int index, ImageFormat imageFormat)
561561
}
562562

563563
string fileExtension = Utils.GetFileExtensionFor(imageFormat);
564-
string fileName = Path.Combine(Options.OutputPath, $"Landtile 0x{index:X4}.{fileExtension}");
564+
string fileName = Path.Combine(Options.OutputPath, $"Landtile {Utils.FormatExportId(index)}.{fileExtension}");
565565

566566
using (Bitmap bit = new Bitmap(Art.GetLand(index)))
567567
{
@@ -652,7 +652,7 @@ private void ExportAllLandTiles(ImageFormat imageFormat)
652652
continue;
653653
}
654654

655-
string fileName = Path.Combine(dialog.SelectedPath, $"Landtile 0x{index:X4}.{fileExtension}");
655+
string fileName = Path.Combine(dialog.SelectedPath, $"Landtile {Utils.FormatExportId(index)}.{fileExtension}");
656656
var landTile = Art.GetLand(index);
657657
if (landTile is null)
658658
{

0 commit comments

Comments
 (0)