changeset 358:760f6a318d2e

Moved some widgets around.
author Jeremy Thurgood <firxen@gmail.com>
date Sat, 28 Aug 2010 16:50:37 +0200
parents e5f28bd6d4ce
children 6b94f549443b
files gamelib/gamescreen.py gamelib/hand.py gamelib/popupmenu.py gamelib/widgets.py
diffstat 4 files changed, 57 insertions(+), 74 deletions(-) [+]
line wrap: on
line diff
--- 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):
--- 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()
-
--- 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)
-
--- 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)
+