Mercurial > boomslang
comparison gamelib/gamescreen.py @ 26:0a68d137f509
Initial inventory palette thing.
author | Jeremy Thurgood <firxen@gmail.com> |
---|---|
date | Sun, 22 Aug 2010 18:38:56 +0200 |
parents | 9d5de13e2ac3 |
children | 5c7bbbdf9296 |
comparison
equal
deleted
inserted
replaced
25:f9e697e0c6ba | 26:0a68d137f509 |
---|---|
1 # menu.py | 1 # menu.py |
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 pygame.color import Color | |
5 from albow.screen import Screen | 6 from albow.screen import Screen |
6 from albow.controls import Button, Label | 7 from albow.controls import Button, Label |
7 from albow.layout import Column | 8 from albow.layout import Column |
9 from albow.palette_view import PaletteView | |
10 | |
11 | |
12 class InventoryView(PaletteView): | |
13 | |
14 info = ["red", "green", "blue", "cyan", "magenta", "yellow"] | |
15 | |
16 sel_color = Color("white") | |
17 sel_width = 2 | |
18 | |
19 def __init__(self): | |
20 PaletteView.__init__(self, (50, 50), 1, 6, scrolling=True) | |
21 self.selection = None | |
22 | |
23 def num_items(self): | |
24 return len(self.info) | |
25 | |
26 def draw_item(self, surface, item_no, rect): | |
27 d = -2 * self.sel_width | |
28 r = rect.inflate(d, d) | |
29 color = Color(self.info[item_no]) | |
30 surface.fill(color, r) | |
31 | |
32 def click_item(self, item_no, event): | |
33 self.selection = item_no | |
34 | |
35 def item_is_selected(self, item_no): | |
36 return self.selection == item_no | |
37 | |
38 def add_item(self, colstr): | |
39 self.info.append(colstr) | |
40 | |
8 | 41 |
9 class GameScreen(Screen): | 42 class GameScreen(Screen): |
10 def __init__(self, shell): | 43 def __init__(self, shell): |
11 Screen.__init__(self, shell) | 44 Screen.__init__(self, shell) |
12 self.shell = shell | 45 self.shell = shell |
13 StartButton = Button('Main Menu', action = self.main_menu) | 46 StartButton = Button('Main Menu', action = self.main_menu) |
14 QuitButton = Button('Quit', action = shell.quit) | 47 QuitButton = Button('Quit', action = shell.quit) |
48 AddItemButton = Button('Add item', action = self.add_item) | |
15 Title = Label('Caught! ... In SPAACE') | 49 Title = Label('Caught! ... In SPAACE') |
16 menu = Column([ | 50 menu = Column([ |
17 Title, | 51 Title, |
18 StartButton, | 52 StartButton, |
19 QuitButton, | 53 QuitButton, |
54 AddItemButton, | |
20 ], align='l', spacing=20) | 55 ], align='l', spacing=20) |
21 self.add_centered(menu) | 56 self.add_centered(menu) |
57 self.inventory = InventoryView() | |
58 self.add(self.inventory) | |
22 | 59 |
23 def main_menu(self): | 60 def main_menu(self): |
24 print 'Returning to menu' | 61 print 'Returning to menu' |
25 self.shell.show_screen(self.shell.menu_screen) | 62 self.shell.show_screen(self.shell.menu_screen) |
26 | 63 |
27 | 64 def add_item(self): |
65 self.inventory.add_item("white") |