local function CreditsText( pn )
	function update(self)
		local str = ScreenSystemLayerHelpers.GetCreditsMessage(pn);
		self:settext(str);
	end

	function UpdateVisible(self)
		local screen = SCREENMAN:GetTopScreen();
		local bShow = true;
		if screen then
			local sClass = screen:GetName();
			bShow = THEME:GetMetric( sClass, "ShowCoinsAndCredits" );
		end

		self:visible( bShow );
	end

	local text = LoadFont(Var "LoadingScreen","credits") .. {
		InitCommand=THEME:GetMetric(Var "LoadingScreen","CreditsInitCommand");
		RefreshCreditTextMessageCommand=update;
		CoinInsertedMessageCommand=update;
		PlayerJoinedMessageCommand=update;
		ScreenChangedMessageCommand=UpdateVisible;
	};
	return text;
end

local t = Def.ActorFrame {
--[[     LoadActor(THEME:GetPathG("_frame", "1D"),{ 1/3, 1/3, 1/3 },LoadActor(THEME:GetPathG("1D","Frames/Icon Cell"))) .. {
        InitCommand=cmd(playcommand,"SetSize",{ Width=SCREEN_WIDTH+128; tween=cmd(x,SCREEN_CENTER_X;y,SCREEN_TOP+14;diffusealpha,0;) };);
        BeginCommand=cmd(playcommand,"SetSize",{ Width=SCREEN_WIDTH+128; tween=cmd(finishtweening;diffusealpha,0;x,SCREEN_CENTER_X;y,SCREEN_TOP+14;diffusealpha,0;) };);
        SystemMessageMessageCommand=cmd(playcommand,"SetSize",{ Width=SCREEN_WIDTH+128; tween=function(self)
            self:diffusealpha(0);
            if params.NoAnimate then
                self:finishtweening();
            end
            self:linear(1);
            self:sleep(5);
            self:linear(0.5);
        end;
        };);
		HideSystemMessageMessageCommand=cmd(finishtweening);
    }; --]]
	LoadFont(Var "LoadingScreen","message") .. {
		InitCommand=cmd(maxwidth,750;
		zoom,0.8;shadowlength,1;
		x,SCREEN_CENTER_X;y,SCREEN_TOP+28;
		diffusealpha,0
		);
		SystemMessageMessageCommand = function(self, params)
			self:settext( params.Message );
			local f = cmd(finishtweening;zoom,1.2;diffusealpha,0;decelerate,1;zoom,1;diffusealpha,1); f(self);
			self:playcommand( "On" );
			if params.NoAnimate then
				self:finishtweening();
			end
			f = cmd(sleep,5;bouncebegin,0.5;zoomy,0;zoomx,4;diffusealpha,0); f(self);
			self:playcommand( "Off" );
		end;
		HideSystemMessageMessageCommand=cmd(finishtweening);
	};
	CreditsText( PLAYER_1 ) .. {
		InitCommand=cmd(x,THEME:GetMetric(Var "LoadingScreen","CreditsP1X");y,THEME:GetMetric(Var "LoadingScreen","CreditsP1Y"));
        BeginCommand=THEME:GetMetric(Var "LoadingScreen","CreditsP1InitCommand");
	};
	CreditsText( PLAYER_2 ) .. {
		InitCommand=cmd(x,THEME:GetMetric(Var "LoadingScreen","CreditsP2X");y,THEME:GetMetric(Var "LoadingScreen","CreditsP2Y"));
        BeginCommand=THEME:GetMetric(Var "LoadingScreen","CreditsP2InitCommand");
	};
};
return t;
