From a54cbc87781feda3e818d281a466d8a66c8b8389 Mon Sep 17 00:00:00 2001 From: John Date: Mon, 17 Aug 2015 12:42:39 +0300 Subject: [PATCH] Cog hover panel in battle gui --- toontown/battle/SuitBattleGlobals.py | 16 +++++++++++- toontown/shtiker/SuitPage.py | 14 ++-------- toontown/toonbase/TTLocalizerEnglish.py | 8 +++++- toontown/town/TownBattle.py | 33 ++++++++++++++++-------- toontown/town/TownBattleCogPanel.py | 34 ++++++++++++++++++++++++- toontown/town/TownBattleToonPanel.py | 15 +++++------ 6 files changed, 85 insertions(+), 35 deletions(-) diff --git a/toontown/battle/SuitBattleGlobals.py b/toontown/battle/SuitBattleGlobals.py index 54433c01..df0c9b73 100755 --- a/toontown/battle/SuitBattleGlobals.py +++ b/toontown/battle/SuitBattleGlobals.py @@ -3170,4 +3170,18 @@ def getAttackTaunt(attackName, index = None): SuitAttackTaunts = TTLocalizer.SuitAttackTaunts -DisabledAttacks = ('Gavel', 'SongAndDance', 'SandTrap', 'FloodTheMarket', 'FiveOClockShadow') \ No newline at end of file +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 \ No newline at end of file diff --git a/toontown/shtiker/SuitPage.py b/toontown/shtiker/SuitPage.py index 73e93e49..cd853cd3 100755 --- a/toontown/shtiker/SuitPage.py +++ b/toontown/shtiker/SuitPage.py @@ -488,19 +488,9 @@ class SuitPage(ShtikerPage.ShtikerPage): name = SuitDNA.suitHeadTypes[index] attributes = SuitBattleGlobals.SuitAttributes[name] level = attributes['level'] - attacks = sorted(attributes['attacks'], key=lambda x: x[0]) - 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) - + groupAttacks, singleAttacks = SuitBattleGlobals.getAttacksByType(attributes) 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.EXIT, self.hideInfo) diff --git a/toontown/toonbase/TTLocalizerEnglish.py b/toontown/toonbase/TTLocalizerEnglish.py index a6563639..5ecdb9d3 100755 --- a/toontown/toonbase/TTLocalizerEnglish.py +++ b/toontown/toonbase/TTLocalizerEnglish.py @@ -8726,7 +8726,13 @@ ShardPageTeleport = 'Teleport to\n%s' 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' BattleGagPopup = '%s: %s\nGags left: %s' diff --git a/toontown/town/TownBattle.py b/toontown/town/TownBattle.py index 7b949a3a..4bcd0870 100755 --- a/toontown/town/TownBattle.py +++ b/toontown/town/TownBattle.py @@ -122,11 +122,11 @@ class TownBattle(StateData.StateData): self.SOSPetInfoPanel = TownBattleSOSPetInfoPanel.TownBattleSOSPetInfoPanel(self.SOSPetInfoPanelDoneEvent) self.fireCogPanelDoneEvent = 'fire-cog-panel-done' 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.toonRolloverFrame.setBin('gui-popup', 0) - self.toonRolloverFrame.hide() + 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.rolloverFrame.setBin('gui-popup', 0) + self.rolloverFrame.hide() 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.posInTopRightCorner() self.timer.setScale(0.4) @@ -146,7 +146,7 @@ class TownBattle(StateData.StateData): del self.FireCogPanel del self.SOSPetSearchPanel del self.SOSPetInfoPanel - del self.toonRolloverFrame + del self.rolloverFrame for panel in self.toonPanels + self.cogPanels: panel.cleanup() @@ -219,13 +219,22 @@ class TownBattle(StateData.StateData): self.timer.setTime(time) return None - def scaleToonRolloverFrame(self, scale, textPos, z): - self.toonRolloverFrame['geom_scale'] = scale - self.toonRolloverFrame['text_pos'] = textPos - self.toonRolloverFrame.setZ(z) + def showRolloverFrame(self, parent, scale, textPos, color, pos, text, extra=None): + self.rolloverFrame['geom_scale'] = scale + self.rolloverFrame['text_pos'] = textPos + 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): - self.toonRolloverFrame.hide() + def hideRolloverFrame(self, extra=None): + 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): self.notify.debug('enterPanels() num: %d localNum: %d' % (num, localNum)) @@ -239,6 +248,7 @@ class TownBattle(StateData.StateData): for cogPanel in self.cogPanels: cogPanel.hide() cogPanel.updateHealthBar() + cogPanel.updateRolloverBind() cogPanel.setPos(0, 0, 0.62) self.positionPanels(num, self.cogPanels) @@ -448,6 +458,7 @@ class TownBattle(StateData.StateData): self.numToons = len(toons) self.localNum = toons.index(base.localAvatar) currStateName = self.fsm.getCurrentState().getName() + if resetActivateMode: self.__enterPanels(self.numToons, self.localNum) for i in xrange(len(toons)): diff --git a/toontown/town/TownBattleCogPanel.py b/toontown/town/TownBattleCogPanel.py index f68b00c7..48c4bffe 100755 --- a/toontown/town/TownBattleCogPanel.py +++ b/toontown/town/TownBattleCogPanel.py @@ -1,17 +1,22 @@ from direct.gui.DirectGui import * +from toontown.battle import SuitBattleGlobals from toontown.suit import Suit, SuitHealthBar from toontown.toonbase import TTLocalizer class TownBattleCogPanel(DirectFrame): - def __init__(self, id): + def __init__(self, battle): 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) self.initialiseoptions(TownBattleCogPanel) + self.battle = battle 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.healthBar = SuitHealthBar.SuitHealthBar() 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.suitHead = None self.hide() @@ -23,9 +28,11 @@ class TownBattleCogPanel(DirectFrame): self.levelText.removeNode() self.typeText.removeNode() self.healthBar.delete() + self.hoverButton.removeNode() del self.levelText del self.typeText del self.healthBar + del self.hoverButton DirectFrame.destroy(self) def cleanupHead(self): @@ -46,6 +53,31 @@ class TownBattleCogPanel(DirectFrame): self.levelText['text'] = TTLocalizer.CogPanelLevel % suit.getActualLevel() self.typeText['text'] = suit.getTypeText() 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): self.suitHead = Suit.attachSuitHead(self, name) diff --git a/toontown/town/TownBattleToonPanel.py b/toontown/town/TownBattleToonPanel.py index aab508f1..de6426f4 100755 --- a/toontown/town/TownBattleToonPanel.py +++ b/toontown/town/TownBattleToonPanel.py @@ -44,9 +44,12 @@ class TownBattleToonPanel(DirectFrame): 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.setTransparency(True) - self.hoverButton.bind(DGG.EXIT, self.battle.hideToonRolloverFrame) + self.hoverButton.bind(DGG.EXIT, self.battle.hideRolloverFrame) self.hide() gui.removeNode() + + def hasAvatar(self): + return self.avatar is not None def setLaffMeter(self, avatar): self.notify.debug('setLaffMeter: new avatar %s' % avatar.doId) @@ -138,7 +141,7 @@ class TownBattleToonPanel(DirectFrame): sosType = TextEncoder.upper(sosType) count = max(0, self.avatar.getNPCFriendCount(targetIndex) - 1) 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: self.sosText.show() elif track >= MIN_TRACK_INDEX and track <= MAX_TRACK_INDEX: @@ -156,7 +159,7 @@ class TownBattleToonPanel(DirectFrame): damage = int(getAvPropDamage(track, level, curExp, organic)) numItems = max(0, self.avatar.inventory.numItem(track, level) - 1) 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): 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: 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): returnStr = ''