Ejemplo n.º 1
0
        public void Draw(Rect position, VirtualCategory category)
        {
            _propertyInspector.DrawIDField(category, true, true);
            category.Name = EditorGUILayout.TextField("Name", category.Name);

            float itemHeight = 20;
            float width      = position.width * 0.4f;
            float height     = position.height - 30;

            CheckAndRemoveInvalidIdsInCategory(_currentCategory);

            GUI.BeginGroup(new Rect(position.x, position.y + 50, width, height));
            _scrollPositionOfCategory = GUI.BeginScrollView(new Rect(0, 0, width, height),
                                                            _scrollPositionOfCategory, new Rect(0, 0, width - 20, 20 * category.ItemIDs.Count));
            GUI.Label(new Rect(0, 0, width, 20), "In Category", GameKitEditorDrawUtil.TitleStyle);
            _categoryItemListControl.Draw(new Rect(0, 20, width, height - 20), _categoryItemListAdaptor);
            GUI.EndScrollView();
            GUI.EndGroup();

            GUI.BeginGroup(new Rect(position.x + position.width - width, position.y + 50, width, height));
            GUI.Label(new Rect(0, 0, width, 20), "Not in Category", GameKitEditorDrawUtil.TitleStyle);
            GUI.BeginGroup(new Rect(0, 20, width, height - 20), string.Empty, "Box");
            _scrollPositionOfNonCategory = GUI.BeginScrollView(new Rect(0, 0, width, height - 20),
                                                               _scrollPositionOfNonCategory, new Rect(0, 0, width - 20, 20 * _itemsWithoutCategory.Count));
            float yOffset = 0;

            foreach (var item in _itemsWithoutCategory)
            {
                if (GUI.Button(new Rect(0, yOffset, position.width * 0.4f, itemHeight), item.ID,
                               item == _currentSelectedItem ?
                               GameKitEditorDrawUtil.ItemSelectedCenterStyle : GameKitEditorDrawUtil.ItemCenterLabelStyle))
                {
                    _currentSelectedItem             = item;
                    _isCurrentSelectedItemInCategory = false;
                }
                yOffset += itemHeight;
            }
            GUI.EndScrollView();
            GUI.EndGroup();
            GUI.EndGroup();

            GUI.enabled = _currentSelectedItem != null && !_isCurrentSelectedItemInCategory;
            if (GUI.Button(new Rect(position.width * 0.5f - 50, position.height * 0.5f - 30, 100, 20), "<Add"))
            {
                category.ItemIDs.Add(_currentSelectedItem.ID);
                _isCurrentSelectedItemInCategory = true;
                UpdateItemsWithoutCategory();
                EditorUtility.SetDirty(GameKit.Config);
            }
            GUI.enabled = _currentSelectedItem != null && _isCurrentSelectedItemInCategory;
            if (_currentSelectedItem != null &&
                GUI.Button(new Rect(position.width * 0.5f - 50, position.height * 0.5f + 30, 100, 20), "Remove>"))
            {
                category.ItemIDs.Remove(_currentSelectedItem.ID);
                _isCurrentSelectedItemInCategory = false;
                UpdateItemsWithoutCategory();
                EditorUtility.SetDirty(GameKit.Config);
            }
            GUI.enabled = true;
        }
Ejemplo n.º 2
0
 public CategoryPropertyView(ItemPropertyInspector propertyInspector, VirtualCategory category)
 {
     _propertyInspector       = propertyInspector;
     _itemsWithoutCategory    = new List <VirtualItem>();
     _categoryItemListControl = new ReorderableListControl(ReorderableListFlags.HideAddButton |
                                                           ReorderableListFlags.HideRemoveButtons | ReorderableListFlags.DisableDuplicateCommand);
     UpdateItemsWithoutCategory();
 }
Ejemplo n.º 3
0
 public bool TryGetCategoryByCategoryID(string id, out VirtualCategory cateroty)
 {
     for (int i = 0; i < Categories.Count; i++)
     {
         if (Categories[i].ID.Equals(id))
         {
             cateroty = Categories[i];
             return(true);
         }
     }
     cateroty = null;
     return(false);
 }
Ejemplo n.º 4
0
        private void CheckAndRemoveInvalidIdsInCategory(VirtualCategory category)
        {
            List <string> toBeRemoved = new List <string>();

            foreach (var itemId in category.ItemIDs)
            {
                if (GameKit.Config.GetVirtualItemByID(itemId) == null)
                {
                    toBeRemoved.Add(itemId);
                }
            }
            foreach (var itemId in toBeRemoved)
            {
                Debug.LogWarning("Category [" + category.ID + "]'s item [" + itemId +
                                 "] doesn't exist, remove it.");
                category.ItemIDs.Remove(itemId);
            }
        }
Ejemplo n.º 5
0
        protected override float DoDrawItem(Rect position, IItem item)
        {
            VirtualItem virtualItem = item as VirtualItem;

            if (virtualItem != null)
            {
                return(DrawVirtualItem(position, virtualItem));
            }
            else
            {
                VirtualCategory category = item as VirtualCategory;
                if (category != null)
                {
                    GUILayout.BeginArea(new Rect(position.x, position.y + 5, position.width, position.height - 10));
                    _categoryPropertyView.Draw(position, category);
                    GUILayout.EndArea();
                    return(position.height);
                }
            }
            return(0);
        }
Ejemplo n.º 6
0
 public void UpdateDisplayItem(VirtualCategory category)
 {
     _currentCategory         = category;
     _categoryItemListAdaptor = new GenericClassListAdaptor <string>(category.ItemIDs, 20, null, DrawItemInCategory);
     UpdateItemsWithoutCategory();
 }
Ejemplo n.º 7
0
 private void UpdateRelatedIDOfItems(IItem[] items, string oldID, string newID)
 {
     foreach (var item in items)
     {
         if (item is Gate)
         {
             Gate gate = item as Gate;
             if (gate.RelatedItemID.Equals(oldID))
             {
                 gate.RelatedItemID = newID;
             }
         }
         else if (item is UpgradeItem)
         {
             UpgradeItem upgrade = item as UpgradeItem;
             if (upgrade.RelatedItemID.Equals(oldID))
             {
                 upgrade.RelatedItemID = newID;
                 upgrade.ID            = upgrade.ID.Replace(oldID, newID);
             }
         }
         else if (item is Reward)
         {
             Reward reward = item as Reward;
             if (reward.RelatedItemID.Equals(oldID))
             {
                 reward.RelatedItemID = newID;
             }
         }
         else if (item is Score)
         {
             Score score = item as Score;
             if (score.RelatedVirtualItemID.Equals(oldID))
             {
                 score.RelatedVirtualItemID = newID;
             }
         }
         else if (item is VirtualCategory)
         {
             VirtualCategory category = item as VirtualCategory;
             for (int i = 0; i < category.ItemIDs.Count; i++)
             {
                 if (category.ItemIDs[i].Equals(oldID))
                 {
                     category.ItemIDs[i] = newID;
                 }
             }
         }
         else if (item is VirtualItem)
         {
             if (item is PurchasableItem)
             {
                 PurchasableItem purchsable = item as PurchasableItem;
                 for (int i = 0; i < purchsable.PurchaseInfo.Count; i++)
                 {
                     if (!purchsable.PurchaseInfo[i].IsMarketPurchase &&
                         purchsable.PurchaseInfo[i].VirtualCurrencyID.Equals(oldID))
                     {
                         purchsable.PurchaseInfo[i].VirtualCurrencyID = newID;
                     }
                 }
             }
             if (item is VirtualItemPack)
             {
                 VirtualItemPack pack = item as VirtualItemPack;
                 for (int i = 0; i < pack.PackElements.Count; i++)
                 {
                     if (pack.PackElements[i].ItemID.Equals(oldID))
                     {
                         pack.PackElements[i].ItemID = newID;
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 8
0
 public bool TryGetCategoryByID(string id, out VirtualCategory category)
 {
     return(IdToCategory.TryGetValue(id, out category));
 }