diff --git a/FCData/scripts/MenuScreens/CutScenePlayer.lua b/FCData/scripts/MenuScreens/CutScenePlayer.lua new file mode 100644 index 0000000..35a91ac --- /dev/null +++ b/FCData/scripts/MenuScreens/CutScenePlayer.lua @@ -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 + diff --git a/Sources/CryGame C++/Solution1/CryGame/Game.h b/Sources/CryGame C++/Solution1/CryGame/Game.h index 01f366a..a14a365 100644 --- a/Sources/CryGame C++/Solution1/CryGame/Game.h +++ b/Sources/CryGame C++/Solution1/CryGame/Game.h @@ -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; } diff --git a/Sources/CryGame C++/Solution1/CryGame/ScriptObjectGame.cpp b/Sources/CryGame C++/Solution1/CryGame/ScriptObjectGame.cpp index 4d9d381..f662482 100644 --- a/Sources/CryGame C++/Solution1/CryGame/ScriptObjectGame.cpp +++ b/Sources/CryGame C++/Solution1/CryGame/ScriptObjectGame.cpp @@ -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); } @@ -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) diff --git a/Sources/CryGame C++/Solution1/CryGame/ScriptObjectGame.h b/Sources/CryGame C++/Solution1/CryGame/ScriptObjectGame.h index c710cbf..627fe8e 100644 --- a/Sources/CryGame C++/Solution1/CryGame/ScriptObjectGame.h +++ b/Sources/CryGame C++/Solution1/CryGame/ScriptObjectGame.h @@ -208,6 +208,8 @@ public _ScriptableEx int LoadMOD(IFunctionHandler * pH); int GetCurrentModName(IFunctionHandler * pH); + int IsStopVideoRequested(IFunctionHandler* pH); + // Controller haptics int CreateHapticsEffectFlat(IFunctionHandler* pH); int CreateHapticsEffectCustom(IFunctionHandler* pH); diff --git a/Sources/CryGame C++/Solution1/CryGame/VRManager.cpp b/Sources/CryGame C++/Solution1/CryGame/VRManager.cpp index f534eb0..d1c3842 100644 --- a/Sources/CryGame C++/Solution1/CryGame/VRManager.cpp +++ b/Sources/CryGame C++/Solution1/CryGame/VRManager.cpp @@ -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); @@ -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); } @@ -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))) @@ -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; } } diff --git a/Sources/CryGame C++/Solution1/CryGame/VRManager.h b/Sources/CryGame C++/Solution1/CryGame/VRManager.h index b9b007e..d3b7902 100644 --- a/Sources/CryGame C++/Solution1/CryGame/VRManager.h +++ b/Sources/CryGame C++/Solution1/CryGame/VRManager.h @@ -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; diff --git a/Sources/CryGame C++/Solution1/CryGame/XClient.cpp b/Sources/CryGame C++/Solution1/CryGame/XClient.cpp index 0a51656..65c29d5 100644 --- a/Sources/CryGame C++/Solution1/CryGame/XClient.cpp +++ b/Sources/CryGame C++/Solution1/CryGame/XClient.cpp @@ -44,6 +44,7 @@ #include "StreamData.h" // CStreamData_WorldPos #include // STL map<> #include "Game.h" +#include "UISystem.h" #include "VRManager.h" ////////////////////////////////////////////////////////////////////// @@ -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) diff --git a/Sources/CryGame C++/Solution1/CryGame/XClient.h b/Sources/CryGame C++/Solution1/CryGame/XClient.h index 8c95b22..464f064 100644 --- a/Sources/CryGame C++/Solution1/CryGame/XClient.h +++ b/Sources/CryGame C++/Solution1/CryGame/XClient.h @@ -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)