Mercurial > rinkhals
comparison gamelib/gameboard.py @ 245:634491bf37e8
Change toolbar to gui.Toolbar -- gives nicer highlighting.
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Sat, 05 Sep 2009 12:15:46 +0000 |
parents | 4f86c2616cdf |
children | 5b9cd693fe7c |
comparison
equal
deleted
inserted
replaced
244:7024d48c41c2 | 245:634491bf37e8 |
---|---|
56 return update_counter | 56 return update_counter |
57 | 57 |
58 class ToolBar(gui.Table): | 58 class ToolBar(gui.Table): |
59 def __init__(self, gameboard, **params): | 59 def __init__(self, gameboard, **params): |
60 gui.Table.__init__(self, **params) | 60 gui.Table.__init__(self, **params) |
61 self.group = gui.Group(name='toolbar', value=None) | |
62 self._next_tool_value = 0 | |
61 self.gameboard = gameboard | 63 self.gameboard = gameboard |
62 self.cash_counter = mklabel(align=1) | 64 self.cash_counter = mklabel(align=1) |
63 self.chicken_counter = mklabel(align=1) | 65 self.chicken_counter = mklabel(align=1) |
64 self.egg_counter = mklabel(align=1) | 66 self.egg_counter = mklabel(align=1) |
65 self.day_counter = mklabel(align=1) | 67 self.day_counter = mklabel(align=1) |
98 for equipment_cls in equipment.EQUIPMENT: | 100 for equipment_cls in equipment.EQUIPMENT: |
99 self.add_tool_button(equipment_cls.NAME.title(), equipment_cls, | 101 self.add_tool_button(equipment_cls.NAME.title(), equipment_cls, |
100 cursors.cursors.get(equipment_cls.NAME, None)) | 102 cursors.cursors.get(equipment_cls.NAME, None)) |
101 self.add_spacer(30) | 103 self.add_spacer(30) |
102 | 104 |
103 self.add_button("Finished Day", self.day_done) | 105 self.add_tool("Finished Day", self.day_done) |
104 | 106 |
105 def day_done(self): | 107 def day_done(self): |
106 import engine | 108 import engine |
107 pygame.event.post(engine.START_NIGHT) | 109 pygame.event.post(engine.START_NIGHT) |
108 | 110 |
119 def add_heading(self, text): | 121 def add_heading(self, text): |
120 self.tr() | 122 self.tr() |
121 self.td(mklabel(text), colspan=2) | 123 self.td(mklabel(text), colspan=2) |
122 | 124 |
123 def add_tool_button(self, text, tool, cursor=None): | 125 def add_tool_button(self, text, tool, cursor=None): |
124 self.add_button(text, lambda: self.gameboard.set_selected_tool(tool, | 126 self.add_tool(text, lambda: self.gameboard.set_selected_tool(tool, |
125 cursor)) | 127 cursor)) |
126 | 128 |
127 def add_button(self, text, func): | 129 def add_tool(self, text, func): |
128 button = gui.Button(text, width=self.rect.w, style={"padding_left": 0}) | 130 label = gui.basic.Label(text) |
129 button.connect(gui.CLICK, func) | 131 value = self._next_tool_value |
132 self._next_tool_value += 1 | |
133 tool = gui.Tool(self.group, label, value, width=self.rect.w, style={"padding_left": 0}) | |
134 tool.connect(gui.CLICK, func) | |
130 self.tr() | 135 self.tr() |
131 self.td(button, align=-1, colspan=2) | 136 self.td(tool, align=-1, colspan=2) |
137 | |
138 def clear_tool(self): | |
139 self.group.value = None | |
132 | 140 |
133 def add_counter(self, icon, label): | 141 def add_counter(self, icon, label): |
134 self.tr() | 142 self.tr() |
135 self.td(icon, width=self.rect.w/2) | 143 self.td(icon, width=self.rect.w/2) |
136 self.td(label, width=self.rect.w/2) | 144 self.td(label, width=self.rect.w/2) |
283 self.sprite_cursor = sprite_curs | 291 self.sprite_cursor = sprite_curs |
284 self.tv.sprites.set_cursor(sprite_curs) | 292 self.tv.sprites.set_cursor(sprite_curs) |
285 | 293 |
286 def reset_states(self): | 294 def reset_states(self): |
287 """Clear current states (highlights, etc.)""" | 295 """Clear current states (highlights, etc.)""" |
288 if self.animal_to_place: | 296 self.set_selected_tool(None, None) |
289 self.select_animal_to_place(None) | 297 self.toolbar.clear_tool() |
290 self.set_cursor() | |
291 | 298 |
292 def update_sprite_cursor(self, e): | 299 def update_sprite_cursor(self, e): |
293 tile_pos = self.tv.screen_to_tile(e.pos) | 300 tile_pos = self.tv.screen_to_tile(e.pos) |
294 self.sprite_cursor.set_pos(tile_pos) | 301 self.sprite_cursor.set_pos(tile_pos) |
295 | 302 |