local ExtraColorsLoaded = false

local Supercolour_CategoryNames = {
	'Vanilla',
	'Pre-Packed',
	'Plain',
	'Super Mystic',
	'Extras',
	'Extra Plain'
}

local Supercolour_SMSColors = {
    ['crisis'] = {SKINCOLOR_CRIMSON, SKINCOLOR_RED, SKINCOLOR_FLAME, SKINCOLOR_KETCHUP, SKINCOLOR_SUPERORANGE5},
    ['antimatter'] = {SKINCOLOR_CARBON, SKINCOLOR_BLACK, SKINCOLOR_JET, SKINCOLOR_SILVER, SKINCOLOR_GREY},
    ['priest'] = {SKINCOLOR_GREY, SKINCOLOR_SILVER, SKINCOLOR_SUPERSILVER5, SKINCOLOR_SUPERSILVER3, SKINCOLOR_SUPERSILVER1},
    ['bluewave'] = {SKINCOLOR_COBALT, SKINCOLOR_BLUE, SKINCOLOR_CORNFLOWER, SKINCOLOR_BLUEBELL, SKINCOLOR_AZURE},
    ['arcticchi'] = {SKINCOLOR_ICY, SKINCOLOR_AETHER, SKINCOLOR_BONE, SKINCOLOR_WHITE, SKINCOLOR_SUPERSILVER5},
    ['ranger'] = {SKINCOLOR_FOREST, SKINCOLOR_GREEN, SKINCOLOR_PERIDOT, SKINCOLOR_SUPERPERIDOT5, SKINCOLOR_SUPERPERIDOT2},
    ['pinkmenace'] = {SKINCOLOR_VIOLET, SKINCOLOR_LILAC, SKINCOLOR_ROSY, SKINCOLOR_PINK, SKINCOLOR_BUBBLEGUM},
    ['metallic'] = {SKINCOLOR_SUPERRUST5, SKINCOLOR_SUPERRUST4, SKINCOLOR_COPPER, SKINCOLOR_SUNSET, SKINCOLOR_GOLD},
    ['hazelglow'] = {SKINCOLOR_BLACK, SKINCOLOR_CARBON, SKINCOLOR_BRONZE, SKINCOLOR_BROWN, SKINCOLOR_BEIGE},
    ['ultradrive'] = {SKINCOLOR_BONE, SKINCOLOR_WHITE, SKINCOLOR_SUPERSILVER3, SKINCOLOR_SUPERSILVER2, SKINCOLOR_SUPERSILVER1},
    ['lapisvapor'] = {SKINCOLOR_DUSK, SKINCOLOR_CERULEAN, SKINCOLOR_BLUE, SKINCOLOR_SAPPHIRE, SKINCOLOR_BLUEBELL},
    ['azurebreaker'] = {SKINCOLOR_WAVE, SKINCOLOR_AZURE, SKINCOLOR_TEAL, SKINCOLOR_AQUA, SKINCOLOR_MOSS}
}

local Supercolour_Categories = {
	['Vanilla'] = {
		{n = 'Silver', a = 'Sonic Team Jr', sc = SKINCOLOR_SUPERSILVER1},
		{n = 'Red', a = 'Sonic Team Jr', sc = SKINCOLOR_SUPERRED1},
		{n = 'Orange', a = 'Sonic Team Jr', sc = SKINCOLOR_SUPERORANGE1},
		{n = 'Gold', a = 'Sonic Team Jr', sc = SKINCOLOR_SUPERGOLD1},
		{n = 'Peridot', a = 'Sonic Team Jr', sc = SKINCOLOR_SUPERPERIDOT1},
		{n = 'Sky', a = 'Sonic Team Jr', sc = SKINCOLOR_SUPERSKY1},
		{n = 'Purple', a = 'Sonic Team Jr', sc = SKINCOLOR_SUPERPURPLE1},
		{n = 'Rust', a = 'Sonic Team Jr', sc = SKINCOLOR_SUPERRUST1},
		{n = 'Tan', a = 'Sonic Team Jr', sc = SKINCOLOR_SUPERTAN1}
	},
	['Pre-Packed']  =  {
		{n = 'Mint', a = 'DirkTheHusky'},
		{n = 'Bubblegum', a = 'DirkTheHusky'},
		{n = 'Sapphire', a = 'DirkTheHusky'},
		{n = 'Wave', a = 'DirkTheHusky'},
		{n = 'Copper', a = 'DirkTheHusky'},
		{n = 'Ruby', a = 'DirkTheHusky'},
		{n = 'Aether', a = 'DirkTheHusky'},
		{n = 'Burning', a = 'Biggy-n'},
		{n = 'Emerald', a = 'Biggy-n'},
		{n = 'Lavender', a = 'Biggy-n'},
		{n = 'Rosy', a = 'Biggy-n'},
		{n = 'Raspberry', a = 'Biggy-n'},
		{n = 'Dark', a = 'Biggy-n'},
		{n = 'Brown', a = 'Biggy-n'},
		{n = 'Magenta', a = 'DirkTheHusky'},
		{n = 'PurpleRust', a = 'Biggy-n'},
		{n = 'RedGold', a = 'Biggy-n'},
		{n = 'RoseGold', a = 'Biggy-n'},
		{n = 'Cobalt', a = 'SuperPhanto'},
		{n = 'Sunset', a = 'SuperPhanto'},
		{n = 'Slate', a = 'SuperPhanto'},
		{n = 'Jet', a = 'DrStephen'},
		{n = 'Lime', a = 'DirkTheHusky'},
		{n = 'Wind', a = 'DirkTheHusky'},
		{n = 'Pseudo', a = 'furless'},
		{n = 'Topaz', a = 'Icezer'},
		{n = 'Aquatic', a = 'Icezer'},
		{n = 'Grape', a = 'Icezer'},
		{n = 'Lemon', a = 'SuperPhanto'},
		{n = 'Amethyst', a = 'Icezer'},
		{n = 'Prismarine', a = 'Icezer'},
		{n = 'Chrome', a = 'Icezer'},
		{n = 'Verglas', a = 'Icezer'},
		{n = 'Wine', a = 'Icezer'},
		{n = 'Toxin', a = 'Icezer'},
		{n = 'Volcanic', a = 'Icezer'},
		{n = 'Radish', a = 'Icezer'},
		{n = 'Shimmering', a = 'Icezer'},
		{n = 'Betacarotene', a = 'Icezer'},
		{n = 'Radiance', a = 'RainbowTH'},
		{n = 'Discovery', a = 'RainbowTH'},
		{n = 'Redemption', a = 'RainbowTH'},
		{n = 'Lovestruck', a = 'RainbowTH'},
		{n = 'Vortex', a = 'Icezer'},
		{n = 'Lightning', a = 'SuperPhanto'},
		{n = 'Spectrum', a = "Cobaltn't"},
		{n = 'LemonLime', a = "Cobaltn't"},
		{n = 'Festive', a = "Cobaltn't"},
		{n = 'VoidReborn', a = 'TheLastKitchenGun'},
		{n = 'Brimstone', a = 'TheLastKitchenGun'},
		{n = 'Xenomite', a = 'TheLastKitchenGun'},
		{n = 'PrimeSoul', a = 'TheLastKitchenGun'},
		{n = 'BurningHeart', a = 'Hajime'},
		{n = 'Aurora', a = 'Hajime'},
		{n = 'MistyRuby', a = 'Great Glass'},
		{n = 'Cyberspace', a = 'Great Glass'},
		{n = 'Paradox', a = 'Great Glass'},
		{n = 'Advance', a = 'Golden Shine'},
	},
	['Plain'] = {
	},
	['Super Mystic'] = {
		{n = 'Crisis', a = 'Golden Shine'},
		{n = 'Antimatter', a = 'Golden Shine'},
		{n = 'Priest', a = 'Golden Shine'},
		{n = 'BlueWave', a = 'Golden Shine'},
		{n = 'ArcticChi', a = 'Golden Shine'},
		{n = 'Ranger', a = 'Golden Shine'},
		{n = 'PinkMenace', a = 'Golden Shine'},
		{n = 'Metallic', a = 'Golden Shine'},
		{n = 'HazelGlow', a = 'Golden Shine'},
		{n = 'UltraDrive', a = 'Golden Shine'},
		{n = 'LapisVapor', a = 'Golden Shine'},
		{n = 'AzureBreaker', a = 'Golden Shine'},
		{n = 'GoldenShine', a = 'Golden Shine', sc = SKINCOLOR_SUPERGOLDENSHINE1}, --entry 13
		{n = 'Emperor', a = 'Golden Shine', sc = SKINCOLOR_SUPEREMPEROR1},
		{n = 'Flamebreaker', a = 'Golden Shine', sc = SKINCOLOR_SUPERFLAMEBREAKER1},
		{n = 'Mystical', a = 'Golden Shine', sc = SKINCOLOR_SUPERMYSTICAL1},
		{n = 'Blue', a = 'Golden Shine', sc = SKINCOLOR_SUPERBLUE1},
		{n = 'Transformation', a = 'Golden Shine', sc = SKINCOLOR_SUPERTRANSFORMATION1},
		{n = 'InfinitysEnd', a = 'Golden Shine', sc = SKINCOLOR_SUPERINFINITYSEND1}
	},
	['Extras'] = {
	},
	['Extra Plain'] = {
	}
}

local Supercolour_Buttons = {
-- 	'GC_FORWARD',
-- 	'GC_BACKWARD',
-- 	'GC_STRAFELEFT',
-- 	'GC_STRAFERIGHT',
-- 	'GC_TURNLEFT',
-- 	'GC_TURNRIGHT',
	'GC_WEAPONNEXT',
	'GC_WEAPONPREV',
	'GC_WEPSLOT1',
	'GC_WEPSLOT2',
	'GC_WEPSLOT3',
	'GC_WEPSLOT4',
	'GC_WEPSLOT5',
	'GC_WEPSLOT6',
	'GC_WEPSLOT7',
	'GC_WEPSLOT8',
	'GC_WEPSLOT9',
	'GC_WEPSLOT10',
	'GC_FIRE',
	'GC_FIRENORMAL',
	'GC_TOSSFLAG',
-- 	'GC_SPIN',
-- 	'GC_CAMTOGGLE',
	'GC_CAMRESET',
-- 	'GC_LOOKUP',
-- 	'GC_LOOKDOWN',
-- 	'GC_CENTERVIEW',
-- 	'GC_MOUSEAIMING',
-- 	'GC_TALKKEY',
-- 	'GC_TEAMKEY',
	'GC_SCORES',
-- 	'GC_JUMP',
-- 	'GC_CONSOLE',
-- 	'GC_PAUSE',
-- 	'GC_SYSTEMMENU',
-- 	'GC_SCREENSHOT',
-- 	'GC_RECORDGIF',
-- 	'GC_VIEWPOINT',
	'GC_CUSTOM1',
	'GC_CUSTOM2',
	'GC_CUSTOM3'
}

local function CMD_MenuButton(p, arg)
	if p then
		if not arg then
			
			local theList = ''
			local counter = 1
			
			for i = 1, 5 do
				for j = 1, 4 do
					if _G[Supercolour_Buttons[counter]] == p.superColourMenu.menuButton then
						theList = $..'\x82'..Supercolour_Buttons[counter]..'\x80, '
					else
						theList = $..Supercolour_Buttons[counter]..', '
					end
					counter = $ + 1
				end
				theList = $..'\n'
			end
			theList = $:sub(1,-4)
			
			CONS_Printf(p, "Rebinds the button used for opening the supercolor menu. (Uses GC_ Constants!)")
			CONS_Printf(p, "The following binds are available.\n\n"..theList)
		else
		
			arg = tostring($)
			if not (arg:sub(1,3):upper() == 'GC_') then
				arg = 'GC_'..($:upper())
			end
			
			local inList = false
			for i = 1, #Supercolour_Buttons do
				if arg == Supercolour_Buttons[i] then
					inList = true
				end
			end
			
			if _G[arg] and inList then
				p.superColourMenu.menuButton = _G[arg]
				CONS_Printf(p, "Button rebound to "..arg:sub(4)..'!')
			else
				CONS_Printf(p, "A valid button must be inputted.")
			end
			
		end
	else
		print("You must be in a level to use this command.")
	end
end

COM_AddCommand("supercolor_rebind", CMD_MenuButton)

local function CMD_MenuOpen(p, arg)
	if p and p.superColourMenu then
		p.superColourMenu.menuActive = not $
		p.superColourMenu.storedVars.angleturn = p.cmd.angleturn
		p.superColourMenu.storedVars.aiming = p.aiming
		p.superColourMenu.storedVars.angle = p.mo.angle
	else
		print("You must be in a level to use this command.")
	end
end

COM_AddCommand("supercolor_menu", CMD_MenuOpen)

addHook('PreThinkFrame', function()
	for p in players.iterate do
		if p.mo and p.mo.valid and p == consoleplayer and p.superColourMenu then
			local SCM = p.superColourMenu
			if SCM.menuActive then
				p.cmd.forwardmove = 0
				p.cmd.sidemove = 0
				p.cmd.buttons = 0
				p.cmd.angleturn = SCM.storedVars.angleturn
				p.aiming = SCM.storedVars.aiming
				p.mo.angle = SCM.storedVars.angle
			end
		end
	end
end)

local Supercolour_Controls = {
	GC_TURNLEFT,
	GC_TURNRIGHT,
	GC_LOOKUP,
	GC_LOOKDOWN,
	GC_JUMP,
	GC_STRAFELEFT,
	GC_STRAFERIGHT,
	GC_FORWARD,
	GC_BACKWARD,
	GC_CENTERVIEW
}

addHook('NetVars', function(n)
	ExtraColorsLoaded = n($)
	Supercolour_Categories = n($)
end)

local function Supercolour_refresh()
	Supercolour_Categories['Extra Plain'] = {}
	Supercolour_Categories['Extras'] = {}
	
	local daSkins = {}
	local daSupers = {}
	local daSupercolors = {}
	
	for i = 1, #Supercolour_Categories['Pre-Packed']
		daSupercolors[Supercolour_Categories['Pre-Packed'][i].n] = true
	end
	for i = 13, #Supercolour_Categories['Super Mystic']
		daSupercolors[Supercolour_Categories['Super Mystic'][i].n] = true
	end
			
	for i = 1, #skins do
		if skins[i] then
			daSkins[skins[i].prefcolor] = skins[i].realname
			daSupers[skins[i].supercolor] = skins[i].realname
		end
	end
	
	for i = 114, #skincolors-1 do
	
		--if skincolors[i].accessible then
		if R_GetColorByName(R_GetNameByColor(i):lower()) and not (R_GetSuperColorByName(R_GetNameByColor(i):sub(7, -3)) or skincolors[i].name:len() == 0) then
			table.insert(Supercolour_Categories['Extra Plain'], {n = skincolors[i].name, sc = i})
			if daSkins[i] then
				Supercolour_Categories['Extra Plain'][#Supercolour_Categories['Extra Plain']].a = 'From '..daSkins[i]
			end
		end
					
		
		if (R_GetSuperColorByName(R_GetNameByColor(i):sub(7, -3))) and not daSupercolors[R_GetNameByColor(i):sub(7, -3)] then
			--print('a')
			daSupercolors[R_GetNameByColor(i):sub(7, -3)] = true
			
			table.insert(Supercolour_Categories['Extras'], {n = R_GetNameByColor(i):sub(7, -3), sc = i})
			if daSupers[i] then
				Supercolour_Categories['Extras'][#Supercolour_Categories['Extras']].a = 'From '..daSupers[i]
			end
		end
		
	end
end
COM_AddCommand("supercolor_refresh", Supercolour_refresh)

local fucktheseskins = { --for supers that use standard colors
	['adventuresonic'] = 'sadxsupersonic',
	['supersonic'] = 'firestormsuper'
}

addHook('KeyDown', function(key)
	local p = consoleplayer
	if p and p.mo and p.mo.valid and p.superColourMenu and key.name == 'backspace' then
	
		local SCM = p.superColourMenu
		local targetcolor = skins[p.mo.skin].supercolor
		
		if fucktheseskins[p.mo.skin] then
			targetcolor = R_GetColorByName(fucktheseskins[p.mo.skin])
		end
		
		if SCM.menuActive and not (Supercolour_Categories[Supercolour_CategoryNames[SCM.currentColor[1]]][SCM.currentColor[2][SCM.currentColor[1]]].sc == targetcolor) then
			for i = 1, #Supercolour_CategoryNames
				local cate = Supercolour_Categories[Supercolour_CategoryNames[i]]
				for j = 1, #cate
					if cate[j].sc == targetcolor then
						SCM.currentColor[1] = i
						SCM.currentColor[2][i] = j
						S_StartSound(nil, sfx_addfil, p)
						break
					end
				end
			end
		end
	end
end)

addHook('ThinkFrame', function()
	if not ExtraColorsLoaded then
		for i = 1, #Supercolour_Categories['Pre-Packed']
			Supercolour_Categories['Pre-Packed'][i].sc = R_GetSuperColorByName(Supercolour_Categories['Pre-Packed'][i].n)
		end
		
		Supercolour_Categories['Pre-Packed'][58].sc = SKINCOLOR_SUPERADVANCEGOLD
		
		for i = 1, 68 do
			table.insert(Supercolour_Categories['Plain'], {n = skincolors[i].name, a = 'Sonic Team Jr', sc = i})
		end
		ExtraColorsLoaded = true
		
	end
		
	if (leveltime == 1 and ExtraColorsLoaded) then
		Supercolour_refresh()
	end
	
	for p in players.iterate do
		if p.mo and p.mo.valid and p == consoleplayer then
			if not p.superColourMenu then
				p.superColourMenu = {
					menuButton = GC_TOSSFLAG,
					buttonsDown = {},
					menuActive = false,
					hudVars = {
						tics = 0
					},
					storedVars = {
						angleturn = 0,
						aiming = 0,
						angle = 0
					},
					currentColor = {1,{4,1,1,1,1,1}},
					angle = 2,
					inverseControls = false
				}
			else
				local SCM = p.superColourMenu
			
				if SCM.menuActive then
					SCM.hudVars.tics = min($ + 1,16)
					 
					local move = 1
					if input.gameControlDown(GC_SPIN) then
						move = 4
					end
					
					local G_UP = GC_LOOKUP
					local G_DOWN = GC_LOOKDOWN
					local G_LEFT = GC_TURNLEFT
					local G_RIGHT = GC_TURNRIGHT
					local M_LEFT = GC_STRAFELEFT
					local M_RIGHT = GC_STRAFERIGHT
					
					if input.gameControlDown(GC_CENTERVIEW) and not SCM.buttonsDown[GC_CENTERVIEW] then
						SCM.inverseControls = not $
						S_StartSound(nil, sfx_s3k63, p)
					end
					if SCM.inverseControls then
						G_UP = GC_FORWARD
						G_DOWN = GC_BACKWARD
						G_LEFT = GC_STRAFELEFT
						G_RIGHT = GC_STRAFERIGHT
						M_LEFT = GC_TURNLEFT
						M_RIGHT = GC_TURNRIGHT
					end
					
					if #Supercolour_Categories[Supercolour_CategoryNames[SCM.currentColor[1]]] > 0 then
						if input.gameControlDown(G_UP) and not SCM.buttonsDown[G_UP] then
							S_StartSound(nil, sfx_menu1, p)
							SCM.currentColor[2][SCM.currentColor[1]] = $ - move
							if SCM.currentColor[2][SCM.currentColor[1]] <= 0 then
								SCM.currentColor[2][SCM.currentColor[1]] = #Supercolour_Categories[Supercolour_CategoryNames[SCM.currentColor[1]]]
							end
						end
						
						if input.gameControlDown(G_DOWN) and not SCM.buttonsDown[G_DOWN] then
							S_StartSound(nil, sfx_menu1, p)
							SCM.currentColor[2][SCM.currentColor[1]] = $ + move
							if SCM.currentColor[2][SCM.currentColor[1]] > #Supercolour_Categories[Supercolour_CategoryNames[SCM.currentColor[1]]] then
								SCM.currentColor[2][SCM.currentColor[1]] = 1
							end
						end
						
						if input.gameControlDown(GC_JUMP) and not SCM.buttonsDown[GC_JUMP] then
							S_StartSound(nil, sfx_s1c3, p)
							SCM.menuActive = false
							p.pflags = $ | PF_JUMPDOWN
							
							--TODO: Does this work???
							local def = Supercolour_Categories[Supercolour_CategoryNames[SCM.currentColor[1]]][SCM.currentColor[2][SCM.currentColor[1]]]
							if (SCM.currentColor[1] == 1 or (SCM.currentColor[1] == 2 and SCM.currentColor[2][2] < 58) or SCM.currentColor[1] == 5 or (SCM.currentColor[1] == 4 and SCM.currentColor[2][4] >= 13)) then --normally flashing supercolors
								p.scolor = R_GetSuperColorByName(def.n)
								p.scolorstring = 'Super Color'
							elseif (SCM.currentColor[1] == 3 or SCM.currentColor[1] == 6) then -- static colors
								p.scolor = R_GetColorByName(def.n)
								p.scolorstring = 'N_ Colour'
							elseif (SCM.currentColor[1] == 2 and SCM.currentColor[2][2] == 58) then -- advance
								p.scolor = 'advance'
								p.scolorstring = 'Advance'
							elseif (SCM.currentColor[1] == 4 and SCM.currentColor[2][4] < 13) -- SMS
								p.scolor = def.n:lower()
								p.scolorstring = 'SMS'
							end	
						end
						
					end
					
					if input.gameControlDown(M_LEFT) and not SCM.buttonsDown[M_LEFT] then
						SCM.angle = $ + 1
						if SCM.angle == 9 then
							SCM.angle = 1
						end
					end
					
					if input.gameControlDown(M_RIGHT) and not SCM.buttonsDown[M_RIGHT] then
						SCM.angle = $ - 1
						if SCM.angle == 0 then
							SCM.angle = 8
						end
					end
					
					if input.gameControlDown(G_LEFT) and not SCM.buttonsDown[G_LEFT] then
						S_StartSound(nil, sfx_s3kb7, p)
						SCM.currentColor[1] = $ - 1
						if SCM.currentColor[1] == 0 then
							SCM.currentColor[1] = #Supercolour_CategoryNames
						end
					end
					
					if input.gameControlDown(G_RIGHT) and not SCM.buttonsDown[G_RIGHT] then
						S_StartSound(nil, sfx_s3kb7, p)
						SCM.currentColor[1] = $ + 1
						if SCM.currentColor[1] > #Supercolour_CategoryNames then
							SCM.currentColor[1] = 1
						end
					end
				else
					SCM.hudVars.tics = max($ - 1,0)
				end
			
				if input.gameControlDown(SCM.menuButton) and not SCM.buttonsDown[SCM.menuButton] then
					S_StartSound(nil, sfx_tink, p)
					SCM.menuActive = not $
					SCM.storedVars.angleturn = p.cmd.angleturn
					SCM.storedVars.aiming = p.aiming
					SCM.storedVars.angle = p.mo.angle
				end
				
				SCM.buttonsDown[SCM.menuButton] = input.gameControlDown(SCM.menuButton)
				for i = 1, #Supercolour_Controls do
					SCM.buttonsDown[Supercolour_Controls[i]] = input.gameControlDown(Supercolour_Controls[i])
				end
			end
		end
	end
end)
/*
s - start
e - end
t - time (0 - FU)
*/
 -- trying to steal from lactozilla now

local function fixinterp(s,e,t)
	return FixedMul((FU - (t)), s) + FixedMul(t, e)
end

local function ease_OutQuad(t,s,e)
	return fixinterp(s, e, FU - FixedMul(FU - t, FU - t))
end

local function adjustHUDTrans(v, num)
	local theShift = min(10,(v.localTransFlag()>>V_ALPHASHIFT)+num)
	--print(theShift)
	if theShift >= 10
		return false
	end
	return (theShift<<V_ALPHASHIFT)
end

local function Supercolour_menu(v, p) --TOUHOU HIJACK LOL (joke)
	if p.mo and p.mo.valid and p.superColourMenu then
		local SCM = p.superColourMenu
		
		
		local alpha = adjustHUDTrans(v, 16-SCM.hudVars.tics)
		if alpha != false then
			local alphaAdvance = adjustHUDTrans(v, 5 - (5 - (min(SCM.hudVars.tics,5))))
			local player_patch, player_flipped = v.getSprite2Patch(p.skin, SPR2_STND, true, A, SCM.angle)
			local colormap
			local colordefs
			
			local targetcolor = skins[p.mo.skin].supercolor
					
			if fucktheseskins[p.mo.skin] then
				targetcolor = R_GetColorByName(fucktheseskins[p.mo.skin])
			end
			
			v.fadeScreen(0xFA00, min(SCM.hudVars.tics / 2, 10))
			
			if #Supercolour_Categories[Supercolour_CategoryNames[SCM.currentColor[1]]] > 0 then
				 colordefs = Supercolour_Categories[Supercolour_CategoryNames[SCM.currentColor[1]]][SCM.currentColor[2][SCM.currentColor[1]]]
				
				if (SCM.currentColor[1] == 3 or (SCM.currentColor[1] == 2 and SCM.currentColor[2][2] == 58) or SCM.currentColor[1] == 6) then -- plain
					colormap = v.getColormap(p.skin, colordefs.sc)
				elseif SCM.currentColor[1] == 4 and SCM.currentColor[2][4] < 13 then -- sms
					colormap = v.getColormap(p.skin, Supercolour_SMSColors[colordefs.n:lower()][abs( ( (leveltime >> 1) % 9) - 4) + 1])
				else
					colormap = v.getColormap(p.skin, colordefs.sc + abs(((leveltime >> 1) % 9) - 4))
				end
				
				if colordefs.a then
					v.drawString(95*FU, ease_OutQuad(min(FU, SCM.hudVars.tics*FU/16), 300*FU, 150*FU), "\x82" .. "Credits: \x80" .. colordefs.a, V_ALLOWLOWERCASE|alpha, "small-fixed-center")
				end
				
				for i = -4, 4 do
					if not Supercolour_Categories[Supercolour_CategoryNames[SCM.currentColor[1]]][SCM.currentColor[2][SCM.currentColor[1]] + i] then
						continue
					end
					
					local color_default = (Supercolour_Categories[Supercolour_CategoryNames[SCM.currentColor[1]]][SCM.currentColor[2][SCM.currentColor[1]] + i].sc == targetcolor) and V_GREENMAP or 0
					if i == 0 then
						v.drawString(ease_OutQuad(min(FU, SCM.hudVars.tics*FU/16), -150*FU, 95*FU), 101*FU, "\x1D"..(((leveltime % 20) / 10) and "  " or " ")..Supercolour_Categories[Supercolour_CategoryNames[SCM.currentColor[1]]][SCM.currentColor[2][SCM.currentColor[1]] + i].n..(((leveltime % 20) / 10) and "  " or " ").."\x1C", V_ALLOWLOWERCASE|V_YELLOWMAP|alpha, "thin-fixed-center")
					else
						if (input.gameControlDown(GC_SPIN) and abs(i) < 4) then
							color_default = $ and V_MAGENTAMAP or V_REDMAP
						end
						v.drawString(ease_OutQuad(min(FU, SCM.hudVars.tics*FU/16), -150*FU, 95*FU), 101*FU + 10*i*FU, Supercolour_Categories[Supercolour_CategoryNames[SCM.currentColor[1]]][SCM.currentColor[2][SCM.currentColor[1]] + i].n, V_ALLOWLOWERCASE|color_default|alpha, "thin-fixed-center")
					end
				end	
				
			else
				colormap = v.getColormap(p.skin, skins[p.mo.skin].supercolor + abs(((leveltime >> 1) % 9) - 4))
				if fucktheseskins[p.mo.skin] then
					colormap = v.getColormap(p.skin, targetcolor)
				end
				v.drawString(ease_OutQuad(min(FU, SCM.hudVars.tics*FU/16), -150*FU, 95*FU), 101*FU, "\x1D"..(((leveltime % 20) / 10) and "  " or " ")..'No colors here!'..(((leveltime % 20) / 10) and "  " or " ").."\x1C", V_ALLOWLOWERCASE|V_REDMAP|alpha, "thin-fixed-center")
			end
			
			v.drawNameTag(160, ease_OutQuad(min(FU, SCM.hudVars.tics*FU/16), -30*FU, 8*FU)/FU, "Supercolor Menu", V_CENTERNAMETAG|alpha, p.skincolor, skincolors[p.skincolor].invcolor)

			v.drawScaled(ease_OutQuad(min(FU, SCM.hudVars.tics*FU/16), 500*FU, 245*FU), 100*FU + ((player_patch.height / 2) * skins[p.skin].highresscale), skins[p.skin].highresscale, player_patch, (player_flipped and V_FLIP or 0)|alpha, colormap)			
			
			if ((SCM.currentColor[1] == 2 and SCM.currentColor[2][2] == 58) and leveltime % 2 == 0) then
				v.drawScaled(ease_OutQuad(min(FU, SCM.hudVars.tics*FU/16), 500*FU, 245*FU), 100*FU + ((player_patch.height / 2) * skins[p.skin].highresscale), skins[p.skin].highresscale, player_patch, (player_flipped and V_FLIP or 0)|alphaAdvance|V_ADD, colormap)
			end
			
			v.drawString(245*FU, ease_OutQuad(min(FU, SCM.hudVars.tics*FU/16), 300*FU, 115*FU + ((player_patch.height / 2) * skins[p.skin].highresscale)), "\x1C"..(((leveltime % 20) / 10) and "  " or " ").."\x1D", V_YELLOWMAP|alpha, "fixed-center")
			
			v.drawString(ease_OutQuad(min(FU, SCM.hudVars.tics*FU/16), -150*FU, 95*FU), 50*FU, Supercolour_CategoryNames[SCM.currentColor[1]], V_ALLOWLOWERCASE|V_YELLOWMAP|alpha, "fixed-center")
			
			v.drawString(ease_OutQuad(min(FU, SCM.hudVars.tics*FU/16), -500*FU, 160*FU), 165*FU, '* [JUMP] selects the colour chosen.', V_ALLOWLOWERCASE|alpha, "small-fixed-center")
			v.drawString(ease_OutQuad(min(FU, SCM.hudVars.tics*FU/16), 500*FU, 160*FU), 170*FU, '* ['..(SCM.inverseControls and 'STRAFE' or 'CAMERA')..' CONTROLS] navigates the UI.', V_ALLOWLOWERCASE|alpha, "small-fixed-center")
			v.drawString(ease_OutQuad(min(FU, SCM.hudVars.tics*FU/16), -500*FU, 160*FU), 175*FU, '* ['..(SCM.inverseControls and 'CAMERA' or 'STRAFE')..' CONTROLS] rotates the player.', V_ALLOWLOWERCASE|alpha, "small-fixed-center")
			v.drawString(ease_OutQuad(min(FU, SCM.hudVars.tics*FU/16), 500*FU, 160*FU), 180*FU, '* [SPIN] can be used to skip through colours faster.', V_ALLOWLOWERCASE|alpha, "small-fixed-center")
			v.drawString(ease_OutQuad(min(FU, SCM.hudVars.tics*FU/16), -500*FU, 160*FU), 185*FU, '* [CENTER VIEW] swaps the controls used in the menu.', V_ALLOWLOWERCASE|alpha, "small-fixed-center")
			v.drawString(ease_OutQuad(min(FU, SCM.hudVars.tics*FU/16), 500*FU, 160*FU), 190*FU, '* [BACKSPACE] will return color selection to character default.', V_ALLOWLOWERCASE|alpha, "small-fixed-center")
		end
	end
end
	
hud.add(Supercolour_menu, 'game')