From 861909b881dff3a46ff5610a58a6f3bea376d3ae Mon Sep 17 00:00:00 2001 From: Zach Date: Tue, 12 May 2015 03:10:49 -0500 Subject: [PATCH] an even more amazing GUI --- astron/dclass/united.dc | 2 +- otp/distributed/DCClassImports.py | 2 +- toontown/toon/DistributedNPCLaffRestock.py | 7 +- toontown/toon/DistributedNPCLaffRestockAI.py | 4 +- toontown/toon/LaffRestockGlobals.py | 2 + toontown/toon/LaffShopGui.py | 256 +++++++++++++++---- toontown/toonbase/TTLocalizerEnglish.py | 2 +- 7 files changed, 211 insertions(+), 64 deletions(-) diff --git a/astron/dclass/united.dc b/astron/dclass/united.dc index 6741f6d1..32d4c7be 100644 --- a/astron/dclass/united.dc +++ b/astron/dclass/united.dc @@ -1959,7 +1959,7 @@ dclass DistributedNPCKartClerk : DistributedNPCToonBase { dclass DistributedNPCLaffRestock : DistributedNPCToonBase { setMovie(uint8, uint32, uint32, uint32[], int16) broadcast ram; - restock(uint32, uint8) airecv clsend; + restock(uint32, uint8, uint8) airecv clsend; transactionDone() airecv clsend; }; diff --git a/otp/distributed/DCClassImports.py b/otp/distributed/DCClassImports.py index b8998e9d..af0035b3 100644 --- a/otp/distributed/DCClassImports.py +++ b/otp/distributed/DCClassImports.py @@ -2,7 +2,7 @@ from pandac.PandaModules import * -hashVal = 630664315 +hashVal = 2180409862L from toontown.coghq import DistributedCashbotBossSafe, DistributedCashbotBossCrane, DistributedBattleFactory, DistributedCashbotBossTreasure, DistributedCogHQDoor, DistributedSellbotHQDoor, DistributedFactoryElevatorExt, DistributedMintElevatorExt, DistributedLawOfficeElevatorExt, DistributedLawOfficeElevatorInt, LobbyManager, DistributedMegaCorp, DistributedFactory, DistributedLawOffice, DistributedLawOfficeFloor, DistributedLift, DistributedDoorEntity, DistributedSwitch, DistributedButton, DistributedTrigger, DistributedCrushableEntity, DistributedCrusherEntity, DistributedStomper, DistributedStomperPair, DistributedLaserField, DistributedGolfGreenGame, DistributedSecurityCamera, DistributedMover, DistributedElevatorMarker, DistributedBarrelBase, DistributedGagBarrel, DistributedBeanBarrel, DistributedHealBarrel, DistributedGrid, ActiveCell, DirectionalCell, CrusherCell, DistributedCrate, DistributedSinkingPlatform, BattleBlocker, DistributedMint, DistributedMintRoom, DistributedMintBattle, DistributedStage, DistributedStageRoom, DistributedStageBattle, DistributedLawbotBossGavel, DistributedLawbotCannon, DistributedLawbotChair, DistributedCogKart, DistributedCountryClub, DistributedCountryClubRoom, DistributedMoleField, DistributedCountryClubBattle, DistributedMaze, DistributedFoodBelt, DistributedBanquetTable, DistributedGolfSpot diff --git a/toontown/toon/DistributedNPCLaffRestock.py b/toontown/toon/DistributedNPCLaffRestock.py index f1d65b2d..4dc05f14 100644 --- a/toontown/toon/DistributedNPCLaffRestock.py +++ b/toontown/toon/DistributedNPCLaffRestock.py @@ -92,8 +92,8 @@ class DistributedNPCLaffRestock(DistributedNPCToonBase): self.setChatAbsolute(TTLocalizer.RestockNoMoneyMessage, CFSpeech | CFTimeout) self.resetLaffClerk() - def __handleRestock(self, cost): - self.sendUpdate('restock', [self.av.doId, cost]) + def __handleRestock(self, laff, cost): + self.sendUpdate('restock', [self.av.doId, laff, cost]) def __handleGuiDone(self, bTimedOut=False): self.ignoreAll() @@ -107,5 +107,4 @@ class DistributedNPCLaffRestock(DistributedNPCToonBase): self.setChatAbsolute('', CFSpeech) self.accept('restockLaff', self.__handleRestock) self.acceptOnce('guiDone', self.__handleGuiDone) - self.laffGui = LaffShopGui(text=TTLocalizer.RestockAskMessage % (laff, cost), - extraArgs=[cost]) + self.laffGui = LaffShopGui(text=TTLocalizer.RestockAskMessage % (laff, cost)) diff --git a/toontown/toon/DistributedNPCLaffRestockAI.py b/toontown/toon/DistributedNPCLaffRestockAI.py index 70a1d815..7799375d 100644 --- a/toontown/toon/DistributedNPCLaffRestockAI.py +++ b/toontown/toon/DistributedNPCLaffRestockAI.py @@ -81,7 +81,7 @@ class DistributedNPCLaffRestockAI(DistributedNPCToonBaseAI): self.d_setMovie(0, NPCToons.SELL_MOVIE_CLEAR) return Task.done - def restock(self, avId, cost): + def restock(self, avId, laff, cost): sendAvId = self.air.getAvatarIdFromSender() if self.busy != avId: self.air.writeServerEvent('suspicious', avId, 'DistributedNPCLaffRestockAI.restock busy with %s' % self.busy) @@ -91,4 +91,4 @@ class DistributedNPCLaffRestockAI(DistributedNPCToonBaseAI): if av: movieType = NPCToons.SELL_MOVIE_COMPLETE av.takeMoney(cost) - av.b_setHp(av.getMaxHp()) + av.b_setHp(av.getHp() + laff) diff --git a/toontown/toon/LaffRestockGlobals.py b/toontown/toon/LaffRestockGlobals.py index 91f9a70a..ecd817b9 100644 --- a/toontown/toon/LaffRestockGlobals.py +++ b/toontown/toon/LaffRestockGlobals.py @@ -2,3 +2,5 @@ LAFFCLERK_TIMER = 30 FullLaff = 12 NoMoney = 14 Success = 1 +GuiOk = 'Ok' +GuiCancel = 'Cancel' diff --git a/toontown/toon/LaffShopGui.py b/toontown/toon/LaffShopGui.py index 7e32e8fd..513b2122 100644 --- a/toontown/toon/LaffShopGui.py +++ b/toontown/toon/LaffShopGui.py @@ -1,55 +1,201 @@ -from pandac.PandaModules import * -from direct.directnotify import DirectNotifyGlobal -from direct.gui.DirectGui import * -from direct.showbase import DirectObject -from toontown.toonbase import ToontownGlobals -from toontown.toonbase import TTLocalizer -from toontown.toonbase import ToontownTimer -from toontown.toontowngui import TTDialog -import LaffRestockGlobals - -class LaffShopGui(object, DirectObject.DirectObject): - notify = DirectNotifyGlobal.directNotify.newCategory('LaffShopGui') - - def __init__(self, **kw): - self.dialog = None - self.timer = None - self.timer = ToontownTimer.ToontownTimer() - self.timer.reparentTo(aspect2d) - self.timer.posInTopRightCorner() - self.timer.accept('RESET_LAFFSHOP_TIMER', self.__resetTimer) - self.timer.countdown(LaffRestockGlobals.LAFFCLERK_TIMER, self.__timerExpired) - self.__doDialog(**kw) - - def destroy(self): - self.ignoreAll() - if self.timer: - self.timer.destroy() - self.timer = None - if self.dialog: - self.dialog.destroy() - self.dialog = None - - def __resetTimer(self): - if self.timer: - self.timer.stop() - self.timer.countdown(LaffRestockGlobals.LAFFCLERK_TIMER, self.__timerExpired) - - def __timerExpired(self): - messenger.send('guiDone', [True]) - - def __destroyDialog(self, resp, cost): - if self.timer: - self.ignoreAll() - if self.dialog: - self.dialog.destroy() - self.dialog = None - if resp == LaffRestockGlobals.Success: - messenger.send('restockLaff', [cost]) - messenger.send('guiDone', [False]) - - def __doDialog(self, **kw): - self.dialog = TTDialog.TTDialog(style=TTDialog.YesNo, - command=self.__destroyDialog, - **kw) - self.dialog.show() +from pandac.PandaModules import * +from direct.directnotify import DirectNotifyGlobal +from direct.gui.DirectGui import * +from direct.showbase import DirectObject +from toontown.toonbase import ToontownGlobals +from toontown.toonbase import TTLocalizer +from direct.task.Task import Task +from toontown.toonbase import ToontownTimer +import LaffRestockGlobals +from LaffMeter import LaffMeter + +class LaffShopGui(DirectFrame): + + def __init__(self, text): + DirectFrame.__init__( + self, + parent=aspect2d, + relief=None, + geom=DGG.getDefaultDialogGeom(), + geom_color=ToontownGlobals.GlobalDialogColor, + geom_scale=(1.33, 1, 1.1), + pos=(0, 0, 0), + text=text, + text_scale=0.07, + text_pos=(0, 0.475), + ) + self.initialiseoptions(LaffShopGui) + self.text = text + self.timer = ToontownTimer.ToontownTimer() + self.timer.reparentTo(aspect2d) + self.timer.posInTopRightCorner() + self.timer.accept('RESET_LAFFSHOP_TIMER', self.__resetTimer) + self.timer.countdown(LaffRestockGlobals.LAFFCLERK_TIMER, self.__timerExpired) + self.hp = base.localAvatar.getHp() + self.maxHp = base.localAvatar.getMaxHp() + self.floorLimit = self.hp + self.ceilLimit = 0 + money = base.localAvatar.getTotalMoney() + while self.ceilLimit * ToontownGlobals.CostPerLaffRestock < money: + self.ceilLimit += 1 + self.__additionalLaff = 0 + self.__setupButtons() + self.__bindButtons() + self.laffMeter = LaffMeter(base.localAvatar.style, self.hp, self.maxHp) + self.laffMeter.reparentTo(self) + self.laffMeter.setPos(0, 0, 0.15) + self.laffMeter.setScale(0.13) + self.__updateLaffMeter(0) + + def __setupButtons(self): + buttons = loader.loadModel('phase_3/models/gui/dialog_box_buttons_gui') + arrowGui = loader.loadModel('phase_3/models/gui/create_a_toon_gui') + okImageList = ( + buttons.find('**/ChtBx_OKBtn_UP'), + buttons.find('**/ChtBx_OKBtn_DN'), + buttons.find('**/ChtBx_OKBtn_Rllvr'), + ) + cancelImageList = ( + buttons.find('**/CloseBtn_UP'), + buttons.find('**/CloseBtn_DN'), + buttons.find('**/CloseBtn_Rllvr'), + ) + arrowImageList = ( + arrowGui.find('**/CrtATn_R_Arrow_UP'), + arrowGui.find('**/CrtATn_R_Arrow_DN'), + arrowGui.find('**/CrtATn_R_Arrow_RLVR'), + arrowGui.find('**/CrtATn_R_Arrow_UP'), + ) + self.cancelButton = DirectButton( + parent=self, + relief=None, + image=cancelImageList, + pos=(-0.2, 0, -0.4), + text=LaffRestockGlobals.GuiCancel, + text_scale=0.06, + text_pos=(0, -0.1), + command=self.__cancel, + ) + self.okButton = DirectButton( + parent=self, + relief=None, + image=okImageList, + pos=(0.2, 0, -0.4), + text=LaffRestockGlobals.GuiOk, + text_scale=0.06, + text_pos=(0, -0.1), + command=self.__requestLaff, + extraArgs=[], + ) + self.upArrow = DirectButton( + parent=self, + relief=None, + image=arrowImageList, + image_scale=(1, 1, 1), + image3_color=Vec4(0.6, 0.6, 0.6, 0.25), + pos=(0.2, 0, -0.165), + ) + self.downArrow = DirectButton( + parent=self, + relief=None, + image=arrowImageList, + image_scale=(-1, 1, 1), + image3_color=Vec4(0.6, 0.6, 0.6, 0.25), + pos=(-0.2, 0, -0.165), + ) + buttons.removeNode() + arrowGui.removeNode() + + def __bindButtons(self): + self.downArrow.bind(DGG.B1PRESS, self.__downButtonDown) + self.downArrow.bind(DGG.B1RELEASE, self.__downButtonUp) + self.upArrow.bind(DGG.B1PRESS, self.__upButtonDown) + self.upArrow.bind(DGG.B1RELEASE, self.__upButtonUp) + + def destroy(self): + self.ignoreAll() + if self.timer: + self.timer.destroy() + taskMgr.remove(self.taskName('runCounter')) + DirectFrame.destroy(self) + + def __resetTimer(self): + if self.timer: + self.timer.stop() + self.timer.countdown(LaffRestockGlobals.LAFFCLERK_TIMER, self.__timerExpired) + + def __timerExpired(self): + self.destroy() + messenger.send('guiDone', [True]) + + def __cancel(self): + self.destroy() + messenger.send('guiDone', [False]) + + def __requestLaff(self): + if self.timer: + self.ignoreAll() + self.destroy() + cost = self.__additionalLaff * ToontownGlobals.CostPerLaffRestock + messenger.send('restockLaff', [self.__additionalLaff, cost]) + messenger.send('guiDone', [False]) + + def __updateLaffMeter(self, amt): + hitLimit = 0 + self.__additionalLaff += amt + newLaff = self.hp + self.__additionalLaff + cost = self.__additionalLaff * ToontownGlobals.CostPerLaffRestock + if newLaff <= self.floorLimit: + self.downArrow['state'] = DGG.DISABLED + hitLimit = 1 + else: + self.downArrow['state'] = DGG.NORMAL + if newLaff >= self.maxHp or self.__additionalLaff >= self.ceilLimit: + self.upArrow['state'] = DGG.DISABLED + hitLimit = 1 + else: + self.upArrow['state'] = DGG.NORMAL + self['text'] = TTLocalizer.RestockAskMessage % (self.__additionalLaff, cost) + self.laffMeter.hp = newLaff + self.laffMeter.start() + return (hitLimit, newLaff, self.__additionalLaff) + + def __runCounter(self, task): + if task.time - task.prevTime < task.delayTime: + return Task.cont + else: + task.delayTime = max(0.05, task.delayTime * 0.75) + task.prevTime = task.time + hitLimit, laff, trans = self.__updateLaffMeter(task.delta) + if hitLimit: + return Task.done + else: + return Task.cont + + def __downButtonUp(self, event): + messenger.send('wakeup') + taskMgr.remove(self.taskName('runCounter')) + + def __downButtonDown(self, event): + messenger.send('wakeup') + task = Task(self.__runCounter) + task.delayTime = 0.4 + task.prevTime = 0.0 + task.delta = -1 + hitLimit, laff, trans = self.__updateLaffMeter(task.delta) + if not hitLimit: + taskMgr.add(task, self.taskName('runCounter')) + + def __upButtonUp(self, event): + messenger.send('wakeup') + taskMgr.remove(self.taskName('runCounter')) + + def __upButtonDown(self, event): + messenger.send('wakeup') + task = Task(self.__runCounter) + task.delayTime = 0.4 + task.prevTime = 0.0 + task.delta = 1 + hitLimit, laff, trans = self.__updateLaffMeter(task.delta) + if not hitLimit: + taskMgr.add(task, self.taskName('runCounter')) diff --git a/toontown/toonbase/TTLocalizerEnglish.py b/toontown/toonbase/TTLocalizerEnglish.py index ce074fd9..c6e06ced 100644 --- a/toontown/toonbase/TTLocalizerEnglish.py +++ b/toontown/toonbase/TTLocalizerEnglish.py @@ -8449,4 +8449,4 @@ FireTalkMessage = "You're fired!" RestockFullLaffMessage = "You're already happy!" RestockNoMoneyMessage = "You need more jellybeans to restock your laff!" RestockLaffMessage = "Have fun!" -RestockAskMessage = "Would you like to restock %s laff for %s jellybeans?" +RestockAskMessage = "Would you like to\nrestock %s laff for %s jellybeans?"