Beispiel #1
0
    def __init__(self, app, area, bounds=None, snap=False):
        super(Slider, self).__init__(app)
        self.app = app
        self.area = area
        self.beingDragged = False
        self.snap = snap
        if not bounds:
            bounds = 0, 100
        self.lowBound, self.highBound = bounds
        self.unscaledSlider = 20
        self.sliderRectWidth = int(self.unscaledSlider *
                                   app.screenManager.scaleFactor)
        self.lineColour = (0, 192, 0)
        self.sliderColour = (0, 255, 0)
        self.onValueChanged = Event()
        self.onSlide = Event()

        self.largeArea = ScaledArea(
            self.area.point.val[0] + self.unscaledSlider / 2,
            self.area.point.val[1],
            self.area.size.val[0] - self.unscaledSlider + 1,
            self.area.size.val[1])

        self.area, self.largeArea = self.largeArea, self.area

        self.sliderVal = self.highBound
Beispiel #2
0
    def __init__(self,
                 app,
                 font,
                 area,
                 colour=(192, 192, 192),
                 backColour=(0, 64, 0),
                 historyLimit=2000,
                 locals={}):
        TwistedInteractiveConsole.__init__(self, locals=locals)
        framework.Element.__init__(self, app)

        self.font = font
        self.area = area
        self.colour = colour
        self.backColour = backColour
        self.rect = None
        self.image = None
        self.dirty = True
        self.history = ['']
        self.historyLimit = historyLimit
        self.inBox = ib = InputBox(self.app,
                                   ScaledArea(0, 0, 1000, 100),
                                   font=self.font)
        ib.onEnter.addListener(self._enter)
        ib.hasFocus = True
        ib.gotFocus()

        self.readDeferred = None
        self.deferredInputs = []  # List of (prompt, deferred)
        self.font = font
        self.typeAhead = []
        self.inText = ''
        self.cursorPos = 0
        self._dummyStdIn = DummyStdIn(self.stdInRead)
        self._dummyStdIn.deferred_raw_input = self.raw_input
Beispiel #3
0
    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]
Beispiel #4
0
    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)
Beispiel #5
0
    def __init__(self,
                 app,
                 colour,
                 onCancel=None,
                 speed=None,
                 loop=True,
                 startOff=False,
                 backText='back to main menu',
                 highlight=(255, 255, 255)):
        super(CreditsScreen, self).__init__(app)
        self.colour = colour
        self.highlight = highlight

        self.onCancel = Event()
        if onCancel is not None:
            self.onCancel.addListener(onCancel)

        f = open(getPath(startupMenu, 'credits.txt'), 'rU', encoding='utf-8')
        area = ScaledArea(50, 130, 900, 540)
        fonts = {
            'body': self.app.fonts.creditsFont,
            'h1': self.app.fonts.creditsH1,
            'h2': self.app.fonts.creditsH2
        }
        text = f.read()
        if not startOff:
            # Make at least some room on top and bottom
            text = '\n' * 3 + text + '\n' * 2
        self.credits = scrollingText.ScrollingText(self.app,
                                                   area,
                                                   text,
                                                   self.colour,
                                                   fonts,
                                                   textAlign='middle',
                                                   loop=loop,
                                                   startOff=startOff)
        self.credits.setShadowColour((192, 192, 192))

        self.credits.setAutoscroll(True)
        if speed is None:
            speed = 80
        self.credits.setSpeed(ScalingSpeed(speed))
        self.credits.setBorder(False)

        self.backText = backText
        cancelButton = self.button(backText, self.onCancel.execute, (-50, -30),
                                   'bottomright')

        self.elements = [self.credits, cancelButton]
    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]
Beispiel #7
0
    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 __init__(self, app, onClose=None, onRestart=None):
        super(ThemeTab, self).__init__(app, 'Themes')

        self.onClose = Event()
        if onClose is not None:
            self.onClose.addListener(onClose)
        self.onRestart = Event()
        if onRestart is not None:
            self.onRestart.addListener(onRestart)

        font = self.app.screenManager.fonts.menuFont
        colours = self.app.theme.colours

        self.inactiveTheme = False
        self.originalTheme = app.theme.name

        # Static text
        self.staticText = [
            TextElement(self.app, 'theme information:', font,
                        ScaledLocation(960, 250, 'topright'),
                        colours.headingColour),
            TextElement(self.app, 'theme contents:', font,
                        ScaledLocation(960, 390, 'topright'),
                        colours.headingColour)
        ]

        # Dynamic text
        self.feedbackText = TextElement(
            self.app, 'Your current theme: %s' % (app.theme.name, ), font,
            ScaledLocation(512, 200, 'midtop'), colours.startButton)
        self.listHeaderText = TextElement(self.app, 'available themes:', font,
                                          ScaledLocation(70, 250),
                                          colours.headingColour)
        self.themeNameText = TextElement(self.app, 'Default Theme', font,
                                         ScaledLocation(960, 290, 'topright'),
                                         colours.startButton)
        self.themeAuthorText = TextElement(
            self.app, 'created by: Trosnoth Team', font,
            ScaledLocation(960, 330, 'topright'), colours.startButton)

        self.contents = []

        numContents = 4
        for yPos in range(430, 430 + numContents * 40 + 1, 40):
            self.contents.append(
                TextElement(self.app, '', font,
                            ScaledLocation(960, yPos, 'topright'),
                            colours.startButton))

        self.dynamicText = [
            self.feedbackText, self.listHeaderText, self.themeNameText,
            self.themeAuthorText
        ] + self.contents

        # Theme list
        self.themeList = ListBox(self.app, ScaledArea(70, 290, 400, 290), [],
                                 font, colours.listboxButtons)
        self.themeList.onValueChanged.addListener(self.updateSidebar)

        # Text buttons
        self.useThemeButton = button(app, 'use selected theme',
                                     self.applyTheme, (0, -125), 'midbottom')
        self.refreshButton = button(app, 'refresh', self.populateList,
                                    (-100, -75), 'midbottom')
        self.cancelButton = button(app, 'cancel', self.backToMain, (100, -75),
                                   'midbottom')
        self.restartButton = button(app, 'restart Trosnoth', self.restart,
                                    (0, -125), 'midbottom')

        self.buttons = [
            self.useThemeButton, self.refreshButton, self.cancelButton,
            self.restartButton
        ]

        # Combine the elements
        self.elements = self.staticText + self.dynamicText + self.buttons + [
            self.themeList
        ]

        self.contentTypes = {
            "sprites": "sprite",
            "blocks": "map block",
            "fonts": "font",
            "startupMenu": "backdrop"
        }

        # Populate the list of replays
        self.populateList()
Beispiel #9
0
    def __init__(self, app, onClose=None):
        super(SoundSettingsTab, self).__init__(app, 'Sounds')

        self.onClose = Event()
        if onClose is not None:
            self.onClose.addListener(onClose)

        font = self.app.screenManager.fonts.bigMenuFont
        colours = app.theme.colours

        text = [
            TextElement(self.app, 'Music Volume', font,
                        ScaledLocation(400, 285, 'topright'),
                        colours.headingColour),
            TextElement(self.app, 'Enable Music', font,
                        ScaledLocation(400, 355, 'topright'),
                        colours.headingColour),
            TextElement(self.app, 'Sound Volume', font,
                        ScaledLocation(400, 425, 'topright'),
                        colours.headingColour),
            TextElement(self.app, 'Enable Sound', font,
                        ScaledLocation(400, 495, 'topright'),
                        colours.headingColour),
        ]

        initVolume = app.soundSettings.musicVolume
        musicVolumeLabel = TextElement(self.app, '%d' % (initVolume, ), font,
                                       ScaledLocation(870, 280, 'topleft'),
                                       colours.headingColour)

        self.musicVolumeSlider = Slider(self.app,
                                        ScaledArea(450, 280, 400, 40))
        onSlide = lambda volume: musicVolumeLabel.setText('%d' % volume)
        self.musicVolumeSlider.onSlide.addListener(onSlide)
        self.musicVolumeSlider.onValueChanged.addListener(onSlide)
        self.musicVolumeSlider.setVal(initVolume)

        self.musicBox = CheckBox(self.app,
                                 ScaledLocation(450, 360),
                                 text='',
                                 font=font,
                                 colour=(192, 192, 192),
                                 initValue=app.soundSettings.musicEnabled)

        initSndVolume = app.soundSettings.soundVolume
        soundVolumeLabel = TextElement(self.app,
                                       '%d' % (initSndVolume, ), font,
                                       ScaledLocation(870, 420, 'topleft'),
                                       colours.headingColour)

        self.soundVolumeSlider = Slider(self.app,
                                        ScaledArea(450, 420, 400, 40))
        onSlide = lambda volume: soundVolumeLabel.setText('%d' % volume)
        self.soundVolumeSlider.onSlide.addListener(onSlide)
        self.soundVolumeSlider.onValueChanged.addListener(onSlide)
        self.soundVolumeSlider.setVal(initSndVolume)

        self.soundBox = CheckBox(self.app,
                                 ScaledLocation(450, 500),
                                 text='',
                                 font=font,
                                 colour=(192, 192, 192),
                                 initValue=app.soundSettings.soundEnabled)

        self.buttons = [
            button(app,
                   'save',
                   self.saveSettings, (-100, -75),
                   'midbottom',
                   secondColour=app.theme.colours.white),
            button(app,
                   'cancel',
                   self.onClose.execute, (100, -75),
                   'midbottom',
                   secondColour=app.theme.colours.white)
        ]

        self.elements = text + [
            musicVolumeLabel, self.musicVolumeSlider, self.musicBox,
            soundVolumeLabel, self.soundVolumeSlider, self.soundBox
        ] + self.buttons
Beispiel #10
0
class Slider(framework.Element):
    def __init__(self, app, area, bounds=None, snap=False):
        super(Slider, self).__init__(app)
        self.app = app
        self.area = area
        self.beingDragged = False
        self.snap = snap
        if not bounds:
            bounds = 0, 100
        self.lowBound, self.highBound = bounds
        self.unscaledSlider = 20
        self.sliderRectWidth = int(self.unscaledSlider *
                                   app.screenManager.scaleFactor)
        self.lineColour = (0, 192, 0)
        self.sliderColour = (0, 255, 0)
        self.onValueChanged = Event()
        self.onSlide = Event()

        self.largeArea = ScaledArea(
            self.area.point.val[0] + self.unscaledSlider / 2,
            self.area.point.val[1],
            self.area.size.val[0] - self.unscaledSlider + 1,
            self.area.size.val[1])

        self.area, self.largeArea = self.largeArea, self.area

        self.sliderVal = self.highBound

    def doSnap(self, value):
        if self.snap:
            return int(value + 0.5)
        return value

    def getVal(self):
        return self.sliderVal

    def setVal(self, val):
        old = self.sliderVal
        self.sliderVal = self.doSnap(val)
        if old != self.sliderVal:
            self.onValueChanged.execute(self.sliderVal)

    def setRange(self, low, high):
        self.lowBound = low
        self.highBound = high
        if self.sliderVal > self.highBound:
            self.sliderVal = self.highBound
        elif self.sliderVal < self.lowBound:
            self.sliderVal = self.lowBound

    def setSliderColour(self, colour):
        self.sliderColour = colour

    def setLineColour(self, colour):
        self.lineColour = colour

    def _getRange(self):
        return self.highBound - self.lowBound

    def _getRect(self):
        return self.area.getRect(self.app)

    def _getPt(self):
        return self._getRect().topleft

    def _getSize(self):
        return self._getRect().size

    def _valPerPixel(self):
        return self._getSize()[0] / (self._getRange() + 0.)

    def _pixelPerVal(self):
        return self._getRange() / (self._getSize()[0] + 0.)

    # Number of pixels from 0 to width
    def _relPx(self, x):
        return min(max(0, (x - self._getPt()[0])), self._getSize()[0])

    def _mouseAt(self, x):
        old = self.sliderVal
        self.sliderVal = self.lowBound + self._pixelPerVal() * self._relPx(x)
        if old != self.sliderVal:
            self.onSlide.execute(self.sliderVal)

    def _getSliderRect(self):
        # Ignore pos for now
        sliderRect = pygame.Rect(0, 0, self._getSliderRectWidth(),
                                 self._getSize()[1])
        pt = self._getPt()
        sliderRect.midtop = (
            (self.sliderVal - self.lowBound) * self._valPerPixel() + pt[0],
            pt[1])
        return sliderRect

    def _getLineWidth(self):
        return max(1, self._getSize()[1] / 8)

    def _getSliderRectWidth(self):
        return int(self.unscaledSlider * self.app.screenManager.scaleFactor)

    def processEvent(self, event):
        if (event.type == pygame.MOUSEBUTTONDOWN
                and self.largeArea.getRect(self.app).collidepoint(event.pos)):
            # Each click of the scroll wheel moves the slider by 5%
            percent = int((self.highBound - self.lowBound) * 0.05)

            if event.button == 1:
                self.beingDragged = True
                self._mouseAt(event.pos[0])
            elif event.button == 4:
                self.setVal(min(self.highBound, self.sliderVal + percent))
            elif event.button == 5:
                self.setVal(max(self.lowBound, self.sliderVal - percent))
            else:
                return event

        elif event.type == pygame.MOUSEMOTION and self.beingDragged:
            self._mouseAt(event.pos[0])

        elif (event.type == pygame.MOUSEBUTTONUP and event.button == 1
              and self.beingDragged):
            self.beingDragged = False
            self.sliderVal = self.doSnap(self.sliderVal)
            self.onValueChanged.execute(self.sliderVal)
        else:
            return event
        return None

    def draw(self, surface):
        r = self.largeArea.getRect(self.app)
        lineWidth = self._getLineWidth()
        pygame.draw.line(surface, self.lineColour, r.midleft, r.midright,
                         lineWidth)

        if self.snap:
            low = r.left
            high = r.right
            count = self.highBound - self.lowBound + 0.
            y0 = r.centery - 0.25 * r.height
            y1 = r.centery + 0.25 * r.height
            for i in xrange(self.lowBound, self.highBound + 1):
                x = (high * i + low * (count - i)) / count
                pygame.draw.line(surface, self.lineColour, (x, y0), (x, y1),
                                 lineWidth)

        surface.fill(self.sliderColour, self._getSliderRect())
Beispiel #11
0
    def __init__(self, app, tabContainer, onCancel=None, onReplay=None):
        super(SavedGameTab, self).__init__(app, 'Saved Games')
        self.app = app
        self.tabContainer = tabContainer
        self.onCancel = Event(listener=onCancel)
        self.onReplay = Event(listener=onReplay)

        font = self.app.screenManager.fonts.ampleMenuFont
        smallFont = self.app.screenManager.fonts.menuFont
        colours = app.theme.colours

        # Static text
        self.staticText = [
            TextElement(self.app, 'server details:', font,
                        ScaledLocation(960, 200, 'topright'),
                        colours.headingColour),
            TextElement(self.app, 'date and time:', font,
                        ScaledLocation(960, 370, 'topright'),
                        colours.headingColour),
            TextElement(self.app, 'replay:', font,
                        ScaledLocation(620, 550, 'topleft'),
                        colours.headingColour),
            TextElement(self.app, 'stats:', font,
                        ScaledLocation(620, 605, 'topleft'),
                        colours.headingColour)
        ]

        # Dynamic text
        self.listHeaderText = TextElement(self.app, 'available game files:',
                                          font, ScaledLocation(65, 200),
                                          colours.headingColour)
        self.noFiles1Text = TextElement(self.app, '', font,
                                        ScaledLocation(65, 260),
                                        colours.noGamesColour)
        self.noFiles2Text = TextElement(self.app, '', font,
                                        ScaledLocation(65, 310),
                                        colours.noGamesColour)
        self.serverNameText = TextElement(self.app, '', smallFont,
                                          ScaledLocation(960, 255, 'topright'),
                                          colours.startButton)
        self.serverDetailsText = TextElement(
            self.app, '', smallFont, ScaledLocation(960, 295, 'topright'),
            colours.startButton)
        self.dateText = TextElement(self.app, '', smallFont,
                                    ScaledLocation(960, 425, 'topright'),
                                    colours.startButton)
        self.lengthText = TextElement(self.app, '', smallFont,
                                      ScaledLocation(960, 465, 'topright'),
                                      colours.startButton)
        self.noReplayText = TextElement(self.app, '', smallFont,
                                        ScaledLocation(960, 550, 'topright'),
                                        colours.noGamesColour)
        self.noStatsText = TextElement(self.app, '', smallFont,
                                       ScaledLocation(960, 605, 'topright'),
                                       colours.noGamesColour)

        self.dynamicText = [
            self.listHeaderText, self.noFiles1Text, self.noFiles2Text,
            self.serverNameText, self.serverDetailsText, self.dateText,
            self.lengthText, self.noReplayText, self.noStatsText
        ]

        # Text buttons
        self.watchButton = TextButton(self.app,
                                      ScaledLocation(960, 550,
                                                     'topright'), '', font,
                                      colours.secondMenuColour, colours.white)
        self.watchButton.onClick.addListener(self.watchReplay)

        self.statsButton = TextButton(self.app,
                                      ScaledLocation(960, 605,
                                                     'topright'), '', font,
                                      colours.secondMenuColour, colours.white)
        self.statsButton.onClick.addListener(self.viewStats)

        self.refreshButton = TextButton(self.app,
                                        ScaledLocation(620, 665,
                                                       'topleft'), 'refresh',
                                        font, colours.secondMenuColour,
                                        colours.white)
        self.refreshButton.onClick.addListener(self.populateList)

        self.cancelButton = TextButton(self.app,
                                       ScaledLocation(960, 665, 'topright'),
                                       'cancel', font,
                                       colours.secondMenuColour, colours.white)
        self.cancelButton.onClick.addListener(self._cancel)

        self.loadFileButton = TextButton(
            self.app, ScaledLocation(960, 190, 'bottomright'), 'load file...',
            font, colours.mainMenuColour, colours.mainMenuHighlight)
        self.loadFileButton.onClick.addListener(self.showOpenDialog)

        self.buttons = [
            self.watchButton, self.statsButton, self.refreshButton,
            self.cancelButton, self.loadFileButton
        ]

        # Replay list
        self.gameList = ListBox(self.app, ScaledArea(65, 255, 500, 450), [],
                                smallFont, colours.listboxButtons)
        self.gameList.onValueChanged.addListener(self.updateSidebar)

        # Combine the elements
        self.elementsFiles = (self.staticText + self.dynamicText +
                              self.buttons + [self.gameList])
        self.elementsNoFiles = self.dynamicText + self.buttons

        # Populate the list of replays
        self.populateList()
Beispiel #12
0
    def __init__(self, app, onClose=None):
        super(DisplaySettingsTab, self).__init__(app, 'Display')

        self.onClose = Event()
        if onClose is not None:
            self.onClose.addListener(onClose)

        font = self.app.screenManager.fonts.bigMenuFont
        smallNoteFont = self.app.screenManager.fonts.smallNoteFont

        colour = self.app.theme.colours.headingColour

        def mkText(text, x, y, textFont=font, anchor='topright'):
            return TextElement(self.app, text, textFont,
                               ScaledLocation(x, y, anchor), colour)

        self.text = [
            mkText('X', 640, 280),
            mkText('Screen resolution', 430, 280),
            mkText('Fullscreen mode', 430, 360),
            mkText('Graphics detail', 430, 440),
            mkText('low', 460, 475, textFont=smallNoteFont, anchor='midtop'),
            mkText('high', 845, 475, textFont=smallNoteFont, anchor='midtop'),
            mkText('Show timings', 430, 525),
        ]

        self.invalidInputText = TextElement(self.app, '', font,
                                            ScaledLocation(512, 230, 'midtop'),
                                            (192, 0, 0))

        self.widthInput = prompt.InputBox(self.app,
                                          ScaledArea(460, 265, 150, 60),
                                          initValue=str(
                                              self.app.screenManager.size[0]),
                                          font=font,
                                          maxLength=4,
                                          validator=prompt.intValidator)

        self.widthInput.onEnter.addListener(lambda sender: self.saveSettings())
        self.widthInput.onClick.addListener(self.setFocus)
        self.widthInput.onTab.addListener(self.tabNext)

        self.heightInput = prompt.InputBox(self.app,
                                           ScaledArea(652, 265, 150, 60),
                                           initValue=str(
                                               self.app.screenManager.size[1]),
                                           font=font,
                                           maxLength=4,
                                           validator=prompt.intValidator)

        self.heightInput.onEnter.addListener(
            lambda sender: self.saveSettings())
        self.heightInput.onClick.addListener(self.setFocus)
        self.heightInput.onTab.addListener(self.tabNext)

        self.tabOrder = [self.widthInput, self.heightInput]

        self.fullscreenBox = CheckBox(
            self.app,
            ScaledLocation(460, 365),
            text='',
            font=font,
            colour=(192, 192, 192),
            initValue=self.app.screenManager.isFullScreen(),
        )
        self.fullscreenBox.onValueChanged.addListener(self.fullscreenChanged)

        displaySettings = app.displaySettings

        self.detailSlider = Slider(
            self.app,
            ScaledArea(460, 430, 390, 40),
            bounds=(0, len(displaySettings.DETAIL_LEVELS) - 1),
            snap=True)
        self.detailSlider.setVal(
            displaySettings.DETAIL_LEVELS.index(displaySettings.detailLevel))
        self.detailSlider.onValueChanged.addListener(self.detailChanged)

        self.showTimingsBox = CheckBox(
            self.app,
            ScaledLocation(460, 530),
            text='',
            font=font,
            colour=(192, 192, 192),
            initValue=displaySettings.showTimings,
        )

        self.input = [
            self.widthInput, self.heightInput, self.widthInput,
            self.fullscreenBox, self.detailSlider, self.showTimingsBox
        ]

        self.elements = self.text + self.input + [
            self.invalidInputText,
            button(app,
                   'save',
                   self.saveSettings, (-100, -75),
                   'midbottom',
                   secondColour=app.theme.colours.white),
            button(app,
                   'cancel',
                   self.cancelMenu, (100, -75),
                   'midbottom',
                   secondColour=app.theme.colours.white),
        ]
        self.setFocus(self.widthInput)
Beispiel #13
0
    def __init__(self, app, onClose=None):
        super(KeymapTab, self).__init__(app, 'Controls')
        self.font = app.screenManager.fonts.bigMenuFont

        self.onClose = Event()
        if onClose is not None:
            self.onClose.addListener(onClose)

        # Break things up into categories
        movement = ['jump', 'down', 'left', 'right']
        menus = ['menu', 'more actions']
        actions = [
            'respawn', 'select upgrade', 'activate upgrade', 'change nickname',
            'ready'
        ]
        misc = ['chat', 'follow']
        upgrades = [
            upgradeClass.action for upgradeClass in sorted(
                allUpgrades, key=lambda upgradeClass: upgradeClass.order)
        ]
        upgrades.append('no upgrade')

        display = ['leaderboard', 'toggle interface', 'toggle terminal']

        actionNames = {
            'select upgrade': 'Select upgrade',
            'activate upgrade': 'Activate upgrade',
            'change nickname': 'Change nickname',
            'chat': 'Chat',
            'down': 'Drop down',
            'follow': 'Auto pan (replay)',
            'jump': 'Jump',
            'leaderboard': 'Show leaderboard',
            'left': 'Move left',
            'menu': 'Main menu',
            'more actions': 'Advanced',
            'no upgrade': 'Deselect upgrade',
            'ready': 'Toggle ready',
            'respawn': 'Respawn',
            'right': 'Move right',
            'status bar': 'Status bar',
            'timer': 'Show timer',
            'toggle interface': 'Toggle HUD',
            'toggle terminal': 'Toggle terminal',
            'zone progress': 'Show zone bar',
        }
        actionNames.update((upgradeClass.action, upgradeClass.name)
                           for upgradeClass in allUpgrades)

        # Organise the categories by column
        self.layout = [
            [movement, menus],
            [actions, display],
            [upgrades, misc],
        ]

        self.errorInfo = TextElement(self.app, '', self.font,
                                     ScaledLocation(512, 580, 'center'))
        self.text = [self.errorInfo]
        self.inputLookup = {}
        xPos = 190

        # Lay everything out automatically.
        keymapFont = self.app.screenManager.fonts.keymapFont
        keymapInputFont = self.app.screenManager.fonts.keymapInputFont
        for column in self.layout:  # Each column
            yPos = 200
            for category in column:  # Each category
                for action in category:  # Each action
                    # Draw action name (eg. Respawn)
                    self.text.append(
                        TextElement(self.app, actionNames[action], keymapFont,
                                    ScaledLocation(xPos, yPos + 6, 'topright'),
                                    self.app.theme.colours.headingColour))

                    # Create input box
                    box = prompt.KeycodeBox(self.app,
                                            ScaledArea(xPos + 10, yPos, 100,
                                                       30),
                                            font=keymapInputFont)
                    box.onClick.addListener(self.setFocus)
                    box.onChange.addListener(self.inputChanged)
                    box.__action = action
                    self.inputLookup[action] = box

                    yPos += 35  # Between items
                yPos += 35  # Between categories
            xPos += 320  # Between columns

        self.elements = self.text + self.inputLookup.values() + [
            button(app,
                   'restore default controls',
                   self.restoreDefaults, (0, -125),
                   'midbottom',
                   secondColour=app.theme.colours.white),
            button(app,
                   'save',
                   self.saveSettings, (-100, -75),
                   'midbottom',
                   secondColour=app.theme.colours.white),
            button(app,
                   'cancel',
                   self.cancel, (100, -75),
                   'midbottom',
                   secondColour=app.theme.colours.white),
        ]

        self.populateInputs()
    def __init__(self, app, onClose=None):
        super(KeymapTab, self).__init__(app, 'Controls')
        self.font = app.screenManager.fonts.bigMenuFont

        self.onClose = Event()
        if onClose is not None:
            self.onClose.addListener(onClose)

        # Break things up into categories
        movement = [
            ACTION_JUMP, ACTION_DOWN, ACTION_LEFT, ACTION_RIGHT, ACTION_HOOK
        ]
        menus = [ACTION_MAIN_MENU, ACTION_MORE_MENU]
        actions = [
            ACTION_UPGRADE_MENU, ACTION_USE_UPGRADE, ACTION_EDIT_PLAYER_INFO,
            ACTION_READY, ACTION_SHOW_TRAJECTORY, ACTION_EMOTE
        ]
        misc = [ACTION_CHAT, ACTION_FOLLOW]
        upgrades = [
            upgradeClass.action for upgradeClass in sorted(
                allUpgrades, key=lambda upgradeClass: upgradeClass.order)
        ]
        upgrades.append(ACTION_CLEAR_UPGRADE)

        display = [
            ACTION_LEADERBOARD_TOGGLE, ACTION_HUD_TOGGLE,
            ACTION_TERMINAL_TOGGLE
        ]

        actionNames = {
            ACTION_EDIT_PLAYER_INFO: 'Change nick / hat',
            ACTION_CHAT: 'Chat',
            ACTION_CLEAR_UPGRADE: 'Deselect upgrade',
            ACTION_DOWN: 'Drop down',
            ACTION_FOLLOW: 'Auto pan (replay)',
            ACTION_HOOK: 'Grappling hook',
            ACTION_HUD_TOGGLE: 'Toggle HUD',
            ACTION_JUMP: 'Jump',
            ACTION_LEADERBOARD_TOGGLE: 'Show leaderboard',
            ACTION_LEFT: 'Move left',
            ACTION_MAIN_MENU: 'Main menu',
            ACTION_MORE_MENU: 'Advanced',
            ACTION_READY: 'Toggle ready',
            ACTION_RIGHT: 'Move right',
            ACTION_TERMINAL_TOGGLE: 'Toggle terminal',
            ACTION_UPGRADE_MENU: 'Select upgrade',
            ACTION_USE_UPGRADE: 'Activate upgrade',
            ACTION_SHOW_TRAJECTORY: 'Show trajectory',
            ACTION_EMOTE: 'Emote',
        }
        actionNames.update((upgradeClass.action, upgradeClass.name)
                           for upgradeClass in allUpgrades)

        # Organise the categories by column
        self.layout = [
            [movement, menus],
            [actions, display],
            [upgrades, misc],
        ]

        self.errorInfo = TextElement(self.app, '', self.font,
                                     ScaledLocation(512, 580, 'center'))
        self.text = [self.errorInfo]
        self.inputLookup = {}
        xPos = 210

        # Lay everything out automatically.
        keymapFont = self.app.screenManager.fonts.keymapFont
        keymapInputFont = self.app.screenManager.fonts.keymapInputFont
        for column in self.layout:  # Each column
            yPos = 200
            for category in column:  # Each category
                for action in category:  # Each action
                    # Draw action name (eg. Respawn)
                    self.text.append(
                        TextElement(self.app, actionNames[action], keymapFont,
                                    ScaledLocation(xPos, yPos + 6, 'topright'),
                                    self.app.theme.colours.headingColour))

                    # Create input box
                    box = prompt.KeycodeBox(self.app,
                                            ScaledArea(xPos + 10, yPos, 100,
                                                       30),
                                            font=keymapInputFont,
                                            acceptMouse=True)
                    box.onClick.addListener(self.setFocus)
                    box.onChange.addListener(self.inputChanged)
                    box.__action = action
                    self.inputLookup[action] = box

                    yPos += 35  # Between items
                yPos += 35  # Between categories
            xPos += 310  # Between columns

        self.elements = self.text + list(self.inputLookup.values()) + [
            button(app,
                   'restore default controls',
                   self.restoreDefaults, (0, -125),
                   'midbottom',
                   secondColour=app.theme.colours.white),
            button(app,
                   'save',
                   self.saveSettings, (-100, -75),
                   'midbottom',
                   secondColour=app.theme.colours.white),
            button(app,
                   'cancel',
                   self.cancel, (100, -75),
                   'midbottom',
                   secondColour=app.theme.colours.white),
        ]

        self.populateInputs()