comparison gamelib/gameboard.py @ 200:67d10f7e0159

selected chickens are selected
author Adrianna Pińska <adrianna.pinska@gmail.com>
date Fri, 04 Sep 2009 19:51:19 +0000
parents d74693555b86
children fe1e9c18d4d7
comparison
equal deleted inserted replaced
199:696936621a93 200:67d10f7e0159
215 def loop(self): 215 def loop(self):
216 self.tv.loop() 216 self.tv.loop()
217 217
218 def set_selected_tool(self, tool, cursor): 218 def set_selected_tool(self, tool, cursor):
219 self.selected_tool = tool 219 self.selected_tool = tool
220 self.animal_to_place = None 220 self.select_animal_to_place(None)
221 if cursor: 221 if cursor:
222 pygame.mouse.set_cursor(*cursor) 222 pygame.mouse.set_cursor(*cursor)
223 else: 223 else:
224 pygame.mouse.set_cursor(*cursors.cursors['arrow']) 224 pygame.mouse.set_cursor(*cursors.cursors['arrow'])
225 if self.sprite_cursor: 225 if self.sprite_cursor:
319 319
320 building = self.get_building(tile_pos) 320 building = self.get_building(tile_pos)
321 if building and building.NAME in buildings.HENHOUSES: 321 if building and building.NAME in buildings.HENHOUSES:
322 self.open_building_dialog(building, do_sell) 322 self.open_building_dialog(building, do_sell)
323 323
324 def select_animal_to_place(self, animal):
325 if self.animal_to_place:
326 self.animal_to_place.unequip_by_name("spotlight")
327 self.animal_to_place = animal
328 if self.animal_to_place:
329 self.animal_to_place.equip(equipment.Spotlight())
330
324 def place_animal(self, tile_pos): 331 def place_animal(self, tile_pos):
325 """Handle an TOOL_PLACE_ANIMALS click. 332 """Handle an TOOL_PLACE_ANIMALS click.
326 333
327 This will either select an animal or 334 This will either select an animal or
328 place a selected animal in a building. 335 place a selected animal in a building.
329 """ 336 """
330 chicken = self.get_outside_chicken(tile_pos) 337 chicken = self.get_outside_chicken(tile_pos)
331 if chicken: 338 if chicken:
332 if chicken is self.animal_to_place: 339 if chicken is self.animal_to_place:
333 self.animal_to_place = None 340 self.select_animal_to_place(None)
334 pygame.mouse.set_cursor(*cursors.cursors['select']) 341 pygame.mouse.set_cursor(*cursors.cursors['select'])
335 else: 342 else:
336 self.animal_to_place = chicken 343 self.select_animal_to_place(chicken)
337 pygame.mouse.set_cursor(*cursors.cursors['chicken']) 344 pygame.mouse.set_cursor(*cursors.cursors['chicken'])
338 return 345 return
339 building = self.get_building(tile_pos) 346 building = self.get_building(tile_pos)
340 if building: 347 if building:
341 if self.animal_to_place: 348 if self.animal_to_place:
342 try: 349 try:
343 place = building.first_empty_place() 350 place = building.first_empty_place()
344 self.relocate_animal(self.animal_to_place, place=place) 351 self.relocate_animal(self.animal_to_place, place=place)
345 self.animal_to_place = None 352 self.select_animal_to_place(None)
346 pygame.mouse.set_cursor(*cursors.cursors['select']) 353 pygame.mouse.set_cursor(*cursors.cursors['select'])
347 except buildings.BuildingFullError: 354 except buildings.BuildingFullError:
348 pass 355 pass
349 else: 356 else:
350 self.open_building_dialog(building) 357 self.open_building_dialog(building)
398 """Create dialog for manipulating the contents of a building.""" 405 """Create dialog for manipulating the contents of a building."""
399 def select_occupant(place, button, sell_callback): 406 def select_occupant(place, button, sell_callback):
400 """Select occupant in place.""" 407 """Select occupant in place."""
401 # sell_callback should return true if we need to remove the 408 # sell_callback should return true if we need to remove the
402 # occupant 409 # occupant
403 self.animal_to_place = place.occupant 410 self.select_animal_to_place(place.occupant)
404 if not sell_callback: 411 if not sell_callback:
405 pygame.mouse.set_cursor(*cursors.cursors['chicken']) 412 pygame.mouse.set_cursor(*cursors.cursors['chicken'])
406 else: 413 else:
407 # Attempt to sell the occupant 414 # Attempt to sell the occupant
408 self.animal_to_place = None 415 self.select_animal_to_place(None)
409 if sell_callback(place.occupant): 416 if sell_callback(place.occupant):
410 button.value = icons.EMPTY_NEST_ICON 417 button.value = icons.EMPTY_NEST_ICON
411 button.disconnect(gui.CLICK, select_occupant) 418 button.disconnect(gui.CLICK, select_occupant)
412 button.connect(gui.CLICK, set_occupant, place, button, 419 button.connect(gui.CLICK, set_occupant, place, button,
413 sell_callback) 420 sell_callback)