Example #1
0
 protected virtual void DrawUsageRequirement(Rect rect, SerializedProperty property, bool isActive, bool isFocused, bool drawFilterType)
 {
     InventoryEditorUtility.DrawStatRequirement(rect, property, isActive, isFocused, drawFilterType);
 }
Example #2
0
        public override void EditItem(CraftingBlueprint item, int itemIndex)
        {
            base.EditItem(item, itemIndex);

            _requiredItemsList = new UnityEditorInternal.ReorderableList(item.requiredItems, typeof(ItemAmountRow), true, true, true, true);
            _requiredItemsList.drawHeaderCallback  += rect => EditorGUI.LabelField(rect, "Required items");
            _requiredItemsList.drawElementCallback += (rect, index, active, focused) => {
                rect.height = 16;
                rect.y     += 2;

                var r2 = rect;
                r2.width /= 2;
                r2.width -= 5;

                if (item.requiredItems[index].amount < 1)
                {
                    item.requiredItems[index].SetAmount(1);
                }

                item.requiredItems[index].SetAmount((uint)EditorGUI.IntField(r2, (int)item.requiredItems[index].amount));

                r2.x += r2.width + 5;

                if (item.requiredItems[index].item == null)
                {
                    GUI.backgroundColor = Color.red;
                }

                ObjectPickerUtility.RenderObjectPickerForType <InventoryItemBase>(r2, "", item.requiredItems[index].item,
                                                                                  newItem => {
                    item.requiredItems[index].SetItem(newItem);
                    GUI.changed = true;     // To save..
                    //                        window.Repaint();
                });

                GUI.backgroundColor = Color.white;
            };
            _requiredItemsList.onAddCallback += list => {
                var l = new List <ItemAmountRow>(item.requiredItems)
                {
                    new ItemAmountRow()
                };

                item.requiredItems = l.ToArray();
                list.list          = item.requiredItems;

                window.Repaint();
            };
            _requiredItemsList.onRemoveCallback += list => {
                var l = new List <ItemAmountRow>(item.requiredItems);
                l.RemoveAt(list.index);
                item.requiredItems = l.ToArray();
                list.list          = item.requiredItems;

                window.Repaint();
            };

            _resultItemsList = new UnityEditorInternal.ReorderableList(item.resultItems, typeof(ItemAmountRow), true, true, true, true);
            _resultItemsList.drawHeaderCallback  += rect => EditorGUI.LabelField(rect, "Result items");
            _resultItemsList.drawElementCallback += (rect, index, active, focused) => {
                rect.height = 16;
                rect.y     += 2;

                var r2 = rect;
                r2.width /= 2;
                r2.width -= 5;

                if (item.resultItems[index].amount < 1)
                {
                    item.resultItems[index].SetAmount(1);
                }

                item.resultItems[index].SetAmount((uint)EditorGUI.IntField(r2, (int)item.resultItems[index].amount));

                r2.x += r2.width + 5;

                if (item.resultItems[index].item == null)
                {
                    GUI.backgroundColor = Color.red;
                }

                ObjectPickerUtility.RenderObjectPickerForType <InventoryItemBase>(r2, "", item.resultItems[index].item,
                                                                                  val => {
                    item.resultItems[index].SetItem(val);
                    GUI.changed = true;     // To save..
                    //                        window.Repaint();
                });

                GUI.backgroundColor = Color.white;
            };
            _resultItemsList.onAddCallback += list => {
                var l = new List <ItemAmountRow>(item.resultItems);
                l.Add(new ItemAmountRow());
                item.resultItems = l.ToArray();
                list.list        = item.resultItems;

                window.Repaint();
            };
            _resultItemsList.onRemoveCallback += list => {
                var l = new List <ItemAmountRow>(item.resultItems);
                l.RemoveAt(list.index);
                item.resultItems = l.ToArray();
                list.list        = item.resultItems;

                window.Repaint();
            };

            _usageRequirementPropertiesList = new UnityEditorInternal.ReorderableList(item.usageRequirement, typeof(StatRequirement), true, true, true, true);
            _usageRequirementPropertiesList.drawHeaderCallback  += rect => EditorGUI.LabelField(rect, "Stat requirements");
            _usageRequirementPropertiesList.elementHeight        = 42;
            _usageRequirementPropertiesList.drawElementCallback += (rect, index, active, focused) => {
                InventoryEditorUtility.DrawStatRequirement(rect, item.usageRequirement[index], active, focused, true);
            };
            _usageRequirementPropertiesList.onAddCallback += list => {
                var l = new List <StatRequirement>(item.usageRequirement);
                l.Add(new StatRequirement());
                item.usageRequirement = l.ToArray();
                list.list             = item.usageRequirement;

                window.Repaint();
            };
            _usageRequirementPropertiesList.onRemoveCallback += list => {
                var l = new List <StatRequirement>(item.usageRequirement);
                l.RemoveAt(list.index);
                item.usageRequirement = l.ToArray();
                list.list             = item.usageRequirement;

                window.Repaint();
            };
        }