Poodletooth-iLand/toontown/toon/NPCFriendPanel.py

219 lines
8.5 KiB
Python
Raw Normal View History

2015-03-03 16:10:12 -06:00
from direct.gui.DirectGui import *
2015-06-01 14:07:59 -05:00
from toontown.toonbase import TTLocalizer, ToontownGlobals, ToontownBattleGlobals
import NPCToons, ToonDNA, ToonHead
2015-03-03 16:10:12 -06:00
def createNPCToonHead(NPCID, dimension = 0.5):
NPCInfo = NPCToons.NPCToonDict[NPCID]
dnaList = NPCInfo[2]
gender = NPCInfo[3]
if dnaList == 'r':
dnaList = NPCToons.getRandomDNA(NPCID, gender)
dna = ToonDNA.ToonDNA()
dna.newToonFromProperties(*dnaList)
head = ToonHead.ToonHead()
head.setupHead(dna, forGui=1)
fitGeometry(head, fFlip=1, dimension=dimension)
return head
def fitGeometry(geom, fFlip = 0, dimension = 0.5):
p1 = Point3()
p2 = Point3()
geom.calcTightBounds(p1, p2)
if fFlip:
t = p1[0]
p1.setX(-p2[0])
p2.setX(-t)
d = p2 - p1
biggest = max(d[0], d[2])
s = dimension / biggest
mid = (p1 + d / 2.0) * s
geomXform = hidden.attachNewNode('geomXform')
for child in geom.getChildren():
child.reparentTo(geomXform)
geomXform.setPosHprScale(-mid[0], -mid[1] + 1, -mid[2], 180, 0, 0, s, s, s)
geomXform.reparentTo(geom)
2015-03-03 16:10:12 -06:00
class NPCFriendPanel(DirectFrame):
2015-06-01 14:07:59 -05:00
def __init__(self, parent = aspect2d, callable = False, **kw):
2015-03-03 16:10:12 -06:00
optiondefs = (('relief', None, None), ('doneEvent', None, None))
self.defineoptions(kw, optiondefs)
DirectFrame.__init__(self, parent=parent)
2015-06-01 14:07:59 -05:00
self.callable = callable
2015-03-03 16:10:12 -06:00
self.cardList = []
2015-06-01 14:07:59 -05:00
self.friendDict = {}
self.pos = 0
2015-03-03 16:10:12 -06:00
self.updateLayout()
self.initialiseoptions(NPCFriendPanel)
2015-06-01 14:07:59 -05:00
gui = loader.loadModel('phase_3.5/models/gui/battle_gui')
buttonImage = (gui.find('**/PckMn_BackBtn'), gui.find('**/PckMn_BackBtn_Dn'), gui.find('**/PckMn_BackBtn_Rlvr'))
self.leftArrow = DirectButton(parent=self, relief=None, image=buttonImage, pos=(-6.8, 0, 0), scale=3.8, command=self.addPageIndex, extraArgs=[-1])
self.rightArrow = DirectButton(parent=self, relief=None, image=buttonImage, pos=(6.8, 0, 0), scale=-3.8, command=self.addPageIndex, extraArgs=[1])
gui.removeNode()
self.leftArrow.hide()
def addPageIndex(self, index):
self.pos += (16 * index)
2015-07-05 18:59:25 -05:00
2015-06-01 14:07:59 -05:00
if self.pos > 0:
self.leftArrow.show()
else:
self.leftArrow.hide()
2015-07-05 18:59:25 -05:00
2015-06-01 14:07:59 -05:00
self.update()
2015-07-05 18:59:25 -05:00
2015-06-01 14:07:59 -05:00
def update(self):
2015-08-12 19:19:58 -05:00
friendList = sorted(self.friendDict.keys(), reverse=True, key=lambda id: NPCToons.getNPCTrackLevelHpRarity(id)[3])
2015-06-01 14:07:59 -05:00
cardNum = 0
2015-07-05 18:59:25 -05:00
2015-06-01 14:07:59 -05:00
for i in xrange(self.pos, self.pos + 16):
card = self.cardList[cardNum]
if len(friendList) > i:
npcId = friendList[i]
card.update(npcId, self.friendDict[npcId], self.callable)
self.rightArrow.show()
else:
card.update(None, 0, self.callable)
self.rightArrow.hide()
cardNum += 1
2015-03-03 16:10:12 -06:00
def updateLayout(self):
for card in self.cardList:
card.destroy()
self.cardList = []
2015-06-01 14:07:59 -05:00
xOffset = -5.2
yOffset = 3.5
2015-03-03 16:10:12 -06:00
count = 0
2015-06-01 14:07:59 -05:00
for i in xrange(16):
card = NPCFriendCard(parent=self, doneEvent=self['doneEvent'])
2015-03-03 16:10:12 -06:00
self.cardList.append(card)
card.setPos(xOffset, 1, yOffset)
card.setScale(0.75)
xOffset += 3.5
count += 1
2015-06-01 14:07:59 -05:00
2015-03-03 16:10:12 -06:00
if count % 4 == 0:
xOffset = -5.25
2015-06-01 14:07:59 -05:00
yOffset += -2.45
2015-03-03 16:10:12 -06:00
2015-06-01 14:07:59 -05:00
def setFriends(self, friends):
self.friendDict = friends
2015-03-03 16:10:12 -06:00
class NPCFriendCard(DirectFrame):
normalTextColor = (0.3, 0.25, 0.2, 1)
maxRarity = 5
sosTracks = ToontownBattleGlobals.Tracks + ToontownBattleGlobals.NPCTracks
2015-06-01 14:07:59 -05:00
def __init__(self, parent = aspect2dp, **kw):
2015-03-03 16:10:12 -06:00
optiondefs = (('NPCID', 'Uninitialized', None), ('relief', None, None), ('doneEvent', None, None))
self.defineoptions(kw, optiondefs)
DirectFrame.__init__(self, parent=parent)
self.initialiseoptions(NPCFriendCard)
cardModel = loader.loadModel('phase_3.5/models/gui/playingCard')
self.front = DirectFrame(parent=self, relief=None, image=cardModel.find('**/card_front'))
self.front.hide()
2015-06-01 14:07:59 -05:00
self.back = DirectFrame(parent=self, relief=None, image=cardModel.find('**/card_back'))
self.sosTypeInfo = DirectLabel(parent=self.front, relief=None, text='', text_font=ToontownGlobals.getMinnieFont(), text_fg=self.normalTextColor, text_scale=0.35, text_align=TextNode.ACenter, text_wordwrap=16.0, pos=(0, 0, 1.15))
2015-03-03 16:10:12 -06:00
self.NPCHead = None
2015-06-01 14:07:59 -05:00
self.NPCName = DirectLabel(parent=self.front, relief=None, text='', text_fg=self.normalTextColor, text_scale=0.4, text_align=TextNode.ACenter, text_wordwrap=8.0, pos=(0, 0, -0.45))
2015-03-03 16:10:12 -06:00
buttonModels = loader.loadModel('phase_3.5/models/gui/inventory_gui')
upButton = buttonModels.find('**/InventoryButtonUp')
downButton = buttonModels.find('**/InventoryButtonDown')
rolloverButton = buttonModels.find('**/InventoryButtonRollover')
self.sosCallButton = DirectButton(parent=self.front, relief=None, text=TTLocalizer.NPCCallButtonLabel, text_fg=self.normalTextColor, text_scale=0.28, text_align=TextNode.ACenter, image=(upButton,
downButton,
rolloverButton,
2015-06-01 14:07:59 -05:00
upButton), image_color=(1.0, 0.2, 0.2, 1), image0_color=Vec4(1.0, 0.4, 0.4, 1), image3_color=Vec4(1.0, 0.4, 0.4, 0.4), image_scale=(4.4, 1, 3.6), image_pos=Vec3(0, 0, 0.08), pos=(-1.15, 0, -0.9), scale=1.25, command=self.__chooseNPCFriend)
2015-03-03 16:10:12 -06:00
self.sosCallButton.hide()
self.sosCountInfo = DirectLabel(parent=self.front, relief=None, text='', text_fg=self.normalTextColor, text_scale=0.75, text_align=TextNode.ALeft, textMayChange=1, pos=(0.0, 0, -1.0))
star = loader.loadModel('phase_3.5/models/gui/name_star')
self.rarityStars = []
2015-06-01 14:07:59 -05:00
2015-03-03 16:10:12 -06:00
for i in xrange(self.maxRarity):
2015-06-01 14:07:59 -05:00
label = DirectLabel(parent=self.front, relief=None, image=star, image_scale=0.2, image_color=Vec4(0.502, 0.251, 0.251, 1.0), pos=(1.1 - i * 0.24, 0, -1.2))
2015-03-03 16:10:12 -06:00
label.hide()
self.rarityStars.append(label)
def __chooseNPCFriend(self):
if self['NPCID'] and self['doneEvent']:
doneStatus = {}
doneStatus['mode'] = 'NPCFriend'
doneStatus['friend'] = self['NPCID']
messenger.send(self['doneEvent'], [doneStatus])
def destroy(self):
if self.NPCHead:
self.NPCHead.detachNode()
self.NPCHead.delete()
2015-06-01 14:07:59 -05:00
2015-03-03 16:10:12 -06:00
DirectFrame.destroy(self)
def update(self, NPCID, count = 0, fCallable = 0):
oldNPCID = self['NPCID']
self['NPCID'] = NPCID
2015-06-01 14:07:59 -05:00
2015-03-03 16:10:12 -06:00
if NPCID != oldNPCID:
if self.NPCHead:
self.NPCHead.detachNode()
self.NPCHead.delete()
if NPCID is None:
self.showBack()
return
2015-06-01 14:07:59 -05:00
2015-03-03 16:10:12 -06:00
self.front.show()
self.back.hide()
self.NPCName['text'] = TTLocalizer.NPCToonNames[NPCID]
self.NPCHead = createNPCToonHead(NPCID, dimension=1.2)
2015-03-03 16:10:12 -06:00
self.NPCHead.reparentTo(self.front)
2015-06-01 14:07:59 -05:00
self.NPCHead.setZ(0.45)
2015-03-03 16:10:12 -06:00
track, level, hp, rarity = NPCToons.getNPCTrackLevelHpRarity(NPCID)
sosText = self.sosTracks[track]
2015-06-01 14:07:59 -05:00
2015-03-03 16:10:12 -06:00
if track == ToontownBattleGlobals.NPC_RESTOCK_GAGS:
if level == -1:
sosText += ' All'
else:
sosText += ' ' + self.sosTracks[level]
sosText = TextEncoder.upper(sosText)
self.sosTypeInfo['text'] = sosText
2015-06-01 14:07:59 -05:00
2015-03-03 16:10:12 -06:00
for i in xrange(self.maxRarity):
if i < rarity:
self.rarityStars[i].show()
else:
self.rarityStars[i].hide()
if fCallable:
self.sosCallButton.show()
2015-06-01 14:07:59 -05:00
self.sosCountInfo.setPos(-0.4, 0, -0.9)
self.sosCountInfo['text_scale'] = 0.4
2015-03-03 16:10:12 -06:00
self.sosCountInfo['text_align'] = TextNode.ALeft
else:
self.sosCallButton.hide()
2015-06-01 14:07:59 -05:00
self.sosCountInfo.setPos(0, 0, -0.9)
self.sosCountInfo['text_scale'] = 0.5
2015-03-03 16:10:12 -06:00
self.sosCountInfo['text_align'] = TextNode.ACenter
if count > 0:
countText = TTLocalizer.NPCFriendPanelRemaining % count
self.sosCallButton['state'] = DGG.NORMAL
else:
countText = TTLocalizer.NPCFriendUnavailable
2015-03-03 16:10:12 -06:00
self.sosCallButton['state'] = DGG.DISABLED
self.sosCountInfo['text'] = countText
return
def showFront(self):
self.front.show()
self.back.hide()
def showBack(self):
self.front.hide()
2015-07-05 18:59:25 -05:00
self.back.show()