Пример #1
0
        /// <summary>
        ///     The item.
        /// </summary>
        /// <param name="name">
        ///     The name.
        /// </param>
        /// <param name="makeChampionUniq">
        ///     The make champion unique.
        /// </param>
        /// <returns>
        ///     The <see cref="MenuItem" />.
        /// </returns>
        public MenuItem Item(string name, bool makeChampionUniq = false)
        {
            if (makeChampionUniq && ObjectManager.LocalHero != null)
            {
                name = ObjectManager.LocalHero.StoredName() + name;
            }

            var      id = this.Name + name + (this.Parent != null ? this.Parent.Name : string.Empty);
            MenuItem tempItem;

            if (ItemDictionary.TryGetValue(id, out tempItem))
            {
                return(tempItem);
            }

            tempItem = this.Items.FirstOrDefault(x => x.Name == name)
                       ?? (from subMenu in this.Children where subMenu.Item(name) != null select subMenu.Item(name))
                       .FirstOrDefault();
            if (tempItem != null)
            {
                ItemDictionary.Add(id, tempItem);
            }

            return(tempItem);
        }
        /// <summary>
        ///     Removes all items from the given cell.
        ///     If the items don't occupy another cell, they are removed as well.
        /// </summary>
        /// <param name="cell">The cell to remove items from</param>
        public void Remove(Point cell)
        {
            lock (lockObject)
            {
                Point    c = Clamp(cell);
                List <T> l;
                Grid.TryGetValue(c, out l);

                if (l != null)
                {
                    foreach (T i in l)
                    {
                        List <Point> pl;
                        ItemDictionary.TryGetValue(i, out pl);
                        if (pl != null)
                        {
                            pl.Remove(c);
                            if (pl.Count == 0)
                            {
                                ListOfPointQueue.Enqueue(pl);
                                ItemDictionary.Remove(i);
                            }
                        }
                    }
                    l.Clear();
                    ListOfItemQueue.Enqueue(l);
                    Grid.Remove(cell);
                }
            }
        }
        private void AddToItems(T item, Point cell)
        {
            List <Point> pl;

            ItemDictionary.TryGetValue(item, out pl);
            if (pl == null)
            {
                if (ListOfPointQueue.Count > 0)
                {
                    pl = ListOfPointQueue.Dequeue();
                }
                else
                {
                    pl = new List <Point>();
                }
                pl.Add(cell);
                ItemDictionary.Add(item, pl);
            }
            else
            {
                if (!pl.Contains(cell))
                {
                    pl.Add(cell);
                }
            }
        }
Пример #4
0
        private void DrawLevel()
        {
            if (!Level.Singleton)
            {
                return;
            }
            EditorGUI.indentLevel++;

            Level           level = Level.Singleton;
            List <ItemData> levelCollectedItems = level.CollectedItems;
            ItemDictionary  itemDictionary      = new ItemDictionary();

            foreach (ItemData collectedItem in levelCollectedItems)
            {
                itemDictionary.TryGetValue(collectedItem, out int curAmount);
                curAmount++;
                itemDictionary[collectedItem] = curAmount;
            }

            foreach (KeyValuePair <ItemData, int> keyValuePair in itemDictionary)
            {
                EditorGUILayout.LabelField(keyValuePair.Key.itemName, keyValuePair.Value + "");
            }

            EditorGUI.indentLevel--;
        }
 public Point[] Get(T item)
 {
     lock (lockObject)
     {
         List <Point> pl;
         ItemDictionary.TryGetValue(item, out pl);
         if (pl == null)
         {
             return(new Point[0]);
         }
         return(pl.ToArray());
     }
 }
        /// <summary>
        ///     Removes the given item from the grid.
        /// </summary>
        /// <param name="item">The item to remove</param>
        public void Remove(T item)
        {
            lock (lockObject)
            {
                List <Point> pl;
                ItemDictionary.TryGetValue(item, out pl);
                if (pl == null)
                {
                    return;
                }

                foreach (Point p in pl)
                {
                    RemoveFromGrid(item, p);
                }

                pl.Clear();
                ListOfPointQueue.Enqueue(pl);
                ItemDictionary.Remove(item);
            }
        }
Пример #7
0
 public bool TryGetField(string fieldName, out JsonField field)
 {
     return(ItemDictionary.TryGetValue(fieldName, out field));
 }