-- Allows player to set their radio station
-- author: robo

function openRadioMenu()

	-- make sure they can't set their channel before they have picked one up.
	if( LocalPlayer():GetNWFloat("radioChannel") == 0 ) then
	
		return;
	
	end

	if( radioFrame != nil ) then
	
		radioFrame:Remove();
		radioFrame = nil;
	
	end
	
	if( CAKE.PlayerMenu != nil ) then
		CAKE.PlayerMenu:Close();
	end
	
	local radioFrame = vgui.Create( "DFrame" );
	radioFrame:SetPos( ScrW() / 2 - 230, ScrH() / 2 - 60 );
	radioFrame:SetSize( 250, 60 );
	radioFrame:SetTitle( "Set your channel." );
	radioFrame:SetDraggable( true );
	radioFrame:ShowCloseButton( true );
	
	local radioEntry = vgui.Create( "DTextEntry", radioFrame );
	radioEntry:SetPos( 10, 30 );
	radioEntry:SetSize( 180, 15 );
	radioEntry:SetEnabled( true );
	radioEntry:SetKeyboardInputEnabled( true );
	radioEntry:SetMouseInputEnabled( true );
	radioEntry:SetValue( tostring( LocalPlayer():GetNWFloat("radioChannel") ) );
	
	local applyChannel = vgui.Create( "DButton", radioFrame );
	applyChannel:SetPos( 200, 30 );
	applyChannel:SetSize( 40, 20 );
	applyChannel:SetText("Apply");
	applyChannel.DoClick = function ( btn )
	
		RunConsoleCommand("rp_setRadio", radioEntry:GetValue(), "\n");
		radioFrame:Close();
	
	end
	
	radioFrame:MakePopup();

end
usermessage.Hook("openRadioMenu", openRadioMenu);