Exemplo n.º 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();
        }
Exemplo n.º 2
0
 public void StartDrag(DraggableItem item, int amount)
 {
     CurrentItem       = item;
     CurrentDragAmount = amount;
     CurrentItem.Item.CurrentAmount -= amount;
     OnDragStarted.Invoke(CurrentItem, CurrentDragAmount);
 }
Exemplo n.º 3
0
        public bool Drag(DraggableItem item, int amount, GUIComponent slot, out DraggableItem itemDraggedTo, out bool wasNew)
        {
            if (!Slots.ContainsKey(slot))
            {
                DraggableItem currentItem = new DraggableItem(item.GUI, slot, new GItem(item.Item.ResourceType, item.Item.Image, item.Item.Tint, item.Item.MinAmount, item.Item.MaxAmount, item.Item.CurrentAmount, item.Item.Price));
                GItem         gItem       = currentItem.Item;


                if (gItem.CurrentAmount + amount <= gItem.MaxAmount)
                {
                    gItem.CurrentAmount += amount;
                }


                Slots[slot]   = currentItem;
                itemDraggedTo = currentItem;
                wasNew        = false;
                return(true);
            }
            else
            {
                DraggableItem currentItem = Slots[slot];

                if (currentItem != null)
                {
                    GItem gItem = currentItem.Item;
                    if (gItem.Name != item.Item.Name)
                    {
                        wasNew        = false;
                        itemDraggedTo = null;
                        return(false);
                    }
                    else
                    {
                        if (gItem.CurrentAmount + amount <= gItem.MaxAmount)
                        {
                            gItem.CurrentAmount += amount;
                            wasNew        = false;
                            itemDraggedTo = currentItem;
                            return(true);
                        }
                    }
                }
                else
                {
                    DraggableItem ditem = new DraggableItem(item.GUI, slot, new GItem(item.Item.ResourceType, item.Item.Image, item.Item.Tint, item.Item.MinAmount, item.Item.MaxAmount, 0, item.Item.Price));
                    Slots[slot]               = ditem;
                    ditem.LocalBounds         = new Rectangle(0, 0, 32, 32);
                    ditem.Item.CurrentAmount += amount;
                    itemDraggedTo             = ditem;
                    wasNew = true;
                    return(true);
                }
                wasNew        = false;
                itemDraggedTo = null;
                return(false);
            }
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
 public bool IsDragValid(DraggableItem item, GUIComponent slot)
 {
     if (!Slots.ContainsKey(slot))
     {
         return(true);
     }
     else
     {
         DraggableItem currentItem = Slots[slot];
         GItem         gItem       = currentItem.Item;
         if (gItem.Name != item.Item.Name)
         {
             return(false);
         }
         else
         {
             return(true);
         }
     }
 }
Exemplo n.º 6
0
        public DraggableItem Drop()
        {
            MouseState mouseState = Mouse.GetState();

            if (CurrentItem != null)
            {
                Rectangle rect = CurrentItem.GlobalBounds;
                rect.X = mouseState.X - rect.Width / 2;
                rect.Y = mouseState.Y - rect.Height / 2;

                GUIComponent drop = GetIntersectingSlot(rect);


                if (drop != null)
                {
                    foreach (GUIComponent slotDropper in IllegalDrags.Keys)
                    {
                        if (CurrentItem.HasAnscestor(slotDropper))
                        {
                            foreach (GUIComponent illegals in IllegalDrags[slotDropper].Keys)
                            {
                                if (drop.HasAnscestor(illegals))
                                {
                                    CurrentItem.Item.CurrentAmount += CurrentDragAmount;
                                    OnDragEnded.Invoke(CurrentItem, null, 0);
                                    return(null);
                                }
                            }
                        }
                    }

                    DraggableItem toReturn = null;
                    bool          wasNew   = false;
                    bool          success  = Drag(CurrentItem, CurrentDragAmount, drop, out toReturn, out wasNew);

                    if (!success)
                    {
                        CurrentItem.Item.CurrentAmount += CurrentDragAmount;
                        OnDragEnded.Invoke(CurrentItem, null, 0);
                        return(null);
                    }
                    else if (wasNew)
                    {
                        OnDragEnded.Invoke(CurrentItem, toReturn, CurrentDragAmount);
                        return(toReturn);
                    }
                    else
                    {
                        OnDragEnded.Invoke(CurrentItem, null, CurrentDragAmount);
                        return(null);
                    }
                }
                else
                {
                    CurrentItem.Item.CurrentAmount += CurrentDragAmount;
                    OnDragEnded.Invoke(CurrentItem, null, 0);
                    return(null);
                }
            }


            CurrentItem       = null;
            CurrentDragAmount = 0;
            OnDragEnded.Invoke(CurrentItem, null, 0);
            return(null);
        }
Exemplo n.º 7
0
 private void DragGrid_OnItemDestroyed(DraggableItem item)
 {
 }
Exemplo n.º 8
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();
        }
Exemplo n.º 9
0
 private void DragGrid_OnItemDestroyed(DraggableItem item)
 {
 }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
0
 public bool IsDragValid(DraggableItem item, GUIComponent slot)
 {
     if(!Slots.ContainsKey(slot))
     {
         return true;
     }
     else
     {
         DraggableItem currentItem = Slots[slot];
         GItem gItem = currentItem.Item;
         if(gItem.Name != item.Item.Name)
         {
             return false;
         }
         else
         {
             return true;
         }
     }
 }
Exemplo n.º 12
0
        public bool Drag(DraggableItem item, int amount, GUIComponent slot, out DraggableItem itemDraggedTo, out bool wasNew)
        {
            if(!Slots.ContainsKey(slot))
            {
                DraggableItem currentItem = new DraggableItem(item.GUI, slot, new GItem(item.Item.Name, item.Item.Image, item.Item.MinAmount, item.Item.MaxAmount, item.Item.CurrentAmount, item.Item.Price));
                GItem gItem = currentItem.Item;

                if(gItem.CurrentAmount + amount <= gItem.MaxAmount)
                {
                    gItem.CurrentAmount += amount;
                }

                Slots[slot] = currentItem;
                itemDraggedTo = currentItem;
                wasNew = false;
                return true;
            }
            else
            {
                DraggableItem currentItem = Slots[slot];

                if(currentItem != null)
                {
                    GItem gItem = currentItem.Item;
                    if(gItem.Name != item.Item.Name)
                    {
                        wasNew = false;
                        itemDraggedTo = null;
                        return false;
                    }
                    else
                    {
                        if(gItem.CurrentAmount + amount <= gItem.MaxAmount)
                        {
                            gItem.CurrentAmount += amount;
                            wasNew = false;
                            itemDraggedTo = currentItem;
                            return true;
                        }
                    }
                }
                else
                {
                    DraggableItem ditem = new DraggableItem(item.GUI, slot, new GItem(item.Item.Name, item.Item.Image, item.Item.MinAmount, item.Item.MaxAmount, 0, item.Item.Price));
                    Slots[slot] = ditem;
                    ditem.LocalBounds = new Rectangle(0, 0, 32, 32);
                    ditem.Item.CurrentAmount += amount;
                    itemDraggedTo = ditem;
                    wasNew = true;
                    return true;
                }
                wasNew = false;
                itemDraggedTo = null;
                return false;
            }
        }
Exemplo n.º 13
0
 private void DragManager_OnDragStarted(DraggableItem item, int amount)
 {
     DrawGrid = true;
 }
Exemplo n.º 14
0
 private void DragGrid_OnItemCreated(DraggableItem item)
 {
 }
Exemplo n.º 15
0
 private void DragManager_OnDragEnded(DraggableItem fromItem, DraggableItem item, int amount)
 {
 }
Exemplo n.º 16
0
 private void DragManager_OnDragStarted(DraggableItem item, int amount)
 {
 }
Exemplo n.º 17
0
 public void StartDrag(DraggableItem item, int amount)
 {
     CurrentItem = item;
     CurrentDragAmount = amount;
     CurrentItem.Item.CurrentAmount -= amount;
     OnDragStarted.Invoke(CurrentItem, CurrentDragAmount);
 }
Exemplo n.º 18
0
 private void DragGrid_OnItemCreated(DraggableItem item)
 {
 }
Exemplo n.º 19
0
 private void DragManager_OnDragEnded(DraggableItem fromItem, DraggableItem item, int amount)
 {
 }
Exemplo n.º 20
0
 private void DragGrid_OnItemRemoved(DraggableItem item, int amount)
 {
 }
Exemplo n.º 21
0
 private void DragManager_OnDragStarted(DraggableItem item, int amount)
 {
 }
Exemplo n.º 22
0
 private void DragManager_OnDragStarted(DraggableItem item, int amount)
 {
     DrawGrid = true;
 }
Exemplo n.º 23
0
 private void DragGrid_OnItemAdded(DraggableItem item, int amount)
 {
 }