1 | #include "director.hpp" |
---|
2 | #include "game.hpp" |
---|
3 | #include "lisp.hpp" |
---|
4 | #include "fonts.hpp" |
---|
5 | |
---|
6 | director scene_director; |
---|
7 | |
---|
8 | void director::scroll_text(char *Text) |
---|
9 | { text=Text; |
---|
10 | text_y=the_game->first_view->cy2-the_game->first_view->cy1+1; |
---|
11 | } |
---|
12 | |
---|
13 | director::director() |
---|
14 | { |
---|
15 | tleft=ttop=tright=tbottom=pan_xv=pan_yv=0; |
---|
16 | text_step=-2; |
---|
17 | frame_speed=100; |
---|
18 | scroll_speed=60; |
---|
19 | pan_speed=60; |
---|
20 | scene_abort=0; |
---|
21 | } |
---|
22 | |
---|
23 | extern unsigned char *white_light; |
---|
24 | |
---|
25 | |
---|
26 | |
---|
27 | int text_draw(int y, int x1, int y1, int x2, int y2, char *buf, JCFont *font, uint8_t *cmap, char color) |
---|
28 | { |
---|
29 | short cx1,cy1,cx2,cy2,word_size,word_len; |
---|
30 | screen->get_clip(cx1,cy1,cx2,cy2); |
---|
31 | screen->in_clip(x1,y1,x2,y2); |
---|
32 | int h=font->height()+2,w=font->width(),x=x1,dist; |
---|
33 | y+=y1; |
---|
34 | char *word_start; |
---|
35 | |
---|
36 | while (buf && *buf) |
---|
37 | { |
---|
38 | do |
---|
39 | { |
---|
40 | if (*buf=='\\' && buf[1]=='n') |
---|
41 | { |
---|
42 | x=x1; |
---|
43 | y+=h*2; |
---|
44 | buf+=2; |
---|
45 | } |
---|
46 | |
---|
47 | // skip space |
---|
48 | if (*buf==' ' || *buf=='\r' || *buf=='\n' || *buf=='\t') |
---|
49 | { |
---|
50 | x+=w; |
---|
51 | while (*buf==' ' || *buf=='\r' || *buf=='\n' || *buf=='\t') // skip space until next word |
---|
52 | buf++; |
---|
53 | } |
---|
54 | |
---|
55 | word_start=buf; |
---|
56 | for (word_len=0,word_start=buf,word_size=0;*buf && *buf!=' ' && *buf!='\r' && *buf!='\n' && |
---|
57 | *buf!='\t' && (*buf!='\\' || buf[1]!='n');buf++,word_size+=w,word_len++); |
---|
58 | |
---|
59 | if (word_size<x2-x1) // make sure the word can fit on the screen |
---|
60 | { |
---|
61 | if (word_size+x>x2) // does word not fit on line? |
---|
62 | { |
---|
63 | y+=h; // go to next line |
---|
64 | x=x1; |
---|
65 | } |
---|
66 | } |
---|
67 | |
---|
68 | |
---|
69 | if (y+h<y1) // word on screen yet? |
---|
70 | x+=word_size; |
---|
71 | |
---|
72 | } while (*buf && y+h<y1); // if not on screen yet, fetch next word |
---|
73 | |
---|
74 | dist=31; |
---|
75 | if (y-y1<dist) |
---|
76 | if (y-y1<1) dist=0; |
---|
77 | else dist=y-y1; |
---|
78 | |
---|
79 | if (y2-y<dist) |
---|
80 | if (y2-y<1) dist=0; |
---|
81 | else dist=y2-y; |
---|
82 | |
---|
83 | int c=cmap[dist]; |
---|
84 | if (y>y2) { buf=NULL; } |
---|
85 | else |
---|
86 | { |
---|
87 | while (word_len--) |
---|
88 | { |
---|
89 | font->put_char(screen,x+1,y+1,*word_start,0); |
---|
90 | font->put_char(screen,x,y,*word_start,c); |
---|
91 | word_start++; |
---|
92 | x+=w; |
---|
93 | } |
---|
94 | } |
---|
95 | |
---|
96 | } |
---|
97 | screen->set_clip(cx1,cy1,cx2,cy2); |
---|
98 | return (y<=y1); |
---|
99 | } |
---|
100 | |
---|
101 | |
---|
102 | |
---|
103 | |
---|
104 | |
---|
105 | |
---|
106 | |
---|
107 | |
---|
108 | void director::wait(void *arg) |
---|
109 | { |
---|
110 | if (scene_abort) return ; |
---|
111 | pan_time=frame_time=text_time=NULL; |
---|
112 | int done=0; |
---|
113 | void *pan_symbol=make_find_symbol("pan"), |
---|
114 | *text_symbol=make_find_symbol("text"); |
---|
115 | |
---|
116 | JCFont *font=eh->font(); |
---|
117 | |
---|
118 | do |
---|
119 | { |
---|
120 | the_game->draw_map(the_game->first_view); |
---|
121 | time_marker cur_time; |
---|
122 | |
---|
123 | if (pan_steps) |
---|
124 | { |
---|
125 | if (pan_time) |
---|
126 | { |
---|
127 | if ((int)(cur_time.diff_time(pan_time)*1000)>pan_speed) |
---|
128 | { |
---|
129 | the_game->pan(pan_xv,pan_yv); |
---|
130 | pan_steps--; |
---|
131 | delete pan_time; |
---|
132 | if (pan_steps) |
---|
133 | pan_time=new time_marker; |
---|
134 | else pan_time=NULL; |
---|
135 | } |
---|
136 | } else pan_time=new time_marker; |
---|
137 | } else if (arg==pan_symbol) done=1; |
---|
138 | |
---|
139 | if (text) |
---|
140 | { |
---|
141 | if (text_draw(text_y, |
---|
142 | the_game->first_view->cx1+tleft, |
---|
143 | the_game->first_view->cy1+ttop, |
---|
144 | the_game->first_view->cx2-tright, |
---|
145 | the_game->first_view->cy2-tbottom,text,font, |
---|
146 | white_light+32*256, |
---|
147 | eh->bright_color() |
---|
148 | |
---|
149 | )) |
---|
150 | text=NULL; |
---|
151 | if (text_time) |
---|
152 | { |
---|
153 | if ((int)(cur_time.diff_time(text_time)*1000)>scroll_speed) |
---|
154 | { |
---|
155 | text_y+=text_step; |
---|
156 | delete text_time; |
---|
157 | if (text) |
---|
158 | text_time=new time_marker; |
---|
159 | else |
---|
160 | text_time=NULL; |
---|
161 | } |
---|
162 | } else text_time=new time_marker; |
---|
163 | } else if (arg==text_symbol) done=1; |
---|
164 | |
---|
165 | eh->flush_screen(); |
---|
166 | while (eh->event_waiting()) |
---|
167 | { |
---|
168 | event ev; |
---|
169 | eh->get_event(ev); |
---|
170 | if (ev.type==EV_KEY) |
---|
171 | { |
---|
172 | switch (ev.key) |
---|
173 | { |
---|
174 | case JK_UP : |
---|
175 | case JK_LEFT : |
---|
176 | { |
---|
177 | if (scroll_speed>=20) |
---|
178 | scroll_speed-=20; |
---|
179 | else text_step--; |
---|
180 | } |
---|
181 | break; |
---|
182 | case JK_RIGHT : |
---|
183 | case JK_DOWN : |
---|
184 | { |
---|
185 | if (text_step<-2) |
---|
186 | text_step++; |
---|
187 | else if (scroll_speed<200) scroll_speed+=20; |
---|
188 | break; |
---|
189 | case JK_ESC : set_abort(1); done=1; break; |
---|
190 | case JK_ENTER : done=1; break; |
---|
191 | } |
---|
192 | } |
---|
193 | } |
---|
194 | } |
---|
195 | } while (!done); |
---|
196 | if (pan_time) delete pan_time; |
---|
197 | if (frame_time) delete frame_time; |
---|
198 | if (text_time) delete text_time; |
---|
199 | } |
---|
200 | |
---|