Exemplo n.º 1
0
 private void DropItem(SlotItem slotItem, EWhereDrop eWhereDrop)
 {
     if (eWhereDrop == EWhereDrop.Inventory)  //pokud vloží někam do inventáře(dropu) někde na volné místo
     {
         SetDropStats(slotItem, _grabedItem); //nastavení všech potřebných atributů
         if (_previousSlot != null && !_previousSlot.Occupied && slotItem != _previousSlot)
         {
             //zde byl bug kvuli tomu že se nenulovat item na předchozím místě item se tvářil že tam není (graficky) logicky tam byl
             _previousSlot.Item = null;
         }
         _grabedItem   = null;                //neni nic uchpeno
         _eDragAndDrop = EDragAndDrop.None;   //state je none
     }
     else if (eWhereDrop == EWhereDrop.Stack) //pokud vloží někam kde se bude stackovat
     {
         if (!StackOverflow(slotItem.Item, _grabedItem))
         {
             slotItem.Item.ActualStack += _grabedItem.ActualStack; //přičtení k aktuálnímu stacku
             _eDragAndDrop              = EDragAndDrop.None;       //state nastaven na none
             _grabedItem = null;                                   //není uchopen
         }
         else
         {                                                                 //pokud přeteče stackování
             int differ = slotItem.Item.Stack - slotItem.Item.ActualStack; //rozdíl staků
             slotItem.Item.ActualStack = slotItem.Item.Stack;              //nastavení staků na max
             _grabedItem.ActualStack  -= differ;                           //odečtení staků z drženého itemu
             _eDragAndDrop             = EDragAndDrop.Drag;                //state je pořád drag
         }
     }
     AddRemoveStats(slotItem);
 }
Exemplo n.º 2
0
 private void SetItemGrabed(SlotItem slotItem)
 {
     _grabedItem   = slotItem.Item;                                                             //nastavení grab itemu na slotitem
     _previousSlot = slotItem;                                                                  //nastavení předchozího slotu
     SetDropStats(slotItem, _grabedItem, false, true);
     slotItem.Occupied = false;                                                                 //inventarový item již neni obsazen
     _grabPosition     = DeltaPosition(slotItem.Item.Position, MyInput.CurrentMousePosition()); //nastavení defaultní pozice kvůli posunování textury na pozici kurzoru
     _eDragAndDrop     = EDragAndDrop.Drag;                                                     //nastavení na statu na drag
     SetPickStats(slotItem.Item, MyInput.CurrentMousePosition() - _grabPosition);
 }
Exemplo n.º 3
0
 private void DropService(List <SlotItem> slotList)
 {
     if (slotList.Any(s => s.Rect.Overlaps(_grabedItem.Rect)))
     {
         if (slotList.Any(s => s.Rect.Contains(MyInput.CurrentMousePosition()) && !s.Occupied && CanIPutToSlot(s, _grabedItem)))
         {   //přidání do inventáře
             DropItem(slotList.Find(s => s.Rect.Contains(MyInput.CurrentMousePosition()) && !s.Occupied && CanIPutToSlot(s, _grabedItem)), EWhereDrop.Inventory);
         }
         else if (slotList.Any(s => s.Rect.Contains(MyInput.CurrentMousePosition()) && s.Occupied && CanWeStack(s.Item, _grabedItem)))
         {   //stackování
             DropItem(slotList.Find(s => s.Rect.Contains(MyInput.CurrentMousePosition()) && s.Occupied && CanWeStack(s.Item, _grabedItem)), EWhereDrop.Stack);
         }
         else
         {                                             //jinak hození na předchozí pozici
             _previousSlot.Item = _grabedItem;         //pozice je předchozí
             _eDragAndDrop      = EDragAndDrop.None;   //nastavení na none
             SetDropStats(_previousSlot, _grabedItem); //nastavení příslušných atributů
             _grabedItem = null;
             AddRemoveStats(_previousSlot);
         }
     }
 }
Exemplo n.º 4
0
        public void MoveBetweenTwoLists(params List <SlotItem>[] listOfLists)
        {
            if (listOfLists.Where(s => s != null).All(s => s.Count > 0))
            {
                if (Input.GetMouseButtonDown(0) && (_eDragAndDrop == EDragAndDrop.Pick || _eDragAndDrop == EDragAndDrop.Stack)) //uchpen předmět
                {
                    foreach (List <SlotItem> slotList in listOfLists.Where(s => s != null).Where(s => s.Count > 0))
                    {
                        if (Input.GetKey(KeyCode.LeftShift) && slotList.Any(s => s.Rect.Contains(MyInput.CurrentMousePosition()) && s.Item != null && !s.Item.Grabed))
                        {
                            _eDragAndDrop = EDragAndDrop.Stack;
                            _click++;                                                                                                                  //přičítání počtu kliků
                            SlotItem actSlotItem = slotList.Find(s => s != null && s.Rect.Contains(MyInput.CurrentMousePosition()) && s.Item != null); //najdení slotu itemů
                            Item     newItem     = new Item(actSlotItem.Item);                                                                         //vytvoření nového itemu
                            _grabPosition = DeltaPosition(actSlotItem.Position, MyInput.CurrentMousePosition());
                            if (actSlotItem.Item.ActualStack > 0)
                            {
                                newItem.ActualStack = _click;       //zápis stacků do itemu
                                actSlotItem.Item.ActualStack--;     //odečtení staků
                            }
                            if (actSlotItem.Item.ActualStack == 0)
                            {
                                RemoveItem(actSlotItem); //odstraň item
                            }
                            _grabedItem = newItem;       //nastav jako uchycený item
                            SetPickStats(newItem, MyInput.CurrentMousePosition() - _grabPosition);
                        }
                        //sebrání itemu na který bylo kliknuto
                        else if (slotList.Any(s => s.Rect.Contains(MyInput.CurrentMousePosition()) && s.Item != null && !s.Item.Grabed) && _grabedItem == null)
                        {
                            SetItemGrabed(slotList.Find(s => s != null && s.Rect.Contains(MyInput.CurrentMousePosition()) && s.Item != null));
                        }
                    }
                }
                else if (Input.GetKeyUp(KeyCode.LeftShift) && _eDragAndDrop == EDragAndDrop.Stack)
                {
                    //pokud pustím shift a stackuju
                    _eDragAndDrop = EDragAndDrop.Drop;
                    _click        = 0;
                }

                if (_eDragAndDrop == EDragAndDrop.Drop)
                {
                    //neustálé nastavování hodnot
                    SetPickStats(_grabedItem, MyInput.CurrentMousePosition() - _grabPosition);
                }
                if (Input.GetMouseButtonUp(0) && _eDragAndDrop == EDragAndDrop.Drag)
                {
                    //pokud neni zmáčknuto tlačítko myši a je drag
                    _eDragAndDrop = EDragAndDrop.Drop;
                    AddRemoveStats(_previousSlot, false);
                }
                else if (Input.GetMouseButtonDown(0) && _eDragAndDrop == EDragAndDrop.Drop)
                {
                    bool saved = false;
                    foreach (List <SlotItem> slotList in listOfLists.Where(s => s != null))
                    {
                        //výběr ze všech listů které nejsou null a obsahují kurzor(kolidují s rectem)
                        if (_grabedItem != null)
                        {
                            if (
                                slotList.Any(s => s.Rect.Contains(MyInput.CurrentMousePosition()) || s.Rect.Overlaps(_grabedItem.Rect)))
                            {
                                saved = true;
                                DropService(slotList);
                            }
                        }
                    }
                    if (!saved && _eDragAndDrop != EDragAndDrop.Drag)
                    {   //ošetření aby nebylo drag(tzn. pokud budu dávat na stack a ten stack bude neprázdný a zbydou mi itemy tak je to nezahodí)
                        _eDragAndDrop = EDragAndDrop.None;
                        RemoveItem(_previousSlot);
                    }
                }
                else if (_eDragAndDrop == EDragAndDrop.None)
                {
                    //pokud je state none automaticky nastaví na pick...
                    _eDragAndDrop = EDragAndDrop.Pick;
                }
            }
        }
Exemplo n.º 5
0
        /* private bool _savePos;
        *  private Vector2 _posit;
        *  private string _result;*/

        public SlotManagement()
        {
            _click        = 0;
            _grabPosition = Vector2.zero;
            _eDragAndDrop = EDragAndDrop.Pick;
        }