Inventory system and making drag and drop work :(

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
User avatar
lil steffi
Newbie
Posts: 7
Joined: Sun Oct 07, 2018 1:12 pm
Contact:

Inventory system and making drag and drop work :(

#1 Post by lil steffi » Sun Oct 07, 2018 1:37 pm

Hi all,

I'm very new to ren'py and don't know any python, so I've been having a really hard time figuring out how to create the inventory system I want. I found Leon's awesome inventory system, and got that to work somewhat but it was lacking the one thing that I really wanted it to do, which was allow the user to drag items out onto hotspots and discard them from the inventory. Because I was having a lot of trouble trying to incorporate this drag and drop system into Leon's system, I pulled back the idea a bit to just be clicking and dragging a word from the inventory onto something else on the screen.

Let's say that I want to just drag the word "Shoe Laces" onto the drawer in the scene (I know it doesn't make sense, but just for example). How would I do this?

here's the relevant code:

Code: Select all

init python:   
    showitems = True
   
    def display_items_overlay():
        if showitems:
            inventory_show = "Inventory: "
            for i in range(0, len(items)):
                item_name = items[i].title()
                if i > 0:
                    inventory_show += ", "
                inventory_show += item_name
            ui.frame()
            ui.text(inventory_show)
    config.overlay_functions.append(display_items_overlay)

# Inventory and such.
default items = []
default flower = False
default keys = False
default diary = False
default laces = False

#image map

screen dianasroomclickable:
    imagemap:
        ground "diana roomwindowclosed.png"
        idle "diana roomidle.png"
        hover "diana roomhover.png"
        
        alpha False
        # This is so that everything transparent is invisible to the cursor. 
       
        hotspot (730, 53, 325, 287) clicked Jump("openwindow")
        hotspot (539, 249, 71, 71) clicked Jump("phone")
        hotspot (821, 340, 110, 100) clicked Jump("turntable")
        hotspot (497, 317, 122, 134) clicked Jump("drawer")
        hotspot (408, 406, 91, 63) clicked Jump("shoes")
        hotspot (254, 419, 68, 61) clicked Jump("hat")
        hotspot (10, 141, 405, 263) clicked Jump("bed")
        hotspot (1120, 246, 81, 84) clicked Jump("dianasdoor")
        hotspot (650, 435, 463, 119) clicked Jump("rug")
        hotspot (493, 66, 97, 174) clicked Jump("cure")
    
label start:

label dianasroommap:
    call screen dianasroomclickable
    
label openwindow:
scene dianas roomstill
menu:
    "Eavesdrop on Van Leiu and police" if tell == "snitch" and eavesdropped == False:
        $ tattle = True
        jump listen
    "Sneak out" if eavesdropped == True:
        jump whichway
    "Sneak out" if tell == "cover":
        jump whichway
    "Leave window closed":
        "I'll just leave this closed for now..."
        jump dianasroommap
        
label turntable:
scene dianas roomstill
menu:
    "Play a record":
        "Doesn't seem to be working right now..."
        jump dianasroommap
    "Nevermind":
        "I'll just leave this here for now..."
        jump dianasroommap
        
label drawer:
scene dianas roomstill
menu:
    "Open Karen's Drawer":
        "Damn it, it's stuck!"
        jump dianasroommap
    "Nevermind":
        "I should probably not go through her things anyway..."
        jump dianasroommap
        
label shoes:
scene dianas roomstill
menu:
    "Smell your chucks" if laces == False:
        "WOW. Pungent."
        jump laces
    "Nevermind":
        "I'll just leave this here for now..."
        jump dianasroommap
    "Smell your chucks" if laces == True:
        "WOW. Pungent."
        jump dianasroommap
label laces:
scene dianas roomstill
menu:
    "Take the shoelaces":
        $ laces = True
        $ items.append("Shoe Laces")
        d "Who knows when a shoe lace could come in handy!"
        jump dianasroommap
    "Nevermind":
        "I'll just leave this here for now..."
        jump dianasroommap
    
label phone:
scene dianas roomstill
menu:
    "Call someone":
        "no one to call for now"
        jump dianasroommap
    "Nevermind":
        "I'll just leave this here for now..."
        jump dianasroommap
        
label hat:
scene dianas roomstill
menu:
    "Look at hat":
        "Eat em' up cats!"
        jump dianasroommap
    "Nevermind":
        "I'll just leave this here for now..."
        jump dianasroommap
        
label bed:
scene dianas roomstill
menu:
    "Sleep":
        "I don't really feel like sleeping just yet..."
        jump dianasroommap
    "Nevermind":
        "I'll just leave this here for now..."
        jump dianasroommap
        
label dianasdoor:
scene dianas roomstill
menu:
    "Go out into the hall":
        "Maybe I should just check and see if Mary's home yet."
        jump hallwayMap
    "Nevermind":
        "I'll just leave this here for now..."
        jump dianasroommap
        
label rug:
scene dianas roomstill
menu:
    "Move rug":
        "There's nothing under here"
        jump dianasroommap
    "Nevermind":
        "I'll just leave this here for now..."
        jump dianasroommap
        
label cure:
scene dianas roomstill
menu:
    "Admire Robert Smith":
        "Wonder if the carpet matches the drapes?"
        jump dianasroommap
    "Nevermind":
        "I'll just leave this here for now..."
        jump dianasroommap
Image

User avatar
Per K Grok
Regular
Posts: 155
Joined: Fri May 18, 2018 1:02 am
Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls
Projects: Defenders of Adacan
Deviantart: pekj
itch: per-k-grok
Location: Sverige
Contact:

Re: Inventory system and making drag and drop work :(

#2 Post by Per K Grok » Sun Oct 07, 2018 4:17 pm

lil steffi wrote:
Sun Oct 07, 2018 1:37 pm
Hi all,

I'm very new to ren'py and don't know any python, so I've been having a really hard time figuring out how to create the inventory system I want. I found Leon's awesome inventory system, and got that to work somewhat but it was lacking the one thing that I really wanted it to do, which was allow the user to drag items out onto hotspots and discard them from the inventory. Because I was having a lot of trouble trying to incorporate this drag and drop system into Leon's system, I pulled back the idea a bit to just be clicking and dragging a word from the inventory onto something else on the screen.

Let's say that I want to just drag the word "Shoe Laces" onto the drawer in the scene (I know it doesn't make sense, but just for example). How would I do this?

----
One thing you could do to give the appearance of dragging an item from the inventory is to have different images for the mouse cursor and shifting which image you use if an item is to be 'dragged' or not.

you can set the mouse cursor image like this

$ setattr(config, "mouse", {"default": [("items2Pointer.png", 0, 0)]})
Image Visual Story Telling, DeviantArt Group for animations, comics, games and illustrations https://www.deviantart.com/acgi

User avatar
lil steffi
Newbie
Posts: 7
Joined: Sun Oct 07, 2018 1:12 pm
Contact:

Re: Inventory system and making drag and drop work :(

#3 Post by lil steffi » Sun Oct 07, 2018 6:57 pm

I'm not sure I understand what you mean by that...

basically I just want to drag the word that was appended to the list onto another "drag"? I think?

philat
Eileen-Class Veteran
Posts: 1439
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Inventory system and making drag and drop work :(

#4 Post by philat » Mon Oct 08, 2018 6:07 am

Suuuuuuuuuper basic example. Build up as needed.

Code: Select all

label start:
    call screen inventory
    jump start

label laces_drawer:
    "Dragged laces to drawer."
    jump start

label flower_door:
    "Dragged flower to door."
    jump start

init python:
    def drag_item(drags, drop):
        if not drop:
            return

        drag_name = drags[0].drag_name        
        drop_name = drop.drag_name

        if drag_name == "laces" and drop_name == "drawer":
            renpy.jump("laces_drawer")
        elif drag_name == "flower" and drop_name == "door":
            renpy.jump("flower_door")

        return


default items = ["flower", "keys", "laces"]

screen inventory():
    $ temp_x = 100

    draggroup:

        for i in items:
            $ temp_x += 150
            drag:
                drag_name i
                child Text(i)
                xpos temp_x
                ypos 50
                dragged drag_item
                draggable True

        drag:
            drag_name "drawer"
            child Text("drawer") # try Solid("#0006", xysize=(50,50)) to test for size, Solid("#0000") for a transparent drag. What you'd do is position the drag over the imagemap
            xpos 600
            ypos 600
            draggable False

        drag:
            drag_name "door"
            child Text("door")
            xpos 200
            ypos 200
            draggable False

User avatar
Per K Grok
Regular
Posts: 155
Joined: Fri May 18, 2018 1:02 am
Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls
Projects: Defenders of Adacan
Deviantart: pekj
itch: per-k-grok
Location: Sverige
Contact:

Re: Inventory system and making drag and drop work :(

#5 Post by Per K Grok » Mon Oct 08, 2018 12:19 pm

lil steffi wrote:
Sun Oct 07, 2018 6:57 pm
I'm not sure I understand what you mean by that...

basically I just want to drag the word that was appended to the list onto another "drag"? I think?

My suggestion is more aimed at your plan A (dragging an item) than at your plan B (dragging a text string).

It is a different approach from what philat is showing in his post.

For my suggestion you need three images

1) the icon for the item
2) your ordinary mouse cursor
3) your cursor and a representation of the item in the same image


With your ordinary cursor (2) you move to the icon (1) in the inventory and click on it. The cursor should now change to (3). You could at the same time remove (1) from the inventory if that fits with what you want to do.

You move the cursor to the hotspot and click there. If that represents leaving the item at the hotspot or that the item is used up with this action, the cursor image should be switched back to (2).

With this model you are not actually dragging anything, just giving the illusion of doing it.
Image Visual Story Telling, DeviantArt Group for animations, comics, games and illustrations https://www.deviantart.com/acgi

User avatar
lil steffi
Newbie
Posts: 7
Joined: Sun Oct 07, 2018 1:12 pm
Contact:

Re: Inventory system and making drag and drop work :(

#6 Post by lil steffi » Mon Oct 08, 2018 9:20 pm

Thanks so much!!! I'm gonna try this approach right now

philat wrote:
Mon Oct 08, 2018 6:07 am
Suuuuuuuuuper basic example. Build up as needed.

Code: Select all

label start:
    call screen inventory
    jump start

label laces_drawer:
    "Dragged laces to drawer."
    jump start

label flower_door:
    "Dragged flower to door."
    jump start

init python:
    def drag_item(drags, drop):
        if not drop:
            return

        drag_name = drags[0].drag_name        
        drop_name = drop.drag_name

        if drag_name == "laces" and drop_name == "drawer":
            renpy.jump("laces_drawer")
        elif drag_name == "flower" and drop_name == "door":
            renpy.jump("flower_door")

        return


default items = ["flower", "keys", "laces"]

screen inventory():
    $ temp_x = 100

    draggroup:

        for i in items:
            $ temp_x += 150
            drag:
                drag_name i
                child Text(i)
                xpos temp_x
                ypos 50
                dragged drag_item
                draggable True

        drag:
            drag_name "drawer"
            child Text("drawer") # try Solid("#0006", xysize=(50,50)) to test for size, Solid("#0000") for a transparent drag. What you'd do is position the drag over the imagemap
            xpos 600
            ypos 600
            draggable False

        drag:
            drag_name "door"
            child Text("door")
            xpos 200
            ypos 200
            draggable False

Post Reply

Who is online

Users browsing this forum: Dinocanid