comparison pytouhou/game/text.py @ 430:c9433188ffdb

Remove AnmWrapper, since ANMs are lists of entries now.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sat, 03 Aug 2013 15:49:04 +0200
parents 6c0cb3eee33e
children 1222341ea22c
comparison
equal deleted inserted replaced
429:40d5f3083ebc 430:c9433188ffdb
26 26
27 self.x, self.y = pos 27 self.x, self.y = pos
28 28
29 29
30 class Widget(object): 30 class Widget(object):
31 def __init__(self, pos, back_wrapper=None, back_script=22): 31 def __init__(self, pos, back_anm=None, back_script=22):
32 self.sprite = None 32 self.sprite = None
33 self.removed = False 33 self.removed = False
34 self.changed = True 34 self.changed = True
35 self.anmrunner = None 35 self.anmrunner = None
36 self.frame = 0 36 self.frame = 0
37 37
38 # Set up the backround sprite 38 # Set up the backround sprite
39 self.back_wrapper = back_wrapper 39 self.back_anm = back_anm
40 if back_wrapper: 40 if back_anm:
41 self.sprite = Sprite() 41 self.sprite = Sprite()
42 self.anmrunner = ANMRunner(back_wrapper, back_script, self.sprite) 42 self.anmrunner = ANMRunner(back_anm, back_script, self.sprite)
43 self.anmrunner.run_frame() 43 self.anmrunner.run_frame()
44 44
45 self.x, self.y = pos 45 self.x, self.y = pos
46 46
47 def update(self): 47 def update(self):
52 self.changed = False 52 self.changed = False
53 53
54 54
55 55
56 class GlyphCollection(Widget): 56 class GlyphCollection(Widget):
57 def __init__(self, pos, anm_wrapper, back_wrapper=None, ref_script=0, 57 def __init__(self, pos, anm, back_anm=None, ref_script=0,
58 xspacing=14, back_script=22): 58 xspacing=14, back_script=22):
59 Widget.__init__(self, pos, back_wrapper, back_script) 59 Widget.__init__(self, pos, back_anm, back_script)
60 60
61 self.ref_sprite = Sprite() 61 self.ref_sprite = Sprite()
62 self.anm_wrapper = anm_wrapper 62 self.anm = anm
63 self.glyphes = [] 63 self.glyphes = []
64 self.xspacing = xspacing 64 self.xspacing = xspacing
65 65
66 # Set up ref sprite 66 # Set up ref sprite
67 anm_runner = ANMRunner(anm_wrapper, ref_script, self.ref_sprite) 67 anm_runner = ANMRunner(anm, ref_script, self.ref_sprite)
68 anm_runner.run_frame() 68 anm_runner.run_frame()
69 self.ref_sprite.corner_relative_placement = True #TODO: perhaps not right 69 self.ref_sprite.corner_relative_placement = True #TODO: perhaps not right
70 70
71 71
72 def set_length(self, length): 72 def set_length(self, length):
80 80
81 81
82 def set_sprites(self, sprite_indexes): 82 def set_sprites(self, sprite_indexes):
83 self.set_length(len(sprite_indexes)) 83 self.set_length(len(sprite_indexes))
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 = self.anm
86 glyph.sprite.texcoords = self.anm.sprites[idx]
86 glyph.sprite.changed = True 87 glyph.sprite.changed = True
87 88
88 89
89 def set_color(self, color, text=True): 90 def set_color(self, color, text=True):
90 if text: 91 if text:
103 glyph.sprite.alpha = alpha 104 glyph.sprite.alpha = alpha
104 105
105 106
106 107
107 class Text(GlyphCollection): 108 class Text(GlyphCollection):
108 def __init__(self, pos, ascii_wrapper, back_wrapper=None, text='', 109 def __init__(self, pos, ascii_anm, back_anm=None, text='',
109 xspacing=14, shift=21, back_script=22, align='left'): 110 xspacing=14, shift=21, back_script=22, align='left'):
110 GlyphCollection.__init__(self, pos, ascii_wrapper, back_wrapper, 111 GlyphCollection.__init__(self, pos, ascii_anm, back_anm,
111 xspacing=xspacing, back_script=back_script) 112 xspacing=xspacing, back_script=back_script)
112 self.text = '' 113 self.text = ''
113 self.shift = shift 114 self.shift = shift
114 115
115 if align == 'center': 116 if align == 'center':
191 self.timeout = timeout + start 192 self.timeout = timeout + start
192 193
193 194
194 195
195 class Counter(GlyphCollection): 196 class Counter(GlyphCollection):
196 def __init__(self, pos, anm_wrapper, back_wrapper=None, script=0, 197 def __init__(self, pos, anm, back_anm=None, script=0,
197 xspacing=16, value=0, back_script=22): 198 xspacing=16, value=0, back_script=22):
198 GlyphCollection.__init__(self, pos, anm_wrapper, 199 GlyphCollection.__init__(self, pos, anm,
199 back_wrapper=back_wrapper, ref_script=script, 200 back_anm=back_anm, ref_script=script,
200 xspacing=xspacing, back_script=back_script) 201 xspacing=xspacing, back_script=back_script)
201 202
202 self.value = value 203 self.value = value
203 self.set_value(value) 204 self.set_value(value)
204 205
219 self.changed = True 220 self.changed = True
220 221
221 222
222 223
223 class Gauge(object): 224 class Gauge(object):
224 def __init__(self, pos, anm_wrapper, max_length=280, maximum=1, value=0): 225 def __init__(self, pos, anm, max_length=280, maximum=1, value=0):
225 self.sprite = Sprite() 226 self.sprite = Sprite()
226 self.anmrunner = ANMRunner(anm_wrapper, 21, self.sprite) 227 self.anmrunner = ANMRunner(anm, 21, self.sprite)
227 self.anmrunner.run_frame() 228 self.anmrunner.run_frame()
228 self.removed = False 229 self.removed = False
229 self.sprite.corner_relative_placement = True #TODO: perhaps not right 230 self.sprite.corner_relative_placement = True #TODO: perhaps not right
230 self.objects = [self] 231 self.objects = [self]
231 232