public static void PopulateWithAllItemsCollection(PanelItemHolder holder, string styleName, string filterName) { List<PuzzleItem> allItems = new List<PuzzleItem>(); // can only have duplicates in same style List<PuzzleItem> styleItems = new List<PuzzleItem>(); // can have duplicates List<PuzzleItem> nonMatchingItems = new List<PuzzleItem>(); List<PuzzleItem> sortedItems = new List<PuzzleItem>(); List<PuzzleItem> remainingItems = new List<PuzzleItem>(); int RecursionDepth = 0; //List<string> filter; //Global.Filters.TryGetValue(filterName, out filter); //switch (filterName) //{ // case "All Items": filter = null; // break; // case "Portal 2 Items": filter = Portal2Items; // break; // case "BEE Items": filter = BEE1Items; // break; // case "HMW Items": filter = HMWItems; // break; // case "Carl's Items": filter = CarlItems; // break; // case "FGE Items": filter = FGEItems; // break; // case "Miscellaneous": filter = MiscItems; // break; // default: filter = null; // break; //} VBSPStyle style = Global.GetStyle(styleName); while (style != null) { RecursionDepth++; if (RecursionDepth > 12) break; styleItems.Clear(); foreach (PuzzleItem aPuzzleItem in style.BaseItems) { if ((!HasItemType(allItems, aPuzzleItem.TypeName))) { //get each subcatagory for (int i = 0; i <= aPuzzleItem.SubcatagoryIndexMax; i++) { styleItems.Add(aPuzzleItem.Clone()); aPuzzleItem.ToggleSubcatagory(); } } } allItems.AddRange(styleItems); style = Global.GetStyle(style.Base); } // repeat for base style of this style, so eg. 1950s items show up for 1970 if they aren't in 1970 //if (filterName != "Items Matching Style") //{ // // lastly, add any remaining items that don't have a matching style // foreach (VBSPStyle style2 in Global.ListOfStyles) // { // foreach (PuzzleItem aPuzzleItem in style2.BaseItems) // { // if ((!HasItemType(allItems, aPuzzleItem.TypeName))) // { // //get each subcatagory // for (int i = 0; i <= aPuzzleItem.SubcatagoryIndexMax; i++) // { // PuzzleItem subtype = aPuzzleItem.Clone(); // if (subtype.PreviewImage != null) // { // subtype.PreviewImage = Global.ScaleImage(subtype.PreviewImage, 64, 64); // using (Graphics g = Graphics.FromImage(subtype.PreviewImage)) // { // g.DrawString(style2.Name, new Font("Tahoma", 12), Brushes.Blue, new PointF(0, 0)); // } // } // allItems.Add(subtype); // aPuzzleItem.ToggleSubcatagory(); // } // } // } // } //} //else //{ // // lastly, add any remaining items that don't have a matching style // foreach (VBSPStyle style2 in Global.ListOfStyles) // { // foreach (PuzzleItem aPuzzleItem in style2.BaseItems) // { // if ((!HasItemType(allItems, aPuzzleItem.TypeName))) // { // //get each subcatagory // for (int i = 0; i <= aPuzzleItem.SubcatagoryIndexMax; i++) // { // PuzzleItem subtype = aPuzzleItem.Clone(); // if (subtype.PreviewImage != null) // { // subtype.PreviewImage = Global.ScaleImage(subtype.PreviewImage, 64, 64); // using (Graphics g = Graphics.FromImage(subtype.PreviewImage)) // { // g.DrawString(style2.Name, new Font("Tahoma", 12), Brushes.Blue, new PointF(0, 0)); // } // } // holder.unfilteredPuzzleItems.Add(subtype); // aPuzzleItem.ToggleSubcatagory(); // } // } // } // } //} foreach (PuzzleItem p in allItems) { holder.InsertBefore(p, 0); } //////if (filter != null) //////{ ////// // now sort them according to the filter ////// string[] sorter = filter.ToArray(); ////// //if (sorter == null || sorter == MiscItems) sorter = AllItems; ////// remainingItems.AddRange(allItems); ////// foreach (string s in sorter) ////// { ////// // in order, add all items that match to the sortedItems ////// foreach (PuzzleItem p in allItems) ////// { ////// if (p.TypeName == s) ////// { ////// sortedItems.Add(p); ////// remainingItems.Remove(p); ////// } ////// } ////// } ////// sortedItems.AddRange(remainingItems); ////// // now add them all to our PanelItemHolder ////// foreach (PuzzleItem aPuzzleItem in sortedItems) ////// { ////// if (filter.Contains(aPuzzleItem.TypeName)) ////// holder.InsertAfter(aPuzzleItem, holder.GetNumberOfItems() - 1); ////// else ////// holder.PuzzleItems.Add(aPuzzleItem); ////// } //////} if (filterName.Trim() == "Items Matching Style") { remainingItems.Clear(); remainingItems.AddRange(allItems); // lastly, add any remaining items that don't have a matching style //foreach (VBSPStyle style2 in Global.ListOfStyles) //{ VBSPStyle style2 = Global.GetStyle(StyleName); foreach (PuzzleItem aPuzzleItem in style2.BaseItems) { if (aPuzzleItem.SubcatagoryIndexMax > 0) { holder.InsertAfter(aPuzzleItem.Clone(), holder.GetNumberOfItems() - 1); remainingItems.Remove((from ri in remainingItems where ri.TypeName == aPuzzleItem.TypeName select ri).FirstOrDefault()); } // if ((!HasItemType(allItems, aPuzzleItem.TypeName))) // { // //get each subcatagory // for (int i = 0; i <= aPuzzleItem.SubcatagoryIndexMax; i++) // { // PuzzleItem subtype = aPuzzleItem.Clone(); // if (subtype.PreviewImage != null) // { // subtype.PreviewImage = Global.ScaleImage(subtype.PreviewImage, 64, 64); // using (Graphics g = Graphics.FromImage(subtype.PreviewImage)) // { // g.DrawString(style2.Name, new Font("Tahoma", 12), Brushes.Blue, new PointF(0, 0)); // } // } // holder.InsertAfter(subtype, holder.GetNumberOfItems() - 1); // //holder.unfilteredPuzzleItems.Add(subtype); // aPuzzleItem.ToggleSubcatagory(); // } // } } foreach (PuzzleItem aPuzzleItem in remainingItems) { holder.PuzzleItems.Add(aPuzzleItem); } //holder.PuzzleItems.AddRange(remainingItems); //} } int oooo = 0; }
public static void LoadItemStyles() { // Item collections can define new styles based on base styles from the .style files // So go through each item collection and create the new styles string[] filePaths = Directory.GetFiles(Global.ItemDirectory, "*.beec"); foreach (string path in filePaths) { string[] filecontents = File.ReadAllLines(path); //Parse the definition for style info ArrayList styleDefinition = new ArrayList(); bool stylish = false; foreach (string line in filecontents) { if (line.Contains("@EndStyle")) { stylish = false; break;//take out the break if you want the whole file to be parsed for styleinfo } if (stylish) styleDefinition.Add(line); if (line.Contains("@Style")) stylish = true; } string[] StyleDefinition = (string[])styleDefinition.ToArray(typeof(string)); //take out the comments for (int i = 0; i < StyleDefinition.Length; i++) { if (StyleDefinition[i].Trim().StartsWith("//")) StyleDefinition[i] = StyleDefinition[i].Trim().Substring(2, StyleDefinition[i].Trim().Length - 2); } //find specific details from the style string styleName = Global.FindValue(StyleDefinition, "Style"); string baseStyleName = Global.FindValue(StyleDefinition, "Base"); string author = Global.FindValue(StyleDefinition, "Author"); string comment = Global.FindValue(StyleDefinition, "Comment"); if (styleName == null) { if (baseStyleName != null) styleName = baseStyleName; else styleName = "Clean"; } // if it's a new style... VBSPStyle thisStyle = GetStyle(styleName); if (thisStyle == null && baseStyleName != styleName) { // ...based on an existing style... VBSPStyle baseStyle = GetStyle(baseStyleName); if (baseStyle != null) { // ...then add it. thisStyle = new VBSPStyle(baseStyle.WholeDefinition); thisStyle.Name = styleName; thisStyle.Author = author; thisStyle.Comment = comment; thisStyle.Base = baseStyleName; ListOfStyles.Add(thisStyle); } } if (thisStyle == null) continue; /* // make a list of the styles available for each item type ItemTypeStyles = new Dictionary<string, List<string>>(); foreach (string s in filecontents) { string line = s.Trim(); //make sure this whole line is long enough to even have a property this long if (line.Length >= 10) { if (line.Substring(1, 5).Equals("Type\"")) { string typeName = line.Substring(4 + 2).Trim(); if (!ItemTypeStyles.ContainsKey(typeName)) ItemTypeStyles.Add(typeName, new List<string>()); ItemTypeStyles[typeName].Add(typeName); } } } */ string[][] individualItemDefinitions = Global.FindSubValues(filecontents, "Item"); foreach (string[] definition in individualItemDefinitions) { PuzzleItem aPuzzleItem = new PuzzleItem(definition); aPuzzleItem.style = thisStyle; thisStyle.BaseItems.Add(aPuzzleItem); //don't need subcategories yet } } // next }