Mercurial > touhou
comparison pytouhou/game/text.py @ 404:6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sun, 24 Mar 2013 10:29:37 +0100 |
parents | e1f5dcd4b83e |
children | c9433188ffdb |
comparison
equal
deleted
inserted
replaced
403:9589a01e6edf | 404:6c0cb3eee33e |
---|---|
84 for glyph, idx in zip(self.glyphes, sprite_indexes): | 84 for glyph, idx in zip(self.glyphes, sprite_indexes): |
85 glyph.sprite.anm, glyph.sprite.texcoords = self.anm_wrapper.get_sprite(idx) | 85 glyph.sprite.anm, glyph.sprite.texcoords = self.anm_wrapper.get_sprite(idx) |
86 glyph.sprite.changed = True | 86 glyph.sprite.changed = True |
87 | 87 |
88 | 88 |
89 def set_color(self, color, text=True): | |
90 if text: | |
91 colors = {'white': (255, 255, 255), 'yellow': (255, 255, 0), | |
92 'blue': (192, 192, 255), 'darkblue': (160, 128, 255), | |
93 'purple': (224, 128, 255), 'red': (255, 64, 0)} | |
94 color = colors[color] | |
95 self.ref_sprite.color = color | |
96 for glyph in self.glyphes: | |
97 glyph.sprite.color = color | |
98 | |
99 | |
100 def set_alpha(self, alpha): | |
101 self.ref_sprite.alpha = alpha | |
102 for glyph in self.glyphes: | |
103 glyph.sprite.alpha = alpha | |
104 | |
105 | |
89 | 106 |
90 class Text(GlyphCollection): | 107 class Text(GlyphCollection): |
91 def __init__(self, pos, ascii_wrapper, back_wrapper=None, text='', | 108 def __init__(self, pos, ascii_wrapper, back_wrapper=None, text='', |
92 xspacing=14, shift=21, back_script=22): | 109 xspacing=14, shift=21, back_script=22, align='left'): |
93 GlyphCollection.__init__(self, pos, ascii_wrapper, back_wrapper, | 110 GlyphCollection.__init__(self, pos, ascii_wrapper, back_wrapper, |
94 xspacing=xspacing, back_script=back_script) | 111 xspacing=xspacing, back_script=back_script) |
95 self.text = '' | 112 self.text = '' |
96 self.shift = shift | 113 self.shift = shift |
97 | 114 |
115 if align == 'center': | |
116 self.x -= xspacing * len(text) // 2 | |
117 elif align == 'right': | |
118 self.x -= xspacing * len(text) | |
119 else: | |
120 assert align == 'left' | |
121 | |
98 self.set_text(text) | 122 self.set_text(text) |
99 | 123 |
100 | 124 |
101 @property | 125 @property |
102 def objects(self): | 126 def objects(self): |
110 self.set_sprites([ord(c) - self.shift for c in text]) | 134 self.set_sprites([ord(c) - self.shift for c in text]) |
111 self.text = text | 135 self.text = text |
112 self.changed = True | 136 self.changed = True |
113 | 137 |
114 | 138 |
115 def set_color(self, color): | 139 def timeout_update(self): |
116 colors = {'white': (255, 255, 255), 'yellow': (255, 255, 0), | 140 GlyphCollection.update(self) |
117 'blue': (192, 192, 255), 'darkblue': (160, 128, 255), | 141 if self.frame == self.timeout: |
118 'purple': (224, 128, 255), 'red': (255, 64, 0)} | 142 self.removed = True |
119 self.ref_sprite.color = colors[color] | |
120 for glyph in self.glyphes: | |
121 glyph.sprite.color = colors[color] | |
122 | 143 |
123 | 144 |
124 def move_timeout_update(self): | 145 def move_timeout_update(self): |
125 GlyphCollection.update(self) | 146 GlyphCollection.update(self) |
126 if self.frame % 2: | 147 if self.frame % 2: |
132 | 153 |
133 def fadeout_timeout_update(self): | 154 def fadeout_timeout_update(self): |
134 GlyphCollection.update(self) | 155 GlyphCollection.update(self) |
135 if self.frame >= self.start: | 156 if self.frame >= self.start: |
136 if self.frame == self.start: | 157 if self.frame == self.start: |
137 self.fade(self.effect, 255, lambda x: x) | 158 self.fade(self.duration, 255, lambda x: x) |
138 elif self.frame == self.timeout - self.effect: | 159 elif self.frame == self.timeout - self.duration: |
139 self.fade(self.effect, 0, lambda x: x) | 160 self.fade(self.duration, 0, lambda x: x) |
140 if self.fade_interpolator: | 161 if self.fade_interpolator: |
141 self.fade_interpolator.update(self.frame) | 162 self.fade_interpolator.update(self.frame) |
142 self.alpha = int(self.fade_interpolator.values[0]) | 163 self.alpha = int(self.fade_interpolator.values[0]) |
143 for glyph in self.glyphes: | 164 for glyph in self.glyphes: |
144 glyph.sprite.alpha = self.alpha | 165 glyph.sprite.alpha = self.alpha |
151 self.fade_interpolator = Interpolator((self.alpha,), self.frame, | 172 self.fade_interpolator = Interpolator((self.alpha,), self.frame, |
152 (alpha,), self.frame + duration, | 173 (alpha,), self.frame + duration, |
153 formula) | 174 formula) |
154 | 175 |
155 | 176 |
156 def set_timeout(self, timeout, effect=None, start=0): | 177 def set_timeout(self, timeout, effect=None, duration=0, start=0): |
157 if effect == None: #XXX | 178 if effect == 'move': |
158 self.update = self.move_timeout_update | 179 self.update = self.move_timeout_update |
159 self.timeout = timeout + start | 180 self.timeout = timeout + start |
160 else: | 181 elif effect == 'fadeout': |
161 self.alpha = 0 | 182 self.alpha = 0 |
162 for glyph in self.glyphes: | 183 for glyph in self.glyphes: |
163 glyph.sprite.alpha = 0 | 184 glyph.sprite.alpha = 0 |
164 self.update = self.fadeout_timeout_update | 185 self.update = self.fadeout_timeout_update |
165 self.effect = effect | 186 self.duration = duration |
166 self.start = start | 187 self.start = start |
188 self.timeout = timeout + start | |
189 else: | |
190 self.update = self.timeout_update | |
167 self.timeout = timeout + start | 191 self.timeout = timeout + start |
168 | 192 |
169 | 193 |
170 | 194 |
171 class Counter(GlyphCollection): | 195 class Counter(GlyphCollection): |