{$ifndef unix}
{$A+,B-,D+,E+,F-,G+,I+,L+,N+,O+,P+,Q-,R-,S+,T-,V-,X+,Y+}
{$else}
{$B-,I+,S-,T-,X+}
{$endif}
unit menus7;

interface

uses
 tstring;

procedure MsgMenu(rasse,id,_x,_y,_z,location:longint);

implementation

uses
 grafik,
 types,
 data,
 schedule,
 evgraph,
 utils,
 kb;
{$ifdef unix}
uses xcrt;
{$endif}
procedure MsgMenu(rasse,id,_x,_y,_z,location:longint);
var
 i,
 n,
 a,
 y:word;
 m:array[0..1999] of word;
 redraw:byte;
 o,p:t_bdata;
 message:t_message;
 f:file;

 c:char;
 sc:byte;

 procedure readmsg(ofs:longint);
 var
{$ifndef unix}
  s:string;
{$else}
  s:array[0..255] of char;
{$endif}
  i:byte;
  j:integer;
 begin
  {$i-}
  seek(f,ofs);
  blockread(f,s[0],1,j);
  if j=0 then setstring(message[i],'')
  else begin
   blockread(f,s[1],byte(s[0]),j);
   byte(s[0]):=j;
   setstring(message[i],substr(s,2,byte(s[0])));
  end;
  if ioresult<>0 then;
  {$i+}
 end;

 procedure clearmsg;
 var
  i:byte;
 begin
  for i:=0 to 29 do setstring(message[i],'');
 end;

begin
 oldmenu;
 fillchar(message,sizeof(message),0);
 if msganz=0 then exit;
 clearscreen(0);
 if not msgav then begin
  writex(1,1,$4e,path+'RACE-'+az10[rasse]+'.MSG nicht gefunden');
  writex(1,3,$4f,'Nachrichten nicht verfgbar!');
  if kbreadkey=#0 then kbreadkey;
  exit;
 end;
 initb(o,20*8,0,60,30,7,0);
 initb(p,0,0,19,30,7,0);
 vline(19*8+2,0,479,$e,0);
 vline(19*8+3,0,479,$f,0);
 vline(19*8+4,0,479,$7,0);
 vline(19*8+5,0,479,$8,0);
 a:=1;
 y:=0;
 repeat
  n:=0;
  for i:=0 to msganz-1 do with msglist^[i]
  do if(a=1)
     or(a and ((1 shl concern1)or(1 shl concern2)or(1 shl concern3))<>0)
  then begin
   m[n]:=i;
   inc(n);
  end;
  if n=0 then clearmsg else msginread(m[y],message);

  writeg(p,#0'C'#$f#12'Meldungen zeigen:'#13#10#10);
  for i:=0 to 9 do begin
   writeg(p,#0'C'#$c+char(48+i)+':');
   if (n=0) or ((i<>0)
	    and (msglist^[y].concern1<>i)
	    and (msglist^[y].concern2<>i)
	    and (msglist^[y].concern3<>i)) then writeg(p,' ')
   else writeg(p,#0'C'#7#7);
   if (a and (1 shl i)<>0)
   then writeg(p,#0'C'#$a+concern[i]+#13#10)
   else writeg(p,#0'C'#$7+concern[i]+#13#10);
  end;

  writeg(o,#0'C'#$7#12);
  for i:=0 to 29 do writeg(o,#0'C'#$7+getstring(message[i])+#13#10);

  writeg(p,#0'C'#$e#10'Meldung'#13#10#0'C'#$a+strg(1+y)+#0'C'#$e'/'#0'C'#$a+strg(n)+' ');
  if y<>0 then writeg(p,#24);
  if y<>n-1 then writeg(p,#25);
  redraw:=0;
  repeat
   c:=kbreadkey;
   if c=#0 then sc:=byte(kbreadkey) else sc:=kbscancode;
   case c of
    #27:begin
     for i:=0 to 29 do setstring(message[i],'');
     exit;
    end;
    '0':begin
     a:=(a and 1) xor 1;
     y:=0;
     redraw:=3;
    end;
    '1'..'9':begin
     a:=(a xor (1 shl (byte(c)-48)))and not 1;
     y:=0;
     redraw:=3;
    end;
    #0:case sc of
     $48:begin
      if y>0 then dec(y);
      redraw:=3;
     end;
     $50:begin
      if y<n-1 then inc(y);
      redraw:=3;
     end;
    end;
   end;
  until redraw>0;
 until redraw>3;
end;

end.