comparison pyntnclick/scenewidgets.py @ 763:afe7b1cb16c0 pyntnclick

Interacts should get their images through the game's resource module
author Stefano Rivera <stefano@rivera.za.net>
date Sat, 26 Jan 2013 13:24:01 +0200
parents f288e5ec0a75
children a8510f4e2ea1
comparison
equal deleted inserted replaced
762:683ff96d413e 763:afe7b1cb16c0
6 from pygame.colordict import THECOLORS 6 from pygame.colordict import THECOLORS
7 from pygame.surface import Surface 7 from pygame.surface import Surface
8 8
9 from pyntnclick.state import Thing 9 from pyntnclick.state import Thing
10 from pyntnclick.widgets.text import LabelWidget 10 from pyntnclick.widgets.text import LabelWidget
11
12 # XXX: Needs a way to get at resource:
13 from pyntnclick.resources import Resources
14 get_image = Resources("data").get_image
15 11
16 12
17 class Interact(object): 13 class Interact(object):
18 14
19 def __init__(self, image, rect, interact_rect): 15 def __init__(self, image, rect, interact_rect):
75 super(InteractImage, self).__init__(None, None, None) 71 super(InteractImage, self).__init__(None, None, None)
76 self._pos = (x, y) 72 self._pos = (x, y)
77 self._image_name = image_name 73 self._image_name = image_name
78 74
79 def set_thing(self, thing): 75 def set_thing(self, thing):
80 self.image = get_image(thing.folder, self._image_name) 76 self.image = thing.resource.get_image(thing.folder, self._image_name)
81 self.rect = Rect(self._pos, self.image.get_size()) 77 self.rect = Rect(self._pos, self.image.get_size())
82 self.interact_rect = self.rect 78 self.interact_rect = self.rect
79
80 def __repr__(self):
81 return '<InteractImage: %s>' % self._image_name
83 82
84 83
85 class InteractImageRect(InteractImage): 84 class InteractImageRect(InteractImage):
86 def __init__(self, x, y, image_name, r_x, r_y, r_w, r_h): 85 def __init__(self, x, y, image_name, r_x, r_y, r_w, r_h):
87 super(InteractImageRect, self).__init__(x, y, image_name) 86 super(InteractImageRect, self).__init__(x, y, image_name)
106 self._frame_count = 0 105 self._frame_count = 0
107 self._anim_seq = None 106 self._anim_seq = None
108 self._delay = delay 107 self._delay = delay
109 108
110 def set_thing(self, thing): 109 def set_thing(self, thing):
111 self._anim_seq = [get_image(thing.folder, x) for x in self._names] 110 self._anim_seq = [thing.resource.get_image(thing.folder, x)
111 for x in self._names]
112 self.image = self._anim_seq[0] 112 self.image = self._anim_seq[0]
113 self.rect = Rect(self._pos, self.image.get_size()) 113 self.rect = Rect(self._pos, self.image.get_size())
114 for image in self._anim_seq: 114 for image in self._anim_seq:
115 assert image.get_size() == self.rect.size 115 assert image.get_size() == self.rect.size
116 self.interact_rect = self.rect 116 self.interact_rect = self.rect