Poodletooth-iLand/toontown/town/TownBattleCogPanel.py

230 lines
7.9 KiB
Python
Raw Normal View History

from pandac.PandaModules import *
from toontown.battle import BattleProps
from toontown.toonbase import ToontownGlobals
from toontown.toonbase.ToontownBattleGlobals import *
from direct.directnotify import DirectNotifyGlobal
import string
from toontown.suit import Suit
from direct.gui.DirectGui import *
from pandac.PandaModules import *
from toontown.toonbase import TTLocalizer
from direct.task.Task import Task
class TownBattleCogPanel(DirectFrame):
notify = DirectNotifyGlobal.directNotify.newCategory('TownBattleCogPanel')
healthColors = (Vec4(0, 1, 0, 1),# 0 Green
Vec4(0.5, 1, 0, 1),#1 Green-Yellow
Vec4(0.75, 1, 0, 1),#2 Yellow-Green
Vec4(1, 1, 0, 1),#3 Yellow
Vec4(1, 0.866, 0, 1),#4 Yellow-Orange
Vec4(1, 0.6, 0, 1),#5 Orange-Yellow
Vec4(1, 0.5, 0, 1),#6 Orange
Vec4(1, 0.25, 0, 1.0),#7 Red-Orange
Vec4(1, 0, 0, 1),#8 Red
Vec4(0.3, 0.3, 0.3, 1))#9 Grey
healthGlowColors = (Vec4(0.25, 1, 0.25, 0.5),#Green
Vec4(0.5, 1, 0.25, .5),#1 Green-Yellow
Vec4(0.75, 1, 0.25, .5),#2 Yellow-Green
2015-06-16 00:56:12 +00:00
Vec4(1, 1, 0.25, 0.5),#Yellow
Vec4(1, 0.866, 0.25, .5),#4 Yellow-Orange
Vec4(1, 0.6, 0.25, .5),#5 Orange-Yellow
Vec4(1, 0.5, 0.25, 0.5),#6 Orange
2015-06-16 00:56:12 +00:00
Vec4(1, 0.25, 0.25, 0.5),#7 Red-Orange
Vec4(1, 0.25, 0.25, 0.5),#8 Red
Vec4(0.3, 0.3, 0.3, 0))#9 Grey
2015-06-16 00:56:12 +00:00
def __init__(self, id):
gui = loader.loadModel('phase_3.5/models/gui/battle_gui')
2015-03-30 22:57:42 +00:00
DirectFrame.__init__(self, relief=None, image=gui.find('**/ToonBtl_Status_BG'), image_color=Vec4(0.86, 0.86, 0.86, 0.7))
self.setScale(0.8)
self.initialiseoptions(TownBattleCogPanel)
self.levelText = DirectLabel(parent=self, text='', pos=(-0.06, 0, -0.075), text_scale=0.055)
self.suitType = DirectLabel(parent=self, text='', pos=(0.12, 0, -0.075), text_scale=0.055)
self.healthBar = None
self.healthBarGlow = None
self.hpChangeEvent = None
self.blinkTask = None
self.suit = None
self.head = None
self.maxHP = None
self.currHP = None
self.hpChangeEvent = None
self.generateHealthBar()
self.hide()
gui.removeNode()
return
2015-06-16 00:56:12 +00:00
def setSuit(self, suit):
if self.suit == suit:
messenger.send(self.suit.uniqueName('hpChange'))
return
self.suit = suit
self.setLevelText(self.suit.getActualLevel())
if self.head:
self.head.removeNode()
self.setSuitHead(self.suit.getStyleName())
self.setMaxHp(self.suit.getMaxHP())
self.setHp(self.suit.getHP())
self.hpChangeEvent = self.suit.uniqueName('hpChange')
if self.blinkTask:
taskMgr.remove(self.blinkTask)
self.blinkTask = None
self.accept(self.hpChangeEvent, self.updateHealthBar)
self.updateHealthBar()
self.healthBar.show()
2015-05-06 22:15:07 +00:00
if self.suit.isSkelecog == 1:
self.type = 'Skel'
self.setTypeText(self.type)
self.suitRevives = self.suit.getSkeleRevives()
if self.suitRevives == 1:
self.type = 'v2.0'
self.setTypeText(self.type)
if self.suitRevives < 1 and self.suit.isSkelecog == 0:
self.type = ''
self.setTypeText(self.type)
def getSuit(self, suit):
return self.suit
2015-05-06 22:15:07 +00:00
def setLevelText(self, level):
self.levelText['text'] = 'Level '+ str(level)
def setTypeText(self, suitType):
self.suitType['text'] = suitType
def setSuitHead(self, suitName):
self.head = Suit.attachSuitHead(self, suitName)
self.head.setX(0.1)
self.head.setZ(0.01)
2015-03-30 22:57:42 +00:00
self.head.setScale(0.05)
def generateHealthBar(self):
model = loader.loadModel('phase_3.5/models/gui/matching_game_gui')
button = model.find('**/minnieCircle')
model.removeNode()
button.setScale(0.5)
button.setH(180.0)
button.setColor(self.healthColors[0])
button.reparentTo(self)
2015-03-30 22:57:42 +00:00
button.setX(-0.065)
button.setZ(0.05)
self.healthBar = button
glow = BattleProps.globalPropPool.getProp('glow')
glow.reparentTo(self.healthBar)
glow.setScale(0.28)
glow.setPos(-0.005, 0.01, 0.015)
glow.setColor(self.healthGlowColors[0])
button.flattenLight()
self.healthBarGlow = glow
self.healthBar.hide()
2015-06-16 00:56:12 +00:00
self.healthCondition = 0
def updateHealthBar(self):
if not self.suit:
return
self.setHp(self.suit.getHP())
health = float(self.currHP) / float(self.maxHP)
if health > 0.95:
condition = 0
elif health > 0.9:
condition = 1
elif health > 0.8:
condition = 2
elif health > 0.7:
condition = 3#Yellow
elif health > 0.6:
2015-06-16 00:56:12 +00:00
condition = 4
elif health > 0.5:
2015-06-16 00:56:12 +00:00
condition = 5
elif health > 0.3:
condition = 6#Orange
elif health > 0.15:
condition = 7
elif health > 0.05:
2015-06-16 00:56:12 +00:00
condition = 8#Red
elif health > 0.0:
condition = 9#Blinking Red
else:
condition = 10
if self.healthCondition != condition:
if condition == 9:
2015-06-16 00:56:12 +00:00
self.blinkTask = self.uniqueName('blink-task')
blinkTask = Task.loop(Task(self.__blinkRed), Task.pause(0.75), Task(self.__blinkGray), Task.pause(0.1))
taskMgr.add(blinkTask, self.blinkTask)
elif condition == 10:
if self.healthCondition == 9:
2015-06-16 00:56:12 +00:00
self.blinkTask = self.uniqueName('blink-task')
taskMgr.remove(self.blinkTask)
self.blinkTask = None
blinkTask = Task.loop(Task(self.__blinkRed), Task.pause(0.25), Task(self.__blinkGray), Task.pause(0.1))
taskMgr.add(blinkTask, self.blinkTask)
else:
if self.blinkTask:
taskMgr.remove(self.blinkTask)
self.blinkTask = None
self.healthBar.setColor(self.healthColors[condition], 1)
self.healthBarGlow.setColor(self.healthGlowColors[condition], 1)
self.healthCondition = condition
def __blinkRed(self, task):
if not self.blinkTask or not self.healthBar:
2015-06-16 00:56:12 +00:00
return Task.done
self.healthBar.setColor(self.healthColors[8], 1)
self.healthBarGlow.setColor(self.healthGlowColors[8], 1)
if self.healthCondition == 7:
self.healthBar.setScale(1.17)
return Task.done
def __blinkGray(self, task):
if not self.blinkTask or not self.healthBar:
return Task.done
self.healthBar.setColor(self.healthColors[9], 1)
self.healthBarGlow.setColor(self.healthGlowColors[9], 1)
if self.healthCondition == 10:
self.healthBar.setScale(1.0)
return Task.done
def removeHealthBar(self):
if self.healthCondition == 9 or self.healthCondition == 10:
if self.blinkTask:
taskMgr.remove(self.blinkTask)
2015-06-16 00:56:12 +00:00
self.blinkTask = None
if self.healthBar:
self.healthBar.removeNode()
self.healthBar = None
self.healthCondition = 0
return
2015-06-16 00:56:12 +00:00
def getDisplayedCurrHp(self):
return self.currHP
2015-06-16 00:56:12 +00:00
def getDisplayedMaxHp(self):
2015-06-16 00:56:12 +00:00
return self.maxHP
def setMaxHp(self, hp):
self.maxHP = hp
def setHp(self, hp):
self.currHP = hp
def show(self):
DirectFrame.show(self)
2015-06-16 00:56:12 +00:00
def cleanup(self):
self.ignoreAll()
self.removeHealthBar()
if self.head is not None:
self.head.removeNode()
del self.head
self.levelText.destroy()
del self.levelText
2015-05-06 22:15:07 +00:00
del self.suitType
del self.healthBar
if self.healthBarGlow is not None:
self.healthBarGlow.removeNode()
del self.healthBarGlow
del self.suit
del self.maxHP
del self.currHP
DirectFrame.destroy(self)