Пример #1
0
    def __init__(self, app, controller):
        super(JoiningDialog, self).__init__(app, ScaledSize(530, 180),
                                            'Trosnoth')
        colours = app.theme.colours
        self.controller = controller

        fonts = self.app.screenManager.fonts
        self.text = elements.TextElement(
            self.app,
            '',
            fonts.menuFont,
            Location(DialogBoxAttachedPoint(self, ScaledSize(0, 40), 'midtop'),
                     'midtop'),
            colour=colours.joiningColour,
        )

        self.elements = [
            self.text,
            elements.TextButton(
                self.app,
                Location(
                    DialogBoxAttachedPoint(self, ScaledSize(0, -10),
                                           'midbottom'), 'midbottom'),
                'Cancel',
                fonts.menuFont,
                colours.inGameButtonColour,
                colours.white,
                onClick=controller.cancelJoin,
            ),
        ]
        self.setColours(colours.joinGameBorderColour,
                        colours.joinGameTitleColour,
                        colours.joinGameBackgroundColour)
Пример #2
0
    def __init__(self, app, game):
        super(GameTimer, self).__init__(app)
        self.world = game.world
        self.app = app

        # Change these constants to say where the box goes
        self.area = Area(FullScreenAttachedPoint(ScaledSize(0, -3), 'midtop'),
                         ScaledSize(110, 35), 'midtop')

        self.lineWidth = max(int(3 * self.app.screenManager.scaleFactor), 1)
        # Anything more than width 2 looks way too thick
        if self.lineWidth > 2:
            self.lineWidth = 2

        self.gameClock = clock.Clock(
            self.app, self.getTimeString,
            Location(FullScreenAttachedPoint(ScaledSize(0, 0), 'midtop'),
                     'midtop'), self.app.screenManager.fonts.timerFont,
            self.app.theme.colours.timerFontColour)
        self.elements = [self.gameClock]
        self.running = False

        # Seconds for half a flash
        self.flashCycle = 0.5
        # Value the countdown has to get to before it starts to flash
        self.flashValue = 30
Пример #3
0
 def _updateTurretGauge(self):
     player = self.player
     if self.turretGauge is None:
         if player.turret:
             self.turretGauge = TurretGauge(self.app, Area(
                     FullScreenAttachedPoint(ScaledSize(0,-100),
                     'midbottom'), ScaledSize(100,30), 'midbottom'),
                     player)
             self.elements.append(self.turretGauge)
     elif not player.turret:
         self.elements.remove(self.turretGauge)
         self.turretGauge = None
Пример #4
0
 def _updateRespawnGauge(self):
     player = self.player
     if self.respawnGauge is None:
         if player.dead:
             self.respawnGauge = RespawnGauge(self.app, Area(
                     FullScreenAttachedPoint(ScaledSize(0,-20),
                     'midbottom'), ScaledSize(100,30), 'midbottom'),
                     player, self.world)
             self.elements.append(self.respawnGauge)
     elif not player.dead:
         self.elements.remove(self.respawnGauge)
         self.respawnGauge = None
 def __init__(self, app):
     super(FirstPlayNotificationBar, self).__init__(
         app,
         message=
         'First time playing Trosnoth? Click here to learn the rules.',
         url='http://www.trosnoth.org/how-to-play',
         font=app.fonts.default,
         area=Area(ScaledPoint(0, 0), ScaledSize(1024, 30), 'topleft'),
         buttonPos=Location(ScaledPoint(1024, 0), 'topright'),
         textPos=Area(ScaledPoint(512, 15), ScaledSize(1024, 30), 'centre'),
     )
     self.onClick.addListener(self.hide)
     self.onClose.addListener(app.identitySettings.notFirstTime)
Пример #6
0
 def _makeUpdateNotificationBar(self):
     from trosnoth.gui.common import Location, Area, ScaledPoint, ScaledSize
     from trosnoth.gui.notify import NotificationBar
     bar = NotificationBar(
         self.app,
         message='This is not the latest stable release. Click for info.',
         url='https://trosnoth.org/download',
         font=self.app.fonts.default,
         area=Area(ScaledPoint(0, 0), ScaledSize(1024, 30), 'topleft'),
         buttonPos=Location(ScaledPoint(1024, 0), 'topright'),
         textPos=Area(ScaledPoint(512, 15), ScaledSize(1024, 30), 'centre'),
     )
     bar.onClick.addListener(bar.hide)
     return bar
Пример #7
0
    def __init__(self, app, gameInterface):
        super(DetailsInterface, self).__init__(app)
        self.gameInterface = gameInterface

        # Maximum number of messages viewable at any one time
        maxView = 8

        self.world = gameInterface.world
        self.player = None
        font = app.screenManager.fonts.messageFont
        self.currentMessages = MessageBank(self.app, maxView, 50,
                Location(FullScreenAttachedPoint(ScaledSize(-40,-40),
                'bottomright'), 'bottomright'), 'right', 'bottom', font)

        # If we want to keep a record of all messages and their senders
        self.input = None
        self.inputText = None
        self.unobtrusiveGetter = None
        self.turretGauge = None
        self.reloadGauge = GunGauge(self.app, Area(
                FullScreenAttachedPoint(ScaledSize(0,-60), 'midbottom'),
                ScaledSize(100,30), 'midbottom'))
        self.respawnGauge = None
        self.itemGauge = ItemGauge(self.app, self.player)
        self.achievementBox = None
        self.currentUpgrade = None
        self.settingsMenu = SettingsMenu(app, onClose=self.hideSettings,
                showThemes=False)

        self.chatBox = ChatBox(app, self.world, self.gameInterface)

        menuloc = Location(FullScreenAttachedPoint((0,0), 'bottomleft'),
                'bottomleft')
        self.menuManager = mainMenu.MainMenu(self.app, menuloc, self,
                self.gameInterface.keyMapping)
        self.upgradeDisplay = UpgradeDisplay(app)
        self.trajectoryOverlay = TrajectoryOverlay(app, gameInterface.gameViewer.viewManager, self.upgradeDisplay)
        self.gameVoteMenu = GameVoteMenu(
            app, self.world, onChange=self._castGameVote)
        self._gameVoteUpdateCounter = 0
        self.elements = [
            self.currentMessages, self.upgradeDisplay, self.reloadGauge,
            self.gameVoteMenu, self.chatBox,
            self.trajectoryOverlay, self.menuManager, self.itemGauge,
        ]

        self.upgradeMap = dict((upgradeClass.action, upgradeClass) for
                upgradeClass in allUpgrades)
Пример #8
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)
Пример #9
0
    def setUpgrade(self, upgradeType, player):
        self.player = player
        self.upgrade = upgradeType
        if player is None or upgradeType is None:
            self.elements = [self.coinsText]
        else:
            pos = Location(Screen(0.6, 0), 'midtop')
            image = self.app.theme.sprites.upgradeImage(upgradeType)
            area = Area(
                RelativePoint(Screen(0.6, 0), (0, 52)),
                ScaledSize(50, 10), 'midtop')
            self.elements = [
                PictureElement(self.app, image, pos),
                self.coinsText,
            ]

            if upgradeType.enabled:
                self.elements.append(
                    CoinGauge(self.app, area, player, upgradeType))
            else:
                self.elements.append(
                    TextElement(self.app, 'DISABLED',
                        self.app.screenManager.fonts.ingameMenuFont,
                        Location(CanvasX(620, 68), 'midbottom'),
                        self.app.theme.colours.errorMessageColour))
    def _updateImage(self):
        try:
            filepath = self.app.theme.getPath('achievements', '%s.png' %
                    self.achievements[0])
        except IOError:
            filepath = self.app.theme.getPath('achievements', 'default.png')

        image = pygame.image.load(filepath)
        image = pygame.transform.smoothscale(image,
                ScaledSize(64, 64).getSize(self.app)).convert()

        if type(self.elements[-1]) == PictureElement:
            self.elements.pop()

        self.image = PictureElement(self.app, image,
                Location(FullScreenAttachedPoint(
                ScaledSize(-self.width / 2 + 7, -105), 'midbottom'),
                'bottomleft'))

        self.elements.append(self.image)
Пример #11
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
Пример #12
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()
Пример #13
0
 def button(self, text, onClick, pos, anchor='topleft', hugeFont=False):
     pos = Location(
         ScaledScreenAttachedPoint(ScaledSize(pos[0], pos[1]), anchor),
         anchor)
     if hugeFont:
         font = self.app.screenManager.fonts.hugeMenuFont
     else:
         font = self.app.screenManager.fonts.bigMenuFont
     result = elements.TextButton(self.app, pos, text, font, self.colour,
                                  self.highlight)
     result.onClick.addListener(lambda sender: onClick())
     return result
Пример #14
0
def mainButton(app, text, onClick, pos, anchor='topleft', hugeFont=False,
        smallFont=False):
    pos = Location(ScaledScreenAttachedPoint(ScaledSize(pos[0], pos[1]),
            'topleft'), anchor)
    if hugeFont:
        font = app.screenManager.fonts.hugeMenuFont
    elif smallFont:
        font = app.screenManager.fonts.menuFont
    else:
        font = app.screenManager.fonts.mainMenuFont
    result = TextButton(app, pos, text, font, app.theme.colours.mainMenuColour,
            app.theme.colours.mainMenuHighlight)
    result.onClick.addListener(lambda sender: onClick())
    return result
Пример #15
0
    def __init__(self, app, textBoxText):

        super(FunBox, self).__init__(app, ScaledSize(300, 200), "Dialog!!")
        h = prompt.InputBox(app,
                            Area((10, 10), (280, 50)),
                            textBoxText,
                            font=app.screenManager.fonts.bigMenuFont)
        h.onClick.addListener(self.setFocus)
        font = ScaledFont("KLEPTOCR.TTF", 30)
        b = elements.TextButton(app, (150, 100), "Close", font, (255, 0, 0),
                                (20, 100, 200))
        b.onClick.addListener(lambda sender: self.close())
        self.elements = [h, b]
        self.setColours(titleColour=(255, 0, 0),
                        backgroundColour=(255, 128, 0))
Пример #16
0
    def __init__(self, app):
        super(TrosnothBackdrop, self).__init__(app)

        backdropPath = app.theme.getPath('startupMenu', 'blackdrop.png')
        backdrop = Backdrop(app, backdropPath,
                app.theme.colours.backgroundFiller)

        # Things that will be part of the backdrop of the entire startup menu
        # system.
        verFont = self.app.screenManager.fonts.versionFont
        self.elements = [
            backdrop,
            TextElement(self.app, titleVersion, verFont,
                Location(FullScreenAttachedPoint(ScaledSize(-10,-10),
                'bottomright'), 'bottomright'),
                app.theme.colours.versionColour),
        ]
Пример #17
0
def button(app, text, onClick, pos, anchor='topleft', hugeFont=False,
        smallFont=False, firstColour=None, secondColour=None):
    if firstColour is None:
        firstColour = app.theme.colours.secondMenuColour
    if secondColour is None:
        secondColour = app.theme.colours.mainMenuHighlight
    pos = Location(ScaledScreenAttachedPoint(ScaledSize(pos[0], pos[1]),
            anchor), anchor)
    if hugeFont:
        font = app.screenManager.fonts.hugeMenuFont
    elif smallFont:
        font = app.screenManager.fonts.menuFont
    else:
        font = app.screenManager.fonts.mainMenuFont
    result = TextButton(app, pos, text, font, firstColour, secondColour)
    result.onClick.addListener(lambda sender: onClick())
    return result
Пример #18
0
    def refreshGauges(self):
        for item in [i for i in self.gauges if i not in self.items]:
            del self.gauges[item]
        self.elements = []

        if not self.items:
            return

        xOffset = 80
        x = -0.5 * (len(self.items) - 1) * xOffset

        for item in sorted(self.items, key=lambda item: item.defaultKey):
            gauge = self.gauges.get(item)
            if not gauge:
                gauge = self.makeGauge(item, x)
                self.gauges[item] = gauge
            else:
                gauge.area.point.val = ScaledSize(x, -20)
            self.elements.append(gauge)
            x += xOffset
Пример #19
0
    def __init__(self, app, reason):
        width = app.screenManager.scaleFactor * absoluteWidth

        font = app.fonts.connectionFailedFont
        boundary = app.screenManager.scaleFactor * 20
        lines = wrapWords(app, reason, font, width - 2 * boundary)

        x = boundary
        elements = []
        colours = app.theme.colours
        for text in lines:
            elements.append(
                TextElement(app,
                            text,
                            font,
                            Location(
                                DialogBoxAttachedPoint(self, (0, x), 'midtop'),
                                'midtop'),
                            colour=colours.errorColour))
            x += font.getHeight(app)

        # Boundary * 3 for top, bottom, and middle
        height = boundary * 3 + font.getHeight(app) * (len(lines) + 1)
        size = ScaledSize(absoluteWidth, height)
        super(ConnectionFailedDialog, self).__init__(app, size,
                                                     'Connection Failed')

        self.elements = elements
        self.elements.append(
            TextButton(app,
                       Location(
                           DialogBoxAttachedPoint(self, (0, -boundary),
                                                  'midbottom'), 'midbottom'),
                       'OK',
                       font,
                       colours.dialogButtonColour,
                       colours.radioMouseover,
                       onClick=lambda sender: self.close()))
        self.onEnter = Event()
        self.onEnter.addListener(self.close)
Пример #20
0
    def __init__(self, app, serverName='server', onCancel=None):
        super(ConnectingScreen, self).__init__(app)
        colours = app.theme.colours

        self.text = TextElement(self.app,
                                'Connecting to %s...' % serverName,
                                self.app.screenManager.fonts.bigMenuFont,
                                ScaledLocation(512, 384, 'center'),
                                colour=colours.connectingColour)

        button = TextButton(
            self.app,
            Location(ScaledScreenAttachedPoint(ScaledSize(0, 300), 'center'),
                     'center'),
            'cancel',
            self.app.screenManager.fonts.bigMenuFont,
            colours.mainMenuColour,
            colours.white,
            onClick=onCancel)
        self.onCancel = button.onClick

        self.elements = [button, self.text]
Пример #21
0
    def __init__(self,
                 app,
                 pos,
                 text,
                 font,
                 colour,
                 initValue=False,
                 hotkey=None,
                 style='circle',
                 fillColour=None):
        super(CheckBox, self).__init__(app)

        self.pos = pos
        self.font = font

        if hasattr(pos, 'apply'):
            self.text = TextElement(
                app, ' ' + text, font,
                Location(
                    AttachedPoint(ScaledSize(self._getBoxSize()[0] / 5, 2),
                                  self._getBoxRect, 'midright'), 'midleft'),
                colour)
        else:
            self.text = TextElement(
                app, ' ' + text, font,
                Location((pos[0] + self._getBoxSize()[0],
                          pos[1] - self._getBoxSize()[0] / 10), 'topleft'),
                colour)

        self.value = initValue
        self.colour = colour
        if fillColour is None:
            self.fillColour = tuple((256 * 3 + i) / 4 for i in colour)
        else:
            self.fillColour = fillColour
        self.hotkey = hotkey
        self.style = style
        self.onValueChanged = Event()
Пример #22
0
    def __init__(self, app, player, achievementId):
        super(AchievementBox, self).__init__(app)
        self.app = app
        self.player = player

        self.achievements = [achievementId]

        self.width = 453
        self.height = 75

        self._setColours()

        self.area = Area(
            FullScreenAttachedPoint(ScaledSize(0, -100), 'midbottom'),
            ScaledSize(self.width, self.height), 'midbottom')

        self.smlBox = Area(
            FullScreenAttachedPoint(ScaledSize(-self.width / 2 + 6,
                                               -104), 'midbottom'),
            ScaledSize(66, 66), 'bottomleft')

        self.titleText = TextElement(
            self.app, "ACHIEVEMENT UNLOCKED!", self.fonts.achievementTitleFont,
            Location(
                FullScreenAttachedPoint(
                    ScaledSize(73 / 2, -100 - self.height + 10), 'midbottom'),
                'midtop'), self.borderColour)

        self.nameText = TextElement(
            self.app,
            self.achievementDefs.getAchievementDetails(achievementId)[0],
            self.fonts.achievementNameFont,
            Location(
                FullScreenAttachedPoint(ScaledSize(73 / 2, -100 - 13),
                                        'midbottom'),
                'midbottom'), self.colours.black)

        self.elements = [self.titleText, self.nameText]
        self._updateImage()

        self.cycler = WeakLoopingCall(self, 'cycleAchievements')
        self.cycler.start(5.0, now=False)
Пример #23
0
 def throwPortError(self):
     box = OkBox(self.app, ScaledSize(450, 150), 'Trosnoth',
                 'Port numbers must be less than 65536')
     box.show()
Пример #24
0
 def connectionFailed(self, reason):
     box = OkBox(self.app, ScaledSize(450, 150), 'Trosnoth',
                 'Could not connect to server')
     box.show()
     self.close()
Пример #25
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()
Пример #26
0
    def __init__(self, app, width=2, height=1):
        super(MapSizeBox, self).__init__(app, ScaledSize(400, 230),
                                         "Custom Size")
        labelFont = app.screenManager.fonts.bigMenuFont
        labelColour = app.theme.colours.dialogBoxTextColour
        btnFont = app.screenManager.fonts.bigMenuFont
        btnColour = app.theme.colours.dialogButtonColour
        highlightColour = app.theme.colours.black
        inputFont = app.screenManager.fonts.defaultTextBoxFont
        inputColour = app.theme.colours.grey

        self.widthBox = InputBox(app,
                                 Region(midleft=self.Relative(0.65, 0.25),
                                        size=self.Relative(0.15, 0.2)),
                                 str(width),
                                 font=inputFont,
                                 colour=inputColour,
                                 onClick=self.setFocus,
                                 onEnter=self.okClicked,
                                 validator=intValidator,
                                 maxLength=2)

        self.heightBox = InputBox(app,
                                  Region(midleft=self.Relative(0.65, 0.55),
                                         size=self.Relative(0.15, 0.2)),
                                  str(height),
                                  font=inputFont,
                                  colour=inputColour,
                                  onClick=self.setFocus,
                                  onEnter=self.okClicked,
                                  validator=intValidator,
                                  maxLength=2)

        # Add elements to screen
        self.elements = [
            TextElement(app, 'Half Width:', labelFont,
                        Location(self.Relative(0.6, 0.25), 'midright'),
                        labelColour),
            self.widthBox,
            TextElement(app, 'Height:', labelFont,
                        Location(self.Relative(0.6, 0.55), 'midright'),
                        labelColour),
            self.heightBox,
            TextButton(app,
                       Location(self.Relative(0.3, 0.9), 'center'),
                       'Ok',
                       btnFont,
                       btnColour,
                       highlightColour,
                       onClick=self.okClicked),
            TextButton(app,
                       Location(self.Relative(0.7, 0.9), 'center'),
                       'Cancel',
                       btnFont,
                       btnColour,
                       highlightColour,
                       onClick=self.cancelClicked),
        ]

        self.tabOrder = [self.widthBox, self.heightBox]
        self.setFocus(self.widthBox)
Пример #27
0
    def setupButtons(self):
        lanButtonPos = Location(
            ScaledScreenAttachedPoint(ScaledPoint(100, 550), 'topleft'))
        self.lanButton = CheckBox(
            self.app,
            lanButtonPos,
            'LAN Discovery',
            self.app.screenManager.fonts.serverSelectionCheckboxesFont,
            self.app.theme.colours.mainMenuColour,
            initValue=self.app.connectionSettings.lanGames,
            style='circle',
            fillColour=self.app.theme.colours.mainMenuColour)
        self.lanButton.onValueChanged.addListener(lambda sender: self.save())

        lanSearchButtonPos = Location(
            ScaledScreenAttachedPoint(ScaledPoint(380, 550), 'topleft'))
        self.lanSearchButton = TextButton(
            self.app,
            lanSearchButtonPos,
            'Search LAN for Game',
            self.app.screenManager.fonts.serverSelectionCheckboxesFont,
            self.app.theme.colours.mainMenuHighlight,
            self.app.theme.colours.white,
            onClick=lambda sender: self.joinLan())

        createButtonPos = Location(
            ScaledScreenAttachedPoint(ScaledPoint(100, 600), 'topleft'))
        self.createButton = CheckBox(
            self.app,
            createButtonPos,
            'Create games on remote servers',
            self.app.screenManager.fonts.serverSelectionCheckboxesFont,
            self.app.theme.colours.mainMenuColour,
            initValue=self.app.connectionSettings.createGames,
            style='circle',
            fillColour=self.app.theme.colours.mainMenuColour)
        self.createButton.onValueChanged.addListener(
            lambda sender: self.save())

        otherButtonPos = Location(
            ScaledScreenAttachedPoint(ScaledPoint(100, 650), 'topleft'))
        self.otherButton = CheckBox(
            self.app,
            otherButtonPos,
            'Ask servers about other games',
            self.app.screenManager.fonts.serverSelectionCheckboxesFont,
            self.app.theme.colours.mainMenuColour,
            initValue=self.app.connectionSettings.otherGames,
            style='circle',
            fillColour=self.app.theme.colours.mainMenuColour)
        self.otherButton.onValueChanged.addListener(lambda sender: self.save())

        newButtonPos = Location(
            ScaledScreenAttachedPoint(ScaledPoint(850, 285), 'topleft'))
        self.newButton = TextButton(
            self.app,
            newButtonPos,
            '+ Server',
            self.app.screenManager.fonts.serverSelectionCheckboxesFont,
            self.app.theme.colours.serverSelectionNewItem,
            self.app.theme.colours.white,
            onClick=lambda sender: self.newServer())

        self.closeButton = elements.TextButton(
            self.app,
            Location(
                ScaledScreenAttachedPoint(ScaledSize(-70, 650), 'topright'),
                'topright'),
            'done',
            self.app.screenManager.fonts.bigMenuFont,
            self.app.theme.colours.mainMenuHighlight,
            self.app.theme.colours.white,
            onClick=lambda sender: self.onClose(),
        )
Пример #28
0
 def makeGauge(self, item, x):
     return SingleUpgradeGauge(self.app, Area(
         FullScreenAttachedPoint(ScaledSize(x, -20),
             'midbottom'), ScaledSize(40, 10), 'midbottom'),
         item)
Пример #29
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()
Пример #30
0
    def __init__(self, app, controller, world):
        super(JoinGameDialog, self).__init__(app, ScaledSize(512, 314),
                                             'Join Game')
        self.result = None
        self.controller = controller
        self.selectedTeam = None

        fonts = self.app.screenManager.fonts
        self.nickBox = prompt.InputBox(
            self.app,
            Area(DialogBoxAttachedPoint(self, ScaledSize(0, 40), 'midtop'),
                 ScaledSize(200, 60), 'midtop'),
            '',
            font=fonts.menuFont,
            maxLength=30,
        )
        self.nickBox.onClick.addListener(self.setFocus)
        self.nickBox.onTab.addListener(lambda sender: self.clearFocus())
        name = app.identitySettings.nick
        if name is not None:
            self.nickBox.setValue(name)

        colours = app.theme.colours
        self.cantJoinYet = elements.TextElement(
            self.app,
            '',
            fonts.ingameMenuFont,
            ScaledLocation(256, 115, 'center'),
            colours.cannotJoinColour,
        )

        teamA = world.teams[0]
        teamB = world.teams[1]

        self.elements = [
            elements.TextElement(
                self.app,
                'Please enter your nick:',
                fonts.smallMenuFont,
                Location(
                    DialogBoxAttachedPoint(self, ScaledSize(0, 10), 'midtop'),
                    'midtop'),
                colours.black,
            ), self.nickBox, self.cantJoinYet,
            elements.TextElement(
                self.app,
                'Select team:',
                fonts.smallMenuFont,
                Location(
                    DialogBoxAttachedPoint(self, ScaledSize(0, 130), 'midtop'),
                    'midtop'),
                colours.black,
            ),
            elements.TextButton(self.app,
                                Location(
                                    DialogBoxAttachedPoint(
                                        self, ScaledSize(-25, 160), 'midtop'),
                                    'topright'),
                                str(teamA),
                                fonts.menuFont,
                                colours.team1msg,
                                colours.white,
                                onClick=lambda obj: self.joinTeam(teamA)),
            elements.TextButton(self.app,
                                Location(
                                    DialogBoxAttachedPoint(
                                        self, ScaledSize(25, 160), 'midtop'),
                                    'topleft'),
                                str(teamB),
                                fonts.menuFont,
                                colours.team2msg,
                                colours.white,
                                onClick=lambda obj: self.joinTeam(teamB)),
            elements.TextButton(self.app,
                                Location(
                                    DialogBoxAttachedPoint(
                                        self, ScaledSize(-25, 210), 'midtop'),
                                    'topright'),
                                'Automatic',
                                fonts.menuFont,
                                colours.inGameButtonColour,
                                colours.white,
                                onClick=lambda obj: self.joinTeam()),
            elements.TextButton(self.app,
                                Location(
                                    DialogBoxAttachedPoint(
                                        self, ScaledSize(25, 210), 'midtop'),
                                    'topleft'),
                                'Spectator',
                                fonts.menuFont,
                                colours.inGameButtonColour,
                                colours.white,
                                onClick=lambda obj: self.spectate()),
            elements.TextButton(self.app,
                                Location(
                                    DialogBoxAttachedPoint(
                                        self, ScaledSize(0, -10), 'midbottom'),
                                    'midbottom'),
                                'Cancel',
                                fonts.menuFont,
                                colours.inGameButtonColour,
                                colours.white,
                                onClick=self.cancel)
        ]
        self.setColours(colours.joinGameBorderColour,
                        colours.joinGameTitleColour,
                        colours.joinGameBackgroundColour)
        self.setFocus(self.nickBox)