Mercurial > boomslang
annotate gamelib/popupmenu.py @ 74:75e1040a1121
Hacky "detail view" widget prototype.
author | Jeremy Thurgood <firxen@gmail.com> |
---|---|
date | Mon, 23 Aug 2010 21:26:48 +0200 |
parents | 213e47dea4d0 |
children | c76f2fad2af5 |
rev | line source |
---|---|
58 | 1 # popmenu.py |
2 # Copyright Boomslang team (see COPYING file) | |
3 # Popup menu for the game screen | |
4 | |
5 from constants import BUTTON_SIZE | |
70 | 6 from cursor import CursorWidget |
58 | 7 |
8 from albow.menu import Menu | |
70 | 9 from albow.controls import Button |
58 | 10 from albow.resource import get_font |
70 | 11 from pygame.rect import Rect |
12 | |
13 class PopupMenuButton(Button, CursorWidget): | |
14 | |
15 def __init__(self, text, action): | |
16 Button.__init__(self, text, action) | |
17 | |
18 self.font = get_font(16, 'Vera.ttf') | |
19 self.set_rect(Rect(0, 0, BUTTON_SIZE, BUTTON_SIZE)) | |
20 self.margin = (BUTTON_SIZE - self.font.get_linesize()) / 2 | |
21 | |
22 def get_cursor(self, event): | |
23 # Draw standard arrow, not the sprite cursor | |
24 return None | |
58 | 25 |
26 class PopupMenu(Menu): | |
27 | |
28 def __init__(self, shell): | |
29 self.shell = shell | |
30 items = [ | |
31 ('Resume Game', 'hide'), | |
69
d4bbb26099cc
Some debug object cleanup.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
32 ('Quit Game', 'quit'), |
58 | 33 ('Exit to Main Menu', 'main_menu'), |
34 ] | |
35 # albow.menu.Menu ignores title string | |
36 Menu.__init__(self, None, items) | |
37 self.font = get_font(16, 'Vera.ttf') | |
38 | |
39 def show_menu(self): | |
40 """Call present, with the correct position""" | |
41 item_height = self.font.get_linesize() | |
42 menu_top = 600 - (len(self.items) * item_height + BUTTON_SIZE) | |
43 item = self.present(self.shell, (0, menu_top)) | |
44 if item > -1: | |
45 # A menu item needs to be invoked | |
46 self.invoke_item(item) | |
47 |