comparison gamelib/gameboard.py @ 162:fa57868123d7

Basic cursor support
author Neil Muller <drnlmuller@gmail.com>
date Thu, 03 Sep 2009 22:19:34 +0000
parents baf857805867
children ab90040013a7
comparison
equal deleted inserted replaced
161:9b4213f6ea7f 162:fa57868123d7
10 import constants 10 import constants
11 import buildings 11 import buildings
12 import animal 12 import animal
13 import equipment 13 import equipment
14 import sound 14 import sound
15 import cursors
15 16
16 class OpaqueLabel(gui.Label): 17 class OpaqueLabel(gui.Label):
17 def paint(self, s): 18 def paint(self, s):
18 s.fill(self.style.background) 19 s.fill(self.style.background)
19 gui.Label.paint(self, s) 20 gui.Label.paint(self, s)
48 self.add_counter(mklabel("Eggs:"), self.egg_counter) 49 self.add_counter(mklabel("Eggs:"), self.egg_counter)
49 self.add_counter(icons.CHKN_ICON, self.chicken_counter) 50 self.add_counter(icons.CHKN_ICON, self.chicken_counter)
50 self.add_counter(icons.KILLED_FOX, self.killed_foxes) 51 self.add_counter(icons.KILLED_FOX, self.killed_foxes)
51 self.add_spacer(20) 52 self.add_spacer(20)
52 53
53 self.add_tool_button("Move Hen", constants.TOOL_PLACE_ANIMALS) 54 self.add_tool_button("Move Hen", constants.TOOL_PLACE_ANIMALS,
55 cursors.cursors['select'])
54 self.add_tool_button("Cut Trees", constants.TOOL_LOGGING) 56 self.add_tool_button("Cut Trees", constants.TOOL_LOGGING)
55 self.add_spacer(20) 57 self.add_spacer(20)
56 58
57 self.add_heading("Sell ...") 59 self.add_heading("Sell ...")
58 self.add_tool_button("Chicken", constants.TOOL_SELL_CHICKEN) 60 self.add_tool_button("Chicken", constants.TOOL_SELL_CHICKEN,
59 self.add_tool_button("Egg", constants.TOOL_SELL_EGG) 61 cursors.cursors['select'])
60 self.add_tool_button("Building", constants.TOOL_SELL_BUILDING) 62 self.add_tool_button("Egg", constants.TOOL_SELL_EGG,
63 cursors.cursors['select'])
64 self.add_tool_button("Building", constants.TOOL_SELL_BUILDING,
65 cursors.cursors['select'])
61 self.add_spacer(20) 66 self.add_spacer(20)
62 67
63 self.add_heading("Buy ...") 68 self.add_heading("Buy ...")
64 self.add_tool_button("Fence", constants.TOOL_BUY_FENCE) 69 self.add_tool_button("Fence", constants.TOOL_BUY_FENCE)
65 for building_cls in buildings.BUILDINGS: 70 for building_cls in buildings.BUILDINGS:
66 self.add_tool_button(building_cls.NAME.title(), building_cls) 71 self.add_tool_button(building_cls.NAME.title(), building_cls,
72 cursors.cursors.get('build', None))
67 for equipment_cls in equipment.EQUIPMENT: 73 for equipment_cls in equipment.EQUIPMENT:
68 self.add_tool_button(equipment_cls.NAME.title(), equipment_cls) 74 self.add_tool_button(equipment_cls.NAME.title(), equipment_cls,
75 cursors.cursors.get(equipment_cls.NAME, None))
69 self.add_spacer() 76 self.add_spacer()
70 77
71 self.add_button("Finished Day", self.day_done) 78 self.add_button("Finished Day", self.day_done)
72 79
73 def day_done(self): 80 def day_done(self):
74 import engine 81 import engine
82 self.gameboard.reset_cursor()
75 pygame.event.post(engine.START_NIGHT) 83 pygame.event.post(engine.START_NIGHT)
76 84
77 update_cash_counter = mkcountupdate('cash_counter') 85 update_cash_counter = mkcountupdate('cash_counter')
78 update_fox_counter = mkcountupdate('killed_foxes') 86 update_fox_counter = mkcountupdate('killed_foxes')
79 update_chicken_counter = mkcountupdate('chicken_counter') 87 update_chicken_counter = mkcountupdate('chicken_counter')
86 94
87 def add_heading(self, text): 95 def add_heading(self, text):
88 self.tr() 96 self.tr()
89 self.td(mklabel(text), colspan=2) 97 self.td(mklabel(text), colspan=2)
90 98
91 def add_tool_button(self, text, tool): 99 def add_tool_button(self, text, tool, cursor=None):
92 self.add_button(text, lambda: self.gameboard.set_selected_tool(tool)) 100 self.add_button(text, lambda: self.gameboard.set_selected_tool(tool,
101 cursor))
93 102
94 def add_button(self, text, func): 103 def add_button(self, text, func):
95 button = gui.Button(text, width=self.rect.w, style={"padding_left": 0}) 104 button = gui.Button(text, width=self.rect.w, style={"padding_left": 0})
96 button.connect(gui.CLICK, func) 105 button.connect(gui.CLICK, func)
97 self.tr() 106 self.tr()
178 self.tvw.reupdate() 187 self.tvw.reupdate()
179 188
180 def loop(self): 189 def loop(self):
181 self.tv.loop() 190 self.tv.loop()
182 191
183 def set_selected_tool(self, tool): 192 def set_selected_tool(self, tool, cursor):
184 self.selected_tool = tool 193 self.selected_tool = tool
185 self.animal_to_place = None 194 self.animal_to_place = None
195 if cursor:
196 pygame.mouse.set_cursor(*cursor)
197 else:
198 pygame.mouse.set_cursor(*cursors.cursors['arrow'])
199
200 def reset_cursor(self):
201 pygame.mouse.set_cursor(*cursors.cursors['arrow'])
186 202
187 def in_bounds(self, pos): 203 def in_bounds(self, pos):
188 """Check if a position is within the game boundaries""" 204 """Check if a position is within the game boundaries"""
189 if pos.x < 0 or pos.y < 0: 205 if pos.x < 0 or pos.y < 0:
190 return False 206 return False
242 """ 258 """
243 chicken = self.get_chicken(tile_pos) 259 chicken = self.get_chicken(tile_pos)
244 if chicken and chicken.abode is None: 260 if chicken and chicken.abode is None:
245 if chicken is self.animal_to_place: 261 if chicken is self.animal_to_place:
246 self.animal_to_place = None 262 self.animal_to_place = None
263 pygame.mouse.set_cursor(*cursors.cursors['arrow'])
247 else: 264 else:
248 self.animal_to_place = chicken 265 self.animal_to_place = chicken
266 pygame.mouse.set_cursor(*cursors.cursors['chicken'])
249 return 267 return
250 building = self.get_building(tile_pos) 268 building = self.get_building(tile_pos)
251 if building: 269 if building:
252 self.open_building_dialog(building) 270 self.open_building_dialog(building)
253 return 271 return
289 def open_building_dialog(self, building): 307 def open_building_dialog(self, building):
290 """Create dialog for manipulating the contents of a building.""" 308 """Create dialog for manipulating the contents of a building."""
291 def select_occupant(place, button): 309 def select_occupant(place, button):
292 """Select occupant in place.""" 310 """Select occupant in place."""
293 self.animal_to_place = place.occupant 311 self.animal_to_place = place.occupant
312 pygame.mouse.set_cursor(*cursors.cursor['chicken'])
294 313
295 def set_occupant(place, button): 314 def set_occupant(place, button):
296 """Set occupant of a given place.""" 315 """Set occupant of a given place."""
297 if self.animal_to_place is not None: 316 if self.animal_to_place is not None:
298 button.value = icons.CHKN_NEST_ICON 317 button.value = icons.CHKN_NEST_ICON