Page 1 of 1

[Solved] Remove old dragged when new dragged is placed into the same droppable

Posted: Wed Aug 11, 2021 10:03 am
by omranpanda
Hello, I want to know how would I go about making it so that when a new drag is placed into an already occupied drop it would displace the old drag outside of the drop.

I'm using a slightly modified code of the one found here https://www.renpy.org/doc/html/drag_drop.html

Here is the code:

Code: Select all

init python:

    def detective_dragged(drags, drop):

        if not drop:
            return

        store.detective = drags[0].drag_name
        store.city = drop.drag_name

        return

screen send_detective_screen:

    # A map as background.
    add "europe.jpg"

    # A drag group ensures that the detectives and the cities can be
    # dragged to each other.
    draggroup:

        # Our detectives.
        drag:
            drag_name "Ivy"
            child "ivy.png"
            droppable False
            dragged detective_dragged
            xpos 100 ypos 100
        drag:
            drag_name "Zack"
            child "zack.png"
            droppable False
            dragged detective_dragged
            xpos 150 ypos 100

        # The cities they can go to.
        drag:
            drag_name "London"
            child "london.png"
            draggable False
            xpos 450 ypos 140
            
            
    key "b" action Return()


label send_detective:
    "We need to investigate! Who should we send, and where should they go?"

    call screen send_detective_screen

    "Okay, we'll send [detective] to [city]."

Re: Remove old dragged when new dragged is placed into the same droppable

Posted: Wed Aug 11, 2021 2:15 pm
by Alex
omranpanda wrote:
Wed Aug 11, 2021 10:03 am
Hello, I want to know how would I go about making it so that when a new drag is placed into an already occupied drop it would displace the old drag outside of the drop....
Try it like - viewtopic.php?f=8&t=38835&p=417941&hilit=snap#p417941

Re: Remove old dragged when new dragged is placed into the same droppable

Posted: Thu Aug 12, 2021 8:41 am
by omranpanda
Alex wrote:
Wed Aug 11, 2021 2:15 pm
omranpanda wrote:
Wed Aug 11, 2021 10:03 am
Hello, I want to know how would I go about making it so that when a new drag is placed into an already occupied drop it would displace the old drag outside of the drop....
Try it like - viewtopic.php?f=8&t=38835&p=417941&hilit=snap#p417941
Sorry but could you specify which part I should be looking at and explain it with a bit more detail if you may?

Re: Remove old dragged when new dragged is placed into the same droppable

Posted: Thu Aug 12, 2021 1:07 pm
by Alex
omranpanda wrote:
Thu Aug 12, 2021 8:41 am
...Sorry but could you specify which part I should be looking at and explain it with a bit more detail if you may?
Khm, the whole thing. You need to store positions for each draggable to know where to put old drag when new one is placed over occupied slot. Then you need to code the action in detective_dragged function (in my sample it's a my_dragged function). So, it became a bit complicated. In sample code I put some comments.

Re: Remove old dragged when new dragged is placed into the same droppable

Posted: Fri Sep 03, 2021 3:47 pm
by omranpanda
Alex wrote:
Thu Aug 12, 2021 1:07 pm
omranpanda wrote:
Thu Aug 12, 2021 8:41 am
...Sorry but could you specify which part I should be looking at and explain it with a bit more detail if you may?
Khm, the whole thing. You need to store positions for each draggable to know where to put old drag when new one is placed over occupied slot. Then you need to code the action in detective_dragged function (in my sample it's a my_dragged function). So, it became a bit complicated. In sample code I put some comments.
Ah, alright thanks!