comparison gamelib/gamescreen.py @ 58:9048cf43f613

Popup menu
author Neil Muller <neil@dip.sun.ac.za>
date Mon, 23 Aug 2010 15:51:27 +0200
parents 0abd45c58bd3
children 3087be3463e0
comparison
equal deleted inserted replaced
57:4f9d412d83db 58:9048cf43f613
2 # Copyright Boomslang team, 2010 (see COPYING File) 2 # Copyright Boomslang team, 2010 (see COPYING File)
3 # Main menu for the game 3 # Main menu for the game
4 4
5 from state import initial_state, Item 5 from state import initial_state, Item
6 from hand import HandButton 6 from hand import HandButton
7 from popupmenu import PopupMenu
7 from constants import BUTTON_SIZE 8 from constants import BUTTON_SIZE
8 9
9 from pygame.color import Color 10 from pygame.color import Color
10 from pygame import Rect 11 from pygame import Rect
11 from pygame.locals import BLEND_ADD 12 from pygame.locals import BLEND_ADD
70 Button('Use hand', action = lambda: self.state.scenes['cryo'].things['cryo.door'].interact(None)), 71 Button('Use hand', action = lambda: self.state.scenes['cryo'].things['cryo.door'].interact(None)),
71 Button('Use triangle', action = lambda: self.state.scenes['cryo'].things['cryo.door'].interact(self.state.items['triangle'])), 72 Button('Use triangle', action = lambda: self.state.scenes['cryo'].things['cryo.door'].interact(self.state.items['triangle'])),
72 Button('Use titanium_leg', action = lambda: self.state.scenes['cryo'].things['cryo.door'].interact(self.state.items['titanium_leg'])), 73 Button('Use titanium_leg', action = lambda: self.state.scenes['cryo'].things['cryo.door'].interact(self.state.items['titanium_leg'])),
73 ], align='l', spacing=20) 74 ], align='l', spacing=20)
74 self.add_centered(menu) 75 self.add_centered(menu)
75 self.menubutton = Button('Menu', action=self.main_menu) 76 self.popup_menu = PopupMenu(shell)
77 self.menubutton = Button('Menu', action=self.popup_menu.show_menu)
76 self.menubutton.font = get_font(16, 'Vera.ttf') 78 self.menubutton.font = get_font(16, 'Vera.ttf')
77 self.menubutton.set_rect(Rect(0, 0, BUTTON_SIZE, BUTTON_SIZE)) 79 self.menubutton.set_rect(Rect(0, 0, BUTTON_SIZE, BUTTON_SIZE))
78 self.menubutton.bottomleft = self.bottomleft 80 self.menubutton.bottomleft = self.bottomleft
79 self.menubutton.margin = (BUTTON_SIZE - self.menubutton.font.get_linesize()) / 2 81 self.menubutton.margin = (BUTTON_SIZE - self.menubutton.font.get_linesize()) / 2
80 self.add(self.menubutton) 82 self.add(self.menubutton)
90 92
91 # Test items 93 # Test items
92 self.state.add_inventory_item('triangle') 94 self.state.add_inventory_item('triangle')
93 self.state.add_inventory_item('titanium_leg') 95 self.state.add_inventory_item('titanium_leg')
94 96
95 def main_menu(self): 97 # Albow uses magic method names (command + '_cmd'). Yay.
96 print 'Returning to menu' 98 # Albow's search order means they need to be defined here, not in
99 # PopMenu, which is annoying.
100 def hide_cmd(self):
101 # This option does nothing, but the method needs to exist for albow
102 return
103
104 def main_menu_cmd(self):
97 self.shell.show_screen(self.shell.menu_screen) 105 self.shell.show_screen(self.shell.menu_screen)
98 106
99 def add_item(self): 107 def add_item(self):
100 self.state.add_inventory_item("triangle") 108 self.state.add_inventory_item("triangle")
101 109