# HG changeset patch # User Jeremy Thurgood # Date 1283007037 -7200 # Node ID 760f6a318d2e085facddf96f172852434af1fb91 # Parent e5f28bd6d4ce375d3ac9355aff7ac7c8a8945599 Moved some widgets around. diff -r e5f28bd6d4ce -r 760f6a318d2e gamelib/gamescreen.py --- a/gamelib/gamescreen.py Sat Aug 28 16:46:46 2010 +0200 +++ b/gamelib/gamescreen.py Sat Aug 28 16:50:37 2010 +0200 @@ -12,10 +12,9 @@ from constants import SCREEN, BUTTON_SIZE, SCENE_SIZE from cursor import CursorWidget -from hand import HandButton -from popupmenu import PopupMenu, PopupMenuButton from state import initial_state, handle_result -from widgets import MessageDialog, BoomButton +from widgets import (MessageDialog, BoomButton, HandButton, PopupMenu, + PopupMenuButton) class InventoryView(PaletteView): diff -r e5f28bd6d4ce -r 760f6a318d2e gamelib/hand.py --- a/gamelib/hand.py Sat Aug 28 16:46:46 2010 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,22 +0,0 @@ -# Button for the hand image - -from constants import BUTTON_SIZE - -from albow.controls import Image -from albow.resource import get_image -from pygame.rect import Rect - - -class HandButton(Image): - """The fancy hand button for the widget""" - - def __init__(self, action): - # FIXME: Yes, please. - this_image = get_image('items', 'hand.png') - Image.__init__(self, image=this_image) - self.action = action - self.set_rect(Rect(0, 0, BUTTON_SIZE, BUTTON_SIZE)) - - def mouse_down(self, event): - self.action() - diff -r e5f28bd6d4ce -r 760f6a318d2e gamelib/popupmenu.py --- a/gamelib/popupmenu.py Sat Aug 28 16:46:46 2010 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -# popmenu.py -# Copyright Boomslang team (see COPYING file) -# Popup menu for the game screen - -from constants import BUTTON_SIZE - -from albow.menu import Menu -from albow.controls import Button -from albow.resource import get_font -from pygame.rect import Rect - -from cursor import CursorWidget - - -class PopupMenuButton(Button): - - 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 - - -class PopupMenu(Menu, CursorWidget): - - def __init__(self, screen): - CursorWidget.__init__(self, screen) - self.screen = screen - self.shell = screen.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) - diff -r e5f28bd6d4ce -r 760f6a318d2e gamelib/widgets.py --- a/gamelib/widgets.py Sat Aug 28 16:46:46 2010 +0200 +++ b/gamelib/widgets.py Sat Aug 28 16:50:37 2010 +0200 @@ -6,9 +6,12 @@ import textwrap import albow.controls -from albow.resource import get_font +import albow.menu +from albow.resource import get_font, get_image from pygame.color import Color +from pygame.rect import Rect +from constants import BUTTON_SIZE from cursor import CursorWidget @@ -36,6 +39,7 @@ def _draw_all_no_bg(self, surface): pass + class BoomButton(BoomLabel): def __init__(self, text, action, screen): @@ -84,3 +88,53 @@ def cursor_highlight(self): return False + + +class HandButton(albow.controls.Image): + """The fancy hand button for the widget""" + + def __init__(self, action): + # FIXME: Yes, please. + this_image = get_image('items', 'hand.png') + albow.controls.Image.__init__(self, image=this_image) + self.action = action + self.set_rect(Rect(0, 0, BUTTON_SIZE, BUTTON_SIZE)) + + def mouse_down(self, event): + self.action() + + +class PopupMenuButton(albow.controls.Button): + + def __init__(self, text, action): + albow.controls.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 + + +class PopupMenu(albow.menu.Menu, CursorWidget): + + def __init__(self, screen): + CursorWidget.__init__(self, screen) + self.screen = screen + self.shell = screen.shell + items = [ + ('Resume Game', 'hide'), + ('Quit Game', 'quit'), + ('Exit to Main Menu', 'main_menu'), + ] + # albow.menu.Menu ignores title string + albow.menu.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) +