include('shared.lua')

SWEP.PrintName = "Destroy 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_destroy") 

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 )	
	
	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_demolish")
	surface.SetTexture(tex)
	surface.SetDrawColor(255,255,255,255)
	surface.DrawTexturedRect(ScrW() *0.15, ScrH() *0.283, 160 /scale_w, 160 /scale_h )
	
	draw.SimpleText("DEMOLISH", "TF2_font_build_dpa1", ScrW() *0.358, ScrH() *0.334, Color(236,227,203,255), 1, 1)
			
	surface.SetTexture(surface.GetTextureID("HUD/eng_build_item_active"))
	surface.DrawTexturedRect(ScrW() *0.17, ScrH() *0.4, 300 /scale_w, 300 /scale_h )
	surface.DrawTexturedRect(ScrW() *0.33, ScrH() *0.4, 300 /scale_w, 300 /scale_h )
	surface.DrawTexturedRect(ScrW() *0.49, ScrH() *0.4, 300 /scale_w, 300 /scale_h )
	surface.DrawTexturedRect(ScrW() *0.65, ScrH() *0.4, 300 /scale_w, 300 /scale_h )
			
	if LocalPlayer():GetNetworkedEntity( "sentrygun" ) and ValidEntity(LocalPlayer():GetNetworkedEntity( "sentrygun" )) then
		surface.SetTexture(surface.GetTextureID("HUD/ico_demolish"))
		surface.DrawTexturedRect(ScrW() *0.21, ScrH() *0.44, 160 /scale_w, 160 /scale_h )
				
		local sentry = LocalPlayer():GetNetworkedEntity( "sentrygun" )
		local sentry_level = sentry:GetNetworkedInt( "sentrygun_level" )
				
		surface.SetTexture(surface.GetTextureID("HUD/hud_obj_status_sentry_" .. sentry_level))
		surface.DrawTexturedRect(ScrW() *0.2, ScrH() *0.42, 180 /scale_w, 180 /scale_h )
	else
		draw.SimpleText("Not Built", "TF2_font1", ScrW() *0.26, ScrH() *0.51, color, 1, 1)
	end
			
	if LocalPlayer():GetNetworkedEntity( "dispenser" ) and ValidEntity(LocalPlayer():GetNetworkedEntity( "dispenser" )) then
		surface.SetTexture(surface.GetTextureID("HUD/ico_demolish"))
		surface.DrawTexturedRect(ScrW() *0.37, ScrH() *0.44, 160 /scale_w, 160 /scale_h )
			
		surface.SetTexture(surface.GetTextureID("HUD/hud_obj_status_dispenser"))
		surface.DrawTexturedRect(ScrW() *0.36, ScrH() *0.42, 180 /scale_w, 180 /scale_h )
	else
		draw.SimpleText("Not Built", "TF2_font1", ScrW() *0.42, ScrH() *0.51, color, 1, 1)
	end
			
	if LocalPlayer():GetNetworkedEntity( "tp_entrance" ) and ValidEntity(LocalPlayer():GetNetworkedEntity( "tp_entrance" )) then
		surface.SetTexture(surface.GetTextureID("HUD/ico_demolish"))
		surface.DrawTexturedRect(ScrW() *0.53, ScrH() *0.44, 160 /scale_w, 160 /scale_h )
		
		surface.SetTexture(surface.GetTextureID("HUD/hud_obj_status_tele_entrance"))
		surface.DrawTexturedRect(ScrW() *0.52, ScrH() *0.42, 180 /scale_w, 180 /scale_h )
	else
		draw.SimpleText("Not Built", "TF2_font1", ScrW() *0.58, ScrH() *0.51, color, 1, 1)
	end
			
	if LocalPlayer():GetNetworkedEntity( "tp_exit" ) and ValidEntity(LocalPlayer():GetNetworkedEntity( "tp_exit" )) then
		surface.SetTexture(surface.GetTextureID("HUD/ico_demolish"))
		surface.DrawTexturedRect(ScrW() *0.68, ScrH() *0.44, 160 /scale_w, 160 /scale_h )
			
		surface.SetTexture(surface.GetTextureID("HUD/hud_obj_status_tele_exit"))
		surface.DrawTexturedRect(ScrW() *0.68, ScrH() *0.42, 180 /scale_w, 180 /scale_h )
	else
		draw.SimpleText("Not Built", "TF2_font1", ScrW() *0.74, ScrH() *0.51, color, 1, 1)
	end
			
			
	surface.SetDrawColor(255,255,255,255)
	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 )
			
	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

/*---------------------------------------------------------
   Name: CustomAmmoDisplay
   Desc: Return a table
---------------------------------------------------------*/
function SWEP:CustomAmmoDisplay()
	return self.AmmoDisplay
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 = "2"
		elseif input.IsKeyDown( 3 ) then
			key = "3"
		elseif input.IsKeyDown( 4 ) then
			key = "4"
		else
			key = "5"
		end
		RunConsoleCommand("tf_eng_weapon_pda_plypressedkey",self:EntIndex() .. " " .. key)
	end
end
