Ejemplo n.º 1
0
        private void LoadTemplatesFromDisk()
        {
            string executionPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            string filePath = executionPath + "/WindWaker/Templates/ActorCategoryList.json";

            string fileContents = File.ReadAllText(filePath);

            try
            {
                var categoryData = JsonConvert.DeserializeObject<List<ObjectUIListEntry>>(fileContents);

                // Sort them by category
                var objByCategory = new Dictionary<string, List<ObjectUIListEntry>>();
                for (int i = 0; i < categoryData.Count; i++)
                {
                    if (!objByCategory.ContainsKey(categoryData[i].Category))
                        objByCategory[categoryData[i].Category] = new List<ObjectUIListEntry>();

                    objByCategory[categoryData[i].Category].Add(categoryData[i]);
                }

                var fullEntryList = new List<ObjectUIListEntry>();
                var tabList = new List<TabItem>();

                // Create tabs for each unique category
                foreach (var kvp in objByCategory)
                {
                    TabItem tab = new TabItem();
                    tab.Header = kvp.Key;

                    foreach (var entry in kvp.Value)
                    {
                        // Create a new BitmapImage to represent the icon - caching the icon on load so that it doesn't
                        // have atomic focus on the file and lock others from using the same icon.
                        using (FileStream fs = new FileStream(entry.IconPath, FileMode.Open))
                        {
                            BitmapImage entryIcon = new BitmapImage();
                            entryIcon.BeginInit();
                            entryIcon.CacheOption = BitmapCacheOption.OnLoad;
                            entryIcon.StreamSource = fs;
                            entryIcon.EndInit();

                            entry.DisplayImage = entryIcon;
                            tab.Content.Add(entry);
                            fullEntryList.Add(entry);
                        }
                    }

                    tabList.Add(tab);
                }

                // Use the flat-list of our entries and assign it as the source of the CollectionViewSource so we can filter it.
                FullList.Source = fullEntryList;

                // Sort the Tabs by header, A-Z (but put "Uncategorized" last)
                tabList.Sort(delegate(TabItem a, TabItem b) { return a.Header.CompareTo(b.Header); });
                TabItem uncatTab = tabList.Find(x => x.Header == "Uncategorized");
                if (uncatTab != null)
                {
                    tabList.Remove(uncatTab);
                    tabList.Add(uncatTab);
                }

                for (int i = 0; i < tabList.Count; i++)
                {
                    Tabs.Add(tabList[i]);
                }
            }
            catch (Exception ex)
            {
                WLog.Error(LogCategory.EditorCore, null, "Caught Exception while loading Actor Object List: {0}", ex);
            }
        }
Ejemplo n.º 2
0
        private void LoadTemplatesFromDisk()
        {
            string executionPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            string filePath      = executionPath + "/WindWaker/Templates/ActorCategoryList.json";

            string fileContents = File.ReadAllText(filePath);

            try
            {
                var categoryData = JsonConvert.DeserializeObject <List <ObjectUIListEntry> >(fileContents);


                // Sort them by category
                var objByCategory = new Dictionary <string, List <ObjectUIListEntry> >();
                for (int i = 0; i < categoryData.Count; i++)
                {
                    if (!objByCategory.ContainsKey(categoryData[i].Category))
                    {
                        objByCategory[categoryData[i].Category] = new List <ObjectUIListEntry>();
                    }

                    objByCategory[categoryData[i].Category].Add(categoryData[i]);
                }

                var fullEntryList = new List <ObjectUIListEntry>();
                var tabList       = new List <TabItem>();

                // Create tabs for each unique category
                foreach (var kvp in objByCategory)
                {
                    TabItem tab = new TabItem();
                    tab.Header = kvp.Key;

                    foreach (var entry in kvp.Value)
                    {
                        // Create a new BitmapImage to represent the icon - caching the icon on load so that it doesn't
                        // have atomic focus on the file and lock others from using the same icon.
                        using (FileStream fs = new FileStream(entry.IconPath, FileMode.Open))
                        {
                            BitmapImage entryIcon = new BitmapImage();
                            entryIcon.BeginInit();
                            entryIcon.CacheOption  = BitmapCacheOption.OnLoad;
                            entryIcon.StreamSource = fs;
                            entryIcon.EndInit();

                            entry.DisplayImage = entryIcon;
                            tab.Content.Add(entry);
                            fullEntryList.Add(entry);
                        }
                    }

                    tabList.Add(tab);
                }

                // Use the flat-list of our entries and assign it as the source of the CollectionViewSource so we can filter it.
                FullList.Source = fullEntryList;

                // Sort the Tabs by header, A-Z (but put "Uncategorized" last)
                tabList.Sort(delegate(TabItem a, TabItem b) { return(a.Header.CompareTo(b.Header)); });
                TabItem uncatTab = tabList.Find(x => x.Header == "Uncategorized");
                if (uncatTab != null)
                {
                    tabList.Remove(uncatTab);
                    tabList.Add(uncatTab);
                }

                for (int i = 0; i < tabList.Count; i++)
                {
                    Tabs.Add(tabList[i]);
                }
            }
            catch (Exception ex)
            {
                WLog.Error(LogCategory.EditorCore, null, "Caught Exception while loading Actor Object List: {0}", ex);
            }
        }