|
| 1 | +using System; |
| 2 | +using System.ComponentModel; |
| 3 | +using System.Globalization; |
| 4 | +using System.Linq; |
| 5 | +using System.Windows; |
| 6 | +using System.Windows.Controls; |
| 7 | +using System.Windows.Input; |
| 8 | +using System.Windows.Media; |
| 9 | + |
| 10 | +using ACViewer.Data; |
| 11 | +using ACE.DatLoader; |
| 12 | + |
| 13 | +namespace ACViewer.View |
| 14 | +{ |
| 15 | + /// <summary> |
| 16 | + /// Interaction logic for ArmorList.xaml |
| 17 | + /// </summary> |
| 18 | + public partial class ArmorList : Window |
| 19 | + { |
| 20 | + public ArmorList() |
| 21 | + { |
| 22 | + InitializeComponent(); |
| 23 | + |
| 24 | + this.Owner = App.Current.MainWindow; |
| 25 | + |
| 26 | + txtArmor.TextChanged += new TextChangedEventHandler(txtArmor_TextChanged); |
| 27 | + txtArmor.Focus(); |
| 28 | + } |
| 29 | + |
| 30 | + private void txtArmor_TextChanged(object sender, TextChangedEventArgs e) |
| 31 | + { |
| 32 | + SearchArmor(txtArmor.Text.Trim()); |
| 33 | + } |
| 34 | + |
| 35 | + private void SearchArmor(string criteria) |
| 36 | + { |
| 37 | + if (criteria != "") |
| 38 | + { |
| 39 | + dgArmorResults.Items.Clear(); |
| 40 | + |
| 41 | + criteria = criteria.ToLower(); |
| 42 | + var results = LootArmorList.Loot.Where(x => x.Value.Name.ToLower().Contains(criteria)).OrderBy(x => x.Key); |
| 43 | + foreach (var s in results) |
| 44 | + { |
| 45 | + dgArmorResults.Items.Add(s.Value); |
| 46 | + } |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + // Get the ClothingBase of the item and load it in the window |
| 51 | + // - This should be so much easier, Optim hates WPF |
| 52 | + // Ref https://wpfadventures.wordpress.com/2008/12/02/wpf-datagrid-detecting-clicked-cell-and-row/ |
| 53 | + private void DataGridCell_MouseDoubleClick(object sender, MouseButtonEventArgs e) |
| 54 | + { |
| 55 | + if (DatManager.PortalDat == null) |
| 56 | + { |
| 57 | + MessageBox.Show($"Please load the DATs before trying to view item."); |
| 58 | + return; |
| 59 | + } |
| 60 | + |
| 61 | + DependencyObject dep = (DependencyObject)e.OriginalSource; |
| 62 | + |
| 63 | + // iteratively traverse the visual tree |
| 64 | + while ((dep != null) && |
| 65 | + !(dep is DataGridRow)) |
| 66 | + { |
| 67 | + dep = VisualTreeHelper.GetParent(dep); |
| 68 | + } |
| 69 | + |
| 70 | + if (dep == null) |
| 71 | + return; |
| 72 | + |
| 73 | + DataGridRow row = dep as DataGridRow; |
| 74 | + // find the object that is related to this row |
| 75 | + object data = row.Item; |
| 76 | + |
| 77 | + // extract the property value |
| 78 | + PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(data); |
| 79 | + PropertyDescriptor cbProperty = properties["ClothingBase"]; |
| 80 | + string clothingBaseString = cbProperty.GetValue(data).ToString(); |
| 81 | + |
| 82 | + PropertyDescriptor wcidProperty = properties["WCID"]; |
| 83 | + uint wcid = Convert.ToUInt32(wcidProperty.GetValue(data)); |
| 84 | + var lootItem = LootArmorList.Get(wcid); |
| 85 | + |
| 86 | + if (!uint.TryParse(lootItem.ClothingBase, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var clothingBase)) |
| 87 | + { |
| 88 | + // input invalid -- throw error? |
| 89 | + MessageBox.Show($"Invalid DID format: {lootItem.ClothingBase}"); |
| 90 | + return; |
| 91 | + } |
| 92 | + |
| 93 | + |
| 94 | + uint filetype = 0; |
| 95 | + |
| 96 | + if (DatManager.PortalDat.AllFiles.TryGetValue(clothingBase, out var portalFile)) |
| 97 | + { |
| 98 | + filetype = clothingBase >> 24; |
| 99 | + var fileTypeSelect = FileExplorer.FileTypes.FirstOrDefault(i => i.ID == filetype); |
| 100 | + if (fileTypeSelect == null) |
| 101 | + { |
| 102 | + Console.WriteLine($"Unknown filetype {clothingBase:X8} found in Portal Dat"); |
| 103 | + return; |
| 104 | + } |
| 105 | + |
| 106 | + var items = FileExplorer.Instance.FileType.Items; |
| 107 | + |
| 108 | + foreach (var item in items) |
| 109 | + { |
| 110 | + if (item is Entity.FileType entityFileType && entityFileType.ID == filetype) |
| 111 | + { |
| 112 | + FileExplorer.Instance.FileType.SelectedItem = item; |
| 113 | + var didStr = clothingBase.ToString("X8"); |
| 114 | + foreach (var file in FileExplorer.Instance.Files.Items) |
| 115 | + { |
| 116 | + if (file.ToString().Equals(didStr)) |
| 117 | + { |
| 118 | + FileExplorer.Instance.Files.SelectedItem = file; |
| 119 | + FileExplorer.Instance.Files.ScrollIntoView(file); |
| 120 | + |
| 121 | + var clothing = DatManager.PortalDat.ReadFromDat<ACE.DatLoader.FileTypes.ClothingTable>(clothingBase); |
| 122 | + ClothingTableList.Instance.OnClickClothingBase(clothing, clothingBase, lootItem.PaletteTemplate, lootItem.Shade); |
| 123 | + this.Close(); |
| 124 | + } |
| 125 | + } |
| 126 | + break; |
| 127 | + } |
| 128 | + |
| 129 | + } |
| 130 | + } |
| 131 | + } |
| 132 | + |
| 133 | + } |
| 134 | +} |
0 commit comments