4 // Copyright 2007, 2008 Lancer-X/ASCEAI
6 // This file is part of Meritous Recharged.
8 // Meritous Recharged is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation, either version 3 of the License, or
11 // (at your option) any later version.
13 // Meritous Recharged is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with Meritous Recharged. If not, see <http://www.gnu.org/licenses/>.
26 #include <SDL_image.h>
29 #include "levelblit.h"
38 struct help_line
*l
[256];
43 struct help_section
*s
[256];
46 struct help_file
*hlp
= NULL
;
47 struct help_section
*itemlist
= NULL
;
58 struct help_section
*current_sec
= NULL
;
59 struct help_line
*current_line
= NULL
;
61 hlp
= malloc(sizeof(struct help_file
));
64 fp
= fopen("dat/d/helpfile.txt", "r");
66 if (fgets(linebuf
, 79, fp
) == NULL
) {
69 if (linebuf
[strlen(linebuf
)-1] == 0x0A)
70 linebuf
[strlen(linebuf
)-1] = 0;
72 if (linebuf
[0] == '\'') {
76 if (linebuf
[0] == ':') {
78 hlp
->s
[hlp
->sections
] = malloc(sizeof(struct help_section
));
79 current_sec
= hlp
->s
[hlp
->sections
];
81 current_sec
->identifier
= malloc(strlen(linebuf
));
82 current_sec
->lines
= 0;
83 strcpy(current_sec
->identifier
, linebuf
+1);
88 if (current_sec
!= NULL
) {
89 current_sec
->l
[current_sec
->lines
] = malloc(sizeof(struct help_line
));
90 current_line
= current_sec
->l
[current_sec
->lines
];
92 current_line
->t
= malloc(strlen(linebuf
)+1);
93 strcpy(current_line
->t
, linebuf
);
100 int CheckItemlistSection(char* id
)
102 if (strcmp(id
, "itemlist_header")==0) {
105 if (strcmp(id
, "artifact_map")==0) {
112 if (strcmp(id
, "artifact_shieldbooster")==0) {
119 if (strcmp(id
, "artifact_extracrystalefficiency")==0) {
126 if (strcmp(id
, "artifact_circuitbooster")==0) {
133 if (strcmp(id
, "artifact_metabolismenhancer")==0) {
140 if (strcmp(id
, "artifact_dodgeenhancer")==0) {
147 if (strcmp(id
, "artifact_etherealmonocle")==0) {
154 if (strcmp(id
, "artifact_crystalgatherer")==0) {
161 if (strcmp(id
, "artifact_sword")==0) {
168 if (strcmp(id
, "artifact_halberd")==0) {
175 if (strcmp(id
, "artifact_bow")==0) {
182 if (strcmp(id
, "artifact_seal")==0) {
189 if (strcmp(id
, "artifact_agateknife")==0) {
190 if (player_shield
== 30) {
199 void InitItemlistSection()
201 itemlist
= malloc(sizeof(struct help_section
));
202 itemlist
->identifier
= malloc(strlen("itemlist"));
204 strcpy(itemlist
->identifier
, "itemlist");
205 hlp
->s
[hlp
->sections
] = itemlist
;
206 itemlistid
= hlp
->sections
;
210 void CreateItemlistSection()
213 int currentline
= itemlist
->lines
;
214 struct help_section
*sec
;
215 struct help_section
*no_artifacts
= NULL
;
216 struct help_section
*footer
= NULL
;
222 /* In main menu; just print an “excuse” message */
223 for (s
=0; s
<hlp
->sections
; s
++) {
225 if (strcmp(sec
->identifier
, "itemlist_mainmenu")==0) {
226 for (l
=0; l
<sec
->lines
; l
++) {
227 itemlist
->l
[currentline
] = sec
->l
[l
];
230 itemlist
->lines
= itemlist
->lines
+ sec
->lines
;
235 for (s
=0; s
<hlp
->sections
; s
++) {
237 if (CheckItemlistSection(sec
->identifier
)) {
238 for (l
=0; l
<sec
->lines
; l
++) {
239 itemlist
->l
[currentline
] = sec
->l
[l
];
242 itemlist
->lines
= itemlist
->lines
+ sec
->lines
;
245 if (strcmp(sec
->identifier
, "no_artifacts") == 0) {
248 if (strcmp(sec
->identifier
, "itemlist_footer") == 0) {
252 /* If there’s only 1 section, then we only have the intro section
253 and can conclude that there are no artifact sections */
255 /* Print out special section for when no artifacts have
257 for (l
=0; l
<no_artifacts
->lines
; l
++) {
258 itemlist
->l
[currentline
] = no_artifacts
->l
[l
];
261 itemlist
->lines
= itemlist
->lines
+ no_artifacts
->lines
;
265 for (l
=0; l
<footer
->lines
; l
++) {
266 itemlist
->l
[currentline
] = footer
->l
[l
];
269 itemlist
->lines
= itemlist
->lines
+ footer
->lines
;
273 void BlitArtifact(char* textptr
, int i
) {
282 sprite
= artifact_spr
;
286 sprite
= agate_knife_spr
;
287 if (agate_knife_spr
== NULL
) {
288 agate_knife_spr
= IMG_Load("dat/i/agate.png");
289 SDL_SetColorKey(agate_knife_spr
, SDL_SRCCOLORKEY
| SDL_RLEACCEL
, 0);
298 from
.h
= 32 - (35 - to
.y
);
299 from
.y
= 32 - from
.h
;
300 to
.y
= to
.y
+ from
.y
;
307 from
.h
= 32 - (to
.y
- 413);
312 if(from
.h
> 0 || from
.h
<= 32) {
313 SDL_BlitSurface(sprite
, &from
, screen
, &to
);
321 struct help_section
*current_sec
= NULL
;
326 char linkfollow
[20] = "";
328 DrawRect(23, 23, 594, 434, 0);
329 DrawRect(24, 24, 592, 432, 200);
330 DrawRect(25, 25, 590, 430, 255);
331 DrawRect(26, 26, 588, 428, 200);
332 DrawRect(27, 27, 586, 426, 100);
333 DrawRect(30, 30, 580, 420, 20);
334 DrawRect(35, 35, 570, 410, 60);
337 current_sec
= hlp
->s
[my_sec
];
339 if (current_sec
->lines
> 40) {
340 my_line
= my_cursor
- 19;
342 my_line
= my_cursor
- 39;
344 if (my_line
< 0) my_line
= 0;
345 if (my_line
>= (current_sec
->lines
)) my_line
= current_sec
->lines
- 1;
346 for (i
= 0; i
< 2; i
++) {
347 draw_text(23+i
, 40+(my_cursor
- my_line
)*10, "->", 255);
348 draw_text(599+i
, 40+(my_cursor
- my_line
)*10, "<-", 255);
351 for (i
= -5; i
< 40; i
++) {
352 line_num
= my_line
+ i
;
354 if (line_num
< current_sec
->lines
) {
355 ltext
= current_sec
->l
[line_num
]->t
;
360 draw_text(40 + (560-strlen(ltext
+1)*8)/2, 40+i
*10, ltext
+1, 255);
363 strncpy(c_ident
, ltext
+1, strchr(ltext
+1, '?')-ltext
-1);
364 c_ident
[strchr(ltext
+1, '?')-ltext
-1] = 0;
366 draw_text(40, 40+i
*10, strchr(ltext
+1, '?')+1, my_cursor
== line_num
? 200+(tick
%16)*3 : 150);
367 if ((my_link
== 1)&&(my_cursor
== line_num
)) {
369 strcpy(linkfollow
, c_ident
);
373 draw_text(80, 40+i
*10, ltext
+1, 200);
376 BlitArtifact(ltext
, i
);
379 draw_text(40, 40+i
*10, ltext
, 200);
383 if (ltext
[0] == ',') {
384 BlitArtifact(ltext
, i
);
391 SDL_UpdateRect(screen
, 0, 0, 0, 0);
400 for (i
= 0; i
< hlp
->sections
; i
++) {
401 if (strcmp(linkfollow
, hlp
->s
[i
]->identifier
) == 0) {
414 static int key_delay
= 0;
415 static int key_up
= 0, key_down
= 0;
416 static int joy_up
= 0, joy_down
= 0;
417 int lastline
= hlp
->s
[my_sec
]->lines
-1;
419 if (key_delay
> 0) key_delay
--;
422 while (SDL_PollEvent(&ev
)) {
423 if (ev
.type
== SDL_KEYDOWN
) {
424 if (ev
.key
.keysym
.sym
== SDLK_DOWN
) {
427 if (my_cursor
< lastline
) my_cursor
++;
429 if (ev
.key
.keysym
.sym
== SDLK_UP
) {
432 if (my_cursor
> 0) my_cursor
--;
434 if (ev
.key
.keysym
.sym
== SDLK_PAGEDOWN
) {
435 my_cursor
= my_cursor
+ 40;
436 if (my_cursor
> lastline
) {
437 my_cursor
= lastline
;
440 if (ev
.key
.keysym
.sym
== SDLK_PAGEUP
) {
441 my_cursor
= my_cursor
- 40;
446 if (ev
.key
.keysym
.sym
== SDLK_HOME
) {
449 if (ev
.key
.keysym
.sym
== SDLK_END
) {
450 my_cursor
= lastline
;
452 if (ev
.key
.keysym
.sym
== SDLK_BACKSPACE
) {
455 if (ev
.key
.keysym
.sym
== SDLK_ESCAPE
) {
458 if (ev
.key
.keysym
.sym
== SDLK_h
|| ev
.key
.keysym
.sym
== SDLK_F1
) {
461 if (ev
.key
.keysym
.sym
== SDLK_i
) {
464 if ((ev
.key
.keysym
.sym
== SDLK_SPACE
) || (ev
.key
.keysym
.sym
== SDLK_RETURN
))
468 if (ev
.type
== SDL_KEYUP
) {
469 if (ev
.key
.keysym
.sym
== SDLK_DOWN
) {
472 if (ev
.key
.keysym
.sym
== SDLK_UP
) {
476 if (ev
.type
== SDL_JOYHATMOTION
) {
477 if (ev
.jhat
.value
& SDL_HAT_DOWN
) {
480 if (my_cursor
< lastline
) my_cursor
++;
484 if (ev
.jhat
.value
& SDL_HAT_UP
) {
487 if (my_cursor
> 0) my_cursor
--;
492 if (ev
.type
== SDL_JOYBUTTONDOWN
) {
493 if (ev
.jbutton
.button
== 1) {
496 if (ev
.jbutton
.button
== 3 || ev
.jbutton
.button
== 4 || ev
.jbutton
.button
== 6) {
500 if (ev
.type
== SDL_QUIT
) {
505 if (key_delay
== 0) {
506 if (key_up
== 1 || joy_up
== 1) {
507 if (my_cursor
> 0) my_cursor
--;
509 if (key_down
== 1 || joy_down
== 1) {
510 if (my_cursor
< hlp
->s
[my_sec
]->lines
-1) my_cursor
++;
518 void ShowHelpWindow(int start_section
)
524 if (itemlist
== NULL
) {
525 InitItemlistSection();
527 CreateItemlistSection();
528 my_sec
= start_section
;
537 in_help
= MoveCursor();
552 if (itemlist
== NULL
) {
553 InitItemlistSection();
555 ShowHelpWindow(itemlistid
);