unit gui;

interface

uses flat_button, variables, sysutils, files_names, textures, constants,
     upgrade_window;

function CheckInterface(mx, my, mode : integer) : boolean;
procedure CreateInterface;
procedure RedrawInterface(mode : integer);

implementation

function CheckInterface(mx, my, mode : integer) : boolean;
var
i : integer;
begin
result := true;
for i := 1 to total_buttons do
  with buttons[i] do
    if (mx >= x) and (mx <= x + width) and
       (my >= y) and (my <= y + height) then
         if visible then
           begin
             case mode of
               1 : Move(i);
               2 : if click_by_gui and
                     (not upgrades_showed) and (not bonuses_showed) then Click(i)
                   else
                     case i of
                       14 : begin
                              SetUpgradesForSelected;
                              if selected_tower <> 0 then upgrades_showed := true;
                            end;
                       15..17 : BuyUpgrade(i - 14);
                       18 : begin upgrades_showed := false; bonuses_showed := false; end;
                       26 : begin
                              SetBonuses;
                              bonuses_showed := true;
                            end;
                     end;
             end;
             exit;
           end;
result := false;
end;

procedure CreateTopPanel;
var
p : integer;
begin
p := screen_width div 10;

buttons[5] := TFlatButton.Create(5, 5 + p * 0, 5, 32, 32, gui_clock_id);
buttons[5].hint := 'Текущее время [ чч : мм ]';
buttons[5].colorize := false;
buttons[6] := TFlatButton.Create(6, 5 + p * 1, 5, 32, 32, gui_time_scale_id);
buttons[6].hint := 'Масштабирование времени [ мин / сек ]';
buttons[6].colorize := false;
buttons[7] := TFlatButton.Create(7, 5 + p * 2, 5, 32, 32, gui_next_wave_id);
buttons[7].hint := 'Следующая волна [ чч : мм ]';
buttons[7].colorize := false;

buttons[8] := TFlatButton.Create(8, 5 + p * 4, 5, 32, 32, gui_money_id);
buttons[8].hint := 'Деньги [ кр. ]';
buttons[8].colorize := false;
buttons[9] := TFlatButton.Create(9, 5 + p * 5, 5, 32, 32, gui_score_id);
buttons[9].hint := 'Очки [ оч. ]';
buttons[9].colorize := false;

buttons[10] := TFlatButton.Create(10, 5 + p * 7, 5, 32, 32, gui_enemys_life_id);
buttons[10].hint := 'Живых врагов';
buttons[10].colorize := false;
buttons[11] := TFlatButton.Create(11, 5 + p * 8, 5, 32, 32, gui_enemys_kill_id);
buttons[11].hint := 'Убито врагов';
buttons[11].colorize := false;      
buttons[12] := TFlatButton.Create(12, 5 + p * 9, 5, 32, 32, gui_enemys_miss_id);
buttons[12].hint := 'Пропущено врагов';
buttons[12].colorize := false;
end;

procedure CreateBottomPanel;
var
p : integer;
begin
p := screen_width div 10;

buttons[20] := TFlatButton.Create(20, 47 + p * 0, screen_height - 37, 32, 32, gui_health_id);
buttons[20].hint := 'Сортировка целей';

buttons[21] := TFlatButton.Create(21, 47 + p * 2, screen_height - 37, 32, 32, gui_radius_id);
buttons[21].hint := 'Радиус';
buttons[21].colorize := false;

buttons[22] := TFlatButton.Create(22, 47 + p * 3, screen_height - 37, 32, 32, gui_shoot_speed_id);
buttons[22].hint := 'Скорострельность';
buttons[22].colorize := false;

buttons[23] := TFlatButton.Create(23, 47 + p * 4, screen_height - 37, 32, 32, gui_health_id);
buttons[23].hint := 'Урон здоровью';
buttons[23].colorize := false;

buttons[24] := TFlatButton.Create(24, 47 + p * 5, screen_height - 37, 32, 32, gui_damage_id);
buttons[24].hint := 'Урон силе';
buttons[24].colorize := false;

buttons[25] := TFlatButton.Create(25, 47 + p * 6, screen_height - 37, 32, 32, gui_speed_id);
buttons[25].hint := 'Урон скорости';
buttons[25].colorize := false;

buttons[27] := TFlatButton.Create(27, 47 + p * 8, screen_height - 37, 32, 32, gui_base_health_id);
buttons[27].hint := 'Здоровье базы';
buttons[27].colorize := false;
end;

procedure CreateLeftPanel;
var
p : integer;
begin
p := screen_width div 20;

buttons[1] := TFlatButton.Create(1, 5, p * 1 + 42, 32, 32, gui_cancel_id);
buttons[1].hint := 'Отмена';

buttons[2] := TFlatButton.Create(2, 5, p * 2 + 42, 32, 32, gui_tower_small_id);
buttons[3] := TFlatButton.Create(3, 5, p * 3 + 42, 32, 32, gui_tower_middle_id);
buttons[4] := TFlatButton.Create(4, 5, p * 4 + 42, 32, 32, gui_tower_big_id);

buttons[13] := TFlatButton.Create(13, 5, screen_height - p * 2 - 37, 32, 32, gui_cancel_id);
buttons[13].hint := 'Выбранная башня';

buttons[14] := TFlatButton.Create(14, 5, screen_height - p * 1 - 37, 32, 32, gui_upgrade_id);
buttons[14].hint := 'Улучшения';
buttons[14].click_by_gui := false;

buttons[19] := TFlatButton.Create(19, 5, screen_height - p * 0 - 37, 32, 32, gui_one_id);
buttons[19].hint := 'Выбор оружия';

buttons[26] := TFlatButton.Create(26, 5, p * 8, 32, 32, gui_bonus_id);
buttons[26].hint := 'Бонусы';
buttons[26].click_by_gui := false;
end;

procedure LoadNewElement(i : integer; file_name : string);
begin
if (i < 1) or (i > max_buttons_textures) then exit;
all_buttons_textures[i] := TTexture.create(gui_folder + file_name);
end;

procedure CreateInterface;
begin
LoadNewElement(gui_cancel_id,       gui_cancel);
LoadNewElement(gui_tower_small_id,  gui_tower_small);
LoadNewElement(gui_tower_middle_id, gui_tower_middle);
LoadNewElement(gui_tower_big_id,    gui_tower_big);
LoadNewElement(gui_clock_id,        gui_clock);
LoadNewElement(gui_time_scale_id,   gui_time_scale);
LoadNewElement(gui_next_wave_id,    gui_next_wave);
LoadNewElement(gui_money_id,        gui_money);
LoadNewElement(gui_score_id,        gui_score);
LoadNewElement(gui_upgrade_id,      gui_upgrade);
LoadNewElement(gui_one_id,          gui_one);
LoadNewElement(gui_two_id,          gui_two);
LoadNewElement(gui_three_id,        gui_three);
LoadNewElement(gui_radius_id,       gui_radius);
LoadNewElement(gui_shoot_speed_id,  gui_shoot_speed);
LoadNewElement(gui_health_id,       gui_health);
LoadNewElement(gui_damage_id,       gui_damage);
LoadNewElement(gui_speed_id,        gui_speed);
LoadNewElement(gui_enemys_life_id,  gui_enemys_life);
LoadNewElement(gui_enemys_kill_id,  gui_enemys_kill);
LoadNewElement(gui_enemys_miss_id,  gui_enemys_miss);
LoadNewElement(gui_bonus_id,        gui_bonus);
LoadNewElement(gui_base_health_id,  gui_base_health);
LoadNewElement(gui_light_id,        gui_light);
LoadNewElement(gui_target_id,       gui_target);

CreateTopPanel;
CreateBottomPanel;
CreateLeftPanel;

SetUpgradeWindow;
end;

procedure RedrawInterface(mode : integer);
var
i : integer;
begin
RedrawUpgradeWindow;

buttons[1].enabled := true;
buttons[2].enabled := true;
buttons[3].enabled := true;
buttons[4].enabled := true;
buttons[tower_creation_mode + 1].enabled := false;
buttons[13].enabled := selected_tower <> 0;
buttons[14].enabled := selected_tower <> 0;
buttons[19].enabled := selected_tower <> 0;
buttons[20].enabled := selected_tower <> 0;

for i := 1 to total_buttons do
  if buttons[i].draw_by_gui then buttons[i].Redraw(mode);
end;

end.
