Skip to content

Commit

Permalink
Update dictionary.csv
Browse files Browse the repository at this point in the history
  • Loading branch information
hzqst committed Jan 20, 2024
1 parent f755b6a commit bcaf917
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 177 deletions.
35 changes: 9 additions & 26 deletions Build/svencoop/captionmod/dictionary.csv
Original file line number Diff line number Diff line change
Expand Up @@ -798,33 +798,16 @@ barney/youhearthat.wav,#youhearthat,Blue,,#HalfLife_Security,,,C
barney/youneedmedic.wav,#youneedmedic,Blue,,#HalfLife_Security,,,C
barney/youtalkmuch.wav,#youtalkmuch,Blue,,#HalfLife_Security,,,C
barney/yup.wav,#yup,Blue,,#HalfLife_Security,,,C
tride/c0a0_tr_gmorn.wav,#c0a0_tr_gmorn,Purple,11,#HalfLife_Train,,,C IGNORE_DISTANCE_LIMIT
tride/c0a0_tr_time.wav,#c0a0_tr_time,Purple,4.7,#HalfLife_Train,tr_time2,4.7,C IGNORE_DISTANCE_LIMIT
tr_time2,#tr_time2,Purple,10,#HalfLife_Train,tr_time3,10,C
tr_time3,#tr_time3,Purple,8,#HalfLife_Train,,8,C
tride/c0a0_tr_dest.wav,#c0a0_tr_dest,Purple,10,#HalfLife_Train,tr_dest2,9.9,C IGNORE_DISTANCE_LIMIT
tr_dest2,#tr_dest2,Purple,6.2,#HalfLife_Train,tr_dest3,6.1,C
tr_dest3,#tr_dest3,Purple,8,#HalfLife_Train,tr_dest4,8,C
tr_dest4,#tr_dest4,Purple,5,#HalfLife_Train,tr_dest5,5,C
tr_dest5,#tr_dest5,Purple,10,#HalfLife_Train,,10,C
tride/c0a0_tr_noeat.wav,#c0a0_tr_noeat,Purple,3.9,#HalfLife_Train,tr_noeat2,3.8,C IGNORE_DISTANCE_LIMIT
tr_noeat2,#tr_noeat2,Purple,5.9,#HalfLife_Train,tr_noeat3,5.8,C
tr_noeat3,#tr_noeat3,Purple,3,#HalfLife_Train,,3,C
tride/c0a0_tr_emerg.wav,#c0a0_tr_emerg,Purple,4.2,#HalfLife_Train,tr_emerg2,4.1,C IGNORE_DISTANCE_LIMIT
tr_emerg2,#tr_emerg2,Purple,5.9,#HalfLife_Train,tr_emerg3,5.8,C
tr_emerg3,#tr_emerg3,Purple,2.1,#HalfLife_Train,tr_emerg4,2.3,C
tr_emerg4,#tr_emerg4,Purple,23,#HalfLife_Train,,,C
tride/c0a0_tr_tourn.wav,#c0a0_tr_tourn,Purple,24.3,#HalfLife_Train,,,C IGNORE_DISTANCE_LIMIT
tride/c0a0_tr_jobs.wav,#c0a0_tr_jobs,Purple,6.3,#HalfLife_Train,tr_jobs2,6.3,C IGNORE_DISTANCE_LIMIT
tr_jobs2,#tr_jobs2,Purple,8,#HalfLife_Train,tr_jobs3,8,C
tr_jobs3,#tr_jobs3,Purple,5,#HalfLife_Train,tr_jobs4,4.9,C
tr_jobs4,#tr_jobs4,Purple,17.4,#HalfLife_Train,,,C
tride/c0a0_tr_haz.wav,#c0a0_tr_haz,Purple,19.7,#HalfLife_Train,tr_haz2,20,C IGNORE_DISTANCE_LIMIT
tr_haz2,#tr_haz2,Purple,11.7,#HalfLife_Train,tr_haz3,11.6,C
tr_haz3,#tr_haz3,Purple,5,#HalfLife_Train,,,C
tride/c0a0_tr_gmorn.wav,#c0a0_tr_gmorn,Purple,,#HalfLife_Train,,,C IGNORE_DISTANCE_LIMIT
tride/c0a0_tr_time.wav,#c0a0_tr_time,Purple,,#HalfLife_Train,,,C IGNORE_DISTANCE_LIMIT
tride/c0a0_tr_dest.wav,#c0a0_tr_dest,Purple,,#HalfLife_Train,,,C IGNORE_DISTANCE_LIMIT
tride/c0a0_tr_noeat.wav,#c0a0_tr_noeat,Purple,,#HalfLife_Train,,,C IGNORE_DISTANCE_LIMIT
tride/c0a0_tr_emerg.wav,#c0a0_tr_emerg,Purple,,#HalfLife_Train,,,C IGNORE_DISTANCE_LIMIT
tride/c0a0_tr_tourn.wav,#c0a0_tr_tourn,Purple,,#HalfLife_Train,,,C IGNORE_DISTANCE_LIMIT
tride/c0a0_tr_jobs.wav,#c0a0_tr_jobs,Purple,,#HalfLife_Train,,,C IGNORE_DISTANCE_LIMIT
tride/c0a0_tr_haz.wav,#c0a0_tr_haz,Purple,,#HalfLife_Train,,,C IGNORE_DISTANCE_LIMIT
tride/c0a0_tr_arrive.wav,#c0a0_tr_arrive,Purple,,#HalfLife_Train,,,C IGNORE_DISTANCE_LIMIT
tride/c0a0_tr_exit.wav,#c0a0_tr_exit,Purple,13,#HalfLife_Train,tr_exit2,13.1,C IGNORE_DISTANCE_LIMIT
tr_exit2,#tr_exit2,Purple,4.1,#HalfLife_Train,,,C
tride/c0a0_tr_exit.wav,#c0a0_tr_exit,Purple,,#HalfLife_Train,,,C IGNORE_DISTANCE_LIMIT
gman/gman_suit.wav,#gman_suit,SweetBlue,,,,,C IGNORE_DISTANCE_LIMIT
gman/gman_nasty.wav,#gman_nasty,SweetBlue,,,,,C IGNORE_DISTANCE_LIMIT
gman/gman_potential.wav,#gman_potential,SweetBlue,,,,,C IGNORE_DISTANCE_LIMIT
Expand Down
Binary file modified Build/svencoop/captionmod/dictionary_english.txt
Binary file not shown.
Binary file modified Build/svencoop/captionmod/dictionary_schinese.txt
Binary file not shown.
58 changes: 40 additions & 18 deletions Plugins/CaptionMod/SubtitlePanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,13 +295,14 @@ void CSubLine::Draw(int x, int w, int align)
surface()->DrawFlushText();
}

void SubtitlePanel::StartNextSubtitle(CDictionary *Dict)
void SubtitlePanel::StartNextSubtitle(CDictionary *pDict)
{
//Check if there is a next dict to be played
CDictionary *pNextDict = Dict->m_pNext;
auto pNextDict = pDict->m_pNext;

if(pNextDict)
{
StartSubtitle(pNextDict, g_pViewPort->GetSystemTime() + Dict->m_flNextDelay);
StartSubtitle(pNextDict, pDict->m_flDuration, g_pViewPort->GetSystemTime() + pDict->m_flNextDelay);
}
}

Expand Down Expand Up @@ -400,8 +401,13 @@ void SubtitlePanel::AddLine(CDictionary *Dict, wchar_t *wszSentence, int nLength
Line->m_TextAlign = Dict->m_iTextAlign ? Dict->m_iTextAlign : m_iTextAlign;
}

static bool IsNonBreakableCharacter(wchar_t ch)
{
return ((ch >= L'A' && ch <= L'Z') || (ch >= L'a' && ch <= L'z') || ch == L'Ç' || ch == L'ç' || ch == L'Ğ' || ch == L'ğ' || ch == L'İ' || ch == L'ı' || ch == L'Ö' || ch == L'ö' || ch == L'Ş' || ch == L'ş' || ch == L'Ü' || ch == L'ü' || ch == L'â' || ch == L'Â' || ch == L':' || ch == L'-' || ch == L'\'' || ch == L'"' || ch == L',' || ch == L'.' || ch == L'!' || ch == L'?' || ch == L';' || ch == '%' || (ch >= L'0' && ch <= L'9')) ? true : false;
}

//2015-11-26 added htimescale for SubtitlePanel
void SubtitlePanel::StartSubtitle(CDictionary *Dict, float flStartTime)
void SubtitlePanel::StartSubtitle(CDictionary * pDict, float flDurationTime, float flStartTime)
{
//Delay the current line till the last backline plays
float flLatestStart = 0;
Expand All @@ -416,8 +422,9 @@ void SubtitlePanel::StartSubtitle(CDictionary *Dict, float flStartTime)
if (m_BackLines[i]->m_StartTime > flLatestStart)
flLatestStart = m_BackLines[i]->m_StartTime;
}

//Already in list, do not start one subtitle for twice at the same time.
if(m_BackLines[i]->m_Dict == Dict)
if(m_BackLines[i]->m_Dict == pDict)
return;
}

Expand All @@ -426,14 +433,14 @@ void SubtitlePanel::StartSubtitle(CDictionary *Dict, float flStartTime)
for (int i = 0; i < m_Lines.Count(); ++i)
{
//Already in display, ignore
if (m_Lines[i]->m_Dict == Dict)
if (m_Lines[i]->m_Dict == pDict)
return;
}
}

std::wstring sentence;

Dict->FinalizeString(sentence, m_iPrefix);
pDict->FinalizeString(sentence, m_iPrefix);

int iPanelWidth = GetWide();
int iMaxTextWidth = iPanelWidth - (m_iScaledXSpace << 1);
Expand Down Expand Up @@ -464,16 +471,16 @@ void SubtitlePanel::StartSubtitle(CDictionary *Dict, float flStartTime)
if(!nTotalCharNum)
return;

float flDuration = Dict->m_flDuration;
float flDuration = flDurationTime;

//use m_flHoldTime as default
//Fallback to m_flHoldTime
if(flDuration <= 0)
flDuration = m_flHoldTime;

if(flDuration <= 0)
flDuration = 4.0f;

if (!Dict->m_bOverrideDuration && g_pCurrentTextMessage)
if (!pDict->m_bOverrideDuration && g_pCurrentTextMessage)
{
if (g_pCurrentTextMessage->effect == 2 && g_pCurrentTextMessage->pMessage)
{
Expand All @@ -499,27 +506,40 @@ void SubtitlePanel::StartSubtitle(CDictionary *Dict, float flStartTime)
int nLastWide;
wchar_t *LastP;
int nLastCharNum;

while(1)
{
nLastWide = nWide;
LastP = p;
nLastCharNum = nCharNum;

//Leave at least 2 chars, one for (*p) and another for '\0'
if (nCharNum + 2 >= _ARRAYSIZE(szBuf) - 1)
break;

//Make sure English words, numbers, punctuations, and certain additional characters don't break in half...
if((*p >= L'A' && *p <= L'Z') || (*p >= L'a' && *p <= L'z') || *p == L'Ç' || *p == L'ç' || *p == L'Ğ' || *p == L'ğ' || *p == L'İ' || *p == L'ı' || *p == L'Ö' || *p == L'ö' || *p == L'Ş' || *p == L'ş' || *p == L'Ü' || *p == L'ü' || *p == L'â' || *p == L'Â' || *p == L':' || *p == L'-' || *p == L'\'' || *p == L'"' || *p == L',' || *p == L'.' || *p == L'!' || *p == L'?' || *p == L';' || *p == '%' || (*p >= L'0' && *p <= L'9'))
if(IsNonBreakableCharacter(*p))
{
while((*p >= L'A' && *p <= L'Z') || (*p >= L'a' && *p <= L'z') || *p == L'Ç' || *p == L'ç' || *p == L'Ğ' || *p == L'ğ' || *p == L'İ' || *p == L'ı' || *p == L'Ö' || *p == L'ö' || *p == L'Ş' || *p == L'ş' || *p == L'Ü' || *p == L'ü' || *p == L'â' || *p == L'Â' || *p == L':' || *p == L'-' || *p == L'\'' || *p == L'"'|| *p == L',' || *p == L'.' || *p == L'!' || *p == L'?' || *p == L';' || *p == '%' || (*p >= L'0' && *p <= L'9'))
szBuf[nCharNum++] = *p++;
while (IsNonBreakableCharacter(*p))
{
//Leave at least 2 chars, one for (*p) and another for '\0'
if (nCharNum + 2 >= _ARRAYSIZE(szBuf) - 1)
break;

szBuf[nCharNum] = *p++;
nCharNum++;
}
szBuf[nCharNum] = L'\0';
}
else
{
szBuf[nCharNum++] = *p++;
szBuf[nCharNum] = L'\0';
}

surface()->GetTextSize(m_hTextFont, szBuf, nWide, nTall);

//It's out of range? go back to last position and make it a new line
//It's out of range? Go back to last position and make it a new line
if(nWide > iMaxTextWidth)
{
nWide = nLastWide;
Expand All @@ -530,7 +550,7 @@ void SubtitlePanel::StartSubtitle(CDictionary *Dict, float flStartTime)
}

//Force to be a new line
if (*p == L'\0' || *p == L'\n' || *p == L'\r')
if ((*p) == L'\0' || (*p) == L'\n' || (*p) == L'\r')
{
nAddedCharNum += nCharNum;
break;
Expand All @@ -544,10 +564,12 @@ void SubtitlePanel::StartSubtitle(CDictionary *Dict, float flStartTime)
//Calculate the StartTime
float flCalcStartTime = flPercentStart * flDuration;
float flRealStartTime;

if(m_flStartTimeScale <= 0)
flRealStartTime = flStartTime;
else
flRealStartTime = flStartTime + flCalcStartTime * m_flStartTimeScale;

//Shall we wait for the latest backlines played?
if(m_iWaitPlay)
flRealStartTime = max(flRealStartTime, flLatestStart);
Expand All @@ -556,15 +578,15 @@ void SubtitlePanel::StartSubtitle(CDictionary *Dict, float flStartTime)
float flCalcDuration = flDuration * flPercentDuration;
float flRealDuration;

//longer start time won't change the duration
//Longer start time won't change the duration
if(m_flStartTimeScale >= 1)
flRealDuration = flCalcDuration;
else//real duration = original starttime - real starttime + original duration
flRealDuration = max(flStartTime + flCalcStartTime - flRealStartTime, 0) + flCalcDuration;

AddLine(Dict, pStart, nCharNum, flRealStartTime, flRealDuration, nWide);
AddLine(pDict, pStart, nCharNum, flRealStartTime, flRealDuration, nWide);

//skip CRLF
//Skip CRLF
while (*p == L'\r' || *p == L'\n')
p++;

Expand Down
4 changes: 2 additions & 2 deletions Plugins/CaptionMod/SubtitlePanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ class SubtitlePanel : public vgui::EditablePanel
void VidInit(void);

public://Subtitle interface
void StartSubtitle(CDictionary *Dict, float flStartTime);
void StartNextSubtitle(CDictionary *Dict);
void StartSubtitle(CDictionary * pDict, float flDurationTime, float flStartTime);
void StartNextSubtitle(CDictionary *pDict);
void AddLine(CDictionary *Dict, wchar_t *wszSentence, int nLength, float flStartTime, float flDuration, int nTextLength);
void StartLine(CSubLine *Line);
void ClearSubtitle(void);
Expand Down
4 changes: 2 additions & 2 deletions Plugins/CaptionMod/Viewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -928,10 +928,10 @@ void CViewport::Init(void)
m_HudMenu.Init();
}

void CViewport::StartSubtitle(CDictionary *dict)
void CViewport::StartSubtitle(CDictionary *dict, float flDurationTime)
{
if (cap_enabled && cap_enabled->value) {
m_pSubtitlePanel->StartSubtitle(dict, g_pViewPort->GetSystemTime());
m_pSubtitlePanel->StartSubtitle(dict, flDurationTime, g_pViewPort->GetSystemTime());
}
}

Expand Down
2 changes: 1 addition & 1 deletion Plugins/CaptionMod/Viewport.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class CViewport : public vgui::Panel
void LinkDictionary(void);

//Subtitle Interface
void StartSubtitle(CDictionary *dict);
void StartSubtitle(CDictionary *dict, float flDurationTime);
void StartNextSubtitle(CDictionary *dict);

//Dictionary Hashtable
Expand Down
Loading

0 comments on commit bcaf917

Please sign in to comment.