Cog hover panel in battle gui

This commit is contained in:
John 2015-08-17 12:42:39 +03:00
parent 3f12bc6500
commit a54cbc8778
6 changed files with 85 additions and 35 deletions

View file

@ -3170,4 +3170,18 @@ def getAttackTaunt(attackName, index = None):
SuitAttackTaunts = TTLocalizer.SuitAttackTaunts SuitAttackTaunts = TTLocalizer.SuitAttackTaunts
DisabledAttacks = ('Gavel', 'SongAndDance', 'SandTrap', 'FloodTheMarket', 'FiveOClockShadow') DisabledAttacks = ('Gavel', 'SongAndDance', 'SandTrap', 'FloodTheMarket', 'FiveOClockShadow')
def getAttacksByType(attributes):
groupAttacks = []
singleAttacks = []
for attack in sorted(attributes['attacks'], key=lambda x: x[0]):
if attack[0] in DisabledAttacks:
continue
if SuitAttacks[attack[0]][1] == ATK_TGT_GROUP:
groupAttacks.append(attack)
else:
singleAttacks.append(attack)
return groupAttacks, singleAttacks

View file

@ -488,19 +488,9 @@ class SuitPage(ShtikerPage.ShtikerPage):
name = SuitDNA.suitHeadTypes[index] name = SuitDNA.suitHeadTypes[index]
attributes = SuitBattleGlobals.SuitAttributes[name] attributes = SuitBattleGlobals.SuitAttributes[name]
level = attributes['level'] level = attributes['level']
attacks = sorted(attributes['attacks'], key=lambda x: x[0]) groupAttacks, singleAttacks = SuitBattleGlobals.getAttacksByType(attributes)
groupAttacks = []
singleAttacks = []
for attack in attacks:
if attack[0] in SuitBattleGlobals.DisabledAttacks:
continue
if SuitBattleGlobals.SuitAttacks[attack[0]][1] == SuitBattleGlobals.ATK_TGT_GROUP:
groupAttacks.append(attack)
else:
singleAttacks.append(attack)
info = TTLocalizer.SuitPageAttackFormat % (level + 1, level + 5, self.getAttackStrings(groupAttacks), self.getAttackStrings(singleAttacks)) info = TTLocalizer.SuitPageAttackFormat % (level + 1, level + 5, self.getAttackStrings(groupAttacks), self.getAttackStrings(singleAttacks))
panel.hoverButton.bind(DGG.ENTER, self.showInfo, extraArgs=[panel, info]) panel.hoverButton.bind(DGG.ENTER, self.showInfo, extraArgs=[panel, info])
panel.hoverButton.bind(DGG.EXIT, self.hideInfo) panel.hoverButton.bind(DGG.EXIT, self.hideInfo)

View file

@ -8726,7 +8726,13 @@ ShardPageTeleport = 'Teleport to\n%s'
TeleportButton = 'Teleport' TeleportButton = 'Teleport'
SuitPageAttackFormat = 'Levels: %s-%s\n\n\x01androidGreen\x01Group attacks:\x02\n%s\n\n\x01androidGreen\x01Regular attacks:\x02\n%s' BattleCogPopup = '\x01androidGreen\x01Group attacks:\x02\n%s\n\n\x01androidGreen\x01Regular attacks:\x02\n%s'
BattleCogPopupAttack = '%s %s HP'
BattleCogPopupAttackDanger = '\x01red\x01' + BattleCogPopupAttack + '\x02'
BattleCogPopupDanger = '\x01red\x01Dangerous!\x02\n\n'
BattleCogPopupDangerColor = '\x01red'
SuitPageAttackFormat = 'Levels: %s-%s\n\n' + BattleCogPopup
SuitPageNoAttacks = 'None' SuitPageNoAttacks = 'None'
BattleGagPopup = '%s: %s\nGags left: %s' BattleGagPopup = '%s: %s\nGags left: %s'

View file

@ -122,11 +122,11 @@ 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.toonRolloverFrame = DirectFrame(aspect2d, relief=None, geom=DGG.getDefaultDialogGeom(), geom_color=(0.6, 1.0, 0.4, 1), geom_scale=(0.5, 0.3, 0.2), text_scale=0.05, text_pos=(0, 0.0125), text='', text_fg=(0, 0, 0, 1), pos=(0.4, 0, 0)) self.rolloverFrame = DirectFrame(aspect2d, relief=None, geom=DGG.getDefaultDialogGeom(), geom_color=(0.6, 1.0, 0.4, 1), geom_scale=(0.5, 0.3, 0.2), text_scale=0.05, text_pos=(0, 0.0125), text='', text_fg=(0, 0, 0, 1), pos=(0.4, 0, 0))
self.toonRolloverFrame.setBin('gui-popup', 0) self.rolloverFrame.setBin('gui-popup', 0)
self.toonRolloverFrame.hide() self.rolloverFrame.hide()
self.toonPanels = [TownBattleToonPanel.TownBattleToonPanel(self) for i in xrange(4)] self.toonPanels = [TownBattleToonPanel.TownBattleToonPanel(self) for i in xrange(4)]
self.cogPanels = [TownBattleCogPanel.TownBattleCogPanel(i) for i in xrange(4)] self.cogPanels = [TownBattleCogPanel.TownBattleCogPanel(self) for i in xrange(4)]
self.timer = ToontownTimer.ToontownTimer() self.timer = ToontownTimer.ToontownTimer()
self.timer.posInTopRightCorner() self.timer.posInTopRightCorner()
self.timer.setScale(0.4) self.timer.setScale(0.4)
@ -146,7 +146,7 @@ class TownBattle(StateData.StateData):
del self.FireCogPanel del self.FireCogPanel
del self.SOSPetSearchPanel del self.SOSPetSearchPanel
del self.SOSPetInfoPanel del self.SOSPetInfoPanel
del self.toonRolloverFrame del self.rolloverFrame
for panel in self.toonPanels + self.cogPanels: for panel in self.toonPanels + self.cogPanels:
panel.cleanup() panel.cleanup()
@ -219,13 +219,22 @@ class TownBattle(StateData.StateData):
self.timer.setTime(time) self.timer.setTime(time)
return None return None
def scaleToonRolloverFrame(self, scale, textPos, z): def showRolloverFrame(self, parent, scale, textPos, color, pos, text, extra=None):
self.toonRolloverFrame['geom_scale'] = scale self.rolloverFrame['geom_scale'] = scale
self.toonRolloverFrame['text_pos'] = textPos self.rolloverFrame['text_pos'] = textPos
self.toonRolloverFrame.setZ(z) self.rolloverFrame['geom_color'] = color
self.rolloverFrame.setPos(pos)
self.rolloverFrame.reparentTo(parent)
self.rolloverFrame.show()
self.rolloverFrame['text'] = text
def hideToonRolloverFrame(self, extra=None): def hideRolloverFrame(self, extra=None):
self.toonRolloverFrame.hide() self.rolloverFrame.hide()
def isAttackDangerous(self, hp):
for panel in self.toonPanels:
if panel.hasAvatar() and panel.avatar.getHp() <= hp:
return True
def __enterPanels(self, num, localNum): def __enterPanels(self, num, localNum):
self.notify.debug('enterPanels() num: %d localNum: %d' % (num, localNum)) self.notify.debug('enterPanels() num: %d localNum: %d' % (num, localNum))
@ -239,6 +248,7 @@ class TownBattle(StateData.StateData):
for cogPanel in self.cogPanels: for cogPanel in self.cogPanels:
cogPanel.hide() cogPanel.hide()
cogPanel.updateHealthBar() cogPanel.updateHealthBar()
cogPanel.updateRolloverBind()
cogPanel.setPos(0, 0, 0.62) cogPanel.setPos(0, 0, 0.62)
self.positionPanels(num, self.cogPanels) self.positionPanels(num, self.cogPanels)
@ -448,6 +458,7 @@ class TownBattle(StateData.StateData):
self.numToons = len(toons) self.numToons = len(toons)
self.localNum = toons.index(base.localAvatar) self.localNum = toons.index(base.localAvatar)
currStateName = self.fsm.getCurrentState().getName() currStateName = self.fsm.getCurrentState().getName()
if resetActivateMode: if resetActivateMode:
self.__enterPanels(self.numToons, self.localNum) self.__enterPanels(self.numToons, self.localNum)
for i in xrange(len(toons)): for i in xrange(len(toons)):

View file

@ -1,17 +1,22 @@
from direct.gui.DirectGui import * from direct.gui.DirectGui import *
from toontown.battle import SuitBattleGlobals
from toontown.suit import Suit, SuitHealthBar from toontown.suit import Suit, SuitHealthBar
from toontown.toonbase import TTLocalizer from toontown.toonbase import TTLocalizer
class TownBattleCogPanel(DirectFrame): class TownBattleCogPanel(DirectFrame):
def __init__(self, id): def __init__(self, battle):
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=(0.86, 0.86, 0.86, 0.7), scale=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.initialiseoptions(TownBattleCogPanel)
self.battle = battle
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.typeText = 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 = SuitHealthBar.SuitHealthBar() self.healthBar = SuitHealthBar.SuitHealthBar()
self.generateHealthBar() self.generateHealthBar()
self.hoverButton = DirectButton(parent=self, relief=None, image_scale=(0.07, 0, 0.06), pos=(0.105, 0, 0.05), image='phase_3/maps/invisible.png', pressEffect=0)
self.hoverButton.setTransparency(True)
self.hoverButton.bind(DGG.EXIT, self.battle.hideRolloverFrame)
self.suit = None self.suit = None
self.suitHead = None self.suitHead = None
self.hide() self.hide()
@ -23,9 +28,11 @@ class TownBattleCogPanel(DirectFrame):
self.levelText.removeNode() self.levelText.removeNode()
self.typeText.removeNode() self.typeText.removeNode()
self.healthBar.delete() self.healthBar.delete()
self.hoverButton.removeNode()
del self.levelText del self.levelText
del self.typeText del self.typeText
del self.healthBar del self.healthBar
del self.hoverButton
DirectFrame.destroy(self) DirectFrame.destroy(self)
def cleanupHead(self): def cleanupHead(self):
@ -46,6 +53,31 @@ class TownBattleCogPanel(DirectFrame):
self.levelText['text'] = TTLocalizer.CogPanelLevel % suit.getActualLevel() self.levelText['text'] = TTLocalizer.CogPanelLevel % suit.getActualLevel()
self.typeText['text'] = suit.getTypeText() self.typeText['text'] = suit.getTypeText()
self.accept(suit.uniqueName('hpChange'), self.updateHealthBar) self.accept(suit.uniqueName('hpChange'), self.updateHealthBar)
self.updateRolloverBind()
def updateRolloverBind(self):
if not self.suit:
return
attributes = SuitBattleGlobals.SuitAttributes[self.suit.getStyleName()]
groupAttacks, singleAttacks = SuitBattleGlobals.getAttacksByType(attributes)
level = self.suit.getLevel()
info = TTLocalizer.BattleCogPopup % (self.getAttackStrings(groupAttacks, level), self.getAttackStrings(singleAttacks, level))
if TTLocalizer.BattleCogPopupDangerColor in info:
info = TTLocalizer.BattleCogPopupDanger + info
self.hoverButton.bind(DGG.ENTER, self.battle.showRolloverFrame, extraArgs=[self, (0.73, 0, 0.65), (0, 0.26), (0.5, 0.5, 0.5, 1), (0.6, 0, 0.1), info])
def getAttackStrings(self, attacks, level):
attackStrings = []
for attack in attacks:
hp = attack[1][level]
attackString = TTLocalizer.BattleCogPopupAttackDanger if self.battle.isAttackDangerous(hp) else TTLocalizer.BattleCogPopupAttack
attackStrings.append(attackString % (TTLocalizer.SuitAttackNames[attack[0]], hp))
return '\n'.join(attackStrings) if attackStrings else TTLocalizer.SuitPageNoAttacks
def generateSuitHead(self, name): def generateSuitHead(self, name):
self.suitHead = Suit.attachSuitHead(self, name) self.suitHead = Suit.attachSuitHead(self, name)

View file

@ -44,9 +44,12 @@ class TownBattleToonPanel(DirectFrame):
self.whichText = DirectLabel(parent=self, text='', pos=(0.1, 0, -0.08), text_scale=0.05) self.whichText = DirectLabel(parent=self, text='', pos=(0.1, 0, -0.08), text_scale=0.05)
self.hoverButton = DirectButton(parent=self, relief=None, image_scale=(0.07, 0, 0.06), pos=(0.105, 0, 0.05), image='phase_3/maps/invisible.png', pressEffect=0) self.hoverButton = DirectButton(parent=self, relief=None, image_scale=(0.07, 0, 0.06), pos=(0.105, 0, 0.05), image='phase_3/maps/invisible.png', pressEffect=0)
self.hoverButton.setTransparency(True) self.hoverButton.setTransparency(True)
self.hoverButton.bind(DGG.EXIT, self.battle.hideToonRolloverFrame) self.hoverButton.bind(DGG.EXIT, self.battle.hideRolloverFrame)
self.hide() self.hide()
gui.removeNode() gui.removeNode()
def hasAvatar(self):
return self.avatar is not None
def setLaffMeter(self, avatar): def setLaffMeter(self, avatar):
self.notify.debug('setLaffMeter: new avatar %s' % avatar.doId) self.notify.debug('setLaffMeter: new avatar %s' % avatar.doId)
@ -138,7 +141,7 @@ class TownBattleToonPanel(DirectFrame):
sosType = TextEncoder.upper(sosType) sosType = TextEncoder.upper(sosType)
count = max(0, self.avatar.getNPCFriendCount(targetIndex) - 1) count = max(0, self.avatar.getNPCFriendCount(targetIndex) - 1)
info = TTLocalizer.BattleSOSPopup % (sosType, NPCToons.getNPCName(targetIndex), hpString if hp else '', rarity, count) info = TTLocalizer.BattleSOSPopup % (sosType, NPCToons.getNPCName(targetIndex), hpString if hp else '', rarity, count)
self.hoverButton.bind(DGG.ENTER, self.showInfo, extraArgs=[(0.5, 0.3, 0.3), (0, 0.08), 0.1, info]) self.hoverButton.bind(DGG.ENTER, self.battle.showRolloverFrame, extraArgs=[self, (0.5, 0.3, 0.3), (0, 0.08), (0.6, 1.0, 0.4, 1), (0.4, 0, 0.1), info])
elif track == BattleBase.SOS or track == BattleBase.PETSOS: elif track == BattleBase.SOS or track == BattleBase.PETSOS:
self.sosText.show() self.sosText.show()
elif track >= MIN_TRACK_INDEX and track <= MAX_TRACK_INDEX: elif track >= MIN_TRACK_INDEX and track <= MAX_TRACK_INDEX:
@ -156,7 +159,7 @@ class TownBattleToonPanel(DirectFrame):
damage = int(getAvPropDamage(track, level, curExp, organic)) damage = int(getAvPropDamage(track, level, curExp, organic))
numItems = max(0, self.avatar.inventory.numItem(track, level) - 1) numItems = max(0, self.avatar.inventory.numItem(track, level) - 1)
info = TTLocalizer.BattleGagPopup % (self.avatar.inventory.getToonupDmgStr(track, 0), damage, numItems) info = TTLocalizer.BattleGagPopup % (self.avatar.inventory.getToonupDmgStr(track, 0), damage, numItems)
self.hoverButton.bind(DGG.ENTER, self.showInfo, extraArgs=[(0.5, 0.3, 0.2), (0, 0.0125), 0, info]) self.hoverButton.bind(DGG.ENTER, self.battle.showRolloverFrame, extraArgs=[self, (0.5, 0.3, 0.2), (0, 0.0125), (0.6, 1.0, 0.4, 1), (0.4, 0, 0), info])
if self.avatar.checkGagBonus(track, level): if self.avatar.checkGagBonus(track, level):
self.gag.setColor((1, 0, 0, 1) if track == 1 and level == 5 else (0, 1, 0, 1)) self.gag.setColor((1, 0, 0, 1) if track == 1 and level == 5 else (0, 1, 0, 1))
@ -176,12 +179,6 @@ class TownBattleToonPanel(DirectFrame):
else: else:
self.notify.error('Bad track value: %s' % track) self.notify.error('Bad track value: %s' % track)
def showInfo(self, scale, textPos, z, text, extra):
self.battle.scaleToonRolloverFrame(scale, textPos, z)
self.battle.toonRolloverFrame.reparentTo(self)
self.battle.toonRolloverFrame.show()
self.battle.toonRolloverFrame['text'] = text
def determineWhichText(self, numTargets, targetIndex, localNum, index): def determineWhichText(self, numTargets, targetIndex, localNum, index):
returnStr = '' returnStr = ''