Mercurial > touhou
comparison pytouhou/ui/anmrenderer.py @ 241:dd2bd7283bec
Add support for multiple-file anms to anmviewer, add feature to force acceptance of translations
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Sun, 01 Jan 2012 23:52:53 +0100 |
parents | 901489c21d19 |
children | d95beee0087a |
comparison
equal
deleted
inserted
replaced
240:02de1563fa18 | 241:dd2bd7283bec |
---|---|
42 width, height = 384, 448 | 42 width, height = 384, 448 |
43 pyglet.window.Window.__init__(self, width=width, height=height, | 43 pyglet.window.Window.__init__(self, width=width, height=height, |
44 caption='PyTouhou', resizable=False) | 44 caption='PyTouhou', resizable=False) |
45 | 45 |
46 self._anm_wrapper = anm_wrapper | 46 self._anm_wrapper = anm_wrapper |
47 self.anm = anm_wrapper.anm_files[0] | |
48 self.sprites = sprites | 47 self.sprites = sprites |
49 self.clear_color = (0., 0., 0., 1.) | 48 self.clear_color = (0., 0., 0., 1.) |
50 if sprites: | 49 self.force_allow_dest_offset = False |
51 self.items = self.anm.sprites | 50 self.index_items() |
52 else: | |
53 self.items = self.anm.scripts | |
54 self.load(index) | 51 self.load(index) |
55 | 52 |
56 self.x = width / 2 | 53 self.x = width / 2 |
57 self.y = height / 2 | 54 self.y = height / 2 |
58 | 55 |
104 if symbol == pyglet.window.key.ESCAPE: | 101 if symbol == pyglet.window.key.ESCAPE: |
105 self.has_exit = True | 102 self.has_exit = True |
106 elif symbol == pyglet.window.key.W: | 103 elif symbol == pyglet.window.key.W: |
107 self.load() | 104 self.load() |
108 elif symbol == pyglet.window.key.X: | 105 elif symbol == pyglet.window.key.X: |
109 self.x, self.y = (192, 224) if self.x == 0 else (0, 0) | 106 self.x, self.y = {(192, 224): (0, 0), |
107 (0, 0): (-224, 0), | |
108 (-224, 0): (192, 224)}[(self.x, self.y)] | |
109 elif symbol == pyglet.window.key.C: | |
110 self.force_allow_dest_offset = not self.force_allow_dest_offset | |
111 self.load() | |
110 elif symbol == pyglet.window.key.LEFT: | 112 elif symbol == pyglet.window.key.LEFT: |
111 self.change(-1) | 113 self.change(-1) |
112 elif symbol == pyglet.window.key.RIGHT: | 114 elif symbol == pyglet.window.key.RIGHT: |
113 self.change(+1) | 115 self.change(+1) |
114 elif symbol == pyglet.window.key.TAB: | 116 elif symbol == pyglet.window.key.TAB: |
142 index = (keys.index(self.num) + diff) % len(keys) | 144 index = (keys.index(self.num) + diff) % len(keys) |
143 item = keys[index] | 145 item = keys[index] |
144 self.load(item) | 146 self.load(item) |
145 | 147 |
146 | 148 |
149 def index_items(self): | |
150 self.items = {} | |
151 if self.sprites: | |
152 for anm in self._anm_wrapper.anm_files: | |
153 self.items.update(anm.sprites) | |
154 else: | |
155 for anm in self._anm_wrapper.anm_files: | |
156 self.items.update(anm.scripts) | |
157 | |
158 | |
147 def toggle_sprites(self): | 159 def toggle_sprites(self): |
148 self.sprites = not(self.sprites) | 160 self.sprites = not(self.sprites) |
149 if self.sprites: | 161 self.index_items() |
150 self.items = self.anm.sprites | |
151 else: | |
152 self.items = self.anm.scripts | |
153 self.load(0) | 162 self.load(0) |
154 | 163 |
155 | 164 |
156 def toggle_clear_color(self): | 165 def toggle_clear_color(self): |
157 if self.clear_color[0] == 0.: | 166 if self.clear_color[0] == 0.: |
162 | 171 |
163 def update(self): | 172 def update(self): |
164 if not self.sprites: | 173 if not self.sprites: |
165 self._anmrunner.run_frame() | 174 self._anmrunner.run_frame() |
166 | 175 |
176 if self.force_allow_dest_offset: | |
177 self._sprite.allow_dest_offset = True | |
178 | |
167 glClearColor(*self.clear_color) | 179 glClearColor(*self.clear_color) |
168 glClear(GL_COLOR_BUFFER_BIT) | 180 glClear(GL_COLOR_BUFFER_BIT) |
169 if not self._sprite._removed: | 181 if not self._sprite._removed: |
170 self.render_elements([self]) | 182 self.render_elements([self]) |
171 | 183 |