Mercurial > boomslang
comparison gamelib/gamescreen.py @ 84:c76f2fad2af5
Draw CursorWidget on top of StateWidget
author | Stefano Rivera <stefano@rivera.za.net> |
---|---|
date | Mon, 23 Aug 2010 23:58:11 +0200 |
parents | 4fd56ee2af61 |
children | 350ce4ebe122 |
comparison
equal
deleted
inserted
replaced
83:4fd56ee2af61 | 84:c76f2fad2af5 |
---|---|
5 import textwrap | 5 import textwrap |
6 | 6 |
7 from albow.controls import Button, Label, Widget | 7 from albow.controls import Button, Label, Widget |
8 from albow.layout import Column | 8 from albow.layout import Column |
9 from albow.palette_view import PaletteView | 9 from albow.palette_view import PaletteView |
10 from pygame import Rect | 10 from albow.screen import Screen |
11 from pygame import Rect, mouse | |
11 from pygame.color import Color | 12 from pygame.color import Color |
12 from pygame.locals import BLEND_ADD | 13 from pygame.locals import BLEND_ADD |
13 | 14 |
14 from constants import BUTTON_SIZE | 15 from constants import BUTTON_SIZE |
15 from cursor import CursorSpriteScreen, CursorWidget | 16 from cursor import CursorWidget |
16 from hand import HandButton | 17 from hand import HandButton |
17 from popupmenu import PopupMenu, PopupMenuButton | 18 from popupmenu import PopupMenu, PopupMenuButton |
18 from state import initial_state, Item | 19 from state import initial_state, Item |
19 from widgets import BoomLabel | 20 from widgets import BoomLabel |
20 | 21 |
21 | 22 |
22 class InventoryView(PaletteView, CursorWidget): | 23 class InventoryView(PaletteView): |
23 | 24 |
24 sel_color = Color("yellow") | 25 sel_color = Color("yellow") |
25 sel_width = 2 | 26 sel_width = 2 |
26 | 27 |
27 def __init__(self, state, handbutton): | 28 def __init__(self, state, handbutton): |
64 | 65 |
65 | 66 |
66 class StateWidget(CursorWidget): | 67 class StateWidget(CursorWidget): |
67 | 68 |
68 def __init__(self, state): | 69 def __init__(self, state): |
69 Widget.__init__(self, Rect(0, 0, 800, 600 - BUTTON_SIZE)) | 70 CursorWidget.__init__(self, Rect(0, 0, 800, 600 - BUTTON_SIZE)) |
70 self.state = state | 71 self.state = state |
71 | 72 |
72 def draw(self, surface): | 73 def draw(self, surface): |
73 self.state.draw(surface) | 74 self.state.draw(surface) |
75 CursorWidget.draw(self, surface) | |
74 | 76 |
75 def mouse_down(self, event): | 77 def mouse_down(self, event): |
76 result = self.state.interact(event.pos) | 78 result = self.state.interact(event.pos) |
77 if result and result.message: | 79 if result and result.message: |
78 # Display the message as a modal dialog | 80 # Display the message as a modal dialog |
83 def mouse_move(self, event): | 85 def mouse_move(self, event): |
84 self.state.mouse_move(event.pos) | 86 self.state.mouse_move(event.pos) |
85 CursorWidget.mouse_move(self, event) | 87 CursorWidget.mouse_move(self, event) |
86 | 88 |
87 | 89 |
88 class DetailWindow(CursorWidget): | 90 class DetailWindow(Widget): |
89 def mouse_down(self, e): | 91 def mouse_down(self, e): |
90 if e not in self: | 92 if e not in self: |
91 self.dismiss() | 93 self.dismiss() |
92 | 94 |
93 def draw(self, surface): | 95 def draw(self, surface): |
94 surface.fill(Color('green')) | 96 surface.fill(Color('green')) |
95 | 97 |
96 | 98 |
97 class GameScreen(CursorSpriteScreen): | 99 class GameScreen(Screen): |
98 def __init__(self, shell): | 100 def __init__(self, shell): |
99 CursorSpriteScreen.__init__(self, shell) | 101 Screen.__init__(self, shell) |
100 | 102 |
101 # TODO: Randomly plonk the state here for now | 103 # TODO: Randomly plonk the state here for now |
102 self.state = initial_state() | 104 self.state = initial_state() |
103 self.state_widget = StateWidget(self.state) | 105 self.state_widget = StateWidget(self.state) |
104 self.add(self.state_widget) | 106 self.add(self.state_widget) |
148 | 150 |
149 def hand_pressed(self): | 151 def hand_pressed(self): |
150 self.handbutton.toggle_selected() | 152 self.handbutton.toggle_selected() |
151 self.inventory.unselect() | 153 self.inventory.unselect() |
152 | 154 |
153 | 155 def mouse_delta(self, event): |
156 w = self.shell.find_widget(event.pos) | |
157 if not isinstance(w, CursorWidget): | |
158 mouse.set_visible(1) |