{*************************************************************************}
{                                                                         }
{ MainUnit.pas - main window for entire program management                }
{                                                                         }
{ 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 MainUnit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,ImgList, ExtCtrls,
  DQE2_TYPES,// Incredible SDK in 1 Unit !
  Menus, ComCtrls, Buttons, AsphyreFonts, AsphyreImages, AsphyreSubsc,
  AsphyreDevices, Asphyre2D, AsphyreCanvas, AsphyreTimers,AsphyreDef,
  ToolWin,inifiles,
  alkatraz,synedit,synmemo, SynEditHighlighter, SynHighlighterPas,SynEditTypes,
  filectrl,mmsystem,shellapi, JvExExtCtrls, JvSplitter, JvSyncSplitter,
  SynCompletionProposal,SynEditMiscClasses,stream_ex;

type
  TForm_Main_DQE = class(TForm)
    ImageList1: TImageList;
    ToolBar1: TToolBar;
    MainMenu1: TMainMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    N3: TMenuItem;
    N4: TMenuItem;
    N5: TMenuItem;
    N6: TMenuItem;
    N7: TMenuItem;
    C1: TMenuItem;
    N10: TMenuItem;
    SaveDialog1: TSaveDialog;
    N11: TMenuItem;
    N12: TMenuItem;
    N13: TMenuItem;
    Jnrhsnm: TMenuItem;
    OpenDialog1: TOpenDialog;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    ToolButton3: TToolButton;
    N9: TMenuItem;
    ToolButton4: TToolButton;
    ToolButton5: TToolButton;
    ToolButton6: TToolButton;
    ToolButton7: TToolButton;
    N14: TMenuItem;
    N15: TMenuItem;
    N16: TMenuItem;
    N17: TMenuItem;
    N18: TMenuItem;
    SynPas: TSynPasSyn;
    SynPopup: TPopupMenu;
    N19: TMenuItem;
    N20: TMenuItem;
    N21: TMenuItem;
    N22: TMenuItem;
    N23: TMenuItem;
    N24: TMenuItem;
    Zscr: TMenuItem;
    DScr: TMenuItem;
    N28: TMenuItem;
    DefZScr: TMenuItem;
    ToolButton8: TToolButton;
    N25: TMenuItem;
    N26: TMenuItem;
    N27: TMenuItem;
    N30: TMenuItem;
    N31: TMenuItem;
    N32: TMenuItem;
    N33: TMenuItem;
    NSeparator: TMenuItem;
    N34: TMenuItem;
    N35: TMenuItem;
    N36: TMenuItem;
    N37: TMenuItem;
    N38: TMenuItem;
    N39: TMenuItem;
    N40: TMenuItem;
    N41: TMenuItem;
    N42: TMenuItem;
    SourceForge1: TMenuItem;
    N8: TMenuItem;
    N43: TMenuItem;
    N45: TMenuItem;
    DefDScr: TMenuItem;
    EScr: TMenuItem;
    DefEScr: TMenuItem;
    Entities1: TMenuItem;
    procedure N21Click(Sender: TObject);
    procedure N20Click(Sender: TObject);
    procedure N19Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure N42Click(Sender: TObject);
    procedure N40Click(Sender: TObject);
    procedure N39Click(Sender: TObject);
    procedure N38Click(Sender: TObject);
    procedure N41Click(Sender: TObject);
    procedure N36Click(Sender: TObject);
    procedure N35Click(Sender: TObject);
    procedure OnItemClick(Sender:TObject);
    procedure SaveWorld(FileName:string);
    procedure RecentAdd(FileName:string);
    procedure UpdateRecent;
    procedure N33Click(Sender: TObject);
    function AskRewrite:boolean;
    procedure LoadWorld(Filename:String;AsSave:boolean);
    procedure FormShow(Sender: TObject);
    procedure N32Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure N31Click(Sender: TObject);
    procedure N30Click(Sender: TObject);
    procedure N27Click(Sender: TObject);
    procedure N25Click(Sender: TObject);
    procedure LoadDefaultTemplate(Category:integer;var OutString:String);
    procedure LoadTemplate(FileName:string;var OutString:String);
    function SetDefaultTemplate(CatID:Integer;TemplateName:string):boolean;
    function GetDefaultTemplate(CatID:Integer):string;
    procedure SynPopupPopup(Sender: TObject);
    procedure OnSynTemplateClick(Sender:TObject);
    procedure OnSynDefaultTemplateClick(Sender:TObject);
    procedure LoadTemplates;
    procedure SetupSynEditor(y:TSynMemo);
    procedure N9Click(Sender: TObject);
    procedure N18Click(Sender: TObject);
    procedure ShowErrorPlace(Sender:DQE2_Scriptable;SynMemo:TSynMemo);
    procedure ShowErrors(Sender:DQE2_Scriptable;SynMemo:TSynMemo;ListBox:TListBox);
    procedure OnSynGutterClick(Sender:TObject;Button:TMouseButton;X,Y,Line:Integer;Mark:TSynEditMark);
    procedure SynUpdateScript(SynMemo:TSynMemo;Script:DQE2_Scriptable);
    procedure SynUpdateGutter(SynMemo:TSynMemo;Script:DQE2_Scriptable);
    procedure OnStateChange(NewState:DQE2_WorldState);
    procedure N17Click(Sender: TObject);
    procedure N16Click(Sender: TObject);
    procedure N15Click(Sender: TObject);
    procedure UpdateAllForms;
    procedure JnrhsnmClick(Sender: TObject);
    procedure N13Click(Sender: TObject);
    procedure N12Click(Sender: TObject);
    procedure N4Click(Sender: TObject);
    procedure N5Click(Sender: TObject);
    procedure N7Click(Sender: TObject);
    procedure N10Click(Sender: TObject);
    procedure C1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure N11Click(Sender: TObject);
    procedure SourceForge1Click(Sender: TObject);
    procedure N43Click(Sender: TObject);
    procedure UpdateCaption;
    procedure LocalizeAll(lang:string);
    procedure OnLocalizeClick(Sender:TObject);
    procedure Localize;
    procedure LoadLanguages;
    procedure N28Click(Sender: TObject);
    procedure UpdateObjectsForm;
    procedure Entities1Click(Sender: TObject);
    procedure WMCopyData(var M: TWMCopyData); message WM_COPYDATA;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form_Main_DQE: TForm_Main_DQE;
  CurFileName:string='';
  Recent:TStringList;
  RecentCount,BackupCount:Integer;
  DoOpenLast:boolean;
  DoSaveBPW:boolean;
  lang_ini:TIniFile;
  cur_lang,tmp_lang:string;
  DefTZ,DefTD,DefTE:string;
  DefSharedDir:string;

const TemplatePaths:array[1..3]of string=('ZoneScripts','DialogScripts','EntityScripts');

implementation

uses GameUnit, ScriptUnit, ZoneUnit, ObjectUnit, DialogUnit, MusicUnit,
  ItemUnit, GameSettingsUnit,FontUnit, AboutUnit, VarUnit, OptionsUnit,
  RollbackUnit, ChooseUnit, EditAnswerUnit, EditBlendUnit, EditDefaultsUnit,
  EditIconUnit, EditPhraseUnit, EditSoundFileUnit, WaitUnit, DebugUnit,
  EntityUnit;

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

var lng:array of string;

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

procedure TForm_Main_DQE.N41Click(Sender: TObject);
var
  HelpFile:string;
begin
  HelpFile:=ExpandFileName(AppPath+'..\doc\Index.html');
  if FileExists(HelpFile)then
    ShellExecute(0,'open',PAnsiChar(HelpFile),nil,nil,SW_SHOWNORMAL)
  else
    MessageDlgRus(lng[44],lng[45]+#13#10+HelpFile,MB_OK or MB_ICONERROR);
end;

procedure TForm_Main_DQE.N42Click(Sender: TObject);
begin
  Form_Objects.Show;
end;

procedure TForm_Main_DQE.N43Click(Sender: TObject);
begin
  Form_Rollback.ShowIt(CurFileName);
end;

procedure TForm_Main_DQE.N4Click(Sender: TObject);
begin
  form_scripts.Show;
end;

procedure TForm_Main_DQE.N5Click(Sender: TObject);
begin
  Form_zones.Show;
end;

procedure TForm_Main_DQE.N7Click(Sender: TObject);
begin
  Form_Game.Visible:=n7.Checked;
end;

procedure TForm_Main_DQE.N9Click(Sender: TObject);
begin
  if MessageDlgRus(lng[46],lng[47]+#13#10+lng[48],
  MB_ICONWARNING or MB_OKCANCEL)=mrok then
  begin
    world.Clear(true);
    CurFileName:='';
    UpdateCaption;
    if AnsiStrIComp(PAnsiChar(World.SharedDir),PAnsiChar(DefSharedDir))<>0 then
      if MessageDlgRus(lng[66],lng[67],MB_ICONQUESTION or MB_YESNO)<>mrNo then
      begin
        World.SharedDir:=DefSharedDir;
        World.Sprites.Clear;
        World.LoadSprites(true);
        UpdateObjectsForm;
        World.Player.Sprite:=DQE2_Sprite(world.Sprites.FindByName('Objects\Dizzy\dizzy.gif'));
        if not World.Player.Sprite.Loaded then World.Player.Sprite.Load;
      end;
    UpdateAllForms;
    world.Player.MoveToZone(world.CurrentZone,0,0);
  end;
end;


procedure TForm_Main_DQE.OnItemClick(Sender: TObject);
var
  n:integer;
begin
  n:=TMenuItem(Sender).MenuIndex-NSeparator.MenuIndex-1;
  if AskRewrite then
    LoadWorld(Recent.Strings[n],false);
end;

procedure TForm_Main_DQE.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_DQE.OnStateChange(NewState:DQE2_WorldState);
begin
  case NewState of
    wsPlay:
    begin
      ToolButton5.Down:=true;
      n3.Enabled:=false;
      if Form_Zones.Visible then Form_Zones.Hide;
      if Form_Items.Visible then Form_Items.Hide;
      if Form_Music.Visible then Form_Music.Hide;
      if Form_Dialogs.Visible then Form_Dialogs.Hide;
      if Form_Scripts.Visible then Form_Scripts.Hide;
      if Form_Fonts.Visible then Form_Fonts.Hide;
      if Form_Zones.Visible then Form_Zones.Hide;
      if Form_Entities.Visible then Form_Entities.Hide;
    end;
    wsPause:
    begin
      ToolButton6.Down:=true;
      n3.Enabled:=true;
      Form_Objects.Enabled:=true;
    end;
    wsStop:
    begin
      ToolButton7.Down:=true;
      n3.Enabled:=true;
      Form_Objects.Enabled:=true;
    end;
  end;
end;

procedure TForm_Main_DQE.OnSynDefaultTemplateClick(Sender: TObject);
var
  capt:string;
begin
  capt:=StringReplace((Sender as TMenuItem).Caption,'&','',[]);
  if SetDefaultTemplate(SynPopup.Tag,capt) then
    (Sender as TMenuItem).Checked:=true;
end;

procedure TForm_Main_DQE.OnSynGutterClick(Sender: TObject; Button: TMouseButton; X,
  Y, Line: Integer; Mark: TSynEditMark);
var
  syn:TSynMemo;
  m:TSynEditMark;
  marks:TSynEditLineMarks;
begin
  syn:=TSynMemo(Sender);
  syn.marks.GetMarksForLine(Line,marks);
  if marks[0]=nil then
  begin
    m:=TSynEditMark.Create;
    m.Line:=Line;
    m.Visible:=true;
    m.ImageIndex:=42;
    m.InternalImage:=false;
    syn.Marks.Add(m);
  end
  else
    syn.Marks.ClearLine(Line);
end;

procedure TForm_Main_DQE.OnSynTemplateClick(Sender: TObject);
var
  i:TMenuItem;
  s,s1,capt:string;
begin
  i:=TMenuItem(Sender);s:=world.SharedDir+'\Templates\';
  s:=s+TemplatePaths[SynPopup.Tag];
  capt:=StringReplace(i.Caption,'&','',[]);
  s:=s+'\'+capt+'.txt';
  if MessageDlgRus(lng[50],lng[51]+#13#10+capt,MB_OKCANCEL or MB_ICONWARNING)=mrOk then
  begin
    LoadTemplate(s,s1);
    TSynMemo(SynPopup.PopupComponent).Text:=s1;
  end;
end;

procedure TForm_Main_DQE.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_DQE.SaveWorld(FileName: string);
var
  f:TSearchRec;
  d,n,ext:string;
  ff:TStringList;
  num:integer;
const
  bf='\_backup\';

  procedure SaveInfo;
  var
    a,b,n:integer;
    x:TFileStreamEx;
    s:string;
  begin
    s:=FileName+'.bpw';
    if DoSaveBPW=false then
      begin DeleteFile(s);exit;end;
    x:=TFileStreamEx.Create(FileName+'.bpw',fmCreate);
    for a:=0 to World.Scripts.Count-1 do
    begin
      n:=DQE2_Script(World.Scripts[a]).BreakpointsCount;
      x.WriteInteger(n);
      for b:=0 to n-1 do
        x.WriteInteger(dqe2_script(World.Scripts[a]).Breakpoints[b]);
    end;
    for a:=0 to World.Dialogs.Count-1 do
    begin
      n:=DQE2_Dialog(World.Dialogs[a]).BreakpointsCount;
      x.WriteInteger(n);
      for b:=0 to n-1 do
        x.WriteInteger(DQE2_Dialog(World.Scripts[a]).Breakpoints[b]);
    end;
    for a:=0 to World.EntityTypes.Count-1 do
    begin
      n:=DQE2_EntityType(World.EntityTypes[a]).BreakpointsCount;
      x.WriteInteger(n);
      for b:=0 to n-1 do
        x.WriteInteger(DQE2_EntityType(World.EntityTypes[a]).Breakpoints[b]);
    end;
    n:=Form_Debug.TheWatches.Items.Count;
    x.WriteInteger(n);
    for a:=0 to n-1 do
      x.WriteString(Form_Debug.TheWatches.Items[a].Caption);
    x.Free;
  end;

begin
  if BackupCount>0 then
  begin
    d:=ExtractFileDir(FileName);
    n:=ExtractFileName(FileName);
    ff:=TStringList.Create;ff.CaseSensitive:=false;
    if FindFirst(d+bf+n+'.~???',faAnyFile,f)=0 then
    repeat
      ff.Add(d+bf+f.Name);
    until FindNext(f)<>0;
    FindClose(f);
    ff.Sort;
    while(ff.Count>=BackupCount)do
    begin
      DeleteFile(ff.Strings[0]);
      ff.Delete(0);
    end;
    if ff.Count>0 then
    begin
      ext:=ExtractFileExt(ff.Strings[ff.Count-1]);
      num:=strtoint(copy(ext,3,length(ext)-2))+1;
    end
    else
      num:=1;
    n:=n+'.~'+IntToStrFixed(num,3);
    world.SaveToFile(d+bf+n);
    CopyFile(PAnsiChar(d+bf+n),PAnsiChar(FileName),false);
  end
  else
    world.SaveToFile(FileName);
  SaveInfo;
  CurFileName:=FileName;
  UpdateCaption;
  RecentAdd(FileName);
end;

function TForm_Main_DQE.SetDefaultTemplate(CatID:Integer;TemplateName:string): boolean;
var
  f:TextFile;
begin
  result:=false;
  try AssignFile(f,AppPath+'..\Shared\Templates\'+TemplatePaths[CatID]+'\Default.ini');except exit;end;
  try Rewrite(f);except CloseFile(f);exit;end;
  try WriteLn(f,TemplateName);except CloseFile(f);exit;end;
  try CloseFile(f);except exit;end;
  case CatID of
    1:DefTZ:=TemplateName;
    2:DefTD:=TemplateName;
    3:DefTE:=TemplateName;
    else exit;
  end;
  result:=true;
end;

procedure TForm_Main_DQE.SetupSynEditor(y:TSynMemo);
var
  x:TSynMemo;
begin
  x:=Form_Scripts.SynMemo1;
  y.Color:=x.Color;
  y.Ctl3D:=x.Ctl3D;
  y.ActiveLineColor:=x.ActiveLineColor;
  y.TabStop:=x.TabStop;
  y.BookMarkOptions.Assign(x.BookMarkOptions);
  y.Gutter.Assign(x.Gutter);
  y.Highlighter:=x.Highlighter;
  y.Options:=x.Options;
  y.TabWidth:=x.TabWidth;
  y.WantReturns:=x.WantReturns;
  y.WantTabs:=x.WantTabs;
  y.ParentCtl3D:=x.ParentCtl3D;
end;

procedure TForm_Main_DQE.ShowErrorPlace(Sender:DQE2_Scriptable;SynMemo:TSynMemo);
var
  a,n,s:integer;
  t:char;
  p:TBufferCoord;
begin
  //if Sender.LastError.IsSyntaxError then
  //begin
    p.Char:=Sender.LastError.Row;p.Line:=Sender.LastError.Line;
    s:=SynMemo.RowColToCharIndex(p)+1;
    a:=s;n:=Length(SynMemo.Text);
      while a<n do
      begin
        dec(a);if(a<1)then break;
        t:=SynMemo.Text[a];
        if((t<'a')or(t>'z'))and((t<'A')or(t>'Z'))and((t<'0')or(t>'9'))and(t<>'_')then break;
      end;
      if a>s then dec(a);
      SynMemo.SelStart:=a;
      if Sender.LastError.IsSyntaxError then
        SynMemo.SelLength:=s-a;
  //end
  //else SynMemo.SelLength:=0;
  SynMemo.SetFocus;
end;

procedure TForm_Main_DQE.ShowErrors(Sender:DQE2_Scriptable;SynMemo:TSynMemo;ListBox:TListBox);
begin
  ListBox.Clear;
  if Sender.LastError.IsError then
    ListBox.AddItem('[Error '+
      IntToStr(Sender.LastError.MsgID)+
      ' at '+IntToStr(Sender.LastError.Line)+':'+IntToStr(sender.LastError.Row)+
      '] '+Sender.LastError.Text,nil);
  //else
  //  ListBox.AddItem('0 OK 0:1',nil);
  ShowErrorPlace(Sender,SynMemo);
end;

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

procedure TForm_Main_DQE.SynPopupPopup(Sender: TObject);
var
  i:integer;
  x:TComponent;
begin
  x:=TPopupMenu(Sender).PopupComponent;
  if x=nil then exit;
  i:=TSynMemo(x).Tag;
  SynPopup.Tag:=i;
  Zscr.Visible:=false;
  Dscr.Visible:=false;
  Escr.Visible:=false;
  DefZscr.Visible:=false;
  DefDscr.Visible:=false;
  DefEscr.Visible:=false;
  case i of
    1:begin Zscr.Visible:=true;DefZscr.Visible:=true;end;
    2:begin DScr.Visible:=true;DefDscr.Visible:=true;end;
    3:begin EScr.Visible:=true;DefEscr.Visible:=true;end;
  end;
end;

procedure TForm_Main_DQE.SynUpdateGutter(SynMemo: TSynMemo;
  Script: DQE2_Scriptable);
var
  a:integer;
  m:TSynEditMark;
begin
  SynMemo.Marks.Clear;
  for a:=0 to Script.BreakpointsCount-1 do
  begin
    m:=TSynEditMark.Create;
    m.Line:=Script.Breakpoints[a];
    m.ImageIndex:=42;
    m.Visible:=true;
    m.InternalImage:=false;
    SynMemo.Marks.Add(m);
  end;
end;

procedure TForm_Main_DQE.SynUpdateScript(SynMemo: TSynMemo;
  Script: DQE2_Scriptable);
var
  a:integer;
begin
  Script.ClearBreakpoints;
  for a:=0 to SynMemo.Marks.Count-1 do
    Script.AddBreakpoint(SynMemo.Marks[a].Line);
end;

procedure TForm_Main_DQE.UpdateAllForms;
begin
  Form_Objects.UpdateZoneList;
  Form_Items.UpdateList;
  Form_Music.UpdateMusicView;
  Form_Music.UpdateSoundView;
  Form_Dialogs.UpdateList;
  Form_Scripts.UpdateList;
  Form_Zones.UpdateList;
  Form_Fonts.UpdateList;
  Form_Options.UpdateList;
  Form_GameSettings.UpdateForm;
  Form_Vars.UpdateList;
  Form_Entities.UpdateList;
  N35.Checked:=World.Player.Visible;
  N36.Checked:=World.Player.Control;
  N7.Checked:=Form_Game.Visible;
  Form_Objects.ComboBox4Change(nil);
  Form_Objects.CheckBox1Click(nil);
  Form_Game.OnZoneChange(World.CurrentZone);
end;

procedure TForm_Main_DQE.UpdateCaption;
begin
  if CurFileName<>'' then
    Caption:=ExtractFileNameOnly(CurFileName)+' - Dizzy Quest Editor 2'
  else
    Caption:=lng[49]+' - Dizzy Quest Editor 2';
end;

procedure TForm_Main_DQE.UpdateObjectsForm;
begin
  Form_Objects.ComboBox3.Items.Clear;
  Form_Objects.ComboBox3.Items.AddStrings(world.ImageList);
  if Form_Objects.ComboBox3.Items.Count>0 then
    Form_Objects.ComboBox3.ItemIndex:=0
  else
    Form_Objects.ComboBox3.ItemIndex:=-1;
  Form_Objects.ComboBox3Change(nil);
end;

procedure TForm_Main_DQE.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_DQE.WMCopyData(var M: TWMCopyData);
begin
  if AskRewrite then
    LoadWorld(PAnsiChar(M.CopyDataStruct.lpData),false);
  M.Result:=1;
end;

procedure TForm_Main_DQE.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  if not AskRewrite then
  begin
    Action:=caNone;
  end
  else
  begin
    Action:=caFree;
    Form_Fonts.Timer1.Enabled:=false;
    World.Stop;
    Form_Game.UpdateINI(true);
    world.Free;
    lang_ini.Free;
  end;
end;

procedure TForm_Main_DQE.FormCreate(Sender: TObject);
var
  b:TBitmap;
begin
  SetCurrentDir(AppPath+'..\Shared\data\icons');
  b:=TBitmap.Create;
  b.LoadFromFile('new.bmp');ImageList1.AddMasked(b,$FF00FF);//0
  b.LoadFromFile('open.bmp');ImageList1.AddMasked(b,$FF00FF);//1
  b.LoadFromFile('open_as_save.bmp');ImageList1.AddMasked(b,$FF00FF);//2
  b.LoadFromFile('save.bmp');ImageList1.AddMasked(b,$FF00FF);//3
  b.LoadFromFile('save_as.bmp');ImageList1.AddMasked(b,$FF00FF);//4
  b.LoadFromFile('editor_parameters.bmp');ImageList1.AddMasked(b,$FE00FE);//5
  b.LoadFromFile('editor_scripts.bmp');ImageList1.AddMasked(b,$FF00FF);//6
  b.LoadFromFile('delete.bmp');ImageList1.AddMasked(b,$FF00FF);//7
  b.LoadFromFile('copy.bmp');ImageList1.AddMasked(b,$FF00FF);//8
  b.LoadFromFile('cut.bmp');ImageList1.AddMasked(b,$FF00FF);//9
  b.LoadFromFile('paste.bmp');ImageList1.AddMasked(b,$FF00FF);//10
  b.LoadFromFile('pause.bmp');ImageList1.AddMasked(b,$FF00FF);//11
  b.LoadFromFile('play.bmp');ImageList1.AddMasked(b,$FF00FF);//12
  b.LoadFromFile('stop.bmp');ImageList1.AddMasked(b,$FF00FF);//13
  b.LoadFromFile('editor_music.bmp');ImageList1.AddMasked(b,$FF00FF);//14
  b.LoadFromFile('keyboard.bmp');ImageList1.AddMasked(b,$808000);//15
  b.LoadFromFile('dizzy.bmp');ImageList1.AddMasked(b,$00FF00);//16
  b.LoadFromFile('history.bmp');ImageList1.AddMasked(b,$FF00FF);//17
  b.LoadFromFile('mail.bmp');ImageList1.AddMasked(b,$FF00FF);//18
  b.LoadFromFile('home_sf.bmp');ImageList1.AddMasked(b,$FF00FF); //19
  b.LoadFromFile('home_site.bmp');ImageList1.AddMasked(b,$FF00FF);//20
  b.LoadFromFile('help.bmp');ImageList1.AddMasked(b,$F2EAE4);//21
  b.LoadFromFile('about.bmp');ImageList1.AddMasked(b,$B4B3B5);//22
  b.LoadFromFile('editor_dialogs.bmp');ImageList1.AddMasked(b,$FFFFFF);//23
  b.LoadFromFile('editor_vars.bmp');ImageList1.AddMasked(b,$C0C0C0);//24
  b.LoadFromFile('editor_objects.bmp');ImageList1.AddMasked(b,$FFFFFF);//25
  b.LoadFromFile('editor_items.bmp');ImageList1.AddMasked(b,$FFFFFF);//26
  b.LoadFromFile('options.bmp');ImageList1.AddMasked(b,$FF00FF);//27
  b.LoadFromFile('build.bmp');ImageList1.AddMasked(b,$12ADF5);//28
  b.LoadFromFile('quit.bmp');ImageList1.AddMasked(b,$000000);//29
  b.LoadFromFile('editor_fonts.bmp');ImageList1.AddMasked(b,$000000);//30
  b.LoadFromFile('editor_zones.bmp');ImageList1.AddMasked(b,$000000);//31
  b.LoadFromFile('bug.bmp');ImageList1.AddMasked(b,$C0C0C0);//32
  b.LoadFromFile('dizzy.bmp');ImageList1.AddMasked(b,$00FF00);//33
  b.LoadFromFile('editor_preview.bmp');ImageList1.AddMasked(b,$000000);//34
  b.LoadFromFile('up.bmp');ImageList1.AddMasked(b,$FFFFFF);//35
  b.LoadFromFile('down.bmp');ImageList1.AddMasked(b,$FFFFFF);//36
  b.LoadFromFile('environment.bmp');ImageList1.AddMasked(b,$FFFFFF);//37
  b.LoadFromFile('gameplayer.bmp');ImageList1.AddMasked(b,$FFFFFF);//38
  b.LoadFromFile('music_play.bmp');ImageList1.AddMasked(b,$000000);//39
  b.LoadFromFile('music_stop.bmp');ImageList1.AddMasked(b,$000000);//40
  b.LoadFromFile('rollback.bmp');ImageList1.AddMasked(b,$FF00FF);//41
  b.LoadFromFile('breakpoint.bmp');ImageList1.AddMasked(b,$000000);//42
  b.LoadFromFile('debug_stop.bmp');ImageList1.AddMasked(b,$00FF00);//43
  b.LoadFromFile('add.bmp');ImageList1.AddMasked(b,$FF0000);//44
  b.LoadFromFile('remove.bmp');ImageList1.AddMasked(b,$0000FF);//45
  b.LoadFromFile('edit.bmp');ImageList1.AddMasked(b,$000000);//46
  b.LoadFromFile('refresh.bmp');ImageList1.AddMasked(b,$FF0000);//47
  b.LoadFromFile('debug_step.bmp');ImageList1.AddMasked(b,$00FF00);//48
  b.LoadFromFile('editor_entities.bmp');ImageList1.AddMasked(b,$000000);//49
  b.Free;
  SetLength(lng,72);
  CurFileName:='';
  DefSharedDir:=ExpandFileName(AppPath+'..\Shared');
end;

procedure TForm_Main_DQE.FormShow(Sender: TObject);
var
  s:string;
begin
  Form_Game.UpdateINI(false);
  LoadLanguages;
  Form_Main_DQE.LoadTemplates;
  UpdateAllForms;
  Recent:=TStringList.Create;
  recent.CaseSensitive:=false;
  s:=AppPath+'Recent.lst';
  if RecentCount=0 then
    if DoOpenLast then
      RecentCount:=1;
  if(FileExists(s))and(RecentCount>0)then Recent.LoadFromFile(s);
  UpdateRecent;
  UpdateCaption;
  ImageList1.GetIcon(33,Form_Main_DQE.Icon);
  ImageList1.GetIcon(34,Form_Game.Icon);
  ImageList1.GetIcon(27,Form_Options.Icon);
  ImageList1.GetIcon(24,Form_Vars.Icon);
  ImageList1.GetIcon(22,Form_About.Icon);
  ImageList1.GetIcon(30,Form_Fonts.Icon);
  ImageList1.GetIcon(5,Form_GameSettings.Icon);
  ImageList1.GetIcon(26,Form_Items.Icon);
  ImageList1.GetIcon(14,Form_Music.Icon);
  ImageList1.GetIcon(23,Form_Dialogs.Icon);
  ImageList1.GetIcon(25,Form_Objects.Icon);
  ImageList1.GetIcon(31,Form_Zones.Icon);
  ImageList1.GetIcon(6,Form_Scripts.Icon);
  ImageList1.GetIcon(49,Form_Entities.Icon);
  SetupSynEditor(Form_Debug.SynMemo1);
  SetupSynEditor(Form_Dialogs.SynMemo1);
  SetupSynEditor(Form_Entities.SynMemo1);
  ShowWindow(Application.Handle,SW_SHOW);
  if DoOpenLast then
    if Recent.Count>0 then
      LoadWorld(Recent.Strings[0],false);
  //Form_Help.LoadMainSyntax;
  (*SynCompletition.AddEditor(Form_Scripts.SynMemo1);
  SynCompletition.AddEditor(Form_Dialogs.SynMemo1);
  SynCompletition.AddEditor(Form_Help.SynEdit1);
  //SynCompletition.Editor:=Form_Scripts.SynMemo1;
    SynCompletition.ItemList.Add('constructor \column{}\style{+B}Create\style{-B}(Param:Type)');
  SynCompletition.InsertList.add('create');*)
end;

function TForm_Main_DQE.GetDefaultTemplate(CatID:Integer): string;
var
  f:TextFile;
begin
  result:='';
  try AssignFile(f,AppPath+'..\Shared\Templates\'+TemplatePaths[CatID]+'\Default.ini');except exit;end;
  try Reset(f);except exit;end;
  try Readln(f,result);except CloseFile(f);exit;end;
  try CloseFile(f);except end;
end;

procedure TForm_Main_DQE.JnrhsnmClick(Sender: TObject);
begin
  if AskRewrite then
    if OpenDialog1.Execute then
      LoadWorld(OpenDialog1.FileName,false);
end;

procedure TForm_Main_DQE.LoadDefaultTemplate(Category: integer;var OutString:String);
var
  s:string;
begin
  case Category of
    1:s:=DefTZ;
    2:s:=DefTD;
    3:s:=DefTE;
    else exit;
  end;
  LoadTemplate(world.SharedDir+'\Templates\'+TemplatePaths[Category]+'\'+s+'.txt',OutString);
end;

procedure TForm_Main_DQE.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;
    N45.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_DQE.LoadTemplate(FileName: string;var OutString:String);
var
  f:TextFile;
  s:string;
begin
  try AssignFile(f,FileName);except exit;end;
  try Reset(f);except exit;end;
  OutString:='';
  try
    while not eof(f) do
    begin
      Readln(f,s);
      OutString:=OutString+s+#13#10;
    end;
  except CloseFile(f);exit;end;
  try CloseFile(f);except end;
end;

procedure TForm_Main_DQE.LoadTemplates;

  procedure AddItems(Category:Integer;Item:TMenuItem;Radio:string);
  var
    s:TStringList;
    a:integer;
    i:TMenuItem;
  begin
    s:=TStringList.Create;
    GetFilesInDir(s,AppPath+'..\Shared\Templates\'+TemplatePaths[Category],'*.txt');
    Item.Clear;
    if s.Count>0 then
      for a:=0 to s.Count-1 do
      begin
        i:=TMenuItem.Create(Item);
        Item.Add(i);
        i.Caption:=ExtractFileNameOnly(s.Strings[a]);
        if radio<>'' then
        begin
          i.RadioItem:=true;
          if i.Caption=Radio then
            i.Checked:=true;
          i.OnClick:=OnSynDefaultTemplateClick;
        end
        else
          i.OnClick:=OnSynTemplateClick;
      end;
    s.Free;
  end;

begin
  DefTZ:=GetDefaultTemplate(1);
  DefTD:=GetDefaultTemplate(2);
  DefTE:=GetDefaultTemplate(3);
  AddItems(1,Zscr,'');
  AddItems(2,DScr,'');
  AddItems(3,EScr,'');
  AddItems(1,DefZscr,DefTZ);
  AddItems(2,DefDScr,DefTD);
  AddItems(2,DefEScr,DefTE);
end;

procedure TForm_Main_DQE.LoadWorld(Filename: String;AsSave:boolean);

  procedure LoadInfo;
  var
    s:String;
    x:TFileStreamEx;
    a,b,n:integer;
    i:TListItem;
  begin
    try
      s:=Filename+'.bpw';
      if FileExists(s) then
      begin
        if DoSaveBPW=false then
          begin DeleteFile(s);exit;end;
        x:=TFileStreamEx.Create(s,fmOpenRead);
        for a:=0 to world.Scripts.Count-1 do
        begin
          n:=x.ReadInteger;
          for b:=0 to n-1 do
            DQE2_Script(World.Scripts[a]).AddBreakpoint(x.ReadInteger);
        end;
        for a:=0 to world.Dialogs.Count-1 do
        begin
          n:=x.ReadInteger;
          for b:=0 to n-1 do
            DQE2_Dialog(World.Dialogs[a]).AddBreakpoint(x.ReadInteger);
        end;
        for a:=0 to world.EntityTypes.Count-1 do
        begin
          n:=x.ReadInteger;
          for b:=0 to n-1 do
            DQE2_EntityType(World.EntityTypes[a]).AddBreakpoint(x.ReadInteger);
        end;
        n:=x.ReadInteger;
        for a:=0 to n-1 do
        begin
          i:=Form_Debug.TheWatches.Items.Add;
          i.Caption:=x.ReadString;
          i.SubItems.Add('');
        end;
        x.Free;
      end;
    except
      for a:=0 to world.Scripts.Count-1 do
        DQE2_Script(World.Scripts[a]).ClearBreakpoints;
      for a:=0 to world.Dialogs.Count-1 do
        DQE2_Dialog(World.Dialogs[a]).ClearBreakpoints;
      for a:=0 to world.EntityTypes.Count-1 do
        DQE2_EntityType(World.EntityTypes[a]).ClearBreakpoints;
      Form_Debug.TheWatches.Items.Clear;
      x.Free;
    end;
  end;

begin
  if FileExists(Filename) then
  begin
    Form_Debug.TheWatches.Clear;
    world.LoadFromFile(Filename,AsSave,true);
    UpdateObjectsForm;
    RecentAdd(FileName);
    CurFileName:=FileName;
    UpdateCaption;
    UpdateAllForms;
    LoadInfo;
  end
  else
    MessageDlgRus(lng[52],lng[53]+#13#10+Filename,MB_ICONERROR or MB_OK);
end;

procedure TForm_Main_DQE.Localize;
begin
  LoadStringsFromIni(MainUnit.lang_ini,Name,lng);
  N1.Caption:=lng[1];
  N9.Caption:=lng[2];
  Jnrhsnm.Caption:=lng[3];
  N33.Caption:=lng[4];
  N10.Caption:=lng[5];
  C1.Caption:=lng[6];
  N31.Caption:=lng[7];
  N32.Caption:=lng[8];
  N43.Caption:=lng[9];
  N2.Caption:=lng[10];
  N6.Caption:=lng[11];
  N7.Caption:=lng[12];
  N3.Caption:=lng[13];
  N4.Caption:=lng[14];
  N11.Caption:=lng[15];
  N13.Caption:=lng[16];
  N25.Caption:=lng[17];
  N5.Caption:=lng[18];
  N12.Caption:=lng[19];
  N30.Caption:=lng[20];
  N42.Caption:=lng[21];
  N18.Caption:=lng[22];
  N14.Caption:=lng[23];
  N15.Caption:=lng[24];
  N16.Caption:=lng[25];
  N17.Caption:=lng[26];
  N35.Caption:=lng[27];
  N36.Caption:=lng[28];
  N26.Caption:=lng[29];
  N41.Caption:=lng[30];
  N27.Caption:=lng[31];
  N37.Caption:=lng[32];
  N38.Caption:=lng[33];
  N39.Caption:=lng[34];
  SourceForge1.Caption:=lng[35];
  N40.Caption:=lng[36];
  N19.Caption:=lng[37];
  N20.Caption:=lng[38];
  N21.Caption:=lng[39];
  N23.Caption:=lng[40];
  ZScr.Caption:=lng[41];
  DScr.Caption:=lng[41];
  N28.Caption:=lng[42];
  DefZScr.Caption:=lng[43];
  DefDScr.Caption:=lng[43];
  OpenDialog1.Filter:=lng[58]+' (*.dqe)|*.dqe';
  OpenDialog1.Title:=lng[59];
  SaveDialog1.Title:=lng[60];
  SaveDialog1.Filter:=lng[58]+' (*.dqe)|*.dqe';
  ToolButton1.Caption:=lng[2];
  ToolButton2.Caption:=lng[61];
  ToolButton3.Caption:=lng[5];
  ToolButton5.Caption:=lng[24];
  ToolButton6.Caption:=lng[25];
  ToolButton7.Caption:=lng[26];
  Entities1.Caption:=lng[71];
  UpdateCaption;
end;

procedure TForm_Main_DQE.LocalizeAll(lang: string);
begin
  cur_lang:=lang;
  lang_ini:=TIniFile.Create(AppPath+'..\Shared\Localization\dqe2.'+cur_lang+'.ini');
  Form_About.Localize;
  Form_Choose.Localize;
  Form_Dialogs.Localize;
  Form_EditAnswer.Localize;
  Form_EditBlend.Localize;
  Form_EditDefaults.Localize;
  Form_EditIcon.Localize;
  Form_EditPhrase.Localize;
  Form_EditSoundFile.Localize;
  Form_Fonts.Localize;
  Form_Game.Localize;
  Form_GameSettings.Localize;
  Form_Items.Localize;
  Form_Main_DQE.Localize;
  Form_Music.Localize;
  Form_Objects.Localize;
  Form_Options.Localize;
  Form_Rollback.Localize;
  Form_Scripts.Localize;
  Form_Vars.Localize;
  Form_Wait.Localize;
  Form_Zones.Localize;
  Form_Debug.Localize;
  Form_Entities.Localize;
end;

procedure TForm_Main_DQE.N10Click(Sender: TObject);
begin
  if CurFileName='' then C1Click(self) else SaveWorld(CurFileName);
end;

function TForm_Main_DQE.AskRewrite: boolean;
var
  s:string;
  res:TModalResult;
begin
  if CurFileName='' then
    s:=lng[54]
  else
    s:=lng[55]+#13#10+ExtractFileNameOnly(CurFileName)+' ?';
  res:=MessageDlgRus(lng[56],s,MB_YESNOCANCEL or MB_ICONQUESTION);
  case res of
    mrYes:begin N10.Click;result:=true;end;
    mrNo:result:=true;
    else result:=false;
  end;
end;

procedure TForm_Main_DQE.C1Click(Sender: TObject);
var
  s,ss:string;
begin
  repeat
    ss:=ExpandFileName(world.SharedDir+'\..\Quests');
    SaveDialog1.InitialDir:=ss;
    if SaveDialog1.Execute then
    begin
      s:=ExtractFileDir(SaveDialog1.FileName);
      if AnsiStrIComp(PAnsiChar(ss),PAnsiChar(s))<>0 then
      begin
        if MessageDlgRus(lng[68],lng[69]+#13#10+ss+#13#10#13#10+lng[70],MB_OKCANCEL or MB_ICONINFORMATION)=mrOK then
          continue
        else
          exit;
      end
      else
      begin
        SaveWorld(SaveDialog1.FileName);
        exit;
      end;
    end
    else
      exit;
  until false;
end;

procedure TForm_Main_DQE.Entities1Click(Sender: TObject);
begin
  Form_Entities.Show;
end;

procedure TForm_Main_DQE.N20Click(Sender: TObject);
begin
  if SynPopup.PopupComponent<>nil then
    TSynMemo(SynPopup.PopupComponent).CopyToClipboard;
end;

procedure TForm_Main_DQE.N21Click(Sender: TObject);
begin
  if SynPopup.PopupComponent<>nil then
    TSynMemo(SynPopup.PopupComponent).PasteFromClipboard;
end;

procedure TForm_Main_DQE.N25Click(Sender: TObject);
begin
  Form_Fonts.Show;
end;

procedure TForm_Main_DQE.N27Click(Sender: TObject);
begin
  form_about.ShowModal;
end;

procedure TForm_Main_DQE.N28Click(Sender: TObject);
var
  s:TSynMemo;
  ss,sss:string;
  res:TModalResult;
  i:TMenuItem;
  ex:boolean;
begin
  s:=(SynPopup.PopupComponent as TSynMemo);
  ss:='';
  while InputQuery(lng[62],lng[63],ss) do
  begin
    sss:=AppPath+'..\Shared\Templates\'+TemplatePaths[SynPopup.Tag]+'\'+ss+'.txt';
    if FileExists(sss)then
    begin
      res:=MessageDlgRus(lng[64],lng[65]+#13#10+ss,MB_YESNOCANCEL or MB_ICONQUESTION);
      if res=mrNo then exit else
      if res<>mrYes then continue;
      ex:=true;
    end
    else
      ex:=false;
    s.Lines.SaveToFile(sss);
    if not ex then
    begin
      if SynPopup.Tag=1 then
      begin
        i:=TMenuItem.Create(ZScr);
        ZScr.Add(i);
      end
      else
      begin
        i:=TMenuItem.Create(DScr);
        DScr.Add(i);
      end;
      i.Caption:=ss;
      i.OnClick:=OnSynTemplateClick;
      if SynPopup.Tag=1 then
      begin
        i:=TMenuItem.Create(DefZScr);
        DefZScr.Add(i);
      end
      else
      begin
        i:=TMenuItem.Create(DefDScr);
        DefDScr.Add(i);
      end;
      i.RadioItem:=true;
      i.Caption:=ss;
      i.OnClick:=OnSynTemplateClick;
    end;
    break;
  end
end;

procedure TForm_Main_DQE.N2Click(Sender: TObject);
begin
  close;
end;

procedure TForm_Main_DQE.N30Click(Sender: TObject);
begin
  Form_Vars.Show;
end;

procedure TForm_Main_DQE.N31Click(Sender: TObject);
var
  s,s1:string;
begin
  s:=ExtractFileDir(CurFileName);
  if SelectDirectory(lng[57],'',s,[sdNewFolder,sdShowEdit,sdNewUI,sdValidateDir],nil) then
  begin
    if CurFileName='' then s1:='Quest' else s1:=ExtractFileNameOnly(CurFileName);
    world.Build(s,s1);
  end;
end;

procedure TForm_Main_DQE.N32Click(Sender: TObject);
begin
  Form_Options.SpinEdit1.Value:=BackupCount;
  Form_Options.SpinEdit2.Value:=RecentCount;
  Form_Options.CheckBox10.Checked:=DoOpenLast;
  Form_Options.CheckBox11.Checked:=DoSaveBPW;
  if Form_Options.ShowIt then
  begin
    BackupCount:=Form_Options.SpinEdit1.Value;
    RecentCount:=Form_Options.SpinEdit2.Value;
    DoOpenLast:=Form_Options.CheckBox10.Checked;
    DoSaveBPW:=Form_Options.CheckBox11.Checked;
  end;
end;

procedure TForm_Main_DQE.N33Click(Sender: TObject);
begin
  if AskRewrite then
    if OpenDialog1.Execute then
    begin
      LoadWorld(OpenDialog1.FileName,true);
      ToolButton5.Down:=true;
    end;
end;

procedure TForm_Main_DQE.N35Click(Sender: TObject);
begin
  world.Player.Visible:=N35.Checked;
end;

procedure TForm_Main_DQE.N36Click(Sender: TObject);
begin
  World.Player.Control:=N36.Checked;
end;

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

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

procedure TForm_Main_DQE.N11Click(Sender: TObject);
begin
  form_Dialogs.Show;
end;

procedure TForm_Main_DQE.N12Click(Sender: TObject);
begin
  form_Music.Show;
end;

procedure TForm_Main_DQE.N13Click(Sender: TObject);
begin
  Form_Items.Show;
end;

procedure TForm_Main_DQE.N15Click(Sender: TObject);
begin
  world.Play;
end;

procedure TForm_Main_DQE.N16Click(Sender: TObject);
begin
  case World.State of
    wsPlay:world.Pause;
    wsPause:world.Play;
    wsStop:World.Stop;
  end;
end;

procedure TForm_Main_DQE.N17Click(Sender: TObject);
begin
  world.Stop;
end;

procedure TForm_Main_DQE.N18Click(Sender: TObject);
begin
  form_GameSettings.Show;
end;

procedure TForm_Main_DQE.N19Click(Sender: TObject);
begin
  if SynPopup.PopupComponent<>nil then
    TSynMemo(SynPopup.PopupComponent).CutToClipboard;
end;

end.
