comparison gamelib/toolbar.py @ 569:3ec614e6fd4a

Replace monolithic sell equipment tool with a tool for each type of equipment.
author Simon Cross <hodgestar@gmail.com>
date Sat, 28 Nov 2009 19:59:46 +0000
parents e813365af567
children 40eee9e1246c
comparison
equal deleted inserted replaced
568:e813365af567 569:3ec614e6fd4a
384 def __init__(self, gameboard, **params): 384 def __init__(self, gameboard, **params):
385 BaseToolBar.__init__(self, gameboard, **params) 385 BaseToolBar.__init__(self, gameboard, **params)
386 self.group = gui.Group(name='sell_toolbar', value=None) 386 self.group = gui.Group(name='sell_toolbar', value=None)
387 self.make_toolbar() 387 self.make_toolbar()
388 388
389 @staticmethod
390 def make_equip_tool(equipment_cls):
391 tool = ("sell_tool", equipment_cls)
392 return tool
393
394 @staticmethod
395 def is_equip_tool(tool):
396 return type(tool) == tuple and tool[0] == "sell_tool"
397
398 @staticmethod
399 def get_equip_cls(tool):
400 return tool[1]
401
389 def make_toolbar(self): 402 def make_toolbar(self):
390 self.add_heading("Sell ...") 403 self.add_heading("Sell ...")
391 self.add_tool_button("Chicken", constants.TOOL_SELL_CHICKEN, 404 self.add_tool_button("Chicken", constants.TOOL_SELL_CHICKEN,
392 self.gameboard.level.sell_price_chicken, cursors.cursors['sell']) 405 self.gameboard.level.sell_price_chicken, cursors.cursors['sell'])
393 self.add_tool_button("Egg", constants.TOOL_SELL_EGG, 406 self.add_tool_button("Egg", constants.TOOL_SELL_EGG,
394 self.gameboard.level.sell_price_egg, cursors.cursors['sell']) 407 self.gameboard.level.sell_price_egg, cursors.cursors['sell'])
395 self.add_tool_button("Equipment", constants.TOOL_SELL_EQUIPMENT,
396 None, cursors.cursors['sell'])
397 self.add_spacer(15) 408 self.add_spacer(15)
409
410 for equipment_cls in equipment.EQUIPMENT:
411 tool = self.make_equip_tool(equipment_cls)
412 self.add_tool_button(equipment_cls.NAME.title(),
413 tool,
414 equipment_cls.SELL_PRICE,
415 cursors.cursors.get('sell', None))
416 self.add_spacer(15)
417
418 #self.add_tool_button("Equipment", constants.TOOL_SELL_EQUIPMENT,
419 # None, cursors.cursors['sell'])
420
398 self.add_tool('Done', self.add_default_toolbar) 421 self.add_tool('Done', self.add_default_toolbar)
399 422
400 def add_default_toolbar(self): 423 def add_default_toolbar(self):
401 self.gameboard.change_toolbar(DefaultToolBar(self.gameboard, 424 self.gameboard.change_toolbar(DefaultToolBar(self.gameboard,
402 width=self.style.width)) 425 width=self.style.width))