unit config1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids,keyboard, StdCtrls, ComCtrls, config2,umklogger;

type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    UpDown1: TUpDown;
    UpDown2: TUpDown;
    UpDown3: TUpDown;
    UpDown4: TUpDown;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    ListBox1: TListBox;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    TrackBar1: TTrackBar;
    TrackBar2: TTrackBar;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure UpDown1Click(Sender: TObject; Button: TUDBtnType);
    procedure UpDown2Click(Sender: TObject; Button: TUDBtnType);
    procedure UpDown3Click(Sender: TObject; Button: TUDBtnType);
    procedure UpDown4Click(Sender: TObject; Button: TUDBtnType);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure ListBox1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation


var j1,j2,j3,j4:integer;
log:tmklogger;

{$R *.dfm}

procedure joy;
begin
        form1.Label5.Caption:=inttostr(j1);
        form1.Label6.Caption:=inttostr(j2);
        form1.Label7.Caption:=inttostr(j3);
        form1.Label8.Caption:=inttostr(j4);
end;

procedure readjez(nazwapliku:string);
var t:textfile;
l,k:string;
begin
assignfile(t,nazwapliku);
reset(t);
        readln(t,l);
repeat
   readln(t,l);
   log.wriln(l);
   if (length(l)>0) then begin
     case l[1] of
       'C': begin
///        {if pos('C',l)=1 then }begin
        delete(l,1,1);
        k:=copy(l,1,pos(':',l)-1);
      //  log.wriln(k);
        delete(l,1,pos(':',l));
     //   log.wriln(l);
        form1.stringgrid1.Cells[0,strtoint(k)]:=l;
        case strtoint(k) of
                6: form1.Label1.Caption:=l;
                7: form1.label2.caption:=l;
                8: form1.Label3.caption:=l;
                5: form1.Label4.caption:=l;
        end; //case
        end; //begin


     'K':begin
       // if pos('K',l)=1 then begin
        delete(l,1,1);
        k:=copy(l,1,pos(':',l)-1);
        delete(l,1,pos(':',l));
        case strtoint(k) of
                1:form1.Button2.caption:=l;
                2:form1.Button1.caption:=l;
                3:form1.Button3.caption:=l;
                4:config2.a1:=l;
                5:config2.a2:=l;
                10: form1.TabSheet1.Caption:=l;
                11: form1.TabSheet2.Caption:=l;
                12: begin
                        form1.label9.Caption:=l;
                        end;
                13:form1.label12.caption:=l;
                14:form1.label10.caption:=l;
                15:form1.label11.caption:=l;
        end; //case
        end; //bgin
        end; //case
        end;
until eof(t);
closefile(t);
end;

procedure readconf;
var t:textfile;
l,k:integer;
begin
assignfile(t,'joyst.bu');
reset(t);
readln(t,j1);
readln(t,j2);
readln(t,j3);
readln(t,j4);
readln(t,l);
form1.TrackBar1.Position:=l;
readln(t,l);
form1.TrackBar2.Position:=l;
form1.UpDown1.Position:=j1;
form1.UpDown2.Position:=j2;
form1.UpDown3.Position:=j3;
form1.UpDown4.Position:=j4;

l:=1;
repeat
        readln(t,k);
        form1.StringGrid1.Cells[1,l]:=VirtualKeycodetokeyname(k);
        inc(l);
until eof(t);
closefile(t);
joy;
end;

procedure TForm1.FormCreate(Sender: TObject);
var sr1: TSearchRec;
begin
log:=tmklogger.create('configlog.txt');
log.czysc;
log.wriln('configlog.txt');
FindFirst('*.jez',faAnyFile	, sr1);
repeat
listbox1.Items.add(sr1.Name);
until FindNext(sr1) <> 0;
readjez('English.jez');
readconf;
end;

procedure TForm1.UpDown1Click(Sender: TObject; Button: TUDBtnType);
begin
j1:=updown1.position;
joy;
end;

procedure TForm1.UpDown2Click(Sender: TObject; Button: TUDBtnType);
begin
j2:=updown2.position;joy;
end;

procedure TForm1.UpDown3Click(Sender: TObject; Button: TUDBtnType);
begin
j3:=updown3.position;    joy;
end;

procedure TForm1.UpDown4Click(Sender: TObject; Button: TUDBtnType);
begin
j4:=updown4.position;        joy;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
halt;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
form2.ShowModal;
if (config2.ret<>0) then
        stringgrid1.Cells[1,stringgrid1.Row]:=virtualkeycodetokeyname(ret);
end;

procedure TForm1.Button1Click(Sender: TObject);
var t:textfile;
i:integer;
begin
assignfile(t,'joyst.bu');
rewrite(t);
writeln(t,j1);
writeln(t,j2);
writeln(t,j3);
writeln(t,j4);
writeln(t,trackbar1.position);
writeln(t,trackbar2.position);
for i:=1 to 60 do
writeln(t,keynametovirtualkeycode(stringgrid1.cells[1,i]));
closefile(t);
end;

procedure TForm1.ListBox1Click(Sender: TObject);
begin
readjez(listbox1.Items[listbox1.ItemIndex]);
end;

end.
