Page 1 of 1

Drag&Drop + Screen Language issue(s):

Posted: Tue Jul 01, 2014 9:21 am
by xela
This is not the code used in the game but it has similar structure (it would take too long to isolate the original code):

Code: Select all

init python:
    class Drags(object):
        def __init__(self):
            self.coords = dict()
            x, y = 0, 0
            for i in range(10):
                self.coords[str(i)] = (x, y)
                x += 50
    
    def dragged(drags, drop):
        for i in d.coords:
            if i == drags[0].drag_name:
                x = d.coords[i][0]
                y = d.coords[i][1]

        if not drop:
            drags[0].snap(x, y, delay=0.2)
            return
        return True


label start:
    $ d = Drags()
    $ renpy.show_screen("dragdrop")
    while 1:
        $ result = ui.interact()
        
screen dragdrop:
    draggroup:
        for i in d.coords:
            $ img = im.Scale("some image", 50, 50)
            drag:
                drag_name i
                child img
                droppable False
                dragged dragged
                clicked NullAction()
                pos (d.coords[i][0], d.coords[i][1])
# Note: chr argument has nothing to do with Python build-in*

Main differences with the games code are:

- Drags class is a lot bigger, it holds the positions and manages the container with objects sorting them and giving assigning them coordinates each time paging occurs, one of it's methods than returns a container with names/coords/objects that is iterated over in screen language to construct a draggroup with paging, draggable and droppable drags.

Issues found:

1) (This one can be replicated just with the code above) If you move different drags one after another fast enough, sooner or later one of them will disappear and be restored not from where it was dragged to but from pos(0, 0).

2) I do hope that I can relay this clear enough...

- In the game these drags can be dropped. Droppable area is also a drag (obviously) but it has a frame and number of buttons. Once dropped, drag is being removed from the group and a new button appears in the frame where it was dropped... Now, if that button is clicked (the whole droppable drag actually represents a team of 1 - 3 people) one of the options removes the teammember and it is added back to the container (page) (interaction is restarted).

so far so good, however:

The restored drag is not added to draggroup for some reason and does NOT go to the assigned coordinates (until it is clicked and dragged somewhere by user (then it would go to coords where it belongs)), instead it appears somewhere near where the button was...

I've opened the widget and found a way to fix it that looks like this:

Code: Select all

        def normalize_pos(self, chr):
            """
            Used to normalize positions of drags on the screen!
            """
            dg = renpy.get_widget("pyt_fg_management", "team_dg")
            if chr in self.get_page_content():
                index = self.get_page_content().index(chr)
                x = self.pos[index][0]
                y = self.pos[index][1]
                dg.__dict__["positions"][chr.fullname] = (x, y)
It does work, but I doubt this is intended per design.

3) Tooltips are not being restored to default when hovered is used over a drag. They just get stuck on whatever the last drag's tt.action is set to instead of going back to default.

4) More serious issue (also hard to describe).

It's a variation of issue 1) but with my game's more complicated code (than the mock-up example), Ren'Py freezes when drags are dragged one after another fast enough. By freezes I mean hangs and becomes completely unresponsive as if has entered an infinite loop. The thing is that it NEVER happens if drags are being dragged one after another at normal speed, game is perfectly stable then. It's just weird to caution players to be careful and not to "play around" with drag/drop system and to use it carefully :D

5) Unrelated to this and to screen language but with the latest version of Ren'Py, cardgame throws this error:
While running game code:
File "game/script.rpy", line 45, in script
python:
File "game/script.rpy", line 47, in <module>
ui.textbutton("Give Up", ui.jumps("giveup"), xalign=.02, yalign=.98)
TypeError: textbutton() takes exactly 1 argument (4 given)

Re: Drag&Drop + Screen Language issue(s):

Posted: Tue Jul 01, 2014 1:19 pm
by Alex
Got not much to say, but for #5 - just replace old-style ui.textbutton with screen containing a button (will work).

Re: Drag&Drop + Screen Language issue(s):

Posted: Tue Jul 01, 2014 1:31 pm
by xela
Alex wrote:Got not much to say, but for #5 - just replace old-style ui.textbutton with screen containing a button (will work).
I know, the point was to make PyTom aware of this so the bug could be fixed in one of the future releases :)