{*************************************************************************}
{                                                                         }
{ EditSoundFileUnit.pas - window to select a sound file from 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 EditSoundFileUnit;

interface

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

type
  TForm_EditSoundFile = class(TForm)
    GroupBox1: TGroupBox;
    ListBox1: TListBox;
    SpeedButton1: TSpeedButton;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    SpeedButton2: TSpeedButton;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure ListBox1DblClick(Sender: TObject);
    procedure ShowIt(UsePlugins:boolean);
    procedure BitBtn2Click(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Localize;
  private
    { Private declarations }
  public
    { Public declarations }
    ok:boolean;
  end;

var
  Form_EditSoundFile: TForm_EditSoundFile;

implementation

uses MainUnit;

{$R *.dfm}

var lng:array of string;

procedure TForm_EditSoundFile.BitBtn2Click(Sender: TObject);
begin
  ok:=(ListBox1.ItemIndex>=0);close;
end;

procedure TForm_EditSoundFile.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  world.MusicPlayer.Music.Close;
end;

procedure TForm_EditSoundFile.FormCreate(Sender: TObject);
begin
  Form_Main_DQE.ImageList1.GetBitmap(39,SpeedButton2.Glyph);
  Form_Main_DQE.ImageList1.GetBitmap(40,SpeedButton1.Glyph);
  SetLength(lng,3);
end;

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

procedure TForm_EditSoundFile.ListBox1DblClick(Sender: TObject);
begin
  SpeedButton2.Click;
end;

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

procedure TForm_EditSoundFile.SpeedButton2Click(Sender: TObject);
begin
  if ListBox1.ItemIndex<>-1 then
  begin
    world.MusicPlayer.Music.Open(World.SharedDir+'\Music\'+ListBox1.Items[ListBox1.itemindex]);
    world.MusicPlayer.Music.Play;
  end;
end;

procedure TForm_EditSoundFile.ShowIt(UsePlugins: boolean);
var
  f:TSearchRec;
  a,n:integer;
begin
  ok:=false;ListBox1.Clear;
  if not UsePlugins then n:=GP_BASSEXTCOUNT-1 else
    n:=World.MusicPlayer.NumberOfExtensions-1;
  if FindFirst(World.SharedDir+'\Music\*.*',faAnyFile,f)=0 then
  repeat
    if (f.Attr and fadirectory)=0 then
      for a:=0 to n do
        if MatchesMask(f.Name,'*'+World.MusicPlayer.SupportedExtensions[a]) then
          begin ListBox1.AddItem(f.Name,nil);break;end;
  until FindNext(f)<>0;
  ShowModal;
end;

procedure TForm_EditSoundFile.SpeedButton1Click(Sender: TObject);
begin
  world.MusicPlayer.Music.Close;
end;

end.
