#include "ui_helpers.lua" #include "game.lua" gScoreShown = 0 gScoreCanvasHeight = 0 gScoreTimer = 0 gScoreBonusScale = 0 gScoreStatsScale = 0 function drawTargetDots(count, taken, blinkUntaken) UiPush() UiScale(1) UiAlign("right middle") for i=1,count do if taken >= i then UiImage("common/score-target-taken-22.png") else UiPush() if blinkUntaken then local a = .7 + math.sin(GetTime()*10)*0.3 UiColorFilter(1, 1, 1, a) end UiImage("common/score-target-22.png") UiPop() end UiTranslate(-28, 0) end UiPop() return 28 * count end function initDrawScore() gScoreShown = 0 gScoreTimer = 0.5 gScoreCanvasHeight = 0 SetValue("gScoreBonusScale", 0) SetValue("gScoreStatsScale", 0) end local bigFontSize = 32 function drawScoreString(count, taken, text, width, offset, blink) UiPush() UiAlign("left middle") UiFont("medium.ttf", 27) UiText(text) UiTranslate(width, offset) drawTargetDots(count, taken, blink) UiPop() end function drawStatString(text, value, width, fontSize) UiPush() UiAlign("left middle") UiTextAlignment("left") UiFont("medium.ttf", fontSize) UiText(text) if value ~= nil then UiTranslate(width, 0) UiAlign("right middle") UiTextAlignment("right") UiFont("medium.ttf", 32) UiText(value) end UiPop() end function drawScoreGroup(width, group) if #group.items == 0 then return end UiFont("medium.ttf", 32) UiColor(group.color[1], group.color[2], group.color[3]) UiAlign("left") UiText(group.title) if group.value ~= nil then UiPush() UiAlign("right") UiTranslate(width, 0) UiText(group.value) UiPop() end UiTranslate(0, 34) for _, it in pairs(group.items) do local offset = 0 if it.count ~= nil and it.count > 0 then drawScoreString(it.count, it.taken, it.title, width, offset, it.blink) else local fontSize = 27 if it.big then fontSize = 48 end drawStatString(it.title, it.value, width, fontSize) end UiTranslate(0, 36) end UiTranslate(0, 15) end function drawScore(id, score, timeLeft, missionTime, animate, width, frame) local internalWidth = width UiPush() UiAlign("left") UiTextAlignment("left") local details if animate then local eval = false if gScoreShown < score+1 then gScoreTimer = gScoreTimer - GetTimeStep() if gScoreTimer < 0.0 then gScoreShown = gScoreShown + 1 gScoreTimer = 0.15 if gScoreShown == score+1 then SetValue("gScoreStatsScale", 1, "linear", 0.5) UiSound("common/score-stats-500.ogg") else eval = true end end end if gScoreShown < score then score = gScoreShown end details = getScoreDetails(id, score); if eval then if score <= details.required + details.optional then UiSound("score.ogg") else UiSound("common/score-bonus.ogg") end if score == details.required then gScoreTimer = gScoreTimer + 0.2 end if score == details.required + details.optional then gScoreTimer = gScoreTimer + 0.4 if gScoreBonusScale == 0.0 and details.bonuses > 0 then SetValue("gScoreBonusScale", 1, "linear", 0.3) UiSound("common/score-bonus-shown.ogg") end end if score > details.required + details.optional then gScoreTimer = gScoreTimer + 0.2 end end else details = getScoreDetails(id, score); gScoreBonusScale = 1 gScoreStatsScale = 1 end UiFont("medium.ttf", bigFontSize) UiColor(.5, .5, .5) if frame then internalWidth = internalWidth - 38 UiTranslate(20, 0) end UiTranslate(0, 48) local targetItems = {} table.insert(targetItems, {count = details.required, taken = details.requiredTaken, title = "loc@UI_TEXT_REQUIRED", items = targetItems}) if details.optional > 0 then table.insert(targetItems, {count = details.optional, taken = details.optionalTaken, title = "loc@UI_TEXT_OPTIONAL", blink = true, items = targetItems }) end drawScoreGroup(internalWidth, { title = "loc@UI_TEXT_TARGETS", color = { 1, 1, 1}, items = targetItems }) local bounsItems = {} for i=1, #details.bonus do table.insert(bounsItems, {count = 1, taken = details.bonus[i].taken, title = details.bonus[i].desc, blink = true}) end UiTranslate(0, 4) drawScoreGroup(internalWidth, { title = "loc@UI_TEXT_BONUS", color = { 1, 1, 0.5}, items = bounsItems}) local statsItems = {} if timeLeft > 0 then table.insert(statsItems, { title = "loc@UI_TEXT_TIME_LEFT", value = math.floor(timeLeft*gScoreStatsScale*10+0.5)/10 ..GetTranslatedStringByKey("TIME_SECONDS_SHORT")}) end if missionTime > 0 then local function timeValue() local m = math.floor(gScoreStatsScale*missionTime/60) local s = math.floor(gScoreStatsScale*missionTime-m*60) if m > 0 then return m..GetTranslatedStringByKey("TIME_MINUTES_SHORT").." "..s..GetTranslatedStringByKey("TIME_SECONDS_SHORT") else return s..GetTranslatedStringByKey("TIME_SECONDS_SHORT") end end table.insert(statsItems, { title = "loc@UI_TEXT_MISSION_TIME", value = timeValue() }) end if timeLeft == 0 and missionTime == 0 then table.insert(statsItems, { title = "loc@UI_TEXT_MISSION_SKIPPED"}) end drawScoreGroup(internalWidth, { title = "loc@UI_TEXT_STATS", color = {1, 1, 0.5}, items = statsItems}) _,gScoreCanvasHeight = UiGetRelativePos() UiPop() if frame then UiPush() UiColor(0.37, 0.37, 0.37) UiImageBox("common/score-frame-7.png", width, gScoreCanvasHeight - 12, 8, 8) UiPop() end return gScoreCanvasHeight end