source: abuse/trunk/src/oldhelp.cpp @ 555

Last change on this file since 555 was 555, checked in by Sam Hocevar, 11 years ago

ps3: make everything compile on the PS3. Of course, nothing links yet
because so much support is missing.

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