Use str_time/str_time_float everywhere

This commit is contained in:
def 2020-10-18 23:33:45 +02:00
parent 8dfcd67fe6
commit 67178b0ea0
7 changed files with 35 additions and 56 deletions

View file

@ -123,23 +123,12 @@ void CHud::RenderGameTimer()
else
Time = (Client()->GameTick(g_Config.m_ClDummy) - m_pClient->m_Snap.m_pGameInfoObj->m_RoundStartTick) / Client()->GameTickSpeed();
str_time_format((int64_t)Time * 100,
if(Time <= 0)
str_format(aBuf, sizeof(aBuf), "00:00");
else if(Time >= 3600 * 24)
str_format(aBuf, sizeof(aBuf), "%dd %02d:%02d:%02d", Time / (3600 * 24), (Time % (3600 * 24)) / 3600, (Time % 3600) / 60, Time % 60);
else if(Time >= 3600)
str_format(aBuf, sizeof(aBuf), "%02d:%02d:%02d", Time / 3600, (Time % 3600) / 60, Time % 60);
else
str_format(aBuf, sizeof(aBuf), "%02d:%02d", Time / 60, Time % 60);
str_time(Time * 100, TIME_DAYS, aBuf, sizeof(aBuf));
float FontSize = 10.0f;
float w;
if(Time >= 3600 * 24)
w = TextRender()->TextWidth(0, 12, "00d 00:00:00", -1, -1.0f);
else if(Time >= 3600)
w = TextRender()->TextWidth(0, 12, "00:00:00", -1, -1.0f);
else
w = TextRender()->TextWidth(0, 12, "00:00", -1, -1.0f);
w = TextRender()->TextWidth(0, 12,
Time >= 3600 * 24 ? "00d 00:00:00" : Time >= 3600 ? "00:00:00" : "00:00",
-1, -1.0f);
// last 60 sec red, last 10 sec blink
if(m_pClient->m_Snap.m_pGameInfoObj->m_TimeLimit && Time <= 60 && (m_pClient->m_Snap.m_pGameInfoObj->m_WarmupTimer <= 0))
{
@ -341,13 +330,7 @@ void CHud::RenderScoreHud()
if(m_pClient->m_GameInfo.m_TimeScore && g_Config.m_ClDDRaceScoreBoard)
{
if(apPlayerInfo[t]->m_Score != -9999)
{
int Secs = abs(apPlayerInfo[t]->m_Score);
if(Secs > 3600)
str_format(aScore[t], sizeof(aScore[t]), "%02d:%02d:%02d", Secs / 3600, (Secs % 3600) / 60, Secs % 60);
else
str_format(aScore[t], sizeof(aScore[t]), "%02d:%02d", Secs / 60, Secs % 60);
}
str_time((int64)abs(apPlayerInfo[t]->m_Score) * 100, TIME_HOURS, aScore[t], sizeof(aScore[t]));
else
aScore[t][0] = 0;
}

View file

@ -1122,19 +1122,18 @@ void CMenus::RenderServerbrowserServerDetail(CUIRect View)
else if(IsRace(pSelectedServer) && g_Config.m_ClDDRaceScoreBoard)
{
if(pSelectedServer->m_aClients[i].m_Score == -9999 || pSelectedServer->m_aClients[i].m_Score == 0)
{
aTemp[0] = 0;
}
else
{
int Time = abs(pSelectedServer->m_aClients[i].m_Score);
str_format(aTemp, sizeof(aTemp), "%02d:%02d", Time / 60, Time % 60);
}
str_time((int64)abs(pSelectedServer->m_aClients[i].m_Score) * 100, TIME_HOURS, aTemp, sizeof(aTemp));
}
else
str_format(aTemp, sizeof(aTemp), "%d", pSelectedServer->m_aClients[i].m_Score);
TextRender()->SetCursor(&Cursor, Score.x, Score.y + (Score.h - FontSize) / 2.0f, FontSize, TEXTFLAG_RENDER | TEXTFLAG_STOP_AT_END);
float ScoreFontSize = 12.0f;
while(ScoreFontSize >= 4.0f && TextRender()->TextWidth(0, ScoreFontSize, aTemp, -1, -1.0f) > Score.w)
ScoreFontSize--;
TextRender()->SetCursor(&Cursor, Score.x, Score.y + (Score.h - ScoreFontSize) / 2.0f, ScoreFontSize, TEXTFLAG_RENDER | TEXTFLAG_STOP_AT_END);
Cursor.m_LineWidth = Score.w;
TextRender()->TextEx(&Cursor, aTemp, -1);

View file

@ -319,9 +319,11 @@ void CMenus::RenderDemoPlayer(CUIRect MainView)
}
// draw time
str_format(aBuffer, sizeof(aBuffer), "%d:%02d / %d:%02d",
CurrentTick / SERVER_TICK_SPEED / 60, (CurrentTick / SERVER_TICK_SPEED) % 60,
TotalTicks / SERVER_TICK_SPEED / 60, (TotalTicks / SERVER_TICK_SPEED) % 60);
char aCurrentTime[32];
str_time((int64)CurrentTick / SERVER_TICK_SPEED * 100, TIME_HOURS, aCurrentTime, sizeof(aCurrentTime));
char aTotalTime[32];
str_time((int64)TotalTicks / SERVER_TICK_SPEED * 100, TIME_HOURS, aTotalTime, sizeof(aTotalTime));
str_format(aBuffer, sizeof(aBuffer), "%s / %s", aCurrentTime, aTotalTime);
UI()->DoLabel(&SeekBar, aBuffer, SeekBar.h * 0.70f, 0);
// do the logic
@ -923,7 +925,7 @@ void CMenus::RenderDemoList(CUIRect MainView)
UI()->DoLabelScaled(&Left, Localize("Length:"), 14.0f, -1);
int Length = m_lDemos[m_DemolistSelectedIndex].Length();
char aBuf[64];
str_format(aBuf, sizeof(aBuf), "%d:%02d", Length / 60, Length % 60);
str_time((int64)Length * 100, TIME_HOURS, aBuf, sizeof(aBuf));
UI()->DoLabelScaled(&Right, aBuf, 14.0f, -1);
Labels.HSplitTop(5.0f, 0, &Labels);
Labels.HSplitTop(20.0f, &Left, &Labels);
@ -1243,7 +1245,7 @@ void CMenus::RenderDemoList(CUIRect MainView)
{
int Length = r.front().Length();
char aBuf[32];
str_format(aBuf, sizeof(aBuf), "%d:%02d", Length / 60, Length % 60);
str_time((int64)Length * 100, TIME_HOURS, aBuf, sizeof(aBuf));
Button.VMargin(4.0f, &Button);
UI()->DoLabelScaled(&Button, aBuf, 12.0f, 1);
}

View file

@ -1157,7 +1157,7 @@ void CMenus::RenderGhost(CUIRect MainView)
Cursor.m_LineWidth = Button.w;
char aBuf[64];
str_format(aBuf, sizeof(aBuf), "%02d:%02d.%03d", pItem->m_Time / (60 * 1000), (pItem->m_Time / 1000) % 60, pItem->m_Time % 1000);
str_time(pItem->m_Time / 10, TIME_HOURS_CENTISECS, aBuf, sizeof(aBuf));
TextRender()->TextEx(&Cursor, aBuf, -1);
}
}

View file

@ -235,9 +235,7 @@ void CScoreboard::RenderScoreboard(float x, float y, float w, int Team, const ch
if(m_pClient->m_GameInfo.m_TimeScore && g_Config.m_ClDDRaceScoreBoard)
{
if(m_ServerRecord > 0)
{
str_format(aBuf, sizeof(aBuf), "%02d:%02d", ((int)m_ServerRecord) / 60, ((int)m_ServerRecord) % 60);
}
str_time_float(m_ServerRecord, TIME_HOURS, aBuf, sizeof(aBuf));
else
aBuf[0] = 0;
}
@ -421,13 +419,7 @@ void CScoreboard::RenderScoreboard(float x, float y, float w, int Team, const ch
if(pInfo->m_Score == -9999)
aBuf[0] = 0;
else
{
int Time = abs(pInfo->m_Score);
if(Time / 3600)
str_format(aBuf, sizeof(aBuf), "%02d:%02d:%02d", Time / 3600, (Time / 60) % 60, Time % 60);
else
str_format(aBuf, sizeof(aBuf), "%02d:%02d", Time / 60, Time % 60);
}
str_time((int64)abs(pInfo->m_Score) * 100, TIME_HOURS, aBuf, sizeof(aBuf));
}
else
str_format(aBuf, sizeof(aBuf), "%d", clamp(pInfo->m_Score, -999, 99999));
@ -548,30 +540,30 @@ void CScoreboard::RenderRecordingNotification(float x)
//draw the text
char aBuf[64] = "\0";
char aBuf2[64];
int Seconds;
char aTime[32];
if(m_pClient->DemoRecorder(RECORDER_MANUAL)->IsRecording())
{
Seconds = m_pClient->DemoRecorder(RECORDER_MANUAL)->Length();
str_format(aBuf2, sizeof(aBuf2), Localize("Manual %3d:%02d "), Seconds / 60, Seconds % 60);
str_time((int64)m_pClient->DemoRecorder(RECORDER_MANUAL)->Length() * 100, TIME_HOURS, aTime, sizeof(aTime));
str_format(aBuf2, sizeof(aBuf2), "%s %s ", Localize("Manual"), aTime);
str_append(aBuf, aBuf2, sizeof(aBuf));
}
if(m_pClient->DemoRecorder(RECORDER_RACE)->IsRecording())
{
Seconds = m_pClient->DemoRecorder(RECORDER_RACE)->Length();
str_format(aBuf2, sizeof(aBuf2), Localize("Race %3d:%02d "), Seconds / 60, Seconds % 60);
str_time((int64)m_pClient->DemoRecorder(RECORDER_RACE)->Length() * 100, TIME_HOURS, aTime, sizeof(aTime));
str_format(aBuf2, sizeof(aBuf2), "%s %s ", Localize("Race"), aTime);
str_append(aBuf, aBuf2, sizeof(aBuf));
}
if(m_pClient->DemoRecorder(RECORDER_AUTO)->IsRecording())
{
Seconds = m_pClient->DemoRecorder(RECORDER_AUTO)->Length();
str_format(aBuf2, sizeof(aBuf2), Localize("Auto %3d:%02d "), Seconds / 60, Seconds % 60);
str_time((int64)m_pClient->DemoRecorder(RECORDER_AUTO)->Length() * 100, TIME_HOURS, aTime, sizeof(aTime));
str_format(aBuf2, sizeof(aBuf2), "%s %s ", Localize("Auto"), aTime);
str_append(aBuf, aBuf2, sizeof(aBuf));
}
if(m_pClient->DemoRecorder(RECORDER_REPLAYS)->IsRecording())
{
Seconds = m_pClient->DemoRecorder(RECORDER_REPLAYS)->Length();
str_format(aBuf2, sizeof(aBuf2), Localize("Replay %3d:%02d "), Seconds / 60, Seconds % 60);
str_time((int64)m_pClient->DemoRecorder(RECORDER_REPLAYS)->Length() * 100, TIME_HOURS, aTime, sizeof(aTime));
str_format(aBuf2, sizeof(aBuf2), "%s %s ", Localize("Replay"), aTime);
str_append(aBuf, aBuf2, sizeof(aBuf));
}

View file

@ -2072,8 +2072,10 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID)
{
pPlayer->m_LastSetTeam = Server()->Tick();
int TimeLeft = (pPlayer->m_TeamChangeTick - Server()->Tick()) / Server()->TickSpeed();
char aTime[32];
str_time((int64)TimeLeft * 100, TIME_HOURS, aTime, sizeof(aTime));
char aBuf[128];
str_format(aBuf, sizeof(aBuf), "Time to wait before changing team: %02d:%02d", TimeLeft / 60, TimeLeft % 60);
str_format(aBuf, sizeof(aBuf), "Time to wait before changing team: %s", aTime);
SendBroadcast(aBuf, ClientID);
return;
}

View file

@ -406,7 +406,8 @@ bool CScore::MapInfoThread(IDbConnection *pSqlServer, const ISqlData *pGameData)
char aAverageString[60] = "\0";
if(Average > 0)
{
str_format(aAverageString, sizeof(aAverageString), " in %d:%02d average", Average / 60, Average % 60);
str_time((int64_t)Average * 100, TIME_HOURS, aBuf, sizeof(aBuf));
str_format(aAverageString, sizeof(aAverageString), " in %s average", aBuf);
}
char aStars[20];