/// <summary> /// Open the Inventory for a category to navigate within it and execute Actions on the Items. /// <para> /// getsCommand is a function which takes an Item and returns wether the Item should receive a/many Command/s or not /// </para> /// <para>onItemSelection is an Action which is executed with the selected Item</para> /// <para>isAvailable is a FUnc which determines wether the item is available or not. It is appended to each Option</para> /// <para>UnavailableMessage is a Func which retruns the string to be printed when the Optionw as selected & unavailable</para> /// <para>if allowItemActions = false, no Item Actions are allowed</para> /// </summary> void NavigateItems(string category, Func <Item, bool> getsCommand, Action <Item> onItemSelection, Func <Item, bool> isAvailable, Func <Item, string> UnavailableMessage, bool allowItemActions) { Option selected = null; while (selected != Optionhandler.Exit) { List <Item> Items = this.GetAllItems(category); if (Items.Count == 0) { return; } printHeader(); Optionhandler OH = new Optionhandler(true); OH.setName("Inventory.Item"); foreach (Item i in Items) { if (allowItemActions == false) { if (getsCommand(i)) { //Options which are available on the Item are defined on the Item and wrapped by the GenericItemOption GenericItemOption opt = new GenericItemOption(i); if (isAvailable != null) { Func <bool> f = () => isAvailable(i); opt.SetAvailable(f); } if (UnavailableMessage != null) { Func <string> ff = () => UnavailableMessage(i); opt.setNotAvailable(ff); } OH.AddOption(opt); } else { CIO.Print(i.getDescription()); } } else { GenericItemOption opt = new GenericItemOption(i); OH.AddOption(opt); } } selected = OH.selectOption(false); if (selected.GetType() == typeof(GenericItemOption)) { onItemSelection(((GenericItemOption)selected).getItem()); } } }
protected Option PickCategory() { printHeader(); Optionhandler OH = new Optionhandler("pick a category", true); OH.setName("Spellbook.Types"); foreach (SpellType i in this.getSpellTypes()) { OH.AddOption(i); } return(OH.selectOption(false)); }
/// <summary> /// Open the Inventory to pick a category. /// </summary> protected GenericOption PickCategory() { printHeader(); Optionhandler OH = new Optionhandler("pick a category", true); OH.setName("Inventory.Category"); foreach (string i in this.GetCategories()) { GenericOption GO = new GenericOption(i); OH.AddOption(GO); } GenericOption selected = (GenericOption)OH.selectOption(false); return(selected); }
void NavigateItems(SpellType type) { Option selected = null; while (selected != Optionhandler.Exit) { List <Spell> Spells = this.getSpells(type); if (Spells.Count == 0) { return; } printHeader(); Optionhandler OH = new Optionhandler(true); OH.setName("Spellbook.Spell"); foreach (Spell i in Spells) { OH.AddOption(i); } selected = OH.selectOption(false); } }