Skip to content

Commit

Permalink
Add extra holdtime
Browse files Browse the repository at this point in the history
  • Loading branch information
hzqst committed Nov 30, 2024
1 parent b9494bd commit 2811164
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 71 deletions.
71 changes: 4 additions & 67 deletions Plugins/CaptionMod/GameUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class COptionsSubAudioAdvancedDlg : public vgui::PropertyPage
m_pHoldTimeEntry = new CCvarTextEntry(this, "HoldTimeEntry", "cap_subtitle_holdtime");
m_pHoldTimeScaleEntry = new CCvarTextEntry(this, "HoldTimeScaleEntry", "cap_subtitle_htimescale");
m_pStartTimeScaleEntry = new CCvarTextEntry(this, "StartTimeScaleEntry", "cap_subtitle_stimescale");
m_pExtraHoldTimeEntry = new CCvarTextEntry(this, "StartTimeScaleEntry", "cap_subtitle_extraholdtime");

LoadControlSettings("captionmod/OptionsSubAudioAdvancedDlg.res");
}
Expand All @@ -59,6 +60,7 @@ class COptionsSubAudioAdvancedDlg : public vgui::PropertyPage
m_pHoldTimeEntry->ApplyChanges();
m_pHoldTimeScaleEntry->ApplyChanges();
m_pStartTimeScaleEntry->ApplyChanges();
m_pExtraHoldTimeEntry->ApplyChanges();
}

void OnApplyChanges() override
Expand All @@ -77,6 +79,7 @@ class COptionsSubAudioAdvancedDlg : public vgui::PropertyPage
m_pHoldTimeEntry->Reset();
m_pHoldTimeScaleEntry->Reset();
m_pStartTimeScaleEntry->Reset();
m_pExtraHoldTimeEntry->Reset();
}

void OnCommand(const char *command) override
Expand Down Expand Up @@ -108,6 +111,7 @@ class COptionsSubAudioAdvancedDlg : public vgui::PropertyPage
CCvarTextEntry *m_pHoldTimeEntry;
CCvarTextEntry *m_pHoldTimeScaleEntry;
CCvarTextEntry *m_pStartTimeScaleEntry;
CCvarTextEntry* m_pExtraHoldTimeEntry;
};

void COptionsSubAudioAdvancedDlg::OnDataChanged()
Expand Down Expand Up @@ -308,74 +312,7 @@ class CVGUI2Extension_KeyValuesCallbacks : public IVGUI2Extension_KeyValuesCallb

void KeyValues_LoadFromFile(void*& pthis, IFileSystem*& pFileSystem, const char*& resourceName, const char*& pathId, const char *sourceModule, VGUI2Extension_CallbackContext* CallbackContext)
{
#if 0
if (CallbackContext->IsPost && !stricmp(resourceName, "resource/GameMenu.res"))
{
bool *pRealReturnValue = (bool*)CallbackContext->pRealReturnValue;

if ((*pRealReturnValue) == true)
{
KeyValues* pKeyValues = (KeyValues*)pthis;

auto name = pKeyValues->GetName();

KeyValues* SectionQuit = NULL;
for (auto p = pKeyValues->GetFirstSubKey(); p; p = p->GetNextKey())
{
auto command = p->GetString("command");
if (!strcmp(command, "Quit"))
{
SectionQuit = p;
}
}
if (SectionQuit)
{
auto NameSectionQuit = SectionQuit->GetName();
int iNameSectionQuit = atoi(NameSectionQuit);
if (iNameSectionQuit > 0)
{
/*

//Update this:
"8"
{
"label" "#GameUI_GameMenu_Quit"
"command" "Quit"
}

//To this:
"8"
{
"label" "#GameUI_GameMenu_TestButton"
"command" "TestButton"
}
"9"
{
"label" "#GameUI_GameMenu_Quit"
"command" "Quit"
}
*/

char szNewNameSectionQuit[32];
snprintf(szNewNameSectionQuit, sizeof(szNewNameSectionQuit), "%d", iNameSectionQuit + 1);

SectionQuit->SetName(szNewNameSectionQuit);

char szNewNameTestButton[32];
snprintf(szNewNameTestButton, sizeof(szNewNameTestButton), "%d", iNameSectionQuit);

auto SectionTestButton = new KeyValues(szNewNameTestButton);

SectionTestButton->SetString("label", "#GameUI_GameMenu_TestButton");
SectionTestButton->SetString("command", "TestCommand");

pKeyValues->AddSubKeyBefore(SectionTestButton, SectionQuit);

}
}
}
}
#endif
}
};

Expand Down
19 changes: 16 additions & 3 deletions Plugins/CaptionMod/SubtitlePanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extern cvar_t* cap_subtitle_fadeout;
extern cvar_t* cap_subtitle_holdtime;
extern cvar_t* cap_subtitle_stimescale;
extern cvar_t* cap_subtitle_htimescale;

extern cvar_t* cap_subtitle_extraholdtime;
using namespace vgui;

SubtitlePanel::SubtitlePanel(Panel *parent) : EditablePanel(parent, "Subtitle")
Expand Down Expand Up @@ -385,7 +385,7 @@ void SubtitlePanel::StartLine(CSubLine *Line)
StartNextSubtitle(Line->m_Dict);
}

void SubtitlePanel::AddLine(CDictionary *Dict, wchar_t *wszSentence, int nLength, float flStartTime, float flDuration, int nTextWide)
CSubLine* SubtitlePanel::AddLine(CDictionary *Dict, wchar_t *wszSentence, int nLength, float flStartTime, float flDuration, int nTextWide)
{
CSubLine *Line = new CSubLine(this, Dict);
m_BackLines[m_BackLines.AddToTail()] = Line;
Expand All @@ -408,6 +408,8 @@ void SubtitlePanel::AddLine(CDictionary *Dict, wchar_t *wszSentence, int nLength
Line->m_YPos = Line->CalcYPos();
Line->m_FadeOut = cap_subtitle_fadeout->value;
Line->m_TextAlign = Dict->m_iTextAlign ? Dict->m_iTextAlign : m_iTextAlign;

return Line;
}

static bool IsNonBreakableCharacter(wchar_t ch)
Expand Down Expand Up @@ -506,6 +508,8 @@ void SubtitlePanel::StartSubtitle(CDictionary * pDict, float flDurationTime, flo

p = pStart;

CSubLine* pAddedLine = NULL;

while(*pStart)
{
//fetch one line from this sentence
Expand Down Expand Up @@ -566,6 +570,9 @@ void SubtitlePanel::StartSubtitle(CDictionary * pDict, float flDurationTime, flo
}
}

if (nCharNum == 0)
break;

//Calculate the duration and start time
float flPercentDuration = (float)nCharNum / nTotalCharNum;
float flPercentStart = (float)(nAddedCharNum - nCharNum) / nTotalCharNum;
Expand Down Expand Up @@ -593,14 +600,20 @@ void SubtitlePanel::StartSubtitle(CDictionary * pDict, float flDurationTime, flo
else//real duration = original starttime - real starttime + original duration
flRealDuration = max(flStartTime + flCalcStartTime - flRealStartTime, 0) + flCalcDuration;

AddLine(pDict, pStart, nCharNum, flRealStartTime, flRealDuration, nWide);
pAddedLine = AddLine(pDict, pStart, nCharNum, flRealStartTime, flRealDuration, nWide);

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

pStart = p;
}

if (pAddedLine && cap_subtitle_extraholdtime->value > 0)
{
//Add extra holdtime for the last line added
pAddedLine->m_Duration += cap_subtitle_extraholdtime->value;
}
}

void SubtitlePanel::ClearSubtitle(void)
Expand Down
2 changes: 1 addition & 1 deletion Plugins/CaptionMod/SubtitlePanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class SubtitlePanel : public vgui::EditablePanel
public://Subtitle interface
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);
CSubLine* AddLine(CDictionary *Dict, wchar_t *wszSentence, int nLength, float flStartTime, float flDuration, int nTextLength);
void StartLine(CSubLine *Line);
void ClearSubtitle(void);
#if 0
Expand Down
2 changes: 2 additions & 0 deletions Plugins/CaptionMod/exportfuncs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ cvar_t* cap_subtitle_fadeout = NULL;
cvar_t* cap_subtitle_holdtime = NULL;
cvar_t* cap_subtitle_stimescale = NULL;
cvar_t* cap_subtitle_htimescale = NULL;
cvar_t* cap_subtitle_extraholdtime = NULL;

void Cap_RegisterSubtitleCvars()
{
Expand All @@ -56,6 +57,7 @@ void Cap_RegisterSubtitleCvars()
cap_subtitle_holdtime = gEngfuncs.pfnRegisterVariable("cap_subtitle_holdtime", "10.0", FCVAR_CLIENTDLL | FCVAR_ARCHIVE);
cap_subtitle_stimescale = gEngfuncs.pfnRegisterVariable("cap_subtitle_stimescale", "1.0", FCVAR_CLIENTDLL | FCVAR_ARCHIVE);
cap_subtitle_htimescale = gEngfuncs.pfnRegisterVariable("cap_subtitle_htimescale", "1.0", FCVAR_CLIENTDLL | FCVAR_ARCHIVE);
cap_subtitle_extraholdtime = gEngfuncs.pfnRegisterVariable("cap_subtitle_extraholdtime", "0", FCVAR_CLIENTDLL | FCVAR_ARCHIVE);
}

cl_entity_t* EngineGetViewEntity(void)
Expand Down

0 comments on commit 2811164

Please sign in to comment.