Ejemplo n.º 1
0
    public void loadInventory(Inventory inventory)
    {
        if (inventory == null)
        {
            return;
        }
        destroySlotUIs();
        this.inventory = inventory;

        RectTransform r = GetComponent <RectTransform> ();

        ItemInventorySlot[] slotBackings = inventory.getSlots();
        dist_between_slots = r.rect.width / slotBackings.Length;
        startingX          = r.rect.xMin + dist_between_slots / 2;

        slots = new ItemInventorySlotUI [slotBackings.Length];
        for (int i = 0; i < slotBackings.Length; i++)
        {
            GameObject iconObj = GameObject.Instantiate(inventorySlotPrefab, GetComponent <Transform> ());
            iconObj.name = "BeltSlot " + i;
            RectTransform iconTrans = iconObj.GetComponent <RectTransform> ();
            iconTrans.localPosition = new Vector2(startingX + dist_between_slots * i, r.rect.center.y);
            ItemInventorySlotUI slot = iconObj.GetComponent <ItemInventorySlotUI> ();
            slot.setSlotBackingInfo(slotBackings[i]);
            slots [i] = slot;
        }
        updateUI();
        selecticle.SetAsLastSibling();
    }
Ejemplo n.º 2
0
 public void updateUI()
 {
     for (int i = 0; i < slots.Length; i++)
     {
         ItemInventorySlotUI slot = slots [i];
         slot.updateUI();
     }
 }
Ejemplo n.º 3
0
    void handleMouseClick(int quantity)
    {
        if (!init)
        {
            if (MoleController.localPlayer.GetComponent <Player> ().info.cursorSlot == null)
            {
                return;
            }
            localPlayer = MoleController.localPlayer.GetComponent <Player> ();
            cursorSlot.setSlotBackingInfo(MoleController.localPlayer.GetComponent <Player> ().info.cursorSlot);
            init = true;
        }



        PointerEventData pointerData = new PointerEventData(EventSystem.current);

        pointerData.position = Input.mousePosition;

        cursorSlot.setSlotBackingInfo(localPlayer.info.cursorSlot);

        List <RaycastResult> results = new List <RaycastResult> ();

        EventSystem.current.RaycastAll(pointerData, results);

        foreach (RaycastResult r in results)
        {
            if (r.gameObject.name.Equals("SlotUIBackground"))
            {
                ItemInventorySlotUI slotUI = r.gameObject.GetComponentInParent <ItemInventorySlotUI>();
                if (slotUI != null)
                {
                    string[] splitName      = slotUI.gameObject.name.Split(' ');
                    string   menuIdentifier = splitName [0];
                    string   slotIdentifier = splitName [1];


                    //pickup half stack if right click
                    if (cursorSlot.getSlotBackingInfo().isEmpty() && quantity == 1)
                    {
                        quantity = Mathf.CeilToInt(slotUI.getSlotBackingInfo().getQuantity() / 2.0f);
                    }

                    handleSlotSelect(slotUI, menuIdentifier, slotIdentifier, quantity);
                    return;
                }
            }
            return;                                //If clicking on a UI component at all, don't drop item. Must explicitly be dropping on game area
        }
        handleSlotSelect(null, "", "0", quantity); //drop items in cursor
    }
Ejemplo n.º 4
0
    void buildSlots()
    {
        if (inventory == null)
        {
            return;
        }

        ItemInventorySlot[] slotBackings = inventory.getSlots();
        slots = new ItemInventorySlotUI[slotBackings.Length];

        for (int i = 0; i < slots.Length; i++)
        {
            int col = i % NUM_SLOTS_WIDTH;
            int row = i / NUM_SLOTS_WIDTH;

            GameObject iconObj = GameObject.Instantiate(inventorySlotPrefab, GetComponent <Transform> ());
            iconObj.name = "BackpackSlot " + i;
            RectTransform iconTrans = iconObj.GetComponent <RectTransform> ();
            iconTrans.localPosition = slotSeed.localPosition + new Vector3(slotSeed.rect.size.x * col, slotSeed.rect.size.y * row);
            ItemInventorySlotUI slot = iconObj.GetComponent <ItemInventorySlotUI> ();
            slot.setSlotBackingInfo(slotBackings[i]);
            slots [i] = slot;
        }
    }
Ejemplo n.º 5
0
    void handleSlotSelect(ItemInventorySlotUI slotUI, string menuIdentifier, string slotIdentifier, int quantity)
    {
        InventoryOperationRequest.InventoryType menuType = InventoryOperationRequest.InventoryType.Ground;
        InventoryOperationRequest req = null;

        if (menuIdentifier.Equals("BeltSlot"))
        {
            menuType = InventoryOperationRequest.InventoryType.Belt;
        }
        else if (menuIdentifier.Equals("BackpackSlot"))
        {
            menuType = InventoryOperationRequest.InventoryType.Backpack;
        }
        else if (menuIdentifier.Equals("EquipSlot"))
        {
            menuType = InventoryOperationRequest.InventoryType.Equip;
        }


        if (slotUI == null)           //THREW IT ON THE GROUND
        {
            req = new InventoryOperationRequest(InventoryOperationRequest.Operation.FromCursor, InventoryOperationRequest.InventoryType.Ground, System.Int32.Parse(slotIdentifier), quantity);
        }
        else if (cursorSlot.getSlotBackingInfo().isEmpty())
        {
            req = new InventoryOperationRequest(InventoryOperationRequest.Operation.ToCursor, menuType, System.Int32.Parse(slotIdentifier), quantity);
        }
        else
        {
            req = new InventoryOperationRequest(InventoryOperationRequest.Operation.FromCursor, menuType, System.Int32.Parse(slotIdentifier), quantity);
        }

        //perform local changes before sending info to server. Annoying to wait on server for ui change. If sync error, server should let us know eventually and fix
        if (InventoryOperationRequest.validateRequest(req, localPlayer.info))            //perform check server will do to verify before performing locally
        {
            ItemInventorySlot dropped = InventoryOperationRequest.performInventoryRequest(req, localPlayer);

            if (!localPlayer.isServer)
            {
                sendInventoryUpdateToServer(req);
            }
            else
            {
                //host drops items
                if (!dropped.isEmpty())
                {
                    SpawnManager spawnManager = GameObject.FindGameObjectWithTag("SpawnManager").GetComponent <SpawnManager>();
                    spawnManager.SpawnPlayerDroppedItem(dropped.getItem(), dropped.getQuantity(), localPlayer.controller);
                }
            }

            cursorSlot.updateUI();

            switch (menuType)
            {
            case InventoryOperationRequest.InventoryType.Belt:
                beltUI.updateUI();
                break;

            case InventoryOperationRequest.InventoryType.Backpack:
                backpackUI.updateUI();
                break;

            case InventoryOperationRequest.InventoryType.Equip:
                if (slotIdentifier.Equals("6"))
                {
                    if (localPlayer.info.backpack == null)
                    {
                        backpackUI.loadInventory(null);
                    }
                    else
                    {
                        backpackUI.loadInventory(localPlayer.info.backpack.inventory);
                    }
                }
                equipUI.updateUI(localPlayer.info);
                break;
            }
        }
    }