Mercurial > boomslang
annotate gamelib/popupmenu.py @ 119:d5f7cccfdb6c
Hook up "detail view" scenes.
author | Jeremy Thurgood <firxen@gmail.com> |
---|---|
date | Tue, 24 Aug 2010 17:04:56 +0200 |
parents | ca10d7e9a2c1 |
children | 97322b78d1c1 |
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 | |
6 | |
7 from albow.menu import Menu | |
70 | 8 from albow.controls import Button |
58 | 9 from albow.resource import get_font |
70 | 10 from pygame.rect import Rect |
11 | |
116
ca10d7e9a2c1
And CursorWidget-ify the popup menu.
Jeremy Thurgood <firxen@gmail.com>
parents:
84
diff
changeset
|
12 from cursor import CursorWidget |
ca10d7e9a2c1
And CursorWidget-ify the popup menu.
Jeremy Thurgood <firxen@gmail.com>
parents:
84
diff
changeset
|
13 |
ca10d7e9a2c1
And CursorWidget-ify the popup menu.
Jeremy Thurgood <firxen@gmail.com>
parents:
84
diff
changeset
|
14 |
84
c76f2fad2af5
Draw CursorWidget on top of StateWidget
Stefano Rivera <stefano@rivera.za.net>
parents:
70
diff
changeset
|
15 class PopupMenuButton(Button): |
70 | 16 |
17 def __init__(self, text, action): | |
18 Button.__init__(self, text, action) | |
19 | |
20 self.font = get_font(16, 'Vera.ttf') | |
21 self.set_rect(Rect(0, 0, BUTTON_SIZE, BUTTON_SIZE)) | |
22 self.margin = (BUTTON_SIZE - self.font.get_linesize()) / 2 | |
23 | |
116
ca10d7e9a2c1
And CursorWidget-ify the popup menu.
Jeremy Thurgood <firxen@gmail.com>
parents:
84
diff
changeset
|
24 class PopupMenu(Menu, CursorWidget): |
58 | 25 |
26 def __init__(self, shell): | |
116
ca10d7e9a2c1
And CursorWidget-ify the popup menu.
Jeremy Thurgood <firxen@gmail.com>
parents:
84
diff
changeset
|
27 CursorWidget.__init__(self) |
58 | 28 self.shell = shell |
29 items = [ | |
30 ('Resume Game', 'hide'), | |
69
d4bbb26099cc
Some debug object cleanup.
Jeremy Thurgood <firxen@gmail.com>
parents:
58
diff
changeset
|
31 ('Quit Game', 'quit'), |
58 | 32 ('Exit to Main Menu', 'main_menu'), |
33 ] | |
34 # albow.menu.Menu ignores title string | |
35 Menu.__init__(self, None, items) | |
36 self.font = get_font(16, 'Vera.ttf') | |
37 | |
38 def show_menu(self): | |
39 """Call present, with the correct position""" | |
40 item_height = self.font.get_linesize() | |
41 menu_top = 600 - (len(self.items) * item_height + BUTTON_SIZE) | |
42 item = self.present(self.shell, (0, menu_top)) | |
43 if item > -1: | |
44 # A menu item needs to be invoked | |
45 self.invoke_item(item) | |
46 |