loadresource("data\\main-menu.jpg","main",1);

function DeleteCurrentSave()
    username = GetSelectedUser();
    savepath = GetSavePath() .. username .. ".sav";
    -- messagebox(savepath);
    os.remove( savepath );
return; end;

--addstaticobjecttogame(1000,"menu2",175,21,"",640,0,340,139);

function UserClick(ncount)
 MenuEffects(false)
end;

function OnOk(ncount)
 MenuEffects(true)
end;

function DelMenu()
    del_object_from_game(1001)
    del_object_from_game(4000)
    del_object_from_game(4001)
    del_object_from_game(4002)
    del_object_from_game(4003)
    del_object_from_game(4004)
        del_object_from_game(4005)
    del_object_from_game(5000)
    del_object_from_game(5001)
    del_object_from_game(5002)
    del_object_from_game(5003)
    del_object_from_game(6000)    
    del_object_from_game(6001)
    del_object_from_game(6002)
    del_object_from_game(7000)
    del_object_from_game(7001)    
    StopEmiter("main_menu");
    StopEmiter("main_menu1");        
end;

function InitMenu()
addstaticobjecttogame(1001,"menu2",293,31,"",185,0,455,556);
addstaticobjecttogame(4000,"menu1",75,679,"",579,0,270,77)
addstaticobjecttogame(4001,"menu1",299,623,"",365,0,214,92);
addstaticobjecttogame(4002,"menu1",456,565,"",186,0,179,78);
addstaticobjecttogame(4003,"menu1",601,525,"",116,0,70,59);
addstaticobjecttogame(4004,"menu1",590,492,"",47,0,69,25);
    --addstaticobjecttogame(4005,"menu1",599,506,"",0,0,47,19);
addstaticobjecttogame(5000,"menu1",773,120,"",579,77,177,505);
addstaticobjecttogame(5001,"menu1",697,145,"",849,0,158,453);
addstaticobjecttogame(5002,"menu1",616,178,"",365,92,153,398);
addstaticobjecttogame(5003,"menu1",590,129,"",186,78,96,373);
addstaticobjecttogame(6000,"menu2",0,0,"",0,0,185,240);
addstaticobjecttogame(6001,"menu1",0,0,"",765,582,185,240);
addstaticobjecttogame(6002,"menu1",0,0,"",579,582,186,240);
addstaticobjecttogame(7000,"menu1",0,442,"",186,451,171,326);
addstaticobjecttogame(7001,"menu1",0,442,"",365,490,159,326);
speciale_action(2,1001,true,15)
--крысы---
for i=4000,4004,1 do
    speciale_action(2,i)
end;
speciale_action(2,4000,true,1)
--крысы---

--тень----
for i=5000,5003,1 do
    speciale_action(2,i)
end;
StartTimer(987134,10)
--тень--

--верхняя паутина---
for i=6000,6002,1 do
    speciale_action(2,i)
end;
speciale_action(2,6002,true,5)
---------
----нижняя паутина------
for i=7000,7001,1 do
    speciale_action(2,i)
end;
speciale_action(2,7000,true,5)
StartEmiter("main_menu");
StartEmiter("main_menu1");    
------------

--тряпка--------
-- addstaticobjecttogame(8000,"menu3",66,0,"",452,0,446,312);
-- addstaticobjecttogame(8001,"menu3",66,0,"",0,0,452,312);
-- addstaticobjecttogame(8002,"menu2",66,0,"",185,556,460,312);
-- for i=8000,8002,1 do
    -- speciale_action(2,i)
-- end;
-- speciale_action(2,8000,true,2)
---------
-------------
end;

function MenuEffects(param)
    mainmenu=param
    if param then
        InitMenu()
    else
        DelMenu()
    end;    

end;
function firstload()
     MenuEffects(false)
end;

loadresource("data\\developers_1.png","developers_1",14);
loadresource("data\\anim_lamp.png","anim_lamp",666999);
loadresource("data\\menu1.png","menu1",14);
loadresource("data\\menu2.png","menu2",14);
loadresource("data\\menu3.png","menu3",14);
add_tree_leaf("Root","mainmenu",-1,-1)
mainmenu=true



add_animation(600002)
    add_animation_frame(600002,"anim_lamp",72,0,0 ,0,842,102,3);
    add_animation_frame(600002,"anim_lamp",72,0,0,102,842,702,0.3);
    add_animation_frame(600002,"anim_lamp",72,0,0,0,842,102,0.2)
    add_animation_frame(600002,"anim_lamp",72,0,0,102,842,702,0.1)
    add_animation_frame(600002,"anim_lamp",72,0,0,0,842,102,0.3)
    add_animation_frame(600002,"anim_lamp",72,0,0,102,842,702,0.2)
    add_animation_frame(600002,"anim_lamp",72,0,0,0,842,102,0.2)
    add_animation_frame(600002,"anim_lamp",72,0,0,102,842,702,0.1)    
    add_animation_frame(600002,"anim_lamp",72,0,0,0,842,102,0.3)
    add_animation_frame(600002,"anim_lamp",72,0,0,102,842,702,0.4)    
    add_animation_frame(600002,"anim_lamp",72,0,0,0,842,102,0.3)
    add_animation_frame(600002,"anim_lamp",72,0,0,102,842,702,0.2)    
StartAnimation(600002)    
set_visible_object(600002,false)


-- ForPart={
-- 0,0,
-- 1,0,
-- 1,1,
-- 0,1}
    -- addstaticobjecttogame(3333,"developers_1",180,120,"")
    -- MoveTexture(3333,0.0,0.00009)
    -- set_visible_object(3333,false)
    set_inpun_fun("gameinput")
    
    
CreatePolygon(900012,4,"ForPart")
AddParticleToObject(900012,"main_menu",838,757);
MoveEmiter("main_menu",838,757);
StartEmiter("main_menu");    

CreatePolygon(900013,4,"ForPart")
AddParticleToObject(900013,"main_menu1",515,438);
MoveEmiter("main_menu1",515,438);
StartEmiter("main_menu1");    
 playfile(".\\sound\\mus13.ogg",true,true);

FirstTime={}
FirstTime["func"]="firstload"
 
MainMenuFon={}
MainMenuFon["img"]="main";
MainMenuFon["posX"]=0.0;
MainMenuFon["posY"]=0.0;
MainMenuFon["posXimg"]=0.0;
MainMenuFon["posYimg"]=0.0;
MainMenuFon["width"]=1024.0;
MainMenuFon["height"]=768.0;
------Имя игрока----------------------------------------------------------------------------------
------Имя игрока----------------------------------------------------------------------------------
UserPos={}
UserPos["posX"]=522.0;
UserPos["posY"]=320.0;
------------положение курсора---------------
CaretPos={}
CaretPos["posX"]=522.0;
CaretPos["posY"]=320.0;
------Имя игрока----------------------------------------------------------------------------------
PlayerPlace={}
PlayerPlace["posX"]=835.0;
PlayerPlace["posY"]=160.0;
------Выделение текущего профайла-------------------------------------------------------------------
SelectLine ={}
SelectLine["img"]="buttons";
SelectLine["posX"]=35.0; --35
SelectLine["posY"]=0.0;
SelectLine["posXimg"]=55.0;
SelectLine["posYimg"]=984.0;
SelectLine["width"]=24.0;
SelectLine["height"]=24.0;
------Окошко профайла-------------------------------------------------------------------------------
ProfWND ={}
ProfWND["img"]="buttons";
ProfWND["posX"]=230.0;            
ProfWND["posY"]=64.0;          
ProfWND["posXimg"]=31.0;       
ProfWND["posYimg"]=351.0;       
ProfWND["width"]=481.0;         
ProfWND["height"]=521.0;      
------Кнопка Ок профайла----------------------------------------------------------------------------
ProfBOK ={}
ProfBOK["img"]="buttons";
ProfBOK["posX"]=531.0;
ProfBOK["posY"]=477.0;
ProfBOK["posXimg"]=916.0;
ProfBOK["posYimg"]=4.0;
ProfBOK["width"]=100.0;
ProfBOK["height"]=44.0;
------Выделение Кнопки Ок профайла---------------------------------------------------------------------
ProfBOKSelect ={}
ProfBOKSelect["img"]="buttons";
ProfBOKSelect["posX"]    =532.0;
ProfBOKSelect["posY"]    =478.0;
ProfBOKSelect["posXimg"]=918.0;
ProfBOKSelect["posYimg"]=55.0;
ProfBOKSelect["width"]    =100.0;
ProfBOKSelect["height"]    =44.0;
------Кнопка Новый игрок-------------------------------------------------------------------------------
ProfBNew ={}
ProfBNew["img"]="buttons";
ProfBNew["posX"]    =293.0;
ProfBNew["posY"]    =477.0;
ProfBNew["posXimg"]=917.0;
ProfBNew["posYimg"]=238.0;
ProfBNew["width"]    =100.0;
ProfBNew["height"]    =44.0;
------Выделение кнопки новый профайл-------------------------------------------------------------------
ProfBNewSelect ={}
ProfBNewSelect["img"]="buttons";
ProfBNewSelect["posX"]     =293.0;
ProfBNewSelect["posY"]     =477.0;
ProfBNewSelect["posXimg"]=917.0;
ProfBNewSelect["posYimg"]=292.0;
ProfBNewSelect["width"]     =100.0;
ProfBNewSelect["height"] =44.0;
------Кнопка удалить-----------------------------------------------------------------------------------
ProfBDel ={}
ProfBDel["img"]="buttons";
ProfBDel["posX"]   =413.0;
ProfBDel["posY"]   =477.0;
ProfBDel["posXimg"]=912.0;
ProfBDel["posYimg"]=130.0;
ProfBDel["width"]  =100.0;
ProfBDel["height"] =44.0;
------Выделение кнопки удалить-------------------------------------------------------------------------
ProfBDelSelect ={}
ProfBDelSelect["img"]="buttons";
ProfBDelSelect["posX"]   =413.0;
ProfBDelSelect["posY"]   =477.0;
ProfBDelSelect["posXimg"]=917.0;
ProfBDelSelect["posYimg"]=184.0;
ProfBDelSelect["width"]  =100.0;
ProfBDelSelect["height"] =44.0;
-------Окно ввода профайла-----------------------------------------------------------------------------
ProfEnterName ={}
ProfEnterName["img"]="buttons";
ProfEnterName["posX"]   =360.0; --360
ProfEnterName["posY"]   =150.0;
ProfEnterName["posXimg"]=216.0;
ProfEnterName["posYimg"]=0.0;
ProfEnterName["width"]  =690.0;
ProfEnterName["height"] =348.0;
-------Кнопка ок ввода профайла----------------------------------------------------------------------------------------------------
ProfEnterBOk ={}
--ProfEnterBOk["img"]="delete";
ProfEnterBOk["img"]="buttons"
ProfEnterBOk["posX"]   =866.0;
ProfEnterBOk["posY"]   =360.0;
ProfEnterBOk["posXimg"]=678.0;
ProfEnterBOk["posYimg"]=942.0;
ProfEnterBOk["width"]  =62.0;
ProfEnterBOk["height"] =70.0;
--------Выделение кнопки Ок профайла---------------------------------------------------------------------------------------------------
ProfEnterBOkSelect ={}
ProfEnterBOkSelect["img"]="buttons";
ProfEnterBOkSelect["posX"]   =866.0;
ProfEnterBOkSelect["posY"]   =360.0;
ProfEnterBOkSelect["posXimg"]=792.0;
ProfEnterBOkSelect["posYimg"]=935.0;
ProfEnterBOkSelect["width"]  =62.0;
ProfEnterBOkSelect["height"] =70.0;
---------Мигающий курсор ввода имени--------------------------------------------------------------------------------------------------
ProfBlinkKursor ={}
ProfBlinkKursor["img"]="buttons";
ProfBlinkKursor["posX"]   =0.0;
ProfBlinkKursor["posY"]   =0.0;
ProfBlinkKursor["posXimg"]=108.0;
ProfBlinkKursor["posYimg"]=987.0;
ProfBlinkKursor["width"]  =3.0;
ProfBlinkKursor["height"] =    25.0;
---------Окошко удаления профайла--------------------------------------------------------------------------------------------------
ProfDelete ={}
ProfDelete["img"]="delete";
ProfDelete["posX"]   =390.0; --420
ProfDelete["posY"]   =172.0;
ProfDelete["posXimg"]=0.0;
ProfDelete["posYimg"]=0.0;
ProfDelete["width"]  =536.0;
ProfDelete["height"] =278.0;
------Кнопка Ок удаления профайла-------------------------------------------------------------------------------------------------
ProfDeleteOK ={}
ProfDeleteOK["img"]="delete";
ProfDeleteOK["posX"]   =839.0;
ProfDeleteOK["posY"]   =354.0;
ProfDeleteOK["posXimg"]=347.0;
ProfDeleteOK["posYimg"]=282.0;
ProfDeleteOK["width"]  =62.0;
ProfDeleteOK["height"] =70.0;
ProfDeleteOK["fnDelete"]="DeleteCurrentSave"; -- Call of function after profile delete
------Выделение кнопки ок удаления-------------------------------------------------------------------------------------------------
ProfDeleteOKSelect ={}
ProfDeleteOKSelect["img"]="delete";
ProfDeleteOKSelect["posX"]   =839.0;
ProfDeleteOKSelect["posY"]   =354.0;
ProfDeleteOKSelect["posXimg"]=458.0;
ProfDeleteOKSelect["posYimg"]=286.0;
ProfDeleteOKSelect["width"]  =62.0;
ProfDeleteOKSelect["height"] =70.0;
----------Кнопка отмена окна удалить-------------------------------------------------------------------------------------------------
ProfDeleteCancel ={}
ProfDeleteCancel["img"]="delete";
ProfDeleteCancel["posX"]   =784.0;
ProfDeleteCancel["posY"]   =216.0;
ProfDeleteCancel["posXimg"]=172.0;
ProfDeleteCancel["posYimg"]=286.0;
ProfDeleteCancel["width"]  =126.0;
ProfDeleteCancel["height"] =62.0;
---------Выделание кнопки отмена удаления--------------------------------------------------------------------------------------------------
ProfDeleteCancelSelect ={}
ProfDeleteCancelSelect["img"]="delete";
ProfDeleteCancelSelect["posX"]   =784.0;
ProfDeleteCancelSelect["posY"]   =216.0;
ProfDeleteCancelSelect["posXimg"]=23.0;
ProfDeleteCancelSelect["posYimg"]=286.0;
ProfDeleteCancelSelect["width"]  =126.0;
ProfDeleteCancelSelect["height"] =62.0;
------Кнопка профиля-----------------------------------------------------------------------------------------------------
Profile ={}
Profile["img"]="buttons";
Profile["posX"]=604.0;
Profile["posY"]=0.0;
Profile["posXimg"]=591.0;
Profile["posYimg"]=351.0;
Profile["width"]=420.0;
Profile["height"]=226.0;
------Настройка вывода профилей-----------------------------------------------------------------------------------------------------
ProfilesSetup ={}
ProfilesSetup["posX"]=338.0; --338
ProfilesSetup["posY"]=211.0;
ProfilesSetup["maxrecord"]=100;
ProfilesSetup["widthrecords"]=253.0; --253
ProfilesSetup["heightrecords"]=28.0; --28
ProfilesSetup["DownSound"]="menu_click";
ProfilesSetup["OverSound"]="menu_on";
ProfilesSetup["UpSound"]="menu_press";
-----------------------------------------------------------------------------------------------------------
--playfile(".\\sound\\037.ogg",true,true);
initfont();

loadresource("data\\delete.png","delete",8000000);

-- loadresource("data\\mb.png","button",3);
-- loadresource("data\\pr_s.png","pr_s",12);
loadresource("data\\buttons.png","buttons",13);
loadresource("data\\buttons_wind.png","buttonsw",13);
loadresource("data\\developers.jpg","developers",14);

loadresource("data\\exit.png","exit",15);
loadresource("data\\options.png","options",16);
--LoadParticleFromFile("\particles\\menu.ptc","menu")
addpagetomenu(1);


SetDownSound(1,"menu_click")
SetOverSound(1,"menu_on")
--SetUpSound(1,"menu_press")
--addimagetomenu(1,"main",0,0);

addBattontomenupage(1,1,160,214,10,8,98,49,0,0);--играть
addSelectImage(1,1,160,214,6,61,98,50,"buttons");

addBattontomenupage(1,3,119,321,7,129,178,49,0,0);--настройки
addSelectImage(1,3,119,321,2,180,180,49,"buttons");

addBattontomenupage(1,2,162,432,109,4,105,52,0,0);--выход
addSelectImage(1,2,162,432,105,66,108,55,"buttons");

addBattontomenupage(1,4,746,650,10,238,140,49,0,0);--разработчики
addSelectImage(1,4,746,650,10,290,141,53,"buttons");

-- addBattontomenupage(1,5,603,0,592,352,419,225,0,0);--игрок

addpagetomenu(2);
--addimagetomenu(2,"main",0,0);
SetDownSound(2,"menu_click")
SetOverSound(2,"menu_on")
--SetUpSound(2,"menu_press")
addimagetomenu(2,"buttons",160,214,10,8,98,49);
addimagetomenu(2,"buttons",119,321,7,129,178,49);
addimagetomenu(2,"buttons",162,432,109,4,105,52);
addimagetomenu(2,"buttons",746,650,10,238,140,49);
addimagetomenu(2,"options",0,0,0,0,1024,768);--Подложка меню настроек

addSlidertomenupage(2,3,487,222,246,729,864,63,63,0,0);--шарик "Звуковые эффекты" куда ложим, расстояние полоски, откуда режем, размеры
addSlidertomenupage(2,2,460,375,244,729,864,63,63,0,0);--шарик "Громкость Музыки"
addBattontomenupage(2,4,730,544,835,692,90,107);--кнопка ОК
addSelectImage(2,4,730,544,930,688,90,107,"buttons",false);

addCheckBox(2,5,249,491,559,743,147,137,   -14,-149);--шарик полно экранный режим

addpagetomenu(3);
SetDownSound(3,"menu_click")
SetOverSound(3,"menu_on")
--SetUpSound(3,"menu_press")

addimagetomenu(3,"developers",0,0,0,0,1024,768);--Подложка меню разработчики    
function gameinput(sender,id)
if dev then
    if sender==5 then
        tomainmenu=true
        WaitRender()
    end;    
    if sender==100 and     tomainmenu then
        tomainmenu=false;
        tomain();    
    end;        
end;
if sender==28 then
    if id==3333 then
        MoveObjectY(3333,768,-768,35);
    end;
end;

if mainmenu then
if sender==16 then
    if id==1001 then
        speciale_action(2,1001,true,15)
    end;
    if id>=4000 and id<=4003 then
        speciale_action(2,id,true,0.3)
        speciale_action(2,id+1,true,0.3)
    end;
    if id==4004 then
        speciale_action(2,id,true,0.3)
        StartTimer(987133,15)
    end;
    if id>=5000 and id<=5002 then
        speciale_action(2,id,true,1.5)
        speciale_action(2,id+1,true,1.5)
    end;
    if id==5003 then
        speciale_action(2,id,true,1.5)
        StartTimer(987134,10)
    end;    
    if id>=6000 and id<=6001 then
        speciale_action(2,id,true,5)
        speciale_action(2,id+1,true,5)
    end;
    if id==6002 then
        speciale_action(2,6002,true,5)
        speciale_action(2,6000,true,5)
    end;        
    if id==7000 then
        speciale_action(2,7000,true,1.9)
        speciale_action(2,7001,true,2)
    end;    
    if id==7001 then
        speciale_action(2,7000,true,2)
        speciale_action(2,7001,true,1.9)
    end;        
    if id>=8000 and id<=8001 then
        speciale_action(2,id,true,4)
        speciale_action(2,id+1,true,4)
    end;
    if id==8002 then
        speciale_action(2,8002,true,4)
        speciale_action(2,8000,true,4)
    end;                
end;

if sender==15 then
    if id==1001 then
        speciale_action(2,1001,true,1)
    end;
end;
if sender==36 then
    if id==987133 then
        speciale_action(2,4000,true,2)
    end;
    if id==987134 then
        speciale_action(2,5000,true,2)
    end;    
return;end;
end;
if sender==100 and todevelopers then
    todevelopers=false
    showdevelopers()
end;

end;
-- addBattontomenupage(3,1,432,660, 917,4,99,44);--кнопка ОК
-- addSelectImage(3,1,432,660,918,54,99,44,"buttons",false);

addpagetomenu(4);
SetDownSound(4,"menu_click")
SetOverSound(4,"menu_on")
--SetUpSound(4,"menu_press")

--ProfileSetUpSound("menu_press")
--addimagetomenu(4,"main",0,0);
addimagetomenu(4,"buttons",160,214,10,8,95,49);
addimagetomenu(4,"buttons",119,321,7,129,178,49);
addimagetomenu(4,"buttons",162,432,109,4,105,52);
addimagetomenu(4,"buttons",746,650,10,238,140,49);
addimagetomenu(4,"exit",0,0,0,0,1024,768);--Подложка меню выхода


addBattontomenupage(4,2,678,471,824,807,79,89);--кнопка ОК    
addSelectImage(4,2,677,471, 940,801,87,89,"buttons",false);

addBattontomenupage(4,1,254,432,861,576,158,109);--кнопка Cancel
addSelectImage(4,1,254,432,696,583,158,109,"buttons",false);

set_menu_page(1);



addPresReactionToBatton(1,1,"tomap");
addPresReactionToBatton(1,2,"_exit");
addPresReactionToBatton(1,3,"options");
addPresReactionToBatton(1,4,"showdevelopers");

addPresReactionToBatton(2,2,"effect");
addPresReactionToBatton(2,3,"musuk");
addPresReactionToBatton(2,4,"tomain");
addPresReactionToBatton(2,5,"fullscrean");
addPresReactionToBatton(2,6,"showdevelopers");

addPresReactionToBatton(3,1,"tomain");

addPresReactionToBatton(4,1,"BackToMain");
addPresReactionToBatton(4,2,"Exit");



function setmenupage(page)
    if page==2 or page==3 or page==4 then
    if page==3 then
        dev=true
    end;
    if page==4 then
        dev=false
        set_visible_object(600002,false)    
        del_object_from_game(3333)    
    end;
    MenuEffects(false)
    end;
    if page==1 then
        dev=false
        set_visible_object(600002,false)    
        del_object_from_game(3333)    
       MenuEffects(true)
    end;    
    set_menu_page(page);
end

function tomap()
--delete_tree_leaf("Root","mainmenu");
WriteToConsole("tomap 1 \n")
    loadprofile();
WriteToConsole("tomap 2 \n")
    setstateplay();
    WriteToConsole("tomap 3 \n")
end

function newgame()
--delete_tree_leaf("Root","mainmenu");
    MenuEffects(false)
    setstateplay();
end

function _exit()
    MenuEffects(false)
    set_menu_page(4);
    
end

function options()
    MenuEffects(false)
    set_menu_page(2);
end
function musuk(val)
    setmusucvalue(val);
end
function effect(val)
    seteffectvalue(val);
end    
function tomain()
dev=false
    MenuEffects(true)
    set_visible_object(600002,false)
    del_object_from_game(3333)
    set_menu_page(1);
end
function fullscrean()
    tofullscrean();
end
function showdevelopers()
    MenuEffects(false)
    set_visible_object(600002,true)
    addstaticobjecttogame(3333,"developers_1",180,768,"")
    MoveObjectY(3333,768,-768,35);
    --MoveTexture(3333,0.0,0.00009)
    speciale_action(4,600002)
    dev=true;    
    
    set_menu_page(3);
end
function BackToOption()
    set_menu_page(2);
end
------------4--------------
function BackToMain()
  --  MenuEffects(true)
    -- set_visible_object(600002,false)
    -- del_object_from_game(3333)
    -- set_visible_object(3333,false)
    MenuEffects(true)
    set_menu_page(1);
end
function Exit()
    MenuEffects(false)
    savesetings();
    exitgame();
end
InitMenu()
---------------------------