예제 #1
0
    public override void OnActivation()
    {
        //Clear old items
        displayed.Clear();
        for (int i = holdingPanel.childCount - 1; i >= 0; i--)
        {
            Destroy(holdingPanel.GetChild(i).gameObject);
        }

        //Clear out empty items
        List <ItemStack> available = examinedInventory.items.ToList().FindAll(x => x != null);
        List <ItemStack> toDisplay = new List <ItemStack>();

        //Set up items to show, based on parameters
        switch (queuedAction)
        {
        case ItemAction.INSPECT:
            toDisplay = available;
            toDisplay.Sort(Inventory.ComparePlayer);
            title.text = "Inventory";
            break;

        case ItemAction.DROP:
            toDisplay = available;
            toDisplay.Sort(Inventory.ComparePlayer);
            selected   = new bool[examinedInventory.capacity];
            title.text = "Drop which items?";
            break;

        case ItemAction.EQUIP:
            //TODO: Do this in a way that isn't dumb, and probably has item slots remember if they're equipabble
            //Filter out toDisplay into items that can be equipped in this slot
            EquipmentSlot slot = Player.player.equipment.equipmentSlots[queuedEquipmentIndex];
            title.text = $"Equip what to {slot.slotName}?";
            toDisplay  = available.FindAll(x => x.held[0].CanEquip);                                  //Pretty cheap
            toDisplay  = toDisplay.FindAll(x => slot.type.Contains(x.held[0].equipable.primarySlot)); //Pretttttty expensive
            break;

        case ItemAction.PICK_UP:
            toDisplay  = available;
            selected   = new bool[examinedInventory.capacity];
            title.text = "Pick up which items?";
            break;

        case ItemAction.APPLY:
            title.text = "Apply which item?";
            toDisplay  = available.FindAll(x => x.held[0].CanApply);
            break;

        default:
            Debug.LogError($"Inventory screen is not set up to handle {queuedAction} types. Yell at Woody about this.");
            break;
        }

        if (toDisplay.Count == 0)
        {
            failureMessage.gameObject.SetActive(true);
        }
        else
        {
            failureMessage.gameObject.SetActive(false);
        }

        //Sort the list into item types
        ItemType currentType = (ItemType)0;

        for (int i = 0; i < toDisplay.Count; i++)
        {
            GameObject instance = Instantiate(itemPanelPrefab);
            ItemPanel  current  = instance.GetComponent <ItemPanel>();
            ItemStack  stack    = toDisplay[i];

            //Set up headers
            if (stack.type != currentType)
            {
                //Create a header!
                GameObject header = Instantiate(itemHeaderPrefab);
                header.GetComponent <ItemHeader>().Setup(stack.type);
                header.transform.SetParent(holdingPanel);
                currentType = stack.type;
            }

            //Set up item readout
            current.Setup(this, toDisplay[i].position);
            current.GenerateItemDescription();
            displayed.Add(current);

            instance.transform.SetParent(holdingPanel);
        }
    }