include('shared.lua')

SWEP.PrintName = "Build PDA"
SWEP.Slot = 2
SWEP.SlotPos = 3
SWEP.DrawAmmo = false
SWEP.DrawCrosshair = false
SWEP.ViewModelFOV = 68
SWEP.ViewModelFlip = false

SWEP.WepSelectIcon = surface.GetTextureID("sprites/bucket_pda_build") 

function SWEP:ItemChosen(itemint)
	if itemint != "false" then self.item = itemint else self.item = nil end
end

function SWEP:DrawHUD()
	local team = "red"
	if LocalPlayer():Team() == 1 then
		team = "blue"
	end
	local ammo = LocalPlayer():GetNetworkedInt( "ammo_metal" )
	
	local scale_w = LocalPlayer():GetPanelScale()[1]
	local scale_h = LocalPlayer():GetPanelScale()[2]
			
	local tex=surface.GetTextureID("HUD/misc_ammo_area_" .. team)
	surface.SetTexture(tex)
	surface.SetDrawColor(255,255,255,255)
	surface.DrawTexturedRect(ScrW() *0.79, ScrH() *0.86, 235 /scale_w, 110 /scale_h )
			
	draw.SimpleText(ammo, "TF2_font_eng_metal", ScrW() *0.866, ScrH() *0.91, Color(239,228,195,255), 1, 1)
	local tex=surface.GetTextureID("HUD/ico_metal")
	surface.SetTexture(tex)
	surface.DrawTexturedRect(ScrW() *0.814, ScrH() *0.884, 32 /scale_w, 32 /scale_h )
	
	if self.item then return end

	local tex=surface.GetTextureID("HUD/eng_build_bg")
	surface.SetTexture(tex)
	surface.SetDrawColor(255,255,255,255)
	surface.DrawTexturedRect(ScrW() *0.5 -580 /scale_w, ScrH() *0.5 -240 /scale_h, 1160 /scale_w, 570 /scale_h )
			
	local tex=surface.GetTextureID("HUD/ico_build")
	surface.SetTexture(tex)
	surface.SetDrawColor(255,255,255,255)
	surface.DrawTexturedRect(ScrW() *0.54 -580 /scale_w, ScrH() *0.474 -240 /scale_h, 128 /scale_w, 128 /scale_h )
			
	draw.SimpleText("BUILD", "TF2_font_build_dpa1", ScrW() *0.358, ScrH() *0.334, Color(236,227,203,255), 1, 1)
	
	local ammo = LocalPlayer():GetNetworkedInt( "ammo_metal" )
	local color = Color(255,255,255,255)
			
	local ico_a_color = Color(255,255,255,255)
	local ico_b_color = Color(255,255,255,255)
	local ico_c_color = Color(255,255,255,255)
	local ico_d_color = Color(255,255,255,255)
			
	if (!LocalPlayer():GetNetworkedEntity( "sentrygun" ) or !ValidEntity(LocalPlayer():GetNetworkedEntity( "sentrygun" ))) and ammo >= 130 then	
		surface.SetTexture(surface.GetTextureID("HUD/eng_build_item_bg"))
		surface.DrawTexturedRect(ScrW() *0.17, ScrH() *0.4, 300 /scale_w, 300 /scale_h )
				
		local tex=surface.GetTextureID("HUD/eng_build_sentry_blueprint")
		surface.SetTexture(tex)
		surface.DrawTexturedRect(ScrW() *0.212, ScrH() *0.46, 145 /scale_w, 145 /scale_h )
	else
		surface.SetTexture(surface.GetTextureID("HUD/eng_build_item_active"))
		surface.DrawTexturedRect(ScrW() *0.17, ScrH() *0.4, 300 /scale_w, 300 /scale_h )
		if LocalPlayer():GetNetworkedEntity( "sentrygun" ) and ValidEntity(LocalPlayer():GetNetworkedEntity( "sentrygun" )) then
			color = Color(118,107,94,255)
			draw.SimpleText("Already Built", "TF2_font1", ScrW() *0.255, ScrH() *0.51, color, 1, 1)
		else
			color = Color(187,24,3,255)
			draw.SimpleText("Not Enough", "TF2_font1", ScrW() *0.255, ScrH() *0.50, color, 1, 1)
			draw.SimpleText("Metal", "TF2_font1", ScrW() *0.255, ScrH() *0.52, color, 1, 1)
			ico_a_color = Color(187,24,3,255)
		end
	end
	draw.SimpleText("130", "TF2_font1", ScrW() *0.23, ScrH() *0.444, color, 1, 1)
			
	local color = Color(255,255,255,255)
	if (!LocalPlayer():GetNetworkedEntity( "dispenser" ) or !ValidEntity(LocalPlayer():GetNetworkedEntity( "dispenser" ))) and ammo >= 100 then
		surface.SetTexture(surface.GetTextureID("HUD/eng_build_item_bg"))
		surface.DrawTexturedRect(ScrW() *0.33, ScrH() *0.4, 300 /scale_w, 300 /scale_h )
				
		local tex=surface.GetTextureID("HUD/eng_build_dispenser_blueprint")
		surface.SetTexture(tex)
		surface.DrawTexturedRect(ScrW() *0.372, ScrH() *0.46, 145 /scale_w, 145 /scale_h )
	else
		surface.SetTexture(surface.GetTextureID("HUD/eng_build_item_active"))
		surface.DrawTexturedRect(ScrW() *0.33, ScrH() *0.4, 300 /scale_w, 300 /scale_h )
				
		if LocalPlayer():GetNetworkedEntity( "dispenser" ) and ValidEntity(LocalPlayer():GetNetworkedEntity( "dispenser" )) then
			color = Color(118,107,94,255)
			draw.SimpleText("Already Built", "TF2_font1", ScrW() *0.42, ScrH() *0.51, color, 1, 1)
		else
			color = Color(187,24,3,255)
			draw.SimpleText("Not Enough", "TF2_font1", ScrW() *0.42, ScrH() *0.5, color, 1, 1)
			draw.SimpleText("Metal", "TF2_font1", ScrW() *0.42, ScrH() *0.52, color, 1, 1)
			ico_b_color = Color(187,24,3,255)
		end
	end
	draw.SimpleText("100", "TF2_font1", ScrW() *0.39, ScrH() *0.444, color, 1, 1)
			
	local color = Color(255,255,255,255)
	if (!LocalPlayer():GetNetworkedEntity( "tp_entrance" ) or !ValidEntity(LocalPlayer():GetNetworkedEntity( "tp_entrance" ))) and ammo >= 125 then
		surface.SetTexture(surface.GetTextureID("HUD/eng_build_item_bg"))
		surface.DrawTexturedRect(ScrW() *0.49, ScrH() *0.4, 300 /scale_w, 300 /scale_h )
				
		local tex=surface.GetTextureID("HUD/eng_build_tele_entrance_blueprint")
		surface.SetTexture(tex)
		surface.DrawTexturedRect(ScrW() *0.532, ScrH() *0.46, 145 /scale_w, 145 /scale_h )
	else
		surface.SetTexture(surface.GetTextureID("HUD/eng_build_item_active"))
		surface.DrawTexturedRect(ScrW() *0.49, ScrH() *0.4, 300 /scale_w, 300 /scale_h )
			
		if LocalPlayer():GetNetworkedEntity( "tp_entrance" ) and ValidEntity(LocalPlayer():GetNetworkedEntity( "tp_entrance" )) then
			color = Color(118,107,94,255)
			draw.SimpleText("Already Built", "TF2_font1", ScrW() *0.58, ScrH() *0.51, color, 1, 1)
		else
			color = Color(187,24,3,255)
			draw.SimpleText("Not Enough", "TF2_font1", ScrW() *0.58, ScrH() *0.5, color, 1, 1)
			draw.SimpleText("Metal", "TF2_font1", ScrW() *0.58, ScrH() *0.52, color, 1, 1)
			ico_c_color = Color(187,24,3,255)
		end
	end
	draw.SimpleText("125", "TF2_font1", ScrW() *0.55, ScrH() *0.444, color, 1, 1)
			
	local color = Color(255,255,255,255)
	if (!LocalPlayer():GetNetworkedEntity( "tp_exit" ) or !ValidEntity(LocalPlayer():GetNetworkedEntity( "tp_exit" ))) and ammo >= 125 then
		surface.SetTexture(surface.GetTextureID("HUD/eng_build_item_bg"))
		surface.DrawTexturedRect(ScrW() *0.65, ScrH() *0.4, 300 /scale_w, 300 /scale_h )
				
		local tex=surface.GetTextureID("HUD/eng_build_tele_exit_blueprint")
		surface.SetTexture(tex)
		surface.DrawTexturedRect(ScrW() *0.692, ScrH() *0.46, 145 /scale_w, 145 /scale_h )
	else
		surface.SetTexture(surface.GetTextureID("HUD/eng_build_item_active"))
		surface.DrawTexturedRect(ScrW() *0.65, ScrH() *0.4, 300 /scale_w, 300 /scale_h )
	
		if LocalPlayer():GetNetworkedEntity( "tp_exit" ) and ValidEntity(LocalPlayer():GetNetworkedEntity( "tp_exit" )) then
			color = Color(118,107,94,255)
			draw.SimpleText("Already Built", "TF2_font1", ScrW() *0.74, ScrH() *0.51, color, 1, 1)
		else
			color = Color(187,24,3,255)
			draw.SimpleText("Not Enough", "TF2_font1", ScrW() *0.74, ScrH() *0.5, color, 1, 1)
			draw.SimpleText("Metal", "TF2_font1", ScrW() *0.74, ScrH() *0.52, color, 1, 1)
			ico_d_color = Color(187,24,3,255)
		end
	end
	draw.SimpleText("125", "TF2_font1", ScrW() *0.71, ScrH() *0.444, color, 1, 1)
	
	local tex=surface.GetTextureID("HUD/ico_key_blank")
	surface.SetTexture(tex)
	surface.DrawTexturedRect(ScrW() *0.244, ScrH() *0.6, 45 /scale_w, 45 /scale_h )
	surface.DrawTexturedRect(ScrW() *0.404, ScrH() *0.6, 45 /scale_w, 45 /scale_h )
	surface.DrawTexturedRect(ScrW() *0.564, ScrH() *0.6, 45 /scale_w, 45 /scale_h )
	surface.DrawTexturedRect(ScrW() *0.724, ScrH() *0.6, 45 /scale_w, 45 /scale_h )
			
	local tex=surface.GetTextureID("HUD/ico_metal")
	surface.SetTexture(tex)
	surface.SetDrawColor(ico_a_color)
	surface.DrawTexturedRect(ScrW() *0.196, ScrH() *0.43, 30 /scale_w, 30 /scale_h )
	surface.SetDrawColor(ico_b_color)
	surface.DrawTexturedRect(ScrW() *0.356, ScrH() *0.43, 30 /scale_w, 30 /scale_h )
	surface.SetDrawColor(ico_c_color)
	surface.DrawTexturedRect(ScrW() *0.516, ScrH() *0.43, 30 /scale_w, 30 /scale_h )
	surface.SetDrawColor(ico_d_color)
	surface.DrawTexturedRect(ScrW() *0.676, ScrH() *0.43, 30 /scale_w, 30 /scale_h )
			
	draw.SimpleText("Sentry Gun", "TF2_font_build_dpa2", ScrW() *0.232, ScrH() *0.408, Color(236,227,203,255), 1, 1)
	draw.SimpleText("Dispenser", "TF2_font_build_dpa2", ScrW() *0.386, ScrH() *0.408, Color(236,227,203,255), 1, 1)
	draw.SimpleText("Entrance", "TF2_font_build_dpa2", ScrW() *0.54, ScrH() *0.408, Color(236,227,203,255), 1, 1)
	draw.SimpleText("Exit", "TF2_font_build_dpa2", ScrW() *0.686, ScrH() *0.408, Color(236,227,203,255), 1, 1)
			
	draw.SimpleText("1", "TF2_font_build_dpa2", ScrW() *0.258, ScrH() *0.615, Color(236,227,203,255), 1, 1)
	draw.SimpleText("2", "TF2_font_build_dpa2", ScrW() *0.418, ScrH() *0.615, Color(236,227,203,255), 1, 1)
	draw.SimpleText("3", "TF2_font_build_dpa2", ScrW() *0.578, ScrH() *0.615, Color(236,227,203,255), 1, 1)
	draw.SimpleText("4", "TF2_font_build_dpa2", ScrW() *0.737, ScrH() *0.615, Color(255,255,255,255), 1, 1)
end

function SWEP:Think()
	if input.IsKeyDown( 2 ) or input.IsKeyDown( 3 ) or input.IsKeyDown( 4 ) or input.IsKeyDown( 5 ) then
		local key
		if input.IsKeyDown( 2 ) then
			key = "1"
		elseif input.IsKeyDown( 3 ) then
			key = "2"
		elseif input.IsKeyDown( 4 ) then
			key = "3"
		else
			key = "4"
		end
		if key then RunConsoleCommand("build",key) end
	end
end
