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(); }
public void StartDrag(DraggableItem item, int amount) { CurrentItem = item; CurrentDragAmount = amount; CurrentItem.Item.CurrentAmount -= amount; OnDragStarted.Invoke(CurrentItem, CurrentDragAmount); }
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); } }
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); }
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); } } }
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); }
private void DragGrid_OnItemDestroyed(DraggableItem item) { }
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(); }
private void DragGrid_OnItemDestroyed(DraggableItem item) { }
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); }
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; } } }
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; } }
private void DragManager_OnDragStarted(DraggableItem item, int amount) { DrawGrid = true; }
private void DragGrid_OnItemCreated(DraggableItem item) { }
private void DragManager_OnDragEnded(DraggableItem fromItem, DraggableItem item, int amount) { }
private void DragManager_OnDragStarted(DraggableItem item, int amount) { }
public void StartDrag(DraggableItem item, int amount) { CurrentItem = item; CurrentDragAmount = amount; CurrentItem.Item.CurrentAmount -= amount; OnDragStarted.Invoke(CurrentItem, CurrentDragAmount); }
private void DragGrid_OnItemCreated(DraggableItem item) { }
private void DragManager_OnDragEnded(DraggableItem fromItem, DraggableItem item, int amount) { }
private void DragGrid_OnItemRemoved(DraggableItem item, int amount) { }
private void DragManager_OnDragStarted(DraggableItem item, int amount) { }
private void DragManager_OnDragStarted(DraggableItem item, int amount) { DrawGrid = true; }
private void DragGrid_OnItemAdded(DraggableItem item, int amount) { }