Poodletooth-iLand/toontown/town/TownBattleToonPanel.py

214 lines
8.9 KiB
Python
Raw Normal View History

from panda3d.core import *
2015-03-03 16:10:12 -06:00
from toontown.toonbase import ToontownGlobals
from toontown.toonbase.ToontownBattleGlobals import *
from direct.directnotify import DirectNotifyGlobal
import string
from toontown.toon import LaffMeter, NPCToons
2015-03-03 16:10:12 -06:00
from toontown.battle import BattleBase
from direct.gui.DirectGui import *
from toontown.toonbase import TTLocalizer
from toontown.toon.NPCFriendPanel import createNPCToonHead
2015-03-03 16:10:12 -06:00
class TownBattleToonPanel(DirectFrame):
notify = DirectNotifyGlobal.directNotify.newCategory('TownBattleToonPanel')
sosTracks = Tracks + NPCTracks
2015-03-03 16:10:12 -06:00
def __init__(self, battle):
2015-03-03 16:10:12 -06:00
gui = loader.loadModel('phase_3.5/models/gui/battle_gui')
DirectFrame.__init__(self, relief=None, image=gui.find('**/ToonBtl_Status_BG'), image_color=Vec4(0.5, 0.9, 0.5, 0.7))
self.setScale(0.8)
self.initialiseoptions(TownBattleToonPanel)
self.battle = battle
2015-03-03 16:10:12 -06:00
self.avatar = None
self.sosText = DirectLabel(parent=self, relief=None, pos=(0.1, 0, 0.015), text=TTLocalizer.TownBattleToonSOS, text_scale=0.06)
self.sosText.hide()
self.fireText = DirectLabel(parent=self, relief=None, pos=(0.1, 0, 0.015), text=TTLocalizer.TownBattleToonFire, text_scale=0.06)
self.fireText.hide()
self.sosHead = None
2015-03-03 16:10:12 -06:00
self.undecidedText = DirectLabel(parent=self, relief=None, pos=(0.1, 0, 0.015), text=TTLocalizer.TownBattleUndecided, text_scale=0.1)
self.healthText = DirectLabel(parent=self, text='', pos=(-0.06, 0, -0.075), text_scale=0.055)
self.hpChangeEvent = None
self.gagNode = self.attachNewNode('gag')
self.gagNode.setPos(0.1, 0, 0.03)
self.hasGag = 0
passGui = gui.find('**/tt_t_gui_bat_pass')
passGui.detachNode()
self.passNode = self.attachNewNode('pass')
self.passNode.setPos(0.1, 0, 0.05)
passGui.setScale(0.2)
passGui.reparentTo(self.passNode)
self.passNode.hide()
self.laffMeter = None
2015-08-27 04:00:22 -05:00
self.whichText = DirectLabel(parent=self, relief=None, text='', pos=(0.1, 0, -0.08), text_scale=0.05)
self.hoverButton = DirectButton(parent=self, relief=None, image_scale=(0.07, 0, 0.06), pos=(0.105, 0, 0.05), image='phase_3/maps/invisible.png', pressEffect=0)
self.hoverButton.setTransparency(True)
2015-08-17 04:42:39 -05:00
self.hoverButton.bind(DGG.EXIT, self.battle.hideRolloverFrame)
2015-03-03 16:10:12 -06:00
self.hide()
gui.removeNode()
2015-08-17 04:42:39 -05:00
def hasAvatar(self):
return self.avatar is not None
2015-03-03 16:10:12 -06:00
def setLaffMeter(self, avatar):
self.notify.debug('setLaffMeter: new avatar %s' % avatar.doId)
2015-03-03 16:10:12 -06:00
if self.avatar == avatar:
messenger.send(self.avatar.uniqueName('hpChange'), [avatar.hp, avatar.maxHp, 1])
return
if self.avatar or self.laffMeter:
self.cleanupLaffMeter()
self.cleanupSosHead()
self.avatar = avatar
self.laffMeter = LaffMeter.LaffMeter(avatar.style, avatar.hp, avatar.maxHp)
self.laffMeter.setAvatar(self.avatar)
self.laffMeter.reparentTo(self)
self.laffMeter.setPos(-0.06, 0, 0.05)
self.laffMeter.setScale(0.045)
self.laffMeter.start()
self.setHealthText(avatar.hp, avatar.maxHp)
self.hpChangeEvent = self.avatar.uniqueName('hpChange')
self.accept(self.hpChangeEvent, self.setHealthText)
2015-03-03 16:10:12 -06:00
def setHealthText(self, hp, maxHp, quietly = 0):
self.healthText['text'] = TTLocalizer.TownBattleHealthText % {'hitPoints': hp,
'maxHit': maxHp}
def show(self):
DirectFrame.show(self)
if self.laffMeter:
self.laffMeter.start()
def hide(self):
DirectFrame.hide(self)
if self.laffMeter:
self.laffMeter.stop()
def updateLaffMeter(self, hp):
if self.laffMeter:
self.laffMeter.adjustFace(hp, self.avatar.maxHp)
self.setHealthText(hp, maxHp)
def setValues(self, index, track, level = None, numTargets = None, targetIndex = None, localNum = None):
self.notify.debug('Toon Panel setValues: index=%s track=%s level=%s numTargets=%s targetIndex=%s localNum=%s' % (index,
track,
level,
numTargets,
targetIndex,
localNum))
self.undecidedText.hide()
self.sosText.hide()
self.fireText.hide()
self.gagNode.hide()
self.whichText.hide()
self.passNode.hide()
self.cleanupSosHead()
self.hoverButton.unbind(DGG.ENTER)
2015-03-03 16:10:12 -06:00
if self.hasGag:
self.gag.removeNode()
self.hasGag = 0
if track == BattleBase.NO_ATTACK or track == BattleBase.UN_ATTACK:
self.undecidedText.show()
elif track == BattleBase.PASS_ATTACK:
self.passNode.show()
elif track == BattleBase.FIRE:
self.fireText.show()
self.whichText.show()
self.whichText['text'] = self.determineWhichText(numTargets, targetIndex, localNum, index)
elif track == BattleBase.NPCSOS:
self.sosHead = createNPCToonHead(targetIndex)
self.sosHead.reparentTo(self)
self.sosHead.setPos(0.1, 0, 0.045)
self.sosHead.setScale(0.24)
track, level, hp, rarity = NPCToons.getNPCTrackLevelHpRarity(targetIndex)
sosType = self.sosTracks[track]
if track == NPC_RESTOCK_GAGS:
if level == -1:
sosType += ' All'
else:
sosType += ' ' + self.sosTracks[level]
if hp:
hpString = TTLocalizer.BattleSOSPopupHP % (TTLocalizer.BattleSOSPopupHeal if track == HEAL_TRACK else TTLocalizer.BattleSOSPopupHarm, hp)
sosType = TextEncoder.upper(sosType)
count = max(0, self.avatar.getNPCFriendCount(targetIndex) - 1)
info = TTLocalizer.BattleSOSPopup % (sosType, NPCToons.getNPCName(targetIndex), hpString if hp else '', rarity, count)
2015-08-27 05:13:37 -05:00
self.hoverButton.bind(DGG.ENTER, self.battle.showRolloverFrame, extraArgs=[self, TTLocalizer.BattleHoverSos, info])
elif track == BattleBase.SOS or track == BattleBase.PETSOS:
2015-03-03 16:10:12 -06:00
self.sosText.show()
elif track >= MIN_TRACK_INDEX and track <= MAX_TRACK_INDEX:
self.undecidedText.hide()
self.passNode.hide()
self.gagNode.show()
invButton = base.localAvatar.inventory.buttonLookup(track, level)
self.gag = invButton.instanceUnderNode(self.gagNode, 'gag')
self.gag.setScale(0.8)
self.gag.setPos(0, 0, 0.02)
self.hasGag = 1
if self.avatar:
curExp, nextExp = self.avatar.inventory.getCurAndNextExpValues(track)
organic = self.avatar.checkGagBonus(track, level)
damage = int(getAvPropDamage(track, level, curExp, organic))
numItems = max(0, self.avatar.inventory.numItem(track, level) - 1)
info = TTLocalizer.BattleGagPopup % (self.avatar.inventory.getToonupDmgStr(track, 0), damage, numItems)
2015-08-27 05:13:37 -05:00
self.hoverButton.bind(DGG.ENTER, self.battle.showRolloverFrame, extraArgs=[self, TTLocalizer.BattleHoverGag, info])
if self.avatar.checkGagBonus(track, level):
self.gag.setColor((1, 0, 0, 1) if track == 1 and level == 5 else (0, 1, 0, 1))
2015-03-03 16:10:12 -06:00
if numTargets is not None and targetIndex is not None and localNum is not None:
self.whichText.show()
self.whichText['text'] = self.determineWhichText(numTargets, targetIndex, localNum, index)
else:
self.notify.error('Bad track value: %s' % track)
def determineWhichText(self, numTargets, targetIndex, localNum, index):
returnStr = ''
targetList = range(numTargets)
targetList.reverse()
2015-03-03 16:10:12 -06:00
for i in targetList:
if targetIndex == -1:
returnStr += 'X'
elif targetIndex == -2:
if i == index:
returnStr += '-'
else:
returnStr += 'X'
elif targetIndex >= 0 and targetIndex <= 3:
if i == targetIndex:
returnStr += 'X'
else:
returnStr += '-'
else:
self.notify.error('Bad target index: %s' % targetIndex)
return returnStr
def cleanup(self):
self.ignoreAll()
self.cleanupLaffMeter()
if self.hasGag:
self.gag.removeNode()
del self.gag
self.gagNode.removeNode()
del self.gagNode
self.hoverButton.removeNode()
del self.hoverButton
self.cleanupSosHead()
2015-03-03 16:10:12 -06:00
DirectFrame.destroy(self)
def cleanupSosHead(self):
if self.sosHead:
self.sosHead.removeNode()
self.sosHead = None
2015-03-03 16:10:12 -06:00
def cleanupLaffMeter(self):
self.ignore(self.hpChangeEvent)
2015-03-03 16:10:12 -06:00
if self.laffMeter:
self.laffMeter.destroy()
self.laffMeter = None