how to have draggables inside a viewport be brought outside to put on a droppable?

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
DFlimbingo
Regular
Posts: 25
Joined: Wed Mar 24, 2021 2:37 am
Contact:

how to have draggables inside a viewport be brought outside to put on a droppable?

#1 Post by DFlimbingo »

Hi! I'm trying to make a drag and drop system that takes the draggable object from a scrollable viewport and onto a outside droppable area. To make it clear, here is the layout currently:

Image

The black square with a question mark is the area I want to be able to put the square with a smiling lad on to. Afterwards, the "? is on ?!" turns into "person is on spot!", which I use to test the variables are working. In previous tests where there was no viewport, this works perfectly fine. however, with the draggable object inside the viewport, it cannot escape the frame it is inside. Here is the code inside the init python block:

Code: Select all

init python:

    def unit_dragged(drags, drop):
        if drop:
            drags[0].snap(drop.x,drop.y)

            store.person = drags[0].drag_name
            store.spot = drop.drag_name
            return
        if not drop:
            drags[0].snap( 5, 5)
            return
and here is the code inside the screen. Do note that this screen is inside a menu.

Code: Select all

screen vcs:

    tag menu

    use evi_menu(_("VCS")):
        hbox:
            yalign 0.1
            xalign 0.0
            add "cam" # the background image of the woman.
        frame:
            area (0, 450, 700, 200)
            viewport id "vp":
                scrollbars "vertical"
                mousewheel True
                draggable True
                side_yfill True

                vbox:
                    draggroup:
                        drag:
                            drag_name "movable"
                            child "icon1_idle.png"
                            ypos 5
                            dragged unit_dragged
                            droppable False
                            xpos 5
            vbar value YScrollValue("vp")

        drag:
            drag_name "postion"
            child "whoisit.png"
            draggable False
            droppable True
            yalign 0.27
            xalign 0.28

        frame:
            xsize 200
            ysize 650
            yalign 0.27
            xalign 0.99
            xpadding 10
            ypadding 10
            text "[person] is on [spot]!"
I am only putting the draggable objects into a viewport to be able to scroll through future added draggable objects. If there is some other way to have a scrollable area without all this headache, that would be a great alternative.
Thank you for reading!! I have been utterly confused with this for a while.

Post Reply

Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot], Google [Bot]