Example #1
0
    private void RemoveItem(OccupiedSlot slot)
    {
        Highlight obj;

        if (objects.TryGetValue(slot, out obj))
        {
            obj.Destroy();
            objects.Remove(slot);
        }
    }
Example #2
0
    /* INTERNAL METHODS */
    private void AddItem(OccupiedSlot slot)
    {
        var highlight = new Highlight(grid)
        {
            color    = ITEM_BACKGROUND,
            position = GridToRealPosition(slot.position),
            size     = GridToRealSize(slot.item.size)
        };

        var obj = slot.item.CreateIcon(highlight.transform, GRID_SIZE / BASE_GRID_SIZE);

        obj.transform.localPosition = new Vector3(
            highlight.size.x / 2, -highlight.size.y / 2, 0
            );

        objects.Add(slot, highlight);
    }
Example #3
0
    public void OnPointerDown(PointerEventData evt)
    {
        var held = ItemManager.main.holdingItem;

        if (held == null)
        {
            var          gridPos = ScreenToGrid(evt.position);
            OccupiedSlot slot    = inventory.GetItemAt(gridPos);
            if (slot != null)
            {
                inventory.Remove(slot);
                ItemManager.main.PickUp(slot.item);
            }
        }
        else
        {
            var          hoverPos = hover.position;
            OccupiedSlot overlap;
            var          result = inventory.GetOverlap(hoverPos, held.size, out overlap);
            switch (result)
            {
            case OverlapType.NONE:
                inventory.Add(held, hoverPos);
                ItemManager.main.PutDown();
                hover.hidden = true;
                break;

            case OverlapType.SINGLE:
                inventory.Remove(overlap);
                inventory.Add(held, hoverPos);
                ItemManager.main.PutDown();
                ItemManager.main.PickUp(overlap.item);
                break;
            }
        }
    }
Example #4
0
    void Update()
    {
        if (!inside)
        {
            return;
        }

        var          gridPos = ScreenToGrid(Input.mousePosition);
        OccupiedSlot slot    = inventory.GetItemAt(gridPos);

        ItemManager.main.SetTooltip(slot?.item);

        var held = ItemManager.main.holdingItem;

        if (held == null)
        {
            return;
        }

        hover.position = gridPos;
        var hoverPos = hover.position;         //this value is now clamped. f**k it

        hover.hidden = false;
        hover.size   = held.size;

        var overlap = inventory.GetOverlapType(hoverPos, held.size);

        if (overlap == OverlapType.MULTI)
        {
            hover.UseErrorColor();
        }
        else
        {
            hover.UseNormalColor();
        }
    }