1 | /* |
---|
2 | * Abuse - dark 2D side-scrolling platform game |
---|
3 | * Copyright (c) 1995 Crack dot Com |
---|
4 | * Copyright (c) 2005-2011 Sam Hocevar <sam@hocevar.net> |
---|
5 | * |
---|
6 | * This software was released into the Public Domain. As with most public |
---|
7 | * domain software, no warranty is made or implied by Crack dot Com, by |
---|
8 | * Jonathan Clark, or by Sam Hocevar. |
---|
9 | */ |
---|
10 | |
---|
11 | #if defined HAVE_CONFIG_H |
---|
12 | # include "config.h" |
---|
13 | #endif |
---|
14 | |
---|
15 | #include <string.h> |
---|
16 | |
---|
17 | #include "help.h" |
---|
18 | #include "game.h" |
---|
19 | |
---|
20 | int help_page=0; |
---|
21 | |
---|
22 | |
---|
23 | #define HELP_PAGES 3 |
---|
24 | |
---|
25 | char *get_page(int x) |
---|
26 | { |
---|
27 | char tmp[800],line[120]; |
---|
28 | FILE *fp=fopen("help.txt","r"); |
---|
29 | if (!fp) |
---|
30 | return strcpy((char *)malloc(40),"help.txt missing"); |
---|
31 | else |
---|
32 | { |
---|
33 | tmp[0]=0; |
---|
34 | while (x) |
---|
35 | { |
---|
36 | fgets(line,120,fp); |
---|
37 | if (line[0]=='.' && line[1]=='n') |
---|
38 | x--; |
---|
39 | if (line[0]=='.' && line[1]=='e') |
---|
40 | { |
---|
41 | fclose(fp); |
---|
42 | return strcpy((char *)malloc(30),"missing page"); |
---|
43 | } |
---|
44 | |
---|
45 | } |
---|
46 | do |
---|
47 | { |
---|
48 | fgets(line,120,fp); |
---|
49 | if (line[0]=='.') |
---|
50 | { |
---|
51 | fclose(fp); |
---|
52 | return strdup(tmp); |
---|
53 | } |
---|
54 | else strcat(tmp,line); |
---|
55 | } while (1); |
---|
56 | } |
---|
57 | } |
---|
58 | |
---|
59 | |
---|
60 | void make_help_page(int page, image *s) |
---|
61 | { |
---|
62 | int x=0,y=0,fw=wm->font()->width(),fh=wm->font()->height(),ya; |
---|
63 | char *h,*ho,imname[30],*inp; |
---|
64 | h=ho=get_page(page); |
---|
65 | |
---|
66 | s->clear(28); // light gray |
---|
67 | |
---|
68 | bFILE *fp=open_file("art/joy.spe","rb"); |
---|
69 | if (fp->open_failure()) |
---|
70 | { |
---|
71 | wm->font()->put_string(s,10,10,"Help file missing!"); |
---|
72 | return ; |
---|
73 | |
---|
74 | } |
---|
75 | spec_directory sd(fp); |
---|
76 | image *im; |
---|
77 | |
---|
78 | |
---|
79 | while (*h) |
---|
80 | { |
---|
81 | ya=fh; |
---|
82 | while (*h && *h!='\n') |
---|
83 | { |
---|
84 | if (*h=='@') |
---|
85 | { |
---|
86 | h++; |
---|
87 | if (*h=='@') |
---|
88 | { |
---|
89 | wm->font()->put_char(s,x,y,*h); |
---|
90 | x+=fw; |
---|
91 | h++; |
---|
92 | } |
---|
93 | else |
---|
94 | { |
---|
95 | inp=imname; |
---|
96 | int center=0; |
---|
97 | if (*h=='#') |
---|
98 | { |
---|
99 | center=1; |
---|
100 | h++; |
---|
101 | } |
---|
102 | if (*h=='+') |
---|
103 | { |
---|
104 | h++; |
---|
105 | while (*h!='+') |
---|
106 | { |
---|
107 | *inp=*h; |
---|
108 | h++; |
---|
109 | inp++; |
---|
110 | } |
---|
111 | h++; |
---|
112 | *inp=0; |
---|
113 | x=atoi(imname); |
---|
114 | inp=imname; |
---|
115 | } |
---|
116 | |
---|
117 | |
---|
118 | while (*h!='@') |
---|
119 | { |
---|
120 | *inp=*h; |
---|
121 | h++; |
---|
122 | inp++; |
---|
123 | } |
---|
124 | *inp=0; |
---|
125 | h++; |
---|
126 | |
---|
127 | if (!sd.find(imname)) |
---|
128 | { |
---|
129 | wm->font()->put_string(s,0,yres-10,"Missing image!"); |
---|
130 | delete fp; |
---|
131 | free(ho); |
---|
132 | return ; |
---|
133 | } |
---|
134 | im=new image(sd.find(imname),fp); |
---|
135 | |
---|
136 | if (center) |
---|
137 | { |
---|
138 | im->put_image(s,x,y-im->height()/2,1); |
---|
139 | if (im->height()/2>=ya) |
---|
140 | ya=im->height()/2+1; |
---|
141 | } |
---|
142 | else |
---|
143 | { |
---|
144 | im->put_image(s,x,y,1); |
---|
145 | if (im->height()>=ya) |
---|
146 | ya=im->height()+1; |
---|
147 | } |
---|
148 | x+=im->width()+1; |
---|
149 | delete im; |
---|
150 | } |
---|
151 | } else if (*h=='`') |
---|
152 | { |
---|
153 | inp=imname; |
---|
154 | h+=2; |
---|
155 | while (*h!='`') |
---|
156 | { |
---|
157 | *inp=*h; |
---|
158 | h++; |
---|
159 | inp++; |
---|
160 | } |
---|
161 | h++; |
---|
162 | *inp=0; |
---|
163 | x=atoi(imname); |
---|
164 | } |
---|
165 | else |
---|
166 | { |
---|
167 | wm->font()->put_char(s,x,y,*h); |
---|
168 | x+=fw; |
---|
169 | h++; |
---|
170 | } |
---|
171 | } |
---|
172 | y+=ya; |
---|
173 | x=0; |
---|
174 | if (*h) h++; |
---|
175 | } |
---|
176 | free(ho); |
---|
177 | delete fp; |
---|
178 | } |
---|
179 | |
---|
180 | |
---|
181 | void show_help(int direction) |
---|
182 | { |
---|
183 | int i; |
---|
184 | image *h=new image(screen->width(),screen->height(),NULL,2),*old_screen; |
---|
185 | |
---|
186 | if (direction>0) |
---|
187 | make_help_page(help_page,h); |
---|
188 | else |
---|
189 | { |
---|
190 | old_screen=screen; |
---|
191 | screen=h; |
---|
192 | the_game->draw(); |
---|
193 | screen=old_screen; |
---|
194 | } |
---|
195 | |
---|
196 | |
---|
197 | int steps=8; |
---|
198 | int scroll_step=screen->height()/steps; |
---|
199 | int helpy=-screen->height()+scroll_step; |
---|
200 | |
---|
201 | for (i=0; i<steps; i++,helpy+=scroll_step) |
---|
202 | { |
---|
203 | screen->scroll(0,0,xres,yres,0,scroll_step); |
---|
204 | h->put_part(screen,0,helpy,0,0,xres,-helpy+scroll_step); |
---|
205 | wm->flush_screen(); |
---|
206 | } |
---|
207 | delete h; |
---|
208 | } |
---|
209 | |
---|
210 | |
---|
211 | |
---|
212 | |
---|
213 | |
---|
214 | |
---|
215 | void help_handle_event(event &ev) |
---|
216 | { |
---|
217 | if (ev.window!=NULL) return ; |
---|
218 | |
---|
219 | if (the_game->state!=HELP_STATE) |
---|
220 | { |
---|
221 | if (ev.type==EV_KEY && (ev.key=='h' || ev.key=='?')) |
---|
222 | { |
---|
223 | the_game->state=HELP_STATE; |
---|
224 | help_page=0; |
---|
225 | show_help(1); |
---|
226 | } |
---|
227 | } else if (ev.type==EV_KEY) |
---|
228 | { |
---|
229 | if (ev.key==JK_ESC || help_page==HELP_PAGES-1) |
---|
230 | { |
---|
231 | show_help(-1); |
---|
232 | the_game->state=RUN_STATE; |
---|
233 | } |
---|
234 | else |
---|
235 | { |
---|
236 | help_page++; |
---|
237 | show_help(1); |
---|
238 | } |
---|
239 | } |
---|
240 | } |
---|