{*************************************************************************}
{                                                                         }
{ MainUnit.pas - main program window                                      }
{                                                                         }
{ This file is a part of the project:                                     }
{   Dizzy Quest Player 2 - player for *.dqe files, created in DQE2        }
{                                                                         }
{ © 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 MainUnit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs,dqe2_types, ExtCtrls, JvTimer, Menus, filesunit, StdCtrls,alkatraz,
  ImgList,shellapi, inifiles, FileCtrl;

const WM_OPENFILE=WM_USER;

type
  TForm_Main_DQP = class(TForm)
    Panel1: TPanel;
    _head: TImage;
    _left: TImage;
    _right: TImage;
    _bottom: TImage;
    MainMenu1: TMainMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    N3: TMenuItem;
    OpenDialog1: TOpenDialog;
    _energy: TImage;
    _top: TImage;
    N4: TMenuItem;
    N5: TMenuItem;
    N6: TMenuItem;
    N7: TMenuItem;
    N8: TMenuItem;
    N9: TMenuItem;
    Label_Zone: TLabel;
    Lifes: TImage;
    N10: TMenuItem;
    N11: TMenuItem;
    N12: TMenuItem;
    ImageList1: TImageList;
    N42: TMenuItem;
    N43: TMenuItem;
    N44: TMenuItem;
    N45: TMenuItem;
    SourceForge1: TMenuItem;
    N46: TMenuItem;
    Language1: TMenuItem;
    View1: TMenuItem;
    Hideskin1: TMenuItem;
    Hidedesktop1: TMenuItem;
    Gofullscreen1: TMenuItem;
    NSeparator: TMenuItem;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure N12Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure N11Click(Sender: TObject);
    procedure DoNewGame;
    procedure N9Click(Sender: TObject);
    procedure UpdatePlayer;
    procedure OnZoneChange(NewZone:DQE2_Zone);
    procedure N8Click(Sender: TObject);
    procedure N7Click(Sender: TObject);
    procedure N6Click(Sender: TObject);
    procedure N5Click(Sender: TObject);
    procedure N3Click(Sender: TObject);
    procedure OnEnergyChange;
    procedure OnLifesChange;
    procedure UpdateSkin;
    procedure N2Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure N43Click(Sender: TObject);
    procedure N44Click(Sender: TObject);
    procedure SourceForge1Click(Sender: TObject);
    procedure N46Click(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure LoadLanguages;
    procedure OnLocalizeClick(Sender:TObject);
    procedure UpdateINI(toini:boolean);
    procedure LocalizeAll(lang:string);
    procedure Localize;
    procedure OnVideoUpdate;
    procedure ChangeSkinVisible(v:boolean);
    procedure UpdateSize;
    procedure SetBack(v:boolean);
    procedure Hidedesktop1Click(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure SetFormOnTop(frm: TForm;ontop:boolean);
    procedure Hideskin1Click(Sender: TObject);
    procedure ShowMenu(doshow:boolean);
    procedure Gofullscreen1Click(Sender: TObject);
    procedure SetFullscreen(fs:boolean);
    procedure UpdateRecent;
    procedure OnItemClick(Sender: TObject);
    procedure LoadWorld(filename:string);
    procedure RecentAdd(FileName: string);
    procedure FormDestroy(Sender: TObject);
    procedure WMCopyData(var M: TWMCopyData); message WM_COPYDATA;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form_Main_DQP: TForm_Main_DQP;
  w,h:integer;
  life:TBitmap;
  maxlifes:integer;
  WorldFileName,WorldName:string;
  lang_ini:TIniFile;
  cur_lang,tmp_lang:string;
  mx,my:integer;
  RecentCount:integer;
  Recent:TStringList;
  infs:boolean;

implementation

uses Types, AboutUnit, OptionsUnit, WaitUnit, BackUnit;

{$R *.dfm}
{$R WindowsXP.res}

var lng:array of string;

procedure TForm_Main_DQP.UpdateRecent;
var
  a,n:integer;
  i:TMenuItem;
begin
  n:=Recent.Count;
  if(n>0)and(RecentCount>0) then
  begin
    while(n1.Count>(NSeparator.MenuIndex+1))do
      n1.Delete(n1.count-1);
    for a:=n-1 downto 0 do
      if not FileExists(Recent.Strings[a]) then
        Recent.Delete(a);
    n:=recent.Count;
    if n>0 then
    begin
      NSeparator.Visible:=true;
      for a:=0 to n-1 do
        if FileExists(Recent.Strings[a]) then
        begin
          i:=TMenuItem.Create(N1);
          Recent.Objects[a]:=i;
          N1.Add(i);
          i.Caption:=MinimizeName(Recent.Strings[a],Canvas,250);
          i.OnClick:=OnItemClick;
        end;
    end
    else
      NSeparator.Visible:=false;
  end;
  Recent.SaveToFile(AppPath+'\Recent.lst');
end;

procedure TForm_Main_DQP.OnItemClick(Sender: TObject);
var
  n:integer;
begin
  n:=TMenuItem(Sender).MenuIndex-NSeparator.MenuIndex-1;
  LoadWorld(Recent.Strings[n]);
end;

procedure TForm_Main_DQP.LoadWorld(filename: string);
begin
  if WorldFileName<>'' then
    if MessageDlgRus(lng[28],lng[29],MB_OKCANCEL)<>mrOk then
      exit;
  WorldFileName:=filename;
  DoNewGame;
  RecentAdd(filename);
end;

procedure TForm_Main_DQP.RecentAdd(FileName: string);
var
  n:integer;
begin
  if(RecentCount>0)and(ExtractFileName(FileName)<>'tempworld.tmp')then
  begin
    n:=Recent.IndexOf(Filename);
    if n>=0 then recent.Delete(n);
    while Recent.Count>=RecentCount do Recent.Delete(0);
    recent.Insert(0,Filename);
    UpdateRecent;
  end;
end;

procedure TForm_Main_DQP.ChangeSkinVisible(v: boolean);
begin
  _head.Visible:=v;
  _left.Visible:=v;
  _right.Visible:=v;
  _bottom.Visible:=v;
  _energy.Visible:=v;
  _top.Visible:=v;
  Lifes.Visible:=v;
end;

procedure TForm_Main_DQP.DoNewGame;
begin
  World.LoadFromFile(WorldFileName,false,true);
  if world.Player.Lifes=0 then world.Player.Lifes:=1;
  if world.Player.Energy=0 then world.Player.Energy:=1;
  UpdatePlayer;
  world.Play;
  N4.Enabled:=true;
end;

procedure TForm_Main_DQP.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  UpdateINI(true);
  World.Free;
end;

procedure TForm_Main_DQP.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
var
  x:TModalResult;
begin
  if WorldFileName='' then exit;
  x:=MessageDlgRus(lng[18],lng[19],MB_YESNOCANCEL or MB_ICONQUESTION);
  case x of
    mrCancel:CanClose:=false;
    mrYes:begin CanClose:=Form_Files.DoShow(true);end;
    mrNo:CanClose:=true;
  end;
end;

procedure TForm_Main_DQP.FormCreate(Sender: TObject);
var
  b:TBitmap;
begin
  SetCurrentDir(AppPath+'..\Shared\data\icons');
  b:=TBitmap.Create;
  b.LoadFromFile('options.bmp');ImageList1.AddMasked(b,$FF00FF);//0
  b.LoadFromFile('dizzy.bmp');ImageList1.AddMasked(b,$00FF00);//1
  b.LoadFromFile('save.bmp');ImageList1.AddMasked(b,$FF00FF);//2
  b.LoadFromFile('quit.bmp');ImageList1.AddMasked(b,$000000);//3
  b.LoadFromFile('open.bmp');ImageList1.AddMasked(b,$FF00FF);//4
  b.LoadFromFile('open_as_save.bmp');ImageList1.AddMasked(b,$FF00FF);//5
  b.LoadFromFile('mail.bmp');ImageList1.AddMasked(b,$FF00FF);//6
  b.LoadFromFile('about.bmp');ImageList1.AddMasked(b,$B4B3B5);//7
  b.LoadFromFile('bug.bmp');ImageList1.AddMasked(b,$C0C0C0);//8
  b.LoadFromFile('new.bmp');ImageList1.AddMasked(b,$FF00FF);//9
  b.LoadFromFile('home_site.bmp');ImageList1.AddMasked(b,$FF00FF);//10
  b.LoadFromFile('home_sf.bmp');ImageList1.AddMasked(b,$FF00FF);//11
  ImageList1.GetIcon(1,Form_Main_DQP.Icon);
  DQE2_World.Create(Panel1.Handle,false);
  SetLength(lng,30);
  WorldFileName:='';
  World.OnVideoUpdate:=OnVideoUpdate;
end;

procedure TForm_Main_DQP.FormDestroy(Sender: TObject);
begin
  Recent.Free;
end;

procedure TForm_Main_DQP.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Menu=nil then
    case key of
      VK_F11:begin SetBack(false);UpdateSize;end;
      VK_F10:Hideskin1.Click;
      VK_F6:N7.Click;
      VK_F9:N8.Click;
      //VK_F4:if ssAlt in shift then n3.Click;
      79:if ssCtrl in shift then n2.Click;
      VK_F12:
        if ssAlt in Shift then
          n12.Click
        else
          SetFullscreen(false);
      83:if ssCtrl in Shift then n5.Click;
      76:if ssctrl in shift then n6.Click;
      78:if ssCtrl in shift then n9.Click;
    end;
end;

procedure TForm_Main_DQP.FormShow(Sender: TObject);
var
  s:string;
begin
  UpdateINI(false);UpdateSize;
  LoadLanguages;
  ImageList1.GetIcon(7,Form_About.Icon);
  ImageList1.GetIcon(0,Form_Options.Icon);
  world.Player.Visible:=false;
  world.OnZoneChange:=OnZoneChange;
  world.Player.OnSlowEnergyChange:=OnEnergyChange;
  world.Player.OnLifesChange:=OnLifesChange;
  world.CurrentZone.Name:='Dizzy Quest Player v'+dqe2versionStr;
  life:=TBitmap.Create;
  UpdateSkin;
  //
  Recent:=TStringList.Create;
  recent.CaseSensitive:=false;
  s:=AppPath+'Recent.lst';
  if(FileExists(s))and(RecentCount>0)then Recent.LoadFromFile(s);
  UpdateRecent;
  if ParamCount>0 then
  begin
    LoadWorld(ParamStr(1));
  end
  else
  begin
    WorldFileName:='';
    UpdatePlayer;
  end;
  Form_Options.UpdateList;
  Form_Options.GroupBox7.Visible:=false;
  Form_Options.GroupBox5.Visible:=false;
  Form_Options.CheckBox10.Visible:=false;
end;

procedure TForm_Main_DQP.Gofullscreen1Click(Sender: TObject);
begin
  SetFullscreen(true);
end;

procedure TForm_Main_DQP.Hidedesktop1Click(Sender: TObject);
begin
  SetBack(true);
  UpdateSize;
end;

procedure TForm_Main_DQP.Hideskin1Click(Sender: TObject);
begin
  ChangeSkinVisible(Hideskin1.Checked);
  UpdateSize;
end;

procedure TForm_Main_DQP.LoadLanguages;
var
  ini:TIniFile;
  i,cur:TMenuItem;
  ch:array[0..1]of char;
  f:TSearchRec;
  _en:TmenuItem;
begin
  cur:=nil;_en:=nil;
  if FindFirst(AppPath+'..\Shared\Localization\dqe2.??.ini',faAnyFile,f)=0 then
  repeat
    ini:=TIniFile.Create(AppPath+'..\Shared\Localization\'+f.Name);
    i:=TMenuItem.Create(nil);
    i.Caption:=ini.ReadString('Info','Language','');
    ini.Free;
    ch[0]:=f.Name[6];ch[1]:=f.Name[7];
    CopyMemory(@w,@ch,2);
    i.Tag:=w;
    i.RadioItem:=true;
    i.OnClick:=OnLocalizeClick;
    Language1.Add(i);
    if ch='en' then
      _en:=i
    else
      if ch=tmp_lang then
        cur:=i;
  until FindNext(f)<>0;
  if cur=nil then OnLocalizeClick(_en) else OnLocalizeClick(cur);
end;

procedure TForm_Main_DQP.Localize;
begin
  LoadStringsFromIni(MainUnit.lang_ini,'_'+Name,lng);
  N1.Caption:=lng[1];
  N2.Caption:=lng[2];
  N12.Caption:=lng[3];
  N3.Caption:=lng[4];
  N4.Caption:=lng[5];
  N5.Caption:=lng[6];
  N6.Caption:=lng[7];
  N7.Caption:=lng[8];
  N8.Caption:=lng[9];
  N9.Caption:=lng[10];
  N10.Caption:=lng[11];
  N11.Caption:=lng[12];
  N42.Caption:=lng[13];
  N43.Caption:=lng[14];
  N44.Caption:=lng[15];
  SourceForge1.Caption:=lng[16];
  N46.Caption:=lng[17];
  OpenDialog1.Filter:=lng[22]+' (*.dqe)|*.dqe';
  OpenDialog1.Title:=lng[23];
  View1.Caption:=lng[24];
  Hideskin1.Caption:=lng[25];
  Hidedesktop1.Caption:=lng[26];
  Gofullscreen1.Caption:=lng[27];
end;

procedure TForm_Main_DQP.LocalizeAll(lang: string);
begin
  cur_lang:=lang;
  lang_ini:=TIniFile.Create(AppPath+'..\Shared\Localization\dqe2.'+cur_lang+'.ini');
  Form_About.Localize;
  Form_Main_DQP.Localize;
  Form_Options.Localize;
  Form_Files.Localize;
  Form_Wait.Localize;
end;

procedure TForm_Main_DQP.N11Click(Sender: TObject);
begin
  Form_About.ShowModal;
end;

procedure TForm_Main_DQP.N12Click(Sender: TObject);
begin
  Form_Options.SpinEdit2.Value:=RecentCount;
  if Form_Options.ShowIt then
    RecentCount:=Form_Options.SpinEdit2.Value;
end;

procedure TForm_Main_DQP.N2Click(Sender: TObject);
begin
  if OpenDialog1.Execute then
    LoadWorld(OpenDialog1.FileName);
end;

procedure TForm_Main_DQP.N3Click(Sender: TObject);
begin
  close;
end;

procedure TForm_Main_DQP.N43Click(Sender: TObject);
begin
  MailTo('AlkatrazStudio@yandex.ru','DQE2','');
end;

procedure TForm_Main_DQP.N44Click(Sender: TObject);
begin
  ShellExecute(0,'open','http://dqe.sourceforge.net/',nil,nil,SW_SHOWNORMAL);
end;

procedure TForm_Main_DQP.N46Click(Sender: TObject);
begin
  ShellExecute(0,'open','https://sourceforge.net/tracker2/?group_id=210117&atid=1012444',nil,nil,SW_SHOWNORMAL);
end;

procedure TForm_Main_DQP.N5Click(Sender: TObject);
begin
  Form_Files.DoShow(true);
end;

procedure TForm_Main_DQP.N6Click(Sender: TObject);
begin
  Form_Files.DoShow(false);
end;

procedure TForm_Main_DQP.N7Click(Sender: TObject);
begin
  Form_Files.SaveIt('QuickSave',false);
end;

procedure TForm_Main_DQP.N8Click(Sender: TObject);
var
  fn:string;
begin
  if WorldFileName='' then exit;
  fn:=world.SharedDir+'\..\Saves\'+WorldName+'.'+'QuickSave.dqe';
  if FileExists(fn)then
  begin
    if not World.CanSave then
    begin
      MessageDlgRus(Form_Files.lng[15],Form_Files.lng[16],MB_OK);
      exit;
    end;
    world.LoadFromFile(fn,true,true);
    UpdatePlayer;
    world.Play;
  end;
end;

procedure TForm_Main_DQP.N9Click(Sender: TObject);
begin
  if WorldFileName<>'' then
    if MessageDlgRus(lng[20],lng[21],MB_OKCANCEL or MB_ICONWARNING)=mrok then
      DoNewGame;
end;

procedure TForm_Main_DQP.OnEnergyChange;
begin
  _energy.Width:=trunc(w/World.Player.MaxEnergy*world.Player.SlowEnergy);
end;

procedure TForm_Main_DQP.OnLifesChange;
var
  n:integer;
begin
  if world.Player.Lifes>maxlifes then n:=maxlifes else n:=world.Player.Lifes;
  Lifes.Width:=n*life.Width;
  if world.Player.Lifes=0 then
    DoNewGame;
end;

procedure TForm_Main_DQP.OnLocalizeClick(Sender: TObject);
var
  w:word;
  ch:array[0..1]of char;
begin
  w:=TMenuItem(Sender).Tag;
  CopyMemory(@ch,@w,2);
  LocalizeAll(ch);
  TMenuItem(Sender).Checked:=true;
end;

procedure TForm_Main_DQP.OnVideoUpdate;
begin
  if infs=false then
  begin
    if(World.ScreenWidth<>640)or(world.ScreenHeight<>480)then
    begin
      ChangeSkinVisible(false);
      Hideskin1.Checked:=false;
      Hideskin1.Enabled:=false;
    end
    else
      Hideskin1.Enabled:=true;
      UpdateSize;
  end
  //else
    //SetFullscreen(true);
end;

procedure TForm_Main_DQP.OnZoneChange(NewZone: DQE2_Zone);
begin
  Label_Zone.Caption:=NewZone.Name;
end;

procedure TForm_Main_DQP.SetBack(v: boolean);
begin
  if v then
  begin
    ShowMenu(false);
    Form_Back.Visible:=true;
    SetFormOnTop(Form_Back,true);
    SetFormOnTop(Form_Main_DQP,true);
    cursor:=crNone;
  end
  else
  begin
    ShowMenu(true);
    SetFormOnTop(Form_Back,false);
    SetFormOnTop(Form_Main_DQP,false);
    Form_Back.Visible:=false;
    Cursor:=crDefault;
  end;
  Panel1.Cursor:=Cursor;
  _head.Cursor:=Cursor;
  _left.Cursor:=Cursor;
  _right.Cursor:=Cursor;
  _bottom.Cursor:=Cursor;
  _top.Cursor:=Cursor;
  _energy.Cursor:=Cursor;
  Lifes.Cursor:=Cursor;
end;

procedure TForm_Main_DQP.SetFormOnTop(frm: TForm;ontop:boolean);
begin
  with frm do
    if ontop then
      SetWindowPos(Handle,HWND_TOPMOST,Left,Top,Width,Height,
        SWP_NOACTIVATE or SWP_NOMOVE or SWP_NOSIZE)
    else
      SetWindowPos(Handle,HWND_NOTOPMOST,Left,Top,Width,Height,
        SWP_NOACTIVATE or SWP_NOMOVE or SWP_NOSIZE)
end;

procedure TForm_Main_DQP.SetFullscreen(fs: boolean);
var
  w,h:single;
begin
  infs:=fs;
  if fs then
  begin
    SetBack(true);
    ChangeSkinVisible(false);
    w:=Monitor.Width/world.ScreenWidth;
    h:=Monitor.Height/World.ScreenHeight;
    if w>h then
    begin
      // vertical
      ClientHeight:=Monitor.Height;
      ClientWidth:=trunc(world.ScreenWidth*h);
    end
    else
    begin
      // horizontal
      ClientWidth:=Monitor.Width;
      ClientHeight:=trunc(world.ScreenHeight*w);
    end;
    Top:=(Monitor.Height-ClientHeight)div 2;
    Left:=(Monitor.Width-ClientWidth)div 2;
    Panel1.Width:=ClientWidth;Panel1.Height:=ClientHeight;
    Panel1.Top:=0;Panel1.Left:=0;
  end
  else
  begin
    SetBack(false);
    ChangeSkinVisible(Hideskin1.Checked);
    UpdateSize;
    Top:=(Monitor.Height-ClientHeight)div 2;
    Left:=(Monitor.Width-ClientWidth)div 2;
  end;
  SetFocus;Activate;
end;

procedure TForm_Main_DQP.ShowMenu(doshow: boolean);
begin
  if doshow then
  begin
    Menu:=MainMenu1;
    BorderStyle:=bsSingle;
  end
  else
  begin
    Menu:=nil;
    BorderStyle:=bsNone;
  end;
end;

procedure TForm_Main_DQP.SourceForge1Click(Sender: TObject);
begin
  ShellExecute(0,'open','https://sourceforge.net/projects/dqe',nil,nil,SW_SHOWNORMAL);
end;

procedure TForm_Main_DQP.UpdateINI(toini: boolean);
begin
  if toini then
  begin
    world.INI.WriteString('Player.Localization','Language.ID',cur_lang);
    world.INI.WriteBool('Player.Common','View.ShowSkin',Hideskin1.Checked);
    world.INI.WriteInteger('Player.Options','FilesTabSheet.Recent',RecentCount);
  end
  else
  begin
    tmp_lang:=world.INI.ReadString('Player.Localization','Language.ID','en');
    ChangeSkinVisible(world.INI.ReadBool('Player.Common','View.ShowSkin',true));
    RecentCount:=world.INI.ReadInteger('Player.Options','FilesTabSheet.Recent',10);
    Hideskin1.Checked:=_head.Visible;
  end;
end;

procedure TForm_Main_DQP.UpdatePlayer;
var
  s:string;
begin
  UpdateSkin;OnLifesChange;OnEnergyChange;OnZoneChange(world.CurrentZone);
  WorldName:=ExtractFileNameOnly(WorldFileName);
  s:='';if WorldName<>'' then s:=s+WorldName+' - ';
  s:=s+'Dizzy Quest Player 2';
  Caption:=s;Application.Title:=s;
end;

procedure TForm_Main_DQP.UpdateSize;
begin
  if _head.Visible then
  begin
    ClientWidth:=World.ScreenWidth+_left.Width+_right.Width;
    ClientHeight:=world.ScreenHeight+_head.Height+_top.Height+_bottom.Height;
    Panel1.Left:=_left.Width;Panel1.Top:=_head.Height+_top.Height;
  end
  else
  begin
    ClientWidth:=World.ScreenWidth;ClientHeight:=world.ScreenHeight;
    Panel1.Left:=0;Panel1.Top:=0;
  end;
  Panel1.Width:=world.ScreenWidth;Panel1.Height:=world.ScreenHeight;
  if Form_Back.Visible then
  begin
    Left:=(Monitor.Width-ClientWidth)div 2;
    Top:=(Monitor.Height-ClientHeight)div 2;
  end;
  Activate;SetFocus;
end;

procedure TForm_Main_DQP.UpdateSkin;
var
  a:integer;
begin
  _top.Picture.LoadFromFile(world.SkinOptions.Top);
  _left.Picture.LoadFromFile(world.SkinOptions.Left);
  _right.Picture.LoadFromFile(world.SkinOptions.Right);
  _bottom.Picture.LoadFromFile(world.SkinOptions.Bottom);
  _head.Picture.LoadFromFile(world.SkinOptions.Head);
  _energy.Picture.LoadFromFile(world.SkinOptions.EnergySprite);
  _energy.Top:=world.SkinOptions.EnergyRect.Top;
  _energy.Left:=world.SkinOptions.EnergyRect.Left;
  w:=world.SkinOptions.EnergyRect.Right-world.SkinOptions.EnergyRect.Left;
  h:=world.SkinOptions.EnergyRect.Bottom-world.SkinOptions.EnergyRect.Top;
  _energy.Width:=w;_energy.Height:=h;
  Lifes.Top:=world.SkinOptions.LifesRect.Top;
  Lifes.Left:=world.SkinOptions.LifesRect.Left;
  Lifes.Width:=world.SkinOptions.LifesRect.Right-world.SkinOptions.LifesRect.Left;
  Lifes.Height:=world.SkinOptions.LifesRect.Bottom-world.SkinOptions.LifesRect.Top;
  Lifes.Picture.Bitmap.Width:=Lifes.Width;Lifes.Picture.Bitmap.Height:=Lifes.Height;
  life.LoadFromFile(world.SkinOptions.LifeSprite);
  maxlifes:=trunc(lifes.Width/life.Width);
  lifes.Height:=life.Height;lifes.Picture.Bitmap.Height:=life.height;
  for a:=1 to maxlifes do
    lifes.Canvas.CopyRect(rect((a-1)*life.Width,0,a*life.Width,life.Height),
                          life.Canvas,life.Canvas.ClipRect);
  lifes.Width:=0;_energy.Width:=0;Label_Zone.Caption:='';
  Label_Zone.Top:=world.SkinOptions.ZoneRect.Top;
  Label_Zone.Left:=world.SkinOptions.ZoneRect.Left;
  Label_Zone.Width:=world.SkinOptions.ZoneRect.Right-world.SkinOptions.ZoneRect.Left;
  Label_Zone.Height:=world.SkinOptions.ZoneRect.Bottom-world.SkinOptions.ZoneRect.Top;
end;

procedure TForm_Main_DQP.WMCopyData(var M: TWMCopyData);
begin
  LoadWorld(PAnsiChar(M.CopyDataStruct.lpData));
  M.Result:=1;
end;

end.
