{*************************************************************************}
{                                                                         }
{ WaitUnit.pas - window for waiting for a user keyboard or joystick input }
{                                                                         }
{ This file is a part of the project:                                     }
{   Dizzy Quest Editor - the quest editor for Dizzy-like games            }
{                                                                         }
{ © Parfenov Alexey Andreevich, 2007                                      }
{                                                                         }
{ e-mail: AlkatrazStudio@yandex.ru                                        }
{                                                                         }
{ This program is free software; you can redistribute it and/or modify    }
{ it under the terms of the GNU General Public License as published by    }
{ the Free Software Foundation; either version 2 of the License, or       }
{ (at your option) any later version.                                     }
{                                                                         }
{ This program is distributed in the hope that it will be useful,         }
{ but WITHOUT ANY WARRANTY; without even the implied warranty of          }
{ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the            }
{ GNU General Public License for more details.                            }
{                                                                         }
{ You may read GNU General Public License at:                             }
{   http://www.gnu.org/copyleft/gpl.html                                  }
{                                                                         }
{*************************************************************************}
unit WaitUnit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, ExtCtrls,dqe2_types,math,alkatraz;

type
  TForm_Wait = class(TForm)
    BitBtn1: TBitBtn;
    Label1: TLabel;
    Timer1: TTimer;
    procedure Timer1Timer(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure DoWait(ForKey:boolean);
    procedure BitBtn1Click(Sender: TObject);
    procedure Localize;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form_Wait: TForm_Wait;
  res:integer;
  _Key:boolean;

implementation

uses MainUnit;

{$R *.dfm}

var lng:array of string;

procedure TForm_Wait.BitBtn1Click(Sender: TObject);
begin
  close;
end;

procedure TForm_Wait.DoWait(ForKey: boolean);
begin
  _key:=ForKey;res:=-1;
  if _key then
    Label1.Caption:=lng[0]
  else
    Label1.Caption:=lng[1];
  Timer1.Enabled:=true;
  ShowModal;
end;

procedure TForm_Wait.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  timer1.Enabled:=false;
end;

procedure TForm_Wait.FormCreate(Sender: TObject);
begin
  SetLength(lng,3);
end;

procedure TForm_Wait.Localize;
begin
  LoadStringsFromIni(MainUnit.lang_ini,Name,lng);
  BitBtn1.Caption:=lng[2];
end;

procedure TForm_Wait.Timer1Timer(Sender: TObject);
var
  a:integer;
begin
  if _key then
  begin
    for a:=8 to 255 do
      if World.KeyPressed[a] then
      begin
        res:=a;close;break;
      end;
  end
  else
  begin
    if world.JoyInfo.dwButtonNumber<>0 then
    begin
      for a:=0 to 31 do
        if (world.JoyInfo.wButtons and (1 shl a))<>0 then
          begin res:=a;close;break;end;
    end;
  end;
end;

end.
