Mercurial > pyntnclick
annotate gamelib/popupmenu.py @ 151:d00aa26941c4
Add machine and engine rooms to map. Fix typo in name of mess hall doorway thing.
author | Simon Cross <hodgestar+bzr@gmail.com> |
---|---|
date | Tue, 24 Aug 2010 23:38:04 +0200 |
parents | 97322b78d1c1 |
children | fbfd8e748ac0 |
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 | |
124 | 24 |
116
ca10d7e9a2c1
And CursorWidget-ify the popup menu.
Jeremy Thurgood <firxen@gmail.com>
parents:
84
diff
changeset
|
25 class PopupMenu(Menu, CursorWidget): |
58 | 26 |
27 def __init__(self, shell): | |
116
ca10d7e9a2c1
And CursorWidget-ify the popup menu.
Jeremy Thurgood <firxen@gmail.com>
parents:
84
diff
changeset
|
28 CursorWidget.__init__(self) |
58 | 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 |