view skaapsteker/menuscene.py @ 274:e006ec7b3d8f

proper levels
author Adrianna Pińska <adrianna.pinska@gmail.com>
date Fri, 08 Apr 2011 19:12:44 +0200
parents afd9256ad682
children 8631e38afc24
line wrap: on
line source

import pygame
from pygame.locals import K_ESCAPE, K_q, KEYDOWN, QUIT

from .cutscene import opening_cutscene
from .engine import ChangeScene, Scene
from .levelscene import LevelScene
from .widgets.text import Text, TextChoice


class MenuScene(Scene):
    def __init__(self, game_state, soundsystem, cur_game=None):
        super(MenuScene, self).__init__(game_state, soundsystem)
        self.widgets.append(Text("MENU:", (50, 50), color='white', size=48))
        self.cur_game = cur_game
        menu_options = [
            ('Starting Cutscene', 'cutscene'),
            ('Temple', 'temple.starting'),
            ("Temple grounds", "temple_grounds.starting"),
            ("Road", "road.starting"),
            ("Town", "town.starting"),
            ("Tea house", "tea_house.starting"),
            ("Kumiko's rooms", "geisha_room.starting"),
            ("Market", "market.starting"),
            ("Fishmonger's house", "fishmonger_house.starting"),
            ("Theatre", "theatre.starting"),
            ("Celestial plane", "celestial_plane.starting"),
            ('Quit', 'quit'),
        ]
        if cur_game is not None:
            menu_options.insert(0, ('Resume Game', 'resume'))
        self.choice = TextChoice(menu_options, (50, 100), color='white')
        self.choice.callbacks.append(self.selected)
        self.widgets.append(self.choice)

    def selected(self, option, data):
        "Callback from menu TextChoice"
        if data == 'resume':
            ChangeScene.post(self.cur_game)
        elif data == 'cutscene':
            ChangeScene.post(opening_cutscene(self.game_state, self._soundsystem))
        elif data == 'quit':
            pygame.event.post(pygame.event.Event(QUIT))
        else:
            ChangeScene.post(LevelScene(self.game_state, self._soundsystem, data))

    def draw(self, surface, engine):
        surface.fill(pygame.Color('black'))
        super(MenuScene, self).draw(surface, engine)

    def dispatch(self, ev):
        if ev.type is KEYDOWN:
            if ev.key in(K_q, K_ESCAPE):
                pygame.event.post(pygame.event.Event(QUIT))
        super(MenuScene, self).dispatch(ev)