Exemplo n.º 1
0
def openPage(app, url):
    # If we're in fullscreen, minimise.
    if app.screenManager.isFullScreen():
        if platform.system() != 'Darwin':
            # Try minimising.
            pygame.display.iconify()
        else:
            # .iconify() has problems on Mac OSX

            from trosnoth.gui.framework.dialogbox import OkBox
            from trosnoth.gui.common import ScaledSize
            # Switch out of full screen.
            app.displaySettings.fullScreen = False
            app.displaySettings.apply()
            box = OkBox(app, ScaledSize(600, 300), 'Web browser opened',
                        'Please refer to web browser.')

            def revert():
                # Switch back to full screen.
                app.displaySettings.fullScreen = True
                app.displaySettings.apply()

            box.onClose.addListener(revert)
            box.show()

    # Open in a new tab if possible.
    try:
        webbrowser.open_new_tab(url)
    except AttributeError:
        webbrowser.open_new(url)
Exemplo n.º 2
0
    def __init__(self, app):
        super(Interface, self).__init__(app)

        # Draw the background
        bg = pygame.surface.Surface(app.screenManager.scaledSize)
        bg.fill((0, 128, 0))
        from random import randint
        for x in range(0, 20):
            randPos = (randint(0, 580), randint(0, 430))
            pygame.draw.rect(bg, (255, 0, 0),
                             pygame.rect.Rect(randPos, (20, 20)), 10)
        box = FunBox(app, "Disgusting Colour Scheme?")
        box._setPos((0, 0))

        box2 = FunBox(app, "Heck Yes!")
        box2.setColours(borderColour=(192, 0, 192))
        box3 = FunBox(app, "")
        box3._setPos((10, 10))
        box4 = YesNoBox(app, (300, 200), "A question: ", "Is Trosnoth cool?")
        box4.onClose.addListener(
            lambda: OkBox(app, (200, 100), "Result", "You pressed %s" %
                          DialogResult.text[box4.result]).show())
        self.elements = [elements.PictureElement(app, bg)]
        box.onClose.addListener(lambda: self.app.screenManager.
                                setScreenProperties((1024, 768), 0, "Testing"))
        box3.show()
        box.show()
        box2.show()
        box4.show()
Exemplo n.º 3
0
    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
Exemplo n.º 4
0
    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()
Exemplo n.º 5
0
    def begin(self, servers, canHost=True):
        self.cancelled = False
        self.passwordGetter.setCancelled(False)
        self.badServers = set()
        if self.lobby is None:
            self.lobby = Lobby(self.app)

        # Removes the third item (http) from the tuple since we don't care about
        # it.
        servers = [(server[:2] if isinstance(server, tuple) else server)
                   for server in servers]

        for server in servers:
            if self.cancelled:
                break

            if server == JOIN_LOCAL_GAME:
                if self.app.server is not None:
                    self.onSucceed.execute()
                    self.app.interface.connectToLocalServer()
                    return

            elif isinstance(server, tuple):
                if server in self.badServers:
                    continue

                self.logBox.log('Requesting games from %s:%d...' % server)
                connected = yield self.attemptServerConnect(
                    self.lobby.getGames, server)
                if connected:
                    return

            elif server == JOIN_LAN_GAME:
                self.logBox.log('Asking local network for other games...')
                games = yield self.lobby.get_adhoc_lan_games()
                for game in games:
                    joinSuccessful = yield self.attemptJoinGame(game)
                    if joinSuccessful:
                        return

            elif server == JOIN_AUTH_LAN_GAME:
                self.logBox.log('Searching for servers on local network...')
                server = yield get_multicast_server()
                if server:
                    self.logBox.log(
                        'Server found. Requesting games from %s:%d...' %
                        server)
                    connected = yield self.attemptServerConnect(
                        self.lobby.getGames, server)
                    if connected:
                        return

        if canHost:
            if not self.cancelled:
                result = yield HostGameQuery(self.app).run()

                if not result:
                    self.onFail.execute()
                    return

                self.app.startListenServer(2, 1)

                self.onSucceed.execute()
                self.app.interface.connectToLocalServer()
        else:
            if not self.cancelled:
                box = OkBox(self.app, ScaledSize(450, 150), 'Trosnoth',
                            'Connection unsuccessful.')
                box.onClose.addListener(self.onFail.execute)
                box.show()
Exemplo n.º 6
0
    def begin(self, servers, canHost=True):
        self.cancelled = False
        self.passwordGetter.cancelled = False
        self.badServers = set()
        if self.lobby is None:
            self.lobby = Lobby(self.app)

        # Removes the third item (http) from the tuple since we don't care about
        # it.
        servers = [(server[:2] if isinstance(server, tuple) else server)
                   for server in servers]

        for server in servers:
            if self.cancelled:
                break

            if server == 'self':
                if self.app.server is not None:
                    self.onSucceed.execute()
                    self.app.interface.connectToLocalServer()
                    return

            elif isinstance(server, tuple):
                if server in self.badServers:
                    continue

                self.logBox.log('Requesting games from %s:%d...' % server)
                connected = yield self.attemptServerConnect(
                    self.lobby.getGames, server)
                if connected:
                    return

            elif server == 'others':
                for server in servers:
                    if (server in self.badServers
                            or not isinstance(server, tuple)):
                        continue

                    self.logBox.log('Asking %s:%d about other games...' %
                                    server)
                    connected = yield self.attemptServerConnect(
                        self.lobby.getOtherGames, server)
                    if connected:
                        return

            elif server == 'lan':
                self.logBox.log('Asking local network for other games...')
                games = yield self.lobby.getMulticastGames()
                for game in games:
                    joinSuccessful = yield self.attemptJoinGame(game)
                    if joinSuccessful:
                        return

            elif server == 'create':
                for server in servers:
                    if server in self.badServers or not isinstance(
                            server, tuple):
                        continue
                    self.logBox.log('Asking to create game on %s...' %
                                    (server[0], ))

                    joinSuccessful = yield self.attemptCreateGame(server)
                    if joinSuccessful:
                        return

        if canHost:
            if not self.cancelled:
                result = yield HostGameQuery(self.app).run()

                if not result:
                    self.onFail.execute()
                    return

                self.app.startServer(2, 1)

                # Notify remaining auth servers of this game.
                for server in servers:
                    if server in self.badServers or not isinstance(
                            server, tuple):
                        continue
                    self.logBox.log('Registering game with %s...' %
                                    (server[0], ))
                    try:
                        result = yield self.lobby.registerGame(
                            server, self.app.server)
                    except ConnectError:
                        self.logBox.log('Unable to connect.')
                    if not result:
                        self.logBox.log('Registration failed.')

                self.onSucceed.execute()
                self.app.interface.connectToLocalServer()
        else:
            if not self.cancelled:
                box = OkBox(self.app, ScaledSize(450, 150), 'Trosnoth',
                            'Connection unsuccessful.')
                box.onClose.addListener(self.onFail.execute)
                box.show()
Exemplo n.º 7
0
 def connectionFailed(self, reason):
     box = OkBox(self.app, ScaledSize(450, 150), 'Trosnoth',
                 'Could not connect to server')
     box.show()
     self.close()
Exemplo n.º 8
0
 def throwPortError(self):
     box = OkBox(self.app, ScaledSize(450, 150), 'Trosnoth',
                 'Port numbers must be less than 65536')
     box.show()