comparison gamelib/gameboard.py @ 83:9bd2c22e1746

Cleaned up some toolbar code a bit.
author Jeremy Thurgood <firxen@gmail.com>
date Tue, 01 Sep 2009 19:40:08 +0000
parents ad9d1bc7ef0c
children 5494af02a0e8
comparison
equal deleted inserted replaced
82:bf28f499c6b4 83:9bd2c22e1746
27 gui.Table.__init__(self, **params) 27 gui.Table.__init__(self, **params)
28 self.gameboard = gameboard 28 self.gameboard = gameboard
29 self.cash_counter = OpaqueLabel("Groats: ", color=constants.FG_COLOR) 29 self.cash_counter = OpaqueLabel("Groats: ", color=constants.FG_COLOR)
30 self.chicken_counter = OpaqueLabel(" ", color=constants.FG_COLOR) 30 self.chicken_counter = OpaqueLabel(" ", color=constants.FG_COLOR)
31 self.killed_foxes = OpaqueLabel(" ", color=constants.FG_COLOR) 31 self.killed_foxes = OpaqueLabel(" ", color=constants.FG_COLOR)
32 self.tr() 32
33 self.add(self.cash_counter) 33 self.add_counter(None, self.cash_counter)
34 self.tr() 34 self.add_counter(icons.CHKN_ICON, self.chicken_counter)
35 self.td(icons.CHKN_ICON, align=-1) 35 self.add_counter(icons.KILLED_FOX, self.killed_foxes)
36 self.add(self.chicken_counter) 36
37 self.tr()
38 self.td(icons.KILLED_FOX, align=-1)
39 self.add(self.killed_foxes)
40 self.add_tool_button("Sell chicken", constants.TOOL_SELL_CHICKEN) 37 self.add_tool_button("Sell chicken", constants.TOOL_SELL_CHICKEN)
41 self.add_tool_button("Sell egg", constants.TOOL_SELL_EGG) 38 self.add_tool_button("Sell egg", constants.TOOL_SELL_EGG)
42 self.add_tool_button("Sell building", constants.TOOL_SELL_BUILDING) 39 self.add_tool_button("Sell building", constants.TOOL_SELL_BUILDING)
43 self.add_tool_button("Buy fence", constants.TOOL_BUY_FENCE) 40 self.add_tool_button("Buy fence", constants.TOOL_BUY_FENCE)
44 for building_cls in buildings.BUILDINGS: 41 for building_cls in buildings.BUILDINGS:
45 self.add_tool_button("Buy %s" % (building_cls.NAME,), building_cls) 42 self.add_tool_button("Buy %s" % (building_cls.NAME,), building_cls)
46 43 self.add_spacer()
47 day_done_button = gui.Button("Finished Day") 44 self.add_button("Finished Day", self.day_done)
48 day_done_button.connect(gui.CLICK, self.day_done)
49 self.tr()
50 self.td(day_done_button, style={"padding_top": 30})
51 45
52 def day_done(self): 46 def day_done(self):
53 import engine 47 import engine
54 pygame.event.post(engine.START_NIGHT) 48 pygame.event.post(engine.START_NIGHT)
55 49
63 57
64 def update_fox_counter(self, number): 58 def update_fox_counter(self, number):
65 self.killed_foxes.update_value(" %s" % number) 59 self.killed_foxes.update_value(" %s" % number)
66 self.repaint() 60 self.repaint()
67 61
62 def add_spacer(self, height=30):
63 self.tr()
64 self.add(gui.Spacer(0, height))
65
68 def add_tool_button(self, text, tool): 66 def add_tool_button(self, text, tool):
67 self.add_button(text, lambda: self.gameboard.set_selected_tool(tool))
68
69 def add_button(self, text, func):
69 button = gui.Button(text) 70 button = gui.Button(text)
70 button.connect(gui.CLICK, lambda: self.gameboard.set_selected_tool(tool)) 71 button.connect(gui.CLICK, func)
71 self.tr() 72 self.tr()
72 self.add(button) 73 self.add(button)
73 74
75 def add_counter(self, icon, label):
76 self.tr()
77 if icon:
78 self.td(icon, align=-1)
79 self.add(label)
74 80
75 class VidWidget(gui.Widget): 81 class VidWidget(gui.Widget):
76 def __init__(self, gameboard, vid, **params): 82 def __init__(self, gameboard, vid, **params):
77 gui.Widget.__init__(self, **params) 83 gui.Widget.__init__(self, **params)
78 self.gameboard = gameboard 84 self.gameboard = gameboard