Skip to content

Commit 36ca1c3

Browse files
committed
improvements to camera swap
set it as a doubleclick action (corresponds to the quick access option, view/unview camera) it saves the old view position (relative if using follow entity) so that when returning to editor view, we return to the same position
1 parent 68412ef commit 36ca1c3

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

lua/pac3/core/client/parts/camera.lua

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ PART.ClassName = "camera"
66
PART.Group = 'entity'
77
PART.Icon = 'icon16/camera.png'
88

9+
PART.ImplementsDoubleClickSpecified = true
10+
911
BUILDER:StartStorableVars()
1012
BUILDER:GetSet("EyeAnglesLerp", 1)
1113
BUILDER:GetSet("DrawViewModel", false)
@@ -75,6 +77,12 @@ function PART:CameraTakePriority(then_view)
7577
self.priority = true
7678
end)
7779
if then_view then
80+
pace.old_ViewAngles = pace.ViewAngles
81+
pace.old_ViewPos = pace.ViewPos
82+
83+
--it should be relative if we use camera follow entity
84+
pace.old_ViewPos_delta = pace.ViewPos - pace.GetViewEntity():GetPos()
85+
7886
timer.Simple(0.2, function() pace.CameraPartSwapView(true) end)
7987
end
8088
end
@@ -351,6 +359,17 @@ function pac.HandleCameraPart(ply, pos, ang, fov, nearz, farz)
351359
--until we make reversible first person a thing, letting some non-drawable parts think, this is the best solution I could come up with
352360
end
353361

362+
function PART:OnDoubleClickSpecified()
363+
if self ~= pac.active_camera then
364+
self:CameraTakePriority(true)
365+
else
366+
pac.active_camera = nil
367+
self.priority = false
368+
self:RemoveSmallIcon()
369+
pace.CameraPartSwapView()
370+
end
371+
end
372+
354373
function pac.HasRemainingCameraPart()
355374
pac.RebuildCameras()
356375
return table.Count(pac.LocalPlayer.pac_cameras) ~= 0

lua/pac3/editor/client/view.lua

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,19 @@ function pace.EnableView(b)
768768
pac.AddHook("HUDShouldDraw", "editor", pace.HUDShouldDraw)
769769
pac.AddHook("PostRenderVGUI", "editor", pace.PostRenderVGUI)
770770
pace.Focused = true
771-
pace.ResetView()
771+
if pace.old_ViewAngles and pace.old_ViewPos and pace.old_ViewPos_delta then
772+
if follow_entity:GetBool() then
773+
pace.ViewPos = pace.old_ViewPos_delta + pace.GetViewEntity():GetPos()
774+
else
775+
pace.ViewPos = pace.old_ViewPos
776+
end
777+
pace.ViewAngles = pace.old_ViewAngles
778+
pace.old_ViewAngles = nil
779+
pace.old_ViewPos = nil
780+
pace.old_ViewPos_delta = nil
781+
else
782+
pace.ResetView()
783+
end
772784
else
773785
lastEntityPos = nil
774786
pac.RemoveHook("GUIMousePressed", "editor")

0 commit comments

Comments
 (0)