Exemple #1
0
        private void DragManager_OnDragEnded(DraggableItem dItem, DraggableItem newSpawnedItem, int amount)
        {
            MouseState m = Mouse.GetState();

            DrawGrid = false;

            if (GlobalBounds.Contains(m.X, m.Y))
            {
                if (newSpawnedItem != null)
                {
                    OnItemCreated.Invoke(newSpawnedItem);
                    Items.Add(newSpawnedItem);
                    newSpawnedItem.LocalBounds    = new Rectangle(0, 0, GridWidth, GridHeight);
                    newSpawnedItem.OnDragStarted += () => DragManager.StartDrag(newSpawnedItem, 1);

                    newSpawnedItem.OnDragEnded += () => DragManager.Drop();
                }
            }


            if (Items.Contains(dItem) && dItem.Item.CurrentAmount <= 0)
            {
                DragManager.Slots[dItem.Parent] = null;
                dItem.Parent.RemoveChild(dItem);
                Items.Remove(dItem);
                OnItemDestroyed.Invoke(dItem);
            }

            OnChanged.Invoke();
        }
Exemple #2
0
        public void AddItem(GUIComponent slot, GItem item)
        {
            DraggableItem dItem = new DraggableItem(GUI, slot, item)
            {
                ToolTip = item.Name
            };

            DragManager.Slots[slot] = dItem;
            dItem.OnDragStarted    += () => DragManager.StartDrag(dItem, 1);

            dItem.OnDragEnded += () => DragManager.Drop();

            dItem.LocalBounds = new Rectangle(0, 0, GridWidth, GridHeight);
            slot.ClearChildren();
            slot.AddChild(dItem);
            Items.Add(dItem);
        }