Poodletooth-iLand/toontown/language/LanguageSelector.py

73 lines
3.6 KiB
Python
Raw Normal View History

2015-03-13 12:14:04 -05:00
from direct.gui.DirectGui import OnscreenImage, DirectLabel, DirectButton
from toontown.toonbase import ToontownGlobals, TTLocalizer
from toontown.toontowngui import TTDialog
import os
class LanguageSelector:
2015-03-13 12:14:04 -05:00
def __init__(self, leaveFunction):
self.title = None
self.current = None
self.available = None
self.english = None
self.french = None
self.backButton = None
self.confirmDialog = None
self.leaveFunction = leaveFunction
2015-03-13 12:14:04 -05:00
def create(self):
self.background = OnscreenImage(parent=render2d, image="phase_3.5/maps/blackboardEmpty.jpg")
self.gui = loader.loadModel('phase_3/models/gui/tt_m_gui_mat_mainGui')
self.shuffleUp = self.gui.find('**/tt_t_gui_mat_shuffleUp')
self.shuffleDown = self.gui.find('**/tt_t_gui_mat_shuffleDown')
2015-03-13 12:14:04 -05:00
self.title = DirectLabel(aspect2d, relief=None, text=TTLocalizer.LanguageSelectorTitle,
text_fg=(0, 1, 0, 1), text_scale=0.15, text_font=ToontownGlobals.getSuitFont(),
pos=(0, 0, 0.70), text_shadow=(0, 0.392, 0, 1))
self.current = DirectLabel(aspect2d, relief=None, text=TTLocalizer.LanguageSelectorCurrent % settings['language'],
text_fg=(0, 1, 0, 1), text_scale=0.09, text_font=ToontownGlobals.getSuitFont(),
pos=(0, 0, 0.55), text_shadow=(0, 0.392, 0, 1))
self.available = DirectLabel(aspect2d, relief=None, text=TTLocalizer.LanguageSelectorAvailable,
text_fg=(1, 0, 0, 1), text_scale=0.09, text_font=ToontownGlobals.getSuitFont(),
pos=(0, 0, 0), text_shadow=(0.545, 0, 0, 1))
self.english = DirectButton(aspect2d, relief=None, text='English',
text_fg=(1, 0.549, 0, 1), text_scale=0.09, text_font=ToontownGlobals.getSuitFont(),
pos=(0, 0, -0.15), text_shadow=(1, 0.27, 0, 1), command=self.switchLanguage, extraArgs=['English'])
self.french = DirectButton(aspect2d, relief=None, text='French',
text_fg=(1, 0.549, 0, 1), text_scale=0.09, text_font=ToontownGlobals.getSuitFont(),
pos=(0, 0, -0.25), text_shadow=(1, 0.27, 0, 1), command=self.switchLanguage, extraArgs=['French'])
self.backButton = DirectButton(aspect2d, relief=None, image=(self.shuffleUp, self.shuffleDown),
text=TTLocalizer.LanguageSelectorBack, text_font=ToontownGlobals.getInterfaceFont(),
text_scale=0.11, text_pos=(0, -0.02), pos=(0, 0, -0.75), text_fg=(1, 1, 1, 1),
text_shadow=(0, 0, 0, 1), command=self.destroy)
def destroy(self):
for element in [self.background, self.title, self.current, self.available, self.english, self.french, self.backButton, self.confirmDialog]:
if element:
element.destroy()
element = None
2015-03-13 12:14:04 -05:00
self.leaveFunction()
2015-03-13 12:14:04 -05:00
def switchLanguage(self, language):
if language == settings['language']:
self.confirmDialog = TTDialog.TTDialog(style=TTDialog.Acknowledge, text=TTLocalizer.LanguageSelectorSameLanguage, command=self.cleanupDialog)
else:
self.confirmDialog = TTDialog.TTDialog(style=TTDialog.YesNo, text=TTLocalizer.LanguageSelectorConfirm % language, command=self.confirmSwitchLanguage, extraArgs=[language])
self.confirmDialog.show()
2015-03-13 12:14:04 -05:00
def confirmSwitchLanguage(self, value, language):
if value > 0:
settings['language'] = language
os._exit(1)
else:
self.cleanupDialog()
2015-03-13 12:14:04 -05:00
def cleanupDialog(self, value=0):
self.confirmDialog.cleanup()