From ffe697b6e4b9a6c6efd18444323cfccc20079a59 Mon Sep 17 00:00:00 2001 From: AlmTech Date: Thu, 31 Oct 2019 20:33:32 +0100 Subject: [PATCH] Cinematic intro added --- .../engine/core/server/sv_player_init.lua | 2 +- gamemode/engine/core/sh_player_binds.lua | 9 ++-- gamemode/engine/derma/menus/menu_intro.lua | 49 +++++++++++++++++++ gamemode/engine/lib/client/cl_cinematic.lua | 42 +++++++++------- 4 files changed, 81 insertions(+), 21 deletions(-) create mode 100644 gamemode/engine/derma/menus/menu_intro.lua diff --git a/gamemode/engine/core/server/sv_player_init.lua b/gamemode/engine/core/server/sv_player_init.lua index c2f2206..b7291aa 100644 --- a/gamemode/engine/core/server/sv_player_init.lua +++ b/gamemode/engine/core/server/sv_player_init.lua @@ -25,7 +25,7 @@ end function GM:PlayerSpawn( ply ) - if( !ply.isloaded ) then + if( ply.isloaded ) then -- replace logic ( reversed ) ply:Spectate( OBS_MODE_FIXED ) Quantum.Net.OpenMenu( ply, "character", Quantum.Server.Char.GetPlayerChars( ply ) ) else diff --git a/gamemode/engine/core/sh_player_binds.lua b/gamemode/engine/core/sh_player_binds.lua index ef5354a..cd84f23 100644 --- a/gamemode/engine/core/sh_player_binds.lua +++ b/gamemode/engine/core/sh_player_binds.lua @@ -14,13 +14,16 @@ if SERVER then end, ["openCharMenu"] = function( pl ) Quantum.Net.OpenMenu( pl, "character", Quantum.Server.Char.GetPlayerChars_cl( pl ) ) + end, + ["introTest"] = function( pl ) + Quantum.Net.OpenMenu( pl, "intro", Quantum.Server.Char.GetPlayerChars_cl( pl ) ) end } function GM:KeyRelease( ply, key ) if( keyfuncs[key] ) then keyfuncs[key]( ply ) end end - function GM:ShowHelp( ply ) - keyfuncs["openCharMenu"]( ply ) - end + function GM:ShowHelp( ply ) keyfuncs["openCharMenu"]( ply ) end + function GM:ShowTeam( ply ) keyfuncs["introTest"]( ply ) end + end \ No newline at end of file diff --git a/gamemode/engine/derma/menus/menu_intro.lua b/gamemode/engine/derma/menus/menu_intro.lua new file mode 100644 index 0000000..7ae4c4a --- /dev/null +++ b/gamemode/engine/derma/menus/menu_intro.lua @@ -0,0 +1,49 @@ +-- __ _ _______ _ __ +-- / / /\ | | |__ __| | | \ \ +-- / / / \ | |_ __ ___ | | ___ ___| |__ \ \ +-- < < / /\ \ | | '_ ` _ \| |/ _ \/ __| '_ \ > > +-- \ \ / ____ \| | | | | | | | __/ (__| | | | / / +-- \_\ /_/ \_\_|_| |_| |_|_|\___|\___|_| |_| /_/ + +local intro = {} + +function intro.open( dt ) + local chars = dt.cont + local resScale = Quantum.Client.ResolutionScale + local sw, sh = ScrW(), ScrH() + local padding = 10 * resScale + local padding_s = 4 * resScale + + if( !f ) then + + Quantum.Client.IsInMenu = true -- hide the hud + + local f = vgui.Create( "DFrame" ) + f:SetSize( sw, sh ) + f:SetTitle( "Cinematic Intro Test" ) + f.Paint = function( self ) end + f:SetDraggable( false ) + f:MakePopup() + function f:OnClose() + Quantum.Client.IsInMenu = false + Quantum.Client.Cam.Stop() -- stop the cinematic + end + + local scene = { + pos1 = Vector(6879, 4135, 72), + pos2 = Vector(8760, 2740, 86), + ang1 = Angle(7, 122, 0), + ang2 = Angle(1, -104, 0) + } + local scene2 = { + pos1 = Vector( 8917, 2194, 83 ), + pos2 = Vector( 8312, 2265, 83 ), + ang1 = Angle( 2, -123, 0 ), + ang2 = Angle( 3, -41, 0 ) + } + + Quantum.Client.Cam.Start( {[1] = scene, [2] = scene2}, 80, {[1] = 10, [2] = 8}, false ) -- start the cinematic + end +end + +return intro \ No newline at end of file diff --git a/gamemode/engine/lib/client/cl_cinematic.lua b/gamemode/engine/lib/client/cl_cinematic.lua index fdaa105..9106d65 100644 --- a/gamemode/engine/lib/client/cl_cinematic.lua +++ b/gamemode/engine/lib/client/cl_cinematic.lua @@ -9,31 +9,43 @@ function Quantum.Client.Cam.InvertAngle( ang ) return Angle( -ang.x, ang.y, -ang.z ) end -- Flip the camera 180* relative to target +function Quantum.Client.Cam.Stop() + hook.Remove( "CalcView", "Quantum_Cinematic" ) + Quantum.Client.Cam.Temp.scene_index = nil -- remove the var becuase it is unneeded + Quantum.Debug( "Stopped cinematic." ) +end + function Quantum.Client.Cam.Start( scene, fov, velocity, loop ) local frac = 0 - local time = velocity || 10 -- speed of the camera ( how long till it reaches its finish point ) - local scene_index = 1 + local time -- speed of the camera ( how long till it reaches its finish point ) + Quantum.Client.Cam.Temp = {} + Quantum.Client.Cam.Temp.scene_index = 1 local view = {} -- calcview vector data - scene.pos2 = scene.pos2 || scene.pos1 -- if there is no finish pos then make it stay still at starting pos - scene.ang2 = scene.ang2 || scene.ang1 - hook.Remove( "CalcView", "Quantum_Cinematic" ) -- if a cinematic is already running; cancel it hook.Add( "CalcView", "Quantum_Cinematic", function( ply, pos, ang, fov ) - frac = math.Clamp( frac + FrameTime()/velocity, 0, 1 ) + time = velocity[Quantum.Client.Cam.Temp.scene_index] || 5 + frac = math.Clamp( frac + FrameTime()/time, 0, 1 ) if( frac <= 0 ) then return end - view.origin = LerpVector( frac, scene.pos1[scene_index], scene.pos2[scene_index] ), - view.angles = LerpAngle( frac, scene.ang1[scene_index], scene.ang2[scene_index] ), - view.fov = fov, + scene[Quantum.Client.Cam.Temp.scene_index].pos2 = scene[Quantum.Client.Cam.Temp.scene_index].pos2 || scene[Quantum.Client.Cam.Temp.scene_index].pos1 -- if there is no finish pos then make it stay still at starting pos + scene[Quantum.Client.Cam.Temp.scene_index].ang2 = scene[Quantum.Client.Cam.Temp.scene_index].ang2 || scene[Quantum.Client.Cam.Temp.scene_index].ang1 + + view.origin = LerpVector( frac, scene[Quantum.Client.Cam.Temp.scene_index].pos1, scene[Quantum.Client.Cam.Temp.scene_index].pos2 ) + view.angles = LerpAngle( frac, scene[Quantum.Client.Cam.Temp.scene_index].ang1, scene[Quantum.Client.Cam.Temp.scene_index].ang2 ) + view.fov = fov view.drawviewer = true - if( view.origin:IsEqualTol( scene.pos2[scene_index], 2 ) ) then - frac = 0 - scene_index = scene_index + 1 - if( scene_index > #scene.pos1 && loop ) then scene_index = 1 end -- if all scenes are finished, loop them if loop is enabled + if( view.origin:IsEqualTol( scene[Quantum.Client.Cam.Temp.scene_index].pos2, 1 ) ) then + if( Quantum.Client.Cam.Temp.scene_index + 1 <= #scene ) then + frac = 0 + Quantum.Client.Cam.Temp.scene_index = Quantum.Client.Cam.Temp.scene_index + 1 + end + if( Quantum.Client.Cam.Temp.scene_index > #scene ) then -- if all scenes are finished, loop them if loop is enabled + Quantum.Client.Cam.Temp.scene_index = 1 + end -- otherwise it will just stop at the end. end @@ -41,7 +53,3 @@ function Quantum.Client.Cam.Start( scene, fov, velocity, loop ) end) end -function Quantum.Client.Cam.Stop() - hook.Remove( "CalcView", "Quantum_Cinematic" ) - Quantum.Debug( "Stopped cinematic." ) -end \ No newline at end of file