--[[
Welcome to another failed piece of code, the dubaiOne Eval Meter.
It was going to be a bunch of stacked quads representing a breakdown of the
step judgments you got, but for some dumb reason it would never fill the
bar entirely. I have NO fucking idea why that is and it's really pissing
me the fuck off.
]]

-- Bar(pn)
-- Makes the dubaiOne Evaluation Meter™.
local function Bar(pn)
	local b = Def.ActorFrame{};
	
	local postfix = "p";
	-- p1 and p2 have different meters because I like the lines going
	-- the same way on each one. This is inelegant but I really don't
	-- give a fuck.
	if pn == PLAYER_1 then postfix = postfix.."1";
	else postfix = postfix.."2";
	end;
	-- do this here because I'm starting to hate magic numbers
	local revealTime = 0.5;
	
	-- now that we have a graphic to load...
	b[#b+1] = Def.ActorFrame{
		-- add the bg.
		LoadActor("_bar "..postfix)..{
			InitCommand=function(self)
				if pn == PLAYER_1 then self:cropleft(1);
				else self:cropright(1);
				end;
			end;
			OnCommand=function(self)
				self:linear(revealTime);
				if pn == PLAYER_1 then self:cropleft(0);
				else self:cropright(0);
				end;
			end;
			OffCommand=function(self)
				self:linear(revealTime);
				if pn == PLAYER_1 then self:cropleft(1);
				else self:cropright(1);
				end;
			end;
		};
		-- the mask would be good too.
		LoadActor("_mask "..postfix)..{
			InitCommand=function(self)
				if pn == PLAYER_1 then self:cropleft(1);
				else self:cropright(1);
				end;
				-- mask time!
				self:blend('BlendMode_NoEffect');
				self:zwrite(true);
				self:clearzbuffer(true);
			end;
			OnCommand=function(self)
				self:linear(revealTime);
				if pn == PLAYER_1 then self:cropleft(0);
				else self:cropright(0);
				end;
			end;
			OffCommand=function(self)
				self:linear(revealTime);
				if pn == PLAYER_1 then self:cropleft(1);
				else self:cropright(1);
				end;
			end;
		};
	};
	
	-- hey how many times do i get the damn stats in this file?
	local stats = STATSMAN:GetCurStageStats():GetPlayerStageStats(pn);
	local steps = GAMESTATE:GetCurrentSteps(pn);
	local total = steps:GetRadarValues(pn):GetValue('RadarCategory_TapsAndHolds');
	local height = 0;
	local thisY = 96;
	local bCheck = false;
	
	local stack = Def.ActorFrame{
		InitCommand=function(self)
			if pn == PLAYER_1 then self:x(-5);
			else self:x(5);
			end;
		end;
	};
	
	Trace("AJ DEBUG [bars]: help i'm trapped in a driver's license factory");
	for i=1,#TNSTypes do
		
		if i > #TNSTypes then
			-- for every one after 1.
			bCheck = true;
		end;
		
		stack[#stack+1] = Def.Quad{
			Name=pn.."Bar"..i;
			InitCommand=cmd(zoom,26,0;ztest,true);
			OnCommand=function(self)
				if bCheck then
					local p = self:GetParent();
					local before = p:GetChild(pn.."Bar"..i-1);
					local prevHeight = before:GetHeight();
					Trace("AJ DEBUG [bars]: height of the bar before me is "..prevHeight);
					thisY = prevHeight+96;
				end;
				
				Trace( "AJ DEBUG [bars]: height of this bar should be "..((stats:GetTapNoteScores(TNSTypes[i]) / total) * 241) );
				self:vertalign(bottom);
				self:y(thisY);
				self:zoomy((stats:GetTapNoteScores(TNSTypes[i]) / total) * 240);
				self:diffuse( JudgeColor(TNSTypes[i]) );
			end;
		};
	end;
	
	b[#b+1] = stack;
	
	return b;
end;

-- bar
		--[[
		Bar(PLAYER_1)..{
			InitCommand=cmd(x,SCREEN_CENTER_X-158;y,SCREEN_CENTER_Y+48);
		};
		]]