-- PaneDisplay.
-- shows up when SSMusicInfo is set to PaneDisplay.

local pd = Def.ActorFrame{
	Name="PaneDisplaySection";
	InitCommand=cmd(x,-64);
};

-- player stuff is out back

local numPlayers = GAMESTATE:GetNumSidesJoined();
local panes = Def.ActorFrame{ }; -- panes!!
local rv;

local headerWidth = 240;
if numPlayers == 2 then
	headerWidth = (headerWidth / 2)-2;
end;

local paneCategories = {
	'RadarCategory_TapsAndHolds',
	'RadarCategory_Jumps',
	'RadarCategory_Holds',
	'RadarCategory_Mines',
	'RadarCategory_Hands',
	'RadarCategory_Rolls'
};

local paneStrings = {
	THEME:GetString("PaneDisplay","Steps"),
	THEME:GetString("PaneDisplay","Jumps"),
	THEME:GetString("PaneDisplay","Holds"),
	THEME:GetString("PaneDisplay","Mines"),
	THEME:GetString("PaneDisplay","Hands"),
	THEME:GetString("PaneDisplay","Rolls")
};

if numPlayers == 1 then
	-- single player
	local player = GAMESTATE:GetMasterPlayerNumber();
	
	panes[#panes+1] = Def.ActorFrame{
		Name="Frame"..player;
		InitCommand=cmd(x,80);
		
		LoadActor( THEME:GetPathB("","_frame 3x3"), "_square blackinset transparent normal", headerWidth-2, 80)..{
			InitCommand=cmd(y,56);
		};
		
		LoadActor( THEME:GetPathB("","_frame 3x1"), "_infobox header", headerWidth )..{
			Name="Header"..player;
			InitCommand=cmd(diffuse,PlayerColor(player);y,-5);
		};
		
		LoadFont("_frutiger lt std 55 roman 24px")..{
			InitCommand=cmd(shadowlength,1;zoom,0.55;y,-5);
			BeginCommand=function(self)
				local str;
				if player == PLAYER_1 then str = "P1 Information";
				else str = "P2 Information";
				end;
				self:settext(str);
			end;
		};
	};
	
	for i=1,#paneCategories do
		panes[#panes+1] = Def.ActorFrame{
			Name=player..paneStrings[i];
			InitCommand=cmd(y,(i)*16);
			
			LoadFont("_frutiger lt std 55 roman 24px")..{
				Text=paneStrings[i];
				InitCommand=cmd(shadowlength,1;horizalign,right;zoom,0.55);
			};
			
			LoadFont("_frutiger lt std 55 roman 24px")..{
				InitCommand=cmd(x,8;shadowlength,1;horizalign,left;zoom,0.55;playcommand,"Set");
				
				SetCommand=function(self)
					local song;
					local steps;
					if GAMESTATE:IsCourseMode() then
						song = GAMESTATE:GetCurrentCourse();
						steps = GAMESTATE:GetCurrentTrail(player);
					else
						song = GAMESTATE:GetCurrentSong();
						steps = GAMESTATE:GetCurrentSteps(player);
					end;
					
					if not song then self:visible(false);
					else self:visible(true);
					end;
					
					if steps then
						rv = steps:GetRadarValues(player);
						self:settext( rv:GetValue(paneCategories[i]) )
					else
						self:settext("");
					end;
				end;
				
				CurrentSongChangedMessageCommand=cmd(playcommand,"Set");
				CurrentCourseChangedMessageCommand=cmd(playcommand,"Set");
				
				CurrentStepsP1ChangedMessageCommand=function(self)
					if player == PLAYER_1 then self:playcommand("Set"); end;
				end;
				CurrentTrailP1ChangedMessageCommand=function(self)
					if player == PLAYER_1 then self:playcommand("Set"); end;
				end;
				CurrentStepsP2ChangedMessageCommand=function(self)
					if player == PLAYER_2 then self:playcommand("Set"); end;
				end;
				CurrentTrailP2ChangedMessageCommand=function(self)
					if player == PLAYER_2 then self:playcommand("Set"); end;
				end;
			};
		};
	end;
else
	-- two players
	
	for pi, pname in pairs(PlayerNumber) do
		panes[#panes+1] = Def.ActorFrame{
			Name="Frame"..pname;
			InitCommand=function(self)
				if pname == PLAYER_1 then self:x(8);
				else self:x(152);
				end;
			end;
			
			LoadActor( THEME:GetPathB("","_frame 3x3"), "_square blackinset transparent normal", headerWidth-2, 80)..{
				InitCommand=cmd(y,56);
			};
			
			LoadActor( THEME:GetPathB("","_frame 3x1"), "_infobox header", headerWidth )..{
				Name="Header"..pname;
				InitCommand=cmd(diffuse,PlayerColor(pname);y,-5);
			};
			
			LoadFont("_frutiger lt std 55 roman 24px")..{
				InitCommand=cmd(shadowlength,1;zoom,0.55;y,-5);
				BeginCommand=function(self)
					local str;
					if pname == PLAYER_1 then str = "P1 Information";
					else str = "P2 Information";
					end;
					self:settext(str);
				end;
			};
		};
		
		for i=1,#paneCategories do
		panes[#panes+1] = Def.ActorFrame{
			Name=pname..paneStrings[i];
			InitCommand=cmd(y,(i)*16);
			
			LoadFont("_frutiger lt std 55 roman 24px")..{
				Text=paneStrings[i];
				InitCommand=cmd(shadowlength,1;horizalign,right;zoom,0.55);
				BeginCommand=function(self)
					if pname == PLAYER_1 then self:x(0);
					else self:x(144);
					end;
				end;
			};
			
			LoadFont("_frutiger lt std 55 roman 24px")..{
				InitCommand=cmd(shadowlength,1;horizalign,left;zoom,0.55;playcommand,"Set");
				BeginCommand=function(self)
					if pname == PLAYER_1 then self:x(8);
					else self:x(152);
					end;
				end;
				
				SetCommand=function(self)
					local song;
					local steps;
					if GAMESTATE:IsCourseMode() then
						song = GAMESTATE:GetCurrentCourse();
						steps = GAMESTATE:GetCurrentTrail(pname);
					else
						song = GAMESTATE:GetCurrentSong();
						steps = GAMESTATE:GetCurrentSteps(pname);
					end;
					
					if not song then self:visible(false);
					else self:visible(true);
					end;
					
					if steps then
						rv = steps:GetRadarValues(pname);
						self:settext( rv:GetValue(paneCategories[i]) )
					else
						self:settext("");
					end;
				end;
				
				CurrentSongChangedMessageCommand=cmd(playcommand,"Set");
				CurrentCourseChangedMessageCommand=cmd(playcommand,"Set");
				
				CurrentStepsP1ChangedMessageCommand=function(self)
					if pname == PLAYER_1 then self:playcommand("Set"); end;
				end;
				CurrentTrailP1ChangedMessageCommand=function(self)
					if pname == PLAYER_1 then self:playcommand("Set"); end;
				end;
				CurrentStepsP2ChangedMessageCommand=function(self)
					if pname == PLAYER_2 then self:playcommand("Set"); end;
				end;
				CurrentTrailP2ChangedMessageCommand=function(self)
					if pname == PLAYER_2 then self:playcommand("Set"); end;
				end;
			};
		};
	end;
	end;
end;

pd[#pd+1] = panes;

return pd;