Advertisement
Bjarke

b_AmmoCount

Aug 30th, 2015
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.47 KB | None | 0 0
  1. --------------------------------------------------------------------------------
  2. --------------------------------------------------------------------------------
  3.  
  4. require "base/internal/ui/reflexcore"
  5.  
  6. b_AmmoCount =
  7. {
  8. };
  9. registerWidget("b_AmmoCount");
  10.  
  11. --------------------------------------------------------------------------------
  12. --------------------------------------------------------------------------------
  13. function b_AmmoCount:draw()
  14.  
  15. -- Early out if HUD shouldn't be shown.
  16. if not shouldShowHUD() then return end;
  17.  
  18. local player = getPlayer();
  19.  
  20. -- Options
  21. local showFrame = true;
  22. local colorNumber = false;
  23.  
  24. -- Size and spacing
  25. local frameWidth = 460;
  26. local frameHeight = 55;
  27. local framePadding = 5;
  28. local numberSpacing = 100;
  29. local iconSpacing = 0;
  30.  
  31.  
  32.  
  33. -- Colors
  34. local frameColor = Color(0,0,0,128);
  35.  
  36. local weaponIndexSelected = player.weaponIndexSelected;
  37. local weapon = player.weapons[weaponIndexSelected];
  38. local ammo = weapon.ammo;
  39.  
  40. local barColor;
  41. if ammo < weapon.lowAmmoWarning then barColor = Color(245,215,50, 160) end
  42. if ammo > weapon.lowAmmoWarning then barColor = Color(245,215,50, 160);
  43. else barColor = Color(245,215,50, 160); end
  44.  
  45. local barBackgroundColor;
  46. if ammo < weapon.lowAmmoWarning then barBackgroundColor = Color(122,111,50, 160) end
  47. if ammo > weapon.lowAmmoWarning then barBackgroundColor = Color(122,111,50, 160);
  48. else barBackgroundColor = Color(122,111,50, 160); end
  49.  
  50. -- Helpers
  51. local frameLeft = 0;
  52. local frameTop = -frameHeight;
  53. local frameRight = frameWidth;
  54. local frameBottom = 0;
  55.  
  56. local barLeft = frameLeft + iconSpacing + numberSpacing
  57. local barTop = frameTop + framePadding;
  58. local barRight = frameRight - framePadding;
  59. local barBottom = frameBottom - framePadding;
  60.  
  61. local barWidth = 200 + numberSpacing + 15 + iconSpacing;
  62. local barHeight = frameHeight - (framePadding * 2);
  63.  
  64. local fontX = barLeft - (numberSpacing / 2);
  65. local fontY = -(frameHeight / 2);
  66. local fontSize = frameHeight * 1.15;
  67.  
  68. if ammo > 100 then fillWidth = (barWidth / 100) * (ammo - 100);
  69. else fillWidth = (barWidth / 100) * ammo; end
  70.  
  71. -- Frame
  72. if showFrame then
  73. nvgBeginPath();
  74. nvgRoundedRect(frameRight + 95, frameBottom - 60, -frameWidth, -frameHeight, 5);
  75. nvgFillColor(frameColor);
  76. nvgFill();
  77. if ammo > 100 then
  78. nvgBeginPath();
  79. nvgRoundedRect(frameRight - 40, frameBottom, -frameWidth + 135, -frameHeight, 5);
  80. nvgFillColor(frameColor);
  81. nvgFill();
  82. end
  83. end
  84.  
  85. -- Background
  86.  
  87. nvgBeginPath();
  88. nvgRect(barRight - 40, barBottom - 60, -barWidth, -barHeight);
  89. nvgFillColor(barBackgroundColor);
  90. nvgFill();
  91. if ammo > 100 then
  92. nvgBeginPath();
  93. nvgRect(barRight - 40, barBottom, -barWidth, -barHeight);
  94. nvgFillColor(barBackgroundColor);
  95. nvgFill();
  96. end
  97.  
  98. -- Bar
  99. if ammo <= 100 then
  100. nvgBeginPath();
  101. nvgRect(barLeft + 315, barBottom - 60, -fillWidth, -barHeight);
  102. nvgFillColor(barColor);
  103. nvgFill();
  104. end
  105. if ammo > 100 then
  106. nvgBeginPath();
  107. nvgRect(barLeft + 315, barBottom, -fillWidth, -barHeight);
  108. nvgFillColor(barColor);
  109. nvgFill();
  110. nvgBeginPath();
  111. nvgRect(barLeft + 315, barBottom - 60, -barWidth, -barHeight);
  112. nvgFillColor(barColor);
  113. nvgFill();
  114. end
  115.  
  116. -- colour changes when low on ammo
  117. local fontColor = Color(230,230,230);
  118. local glow = false;
  119. if ammo == 0 then
  120. fontColor = Color(230, 0, 0);
  121. glow = true;
  122. elseif ammo < weapon.lowAmmoWarning then
  123. fontColor = Color(230, 230, 0);
  124. glow = true;
  125. end
  126.  
  127. nvgFontSize(fontSize);
  128. nvgFontFace(FONT_HUD);
  129. nvgTextAlign(NVG_ALIGN_RIGHT, NVG_ALIGN_MIDDLE);
  130.  
  131. -- unlimited ammo if melee, in race mode, or in warmup mode
  132. if weaponIndexSelected == 1 then ammo = "-" end
  133. if isRaceMode() then ammo = "-" end
  134.  
  135. if glow then
  136. nvgFontBlur(5);
  137. nvgFillColor(Color(64, 64, 200));
  138. nvgText(fontX + 447, fontY - 60, ammo);
  139. end
  140.  
  141. nvgFontBlur(0);
  142. nvgFillColor(fontColor);
  143. nvgText(fontX + 447, fontY - 60, ammo);
  144.  
  145. -- Draw icon
  146. local iconX = frameLeft + (iconSpacing / 2) + framePadding;
  147. local iconY = -(frameHeight / 2);
  148. local iconSize = (frameHeight / 2) * 0.75;
  149. local svgName = "internal/ui/icons/weapon" .. weaponIndexSelected;
  150. iconColor = player.weapons[weaponIndexSelected].color;
  151. nvgFillColor(iconColor);
  152. nvgSvg(svgName, iconX + 525, iconY - 60, iconSize);
  153. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement