Mercurial > rinkhals
comparison gamelib/gameboard.py @ 565:32b6b66e114a
Cursors change.
author | Jeremy Thurgood <firxen@gmail.com> |
---|---|
date | Sat, 28 Nov 2009 19:15:56 +0000 |
parents | 7f037ee2a6c8 |
children | a8dde729000a |
comparison
equal
deleted
inserted
replaced
564:fb8ab1ee3eaf | 565:32b6b66e114a |
---|---|
38 def event(self, e): | 38 def event(self, e): |
39 if e.type == MOUSEBUTTONDOWN: | 39 if e.type == MOUSEBUTTONDOWN: |
40 self.gameboard.use_tool(e) | 40 self.gameboard.use_tool(e) |
41 elif e.type == MOUSEMOTION and self.gameboard.sprite_cursor: | 41 elif e.type == MOUSEMOTION and self.gameboard.sprite_cursor: |
42 self.gameboard.update_sprite_cursor(e) | 42 self.gameboard.update_sprite_cursor(e) |
43 elif e.type == gui.ENTER: | |
44 self.gameboard.set_tool_cursor() | |
45 elif e.type == gui.EXIT: | |
46 self.gameboard.set_menu_cursor() | |
43 else: | 47 else: |
44 return False | 48 return False |
45 | 49 |
46 | 50 |
47 class AnimalPositionCache(object): | 51 class AnimalPositionCache(object): |
250 sprite_curs = sprite_cursor.SpriteCursor(tool.IMAGE, self.tv, tool.BUY_PRICE) | 254 sprite_curs = sprite_cursor.SpriteCursor(tool.IMAGE, self.tv, tool.BUY_PRICE) |
251 elif equipment.is_equipment(tool): | 255 elif equipment.is_equipment(tool): |
252 sprite_curs = sprite_cursor.SpriteCursor(tool.CHICKEN_IMAGE_FILE, self.tv) | 256 sprite_curs = sprite_cursor.SpriteCursor(tool.CHICKEN_IMAGE_FILE, self.tv) |
253 elif tool == constants.TOOL_PLACE_ANIMALS and self.selected_chickens: | 257 elif tool == constants.TOOL_PLACE_ANIMALS and self.selected_chickens: |
254 cursor = cursors.cursors['chicken'] | 258 cursor = cursors.cursors['chicken'] |
255 self.set_cursor(cursor, sprite_curs) | 259 self.current_cursor = (cursor, sprite_curs) |
260 self.set_tool_cursor((cursor, sprite_curs)) | |
256 return True | 261 return True |
262 | |
263 def set_tool_cursor(self, current_cursor=None): | |
264 if current_cursor: | |
265 self.current_cursor = current_cursor | |
266 if pygame.mouse.get_pos()[0] >= constants.TOOLBAR_WIDTH: | |
267 self.set_cursor(*self.current_cursor) | |
268 | |
269 def set_menu_cursor(self): | |
270 self.set_cursor() | |
257 | 271 |
258 def apply_tool_to_selected(self, tool): | 272 def apply_tool_to_selected(self, tool): |
259 if self.selected_chickens: | 273 if self.selected_chickens: |
260 # dispatch call to selected chickens if appropriate | 274 # dispatch call to selected chickens if appropriate |
261 if tool == constants.TOOL_SELL_CHICKEN: | 275 if tool == constants.TOOL_SELL_CHICKEN: |
540 self.open_building_dialog(building, True) | 554 self.open_building_dialog(building, True) |
541 except buildings.BuildingFullError: | 555 except buildings.BuildingFullError: |
542 pass | 556 pass |
543 if not self.selected_chickens: | 557 if not self.selected_chickens: |
544 # if we placed all the chickens, switch to select cursor | 558 # if we placed all the chickens, switch to select cursor |
545 pygame.mouse.set_cursor(*cursors.cursors['select']) | 559 self.set_tool_cursor((cursors.cursors['select'],)) |
546 elif self.tv.get(tile_pos) == self.GRASSLAND: | 560 elif self.tv.get(tile_pos) == self.GRASSLAND: |
547 for chicken in self.selected_chickens: | 561 for chicken in self.selected_chickens: |
548 try_pos = tile_pos | 562 try_pos = tile_pos |
549 cur_chick = self.get_outside_chicken(try_pos) | 563 cur_chick = self.get_outside_chicken(try_pos) |
550 if cur_chick == chicken: | 564 if cur_chick == chicken: |
578 if tile_pos and not self.selected_chickens: | 592 if tile_pos and not self.selected_chickens: |
579 # Old behaviour | 593 # Old behaviour |
580 chicken = self.get_chicken_at_pos(tile_pos) | 594 chicken = self.get_chicken_at_pos(tile_pos) |
581 if chicken: | 595 if chicken: |
582 self.select_animal(chicken) | 596 self.select_animal(chicken) |
583 pygame.mouse.set_cursor(*cursors.cursors['chicken']) | 597 self.set_tool_cursor((cursors.cursors['chicken'],)) |
584 return | 598 return |
585 elif tile_pos: | 599 elif tile_pos: |
586 building = self.get_building(tile_pos) | 600 building = self.get_building(tile_pos) |
587 def sure(val): | 601 def sure(val): |
588 if val: | 602 if val: |
913 self.restore_selection(self.stored_selections.get(e.key, []), additive) | 927 self.restore_selection(self.stored_selections.get(e.key, []), additive) |
914 return True | 928 return True |
915 elif e.type == KEYDOWN: | 929 elif e.type == KEYDOWN: |
916 mods = pygame.key.get_mods() | 930 mods = pygame.key.get_mods() |
917 if mods & KMOD_CTRL and self.selected_tool == constants.TOOL_SELECT_CHICKENS and self.selected_chickens: | 931 if mods & KMOD_CTRL and self.selected_tool == constants.TOOL_SELECT_CHICKENS and self.selected_chickens: |
918 pygame.mouse.set_cursor(*cursors.cursors['chicken']) | 932 self.set_tool_cursor((cursors.cursors['chicken'],)) |
919 elif e.type == KEYUP: | 933 elif e.type == KEYUP: |
920 mods = pygame.key.get_mods() | 934 mods = pygame.key.get_mods() |
921 if not (mods & KMOD_CTRL) and self.selected_tool == constants.TOOL_SELECT_CHICKENS: | 935 if not (mods & KMOD_CTRL) and self.selected_tool == constants.TOOL_SELECT_CHICKENS: |
922 pygame.mouse.set_cursor(*cursors.cursors['select']) | 936 self.set_tool_cursor((cursors.cursors['select'],)) |
923 return False | 937 return False |
924 | 938 |
925 def restore_selection(self, selection, additive=False): | 939 def restore_selection(self, selection, additive=False): |
926 if not additive: | 940 if not additive: |
927 self.unselect_all() | 941 self.unselect_all() |