3 protected static CameraToolsMenu m_Instance;
4 vector m_FreeflightCamTransform[4];
5 protected vector m_NextCamPosition;
10 protected Camera m_Camera2;
14 protected int m_NextCameraIndex = 1;
16 protected float m_FollowingTimeFinished;
19 protected CTKeyframe m_SelectedKeyframe;
20 protected CTEvent m_SelectedEvent;
21 protected CTActor m_SelectedActor;
27 protected Widget m_KeyframeContent;
28 protected Widget m_EventContent;
30 protected XComboBoxWidget m_InterpTypeSpeedCombo;
31 protected XComboBoxWidget m_InterpTypeCombo;
38 protected ButtonWidget m_AddItem;
39 protected ButtonWidget m_AddHandsItem;
40 protected ButtonWidget m_AddActor;
41 protected ButtonWidget m_Play;
42 protected ButtonWidget m_Stop;
43 protected ButtonWidget m_Save;
44 protected ButtonWidget m_Load;
46 protected ButtonWidget m_AddKeyframe;
47 protected ButtonWidget m_SaveKeyframe;
48 protected ButtonWidget m_DeleteKeyframe;
49 protected ButtonWidget m_ViewKeyframe;
51 protected ButtonWidget m_AddEvent;
52 protected ButtonWidget m_SaveEvent;
53 protected ButtonWidget m_DeleteEvent;
54 protected ButtonWidget m_ViewEvent;
56 protected ButtonWidget m_CopyButton;
57 protected ButtonWidget m_ApplyButton;
61 void CameraToolsMenu()
73 void ~CameraToolsMenu()
75 m_Camera1.SetActive(
false );
76 m_Camera2.SetActive(
false );
83 MissionGameplay ms = MissionGameplay.Cast(
GetGame().GetMission() );
85 ms.GetHud().Show(
true );
93 GetGame().GetMission().AddActiveInputExcludes({
"menu"});
102 GetGame().GetUIManager().ShowUICursor(
false);
103 GetGame().GetMission().RemoveActiveInputExcludes({
"menu"},
true);
107 void SelectKeyframe( CTKeyframe kf )
109 if ( m_SelectedKeyframe )
110 m_SelectedKeyframe.Unselect();
112 m_SelectedKeyframe = kf;
113 m_SelectedKeyframe.Select();
118 m_SelectedEvent = ev;
121 void SelectActor( CTActor ac )
123 m_SelectedActor = ac;
128 layoutRoot =
GetGame().GetWorkspace().CreateWidgets(
"gui/layouts/camera_tools/camera_tools.layout" );
130 m_KeyframeContent = layoutRoot.FindAnyWidget(
"keyframe_list_content" );
131 m_EventContent = layoutRoot.FindAnyWidget(
"events_list_content" );
132 m_InterpTypeCombo = XComboBoxWidget.Cast( layoutRoot.FindAnyWidget(
"interp_type" ) );
133 m_InterpTypeSpeedCombo = XComboBoxWidget.Cast( layoutRoot.FindAnyWidget(
"interp_speed_type" ) );
134 m_BlurEditWidget =
EditBoxWidget.Cast( layoutRoot.FindAnyWidget(
"blur_value" ) );
135 m_ActorTypeWidget =
EditBoxWidget.Cast( layoutRoot.FindAnyWidget(
"add_actor_type" ) );
136 m_ActorIdWidget =
EditBoxWidget.Cast( layoutRoot.FindAnyWidget(
"add_actor_id" ) );
137 m_ActorItemTypeWidget =
EditBoxWidget.Cast( layoutRoot.FindAnyWidget(
"add_item_type" ) );
139 m_AddKeyframe = ButtonWidget.Cast( layoutRoot.FindAnyWidget(
"add_keyframe" ) );
140 m_AddEvent = ButtonWidget.Cast( layoutRoot.FindAnyWidget(
"add_event" ) );
142 m_AddItem = ButtonWidget.Cast( layoutRoot.FindAnyWidget(
"add_actor_item" ) );
143 m_AddHandsItem = ButtonWidget.Cast( layoutRoot.FindAnyWidget(
"add_actor_item_hands" ) );
144 m_AddActor = ButtonWidget.Cast( layoutRoot.FindAnyWidget(
"add_actor" ) );
145 m_Play = ButtonWidget.Cast( layoutRoot.FindAnyWidget(
"play" ) );
146 m_Stop = ButtonWidget.Cast( layoutRoot.FindAnyWidget(
"stop" ) );
147 m_Save = ButtonWidget.Cast( layoutRoot.FindAnyWidget(
"save" ) );
148 m_Load = ButtonWidget.Cast( layoutRoot.FindAnyWidget(
"load" ) );
150 m_SaveKeyframe = ButtonWidget.Cast( layoutRoot.FindAnyWidget(
"save_keyframe" ) );
151 m_DeleteKeyframe = ButtonWidget.Cast( layoutRoot.FindAnyWidget(
"delete_keyframe" ) );
152 m_ViewKeyframe = ButtonWidget.Cast( layoutRoot.FindAnyWidget(
"snap_to_keyframe" ) );
153 m_SaveEvent = ButtonWidget.Cast( layoutRoot.FindAnyWidget(
"save_event" ) );
154 m_DeleteEvent = ButtonWidget.Cast( layoutRoot.FindAnyWidget(
"delete_event" ) );
155 m_ViewEvent = ButtonWidget.Cast( layoutRoot.FindAnyWidget(
"snap_to_event" ) );
157 m_CopyButton = ButtonWidget.Cast( layoutRoot.FindAnyWidget(
"CopyButton" ) );
158 m_ApplyButton = ButtonWidget.Cast( layoutRoot.FindAnyWidget(
"ApplyButton" ) );
159 m_CameraEditbox =
EditBoxWidget.Cast( layoutRoot.FindAnyWidget(
"CameraEditbox" ) );
160 m_CameraValues =
TextWidget.Cast( layoutRoot.FindAnyWidget(
"CameraValues" ) );
162 MissionGameplay ms = MissionGameplay.Cast(
GetGame().GetMission() );
163 ms.GetHud().Show(
false );
166 m_BlurEditWidget.SetText(
"0.0" );
172 if ( index > -1 && index < m_Actors.Count() )
173 return PlayerBase.Cast( m_Actors.Get( index ).GetObj() );
178 static void PlayAnimOnActor(
int actor,
int anim )
186 cb.EnableCancelCondition(
true);
202 if (!JsonFileLoader<ref CTSaveStructure>.LoadFile(
g_Game.GetMissionFolderPath() +
"/CameraTools/keyframe_data.json", save_data, errorMessage))
205 m_InterpTypeCombo.SetCurrentItem( save_data.m_InterpType );
206 m_InterpTypeSpeedCombo.SetCurrentItem( save_data.m_InterpSpeed );
207 SetBlurValue( save_data.m_BlurValue );
209 foreach ( Param6<vector, vector, float, float, float, int> transform : save_data.m_Cameras )
211 CTKeyframe kf =
new CTKeyframe( m_Cameras.Count(), transform.param1, transform.param2, transform.param3, transform.param4, transform.param5, transform.param6, GetTotalTime( m_Cameras.Count() ), m_KeyframeContent,
this );
212 kf.SetInterpTime( transform.param3 );
213 m_Cameras.Insert( kf );
216 foreach ( Param4<int, int, float, bool> event_t : save_data.m_Events )
218 CTEvent ev =
new CTEvent( m_Events.Count(), event_t.param1, m_EventContent, event_t.param4,
this );
219 ev.SetEventType( event_t.param2 );
220 ev.SetEventTime( event_t.param3 );
221 m_Events.Insert( ev );
226 CTActor ac =
new CTActor( m_Actors.Count(), actor_t.param1, actor_t.param2, actor_t.param3, actor_t.param4, actor_t.param5,
this );
227 m_Actors.Insert( ac );
237 save_data.m_InterpType = m_InterpTypeCombo.GetCurrentItem();
238 save_data.m_InterpSpeed = m_InterpTypeSpeedCombo.GetCurrentItem();
239 save_data.m_BlurValue = GetBlurValue();
241 foreach ( CTKeyframe keyframe : m_Cameras )
243 Param6<vector, vector, float, float, float, int> transform =
new Param6<vector, vector, float, float, float, int>( keyframe.GetPosition(), keyframe.GetOrientation(), keyframe.GetInterpTime(), keyframe.GetFOV(), keyframe.GetDOF(), keyframe.GetPin() );
244 save_data.m_Cameras.Insert( transform );
247 foreach ( CTEvent event_t : m_Events )
249 Param4<int, int, float, bool> ev =
new Param4<int, int, float, bool>( event_t.GetEventActor(), event_t.GetEventType(), event_t.GetEventTime(), event_t.GetEventWalk() );
250 save_data.m_Events.Insert( ev );
253 foreach ( CTActor actor_t : m_Actors )
255 Param5<vector, vector, string, ref array<string>,
string> ac =
new Param5<vector, vector, string, ref array<string>,
string>( actor_t.GetPosition(), actor_t.GetRotation(), actor_t.GetActorType(), actor_t.GetItems(), actor_t.GetHandsItem() );
256 save_data.m_Actors.Insert( ac );
260 if (!JsonFileLoader<ref CTSaveStructure>.SaveFile(
g_Game.GetMissionFolderPath() +
"/CameraTools/keyframe_data.json", save_data, errorMessage))
264 float GetTotalTime(
int index )
267 index =
Math.Clamp( index, 0, m_Cameras.Count() );
268 for (
int i = 0; i < index; i++ )
270 time += m_Cameras.Get( i ).GetInterpTime();
277 if (
Camera.GetCurrentCamera() )
279 vector pos =
Camera.GetCurrentCamera().GetWorldPosition();
280 vector orient =
Camera.GetCurrentCamera().GetOrientation();
281 CTKeyframe kf =
new CTKeyframe( m_Cameras.Count(), pos, orient, 1, 70, 50, -1, GetTotalTime( m_Cameras.Count() ), m_KeyframeContent,
this );
282 m_Cameras.Insert( kf );
283 SelectKeyframe( kf );
289 if ( m_SelectedKeyframe &&
Camera.GetCurrentCamera() )
291 m_SelectedKeyframe.SetPosition(
Camera.GetCurrentCamera().GetWorldPosition() );
292 m_SelectedKeyframe.SetOrientation(
Camera.GetCurrentCamera().GetOrientation() );
296 void DeleteKeyframe()
298 if ( m_SelectedKeyframe )
300 int index = m_Cameras.Find( m_SelectedKeyframe );
301 m_Cameras.Remove( index );
302 index =
Math.Clamp( index, 0, m_Cameras.Count() - 1 );
303 if ( m_Cameras.Count() > 0 )
305 SelectKeyframe( m_Cameras.Get( index ) );
312 if ( m_SelectedKeyframe &&
Camera.GetCurrentCamera() )
314 Camera.GetCurrentCamera().SetPosition( m_SelectedKeyframe.GetPosition() );
315 Camera.GetCurrentCamera().SetOrientation( m_SelectedKeyframe.GetOrientation() );
319 void AddActor(
string actor_type )
321 vector pos = GetCameraLookDir();
322 CTActor ac =
new CTActor( m_Actors.Count(), pos,
"0 0 0", actor_type,
new array<string>,
"",
this );
324 m_Actors.Insert( ac );
327 void AddEvent(
int actor_index )
329 if ( actor_index > -1 )
331 CTEvent ev =
new CTEvent( m_Events.Count(), actor_index, m_EventContent,
false,
this );
332 m_Events.Insert( ev );
337 void AddItem(
string id,
string type )
339 int id_int =
id.ToInt();
340 if ( m_Actors.Count() > id_int && id_int > -1 )
342 CTActor ac = m_Actors.Get( id_int );
348 void AddHandsItem(
string id,
string type )
350 int id_int =
id.ToInt();
351 if ( m_Actors.Count() > id_int && id_int > -1 )
353 CTActor ac = m_Actors.Get( id_int );
355 ac.SetHandsItem( type );
374 Param6<vector, vector, float, float, float, int> GetCameraLine(
int index )
376 if ( index > -1 && index < m_CameraLines.Count() )
378 return m_CameraLines[index];
385 if (
Camera.GetCurrentCamera())
386 Camera.GetCurrentCamera().GetTransform(m_FreeflightCamTransform);
387 if ( m_Cameras.Count() > 0 )
389 layoutRoot.Show(
false );
390 GetGame().GetUIManager().ShowUICursor(
false );
393 foreach ( CTKeyframe keyframe : m_Cameras )
395 Param6<vector, vector, float, float, float, int> transform =
new Param6<vector, vector, float, float, float, int>( keyframe.GetPosition(), keyframe.GetOrientation(), keyframe.GetInterpTime(), keyframe.GetFOV(), keyframe.GetDOF(), keyframe.GetPin() );
396 m_CameraLines.Insert( transform );
400 foreach ( CTActor ac : m_Actors )
405 foreach ( CTEvent ev : m_Events )
412 int time = SetCameraData( GetCameraLine( 0 ), GetCameraLine( 1 ) );
414 if ( GetCameraLine( 0 ).param6 > -1 )
416 m_FollowingTimeFinished = time;
417 m_NextCamPosition =
"0 0 0";
418 m_Camera1.SetActive(
true );
422 m_NextCamPosition = m_Camera2.GetPosition();
423 m_FollowingTimeFinished = -1;
424 m_Camera1.SetActive(
true );
425 m_Camera1.InterpolateTo( m_Camera2, time, m_InterpTypeCombo.GetCurrentItem() );
428 m_NextCameraIndex = 1;
436 layoutRoot.Show(
true );
437 GetGame().GetUIManager().ShowUICursor(
true );
439 m_Camera1.SetActive(
false );
440 m_Camera2.SetActive(
false );
441 FreeDebugCamera.GetInstance().SetActive(
true);
443 m_NextCameraIndex = 1;
446 foreach ( CTEvent ev : m_Events )
451 foreach ( CTActor ac : m_Actors )
457 Camera.GetCurrentCamera().SetTransform(m_FreeflightCamTransform);
462 vector dir = FreeDebugCamera.GetInstance().GetDirection();
463 vector from = FreeDebugCamera.GetInstance().GetPosition();
464 vector to = from + ( dir * 10000 );
467 int contact_component;
469 if ( m_SelectedEvent )
470 ev_obj = GetActor( m_SelectedEvent.GetEventActor() );
471 if (
DayZPhysics.RaycastRV(from, to, contact_pos, contact_dir, contact_component,
null,
null, ev_obj) )
482 vector from = FreeDebugCamera.GetInstance().GetPosition();
483 vector to = from + ( dir * 10000 );
486 int contact_component;
488 if ( m_SelectedEvent )
489 ev_obj = GetActor( m_SelectedEvent.GetEventActor() );
490 if (
DayZPhysics.RaycastRV(from, to, contact_pos, contact_dir, contact_component,
null,
null, ev_obj) )
498 override void Update(
float timeslice )
501 string camPos = MiscGameplayFunctions.TruncateVecToS(FreeDebugCamera.GetInstance().GetPosition(),0);
502 string camOri = MiscGameplayFunctions.TruncateVecToS(FreeDebugCamera.GetInstance().GetOrientation(),0);
503 m_CameraValues.SetText(
"Pos:" +camPos +
" | Rot:" + camOri);
505 #ifdef DIAG_DEVELOPER
510 if (!cam && m_Camera1)
514 Param4<vector, vector,float,float> p4 =
new Param4<vector, vector,float,float>(
GetGame().GetCurrentCameraPosition(),
GetGame().GetCurrentCameraDirection(), cam.GetNearPlane(), cam.GetCurrentFOV());
515 GetGame().RPCSingleParam(
null,
ERPCs.DIAG_CAMERATOOLS_CAM_DATA, p4,
false);
523 foreach ( CTEvent ev : m_Events )
533 if ( !
Camera.GetCurrentCamera() || !m_Camera1 || !m_Camera2 )
538 if ( m_FollowingBone )
540 PlayerBase p = GetActor( m_FollowingBone.param1 );
543 vector pos = p.GetBonePositionWS( m_FollowingBone.param2 );
545 int bone_index = p.GetBoneIndexByName(
"LeftHand_Dummy");
547 p.GetBoneRotationWS( bone_index, bone_rot );
553 float temp = new_orient[1];
554 new_orient[0] = new_orient[0] + 325;
555 new_orient[1] = new_orient[2] + 245;
556 new_orient[2] = temp + 290;
560 m_Camera1.SetPosition(pos);
561 m_Camera1.SetOrientation(new_orient);
565 if ( m_NextCameraIndex + 1 == m_CameraLines.Count() )
569 foreach ( CTEvent ev2 : m_Events )
576 if (
Camera.GetCurrentCamera().GetPosition() == m_NextCamPosition || ( m_FollowingTimeFinished != -1 &&
m_Time >= m_FollowingTimeFinished ) )
579 if ( GetCameraLine( m_NextCameraIndex - 1 ).param6 > -1 )
582 GetCameraLine( m_NextCameraIndex ).param6 = -1;
584 time = SetCameraData( GetCameraLine( m_NextCameraIndex ), GetCameraLine( m_NextCameraIndex + 1 ) );
588 time = SetCameraData( GetCameraLine( m_NextCameraIndex ), GetCameraLine( m_NextCameraIndex + 1 ) );
592 if ( GetCameraLine( m_NextCameraIndex - 1 ).param6 > -1 )
594 m_FollowingTimeFinished = time +
m_Time;
595 m_NextCamPosition =
"0 0 0";
596 m_Camera1.SetActive(
true );
598 else if ( GetCameraLine( m_NextCameraIndex ) )
600 m_NextCamPosition = GetCameraLine( m_NextCameraIndex ).param1;
601 m_FollowingTimeFinished = -1;
602 m_Camera1.SetActive(
true );
603 m_Camera1.InterpolateTo( m_Camera2, time, m_InterpTypeCombo.GetCurrentItem() );
609 FreeDebugCamera.GetInstance().SetOrientation(
"0 0 0" );
610 foreach( CTEvent ev3 : m_Events )
619 if ( m_Camera1.GetPosition() == m_NextCamPosition )
624 for (
int i = 0; i < ( m_Cameras.Count() - 1 ); i++ )
626 vector pos0 = m_Cameras.Get( i ).GetPosition();
627 vector pos1 = m_Cameras.Get( i + 1 ).GetPosition();
631 if ( m_SelectedActor )
633 if ( !
g_Game.IsLeftCtrlDown() )
634 m_SelectedActor.SetPosition( GetMouseLookDir() );
637 vector from = m_SelectedActor.GetPosition();
638 vector to = GetMouseLookDir();
640 m_SelectedActor.SetRotation(
vector.Direction( from,to ).Normalized().VectorToAngles() );
645 foreach ( CTActor ac : m_Actors )
647 ac.Update( timeslice );
652 float SetCameraData( Param6<vector, vector, float, float, float,int> transform1, Param6<vector, vector, float, float, float, int> transform2 )
654 float int_value = transform1.param3;
655 if ( m_InterpTypeSpeedCombo.GetCurrentItem() == 1 )
657 int_value =
vector.Distance( transform1.param1, transform2.param1 ) / int_value;
662 if ( transform1.param6 > -1 )
664 p = GetActor( transform1.param6 );
667 b_index = p.GetBoneIndexByName(
"LeftHand_Dummy" );
673 m_Camera1.SetPosition( transform1.param1 );
674 m_Camera1.SetOrientation( transform1.param2 );
675 m_FollowingBone =
null;
677 m_Camera1.SetFOV( transform1.param4 *
Math.DEG2RAD );
678 m_Camera1.SetFocus( transform1.param5, GetBlurValue() );
682 if ( transform2.param6 > -1 )
685 p = GetActor( transform2.param6 );
688 b_index = p.GetBoneIndexByName(
"LeftHand_Dummy" );
691 m_Camera2.SetPosition( p.GetBonePositionWS( b_index ) );
693 p.GetBoneRotationWS( b_index, pQuat);
698 DbgUI.Text( v.ToString() );
699 m_Camera2.SetYawPitchRoll( v );
705 m_Camera2.SetPosition( transform2.param1 );
706 m_Camera2.SetOrientation( transform2.param2 );
709 m_Camera2.SetFOV( transform2.param4 *
Math.DEG2RAD );
710 m_Camera2.SetFocus( transform2.param5, GetBlurValue() );
716 void SetBlurValue(
float blur )
718 m_BlurEditWidget.SetText( blur.ToString() );
723 return m_BlurEditWidget.GetText().ToFloat();
730 GetGame().GetInput().ResetGameFocus();
731 GetGame().GetInput().ChangeGameFocus(-1);
732 GetGame().GetUIManager().ShowUICursor(
false);
733 GetGame().GetMission().RemoveActiveInputExcludes({
"menu"});
746 if ( w == layoutRoot && button ==
MouseState.LEFT )
758 if ( w == m_SaveKeyframe )
763 else if ( w == m_DeleteKeyframe )
768 else if ( w == m_ViewKeyframe )
773 else if ( w == m_SaveEvent )
778 else if ( w == m_DeleteEvent )
783 else if ( w == m_ViewEvent )
788 else if ( w == m_AddKeyframe )
793 else if ( w == m_AddEvent )
798 else if ( w == m_Play )
803 else if ( w == m_Stop )
808 else if ( w == m_Save )
813 else if ( w == m_Load )
818 else if ( w == m_AddActor )
820 AddActor( m_ActorTypeWidget.GetText() );
822 else if ( w == m_AddItem )
824 AddItem( m_ActorIdWidget.GetText(), m_ActorItemTypeWidget.GetText() );
826 else if ( w == m_AddHandsItem )
828 AddHandsItem( m_ActorIdWidget.GetText(), m_ActorItemTypeWidget.GetText() );
830 else if ( w == m_CopyButton )
832 string clipboardIn = FreeDebugCamera.GetInstance().GetPosition().ToString(
false)+
"|"+ FreeDebugCamera.GetInstance().GetOrientation().ToString(
false);
833 GetGame().CopyToClipboard( clipboardIn );
837 else if ( w == m_ApplyButton )
839 string camText = m_CameraEditbox.GetText();
840 if (camText && camText.IndexOf(
"|") !=-1)
842 int seperatorIndex = camText.IndexOf(
"|");
843 int length = camText.Length();
845 string posStr = camText.Substring(0,seperatorIndex);
846 string oriStr = camText.Substring(seperatorIndex+1, length - seperatorIndex - 1);
847 FreeDebugCamera.GetInstance().SetPosition(posStr.ToVector());
848 FreeDebugCamera.GetInstance().SetOrientation(oriStr.ToVector());
858 if ( w == m_CameraEditbox)
859 m_CameraEditbox.SetText(
"");
882 ColorWhite( w,
null );
892 return ( w == m_SaveKeyframe || w == m_DeleteKeyframe || w == m_ViewKeyframe || w == m_SaveEvent || w == m_DeleteEvent || w == m_ViewEvent || w == m_AddKeyframe || w == m_AddEvent || w == m_Play || w == m_Stop || w == m_Save || w == m_Load || w == m_InterpTypeCombo );
897 override bool OnKeyPress(
Widget w,
int x,
int y,
int key)
899 if (!w && key ==
KeyCode.KC_P )
929 else if ( !w &&
g_Game.IsLeftCtrlDown() )
941 if ( w.IsInherited( ButtonWidget ) )
943 ButtonWidget button = ButtonWidget.Cast( w );
944 button.SetTextColor(
ARGB( 255, 255, 0, 0 ) );
945 button.SetAlpha( 0.9 );
951 if ( w.IsInherited( ButtonWidget ) )
953 ButtonWidget button = ButtonWidget.Cast( w );
956 button.SetTextColor(
ARGB( 255, 255, 255, 255 ) );
957 button.SetAlpha( 0.75 );