Refactor suit health bar

This commit is contained in:
John 2015-08-09 15:23:35 +03:00
parent 7019d1ba9a
commit 1d8fe20587
6 changed files with 66 additions and 266 deletions

View file

@ -200,7 +200,7 @@ def removeReviveSuit(suit, deathSuit):
if not deathSuit.isEmpty(): if not deathSuit.isEmpty():
deathSuit.detachNode() deathSuit.detachNode()
suit.cleanupLoseActor() suit.cleanupLoseActor()
suit.healthBar.show() suit.healthBar.geom.show()
suit.resetHealthBarForSkele() suit.resetHealthBarForSkele()

View file

@ -1,23 +1,16 @@
from panda3d.core import *
from direct.actor import Actor from direct.actor import Actor
from direct.directnotify import DirectNotifyGlobal from direct.directnotify import DirectNotifyGlobal
from direct.fsm import FSM from direct.fsm import FSM
from direct.fsm import State
from direct.interval.IntervalGlobal import * from direct.interval.IntervalGlobal import *
from direct.showbase.PythonUtil import Functor
from direct.task.Task import Task from direct.task.Task import Task
from panda3d.core import *
import types
import random
import Suit
import SuitDNA
from otp.avatar import Avatar from otp.avatar import Avatar
from toontown.battle import BattleParticles
from toontown.battle import BattleProps
from otp.nametag.NametagGroup import NametagGroup from otp.nametag.NametagGroup import NametagGroup
from otp.nametag.NametagConstants import * from otp.nametag.NametagConstants import *
from toontown.toonbase import TTLocalizer from toontown.battle import BattleParticles, BattleProps
from toontown.toonbase import ToontownGlobals from toontown.toonbase import TTLocalizer, ToontownGlobals
import Suit, SuitDNA, SuitHealthBar
import types, random
GenericModel = 'phase_9/models/char/bossCog' GenericModel = 'phase_9/models/char/bossCog'
ModelDict = {'s': 'phase_9/models/char/sellbotBoss', ModelDict = {'s': 'phase_9/models/char/sellbotBoss',
@ -28,8 +21,6 @@ AnimList = ('Ff_speech', 'ltTurn2Wave', 'wave', 'Ff_lookRt', 'turn2Fb', 'Ff_neut
class BossCog(Avatar.Avatar): class BossCog(Avatar.Avatar):
notify = DirectNotifyGlobal.directNotify.newCategory('BossCog') notify = DirectNotifyGlobal.directNotify.newCategory('BossCog')
healthColors = Suit.Suit.healthColors
healthGlowColors = Suit.Suit.healthGlowColors
def __init__(self): def __init__(self):
Avatar.Avatar.__init__(self) Avatar.Avatar.__init__(self)
@ -52,15 +43,14 @@ class BossCog(Avatar.Avatar):
self.queuedAnimIvals = [] self.queuedAnimIvals = []
self.treadsLeftPos = 0 self.treadsLeftPos = 0
self.treadsRightPos = 0 self.treadsRightPos = 0
self.healthBar = None self.healthBar = SuitHealthBar.SuitHealthBar()
self.healthCondition = 0
self.animDoneEvent = 'BossCogAnimDone' self.animDoneEvent = 'BossCogAnimDone'
self.animIvalName = 'BossCogAnimIval' self.animIvalName = 'BossCogAnimIval'
self.warningSfx = loader.loadSfx('phase_9/audio/sfx/CHQ_GOON_tractor_beam_alarmed.ogg') self.warningSfx = loader.loadSfx('phase_9/audio/sfx/CHQ_GOON_tractor_beam_alarmed.ogg')
def delete(self): def delete(self):
Avatar.Avatar.delete(self) Avatar.Avatar.delete(self)
self.removeHealthBar() self.healthBar.delete()
self.setDizzy(0) self.setDizzy(0)
self.stopAnimate() self.stopAnimate()
if self.doorA: if self.doorA:
@ -155,92 +145,17 @@ class BossCog(Avatar.Avatar):
self.collNode.setCollideMask(self.collNode.getIntoCollideMask() | ToontownGlobals.PieBitmask) self.collNode.setCollideMask(self.collNode.getIntoCollideMask() | ToontownGlobals.PieBitmask)
def generateHealthBar(self): def generateHealthBar(self):
self.removeHealthBar() self.healthBar.generate()
chestNull = self.find('**/joint_lifeMeter') self.healthBar.geom.reparentTo(self.find('**/joint_lifeMeter'))
if chestNull.isEmpty(): self.healthBar.geom.setScale(6.0)
return self.healthBar.geom.setHpr(0, -20, 0)
model = loader.loadModel('phase_3.5/models/gui/matching_game_gui') self.healthBar.geom.show()
button = model.find('**/minnieCircle')
button.setScale(6.0)
button.setP(-20)
button.setColor(self.healthColors[0])
button.reparentTo(chestNull)
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.healthCondition = 0
def updateHealthBar(self): def updateHealthBar(self):
if self.healthBar == None:
return
health = 1.0 - float(self.bossDamage) / float(self.bossMaxDamage)
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:
condition = 4
elif health > 0.5:
condition = 5
elif health > 0.3:
condition = 6#Orange
elif health > 0.15:
condition = 7
elif health > 0.05:
condition = 8#Red
elif health > 0.0:
condition = 9#Blinking Red
else:
condition = 10
if self.healthCondition != condition:
if condition == 9:
blinkTask = Task.loop(Task(self.__blinkRed), Task.pause(0.75), Task(self.__blinkGray), Task.pause(0.1))
taskMgr.add(blinkTask, self.uniqueName('blink-task'))
elif condition == 10:
if self.healthCondition == 9:
taskMgr.remove(self.uniqueName('blink-task'))
blinkTask = Task.loop(Task(self.__blinkRed), Task.pause(0.25), Task(self.__blinkGray), Task.pause(0.1))
taskMgr.add(blinkTask, self.uniqueName('blink-task'))
else:
self.healthBar.setColor(self.healthColors[condition], 1)
self.healthBarGlow.setColor(self.healthGlowColors[condition], 1)
self.healthCondition = condition
def __blinkRed(self, task):
if not self.healthBar: if not self.healthBar:
return return
self.healthBar.setColor(self.healthColors[8], 1)
self.healthBarGlow.setColor(self.healthGlowColors[8], 1)
if self.healthCondition == 10:
self.healthBar.setScale(1.17)
return Task.done
def __blinkGray(self, task): self.healthBar.update(1.0 - float(self.bossDamage) / float(self.bossMaxDamage))
if not self.healthBar:
return
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.healthBar:
self.healthBar.removeNode()
self.healthBar = None
if self.healthCondition == 9 or self.healthCondition == 10:
taskMgr.remove(self.uniqueName('blink-task'))
self.healthCondition = 0
return
def reverseHead(self): def reverseHead(self):
self.neck.setHpr(self.neckReversedHpr) self.neck.setHpr(self.neckReversedHpr)

View file

@ -784,7 +784,7 @@ class DistributedCashbotBoss(DistributedBossCog.DistributedBossCog, FSM.FSM):
self.stopAnimate() self.stopAnimate()
self.cleanupAttacks() self.cleanupAttacks()
self.setDizzy(0) self.setDizzy(0)
self.removeHealthBar() self.healthBar.delete()
localAvatar.setCameraFov(ToontownGlobals.CogHQCameraFov) localAvatar.setCameraFov(ToontownGlobals.CogHQCameraFov)
if self.newState != 'Victory': if self.newState != 'Victory':
self.battleThreeMusic.stop() self.battleThreeMusic.stop()

View file

@ -326,12 +326,12 @@ class DistributedSuitBase(DistributedAvatar.DistributedAvatar, Suit.Suit, SuitBa
self.loop('neutral', 0) self.loop('neutral', 0)
self.disableBattleDetect() self.disableBattleDetect()
self.corpMedallion.hide() self.corpMedallion.hide()
self.healthBar.show() self.healthBar.geom.show()
if self.currHP < self.maxHP: if self.currHP < self.maxHP:
self.updateHealthBar(0, 1) self.updateHealthBar(0, 1)
def exitBattle(self): def exitBattle(self):
self.healthBar.hide() self.healthBar.geom.hide()
self.corpMedallion.show() self.corpMedallion.show()
self.currHP = self.maxHP self.currHP = self.maxHP
self.interactivePropTrackBonus = -1 self.interactivePropTrackBonus = -1

View file

@ -2,11 +2,11 @@ from panda3d.core import *
from direct.actor import Actor from direct.actor import Actor
from direct.task.Task import Task from direct.task.Task import Task
from otp.avatar import Avatar from otp.avatar import Avatar
from toontown.battle import BattleProps, SuitBattleGlobals from toontown.battle import SuitBattleGlobals
from otp.nametag.NametagGroup import NametagGroup from otp.nametag.NametagGroup import NametagGroup
from toontown.toonbase import TTLocalizer, ToontownGlobals from toontown.toonbase import TTLocalizer, ToontownGlobals
from toontown.suit import SuitGlobals from toontown.suit import SuitGlobals
import SuitDNA, string import SuitDNA, SuitHealthBar, string
aSize = 6.06 aSize = 6.06
bSize = 5.29 bSize = 5.29
@ -299,26 +299,6 @@ def attachSuitHead(node, suitName):
class Suit(Avatar.Avatar): class Suit(Avatar.Avatar):
__module__ = __name__ __module__ = __name__
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
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
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
medallionColors = {'c': Vec4(0.863, 0.776, 0.769, 1.0), medallionColors = {'c': Vec4(0.863, 0.776, 0.769, 1.0),
's': Vec4(0.843, 0.745, 0.745, 1.0), 's': Vec4(0.843, 0.745, 0.745, 1.0),
'l': Vec4(0.749, 0.776, 0.824, 1.0), 'l': Vec4(0.749, 0.776, 0.824, 1.0),
@ -341,8 +321,7 @@ class Suit(Avatar.Avatar):
self.shadowJoint = None self.shadowJoint = None
self.nametagJoint = None self.nametagJoint = None
self.headParts = [] self.headParts = []
self.healthBar = None self.healthBar = SuitHealthBar.SuitHealthBar()
self.healthCondition = 0
self.isDisguised = 0 self.isDisguised = 0
self.isWaiter = 0 self.isWaiter = 0
self.isRental = 0 self.isRental = 0
@ -368,7 +347,7 @@ class Suit(Avatar.Avatar):
part.removeNode() part.removeNode()
self.headParts = [] self.headParts = []
self.removeHealthBar() self.healthBar.delete()
Avatar.Avatar.delete(self) Avatar.Avatar.delete(self)
def setHeight(self, height): def setHeight(self, height):
@ -585,97 +564,18 @@ class Suit(Avatar.Avatar):
icons.removeNode() icons.removeNode()
def generateHealthBar(self): def generateHealthBar(self):
self.removeHealthBar() self.healthBar.generate()
model = loader.loadModel('phase_3.5/models/gui/matching_game_gui') self.healthBar.geom.reparentTo(self.find('**/joint_attachMeter'))
button = model.find('**/minnieCircle') self.healthBar.geom.setScale(3.0)
model.removeNode()
button.setScale(3.0)
button.setH(180.0)
button.setColor(self.healthColors[0])
chestNull = self.find('**/joint_attachMeter')
button.reparentTo(chestNull)
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()
self.healthCondition = 0
def resetHealthBarForSkele(self): def resetHealthBarForSkele(self):
self.healthBar.setPos(0.0, 0.1, 0.0) self.healthBar.geom.setPos(0.0, 0.1, 0.0)
def updateHealthBar(self, hp, forceUpdate = 0): def updateHealthBar(self, hp, forceUpdate = 0):
if hp > self.currHP: if hp > self.currHP:
hp = self.currHP hp = self.currHP
self.currHP -= hp self.currHP -= hp
health = float(self.currHP) / float(self.maxHP) self.healthBar.update(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:
condition = 4
elif health > 0.5:
condition = 5
elif health > 0.3:
condition = 6#Orange
elif health > 0.15:
condition = 7
elif health > 0.05:
condition = 8#Red
elif health > 0.0:
condition = 9#Blinking Red
else:
condition = 10
if self.healthCondition != condition or forceUpdate:
if condition == 9:
blinkTask = Task.loop(Task(self.__blinkRed), Task.pause(0.75), Task(self.__blinkGray), Task.pause(0.1))
taskMgr.add(blinkTask, self.uniqueName('blink-task'))
elif condition == 10:
if self.healthCondition == 9:
taskMgr.remove(self.uniqueName('blink-task'))
blinkTask = Task.loop(Task(self.__blinkRed), Task.pause(0.25), Task(self.__blinkGray), Task.pause(0.1))
taskMgr.add(blinkTask, self.uniqueName('blink-task'))
else:
self.healthBar.setColor(self.healthColors[condition], 1)
self.healthBarGlow.setColor(self.healthGlowColors[condition], 1)
self.healthCondition = condition
def __blinkRed(self, task):
if not self.healthBar:
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.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.healthBar:
self.healthBar.removeNode()
self.healthBar = None
if self.healthCondition == 9 or self.healthCondition == 10:
taskMgr.remove(self.uniqueName('blink-task'))
self.healthCondition = 0
return
def getLoseActor(self): def getLoseActor(self):
if self.loseActor == None: if self.loseActor == None:

View file

@ -1,8 +1,8 @@
from direct.task import Task from direct.task.Task import Task
from toontown.battle import BattleProps from toontown.battle import BattleProps
class SuitHealthBar: HEALTH_COLORS = (
healthColors = ((0, 1, 0, 1), (0, 1, 0, 1),
(0.5, 1, 0, 1), (0.5, 1, 0, 1),
(0.75, 1, 0, 1), (0.75, 1, 0, 1),
(1, 1, 0, 1), (1, 1, 0, 1),
@ -11,8 +11,10 @@ class SuitHealthBar:
(1, 0.5, 0, 1), (1, 0.5, 0, 1),
(1, 0.25, 0, 1.0), (1, 0.25, 0, 1.0),
(1, 0, 0, 1), (1, 0, 0, 1),
(0.3, 0.3, 0.3, 1)) (0.3, 0.3, 0.3, 1)
healthGlowColors = ((0.25, 1, 0.25, 0.5), )
HEALTH_GLOW_COLORS = (
(0.25, 1, 0.25, 0.5),
(0.5, 1, 0.25, .5), (0.5, 1, 0.25, .5),
(0.75, 1, 0.25, .5), (0.75, 1, 0.25, .5),
(1, 1, 0.25, 0.5), (1, 1, 0.25, 0.5),
@ -23,44 +25,41 @@ class SuitHealthBar:
(1, 0.25, 0.25, 0.5), (1, 0.25, 0.25, 0.5),
(0.3, 0.3, 0.3, 0)) (0.3, 0.3, 0.3, 0))
class SuitHealthBar:
def __init__(self): def __init__(self):
print 'New Healthbar'
self.geom = None self.geom = None
self.geomGlow = None self.geomGlow = None
self.healthCondition = 0 self.healthCondition = 0
def delete(self): def delete(self):
print 'Deleting'
if self.geom: if self.geom:
self.geom.removeNode() self.geom.removeNode()
self.geom = None self.geom = None
self.geomGlow = None self.geomGlow = None
taskMgr.remove('blink-task-%s' % id(self)) taskMgr.remove('blink-task-%s' % id(self))
self.healthCondition = 0 self.healthCondition = 0
print 'Deleted'
def generate(self): def generate(self):
print 'Generating'
self.delete() self.delete()
model = loader.loadModel('phase_3.5/models/gui/matching_game_gui') model = loader.loadModel('phase_3.5/models/gui/matching_game_gui')
button = model.find('**/minnieCircle') button = model.find('**/minnieCircle')
model.removeNode() model.removeNode()
button.setH(180.0) button.setH(180.0)
button.setColor(self.healthColors[0]) button.setColor(HEALTH_COLORS[0])
self.geom = button self.geom = button
glow = BattleProps.globalPropPool.getProp('glow') glow = BattleProps.globalPropPool.getProp('glow')
glow.reparentTo(self.geom) glow.reparentTo(self.geom)
glow.setScale(0.28) glow.setScale(0.28)
glow.setPos(-0.005, 0.01, 0.015) glow.setPos(-0.005, 0.01, 0.015)
glow.setColor(self.healthGlowColors[0]) glow.setColor(HEALTH_GLOW_COLORS[0])
button.flattenLight() button.flattenLight()
self.geomGlow = glow self.geomGlow = glow
self.geom.hide() self.geom.hide()
self.healthCondition = 0 self.healthCondition = 0
print 'Generated'
def getHealthCondition(self, health): def getHealthCondition(self, health):
if health > 0.95: if health > 0.95:
@ -87,9 +86,7 @@ class SuitHealthBar:
def update(self, hp, forceUpdate = 0): def update(self, hp, forceUpdate = 0):
if not self.geom: if not self.geom:
print 'Not generated yet'
return return
print 'Updating: %s %s' % (hp, forceUpdate)
condition = self.getHealthCondition(hp) condition = self.getHealthCondition(hp)
if self.healthCondition != condition or forceUpdate: if self.healthCondition != condition or forceUpdate:
@ -99,32 +96,20 @@ class SuitHealthBar:
blinkTask = Task.loop(Task(self.__blinkRed), Task.pause(0.75 if condition == 9 else 0.25), Task(self.__blinkGray), Task.pause(0.1)) blinkTask = Task.loop(Task(self.__blinkRed), Task.pause(0.75 if condition == 9 else 0.25), Task(self.__blinkGray), Task.pause(0.1))
taskMgr.add(blinkTask, 'blink-task-%s' % id(self)) taskMgr.add(blinkTask, 'blink-task-%s' % id(self))
else: else:
self.geom.setColor(self.healthColors[condition], 1) self.geom.setColor(HEALTH_COLORS[condition], 1)
self.geomGlow.setColor(self.healthGlowColors[condition], 1) self.geomGlow.setColor(HEALTH_GLOW_COLORS[condition], 1)
self.healthCondition = condition self.healthCondition = condition
print 'Updated'
def __blink(self, color):
if not self.geom:
return
self.geom.setColor(HEALTH_COLORS[color], 1)
self.geomGlow.setColor(HEALTH_GLOW_COLORS[color], 1)
def __blinkRed(self, task): def __blinkRed(self, task):
if not self.geom: self.__blink(8)
return
print 'Blinking Red'
self.geom.setColor(self.healthColors[8], 1)
self.geomGlow.setColor(self.healthGlowColors[8], 1)
if self.healthCondition == 7:
self.geom.setScale(1.17)
print 'Blinked Red'
def __blinkGray(self, task): def __blinkGray(self, task):
if not self.geom: self.__blink(9)
return
print 'Blinking Gray'
self.geom.setColor(self.healthColors[9], 1)
self.geomGlow.setColor(self.healthGlowColors[9], 1)
if self.healthCondition == 10:
self.geom.setScale(1.0)
print 'Blinked Gray'