if ( SERVER ) then
	AddCSLuaFile()
else

	local function SleekWeaponSwitch()
		if ( GAMEMODE.Name ~= "Trouble in Terrorist Town" ) then
			hook.Remove( "Initialize", "SleekTTTWeaponSwitch" )
			return
		end

		local margin = 10
		local width = 300
		local height = 30

		local barcorner = surface.GetTextureID( "gui/corner8" )

		surface.CreateFont("WepFont", {font = "Bebas Neue",
											size = 22,
											weight = 0})

		local col_active = {
		   tip = {
			  [ROLE_INNOCENT]  = Color(55, 170, 50, 255),
			  [ROLE_TRAITOR]   = Color(180, 50, 40, 255),
			  [ROLE_DETECTIVE] = Color(50, 60, 180, 255)
		   },

		   bg = Color(20, 20, 20, 250),

		   text_empty = Color(200, 20, 20, 255),
		   text = Color(255, 255, 255, 255),

		   shadow = 255
		};

		local col_dark = {
		   tip = {
			  [ROLE_INNOCENT]  = Color(60, 160, 50, 155),
			  [ROLE_TRAITOR]   = Color(160, 50, 60, 155),
			  [ROLE_DETECTIVE] = Color(50, 60, 160, 155),
		   },

		   bg = Color(20, 20, 20, 200),

		   text_empty = Color(200, 20, 20, 100),
		   text = Color(255, 255, 255, 100),

		   shadow = 100
		};

		-- Draw a bar in the style of the the weapon pickup ones
		local round = math.Round
		function WSWITCH:DrawBarBg(x, y, w, h, col)
		   local rx = round(x - 4)
		   local ry = round(y - (h / 2)-4)
		   local rw = round(w + 9)
		   local rh = round(h + 8)

		   local b = 8 --bordersize
		   local bh = b / 2

		   local role = LocalPlayer():GetRole() or ROLE_INNOCENT

		   local c = col.tip[role]

		   -- Draw the colour tip
		   surface.SetTexture(barcorner)

		   surface.SetDrawColor(c.r, c.g, c.b, c.a)
		   --surface.DrawTexturedRectRotated( rx + bh , ry + bh, b, b, 0 ) 
		  -- surface.DrawTexturedRectRotated( rx + bh , ry + rh -bh, b, b, 90 ) 
		   --surface.DrawRect( rx, ry+b, b, rh-b*2 )
		   --surface.DrawRect( rx+b, ry, h - 4, rh )
		   
		   -- Draw the remainder
		   -- Could just draw a full roundedrect bg and overdraw it with the tip, but
		   -- I don't have to do the hard work here anymore anyway
		   c = col.bg
		   surface.SetDrawColor(c.r, c.g, c.b, c.a)
		   
		   local bgCol = {}
		   
			bgCol["traitor"] = { fCol = Color( 192, 57, 43 ), sCol = Color( 231, 76, 60 ) }
			bgCol["detective"] = { fCol = Color( 41, 128, 185 ), sCol = Color( 52, 152, 219 ) }
			bgCol["innocent"] = { fCol = Color( 39, 174, 96 ), sCol = Color( 46, 204, 113 ) }
			
				if LocalPlayer():GetRole() == ROLE_TRAITOR then
					hCol = bgCol["traitor"]
				elseif LocalPlayer():GetRole() == ROLE_DETECTIVE then
					hCol = bgCol["detective"]
				else
					hCol = bgCol["innocent"]
				end

		   --surface.DrawRect( rx+b+h-4, ry,  rw - (h - 4) - b*2,  rh )
		   
			draw.RoundedBox( 8, rx+b+h-4 - 24, ry, rw - (h - 4) - b*2 + 20, rh, Color( 44, 59, 75 ) )
			draw.RoundedBox( 8, rx+b+h-4 - 24 + 1, ry + 1, rw - (h - 4) - b*2 - 2 + 20, rh - 10, Color( 134, 143, 152 ) )
			draw.RoundedBox( 8, rx+b+h-4 - 24 + 1, ry + 2, rw - (h - 4) - b*2 - 2 + 20, rh - 4, Color( 44, 62, 80 ) )
			draw.RoundedBoxEx( 8, rx+b+h-4 - 24 + 1, ry + 2, rw - (h - 4) - b*2 - 2 + 20, rh - 20, Color( 52, 73, 94 ), true, true, false, false )
			
			draw.RoundedBoxEx( 8, rx+b+h-4 - 24 + 1, ry + 1, 24, 30, Color( 254, 243, 223 ), true, false, true, false )
			draw.RoundedBoxEx( 8, rx+b+h-4 - 24 + 1, ry + 2, 24, 36, hCol.fCol, true, false, true, false )
			draw.RoundedBoxEx( 8, rx+b+h-4 - 24 + 1, ry + 2, 24, 18, hCol.sCol, true, false, false, false )
		   
		   --surface.DrawTexturedRectRotated( rx + rw - bh , ry + rh - bh, b, b, 180 ) 
		   --surface.DrawTexturedRectRotated( rx + rw - bh , ry + bh, b, b, 270 ) 
		   --surface.DrawRect( rx+rw-b,  ry+b,  b,  rh-b*2 )

		end

		local TryTranslation = LANG.TryTranslation
		function WSWITCH:DrawWeapon(x, y, c, wep)
		   if not IsValid(wep) then return false end

		   local name = TryTranslation(wep:GetPrintName() or wep.PrintName or "...")
		   local cl1, am1 = wep:Clip1(), wep:Ammo1()
		   local ammo = false

		   -- Clip1 will be -1 if a melee weapon
		   -- Ammo1 will be false if weapon has no owner (was just dropped)
		   if cl1 != -1 and am1 != false then
			  ammo = Format("%i + %02i", cl1, am1)
		   end

		   -- Slot
		   local spec = {text=wep.Slot+1, font="WepFont", pos={x+25, y + 13}, yalign=TEXT_ALIGN_CENTER, color=c.text}
		   draw.TextShadow(spec, 1, c.shadow)

		   -- Name
		   spec.text  = name
		   spec.font  = "WepFont"
		   spec.pos[1] = x + 20 + height
		   draw.Text(spec)

		   if ammo then
			  local col = c.text

			  if wep:Clip1() == 0 and wep:Ammo1() == 0 then
				 col = c.text_empty
			  end

			  -- Ammo
			  spec.text   = ammo
			  spec.pos[1] = ScrW() - margin*3 - 20
			  spec.xalign = TEXT_ALIGN_RIGHT
			  spec.color  = col
			  draw.Text(spec)
		   end

		   return true
		end

		local function getAmmo( player )
			local weapon = player:GetActiveWeapon()
			if ( not player:Alive() or not IsValid( weapon ) ) then
				return -1
			end

			local clipAmmo		= weapon:Clip1() or 0
			local maxAmmo		= weapon.Primary.ClipSize or 0
			local remainingAmmo = weapon:Ammo1() or 0

			return clipAmmo, maxAmmo, remainingAmmo
		end

		function WSWITCH:Draw(client)
		   if not self.Show then return end

		   local weps = self.WeaponCache

		   local x = ScrW() - width - margin*2
		   local y = ScrH() - (#weps * (height + margin))

		   local col = col_dark
		   for k, wep in pairs(weps) do
			  if self.Selected == k then
				 col = col_active
			  else
				 col = col_dark
			  end

			  self:DrawBarBg(x + 10, y + 10, width, height, col)
			  if not self:DrawWeapon(x, y, col, wep) then
				 
				 self:UpdateWeaponCache()
				 return
			  end

			  y = y + height + margin
		   end
		end
	end
	hook.Add( "Initialize", "SleekTTTWeaponSwitch", SleekWeaponSwitch )

	if GAMEMODE then
		SleekWeaponSwitch()
	end
end