I'm preparing a sort of escape room for NaNoRenO and I'm trying to implement an inventory system.
My goal is that the player will be able to drags items from an inventory shown on screen to certain "hotspots" on the screen.
I spent some time wrapping my head around the drag&drop documentation and I achieved something that (mostly) works. I can drag obects on the screen and make things happen when they're dropped at the right place. (hourray \o/)
Now, I'd like that each time I drop the item, it comes back to its original place in the inventory frame. But the dragged items "remember" their position (which is usually the wanted behaviour). How could I "reset" that position and make them go back in their original place ?
(I suppose that something should be done in the callback function, for example ?)
Here is a sample of my code
Code: Select all
init python: ## callback function for drag&drop
def item_dragged(drags, drop):
if not drop:
return
# Interactions contains all predefined interactions between items and places
if interactions.has_key( (drags[0].drag_name, drop.drag_name) ):
renpy.call(interactions[(drags[0].drag_name, drop.drag_name)])
else:
renpy.call("nothing_happens") ## default interaction
#return
screen use_item(view_data):
add view_data['background']
# Inventory frame backbground
frame:
xpadding 20
ypadding 20
xalign .5
ypos 20
xsize 720
ysize 90
background Solid("#fff")
grid 10 1:
xsize 50
spacing 20
for i in range(10):
add Solid("#eee") id "i"
draggroup:
# droppable zones (retrieved from a list)
for spot in view_data['hotspots']:
drag:
drag_name spot["name"]
child spot["child"]
draggable False
xpos spot["coordinates"][0]
ypos spot["coordinates"][1]
# draggable items (retrieved from a list called inventory)
$ x_pos = 280
for item in inventory:
$ x_pos += 20
drag:
drag_name item["drag_name"]
child item["image"]
droppable False
dragged item_dragged
xpos x_pos
ypos 40