source: gamelib/mainmenu.py @ 346:6baf8b5beb5c

Last change on this file since 346:6baf8b5beb5c was 346:6baf8b5beb5c, checked in by Neil Muller <drnlmuller@…>, 11 years ago

Remove the "constant" constant

File size: 1.9 KB
Line 
1"""Main menu."""
2
3from pgu import gui
4import pygame
5import constants
6import engine
7import imagecache
8
9def make_main_menu():
10    """Create a main menu"""
11    main_menu = MainMenu()
12
13    c = MenuContainer(align=0, valign=0)
14    c.add(main_menu, 0, 0)
15
16    return c
17
18class MenuContainer(gui.Container):
19    def paint(self, s):
20        pygame.display.set_caption(constants.NAME)
21        splash = imagecache.load_image("images/splash.png")
22        pygame.display.get_surface().blit(splash, (0, 0))
23        gui.Container.paint(self, s)
24
25    def get_mode(self):
26        return self.widgets[0].mode
27
28class MainMenu(gui.Table):
29    def __init__(self, **params):
30        gui.Table.__init__(self, **params)
31        self.mode = None
32
33        def fullscreen_toggled():
34            pygame.display.toggle_fullscreen()
35
36        def quit_pressed():
37            pygame.event.post(engine.QUIT)
38
39        def start_game(mode):
40            self.mode = mode
41            pygame.event.post(engine.START_DAY)
42
43        def help_pressed():
44            pygame.event.post(engine.GO_HELP_SCREEN)
45
46        style = {
47            "padding_bottom": 15,
48        }
49        td_kwargs = {
50            "align": 0,
51            "style": style,
52        }
53 
54        for mode in constants.TURN_LIMITS:
55            button = gui.Button(mode)
56            button.connect(gui.CLICK, start_game, mode)
57            self.tr()
58            self.td(button, **td_kwargs)
59
60        quit_button = gui.Button("Quit")
61        quit_button.connect(gui.CLICK, quit_pressed)
62
63        help_button = gui.Button("Instructions")
64        help_button.connect(gui.CLICK, help_pressed)
65
66        fullscreen_toggle = gui.Button("Toggle Fullscreen")
67        fullscreen_toggle.connect(gui.CLICK, fullscreen_toggled)
68
69        self.tr()
70        self.td(help_button, **td_kwargs)
71
72        self.tr()
73        self.td(fullscreen_toggle, **td_kwargs)
74
75        self.tr()
76        self.td(quit_button, **td_kwargs)
Note: See TracBrowser for help on using the repository browser.