dofile("data/Lua/Screens/OptionsMain.lua")

function InitButtons(screen)
    local game_state = options.game_state
    local up = screen:GetObject("exitup"):GetAnimationPtr()
	local over = screen:GetObject("exitover"):GetAnimationPtr()	
	local down = screen:GetObject("exitdown"):GetAnimationPtr()	
	game_state.exit_button = CreateButton(up, over, down, "Exit", screen)
	game_state.exit_button:AttachTo(screen)
	game_state.exit_button:SetXY(525, 524)
	game_state.exit_button:SetZ(140)
	
	local up = screen:GetObject("resumeup"):GetAnimationPtr()
	local over = screen:GetObject("resumeover"):GetAnimationPtr()	
	local down = screen:GetObject("resumedown"):GetAnimationPtr()	
	game_state.resume_button = CreateButton(up, over, down, "Resume", screen)
	game_state.resume_button:AttachTo(screen)
	game_state.resume_button:SetXY(525, 413)
	game_state.resume_button:SetZ(140)
	game_state.resume_button:SetHotKey(27)
		
	game_state.is_arrow_moving = false
end

function PostLoad()
	local anim = CreateAnimation('data/Texture/GUI/Dialog/front.png',0,0,595,189,1,0)
	anim:SetHotSpot(297,94)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	options:CreateObject('front',anim,526,470,135,0,1,1)
	options:GetObject('strelka'):SetXY(525, 470)
    options.ExitToMenu = function()
        play_field:GetLevelScreen():ScreenDestroy()
        options:ScreenDestroy()
        load_screen('data/Lua/Screens/Menu.lua')
    end
	--play_field:GetLevelScreen():GetPanel():Stop();
	play_field:GetLevelScreen():GetPanel():SetAllowInput(false);
	play_field:SetEnabled(false);
    play_field:GetLevelScreen():SetAllowInput(false)
	SetCursor('CursorArrow')
end

function OnButtonPress(title)    
    local move_time = 0.1
    options:SetAllowInput(false)
    
    DefaultOnButtonPress(title)
    
    local arrow = options:GetObject('strelka')
	
	local af = CreateAnimationEffector()	
	af:AttachTo(arrow)
	af:SetMode(_ANIM_FWD + _ANIM_NOLOOP)
	af:SetKey(_TRACK_A, 0, arrow:GetAngle());   
    
    local OnMoveFinish = function()    
    
        DefaultOnButtonPress(title)
        if title == "Resume" then    
            SetParameters();		
            options:ScreenDestroy()                                    

            if(game_state.screen ~= nil) then
				game_state.screen:Go();
			else
				play_field:GetLevelScreen():GetPanel():Go();
            end
            
            play_field:SetEnabled(true);
            play_field:GetLevelScreen():SetAllowInput(true)
            play_field:Go()
            play_field:GainFocus()            
        end
        if title == "Exit" then
            load_screen("data/Lua/Screens/DialogExitToMenu.lua")
			--[[local ls = play_field:GetLevelScreen()
            ls:SetOpacity(0)
			ls:ScreenDestroy()
            options:Destroy()
            load_screen('data/Lua/Screens/Menu.lua')]]
        end
    end
    
    if title == "Resume" then
		af:SetKey(_TRACK_A, move_time, 0 / 180 * M_PI);
	end
	if title == "Exit" then
	    af:SetKey(_TRACK_A, move_time, 180 / 180 * M_PI);		
	end	
    
    af:Play()
	TimerDo(options:GetTimer(), move_time, OnMoveFinish, title)
end

