def __init__(self, app, onCancel=None, onReplay=None): super(SavedGameMenu, self).__init__(app) area = ScaledArea(50, 140, 924, 570) bg = pygame.Surface((924, 500)) bg.fill(app.theme.colours.replayMenu) if app.displaySettings.alphaOverlays: bg.set_alpha(192) font = self.app.screenManager.fonts.ampleMenuFont self.tabContainer = TabContainer(self.app, area, font, app.theme.colours.replayTabBorder) bp = SizedPicture( app, bg, Location(AttachedPoint((0, 0), self.tabContainer._getTabRect)), TabSize(self.tabContainer)) self.replayTab = SavedGameTab(app, self.tabContainer, onCancel=onCancel, onReplay=onReplay) self.tabContainer.addTab(self.replayTab) self.elements = [bp, self.tabContainer]
def __init__(self, app): size = Canvas(512, 384) DialogBox.__init__(self, app, size, 'Please authenticate') self._deferred = None self._host = None font = app.screenManager.fonts.defaultTextBoxFont btnColour = app.theme.colours.dialogButtonColour highlightColour = app.theme.colours.black errorTextColour = app.theme.colours.errorColour self.tabContainer = TabContainer(app, Region(topleft=self.Relative(0, 0), size=self.Relative(1, 0.75)), font, app.theme.colours.tabContainerColour) self.tabContainer.addTab(LoginTab(app)) self.tabContainer.addTab(CreateAccountTab(app)) self.errorText = TextElement(app, '', font, Location(self.Relative(0.5, 0.8), 'center'), errorTextColour) font = app.screenManager.fonts.bigMenuFont self.elements = [ self.tabContainer, self.errorText, TextButton(app, Location(self.Relative(0.3, 0.9), 'center'), 'Ok', font, btnColour, highlightColour, onClick=self.okClicked), TextButton(app, Location(self.Relative(0.7, 0.9), 'center'), 'Cancel', font, btnColour, highlightColour, onClick=self.cancelClicked), ] self.cancelled = False
def __init__(self, app, host, port, onClose): super(AccountSettingsScreen, self).__init__(app) self.onClose = onClose self.host = host self.port = port area = ScaledArea(50, 140, 924, 570) alpha = 192 if app.displaySettings.alphaOverlays else 255 font = app.screenManager.fonts.bigMenuFont self.tabContainer = TabContainer(self.app, area, font, app.theme.colours.playTabBorder) self.background = elements.SolidRect( self.app, app.theme.colours.playMenu, alpha, Area(AttachedPoint((0, 0), self.tabContainer._getTabRect), TabSize(self.tabContainer))) self.passwordTab = ChangePasswordTab(app, host, onClose=self.close, onSave=self.save) self.tabContainer.addTab(self.passwordTab) self.passwordGetter = self.passwordGUIFactory(self.app) self.elements = [self.background, self.tabContainer] self.protocol = None d = ClientCreator(reactor, amp.AMP).connectTCP(host, port) d.addCallbacks(self.connectionEstablished, self.connectionFailed)
class ServerSelectionScreen(framework.CompoundElement): connectScreenFactory = PlayAuthScreen accountScreenFactory = AccountSettingsScreen def __init__(self, app, onClose): super(ServerSelectionScreen, self).__init__(app) self.onClose = onClose area = ScaledArea(50, 140, 924, 570) if app.displaySettings.alphaOverlays: alpha = 192 else: alpha = 255 font = app.screenManager.fonts.bigMenuFont self.tabContainer = TabContainer(self.app, area, font, app.theme.colours.playTabBorder) self.background = elements.SolidRect( self.app, app.theme.colours.playMenu, alpha, Area(AttachedPoint((0, 0), self.tabContainer._getTabRect), TabSize(self.tabContainer))) self.tab = ServerSelectionTab(app, onClose=onClose, onJoin=self.join, onAccountSettings=self.accountSettings) self.tabContainer.addTab(self.tab) self.setElements() def join(self, servers): playAuthScreen = self.connectScreenFactory(self.app, onSucceed=self.onClose, onFail=self.joinFailed) self.elements = [playAuthScreen] playAuthScreen.begin(servers, canHost=False) def joinFailed(self): self.setElements() def reload(self): self.tab.reload() self.setElements() def setElements(self): self.elements = [self.background, self.tabContainer] def accountSettings(self, host, port): accountScreen = self.accountScreenFactory(self.app, host, port, onClose=self.reload) self.elements = [accountScreen]
def __init__(self, app, onClose=None, onRestart=None, showThemes=False, showSound=True, showDisplay=True, showKeymap=True): super(SettingsMenu, self).__init__(app) self.onClose = Event() if onClose is not None: self.onClose.addListener(onClose) self.onRestart = Event() if onRestart is not None: self.onRestart.addListener(onRestart) area = ScaledArea(50, 140, 924, 570) bg = pygame.Surface((924, 500)) bg.fill(app.theme.colours.settingsMenu) if app.displaySettings.alphaOverlays: bg.set_alpha(192) font = app.screenManager.fonts.bigMenuFont self.tabContainer = TabContainer(self.app, area, font, app.theme.colours.settingsTabBorder) bp = elements.SizedPicture( app, bg, Location(AttachedPoint((0, 0), self.tabContainer._getTabRect)), TabSize(self.tabContainer)) if showDisplay: displayTab = DisplaySettingsTab(app, onClose=self.onClose.execute) self.tabContainer.addTab(displayTab) if showKeymap: keymapTab = KeymapTab(app, onClose=self.onClose.execute) self.tabContainer.addTab(keymapTab) if showSound: soundTab = SoundSettingsTab(app, onClose=self.onClose.execute) self.tabContainer.addTab(soundTab) if showThemes: themeTab = ThemeTab(app, onClose=self.onClose.execute, onRestart=self.onRestart.execute) self.tabContainer.addTab(themeTab) self.elements = [bp, self.tabContainer]
def __init__(self, app, onClose): super(ServerSelectionScreen, self).__init__(app) self.onClose = onClose area = ScaledArea(50, 140, 924, 570) if app.displaySettings.alphaOverlays: alpha = 192 else: alpha = 255 font = app.screenManager.fonts.bigMenuFont self.tabContainer = TabContainer(self.app, area, font, app.theme.colours.playTabBorder) self.background = elements.SolidRect( self.app, app.theme.colours.playMenu, alpha, Area(AttachedPoint((0, 0), self.tabContainer._getTabRect), TabSize(self.tabContainer))) self.tab = ServerSelectionTab(app, onClose=onClose, onJoin=self.join, onAccountSettings=self.accountSettings) self.tabContainer.addTab(self.tab) self.setElements()
class PasswordGUI(DialogBox): def __init__(self, app): size = Canvas(512, 384) DialogBox.__init__(self, app, size, 'Please authenticate') self._deferred = None self._host = None font = app.screenManager.fonts.defaultTextBoxFont btnColour = app.theme.colours.dialogButtonColour highlightColour = app.theme.colours.black errorTextColour = app.theme.colours.errorColour self.tabContainer = TabContainer( app, Region(topleft=self.Relative(0, 0), size=self.Relative(1, 0.75)), font, app.theme.colours.tabContainerColour) self.tabContainer.addTab(LoginTab(app)) self.tabContainer.addTab(CreateAccountTab(app)) self.errorText = TextElement( app, '', font, Location(self.Relative(0.5, 0.8), 'center'), errorTextColour) font = app.screenManager.fonts.bigMenuFont self.elements = [ self.tabContainer, self.errorText, TextButton(app, Location(self.Relative(0.3, 0.9), 'center'), 'Ok', font, btnColour, highlightColour, onClick=self.okClicked), TextButton(app, Location(self.Relative(0.7, 0.9), 'center'), 'Cancel', font, btnColour, highlightColour, onClick=self.cancelClicked), ] self.cancelled = False def setCancelled(self, cancelled): self.cancelled = cancelled def processEvent(self, event): if event.type == pygame.KEYDOWN and event.key in (pygame.K_KP_ENTER, pygame.K_RETURN): self.okClicked() return None else: return DialogBox.processEvent(self, event) def cancelClicked(self, element=None): self.close() self._deferred.callback(None) def okClicked(self, element=None): if self.tabContainer.selectedIndex == 1: create = True # Check that passwords match. tab = self.tabContainer.tabs[1] if tab.passwordField.value != tab.passwordField2.value: self.setErrorText('Passwords do not match!') return else: create = False tab = self.tabContainer.tabs[0] username = tab.usernameField.value password = tab.passwordField.value if len(username) == 0: self.setErrorText('You must give a username!') return if len(password) == 0: self.setErrorText('Password cannot be blank!') return self.close() self.app.identitySettings.usernames[self._host] = username self._deferred.callback((create, username, password)) def getPassword(self, host, errorMsg=''): if self.showing: raise PasswordGUIError('PasswordGUI already showing') if self.cancelled: self.cancelled = False result = self._deferred = defer.Deferred() WeakCallLater(0.1, result, 'callback', None) return result self.setCaption(host) self.tabContainer.tabs[0].reset(host) self.tabContainer.tabs[1].reset() self.setErrorText(errorMsg) self.show() self._host = host result = self._deferred = defer.Deferred() return result def setErrorText(self, text): self.errorText.setText(text)
class AccountSettingsScreen(framework.CompoundElement): passwordGUIFactory = PasswordGUI def __init__(self, app, host, port, onClose): super(AccountSettingsScreen, self).__init__(app) self.onClose = onClose self.host = host self.port = port area = ScaledArea(50, 140, 924, 570) alpha = 192 if app.displaySettings.alphaOverlays else 255 font = app.screenManager.fonts.bigMenuFont self.tabContainer = TabContainer(self.app, area, font, app.theme.colours.playTabBorder) self.background = elements.SolidRect( self.app, app.theme.colours.playMenu, alpha, Area(AttachedPoint((0, 0), self.tabContainer._getTabRect), TabSize(self.tabContainer))) self.passwordTab = ChangePasswordTab(app, host, onClose=self.close, onSave=self.save) self.tabContainer.addTab(self.passwordTab) self.passwordGetter = self.passwordGUIFactory(self.app) self.elements = [self.background, self.tabContainer] self.protocol = None d = ClientCreator(reactor, amp.AMP).connectTCP(host, port) d.addCallbacks(self.connectionEstablished, self.connectionFailed) @defer.inlineCallbacks def connectionEstablished(self, protocol): self.protocol = protocol try: yield authenticate(protocol, self.host, self.passwordGetter) except: OkBox(self.app, ScaledSize(450, 150), 'Trosnoth', 'Unable to authenticate with server').show() self.close() return try: result = yield self.protocol.callRemote( authcommands.GetSupportedSettings) tabs = set(result['result']) self.showTabs(tabs) except: log.error('Error calling GetSupportedSettings', exc_info=True) OkBox(self.app, ScaledSize(450, 150), 'Trosnoth', 'Error communicating with server').show() self.close() return def showTabs(self, tabs): tabs = set(tabs) def connectionFailed(self, reason): box = OkBox(self.app, ScaledSize(450, 150), 'Trosnoth', 'Could not connect to server') box.show() self.close() def close(self): if self.protocol and self.protocol.transport.connected: self.protocol.transport.loseConnection() self.onClose() @defer.inlineCallbacks def save(self): try: failReason = yield self.passwordTab.save(self.protocol) except: log.error('Error saving account settings', exc_info=True) failReason = 'Error saving settings to server' if failReason: OkBox(self.app, ScaledSize(450, 150), 'Trosnoth', failReason).show() else: self.close()