unit SD_menu;

interface

const
  MofOB = 9;

type
  tMenuButton = class
    X, Y, W, H, T, N : Integer;
    MD : Boolean;
    NS : string;
    function MouseInB : Boolean;
    procedure Draw;
  end;

  tSetupMenu = class
    OptionButton : array[1..MofOB] of tMenuButton;
    procedure Draw;
    procedure Work;
    procedure GetOpt;
    procedure GetRealOpt;
    procedure Init;
  end;

implementation

uses
  zglHeader, Setup, uMaterials, u_Menu,
  LexUtils, GSound;
var
  fWinW, fWinH : Integer;
  ffVSync : Boolean;
const
  OptBNS  : array[1..MofOB] of string= ('1024x768', '1280x800', '1280x1024', 'Текущее',
                                        'В окне',
                                        'Вертикальная синхронизация',
                                        'Рисовать облака',
                                        'Применить', 'Отмена');

function tMenuButton.MouseInB;
begin
  if  (mouse_X > X)
  and (mouse_Y > Y)
  and (mouse_X < X + W)
  and (mouse_Y < Y + H) then
    Result := True
  else
    Result := False;
  MD := Result;
end;

procedure tSetupMenu.GetOpt;
var
  I : Integer;
begin
  for I := 1 to MofOB do
  OptionButton[I].NS := OptBNS[I];

  if (fWinW = 1024) and (fWinH = 768) then  I := 1 else
  if (fWinW = 1280) and (fWinH = 800) then  I := 2 else
  if (fWinW = 1280) and (fWinH = 1024) then I := 3 else
  I := 4;
  if FullMonitor then
    I := 4;

  if I > 0 then
    OptionButton[I].NS := '#' + OptBNS[I] + '#';

  if FullWin then
    OptionButton[5].NS := '# Полноэкранный режим #';

  if VSync then
    OptionButton[6].NS := '# ' + OptBNS[6] + ' #';

  if SkyDraw then
    OptionButton[7].NS := '# ' + OptBNS[7] + ' #';
end;

procedure tSetupMenu.GetRealOpt;
begin
  fWinW  := WinW;
  fWinH  := WinH;
end;

procedure tSetupMenu.Init;
var
  sBW  : Integer;
  I, S : Integer;
begin
  for I := 1 to MofOB do
  OptionButton[I] := tMenuButton.Create;

  sBW := WinW div 5;

  for I := 1 to 4 do
  with OptionButton[I] do
  begin
    X := round(I * sBW - sBW / 2);
    Y := (WinH - sBW) div 2 - 64;
    W := round(sBW - 16);
    H := round(sBW / 5);
  end;

  sBW := trunc(WinW / 2.2);

  for I := 5 to 7 do
  with OptionButton[I] do
  begin
    X := round((WinW - sBW) / 2);
    Y := round(OptionButton[1].Y + 8 + (sBW / 10 + 8) * (I - 4) );
    W := round(sBW - 16);
    H := OptionButton[1].H;
  end;

  sBW := WInW div 3;
  for I := 8 to 9 do
  with OptionButton[I] do
  begin
    Y := round(OptionButton[7].Y + 2.5 * OptionButton[1].H);
    W := round(sBW - 16);
    H := OptionButton[1].H;
    OptionButton[I].NS := OptBNS[I];
  end;

  OptionButton[8].X := round( WinW / 2 - sBW);
  OptionButton[9].X := round( WinW / 2 + 16);

  GetRealOpt;
  GetOpt;
end;

procedure tSetupMenu.Draw;
var
  I : Integer;
begin
  for I := 1 to MofOB do
     OptionButton[I].Draw;
end;

procedure tSetupMenu.Work;
var
  I, BLevel,
  iDo : Integer;
begin
  iDo := 0;
  BLevel := 1;

  for I := 1 to MofOB do
  if (OptionButton[I].MouseInB) then
    iDo := 30 + I;

  if  (iDo > 0)
  and mouse_Click(M_BLEFT) then
  begin
    PlaySound(7);
    case iDo of
      31 : begin
             fWinW := 1024;
             fWinH := 768;
             FullMonitor := False;
           end;
      32 : begin
             fWinW := 1280;
             fWinH := 800;
             FullMonitor := False;
           end;
      33 : begin
             fWinW := 1280;
             fWinH := 1024;
             FullMonitor := False;
           end;
      34 : begin
             FullMonitor := True;
           end;
      35 : FullWin := not FullWin;
      36 : VSync   := not VSync;
      37 : SkyDraw := not SkyDraw;
      38 : begin
             WinW := fWinW;
             WinH := fWinH;
             Setup.SaveSetupFile;
             Menu.S := 0;
           end;
      39 : begin
             Setup.LoadSetupFile;
             GetRealOpt;
             Menu.S := 0;
           end;
    end;

    if iDo > 30 then
      GetOpt;
  end;

  if Key_Press(k_Escape) then
  begin
    Menu.S := 0;
  end;  
end;

procedure tMenuButton.Draw;
begin
  if MD then
    Pr2D_Rect(X + 3, Y + 7, W - 6, H - 14, $FFD0D9, 150, PR2D_FILL);
  Pr2D_Rect(X, Y, W, H, $C05070, 200, PR2D_FILL);
  Pr2D_Rect(X, Y, W, H, $FFFFFF, 220, 0);

  Text_DrawEx(mFont_1, X + W div 2, Y + (H-24) div 2 + 2, 0.8, 0, AnsiToUtf8(NS), $F0, $FFFFFF, TEXT_HALIGN_CENTER );
end;
     {
procedure Init;
begin
  if SetupMenu <> nil then
    SetupMenu.Free;
  SetupMenu := tSetupMenu.Create;
  SetupMenu.Init;
end;

procedure Work;
begin
  SetupMenu.Work;
end;

procedure Draw;
begin
  SetupMenu.Draw
end;  }

end.
