예제 #1
0
 public void Awake()
 {
     uItem      = GetComponentInChildren <UIItem>();
     ui         = GameObject.Find("InventorySystem").GetComponent <InventorySlotUI>();
     ui.enabled = true;
     text       = GetComponentInChildren <Text>();
 }
예제 #2
0
 /// <summary>
 /// Called when the cursor exits a UI slot
 /// </summary>
 public void OnMouseExit(InventorySlotUI Slot)
 {
     if (CurrentSlot == Slot)
     {
         CurrentSlot = null;
     }
 }
예제 #3
0
        public void OnPointerClick(PointerEventData eventData)
        {
            //Get the players inventory and equipment
            Inventory playerInventory = GameObject.FindGameObjectWithTag("Player").GetComponent <Inventory>();
            Equipment playerEquipment = GameObject.FindGameObjectWithTag("Player").GetComponent <Equipment>();

            //Get the slot ui
            InventorySlotUI inventorySlot = GetComponentInParent <InventorySlotUI>();
            ActionSlotUI    actionSlot    = GetComponentInParent <ActionSlotUI>();

            //if this is an inventory slot
            if (inventorySlot)
            {
                int indexOfItem = inventorySlot._index;
                playerInventory.SelectItem(indexOfItem);
            }
            //if this is an action slot
            else if (actionSlot)
            {
                int indexOfItem = actionSlot._index;
                playerInventory.SelectItem(indexOfItem);
            }
            //if it is neither a inventory or a action slot then we are an equipment slot
            else
            {
                EquipmentSlotUI equipmentSlot = GetComponentInParent <EquipmentSlotUI>();
                EquipLocation   location      = equipmentSlot.EquipLocation;
                playerEquipment.Select(location);
            }
        }
예제 #4
0
    /* Unhandled for nulls.. only use if necessary
     * public string PrintGrid() {
     *  string line = "";
     *
     *  for (int y = 0; y < _inventorySlots.GetLength(0); y++)
     *  {
     *      for (int x = 0; x < _inventorySlots.GetLength(1); x++)
     *      {
     *          line += _inventorySlots[y, x] != null ? "[" + x + "," + y + "]" : "   ";
     *
     *      }
     *      line += "\n";
     *  }
     *  return line;
     * }
     */

    public string PrintLayout()
    {
        string line = "";

        for (int y = 0; y < _inventorySlots.GetLength(0); y++)
        {
            for (int x = 0; x < _inventorySlots.GetLength(1); x++)
            {
                // line += _inventorySlots[y, x] != null ? "[ " + "]" : "   ";

                InventorySlotUI slot = GetSlotAt(x, y);
                if (slot == null)
                {
                    line += "   ";
                }
                else if (slot.free)
                {
                    line += "[ ]";
                }
                else if (!slot.free)
                {
                    line += "[.]";
                }
            }
            line += "\n";
        }
        return(line);
    }
예제 #5
0
    public InventorySlotUI FindNeighbours(UIMoveDirection dir)
    {
        InventorySlotUI s = null;

        if (dir == UIMoveDirection.Down)
        {
            if (selectable.FindSelectableOnDown().TryGetComponent <InventorySlotUI>(out InventorySlotUI outSlot))
            {
                s = outSlot;
            }
        }
        else if (dir == UIMoveDirection.Up)
        {
            if (selectable.FindSelectableOnUp().TryGetComponent <InventorySlotUI>(out InventorySlotUI outSlot))
            {
                s = outSlot;
            }
        }
        else if (dir == UIMoveDirection.Right)
        {
            if (selectable.FindSelectableOnRight().TryGetComponent <InventorySlotUI>(out InventorySlotUI outSlot))
            {
                s = outSlot;
            }
        }
        else if (dir == UIMoveDirection.Left)
        {
            if (selectable.FindSelectableOnLeft().TryGetComponent <InventorySlotUI>(out InventorySlotUI outSlot))
            {
                s = outSlot;
            }
        }
        return(s);
    }
예제 #6
0
 public static void ClearHighlightedCell(InventorySlotUI slot)
 {
     if (m_instance.m_highlightedSlot == slot)
     {
         m_instance.m_highlightedSlot = null;
     }
 }
예제 #7
0
    public static bool AttemptSwap(ItemUIElement item1, ItemUIElement item2)
    {
        InventorySlotUI slot1 = item1.ItemInfo.CurrentSlot;
        InventorySlotUI slot2 = item2.ItemInfo.CurrentSlot;

        if (slot1.CanFitItem(item2.ItemInfo) && slot2.CanFitItem(item1.ItemInfo) &&
            item1.ItemInfo.CanEnterInventory(slot2.m_container, slot2) &&
            item2.ItemInfo.CanEnterInventory(slot1.m_container, slot1))
        {
            Debug.Log("Moving item 1");
            GameObject      newSlot  = Instantiate(m_instance.SlotPrefab, m_instance.transform);
            InventorySlotUI tempSlot = newSlot.GetComponent <InventorySlotUI>();
            tempSlot.m_container = m_instance.m_Container;
            m_instance.MoveItemTo(item1, tempSlot);

            Debug.Log("Moving item 2");
            m_instance.MoveItemTo(item2, slot1);
            m_instance.MoveItemTo(item1, slot2);
            Destroy(newSlot);
            return(true);
        }
        item1.ReturnPos();
        item2.ReturnPos();
        return(false);
    }
예제 #8
0
 private void ShowTooltip(InventorySlotUI itemSlot)
 {
     if (itemSlot.item != null)
     {
         itemTooltip.ShowTooltip(itemSlot.item);
     }
 }
예제 #9
0
 private void HideTooltip(InventorySlotUI itemSlot)
 {
     if (itemTooltip.gameObject.activeSelf)
     {
         itemTooltip.HideTooltip();
     }
 }
    private void DropItemIntoContainer(InventorySlotUI destination)
    {
        if (destination != null && object.ReferenceEquals(destination, startMoveSlot))
        {
            return;
        }

        var destinationContainer = destination;
        var sourceContainer      = startMoveSlot;

        if (sourceContainer.GetItem() == null)
        {
            return;
        }


        // Swap won't be possible
        if (destinationContainer == null || sourceContainer == null ||
            destinationContainer.GetItem() == null ||
            object.ReferenceEquals(destinationContainer.GetItem(), sourceContainer.GetItem()))
        {
            AttemptSimpleTransfer(destination);
            return;
        }

        AttemptSwap(destinationContainer, sourceContainer);
    }
예제 #11
0
    public void MousePutDown(InventorySlotUI slot)
    {
        if (airItem == null)
        {
            return;
        }
        if (airItem.onActionBar)
        {
            return;
        }
        int        slotSize = SlotSize(airItem.item);
        GameObject result   = PutItemOnCoords(slot.slotX, slot.slotY, airItem.item, slotSize, airItem.UpgradeLevel);

        result.GetComponent <ItemUI>().ChangeQuantity(airItem.GetQuantity());
        if (result != null)
        {
            //if it was previously in inventory, not eq
            if ((airItem.itemX != -1) && (airItem.itemY != -1))
            {
                ClearSlot(airItem.itemX, airItem.itemY, slotSize);
            }
            else
            {
                airItem.eqPieceSlot.item   = null;
                airItem.eqPieceSlot.itemUI = null;
                airItem.eqPieceSlot        = null;
                Debug.Log("nulled items belonging to eq");
            }
            airItem.MoveObserversTo(result.GetComponent <ItemUI>());
            Destroy(airItem.gameObject);
            myUI.playerUI.UpdatePlayerStats();
        }
        airItem = null;
    }
예제 #12
0
    protected virtual void OnDropAreaDrop(PointerEventData eventData)
    {
        // This can work only with InventorySlotUI objects.
        InventorySlotUI slotDropped = eventData.pointerDrag.GetComponent <InventorySlotUI>();

        if (slotDropped != null)
        {
            // If the slot is of an item from elsewhere, take it into this display window,
            // provided its underlying inventory has the space for the item.
            SKSItem itemDropped = slotDropped.itemToDisplay;
            if (!inventory.Contains(itemDropped) && inventory.itemCount < inventory.capacity)
            {
                SKSInventory otherInventory = itemDropped.belongsTo as SKSInventory;
                if (otherInventory != null)
                {
                    otherInventory.Remove(itemDropped);
                }
                inventory.Add(itemDropped);

                // Destroy the slot; a new one should be made in its place thanks to
                // the moving around of items.
                Destroy(slotDropped.gameObject);
            }
            else
            {
                // This slot was inside this window, so just put it back where it belongs.
                slotDropped.ResetParent();
            }
        }

        base.OnDrop(eventData);
    }
예제 #13
0
    protected override void Awake()
    {
        base.Awake();

        GameObject masterSlot = GameObject.Find("Canvas/btn_inv");

        m_canvas = GameObject.Find("Canvas");

        if (m_canvas == null)
        {
            UnityEngine.Debug.LogWarning("Could not find canvas");
        }

        if (masterSlot == null)
        {
            UnityEngine.Debug.LogWarning("Could not find inventory slot");
        }
        else
        {
            m_inventorySlot.Add(InventorySlotUI.CreateFromGameObject(masterSlot, 0));
            SetupEvents(m_inventorySlot[0]);
        }

        // TODO - Automate all of this using reflection
        m_healthText      = GameObject.Find("Canvas/txt_Health").GetComponent <Text>();
        m_mouseTileInfo   = GameObject.Find("Canvas/txt_MouseCursorHover").GetComponent <Text>();
        m_gameOverMessage = GameObject.Find("Canvas/txt_DeadMessage").GetComponent <Text>();
        m_xpSlider        = GameObject.Find("Canvas/sld_XP").GetComponent <Slider>();
        m_txtLevel        = GameObject.Find("Canvas/txt_Level").GetComponent <Text>();
    }
예제 #14
0
    void OnSlotClicked(PointerEventData eventData)
    {
        InventorySlotUI slotUI = eventData.pointerPress.GetComponent <InventorySlotUI>();

        this.itemToDisplay = slotUI.itemToDisplay;
        Refresh();
    }
 private void StartMove()
 {
     startMoveSlot = inventoryUICursor.GetCurrentSlot();
     if (startMoveSlot.GetItem() != null)
     {
         moveStarted = true;
     }
 }
예제 #16
0
 public void OpenOptionsList(InventorySlotUI slot)
 {
     if (slot.slot.IsEmpty())
     {
         return;
     }
     optionsList.OpenOptions(slot);
 }
    private void EndMove()
    {
        endMoveSlot = inventoryUICursor.GetCurrentSlot();

        DropItemIntoContainer(endMoveSlot);
        moveStarted   = false;
        startMoveSlot = null;
        endMoveSlot   = null;
    }
예제 #18
0
 public void MoveItem(int index)
 {
     if (slots[index].slot.item == null)
     {
         return;
     }
     moving        = slots[index];
     selectionMode = true;
 }
예제 #19
0
    // Check the inventory space if the following slot position is active and free
    public bool IsSlotFree(Vector2 itemSlot)
    {
        InventorySlotUI slot = GetSlotAt((int)itemSlot.x, (int)itemSlot.y);

        if (slot == null || !slot.free)
        {
            // Debug.Log("Slot: " + itemSlot + " is not free" );
            return(false);
        }
        return(true);
    }
예제 #20
0
    private void UpdateText()
    {
        if (!GameManager.Instance)
        {
            return;
        }

        // Update all texts for now
        for (int i = 0; i < NumInventorySlots; ++i)
        {
            ItemCount ic = GameManager.Instance.MainPlayer.Inventory.GetSlotInformation(i);

            InventorySlotUI isu = m_inventorySlot[i];

            if (ic.Count == 0)
            {
                isu.m_count.text = "";
            }
            else
            {
                isu.m_count.text = ic.Count.ToString();
            }

            isu.m_title.color = (i == m_selectSlotIndex)
            ? new Color(48 / 255f, 255 / 255f, 42 / 255f)
            : new Color(1f, 1f, 1f);

            // set what is owned by this inventory slot
            if (ic.Item == EItem.None)
            {
                isu.m_icon.sprite = null;
                isu.m_icon.color  = new Color(1f, 1f, 1f, 0f);
            }
            else
            {
                if (isu.m_icon.sprite == null)
                {
                    TileResourceDef tileResourceDef = TileMapping.GetTileResourceDef((ETile)ic.Item);
                    Texture2D       tex             = tileResourceDef != null
                        ? Resources.Load(tileResourceDef.Filename) as Texture2D
                        : null;

                    if (tex)
                    {
                        Sprite sprite = Sprite.Create(tex, tileResourceDef.Rect, Vector2.zero);
                        isu.m_icon.sprite = sprite;
                        isu.m_icon.color  = ItemInstance.GetColorForItem(ic.Item);
                        isu.m_icon.rectTransform.SetWidth(Mathf.Min(tileResourceDef.Rect.width, 32));
                        isu.m_icon.rectTransform.SetHeight(Mathf.Min(tileResourceDef.Rect.height, 32));
                    }
                }
            }
        }
    }
예제 #21
0
 // Event listener, called when selected item slot changed
 public void OnSelectionChanged()
 {
     // Update background colors of the old and new selected slots
     if (_lastSelected != null)
     {
         _lastSelected.backgroundImage.color = slotUnselectedColor;
     }
     _lastSelected = _slots[selectedSlotVar.Value];
     _lastSelected.backgroundImage.color = slotSelectedColor;
     _lastSelected.UpdateUI();
 }
    private void AttemptSwap(InventorySlotUI destination, InventorySlotUI source)
    {
        // Provisionally remove item from both sides.
        var removedSourceNumber      = source.GetNumber();
        var removedSourceItem        = source.GetItem();
        var removedDestinationNumber = destination.GetNumber();
        var removedDestinationItem   = destination.GetItem();

        source.RemoveItems(removedSourceNumber);
        destination.RemoveItems(removedDestinationNumber);

        var sourceTakeBackNumber      = CalculateTakeBack(removedSourceItem, removedSourceNumber, source, destination);
        var destinationTakeBackNumber = CalculateTakeBack(removedDestinationItem, removedDestinationNumber, destination, source);

        // Do take backs (if needed)
        if (sourceTakeBackNumber > 0)
        {
            source.AddItems(removedSourceItem, sourceTakeBackNumber);
            removedSourceNumber -= sourceTakeBackNumber;
        }
        if (destinationTakeBackNumber > 0)
        {
            destination.AddItems(removedDestinationItem, destinationTakeBackNumber);
            removedDestinationNumber -= destinationTakeBackNumber;
        }

        // Abort if we can't do a successful swap
        if (source.MaxAcceptable(removedDestinationItem) < removedDestinationNumber ||
            destination.MaxAcceptable(removedSourceItem) < removedSourceNumber ||
            removedSourceNumber == 0)
        {
            if (removedDestinationNumber > 0)
            {
                destination.AddItems(removedDestinationItem, removedDestinationNumber);
            }
            if (removedSourceNumber > 0)
            {
                source.AddItems(removedSourceItem, removedSourceNumber);
            }
            return;
        }

        // Do swaps
        if (removedDestinationNumber > 0)
        {
            source.AddItems(removedDestinationItem, removedDestinationNumber);
        }
        if (removedSourceNumber > 0)
        {
            destination.AddItems(removedSourceItem, removedSourceNumber);
        }
    }
예제 #23
0
 protected virtual void Populate()
 {
     // Add an inventory slot display for each item in the inventory, making sure
     // they display the right things.
     foreach (SKSItem item in inventoryToDisplay.items)
     {
         GameObject newSlot = Instantiate <GameObject>(slotPrefab);
         newSlot.name = item.name;
         newSlot.transform.SetParent(slotHolder, false);
         InventorySlotUI slotDisplay = newSlot.GetComponent <InventorySlotUI>();
         slotDisplay.itemToDisplay = item;
     }
 }
예제 #24
0
    private void MoveItemTo(ItemUIElement iue, InventorySlotUI slot)
    {
        iue.UpdateReturnPos(slot.ItemOffsetPos);
        if (slot.transform.parent.parent != null)
        {
            iue.transform.SetParent(slot.transform.parent.parent.Find("Items"));
            iue.ReturnPos();
        }

        iue.ItemInfo.CurrentSlot.m_container.ClearItem(iue.ItemInfo.CurrentSlot.Coordinate);
        slot.AddItem(iue.ItemInfo);
        iue.ItemInfo.CurrentSlot = slot;
    }
예제 #25
0
    public virtual void OnEndDrag(PointerEventData eventData)
    {
        startDragPosition = parent.position;
        child.SetParent(parent);
        child.localPosition = startPosition;

        Image icon = child.gameObject.GetComponent <Image>() as Image;

        InventorySlotUI slotUI = (eventData.pointerCurrentRaycast.gameObject != null)
            ? eventData.pointerCurrentRaycast.gameObject.GetComponent <InventorySlotUI>() : null;

        EndDrag((slotUI != null) ? slotUI.slot : null);
    }
예제 #26
0
    public override void CreateMenu(RectTransform Parent)
    {
        Entity_Player player     = Entity_Player.Main;
        Vector2       startPoint = new Vector2(0, -Parent.rect.height * 0.5f);

        // Add callback
        mInventory = player.mInventory;
        mInventory.mChangeEvent += OnInventoryChange;

        // Create player hotbar
        uint  width     = Entity_Player.InventoryWidth;
        uint  height    = Entity_Player.InventoryHeight;
        float halfWidth = width * 0.5f;

        mInventorySlots = new InventorySlotUI[width, height];


        for (int x = 0; x < width; ++x)
        {
            for (int y = 0; y < height; ++y)
            {
                // Inventory slot
                InventorySlotUI slot = Instantiate(InventorySlotUI.DefaultSlot, Parent);
                slot.name = "Slot " + x + "," + y;
                slot.Construct(mInventory, x, y);

                // Make sure inventory is in order from top-left to bottom-right
                int displayY = y;
                if (y != 0)
                {
                    displayY = (int)height - y;
                }

                RectTransform slotRect = slot.GetComponent <RectTransform>();
                slotRect.localPosition = startPoint + new Vector2(slotRect.rect.width * (x - halfWidth + 0.5f), slotRect.rect.height * (displayY + 0.5f));


                // Set hotbar different colour
                if (y != 0)
                {
                    slot.SetColour(Color.grey);
                }


                // Set contents
                slot.SetItem(player.mInventory.Get(x, y));

                mInventorySlots[x, y] = slot;
            }
        }
    }
예제 #27
0
    public void OpenOptions(InventorySlotUI slot)
    {
        focusedSlot = slot;
        SetOptions();

        if (options.Count == 0)
        {
            return;
        }
        gameObject.SetActive(true);
        transform.position = slot.transform.position;
        GamepadInputManager.instance.gamepadInputs[playerInventory.player.mPlayerIndex].GetEventSystem().SetSelectedGameObject(options[0].gameObject);
        options[0].gameObject.GetComponent <Button>().OnSelect(null);
    }
예제 #28
0
    private void Duplicate()
    {
        if (m_initialized)
        {
            return;
        }

        if (m_inventorySlot.Count == 0 || m_canvas == null)
        {
            return;
        }

        RectTransform rtOriginal = m_inventorySlot[0].m_parent.GetComponent <RectTransform>();

        for (int i = 1; i < NumInventorySlots; ++i)
        {
            GameObject clone = (GameObject)Instantiate(m_inventorySlot[0].m_parent, m_inventorySlot[0].m_parent.transform.position, m_inventorySlot[0].m_parent.transform.rotation);
            if (clone != null)
            {
                clone.name = "btn_inv (" + i + ")";
                clone.transform.SetParent(m_canvas.transform);
                //clone.transform.parent = m_canvas.transform;
                clone.transform.position   = m_inventorySlot[0].m_parent.transform.position;
                clone.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f);

                InventorySlotUI ui = InventorySlotUI.CreateFromGameObject(clone, i);
                m_inventorySlot.Add(ui);

                RectTransform rtClone = clone.GetComponent <RectTransform>();
                Vector2       origin  = rtOriginal.localPosition;
                float         width   = rtOriginal.GetWidth();
                rtClone.localPosition = origin + new Vector2((width + 5) * i, 0f);

                SetupEvents(ui);

                if (i == 9)
                {
                    ui.m_title.text = "0";
                }
                else
                {
                    ui.m_title.text = (i + 1).ToString();
                }
            }
        }

        UpdateText();
        m_initialized = true;
    }
예제 #29
0
    private void Start()
    {
        m_TimeBetaweenTwoDash = nextDashing;
        loot = FindObjectOfType <InventorySlotUI>();

        if (tuto != null)
        {
            sword = tuto.weapon;
            axe   = tuto.axe;
        }

        if (loader.m_SaveWeapon != null)
        {
            SetWeapon();
        }
    }
예제 #30
0
    public void SlotSelected(InventorySlotUI selectedSlot)
    {
        if (selectionMode)
        {
            if (moving.slotID != selectedSlot.slotID)
            {
                player.Inventory.MoveItem(moving.slot, selectedSlot.slot);
            }

            moving        = null;
            selectionMode = false;
        }
        else
        {
            OpenOptionsList(selectedSlot);
        }
    }