http://www.flickr.com/photos/pcmacgames/6580579419/
the code, though is just standard drag&drop and tooltip, I don't think there's anything strange:
Code: Select all
init python:
# Definitions for the party drag and drop functions.
def dragChar(pDrag, pDrop):
# This is called whenever a Character is dragged somewhere.
# self.listPosition => Tuple, the position in the list for this character.
# self.currentPosition => None or a partyslot.
# self.character => The character object.
if pDrag[0].currentPosition:
# If the character is already occupying a slot remove him from that slot.
pDrag[0].currentPosition.occupied = None
pDrag[0].currentPosition.party.partyPosition[pDrag[0].currentPosition.positionKey] = None
pDrag[0].currentPosition = None
if pDrop and (pDrop.party.partysize() < pDrop.party.partylimit or pDrop.occupied) :
# This is the case if the character is dropped on a partyslot.
if pDrop.occupied:
pDrop.party.partyPosition[pDrop.positionKey] = None
pDrop.occupied.snap(pDrop.occupied.listPosition[0],pDrop.occupied.listPosition[1],0.0)
pDrop.occupied.currentPosition = None
pDrop.occupied = None
pDrag[0].snap(pDrop.x,pDrop.y,0.1)
pDrag[0].currentPosition = pDrop
pDrop.occupied = pDrag[0]
pDrop.party.partyPosition[pDrop.positionKey] = pDrag[0].character
else:
# This is the case when the character is not dropped on a partyslot.
pDrag[0].snap(pDrag[0].listPosition[0],pDrag[0].listPosition[1],0.2)
return
def getCharacters(pParty):
rv = []
runningTotal = 0
listPositions = [(50,80),(50,195),(50,310),(50,425),(175,80),(175,195),(175,310),(175,425),(300,80),(300,195),(300,310),(300,425),(425,80),(425,195),(425,310),(425,425)]
for entry in pParty.available:
tmp = Drag(Image(("gfx/party/p_" + entry.name + ".png")), entry.name, True, False, True, dragChar, xpos=listPositions[runningTotal][0], ypos=listPositions[runningTotal][1])
if entry in pParty.partyPosition.values():
for search in pParty.partyPosition.items():
if search[1] == entry:
tmp.currentPosition = pParty.partySlots[search[0]]
else:
tmp.currentPosition = None
tmp.character = entry
tmp.listPosition = listPositions[runningTotal]
runningTotal += 1
rv.append(tmp)
return rv
init:
screen chooseParty:
default tt = Tooltip(("The current partylimit is: %s\n\nDrag and drop the character portraits to setup your battle formation." % party.partylimit))
zorder 0
frame:
xfill True yfill True
textbutton "Front Row" pos (720, 20) action Return() xcenter .5 style "file_picker_button" hovered tt.Action("Front Row characters are in direct contact with enemies and can be engaged in melee combat. Don't put Mages here!")
textbutton "Back Row" pos (720, 170) action Return() xcenter .5 style "file_picker_button" hovered tt.Action("Back Row characters are protected by First Row characters, and can attack only through magic or missile weapons.")
text tt.value pos (720, 350) outlines [(2,"#1e1a16")] xcenter .5 xmaximum 400 justify True
textbutton "{size=32}Finish{/size}" action Return() pos (630, 460) xminimum 200 yminimum 64
draggroup:
for entry in party.partySlots.values():
add entry
for entry in getCharacters(party):
add entry
if entry.currentPosition:
$ entry.snap(entry.currentPosition.x,entry.currentPosition.y,0)