comparison gamelib/mainmenu.py @ 389:463802281182

Add basic level support (level choosing needs work)
author Neil Muller <drnlmuller@gmail.com>
date Thu, 29 Oct 2009 20:55:37 +0000
parents 79fe97f8e8f5
children 1e24eedbf40f
comparison
equal deleted inserted replaced
388:c6f0e3e72e86 389:463802281182
4 import pygame 4 import pygame
5 import constants 5 import constants
6 import engine 6 import engine
7 import imagecache 7 import imagecache
8 8
9 def make_main_menu(): 9 def make_main_menu(level):
10 """Create a main menu""" 10 """Create a main menu"""
11 main_menu = MainMenu() 11 main_menu = MainMenu(level)
12 12
13 c = MenuContainer(align=0, valign=0) 13 c = MenuContainer(align=0, valign=0)
14 c.add(main_menu, 0, 0) 14 c.add(main_menu, 0, 0)
15 15
16 return c 16 return c
24 24
25 def get_mode(self): 25 def get_mode(self):
26 return self.widgets[0].mode 26 return self.widgets[0].mode
27 27
28 class MainMenu(gui.Table): 28 class MainMenu(gui.Table):
29 def __init__(self, **params): 29 def __init__(self, level, **params):
30 gui.Table.__init__(self, **params) 30 gui.Table.__init__(self, **params)
31 self.mode = None 31 self.mode = None
32 32
33 def fullscreen_toggled(): 33 def fullscreen_toggled():
34 pygame.display.toggle_fullscreen() 34 pygame.display.toggle_fullscreen()
35 35
36 def quit_pressed(): 36 def quit_pressed():
37 pygame.event.post(engine.QUIT) 37 pygame.event.post(engine.QUIT)
38 38
39 def start_game(mode): 39 def start_game():
40 self.mode = mode
41 pygame.event.post(engine.START_DAY) 40 pygame.event.post(engine.START_DAY)
41
42 def choose_level():
43 print 'Needs to be implemented. Specify the level name as a parameter'
42 44
43 def help_pressed(): 45 def help_pressed():
44 pygame.event.post(engine.GO_HELP_SCREEN) 46 pygame.event.post(engine.GO_HELP_SCREEN)
45 47
46 style = { 48 style = {
48 } 50 }
49 td_kwargs = { 51 td_kwargs = {
50 "align": 0, 52 "align": 0,
51 "style": style, 53 "style": style,
52 } 54 }
53 55
54 for mode in constants.TURN_LIMITS: 56 change_button = gui.Button('Choose level')
55 button = gui.Button(mode) 57 change_button.connect(gui.CLICK, choose_level)
56 button.connect(gui.CLICK, start_game, mode) 58 self.tr()
57 self.tr() 59 self.td(change_button, **td_kwargs)
58 self.td(button, **td_kwargs) 60
61 start_button = gui.Button(level.level_name)
62 start_button.connect(gui.CLICK, start_game)
63 self.tr()
64 self.td(start_button, **td_kwargs)
59 65
60 quit_button = gui.Button("Quit") 66 quit_button = gui.Button("Quit")
61 quit_button.connect(gui.CLICK, quit_pressed) 67 quit_button.connect(gui.CLICK, quit_pressed)
62 68
63 help_button = gui.Button("Instructions") 69 help_button = gui.Button("Instructions")