--I'm going to have to give most of the credit for this method to the Infected Wars team. Their math fuels most of this code.
local PowRadialOpen = false
function ThinkHook()
	if not PowRadialOpen then
		if LocalPlayer():KeyPressed(IN_RELOAD) then
		PowRadialOpen = true
		StanceStart()
		end
	elseif not LocalPlayer():KeyDown(IN_RELOAD) then
	StanceEnd()
	PowRadialOpen = false
	end
end
hook.Add("Think", "ThinkHook", ThinkHook)

local stances = {"Increase Shields", "Increase Engines", "Decrease Engines", "Decrease Shields", "Decrease Weapons", "Increase Weapons"}
local stances2 = {"Max Shields", "Max Engines", "Min Engines", "Min Shields", "Min Weapons", "Max Weapons"}

function GetCurrentStance()
	
	local x = ScrW()/2 - gui.MouseX()
	local y = ScrH()/2 - gui.MouseY()
	local step = 360 / #stances
	if math.abs(x) + math.abs(y) < 75 then
	return "fail"
	else
	local angle = math.deg(math.atan2(-x,y))
	if angle < 0 then 
    angle = angle + 360
    end
	local j = math.Round(angle / step) + 1
		if math.abs(x) + math.abs(y) > 200 then
		j = j + 6
			if (j > 12) then 
    		j = 7
			end	
		elseif (j > #stances) then 
    	j = 1	
    	end


	return j
	end
end

function StanceMenuPaint()
	
	local ply = LocalPlayer()
	local teamcol = Color(0,255,0)
	if #stances > 0 then
		local count = #stances
		local dist = 360 / count
		
		surface.SetDrawColor(teamcol)
		if (gui.MouseX() ~= 0 && gui.MouseY() ~= 0) then
			surface.DrawLine((ScrW()/2),(ScrH()/2),gui.MouseX(),gui.MouseY())
		end
		local angle = 180
		for k, item in pairs(stances) do
			local x = (ScrW()/2) + (math.sin(math.rad(angle)) * 135)
			local y = (ScrH()/2) + (math.cos(math.rad(angle)) * 135)

			local color = teamcol
			if k > 2 && k < 6 then
    			local r = color.r
    			local g = color.g
    			local b = color.b
    			if r == 0 then
    			r = 255
    			else
    			r = 0
    			end
    			if g == 0 then
    			g = 255
    			else
    			g = 0
    			end
    			if b == 0 then
    			b = 255
    			else
    			b = 0
    			end
    		color = Color(r,g,b,255)
    		elseif k > 6 then
    		color = Color(115,115,115,255)
			end
			local color2 = Color(0,0,0,255)
			if (GetCurrentStance() == k) then
				color2 = Color(255,255,255,255)
			end
			local w = 150
			local h = 40
			draw.RoundedBox( 10, x-(w/2),y - (h/2),w,h, Color(0, 0, 0, 200) )			
			draw.SimpleTextOutlined(item,"MenuLarge",x ,y, color,TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 2, color2 )
		
			angle = angle - dist
		end
		
		for k, item in pairs(stances2) do
			local x = (ScrW()/2) + (math.sin(math.rad(angle)) * 250)
			local y = (ScrH()/2) + (math.cos(math.rad(angle)) * 250)

			local color = teamcol
			if k > 2 && k < 6 then
    			local r = color.r
    			local g = color.g
    			local b = color.b
    			if r == 0 then
    			r = 255
    			else
    			r = 0
    			end
    			if g == 0 then
    			g = 255
    			else
    			g = 0
    			end
    			if b == 0 then
    			b = 255
    			else
    			b = 0
    			end
    		color = Color(r,g,b,255)
    		elseif k > 6 then
    		color = Color(115,115,115,255)
			end
			local color2 = Color(0,0,0,255)
			if (GetCurrentStance() == k + 6) then
				color2 = Color(255,255,255,255)
			end
			local w = 150
			local h = 40
			draw.RoundedBox( 10, x-(w/2),y - (h/2),w,h, Color(0, 0, 0, 200) )			
			draw.SimpleTextOutlined(item,"MenuLarge",x ,y, color,TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 2, color2 )
		
			angle = angle - dist
		end
	end
end

function StanceStart()
	gui.EnableScreenClicker(true) 
	gui.SetMousePos(ScrW()/2,ScrH()/2)
hook.Add("HUDPaint","StanceMenuPaint",StanceMenuPaint)
hook.Add("GUIMousePressed","StanceClick",StanceClick)
end

function StanceClick(num)
if num == 107 then
RunConsoleCommand("-wmstanceradial")
end
end

function StanceEnd()
local selection = GetCurrentStance()
if selection ~= "fail" then
	if selection == 1 then
RunConsoleCommand("sNRGup")
	elseif selection == 2 then
RunConsoleCommand("eNRGup")
	elseif selection == 3 then
RunConsoleCommand("eNRGDown")
	elseif selection == 4 then
RunConsoleCommand("sNRGDown")
	elseif selection == 5 then
RunConsoleCommand("wNRGDown")
	elseif selection == 6 then
RunConsoleCommand("wNRGUp")
	elseif selection == 7 then
	for i=0, 3 do 
RunConsoleCommand("sNRGup")
end
	elseif selection == 8 then
	for i=0, 3 do 
RunConsoleCommand("eNRGup")
end
	elseif selection == 9 then
for i=0, 3 do 
RunConsoleCommand("eNRGDown")
end
	elseif selection == 10 then
	for i=0, 3 do 
RunConsoleCommand("sNRGDown")
	end
	elseif selection == 11 then
	for i=0, 3 do 
RunConsoleCommand("wNRGDown")
	end
	elseif selection == 12 then
	for i=0, 3 do 
RunConsoleCommand("wNRGUp")
	end
	end
end
hook.Remove("HUDPaint","StanceMenuPaint")
hook.Remove("GUIMousePressed","StanceClick")
gui.EnableScreenClicker(false)
end

concommand.Add("+wmstanceradial", StanceStart);
concommand.Add("-wmstanceradial", StanceEnd);

teleportlocations = {"New TP Marker"}
--teleportlocations[0] = "New TP Marker"
local tpoptions = {"Delete", "Rename", "Overwrite"}

function GetCurrentTPSel()
	
	local x = ScrW()/2 - gui.MouseX()
	local y = ScrH()/2 - gui.MouseY()
	local step = 360 / table.Count(teleportlocations)
	if math.abs(x) + math.abs(y) < 110 then
	return "cycle"
	else
	local angle = math.deg(math.atan2(-x,y))
    	if angle < 0 then 
        angle = angle + 360
        end
	local j = math.Round(angle / step) + 1
    	if (j > table.Count(teleportlocations))then 
    		j = 1	
    	end
	return j
	end
end

function GetCurrentTPSel2(origin)
	local x = ScrW()/2 - gui.MouseX()
	local y = ScrH()/2 - gui.MouseY()
	local step = 360 / (table.Count(teleportlocations) * 12)
	local origin = math.abs(origin - 180)
        if math.abs(x) + math.abs(y) > 275 then
    	local angle = math.deg(math.atan2(-x,y))
        	if angle < 0 then 
            angle = angle + 360
            end
    	local j = math.AngleDifference(angle,origin)
        	if j <=  -step then
        	j = 3
        	elseif j > -step && j < step then
        	j = 2
        	elseif j >= step then
        	j = 1
        	end
        --LocalPlayer():PrintMessage(HUD_PRINTTALK, j )         
    	return j
    	else
    	return 9999
    	end
end

local submenu = 1
local submenupointer = 1
function TeleportMenuPaint()
if LocalPlayer():KeyDown(IN_JUMP) then
RunConsoleCommand("-wmteleportradial")
end	
	local ply = LocalPlayer()
	local teamcol = team.GetColor(ply:Team())
	if table.Count(teleportlocations) > 0 then
		local count = table.Count(teleportlocations)
		local dist = 360 / count
		
		surface.SetDrawColor(teamcol)
		if (gui.MouseX() ~= 0 && gui.MouseY() ~= 0) then
			surface.DrawLine((ScrW()/2),(ScrH()/2),gui.MouseX(),gui.MouseY())
		end
		local angle = 180
		local w = 110
		local h = 40
		local tempcount = 0
		for k, item in pairs(teleportlocations) do
		tempcount = tempcount + 1
			local x = (ScrW()/2) + (math.sin(math.rad(angle)) * 135)
			local y = (ScrH()/2) + (math.cos(math.rad(angle)) * 135)

			local color = teamcol
			if k == 1 then
    			local r = color.r
    			local g = color.g
    			local b = color.b
    			if r == 0 then
    			r = 255
    			else
    			r = 0
    			end
    			if g == 0 then
    			g = 255
    			else
    			g = 0
    			end
    			if b == 0 then
    			b = 255
    			else
    			b = 0
    			end
    		color = Color(r,g,b,255)
			end
			local color2 = Color(0,0,0,255)
			if (GetCurrentTPSel() == tempcount) then
				color2 = Color(255,255,255,255)
				submenupointer = k
			     if tempcount ~= 1 then
        			     
        			local subangle = 180 / (table.Count(teleportlocations) * 3) * -1
        			local insubmenu = false
            		  for e, r in pairs (tpoptions) do
            		    
                		 local x2 = (ScrW()/2) + (math.sin(math.rad(angle + subangle)) * 275)
            			 local y2 = (ScrH()/2) + (math.cos(math.rad(angle + subangle)) * 275)
            			 local color4 = Color(0,0,0,255)
            			if GetCurrentTPSel2(angle) == e then 
                        color4 = Color(255,255,255,255)
                        submenu = e
                        insubmenu = true
                        elseif e == 3 && insubmenu == false then
                        submenu = 9999
                        end
                		draw.RoundedBox( 10, x2-(95/2),y2 - (30/2),95,30, Color(0, 0, 0, 125) )			
            			draw.SimpleTextOutlined(r,"MenuLarge",x2 ,y2, color,TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 2, color4 )
            			subangle = subangle + (180 / (table.Count(teleportlocations) * 3))
            		  end
            	 end
			end
			draw.RoundedBox( 10, x-(w/2),y - (h/2),w,h, Color(0, 0, 0, 200) )			
			draw.SimpleTextOutlined(item,"MenuLarge",x ,y, color,TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 2, color2 )
		
			angle = angle - dist
		end
		
		local color3 = Color(0,0,0,255)
		if GetCurrentTPSel() == "cycle" then color3 = Color(255,255,255,255) end
		draw.RoundedBox( 10, (ScrW()/2)-(w/2),(ScrH()/2) - (h/2),w,h, Color(0, 0, 0, 200) )			
		draw.SimpleTextOutlined("Cycle","MenuLarge",(ScrW()/2) ,(ScrH()/2), Color(100,100,100,255),TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 2,  color3 )
	end
end

