Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --------------------------------------------------------------------------------
- --------------------------------------------------------------------------------
- require "base/internal/ui/reflexcore"
- b_AmmoCount =
- {
- };
- registerWidget("b_AmmoCount");
- --------------------------------------------------------------------------------
- --------------------------------------------------------------------------------
- function b_AmmoCount:draw()
- -- Early out if HUD shouldn't be shown.
- if not shouldShowHUD() then return end;
- local player = getPlayer();
- -- Options
- local showFrame = true;
- local colorNumber = false;
- -- Size and spacing
- local frameWidth = 460;
- local frameHeight = 55;
- local framePadding = 5;
- local numberSpacing = 100;
- local iconSpacing = 0;
- -- Colors
- local frameColor = Color(0,0,0,128);
- local weaponIndexSelected = player.weaponIndexSelected;
- local weapon = player.weapons[weaponIndexSelected];
- local ammo = weapon.ammo;
- local barColor;
- if ammo < weapon.lowAmmoWarning then barColor = Color(245,215,50, 160) end
- if ammo > weapon.lowAmmoWarning then barColor = Color(245,215,50, 160);
- else barColor = Color(245,215,50, 160); end
- local barBackgroundColor;
- if ammo < weapon.lowAmmoWarning then barBackgroundColor = Color(122,111,50, 160) end
- if ammo > weapon.lowAmmoWarning then barBackgroundColor = Color(122,111,50, 160);
- else barBackgroundColor = Color(122,111,50, 160); end
- -- Helpers
- local frameLeft = 0;
- local frameTop = -frameHeight;
- local frameRight = frameWidth;
- local frameBottom = 0;
- local barLeft = frameLeft + iconSpacing + numberSpacing
- local barTop = frameTop + framePadding;
- local barRight = frameRight - framePadding;
- local barBottom = frameBottom - framePadding;
- local barWidth = 200 + numberSpacing + 15 + iconSpacing;
- local barHeight = frameHeight - (framePadding * 2);
- local fontX = barLeft - (numberSpacing / 2);
- local fontY = -(frameHeight / 2);
- local fontSize = frameHeight * 1.15;
- if ammo > 100 then fillWidth = (barWidth / 100) * (ammo - 100);
- else fillWidth = (barWidth / 100) * ammo; end
- -- Frame
- if showFrame then
- nvgBeginPath();
- nvgRoundedRect(frameRight + 95, frameBottom - 60, -frameWidth, -frameHeight, 5);
- nvgFillColor(frameColor);
- nvgFill();
- if ammo > 100 then
- nvgBeginPath();
- nvgRoundedRect(frameRight - 40, frameBottom, -frameWidth + 135, -frameHeight, 5);
- nvgFillColor(frameColor);
- nvgFill();
- end
- end
- -- Background
- nvgBeginPath();
- nvgRect(barRight - 40, barBottom - 60, -barWidth, -barHeight);
- nvgFillColor(barBackgroundColor);
- nvgFill();
- if ammo > 100 then
- nvgBeginPath();
- nvgRect(barRight - 40, barBottom, -barWidth, -barHeight);
- nvgFillColor(barBackgroundColor);
- nvgFill();
- end
- -- Bar
- if ammo <= 100 then
- nvgBeginPath();
- nvgRect(barLeft + 315, barBottom - 60, -fillWidth, -barHeight);
- nvgFillColor(barColor);
- nvgFill();
- end
- if ammo > 100 then
- nvgBeginPath();
- nvgRect(barLeft + 315, barBottom, -fillWidth, -barHeight);
- nvgFillColor(barColor);
- nvgFill();
- nvgBeginPath();
- nvgRect(barLeft + 315, barBottom - 60, -barWidth, -barHeight);
- nvgFillColor(barColor);
- nvgFill();
- end
- -- colour changes when low on ammo
- local fontColor = Color(230,230,230);
- local glow = false;
- if ammo == 0 then
- fontColor = Color(230, 0, 0);
- glow = true;
- elseif ammo < weapon.lowAmmoWarning then
- fontColor = Color(230, 230, 0);
- glow = true;
- end
- nvgFontSize(fontSize);
- nvgFontFace(FONT_HUD);
- nvgTextAlign(NVG_ALIGN_RIGHT, NVG_ALIGN_MIDDLE);
- -- unlimited ammo if melee, in race mode, or in warmup mode
- if weaponIndexSelected == 1 then ammo = "-" end
- if isRaceMode() then ammo = "-" end
- if glow then
- nvgFontBlur(5);
- nvgFillColor(Color(64, 64, 200));
- nvgText(fontX + 447, fontY - 60, ammo);
- end
- nvgFontBlur(0);
- nvgFillColor(fontColor);
- nvgText(fontX + 447, fontY - 60, ammo);
- -- Draw icon
- local iconX = frameLeft + (iconSpacing / 2) + framePadding;
- local iconY = -(frameHeight / 2);
- local iconSize = (frameHeight / 2) * 0.75;
- local svgName = "internal/ui/icons/weapon" .. weaponIndexSelected;
- iconColor = player.weapons[weaponIndexSelected].color;
- nvgFillColor(iconColor);
- nvgSvg(svgName, iconX + 525, iconY - 60, iconSize);
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement