示例#1
0
        /** Upgrades the item from a previous version of AC */
        public void Upgrade()
        {
            if (maxCount < 1)
            {
                maxCount = 999;
            }

            if (carryOnStartID >= 0 && carryOnStartIDs.Count == 0)
            {
                carryOnStartIDs.Add(carryOnStartID);
                carryOnStartID = -1;
            }

            if (canCarryMultiple && useSeparateSlots)
            {
                useSeparateSlots = false;
                maxCount         = 1;
            }

            if (selectSingle)
            {
                itemStackingMode = ItemStackingMode.Single;
                selectSingle     = false;
            }
        }
示例#2
0
        /**
         * <summary>A Constructor in which the id is explicitly set.</summary>
         * <param name = "_id">The ID number to assign</param>
         */
        public InvItem(int _id)
        {
            count                  = 0;
            tex                    = null;
            activeTex              = null;
            selectedTex            = null;
            cursorIcon             = new CursorIcon();
            id                     = _id;
            binID                  = -1;
            carryOnStartNotDefault = false;
            vars                   = new List <InvVar>();
            canBeAnimated          = false;
            linkedPrefab           = null;
            maxCount               = 999;
            canBeLowerCase         = false;

            itemStackingMode = ItemStackingMode.All;
            interactions     = new List <InvInteraction>();

            combineActionList = new List <ActionListAsset>();
            combineID         = new List <int>();

            overrideUseSyntax = false;
            hotspotPrefix1    = new HotspotPrefix("Use");
            hotspotPrefix2    = new HotspotPrefix("on");

            label    = "Inventory item " + (id + 1).ToString();
            altLabel = "";
        }
示例#3
0
        public void ShowGUI(string apiPrefix, List <string> binList)
        {
            Upgrade();

            label    = CustomGUILayout.TextField("Name:", label, apiPrefix + ".label", "The item's Editor name");
            altLabel = CustomGUILayout.TextField("Label (if not name):", altLabel, apiPrefix + ".altLabel", "The item's in-game name, if not label");

            bool isPronoun = !canBeLowerCase;

            isPronoun      = CustomGUILayout.Toggle("Name is pronoun?", isPronoun, "!" + apiPrefix + ".canBeLowerCase", "If False, the name will be lower-cased when inside sentences.");
            canBeLowerCase = !isPronoun;

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(new GUIContent("Category:", "The category that the item belongs to"), GUILayout.Width(146f));
            if (KickStarter.inventoryManager.bins.Count > 0)
            {
                int binNumber = KickStarter.inventoryManager.GetBinSlot(binID);
                binNumber = CustomGUILayout.Popup(binNumber, binList.ToArray(), apiPrefix + ".binID");
                binID     = KickStarter.inventoryManager.bins[binNumber].id;
            }
            else
            {
                binID = -1;
                EditorGUILayout.LabelField("No categories defined!", EditorStyles.miniLabel, GUILayout.Width(146f));
            }
            EditorGUILayout.EndHorizontal();

            carryOnStart = CustomGUILayout.Toggle("Carry on start?", carryOnStart, apiPrefix + ".carryOnStart", "If True, the Player carries the item when the game begins");
            if (carryOnStart && AdvGame.GetReferences().settingsManager&& AdvGame.GetReferences().settingsManager.playerSwitching == PlayerSwitching.Allow && !AdvGame.GetReferences().settingsManager.shareInventory)
            {
                carryOnStartNotDefault = CustomGUILayout.Toggle("Non-default Player(s)?", carryOnStartNotDefault, apiPrefix + ".carryOnStartNotDefault", "If True, then a Player prefab that is not the default carries the item when the game begins");
                if (carryOnStartNotDefault)
                {
                    carryOnStartIDs = ChoosePlayerGUI(carryOnStartIDs, apiPrefix + ".carryOnStartID");
                }
            }

            canCarryMultiple = CustomGUILayout.Toggle("Can carry multiple?", canCarryMultiple, apiPrefix + ".canCarryMultiple", "If True, then multiple instances of the item can be carried at once");

            if (carryOnStart && canCarryMultiple)
            {
                count = CustomGUILayout.IntField("Quantity on start:", count, apiPrefix + ".count", "The number of instances that the player is carrying when the game begins");
            }
            else
            {
                count = 1;
            }

            if (canCarryMultiple)
            {
                if (maxCount == 0)
                {
                    maxCount = 999;
                }
                maxCount = CustomGUILayout.IntField("Slot capacity:", maxCount, apiPrefix + ".maxCount", "The number of instances of the item that can occupy a single inventory slot");
                if (maxCount < 1)
                {
                    maxCount = 1;
                }

                if (maxCount > 1)
                {
                    itemStackingMode = (ItemStackingMode)CustomGUILayout.EnumPopup("Selection mode:", itemStackingMode, apiPrefix + ".itemStackingMode", "How to select items when multiple are in a given slot");
                }
            }

            overrideUseSyntax = CustomGUILayout.Toggle("Override 'Use' syntax?", overrideUseSyntax, apiPrefix + ".overrideUseSyntax", "If True, then the item has its own 'Use X on Y' syntax when selected");
            if (overrideUseSyntax)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Use syntax:", GUILayout.Width(100f));
                hotspotPrefix1.label = EditorGUILayout.TextField(hotspotPrefix1.label, GUILayout.MaxWidth(80f));
                EditorGUILayout.LabelField("(item)", GUILayout.MaxWidth(40f));
                hotspotPrefix2.label = EditorGUILayout.TextField(hotspotPrefix2.label, GUILayout.MaxWidth(80f));
                EditorGUILayout.LabelField("(hotspot)", GUILayout.MaxWidth(55f));
                EditorGUILayout.EndHorizontal();
            }

            linkedPrefab = (GameObject)CustomGUILayout.ObjectField <GameObject> ("Linked prefab:", linkedPrefab, false, apiPrefix + ".linkedPrefab", "A GameObject that can be associated with the item, for the creation of e.g. 3D inventory items (through scripting only)");
            if (linkedPrefab != null)
            {
                EditorGUILayout.HelpBox("This reference is accessible through scripting, or via Inventory parameter in the 'Object: Add or remove' Action.", MessageType.Info);
            }

            CustomGUILayout.DrawUILine();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(new GUIContent("Main graphic:", "The item's main graphic"), GUILayout.Width(145));
            tex = (Texture)CustomGUILayout.ObjectField <Texture> (tex, false, GUILayout.Width(70), GUILayout.Height(70), apiPrefix + ".tex");
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(new GUIContent("Active graphic:", "The item's 'highlighted' graphic"), GUILayout.Width(145));
            activeTex = (Texture)CustomGUILayout.ObjectField <Texture> (activeTex, false, GUILayout.Width(70), GUILayout.Height(70), apiPrefix + ".activeTex");
            EditorGUILayout.EndHorizontal();

            if (AdvGame.GetReferences().settingsManager != null && AdvGame.GetReferences().settingsManager.selectInventoryDisplay == SelectInventoryDisplay.ShowSelectedGraphic)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField(new GUIContent("Selected graphic:", "The item's 'selected' graphic"), GUILayout.Width(145));
                selectedTex = (Texture)CustomGUILayout.ObjectField <Texture> (selectedTex, false, GUILayout.Width(70), GUILayout.Height(70), apiPrefix + ".selectedTex");
                EditorGUILayout.EndHorizontal();
            }
            if (AdvGame.GetReferences().cursorManager != null)
            {
                CursorManager cursorManager = AdvGame.GetReferences().cursorManager;
                if (cursorManager.inventoryHandling == InventoryHandling.ChangeCursor || cursorManager.inventoryHandling == InventoryHandling.ChangeCursorAndHotspotLabel)
                {
                    cursorIcon.ShowGUI(true, true, "Cursor (optional):", cursorManager.cursorRendering, apiPrefix + ".cursorIcon", "A Cursor that, if assigned, will be used in place of the 'tex' Texture when the item is selected on the cursor");
                    CustomGUILayout.DrawUILine();
                }
            }

            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Standard interactions", CustomStyles.subHeader);
            if (KickStarter.settingsManager && KickStarter.settingsManager.interactionMethod != AC_InteractionMethod.ContextSensitive && KickStarter.settingsManager.inventoryInteractions == InventoryInteractions.Multiple && KickStarter.cursorManager)
            {
                List <string> iconList = new List <string> ();
                foreach (CursorIcon icon in KickStarter.cursorManager.cursorIcons)
                {
                    iconList.Add(icon.id.ToString() + ": " + icon.label);
                }

                if (KickStarter.cursorManager.cursorIcons.Count > 0)
                {
                    foreach (InvInteraction interaction in interactions)
                    {
                        EditorGUILayout.BeginHorizontal();
                        int invNumber = GetIconSlot(interaction.icon.id);
                        invNumber        = EditorGUILayout.Popup(invNumber, iconList.ToArray());
                        interaction.icon = KickStarter.cursorManager.cursorIcons[invNumber];

                        int    i        = interactions.IndexOf(interaction);
                        string autoName = label + "_" + interaction.icon.label;
                        interaction.actionList = ActionListAssetMenu.AssetGUI("", interaction.actionList, autoName, apiPrefix + ".interactions[" + i + "].actionList", "The ActionList to run when the interaction is triggered");

                        if (GUILayout.Button(string.Empty, CustomStyles.IconCog))
                        {
                            SideInteractionMenu(interactions.IndexOf(interaction));
                        }

                        EditorGUILayout.EndHorizontal();
                    }
                }
                else
                {
                    EditorGUILayout.HelpBox("No interaction icons defined - please use the Cursor Manager", MessageType.Warning);
                }
                if (GUILayout.Button("Add interaction"))
                {
                    Undo.RecordObject(KickStarter.inventoryManager, "Add new interaction");
                    interactions.Add(new InvInteraction(KickStarter.cursorManager.cursorIcons[0]));
                }
            }
            else
            {
                string autoName = label + "_Use";
                useActionList = ActionListAssetMenu.AssetGUI("Use:", useActionList, autoName, apiPrefix + ".useActionList", "The ActionList asset to run when using the item is used");
                if (KickStarter.cursorManager && KickStarter.cursorManager.allowInteractionCursorForInventory && KickStarter.cursorManager.cursorIcons.Count > 0)
                {
                    int useCursor_int = KickStarter.cursorManager.GetIntFromID(useIconID) + 1;
                    if (useIconID == -1)
                    {
                        useCursor_int = 0;
                    }
                    useCursor_int = CustomGUILayout.Popup("Use cursor icon:", useCursor_int, KickStarter.cursorManager.GetLabelsArray(true), apiPrefix + ".useIconID", "The Cursor to show when hovering over the item");

                    if (useCursor_int == 0)
                    {
                        useIconID = -1;
                    }
                    else if (KickStarter.cursorManager.cursorIcons.Count > (useCursor_int - 1))
                    {
                        useIconID = KickStarter.cursorManager.cursorIcons[useCursor_int - 1].id;
                    }
                }
                else
                {
                    useIconID = 0;
                }
                autoName       = label + "_Examine";
                lookActionList = ActionListAssetMenu.AssetGUI("Examine:", lookActionList, autoName, apiPrefix + ".lookActionList", "The ActionListAsset to run when the item is examined");
            }

            if (KickStarter.settingsManager && KickStarter.settingsManager.CanSelectItems(false))
            {
                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Unhandled interactions", CustomStyles.subHeader);
                string autoName = label + "_Unhandled_Hotspot";
                unhandledActionList        = ActionListAssetMenu.AssetGUI("Unhandled use on Hotspot:", unhandledActionList, autoName, apiPrefix + ".unhandledActionList", "The ActionList asset to run when using the item on a Hotspot is unhandled");
                autoName                   = label + "_Unhandled_Combine";
                unhandledCombineActionList = ActionListAssetMenu.AssetGUI("Unhandled combine:", unhandledCombineActionList, autoName, apiPrefix + ".unhandledCombineActionList", "The ActionListAsset to run when using the item on another InvItem is unhandled");
            }

            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Combine interactions", CustomStyles.subHeader);
            for (int i = 0; i < combineActionList.Count; i++)
            {
                EditorGUILayout.BeginHorizontal();
                int invNumber = KickStarter.inventoryManager.GetArraySlot(combineID[i]);
                invNumber    = EditorGUILayout.Popup(invNumber, KickStarter.inventoryManager.GetLabelList());
                combineID[i] = KickStarter.inventoryManager.items[invNumber].id;

                string autoName = label + "_Combine_" + KickStarter.inventoryManager.GetLabelList()[invNumber];
                combineActionList[i] = ActionListAssetMenu.AssetGUI(string.Empty, combineActionList[i], autoName, apiPrefix + ".combineActionList[" + i + "]", "A List of all 'Combine' InvInteraction objects associated with the item");

                if (GUILayout.Button(deleteContent, EditorStyles.miniButtonRight, buttonWidth))
                {
                    Undo.RecordObject(KickStarter.inventoryManager, "Delete combine event");
                    combineActionList.RemoveAt(i);
                    combineID.RemoveAt(i);
                    break;
                }
                EditorGUILayout.EndHorizontal();
            }
            if (GUILayout.Button("Add combine event"))
            {
                Undo.RecordObject(KickStarter.inventoryManager, "Add new combine event");
                combineActionList.Add(null);
                combineID.Add(0);
            }

            // List all "reverse" inventory combinations
            string reverseCombinations = string.Empty;

            foreach (InvItem otherItem in KickStarter.inventoryManager.items)
            {
                if (otherItem != this)
                {
                    if (otherItem.combineID.Contains(id))
                    {
                        reverseCombinations += "- " + otherItem.label + "\n";
                        continue;
                    }
                }
            }
            if (reverseCombinations.Length > 0)
            {
                EditorGUILayout.Space();
                EditorGUILayout.HelpBox("The following inventory items have combine interactions that reference this item:\n" + reverseCombinations, MessageType.Info);
            }

            if (KickStarter.inventoryManager.invVars.Count > 0)
            {
                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Properties", CustomStyles.subHeader);

                RebuildProperties();

                // UI for setting property values
                if (vars.Count > 0)
                {
                    foreach (InvVar invVar in vars)
                    {
                        invVar.ShowGUI(apiPrefix + ".GetProperty (" + invVar.id + ")");
                    }
                }
                else
                {
                    EditorGUILayout.HelpBox("No properties have been defined that this inventory item can use.", MessageType.Info);
                }
            }
        }
示例#4
0
        /**
         * <summary>A Constructor that sets all its values by copying another InvItem.</summary>
         * <param name = "assetItem">The InvItem to copy</param>
         */
        public InvItem(InvItem assetItem)
        {
            count       = assetItem.count;
            tex         = assetItem.tex;
            activeTex   = assetItem.activeTex;
            selectedTex = assetItem.selectedTex;

            //cursorIcon = assetItem.cursorIcon;
            cursorIcon = new CursorIcon();
            cursorIcon.Copy(assetItem.cursorIcon, true);

            carryOnStart           = assetItem.carryOnStart;
            carryOnStartNotDefault = assetItem.carryOnStartNotDefault;
            carryOnStartID         = assetItem.carryOnStartID;
            carryOnStartIDs.Clear();
            foreach (int _id in assetItem.carryOnStartIDs)
            {
                carryOnStartIDs.Add(_id);
            }
            Upgrade();
            canCarryMultiple = assetItem.canCarryMultiple;
            label            = assetItem.label;
            altLabel         = assetItem.altLabel;
            id        = assetItem.id;
            lineID    = assetItem.lineID;
            useIconID = assetItem.useIconID;

            canBeLowerCase = assetItem.canBeLowerCase;

            binID = assetItem.binID;
            if (binID == -1 && KickStarter.inventoryManager && KickStarter.inventoryManager.bins != null && KickStarter.inventoryManager.bins.Count > 0)
            {
                // Place item in first available cateogry if undefined
                binID = KickStarter.inventoryManager.bins[0].id;
            }

            maxCount         = assetItem.maxCount;
            itemStackingMode = assetItem.itemStackingMode;

            overrideUseSyntax = assetItem.overrideUseSyntax;
            hotspotPrefix1    = assetItem.hotspotPrefix1;
            hotspotPrefix2    = assetItem.hotspotPrefix2;

            useActionList              = assetItem.useActionList;
            lookActionList             = assetItem.lookActionList;
            interactions               = assetItem.interactions;
            combineActionList          = assetItem.combineActionList;
            unhandledActionList        = assetItem.unhandledActionList;
            unhandledCombineActionList = assetItem.unhandledCombineActionList;
            combineID    = assetItem.combineID;
            linkedPrefab = assetItem.linkedPrefab;

            canBeAnimated = DetermineCanBeAnimated();

            vars.Clear();
            foreach (InvVar invVar in assetItem.vars)
            {
                vars.Add(new InvVar(invVar));
            }

            if (Application.isPlaying)
            {
                for (int i = 0; i < vars.Count; i++)
                {
                    if (vars[i].type == VariableType.PopUp)
                    {
                        // Transfer ID of PopUps translation from global property to per-item
                        vars[i].popUpsLineID = KickStarter.inventoryManager.invVars[i].popUpsLineID;
                    }
                }
            }
        }
示例#5
0
        private bool HandleDefaultClick(MouseState _mouseState, int _slot)
        {
            InvInstance clickedInstance = GetInstance(_slot);

            if (_mouseState == MouseState.SingleClick)
            {
                if (!InvInstance.IsValid(KickStarter.runtimeInventory.SelectedInstance))
                {
                    if (InvInstance.IsValid(clickedInstance))
                    {
                        // Clicked on an item while nothing selected

                        switch (containerSelectMode)
                        {
                        case ContainerSelectMode.MoveToInventory:
                        case ContainerSelectMode.MoveToInventoryAndSelect:
                            bool selectItem = (containerSelectMode == ContainerSelectMode.MoveToInventoryAndSelect);

                            ItemStackingMode itemStackingMode = clickedInstance.ItemStackingMode;
                            if (itemStackingMode != ItemStackingMode.All)
                            {
                                // Only take one
                                clickedInstance.TransferCount = 1;
                            }

                            InvInstance newInstance = KickStarter.runtimeInventory.PlayerInvCollection.AddToEnd(clickedInstance);
                            if (selectItem && InvInstance.IsValid(newInstance))
                            {
                                KickStarter.runtimeInventory.SelectItem(newInstance);
                            }
                            break;

                        case ContainerSelectMode.SelectItemOnly:
                            KickStarter.runtimeInventory.SelectItem(clickedInstance);
                            break;
                        }

                        return(true);
                    }
                }
                else
                {
                    // Clicked while selected

                    if (KickStarter.runtimeInventory.SelectedInstance == clickedInstance && KickStarter.runtimeInventory.SelectedInstance.CanStack())
                    {
                        KickStarter.runtimeInventory.SelectedInstance.AddStack();
                    }
                    else
                    {
                        KickStarter.runtimeInventory.CraftingInvCollection.Insert(KickStarter.runtimeInventory.SelectedInstance, _slot, OccupiedSlotBehaviour.FailTransfer);
                        KickStarter.runtimeInventory.SetNull();
                    }

                    return(true);
                }
            }
            else if (_mouseState == MouseState.RightClick)
            {
                if (InvInstance.IsValid(KickStarter.runtimeInventory.SelectedInstance))
                {
                    if (KickStarter.runtimeInventory.SelectedInstance == clickedInstance && KickStarter.runtimeInventory.SelectedInstance.ItemStackingMode == ItemStackingMode.Stack)
                    {
                        KickStarter.runtimeInventory.SelectedInstance.RemoveStack();
                    }
                    else
                    {
                        KickStarter.runtimeInventory.SetNull();
                    }

                    return(true);
                }
            }

            return(false);
        }