コード例 #1
0
ファイル: DragGrid.cs プロジェクト: svifylabs/dwarfcorp
        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();
        }
コード例 #2
0
ファイル: DragGrid.cs プロジェクト: svifylabs/dwarfcorp
        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);
        }
コード例 #3
0
ファイル: DragGrid.cs プロジェクト: scorvi/dwarfcorp
 public DragGrid(DwarfGUI gui, GUIComponent parent, DragManager dragManager, int gridWidth, int gridHeight)
     : base(gui, parent)
 {
     Items = new List<DraggableItem>();
     DragManager = dragManager;
     GridWidth = gridWidth;
     GridHeight = gridHeight;
     SetupLayout();
     DrawGrid = false;
     DragManager.OnDragEnded += DragManager_OnDragEnded;
     DragManager.OnDragStarted += DragManager_OnDragStarted;
     OnItemCreated += DragGrid_OnItemCreated;
     OnItemDestroyed += DragGrid_OnItemDestroyed;
     OnChanged += DragGrid_OnChanged;
     DrawBackground = true;
     BackColor = new Color(255, 255, 255, 100);
     BorderColor = new Color(0, 0, 0, 100);
 }
コード例 #4
0
ファイル: DragGrid.cs プロジェクト: svifylabs/dwarfcorp
 public DragGrid(DwarfGUI gui, GUIComponent parent, DragManager dragManager, int gridWidth, int gridHeight) :
     base(gui, parent)
 {
     Items       = new List <DraggableItem>();
     DragManager = dragManager;
     GridWidth   = gridWidth;
     GridHeight  = gridHeight;
     SetupLayout();
     DrawGrid = false;
     DragManager.OnDragEnded   += DragManager_OnDragEnded;
     DragManager.OnDragStarted += DragManager_OnDragStarted;
     OnItemCreated             += DragGrid_OnItemCreated;
     OnItemDestroyed           += DragGrid_OnItemDestroyed;
     OnChanged     += DragGrid_OnChanged;
     DrawBackground = true;
     BackColor      = new Color(255, 255, 255, 100);
     BorderColor    = new Color(0, 0, 0, 100);
 }