From 9a09d1d678c82b49041407503c69ed701cc44d38 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Sun, 24 May 2020 17:43:24 +0200 Subject: [PATCH] Dialogue menu stuff --- entities/entities/q_npc/init.lua | 9 ++-- gamemode/cl_init.lua | 1 + .../engine/derma/lib/cl_menu_dialogueBox.lua | 5 +- gamemode/engine/derma/menus/menu_dialogue.lua | 54 +++++++++++++++++++ gamemode/engine/lib/client/cl_cinematic.lua | 7 +-- gamemode/engine/lib/sh_dialogue.lua | 11 ++++ gamemode/engine/lib/sh_node.lua | 3 +- gamemode/init.lua | 2 + gamemode/settings/sh_nodes.lua | 1 + 9 files changed, 84 insertions(+), 9 deletions(-) diff --git a/entities/entities/q_npc/init.lua b/entities/entities/q_npc/init.lua index 1ba8f72..2ca365c 100644 --- a/entities/entities/q_npc/init.lua +++ b/entities/entities/q_npc/init.lua @@ -27,11 +27,14 @@ function ENT:Initialize() self:DropToFloor() end -function ENT:Use() +function ENT:Use( activator, caller ) if( self.node != nil ) then - -- open up dialogue menu + if( self.node.dialogueID ) then + -- open up dialogue menu + Quantum.Net.OpenMenu(activator, "dialogue", { ent = self, dialogueID = self.node.dialogueID }) + end if( #self.node.voiceLines > 0 ) then - self:EmitSound(self.node.voiceLines[math.random(1, #self.node.voiceLines)]) + self:EmitSound(self.node.voiceLines[math.random(1, #self.node.voiceLines)]) -- emit a voiceline end end end diff --git a/gamemode/cl_init.lua b/gamemode/cl_init.lua index 519b152..6974333 100644 --- a/gamemode/cl_init.lua +++ b/gamemode/cl_init.lua @@ -53,6 +53,7 @@ if CLIENT then include( "settings/sh_recipes.lua" ) include( "settings/sh_nodes.lua" ) include( "settings/sh_properties.lua" ) + include( "settings/sh_dialogues.lua" ) end local function loadPlugins() diff --git a/gamemode/engine/derma/lib/cl_menu_dialogueBox.lua b/gamemode/engine/derma/lib/cl_menu_dialogueBox.lua index cfbc4a1..39c3d5a 100644 --- a/gamemode/engine/derma/lib/cl_menu_dialogueBox.lua +++ b/gamemode/engine/derma/lib/cl_menu_dialogueBox.lua @@ -14,7 +14,8 @@ local padding_s = 4 * scale local theme = Quantum.Client.Menu.GetAPI( "theme" ) -function log.createinfobox( logdata, parent ) +function log.createinfobox( logdata, parent, cinematic ) + cinematic = cinematic || true local fw, fh = parent:GetSize() local logtitle = logdata[1].title local logtext = logdata[1].text @@ -74,7 +75,7 @@ function log.createinfobox( logdata, parent ) text:SetPos( scroll.w/2 - text.w/2, 0 ) text.Think = function( self ) - if( Quantum.Client.Cam.Temp != nil ) then + if( Quantum.Client.Cam.Temp != nil && cinematic ) then if( logdata[Quantum.Client.Cam.Temp.scene_index] != nil ) then self:SetText( logdata[Quantum.Client.Cam.Temp.scene_index].text ) end diff --git a/gamemode/engine/derma/menus/menu_dialogue.lua b/gamemode/engine/derma/menus/menu_dialogue.lua index f615213..75584a5 100644 --- a/gamemode/engine/derma/menus/menu_dialogue.lua +++ b/gamemode/engine/derma/menus/menu_dialogue.lua @@ -9,14 +9,68 @@ local menu = {} local snm = Quantum.Client.Menu.GetAPI( "net" ) local theme = Quantum.Client.Menu.GetAPI( "theme" ) +local fade = Quantum.Client.Menu.GetAPI( "fade" ) local resScale = Quantum.Client.ResolutionScale local sw, sh = ScrW(), ScrH() local padding = 10 * resScale local padding_s = 4 * resScale +local scenes = { + [1] = { + fov = 60, + velocity = 1, + } +} + function menu.open( dt ) + if( dt.cont.dialogueID == nil ) then return end + if( !f ) then + Quantum.Client.IsInMenu = true -- hide the hud + + -- make the cinematic start from the players pov + scenes[1].pos1 = LocalPlayer():GetBonePosition(LocalPlayer():LookupBone("ValveBiped.Bip01_Head1")) || Vector() + scenes[1].ang1 = LocalPlayer():GetAngles() + + local npc = dt.cont.ent + scenes[1].ang2 = Quantum.Client.Cam.InvertAngle(npc:GetAngles()) || Angle() -- make the camera look at the NPC + scenes[1].pos2 = npc:GetBonePosition(npc:LookupBone("ValveBiped.Bip01_Head1")) + scenes[1].ang2:Forward() * -28 || Vector() -- Move the camera forward + + Quantum.Client.Cam.Start( scenes, true, false ) + + local dialogue = Quantum.Dialogue.Get( dt.cont.dialogueID ) + + local f = vgui.Create( "DFrame" ) + f:SetSize( sw, sh ) + f:SetTitle( "" ) + f:ShowCloseButton( false ) + f.Paint = function( self, w, h ) + surface.SetDrawColor( Color( 20, 20, 20, 255 ) ) + local height = 90 * resScale + surface.DrawRect( 0, 0, w, height ) + surface.DrawRect( 0, h - height, w, height ) + end + f:SetDraggable( false ) + f:MakePopup() + function f:OnClose() + Quantum.Client.IsInMenu = false + Quantum.Client.Cam.Stop() -- stop the cinematic + end + + local keycodesClose = { + [KEY_ESCAPE] = true, + [KEY_TAB] = true + } + + function f:OnKeyCodeReleased( keyCode ) + if( keycodesClose[keyCode] ) then + self:Close() + end + end + f.w, f.h = f:GetSize() + + local q = vgui.Create( "DLabel", f ) end end diff --git a/gamemode/engine/lib/client/cl_cinematic.lua b/gamemode/engine/lib/client/cl_cinematic.lua index e617160..0f24f65 100644 --- a/gamemode/engine/lib/client/cl_cinematic.lua +++ b/gamemode/engine/lib/client/cl_cinematic.lua @@ -7,14 +7,15 @@ Quantum.Client.Cam = {} -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.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 = nil -- remove the var becuase it is unneeded end -function Quantum.Client.Cam.Start( scene, loop ) +function Quantum.Client.Cam.Start( scene, loop, drawviewer ) + drawviewer = drawviewer || false if( scene == nil ) then Quantum.Error( "Scene does not exist! Aborting..." ) return @@ -43,7 +44,7 @@ function Quantum.Client.Cam.Start( scene, loop ) 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 + view.drawviewer = drawviewer if( view.origin:IsEqualTol( scene[Quantum.Client.Cam.Temp.scene_index].pos2, 1 ) ) then if( Quantum.Client.Cam.Temp.scene_index + 1 <= #scene ) then diff --git a/gamemode/engine/lib/sh_dialogue.lua b/gamemode/engine/lib/sh_dialogue.lua index 25498e9..bf44c43 100644 --- a/gamemode/engine/lib/sh_dialogue.lua +++ b/gamemode/engine/lib/sh_dialogue.lua @@ -44,3 +44,14 @@ function Quantum.Dialogue.AddResponse( id, qid, tbl, order ) }) end end + + +function Quantum.Dialogue.Get( id ) + if CLIENT then + Quantum.Debug("Dialogue fetch:") + PrintTable(Quantum.DialogueTbl) + return Quantum.DialogueTbl[id] + else + Quantum.Error("Can not fetch dialogue table from serverside!") + end +end \ No newline at end of file diff --git a/gamemode/engine/lib/sh_node.lua b/gamemode/engine/lib/sh_node.lua index 373856e..314bef0 100644 --- a/gamemode/engine/lib/sh_node.lua +++ b/gamemode/engine/lib/sh_node.lua @@ -25,7 +25,8 @@ function Quantum.Node.Create( nodeid, tbl ) health = tbl.health || Quantum.DefaultNodeHealth, respawn = tbl.respawn || Quantum.DefaultNodeRespawnTimer, voiceLines = tbl.voiceLines || {}, - damageSounds = tbl.damageSounds || {} + damageSounds = tbl.damageSounds || {}, + dialogueID = tbl.dialogueID } node.id = nodeid diff --git a/gamemode/init.lua b/gamemode/init.lua index a911cae..8e3d8bd 100644 --- a/gamemode/init.lua +++ b/gamemode/init.lua @@ -18,6 +18,7 @@ if SERVER then AddCSLuaFile( "settings/sh_crafting_stations.lua" ) AddCSLuaFile( "settings/sh_nodes.lua" ) AddCSLuaFile( "settings/sh_properties.lua" ) + AddCSLuaFile( "settings/sh_dialogues.lua" ) AddCSLuaFile( "cl_init.lua" ) AddCSLuaFile( "shared.lua" ) @@ -125,6 +126,7 @@ if SERVER then include( "settings/sh_nodes.lua" ) include( "settings/sv_nodes_locations.lua" ) include( "settings/sh_properties.lua" ) + include( "settings/sh_dialogues.lua" ) Quantum.Server.Station.UpdateAll() end diff --git a/gamemode/settings/sh_nodes.lua b/gamemode/settings/sh_nodes.lua index 02026d4..721bdf4 100644 --- a/gamemode/settings/sh_nodes.lua +++ b/gamemode/settings/sh_nodes.lua @@ -10,6 +10,7 @@ Quantum.Node.Create( "generalvendor", { name = "General Goods Vendor", model = "models/kleiner.mdl", type = Quantum.NodeType.npc, + dialogueID = "npc_generalvendor", voiceLines = { "vo/coast/odessa/nlo_cub_hello.wav",