Poodletooth-iLand/toontown/town/TownBattleCogPanel.py

94 lines
3.7 KiB
Python
Raw Normal View History

from direct.gui.DirectGui import *
2015-08-17 04:42:39 -05:00
from toontown.battle import SuitBattleGlobals
2015-08-09 06:32:13 -05:00
from toontown.suit import Suit, SuitHealthBar
from toontown.toonbase import TTLocalizer
class TownBattleCogPanel(DirectFrame):
2015-07-05 18:59:25 -05:00
2015-08-17 04:42:39 -05:00
def __init__(self, battle):
gui = loader.loadModel('phase_3.5/models/gui/battle_gui')
2015-08-09 06:32:13 -05:00
DirectFrame.__init__(self, relief=None, image=gui.find('**/ToonBtl_Status_BG'), image_color=(0.86, 0.86, 0.86, 0.7), scale=0.8)
self.initialiseoptions(TownBattleCogPanel)
2015-08-17 04:42:39 -05:00
self.battle = battle
self.levelText = DirectLabel(parent=self, text='', pos=(-0.06, 0, -0.075), text_scale=0.055)
2015-08-09 06:32:13 -05:00
self.typeText = DirectLabel(parent=self, text='', pos=(0.12, 0, -0.075), text_scale=0.045)
self.healthBar = SuitHealthBar.SuitHealthBar()
self.generateHealthBar()
2015-08-17 04:42:39 -05:00
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)
self.hoverButton.bind(DGG.EXIT, self.battle.hideRolloverFrame)
2015-08-09 06:32:13 -05:00
self.suit = None
self.suitHead = None
self.hide()
gui.removeNode()
2015-08-09 06:32:13 -05:00
def cleanup(self):
self.cleanupHead()
self.levelText.removeNode()
self.typeText.removeNode()
self.healthBar.delete()
2015-08-17 04:42:39 -05:00
self.hoverButton.removeNode()
2015-08-09 06:32:13 -05:00
del self.levelText
del self.typeText
del self.healthBar
2015-08-17 04:42:39 -05:00
del self.hoverButton
2015-08-09 06:32:13 -05:00
DirectFrame.destroy(self)
def cleanupHead(self):
if self.suitHead:
self.suitHead.removeNode()
del self.suitHead
2015-07-05 18:59:25 -05:00
def setSuit(self, suit):
if self.suit == suit:
return
2015-08-09 06:32:13 -05:00
self.cleanupHead()
self.suit = suit
2015-08-09 06:32:13 -05:00
self.generateSuitHead(suit.getStyleName())
self.updateHealthBar()
2015-08-09 06:32:13 -05:00
self.levelText['text'] = TTLocalizer.CogPanelLevel % suit.getActualLevel()
self.typeText['text'] = suit.getTypeText()
2015-08-17 04:42:39 -05:00
self.updateRolloverBind()
def updateRolloverBind(self):
if not self.suit:
return
attributes = SuitBattleGlobals.SuitAttributes[self.suit.getStyleName()]
groupAttacks, singleAttacks = SuitBattleGlobals.getAttacksByType(attributes)
level = self.suit.getLevel()
info = TTLocalizer.BattleCogPopup % (self.getAttackStrings(groupAttacks, level), self.getAttackStrings(singleAttacks, level))
if TTLocalizer.BattleCogPopupDangerColor in info:
info = TTLocalizer.BattleCogPopupDanger + info
2015-08-27 05:13:37 -05:00
self.hoverButton.bind(DGG.ENTER, self.battle.showRolloverFrame, extraArgs=[self, TTLocalizer.BattleHoverCog, info])
2015-08-17 04:42:39 -05:00
def getAttackStrings(self, attacks, level):
attackStrings = []
for attack in attacks:
hp = attack[1][level]
attackString = TTLocalizer.BattleCogPopupAttackDanger if self.battle.isAttackDangerous(hp) else TTLocalizer.BattleCogPopupAttack
attackStrings.append(attackString % (TTLocalizer.SuitAttackNames[attack[0]], hp))
return '\n'.join(attackStrings) if attackStrings else TTLocalizer.SuitPageNoAttacks
2015-08-09 06:32:13 -05:00
def generateSuitHead(self, name):
self.suitHead = Suit.attachSuitHead(self, name)
self.suitHead.setScale(0.05)
self.suitHead.setPos(0.1, 0, 0.01)
def generateHealthBar(self):
2015-08-09 06:32:13 -05:00
self.healthBar.generate()
self.healthBar.geom.reparentTo(self)
self.healthBar.geom.setScale(0.5)
self.healthBar.geom.setPos(-0.065, 0, 0.05)
self.healthBar.geom.show()
def updateHealthBar(self):
if not self.suit:
return
2015-08-09 06:32:13 -05:00
self.healthBar.update(float(self.suit.getHP()) / float(self.suit.getMaxHP()))