comparison pyntnclick/cursor.py @ 660:dbec226debe3 pyntnclick

We don't need no resources hacks
author Stefano Rivera <stefano@rivera.za.net>
date Sun, 12 Feb 2012 14:48:47 +0200
parents 2703924c8c70
children 67373f9d2d20
comparison
equal deleted inserted replaced
659:363b603794f5 660:dbec226debe3
9 import pygame.cursors 9 import pygame.cursors
10 import pygame.mouse 10 import pygame.mouse
11 11
12 from pyntnclick.engine import Screen 12 from pyntnclick.engine import Screen
13 13
14 # XXX: Need a way to get at the constants
15 from pyntnclick.constants import GameConstants
16 SCENE_SIZE = GameConstants().scene_size
17 # XXX: Needs a way to get at resource:
18 from pyntnclick.resources import Resources
19 get_image = Resources("Resources").get_image
20
21 14
22 class CursorSprite(Sprite): 15 class CursorSprite(Sprite):
23 "A Sprite that follows the Cursor" 16 "A Sprite that follows the Cursor"
24 17
25 def __init__(self, filename, x=None, y=None): 18 def __init__(self, filename, x=None, y=None):
27 self.filename = filename 20 self.filename = filename
28 self.pointer_x = x 21 self.pointer_x = x
29 self.pointer_y = y 22 self.pointer_y = y
30 self.highlighted = False 23 self.highlighted = False
31 24
32 def load(self): 25 def load(self, resources):
33 if not hasattr(self, 'plain_image'): 26 if not hasattr(self, 'plain_image'):
34 self.plain_image = get_image('items', self.filename) 27 self.plain_image = resources.get_image('items', self.filename)
35 self.image = self.plain_image 28 self.image = self.plain_image
36 self.rect = self.image.get_rect() 29 self.rect = self.image.get_rect()
37 30
38 if self.pointer_x is None: 31 if self.pointer_x is None:
39 self.pointer_x = self.rect.size[0] // 2 32 self.pointer_x = self.rect.size[0] // 2
90 cursor = HAND 83 cursor = HAND
91 else: 84 else:
92 cursor = item.CURSOR 85 cursor = item.CURSOR
93 if cursor != self._loaded_cursor: 86 if cursor != self._loaded_cursor:
94 self._loaded_cursor = cursor 87 self._loaded_cursor = cursor
95 self._loaded_cursor.load() 88 self._loaded_cursor.load(self.gd.resource)
96 self._cursor_group.empty() 89 self._cursor_group.empty()
97 self._cursor_group.add(self._loaded_cursor) 90 self._cursor_group.add(self._loaded_cursor)
98 91
99 def cursor_highlight(self): 92 def cursor_highlight(self):
100 if not Rect((0, 0), SCENE_SIZE).collidepoint(pygame.mouse.get_pos()): 93 #XXX: if not Rect((0, 0), SCENE_SIZE).collidepoint(pygame.mouse.get_pos()):
101 return False 94 #XXX: return False
102 if self.screen.game.highlight_override: 95 if self.screen.game.highlight_override:
103 return True 96 return True
104 current_thing = self.screen.game.current_thing 97 current_thing = self.screen.game.current_thing
105 if current_thing: 98 if current_thing:
106 return current_thing.is_interactive() 99 return current_thing.is_interactive()