an even more amazing GUI

This commit is contained in:
Zach 2015-05-12 03:10:49 -05:00
parent b491ff1cfe
commit 861909b881
7 changed files with 211 additions and 64 deletions

View file

@ -1959,7 +1959,7 @@ dclass DistributedNPCKartClerk : DistributedNPCToonBase {
dclass DistributedNPCLaffRestock : DistributedNPCToonBase { dclass DistributedNPCLaffRestock : DistributedNPCToonBase {
setMovie(uint8, uint32, uint32, uint32[], int16) broadcast ram; setMovie(uint8, uint32, uint32, uint32[], int16) broadcast ram;
restock(uint32, uint8) airecv clsend; restock(uint32, uint8, uint8) airecv clsend;
transactionDone() airecv clsend; transactionDone() airecv clsend;
}; };

View file

@ -2,7 +2,7 @@
from pandac.PandaModules import * 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 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

View file

@ -92,8 +92,8 @@ class DistributedNPCLaffRestock(DistributedNPCToonBase):
self.setChatAbsolute(TTLocalizer.RestockNoMoneyMessage, CFSpeech | CFTimeout) self.setChatAbsolute(TTLocalizer.RestockNoMoneyMessage, CFSpeech | CFTimeout)
self.resetLaffClerk() self.resetLaffClerk()
def __handleRestock(self, cost): def __handleRestock(self, laff, cost):
self.sendUpdate('restock', [self.av.doId, cost]) self.sendUpdate('restock', [self.av.doId, laff, cost])
def __handleGuiDone(self, bTimedOut=False): def __handleGuiDone(self, bTimedOut=False):
self.ignoreAll() self.ignoreAll()
@ -107,5 +107,4 @@ class DistributedNPCLaffRestock(DistributedNPCToonBase):
self.setChatAbsolute('', CFSpeech) self.setChatAbsolute('', CFSpeech)
self.accept('restockLaff', self.__handleRestock) self.accept('restockLaff', self.__handleRestock)
self.acceptOnce('guiDone', self.__handleGuiDone) self.acceptOnce('guiDone', self.__handleGuiDone)
self.laffGui = LaffShopGui(text=TTLocalizer.RestockAskMessage % (laff, cost), self.laffGui = LaffShopGui(text=TTLocalizer.RestockAskMessage % (laff, cost))
extraArgs=[cost])

View file

@ -81,7 +81,7 @@ class DistributedNPCLaffRestockAI(DistributedNPCToonBaseAI):
self.d_setMovie(0, NPCToons.SELL_MOVIE_CLEAR) self.d_setMovie(0, NPCToons.SELL_MOVIE_CLEAR)
return Task.done return Task.done
def restock(self, avId, cost): def restock(self, avId, laff, cost):
sendAvId = self.air.getAvatarIdFromSender() sendAvId = self.air.getAvatarIdFromSender()
if self.busy != avId: if self.busy != avId:
self.air.writeServerEvent('suspicious', avId, 'DistributedNPCLaffRestockAI.restock busy with %s' % self.busy) self.air.writeServerEvent('suspicious', avId, 'DistributedNPCLaffRestockAI.restock busy with %s' % self.busy)
@ -91,4 +91,4 @@ class DistributedNPCLaffRestockAI(DistributedNPCToonBaseAI):
if av: if av:
movieType = NPCToons.SELL_MOVIE_COMPLETE movieType = NPCToons.SELL_MOVIE_COMPLETE
av.takeMoney(cost) av.takeMoney(cost)
av.b_setHp(av.getMaxHp()) av.b_setHp(av.getHp() + laff)

View file

@ -2,3 +2,5 @@ LAFFCLERK_TIMER = 30
FullLaff = 12 FullLaff = 12
NoMoney = 14 NoMoney = 14
Success = 1 Success = 1
GuiOk = 'Ok'
GuiCancel = 'Cancel'

View file

@ -4,31 +4,120 @@ from direct.gui.DirectGui import *
from direct.showbase import DirectObject from direct.showbase import DirectObject
from toontown.toonbase import ToontownGlobals from toontown.toonbase import ToontownGlobals
from toontown.toonbase import TTLocalizer from toontown.toonbase import TTLocalizer
from direct.task.Task import Task
from toontown.toonbase import ToontownTimer from toontown.toonbase import ToontownTimer
from toontown.toontowngui import TTDialog
import LaffRestockGlobals import LaffRestockGlobals
from LaffMeter import LaffMeter
class LaffShopGui(object, DirectObject.DirectObject): class LaffShopGui(DirectFrame):
notify = DirectNotifyGlobal.directNotify.newCategory('LaffShopGui')
def __init__(self, **kw): def __init__(self, text):
self.dialog = None DirectFrame.__init__(
self.timer = None 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 = ToontownTimer.ToontownTimer()
self.timer.reparentTo(aspect2d) self.timer.reparentTo(aspect2d)
self.timer.posInTopRightCorner() self.timer.posInTopRightCorner()
self.timer.accept('RESET_LAFFSHOP_TIMER', self.__resetTimer) self.timer.accept('RESET_LAFFSHOP_TIMER', self.__resetTimer)
self.timer.countdown(LaffRestockGlobals.LAFFCLERK_TIMER, self.__timerExpired) self.timer.countdown(LaffRestockGlobals.LAFFCLERK_TIMER, self.__timerExpired)
self.__doDialog(**kw) 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): def destroy(self):
self.ignoreAll() self.ignoreAll()
if self.timer: if self.timer:
self.timer.destroy() self.timer.destroy()
self.timer = None taskMgr.remove(self.taskName('runCounter'))
if self.dialog: DirectFrame.destroy(self)
self.dialog.destroy()
self.dialog = None
def __resetTimer(self): def __resetTimer(self):
if self.timer: if self.timer:
@ -36,20 +125,77 @@ class LaffShopGui(object, DirectObject.DirectObject):
self.timer.countdown(LaffRestockGlobals.LAFFCLERK_TIMER, self.__timerExpired) self.timer.countdown(LaffRestockGlobals.LAFFCLERK_TIMER, self.__timerExpired)
def __timerExpired(self): def __timerExpired(self):
self.destroy()
messenger.send('guiDone', [True]) messenger.send('guiDone', [True])
def __destroyDialog(self, resp, cost): def __cancel(self):
if self.timer: self.destroy()
self.ignoreAll()
if self.dialog:
self.dialog.destroy()
self.dialog = None
if resp == LaffRestockGlobals.Success:
messenger.send('restockLaff', [cost])
messenger.send('guiDone', [False]) messenger.send('guiDone', [False])
def __doDialog(self, **kw): def __requestLaff(self):
self.dialog = TTDialog.TTDialog(style=TTDialog.YesNo, if self.timer:
command=self.__destroyDialog, self.ignoreAll()
**kw) self.destroy()
self.dialog.show() 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'))

View file

@ -8449,4 +8449,4 @@ FireTalkMessage = "You're fired!"
RestockFullLaffMessage = "You're already happy!" RestockFullLaffMessage = "You're already happy!"
RestockNoMoneyMessage = "You need more jellybeans to restock your laff!" RestockNoMoneyMessage = "You need more jellybeans to restock your laff!"
RestockLaffMessage = "Have fun!" 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?"