def __init__(self, app):
     super(Interface, self).__init__(app)
     backdrop = pygame.Surface(app.screenManager.scaledSize)
     backdrop.fill((128, 0, 128))
     s1 = slider.Slider(app, ScaledArea(100, 100, 400, 60))
     #s1.setRange(50,150)
     t1 = elements.TextElement(app, "100", Font(None, 60),
                               ScaledLocation(100, 200))
     t2 = elements.TextElement(app, "100", Font(None, 60),
                               ScaledLocation(550, 100))
     onSlide = lambda x: t1.setText("%.1f" % x)
     onChange = lambda x: t2.setText("%.1f" % x)
     s1.onSlide.addListener(onSlide)
     s1.onValueChanged.addListener(onChange)
     self.elements = [elements.PictureElement(app, backdrop), s1, t1, t2]
示例#2
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)
示例#3
0
    def recalculateTarget(self):
        targetRect = self.region.getRect(self.app)
        titleBtn = self.makeTitleButton(targetRect)
        results = [titleBtn]

        y = targetRect.top + titleBtn.stdImage.get_height() + 4
        maxWidth = targetRect.width - 4
        font = self.font._getFont(self.app)
        if not self.hidden:
            x = targetRect.left + 2
            for line in self.lines:
                for subline in wrapline(line, font, maxWidth):
                    element = elements.TextElement(app=self.app,
                                                   text=subline,
                                                   font=self.font,
                                                   pos=Location((x, y),
                                                                'topleft'),
                                                   colour=self.colour)
                    results.append(element)
                    y += element.image.getImage(self.app).get_height() + 2
        targetRect.height = y - targetRect.top
        return targetRect, results
示例#4
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)
示例#5
0
    def refresh(self, menu=None):
        '''Updates the display of this menu to reflect the currently-showing
        menu of the manager.'''

        if menu is None:
            menu = self.manager.menu
        if menu is None:
            menuItemCount = 0
        else:
            menuItemCount = len(menu.items)

        if self.hidable and self.hidden:
            # Display the menu title only.
            itemSpacing = self.font.getLineSize(self.app)
        elif self.autosize:
            # Make a canvas for the new menu.
            itemSpacing = self.font.getLineSize(self.app)
            size = (self.rect.width, itemSpacing * (1 + menuItemCount))
            self.image = pygame.Surface(size)
            if self.transparent:
                self.image.set_colorkey(self.backColour)

        rect = self.image.get_rect()

        if not (self.autosize or (self.hidable and self.hidden)):
            # Calculate the item spacing.
            itemSpacing = rect.height / (1 + menuItemCount)

        self.elements = []

        if menu is None:
            return

        x = rect.width // 2

        # Menu title.
        if self.hidable:
            stdImage = pygame.Surface((self.rect.width, itemSpacing))
            stdImage.fill(self.backColour)
            img = self.font.render(self.app, menu.name, True, self.titleColour)
            r = img.get_rect()
            r.center = (self.rect.width // 2, itemSpacing // 2)
            stdImage.blit(img, r)

            hvrImage = pygame.Surface((self.rect.width, itemSpacing))
            hvrImage.fill(self.backColour)
            img = self.font.render(self.app, menu.name, True, self.hvrColour)
            hvrImage.blit(img, r)

            btn = elements.HoverButton(app=self.app,
                                       pos=Location((x, itemSpacing / 2),
                                                    'center'),
                                       stdImage=stdImage,
                                       hvrImage=hvrImage)
            btn.onClick.addListener(self.hide)
            self.elements.append(btn)
            if self.hidden:
                return
        else:
            self.elements.append(
                elements.TextElement(app=self.app,
                                     text=menu.name,
                                     font=self.font,
                                     pos=Location((x, itemSpacing / 2),
                                                  'center'),
                                     colour=self.titleColour))

        # Menu items.
        y = itemSpacing * 3 / 2
        for item in menu.items:
            self.addMenuItem(item, x, y, rect.width, itemSpacing)
            y += itemSpacing