public void AddNewDefToCat(Def newDef, DetailCategory cat) { ItemDetail newItem = DefDatabaseBuilder.MakeItemDetail(newDef, cat); cat.Add(newItem); newItem.Filter(_filterString); itemDetails.Add(newDef, newItem); if (MainWindow.openWindow == this) { SelectedItemDef = newItem; } }
public static IEnumerable <Widgets.DropdownMenuElement <string> > MakeDropdownMenu(Type type, Func <object, bool> func) { List <Widgets.DropdownMenuElement <string> > options = new List <Widgets.DropdownMenuElement <string> >();; if (type == typeof(bool)) { options.Add(new Widgets.DropdownMenuElement <string> { option = new FloatMenuOption("True", () => func(true), MenuOptionPriority.Default), payload = "true" }); options.Add(new Widgets.DropdownMenuElement <string> { option = new FloatMenuOption("False", () => func(false), MenuOptionPriority.Default), payload = "false" }); return(options); } else if (type.IsEnum) { var vals = Enum.GetValues(type); foreach (var val in vals) { string name = Enum.GetName(type, val); options.Add(new Widgets.DropdownMenuElement <string> { option = new FloatMenuOption(name, () => func(val), MenuOptionPriority.Default), payload = name }); } return(options); } else if (!typeof(Def).IsAssignableFrom(type)) // not def, enum, or bool { return(new Widgets.DropdownMenuElement <string>[] { new Widgets.DropdownMenuElement <string> { option = new FloatMenuOption("Nothing found", null, MenuOptionPriority.Default), payload = null } }); } IEnumerator iterator; if (type == typeof(Def)) { List <Def> allDefs = new List <Def>(); Type[] defTypes = DatabaseHelper.AllTypeSubclasses(typeof(Def)); foreach (Type t in defTypes) { allDefs.AddRange(DefDatabaseBuilder.GetDefDatabaseList(t) as ICollection <Def>); } iterator = allDefs.GetEnumerator(); } else { iterator = (DefDatabaseBuilder.GetDefDatabaseList(type) as ICollection).GetEnumerator(); } while (iterator.MoveNext()) { object cur = iterator.Current; string name = (cur as Def).defName; options.Add(new Widgets.DropdownMenuElement <string> { option = new FloatMenuOption(name, () => func(cur), MenuOptionPriority.Default), payload = name }); } options.SortBy(x => x.payload); options.Insert(0, new Widgets.DropdownMenuElement <string> { option = new FloatMenuOption("null", () => func(null), MenuOptionPriority.High), payload = "null" }); return(options); }