unit uMenu;

interface
uses
  Omega, MikModEng;

// Сцена меню
type
  TMenu_Scene = ( sMain, sOptions, sOptions2, sAbout, sTop, sSelOptions, sMessage, sInfo, sHelp );

// Кнопка
type
  TButton = Record
  tex: array [0..1] of PTexture;
  alpha: integer;
  play: boolean;
  rect: OERect;
  end;

// бар
type
  TBar = Record
  scrollbutton_tex: array [0..1] of PTexture;
  bar_tex: PTexture;
  alpha, move_x, r_x: integer;
  play, move: boolean;
  rect: OERect;
  end;

// топ
type
  TTop = Record
  nick: String[10];
  points: integer;
  end;

// чек баттон
type
  TCheck_Button = Record
  buttons: array [0..1] of PTexture;
  check_tex: PTexture;
  Str: String[5];
  alpha: integer;
  play, check: boolean;
  rect: OERect;
  end;

// шестерёнки на фоне
type
  TBall = Record
  Tex: PTexture;
  X, Y, Speed, Alpha, W, H: integer;
  Angle: single;
  end;

type
  TBlack_Menu = record
  tex: PTexture;
  enable: boolean;
  alpha, direct: integer;
  end;

var
  Top_Scores: array[0..4] of TTop;
  Balls: array [0..14] of TBall;
  Balls2: array [0..5] of TBall;
  BrightTex: array[0..1] of PTexture;
  Menu_Scene, Next_Scene: TMenu_Scene;
  Black_Menu: TBlack_Menu;
  Music_Bar, Sounds_Bar, Brightness_Bar: TBar;
  NewGame, Options, About, TopScores, Quit, RBack, BigSounds,
  BigOther, Pause, yes, no, BigAbout, BigHelp, Resume, Restart, ToMenu, NextLevel: TButton;
  MuteSounds_Check, ShowFPS_Check, ShowGears_Check, Fullscreen_Check: TCheck_Button;
  FPS, Test, Test2, Brightness: integer;
  ShowFPS, ShowGears, Nick_play, savenick: boolean;
  Ball, Message_panel, Black_Message: PTexture;
  Nick_Rect: OERect;
  Nick_LabelType: byte;
  Nick_LabelAlpha, Music_Volume, Sounds_Volume, Sounds_Volume2, Message_BlackAlpha,
  Message_Alpha, Message_BlackDir, Message_test, balls_count: integer;
  procedure Menu_Process;
  procedure Menu_Paint;
  procedure Balls_Process;
  procedure Balls_Paint;
  function Text_GetWidth( Font: PFont2D; Text: PChar; Scale: Single; Step: Single ): Single;

implementation
uses
  uGame, uInit;

function Text_GetWidth;
var
  i: integer;
begin
  Result := 0;
  for i := 0 to Length( Text ) - 1 do
  Result := Result + Font^.Sizes[ Byte( Text[ i ] ) ].Width * Scale + Step;
end;

// Воздушные шары
procedure Balls_Process;
var
i: integer;
begin
  // шестерёнки
  for i := 0 to 14 do
  begin
    Balls[i].y := Balls[i].y - 1;
    Balls[i].x := Balls[i].x - 1;
    Balls[i].w := Balls[i].w + 2;
    Balls[i].h := Balls[i].h + 2;
    Balls[i].Alpha := Balls[i].Alpha - Balls[i].Speed;
    Balls[i].Angle := Balls[i].Angle + Balls[i].Speed * 0.8;
    if Balls[i].Alpha < 10 then
    begin
      Balls[i].x := Random(700);
      Balls[i].y := Random(500);
      Balls[i].W := 1;
      Balls[i].H := 1;
      Balls[i].Alpha := 255;
      Balls[i].Speed := Random(3) + 1;
      Balls[i].Tex := Ball;
    end;
  end;
  for i := 0 to 5 do
  begin
    if Balls2[i].Alpha > 0 then
    begin
      Balls2[i].y := Balls2[i].y - 1;
      Balls2[i].x := Balls2[i].x - 1;
      Balls2[i].w := Balls2[i].w + 2;
      Balls2[i].h := Balls2[i].h + 2;
      Balls2[i].Alpha := Balls2[i].Alpha - Balls2[i].Speed;
      Balls2[i].Angle := Balls2[i].Angle + Balls2[i].Speed * 0.8;
    end;
  end;
end;

// Отрисовка шестерёнок
procedure Balls_Paint;
var
i: integer;
begin
  for i := 0 to 14 do SSprite_Draw( Balls[i].Tex, Balls[i].X, Balls[i].Y, Balls[i].W, Balls[i].H, Balls[i].Alpha, Balls[i].Angle, FX_DEFAULT  );
  for i := 0 to 5 do if Balls2[i].Alpha > 0 then SSprite_Draw( Balls2[i].Tex, Balls2[i].X, Balls2[i].Y, Balls2[i].W, Balls2[i].H, Balls2[i].Alpha, Balls2[i].Angle, FX_DEFAULT  );
end;

// События
procedure Menu_Process;
var
i, j: integer;
begin
  if Key_Press( K_SnapShot ) then
  begin
    U_SnapShot( 'data\screens', 'screen' );
  end;
  if Mouse_click ( M_RBUTTON ) then
  begin
    balls_count := balls_count + 1;
    if balls_count > 5 then balls_count := 0;
    Balls2[balls_count].x := mouse_x;
    Balls2[balls_count].y := Mouse_y;
    Balls2[balls_count].W := 1;
    Balls2[balls_count].H := 1;
    Balls2[balls_count].Alpha := 255;
    Balls2[balls_count].Speed := Random(3) + 1;
  end;
  // переход на другую сцену
  if Black_Menu.enable then
  begin
    case Black_Menu.direct of
    1: Black_Menu.alpha := Black_Menu.alpha + 5;
    2: Black_Menu.alpha := Black_Menu.alpha - 5;
    end;
    if Black_Menu.alpha = 251 then
    begin
      Menu_Scene := Next_Scene;
      Scene := Next_Scene2;
      NewGame.alpha := 0;
      Options.alpha := 0;
      About.alpha := 0;
      TopScores.alpha := 0;
      Quit.alpha := 0;
      RBack.alpha := 0;
      BigSounds.alpha := 0;
      BigOther.alpha := 0;
      BigAbout.alpha := 0;
      BigHelp.alpha := 0;
      Black_Menu.direct := 2;
      Nick_LabelType := 2;
      if (savenick = true) then
      begin
        Key_BeginReadText(PChar(string(save_nick)));
        Nick := Save_Nick;
      end
      else Key_BeginReadText(PChar(string(nick)));
      Save_Nick := Nick;
      savenick := false;
    end;
    if Black_Menu.alpha <= 0 then Black_Menu.enable := false;
  end;
  // мерцание курсора
  if Cursor_ColorAlpha <= 001 then Cursor_ColorCoff := 1;
  if Cursor_ColorAlpha >= 150 then Cursor_ColorCoff := 2;
  if Cursor_ColorCoff = 1 then Cursor_ColorAlpha := Cursor_ColorAlpha + 2;
  if Cursor_ColorCoff = 2 then Cursor_ColorAlpha := Cursor_ColorAlpha - 2;
  if Black_Screen and (Black_Alpha > 0) then Black_Alpha := Black_Alpha - 2;
  if Black_Alpha < 0 then Black_Screen := false;
  case Menu_Scene of
  // главное меню
  sMain:
  begin
    if Key_Press ( K_SPACE ) then test2 := test2 + 1;
    if Key_Press ( K_G ) then test2 := test2 + 1;
    if test2 > 100 then test2 := 0;
    if ShowGears then Balls_Process; // шестерёнки
    FPS := OE_GETFPS; // фпс
    if Key_Press( K_ESCAPE ) then
    begin
      Message_Alpha := 0;
      Message_BlackAlpha := 0;
      Message_BlackDir := 1;
      Menu_Scene := sMessage; // сообщение о выходе из игры
    end;
    case Nick_LabelType of
    1: Test := Round(Text_GetWidth( Font[0], PChar('Welcome, '+Key_EndReadText), 1, 1 ));
    2:
    begin
      Nick := Save_Nick;
      Test := Round(Text_GetWidth( Font[0], PChar('Welcome, '+string(Nick)), 1, 1 ));
    end;
    end;
    Nick_Rect.X := ((800 - test) / 2) + 2;
    Nick_Rect.Y := 150;
    Nick_Rect.Width := Test - 15;
    Nick_Rect.Height := 28;
    // NickLabel
    if Col_PointInAABB( Mouse_X, Mouse_Y, @Nick_Rect ) and (Nick_LabelAlpha < 254)
    then Nick_LabelAlpha := Nick_LabelAlpha + 3;
    if (Col_PointInAABB( Mouse_X, Mouse_Y, @Nick_Rect ) = false) and (Nick_LabelAlpha >= 3)
    then Nick_LabelAlpha := Nick_LabelAlpha - 3;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @Nick_Rect ) then
    begin
      if Nick_play and (MuteSounds_check.check = false) then Snd_Play(button_snd, 1, volume(sounds_volume2), 50, false);
      Nick_play := false
    end else
    begin
      Nick_play := true;
    end;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @Nick_Rect ) and (Nick_LabelType = 2) and Mouse_Click( M_LBUTTON ) then
    begin
      if MuteSounds_Check.check = false then Snd_Play(click_snd, 1, volume(sounds_volume2), 50, false);
      Key_BeginReadText( PChar(String(Nick)) );
      Nick_LabelType := 1;
    end;
    if Key_Press( K_ENTER ) then
    begin
      if (Nick_LabelType = 1) then
      begin
        Nick_LabelType := 2;
        Nick := Key_EndReadText;
        Save_Nick := Nick;
      end;
    end;
    if Mouse_Press( M_LBUTTON ) and (Col_PointInAABB( Mouse_X, Mouse_Y, @Nick_Rect ) = false) then
    begin
      if (Nick_LabelType = 1) then
      begin
        Nick_LabelType := 2;
        Nick := Key_EndReadText;
        Save_Nick := Nick;
      end;
    end;
    //if Col_PointInAABB( Mouse_X, Mouse_Y, @Nick_Rect ) then Nick_LabelType := 2 else Nick_LabelType := 1;
    // Кнопки
    // NewGame
    if Col_PointInAABB( Mouse_X, Mouse_Y, @NewGame.rect ) and (NewGame.alpha < 254)
    then NewGame.alpha := NewGame.alpha + 3;
    if (Col_PointInAABB( Mouse_X, Mouse_Y, @NewGame.rect ) = false) and (NewGame.alpha >= 3)
    then NewGame.alpha := NewGame.alpha - 3;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @NewGame.Rect ) then
    begin
      if NewGame.play and (MuteSounds_check.check = false) then Snd_Play(button_snd, 1, volume(sounds_volume2), 50, false);
      NewGame.play := false
    end else
    begin
      NewGame.play := true;
    end;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @NewGame.rect ) and Mouse_Click( M_LBUTTON ) then
    begin
      if MuteSounds_Check.check = false then Snd_Play(click_snd, 1, volume(sounds_volume2), 50, false);
      if Black_Menu.enable = false then
      begin
        Black_Menu.enable := true;
        Black_Menu.alpha := 1;
        Black_Menu.direct := 1;
        Next_Scene2 := sGame;
        for i := 1 to 18 do
        begin
          greed[i,1].byte := 10;
          greed[i,16].byte := 8;
          greed[i,1].tex := Blocks[10];
          greed[i,16].tex := Blocks[8];
          greed[i,1].full := true;
          greed[i,16].full := true;
          greed[i,1].openright := true;
          greed[i,16].openleft := true;
        end;
        for i := 2 to 17 do
        begin
          greed[i,1].delbyte := i - 1;
          greed[i,16].delbyte := 15 + i;
        end;
        greed[18,1].tex := Blocks[5];
        greed[18,16].tex := Blocks[4];
        greed[1,1].tex := Blocks[6];
        greed[1,16].tex := Blocks[7];
        for i := 2 to 15 do
        begin
          greed[18,i].byte := 3;
          greed[18,i].tex := Blocks[3];
          greed[1,i].byte := 3;
          greed[1,i].tex := Blocks[3];
        end;
        for i := 2 to 17 do
        for j := 2 to 15 do
        begin
          greed[i,j].byte := 1;
          greed[i,j].delalpha := 255;
          greed[i,j].move := true;
          greed[i,j].full := false;
          greed[i,j].alpha := 0;
          greed[i,j].openleft := false;
          greed[i,j].openright := false;
          greed[i,j].opentop := false;
          greed[i,j].opendown := false;
          greed[i,j].delbyte := 0;
        end;
        //for i := 0 to 17 do greed[20,i].byte := 2;
        play.nextf := random(7) + 1;
        play.f := play.nextf;
        play.nextf := random(7) + 1;
        preview1 := preview[play.nextf];
        preview_alpha := 255;
        play.a := random(4);
        play.stop := 500;
        play.stopl := 1;
        play.stopr := 1;
        play.stopro := 1;
        play.enable := true;
        play.x := 7;
        play.y := 2;
        Points := 0;
        Add_Points := 0;
        Level := 1;
        Pipes_Left := 50;
        game_over2 := true;
        game_over := false;
        Save_Nick := Nick;
      end;
    end;
    // TopScores
    if Col_PointInAABB( Mouse_X, Mouse_Y, @TopScores.rect ) and (TopScores.alpha < 254)
    then TopScores.alpha := TopScores.alpha + 3;
    if (Col_PointInAABB( Mouse_X, Mouse_Y, @TopScores.rect ) = false) and (TopScores.alpha >= 3)
    then TopScores.alpha := TopScores.alpha - 3;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @TopScores.Rect ) then
    begin
      if TopScores.play and (MuteSounds_check.check = false) then Snd_Play(button_snd, 1, volume(sounds_volume2), 50, false);
      TopScores.play := false
    end else
    begin
      TopScores.play := true;
    end;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @TopScores.rect ) and Mouse_Click( M_LBUTTON ) then
    begin
      if MuteSounds_Check.check = false then Snd_Play(click_snd, 1, volume(sounds_volume2), 50, false);
      if Black_Menu.enable = false then
      begin
        Black_Menu.enable := true;
        Black_Menu.alpha := 1;
        Black_Menu.direct := 1;
        Next_Scene := sTop;
        Next_Scene2 := sMenu;
      end;
    end;
    // Options
    if Col_PointInAABB( Mouse_X, Mouse_Y, @Options.rect ) and (Options.alpha < 254)
    then Options.alpha := Options.alpha + 3;
    if (Col_PointInAABB( Mouse_X, Mouse_Y, @Options.rect ) = false) and (Options.alpha >= 3)
    then Options.alpha := Options.alpha - 3;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @Options.Rect ) then
    begin
      if Options.play and (MuteSounds_check.check = false) then Snd_Play(button_snd, 1, volume(sounds_volume2), 50, false);
      Options.play := false
    end else
    begin
      Options.play := true;
    end;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @Options.rect ) and Mouse_Click( M_LBUTTON ) then
    begin
      if MuteSounds_Check.check = false then Snd_Play(click_snd, 1, volume(sounds_volume2), 50, false);
      if Black_Menu.enable = false then
      begin
        Black_Menu.enable := true;
        Black_Menu.alpha := 1;
        Black_Menu.direct := 1;
        Next_Scene := sSelOptions;
        Next_Scene2 := sMenu;
      end;
    end;
    // About
    if Col_PointInAABB( Mouse_X, Mouse_Y, @About.rect ) and (About.alpha < 254)
    then About.alpha := About.alpha + 3;
    if (Col_PointInAABB( Mouse_X, Mouse_Y, @About.rect ) = false) and (About.alpha >= 3)
    then About.alpha := About.alpha - 3;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @About.Rect ) then
    begin
      if About.play and (MuteSounds_check.check = false) then Snd_Play(button_snd, 1, volume(sounds_volume2), 50, false);
      About.play := false
    end else
    begin
      About.play := true;
    end;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @About.rect ) and Mouse_Click( M_LBUTTON ) then
    begin
      if MuteSounds_Check.check = false then Snd_Play(click_snd, 1, volume(sounds_volume2), 50, false);
      if Black_Menu.enable = false then
      begin
        Black_Menu.enable := true;
        Black_Menu.alpha := 1;
        Black_Menu.direct := 1;
        Next_Scene := sInfo;
        Next_Scene2 := sMenu;
      end;
    end;
    // Quit
    if Col_PointInAABB( Mouse_X, Mouse_Y, @Quit.rect ) and (Quit.alpha < 254)
    then Quit.alpha := Quit.alpha + 3;
    if (Col_PointInAABB( Mouse_X, Mouse_Y, @Quit.rect ) = false) and (Quit.alpha >= 3)
    then Quit.alpha := Quit.alpha - 3;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @Quit.Rect ) then
    begin
      if Quit.play and (MuteSounds_check.check = false) then Snd_Play(button_snd, 1, volume(sounds_volume2), 50, false);
      Quit.play := false
    end else
    begin
      Quit.play := true;
    end;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @Quit.rect ) and Mouse_Click( M_LBUTTON ) then
    begin
      if MuteSounds_Check.check = false then Snd_Play(click_snd, 1, volume(sounds_volume2), 50, false);
      Message_Alpha := 0;
      Message_BlackAlpha := 0;
      Message_BlackDir := 1;
      Menu_Scene := sMessage;
    end;
  end;
  sOptions:
  begin
    if ShowGears then Balls_Process;
    FPS := OE_GETFPS;
    Music_Volume := Round( (Music_Bar.move_X - 236) / 3 );
    Sounds_Volume2 := Round( (((Sounds_Bar.move_X - 236) / 3) / 2) + 50  );
    Sounds_Volume := Round( (Sounds_Bar.move_X - 236) / 3 );
    if Key_Press( K_ESCAPE ) then
    begin
      if Black_Menu.enable = false then
      begin
        Black_Menu.enable := true;
        Black_Menu.alpha := 1;
        Black_Menu.direct := 1;
        Next_Scene := sSelOptions;
        Next_Scene2 := sMenu;
      end;
    end;
    // Music bar
    if Col_PointInAABB( Mouse_X, Mouse_Y, @Music_Bar.rect ) and (Music_Bar.alpha < 254)
    then Music_Bar.alpha := Music_Bar.alpha + 3;
    if (Col_PointInAABB( Mouse_X, Mouse_Y, @Music_Bar.rect ) = false) and (Music_Bar.alpha >= 3)
    and (Music_Bar.move = false) then Music_Bar.alpha := Music_Bar.alpha - 3;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @Music_Bar.rect ) then
    begin
      if Music_Bar.play and (MuteSounds_check.check = false)
      and (Music_Bar.move = false) then Snd_Play(button_snd, 1, volume(sounds_volume2), 50, false);
      Music_Bar.play := false
    end else
    begin
      Music_Bar.play := true;
    end;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @Music_Bar.rect ) and Mouse_Click( M_LBUTTON ) then
    begin
      Music_Bar.move := true;
      Music_Bar.r_x := Mouse_X - Music_Bar.move_x;
    end;
    if Music_Bar.move then
    begin
      Music_Bar.move_x := Mouse_X - Music_Bar.r_x;
      Music_Bar.rect.X := Music_Bar.move_x + 2;
    end;
    if Mouse_Press( M_LBUTTON ) then
    begin
      Music_Bar.move := false;
      Sounds_Bar.move := false;
      if Col_PointInAABB( Mouse_X, Mouse_Y, @MuteSounds_Check.rect ) then
      begin
        if MuteSounds_Check.check = false then Snd_Play(check_snd, 1, volume(sounds_volume2), 50, false);
        if MuteSounds_Check.check then MuteSounds_Check.check := false else MuteSounds_Check.check := true;
        //if MuteSounds_Check.check then MuteSounds_Check.Str := 'True' else MuteSounds_Check.Str := 'False';
      end;
    end;
    if Music_Bar.move_x < 236 then
    begin
      Music_Bar.move_x := 236;
      Music_Bar.rect.X := 236 + 2;
    end;
    if Music_Bar.move_x > 536 then
    begin
      Music_Bar.move_x := 536;
      Music_Bar.rect.x := 536 + 2;
    end;
    // Sounds bar
    if Col_PointInAABB( Mouse_X, Mouse_Y, @Sounds_Bar.rect ) and (Sounds_Bar.alpha < 254)
    then Sounds_Bar.alpha := Sounds_Bar.alpha + 3;
    if (Col_PointInAABB( Mouse_X, Mouse_Y, @Sounds_Bar.rect ) = false) and (Sounds_Bar.alpha >= 3)
    and (Sounds_Bar.move = false) then Sounds_Bar.alpha := Sounds_Bar.alpha - 3;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @Sounds_Bar.rect ) then
    begin
      if Sounds_Bar.play and (MuteSounds_check.check = false)
      and (Sounds_Bar.move = false) then Snd_Play(button_snd, 1, volume(sounds_volume2), 50, false);
      Sounds_Bar.play := false
    end else
    begin
      Sounds_Bar.play := true;
    end;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @Sounds_Bar.rect ) and Mouse_Click( M_LBUTTON ) then
    begin
      Sounds_Bar.move := true;
      Sounds_Bar.r_x := Mouse_X - Sounds_Bar.move_x;
    end;
    if Sounds_Bar.move then
    begin
      Sounds_Bar.move_x := Mouse_X - Sounds_Bar.r_x;
      Sounds_Bar.rect.X := Sounds_Bar.move_x + 2;
    end;
    if Sounds_Bar.move_x < 236 then
    begin
      Sounds_Bar.move_x := 236;
      Sounds_Bar.rect.X := 236 + 2;
    end;
    if Sounds_Bar.move_x > 536 then
    begin
      Sounds_Bar.move_x := 536;
      Sounds_Bar.rect.x := 536 + 2;
    end;
    // Back button
    if Col_PointInAABB( Mouse_X, Mouse_Y, @RBack.rect ) and (RBack.alpha < 254)
    then RBack.alpha := RBack.alpha + 3;
    if (Col_PointInAABB( Mouse_X, Mouse_Y, @RBack.rect ) = false) and (RBack.alpha >= 3)
    then RBack.alpha := RBack.alpha - 3;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @RBack.Rect ) then
    begin
      if RBack.play and (MuteSounds_check.check = false) then Snd_Play(button_snd, 1, volume(sounds_volume2), 50, false);
      RBack.play := false
    end else
    begin
      RBack.play := true;
    end;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @RBack.rect ) and Mouse_Click( M_LBUTTON ) then
    begin
      if MuteSounds_Check.check = false then Snd_Play(click_snd, 1, volume(sounds_volume2), 50, false);
      if Black_Menu.enable = false then
      begin
        Black_Menu.enable := true;
        Black_Menu.alpha := 1;
        Black_Menu.direct := 1;
        Next_Scene := sSelOptions;
        Next_Scene2 := sMenu;
      end;
    end;
    // MuteSounds_Check
    if Col_PointInAABB( Mouse_X, Mouse_Y, @MuteSounds_Check.rect ) and (MuteSounds_Check.alpha < 254)
    then MuteSounds_Check.alpha := MuteSounds_Check.alpha + 3;
    if (Col_PointInAABB( Mouse_X, Mouse_Y, @MuteSounds_Check.rect ) = false) and (MuteSounds_Check.alpha >= 3)
    then MuteSounds_Check.alpha := MuteSounds_Check.alpha - 3;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @MuteSounds_Check.rect ) then
    begin
      if MuteSounds_Check.play and (MuteSounds_check.check = false) then Snd_Play(button_snd, 1, volume(sounds_volume2), 50, false);
      MuteSounds_Check.play := false
    end else
    begin
      MuteSounds_Check.play := true;
    end;
    if MuteSounds_Check.check then MikMod.Volume := 0 else MikMod.Volume := Music_Volume;
  end;
  sOptions2:
  begin
    if ShowGears then Balls_Process;
    FPS := OE_GETFPS;
    Brightness := Round( (Brightness_Bar.move_X - 236) / 3 );
    if Key_Press( K_ESCAPE ) then
    begin
      if Black_Menu.enable = false then
      begin
        Black_Menu.enable := true;
        Black_Menu.alpha := 1;
        Black_Menu.direct := 1;
        Next_Scene := sSelOptions;
        Next_Scene2 := sMenu;
      end;
    end;
    // Brightness bar
    if Col_PointInAABB( Mouse_X, Mouse_Y, @Brightness_Bar.rect ) and (Brightness_Bar.alpha < 254)
    then Brightness_Bar.alpha := Brightness_Bar.alpha + 3;
    if (Col_PointInAABB( Mouse_X, Mouse_Y, @Brightness_Bar.rect ) = false) and (Brightness_Bar.alpha >= 3)
    and (Brightness_Bar.move = false) then Brightness_Bar.alpha := Brightness_Bar.alpha - 3;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @Brightness_Bar.rect ) then
    begin
      if Brightness_Bar.play and (MuteSounds_check.check = false)
      and (Brightness_Bar.move = false) then Snd_Play(button_snd, 1, volume(sounds_volume2), 50, false);
      Brightness_Bar.play := false
    end else
    begin
      Brightness_Bar.play := true;
    end;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @Brightness_Bar.rect ) and Mouse_Click( M_LBUTTON ) then
    begin
      Brightness_Bar.move := true;
      Brightness_Bar.r_x := Mouse_X - Brightness_Bar.move_x;
    end;
    if Brightness_Bar.move then
    begin
      Brightness_Bar.move_x := Mouse_X - Brightness_Bar.r_x;
      Brightness_Bar.rect.X := Brightness_Bar.move_x + 2;
    end;
    if Mouse_Press( M_LBUTTON ) then
    begin
      Brightness_Bar.move := false;
      if Col_PointInAABB( Mouse_X, Mouse_Y, @ShowGears_Check.rect ) then
      begin
        if MuteSounds_Check.check = false then Snd_Play(check_snd, 1, volume(sounds_volume2), 50, false);
        if ShowGears_Check.check then ShowGears_Check.check := false else ShowGears_Check.check := true;
        ShowGears := ShowGears_Check.check;
      end;
      if Col_PointInAABB( Mouse_X, Mouse_Y, @ShowFPS_Check.rect ) then
      begin
        if MuteSounds_Check.check = false then Snd_Play(check_snd, 1, volume(sounds_volume2), 50, false);
        if ShowFPS_Check.check then ShowFPS_Check.check := false else ShowFPS_Check.check := true;
        ShowFPS := ShowFPS_Check.check;
      end;
      if Col_PointInAABB( Mouse_X, Mouse_Y, @Fullscreen_Check.rect ) then
      begin
        if MuteSounds_Check.check = false then Snd_Play(check_snd, 1, volume(sounds_volume2), 50, false);
        if Fullscreen_Check.check then Fullscreen_Check.check := false else Fullscreen_Check.check := true;
        Fullscreen := Fullscreen_Check.check;
        if Fullscreen then OE_ChangeScreenOptions( 800, 600, 32, 0, TRUE, FALSE )
        else OE_ChangeScreenOptions( 800, 600, 32, 0, FALSE, FALSE );
      end;
    end;
    if Brightness_Bar.move_x < 236 then
    begin
      Brightness_Bar.move_x := 236;
      Brightness_Bar.rect.X := 236 + 2;
    end;
    if Brightness_Bar.move_x > 536 then
    begin
      Brightness_Bar.move_x := 536;
      Brightness_Bar.rect.x := 536 + 2;
    end;
    //if Key_Press( K_ESCAPE ) then Menu_Scene := sMain;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @RBack.rect ) and (RBack.alpha < 254)
    then RBack.alpha := RBack.alpha + 3;
    if (Col_PointInAABB( Mouse_X, Mouse_Y, @RBack.rect ) = false) and (RBack.alpha >= 3)
    then RBack.alpha := RBack.alpha - 3;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @RBack.Rect ) then
    begin
      if RBack.play and (MuteSounds_check.check = false) then Snd_Play(button_snd, 1, volume(sounds_volume2), 50, false);
      RBack.play := false
    end else
    begin
      RBack.play := true;
    end;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @RBack.rect ) and Mouse_Click( M_LBUTTON ) then
    begin
      if MuteSounds_Check.check = false then Snd_Play(click_snd, 1, volume(sounds_volume2), 50, false);
      if Black_Menu.enable = false then
      begin
        Black_Menu.enable := true;
        Black_Menu.alpha := 1;
        Black_Menu.direct := 1;
        Next_Scene := sSelOptions;
        Next_Scene2 := sMenu;
      end;
    end;
    // Fullscreen_Check
    if Col_PointInAABB( Mouse_X, Mouse_Y, @Fullscreen_Check.rect ) and (Fullscreen_Check.alpha < 254)
    then Fullscreen_Check.alpha := Fullscreen_Check.alpha + 3;
    if (Col_PointInAABB( Mouse_X, Mouse_Y, @Fullscreen_Check.rect ) = false) and (Fullscreen_Check.alpha >= 3)
    then Fullscreen_Check.alpha := Fullscreen_Check.alpha - 3;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @Fullscreen_Check.rect ) then
    begin
      if Fullscreen_Check.play and (MuteSounds_check.check = false) then Snd_Play(button_snd, 1, volume(sounds_volume2), 50, false);
      Fullscreen_Check.play := false
    end else
    begin
      Fullscreen_Check.play := true;
    end;
    // ShowGears_Check
    if Col_PointInAABB( Mouse_X, Mouse_Y, @ShowGears_Check.rect ) and (ShowGears_Check.alpha < 254)
    then ShowGears_Check.alpha := ShowGears_Check.alpha + 3;
    if (Col_PointInAABB( Mouse_X, Mouse_Y, @ShowGears_Check.rect ) = false) and (ShowGears_Check.alpha >= 3)
    then ShowGears_Check.alpha := ShowGears_Check.alpha - 3;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @ShowGears_Check.rect ) then
    begin
      if ShowGears_Check.play and (MuteSounds_check.check = false) then Snd_Play(button_snd, 1, volume(sounds_volume2), 50, false);
      ShowGears_Check.play := false
    end else
    begin
      ShowGears_Check.play := true;
    end;
    // ShowFPS_Check
    if Col_PointInAABB( Mouse_X, Mouse_Y, @ShowFPS_Check.rect ) and (ShowFPS_Check.alpha < 254)
    then ShowFPS_Check.alpha := ShowFPS_Check.alpha + 3;
    if (Col_PointInAABB( Mouse_X, Mouse_Y, @ShowFPS_Check.rect ) = false) and (ShowFPS_Check.alpha >= 3)
    then ShowFPS_Check.alpha := ShowFPS_Check.alpha - 3;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @ShowFPS_Check.rect ) then
    begin
      if ShowFPS_Check.play and (MuteSounds_check.check = false) then Snd_Play(button_snd, 1, volume(sounds_volume2), 50, false);
      ShowFPS_Check.play := false
    end else
    begin
      ShowFPS_Check.play := true;
    end;
  end;
  sSelOptions:
  begin
    if ShowGears then Balls_Process;
    FPS := OE_GETFPS;
    if Key_Press( K_ESCAPE ) then
    begin
      if Black_Menu.enable = false then
      begin
        Black_Menu.enable := true;
        Black_Menu.alpha := 1;
        Black_Menu.direct := 1;
        Next_Scene := sMain;
        Next_Scene2 := sMenu;
      end;
    end;
    // BigSounds button
    if Col_PointInAABB( Mouse_X, Mouse_Y, @BigSounds.rect ) and (BigSounds.alpha < 254)
    then BigSounds.alpha := BigSounds.alpha + 3;
    if (Col_PointInAABB( Mouse_X, Mouse_Y, @BigSounds.rect ) = false) and (BigSounds.alpha >= 3)
    then BigSounds.alpha := BigSounds.alpha - 3;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @BigSounds.Rect ) then
    begin
      if BigSounds.play and (MuteSounds_check.check = false) then Snd_Play(button_snd, 1, volume(sounds_volume2), 50, false);
      BigSounds.play := false
    end else
    begin
      BigSounds.play := true;
    end;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @BigSounds.rect ) and Mouse_Click( M_LBUTTON ) then
    begin
      if MuteSounds_Check.check = false then Snd_Play(click_snd, 1, volume(sounds_volume2), 50, false);
      if Black_Menu.enable = false then
      begin
        Black_Menu.enable := true;
        Black_Menu.alpha := 1;
        Black_Menu.direct := 1;
        Next_Scene := sOptions;
        Next_Scene2 := sMenu;
      end;
    end;
    // BigOther button
    if Col_PointInAABB( Mouse_X, Mouse_Y, @BigOther.rect ) and (BigOther.alpha < 254)
    then BigOther.alpha := BigOther.alpha + 3;
    if (Col_PointInAABB( Mouse_X, Mouse_Y, @BigOther.rect ) = false) and (BigOther.alpha >= 3)
    then BigOther.alpha := BigOther.alpha - 3;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @BigOther.Rect ) then
    begin
      if BigOther.play and (MuteSounds_check.check = false) then Snd_Play(button_snd, 1, volume(sounds_volume2), 50, false);
      BigOther.play := false
    end else
    begin
      BigOther.play := true;
    end;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @BigOther.rect ) and Mouse_Click( M_LBUTTON ) then
    begin
      if MuteSounds_Check.check = false then Snd_Play(click_snd, 1, volume(sounds_volume2), 50, false);
      if Black_Menu.enable = false then
      begin
        Black_Menu.enable := true;
        Black_Menu.alpha := 1;
        Black_Menu.direct := 1;
        Next_Scene := sOptions2;
        Next_Scene2 := sMenu;
      end;
    end;
    // RBack button
    if Col_PointInAABB( Mouse_X, Mouse_Y, @RBack.rect ) and (RBack.alpha < 254)
    then RBack.alpha := RBack.alpha + 3;
    if (Col_PointInAABB( Mouse_X, Mouse_Y, @RBack.rect ) = false) and (RBack.alpha >= 3)
    then RBack.alpha := RBack.alpha - 3;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @RBack.Rect ) then
    begin
      if RBack.play and (MuteSounds_check.check = false) then Snd_Play(button_snd, 1, volume(sounds_volume2), 50, false);
      RBack.play := false
    end else
    begin
      RBack.play := true;
    end;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @RBack.rect ) and Mouse_Click( M_LBUTTON ) then
    begin
      if MuteSounds_Check.check = false then Snd_Play(click_snd, 1, volume(sounds_volume2), 50, false);
      if Black_Menu.enable = false then
      begin
        Black_Menu.enable := true;
        Black_Menu.alpha := 1;
        Black_Menu.direct := 1;
        Next_Scene := sMain;
        Next_Scene2 := sMenu;
      end;
    end;
  end;
  sInfo:
    begin
    if ShowGears then Balls_Process;
    if Key_Press( K_ESCAPE ) then
    begin
      if Black_Menu.enable = false then
      begin
        Black_Menu.enable := true;
        Black_Menu.alpha := 1;
        Black_Menu.direct := 1;
        Next_Scene := sMain;
        Next_Scene2 := sMenu;
      end;
    end;
    // RBack button
    if Col_PointInAABB( Mouse_X, Mouse_Y, @RBack.rect ) and (RBack.alpha < 254)
    then RBack.alpha := RBack.alpha + 3;
    if (Col_PointInAABB( Mouse_X, Mouse_Y, @RBack.rect ) = false) and (RBack.alpha >= 3)
    then RBack.alpha := RBack.alpha - 3;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @RBack.Rect ) then
    begin
      if RBack.play and (MuteSounds_check.check = false) then Snd_Play(button_snd, 1, volume(sounds_volume2), 50, false);
      RBack.play := false
    end else
    begin
      RBack.play := true;
    end;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @RBack.rect ) and Mouse_Click( M_LBUTTON ) then
    begin
      if MuteSounds_Check.check = false then Snd_Play(click_snd, 1, volume(sounds_volume2), 50, false);
      if Black_Menu.enable = false then
      begin
        Black_Menu.enable := true;
        Black_Menu.alpha := 1;
        Black_Menu.direct := 1;
        Next_Scene := sMain;
        Next_Scene2 := sMenu;
      end;
    end;
    // BigAbout button
    if Col_PointInAABB( Mouse_X, Mouse_Y, @BigAbout.rect ) and (BigAbout.alpha < 254)
    then BigAbout.alpha := BigAbout.alpha + 3;
    if (Col_PointInAABB( Mouse_X, Mouse_Y, @BigAbout.rect ) = false) and (BigAbout.alpha >= 3)
    then BigAbout.alpha := BigAbout.alpha - 3;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @BigAbout.Rect ) then
    begin
      if BigAbout.play and (MuteSounds_check.check = false) then Snd_Play(button_snd, 1, volume(sounds_volume2), 50, false);
      BigAbout.play := false
    end else
    begin
      BigAbout.play := true;
    end;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @BigAbout.rect ) and Mouse_Click( M_LBUTTON ) then
    begin
      if MuteSounds_Check.check = false then Snd_Play(click_snd, 1, volume(sounds_volume2), 50, false);
      if Black_Menu.enable = false then
      begin
        strings[0].y := 500;
        for i := 0 to 17 do
        begin
          strings[i].alpha := 0;
          strings[i].alpha_dir := 3;
        end;
        Black_Menu.enable := true;
        Black_Menu.alpha := 1;
        Black_Menu.direct := 1;
        Next_Scene := sAbout;
        Next_Scene2 := sMenu;
      end;
    end;
    // BigHelp button
    if Col_PointInAABB( Mouse_X, Mouse_Y, @BigHelp.rect ) and (BigHelp.alpha < 254)
    then BigHelp.alpha := BigHelp.alpha + 3;
    if (Col_PointInAABB( Mouse_X, Mouse_Y, @BigHelp.rect ) = false) and (BigHelp.alpha >= 3)
    then BigHelp.alpha := BigHelp.alpha - 3;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @BigHelp.Rect ) then
    begin
      if BigHelp.play and (MuteSounds_check.check = false) then Snd_Play(button_snd, 1, volume(sounds_volume2), 50, false);
      BigHelp.play := false
    end else
    begin
      BigHelp.play := true;
    end;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @BigHelp.rect ) and Mouse_Click( M_LBUTTON ) then
    begin
      if MuteSounds_Check.check = false then Snd_Play(click_snd, 1, volume(sounds_volume2), 50, false);
      if Black_Menu.enable = false then
      begin
        strings2[0].y := 500;
        for i := 0 to 15 do
        begin
          strings2[i].alpha := 0;
          strings2[i].alpha_dir := 3;
        end;
        Black_Menu.enable := true;
        Black_Menu.alpha := 1;
        Black_Menu.direct := 1;
        Next_Scene := sHelp;
        Next_Scene2 := sMenu;
      end;
    end;
  end;
  sAbout:
  begin
    scroll_text;
    if ShowGears then Balls_Process;
    FPS := OE_GETFPS;
    if Key_Press( K_ESCAPE ) then
    begin
      if Black_Menu.enable = false then
      begin
        Black_Menu.enable := true;
        Black_Menu.alpha := 1;
        Black_Menu.direct := 1;
        Next_Scene := sMain;
        Next_Scene2 := sMenu;
      end;
    end;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @RBack.rect ) and (RBack.alpha < 254)
    then RBack.alpha := RBack.alpha + 3;
    if (Col_PointInAABB( Mouse_X, Mouse_Y, @RBack.rect ) = false) and (RBack.alpha >= 3)
    then RBack.alpha := RBack.alpha - 3;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @RBack.Rect ) then
    begin
      if RBack.play and (MuteSounds_check.check = false) then Snd_Play(button_snd, 1, volume(sounds_volume2), 50, false);
      RBack.play := false
    end else
    begin
      RBack.play := true;
    end;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @RBack.rect ) and Mouse_Click( M_LBUTTON ) then
    begin
      if MuteSounds_Check.check = false then Snd_Play(click_snd, 1, volume(sounds_volume2), 50, false);
      if Black_Menu.enable = false then
      begin
        Black_Menu.enable := true;
        Black_Menu.alpha := 1;
        Black_Menu.direct := 1;
        Next_Scene := sInfo;
        Next_Scene2 := sMenu;
      end;
    end;
  end;
  sHelp:
  begin
    scroll_text2;
    if ShowGears then Balls_Process;
    if Key_Press( K_ESCAPE ) then
    begin
      if Black_Menu.enable = false then
      begin
        Black_Menu.enable := true;
        Black_Menu.alpha := 1;
        Black_Menu.direct := 1;
        Next_Scene := sMain;
        Next_Scene2 := sMenu;
      end;
    end;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @RBack.rect ) and (RBack.alpha < 254)
    then RBack.alpha := RBack.alpha + 3;
    if (Col_PointInAABB( Mouse_X, Mouse_Y, @RBack.rect ) = false) and (RBack.alpha >= 3)
    then RBack.alpha := RBack.alpha - 3;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @RBack.Rect ) then
    begin
      if RBack.play and (MuteSounds_check.check = false) then Snd_Play(button_snd, 1, volume(sounds_volume2), 50, false);
      RBack.play := false
    end else
    begin
      RBack.play := true;
    end;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @RBack.rect ) and Mouse_Click( M_LBUTTON ) then
    begin
      if MuteSounds_Check.check = false then Snd_Play(click_snd, 1, volume(sounds_volume2), 50, false);
      if Black_Menu.enable = false then
      begin
        Black_Menu.enable := true;
        Black_Menu.alpha := 1;
        Black_Menu.direct := 1;
        Next_Scene := sInfo;
        Next_Scene2 := sMenu;
      end;
    end;
  end;
  sTop:
  begin
    if ShowGears then Balls_Process;
    FPS := OE_GETFPS;
    if Key_Press( K_ESCAPE ) then
    begin
      if Black_Menu.enable = false then
      begin
        Black_Menu.enable := true;
        Black_Menu.alpha := 1;
        Black_Menu.direct := 1;
        Next_Scene := sMain;
        Next_Scene2 := sMenu;
      end;
    end;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @RBack.rect ) and (RBack.alpha < 254)
    then RBack.alpha := RBack.alpha + 3;
    if (Col_PointInAABB( Mouse_X, Mouse_Y, @RBack.rect ) = false) and (RBack.alpha >= 3)
    then RBack.alpha := RBack.alpha - 3;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @RBack.Rect ) then
    begin
      if RBack.play and (MuteSounds_check.check = false) then Snd_Play(button_snd, 1, volume(sounds_volume2), 50, false);
      RBack.play := false
    end else
    begin
      RBack.play := true;
    end;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @RBack.rect ) and Mouse_Click( M_LBUTTON ) then
    begin
      if MuteSounds_Check.check = false then Snd_Play(click_snd, 1, volume(sounds_volume2), 50, false);
      if Black_Menu.enable = false then
      begin
        Black_Menu.enable := true;
        Black_Menu.alpha := 1;
        Black_Menu.direct := 1;
        Next_Scene := sMain;
        Next_Scene2 := sMenu;
      end;
    end;
  end;
  sMessage:
  begin
    case Message_BlackDir of
    1:
    begin
      if message_blackalpha < 170 then message_blackalpha := message_blackalpha + 3;
      if message_alpha < 255 then message_alpha := message_alpha + 5;
    end;
    2:
    begin
      if message_blackalpha > 0 then message_blackalpha := message_blackalpha - 3;
      if message_alpha > 0 then message_alpha := message_alpha - 5;
      if (message_alpha <= 0) or (message_blackalpha <= 0) then
      begin
        yes.alpha := 0;
        no.alpha := 0;
        Menu_Scene := sMain;
      end;
    end;
    end;
    if Key_Press( K_ESCAPE ) then Message_test := Message_test + 1;
    if Message_test > 100 then Message_test := 0;
    // yes button
    if Col_PointInAABB( Mouse_X, Mouse_Y, @yes.rect ) and (yes.alpha < 254)
    then yes.alpha := yes.alpha + 3;
    if (Col_PointInAABB( Mouse_X, Mouse_Y, @yes.rect ) = false) and (yes.alpha >= 3)
    then yes.alpha := yes.alpha - 3;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @yes.Rect ) then
    begin
      if yes.play and (MuteSounds_check.check = false) then Snd_Play(button_snd, 1, volume(sounds_volume2), 50, false);
      yes.play := false
    end else
    begin
      yes.play := true;
    end;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @yes.rect ) and Mouse_Click( M_LBUTTON ) then
    begin
      if MuteSounds_Check.check = false then Snd_Play(click_snd, 1, volume(sounds_volume2), 50, false);
      OE_QUIT;
    end;
    // no button
    if Col_PointInAABB( Mouse_X, Mouse_Y, @no.rect ) and (no.alpha < 254)
    then no.alpha := no.alpha + 3;
    if (Col_PointInAABB( Mouse_X, Mouse_Y, @no.rect ) = false) and (no.alpha >= 3)
    then no.alpha := no.alpha - 3;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @no.Rect ) then
    begin
      if no.play and (MuteSounds_check.check = false) then Snd_Play(button_snd, 1, volume(sounds_volume2), 50, false);
      no.play := false
    end else
    begin
      no.play := true;
    end;
    if Col_PointInAABB( Mouse_X, Mouse_Y, @no.rect ) and Mouse_Click( M_LBUTTON ) then
    begin
      if MuteSounds_Check.check = false then Snd_Play(click_snd, 1, volume(sounds_volume2), 50, false);
      Message_BlackDir := 2;
    end;
  end;
  end;
end;

// Отрисовка
procedure Menu_Paint;
var
i: integer;
begin
  SSprite_Draw( Back, -10, -10, 815, 615, 255, 0, FX_DEFAULT );
  if ShowGears then Balls_Paint;
  if ShowFPS then Text_Draw( Font[0], 10, 10, PChar('FPS: '+U_IntToStr(FPS)));
  //Text_Draw( Font[0], 10, 40, PChar('X: '+U_IntToStr(Mouse_X)+',Y: '+U_IntToStr(Mouse_Y)));
  //Text_Draw( Font[0], 10, 40, PChar('Brightness: '+U_IntToStr(Brightness)));
  //Text_Draw( Font[0], 10, 40, PChar('X: '+U_IntToStr(Music_Bar.move_x)));
  //Text_Draw( Font[0], 10, 40, PChar('Alpha: '+U_IntToStr(Round(NewGame.alpha))));
  //Text_Draw( Font[0], 10, 10, PChar('Test: '+U_IntToStr(Test)));
  //Pr2D_TRect( @FullScreen_Check.rect, $FEDECF, 255, PR_DEFAULT );
  //Pr2D_TRect( @Music_Bar.rect, $FEDECF, 255, PR_DEFAULT );
  SSprite_Draw( Title, 140, 50, 520, 100, 255, 0, FX_DEFAULT );
  //SSprite_Draw( Neko, 20, 450, 160, 130, 255, 0, FX_DEFAULT );
  //SSprite_Draw( Neko2, 620, 450, 160, 130, 255, 0, FX_DEFAULT );
  {case Nick_LabelType of
  1: Text_Draw( Font[0], ((800 - test) / 2) + 2, 150, PChar('Welcome, '+String(Nick)));
  2: Text_Draw( Font[1], ((800 - test) / 2) + 2, 150, PChar('Welcome, '+String(Nick)));
  end;}
  case Menu_Scene of
  sMain:
  begin
    case Nick_LabelType of
    1:
    begin
      Text_Draw( Font[0], ((800 - test) / 2) + 2, 150, PChar('Welcome, '+Key_EndReadText+'|'), 1, 0, 255 - Nick_LabelAlpha);
      if Nick_LabelAlpha > 0 then Text_Draw( Font[1], ((800 - test) / 2) + 2, 150, PChar('Welcome, '+Key_EndReadText+'|'), 1 , 0, Nick_LabelAlpha );
    end;
    2:
    begin
      Text_Draw( Font[0], ((800 - test) / 2) + 2, 150, PChar('Welcome, '+String(Nick)), 1, 0, 255 - Nick_LabelAlpha);
      if Nick_LabelAlpha > 0 then Text_Draw( Font[1], ((800 - test) / 2) + 2, 150, PChar('Welcome, '+String(Nick)), 1 , 0, Nick_LabelAlpha );
    end;
    end;
    //Pr2D_TRect( @Nick_Rect, $FEDECF );
    // Кнопки
    // NewGame
    //Pr2D_TRect( @NewGame.rect, $FEDECF, 255, PR_DEFAULT );
    SSprite_Draw( NewGame.tex[0], NewGame.rect.X, NewGame.rect.Y, NewGame.rect.Width, NewGame.rect.Height, 255, 0, FX_DEFAULT );
    if NewGame.alpha > 0 then SSprite_Draw( NewGame.tex[1], NewGame.rect.X, NewGame.rect.Y, NewGame.rect.Width, NewGame.rect.Height, NewGame.alpha, 0, FX_DEFAULT );
    // TopScores
    SSprite_Draw( TopScores.tex[0], TopScores.rect.X, TopScores.rect.Y, TopScores.rect.Width, TopScores.rect.Height, 255, 0, FX_DEFAULT );
    if TopScores.alpha > 0 then SSprite_Draw( TopScores.tex[1], TopScores.rect.X, TopScores.rect.Y, TopScores.rect.Width, TopScores.rect.Height, TopScores.alpha, 0, FX_DEFAULT );
    // Options
    SSprite_Draw( Options.tex[0], Options.rect.X, Options.rect.Y, Options.rect.Width, Options.rect.Height, 255, 0, FX_DEFAULT );
    if Options.alpha > 0 then SSprite_Draw( Options.tex[1], Options.rect.X, Options.rect.Y, Options.rect.Width, Options.rect.Height, Options.alpha, 0, FX_DEFAULT );
    // About
    SSprite_Draw( About.tex[0], About.rect.X, About.rect.Y, About.rect.Width, About.rect.Height, 255, 0, FX_DEFAULT );
    if About.alpha > 0 then SSprite_Draw( About.tex[1], About.rect.X, About.rect.Y, About.rect.Width, About.rect.Height, About.alpha, 0, FX_DEFAULT );
    // Quit
    SSprite_Draw( Quit.tex[0], Quit.rect.X, Quit.rect.Y, Quit.rect.Width, Quit.rect.Height, 255, 0, FX_DEFAULT );
    if Quit.alpha > 0 then SSprite_Draw( Quit.tex[1], Quit.rect.X, Quit.rect.Y, Quit.rect.Width, Quit.rect.Height, Quit.alpha, 0, FX_DEFAULT );
    // Курсор
  end;
  sOptions:
  begin
    // Music bar
    Text_Draw( Font[0], 300, 200, PChar('Music vоlume'));
    SSprite_Draw( Music_Bar.bar_tex, 234, 245, 330, 14, 255, 0, FX_DEFAULT );
    SSprite_Draw( Music_Bar.scrollbutton_tex[0], Music_Bar.move_x, 231, 28, 42, 255, 0, FX_DEFAULT );
    if Music_Bar.alpha > 0 then SSprite_Draw( Music_Bar.scrollbutton_tex[1], Music_Bar.move_x, 231, 28, 42, Music_Bar.alpha, 0, FX_DEFAULT );
    // Sounds bar
    Text_Draw( Font[0], 290, 290, PChar('Sounds vоlume'));
    SSprite_Draw( Sounds_Bar.bar_tex, 234, 335, 330, 14, 255, 0, FX_DEFAULT );
    SSprite_Draw( Sounds_Bar.scrollbutton_tex[0], Sounds_Bar.move_x, 321, 28, 42, 255, 0, FX_DEFAULT );
    if Sounds_Bar.alpha > 0 then SSprite_Draw( Sounds_Bar.scrollbutton_tex[1], Sounds_Bar.move_x, 321, 28, 42, Sounds_Bar.alpha, 0, FX_DEFAULT );
    // MuteSounds_Check
    SSprite_Draw( MuteSounds_Check.buttons[0], 235, 380, 36, 36, 255, 0, FX_DEFAULT );
    if MuteSounds_Check.alpha > 0 then SSprite_Draw( MuteSounds_Check.buttons[1], 235, 380, 36, 36, MuteSounds_Check.alpha, 0, FX_DEFAULT );
    if MuteSounds_Check.check then SSprite_Draw( MuteSounds_Check.check_tex, 235, 380, 36, 36, 255, 0, FX_DEFAULT );
    Text_Draw( Font[0], 285, 384, PChar('Mute all sounds'));
    // Back
    SSprite_Draw( RBack.tex[0], RBack.rect.X, RBack.rect.Y, RBack.rect.Width, RBack.rect.Height, 255, 0, FX_DEFAULT );
    if RBack.alpha > 0 then SSprite_Draw( RBack.tex[1], RBack.rect.X, RBack.rect.Y, RBack.rect.Width, RBack.rect.Height, RBack.alpha, 0, FX_DEFAULT );
  end;
  sOptions2:
  begin
    // Music bar
    Text_Draw( Font[0], 315, 200, PChar('Brightness'));
    SSprite_Draw( Brightness_Bar.bar_tex, 234, 245, 330, 14, 255, 0, FX_DEFAULT );
    SSprite_Draw( Brightness_Bar.scrollbutton_tex[0], Brightness_Bar.move_x, 231, 28, 42, 255, 0, FX_DEFAULT );
    if Brightness_Bar.alpha > 0 then SSprite_Draw( Brightness_Bar.scrollbutton_tex[1], Brightness_Bar.move_x, 231, 28, 42, Brightness_Bar.alpha, 0, FX_DEFAULT );
    // Back
    SSprite_Draw( RBack.tex[0], RBack.rect.X, RBack.rect.Y, RBack.rect.Width, RBack.rect.Height, 255, 0, FX_DEFAULT );
    if RBack.alpha > 0 then SSprite_Draw( RBack.tex[1], RBack.rect.X, RBack.rect.Y, RBack.rect.Width, RBack.rect.Height, RBack.alpha, 0, FX_DEFAULT );
    // ShowFPS_Check
    SSprite_Draw( ShowFPS_Check.buttons[0], 235, 285, 36, 36, 255, 0, FX_DEFAULT );
    if ShowFPS_Check.alpha > 0 then SSprite_Draw( ShowFPS_Check.buttons[1], 235, 285, 36, 36, ShowFPS_Check.alpha, 0, FX_DEFAULT );
    if ShowFPS_Check.check then SSprite_Draw( ShowFPS_Check.check_tex, 235, 285, 36, 36, 255, 0, FX_DEFAULT );
    Text_Draw( Font[0], 285, 289, PChar('Show FPS'));
    // ShowGears_Check
    SSprite_Draw( ShowGears_Check.buttons[0], 235, 335, 36, 36, 255, 0, FX_DEFAULT );
    if ShowGears_Check.alpha > 0 then SSprite_Draw( ShowGears_Check.buttons[1], 235, 335, 36, 36, ShowGears_Check.alpha, 0, FX_DEFAULT );
    if ShowGears_Check.check then SSprite_Draw( ShowGears_Check.check_tex, 235, 335, 36, 36, 255, 0, FX_DEFAULT );
    Text_Draw( Font[0], 285, 339, PChar('Show gears'));
    // Fullscreen_Check
    SSprite_Draw( Fullscreen_Check.buttons[0], 235, 385, 36, 36, 255, 0, FX_DEFAULT );
    if Fullscreen_Check.alpha > 0 then SSprite_Draw( Fullscreen_Check.buttons[1], 235, 385, 36, 36, Fullscreen_Check.alpha, 0, FX_DEFAULT );
    if Fullscreen_Check.check then SSprite_Draw( Fullscreen_Check.check_tex, 235, 385, 36, 36, 255, 0, FX_DEFAULT );
    Text_Draw( Font[0], 285, 389, PChar('Fullscreen'));
  end;
  sSelOptions:
  begin
    // BigSounds button
    SSprite_Draw( BigSounds.tex[0], BigSounds.rect.X, BigSounds.rect.Y, BigSounds.rect.Width, BigSounds.rect.Height, 255, 0, FX_DEFAULT );
    if BigSounds.alpha > 0 then SSprite_Draw( BigSounds.tex[1], BigSounds.rect.X, BigSounds.rect.Y, BigSounds.rect.Width, BigSounds.rect.Height, BigSounds.alpha, 0, FX_DEFAULT );
    // BigOther button
    SSprite_Draw( BigOther.tex[0], BigOther.rect.X, BigOther.rect.Y, BigOther.rect.Width, BigOther.rect.Height, 255, 0, FX_DEFAULT );
    if BigOther.alpha > 0 then SSprite_Draw( BigOther.tex[1], BigOther.rect.X, BigOther.rect.Y, BigOther.rect.Width, BigOther.rect.Height, BigOther.alpha, 0, FX_DEFAULT );
    // Back
    SSprite_Draw( RBack.tex[0], RBack.rect.X, RBack.rect.Y, RBack.rect.Width, RBack.rect.Height, 255, 0, FX_DEFAULT );
    if RBack.alpha > 0 then SSprite_Draw( RBack.tex[1], RBack.rect.X, RBack.rect.Y, RBack.rect.Width, RBack.rect.Height, RBack.alpha, 0, FX_DEFAULT );
  end;
  sInfo:
  begin
    // BigAbout button
    SSprite_Draw( BigAbout.tex[0], BigAbout.rect.X, BigAbout.rect.Y, BigAbout.rect.Width, BigAbout.rect.Height, 255, 0, FX_DEFAULT );
    if BigAbout.alpha > 0 then SSprite_Draw( BigAbout.tex[1], BigAbout.rect.X, BigAbout.rect.Y, BigAbout.rect.Width, BigAbout.rect.Height, BigAbout.alpha, 0, FX_DEFAULT );
    // BigHelp button
    SSprite_Draw( BigHelp.tex[0], BigHelp.rect.X, BigHelp.rect.Y, BigHelp.rect.Width, BigHelp.rect.Height, 255, 0, FX_DEFAULT );
    if BigHelp.alpha > 0 then SSprite_Draw( BigHelp.tex[1], BigHelp.rect.X, BigHelp.rect.Y, BigHelp.rect.Width, BigHelp.rect.Height, BigHelp.alpha, 0, FX_DEFAULT );
    // Back
    SSprite_Draw( RBack.tex[0], RBack.rect.X, RBack.rect.Y, RBack.rect.Width, RBack.rect.Height, 255, 0, FX_DEFAULT );
    if RBack.alpha > 0 then SSprite_Draw( RBack.tex[1], RBack.rect.X, RBack.rect.Y, RBack.rect.Width, RBack.rect.Height, RBack.alpha, 0, FX_DEFAULT );
  end;
  sAbout:
  begin
    //Text_Draw( Font[0], 305, 200, PChar('Pipes Tetris'));
    //Text_Draw( Font[0], 270, 250, PChar('Special fоr IGDC'));
    //Text_Draw( Font[0], 300, 300, PChar('Cоde by Gluk'));
    //Text_Draw( Font[0], 295, 350, PChar('Omega Engine'));
    //Text_Draw( Font[0], 335, 400, PChar('by Andru'));
    for i := 0 to 17 do
    begin
      Text_Draw( Font[0], ((800 - strings[i].x) / 2) + 2, round(strings[i].y), PChar(String(strings[i].text)), 1, 0, round(strings[i].alpha));
    end;
    // Back
    SSprite_Draw( RBack.tex[0], RBack.rect.X, RBack.rect.Y, RBack.rect.Width, RBack.rect.Height, 255, 0, FX_DEFAULT );
    if RBack.alpha > 0 then SSprite_Draw( RBack.tex[1], RBack.rect.X, RBack.rect.Y, RBack.rect.Width, RBack.rect.Height, RBack.alpha, 0, FX_DEFAULT );
  end;
  sHelp:
  begin
    {Text_Draw( Font[0], round(((800 - Text_GetWidth( Font[0], PChar
    ('Build a pipeline'), 1, 1 )) / 2) + 2), 160, PChar('Build a pipeline'));
    Text_Draw( Font[1], round(((800 - Text_GetWidth( Font[0], PChar
    ('and collect points =)'), 1, 1 )) / 2) + 2), 200, PChar('and collect points =)'));
    Text_Draw( Font[0], round(((800 - Text_GetWidth( Font[0], PChar
    ('buttons controls:'), 1, 1 )) / 2) + 2), 240, PChar('buttons controls:'));
    Text_Draw( Font[1], round(((800 - Text_GetWidth( Font[0], PChar
    ('left - move left'), 1, 1 )) / 2) + 2), 280, PChar('left - move left'));
    Text_Draw( Font[0], round(((800 - Text_GetWidth( Font[0], PChar
    ('right - move right'), 1, 1 )) / 2) + 2), 320, PChar('right - move right'));
    Text_Draw( Font[1], round(((800 - Text_GetWidth( Font[0], PChar
    ('up - rotate figure'), 1, 1 )) / 2) + 2), 360, PChar('up - rotate figure'));
    Text_Draw( Font[0], round(((800 - Text_GetWidth( Font[0], PChar
    ('space - set figure'), 1, 1 )) / 2) + 2), 400, PChar('space - set figure'));
    Text_Draw( Font[1], round(((800 - Text_GetWidth( Font[0], PChar
    ('g - show\hide greed'), 1, 1 )) / 2) + 2), 440, PChar('g - show\hide greed'));}
    for i := 0 to 15 do
    begin
      Text_Draw( Font[0], ((800 - strings2[i].x) / 2) + 2, round(strings2[i].y), PChar(String(strings2[i].text)), 1, 0, round(strings2[i].alpha));
    end;
    // Back
    SSprite_Draw( RBack.tex[0], RBack.rect.X, RBack.rect.Y, RBack.rect.Width, RBack.rect.Height, 255, 0, FX_DEFAULT );
    if RBack.alpha > 0 then SSprite_Draw( RBack.tex[1], RBack.rect.X, RBack.rect.Y, RBack.rect.Width, RBack.rect.Height, RBack.alpha, 0, FX_DEFAULT );
  end;
  sTop:
  begin
    Text_Draw( Font[0], round(((800 - Text_GetWidth( Font[0], PChar(String(top_scores[0].nick)+'-'+U_IntToStr(top_scores[0].Points)), 1, 1 )) / 2) + 2), 200, PChar(String(top_scores[0].nick)+'-'+U_IntToStr(top_scores[0].Points)));
    Text_Draw( Font[0], round(((800 - Text_GetWidth( Font[0], PChar(String(top_scores[1].nick)+'-'+U_IntToStr(top_scores[1].Points)), 1, 1 )) / 2) + 2), 250, PChar(String(top_scores[1].nick)+'-'+U_IntToStr(top_scores[1].Points)));
    Text_Draw( Font[0], round(((800 - Text_GetWidth( Font[0], PChar(String(top_scores[2].nick)+'-'+U_IntToStr(top_scores[2].Points)), 1, 1 )) / 2) + 2), 300, PChar(String(top_scores[2].nick)+'-'+U_IntToStr(top_scores[2].Points)));
    Text_Draw( Font[0], round(((800 - Text_GetWidth( Font[0], PChar(String(top_scores[3].nick)+'-'+U_IntToStr(top_scores[3].Points)), 1, 1 )) / 2) + 2), 350, PChar(String(top_scores[3].nick)+'-'+U_IntToStr(top_scores[3].Points)));
    Text_Draw( Font[0], round(((800 - Text_GetWidth( Font[0], PChar(String(top_scores[4].nick)+'-'+U_IntToStr(top_scores[4].Points)), 1, 1 )) / 2) + 2), 400, PChar(String(top_scores[4].nick)+'-'+U_IntToStr(top_scores[4].Points)));
    // Back
    SSprite_Draw( RBack.tex[0], RBack.rect.X, RBack.rect.Y, RBack.rect.Width, RBack.rect.Height, 255, 0, FX_DEFAULT );
    if RBack.alpha > 0 then SSprite_Draw( RBack.tex[1], RBack.rect.X, RBack.rect.Y, RBack.rect.Width, RBack.rect.Height, RBack.alpha, 0, FX_DEFAULT );
  end;
  sMessage:
  begin
    case Nick_LabelType of
    1:
    begin
      Text_Draw( Font[0], ((800 - test) / 2) + 2, 150, PChar('Welcome, '+Key_EndReadText+'|'), 1, 0, 255 - Nick_LabelAlpha);
      if Nick_LabelAlpha > 0 then Text_Draw( Font[1], ((800 - test) / 2) + 2, 150, PChar('Welcome, '+Key_EndReadText+'|'), 1 , 0, Nick_LabelAlpha );
    end;
    2:
    begin
      Text_Draw( Font[0], ((800 - test) / 2) + 2, 150, PChar('Welcome, '+String(Nick)), 1, 0, 255 - Nick_LabelAlpha);
      if Nick_LabelAlpha > 0 then Text_Draw( Font[1], ((800 - test) / 2) + 2, 150, PChar('Welcome, '+String(Nick)), 1 , 0, Nick_LabelAlpha );
    end;
    end;
    SSprite_Draw( NewGame.tex[0], NewGame.rect.X, NewGame.rect.Y, NewGame.rect.Width, NewGame.rect.Height, 255, 0, FX_DEFAULT );
    if NewGame.alpha > 0 then SSprite_Draw( NewGame.tex[1], NewGame.rect.X, NewGame.rect.Y, NewGame.rect.Width, NewGame.rect.Height, NewGame.alpha, 0, FX_DEFAULT );
    // TopScores
    SSprite_Draw( TopScores.tex[0], TopScores.rect.X, TopScores.rect.Y, TopScores.rect.Width, TopScores.rect.Height, 255, 0, FX_DEFAULT );
    if TopScores.alpha > 0 then SSprite_Draw( TopScores.tex[1], TopScores.rect.X, TopScores.rect.Y, TopScores.rect.Width, TopScores.rect.Height, TopScores.alpha, 0, FX_DEFAULT );
    // Options
    SSprite_Draw( Options.tex[0], Options.rect.X, Options.rect.Y, Options.rect.Width, Options.rect.Height, 255, 0, FX_DEFAULT );
    if Options.alpha > 0 then SSprite_Draw( Options.tex[1], Options.rect.X, Options.rect.Y, Options.rect.Width, Options.rect.Height, Options.alpha, 0, FX_DEFAULT );
    // About
    SSprite_Draw( About.tex[0], About.rect.X, About.rect.Y, About.rect.Width, About.rect.Height, 255, 0, FX_DEFAULT );
    if About.alpha > 0 then SSprite_Draw( About.tex[1], About.rect.X, About.rect.Y, About.rect.Width, About.rect.Height, About.alpha, 0, FX_DEFAULT );
    // Quit
    SSprite_Draw( Quit.tex[0], Quit.rect.X, Quit.rect.Y, Quit.rect.Width, Quit.rect.Height, 255, 0, FX_DEFAULT );
    if Quit.alpha > 0 then SSprite_Draw( Quit.tex[1], Quit.rect.X, Quit.rect.Y, Quit.rect.Width, Quit.rect.Height, Quit.alpha, 0, FX_DEFAULT );
    /////////////////////////////////////////////////
    SSprite_Draw( Black_message, -10, -10, 815, 615, Round(message_blackalpha), 0, FX_DEFAULT );
    SSprite_Draw( message_panel, 215, 200, 370, 200, Round(message_alpha), 0, FX_DEFAULT );
    Text_Draw( Font[1], 256, 220, PChar('Do you really want'), 1, 0, Round(message_alpha));
    Text_Draw( Font[1], 301, 260, PChar('a quit game?'), 1, 0, Round(message_alpha));
    // yes button
    SSprite_Draw( yes.tex[0], yes.rect.X, yes.rect.Y, yes.rect.Width, yes.rect.Height, 255 - (255 - message_alpha), 0, FX_DEFAULT );
    if yes.alpha > 0 then SSprite_Draw( yes.tex[1], yes.rect.X, yes.rect.Y, yes.rect.Width, yes.rect.Height, yes.alpha - (255 - message_alpha), 0, FX_DEFAULT );
    // no button
    SSprite_Draw( no.tex[0], no.rect.X, no.rect.Y, no.rect.Width, no.rect.Height, 255 - (255 - message_alpha), 0, FX_DEFAULT );
    if no.alpha > 0 then
    begin
      case Message_BlackDir of
        1:SSprite_Draw( no.tex[1], no.rect.X, no.rect.Y, no.rect.Width, no.rect.Height, no.alpha - (255 - message_alpha), 0, FX_DEFAULT );
        2:SSprite_Draw( no.tex[1], no.rect.X, no.rect.Y, no.rect.Width, no.rect.Height, message_alpha, 0, FX_DEFAULT );
      end;
    end;
    /////////////////////////////////////////////////
  end;
  end;
  SSprite_Draw( Cursor, Mouse_X, Mouse_Y, 50, 50, 255, 0, FX_DEFAULT );
  SSprite_Draw( Cursor_Color, Mouse_X, Mouse_Y, 50, 50, Round(Cursor_ColorAlpha), 0, FX_DEFAULT );
  // Brightness
  if Brightness < 50 then SSprite_Draw( BrightTex[0], -10, -10, 815, 615, 150 - (Brightness * 3), 0, FX_DEFAULT );
  if Brightness > 50 then SSprite_Draw( BrightTex[1], -10, -10, 815, 615, Round((Brightness - 50) * 1.5), 0, FX_DEFAULT );
  if Black_Menu.enable then SSprite_Draw( Black_Menu.tex, -10, -10, 815, 615, Black_Menu.alpha, 0, FX_DEFAULT );
  if Black_Screen then SSprite_Draw( Black, -10, -10, 815, 615, Round(Black_Alpha), 0, FX_DEFAULT );
  //OE_SetWndName( PChar('FPS: '+U_IntToStr(FPS)) );
end;

end.

