ExperimentalGear/scripts/components/volforceWindow.lua

83 lines
2.1 KiB
Lua

local VF_BRACKETS = { 0, 10, 12, 14, 15, 16, 17, 18, 19, 20, 24 }
local function handleForce(vf)
local volforceAmount, volforceNumber, starsCount, starType = vf, 1, 1, 1
for i = 1, 10 do
local top, down = VF_BRACKETS[i + 1], VF_BRACKETS[i]
if vf < top or i == 10 then
volforceNumber = i
local range = top - down
for b = 1, 4 do
if vf < (down + b * 0.25 * range) or b == 4 then
starsCount = b
break
end
end
break
end
end
if volforceNumber >= 7 then
starType = 2
end
return volforceAmount, volforceNumber, starsCount, starType
end
local volforceBadgeImage = {}
local vfStar = {}
function render(deltatime, x, y, size, amount, onlyText, onlyImage, hasStars)
gfx.LoadSkinFont('Digital-Serial-Bold.ttf')
gfx.TextAlign(gfx.TEXT_ALIGN_LEFT + gfx.TEXT_ALIGN_MIDDLE)
local volforceAmount, volforceNumber, starsCount, starType = handleForce(amount or 0)
if onlyImage then
if not volforceBadgeImage[volforceNumber] then
volforceBadgeImage[volforceNumber] = gfx.CreateSkinImage("volforce/" .. volforceNumber .. ".png", 1)
end
gfx.BeginPath()
gfx.ImageRect(x - 8, y - 16, size * 1.5, size * 1.5, volforceBadgeImage[volforceNumber], 1, 0)
end
if hasStars then
local divider
if not vfStar[starType] then
vfStar[starType] = gfx.CreateSkinImage("volforce/stars/" .. starType .. ".png", 1)
end
for i = 1, starsCount do
if starsCount == 1 then
divider = 18
elseif starsCount == 2 then
divider = 13
elseif starsCount == 3 then
divider = 8.25
elseif starsCount == 4 then
divider = 5
end
gfx.BeginPath()
gfx.ImageRect(x + divider + (i - 1) * (divider + (starsCount == 1 and 0 or (starsCount == 2 and -2 or (starsCount == 3 and 2 or 5)))), y + 32.5, size / 4, size / 4, vfStar[starType], 1, 0)
end
end
if onlyText then
gfx.FontSize(11)
gfx.Text('VOLFORCE', x + 47, y + 14)
gfx.FontSize(18)
gfx.Text(string.format('%.3f', volforceAmount), x + 47, y + 30)
end
end
return {
render = render
}