Mercurial > rinkhals
comparison gamelib/toolbar.py @ 447:f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Sat, 21 Nov 2009 19:58:49 +0000 |
parents | 0c523d384681 |
children | 92e7a641b4a6 |
comparison
equal
deleted
inserted
replaced
446:0c523d384681 | 447:f04a2490c35f |
---|---|
49 def update_counter(self, value): | 49 def update_counter(self, value): |
50 getattr(self, counter).update_value("%s " % value) | 50 getattr(self, counter).update_value("%s " % value) |
51 self.repaint() | 51 self.repaint() |
52 return update_counter | 52 return update_counter |
53 | 53 |
54 class ToolBar(gui.Table): | 54 class BaseToolBar(gui.Table): |
55 def __init__(self, gameboard, **params): | 55 def __init__(self, gameboard, **params): |
56 gui.Table.__init__(self, **params) | 56 gui.Table.__init__(self, **params) |
57 self.group = gui.Group(name='toolbar', value=None) | 57 self.group = gui.Group(name='base_toolbar', value=None) |
58 self._next_tool_value = 0 | 58 self._next_tool_value = 0 |
59 self.gameboard = gameboard | 59 self.gameboard = gameboard |
60 self.cash_counter = mklabel(align=1) | 60 self.cash_counter = mklabel(align=1) |
61 self.wood_counter = mklabel(align=1) | 61 self.wood_counter = mklabel(align=1) |
62 self.chicken_counter = mklabel(align=1) | 62 self.chicken_counter = mklabel(align=1) |
63 self.egg_counter = mklabel(align=1) | 63 self.egg_counter = mklabel(align=1) |
64 self.day_counter = mklabel(align=1) | 64 self.day_counter = mklabel(align=1) |
65 self.killed_foxes = mklabel(align=1) | 65 self.killed_foxes = mklabel(align=1) |
66 | 66 self.add_labels() |
67 self.make_default_toolbar() | 67 |
68 | 68 def add_labels(self): |
69 def make_default_toolbar(self): | |
70 self.tr() | 69 self.tr() |
71 self.td(gui.Spacer(self.rect.w/2, 0)) | 70 self.td(gui.Spacer(self.rect.w/2, 0)) |
72 self.td(gui.Spacer(self.rect.w/2, 0)) | 71 self.td(gui.Spacer(self.rect.w/2, 0)) |
73 self.add_counter(mklabel("Day:"), self.day_counter) | 72 self.add_counter(mklabel("Day:"), self.day_counter) |
74 self.add_counter(mklabel("Groats:"), self.cash_counter) | 73 self.add_counter(mklabel("Groats:"), self.cash_counter) |
75 self.add_counter(mklabel("Planks:"), self.wood_counter) | 74 self.add_counter(mklabel("Planks:"), self.wood_counter) |
76 self.add_counter(mklabel("Eggs:"), self.egg_counter) | 75 self.add_counter(mklabel("Eggs:"), self.egg_counter) |
77 self.add_counter(icons.CHKN_ICON, self.chicken_counter) | 76 self.add_counter(icons.CHKN_ICON, self.chicken_counter) |
78 self.add_counter(icons.KILLED_FOX, self.killed_foxes) | 77 self.add_counter(icons.KILLED_FOX, self.killed_foxes) |
79 self.add_spacer(5) | 78 self.add_spacer(5) |
80 | |
81 self.add_tool_button("Move Hen", constants.TOOL_PLACE_ANIMALS, | |
82 None, cursors.cursors['select']) | |
83 self.add_spacer(5) | |
84 | |
85 self.add_heading("Sell ...") | |
86 self.add_tool_button("Chicken", constants.TOOL_SELL_CHICKEN, | |
87 self.gameboard.level.sell_price_chicken, cursors.cursors['sell']) | |
88 self.add_tool_button("Egg", constants.TOOL_SELL_EGG, | |
89 self.gameboard.level.sell_price_egg, cursors.cursors['sell']) | |
90 self.add_tool_button("Building", constants.TOOL_SELL_BUILDING, | |
91 None, cursors.cursors['sell']) | |
92 self.add_tool_button("Equipment", constants.TOOL_SELL_EQUIPMENT, | |
93 None, cursors.cursors['sell']) | |
94 self.add_spacer(5) | |
95 | |
96 self.add_heading("Buy ...") | |
97 | |
98 for building_cls in buildings.BUILDINGS: | |
99 self.add_tool_button(building_cls.NAME.title(), building_cls, | |
100 None, cursors.cursors.get('build', None)) | |
101 | |
102 for equipment_cls in equipment.EQUIPMENT: | |
103 self.add_tool_button(equipment_cls.NAME.title(), | |
104 equipment_cls, | |
105 equipment_cls.BUY_PRICE, | |
106 cursors.cursors.get('buy', None)) | |
107 | |
108 self.add_spacer(5) | |
109 self.add_tool_button("Repair", constants.TOOL_REPAIR_BUILDING, None, cursors.cursors['repair']) | |
110 | |
111 self.add_spacer(5) | |
112 self.add_tool("Price Reference", self.show_prices) | |
113 | |
114 #self.add_spacer(5) | |
115 #self.add_tool("Save Game", self.save_game) | |
116 #self.add_tool("Load Game", self.load_game) | |
117 | |
118 self.fin_tool = self.add_tool("Finished Day", self.day_done) | |
119 | |
120 def day_done(self): | |
121 if self.gameboard.day: | |
122 pygame.event.post(engine.START_NIGHT) | |
123 else: | |
124 pygame.event.post(engine.FAST_FORWARD) | |
125 | 79 |
126 def start_night(self): | 80 def start_night(self): |
127 self.clear_tool() | 81 self.clear_tool() |
128 self._set_all_disabled(True) | 82 self._set_all_disabled(True) |
129 self.fin_tool.widget = gui.basic.Label('Fast Forward') | 83 self.fin_tool.widget = gui.basic.Label('Fast Forward') |
274 def resize(self, width=None, height=None): | 228 def resize(self, width=None, height=None): |
275 width, height = gui.Table.resize(self, width, height) | 229 width, height = gui.Table.resize(self, width, height) |
276 width = constants.TOOLBAR_WIDTH | 230 width = constants.TOOLBAR_WIDTH |
277 return width, height | 231 return width, height |
278 | 232 |
233 class DefaultToolBar(BaseToolBar): | |
234 def __init__(self, gameboard, **params): | |
235 BaseToolBar.__init__(self, gameboard, **params) | |
236 self.group = gui.Group(name='default_toolbar', value=None) | |
237 self.make_toolbar() | |
238 | |
239 def make_toolbar(self): | |
240 self.add_tool_button("Select chicken", constants.TOOL_SELECT_CHICKENS, | |
241 None, cursors.cursors['select']) | |
242 | |
243 self.add_spacer(5) | |
244 | |
245 self.add_heading("Sell ...") | |
246 self.add_tool_button("Chicken", constants.TOOL_SELL_CHICKEN, | |
247 self.gameboard.level.sell_price_chicken, cursors.cursors['sell']) | |
248 self.add_tool_button("Egg", constants.TOOL_SELL_EGG, | |
249 self.gameboard.level.sell_price_egg, cursors.cursors['sell']) | |
250 self.add_tool_button("Building", constants.TOOL_SELL_BUILDING, | |
251 None, cursors.cursors['sell']) | |
252 self.add_tool_button("Equipment", constants.TOOL_SELL_EQUIPMENT, | |
253 None, cursors.cursors['sell']) | |
254 self.add_spacer(5) | |
255 | |
256 self.add_heading(" ") | |
257 | |
258 self.add_tool('Buy building', self.add_building_toolbar) | |
259 | |
260 self.add_heading("For selection, ...") | |
261 | |
262 self.add_tool('Buy equipment', self.add_equipment_toolbar) | |
263 | |
264 self.add_tool_button("Move selected hen", constants.TOOL_PLACE_ANIMALS, | |
265 None, cursors.cursors['select']) | |
266 | |
267 self.add_heading(" ") | |
268 self.add_tool_button("Repair", constants.TOOL_REPAIR_BUILDING, None, cursors.cursors['repair']) | |
269 | |
270 self.add_heading("Help") | |
271 self.add_tool("Price Reference", self.show_prices) | |
272 | |
273 self.add_spacer(5) | |
274 self.add_tool("Save Game", self.save_game) | |
275 self.add_tool("Load Game", self.load_game) | |
276 | |
277 self.add_heading(" ") | |
278 self.add_spacer(10) | |
279 self.fin_tool = self.add_tool("Finished Day", self.day_done) | |
280 | |
281 def add_building_toolbar(self): | |
282 self.gameboard.change_toolbar(BuildingToolBar(self.gameboard, | |
283 width=self.style.width)) | |
284 | |
285 def add_equipment_toolbar(self): | |
286 self.gameboard.change_toolbar(EquipmentToolBar(self.gameboard, | |
287 width=self.style.width)) | |
288 | |
289 def day_done(self): | |
290 if self.gameboard.day: | |
291 pygame.event.post(engine.START_NIGHT) | |
292 else: | |
293 pygame.event.post(engine.FAST_FORWARD) | |
294 | |
295 class BuildingToolBar(BaseToolBar): | |
296 def __init__(self, gameboard, **params): | |
297 BaseToolBar.__init__(self, gameboard, **params) | |
298 self.group = gui.Group(name='building_toolbar', value=None) | |
299 self.make_toolbar() | |
300 | |
301 def make_toolbar(self): | |
302 self.gameboard.set_cursor(cursors.cursors['arrow'], None) | |
303 for building_cls in buildings.BUILDINGS: | |
304 self.add_tool_button(building_cls.NAME.title(), building_cls, | |
305 None, cursors.cursors.get('build', None)) | |
306 self.add_spacer(15) | |
307 self.add_tool('Done', self.add_default_toolbar) | |
308 | |
309 def add_default_toolbar(self): | |
310 self.gameboard.change_toolbar(DefaultToolBar(self.gameboard, | |
311 width=self.style.width)) | |
312 | |
313 class EquipmentToolBar(BaseToolBar): | |
314 def __init__(self, gameboard, **params): | |
315 BaseToolBar.__init__(self, gameboard, **params) | |
316 self.group = gui.Group(name='building_toolbar', value=None) | |
317 self.make_toolbar() | |
318 | |
319 def make_toolbar(self): | |
320 self.gameboard.set_cursor(cursors.cursors['arrow'], None) | |
321 for equipment_cls in equipment.EQUIPMENT: | |
322 self.add_tool_button(equipment_cls.NAME.title(), | |
323 equipment_cls, | |
324 equipment_cls.BUY_PRICE, | |
325 cursors.cursors.get('buy', None)) | |
326 self.add_spacer(15) | |
327 self.add_tool('Done', self.add_default_toolbar) | |
328 | |
329 def add_default_toolbar(self): | |
330 self.gameboard.change_toolbar(DefaultToolBar(self.gameboard, | |
331 width=self.style.width)) | |
332 |