#Help Needed: Implementing Right-Click Drag to Transfer Half Stack in Godot 4
10 messages · Page 1 of 1 (latest)
Are you using the _get_drag_data / _drop_data methods?
Or your own custom setup?
Oh, sorry, I didn't see the expand button on your code. Let me take a look
So it seems simple enough. I think you just need the "amount" element in your data to be half of whatever the full stack is. You can add a var amount_multipler: float to your InventorySlotUI.
If the user left clicks, set amount_multipler to 1.
if the user right clicks, set amount_multipler to 0.5.
In _get_drag_data, amount *= amount_multipler.
I haven't interrogated your code too intensely, but you may not even need to change your _drop_data method.
First of all, thank you so much for your help! The idea with the amount_multiplier variable worked great, and now I can properly handle both the right and left clicks, adjusting the quantity correctly during drag-and-drop.
However, there's still one issue I haven't been able to solve. My original idea was to create an amount variable and pass it in the return for the drag_data, but I just can't figure out how to make it so that when I right-click, I can drag the item. No matter what I tried, it doesn't work the way I want it to. The main issue is that I only want the drag-and-drop to be triggered with the right-click, but it always gets triggered with the left-click.
Do you have any ideas on how I can implement the drag-and-drop with right-click? I've tried several approaches, and none of them have worked so far.
Thanks in advance for any help!
Oh darn, I had assumed there was a way to tell Godot that right click dragging was permitted. Apparently there's not. That's kind of a huge bummer for my project as well haha.
Apparently there's a work around:
https://www.reddit.com/r/godot/comments/17qnepj/can_draganddrop_work_with_rightclickanddrag/
Really hope the improve on click/drag functionality in the future. Just another push for me to build my own system
Actually, I'm going to experiment with something. Give me a minute
So goodish news? It looks like you can call _drop_data from anywhere, which means you could build your own drag/drop implantation using _input that accepts right clicks. Though I don't know how complex it would be to get the preview working. I also don't know if it's any better than the reddit solution.
That's the best I can do atm
Thanks for the update! That’s actually really helpful—calling _drop_data from anywhere seems like a viable workaround, and using _input to handle right-click drag-and-drop might be the right approach. I’ll experiment with building my own drag-and-drop system this way.
I’ll also look into how complex it might be to get the preview working with this method. It’s definitely a different direction from the Reddit solution, so I’ll see which approach works best for my needs.
Thanks again for your time and insight! I’ll let you know how it goes.