Ejemplo n.º 1
0
        /// <summary>
        /// Adds support for dragging a
        /// <see cref="InventoryForm.InventoryItemPB"/> onto an <see cref="InventoryForm.InventoryItemPB"/>.
        /// </summary>
        /// <param name="srcDDP">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="destDDP">The <see cref="IDragDropProvider"/> that that <paramref name="srcDDP"/>
        /// was dropped onto.</param>
        /// <returns>True if the drag-and-drop can be or was successful; otherwise false.</returns>
        bool CanDrop_InventoryItemToInventoryItem(IDragDropProvider srcDDP, IDragDropProvider destDDP)
        {
            var src  = srcDDP as InventoryForm.InventoryItemPB;
            var dest = destDDP as InventoryForm.InventoryItemPB;

            if (src == null || dest == null)
            {
                return(false);
            }

            if (src == dest || src.Slot == dest.Slot)
            {
                return(false);
            }

            if (src.Parent != dest.Parent)
            {
                return(false);
            }

            if (src.InventoryForm.Inventory != _gps.UserInfo.Inventory)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds support for dragging a
        /// <see cref="InventoryForm.InventoryItemPB"/> onto an <see cref="EquippedForm"/>.
        /// </summary>
        /// <param name="srcDDP">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="destDDP">The <see cref="IDragDropProvider"/> that that <paramref name="srcDDP"/>
        /// was dropped onto.</param>
        /// <returns>True if the drag-and-drop can be or was successful; otherwise false.</returns>
        bool Drop_InventoryItemToEquipped(IDragDropProvider srcDDP, IDragDropProvider destDDP)
        {
            if (!CanDrop_InventoryItemToEquipped(srcDDP, destDDP))
            {
                return(false);
            }

            var src = (InventoryForm.InventoryItemPB)srcDDP;

            src.InventoryForm.InvokeRequestUseItem(src.Slot);

            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Adds support for dragging a
        /// <see cref="EquippedForm.EquippedItemPB"/> onto an <see cref="InventoryForm"/>.
        /// </summary>
        /// <param name="srcDDP">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="destDDP">The <see cref="IDragDropProvider"/> that that <paramref name="srcDDP"/>
        /// was dropped onto.</param>
        /// <returns>True if the drag-and-drop can be or was successful; otherwise false.</returns>
        bool Drop_EquippedItemToInventory(IDragDropProvider srcDDP, IDragDropProvider destDDP)
        {
            if (!CanDrop_EquippedItemToInventory(srcDDP, destDDP))
            {
                return(false);
            }

            var src = (EquippedForm.EquippedItemPB)srcDDP;

            _gps.EquippedForm_RequestUnequip(src.EquippedForm, EventArgsHelper.Create(src.Slot));

            return(true);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Sends an event for a mouse button being pressed to this <see cref="IGUIManager"/>.
        /// </summary>
        /// <param name="e">The event arguments.</param>
        public void SendEventMouseButtonPressed(MouseButtonEventArgs e)
        {
            UpdateControlUnderCursor(e.X, e.Y);

            var c = UnderCursor;

            if (c != null)
            {
                _lastPressedControl = c;
            }

            // Handle a left mouse button press
            if (e.Button == MouseButton.Left)
            {
                // Update the focus control
                var lastFocused = FocusedControl;
                FocusedControl = c;

                // If the focused control changed, send the corresponding events
                if (lastFocused != FocusedControl)
                {
                    // Tell the old control it lost focus
                    if (lastFocused != null)
                    {
                        lastFocused.SendLostFocusEvent(e);
                    }
                }

                // Tell the new control is acquired focus
                if (FocusedControl != null)
                {
                    FocusedControl.SendFocusedEvent(e);

                    // Check if the new focused control supports drag-and-drop
                    var ddp = _underCursor as IDragDropProvider;
                    if (ddp != null && ddp.CanDragContents && !_underCursor.CanDrag)
                    {
                        _draggedDragDropProvider = ddp;
                    }
                }
            }

            // Forward the event to the focused control, if any
            if (c != null)
            {
                c.SendMouseButtonPressedEvent(e);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets if the specified <see cref="IDragDropProvider"/> can be dropped on this <see cref="IDragDropProvider"/>.
        /// </summary>
        /// <param name="source">The <see cref="IDragDropProvider"/> to check if can be dropped on this
        /// <see cref="IDragDropProvider"/>. This value will never be null.</param>
        /// <returns>True if the <paramref name="source"/> can be dropped on this <see cref="IDragDropProvider"/>;
        /// otherwise false.</returns>
        bool IDragDropProvider.CanDrop(IDragDropProvider source)
        {
            // Only allow drag-and-drop when trading
            if (!IsTradeActive)
            {
                return(false);
            }

            // Only allow drag-and-drop from an inventory item control
            if (!(source is InventoryForm.InventoryItemPB))
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Adds support for dragging a
        /// <see cref="ShopForm.ShopItemPB"/> onto an <see cref="InventoryForm"/>.
        /// </summary>
        /// <param name="srcDDP">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="destDDP">The <see cref="IDragDropProvider"/> that that <paramref name="srcDDP"/>
        /// was dropped onto.</param>
        /// <returns>True if the drag-and-drop can be or was successful; otherwise false.</returns>
        bool Drop_ShopItemToInventory(IDragDropProvider srcDDP, IDragDropProvider destDDP)
        {
            if (!CanDrop_ShopItemToInventory(srcDDP, destDDP))
            {
                return(false);
            }

            var src = (ShopForm.ShopItemPB)srcDDP;

            using (var pw = ClientPacket.BuyFromShop(src.Slot, 1))
            {
                _gps.Socket.Send(pw, ClientMessageType.GUIItems);
            }

            return(true);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Adds support for dragging a
        /// <see cref="EquippedForm.EquippedItemPB"/> onto an <see cref="InventoryForm"/>.
        /// </summary>
        /// <param name="srcDDP">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="destDDP">The <see cref="IDragDropProvider"/> that that <paramref name="srcDDP"/>
        /// was dropped onto.</param>
        /// <returns>True if the drag-and-drop can be or was successful; otherwise false.</returns>
        static bool CanDrop_EquippedItemToInventory(IDragDropProvider srcDDP, IDragDropProvider destDDP)
        {
            var src  = srcDDP as EquippedForm.EquippedItemPB;
            var dest = destDDP as InventoryForm;

            if (src == null || dest == null)
            {
                return(false);
            }

            if (src.EquippedForm == null)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Adds support for dragging a
        /// <see cref="ShopForm.ShopItemPB"/> onto an <see cref="InventoryForm"/>.
        /// </summary>
        /// <param name="srcDDP">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="destDDP">The <see cref="IDragDropProvider"/> that that <paramref name="srcDDP"/>
        /// was dropped onto.</param>
        /// <returns>True if the drag-and-drop can be or was successful; otherwise false.</returns>
        static bool CanDrop_ShopItemToInventory(IDragDropProvider srcDDP, IDragDropProvider destDDP)
        {
            var src  = srcDDP as ShopForm.ShopItemPB;
            var dest = destDDP as InventoryForm;

            if (src == null || dest == null)
            {
                return(false);
            }

            if (src.ShopForm.ShopInfo == null)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Handles when the specified <see cref="IDragDropProvider"/> is dropped on this <see cref="IDragDropProvider"/>.
        /// </summary>
        /// <param name="source">The <see cref="IDragDropProvider"/> that is being dropped on this
        /// <see cref="IDragDropProvider"/>.</param>
        void IDragDropProvider.Drop(IDragDropProvider source)
        {
            var ptih = PeerTradeInfoHandler;

            if (ptih == null)
            {
                return;
            }

            // Handle an inventory item control
            var asInvItem = source as InventoryForm.InventoryItemPB;

            if (asInvItem != null)
            {
                AddToTrade(asInvItem.Slot);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Adds support for dragging a
        /// <see cref="InventoryForm.InventoryItemPB"/> onto an <see cref="InventoryForm.InventoryItemPB"/>.
        /// </summary>
        /// <param name="srcDDP">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="destDDP">The <see cref="IDragDropProvider"/> that that <paramref name="srcDDP"/>
        /// was dropped onto.</param>
        /// <returns>True if the drag-and-drop can be or was successful; otherwise false.</returns>
        bool Drop_InventoryItemToInventoryItem(IDragDropProvider srcDDP, IDragDropProvider destDDP)
        {
            if (!CanDrop_InventoryItemToInventoryItem(srcDDP, destDDP))
            {
                return(false);
            }

            var src  = (InventoryForm.InventoryItemPB)srcDDP;
            var dest = (InventoryForm.InventoryItemPB)destDDP;

            using (var pw = ClientPacket.SwapInventorySlots(src.Slot, dest.Slot))
            {
                _gps.Socket.Send(pw, ClientMessageType.GUIItems);
            }

            return(true);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Adds support for dragging a
        /// <see cref="InventoryForm.InventoryItemPB"/> onto an <see cref="ShopForm"/>.
        /// </summary>
        /// <param name="srcDDP">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="destDDP">The <see cref="IDragDropProvider"/> that that <paramref name="srcDDP"/>
        /// was dropped onto.</param>
        /// <returns>True if the drag-and-drop can be or was successful; otherwise false.</returns>
        bool Drop_InventoryItemToShop(IDragDropProvider srcDDP, IDragDropProvider destDDP)
        {
            if (!CanDrop_InventoryItemToShop(srcDDP, destDDP))
            {
                return(false);
            }

            if (UserInventory == null)
            {
                return(false);
            }

            var src = (InventoryForm.InventoryItemPB)srcDDP;

            UserInventory.SellToShop(src.Slot, _gps.GUIManager);

            return(true);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Handles the drag-and-drop for the given <see cref="IDragDropProvider"/>s.
        /// </summary>
        /// <param name="src">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="dest">The <see cref="IDragDropProvider"/> that that <paramref name="src"/> was dropped onto.</param>
        public void Drop(IDragDropProvider src, IDragDropProvider dest)
        {
            // Check for valid parameters
            if (src == null || dest == null)
            {
                Debug.Fail("Shouldn't ever be passed a null argument.");
                return;
            }

            // Use the first method that successfully handles the given source and destination
            for (var i = 0; i < _dropCallbacks.Length; i++)
            {
                if (_dropCallbacks[i](src, dest))
                {
                    return;
                }
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Gets if the specified <see cref="IDragDropProvider"/> can be dropped on this <see cref="IDragDropProvider"/>.
        /// </summary>
        /// <param name="src">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="dest">The <see cref="IDragDropProvider"/> that that <paramref name="src"/> was dropped onto.</param>
        /// <returns>True if the <paramref name="src"/> can be dropped on this <see cref="IDragDropProvider"/>;
        /// otherwise false.</returns>
        public bool CanDrop(IDragDropProvider src, IDragDropProvider dest)
        {
            // Check for valid parameters
            if (src == null || dest == null)
            {
                Debug.Fail("Shouldn't ever be passed a null argument.");
                return(false);
            }

            // Check if any of our implementations are supported
            for (var i = 0; i < _canDropCallbacks.Length; i++)
            {
                if (_canDropCallbacks[i](src, dest))
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Sends an event for the mouse moving to this <see cref="IGUIManager"/>.
        /// </summary>
        /// <param name="e">The event arguments.</param>
        public void SendEventMouseMoved(MouseMoveEventArgs e)
        {
            UpdateControlUnderCursor(e);

            var c = UnderCursor;

            // Update the DropOntoContorl
            if (DraggedDragDropProvider != null)
            {
                // Take the control we already found as being under the cursor. Then, create a loop that will check if
                // the control implements IDragDropProvider. If not, grab the parent. This will either give us the first
                // control to implement IDragDropProvider, or null.
                var tmpDropOntoControl = c;
                while (tmpDropOntoControl != null)
                {
                    var asDDP = tmpDropOntoControl as IDragDropProvider;

                    // If the control implements IDragDropProvider, and we can drop onto it, use that. Otherwise, move onto the parent.
                    if (asDDP != null && asDDP.CanDrop(DraggedDragDropProvider))
                    {
                        break;
                    }

                    tmpDropOntoControl = tmpDropOntoControl.Parent;
                }

                // Store the results of the above loop, which will be either a valid control we can drop on, or null
                _dropOntoControl = tmpDropOntoControl as IDragDropProvider;
            }
            else
            {
                // Nothing is being dragged, so don't take the time to calculate the control to drop onto
                _dropOntoControl = null;
            }

            // Send the mouse moved event
            if (c != null)
            {
                c.SendMouseMoveEvent(e);
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Adds support for dragging a
        /// <see cref="IQuickBarItemProvider"/> onto an <see cref="QuickBarForm.QuickBarItemPB"/>.
        /// </summary>
        /// <param name="srcDDP">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="destDDP">The <see cref="IDragDropProvider"/> that that <paramref name="srcDDP"/>
        /// was dropped onto.</param>
        /// <returns>True if the drag-and-drop can be or was successful; otherwise false.</returns>
        static bool CanDrop_IQuickBarItemProviderToQuickBar(IDragDropProvider srcDDP, IDragDropProvider destDDP)
        {
            var src  = srcDDP as IQuickBarItemProvider;
            var dest = destDDP as QuickBarForm.QuickBarItemPB;

            if (src == null || dest == null)
            {
                return(false);
            }

            // Check if can be added to quick bar
            QuickBarItemType type;
            int value;

            if (!src.TryAddToQuickBar(out type, out value))
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Adds support for dragging a
        /// <see cref="InventoryForm.InventoryItemPB"/> onto an <see cref="ShopForm"/>.
        /// </summary>
        /// <param name="srcDDP">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="destDDP">The <see cref="IDragDropProvider"/> that that <paramref name="srcDDP"/>
        /// was dropped onto.</param>
        /// <returns>True if the drag-and-drop can be or was successful; otherwise false.</returns>
        static bool CanDrop_InventoryItemToShop(IDragDropProvider srcDDP, IDragDropProvider destDDP)
        {
            var src  = srcDDP as InventoryForm.InventoryItemPB;
            var dest = destDDP as ShopForm;

            if (src == null || dest == null)
            {
                return(false);
            }

            if (dest.ShopInfo == null)
            {
                return(false);
            }

            if (!dest.ShopInfo.CanBuy)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Adds support for dragging a
        /// <see cref="InventoryForm.InventoryItemPB"/> onto an <see cref="EquippedForm"/>.
        /// </summary>
        /// <param name="srcDDP">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="destDDP">The <see cref="IDragDropProvider"/> that that <paramref name="srcDDP"/>
        /// was dropped onto.</param>
        /// <returns>True if the drag-and-drop can be or was successful; otherwise false.</returns>
        bool CanDrop_InventoryItemToEquipped(IDragDropProvider srcDDP, IDragDropProvider destDDP)
        {
            var src  = srcDDP as InventoryForm.InventoryItemPB;
            var dest = destDDP as EquippedForm;

            if (src == null || dest == null)
            {
                return(false);
            }

            if (src.Item == null)
            {
                return(false);
            }

            if (src.InventoryForm.Inventory != _gps.UserInfo.Inventory)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Adds support for dragging a
        /// <see cref="IQuickBarItemProvider"/> onto an <see cref="QuickBarForm.QuickBarItemPB"/>.
        /// </summary>
        /// <param name="srcDDP">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="destDDP">The <see cref="IDragDropProvider"/> that that <paramref name="srcDDP"/>
        /// was dropped onto.</param>
        /// <returns>True if the drag-and-drop can be or was successful; otherwise false.</returns>
        static bool Drop_IQuickBarItemProviderToQuickBar(IDragDropProvider srcDDP, IDragDropProvider destDDP)
        {
            if (!CanDrop_IQuickBarItemProviderToQuickBar(srcDDP, destDDP))
            {
                return(false);
            }

            var src  = (IQuickBarItemProvider)srcDDP;
            var dest = (QuickBarForm.QuickBarItemPB)destDDP;

            // Get the quick bar values
            QuickBarItemType type;
            int value;

            if (!src.TryAddToQuickBar(out type, out value))
            {
                return(false);
            }

            var oldType  = dest.QuickBarItemType;
            var oldValue = dest.QuickBarItemValue;

            // Set the quick bar values
            dest.SetQuickBar(type, value);

            // If the source was a quick bar item, too, then set the source's item to the dest's item to give a "swap"
            // instead of just "copying" the value.
            var srcQBI = src as QuickBarForm.QuickBarItemPB;

            if (srcQBI != null)
            {
                srcQBI.SetQuickBar(oldType, oldValue);
            }

            return(true);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Sends an event for a mouse button being released to this <see cref="IGUIManager"/>.
        /// </summary>
        /// <param name="e">The event arguments.</param>
        public void SendEventMouseButtonReleased(MouseButtonEventArgs e)
        {
            UpdateControlUnderCursor(e.X, e.Y);

            // If it was the left mouse button that was released, then stop dragging the drag-and-drop provider
            // control (if we have one)
            if (e.Button == MouseButton.Left && DraggedDragDropProvider != null)
            {
                if (DropOntoControl != null && DropOntoControl.CanDrop(DraggedDragDropProvider))
                {
                    DropOntoControl.Drop(DraggedDragDropProvider);
                }

                _draggedDragDropProvider = null;
            }

            // Forward the event to the control under the cursor
            var c = UnderCursor;

            if (c != null)
            {
                c.SendMouseButtonReleasedEvent(e);
            }
        }
Ejemplo n.º 20
0
 /// <summary>
 /// Gets if the specified <see cref="IDragDropProvider"/> can be dropped on this <see cref="IDragDropProvider"/>.
 /// </summary>
 /// <param name="source">The <see cref="IDragDropProvider"/> to check if can be dropped on this
 /// <see cref="IDragDropProvider"/>. This value will never be null.</param>
 /// <returns>True if the <paramref name="source"/> can be dropped on this <see cref="IDragDropProvider"/>;
 /// otherwise false.</returns>
 bool IDragDropProvider.CanDrop(IDragDropProvider source)
 {
     return(false);
 }
Ejemplo n.º 21
0
 /// <summary>
 /// Gets if the specified <see cref="IDragDropProvider"/> can be dropped on this <see cref="IDragDropProvider"/>.
 /// </summary>
 /// <param name="source">The <see cref="IDragDropProvider"/> to check if can be dropped on this
 /// <see cref="IDragDropProvider"/>. This value will never be null.</param>
 /// <returns>True if the <paramref name="source"/> can be dropped on this <see cref="IDragDropProvider"/>;
 /// otherwise false.</returns>
 bool IDragDropProvider.CanDrop(IDragDropProvider source)
 {
     return _dragDropHandler.CanDrop(source, this);
 }
Ejemplo n.º 22
0
 /// <summary>
 /// Gets if the specified <see cref="IDragDropProvider"/> can be dropped on this <see cref="IDragDropProvider"/>.
 /// </summary>
 /// <param name="source">The <see cref="IDragDropProvider"/> to check if can be dropped on this
 /// <see cref="IDragDropProvider"/>. This value will never be null.</param>
 /// <returns>True if the <paramref name="source"/> can be dropped on this <see cref="IDragDropProvider"/>;
 /// otherwise false.</returns>
 bool IDragDropProvider.CanDrop(IDragDropProvider source)
 {
     return false;
 }
Ejemplo n.º 23
0
 /// <summary>
 /// Gets if the specified <see cref="IDragDropProvider"/> can be dropped on this <see cref="IDragDropProvider"/>.
 /// </summary>
 /// <param name="source">The <see cref="IDragDropProvider"/> to check if can be dropped on this
 /// <see cref="IDragDropProvider"/>. This value will never be null.</param>
 /// <returns>True if the <paramref name="source"/> can be dropped on this <see cref="IDragDropProvider"/>;
 /// otherwise false.</returns>
 bool IDragDropProvider.CanDrop(IDragDropProvider source)
 {
     return(_dragDropHandler.CanDrop(source, this));
 }
Ejemplo n.º 24
0
        /// <summary>
        /// Adds support for dragging a
        /// <see cref="InventoryForm.InventoryItemPB"/> onto an <see cref="ShopForm"/>.
        /// </summary>
        /// <param name="srcDDP">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="destDDP">The <see cref="IDragDropProvider"/> that that <paramref name="srcDDP"/>
        /// was dropped onto.</param>
        /// <returns>True if the drag-and-drop can be or was successful; otherwise false.</returns>
        static bool CanDrop_InventoryItemToShop(IDragDropProvider srcDDP, IDragDropProvider destDDP)
        {
            var src = srcDDP as InventoryForm.InventoryItemPB;
            var dest = destDDP as ShopForm;

            if (src == null || dest == null)
                return false;

            if (dest.ShopInfo == null)
                return false;

            if (!dest.ShopInfo.CanBuy)
                return false;

            return true;
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Adds support for dragging a
        /// <see cref="InventoryForm.InventoryItemPB"/> onto an <see cref="InventoryForm.InventoryItemPB"/>.
        /// </summary>
        /// <param name="srcDDP">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="destDDP">The <see cref="IDragDropProvider"/> that that <paramref name="srcDDP"/>
        /// was dropped onto.</param>
        /// <returns>True if the drag-and-drop can be or was successful; otherwise false.</returns>
        bool CanDrop_InventoryItemToInventoryItem(IDragDropProvider srcDDP, IDragDropProvider destDDP)
        {
            var src = srcDDP as InventoryForm.InventoryItemPB;
            var dest = destDDP as InventoryForm.InventoryItemPB;

            if (src == null || dest == null)
                return false;

            if (src == dest || src.Slot == dest.Slot)
                return false;

            if (src.Parent != dest.Parent)
                return false;

            if (src.InventoryForm.Inventory != _gps.UserInfo.Inventory)
                return false;

            return true;
        }
Ejemplo n.º 26
0
 /// <summary>
 /// Handles when the specified <see cref="IDragDropProvider"/> is dropped on this <see cref="IDragDropProvider"/>.
 /// </summary>
 /// <param name="source">The <see cref="IDragDropProvider"/> that is being dropped on this
 /// <see cref="IDragDropProvider"/>.</param>
 void IDragDropProvider.Drop(IDragDropProvider source)
 {
     QuickBarForm._gps.DragDropHandler.Drop(source, this);
 }
Ejemplo n.º 27
0
        /// <summary>
        /// Adds support for dragging a
        /// <see cref="ShopForm.ShopItemPB"/> onto an <see cref="InventoryForm"/>.
        /// </summary>
        /// <param name="srcDDP">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="destDDP">The <see cref="IDragDropProvider"/> that that <paramref name="srcDDP"/>
        /// was dropped onto.</param>
        /// <returns>True if the drag-and-drop can be or was successful; otherwise false.</returns>
        static bool CanDrop_ShopItemToInventory(IDragDropProvider srcDDP, IDragDropProvider destDDP)
        {
            var src = srcDDP as ShopForm.ShopItemPB;
            var dest = destDDP as InventoryForm;

            if (src == null || dest == null)
                return false;

            if (src.ShopForm.ShopInfo == null)
                return false;

            return true;
        }
Ejemplo n.º 28
0
 /// <summary>
 /// Handles when the specified <see cref="IDragDropProvider"/> is dropped on this <see cref="IDragDropProvider"/>.
 /// </summary>
 /// <param name="source">The <see cref="IDragDropProvider"/> that is being dropped on this
 /// <see cref="IDragDropProvider"/>.</param>
 void IDragDropProvider.Drop(IDragDropProvider source)
 {
     QuickBarForm._gps.DragDropHandler.Drop(source, this);
 }
Ejemplo n.º 29
0
 /// <summary>
 /// Gets if the specified <see cref="IDragDropProvider"/> can be dropped on this <see cref="IDragDropProvider"/>.
 /// </summary>
 /// <param name="source">The <see cref="IDragDropProvider"/> to check if can be dropped on this
 /// <see cref="IDragDropProvider"/>. This value will never be null.</param>
 /// <returns>True if the <paramref name="source"/> can be dropped on this <see cref="IDragDropProvider"/>;
 /// otherwise false.</returns>
 bool IDragDropProvider.CanDrop(IDragDropProvider source)
 {
     return InventoryForm._dragDropHandler.CanDrop(source, this);
 }
Ejemplo n.º 30
0
 /// <summary>
 /// Gets if the specified <see cref="IDragDropProvider"/> can be dropped on this <see cref="IDragDropProvider"/>.
 /// </summary>
 /// <param name="source">The <see cref="IDragDropProvider"/> to check if can be dropped on this
 /// <see cref="IDragDropProvider"/>. This value will never be null.</param>
 /// <returns>True if the <paramref name="source"/> can be dropped on this <see cref="IDragDropProvider"/>;
 /// otherwise false.</returns>
 bool IDragDropProvider.CanDrop(IDragDropProvider source)
 {
     return QuickBarForm._gps.DragDropHandler.CanDrop(source, this);
 }
Ejemplo n.º 31
0
 /// <summary>
 /// Handles when the specified <see cref="IDragDropProvider"/> is dropped on this <see cref="IDragDropProvider"/>.
 /// </summary>
 /// <param name="source">The <see cref="IDragDropProvider"/> that is being dropped on this
 /// <see cref="IDragDropProvider"/>.</param>
 void IDragDropProvider.Drop(IDragDropProvider source)
 {
     InventoryForm._dragDropHandler.Drop(source, this);
 }
Ejemplo n.º 32
0
 /// <summary>
 /// Gets if the specified <see cref="IDragDropProvider"/> can be dropped on this <see cref="IDragDropProvider"/>.
 /// </summary>
 /// <param name="source">The <see cref="IDragDropProvider"/> to check if can be dropped on this
 /// <see cref="IDragDropProvider"/>. This value will never be null.</param>
 /// <returns>True if the <paramref name="source"/> can be dropped on this <see cref="IDragDropProvider"/>;
 /// otherwise false.</returns>
 bool IDragDropProvider.CanDrop(IDragDropProvider source)
 {
     return(InventoryForm._dragDropHandler.CanDrop(source, this));
 }
Ejemplo n.º 33
0
        /// <summary>
        /// Sends an event for a mouse button being released to this <see cref="IGUIManager"/>.
        /// </summary>
        /// <param name="e">The event arguments.</param>
        public void SendEventMouseButtonReleased(MouseButtonEventArgs e)
        {
            UpdateControlUnderCursor(e.X, e.Y);

            // If it was the left mouse button that was released, then stop dragging the drag-and-drop provider
            // control (if we have one)
            if (e.Button == MouseButton.Left && DraggedDragDropProvider != null)
            {
                if (DropOntoControl != null && DropOntoControl.CanDrop(DraggedDragDropProvider))
                    DropOntoControl.Drop(DraggedDragDropProvider);

                _draggedDragDropProvider = null;
            }

            // Forward the event to the control under the cursor
            var c = UnderCursor;
            if (c != null)
                c.SendMouseButtonReleasedEvent(e);
        }
Ejemplo n.º 34
0
        /// <summary>
        /// Sends an event for a mouse button being pressed to this <see cref="IGUIManager"/>.
        /// </summary>
        /// <param name="e">The event arguments.</param>
        public void SendEventMouseButtonPressed(MouseButtonEventArgs e)
        {
            UpdateControlUnderCursor(e.X, e.Y);

            var c = UnderCursor;

            if (c != null)
                _lastPressedControl = c;

            // Handle a left mouse button press
            if (e.Button == MouseButton.Left)
            {
                // Update the focus control
                var lastFocused = FocusedControl;
                FocusedControl = c;

                // If the focused control changed, send the corresponding events
                if (lastFocused != FocusedControl)
                {
                    // Tell the old control it lost focus
                    if (lastFocused != null)
                        lastFocused.SendLostFocusEvent(e);
                }

                // Tell the new control is acquired focus
                if (FocusedControl != null)
                {
                    FocusedControl.SendFocusedEvent(e);

                    // Check if the new focused control supports drag-and-drop
                    var ddp = _underCursor as IDragDropProvider;
                    if (ddp != null && ddp.CanDragContents && !_underCursor.CanDrag)
                        _draggedDragDropProvider = ddp;
                }
            }

            // Forward the event to the focused control, if any
            if (c != null)
                c.SendMouseButtonPressedEvent(e);
        }
Ejemplo n.º 35
0
        /// <summary>
        /// Adds support for dragging a
        /// <see cref="InventoryForm.InventoryItemPB"/> onto an <see cref="EquippedForm"/>.
        /// </summary>
        /// <param name="srcDDP">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="destDDP">The <see cref="IDragDropProvider"/> that that <paramref name="srcDDP"/>
        /// was dropped onto.</param>
        /// <returns>True if the drag-and-drop can be or was successful; otherwise false.</returns>
        bool Drop_InventoryItemToEquipped(IDragDropProvider srcDDP, IDragDropProvider destDDP)
        {
            if (!CanDrop_InventoryItemToEquipped(srcDDP, destDDP))
                return false;

            var src = (InventoryForm.InventoryItemPB)srcDDP;

            src.InventoryForm.InvokeRequestUseItem(src.Slot);

            return true;
        }
Ejemplo n.º 36
0
        /// <summary>
        /// Gets if the specified <see cref="IDragDropProvider"/> can be dropped on this <see cref="IDragDropProvider"/>.
        /// </summary>
        /// <param name="src">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="dest">The <see cref="IDragDropProvider"/> that that <paramref name="src"/> was dropped onto.</param>
        /// <returns>True if the <paramref name="src"/> can be dropped on this <see cref="IDragDropProvider"/>;
        /// otherwise false.</returns>
        public bool CanDrop(IDragDropProvider src, IDragDropProvider dest)
        {
            // Check for valid parameters
            if (src == null || dest == null)
            {
                Debug.Fail("Shouldn't ever be passed a null argument.");
                return false;
            }

            // Check if any of our implementations are supported
            for (var i = 0; i < _canDropCallbacks.Length; i++)
            {
                if (_canDropCallbacks[i](src, dest))
                    return true;
            }

            return false;
        }
Ejemplo n.º 37
0
        /// <summary>
        /// Adds support for dragging a
        /// <see cref="ShopForm.ShopItemPB"/> onto an <see cref="InventoryForm"/>.
        /// </summary>
        /// <param name="srcDDP">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="destDDP">The <see cref="IDragDropProvider"/> that that <paramref name="srcDDP"/>
        /// was dropped onto.</param>
        /// <returns>True if the drag-and-drop can be or was successful; otherwise false.</returns>
        bool Drop_ShopItemToInventory(IDragDropProvider srcDDP, IDragDropProvider destDDP)
        {
            if (!CanDrop_ShopItemToInventory(srcDDP, destDDP))
                return false;

            var src = (ShopForm.ShopItemPB)srcDDP;

            using (var pw = ClientPacket.BuyFromShop(src.Slot, 1))
            {
                _gps.Socket.Send(pw, ClientMessageType.GUIItems);
            }

            return true;
        }
Ejemplo n.º 38
0
        /// <summary>
        /// Handles the drag-and-drop for the given <see cref="IDragDropProvider"/>s.
        /// </summary>
        /// <param name="src">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="dest">The <see cref="IDragDropProvider"/> that that <paramref name="src"/> was dropped onto.</param>
        public void Drop(IDragDropProvider src, IDragDropProvider dest)
        {
            // Check for valid parameters
            if (src == null || dest == null)
            {
                Debug.Fail("Shouldn't ever be passed a null argument.");
                return;
            }

            // Use the first method that successfully handles the given source and destination
            for (var i = 0; i < _dropCallbacks.Length; i++)
            {
                if (_dropCallbacks[i](src, dest))
                    return;
            }
        }
Ejemplo n.º 39
0
        /// <summary>
        /// Adds support for dragging a
        /// <see cref="InventoryForm.InventoryItemPB"/> onto an <see cref="ShopForm"/>.
        /// </summary>
        /// <param name="srcDDP">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="destDDP">The <see cref="IDragDropProvider"/> that that <paramref name="srcDDP"/>
        /// was dropped onto.</param>
        /// <returns>True if the drag-and-drop can be or was successful; otherwise false.</returns>
        bool Drop_InventoryItemToShop(IDragDropProvider srcDDP, IDragDropProvider destDDP)
        {
            if (!CanDrop_InventoryItemToShop(srcDDP, destDDP))
                return false;

            if (UserInventory == null)
                return false;

            var src = (InventoryForm.InventoryItemPB)srcDDP;

            UserInventory.SellToShop(src.Slot, _gps.GUIManager);

            return true;
        }
Ejemplo n.º 40
0
        /// <summary>
        /// Adds support for dragging a
        /// <see cref="IQuickBarItemProvider"/> onto an <see cref="QuickBarForm.QuickBarItemPB"/>.
        /// </summary>
        /// <param name="srcDDP">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="destDDP">The <see cref="IDragDropProvider"/> that that <paramref name="srcDDP"/>
        /// was dropped onto.</param>
        /// <returns>True if the drag-and-drop can be or was successful; otherwise false.</returns>
        static bool CanDrop_IQuickBarItemProviderToQuickBar(IDragDropProvider srcDDP, IDragDropProvider destDDP)
        {
            var src = srcDDP as IQuickBarItemProvider;
            var dest = destDDP as QuickBarForm.QuickBarItemPB;

            if (src == null || dest == null)
                return false;

            // Check if can be added to quick bar
            QuickBarItemType type;
            int value;
            if (!src.TryAddToQuickBar(out type, out value))
                return false;

            return true;
        }
Ejemplo n.º 41
0
        /// <summary>
        /// Adds support for dragging a
        /// <see cref="InventoryForm.InventoryItemPB"/> onto an <see cref="InventoryForm.InventoryItemPB"/>.
        /// </summary>
        /// <param name="srcDDP">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="destDDP">The <see cref="IDragDropProvider"/> that that <paramref name="srcDDP"/>
        /// was dropped onto.</param>
        /// <returns>True if the drag-and-drop can be or was successful; otherwise false.</returns>
        bool Drop_InventoryItemToInventoryItem(IDragDropProvider srcDDP, IDragDropProvider destDDP)
        {
            if (!CanDrop_InventoryItemToInventoryItem(srcDDP, destDDP))
                return false;

            var src = (InventoryForm.InventoryItemPB)srcDDP;
            var dest = (InventoryForm.InventoryItemPB)destDDP;

            using (var pw = ClientPacket.SwapInventorySlots(src.Slot, dest.Slot))
            {
                _gps.Socket.Send(pw, ClientMessageType.GUIItems);
            }

            return true;
        }
Ejemplo n.º 42
0
        /// <summary>
        /// Adds support for dragging a
        /// <see cref="IQuickBarItemProvider"/> onto an <see cref="QuickBarForm.QuickBarItemPB"/>.
        /// </summary>
        /// <param name="srcDDP">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="destDDP">The <see cref="IDragDropProvider"/> that that <paramref name="srcDDP"/>
        /// was dropped onto.</param>
        /// <returns>True if the drag-and-drop can be or was successful; otherwise false.</returns>
        static bool Drop_IQuickBarItemProviderToQuickBar(IDragDropProvider srcDDP, IDragDropProvider destDDP)
        {
            if (!CanDrop_IQuickBarItemProviderToQuickBar(srcDDP, destDDP))
                return false;

            var src = (IQuickBarItemProvider)srcDDP;
            var dest = (QuickBarForm.QuickBarItemPB)destDDP;

            // Get the quick bar values
            QuickBarItemType type;
            int value;
            if (!src.TryAddToQuickBar(out type, out value))
                return false;

            var oldType = dest.QuickBarItemType;
            var oldValue = dest.QuickBarItemValue;

            // Set the quick bar values
            dest.SetQuickBar(type, value);

            // If the source was a quick bar item, too, then set the source's item to the dest's item to give a "swap"
            // instead of just "copying" the value.
            var srcQBI = src as QuickBarForm.QuickBarItemPB;
            if (srcQBI != null)
                srcQBI.SetQuickBar(oldType, oldValue);

            return true;
        }
Ejemplo n.º 43
0
 /// <summary>
 /// Handles when the specified <see cref="IDragDropProvider"/> is dropped on this <see cref="IDragDropProvider"/>.
 /// </summary>
 /// <param name="source">The <see cref="IDragDropProvider"/> that is being dropped on this
 /// <see cref="IDragDropProvider"/>.</param>
 void IDragDropProvider.Drop(IDragDropProvider source)
 {
 }
Ejemplo n.º 44
0
        /// <summary>
        /// Adds support for dragging a
        /// <see cref="EquippedForm.EquippedItemPB"/> onto an <see cref="InventoryForm"/>.
        /// </summary>
        /// <param name="srcDDP">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="destDDP">The <see cref="IDragDropProvider"/> that that <paramref name="srcDDP"/>
        /// was dropped onto.</param>
        /// <returns>True if the drag-and-drop can be or was successful; otherwise false.</returns>
        static bool CanDrop_EquippedItemToInventory(IDragDropProvider srcDDP, IDragDropProvider destDDP)
        {
            var src = srcDDP as EquippedForm.EquippedItemPB;
            var dest = destDDP as InventoryForm;

            if (src == null || dest == null)
                return false;

            if (src.EquippedForm == null)
                return false;

            return true;
        }
Ejemplo n.º 45
0
 /// <summary>
 /// Handles when the specified <see cref="IDragDropProvider"/> is dropped on this <see cref="IDragDropProvider"/>.
 /// </summary>
 /// <param name="source">The <see cref="IDragDropProvider"/> that is being dropped on this
 /// <see cref="IDragDropProvider"/>.</param>
 void IDragDropProvider.Drop(IDragDropProvider source)
 {
     _dragDropHandler.Drop(source, this);
 }
Ejemplo n.º 46
0
        /// <summary>
        /// Adds support for dragging a
        /// <see cref="EquippedForm.EquippedItemPB"/> onto an <see cref="InventoryForm"/>.
        /// </summary>
        /// <param name="srcDDP">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="destDDP">The <see cref="IDragDropProvider"/> that that <paramref name="srcDDP"/>
        /// was dropped onto.</param>
        /// <returns>True if the drag-and-drop can be or was successful; otherwise false.</returns>
        bool Drop_EquippedItemToInventory(IDragDropProvider srcDDP, IDragDropProvider destDDP)
        {
            if (!CanDrop_EquippedItemToInventory(srcDDP, destDDP))
                return false;

            var src = (EquippedForm.EquippedItemPB)srcDDP;

            _gps.EquippedForm_RequestUnequip(src.EquippedForm, EventArgsHelper.Create(src.Slot));

            return true;
        }
Ejemplo n.º 47
0
 /// <summary>
 /// Handles when the specified <see cref="IDragDropProvider"/> is dropped on this <see cref="IDragDropProvider"/>.
 /// </summary>
 /// <param name="source">The <see cref="IDragDropProvider"/> that is being dropped on this
 /// <see cref="IDragDropProvider"/>.</param>
 void IDragDropProvider.Drop(IDragDropProvider source)
 {
 }
Ejemplo n.º 48
0
        /// <summary>
        /// Adds support for dragging a
        /// <see cref="InventoryForm.InventoryItemPB"/> onto an <see cref="EquippedForm"/>.
        /// </summary>
        /// <param name="srcDDP">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="destDDP">The <see cref="IDragDropProvider"/> that that <paramref name="srcDDP"/>
        /// was dropped onto.</param>
        /// <returns>True if the drag-and-drop can be or was successful; otherwise false.</returns>
        bool CanDrop_InventoryItemToEquipped(IDragDropProvider srcDDP, IDragDropProvider destDDP)
        {
            var src = srcDDP as InventoryForm.InventoryItemPB;
            var dest = destDDP as EquippedForm;

            if (src == null || dest == null)
                return false;

            if (src.Item == null)
                return false;

            if (src.InventoryForm.Inventory != _gps.UserInfo.Inventory)
                return false;

            return true;
        }
Ejemplo n.º 49
0
 /// <summary>
 /// Handles when the specified <see cref="IDragDropProvider"/> is dropped on this <see cref="IDragDropProvider"/>.
 /// </summary>
 /// <param name="source">The <see cref="IDragDropProvider"/> that is being dropped on this
 /// <see cref="IDragDropProvider"/>.</param>
 void IDragDropProvider.Drop(IDragDropProvider source)
 {
     _dragDropHandler.Drop(source, this);
 }
Ejemplo n.º 50
0
        /// <summary>
        /// Sends an event for the mouse moving to this <see cref="IGUIManager"/>.
        /// </summary>
        /// <param name="e">The event arguments.</param>
        public void SendEventMouseMoved(MouseMoveEventArgs e)
        {
            UpdateControlUnderCursor(e);

            var c = UnderCursor;

            // Update the DropOntoContorl
            if (DraggedDragDropProvider != null)
            {
                // Take the control we already found as being under the cursor. Then, create a loop that will check if
                // the control implements IDragDropProvider. If not, grab the parent. This will either give us the first
                // control to implement IDragDropProvider, or null.
                var tmpDropOntoControl = c;
                while (tmpDropOntoControl != null)
                {
                    var asDDP = tmpDropOntoControl as IDragDropProvider;

                    // If the control implements IDragDropProvider, and we can drop onto it, use that. Otherwise, move onto the parent.
                    if (asDDP != null && asDDP.CanDrop(DraggedDragDropProvider))
                        break;

                    tmpDropOntoControl = tmpDropOntoControl.Parent;
                }

                // Store the results of the above loop, which will be either a valid control we can drop on, or null
                _dropOntoControl = tmpDropOntoControl as IDragDropProvider;
            }
            else
            {
                // Nothing is being dragged, so don't take the time to calculate the control to drop onto
                _dropOntoControl = null;
            }

            // Send the mouse moved event
            if (c != null)
                c.SendMouseMoveEvent(e);
        }
Ejemplo n.º 51
0
 /// <summary>
 /// Handles when the specified <see cref="IDragDropProvider"/> is dropped on this <see cref="IDragDropProvider"/>.
 /// </summary>
 /// <param name="source">The <see cref="IDragDropProvider"/> that is being dropped on this
 /// <see cref="IDragDropProvider"/>.</param>
 void IDragDropProvider.Drop(IDragDropProvider source)
 {
     InventoryForm._dragDropHandler.Drop(source, this);
 }
Ejemplo n.º 52
0
 /// <summary>
 /// Gets if the specified <see cref="IDragDropProvider"/> can be dropped on this <see cref="IDragDropProvider"/>.
 /// </summary>
 /// <param name="source">The <see cref="IDragDropProvider"/> to check if can be dropped on this
 /// <see cref="IDragDropProvider"/>. This value will never be null.</param>
 /// <returns>True if the <paramref name="source"/> can be dropped on this <see cref="IDragDropProvider"/>;
 /// otherwise false.</returns>
 bool IDragDropProvider.CanDrop(IDragDropProvider source)
 {
     return(QuickBarForm._gps.DragDropHandler.CanDrop(source, this));
 }