public void LoadData (ContainerData data)
		{
			if (GetComponent <Container>())
			{
				Container container = GetComponent <Container>();
				container.items.Clear ();

				for (int i=0; i<data.IDs.Count; i++)
				{
					ContainerItem newItem = new ContainerItem (data.linkedIDs[i], data.counts[i], data.IDs[i]);
					container.items.Add (newItem);
				}
			}
		}
Пример #2
0
        /**
         * <summary>Deserialises a string of data, and restores the GameObject to it's previous state.</summary>
         * <param name = "stringData">The data, serialised as a string</param>
         */
        public override void LoadData(string stringData)
        {
            ContainerData data = Serializer.LoadScriptData <ContainerData> (stringData);
            if (data == null) return;

            if (GetComponent <Container>())
            {
                Container container = GetComponent <Container>();
                container.items.Clear ();

                int[] linkedIDs = StringToIntArray (data._linkedIDs);
                int[] counts = StringToIntArray (data._counts);
                int[] IDs = StringToIntArray (data._IDs);

                for (int i=0; i<IDs.Length; i++)
                {
                    ContainerItem newItem = new ContainerItem (linkedIDs[i], counts[i], IDs[i]);
                    container.items.Add (newItem);
                }
            }
        }
Пример #3
0
        /**
         * <summary>Performs what should happen when the element is clicked on, if inventoryBoxType = AC_InventoryBoxType.Container.</summary>
         * <param name = "_mouseState">The state of the mouse button</param>
         * <param name = "_slot">The index number of the slot that was clicked on</param>
         * <param name = "container">The Container that the element references</param>
         */
        public void ClickContainer(MouseState _mouseState, int _slot, Container container)
        {
            if (container == null || KickStarter.runtimeInventory == null)
            {
                return;
            }

            KickStarter.runtimeInventory.SetFont(font, GetFontSize(), fontColor, textEffects);

            if (_mouseState == MouseState.SingleClick)
            {
                if (KickStarter.runtimeInventory.selectedItem == null)
                {
                    if (container.items.Count > (_slot + offset) && container.items [_slot + offset] != null)
                    {
                        ContainerItem containerItem = container.items [_slot + offset];
                        KickStarter.runtimeInventory.Add(containerItem.linkedID, containerItem.count, selectItemsAfterTaking, -1);
                        container.items.Remove(containerItem);
                    }
                }
                else
                {
                    // Placing an item inside the container
                    container.InsertAt(KickStarter.runtimeInventory.selectedItem, _slot + offset);
                    KickStarter.runtimeInventory.Remove(KickStarter.runtimeInventory.selectedItem);
                }
            }

            else if (_mouseState == MouseState.RightClick)
            {
                if (KickStarter.runtimeInventory.selectedItem != null)
                {
                    KickStarter.runtimeInventory.SetNull();
                }
            }
        }
Пример #4
0
        /**
         * <summary>Triggers either the OnContainerAdd or OnContainerRemove events.<summary>
         * <param name = "transferringToContainer">If True, an item is being added to a Container; otherwise, it is being removed</param>
         * <param name = "container">The Container being manipulated</param>
         * <param name = "containerItem">The ContainerItem being moved to/from the Container</param>
         */
        public void Call_OnUseContainer(bool transferringToContainer, Container container, ContainerItem containerItem)
        {
            if (containerItem == null || container == null)
            {
                return;
            }

            if (transferringToContainer)
            {
                if (OnContainerAdd != null)
                {
                    OnContainerAdd(container, containerItem);
                }
            }
            else
            {
                if (OnContainerRemove != null)
                {
                    OnContainerRemove(container, containerItem);
                }
            }
        }
Пример #5
0
        /**
         * <summary>Adds an inventory item to the Container's contents, at a particular index.</summary>
         * <param name = "_item">The InvItem to place within the Container</param>
         * <param name = "_index">The index number within the Container's current contents to insert the new item</param>
         */
        public void InsertAt(InvItem _item, int _index)
        {
            ContainerItem newContainerItem = new ContainerItem (_item.id, GetIDArray ());
            newContainerItem.count = _item.count;

            if (items.Count <= _index)
            {
                items.Add (newContainerItem);
            }
            else
            {
                items.Insert (_index, newContainerItem);
            }
        }
Пример #6
0
        public override float Run()
        {
            if (runtimeContainer == null)
            {
                return(0f);
            }

            if (!setAmount)
            {
                amount = 1;
            }

            if (containerAction == ContainerAction.Add)
            {
                runtimeContainer.Add(invID, amount);
            }
            else if (containerAction == ContainerAction.Remove)
            {
                ContainerItem[] containerItems = runtimeContainer.GetItemsWithInvID(invID);

                foreach (ContainerItem containerItem in containerItems)
                {
                    ContainerItem backUpItem = new ContainerItem(containerItem);

                    // Prevent if player is already carrying one, and multiple can't be carried
                    InvItem invItem = KickStarter.inventoryManager.GetItem(containerItem.linkedID);
                    if (KickStarter.runtimeInventory.IsCarryingItem(invItem.id) && !invItem.canCarryMultiple)
                    {
                        continue;
                    }

                    if (transferToPlayer && KickStarter.runtimeInventory.CanTransferContainerItemsToInventory(containerItem))
                    {
                        int _amount = Mathf.Min(amount, containerItem.count);
                        KickStarter.runtimeInventory.Add(containerItem.linkedID, _amount);
                    }

                    runtimeContainer.Remove(containerItem, amount);

                    KickStarter.eventManager.Call_OnUseContainer(false, runtimeContainer, backUpItem);

                    if (!removeAllInstances)
                    {
                        break;
                    }
                }
            }
            else if (containerAction == ContainerAction.RemoveAll)
            {
                if (transferToPlayer)
                {
                    for (int i = 0; i < runtimeContainer.items.Count; i++)
                    {
                        ContainerItem containerItem = runtimeContainer.items[i];
                        if (!containerItem.IsEmpty)
                        {
                            ContainerItem backUpItem = new ContainerItem(containerItem);

                            // Prevent if player is already carrying one, and multiple can't be carried
                            InvItem invItem = KickStarter.inventoryManager.GetItem(containerItem.linkedID);
                            if (KickStarter.runtimeInventory.IsCarryingItem(invItem.id) && !invItem.canCarryMultiple)
                            {
                                continue;
                            }

                            if (!KickStarter.runtimeInventory.CanTransferContainerItemsToInventory(containerItem))
                            {
                                continue;
                            }

                            KickStarter.runtimeInventory.Add(containerItem.linkedID, containerItem.count, false, -1);
                            runtimeContainer.items.Remove(containerItem);
                            i = -1;

                            KickStarter.eventManager.Call_OnUseContainer(false, runtimeContainer, backUpItem);
                        }
                    }
                }
                else
                {
                    runtimeContainer.RemoveAll();
                }
            }

            return(0f);
        }
        public override void OnInspectorGUI()
        {
            if (_target == null || inventoryManager == null)
            {
                OnEnable();
                return;
            }

            ShowCategoriesUI(_target);
            EditorGUILayout.Space();

            EditorGUILayout.LabelField("Stored Inventory items", EditorStyles.boldLabel);
            if (_target.items.Count > 0)
            {
                EditorGUILayout.BeginVertical("Button");
                for (int i = 0; i < _target.items.Count; i++)
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField("Item name:", GUILayout.Width(80f));
                    if (inventoryManager.CanCarryMultiple(_target.items[i].linkedID))
                    {
                        EditorGUILayout.LabelField(inventoryManager.GetLabel(_target.items[i].linkedID), EditorStyles.boldLabel, GUILayout.Width(135f));
                        EditorGUILayout.LabelField("Count:", GUILayout.Width(50f));
                        _target.items[i].count = EditorGUILayout.IntField(_target.items[i].count, GUILayout.Width(44f));
                    }
                    else
                    {
                        EditorGUILayout.LabelField(inventoryManager.GetLabel(_target.items[i].linkedID), EditorStyles.boldLabel);
                        _target.items[i].count = 1;
                    }

                    if (GUILayout.Button(Resource.CogIcon, GUILayout.Width(20f), GUILayout.Height(15f)))
                    {
                        SideMenu(_target.items[i]);
                    }

                    EditorGUILayout.EndHorizontal();

                    if (_target.limitToCategory && _target.categoryIDs != null && _target.categoryIDs.Count > 0)
                    {
                        InvItem listedItem = inventoryManager.GetItem(_target.items[i].linkedID);
                        if (listedItem != null && !_target.categoryIDs.Contains(listedItem.binID))
                        {
                            EditorGUILayout.HelpBox("This item is not in the categories checked above and will not be displayed.", MessageType.Warning);
                        }
                    }

                    GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1));
                }
                EditorGUILayout.EndVertical();
            }
            else
            {
                EditorGUILayout.HelpBox("This Container has no items", MessageType.Info);
            }

            EditorGUILayout.Space();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Item to create:", GUILayout.MaxWidth(130f));
            itemNumber = EditorGUILayout.Popup(itemNumber, CreateItemList());
            if (GUILayout.Button("Add new item"))
            {
                ContainerItem newItem = new ContainerItem(CreateItemID(itemNumber), _target.GetIDArray());
                _target.items.Add(newItem);
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Space();

            UnityVersionHandler.CustomSetDirty(_target);
        }
Пример #8
0
        public override void OnInspectorGUI()
        {
            if (_target == null || inventoryManager == null)
            {
                OnEnable();
                return;
            }

            if (!sideIcon)
            {
                sideIcon = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/AdventureCreator/Graphics/Textures/inspector-use.png", typeof(Texture2D));
            }

            EditorGUILayout.LabelField("Stored Inventory items", EditorStyles.boldLabel);
            if (_target.items.Count > 0)
            {
                EditorGUILayout.BeginVertical("Button");
                for (int i = 0; i < _target.items.Count; i++)
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField("Item name:", GUILayout.Width(80f));
                    if (inventoryManager.CanCarryMultiple(_target.items[i].linkedID))
                    {
                        EditorGUILayout.LabelField(inventoryManager.GetLabel(_target.items[i].linkedID), EditorStyles.boldLabel, GUILayout.Width(135f));
                        EditorGUILayout.LabelField("Count:", GUILayout.Width(50f));
                        _target.items[i].count = EditorGUILayout.IntField(_target.items[i].count, GUILayout.Width(44f));
                    }
                    else
                    {
                        EditorGUILayout.LabelField(inventoryManager.GetLabel(_target.items[i].linkedID), EditorStyles.boldLabel);
                        _target.items[i].count = 1;
                    }

                    if (GUILayout.Button(sideIcon, GUILayout.Width(20f), GUILayout.Height(15f)))
                    {
                        SideMenu(_target.items[i]);
                    }

                    EditorGUILayout.EndHorizontal();
                    GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1));
                }
                EditorGUILayout.EndVertical();
            }
            else
            {
                EditorGUILayout.HelpBox("This Container has no items", MessageType.Info);
            }

            EditorGUILayout.Space();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Item to create:", GUILayout.MaxWidth(130f));
            itemNumber = EditorGUILayout.Popup(itemNumber, CreateItemList());
            if (GUILayout.Button("Add new item"))
            {
                ContainerItem newItem = new ContainerItem(CreateItemID(itemNumber), _target.GetIDArray());
                _target.items.Add(newItem);
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Space();

            if (GUI.changed)
            {
                EditorUtility.SetDirty(_target);
            }
        }
        public override void OnInspectorGUI()
        {
            if (_target == null || inventoryManager == null)
            {
                OnEnable ();
                return;
            }

            if (!sideIcon)
            {
                sideIcon = (Texture2D) AssetDatabase.LoadAssetAtPath ("Assets/AdventureCreator/Graphics/Textures/inspector-use.png", typeof (Texture2D));
            }

            EditorGUILayout.LabelField ("Stored Inventory items", EditorStyles.boldLabel);
            if (_target.items.Count > 0)
            {
                EditorGUILayout.BeginVertical ("Button");
                for (int i=0; i<_target.items.Count; i++)
                {
                    EditorGUILayout.BeginHorizontal ();
                    EditorGUILayout.LabelField ("Item name:", GUILayout.Width (80f));
                    if (inventoryManager.CanCarryMultiple (_target.items[i].linkedID))
                    {
                        EditorGUILayout.LabelField (inventoryManager.GetLabel (_target.items[i].linkedID), EditorStyles.boldLabel, GUILayout.Width (135f));
                        EditorGUILayout.LabelField ("Count:", GUILayout.Width (50f));
                        _target.items[i].count = EditorGUILayout.IntField (_target.items[i].count, GUILayout.Width (44f));
                    }
                    else
                    {
                        EditorGUILayout.LabelField (inventoryManager.GetLabel (_target.items[i].linkedID), EditorStyles.boldLabel);
                        _target.items[i].count = 1;
                    }

                    if (GUILayout.Button (sideIcon, GUILayout.Width (20f), GUILayout.Height (15f)))
                    {
                        SideMenu (_target.items[i]);
                    }

                    EditorGUILayout.EndHorizontal ();
                    GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1));
                }
                EditorGUILayout.EndVertical ();
            }
            else
            {
                EditorGUILayout.HelpBox ("This Container has no items", MessageType.Info);
            }

            EditorGUILayout.Space ();

            EditorGUILayout.BeginHorizontal ();
            EditorGUILayout.LabelField ("Item to create:", GUILayout.MaxWidth (130f));
            itemNumber = EditorGUILayout.Popup (itemNumber, CreateItemList ());
            if (GUILayout.Button ("Add new item"))
            {
                ContainerItem newItem = new ContainerItem (CreateItemID (itemNumber), _target.GetIDArray ());
                _target.items.Add (newItem);
            }
            EditorGUILayout.EndHorizontal ();
            EditorGUILayout.Space ();

            if (GUI.changed)
            {
                EditorUtility.SetDirty (_target);
            }
        }
        private void SideMenu(ContainerItem item)
        {
            GenericMenu menu = new GenericMenu ();
            sideItem = _target.items.IndexOf (item);

            if (_target.items.Count > 0)
            {
                menu.AddItem (new GUIContent ("Delete"), false, Callback, "Delete");
            }
            if (sideItem > 0 || sideItem < _target.items.Count-1)
            {
                menu.AddSeparator ("");
            }
            if (sideItem > 0)
            {
                menu.AddItem (new GUIContent ("Move up"), false, Callback, "Move up");
            }
            if (sideItem < _target.items.Count-1)
            {
                menu.AddItem (new GUIContent ("Move down"), false, Callback, "Move down");
            }

            menu.ShowAsContext ();
        }