Mercurial > boomslang
comparison gamelib/gamescreen.py @ 70:213e47dea4d0
Funkier cursor handling
author | Neil Muller <neil@dip.sun.ac.za> |
---|---|
date | Mon, 23 Aug 2010 20:54:04 +0200 |
parents | d4bbb26099cc |
children | 99c5506de7ea |
comparison
equal
deleted
inserted
replaced
69:d4bbb26099cc | 70:213e47dea4d0 |
---|---|
3 # Main menu for the game | 3 # Main menu for the game |
4 | 4 |
5 from albow.controls import Button, Label, Widget | 5 from albow.controls import Button, Label, Widget |
6 from albow.layout import Column | 6 from albow.layout import Column |
7 from albow.palette_view import PaletteView | 7 from albow.palette_view import PaletteView |
8 from albow.resource import get_font | |
9 from pygame import Rect | 8 from pygame import Rect |
10 from pygame.color import Color | 9 from pygame.color import Color |
11 from pygame.locals import BLEND_ADD | 10 from pygame.locals import BLEND_ADD |
12 | 11 |
13 from constants import BUTTON_SIZE | 12 from constants import BUTTON_SIZE |
14 from cursor import CursorSpriteScreen | 13 from cursor import CursorSpriteScreen, CursorWidget |
15 from hand import HandButton | 14 from hand import HandButton |
16 from popupmenu import PopupMenu | 15 from popupmenu import PopupMenu, PopupMenuButton |
17 from state import initial_state, Item | 16 from state import initial_state, Item |
18 | 17 |
19 class InventoryView(PaletteView): | 18 class InventoryView(PaletteView, CursorWidget): |
20 | 19 |
21 sel_color = Color("yellow") | 20 sel_color = Color("yellow") |
22 sel_width = 2 | 21 sel_width = 2 |
23 | 22 |
24 def __init__(self, state, handbutton): | 23 def __init__(self, state, handbutton): |
43 | 42 |
44 def unselect(self): | 43 def unselect(self): |
45 self.selection = None | 44 self.selection = None |
46 | 45 |
47 | 46 |
48 class StateWidget(Widget): | 47 class StateWidget(CursorWidget): |
49 | 48 |
50 def __init__(self, state): | 49 def __init__(self, state): |
51 Widget.__init__(self, Rect(0, 0, 800, 600 - BUTTON_SIZE)) | 50 Widget.__init__(self, Rect(0, 0, 800, 600 - BUTTON_SIZE)) |
52 self.state = state | 51 self.state = state |
53 # current mouse-over thing description | 52 # current mouse-over thing description |
68 | 67 |
69 def mouse_move(self, event): | 68 def mouse_move(self, event): |
70 if self.state.check_for_new_description(event.pos): | 69 if self.state.check_for_new_description(event.pos): |
71 # queue a redraw | 70 # queue a redraw |
72 self.invalidate() | 71 self.invalidate() |
72 CursorWidget.mouse_move(self, event) | |
73 | 73 |
74 | 74 |
75 class GameScreen(CursorSpriteScreen): | 75 class GameScreen(CursorSpriteScreen): |
76 def __init__(self, shell): | 76 def __init__(self, shell): |
77 CursorSpriteScreen.__init__(self, shell) | 77 CursorSpriteScreen.__init__(self, shell) |
80 self.state = initial_state() | 80 self.state = initial_state() |
81 self.state_widget = StateWidget(self.state) | 81 self.state_widget = StateWidget(self.state) |
82 self.add(self.state_widget) | 82 self.add(self.state_widget) |
83 | 83 |
84 self.popup_menu = PopupMenu(shell) | 84 self.popup_menu = PopupMenu(shell) |
85 self.menubutton = Button('Menu', action=self.popup_menu.show_menu) | 85 self.menubutton = PopupMenuButton('Menu', |
86 self.menubutton.font = get_font(16, 'Vera.ttf') | 86 action=self.popup_menu.show_menu) |
87 self.menubutton.set_rect(Rect(0, 0, BUTTON_SIZE, BUTTON_SIZE)) | |
88 self.menubutton.bottomleft = self.bottomleft | 87 self.menubutton.bottomleft = self.bottomleft |
89 self.menubutton.margin = (BUTTON_SIZE - self.menubutton.font.get_linesize()) / 2 | |
90 self.add(self.menubutton) | 88 self.add(self.menubutton) |
91 self.handbutton = HandButton(action=self.hand_pressed) | 89 self.handbutton = HandButton(action=self.hand_pressed) |
92 self.handbutton.bottomleft = self.bottomleft | 90 self.handbutton.bottomleft = self.bottomleft |
93 self.handbutton.get_rect().move_ip(BUTTON_SIZE, 0) | 91 self.handbutton.get_rect().move_ip(BUTTON_SIZE, 0) |
94 self.add(self.handbutton) | 92 self.add(self.handbutton) |