Mercurial > boomslang
view gamelib/popupmenu.py @ 71:99c5506de7ea
Start of interact handling.
author | Simon Cross <hodgestar+bzr@gmail.com> |
---|---|
date | Mon, 23 Aug 2010 21:04:43 +0200 |
parents | 213e47dea4d0 |
children | c76f2fad2af5 |
line wrap: on
line source
# popmenu.py # Copyright Boomslang team (see COPYING file) # Popup menu for the game screen from constants import BUTTON_SIZE from cursor import CursorWidget from albow.menu import Menu from albow.controls import Button from albow.resource import get_font from pygame.rect import Rect class PopupMenuButton(Button, CursorWidget): def __init__(self, text, action): Button.__init__(self, text, action) self.font = get_font(16, 'Vera.ttf') self.set_rect(Rect(0, 0, BUTTON_SIZE, BUTTON_SIZE)) self.margin = (BUTTON_SIZE - self.font.get_linesize()) / 2 def get_cursor(self, event): # Draw standard arrow, not the sprite cursor return None class PopupMenu(Menu): def __init__(self, shell): self.shell = shell items = [ ('Resume Game', 'hide'), ('Quit Game', 'quit'), ('Exit to Main Menu', 'main_menu'), ] # albow.menu.Menu ignores title string Menu.__init__(self, None, items) self.font = get_font(16, 'Vera.ttf') def show_menu(self): """Call present, with the correct position""" item_height = self.font.get_linesize() menu_top = 600 - (len(self.items) * item_height + BUTTON_SIZE) item = self.present(self.shell, (0, menu_top)) if item > -1: # A menu item needs to be invoked self.invoke_item(item)