require( "scripts/style.lua" );


MyFont = {
  standardFont,
  30,
  BlackColor
};

NameFont = {
  standardFont,
  20,
  BlackColor
};
if( PauseGame) then PauseGame(); end;

function LoadEndlessLevelOnCheat(aLevNum)
    if (aLevNum >= 1 or aLevNum <= 3) then
        if (aLevNum == 1) then gEndlessDifficulty = 1; end
        if (aLevNum == 2) then gEndlessDifficulty = 2; end
        if (aLevNum == 3) then gEndlessDifficulty = 3; end
        gCurFarmBegin = 1;
        gCurFarm = 1;
    end
    if (aLevNum >= 4 or aLevNum <= 6) then
        if (aLevNum == 4) then gEndlessDifficulty = 1; end
        if (aLevNum == 5) then gEndlessDifficulty = 2; end
        if (aLevNum == 6) then gEndlessDifficulty = 3; end
        gCurFarmBegin = 4;
        gCurFarm = 2;
    end
    if (aLevNum >= 7 or aLevNum <= 9) then
        if (aLevNum == 7) then gEndlessDifficulty = 1; end
        if (aLevNum == 8) then gEndlessDifficulty = 2; end
        if (aLevNum == 9) then gEndlessDifficulty = 3; end
        gCurFarmBegin = 7;
        gCurFarm = 3;
    end
    if (aLevNum >= 10 or aLevNum <= 12) then
        if (aLevNum == 10) then gEndlessDifficulty = 1; end
        if (aLevNum == 11) then gEndlessDifficulty = 2; end
        if (aLevNum == 12) then gEndlessDifficulty = 3; end
        gCurFarmBegin = 10;
        gCurFarm = 4;
    end
    
    SetCurrentGameMode(gEndlessDifficulty);
    CPP_LoadGO();
    
    LevelForLoading = aLevNum;
    gGlobalPlayerInfo.gLevelNum = LevelForLoading;
    --if(LoadLevel)then
    LoadLevel(LevelForLoading);
end

MakeDialog
{
    Bitmap
    { 
        image="backgrounds/dialog",
        x=kCenter,
        y=kCenter,
        
        Text
        {
            font = MyFont,
            name = "entername",
            x=0,y=20,w=kMax,h=30,
            flags = kHAlignCenter + kVAlignTop,
            label = "enterlevnum"
        };
        
        Bitmap
        {
            image="backgrounds/textfield.png",
            x=kCenter,
            y=kCenter,
            
            TextEdit
            {
                font = NameFont,
                name = "cheat_ln_edit",
                label = "",
                enablewindow = "enterok",
                clearinitial = true,
                x=3,y=5,w=kMax-3,h=kMax,
                length=3,
                ignore = "!@#$%^&*()><\\\"\'[]{}|?/+=~`.,;:-qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM "
                
            };
        };
            
        Button
        {
            x=50,
            y=-60,
            font = BlackButtonFont;
            graphics = StandardButtonGraphics,
            name="enterok",
            label="ok",
            type = kPush,
            default=true,   -- Make this the default button
            command = 
                function()
                    if (GetLabel("cheat_ln_edit") ~= "") then
                        local num_lev = tonumber(GetLabel("cheat_ln_edit"));
                        gGlobalPlayerInfo.gLevelNum = num_lev;
                        if (gGlobalPlayerInfo.gLevelNum <= CPP_GetLastLevelNum() and gGlobalPlayerInfo.gLevelNum >= 0) then
                            CPP_WriteGO();                            
                            CloseWindow(GetLabel("cheat_ln_edit"));
                            
                            if( isMinigame == 1)then
                                if(StopGame)then StopGame(0); end;
                                PopModal( "bonus_dialog" );                            
                            end
							CheckLoadingWindow();
                            if (gGameMode == 0) then  --story mode
                                LoadLevel(gGlobalPlayerInfo.gLevelNum);                                                        
                            else                      --endless mode
                                LoadEndlessLevelOnCheat(gGlobalPlayerInfo.gLevelNum);
                            end
                        else
                            DisplayDialog { "scripts/ok.lua", body ="enterlevnumerror",title = ""};
                            SetFocus( "nameedit" )
                        end
                    else
                        DisplayDialog { "scripts/ok.lua", body ="enterlevnumerror",title = "" };
                        SetFocus( "nameedit" )
                    end
                end
        },
        
        Button
        {
            x=250,
            y=-60,
            font = BlackButtonFont;
            graphics = StandardButtonGraphics,
            name="entercancel",
            label="cancel",
            type = kPush,
            command = 
                function()
                    CloseWindow(nil);
					if( ResumeGame) then ResumeGame(); end;
                end
        };
    },
    
}
EnableWindow("enterok",false);
SetFocus( "cheat_ln_edit" );
--SetLabel("cheat_ln_edit","1");


