unit menu_scene;

{$mode delphi}

interface

uses
  Classes, SysUtils,
  SceneUnit,var_const,
  core_Unit,zglHeader,zglGUI,
  menu_gui;
type

  { TMenu }

  TMenu = class(TScene)
    protected
     MenuGUI:zglTGui;
     sceneTime:double;
     logo:zglPTexture;
     scoreFile:TStringList;
    public
     procedure Draw; override;
     procedure Proc(dt: double); override;
     procedure Init; override;
     procedure Exit; override;
  end;

implementation

{ TMenu }

procedure TMenu.Draw;
begin
    //inherited Draw;
     if round(sceneTime)>=255 then
     begin
     emitter2d_Draw(bgEmitter);
     fx_SetBlendMode(FX_BLEND_NORMAL);
     MenuGUI.Draw;
     MenuGUI.DrawMouse;
     end else
     ssprite2d_Draw(logo,Game.GetScreenW/2 - 256,Game.GetScreenH/2-256,512,512,0,255);
end;

procedure TMenu.Proc(dt: double);
begin
 //   inherited Proc(dt);
     MenuGUI.Update(dt);
     emitter2d_Proc(bgemitter,dt);
     sceneTime+=dt/10;
     bestScoreLAbel.Caption:=inttostr(bestScore);
end;

procedure TMenu.Init;
begin
   // inherited Init;

    scoreFile:=TStringList.Create;
    scoreFile.LoadFromFile('data/bestScore.dat');
    bestScore:=strtoint(scoreFile.Strings[0]);

    fntMain := font_LoadFromFile('data/fonts/Main.zfi');
    gSkin := zglTGuiSkin.Create('data/GUIskins/main.skin');

  snd_Init;
    snd_PlayFile('data/music/NmnMnmN.ogg',true,0.5);
    BlasterSound:=snd_LoadFromFile('data/music/Blaster.ogg',1);
    TeleportSound:=snd_LoadFromFile('data/music/teleport.ogg',2);
    StepSound:=snd_LoadFromFile('data/music/step.ogg',1);
    BoomSound:=snd_LoadFromFile('data/music/boom.ogg',1);
    missSound:=snd_LoadFromFile('data/music/miss.ogg',1);
    selectSound:=snd_LoadFromFile('data/music/select.ogg',1);
    repairSound:=snd_LoadFromFile('data/music/repair.ogg',1);
    healSound:=snd_LoadFromFile('data/music/heal.ogg',1);

    floor := tex_loadfromfile('data/textures/floor.png');
    walltex_0 := tex_loadfromfile('data/textures/wall_0.png');
    walltex_1 := tex_loadfromfile('data/textures/wall_1.png');
    soldiertex := tex_loadfromfile('data/textures/soldier.png');
    rocketmantex := tex_loadfromfile('data/textures/rocketman.png');
    tanktex := tex_loadfromfile('data/textures/tank.png');
    medictex := tex_loadfromfile('data/textures/medic.png');                        //Needed to be free!!
    Capitantex := tex_loadfromfile('data/textures/capitan.png');                   //..but ZenGL on exit clear all mamory by self
    SniperTex:=  tex_loadfromfile('data/textures/sniper.png');
    tracertex := tex_loadfromfile('data/textures/tracer.png');
    ShellTex_0 := tex_loadfromfile('data/textures/shell_normal.png');
    Sentry_body_Tex := tex_loadfromfile('data/textures/sentry_body.png');
    Sentry_Head_Tex_0:=tex_loadfromfile('data/textures/sentry_head.png');
    Sentry_Head_Tex_1:=tex_loadfromfile('data/textures/sentry_head1.png');
    Sentry_Head_Tex_2:=tex_loadfromfile('data/textures/sentry_head2.png');
    logo:=tex_loadfromfile('data/textures/igdc.png');

    bgTex:=tex_loadfromfile('data/textures/bg.png');

    teleportEmitter:=emitter2d_LoadFromFile('data/particles/teleport.zei');
    tracerEmitter:=emitter2d_LoadFromFile('data/particles/tracer.zei');
    shellTracerEmitter:=emitter2d_LoadFromFile('data/particles/shell_tracer.zei');
    //shellTracerMedicEmitter:=emitter2d_LoadFromFile('data/particles/shell_tracer_medic.zei');
    boomEmitter:=emitter2d_LoadFromFile('data/particles/boom.zei');
    HealEmitter:=emitter2d_LoadFromFile('data/particles/Heal_emitter.zei');

    bgEmitter:=emitter2d_LoadFromFile('data/particles/background.zei');
    bgEmitter.AsRect.Rect.X:=0;
    bgEmitter.AsRect.Rect.Y:=0;
    bgEmitter.AsRect.Rect.W:=Game.GetScreenW();
    bgEmitter.AsRect.Rect.H:=Game.GetScreenH();

    MenuGui := zglTGui.Create(gSkin, 0, 0, Game.GetScreenW,Game.GetScreenH,
      zglTFontContainer.Create(
        zglTFontObject.Create(fntMain, 1, $000000, 255),
        zglTFontObject.Create(fntMain, 1, $101010, 255),
        zglTFontObject.Create(fntMain, 1, $555555, 128)
      ));

     InitGUI(MenuGui);
     MenuForm.MoveToCenter;

     //MenuForm.Hide;
     //MenuForm.DisplayEffect:=deZoomIn;
     //MenuForm.Show;

end;

procedure TMenu.Exit;
begin
  //  inherited Exit;
     scoreFile.Strings[0]:=intTostr(bestScore);
     scoreFile.SaveToFile('data/bestScore.dat');
     MenuGUI.Free;
     snd_Free;
end;

end.

