Here is most of a test case of an inventory system. However I can't seem to get rid of this bug where one of the items swaps places with the one that's currently being dragged.
Code: Select all
# You can place the script of your game in this file.
# Declare images below this line, using the image statement.
# eg. image eileen happy = "eileen_happy.png"
# Declare characters used by this game.
define e = Character('Eileen', color="#c8ffc8")
init python:
import inspect
def testDrop(target, sourceDrop):
print "Target: {0}\n Source: {1}".format(target.drag_name, sourceDrop[0].drag_name)
def returnDrop(xPos,yPos):
def innerReturnDrop(sourceDrop, target ):
if target == None:
return None
sourceDrop[0].snap(xPos, yPos, delay=10)
print "Target: {0}\n Source: {1}".format(target.drag_name, sourceDrop[0].drag_name)
renpy.restart_interaction
return innerReturnDrop
def resetIndexLocation(sourceWidget, newList, originalItem, newBoxX, newBoxY):
num = newList.index(originalItem)
xLocation = newBoxX + (num % 2) * (54 + 60)
yLocation = newBoxY + (num // 2) * 54
sourceWidget.snap(xLocation, yLocation)
def giveItem(sourceList, theItem, originalX, originalY):
def innerGiveItem(sourceDrop, target):
global inventory1, inventory2
if target == None:
sourceDrop[0].snap(originalX, originalY)
else:
if target.drag_name == "Inv1":
if sourceList == inventory1:
sourceDrop[0].snap(originalX, originalY)
else:
sourceList.remove(theItem)
inventory1.append(theItem)
#resetIndexLocation(sourceDrop[0],inventory1, theItem, 25, 305)
elif target.drag_name == "Inv2":
if sourceList == inventory2:
sourceDrop[0].snap(originalX, originalY)
else:
sourceList.remove(theItem)
inventory2.append(theItem)
#resetIndexLocation(sourceDrop[0],inventory2, theItem,355, 305)
else:
pass
#sourceDrop[0].snap(originalX, originalY)
renpy.restart_interaction()
return innerGiveItem
transform testTransform:
on show:
alpha 0.0
linear 1.0 alpha 1.0
on hide:
alpha 1.0
linear 1.0 alpha 0.0
screen innerTestScreen(viewId):
side "c r":
viewport id viewId:
has vbox
for i in xrange(1,30):
text "hi {0}".format(i)
vbar:
value YScrollValue(viewId)
screen testScreen:
$ print "inventory1 = {0}".format(inventory1)
$ print "inventory2 = {0}\n".format(inventory2)
textbutton "restart Interaction":
xalign 1.0
yalign 1.0
action Return()
frame:
area (0,0, 200, 200)
at testTransform
use innerTestScreen("viewportA")
frame:
area (250, 0, 450, 200)
at testTransform
use innerTestScreen("viewportB")
draggroup:
drag:
drag_name "Inv1"
child Frame("dark-window-normal.png", 10, 10)
draggable False
xpos 20 ypos 300 xsize 200 ysize 300
drag:
drag_name "Inv2"
child Frame("dark-window-normal.png", 10, 10)
draggable False
xpos 350 ypos 300 xsize 200 ysize 300
$ startX, startY = (25, 305)
for num,i in enumerate(inventory1):
$ xLocation = startX + (num % 2) * (54 + 60)
$ yLocation = startY + (num // 2) * 54
drag id "{0}-{1}".format(num,i):
child Fixed(Image("book.png"), Text("Book {0}".format(i), yalign=0.5, xpos= 1.0, xoffset=4, xsize=40, xanchor=0.0, size=12), xsize=50, ysize=50)
droppable False
dragged giveItem(inventory1, i, xLocation, yLocation)
xpos xLocation ypos yLocation
$ startX, startY = (355, 305)
for num,i in enumerate(inventory2):
$ xLocation = startX + (num % 2) * (54 + 60)
$ yLocation = startY + (num // 2) * 54
drag id "{0}-{1}".format(num,i):
child Fixed(Image("book.png"), Text("Book {0}".format(i), yalign=0.5, xpos= 1.0, xoffset=4, xsize=40, xanchor=0.0, size=12), xsize=50, ysize=50)
droppable False
dragged giveItem(inventory2, i, xLocation, yLocation)
xpos xLocation ypos yLocation
# The game starts here.
label start:
python:
inventory1 = ["a", "c", "d", "m", "fark"]
inventory2 = ["b"]
e "You've created a new Ren'Py game."
call screen testScreen
e "Once you add a story, pictures, and music, you can release it to the world!"
return