Пример #1
0
 public void updateUI()
 {
     for (int i = 0; i < slots.Length; i++)
     {
         ItemInventorySlotUI slot = slots [i];
         slot.updateUI();
     }
 }
Пример #2
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;
            }
        }
    }