Mercurial > rinkhals
comparison gamelib/gameboard.py @ 573:ffdaac5d6cf8
Select is the default tool.
author | Jeremy Thurgood <firxen@gmail.com> |
---|---|
date | Sat, 28 Nov 2009 20:29:33 +0000 |
parents | 2921169e545b |
children | 2899ddc4d92c |
comparison
equal
deleted
inserted
replaced
572:40eee9e1246c | 573:ffdaac5d6cf8 |
---|---|
245 self.tv.loop() | 245 self.tv.loop() |
246 | 246 |
247 def set_selected_tool(self, tool, cursor): | 247 def set_selected_tool(self, tool, cursor): |
248 if not self.day: | 248 if not self.day: |
249 return False | 249 return False |
250 if tool is None: | |
251 tool = constants.TOOL_SELECT_CHICKENS | |
252 cursor = cursors.cursors['select'] | |
250 if self.apply_tool_to_selected(tool): | 253 if self.apply_tool_to_selected(tool): |
251 return False # Using the tool on selected chickens is immediate | 254 return False # Using the tool on selected chickens is immediate |
252 self.selected_tool = tool | 255 self.selected_tool = tool |
253 sprite_curs = None | 256 sprite_curs = None |
254 if buildings.is_building(tool): | 257 if buildings.is_building(tool): |
310 | 313 |
311 def start_night(self): | 314 def start_night(self): |
312 self.day, self.night = False, True | 315 self.day, self.night = False, True |
313 self.tv.sun(False) | 316 self.tv.sun(False) |
314 self.reset_states() | 317 self.reset_states() |
318 self.selected_tool = None | |
319 self.current_cursor = (cursors.cursors['arrow'],) | |
320 self.set_menu_cursor() | |
315 self.unselect_all() | 321 self.unselect_all() |
316 self.toolbar.start_night() | 322 self.toolbar.start_night() |
317 self.spawn_foxes() | 323 self.spawn_foxes() |
318 self.eggs = 0 | 324 self.eggs = 0 |
319 for chicken in self.chickens.copy(): | 325 for chicken in self.chickens.copy(): |
354 | 360 |
355 def use_tool(self, e): | 361 def use_tool(self, e): |
356 if not self.day: | 362 if not self.day: |
357 return | 363 return |
358 if e.button == 3: # Right button | 364 if e.button == 3: # Right button |
359 if self.toolbar.MOVE_SELECT_PERMITTED: | 365 if self.selected_tool == constants.TOOL_SELECT_CHICKENS: |
360 if self.selected_tool != constants.TOOL_SELECT_CHICKENS: | 366 self.place_animal(self.tv.screen_to_tile(e.pos)) |
361 self.set_selected_tool(constants.TOOL_SELECT_CHICKENS, cursors.cursors["select"]) | |
362 elif self.selected_tool == constants.TOOL_SELECT_CHICKENS: | |
363 self.set_selected_tool(constants.TOOL_PLACE_ANIMALS, cursors.cursors["chicken"]) | |
364 if self.toolbar.IS_DEFAULT: | |
365 self.toolbar.highlight_move_select_button() | |
366 return | 367 return |
367 elif e.button == 2: # Middle button | 368 elif e.button == 2: # Middle button |
368 self.reset_states() | 369 self.reset_states() |
369 self.unselect_all() | 370 self.unselect_all() |
371 return | |
370 elif e.button != 1: # Left button | 372 elif e.button != 1: # Left button |
371 return | 373 return |
372 mods = pygame.key.get_mods() | 374 mods = pygame.key.get_mods() |
373 if self.selected_tool == constants.TOOL_SELL_CHICKEN: | 375 if self.selected_tool == constants.TOOL_SELL_CHICKEN: |
374 self.sell_chicken(self.tv.screen_to_tile(e.pos)) | 376 self.sell_chicken(self.tv.screen_to_tile(e.pos)) |
375 elif self.selected_tool == constants.TOOL_SELL_EGG: | 377 elif self.selected_tool == constants.TOOL_SELL_EGG: |
376 self.sell_egg(self.tv.screen_to_tile(e.pos)) | 378 self.sell_egg(self.tv.screen_to_tile(e.pos)) |
377 elif self.selected_tool == constants.TOOL_PLACE_ANIMALS: | 379 elif self.selected_tool == constants.TOOL_PLACE_ANIMALS: |
378 self.place_animal(self.tv.screen_to_tile(e.pos)) | 380 self.place_animal(self.tv.screen_to_tile(e.pos)) |
379 self.set_selected_tool(constants.TOOL_SELECT_CHICKENS, cursors.cursors["select"]) | 381 self.set_selected_tool(constants.TOOL_SELECT_CHICKENS, cursors.cursors["select"]) |
382 self.toolbar.unhighlight_move_button() | |
380 elif self.selected_tool == constants.TOOL_SELECT_CHICKENS: | 383 elif self.selected_tool == constants.TOOL_SELECT_CHICKENS: |
381 # ctrl moves current selection without having to select move tool | 384 # ctrl moves current selection without having to select move tool |
382 if (mods & KMOD_CTRL): | 385 if (mods & KMOD_CTRL): |
383 self.place_animal(self.tv.screen_to_tile(e.pos)) | 386 self.place_animal(self.tv.screen_to_tile(e.pos)) |
384 else: | 387 else: |
395 equipment_cls = toolbar.SellToolBar.get_equip_cls(self.selected_tool) | 398 equipment_cls = toolbar.SellToolBar.get_equip_cls(self.selected_tool) |
396 self.sell_equipment(self.tv.screen_to_tile(e.pos), equipment_cls) | 399 self.sell_equipment(self.tv.screen_to_tile(e.pos), equipment_cls) |
397 elif equipment.is_equipment(self.selected_tool): | 400 elif equipment.is_equipment(self.selected_tool): |
398 if not self.selected_chickens: | 401 if not self.selected_chickens: |
399 # old selection behaviour | 402 # old selection behaviour |
400 self.buy_equipment(self.tv.screen_to_tile(e.pos), | 403 self.buy_equipment(self.tv.screen_to_tile(e.pos), self.selected_tool) |
401 self.selected_tool) | |
402 | 404 |
403 def get_outside_chicken(self, tile_pos): | 405 def get_outside_chicken(self, tile_pos): |
404 for chick in self.chickens: | 406 for chick in self.chickens: |
405 if chick.covers(tile_pos) and chick.outside(): | 407 if chick.covers(tile_pos) and chick.outside(): |
406 return chick | 408 return chick |