From 281116434735065d3800b82fb4798b450abe2f9e Mon Sep 17 00:00:00 2001 From: hzqst <113660872@qq.com> Date: Sat, 30 Nov 2024 17:05:01 +0800 Subject: [PATCH] Add extra holdtime --- Plugins/CaptionMod/GameUI.cpp | 71 ++-------------------------- Plugins/CaptionMod/SubtitlePanel.cpp | 19 ++++++-- Plugins/CaptionMod/SubtitlePanel.h | 2 +- Plugins/CaptionMod/exportfuncs.cpp | 2 + 4 files changed, 23 insertions(+), 71 deletions(-) diff --git a/Plugins/CaptionMod/GameUI.cpp b/Plugins/CaptionMod/GameUI.cpp index fb4f539d..cfd945da 100644 --- a/Plugins/CaptionMod/GameUI.cpp +++ b/Plugins/CaptionMod/GameUI.cpp @@ -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"); } @@ -59,6 +60,7 @@ class COptionsSubAudioAdvancedDlg : public vgui::PropertyPage m_pHoldTimeEntry->ApplyChanges(); m_pHoldTimeScaleEntry->ApplyChanges(); m_pStartTimeScaleEntry->ApplyChanges(); + m_pExtraHoldTimeEntry->ApplyChanges(); } void OnApplyChanges() override @@ -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 @@ -108,6 +111,7 @@ class COptionsSubAudioAdvancedDlg : public vgui::PropertyPage CCvarTextEntry *m_pHoldTimeEntry; CCvarTextEntry *m_pHoldTimeScaleEntry; CCvarTextEntry *m_pStartTimeScaleEntry; + CCvarTextEntry* m_pExtraHoldTimeEntry; }; void COptionsSubAudioAdvancedDlg::OnDataChanged() @@ -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 } }; diff --git a/Plugins/CaptionMod/SubtitlePanel.cpp b/Plugins/CaptionMod/SubtitlePanel.cpp index b7f925ef..9d9dedf3 100644 --- a/Plugins/CaptionMod/SubtitlePanel.cpp +++ b/Plugins/CaptionMod/SubtitlePanel.cpp @@ -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") @@ -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; @@ -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) @@ -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 @@ -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; @@ -593,7 +600,7 @@ 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') @@ -601,6 +608,12 @@ void SubtitlePanel::StartSubtitle(CDictionary * pDict, float flDurationTime, flo 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) diff --git a/Plugins/CaptionMod/SubtitlePanel.h b/Plugins/CaptionMod/SubtitlePanel.h index 06fd364e..f1462f8e 100644 --- a/Plugins/CaptionMod/SubtitlePanel.h +++ b/Plugins/CaptionMod/SubtitlePanel.h @@ -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 diff --git a/Plugins/CaptionMod/exportfuncs.cpp b/Plugins/CaptionMod/exportfuncs.cpp index 3342359f..fd511cbd 100644 --- a/Plugins/CaptionMod/exportfuncs.cpp +++ b/Plugins/CaptionMod/exportfuncs.cpp @@ -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() { @@ -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)