Poodletooth-iLand/toontown/minigame/MinigameRulesPanel.py

70 lines
3.5 KiB
Python
Raw Normal View History

2015-03-03 16:10:12 -06:00
from direct.task import Task
from direct.fsm import StateData
from toontown.toonbase.ToontownGlobals import *
from direct.gui.DirectGui import *
from panda3d.core import *
2015-03-03 16:10:12 -06:00
from toontown.toonbase import ToontownTimer
from toontown.toonbase import TTLocalizer
import MinigameGlobals
class MinigameRulesPanel(StateData.StateData):
2015-06-21 14:09:31 -05:00
def __init__(self, panelName, gameTitle, instructions, doneEvent, timeout = MinigameGlobals.rulesDuration, playerCount = 0):
2015-03-03 16:10:12 -06:00
StateData.StateData.__init__(self, doneEvent)
self.gameTitle = gameTitle
self.instructions = instructions
self.TIMEOUT = timeout
2015-06-21 14:09:31 -05:00
self.playerCount = playerCount
2015-03-03 16:10:12 -06:00
def load(self):
minigameGui = loader.loadModel('phase_4/models/gui/minigame_rules_gui')
buttonGui = loader.loadModel('phase_3.5/models/gui/inventory_gui')
2015-06-21 14:09:31 -05:00
buttonImage = (buttonGui.find('**/InventoryButtonUp'), buttonGui.find('**/InventoryButtonDown'), buttonGui.find('**/InventoryButtonRollover'))
2015-03-03 16:10:12 -06:00
self.frame = DirectFrame(image=minigameGui.find('**/minigame-rules-panel'), relief=None, pos=(0.1375, 0, -0.6667))
self.gameTitleText = DirectLabel(parent=self.frame, text=self.gameTitle, scale=TTLocalizer.MRPgameTitleText, text_align=TextNode.ACenter, text_font=getSignFont(), text_fg=(1.0, 0.33, 0.33, 1.0), pos=TTLocalizer.MRgameTitleTextPos, relief=None)
self.instructionsText = DirectLabel(parent=self.frame, text=self.instructions, scale=TTLocalizer.MRPinstructionsText, text_align=TextNode.ACenter, text_wordwrap=TTLocalizer.MRPinstructionsTextWordwrap, pos=TTLocalizer.MRPinstructionsTextPos, relief=None)
2015-06-21 14:09:31 -05:00
self.playButton = DirectButton(parent=self.frame, relief=None, image=buttonImage, image_color=Vec4(0, 0.9, 0.1, 1), text=TTLocalizer.MinigameRulesPanelPlay, text_fg=(1, 1, 1, 1), text_pos=(0, -0.02, 0), text_scale=TTLocalizer.MRPplayButton, pos=(1.0025, 0, -0.203), scale=1.05, command=self.playCallback)
if self.playerCount:
self.skipButton = DirectButton(parent=self.frame, relief=None, image=buttonImage, image_color=Vec4(0, 0.9, 0.1, 1), text=TTLocalizer.MinigameRulesPanelSkip % (0, self.playerCount), text_fg=(1, 1, 1, 1), text_pos=(0, 0.01, 0), text_scale=0.045, pos=(0, 0, 0.25), scale=1.05, command=self.skipCallback)
self.acceptOnce('disableMinigameSkip', self.skipButton.hide)
self.accept('gameSkipCountChange', self.updateSkipButton)
2015-03-03 16:10:12 -06:00
minigameGui.removeNode()
buttonGui.removeNode()
self.timer = ToontownTimer.ToontownTimer()
self.timer.reparentTo(self.frame)
self.timer.setScale(0.4)
self.timer.setPos(0.997, 0, 0.064)
self.frame.hide()
def unload(self):
2015-06-21 14:09:31 -05:00
self.ignoreAll()
if hasattr(self, 'skipButton'):
self.skipButton.destroy()
del self.skipButton
2015-03-03 16:10:12 -06:00
self.frame.destroy()
del self.frame
del self.gameTitleText
del self.instructionsText
self.playButton.destroy()
del self.playButton
del self.timer
def enter(self):
self.frame.show()
self.timer.countdown(self.TIMEOUT, self.playCallback)
self.accept('enter', self.playCallback)
def exit(self):
self.frame.hide()
self.timer.stop()
self.ignore('enter')
def playCallback(self):
messenger.send(self.doneEvent)
2015-06-21 14:09:31 -05:00
def skipCallback(self):
messenger.send('minigameSkip')
def updateSkipButton(self, min, max):
2015-07-05 18:59:25 -05:00
self.skipButton['text'] = TTLocalizer.MinigameRulesPanelSkip % (min, max)