source: abuse/tags/0.7.0/src/oldhelp.cpp @ 672

Last change on this file since 672 was 2, checked in by Sam Hocevar, 17 years ago
  • imported original 0.7.0 tarball
File size: 3.7 KB
Line 
1#include "help.hpp"
2#include "game.hpp"
3
4int help_page=0;
5
6
7#define HELP_PAGES 3
8
9char *get_page(int x)
10{
11  char tmp[800],line[120]; 
12  FILE *fp=fopen("help.txt","r");
13  if (!fp) 
14    return strcpy((char *)jmalloc(40,"Help missing error string"),"help.txt missing");   
15  else
16  {
17    tmp[0]=0;
18    while (x)
19    {
20      fgets(line,120,fp);
21      if (line[0]=='.' && line[1]=='n')     
22        x--;     
23      if (line[0]=='.' && line[1]=='e')
24      {
25        fclose(fp);     
26        return strcpy((char *)jmalloc(30,"help : page missing string"),"missing page");         
27      }
28     
29    }
30    do
31    {
32      fgets(line,120,fp);
33      if (line[0]=='.')     
34      {
35        fclose(fp);     
36        return strcpy((char *)jmalloc(strlen(tmp)+1,"help page"),tmp);
37      }     
38      else strcat(tmp,line);
39    } while (1);
40  }
41}
42
43
44void make_help_page(int page, image *s)
45{
46  int x=0,y=0,fw=eh->font()->width(),fh=eh->font()->height(),ya;
47  char *h,*ho,imname[30],*inp;
48  h=ho=get_page(page);
49 
50  s->clear(28);      // light gray
51 
52  bFILE *fp=open_file("art/joy.spe","rb");
53  if (fp->open_failure())
54  {
55    eh->font()->put_string(s,10,10,"Help file missing!");
56    return ;
57   
58  } 
59  spec_directory sd(fp);
60  image *im;
61   
62
63  while (*h)
64  {
65    ya=fh;   
66    while (*h && *h!='\n')
67    {     
68      if (*h=='@')
69      {
70        h++;
71        if (*h=='@')
72        {         
73          eh->font()->put_char(s,x,y,*h);
74          x+=fw;         
75          h++;   
76        }       
77        else
78        {
79          inp=imname;
80          int center=0;
81          if (*h=='#')
82          {
83            center=1;
84            h++;           
85          }
86          if (*h=='+')
87          {
88            h++;           
89            while (*h!='+')
90            {
91              *inp=*h;
92              h++;
93              inp++;       
94            }
95            h++;           
96            *inp=0;
97            x=atoi(imname);
98            inp=imname;     
99          }
100         
101         
102          while (*h!='@')
103          {
104            *inp=*h;
105            h++;
106            inp++;         
107          }
108          *inp=0;
109          h++;
110         
111          if (!sd.find(imname))
112          {         
113            eh->font()->put_string(s,0,yres-10,"Missing image!");
114            delete fp;
115            jfree(ho);     
116            return ;       
117          }
118          im=new image(sd.find(imname),fp);
119
120          if (center)
121          {         
122            im->put_image(s,x,y-im->height()/2,1);
123            if (im->height()/2>=ya)
124              ya=im->height()/2+1;
125          }       
126          else
127          {         
128            im->put_image(s,x,y,1);
129            if (im->height()>=ya)
130              ya=im->height()+1;
131          }       
132          x+=im->width()+1;               
133          delete im;     
134        }
135      } else if (*h=='`')
136      {
137        inp=imname;             
138        h+=2;   
139        while (*h!='`')
140        {
141          *inp=*h;
142          h++;
143          inp++;           
144        }
145        h++;       
146        *inp=0;
147        x=atoi(imname);
148      }
149      else
150      {
151        eh->font()->put_char(s,x,y,*h);
152        x+=fw;   
153        h++;   
154      }                 
155    }   
156    y+=ya;
157    x=0;   
158    if (*h) h++;   
159  }   
160  jfree(ho);
161  delete fp;
162}
163
164
165void show_help(int direction)
166{
167  int i;   
168  image *h=new image(screen->width(),screen->height(),NULL,2),*old_screen;
169
170  if (direction>0)
171    make_help_page(help_page,h);
172  else
173  {
174    old_screen=screen;
175    screen=h;
176    the_game->draw();
177    screen=old_screen;   
178  }
179 
180 
181  int steps=8; 
182  int scroll_step=screen->height()/steps;
183  int helpy=-screen->height()+scroll_step;
184 
185  for (i=0;i<steps;i++,helpy+=scroll_step)
186  {
187    screen->scroll(0,0,xres,yres,0,scroll_step);
188    h->put_part(screen,0,helpy,0,0,xres,-helpy+scroll_step);
189    eh->flush_screen();   
190  }
191  delete h;       
192}
193
194
195
196
197
198
199void help_handle_event(event &ev)
200{
201  if (ev.window!=NULL) return ;
202 
203  if (the_game->state!=HELP_STATE)
204  {
205    if (ev.type==EV_KEY && (ev.key=='h' || ev.key=='?'))
206    {
207      the_game->state=HELP_STATE;
208      help_page=0;
209      show_help(1);     
210    }
211  } else if (ev.type==EV_KEY)
212  {
213    if (ev.key==JK_ESC || help_page==HELP_PAGES-1)
214    {         
215      show_help(-1);
216      the_game->state=RUN_STATE;   
217    }
218    else
219    {
220      help_page++;
221      show_help(1);           
222    }   
223  }   
224}
Note: See TracBrowser for help on using the repository browser.