Skip to content

Commit

Permalink
Enable skipping videos by long pressing any button on the overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
fholger committed Aug 20, 2023
1 parent e0cf1f6 commit 2fb01bd
Show file tree
Hide file tree
Showing 8 changed files with 228 additions and 0 deletions.
184 changes: 184 additions & 0 deletions FCData/scripts/MenuScreens/CutScenePlayer.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
UI.PageCutScenePlayer=
{
GUI=
{
CutScene =
{
classname = "videopanel",

left = 0, top = 0,
width = 800, height = 600,

color = "0 0 0 255",

zorder = 1000,

bordersize = 0,
tabstop = 1,

looping = 0,
keepaspect = 1,

OnFinished = function(Sender)
UI.PageCutScenePlayer:Finished();
end
},

OnUpdate = function(Sender)

local bPlaying = UI.PageCutScenePlayer.GUI.CutScene:IsPlaying();

if ((not bPlaying) or (tonumber(bPlaying) == 0)) then
UI:StopCutScene();

return;
end

if (UI.PageCutScenePlayer.bCanSkip and tonumber(UI.PageCutScenePlayer.bCanSkip) ~= 0) then
if ((_time - UI.PageCutScenePlayer.fStartTime) >= UI.fCanSkipTime) then
local szKeyName = Input:GetXKeyPressedName();
local stopVideoRequested = Game:IsStopVideoRequested();

if ((szKeyName == "esc") or (szKeyName == "spacebar") or (szKeyName == "f7") or stopVideoRequested) then
UI:StopCutScene();
end
end
end

if (UI.PageCutScenePlayer.bFinished) then
UI:DeactivateScreen("CutScenePlayer");
end
end,

OnActivate= function(Sender)
UI.PageCutScenePlayer.bFinished = nil;

if (UI.PageCutScenePlayer.szCutSceneName) then
local szLocalizedCutSceneFolder = gsub(UI.szLocalizedCutSceneFolder, "&language&", getglobal("g_language"));

UI:HideMouseCursor();
UI:HideBackground();

local szCutScene = UI:GetCutSceneDrive()..szLocalizedCutSceneFolder..UI.PageCutScenePlayer.szCutSceneName;

-- check the localized version
if (not UI.PageCutScenePlayer.GUI.CutScene:LoadVideo(szCutScene, 1)) then
-- did not load, check the non localized version
szCutScene = UI:GetCutSceneDrive()..UI.szCutSceneFolder..UI.PageCutScenePlayer.szCutSceneName;

if (not UI.PageCutScenePlayer.GUI.CutScene:LoadVideo(szCutScene, 1)) then
-- non-localized version not found on disk, try cd
if (UI:GetCutSceneDrive() == "./") then

local szCDPath = Game:GetCDPath();

if (szCDPath) then
szCutScene = strsub(szCDPath, 1, 2).."/"..UI.szCutSceneFolder..UI.PageCutScenePlayer.szCutSceneName;

if (not UI.PageCutScenePlayer.GUI.CutScene:LoadVideo(szCutScene, 1)) then
-- there is no way to find this cutscene
UI.PageCutScenePlayer:Finished();
end
else
-- there is no way to find this cutscene
UI.PageCutScenePlayer:Finished();
end
else
-- there is no way to find this cutscene
UI.PageCutScenePlayer:Finished();
end
end
end

UI.PageCutScenePlayer.GUI.CutScene:SetVolume(tonumber(getglobal("s_SFXVolume")));

if (getglobal("s_SoundEnable") and tonumber(getglobal("s_SoundEnable")) ~= 0) then
UI.PageCutScenePlayer.GUI.CutScene:EnableAudio(1);
else
UI.PageCutScenePlayer.GUI.CutScene:SetVolume(0);
end

UI.PageCutScenePlayer.GUI.CutScene:Play();
UI.PageCutScenePlayer.fStartTime = _time;
end

UI.PageCutScenePlayer.szCutSceneName = nil;
UI:StopMusic();
end,

OnDeactivate = function(Sender)
local bPlaying = UI.PageCutScenePlayer.GUI.CutScene:IsPlaying();

UI.PageCutScenePlayer.GUI.CutScene:ReleaseVideo();

if (bPlaying) then
UI.PageCutScenePlayer:Finished();
end

UI.bInGameOverride = nil;

if (UI.PageCutScenePlayer.szGotoPage) then
GotoPage(UI.PageCutScenePlayer.szGotoPage, UI.PageCutScenePlayer.bGotoPageShowBack);
end
UI:SetFocus(Sender.CutScene);
UI:PlayMusic();
end
},
};

function UI.PageCutScenePlayer:Finished()

UI.PageCutScenePlayer.bFinished = 1;

Game:HideMenu();

UI.bInGameOverride = nil;
UI.PageCutScenePlayer.szCutSceneName = nil;

UI:DeactivateScreen("CutScenePlayer");

if (UI.PageCutScenePlayer.szMessage and strlen(UI.PageCutScenePlayer.szMessage)) then
Game:SendMessage(UI.PageCutScenePlayer.szMessage);
elseif (UI.PageCutScenePlayer.pfnFunction) then
UI.PageCutScenePlayer.pfnFunction();
end
end

UI:CreateScreenFromTable("CutScenePlayer", UI.PageCutScenePlayer.GUI);

function UI:PlayCutScene(szCutSceneName, szMessage, szGotoPage, bGotoPageShowBack)
UI:PlayCutSceneEx(szCutSceneName, szMessage, szGotoPage, bGotoPageShowBack, 1);
end

function UI:PlayCutSceneEx(szCutSceneName, szMessage, szGotoPage, bGotoPageShowBack, bCanSkip)

if (UI.MusicId ~= nil) then
Sound:StopSound(UI.MusicId);
end

UI.bInGameOverride = 1; -- don't use the current ingame menu

Game:ShowMenu();

UI.PageCutScenePlayer.szCutSceneName = szCutSceneName;
UI.PageCutScenePlayer.szGotoPage = szGotoPage;
UI.PageCutScenePlayer.bGotoPageShowBack = bGotoPageShowBack;
UI.PageCutScenePlayer.bCanSkip = bCanSkip;

if (type(szMessage) == "function") then
UI.PageCutScenePlayer.pfnFunction = szMessage;
UI.PageCutScenePlayer.szMessage = nil;
else
UI.PageCutScenePlayer.szMessage = szMessage;
UI.PageCutScenePlayer.pfnFunction = nil;
end

UI:DeactivateAllScreens();
UI:ActivateScreen("CutScenePlayer");
end

function UI:StopCutScene()
Input:ResetKeyState();
UI:DeactivateScreen("CutScenePlayer");
end

5 changes: 5 additions & 0 deletions Sources/CryGame C++/Solution1/CryGame/Game.h
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,11 @@ class CXGame :

bool IsCutSceneActive() const { return m_pMovieUser && m_pMovieUser->IsCutSceneActive(); }

void RequestStopVideo(bool enabled) { m_requestStopVideo = enabled; }
bool IsStopVideoRequested() const { return m_requestStopVideo; }

bool m_requestStopVideo = false;


ActionsEnumMap& GetActionsEnumMap() { return m_mapActionsEnum; }

Expand Down
7 changes: 7 additions & 0 deletions Sources/CryGame C++/Solution1/CryGame/ScriptObjectGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ void CScriptObjectGame::InitializeTemplate(IScriptSystem *pSS)
REG_FUNC(CScriptObjectGame,AddCommand);
REG_FUNC(CScriptObjectGame,EnableQuicksave);
REG_FUNC(CScriptObjectGame,GetServerIP);
REG_FUNC(CScriptObjectGame,IsStopVideoRequested);
REG_FUNC(CScriptObjectGame, CreateHapticsEffectFlat);
REG_FUNC(CScriptObjectGame, CreateHapticsEffectCustom);
}
Expand Down Expand Up @@ -3848,6 +3849,12 @@ int CScriptObjectGame::GetCurrentModName(IFunctionHandler * pH)
return pH->EndFunction(pMods->GetCurrentMod());
}

int CScriptObjectGame::IsStopVideoRequested(IFunctionHandler* pH)
{
CHECK_PARAMETERS(0);
return pH->EndFunction(m_pGame->IsStopVideoRequested());
}

int CScriptObjectGame::CreateHapticsEffectFlat(IFunctionHandler* pH)
{
if (pH->GetParamCount() < 3)
Expand Down
2 changes: 2 additions & 0 deletions Sources/CryGame C++/Solution1/CryGame/ScriptObjectGame.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ public _ScriptableEx<CScriptObjectGame>
int LoadMOD(IFunctionHandler * pH);
int GetCurrentModName(IFunctionHandler * pH);

int IsStopVideoRequested(IFunctionHandler* pH);

// Controller haptics
int CreateHapticsEffectFlat(IFunctionHandler* pH);
int CreateHapticsEffectCustom(IFunctionHandler* pH);
Expand Down
21 changes: 21 additions & 0 deletions Sources/CryGame C++/Solution1/CryGame/VRManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ void VRManager::ProcessInput()
if (!m_wasInMenu)
{
m_wasInMenu = true;
m_buttonPressed = false;
vr::VROverlay()->SetOverlayInputMethod(m_hudOverlay, vr::VROverlayInputMethod_Mouse);
vr::VROverlay()->SetOverlayFlag(m_hudOverlay, vr::VROverlayFlags_MakeOverlaysInteractiveIfVisible, true);
vr::VROverlay()->SetOverlayFlag(m_hudOverlay, vr::VROverlayFlags_HideLaserIntersection, true);
Expand All @@ -630,6 +631,7 @@ void VRManager::ProcessInput()
if (m_wasInMenu)
{
m_wasInMenu = false;
m_buttonPressed = false;
vr::VROverlay()->SetOverlayInputMethod(m_hudOverlay, vr::VROverlayInputMethod_None);
vr::VROverlay()->SetOverlayFlag(m_hudOverlay, vr::VROverlayFlags_MakeOverlaysInteractiveIfVisible, false);
}
Expand All @@ -653,6 +655,7 @@ void VRManager::ProcessMenuInput()
{
m_mousePressed = false;
m_mouseReleased = false;
m_pGame->RequestStopVideo(false);

vr::VREvent_t event;
while (vr::VROverlay()->PollNextOverlayEvent(m_hudOverlay, &event, sizeof(vr::VREvent_t)))
Expand All @@ -667,12 +670,30 @@ void VRManager::ProcessMenuInput()
{
if (event.data.mouse.button == vr::VRMouseButton_Left)
m_mousePressed = true;
m_buttonPressed = true;
m_lastTimeButtonPressed = m_pGame->GetSystem()->GetITimer()->GetAsyncCurTime();
}
if (event.eventType == vr::VREvent_MouseButtonUp)
{
if (event.data.mouse.button == vr::VRMouseButton_Left)
m_mouseReleased = true;
m_buttonPressed = false;
}
if (event.eventType == vr::VREvent_ButtonPress)
{
m_buttonPressed = true;
m_lastTimeButtonPressed = m_pGame->GetSystem()->GetITimer()->GetAsyncCurTime();
}
if (event.eventType == vr::VREvent_ButtonUnpress)
{
m_buttonPressed = false;
}
}

if (m_buttonPressed && m_pGame->GetSystem()->GetITimer()->GetAsyncCurTime() - m_lastTimeButtonPressed >= 0.5f)
{
m_pGame->RequestStopVideo(true);
m_buttonPressed = false;
}
}

Expand Down
2 changes: 2 additions & 0 deletions Sources/CryGame C++/Solution1/CryGame/VRManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ class VRManager
bool m_wasInMenu = false;
bool m_mousePressed = false;
bool m_mouseReleased = false;
float m_lastTimeButtonPressed = 0;
bool m_buttonPressed = false;

Matrix34 m_fixedHudTransform;

Expand Down
6 changes: 6 additions & 0 deletions Sources/CryGame C++/Solution1/CryGame/XClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include "StreamData.h" // CStreamData_WorldPos
#include <map> // STL map<>
#include "Game.h"
#include "UISystem.h"
#include "VRManager.h"

//////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -1835,6 +1836,11 @@ void CXClient::StopCutScene(float fValue, XActivationEvent ae)
m_pGame->StopCurrentCutscene();
}

void CXClient::StopVideo(float fValue, XActivationEvent ae)
{
m_pGame->GetUISystem()->StopAllVideo();
}

//////////////////////////////////////////////////////////////////////
// move mode double click
void CXClient::TriggerMoveMode2(float fValue,XActivationEvent ae)
Expand Down
1 change: 1 addition & 0 deletions Sources/CryGame C++/Solution1/CryGame/XClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ public IEntitySystemSink

void NoOp(float fValue, XActivationEvent ae) {}
void StopCutScene(float fValue, XActivationEvent ae);
void StopVideo(float fValue, XActivationEvent ae);

BEGIN_INPUTACTIONMAP()
REGISTER_INPUTACTIONMAP(ACTION_MOVE_LEFT, TriggerMoveLeft)
Expand Down

0 comments on commit 2fb01bd

Please sign in to comment.