Poodletooth-iLand/toontown/estate/BankGUI.py

142 lines
7.1 KiB
Python
Raw Normal View History

2015-03-03 16:10:12 -06:00
from direct.gui.DirectGui import *
from pandac.PandaModules import *
2015-04-08 06:51:59 -05:00
from direct.directnotify import DirectNotifyGlobal
2015-03-03 16:10:12 -06:00
from toontown.toonbase import ToontownGlobals
2015-04-08 06:51:59 -05:00
from toontown.toonbase import TTLocalizer
from direct.task.Task import Task
2015-03-03 16:10:12 -06:00
2015-04-08 06:51:59 -05:00
class BankGui(DirectFrame):
notify = DirectNotifyGlobal.directNotify.newCategory('BankGui')
2015-03-03 16:10:12 -06:00
def __init__(self, doneEvent, allowWithdraw = 1):
2015-04-08 06:51:59 -05:00
DirectFrame.__init__(self, relief=None, geom=DGG.getDefaultDialogGeom(), geom_color=ToontownGlobals.GlobalDialogColor, geom_scale=(1.33, 1, 1.1), pos=(0, 0, 0))
self.initialiseoptions(BankGui)
2015-03-03 16:10:12 -06:00
self.doneEvent = doneEvent
self.__transactionAmount = 0
2015-04-08 06:51:59 -05:00
buttons = loader.loadModel('phase_3/models/gui/dialog_box_buttons_gui')
jarGui = loader.loadModel('phase_3.5/models/gui/jar_gui')
2015-03-03 16:10:12 -06:00
arrowGui = loader.loadModel('phase_3/models/gui/create_a_toon_gui')
2015-04-08 06:51:59 -05:00
bankModel = loader.loadModel('phase_5.5/models/estate/jellybeanBank')
bankModel.setDepthWrite(1)
bankModel.setDepthTest(1)
bankModel.find('**/jellybeans').setDepthWrite(0)
bankModel.find('**/jellybeans').setDepthTest(0)
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=TTLocalizer.BankGuiCancel, 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=TTLocalizer.BankGuiOk, text_scale=0.06, text_pos=(0, -0.1), command=self.__requestTransaction)
self.jarDisplay = DirectLabel(parent=self, relief=None, pos=(-0.4, 0, 0), scale=0.7, text=str(base.localAvatar.getMoney()), text_scale=0.2, text_fg=(0.95, 0.95, 0, 1), text_shadow=(0, 0, 0, 1), text_pos=(0, -0.1, 0), image=jarGui.find('**/Jar'), text_font=ToontownGlobals.getSignFont())
self.bankDisplay = DirectLabel(parent=self, relief=None, pos=(0.4, 0, 0), scale=0.9, text=str(base.localAvatar.getBankMoney()), text_scale=0.2, text_fg=(0.95, 0.95, 0, 1), text_shadow=(0, 0, 0, 1), text_pos=(0, -0.1, 0), geom=bankModel, geom_scale=0.08, geom_pos=(0, 10, -0.26), geom_hpr=(0, 0, 0), text_font=ToontownGlobals.getSignFont())
2015-03-03 16:10:12 -06:00
self.depositArrow = 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.01, 0, 0.15))
self.withdrawArrow = 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.01, 0, -0.15))
self.depositArrow.bind(DGG.B1PRESS, self.__depositButtonDown)
self.depositArrow.bind(DGG.B1RELEASE, self.__depositButtonUp)
self.withdrawArrow.bind(DGG.B1PRESS, self.__withdrawButtonDown)
self.withdrawArrow.bind(DGG.B1RELEASE, self.__withdrawButtonUp)
self.accept('bankAsleep', self.__cancel)
self.accept(localAvatar.uniqueName('moneyChange'), self.__moneyChange)
self.accept(localAvatar.uniqueName('bankMoneyChange'), self.__bankMoneyChange)
if allowWithdraw:
self.depositArrow.setPos(0.01, 0, 0.15)
self.withdrawArrow.setPos(-0.01, 0, -0.15)
else:
self.depositArrow.setPos(0, 0, 0)
self.withdrawArrow.hide()
2015-04-08 06:51:59 -05:00
buttons.removeNode()
2015-03-03 16:10:12 -06:00
jarGui.removeNode()
arrowGui.removeNode()
self.__updateTransaction(0)
2015-04-08 06:51:59 -05:00
return
2015-03-03 16:10:12 -06:00
def destroy(self):
taskMgr.remove(self.taskName('runCounter'))
self.ignore(localAvatar.uniqueName('moneyChange'))
self.ignore(localAvatar.uniqueName('bankMoneyChange'))
DirectFrame.destroy(self)
def __cancel(self):
messenger.send(self.doneEvent, [0])
def __requestTransaction(self):
messenger.send(self.doneEvent, [self.__transactionAmount])
def __updateTransaction(self, amount):
hitLimit = 0
self.__transactionAmount += amount
jarMoney = base.localAvatar.getMoney()
maxJarMoney = base.localAvatar.getMaxMoney()
bankMoney = base.localAvatar.getBankMoney()
2015-04-08 06:51:59 -05:00
maxBankMoney = base.localAvatar.getMaxBankMoney()
2015-03-03 16:10:12 -06:00
self.__transactionAmount = min(self.__transactionAmount, jarMoney)
self.__transactionAmount = min(self.__transactionAmount, maxBankMoney - bankMoney)
self.__transactionAmount = -min(-self.__transactionAmount, maxJarMoney - jarMoney)
self.__transactionAmount = -min(-self.__transactionAmount, bankMoney)
newJarMoney = jarMoney - self.__transactionAmount
newBankMoney = bankMoney + self.__transactionAmount
if newJarMoney <= 0 or newBankMoney >= maxBankMoney:
self.depositArrow['state'] = DGG.DISABLED
hitLimit = 1
else:
self.depositArrow['state'] = DGG.NORMAL
if newBankMoney <= 0 or newJarMoney >= maxJarMoney:
self.withdrawArrow['state'] = DGG.DISABLED
hitLimit = 1
else:
self.withdrawArrow['state'] = DGG.NORMAL
self.jarDisplay['text'] = str(newJarMoney)
self.bankDisplay['text'] = str(newBankMoney)
2015-04-08 06:51:59 -05:00
return (hitLimit,
newJarMoney,
newBankMoney,
self.__transactionAmount)
2015-03-03 16:10:12 -06:00
def __runCounter(self, task):
if task.time - task.prevTime < task.delayTime:
return Task.cont
2015-04-08 06:51:59 -05:00
else:
task.delayTime = max(0.05, task.delayTime * 0.75)
task.prevTime = task.time
hitLimit, jar, bank, trans = self.__updateTransaction(task.delta)
if hitLimit:
return Task.done
else:
return Task.cont
2015-03-03 16:10:12 -06:00
def __depositButtonUp(self, event):
messenger.send('wakeup')
taskMgr.remove(self.taskName('runCounter'))
def __depositButtonDown(self, event):
messenger.send('wakeup')
task = Task(self.__runCounter)
2015-04-08 06:51:59 -05:00
task.delayTime = 0.4
2015-03-03 16:10:12 -06:00
task.prevTime = 0.0
2015-04-08 06:51:59 -05:00
task.delta = 1
hitLimit, jar, bank, trans = self.__updateTransaction(task.delta)
2015-03-03 16:10:12 -06:00
if not hitLimit:
taskMgr.add(task, self.taskName('runCounter'))
def __withdrawButtonUp(self, event):
messenger.send('wakeup')
taskMgr.remove(self.taskName('runCounter'))
def __withdrawButtonDown(self, event):
messenger.send('wakeup')
task = Task(self.__runCounter)
2015-04-08 06:51:59 -05:00
task.delayTime = 0.4
2015-03-03 16:10:12 -06:00
task.prevTime = 0.0
2015-04-08 06:51:59 -05:00
task.delta = -1
hitLimit, jar, bank, trans = self.__updateTransaction(task.delta)
2015-03-03 16:10:12 -06:00
if not hitLimit:
taskMgr.add(task, self.taskName('runCounter'))
def __moneyChange(self, money):
self.__updateTransaction(0)
def __bankMoneyChange(self, bankMoney):
self.__updateTransaction(0)