Advertisement
Guest User

Untitled

a guest
Aug 20th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.28 KB | None | 0 0
  1. MODULE.Name = "HUD"
  2. MODULE.Author = "Q2F2 & Ghosty"
  3. MODULE.Realm = 2
  4.  
  5. local tag = "BaseWars.HUD"
  6.  
  7. function MODULE:__INIT()
  8.  
  9. surface.CreateFont(tag, {
  10. font = "Roboto",
  11. size = 16,
  12. weight = 800,
  13. })
  14.  
  15. surface.CreateFont(tag .. ".Large", {
  16. font = "Roboto",
  17. size = 20,
  18. weight = 1200,
  19. })
  20.  
  21. surface.CreateFont(tag .. ".Time", {
  22. font = "Roboto",
  23. size = 28,
  24. weight = 800,
  25. })
  26. surface.CreateFont("ScoreboardHeader", {
  27. font = "Roboto",
  28. size = 28,
  29. weight = 800,
  30. })
  31.  
  32. end
  33.  
  34. local clamp = math.Clamp
  35. local floor = math.floor
  36. local round = math.Round
  37.  
  38. local function Calc(real, max, min, w)
  39.  
  40. real = clamp(real,min or 0,max)
  41. real = real / max
  42.  
  43. if w then
  44.  
  45. local calw = w * real
  46.  
  47. return calw, w - calw
  48.  
  49. else
  50.  
  51. return real
  52.  
  53. end
  54.  
  55. end
  56.  
  57. local oldhW = 0
  58. local oldHP = 0
  59.  
  60. local oldaW = 0
  61. local oldAM = 0
  62.  
  63. local shade = Color(0, 0, 0, 140)
  64. local trans = Color(255, 255, 255, 150)
  65. local textc = Color(100, 150, 200, 255)
  66. local hpbck = Color(255, 0 , 0 , 100)
  67. local pwbck = Color(0 , 0 , 255, 100)
  68. local red = Color(255, 0 , 0 , 245)
  69.  
  70. function MODULE:DrawStructureInfo(ent)
  71.  
  72. local Pos = ent:GetPos()
  73. Pos.z = Pos.z + 14
  74.  
  75. Pos = Pos:ToScreen()
  76.  
  77. local name = (ent.PrintName or (ent.GetName and ent:GetName()) or (ent.Nick and ent:Nick()) or ent:GetClass()):Trim()
  78. local W = BaseWars.Config.HUD.EntW
  79. local H = BaseWars.Config.HUD.EntH
  80.  
  81. local oldx, oldy = Pos.x, Pos.y
  82. local curx, cury = Pos.x, Pos.y
  83. local w, h
  84. local Font = BaseWars.Config.HUD.EntFont
  85. local Font2 = BaseWars.Config.HUD.EntFont2
  86. local Padding = 5
  87. local EndPad = -Padding * 2
  88.  
  89. curx = curx - W / 2
  90. cury = cury - H / 2
  91.  
  92. surface.SetDrawColor(shade)
  93. surface.DrawRect(curx, cury, W, H)
  94.  
  95. surface.SetFont(Font)
  96. w, h = surface.GetTextSize(name)
  97.  
  98. draw.DrawText(name, Font, oldx - w / 2, cury, shade)
  99. draw.DrawText(name, Font, oldx - w / 2, cury, textc)
  100.  
  101. if ent:Health() > 0 then
  102.  
  103. cury = cury + H + 1
  104.  
  105. surface.SetDrawColor(shade)
  106. surface.DrawRect(curx, cury, W, H)
  107.  
  108. local MaxHealth = ent:GetMaxHealth() or 100
  109. local HealthStr = ent:Health() .. "/" .. MaxHealth .. " HP"
  110.  
  111. local HPLen = W * (ent:Health() / MaxHealth)
  112.  
  113. draw.RoundedBox(0, curx + Padding, cury + Padding, HPLen + EndPad, H + EndPad, hpbck)
  114.  
  115. surface.SetFont(Font2)
  116. w, h = surface.GetTextSize(HealthStr)
  117.  
  118. draw.DrawText(HealthStr, Font2, oldx - w / 2, cury + Padding, shade)
  119. draw.DrawText(HealthStr, Font2, oldx - w / 2, cury + Padding, color_white)
  120.  
  121. end
  122.  
  123. if ent.GetPower then
  124.  
  125. cury = cury + H + 1
  126.  
  127. surface.SetDrawColor(shade)
  128. surface.DrawRect(curx, cury, W, H)
  129.  
  130. local MaxPower = ent:GetMaxPower() or 100
  131. local PowerStr = (ent:GetPower() > 0 and ent:GetPower() .. "/" .. MaxPower .. " PW") or BaseWars.LANG.PowerFailure
  132.  
  133. local PWLen = W * (ent:GetPower() / MaxPower)
  134.  
  135. draw.RoundedBox(0, curx + Padding, cury + Padding, PWLen + EndPad, H + EndPad, pwbck)
  136.  
  137. surface.SetFont(Font2)
  138. w, h = surface.GetTextSize(PowerStr)
  139.  
  140. draw.DrawText(PowerStr, Font2, oldx - w / 2, cury + Padding, shade)
  141. draw.DrawText(PowerStr, Font2, oldx - w / 2, cury + Padding, color_white)
  142.  
  143. end
  144.  
  145. if ent:BadlyDamaged() then
  146.  
  147. cury = cury + H + 1
  148.  
  149. surface.SetDrawColor(shade)
  150. surface.DrawRect(curx, cury, W, H)
  151.  
  152. local Str = BaseWars.LANG.HealthFailure
  153.  
  154. surface.SetFont(Font2)
  155. w, h = surface.GetTextSize(Str)
  156.  
  157. draw.DrawText(Str, Font2, oldx - w / 2, cury + Padding - 1, shade)
  158. draw.DrawText(Str, Font2, oldx - w / 2, cury + Padding - 1, color_white)
  159.  
  160. end
  161.  
  162. end
  163.  
  164. function MODULE:DrawDisplay()
  165.  
  166. local me = LocalPlayer()
  167. local Ent = me:GetEyeTrace().Entity
  168.  
  169. if BaseWars.Ents:ValidClose(Ent, me, 200) and (Ent.IsElectronic or Ent.IsGenerator or Ent.DrawStructureDisplay) then
  170.  
  171. self:DrawStructureInfo(Ent)
  172.  
  173. end
  174.  
  175. end
  176.  
  177. local StuckTime
  178. local me = LocalPlayer and LocalPlayer()
  179. local stuckstr = CLIENT and string.format(BaseWars.LANG.StuckText, (input.LookupBinding("+duck") or "NONE"):upper(), (input.LookupBinding("+jump") or "NONE"):upper())
  180. local Key = CLIENT and (input.LookupBinding("+menu") or "NONE"):upper() .. BaseWars.LANG.SpawnMenuControl
  181. local col2 = Color(159,1,1,150)
  182. local col1 = Color(1,159,1,150)
  183.  
  184. local enable_keyinfo = CLIENT and CreateClientConVar("bw_enable_keyinfo", "1", true, false)
  185.  
  186. function MODULE:Paint()
  187.  
  188. if not IsValid(me) then me = LocalPlayer() return end
  189.  
  190. self:DrawDisplay()
  191. self:Ammo()
  192. local hp, su = me:Health(), me:Armor()
  193.  
  194. if not me:Alive() then hp = 0 su = 0 end
  195.  
  196. local hpF = Lerp(0.15, oldHP, hp)
  197. oldHP = hpF
  198.  
  199. local suF = Lerp(0.15, oldAM, su)
  200. oldAM = suF
  201.  
  202. local pbarW, pbarH = 256, 6
  203. local sW, sH = ScrW(), ScrH()
  204.  
  205. local Karma = me:GetKarma()
  206. local KarmaText = string.format(BaseWars.LANG.KarmaText, Karma)
  207.  
  208. local Level = me:GetLevel()
  209. local XP = me:GetXP()
  210. local NextLevelXP = me:GetXPNextLevel()
  211. local LevelText = string.format(BaseWars.LANG.LevelText, Level)
  212. local XPText = string.format(BaseWars.LANG.XPText, XP, NextLevelXP)
  213. local LvlText = LevelText .. ", " .. XPText
  214.  
  215. local PrestigeXP = PrestigeSystem:GetXP()
  216. local PrestigeNextLevelXP = PrestigeSystem:GetNextLevelXP()
  217. local PrestigeLevel = PrestigeSystem:GetLevel()
  218. local PrestigeCount = PrestigeSystem:GetCount()
  219. local PrestigePoints = PrestigeSystem:GetPoints()
  220.  
  221. local PrestigeText = "Prestige " .. PrestigeCount .. " Level " .. PrestigeLevel .. " Points " .. PrestigePoints
  222. local PrestigeXP = "Prestige XP, " .. string.format(BaseWars.LANG.XPText, PrestigeXP, PrestigeNextLevelXP)
  223.  
  224. local hW = Calc(hp, 100, 0, pbarW)
  225. local aW = Calc(su, 100, 0, pbarW)
  226.  
  227. local nhW,naW = 0,0
  228.  
  229. hW = Lerp(0.15,oldhW,hW)
  230. oldhW = hW
  231. nhW = pbarW - hW
  232.  
  233. aW = Lerp(0.15,oldaW,aW)
  234. oldaW = aW
  235. naW = pbarW - aW
  236.  
  237. if BaseWars.PSAText then
  238.  
  239. surface.SetFont("BudgetLabel")
  240. local w, h = surface.GetTextSize(BaseWars.PSAText)
  241.  
  242. local fw = sW + w * 2
  243. local x, y = ((SysTime() * 50) % fw) - w, ScrH()/1080 * 40
  244.  
  245. local Col = HSVToColor(CurTime() % 6 * 60, 1, 1)
  246.  
  247. draw.DrawText(BaseWars.PSAText, tag .. ".Large", x, y-20, Col, TEXT_ALIGN_LEFT)
  248.  
  249. end
  250.  
  251. -- Karma, XP + Controls
  252. if enable_keyinfo:GetBool() then
  253. draw.DrawText(BaseWars.LANG.MainMenuControl, tag, sW - 5, sH-47, red, TEXT_ALIGN_RIGHT)
  254. draw.DrawText(Key, tag, sW - 5, sH-57, red, TEXT_ALIGN_RIGHT)
  255. draw.DrawText("F4 - Prestige Menu (Perks)", tag, sW - 5, sH-37, red, TEXT_ALIGN_RIGHT )
  256. draw.DrawText("F10 - Suggestions Menu (Server Suggestions)", tag, sW - 5, sH-27, red, TEXT_ALIGN_RIGHT )
  257. end
  258.  
  259. draw.DrawText(KarmaText, tag, 64 + 26 + pbarW / 2, sH - 128 - 48 - 8-20, shade, TEXT_ALIGN_CENTER)
  260. draw.DrawText(KarmaText, tag, 64 + 24 + pbarW / 2, sH - 128 - 48 - 10-20, trans, TEXT_ALIGN_CENTER)
  261.  
  262. draw.DrawText(LvlText, tag, 64 + 26 + pbarW / 2, sH - 128 - 8-20, shade, TEXT_ALIGN_CENTER)
  263. draw.DrawText(LvlText, tag, 64 + 24 + pbarW / 2, sH - 128 - 10-20, trans, TEXT_ALIGN_CENTER)
  264.  
  265. draw.DrawText(PrestigeText, tag, 64 + 26 + pbarW / 2, sH - 124-20, shade, TEXT_ALIGN_CENTER)
  266. draw.DrawText(PrestigeText, tag, 64 + 24 + pbarW / 2, sH - 126-20, trans, TEXT_ALIGN_CENTER)
  267. -- PrestigeXP
  268. draw.DrawText(PrestigeXP, tag, 64 + 26 + pbarW / 2, sH - 116-20, shade, TEXT_ALIGN_CENTER)
  269. draw.DrawText(PrestigeXP, tag, 64 + 24 + pbarW / 2, sH - 114-20, trans, TEXT_ALIGN_CENTER)
  270.  
  271. -- Health
  272.  
  273. draw.DrawText("HP", tag, 64 + 18, sH - 128 - 32 - 8 -20, shade, TEXT_ALIGN_RIGHT)
  274. draw.DrawText("HP", tag, 64 + 16, sH - 128 - 32 - 10 -20, trans, TEXT_ALIGN_RIGHT)
  275.  
  276. if hW > 0.01 then
  277.  
  278. draw.RoundedBox(0, 64 + 24, sH - 128 - 32 - 4 -20, hW, pbarH, col1)
  279. draw.RoundedBox(0, 64 + 24 - nhW + pbarW, sH - 128 - 32 - 4-20, nhW, pbarH, col2)
  280.  
  281. else
  282.  
  283. draw.RoundedBox(0, 64 + 24, sH - 128 - 32 - 4-20, pbarW, pbarH, col2)
  284.  
  285. end
  286.  
  287. draw.DrawText(round(hpF), tag, pbarW + 98, sH - 128 - 32 - 8-20, shade, TEXT_ALIGN_LEFT)
  288. draw.DrawText(round(hpF), tag, pbarW + 96, sH - 128 - 32 - 10-20, trans, TEXT_ALIGN_LEFT)
  289.  
  290. -- Armor
  291. draw.DrawText("SUIT", tag, 64 + 18, sH - 128 - 16 - 8 -20, shade, TEXT_ALIGN_RIGHT)
  292. draw.DrawText("SUIT", tag, 64 + 16, sH - 128 - 16 - 10 -20, trans, TEXT_ALIGN_RIGHT)
  293.  
  294. if aW > 0.01 then
  295.  
  296. draw.RoundedBox(0, 64 + 24, sH - 128 - 16 - 4-20, aW, pbarH, Color(90,120,200,150))
  297. draw.RoundedBox(0, 64 + 24 - naW + pbarW, sH - 128 - 16 - 4-20, naW, pbarH, Color(10,40,150,150))
  298.  
  299. else
  300.  
  301. draw.RoundedBox(0, 64 + 24, sH - 128 - 16 - 4-20, pbarW, pbarH, Color(10,40,150,150))
  302.  
  303. end
  304.  
  305. draw.DrawText(round(suF), tag, pbarW + 98, sH - 128 - 16 - 8-20, shade, TEXT_ALIGN_LEFT)
  306. draw.DrawText(round(suF), tag, pbarW + 96, sH - 128 - 16 - 10-20, trans, TEXT_ALIGN_LEFT)
  307.  
  308. if me.Stuck and me:Stuck() and me:GetMoveType() == MOVETYPE_WALK then
  309.  
  310. if not StuckTime then StuckTime = CurTime() end
  311.  
  312. if CurTime() > StuckTime + 1 then
  313.  
  314. draw.DrawText(stuckstr, tag .. ".Large", sW / 2 + 2, sH / 2 + 2-20, shade, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
  315. draw.DrawText(stuckstr, tag .. ".Large", sW / 2, sH / 2-20, trans, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
  316.  
  317. end
  318.  
  319. else
  320.  
  321. StuckTime = nil
  322.  
  323. end
  324.  
  325. end
  326. hook.Add("HUDPaint", tag .. ".Paint", Curry(MODULE.Paint))
  327.  
  328. function MODULE:Ammo()
  329. local ply = LocalPlayer()
  330.  
  331. if not ply:Alive() then return end
  332.  
  333. local awpn = ply:GetActiveWeapon()
  334. local clip, extra = 0, 0;
  335.  
  336. if( IsValid( awpn ) )then
  337. local scrw, scrh = ScrW(), ScrH()
  338. clip = awpn:Clip1()
  339. extra = ply:GetAmmoCount(awpn:GetPrimaryAmmoType())
  340.  
  341. if awpn:Clip1() == -1 then clip = "∞" extra = "∞" end
  342. if clip == nil then clip = 1 end
  343.  
  344.  
  345. draw.DrawText( clip .." / "..extra, "ScoreboardHeader", scrw - (scrw/5) + (scrw/12), scrh - (scrh/5) + 50, Color(255,255,255,255), TEXT_ALIGN_CENTER)
  346. draw.RoundedBox(4, scrw - (scrw/5) + scrw/26, scrh - (scrh/5), 200, 100, Color(51, 58, 51,100))
  347. draw.RoundedBox(4, scrw - (scrw/5) + scrw/26, scrh - (scrh/5), 200, 25, Color(255,255,0,200))
  348. draw.DrawText( "Ammo", "Trebuchet24", scrw - (scrw/5) + (scrw/12), scrh - (scrh/5), Color(255,255,255,255), TEXT_ALIGN_CENTER)
  349.  
  350. end
  351. end
  352.  
  353. function HideHUD(name)
  354.  
  355. for k, v in next, {"CHudHealth", "CHudBattery", "CHudAmmo", "CHudSecondaryAmmo"} do
  356.  
  357. if name == v then
  358.  
  359. return false
  360.  
  361. end
  362.  
  363. end
  364.  
  365. end
  366. hook.Add("HUDShouldDraw", tag .. ".HideOldHUD", HideHUD)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement