--[[ ScreenSelectMusic decorations ]]
local t = LoadFallbackB();

t[#t+1] = StandardDecorationFromFileOptional("BannerFrame","BannerFrame");
t[#t+1] = StandardDecorationFromFileOptional( "StageDisplay", "StageDisplay" );
t[#t+1] = StandardDecorationFromFileOptional( "SortDisplay", "SortDisplay" );
t[#t+1] = StandardDecorationFromFile( "BPMDisplay", "BPMDisplay" );
t[#t+1] = StandardDecorationFromFile( "SongLength", "SongLength" );
t[#t+1] = StandardDecorationFromFileOptional( "AvailableDifficulties", "AvailableDifficulties" );
t[#t+1] = StandardDecorationFromFileOptional( "GrooveRadar", "GrooveRadar" );
t[#t+1] = StandardDecorationFromFileOptional( "StepsDisplayList", "StepsDisplayList" );
t[#t+1] = StandardDecorationFromFileOptional( "CourseContents", "CourseContents" );
t[#t+1] = StandardDecorationFromFileOptional( "Balloon", "Balloon" );
t[#t+1] = StandardDecorationFromFileOptional( "NumCourseSongs", "NumCourseSongs" );
t[#t+1] = StandardDecorationFromFileOptional( "CourseHasMods", "CourseHasMods" );
--t[#t+1] = StandardDecorationFromFileOptional( "MachineRank", "MachineRank" );

for pn in ivalues(GAMESTATE:GetHumanPlayers()) do
	local diffIcon = LoadActor( THEME:GetPathG( Var "LoadingScreen", "DifficultyIcon" ), pn );
	t[#t+1] = StandardDecorationFromTable( "DifficultyIcon" .. ToEnumShortString(pn), diffIcon );
end

for pn in ivalues(PlayerNumber) do
	local MetricsName = "PaneDisplay" .. PlayerNumberToString(pn);
	t[#t+1] = Def.PaneDisplay {
		MetricsGroup="PaneDisplay";
		PlayerNumber=pn;
		InitCommand=function(self) self:player(pn); self:playcommand("Set"); self:name(MetricsName); ActorUtil.LoadAllCommandsAndSetXY(self,Var "LoadingScreen"); end;
		SetCommand=function(self) self:SetFromGameState() end;
		CurrentSongChangedMessageCommand=cmd(playcommand,"Set");
		CurrentStepsP1ChangedMessageCommand=function(self)
			if pn == PLAYER_1 then self:playcommand("Set"); end;
		end;
		CurrentStepsP2ChangedMessageCommand=function(self)
			if pn == PLAYER_2 then self:playcommand("Set"); end;
		end;
		CurrentTrailP1ChangedMessageCommand=function(self)
			if pn == PLAYER_1 then self:playcommand("Set"); end;
		end;
		CurrentTrailP2ChangedMessageCommand=function(self)
			if pn == PLAYER_2 then self:playcommand("Set"); end;
		end;
		SortOrderChangedMessageCommand=cmd(playcommand,"Set");
	};
end;

local function StepsDisplay(pn)
	local function set(self, player)
		self:SetFromGameState( player );
	end

	local name = GAMESTATE:IsCourseMode() and "StepsDisplayCourse" or "StepsDisplay";

	local sd = Def.StepsDisplay {
		InitCommand=cmd(Load,name .. PlayerNumberToString(pn),GAMESTATE:GetPlayerState(pn););
		CurrentSongChangedMessageCommand=function(self)
			local SongOrCourse = GAMESTATE:IsCourseMode() and GAMESTATE:GetCurrentCourse() or GAMESTATE:GetCurrentSong();
			-- wrong? check 3.9
			self:GetChild("Meter"):visible(SongOrCourse and true or false);
			self:GetChild("Ticks"):visible(SongOrCourse and true or false);
		end;
	};

	if pn == PLAYER_1 then
		sd.CurrentStepsP1ChangedMessageCommand=function(self) set(self, pn); end;
		sd.CurrentTrailP1ChangedMessageCommand=function(self) set(self, pn); end;
	else
		sd.CurrentStepsP2ChangedMessageCommand=function(self) set(self, pn); end;
		sd.CurrentTrailP2ChangedMessageCommand=function(self) set(self, pn); end;
	end

	return sd;
end

for pn in ivalues(GAMESTATE:GetHumanPlayers()) do
	local MetricsName = "StepsDisplay" .. PlayerNumberToString(pn);
	t[#t+1] = StepsDisplay(pn) .. {
		InitCommand=function(self)
			self:player(pn);
			self:name(MetricsName);
			ActorUtil.LoadAllCommandsAndSetXY(self,Var "LoadingScreen");
		end;
	};
end

if ShowStandardDecoration("SongOptions") then
	t[#t+1] = StandardDecorationFromFileOptional("SongOptions","SongOptions") .. {
		ShowPressStartForOptionsCommand=THEME:GetMetric(Var "LoadingScreen","SongOptionsShowCommand");
		ShowEnteringOptionsCommand=THEME:GetMetric(Var "LoadingScreen","SongOptionsEnterCommand");
		HidePressStartForOptionsCommand=THEME:GetMetric(Var "LoadingScreen","SongOptionsHideCommand");
	};
end;

if not GAMESTATE:IsCourseMode() then
	local function GenerateModIconRow(pn)
		local MetricsName = "OptionsArea" .. ToEnumShortString(pn);
		local spacingX = THEME:GetMetric("ModIconRowSelectMusic","SpacingX");
		local spacingY = THEME:GetMetric("ModIconRowSelectMusic","SpacingY");
		local numIcons = THEME:GetMetric("ModIconRowSelectMusic","NumModIcons");
		if ShowStandardDecoration("OptionsArea") then
			return Def.ActorFrame {
				InitCommand=function(self) self:name(MetricsName); ActorUtil.LoadAllCommandsAndSetXY(self,Var "LoadingScreen"); end;
				LoadActor( THEME:GetPathG("OptionIcon","Player") )..{
					InitCommand=cmd(pause;horizalign,left;x,WideScale(-SCREEN_CENTER_X,-SCREEN_CENTER_X*0.745));
					BeginCommand=function(self)
						self:setstate( pn == PLAYER_1 and 0 or 1 );
					end;
				};
				Def.ModIconRow {
					InitCommand=cmd(Load,"ModIconRowSelectMusic",pn;x,20);
					OnCommand=cmd(zoomy,0;linear,0.5;zoomy,1;);
					OffCommand=cmd(linear,0.5;zoomy,0;);
				};
			};
		end;
	end;

	for pn in ivalues(GAMESTATE:GetHumanPlayers()) do
		if ShowStandardDecoration("OptionsArea") then
			t[#t+1] = GenerateModIconRow(pn);
		end;
	end;
end;

t[#t+1] = Def.Actor{
	Name="TheQuickerHackerUper"; -- BOUNTY
	SetCommand=function(self)
		local SongOrCourse = GAMESTATE:IsCourseMode() and GAMESTATE:GetCurrentCourse() or GAMESTATE:GetCurrentSong();
		if not SongOrCourse then
			-- hack time
			for pn in ivalues(PlayerNumber) do
				-- ScoreDisplay doesn't get set to 0 in code
				local score = SCREENMAN:GetTopScreen():GetChild("Score"..ToEnumShortString(pn));
				if score then
					score:settext("        0");
				end;
			end;
		end;
	end;
	CurrentSongChangedMessageCommand=cmd(playcommand,"Set");
	CurrentCourseChangedMessageCommand=cmd(playcommand,"Set");
};

return t;