private void AddGridRow(DataGridView grid, object wzObject) { int id; string properties = BuildProperties(wzObject); string name = null; WzObject icon = null; if (wzObject is WzImage image) { id = int.Parse(Path.GetFileNameWithoutExtension(image.Name)); properties = BuildProperties(image) ?? ""; WzImageProperty linkProperty = image.GetFromPath("info/link"); if (linkProperty != null) { string linkName = ((WzStringProperty)linkProperty).Value; image = ((WzDirectory)image.Parent).GetChildImages().Find(p => p.Name.Equals(linkName + ".img")); if (image == null) { return; } } WzObject entityIcon = image.GetFromPath("stand/0"); if (image.WzFileParent.Name.StartsWith("Npc")) // icon path like: '{ID}/stand/0' { name = StringUtility.GetNPC(id); } else if (image.WzFileParent.Name.StartsWith("Mob")) // icon path like: '{ID}/(move|stand|fly)/0' { name = StringUtility.GetMob(id); if (entityIcon == null) { entityIcon = image.GetFromPath("fly/0") ?? image.GetFromPath("move/0"); // attempt to get image of the monster } } else if (image.WzFileParent.Name.StartsWith("Reactor")) { name = image.GetFromPath("action")?.WzValue.ToString(); entityIcon = image.GetFromPath("0/0"); } else // for breadcrumb like: '{ID}.img/info/icon' { if (ItemConstants.IsEquip(id)) { name = StringUtility.GetEqp(id); } else if (ItemConstants.IsPet(id)) { name = StringUtility.GetPet(id); } icon = image.GetFromPath("info/icon"); } if (icon == null) { icon = entityIcon; } } else if (wzObject is WzSubProperty subProperty) { // for path like: 'category.img/{ID}/info/icon' (Etc.wz) string imgName = subProperty.Name; id = int.Parse(imgName); if (ItemConstants.IsEtc(id)) { name = StringUtility.GetEtc(id); } else if (ItemConstants.IsCash(id)) { name = StringUtility.GetCash(id); } else if (ItemConstants.IsChair(id)) { name = StringUtility.GetChair(id); } else if (ItemConstants.IsConsume(id)) { name = StringUtility.GetConsume(id); } icon = subProperty.GetFromPath("info/icon"); } else { return; } grid.Rows.Add(id, icon?.GetBitmap(), name, properties); }
private void LoadWzData(WzMapleVersion mapleVersion, string mapleDirectory) { int selectedRoot = TabControlMain.SelectedIndex; switch (TabControlMain.SelectedTab.Controls[0]) { case DataViewer view: { // contains just the grid table view.GridView.Rows.Clear(); break; } case TabControl ctrl: { // contains sub-categories if (ctrl.SelectedTab.Controls[0] is DataViewer view) { view.GridView.Rows.Clear(); } break; } } ((DataViewer)EquipTab.SelectedTab.Controls[0]).GridView.Rows.Clear(); switch (selectedRoot) { default: Debug.WriteLine($"Unable to load WZ data unhandled selected index: {TabControlMain.SelectedIndex}"); break; case 0: // Equips { if (!LoadWzFileIfAbsent(ref CharacterWz, mapleDirectory + "/Character", mapleVersion)) { return; } List <WzImage> children = CharacterWz.WzDirectory.GetChildImages(); children.Sort((a, b) => a.Name.CompareTo(b.Name)); for (int i = 0; i < CharacterWz.WzDirectory.CountImages(); i++) { WzImage image = children[i]; string name = Path.GetFileNameWithoutExtension(image.Name); if (int.TryParse(name, out int equipId)) { int selectedTab = EquipTab.SelectedIndex; int bodyPart = equipId / 10000; switch (bodyPart) { default: if (selectedTab == 2 && bodyPart >= 130 && bodyPart <= 170) { AddGridRow(EquipWeaponsView.GridView, image); } else if (selectedTab == 1 && (bodyPart == 2 || bodyPart == 5)) { AddFaceRow(image); } else if (selectedTab == 0 && (bodyPart == 3 || bodyPart == 4)) { AddHairRow(image); } break; case 100: // Caps if (selectedTab == 4) { AddGridRow(EquipCapsView.GridView, image); } break; case 101: case 102: case 103: case 112: case 113: case 114: // Accessory if (selectedTab == 3) { AddGridRow(EquipAccessoryView.GridView, image); } break; case 110: // Cape if (selectedTab == 9) { AddGridRow(EquipCapesView.GridView, image); } break; case 104: // Coat if (selectedTab == 6) { AddGridRow(EquipTopsView.GridView, image); } break; case 108: // Glove if (selectedTab == 10) { AddGridRow(EquipGlovesView.GridView, image); } break; case 105: // Longcoat if (selectedTab == 5) { AddGridRow(EquipsOverallsView.GridView, image); } break; case 106: // Pants if (selectedTab == 7) { AddGridRow(EquipPantsView.GridView, image); } break; case 180: case 181: case 182: case 183: // Pet Equips // image.ParseImage(); break; case 111: // Rings if (selectedTab == 11) { AddGridRow(EquipRingsView.GridView, image); } break; case 109: // Shield if (selectedTab == 12) { AddGridRow(EquipShieldsView.GridView, image); } break; case 107: // Shoes if (selectedTab == 8) { AddGridRow(EquipShoesView.GridView, image); } break; case 190: case 191: case 193: // Taming Mob if (selectedTab == 13) { AddGridRow(EquipMountsView.GridView, image); } break; } } } break; } case 1: // Use case 2: // Setup case 3: // Etc case 4: // Cash case 9: // Pets { if (!LoadWzFileIfAbsent(ref ItemWz, mapleDirectory + "/Item", mapleVersion)) { return; } List <WzImage> children = ItemWz.WzDirectory.GetChildImages(); children.Sort((a, b) => a.Name.CompareTo(b.Name)); for (int i = 0; i < ItemWz.WzDirectory.CountImages(); i++) { WzImage image = children[i]; string name = Path.GetFileNameWithoutExtension(image.Name); if (int.TryParse(name, out int itemId)) { switch (itemId) { default: image.ParseImage(); if (selectedRoot == 9 && ItemConstants.IsPet(itemId)) // pet { AddGridRow(PetsView.GridView, image); } if (selectedRoot == 3 && ItemConstants.IsEtc(itemId)) // etc { image.WzProperties.ForEach(img => AddGridRow(EtcView.GridView, img)); } if (selectedRoot == 4 && ItemConstants.IsCash(itemId)) // cash { image.WzProperties.ForEach(img => AddGridRow(CashView.GridView, img)); } if (selectedRoot == 1 && ItemConstants.IsConsume(itemId)) // consume { image.WzProperties.ForEach(img => AddGridRow(UseConsumeView.GridView, img)); } break; case 204: // scrolls if (selectedRoot == 1) { image.WzProperties.ForEach(img => AddGridRow(UseScrollsView.GridView, img)); } break; case 206: case 207: case 233: // projectiles if (selectedRoot == 1) { image.WzProperties.ForEach(img => AddGridRow(UseProjectileView.GridView, img)); } break; case 301: // chairs case 399: // x-mas characters if (selectedRoot == 2) { image.WzProperties.ForEach(img => AddGridRow((itemId == 301 ? SetupChairsView : SetupOthersView).GridView, img)); } break; } } } break; } case 5: // Map { if (!LoadWzFileIfAbsent(ref MapWz, mapleDirectory + "/Map", mapleVersion)) { return; } List <WzImage> children = MapWz.WzDirectory.GetChildImages(); children.Sort((a, b) => a.Name.CompareTo(b.Name)); for (int i = 0; i < MapWz.WzDirectory.CountImages(); i++) { WzImage image = children[i]; string sMapId = Path.GetFileNameWithoutExtension(image.Name); if (int.TryParse(sMapId, out int mapId)) { image.ParseImage(); string properties = BuildProperties(image); WzCanvasProperty icon = (WzCanvasProperty)image.GetFromPath("miniMap/canvas"); string name = StringUtility.GetFieldFullName(mapId); MapsView.GridView.Rows.Add(mapId, icon?.GetBitmap(), name, properties); } } break; } case 6: // Mob { if (!LoadWzFileIfAbsent(ref MobWz, mapleDirectory + "/Mob", mapleVersion)) { return; } MobsView.GridView.Rows.Clear(); List <WzImage> children = MobWz.WzDirectory.GetChildImages(); children.Sort((a, b) => a.Name.CompareTo(b.Name)); for (int i = 0; i < MobWz.WzDirectory.CountImages(); i++) { WzImage image = children[i]; AddGridRow(MobsView.GridView, image); } break; } case 7: // Skills { if (!LoadWzFileIfAbsent(ref SkillWz, mapleDirectory + "/Skill", mapleVersion)) { return; } SkillsView.GridView.Rows.Clear(); SkillWz.WzDirectory.ParseImages(); List <WzImage> children = SkillWz.WzDirectory.GetChildImages(); for (int i = 0; i < SkillWz.WzDirectory.CountImages(); i++) { WzImage image = children[i]; string name = Path.GetFileNameWithoutExtension(image.Name); if (int.TryParse(name, out _)) { WzImageProperty tree = image.GetFromPath("skill"); if (tree is WzSubProperty) { List <WzImageProperty> skills = tree.WzProperties; skills.ForEach(s => AddSkillRow(s)); } } } break; } case 8: // NPCs { if (!LoadWzFileIfAbsent(ref NpcWz, mapleDirectory + "/Npc", mapleVersion)) { return; } NPCView.GridView.Rows.Clear(); List <WzImage> children = NpcWz.WzDirectory.GetChildImages(); children.Sort((a, b) => a.Name.CompareTo(b.Name)); for (int i = 0; i < NpcWz.WzDirectory.CountImages(); i++) { WzImage image = children[i]; AddGridRow(NPCView.GridView, image); } break; } case 10: // Reactors { if (!LoadWzFileIfAbsent(ref ReactorWz, mapleDirectory + "/Reactor", mapleVersion)) { return; } ReactorView.GridView.Rows.Clear(); List <WzImage> children = ReactorWz.WzDirectory.GetChildImages(); children.Sort((a, b) => a.Name.CompareTo(b.Name)); for (int i = 0; i < ReactorWz.WzDirectory.CountImages(); i++) { WzImage image = children[i]; AddGridRow(ReactorView.GridView, image); } break; } } }
private void AddGridRow(DataGridView grid, object wzObject) { int id; string properties = BuildProperties(wzObject); string name = null; WzCanvasProperty icon = null; if (wzObject is WzImage image) { image.ParseImage(); string imgName = Path.GetFileNameWithoutExtension(image.Name); properties = BuildProperties(image) ?? ""; id = int.Parse(imgName); WzImageProperty entityIcon = image.GetFromPath("stand/0"); WzImageProperty linkProperty = image.GetFromPath("info/link"); if (linkProperty != null) { string linkName = ((WzStringProperty)linkProperty).Value; image = ((WzDirectory)image.Parent).GetChildImages().Find(p => p.Name.Equals(linkName + ".img")); if (image == null) { return; } } if (image.WzFileParent.Name.StartsWith("Npc")) // icon path like: '{ID}/stand/0' // and also sometimes contains a link STRING property instead of using UOL { name = StringUtility.GetNPC(id); } else if (image.WzFileParent.Name.StartsWith("Mob")) { // icon path like: '{ID}/(move|stand|fly)/0' name = StringUtility.GetMob(id); // attempt to get image of the monster entityIcon = image.GetFromPath("fly/0") ?? image.GetFromPath("move/0"); } else if (image.WzFileParent.Name.StartsWith("Reactor")) { name = image.GetFromPath("action")?.WzValue.ToString(); entityIcon = image.GetFromPath("0/0"); } else // for breadcrumb like: '{ID}.img/info/icon' { if (ItemConstants.IsEquip(id)) { name = StringUtility.GetEqp(id); } else if (ItemConstants.IsPet(id)) { name = StringUtility.GetPet(id); } icon = (WzCanvasProperty)image.GetFromPath("info/icon"); } if (icon == null) { if (entityIcon is WzUOLProperty uol) { icon = (WzCanvasProperty)uol.LinkValue; } else { icon = (WzCanvasProperty)entityIcon; } } } else if (wzObject is WzSubProperty subProperty) { if (subProperty.WzFileParent.Name.StartsWith("Skill")) { id = int.Parse(subProperty.Name); name = StringUtility.GetSkill(subProperty.Name); icon = (WzCanvasProperty)subProperty.GetFromPath("icon"); } else // for breadcrumb like: 'category.img/{ID}/info/icon' (etc.wz) { string imgName = subProperty.Name; id = int.Parse(imgName); if (ItemConstants.IsEtc(id)) { name = StringUtility.GetEtc(id); } else if (ItemConstants.IsCash(id)) { name = StringUtility.GetCash(id); } else if (ItemConstants.IsChair(id)) { name = StringUtility.GetChair(id); } else if (ItemConstants.IsConsume(id)) { name = StringUtility.GetConsume(id); } WzImageProperty imgIcon = subProperty.GetFromPath("info/icon"); if (imgIcon is WzUOLProperty ufo) { imgIcon = (WzCanvasProperty)ufo.LinkValue; } else if (imgIcon is WzCanvasProperty canvas) { imgIcon = canvas; } if (imgIcon != null) { icon = (WzCanvasProperty)imgIcon; } } } else { return; } Bitmap bitmap = null; try { bitmap = icon?.GetBitmap(); } catch (Exception) { } grid.Rows.Add(id, bitmap, name, properties); }