Mercurial > touhou
comparison pytouhou/ui/gamerunner.pyx @ 456:cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Tue, 16 Jul 2013 21:11:40 +0200 |
parents | 6864a38b2413 |
children | 1b56d62250ab |
comparison
equal
deleted
inserted
replaced
455:6864a38b2413 | 456:cae1ae9de430 |
---|---|
26 from .gamerenderer import GameRenderer | 26 from .gamerenderer import GameRenderer |
27 from .background import BackgroundRenderer | 27 from .background import BackgroundRenderer |
28 from .music import MusicPlayer, SFXPlayer, NullPlayer | 28 from .music import MusicPlayer, SFXPlayer, NullPlayer |
29 from .shaders.eosd import GameShader, BackgroundShader | 29 from .shaders.eosd import GameShader, BackgroundShader |
30 | 30 |
31 from collections import namedtuple | |
32 Rect = namedtuple('Rect', 'x y w h') | |
33 Color = namedtuple('Color', 'r g b a') | |
31 | 34 |
32 logger = get_logger(__name__) | 35 logger = get_logger(__name__) |
33 | 36 |
34 | 37 |
35 class GameRunner(GameRenderer): | 38 class GameRunner(GameRenderer): |
156 self.save_keystates.append(keystate) | 159 self.save_keystates.append(keystate) |
157 | 160 |
158 self.game.run_iter(keystate) | 161 self.game.run_iter(keystate) |
159 if not self.skip: | 162 if not self.skip: |
160 self.render_game() | 163 self.render_game() |
164 self.render_text() | |
161 self.render_interface() | 165 self.render_interface() |
162 return True | 166 return True |
163 | 167 |
164 | 168 |
165 def render_game(self): | 169 def render_game(self): |
173 | 177 |
174 GameRenderer.render(self) | 178 GameRenderer.render(self) |
175 | 179 |
176 glDisable(GL_SCISSOR_TEST) | 180 glDisable(GL_SCISSOR_TEST) |
177 | 181 |
182 if self.game.msg_runner: | |
183 rect = Rect(48, 368, 288, 48) | |
184 color1 = Color(0, 0, 0, 192) | |
185 color2 = Color(0, 0, 0, 128) | |
186 self.render_quads([rect], [(color1, color1, color2, color2)], 0) | |
187 | |
188 | |
189 def render_text(self): | |
190 if self.font_manager is None: | |
191 return | |
192 | |
193 labels = [label for label in self.game.texts + self.game.native_texts if label is not None] | |
194 self.font_manager.load(labels) | |
195 | |
196 black = Color(0, 0, 0, 255) | |
197 | |
198 for label in labels: | |
199 if label is None: | |
200 continue | |
201 | |
202 rect = Rect(label.x, label.y, label.width, label.height) | |
203 gradient = [Color(*color, a=label.alpha) for color in label.gradient] | |
204 | |
205 if label.shadow: | |
206 shadow_rect = Rect(label.x + 1, label.y + 1, label.width, label.height) | |
207 shadow = [black._replace(a=label.alpha)] * 4 | |
208 self.render_quads([shadow_rect, rect], [shadow, gradient], label.texture) | |
209 else: | |
210 self.render_quads([rect], [gradient], label.texture) | |
211 | |
178 | 212 |
179 def render_interface(self): | 213 def render_interface(self): |
180 elements = [] | 214 elements = [] |
181 interface = self.game.interface | 215 interface = self.game.interface |
182 interface.labels['framerate'].set_text('%.2ffps' % self.window.get_fps()) | 216 interface.labels['framerate'].set_text('%.2ffps' % self.window.get_fps()) |