Mercurial > boomslang
comparison gamelib/gamescreen.py @ 73:932b0956e77a
Make tools usable.
author | Simon Cross <hodgestar+bzr@gmail.com> |
---|---|
date | Mon, 23 Aug 2010 21:19:34 +0200 |
parents | 99c5506de7ea |
children | 75e1040a1121 |
comparison
equal
deleted
inserted
replaced
72:d2250cf40ee7 | 73:932b0956e77a |
---|---|
21 sel_width = 2 | 21 sel_width = 2 |
22 | 22 |
23 def __init__(self, state, handbutton): | 23 def __init__(self, state, handbutton): |
24 PaletteView.__init__(self, (BUTTON_SIZE, BUTTON_SIZE), 1, 6, scrolling=True) | 24 PaletteView.__init__(self, (BUTTON_SIZE, BUTTON_SIZE), 1, 6, scrolling=True) |
25 self.state = state | 25 self.state = state |
26 self.selection = None | |
27 self.handbutton = handbutton | 26 self.handbutton = handbutton |
28 | 27 |
29 def num_items(self): | 28 def num_items(self): |
30 return len(self.state.inventory) | 29 return len(self.state.inventory) |
31 | 30 |
32 def draw_item(self, surface, item_no, rect): | 31 def draw_item(self, surface, item_no, rect): |
33 item_image = self.state.inventory[item_no].get_inventory_image() | 32 item_image = self.state.inventory[item_no].get_inventory_image() |
34 surface.blit(item_image, rect, None, BLEND_ADD) | 33 surface.blit(item_image, rect, None, BLEND_ADD) |
35 | 34 |
36 def click_item(self, item_no, event): | 35 def click_item(self, item_no, event): |
37 self.selection = item_no | 36 self.state.set_tool(self.state.inventory[item_no]) |
38 self.handbutton.unselect() | 37 self.handbutton.unselect() |
39 | 38 |
40 def item_is_selected(self, item_no): | 39 def item_is_selected(self, item_no): |
41 return self.selection == item_no | 40 return self.state.tool is self.state.inventory[item_no] |
42 | 41 |
43 def unselect(self): | 42 def unselect(self): |
44 self.selection = None | 43 self.state.set_tool(None) |
45 | 44 |
46 | 45 |
47 class StateWidget(CursorWidget): | 46 class StateWidget(CursorWidget): |
48 | 47 |
49 def __init__(self, state): | 48 def __init__(self, state): |
64 desc = self.state.get_description() | 63 desc = self.state.get_description() |
65 if desc: | 64 if desc: |
66 print desc | 65 print desc |
67 | 66 |
68 def mouse_down(self, event): | 67 def mouse_down(self, event): |
69 # TODO: replace None with the correct item | 68 self.state.interact(event.pos) |
70 self.state.interact(None, event.pos) | |
71 | 69 |
72 def mouse_move(self, event): | 70 def mouse_move(self, event): |
73 # TODO: replace None with the correct item | 71 self.state.mouse_move(event.pos) |
74 self.state.mouse_move(None, event.pos) | |
75 if self.state.check_for_new_description(event.pos): | 72 if self.state.check_for_new_description(event.pos): |
76 # queue a redraw | 73 # queue a redraw |
77 self.invalidate() | 74 self.invalidate() |
78 CursorWidget.mouse_move(self, event) | 75 CursorWidget.mouse_move(self, event) |
79 | 76 |