Example #1
0
    def __init__(self, app, tabContainer):
        super(CompoundElement, self).__init__(app)

        self.firstVisible = 0
        self.skipOnMove = 3
        self.numToDisplay = 0
        self.arrowWidth = arrowWidth = 30

        self.elements = []
        self.headers = []
        self.selectedIndex = -1

        onLeft = lambda: self._moveDirection(True)
        onRight = lambda: self._moveDirection(False)
        canClickLeft = lambda: self.firstVisible > 0
        canClickRight = lambda: (self.firstVisible + self.numToDisplay < len(
            self.headers))
        self.tabContainer = tabContainer

        self._getHeight = _getHeight = tabContainer._getHeaderHeight

        class ArrowSize(object):
            def __init__(self, text):
                self.text = text

            def getSize(self, app):
                return (arrowWidth, _getHeight())

            def __repr__(self):
                return "Arrow Size"

        self.leftArrow = TabHeaderArrow(app, tabContainer, "<",
                                        tabContainer.font, onLeft,
                                        canClickLeft)
        leftLocation = Location(
            AttachedPoint((0, 0), tabContainer._getRect, 'topleft'), 'topleft')
        leftSize = ArrowSize("<")
        self.leftArrow.setDimensions(leftLocation, leftSize)

        self.rightArrow = TabHeaderArrow(app, tabContainer, ">",
                                         tabContainer.font, onRight,
                                         canClickRight)
        rightLocation = Location(
            AttachedPoint((0, 0), tabContainer._getRect, 'topright'),
            'topright')
        rightSize = ArrowSize(">")
        self.rightArrow.setDimensions(rightLocation, rightSize)

        self._getPt = self.tabContainer._getPt
Example #2
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]
Example #3
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)
Example #4
0
    def __init__(self, app, area, text, colour, fonts, bgColour=None,
            textAlign='left', loop=False, startOff=False, antiAlias=False):
        super(ScrollingText,self).__init__(app)

        self.area = area
        self.border = False
        self.shadowColour = None
        self.loop = loop
        self.startOff = startOff
        self.bgColour = bgColour
        self.speed = 50

        self.offset = 0
        self.colour = colour
        self.fonts = fonts
        self.text = text
        self.textAlign = textAlign
        self.antiAlias = antiAlias
        self.dirty = False

        # A test to see whether the size has changed
        self.lastSize = app.screenManager.size

        self._setImage()

        self.autoScroll = False


        # Create up and down buttons for if there's autoscroll.
        if 'buttons' in fonts:
            font = fonts['buttons']
        else:
            font = app.fonts.scrollingButtonsFont
        pos = Location(AttachedPoint((0, 0), self._getRect, 'topright'),
                'topleft')
        self.upBtn = TextButton(app, pos, ' up', font, colour, (255,255,255))
        pos = Location(AttachedPoint((0,0), self._getRect, 'bottomright'),
                'bottomleft')
        self.dnBtn = TextButton(app, pos, ' down', font, colour, (255,255,255))

        self.onFinishedScrolling = Event()
    def __init__(self, app, text, area, image, value=None):
        super(ImageRadioButton, self).__init__(app)
        textLoc = Location(AttachedPoint((0, 0), self._getRect, 'midbottom'),
                           'midbottom')
        font = app.screenManager.fonts.smallNoteFont
        self.text = TextElement(app, text, font, textLoc, (0, 0, 0))
        picLoc = Location(AttachedPoint((0, 0), self._getRect, 'midtop'),
                          'midtop')
        self.area = area

        self.value = value

        self._selected = False
        self.group = None

        self.bg = self.IRB_background(app, self)

        self.elements = [self.bg, self.text]

        if image is not None:
            self.image = PictureElement(app, image, picLoc)
            self.elements.insert(1, self.image)
Example #6
0
 def setColour(self, colour):
     self.colour = colour
     self.dirty = True
     pos = Location(AttachedPoint((0,0), self._getRect, 'topright'),
             'topleft')
     if 'buttons' in self.fonts:
         font = self.fonts['buttons']
     else:
         font = self.app.fonts.scrollingButtonsFont
     self.upBtn = TextButton(self.app, pos, ' up', font, colour,
             (255,255,255))
     self.dnBtn = TextButton(self.app, pos, ' down', font, colour,
             (255,255,255))
Example #7
0
    def __init__(self, app, pos, size, displaySize):
        CompoundElement.__init__(self, app)

        self.pos = pos
        self.size = size
        self.displaySize = displaySize
        self.backgroundColour = (64, 64, 64)

        self._screenSize = tuple(app.screenManager.size)

        self.__horizontalScrollBar = ScrollBar(
            app, self,
            Location(AttachedPoint((0, 0), self._getRect, 'bottomleft'),
                     'bottomleft'), True)
        self.__verticalScrollBar = ScrollBar(
            app, self,
            Location(AttachedPoint((0, 0), self._getRect, 'topright'),
                     'topright'), False)

        # internalPos is the position on the full canvas that we are drawing
        # from
        self.internalPos = None
        self.setInternalPos((0, 0))
    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]
Example #9
0
    def __init__(self,
                 app,
                 area,
                 items,
                 font,
                 colour,
                 hlColour=None,
                 showBtns=True):
        super(ListBox, self).__init__(app)
        self.area = area
        self.items = items
        self.font = font
        self.showBtns = showBtns
        self.onValueChanged = Event()

        self.setColour(colour, hlColour)

        self.offset = 0
        self.index = -1

        # Create up and down buttons.
        if showBtns:
            img1 = TextImage('up', font, colour)
            img2 = TextImage('up', font, self.hlColour)
            self.upBtn = HoverButton(
                self.app,
                Location(AttachedPoint((0, 0), self._getRect, 'topright'),
                         'topright'), img1, img2)
            self.upBtn.onClick.addListener(self.upClick)
            img1 = TextImage('down', font, colour)
            img2 = TextImage('down', font, self.hlColour)
            self.dnBtn = HoverButton(
                self.app,
                Location(AttachedPoint((0, 0), self._getRect, 'bottomright'),
                         'bottomright'), img1, img2)
            self.dnBtn.onClick.addListener(self.dnClick)
Example #10
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()
Example #11
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()
Example #12
0
def ScrollableCanvasAttachedPoint(scrollableCanvas, val, anchor='topleft'):
    return AttachedPoint(val, scrollableCanvas._getOffsetCanvasRect, anchor)
def DialogBoxAttachedPoint(box, val, anchor='topleft'):
    return AttachedPoint(val, lambda: getInsideRectFromZero(box), anchor)