-- This code is likely to become convoluted so it's going in another file.
-- Porting over the cool mod icons to eval itLf (in this Lua file)

-- IF THERE'S NO PLAYER I'M GONNA SHIT ON YOUR HEAD!!!!!!!!!!!!!!!!!!!!!!!
local Player = ...
assert(Player);

local icons = Def.ActorFrame{};

-- it's really a pain to modify the original because I don't understand it
-- now that I go back to it. Let's try to simplify.
local function OptionIcons()
	-- make the ActorFrame to store the icons.
	local u = Def.ActorFrame{
		Name="OptionIcons"..Player;
	};
	
	-- I moved it here for no good reason
	local function MakeIcon(text,myX,myY)
		u[#u+1] = Def.ActorFrame{
			InitCommand=cmd(x,myX;y,myY);
			
			LoadActor("_optionicon")..{
				InitCommand=cmd(diffuse,PlayerColor(Player);diffusealpha,0.8);
			};
			LoadFont("_frutiger lt std 55 roman 24px")..{
				Text=text;
				InitCommand=cmd(zoom,0.5;diffuse,color("#FFFFFF");shadowlength,1;maxwidth,90);
			};
		};
	end;
	
	-- set the max icons per column. (22*16 = 352 which is slightly less than
	-- SCREEN_HEIGHT for pretty much everyone.)
	-- Perhaps change this to be based on 75% of SCREEN_HEIGHT later?
	local maxIconsPerColumn = 22;
	
	-- get the options.
	local PlayerState = GAMESTATE:GetPlayerState(Player);
	-- grab the song options from this PlayerState.
	local options = PlayerState:GetPlayerOptions('ModsLevel_Preferred');
	-- now using split, let's put them into a table for comparison
	local listOfOptions = split(", ", options);
	-- find out how many options are in play.
	local numOptions = #listOfOptions;
	
	-- perform some checks here.
	if #listOfOptions == 0 then
		-- no options, we don't need to be here wasting my cycles which
		-- can be used up by other advanced functions.
		return;
	-- here's where it starts getting tricky.
	elseif #listOfOptions > maxIconsPerColumn then
		-- oh crap they used SO MANY MODS that we need another column.
		for i=1,#listOfOptions do
			-- set text
			local text = listOfOptions[i];
			
			-- find out where we are.
			-- first, horizontal.
			local xPos = 0;
			if i < (maxIconsPerColumn/2)+1 then
				-- shift first column left
				xPos = -47;
			end;
			-- then, vertical.
			local yPos = 0;
			if i > (maxIconsPerColumn/2) then
				-- reset y for second column
				yPos = 0;
			else
				yPos = i;
			end;
			
			MakeIcon(text,xPos,(yPos * 15)-1);
		end;
	else
		-- the more sensible version.
		for i=1,#listOfOptions do
			-- set text
			local text = listOfOptions[i];
			
			-- find out where we are.
			-- vertical only, there's one column!
			local yPos = 0;
			if i > (maxIconsPerColumn/2) then
				-- reset y for second column
				yPos = 0;
			else
				yPos = i;
			end;
			
			MakeIcon(text,0,(yPos * 15)-1);
		end;
	end;
	
	return u;
end;

icons[#icons+1] = OptionIcons();

return icons;