Added Cog Level Gui, time to polish it...

This commit is contained in:
Loudrob 2015-03-29 15:05:19 -04:00
parent 983eb61b68
commit 72cd51bf93
11 changed files with 530 additions and 49 deletions

View file

@ -0,0 +1,47 @@
(dp1
I4000
(lp2
I11
aI177
aI238
aI152
aI89
asI1000
(lp3
I123
aI161
aI145
aI138
aI122
asI9000
(lp4
I66
aI201
aI27
aI102
aI185
asI2000
(lp5
I135
aI20
aI54
aI240
aI147
asI5000
(lp6
I129
aI194
aI222
aI92
aI37
asI3000
(lp7
I166
aI114
aI70
aI144
aI30
asS'day'
p8
I16523
s.

View file

@ -117,7 +117,7 @@ speedChatStyles = (
(210 / 255.0, 200 / 255.0, 180 / 255.0)
)
)
PageMode = PythonUtil.Enum('Options, Codes')
PageMode = PythonUtil.Enum('Options, Codes, MoreOptions')
class OptionsPage(ShtikerPage.ShtikerPage):
@ -128,9 +128,11 @@ class OptionsPage(ShtikerPage.ShtikerPage):
self.optionsTabPage = None
self.codesTabPage = None
self.moreOptionsTabPage = None
self.title = None
self.optionsTab = None
self.codesTab = None
self.moreOptionsTab = None
def load(self):
ShtikerPage.ShtikerPage.load(self)
@ -139,6 +141,8 @@ class OptionsPage(ShtikerPage.ShtikerPage):
self.optionsTabPage.hide()
self.codesTabPage = CodesTabPage(self)
self.codesTabPage.hide()
self.moreOptionsTabPage = MoreOptionsTabPage(self)
self.moreOptionsTabPage.hide()
self.title = DirectLabel(
parent=self, relief=None, text=TTLocalizer.OptionsPageTitle,
@ -158,7 +162,7 @@ class OptionsPage(ShtikerPage.ShtikerPage):
image1_color=clickColor, image2_color=rolloverColor,
image3_color=diabledColor, text_fg=Vec4(0.2, 0.1, 0, 1),
command=self.setMode, extraArgs=[PageMode.Options],
pos=(-0.36, 0, 0.77))
pos=(-0.64, 0, 0.77))
self.codesTab = DirectButton(
parent=self, relief=None, text=TTLocalizer.OptionsPageCodesTab,
text_scale=TTLocalizer.OPoptionsTab, text_align=TextNode.ALeft,
@ -168,7 +172,17 @@ class OptionsPage(ShtikerPage.ShtikerPage):
image_color=normalColor, image1_color=clickColor,
image2_color=rolloverColor, image3_color=diabledColor,
text_fg=Vec4(0.2, 0.1, 0, 1), command=self.setMode,
extraArgs=[PageMode.Codes], pos=(0.11, 0, 0.77))
extraArgs=[PageMode.Codes], pos=(-0.12, 0, 0.77))
self.moreOptionsTab = DirectButton(
parent=self, relief=None, text=TTLocalizer.MoreOptionsPageTitle,
text_scale=TTLocalizer.OPmoreOptionsTab, text_align=TextNode.ALeft,
text_pos=(-0.035, 0.0, 0.0),
image=gui.find('**/tabs/polySurface2'), image_pos=(0.12, 1, -0.91),
image_hpr=(0, 0, -90), image_scale=(0.033, 0.033, 0.035),
image_color=normalColor, image1_color=clickColor,
image2_color=rolloverColor, image3_color=diabledColor,
text_fg=Vec4(0.2, 0.1, 0, 1), command=self.setMode,
extraArgs=[PageMode.MoreOptions], pos=(0.42, 0, 0.77))
gui.removeNode()
def enter(self):
@ -220,13 +234,24 @@ class OptionsPage(ShtikerPage.ShtikerPage):
self.optionsTabPage.enter()
self.codesTab['state'] = DGG.NORMAL
self.codesTabPage.exit()
self.moreOptionsTab['state'] = DGG.NORMAL
self.moreOptionsTabPage.exit()
elif mode == PageMode.Codes:
self.title['text'] = TTLocalizer.CdrPageTitle
self.optionsTab['state'] = DGG.NORMAL
self.optionsTabPage.exit()
self.moreOptionsTab['state'] = DGG.NORMAL
self.moreOptionsTabPage.exit()
self.codesTab['state'] = DGG.DISABLED
self.codesTabPage.enter()
elif mode == PageMode.MoreOptions:
self.title['text'] = TTLocalizer.MoreOptionsPageTitle
self.optionsTab['state'] = DGG.NORMAL
self.optionsTabPage.exit()
self.codesTab['state'] = DGG.NORMAL
self.codesTabPage.exit()
self.moreOptionsTab['state'] = DGG.DISABLED
self.moreOptionsTabPage.enter()
class OptionsTabPage(DirectFrame):
notify = directNotify.newCategory('OptionsTabPage')
@ -676,3 +701,82 @@ class CodesTabPage(DirectFrame):
self.codeInput['state'] = DGG.NORMAL
self.codeInput['focus'] = 1
self.submitButton['state'] = DGG.NORMAL
class MoreOptionsTabPage(DirectFrame):
notify = directNotify.newCategory('MoreOptionsTabPage')
def __init__(self, parent = aspect2d):
self.parent = parent
self.currentSizeIndex = None
DirectFrame.__init__(self, parent=self.parent, relief=None, pos=(0.0, 0.0, 0.0), scale=(1.0, 1.0, 1.0))
self.load()
def destroy(self):
self.parent = None
DirectFrame.destroy(self)
def load(self):
guiButton = loader.loadModel('phase_3/models/gui/quit_button')
gui = loader.loadModel('phase_3.5/models/gui/friendslist_gui')
titleHeight = 0.61
textStartHeight = 0.45
textRowHeight = 0.145
leftMargin = -0.72
buttonbase_xcoord = 0.35
buttonbase_ycoord = 0.45
button_image_scale = (0.7, 1, 1)
button_textpos = (0, -0.02)
options_text_scale = 0.052
disabled_arrow_color = Vec4(0.6, 0.6, 0.6, 1.0)
self.speed_chat_scale = 0.055
self.CogLevel_toggleButton = DirectButton(parent=self, relief=None, image=(guiButton.find('**/QuitBtn_UP'), guiButton.find('**/QuitBtn_DN'), guiButton.find('**/QuitBtn_RLVR')), image_scale=button_image_scale, text='', text_scale=options_text_scale, text_pos=button_textpos, pos=(buttonbase_xcoord, 0.0, buttonbase_ycoord), command=self.__doToggleCogLevelGui)
self.CogLevel_Label = DirectLabel(parent=self, relief=None, text='', text_align=TextNode.ALeft, text_scale=options_text_scale, text_wordwrap=16, pos=(leftMargin, 0, textStartHeight))
gui.removeNode()
guiButton.removeNode()
def enter(self):
self.show()
self.settingsChanged = 0
self.__setCogLevelGuiButton()
def exit(self):
self.ignore('confirmDone')
self.hide()
def unload(self):
self.CogLevel_Label.destroy()
del self.CogLevel_Label
self.CogLevel_toggleButton.destroy()
del self.CogLevel_toggleButton
def __doToggleCogLevelGui(self):
messenger.send('wakeup')
if base.wantCogLevelGui:
base.wantCogLevelGui = False
settings['want-Cog-Level-GUI'] = False
else:
base.wantCogLevelGui = True
settings['want-Cog-Level-GUI'] = True
self.settingsChanged = 1
self.__setCogLevelGuiButton()
def __setCogLevelGuiButton(self):
if base.wantCogLevelGui:
self.CogLevel_Label['text'] = 'Cog Level GUI In-Battle:'
self.CogLevel_toggleButton['text'] = 'On'
else:
self.CogLevel_Label['text'] = 'Cog Level GUI In-Battle:'
self.CogLevel_toggleButton['text'] = 'Off'
def __doToggleAntialiasing(self):
# To toggle anti-aliasing in the future.
pass
def __setAntialiasingGuiButton(self):
# More anti-aliasing stuff.
pass

View file

@ -181,22 +181,32 @@ class BossCog(Avatar.Avatar):
health = 1.0 - float(self.bossDamage) / float(self.bossMaxDamage)
if health > 0.95:
condition = 0
elif health > 0.7:
elif health > 0.9:
condition = 1
elif health > 0.3:
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 = 3
condition = 8#Red
elif health > 0.0:
condition = 4
condition = 9#Blinking Red
else:
condition = 5
condition = 10
if self.healthCondition != condition:
if condition == 4:
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 == 5:
if self.healthCondition == 4:
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'))
@ -204,19 +214,22 @@ class BossCog(Avatar.Avatar):
self.healthBar.setColor(self.healthColors[condition], 1)
self.healthBarGlow.setColor(self.healthGlowColors[condition], 1)
self.healthCondition = condition
return
def __blinkRed(self, task):
self.healthBar.setColor(self.healthColors[3], 1)
self.healthBarGlow.setColor(self.healthGlowColors[3], 1)
if self.healthCondition == 5:
if not self.healthBar:
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.setColor(self.healthColors[4], 1)
self.healthBarGlow.setColor(self.healthGlowColors[4], 1)
if self.healthCondition == 5:
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
@ -224,7 +237,7 @@ class BossCog(Avatar.Avatar):
if self.healthBar:
self.healthBar.removeNode()
self.healthBar = None
if self.healthCondition == 4 or self.healthCondition == 5:
if self.healthCondition == 9 or self.healthCondition == 10:
taskMgr.remove(self.uniqueName('blink-task'))
self.healthCondition = 0
return

View file

@ -125,6 +125,9 @@ class DistributedSuitBase(DistributedAvatar.DistributedAvatar, Suit.Suit, SuitBa
def getHP(self):
return self.currHP
def getMaxHP(self):
return self.maxHP
def setHP(self, hp):
if hp > self.maxHP:
self.currHP = self.maxHP
@ -461,4 +464,4 @@ class DistributedSuitBase(DistributedAvatar.DistributedAvatar, Suit.Suit, SuitBa
except:
level = '???'
return '%s\n%s\nLevel %s' % (self.getName(), self.doId, level)
return '%s\n%s\nLevel %s' % (self.getName(), self.doId, level)

View file

@ -318,16 +318,26 @@ def attachSuitHead(node, suitName):
class Suit(Avatar.Avatar):
__module__ = __name__
healthColors = (Vec4(0, 1, 0, 1),
Vec4(1, 1, 0, 1),
Vec4(1, 0.5, 0, 1),
Vec4(1, 0, 0, 1),
Vec4(0.3, 0.3, 0.3, 1))
healthGlowColors = (Vec4(0.25, 1, 0.25, 0.5),
Vec4(1, 1, 0.25, 0.5),
Vec4(1, 0.5, 0.25, 0.5),
Vec4(1, 0.25, 0.25, 0.5),
Vec4(0.3, 0.3, 0.3, 0))
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),
's': Vec4(0.843, 0.745, 0.745, 1.0),
'l': Vec4(0.749, 0.776, 0.824, 1.0),
@ -629,22 +639,32 @@ class Suit(Avatar.Avatar):
health = float(self.currHP) / float(self.maxHP)
if health > 0.95:
condition = 0
elif health > 0.7:
elif health > 0.9:
condition = 1
elif health > 0.3:
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 = 3
condition = 8#Red
elif health > 0.0:
condition = 4
condition = 9#Blinking Red
else:
condition = 5
condition = 10
if self.healthCondition != condition or forceUpdate:
if condition == 4:
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 == 5:
if self.healthCondition == 4:
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'))
@ -654,18 +674,20 @@ class Suit(Avatar.Avatar):
self.healthCondition = condition
def __blinkRed(self, task):
self.healthBar.setColor(self.healthColors[3], 1)
self.healthBarGlow.setColor(self.healthGlowColors[3], 1)
if self.healthCondition == 5:
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
self.healthBar.setColor(self.healthColors[4], 1)
self.healthBarGlow.setColor(self.healthGlowColors[4], 1)
if self.healthCondition == 5:
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
@ -673,7 +695,7 @@ class Suit(Avatar.Avatar):
if self.healthBar:
self.healthBar.removeNode()
self.healthBar = None
if self.healthCondition == 4 or self.healthCondition == 5:
if self.healthCondition == 9 or self.healthCondition == 10:
taskMgr.remove(self.uniqueName('blink-task'))
self.healthCondition = 0
return

View file

@ -29,6 +29,20 @@ class SuitBase:
if hasattr(self, 'legList'):
del self.legList
def getCurrHp(self):
if hasattr(self, 'currHP') and self.currHP:
return self.currHP
else:
self.notify.error('currHP is None')
return 'unknown'
def getMaxHp(self):
if hasattr(self, 'maxHP') and self.maxHP:
return self.maxHP
else:
self.notify.error('maxHP is None')
return 'unknown'
def getStyleName(self):
if hasattr(self, 'dna') and self.dna:
return self.dna.name

View file

@ -4605,6 +4605,7 @@ MapPageYouAreAtHome = 'You are at\nyour estate'
MapPageYouAreAtSomeonesHome = 'You are at %s estate'
MapPageGoTo = 'Go To\n%s'
OptionsPageTitle = 'Options'
MoreOptionsPageTitle = 'More Options'
OptionsTabTitle = 'Options\n& Codes'
OptionsPagePurchase = 'Subscribe'
OptionsPageExitToontown = 'Exit Toontown'

View file

@ -245,6 +245,7 @@ TPstartFrame = 0.12
TPendFrame = 0.12
SBpageTab = 0.75
OPoptionsTab = 0.07
OPmoreOptionsTab = 0.06
OPCodesInstructionPanelTextPos = (0, -0.01)
OPCodesInstructionPanelTextWordWrap = 6
OPCodesResultPanelTextPos = (0, 0.35)

View file

@ -235,6 +235,8 @@ class ToonBase(OTPBase.OTPBase):
self.filters = CommonFilters(self.win, self.cam)
self.wantCogLevelGui = settings.get('want-Cog-Level-GUI', True)
def openMainWindow(self, *args, **kw):
result = OTPBase.OTPBase.openMainWindow(self, *args, **kw)
self.setCursorAndIcon()

View file

@ -10,6 +10,7 @@ import TownBattleSOSPanel
import TownBattleSOSPetSearchPanel
import TownBattleSOSPetInfoPanel
import TownBattleToonPanel
import TownBattleCogPanel
from toontown.toontowngui import TTDialog
from direct.directnotify import DirectNotifyGlobal
from toontown.battle import BattleBase
@ -129,6 +130,10 @@ class TownBattle(StateData.StateData):
TownBattleToonPanel.TownBattleToonPanel(1),
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.posInTopRightCorner()
self.timer.setScale(0.4)
@ -152,7 +157,11 @@ class TownBattle(StateData.StateData):
for toonPanel in self.toonPanels:
toonPanel.cleanup()
for cogPanel in self.cogPanels:
cogPanel.cleanup()
del self.toonPanels
del self.cogPanels
self.timer.destroy()
del self.timer
del self.toons
@ -255,6 +264,40 @@ class TownBattle(StateData.StateData):
self.notify.error('Bad number of toons: %s' % num)
return None
def __enterCogPanels(self, num):
for cogPanel in self.cogPanels:
cogPanel.hide()
cogPanel.updateHealthBar()
cogPanel.setPos(0, 0, 0.75)
if num == 1:
self.cogPanels[0].setX(self.oddPos[1])
self.cogPanels[0].show()
elif num == 2:
self.cogPanels[0].setX(self.evenPos[1])
self.cogPanels[0].show()
self.cogPanels[1].setX(self.evenPos[2])
self.cogPanels[1].show()
elif num == 3:
self.cogPanels[0].setX(self.oddPos[0])
self.cogPanels[0].show()
self.cogPanels[1].setX(self.oddPos[1])
self.cogPanels[1].show()
self.cogPanels[2].setX(self.oddPos[2])
self.cogPanels[2].show()
elif num == 4:
self.cogPanels[0].setX(self.evenPos[0])
self.cogPanels[0].show()
self.cogPanels[1].setX(self.evenPos[1])
self.cogPanels[1].show()
self.cogPanels[2].setX(self.evenPos[2])
self.cogPanels[2].show()
self.cogPanels[3].setX(self.evenPos[3])
self.cogPanels[3].show()
else:
self.notify.error('Bad number of toons: %s' % num)
return None
def updateChosenAttacks(self, battleIndices, tracks, levels, targets):
self.notify.debug('updateChosenAttacks bi=%s tracks=%s levels=%s targets=%s' % (battleIndices,
tracks,
@ -310,6 +353,9 @@ class TownBattle(StateData.StateData):
for toonPanel in self.toonPanels:
toonPanel.hide()
for cogPanel in self.cogPanels:
cogPanel.hide()
self.toonAttacks = [(-1, 0, 0),
(-1, 0, 0),
(-1, 0, 0),
@ -322,6 +368,8 @@ class TownBattle(StateData.StateData):
def exitOff(self):
if self.isLoaded:
self.__enterPanels(self.numToons, self.localNum)
if base.wantCogLevelGui:
self.__enterCogPanels(self.numCogs)
self.timer.show()
self.track = -1
self.level = -1
@ -442,8 +490,16 @@ class TownBattle(StateData.StateData):
cogFireCostIndex += 1
creditLevel = maxSuitLevel
resetActivateMode = 0
if numCogs == self.numCogs and creditLevel == self.creditLevel and luredIndices == self.luredIndices and trappedIndices == self.trappedIndices and toonIds == self.toons:
resetActivateMode = 0
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)
@ -460,6 +516,11 @@ class TownBattle(StateData.StateData):
for i in xrange(len(toons)):
self.toonPanels[i].setLaffMeter(toons[i])
if base.wantCogLevelGui:
self.__enterCogPanels(self.numCogs)
for i in xrange(len(cogs)):
self.cogPanels[i].setSuit(cogs[i])
if currStateName == 'ChooseCog':
self.chooseCogPanel.adjustCogs(self.numCogs, self.luredIndices, self.trappedIndices, self.track)
elif currStateName == 'ChooseToon':

View file

@ -0,0 +1,213 @@
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
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.5, 0.5, 0.5, 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.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
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()
def getSuit(self, suit):
return self.suit
def setLevelText(self, level):
self.levelText['text'] = 'Level '+ str(level)
def setSuitHead(self, suitName):
self.head = Suit.attachSuitHead(self, suitName)
self.head.setX(0.1)
self.head.setZ(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.08)
button.setZ(0.02)
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):
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.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)