Videogamers0/MGUI

Item Drag Drop sample

Closed this issue · 3 comments

I think it would be amazing if you could provide a few items that can be moved around in the inventory demo.
Any maybe an example on how we can drag items from inventory to the skillbar in the HUD.

7b1543a

Unfortunately MGUI doesn't provide a drag+drop framework, so you'd have to subscribe and react to mouse events yourself to implement the desired behavior. I've added a simple example of this to the FF7Inventory dialog. You can now drag an item from the inventory and drop it onto a party member in the list on the left to use the item on the party member.

In the sample, drag+drop is mainly implemented by doing the following:

  1. Detect when an item in the inventory is pressed and when it is released. You can find this logic in MGListBox's constructor, mainly lines 687 to 711.

  2. Detect when a party member in the party list is hovered. You can find this logic in FF7Inventory.xaml.cs 's constructor, mainly lines 208 to 239.

If a party member is hovered, while an inventory item is currently pressed but not released, we render an additional transparent yellow overlay onto the party member (line #234). When the left-mouse button is released, we prioritize using the pressed inventory item instead of the selected inventory item (line #213)

7b1543a

Unfortunately MGUI doesn't provide a drag+drop framework, so you'd have to subscribe and react to mouse events yourself to implement the desired behavior. I've added a simple example of this to the FF7Inventory dialog. You can now drag an item from the inventory and drop it onto a party member in the list on the left to use the item on the party member.

In the sample, drag+drop is mainly implemented by doing the following:

  1. Detect when an item in the inventory is pressed and when it is released. You can find this logic in MGListBox's constructor, mainly lines 687 to 711.
  2. Detect when a party member in the party list is hovered. You can find this logic in FF7Inventory.xaml.cs 's constructor, mainly lines 208 to 239.

If a party member is hovered, while an inventory item is currently pressed but not released, we render an additional transparent yellow overlay onto the party member (line #234). When the left-mouse button is released, we prioritize using the pressed inventory item instead of the selected inventory item (line #213)

Awesome, thank you for the sample.

I wanted to ask as well if MGUI is compatible with Android Touch Input ? I have seen only things related to mouse/keyboard in the documentation. If it's not, could you suggest a good starting point for implementing it ?

Also does MGUI work with visual studio's intellisense for autocomplete ?

No, I've never worked with Microsoft.Xna.Framework.Input.Touch. If the touch input registers as a mouse click it would probably work fine out of the box. But gestures would need their own specific logic.

VS intellisense should work as long as you set the default namespace to xmlns="clr-namespace:MGUI.Core.UI.XAML;assembly=MGUI.Core". See here