-- ui screen events

offset = 0
timer = 0
startoffset = 0
flag1 = 0
fspeed = 50

function OnLoad ()
    CacheSound("sfx/whoosh1.ogg")
    
	SetProperty ("/StoryIntro:enter_trans_duration", 0.5);
	SetProperty ("/StoryIntro:leave_trans_duration", 1.8);
    
end;



function OnEnter ()
	InitGameLevel ();
	Reset()
	if (GetVar ("HardwareRendering") == 0) then
		
	
	end;
	--SetProperty ("Continue:visible", 0);
end;

function Reset ()
   timer = 0

end;

function OnLeave ()
		--InitGameLevel ();
		PushScreen ("Game");
end;


function OnClick (name)

	if (name == "Continue") then
		PopScreen ();--SwitchScreen ("WorldMap");
	end;
	
	if (name == "Reset") then
		Reset ()
	end;
end;

function clamp (value, min_value, max_value)
	value = math.min (value, max_value);
	value = math.max (value, min_value);
	return value;
end;

function OnUpdate (tdelta)

  alpha = 99.0
  timer = timer + tdelta;
  SetProperty ("Continue:alpha", clamp(2*(timer-0.5)-1, 0, 1))

  
  akey = GetActiveScreenAnimKey ();
  
 
  
end;


function OnDraw ()

	if (IsScreenLeaving ()) then
		SetProperty ("zoomin:visible", 0);
		x = GetProperty ("zoomin:static_position.x");
		y = GetProperty ("zoomin:static_position.y");
		
		start_scale = GetProperty ("zoomin:scale");
		end_scale = 1.71;

		start_angle = GetProperty ("zoomin:angle");
	
		trans = 1-math.sin (math.pi/2 * (GetActiveScreenTransPhase ()));
		angle = (1-trans) * start_angle;-- + (1-trans) * 0.25;
		
		x = (1-trans) * x + trans * (400+33);
		y = (1-trans) * y + trans * (300+30);

		NX_SetAlpha (1);
		NX_SetColor (1,1,1);
		NX_DrawBitmapRS ("story/square-view1-big.png", x, y, angle, start_scale + (end_scale - start_scale) * trans);

		x = (1-trans) * x + trans * (400);
		y = (1-trans) * y + trans * (300);
				
		NX_SetAlpha (trans);
		NX_SetColor (1,1,1);
		NX_DrawBitmapRS ("GAME_BACKGROUND", x, y, angle, 0.5 + 0.5 * trans);
		
	else
		SetProperty ("zoomin:visible", 1);
	end;
end;
