unit launcher;

interface

uses
  Forms, main_, variables, Classes, Controls, StdCtrls, SysUtils, Graphics;

type
  Tlauncher_ = class(TForm)
    logo: TLabel;
    hint: TLabel;
    level: TComboBox;
    bstart: TLabel;
    boptions: TLabel;
    bclose: TLabel;
    Label1: TLabel;
    Label3: TLabel;
    resolution: TComboBox;
    filter: TCheckBox;
    name: TEdit;
    brecords: TLabel;
    procedure bstartClick(Sender: TObject);
    procedure boptionsClick(Sender: TObject);
    procedure bcloseClick(Sender: TObject);
    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure bstartMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure FormActivate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure brecordsClick(Sender: TObject);
    procedure bstartMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  launcher_: Tlauncher_;
  level_name : string;

procedure LabelMouseMove(l : TLabel; f : TForm);
procedure LabelMouseDown(l : TLabel; f : TForm);

implementation

uses options, highscores;

{$R *.DFM}

procedure LabelMouseMove(l : TLabel; f : TForm);
var
old : TColor;
begin
old := l.font.color;
f.OnMouseMove(nil, [ssLeft], 1, 1);
l.font.color := $00FFFFFF;
if (old <> l.font.color) and sound_effects then
  main.snd_list.Items.Find('interface_move').play(false);
end;

procedure LabelMouseDown(l : TLabel; f : TForm);
var
old : TColor;
begin
old := l.font.color;
f.OnMouseMove(nil, [ssLeft], 1, 1);
l.font.color := $00552B00;
if (old <> l.font.color) and sound_effects then
  main.snd_list.Items.Find('interface_click').play(false);
end;

procedure Tlauncher_.bstartClick(Sender: TObject);
begin
player_name := name.text;
case level.itemindex of
  0 : level_name := 'levels/level1.txt';
  1 : level_name := 'levels/level2.txt';
  2 : level_name := 'levels/level3.txt';
end;

if not fileexists(level_name) then exit;

case resolution.itemindex of
  0 : begin
        screen_width := 640;
        screen_height := 480;
      end;
  1 : begin
        screen_width := 800;
        screen_height := 600;
      end;
  2 : begin
        screen_width := 1024;
        screen_height := 768;
      end;
  3 : begin
        screen_width := 1280;
        screen_height := 1024;
      end;
end;

filtered_textures := filter.checked;

StartNewGame(level_name);
bstart.enabled := false;
launcher_.hide; main.show; view_only := false;
end;

procedure Tlauncher_.boptionsClick(Sender: TObject);
begin
launcher_.hide;
options_.show;
end;

procedure Tlauncher_.bcloseClick(Sender: TObject);
begin
close;
end;

procedure Tlauncher_.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
bstart.font.color := launcher_.font.color;
boptions.font.color := launcher_.font.color;
brecords.font.color := launcher_.font.color;
bclose.font.color := launcher_.font.color;
end;

procedure Tlauncher_.bstartMouseMove(Sender: TObject; Shift: TShiftState;
  X, Y: Integer);
begin
LabelMouseMove(TLabel(sender), self);
end;

procedure Tlauncher_.FormActivate(Sender: TObject);
begin       
doublebuffered := true;
level.itemindex := 0;
resolution.itemindex := 2;
filter.checked := true;
LoadOptions('options.cfg');
end;

procedure Tlauncher_.FormDestroy(Sender: TObject);
begin
SaveOptions('options.cfg');
end;

procedure Tlauncher_.brecordsClick(Sender: TObject);
begin
launcher_.hide;
player_name := name.text;
highscores_.show;
end;

procedure Tlauncher_.bstartMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
LabelMouseDown(TLabel(sender), self);
end;

procedure Tlauncher_.FormShow(Sender: TObject);
begin
TForm(sender).OnMouseMove(nil, [ssLeft], 1, 1);
end;

end.
