Esempio n. 1
0
 public void InventoryUpdate()
 {
     if (Input.newMs.RightButton == ButtonState.Pressed)
     {
         if (draggedItem == null)
         {
             //get item if clicked slot
             ItemSlot i = Inventory.SlotAtMousePos();
             if (i != null && i.Item != null)
             {
                 draggedItem = new Item(i.Item.Properties, Input.MousePosition);
                 if (Input.newKs.IsKeyDown(Keys.LeftShift))
                 {
                     noOfItems = i.StackSize;
                 }
                 else
                 {
                     noOfItems = 1;
                 }
                 i.Remove(noOfItems);
                 draggedItem.Position = Input.MousePosition;
             }
         }
         else
         {
             //track mouse with it
             draggedItem.Position -= Input.DeltaPos - Velocity; // should have used a separate spritebatch for ui :((
         }
     }
     else
     {
         if (draggedItem != null)
         {
             //put in slot under mouse or if none exists put back in standard slot
             ItemSlot i = Inventory.SlotAtMousePos();
             if (i != null)
             {
                 if (i.CanContain(draggedItem))
                 {
                     for (byte j = 0; j < noOfItems; j++)
                     {
                         if (i.CanContain(draggedItem))
                         {
                             i.SoftAdd(draggedItem);
                         }
                     }
                 }
                 else
                 {
                     for (byte j = 0; j < noOfItems; j++)
                     {
                         if (inventory.Fits(draggedItem))
                         {
                             inventory.Add(draggedItem);
                         }
                         else
                         {
                             draggedItem.Position = Position;
                             SceneManager.CurrentScene.AddObject(draggedItem);
                             if (draggedItem.Properties.IsMeleeWeapon && draggedItem.Properties.MeleeWeaponProperties == MeleeWeapon)
                             {
                                 MeleeWeapon = null;
                             }
                         }
                     }
                 }
             }
             else
             {
                 draggedItem.Position = Position;
                 for (byte j = 0; j < noOfItems; j++)
                 {
                     SceneManager.CurrentScene.AddObject(draggedItem);
                     if (draggedItem.Properties.IsMeleeWeapon && draggedItem.Properties.MeleeWeaponProperties == MeleeWeapon)
                     {
                         MeleeWeapon = null;
                     }
                 }
             }
             draggedItem = null;
         }
     }
 }