{*************************************************************************}
{                                                                         }
{ ChooseUnit.pas - window to select one element from the list             }
{                                                                         }
{ 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 ChooseUnit;

interface

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

type
  TForm_Choose = class(TForm)
    GroupBox1: TGroupBox;
    Label1: TLabel;
    ComboBox1: TComboBox;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    function ShowIt(List:DQE2_List;DefaultIndex:integer=0):DQE2_Dummy;
    procedure BitBtn2Click(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Localize;
  private
    { Private declarations }
  public
    { Public declarations }
    ok:boolean;
  end;

var
  Form_Choose: TForm_Choose;

implementation

uses MainUnit;

{$R *.dfm}

var lng:array of string;

procedure TForm_Choose.BitBtn1Click(Sender: TObject);
begin
  ok:=true;close;
end;

procedure TForm_Choose.BitBtn2Click(Sender: TObject);
begin
  close;
end;

procedure TForm_Choose.FormCreate(Sender: TObject);
begin
  SetLength(lng,4);
end;

procedure TForm_Choose.Localize;
begin
  LoadStringsFromIni(MainUnit.lang_ini,Name,lng);
  Label1.Caption:=lng[2];
  BitBtn2.Caption:=lng[3];
end;

function TForm_Choose.ShowIt(List:DQE2_List;DefaultIndex:integer=0): DQE2_Dummy;
var
  a:integer;
begin
  caption:=Format(lng[0],[List.FriendlyClassName]);
  GroupBox1.Caption:=Format(lng[1],[List.FriendlyClassName]);
  ComboBox1.Clear;ok:=false;
  if list.Count>0 then
  begin
    for a:=0 to List.Count-1 do
      ComboBox1.Items.Add(DQE2_Dummy(List[a]).Name);
    ComboBox1.ItemIndex:=DefaultIndex;
    ShowModal;
    if ok then result:=DQE2_Dummy(List[ComboBox1.ItemIndex])
      else result:=nil;
  end
  else
    result:=nil;
end;

end.
