示例#1
0
文件: screens.py 项目: RedSoxFan/LD34
    def tick(self, surface, delta, fontmap):
        scr = None

        # Paint the background
        surface.fill(pygame.color.Color("#222222"))

        # Paint the title
        ttl = fontmap["title"].render(Constants.TITLE, True, pygame.color.Color("#FFFFFF"))
        (w, h) = fontmap["title"].size(Constants.TITLE)
        surface.blit(ttl, (Constants.WIDTH // 2 - w // 2, Constants.HEIGHT // 4 + h // 2))

        # Paint the options
        msel = -1
        for i, option in enumerate(MainMenu.options):
            # Get the bounding box
            (w, h) = fontmap["option"].size(option)
            (x, y) = (Constants.WIDTH // 2 - w // 2, Constants.HEIGHT // 2 + i * h * 2)
            # Determine if the option is highlighted or if the mouse is hovering over it
            m = Mouse.getX() in xrange(x, x + w) and Mouse.getY() in xrange(y, y + h)
            msel = i if m else msel
            s = self.sel == i or m
            # Paint the option
            txt = fontmap["option"].render(option, True, pygame.color.Color("#00FF00" if s else "#CCCCCC"))
            surface.blit(txt, (x, y))

        # Check for input
        if len(MainMenu.options) > 0:
            if Keyboard.released(pygame.K_DOWN):
                # If not at bottom, move the selection down
                Sound.play('menumove')
                self.sel = min(self.sel + 1, len(MainMenu.options) - 1)
            elif Keyboard.released(pygame.K_UP):
                # If not at top, move the selection up
                Sound.play('menumove')
                self.sel = max(0, self.sel - 1)
            elif Keyboard.released(pygame.K_RETURN):
                # Select the highlighted option
                Sound.play('menuselect')
                scr = MainMenu.screens[self.sel]
            elif msel >= 0 and Mouse.leftReleased():
                # Select the option that mouse is hovering over
                Sound.play('menuselect')
                scr = MainMenu.screens[msel]

        return scr
示例#2
0
文件: screens.py 项目: RedSoxFan/LD34
    def tick(self, surface, delta, fontmap):
        scr = None

        # Paint the background
        surface.fill(pygame.color.Color("#222222"))

        # Paint the title
        ttl = fontmap["title"].render("Settings", True, pygame.color.Color("#FFFFFF"))
        (w, h) = fontmap["title"].size("Settings")
        surface.blit(ttl, (Constants.WIDTH // 2 - w // 2, Constants.HEIGHT // 4 + h // 2))

        # Paint the options
        mcb = None
        yoff = 0
        for i, key in enumerate(sorted(self.options.keys())):
            # Get the bounding box
            (w, h) = fontmap["msgtitle"].size(key.replace("~", ""))
            (x, y) = (Constants.WIDTH // 2 - w // 2, Constants.HEIGHT // 2 + yoff)
            # Paint the option
            txt = fontmap["msgtitle"].render(key.replace("~", ""), True, pygame.color.Color("#CCCCCC"))
            surface.blit(txt, (x, y))
            yoff += h + 2

            for j, (txt, val, cb) in enumerate(self.options[key]):
                # Get the bounding box
                (w, h) = fontmap["msgbody"].size(txt)
                (x, y) = (Constants.WIDTH // 2 - w // 2, Constants.HEIGHT // 2 + yoff)
                # Determine if the option is highlighted or if the mouse is hovering over it
                m = Mouse.getX() in xrange(x, x + w) and Mouse.getY() in xrange(y, y + h)
                mcb = cb if m else mcb
                s = self.sel == (i, j) or m
                # Paint the option
                col = "#008800" if val() else "#CCCCCC"
                txt = fontmap["msgbody"].render(txt, True, pygame.color.Color("#00FF00" if s else col))
                surface.blit(txt, (x, y))
                yoff += h + 2

            yoff += 20

        # Check for input
        if len(MainMenu.options) > 0:
            if Keyboard.released(pygame.K_DOWN):
                # If not at bottom, move the selection down
                if self.sel[1] < len(self.options[sorted(self.options.keys())[self.sel[0]]]) - 1:
                    self.sel = (self.sel[0], self.sel[1] + 1)
                    Sound.play('menumove')
                elif self.sel[0] < len(self.options.keys()) - 1:
                    self.sel = (self.sel[0] + 1, 0)
                    Sound.play('menumove')
            elif Keyboard.released(pygame.K_UP):
                # If not at top, move the selection up
                if self.sel[1] > 0:
                    self.sel = (self.sel[0], self.sel[1] - 1)
                    Sound.play('menumove')
                elif self.sel[0] > 0:
                    self.sel = (self.sel[0] - 1, len(self.options[sorted(self.options.keys())[self.sel[0] - 1]]) - 1)
                    Sound.play('menumove')
            elif Keyboard.released(pygame.K_RETURN):
                # Select the highlighted option
                scr = self.options[sorted(self.options.keys())[self.sel[0]]][self.sel[1]][2]()
                Sound.play('menuselect')
            elif mcb is not None and Mouse.leftReleased():
                # Select the option that mouse is hovering over
                scr = mcb()
                Sound.play('menuselect')

        return scr