ExperimentalGear/scripts/gameplay/earlylate.lua

103 lines
2.7 KiB
Lua
Raw Normal View History

2022-05-14 10:54:17 +02:00
local Dimensions = require "common.dimensions"
2021-09-05 16:07:17 +02:00
2022-05-14 10:54:17 +02:00
-- Used for comparing button_hit()'s delta parameter with the
-- gameplay_earlyLateFor/gameplay_msDisplay skin settings values.
-- If the number is <= delta then the EarlyLate/ms should be shown
local compare = {
["ALL"] = 2,
["CRITICAL (or worse)"] = 2,
["NEAR (or worse)"] = 1,
["NONE"] = -1,
["OFF"] = -1
}
2021-09-05 16:07:17 +02:00
local portraitHeightFractions = {
["UPPER+"] = 2.4,
2022-05-14 10:54:17 +02:00
["UPPER"] = 3,
["STANDARD"] = 4,
["LOWER"] = 5.3,
}
local landscapeHeightFractions = {
["UPPER+"] = 1.4,
["UPPER"] = 2.7,
["STANDARD"] = 5.1,
["LOWER"] = 6.7,
2022-05-14 10:54:17 +02:00
}
2021-09-05 16:07:17 +02:00
2022-05-14 10:54:17 +02:00
local earlyLateFor = compare[game.GetSkinSetting("gameplay_earlyLateFor")]
local msFor = compare[game.GetSkinSetting("gameplay_msFor")]
local earlyLatePosition = game.GetSkinSetting("gameplay_earlyLatePosition")
2022-05-14 10:54:17 +02:00
local EarlyLate = {
timer = 0,
lastMillisec = 0,
showEarlyLate = false,
showMillisec = false,
}
function EarlyLate.render(deltaTime)
if EarlyLate.timer <= 0 then
return
2021-09-05 16:07:17 +02:00
end
2022-05-14 10:54:17 +02:00
EarlyLate.timer = EarlyLate.timer - deltaTime * 100
local screenW, screenH = Dimensions.screen.width, Dimensions.screen.height
local screenCenterX = screenW / 2
2021-09-05 16:07:17 +02:00
local desh, fractionTable
2022-05-14 10:54:17 +02:00
if screenH > screenW then
desh = 1920
fractionTable = portraitHeightFractions
2022-05-14 10:54:17 +02:00
else
desh = 1080
fractionTable = landscapeHeightFractions
2021-09-05 16:07:17 +02:00
end
local scale = screenH / desh
local y = screenH / 8 * fractionTable[earlyLatePosition]
2022-05-14 10:54:17 +02:00
gfx.BeginPath()
gfx.LoadSkinFont("Digital-Serial-Bold.ttf")
gfx.FontSize(20 * scale)
2021-09-05 16:07:17 +02:00
2022-05-14 10:54:17 +02:00
if EarlyLate.showEarlyLate then
gfx.TextAlign(gfx.TEXT_ALIGN_LEFT + gfx.TEXT_ALIGN_BASELINE)
if EarlyLate.lastMillisec < 0 then
2022-05-16 11:21:19 +02:00
gfx.FillColor(206, 94, 135)
2022-05-14 10:54:17 +02:00
gfx.FastText("EARLY", screenCenterX - 100 * scale, y)
else
2022-05-16 11:21:19 +02:00
gfx.FillColor(53, 102, 197)
2022-05-14 10:54:17 +02:00
gfx.FastText("LATE", screenCenterX - 100 * scale, y)
end
end
if EarlyLate.showMillisec then
local msString = string.format("%dms", EarlyLate.lastMillisec)
if EarlyLate.lastMillisec >= 0 then
msString = "+"..msString -- prepend + sign for lates
end
gfx.TextAlign(gfx.TEXT_ALIGN_RIGHT + gfx.TEXT_ALIGN_BASELINE)
gfx.FastText(msString, screenCenterX + 100 * scale, y)
end
2021-09-05 16:07:17 +02:00
end
2022-05-14 10:54:17 +02:00
function EarlyLate.TriggerAnimation(rating, millisec)
local showEarlyLate = rating <= earlyLateFor
local showMillisec = rating <= msFor
if showEarlyLate or showMillisec then
EarlyLate.timer = 120
EarlyLate.lastMillisec = millisec
EarlyLate.showEarlyLate = showEarlyLate
EarlyLate.showMillisec = showMillisec
end
2021-09-05 16:07:17 +02:00
end
2022-05-14 10:54:17 +02:00
return EarlyLate