Rewritten (no pun intended) cog panel

This commit is contained in:
John 2015-08-09 14:32:13 +03:00
parent a2d5b004c9
commit 7019d1ba9a
4 changed files with 193 additions and 259 deletions

View file

@ -773,3 +773,14 @@ class Suit(Avatar.Avatar):
return SkelSuitDialogArray return SkelSuitDialogArray
else: else:
return SuitDialogArray 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 ''

View file

@ -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'

View file

@ -122,19 +122,12 @@ class TownBattle(StateData.StateData):
self.SOSPetInfoPanel = TownBattleSOSPetInfoPanel.TownBattleSOSPetInfoPanel(self.SOSPetInfoPanelDoneEvent) self.SOSPetInfoPanel = TownBattleSOSPetInfoPanel.TownBattleSOSPetInfoPanel(self.SOSPetInfoPanelDoneEvent)
self.fireCogPanelDoneEvent = 'fire-cog-panel-done' self.fireCogPanelDoneEvent = 'fire-cog-panel-done'
self.FireCogPanel = FireCogPanel.FireCogPanel(self.fireCogPanelDoneEvent) self.FireCogPanel = FireCogPanel.FireCogPanel(self.fireCogPanelDoneEvent)
self.toonPanels = (TownBattleToonPanel.TownBattleToonPanel(0), self.toonPanels = [TownBattleToonPanel.TownBattleToonPanel(i) for i in xrange(4)]
TownBattleToonPanel.TownBattleToonPanel(1), self.cogPanels = [TownBattleCogPanel.TownBattleCogPanel(i) for i in xrange(4)]
TownBattleToonPanel.TownBattleToonPanel(2),
TownBattleToonPanel.TownBattleToonPanel(3))
self.cogPanels = (TownBattleCogPanel.TownBattleCogPanel(0),
TownBattleCogPanel.TownBattleCogPanel(1),
TownBattleCogPanel.TownBattleCogPanel(2),
TownBattleCogPanel.TownBattleCogPanel(3))
self.timer = ToontownTimer.ToontownTimer() self.timer = ToontownTimer.ToontownTimer()
self.timer.posInTopRightCorner() self.timer.posInTopRightCorner()
self.timer.setScale(0.4) self.timer.setScale(0.4)
self.timer.hide() self.timer.hide()
return
def cleanup(self): def cleanup(self):
self.ignore(self.attackPanelDoneEvent) self.ignore(self.attackPanelDoneEvent)
@ -150,11 +143,9 @@ class TownBattle(StateData.StateData):
del self.FireCogPanel del self.FireCogPanel
del self.SOSPetSearchPanel del self.SOSPetSearchPanel
del self.SOSPetInfoPanel del self.SOSPetInfoPanel
for toonPanel in self.toonPanels:
toonPanel.cleanup()
for cogPanel in self.cogPanels: for panel in self.toonPanels + self.cogPanels:
cogPanel.cleanup() panel.cleanup()
del self.toonPanels del self.toonPanels
del self.cogPanels del self.cogPanels
@ -167,7 +158,6 @@ class TownBattle(StateData.StateData):
self.parentFSMState.addChild(self.fsm) self.parentFSMState.addChild(self.fsm)
if not self.isLoaded: if not self.isLoaded:
self.load() self.load()
print 'Battle Event %s' % event
self.battleEvent = event self.battleEvent = event
self.fsm.enterInitialState() self.fsm.enterInitialState()
base.localAvatar.laffMeter.start() base.localAvatar.laffMeter.start()
@ -182,7 +172,6 @@ class TownBattle(StateData.StateData):
base.localAvatar.inventory.setBattleCreditMultiplier(self.creditMultiplier) base.localAvatar.inventory.setBattleCreditMultiplier(self.creditMultiplier)
base.localAvatar.inventory.setActivateMode('battle', heal=0, bldg=bldg, tutorialFlag=tutorialFlag) base.localAvatar.inventory.setActivateMode('battle', heal=0, bldg=bldg, tutorialFlag=tutorialFlag)
self.SOSPanel.bldg = bldg self.SOSPanel.bldg = bldg
return
def exit(self): def exit(self):
base.localAvatar.laffMeter.stop() base.localAvatar.laffMeter.stop()
@ -231,44 +220,21 @@ class TownBattle(StateData.StateData):
for toonPanel in self.toonPanels: for toonPanel in self.toonPanels:
toonPanel.hide() toonPanel.hide()
toonPanel.setPos(0, 0, -0.9) toonPanel.setPos(0, 0, -0.9)
if num == 1: self.positionPanels(num, self.toonPanels)
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
def __enterCogPanels(self, num): def __enterCogPanels(self, num):
for cogPanel in self.cogPanels: for cogPanel in self.cogPanels:
cogPanel.hide() cogPanel.hide()
cogPanel.updateHealthBar() cogPanel.updateHealthBar()
cogPanel.setPos(0, 0, 0.62) 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 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: if num > i:
panel.setX(pos[i if num >= 3 else i + 1]) panel.setX(pos[i if num >= 3 else i + 1])
panel.show() panel.show()
@ -460,18 +426,7 @@ class TownBattle(StateData.StateData):
maxSuitLevel = max(maxSuitLevel, cog.getActualLevel()) maxSuitLevel = max(maxSuitLevel, cog.getActualLevel())
creditLevel = maxSuitLevel creditLevel = maxSuitLevel
resetActivateMode = 0 resetActivateMode = numCogs != self.numCogs or creditLevel != self.creditLevel or luredIndices != self.luredIndices or trappedIndices != self.trappedIndices or toonIds != self.toons
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
self.notify.debug('adjustCogsAndToons() resetActivateMode: %s' % resetActivateMode) self.notify.debug('adjustCogsAndToons() resetActivateMode: %s' % resetActivateMode)
self.numCogs = numCogs self.numCogs = numCogs
self.creditLevel = creditLevel self.creditLevel = creditLevel

View file

@ -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 direct.gui.DirectGui import *
from toontown.suit import Suit, SuitHealthBar
from toontown.toonbase import TTLocalizer from toontown.toonbase import TTLocalizer
from direct.task.Task import Task
class TownBattleCogPanel(DirectFrame): 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): def __init__(self, id):
gui = loader.loadModel('phase_3.5/models/gui/battle_gui') 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)) 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.setScale(0.8)
self.initialiseoptions(TownBattleCogPanel) self.initialiseoptions(TownBattleCogPanel)
self.levelText = DirectLabel(parent=self, text='', pos=(-0.06, 0, -0.075), text_scale=0.055) 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.typeText = DirectLabel(parent=self, text='', pos=(0.12, 0, -0.075), text_scale=0.045)
self.healthBar = None self.healthBar = SuitHealthBar.SuitHealthBar()
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.generateHealthBar()
self.suit = None
self.suitHead = None
self.hide() self.hide()
gui.removeNode() 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): def setSuit(self, suit):
if self.suit == suit: if self.suit == suit:
messenger.send(self.suit.uniqueName('hpChange')) messenger.send(self.suit.uniqueName('hpChange'))
return return
self.ignoreAll()
self.cleanupHead()
self.suit = suit self.suit = suit
self.setLevelText(self.suit.getActualLevel()) self.generateSuitHead(suit.getStyleName())
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.updateHealthBar()
self.healthBar.show() self.levelText['text'] = TTLocalizer.CogPanelLevel % suit.getActualLevel()
if self.suit.virtual: self.typeText['text'] = suit.getTypeText()
self.setTypeText(TTLocalizer.CogPanelVirtual) self.accept(suit.uniqueName('hpChange'), self.updateHealthBar)
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)
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): def generateHealthBar(self):
model = loader.loadModel('phase_3.5/models/gui/matching_game_gui') self.healthBar.generate()
button = model.find('**/minnieCircle') self.healthBar.geom.reparentTo(self)
model.removeNode() self.healthBar.geom.setScale(0.5)
button.setScale(0.5) self.healthBar.geom.setPos(-0.065, 0, 0.05)
button.setH(180.0) self.healthBar.geom.show()
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
def updateHealthBar(self): def updateHealthBar(self):
if not self.suit: if not self.suit:
return 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): self.healthBar.update(float(self.suit.getHP()) / float(self.suit.getMaxHP()))
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)