Beispiel #1
0
 public TagEntry(ITag baseTag, TagClass parent, string name)
 {
     RawTag = baseTag;
     TagFileName = name;
     ParentClass = parent;
 }
Beispiel #2
0
 private bool FilterClass(TagClass tagClass, string filter)
 {
     bool emptyFilter = string.IsNullOrWhiteSpace(filter);
     return tagClass.Children.Count != 0 ||
            (App.AssemblyStorage.AssemblySettings.HalomapShowEmptyClasses && emptyFilter &&
             !App.AssemblyStorage.AssemblySettings.HalomapOnlyShowBookmarkedTags);
 }
Beispiel #3
0
        private void LoadTags()
        {
            if (_cacheFile.TagClasses == null || _cacheFile.Tags == null)
                return;

            // Load all the tag classes into data
            var classes = new List<TagClass>();
            var classWrappers = new Dictionary<ITagClass, TagClass>();
            Dispatcher.Invoke(new Action(() =>
                                  {
                                      foreach (var tagClass in _cacheFile.TagClasses)
                                      {
                                          var wrapper = new TagClass(tagClass, CharConstant.ToString(tagClass.Magic), _cacheFile.StringIDs.GetString(tagClass.Description));
                                          classes.Add(wrapper);
                                          classWrappers[tagClass] = wrapper;
                                      }
                                  }));

            Dispatcher.Invoke(new Action(() => StatusUpdater.Update("Loaded Tag Classes")));

            // Load all the tags into the treeview (into their class categoies)
            _hierarchy.Entries = new List<TagEntry>();
            foreach (var tag in _cacheFile.Tags)
            {
                if (tag.MetaLocation != null)
                {
                    var fileName = _cacheFile.FileNames.GetTagName(tag);
                    if (fileName == null || fileName.Trim() == "")
                        fileName = tag.Index.ToString();

                    var parentClass = classWrappers[tag.Class];
                    var entry = new TagEntry(tag, parentClass, fileName);
                    parentClass.Children.Add(entry);
                    _hierarchy.Entries.Add(entry);
                }
                else
                    _hierarchy.Entries.Add(null);
            }

            foreach (var tagClass in classes)
                tagClass.Children.Sort((x, y) => String.Compare(x.TagFileName, y.TagFileName, StringComparison.OrdinalIgnoreCase));

            //// Taglist Generation
            /*string taglistPath = @"C:\" + _cacheFile.Info.InternalName.ToLower() + ".taglist";
            List<string> taglist = new List<string>();
            taglist.Add("<scenario=\"" + _cacheFile.Info.ScenarioName + "\">");
            for (int i = 0; i < _cacheFile.Tags.Count; i++)
            {
                ITag tag = _cacheFile.Tags[i];
                if (tag.Index.IsValid)
                    taglist.Add(string.Format("\t<tag id=\"{0}\" class=\"{1}\">{2}</tag>", tag.Index.ToString(), ExtryzeDLL.Util.CharConstant.ToString(tag.Class.Magic) ,_cacheFile.FileNames.FindTagName(tag.Index)));
            }
            taglist.Add("</scenario>");
            File.WriteAllLines(taglistPath, taglist.ToArray<string>());*/

            Dispatcher.Invoke(new Action(() => StatusUpdater.Update("Loaded Tags")));

            classes.Sort((x, y) => String.Compare(x.TagClassMagic, y.TagClassMagic, StringComparison.OrdinalIgnoreCase));
            Dispatcher.Invoke(new Action(delegate
                                  {
                                      _tagsComplete = new ObservableCollection<TagClass>(classes);

                                      // Load un-populated tags
                                      foreach (var tagClass in _tagsComplete.Where(tagClass => tagClass.Children.Count > 0))
                                          _tagsPopulated.Add(tagClass);
                                      _hierarchy.Classes = _tagsPopulated;
                                  }));

            // Add to the treeview
            Dispatcher.Invoke(new Action(() => UpdateEmptyTags(cbShowEmptyTags.IsChecked != null && (bool) cbShowEmptyTags.IsChecked)));
        }
Beispiel #4
0
        private TagHierarchy BuildTagHierarchy(Func<TagClass, bool> classFilter, Func<TagEntry, bool> tagFilter)
        {
            // Build a dictionary of tag classes
            var classWrappers = new Dictionary<ITagClass, TagClass>();
            foreach (ITagClass tagClass in _cacheFile.TagClasses)
            {
                string name = CharConstant.ToString(tagClass.Magic);
                string description = _cacheFile.StringIDs.GetString(tagClass.Description) ?? "unknown";
                var wrapper = new TagClass(tagClass, name, description);
                classWrappers[tagClass] = wrapper;
            }

            // Now add tags which match the filter to their respective classes
            var result = new TagHierarchy
            {
                Entries = _tagEntries
            };

            foreach (TagEntry tag in _tagEntries.Where(t => t != null))
            {
                TagClass parentClass = classWrappers[tag.RawTag.Class];
                if (tagFilter(tag))
                    parentClass.Children.Add(tag);
            }

            // Build a sorted list of classes, and then sort each tag in them
            List<TagClass> classList = classWrappers.Values.Where(classFilter).ToList();
            classList.Sort((a, b) => String.Compare(a.TagClassMagic, b.TagClassMagic, StringComparison.OrdinalIgnoreCase));
            foreach (TagClass tagClass in classList)
                tagClass.Children.Sort((a, b) => String.Compare(a.TagFileName, b.TagFileName, StringComparison.OrdinalIgnoreCase));

            // Done!
            Dispatcher.Invoke(new Action(delegate
            {
                // Give the dispatcher ownership of the ObservableCollection
                result.Classes = new ObservableCollection<TagClass>(classList);
            }));

            return result;
        }
Beispiel #5
0
        private void txtTagSearch_TextChanged(object sender = null, TextChangedEventArgs e = null)
        {
            var searchString = string.Empty;
            if (sender != null)
                searchString = ((TextBox) sender).Text;

            if (String.IsNullOrWhiteSpace(searchString))
            {
                tvTagList.DataContext = Settings.halomapShowEmptyClasses
                                            ? _tagsComplete
                                      : Settings.halomapOnlyShowBookmarkedTags
                                            ? TagsBookmarked
                                            : _tagsPopulated;

                return;
            }

            // Set Usage type
            var tagsToSearch = Settings.halomapOnlyShowBookmarkedTags ? TagsBookmarked : _tagsPopulated;

            // Apply Filtered Collection
            FilteredTags = new ObservableCollection<TagClass>();
            tvTagList.DataContext = FilteredTags;

            // Check if we're doing a Datum Search
            uint datumIndex;
            if (searchString.StartsWith("0x") && uint.TryParse(searchString.Remove(0, 2), NumberStyles.HexNumber, null, out datumIndex))
            {
                // Do search
                foreach (var tagClass in tagsToSearch)
                {
                    var tagEntries = tagClass.Children.Where(tag => tag.RawTag.Index.ToString().Remove(0, 2).ToLowerInvariant().Contains(searchString.ToLowerInvariant().Remove(0, 2))).ToList();
                    if (tagEntries.Count <= 0) continue;

                    var newTagClass = tagClass;
                    newTagClass.Children = tagEntries;
                    FilteredTags.Add(newTagClass);
                }

                return;
            }

            // Check if we're doing a TagClass Search
            if (searchString.StartsWith("\"") && searchString.EndsWith("\""))
            {
                // Do search
                foreach (var tagClass in tagsToSearch.Where(tagClass => tagClass.TagClassMagic.ToLowerInvariant().Contains(searchString.ToLowerInvariant().Replace("\"", ""))))
                {
                    var newTagClass = new TagClass(tagClass.RawClass, tagClass.TagClassMagic, tagClass.Description)
                                            {
                                                Children = new List<TagEntry>()
                                            };
                    foreach (var entry in tagClass.Children)
                        newTagClass.Children.Add(new TagEntry(entry.RawTag, newTagClass, entry.TagFileName));
                    FilteredTags.Add(newTagClass);
                    NotifyPropertyChanged("FilteredTags");
                }

                return;
            }

            // ugh, gotta do a boring search
            foreach (var tagClass in tagsToSearch)
            {
                var tagEntries = tagClass.Children.Where(tag => tag.TagFileName.ToLowerInvariant().Contains(searchString)).ToList();
                if (tagEntries.Count <= 0) continue;

                var newTagClass = new TagClass(tagClass.RawClass, tagClass.TagClassMagic, tagClass.Description)
                                      {
                                          Children = new List<TagEntry>()
                                      };
                foreach (var entry in tagEntries)
                    newTagClass.Children.Add(new TagEntry(entry.RawTag, newTagClass, entry.TagFileName));
                FilteredTags.Add(newTagClass);
            }
        }