Mercurial > touhou
comparison pytouhou/game/text.py @ 381:f1649d6c6397
Don’t hardcode background script for Widget.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Fri, 07 Sep 2012 12:54:40 +0200 |
parents | b150ed7188a2 |
children | 690b5faaa0e6 |
comparison
equal
deleted
inserted
replaced
380:c25530efea3b | 381:f1649d6c6397 |
---|---|
25 | 25 |
26 self.x, self.y = pos | 26 self.x, self.y = pos |
27 | 27 |
28 | 28 |
29 class Widget(object): | 29 class Widget(object): |
30 def __init__(self, pos, back_wrapper=None): | 30 def __init__(self, pos, back_wrapper=None, back_script=22): |
31 self.sprite = None | 31 self.sprite = None |
32 self.removed = False | 32 self.removed = False |
33 self.changed = True | 33 self.changed = True |
34 self.anmrunner = None | 34 self.anmrunner = None |
35 | 35 |
36 # Set up the backround sprite | 36 # Set up the backround sprite |
37 self.back_wrapper = back_wrapper | 37 self.back_wrapper = back_wrapper |
38 if back_wrapper: | 38 if back_wrapper: |
39 self.sprite = Sprite() | 39 self.sprite = Sprite() |
40 self.anmrunner = ANMRunner(back_wrapper, 22, self.sprite) | 40 self.anmrunner = ANMRunner(back_wrapper, back_script, self.sprite) |
41 self.anmrunner.run_frame() | 41 self.anmrunner.run_frame() |
42 | 42 |
43 self.x, self.y = pos | 43 self.x, self.y = pos |
44 | 44 |
45 def update(self): | 45 def update(self): |
49 self.changed = False | 49 self.changed = False |
50 | 50 |
51 | 51 |
52 | 52 |
53 class GlyphCollection(Widget): | 53 class GlyphCollection(Widget): |
54 def __init__(self, pos, anm_wrapper, back_wrapper=None, ref_script=0, xspacing=14): | 54 def __init__(self, pos, anm_wrapper, back_wrapper=None, ref_script=0, |
55 Widget.__init__(self, pos, back_wrapper) | 55 xspacing=14, back_script=22): |
56 Widget.__init__(self, pos, back_wrapper, back_script) | |
56 | 57 |
57 self.ref_sprite = Sprite() | 58 self.ref_sprite = Sprite() |
58 self.anm_wrapper = anm_wrapper | 59 self.anm_wrapper = anm_wrapper |
59 self.glyphes = [] | 60 self.glyphes = [] |
60 self.xspacing = xspacing | 61 self.xspacing = xspacing |
72 def set_length(self, length): | 73 def set_length(self, length): |
73 current_length = len(self.glyphes) | 74 current_length = len(self.glyphes) |
74 if length > current_length: | 75 if length > current_length: |
75 self.glyphes.extend(Glyph(copy(self.ref_sprite), | 76 self.glyphes.extend(Glyph(copy(self.ref_sprite), |
76 (self.x + self.xspacing * i, self.y)) | 77 (self.x + self.xspacing * i, self.y)) |
77 for i in range(current_length, length)) | 78 for i in range(current_length, length)) |
78 elif length < current_length: | 79 elif length < current_length: |
79 self.glyphes[:] = self.glyphes[:length] | 80 self.glyphes[:] = self.glyphes[:length] |
80 | 81 |
81 | 82 |
82 def set_sprites(self, sprite_indexes): | 83 def set_sprites(self, sprite_indexes): |
86 glyph.sprite.changed = True | 87 glyph.sprite.changed = True |
87 | 88 |
88 | 89 |
89 | 90 |
90 class Text(GlyphCollection): | 91 class Text(GlyphCollection): |
91 def __init__(self, pos, ascii_wrapper, back_wrapper=None, text='', xspacing=14, shift=21): | 92 def __init__(self, pos, ascii_wrapper, back_wrapper=None, text='', |
92 GlyphCollection.__init__(self, pos, ascii_wrapper, back_wrapper, xspacing=xspacing) | 93 xspacing=14, shift=21, back_script=22): |
94 GlyphCollection.__init__(self, pos, ascii_wrapper, back_wrapper, | |
95 xspacing=xspacing, back_script=back_script) | |
93 self.text = '' | 96 self.text = '' |
94 self.shift = shift | 97 self.shift = shift |
95 | 98 |
96 self.set_text(text) | 99 self.set_text(text) |
97 | 100 |
104 self.text = text | 107 self.text = text |
105 self.changed = True | 108 self.changed = True |
106 | 109 |
107 | 110 |
108 def set_color(self, color): | 111 def set_color(self, color): |
109 colors = {'white': (255, 255, 255), 'yellow': (255, 255, 0), 'blue': (192, 192, 255), 'darkblue': (160, 128, 255), 'purple': (224, 128, 255), 'red': (255, 64, 0)} | 112 colors = {'white': (255, 255, 255), 'yellow': (255, 255, 0), |
113 'blue': (192, 192, 255), 'darkblue': (160, 128, 255), | |
114 'purple': (224, 128, 255), 'red': (255, 64, 0)} | |
110 self.ref_sprite.color = colors[color] | 115 self.ref_sprite.color = colors[color] |
111 for glyph in self.glyphes: | 116 for glyph in self.glyphes: |
112 glyph.sprite.color = colors[color] | 117 glyph.sprite.color = colors[color] |
113 | 118 |
114 | 119 |
127 self.update = self.timeout_update | 132 self.update = self.timeout_update |
128 | 133 |
129 | 134 |
130 | 135 |
131 class Counter(GlyphCollection): | 136 class Counter(GlyphCollection): |
132 def __init__(self, pos, anm_wrapper, back_wrapper=None, script=0, xspacing=16, value=0): | 137 def __init__(self, pos, anm_wrapper, back_wrapper=None, script=0, |
133 GlyphCollection.__init__(self, pos, | 138 xspacing=16, value=0, back_script=22): |
134 anm_wrapper, back_wrapper=back_wrapper, | 139 GlyphCollection.__init__(self, pos, anm_wrapper, |
135 ref_script=script, xspacing=xspacing) | 140 back_wrapper=back_wrapper, ref_script=script, |
141 xspacing=xspacing, back_script=back_script) | |
136 | 142 |
137 self.value = value | 143 self.value = value |
138 self.set_value(value) | 144 self.set_value(value) |
139 | 145 |
140 | 146 |