diff --git a/toontown/suit/Suit.py b/toontown/suit/Suit.py index f2b734f5..9c32aa7e 100755 --- a/toontown/suit/Suit.py +++ b/toontown/suit/Suit.py @@ -773,3 +773,14 @@ class Suit(Avatar.Avatar): return SkelSuitDialogArray else: return SuitDialogArray + + def getTypeText(self): + if self.virtual: + return TTLocalizer.CogPanelVirtual + elif self.isWaiter: + return TTLocalizer.CogPanelWaiter + elif self.skeleRevives: + return TTLocalizer.CogPanelRevives % (self.skeleRevives + 1) + elif self.isSkelecog: + return TTLocalizer.CogPanelSkeleton + return '' \ No newline at end of file diff --git a/toontown/suit/SuitHealthBar.py b/toontown/suit/SuitHealthBar.py new file mode 100644 index 00000000..398bad44 --- /dev/null +++ b/toontown/suit/SuitHealthBar.py @@ -0,0 +1,130 @@ +from direct.task import Task +from toontown.battle import BattleProps + +class SuitHealthBar: + healthColors = ((0, 1, 0, 1), + (0.5, 1, 0, 1), + (0.75, 1, 0, 1), + (1, 1, 0, 1), + (1, 0.86, 0, 1), + (1, 0.6, 0, 1), + (1, 0.5, 0, 1), + (1, 0.25, 0, 1.0), + (1, 0, 0, 1), + (0.3, 0.3, 0.3, 1)) + healthGlowColors = ((0.25, 1, 0.25, 0.5), + (0.5, 1, 0.25, .5), + (0.75, 1, 0.25, .5), + (1, 1, 0.25, 0.5), + (1, 0.866, 0.25, .5), + (1, 0.6, 0.25, .5), + (1, 0.5, 0.25, 0.5), + (1, 0.25, 0.25, 0.5), + (1, 0.25, 0.25, 0.5), + (0.3, 0.3, 0.3, 0)) + + def __init__(self): + print 'New Healthbar' + self.geom = None + self.geomGlow = None + self.healthCondition = 0 + + def delete(self): + print 'Deleting' + if self.geom: + self.geom.removeNode() + self.geom = None + self.geomGlow = None + taskMgr.remove('blink-task-%s' % id(self)) + self.healthCondition = 0 + print 'Deleted' + + def generate(self): + print 'Generating' + self.delete() + model = loader.loadModel('phase_3.5/models/gui/matching_game_gui') + button = model.find('**/minnieCircle') + model.removeNode() + + button.setH(180.0) + button.setColor(self.healthColors[0]) + self.geom = button + + glow = BattleProps.globalPropPool.getProp('glow') + glow.reparentTo(self.geom) + glow.setScale(0.28) + glow.setPos(-0.005, 0.01, 0.015) + glow.setColor(self.healthGlowColors[0]) + + button.flattenLight() + self.geomGlow = glow + self.geom.hide() + self.healthCondition = 0 + print 'Generated' + + def getHealthCondition(self, health): + if health > 0.95: + return 0 + elif health > 0.9: + return 1 + elif health > 0.8: + return 2 + elif health > 0.7: + return 3 + elif health > 0.6: + return 4 + elif health > 0.5: + return 5 + elif health > 0.3: + return 6 + elif health > 0.15: + return 7 + elif health > 0.05: + return 8 + elif health > 0.0: + return 9 + return 10 + + def update(self, hp, forceUpdate = 0): + if not self.geom: + print 'Not generated yet' + return + print 'Updating: %s %s' % (hp, forceUpdate) + condition = self.getHealthCondition(hp) + + if self.healthCondition != condition or forceUpdate: + taskMgr.remove('blink-task-%s' % id(self)) + + if condition in (9, 10): + 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)) + else: + self.geom.setColor(self.healthColors[condition], 1) + self.geomGlow.setColor(self.healthGlowColors[condition], 1) + + self.healthCondition = condition + print 'Updated' + + def __blinkRed(self, task): + if not self.geom: + 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): + if not self.geom: + 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' \ No newline at end of file diff --git a/toontown/town/TownBattle.py b/toontown/town/TownBattle.py index e44e7862..b44cdc32 100755 --- a/toontown/town/TownBattle.py +++ b/toontown/town/TownBattle.py @@ -122,19 +122,12 @@ class TownBattle(StateData.StateData): self.SOSPetInfoPanel = TownBattleSOSPetInfoPanel.TownBattleSOSPetInfoPanel(self.SOSPetInfoPanelDoneEvent) self.fireCogPanelDoneEvent = 'fire-cog-panel-done' self.FireCogPanel = FireCogPanel.FireCogPanel(self.fireCogPanelDoneEvent) - self.toonPanels = (TownBattleToonPanel.TownBattleToonPanel(0), - TownBattleToonPanel.TownBattleToonPanel(1), - TownBattleToonPanel.TownBattleToonPanel(2), - TownBattleToonPanel.TownBattleToonPanel(3)) - self.cogPanels = (TownBattleCogPanel.TownBattleCogPanel(0), - TownBattleCogPanel.TownBattleCogPanel(1), - TownBattleCogPanel.TownBattleCogPanel(2), - TownBattleCogPanel.TownBattleCogPanel(3)) + self.toonPanels = [TownBattleToonPanel.TownBattleToonPanel(i) for i in xrange(4)] + self.cogPanels = [TownBattleCogPanel.TownBattleCogPanel(i) for i in xrange(4)] self.timer = ToontownTimer.ToontownTimer() self.timer.posInTopRightCorner() self.timer.setScale(0.4) self.timer.hide() - return def cleanup(self): self.ignore(self.attackPanelDoneEvent) @@ -150,11 +143,9 @@ class TownBattle(StateData.StateData): del self.FireCogPanel del self.SOSPetSearchPanel del self.SOSPetInfoPanel - for toonPanel in self.toonPanels: - toonPanel.cleanup() - for cogPanel in self.cogPanels: - cogPanel.cleanup() + for panel in self.toonPanels + self.cogPanels: + panel.cleanup() del self.toonPanels del self.cogPanels @@ -167,7 +158,6 @@ class TownBattle(StateData.StateData): self.parentFSMState.addChild(self.fsm) if not self.isLoaded: self.load() - print 'Battle Event %s' % event self.battleEvent = event self.fsm.enterInitialState() base.localAvatar.laffMeter.start() @@ -182,7 +172,6 @@ class TownBattle(StateData.StateData): base.localAvatar.inventory.setBattleCreditMultiplier(self.creditMultiplier) base.localAvatar.inventory.setActivateMode('battle', heal=0, bldg=bldg, tutorialFlag=tutorialFlag) self.SOSPanel.bldg = bldg - return def exit(self): base.localAvatar.laffMeter.stop() @@ -231,44 +220,21 @@ class TownBattle(StateData.StateData): for toonPanel in self.toonPanels: toonPanel.hide() toonPanel.setPos(0, 0, -0.9) - - if num == 1: - self.toonPanels[0].setX(self.oddPos[1]) - self.toonPanels[0].show() - elif num == 2: - self.toonPanels[0].setX(self.evenPos[1]) - self.toonPanels[0].show() - self.toonPanels[1].setX(self.evenPos[2]) - self.toonPanels[1].show() - elif num == 3: - self.toonPanels[0].setX(self.oddPos[0]) - self.toonPanels[0].show() - self.toonPanels[1].setX(self.oddPos[1]) - self.toonPanels[1].show() - self.toonPanels[2].setX(self.oddPos[2]) - self.toonPanels[2].show() - elif num == 4: - self.toonPanels[0].setX(self.evenPos[0]) - self.toonPanels[0].show() - self.toonPanels[1].setX(self.evenPos[1]) - self.toonPanels[1].show() - self.toonPanels[2].setX(self.evenPos[2]) - self.toonPanels[2].show() - self.toonPanels[3].setX(self.evenPos[3]) - self.toonPanels[3].show() - else: - self.notify.error('Bad number of toons: %s' % num) - return None + + self.positionPanels(num, self.toonPanels) def __enterCogPanels(self, num): for cogPanel in self.cogPanels: cogPanel.hide() cogPanel.updateHealthBar() cogPanel.setPos(0, 0, 0.62) - + + self.positionPanels(num, self.cogPanels) + + def positionPanels(self, num, panels): pos = self.evenPos if num % 2 == 0 else self.oddPos - for i, panel in enumerate(self.cogPanels): + for i, panel in enumerate(panels): if num > i: panel.setX(pos[i if num >= 3 else i + 1]) panel.show() @@ -460,18 +426,7 @@ class TownBattle(StateData.StateData): maxSuitLevel = max(maxSuitLevel, cog.getActualLevel()) creditLevel = maxSuitLevel - resetActivateMode = 0 - if numCogs == self.numCogs and creditLevel == self.creditLevel and luredIndices == self.luredIndices and trappedIndices == self.trappedIndices and toonIds == self.toons: - for i in xrange(len(cogs)): - if cogs[i].getHP() == self.cogPanels[i].getDisplayedCurrHp(): - if cogs[i].getMaxHP() == self.cogPanels[i].getDisplayedMaxHp(): - if cogs[i] == self.cogPanels[i].getSuit(): - continue - else: - resetActivateMode = 1 - break - else: - resetActivateMode = 1 + resetActivateMode = numCogs != self.numCogs or creditLevel != self.creditLevel or luredIndices != self.luredIndices or trappedIndices != self.trappedIndices or toonIds != self.toons self.notify.debug('adjustCogsAndToons() resetActivateMode: %s' % resetActivateMode) self.numCogs = numCogs self.creditLevel = creditLevel diff --git a/toontown/town/TownBattleCogPanel.py b/toontown/town/TownBattleCogPanel.py index 07f04e35..f68b00c7 100755 --- a/toontown/town/TownBattleCogPanel.py +++ b/toontown/town/TownBattleCogPanel.py @@ -1,228 +1,66 @@ -from panda3d.core 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 toontown.suit import Suit, SuitHealthBar 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 - 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 def __init__(self, id): 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.86, 0.86, 0.86, 0.7)) - self.setScale(0.8) + 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) 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.045) - 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.typeText = DirectLabel(parent=self, text='', pos=(0.12, 0, -0.075), text_scale=0.045) + self.healthBar = SuitHealthBar.SuitHealthBar() self.generateHealthBar() + self.suit = None + self.suitHead = None self.hide() gui.removeNode() - return + + def cleanup(self): + self.ignoreAll() + self.cleanupHead() + self.levelText.removeNode() + self.typeText.removeNode() + self.healthBar.delete() + del self.levelText + del self.typeText + del self.healthBar + DirectFrame.destroy(self) + + def cleanupHead(self): + if self.suitHead: + self.suitHead.removeNode() + del self.suitHead def setSuit(self, suit): if self.suit == suit: messenger.send(self.suit.uniqueName('hpChange')) return + + self.ignoreAll() + self.cleanupHead() 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.generateSuitHead(suit.getStyleName()) self.updateHealthBar() - self.healthBar.show() - if self.suit.virtual: - self.setTypeText(TTLocalizer.CogPanelVirtual) - elif self.suit.isWaiter: - self.setTypeText(TTLocalizer.CogPanelWaiter) - elif self.suit.skeleRevives: - self.setTypeText(TTLocalizer.CogPanelRevives % (self.suit.skeleRevives + 1)) - elif self.suit.isSkelecog: - self.setTypeText(TTLocalizer.CogPanelSkeleton) - else: - self.setTypeText('') - - def getSuit(self, suit): - return self.suit - - def setLevelText(self, level): - self.levelText['text'] = TTLocalizer.CogPanelLevel % 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) - self.head.setScale(0.05) + self.levelText['text'] = TTLocalizer.CogPanelLevel % suit.getActualLevel() + self.typeText['text'] = suit.getTypeText() + self.accept(suit.uniqueName('hpChange'), self.updateHealthBar) + 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): - 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) - 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() - self.healthCondition = 0 + 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 - 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: - 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: - 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: - 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: - 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) - self.blinkTask = None - if self.healthBar: - self.healthBar.removeNode() - self.healthBar = None - self.healthCondition = 0 - return - - def getDisplayedCurrHp(self): - return self.currHP - - def getDisplayedMaxHp(self): - return self.maxHP - - def setMaxHp(self, hp): - self.maxHP = hp - - def setHp(self, hp): - self.currHP = hp - - def show(self): - DirectFrame.show(self) - - 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 - 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) + self.healthBar.update(float(self.suit.getHP()) / float(self.suit.getMaxHP())) \ No newline at end of file