local function IsPlayerPresent(pn)
	return GAMESTATE:IsHumanPlayer(pn);
end

local function PlayerSet(pn)
	local p = Def.ActorFrame {
--[[ 		Def.ActorFrame {
			LoadActor("StatusBack") .. {
				OnCommand=cmd(playcommand,"Refresh");
				BeginCommand=cmd(playcommand,"Refresh");
				PlayerJoinedMessageCommand=cmd(playcommand,"Refresh");
				PlayerUnjoinedMessageCommand=cmd(playcommand,"Refresh");
				CurrentStyleChangedMessageCommand=cmd(playcommand,"Refresh");
				CoinInsertedMessageCommand=cmd(playcommand,"Refresh");
				CoinModeChangedMessageCommand=cmd(playcommand,"Refresh");
				RefreshCommand=function(self)
					if IsPlayerPresent(pn) then
						self:diffuse(DarkColor(PlayerColor(PLAYER_1)));
					else
						self:diffuse(1,0,0,1);
					end
				end
			};
			LoadActor("StatusFrame");
		}; --]]
		Def.ActorFrame {
			Def.Quad {
				InitCommand=cmd(zoomto,200,16;diffuse,cBlue);
				OnCommand=cmd(playcommand,"Refresh");
				BeginCommand=cmd(playcommand,"Refresh");
				PlayerJoinedMessageCommand=cmd(playcommand,"Refresh");
				PlayerUnjoinedMessageCommand=cmd(playcommand,"Refresh");
				CurrentStyleChangedMessageCommand=cmd(playcommand,"Refresh");
				CoinInsertedMessageCommand=cmd(playcommand,"Refresh");
				CoinModeChangedMessageCommand=cmd(playcommand,"Refresh");
				RefreshCommand=function(self)
					if IsPlayerPresent(pn) then
						self:diffuse(DarkColor(cBlue));
					else
						self:diffuse(DarkColor(cRed));
					end
				end
			};
			Def.Quad {
				InitCommand=cmd(vertalign,bottom;y,-8;zoomto,200,40;diffuse,cBlue;diffusebottomedge,LightColor(cBlue));
				OnCommand=cmd(playcommand,"Refresh");
				BeginCommand=cmd(playcommand,"Refresh");
				PlayerJoinedMessageCommand=cmd(playcommand,"Refresh");
				PlayerUnjoinedMessageCommand=cmd(playcommand,"Refresh");
				CurrentStyleChangedMessageCommand=cmd(playcommand,"Refresh");
				CoinInsertedMessageCommand=cmd(playcommand,"Refresh");
				CoinModeChangedMessageCommand=cmd(playcommand,"Refresh");
				RefreshCommand=function(self)
					if IsPlayerPresent(pn) then
						self:stoptweening();
						self:zoomy(40);
					else
						self:stoptweening();
						self:zoomy(0);
					end
				end
			};
		};
		LoadFont("Common Normal") .. {
			InitCommand=cmd(zoom,0.5;maxwidth,240;NoStroke;shadowlength,1);
			OnCommand=cmd(playcommand,"Refresh");
			BeginCommand=cmd(playcommand,"Refresh");
			PlayerJoinedMessageCommand=cmd(playcommand,"Refresh");
			PlayerUnjoinedMessageCommand=cmd(playcommand,"Refresh");
			CurrentStyleChangedMessageCommand=cmd(playcommand,"Refresh");
			CoinInsertedMessageCommand=cmd(playcommand,"Refresh");
			CoinModeChangedMessageCommand=cmd(playcommand,"Refresh");
			RefreshCommand=function(self)
				if IsPlayerPresent(pn) then
					self:diffuse(1,1,1,1);
					self:diffusebottomedge(cBlue);
					self:settext("PRESENT");
				else
					self:diffuse(LightColor(cRed));
					self:diffusebottomedge(cRed);
					self:settext("ABSENT");
				end
			end
		};
	};
	
	p.ScreenChangedMessageCommand=function(self)
		local screen = SCREENMAN:GetTopScreen();
		local bShow = true;
		if screen then
			local sClass = screen:GetName();
			bShow = THEME:GetMetric( sClass, "ShowStatus" );
		end

		self:visible( bShow );
	end
	return p
end

local t = Def.ActorFrame {};
t[#t+1] = PlayerSet(PLAYER_1) .. {
	InitCommand=cmd(x,THEME:GetMetric("ScreenWithMenuElements","StatusP1X");y,THEME:GetMetric("ScreenWithMenuElements","StatusP1Y"));
};
t[#t+1] = PlayerSet(PLAYER_2) .. {
	InitCommand=cmd(x,THEME:GetMetric("ScreenWithMenuElements","StatusP2X");y,THEME:GetMetric("ScreenWithMenuElements","StatusP2Y"));
};

return t