[197] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 |
|
---|
| 4 | namespace AllocsFixes
|
---|
| 5 | {
|
---|
| 6 | public class ItemList
|
---|
| 7 | {
|
---|
| 8 | private static ItemList instance;
|
---|
| 9 |
|
---|
| 10 | public static ItemList Instance {
|
---|
| 11 | get {
|
---|
| 12 | if (instance == null) {
|
---|
| 13 | instance = new ItemList ();
|
---|
| 14 | }
|
---|
| 15 | return instance;
|
---|
| 16 | }
|
---|
| 17 | }
|
---|
| 18 |
|
---|
| 19 | private ItemList ()
|
---|
| 20 | {
|
---|
| 21 | }
|
---|
| 22 |
|
---|
| 23 | private SortedDictionary<string, ItemValue> items = new SortedDictionary<string, ItemValue> ();
|
---|
| 24 |
|
---|
| 25 | public List<string> ItemNames {
|
---|
| 26 | get { return new List<string> (items.Keys); }
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | public Nullable<ItemValue> GetItemValue (string itemName)
|
---|
| 30 | {
|
---|
| 31 | if (items.ContainsKey (itemName)) {
|
---|
| 32 | return items [itemName];
|
---|
| 33 | } else {
|
---|
| 34 | itemName = itemName.ToLower ();
|
---|
| 35 | foreach (KeyValuePair<string, ItemValue> kvp in items) {
|
---|
| 36 | if (kvp.Key.ToLower ().Equals (itemName)) {
|
---|
| 37 | return kvp.Value;
|
---|
| 38 | }
|
---|
| 39 | }
|
---|
| 40 | return null;
|
---|
| 41 | }
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | public void Init ()
|
---|
| 45 | {
|
---|
| 46 | NGuiInvGridCreativeMenu cm = new NGuiInvGridCreativeMenu ();
|
---|
| 47 | foreach (InventoryField invF in cm.GetAllItems()) {
|
---|
| 48 | ItemBase ib = ItemBase.list [invF.itemValue.type];
|
---|
| 49 | string name = ib.GetItemName (invF.itemValue);
|
---|
| 50 | if (name != null && name.Length > 0) {
|
---|
| 51 | if (!items.ContainsKey (name))
|
---|
| 52 | items.Add (name, invF.itemValue);
|
---|
| 53 | else
|
---|
| 54 | Log.Out ("Item \"" + name + "\" already in list!");
|
---|
| 55 | }
|
---|
| 56 | }
|
---|
| 57 | foreach (InventoryField invF in cm.GetAllBlocks()) {
|
---|
| 58 | ItemBase ib = ItemBase.list [invF.itemValue.type];
|
---|
| 59 | string name = ib.GetItemName (invF.itemValue);
|
---|
| 60 | if (name != null && name.Length > 0) {
|
---|
| 61 | if (!items.ContainsKey (name))
|
---|
| 62 | items.Add (name, invF.itemValue);
|
---|
| 63 | else
|
---|
| 64 | Log.Out ("Item \"" + name + "\" already in list!");
|
---|
| 65 | }
|
---|
| 66 | }
|
---|
| 67 | }
|
---|
| 68 | }
|
---|
| 69 | }
|
---|
| 70 |
|
---|