Skip to content

Commit 30b681d

Browse files
committed
Bug fixes:
- Fixed an issue with images not loading using a KMS (1.2.65) file structure - Added a right click function to the save button. This will save all parsed images as a PNG in the application's folder
1 parent 2a9d9e0 commit 30b681d

File tree

3 files changed

+84
-33
lines changed

3 files changed

+84
-33
lines changed

WzVisualizer/GUI/Form1.Designer.cs

Lines changed: 18 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

WzVisualizer/GUI/Form1.cs

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ private void AddGridRow(DataGridView grid, object wzObject)
161161

162162
if (wzObject is WzImage image)
163163
{
164-
if (image.WzFileParent.Name == "Npc.wz")
164+
if (image.WzFileParent.Name.StartsWith("Npc"))
165165
{
166166
// NPC icon breadcrumb like: '{ID}/stand/0'
167167
// and also sometimes contains a link STRING property instead of using UOL
@@ -179,7 +179,7 @@ private void AddGridRow(DataGridView grid, object wzObject)
179179
if (image == null) return;
180180
}
181181
icon = (WzCanvasProperty)image.GetFromPath("stand/0");
182-
} else if (image.WzFileParent.Name == "Mob.wz")
182+
} else if (image.WzFileParent.Name.StartsWith("Mob"))
183183
{
184184
// Mob icon breadcrumb like: '{ID}/(move|stand)/0'
185185
// where the 'move' or 'stand' sub property may not exist
@@ -216,7 +216,7 @@ private void AddGridRow(DataGridView grid, object wzObject)
216216
}
217217
} else if (wzObject is WzSubProperty subProperty)
218218
{
219-
if (subProperty.WzFileParent.Name == "Skill.wz")
219+
if (subProperty.WzFileParent.Name.StartsWith("Skill"))
220220
{
221221
ID = int.Parse(subProperty.Name);
222222
name = StringUtility.GetSkill(subProperty.Name);
@@ -639,12 +639,20 @@ private void BtnWzLoad_Click(object sender, EventArgs e)
639639
{
640640
_StringWZ = new WzFile(stringWzPath + ".wz", mapleVersion);
641641
_StringWZ.ParseWzFile();
642-
} else if (Directory.Exists(stringWzPath))
642+
}
643+
else if (Directory.Exists(stringWzPath))
643644
{ // KMS
645+
_StringWZ = new WzFile(stringWzPath, mapleVersion);
644646
WzDirectory dir = new WzDirectory("String", _StringWZ);
645647
_StringWZ.WzDirectory = dir;
646648
RecursivelyLoadDirectory(dir, stringWzPath, mapleVersion);
647649
}
650+
else
651+
{
652+
MessageBox.Show("Failed to load String data in the specified directory", "File not found", MessageBoxButtons.OK, MessageBoxIcon.Error);
653+
DisposeWzFiles();
654+
return;
655+
}
648656
StringUtility = new WzStringUtility(_StringWZ);
649657
LoadWzData(mapleVersion, folderPath);
650658
}
@@ -665,17 +673,37 @@ private void ComboLoadType_SelectedIndexChanged(object sender, EventArgs e)
665673
/// upon clicking the save button, store data of the current opened grid.
666674
/// Some tabs may have another TabControl in which that Control contains a Grid control.
667675
/// </summary>
668-
private void BtnSave_Click(object sender, EventArgs e)
676+
private void BtnSave_Click(object sender, EventArgs ev)
669677
{
670-
var control = TabControlMain.SelectedTab.Controls[0];
671-
if (control is DataGridView grid) // no child tabs and contains 1 child Control (DataGridView)
672-
GridIOUtility.ExportGrid(grid, TabControlMain.SelectedTab.Text);
673-
else if (control is TabControl tab) // sub-categories (e.g. Equips.Hairs, Equips.Faces)
674-
{
675-
control = tab.SelectedTab; // The selected child Tab (e.g. Equips.Hairs)
676-
GridIOUtility.ExportGrid((DataGridView) control.Controls[0], TabControlMain.SelectedTab.Text); // The DataGridView contained in the TabPage control
678+
MouseEventArgs e = (MouseEventArgs)ev;
679+
switch (e.Button) {
680+
case MouseButtons.Left:
681+
{
682+
var control = TabControlMain.SelectedTab.Controls[0];
683+
if (control is DataGridView grid) // no child tabs and contains 1 child Control (DataGridView)
684+
GridIOUtility.ExportGrid(grid, TabControlMain.SelectedTab.Text);
685+
else if (control is TabControl tab) // sub-categories (e.g. Equips.Hairs, Equips.Faces)
686+
{
687+
control = tab.SelectedTab; // The selected child Tab (e.g. Equips.Hairs)
688+
GridIOUtility.ExportGrid((DataGridView)control.Controls[0], TabControlMain.SelectedTab.Text); // The DataGridView contained in the TabPage control
689+
}
690+
MessageBox.Show("Bin save complete!");
691+
break;
692+
}
693+
case MouseButtons.Right:
694+
{
695+
var control = TabControlMain.SelectedTab.Controls[0];
696+
if (control is DataGridView grid) // no child tabs and contains 1 child Control (DataGridView)
697+
GridIOUtility.ExportGridImages(grid, TabControlMain.SelectedTab.Text);
698+
else if (control is TabControl tab) // sub-categories (e.g. Equips.Hairs, Equips.Faces)
699+
{
700+
control = tab.SelectedTab; // The selected child Tab (e.g. Equips.Hairs)
701+
GridIOUtility.ExportGridImages((DataGridView)control.Controls[0], TabControlMain.SelectedTab.Text); // The DataGridView contained in the TabPage control
702+
}
703+
MessageBox.Show("Image save complete!");
704+
break;
705+
}
677706
}
678-
MessageBox.Show("Save complete!");
679707
}
680708

681709
#region tab change events

WzVisualizer/IO/GridIOUtility.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace WzVisualizer
1414
class GridIOUtility
1515
{
1616
private const string ExportFolder = "exports";
17+
private const string ImagesFolder = "images";
1718

1819
private static void ReadFileContents(string path, ref List<BinData> datas)
1920
{
@@ -58,7 +59,7 @@ private static void ReadFileContents(string path, ref List<BinData> datas)
5859

5960
internal static void ImportGrid(string file, DataGridView grid, AddGridRowCallBack callbackTask)
6061
{
61-
string path = string.Format("{0}/{1}", ExportFolder, file);
62+
string path = string.Format("{0}/{1}", ImagesFolder, file);
6263
if (!File.Exists(path))
6364
return;
6465
List<BinData> datas = new List<BinData>();
@@ -68,11 +69,33 @@ internal static void ImportGrid(string file, DataGridView grid, AddGridRowCallBa
6869
thread.Start();
6970
}
7071

72+
internal static void ExportGridImages(DataGridView grid, string folder)
73+
{
74+
string directory = string.Format("{0}/{1}", ImagesFolder, folder);
75+
Directory.CreateDirectory(directory);
76+
var rows = grid.Rows;
77+
for (int a = 0; a < rows.Count; a++)
78+
{
79+
var cells = rows[a].Cells;
80+
Bitmap bitmap = null;
81+
string fileName = null;
82+
for (int b = 0; b < cells.Count; b++)
83+
{
84+
var cell = cells[b];
85+
string ownColumnName = cell.OwningColumn.Name;
86+
if (ownColumnName.EndsWith("Image")) bitmap = (Bitmap)cell.Value;
87+
if (ownColumnName.EndsWith("ID")) fileName = (int)cell.Value + ".png";
88+
}
89+
if (bitmap == null || fileName == null) continue;
90+
bitmap.Save(string.Format("{0}/{1}", directory, fileName), ImageFormat.Png);
91+
}
92+
}
93+
7194
internal static void ExportGrid(DataGridView grid, string folder)
7295
{
7396
string directory = string.Format("{0}/{1}", ExportFolder, folder);
7497
Directory.CreateDirectory(directory);
75-
string path = string.Format("{0}/{2}.bin", directory, folder, ((TabPage)grid.Parent).Text);
98+
string path = string.Format("{0}/{1}.bin", directory, ((TabPage)grid.Parent).Text);
7699
using (BinaryWriter bwriter = new BinaryWriter(new FileStream(path, FileMode.Create)))
77100
{
78101
var rows = grid.Rows;

0 commit comments

Comments
 (0)