3 static string SCENE_DEFAULT_NAME =
"default";
4 static string SCENE_SUFIX =
"scene";
6 static PluginSceneManager instance;
13 static const int SCENE_EDITOR_CMD_REFRESH = 0;
14 static const int SCENE_EDITOR_CMD_POPUP = 1;
15 static const int SCENE_EDITOR_CMD_SAVE = 2;
21 void PluginSceneManager()
23 if ( instance == NULL )
30 void ~PluginSceneManager()
32 if ( instance == NULL )
38 static PluginSceneManager GetInstance()
40 return PluginSceneManager.Cast(
GetPlugin( PluginSceneManager ) );
48 m_ModuleDeveloper = PluginDeveloper.Cast(
GetPlugin(PluginDeveloper) );
49 m_ModuleConfigScene = PluginConfigScene.Cast(
GetPlugin(PluginConfigScene) );
53 m_RulerActivated =
false;
70 void OnMouseWheel(
int wheel)
72 if ( !IsMouseInScene() )
77 if ( GetSelectedSceneObject() )
79 GetSelectedSceneObject().AddRotation(GetRotationAngle() * wheel);
88 void OnUIEditorOpened()
102 void OnUIEditorClosed()
106 FreeCameraControlEnable();
108 m_ModuleDeveloper.ToggleFreeCameraBackPos();
118 if ( !IsMouseInScene() || !m_IsOpen )
127 vector from = FreeDebugCamera.GetInstance().GetPosition();
129 vector to = from + ( dir * 10000 );
133 int contact_component;
134 set<Object> objects =
new set<Object>;
135 bool selected =
false;
137 if (
DayZPhysics.RaycastRV(from, to, contact_pos, contact_dir, contact_component, objects) )
139 for (
int i = 0; i < objects.Count(); ++i )
141 Object obj = objects.Get(i);
147 if ( sc_object == NULL )
153 SelectObject( sc_object );
166 if ( IsRulerActivated() && GetSelectedSceneObject() == NULL )
178 void Event_OnClickMiddle()
180 if ( !IsMouseInScene() || !m_IsOpen )
185 if ( GetSelectedSceneObject() != NULL )
191 vector from = FreeDebugCamera.GetInstance().GetPosition();
193 vector to = from + ( dir * 10000 );
197 int contact_component;
198 set<Object> objects =
new set<Object>;
199 bool selected =
false;
201 if (
DayZPhysics.RaycastRV(from, to, contact_pos, contact_dir, contact_component, objects) )
203 for (
int i = 0; i < objects.Count(); ++i )
205 Object obj = objects.Get(i);
210 SceneObject scene_object = m_SceneData.GetSceneObjectByEntityAI(eai);
212 if ( !scene_object.IsPlayer() )
214 if ( scene_object != NULL && scene_object != GetSelectedSceneObject() )
216 if ( !AreSceneObjectsLinked(GetSelectedSceneObject(), scene_object) )
218 LinkSceneObjects( GetSelectedSceneObject(), scene_object );
222 UnlinkSceneObjects( GetSelectedSceneObject(), scene_object );
228 SceneEditorMenuCmdPopup(
"I am sorry. You cant create link on player!");
243 if ( !IsMouseInScene() || !m_IsOpen )
248 if ( GetSelectedSceneObject() != NULL )
254 vector from = FreeDebugCamera.GetInstance().GetPosition();
256 vector to = from + ( dir * 10000 );
260 int contact_component;
264 if (
DayZPhysics.RaycastRV(from, to, contact_pos, contact_dir, contact_component, NULL, NULL, NULL,
false,
true) )
266 GetSelectedSceneObject().SetPosition(contact_pos);
278 if ( !IsMouseInScene() || !m_IsOpen || m_ClassBrowserSelected ==
"" )
287 vector from = FreeDebugCamera.GetInstance().GetPosition();
289 vector to = from + ( dir * 10000 );
293 int contact_component;
295 if (
DayZPhysics.RaycastRV(from, to, contact_pos, contact_dir, contact_component) )
297 SceneObject obj = m_SceneData.CreateSceneObject(m_ClassBrowserSelected, contact_pos);
316 SceneLoad( PluginMissionConfig.GetInstance().GetSceneEditorName() );
318 RestoreSceneObjectsLinks();
320 ExecuteInitScripts();
326 void RestoreSceneObjectsLinks()
330 for (
int i = 0; i < scene_objects.Count(); i++ )
334 array<int> linked_scene_objects_indices = scene_object.m_LinkedSceneObjectsIndices;
335 if (linked_scene_objects_indices)
337 for (
int j = 0; j < linked_scene_objects_indices.Count(); j++ )
339 int index = linked_scene_objects_indices.Get(j);
340 if ( index >= 0 && index < scene_objects.Count() )
342 scene_object.LinkSceneObject( scene_objects.Get(index),
false );
348 scene_object.m_LinkedSceneObjectsIndices = NULL;
355 void ExecuteInitScripts()
358 for (
int i = 0; i < scene_objects.Count(); i++ )
361 ExecuteEnforceScript( i, scene_object, scene_object.GetInitScript() );
372 if (
GetGame().IsMultiplayer() )
380 GetGame().GetUIManager().Back();
409 void FreeCameraControlEnable()
412 GetGame().GetInput().ChangeGameFocus(-1);
415 GetGame().GetUIManager().ShowUICursor(
false);
417 if(
GetGame().GetUIManager().GetMenu() )
418 GetGame().GetUIManager().GetMenu().OnHide();
424 void FreeCameraControlDisable()
427 GetGame().GetInput().ChangeGameFocus(1);
430 GetGame().GetUIManager().ShowUICursor(
true);
432 if(
GetGame().GetUIManager().GetMenu() )
433 GetGame().GetUIManager().GetMenu().OnShow();
439 void DeleteSelectedObject()
441 SceneObject selected_obj = GetSelectedSceneObject();
443 if ( selected_obj != NULL )
445 if ( !selected_obj.IsPlayer() )
448 for (
int i = 0; i < scene_objects.Count(); i++ )
450 if ( AreSceneObjectsLinked(scene_objects.Get(i), selected_obj) )
452 UnlinkSceneObjects(scene_objects.Get(i), selected_obj);
456 m_SceneData.DeleteSceneObject(selected_obj);
458 scene_objects.RemoveItem(selected_obj);
464 SceneEditorMenuCmdPopup(
"You cant delete player!");
476 if ( GetSelectedSceneObject() != NULL && GetSelectedSceneObject() == obj )
499 void SelectedObjectDuplicate()
501 SceneObject selected_obj = GetSelectedSceneObject();
505 if ( selected_obj.GetObject() ==
PLAYER )
510 vector size = GetSelectedSceneObject().GetSize();
512 vector new_pos = selected_obj.GetPosition() +
Vector(1, 0, 1) + size;
514 SceneObject obj = m_SceneData.CreateSceneObject(selected_obj.GetTypeName(), new_pos );
515 obj.SetRotation(selected_obj.GetRotation());
518 for (
int i = 0; i < attachments.Count(); i++ )
520 obj.AddAttachment( attachments.Get(i).GetType() );
530 void SelectedObjectSetRot(
float dir)
532 if ( GetSelectedSceneObject() )
534 GetSelectedSceneObject().SetRotation(dir);
543 void SelectedObjectSetPosX(
float value)
545 SceneObject selected_obj = GetSelectedSceneObject();
549 vector v = selected_obj.GetPosition();
551 selected_obj.SetPosition(v);
560 void SelectedObjectSetPosY(
float value)
562 SceneObject selected_obj = GetSelectedSceneObject();
566 vector v = selected_obj.GetPosition();
568 selected_obj.SetPosition(v);
577 void SelectedObjectSetPosZ(
float value)
579 SceneObject selected_obj = GetSelectedSceneObject();
581 if ( GetSelectedSceneObject() )
583 vector v = selected_obj.GetPosition();
585 selected_obj.SetPosition(v);
594 void SelectedObjectSetDamage(
float value)
596 SceneObject selected_obj = GetSelectedSceneObject();
597 EntityAI selected_obj_EAI = selected_obj.GetObject();
601 selected_obj.SetHealth(
Math.Clamp ( value, 0, selected_obj_EAI.GetMaxHealth(
"",
"") ));
610 void SelectedObjectFocus()
612 SceneObject selected_obj = GetSelectedSceneObject();
616 vector cam_pos = FreeDebugCamera.GetInstance().GetPosition();
617 vector obj_pos = selected_obj.GetPosition();
618 vector view_target = obj_pos;
620 vector obj_size = selected_obj.GetSize();
624 cam_pos[0] = cam_pos[0] + ( obj_size[0] * 2 );
625 cam_pos[1] = cam_pos[1] + obj_size[1] + 0.5;
626 cam_pos[2] = cam_pos[2] + ( obj_size[2] * 2 );
628 view_target[1] = view_target[1] + (obj_size[1] * 0.5);
630 vector cam_dir = view_target - cam_pos;
633 FreeDebugCamera.GetInstance().SetPosition(cam_pos);
634 FreeDebugCamera.GetInstance().SetDirection(cam_dir);
645 void SelectedObjectAddAttachment(
string att_name)
647 if ( GetSelectedSceneObject() )
649 GetSelectedSceneObject().AddAttachment(att_name);
658 void SelectedObjectRemoveAttachment(
EntityAI e)
660 if ( GetSelectedSceneObject() )
662 GetSelectedSceneObject().RemoveAttachment(e);
673 scene_object1.LinkSceneObject(scene_object2);
674 scene_object2.LinkSceneObject(scene_object1);
682 scene_object1.UnlinkSceneObject(scene_object2);
683 scene_object2.UnlinkSceneObject(scene_object1);
691 if ( scene_object1.IsLinkedWithSceneObject(scene_object2) && scene_object2.IsLinkedWithSceneObject(scene_object1) )
704 void SetDrawSelection(
bool draw)
706 m_ModuleConfigDebugProfile.SetSceneEditorDrawSelection(draw);
714 bool GetDrawSelection()
716 return m_ModuleConfigDebugProfile.GetSceneEditorDrawSelection();
722 void SetLoadPlayerPos(
bool save)
724 m_ModuleConfigDebugProfile.SetSceneEditorLoadPlayerPos(save);
730 bool GetLoadPlayerPos()
732 return m_ModuleConfigDebugProfile.GetSceneEditorLoadPlayerPos();
738 void SetRotationAngle(
int angle)
740 m_ModuleConfigDebugProfile.SetSceneEditorRotationAngle(angle);
746 int GetRotationAngle()
748 return m_ModuleConfigDebugProfile.GetSceneEditorRotationAngle();
754 void SceneLoad(
string scene_name)
758 PluginMissionConfig.GetInstance().SetSceneEditorName(scene_name);
759 m_SceneData = m_ModuleConfigScene.SceneDataLoad(scene_name);
781 m_ModuleConfigScene.ClearParams();
782 m_ModuleConfigScene.SceneDataSave(m_SceneData);
783 SceneEditorMenuCmdSave();
790 bool SceneCanDelete(
string scene_name)
792 if ( scene_name == m_SceneData.GetNameScene() )
803 bool SceneDelete(
string scene_name)
805 if ( scene_name == m_SceneData.GetNameScene() )
810 m_ModuleConfigScene.SceneDelete(scene_name);
820 void SceneDuplicate(
string scene_name)
822 m_ModuleConfigScene.SceneDuplicate(scene_name);
830 void SceneRename(
string scene_name,
string new_name)
832 m_ModuleConfigScene.SceneRename(scene_name, new_name);
834 if ( scene_name == m_SceneData.GetNameScene() )
836 m_SceneData.SetNameScene(new_name);
845 string SceneGetName()
849 return m_SceneData.GetNameScene();
858 void SetWeather(
float overcast,
float rain,
float fog,
float wind_force)
860 m_SceneData.SetInitOvercast(overcast);
861 m_SceneData.SetInitRain(rain);
862 m_SceneData.SetInitFog(fog);
863 m_SceneData.SetInitWindForce(wind_force);
869 void SetDate(
int year,
int month,
int day,
int hour,
int minute )
871 m_SceneData.SetInitYear(year);
872 m_SceneData.SetInitMonth(month);
873 m_SceneData.SetInitDay(day);
874 m_SceneData.SetInitHour(hour);
875 m_SceneData.SetInitMinute(minute);
881 void SelectAndFocusPlayerObject()
884 for (
int i = 0; i < scene_objects.Count(); i++ )
888 SelectObject( scene_objects.Get(i) );
889 SelectedObjectFocus();
898 void ExecuteEnforceScript(
int index,
SceneObject scene_object,
string script )
902 string cls = scene_object.GetObject().ClassName();
903 string wrapped_script =
"void scMngMain() \n{\n PluginSceneManager se = GetPlugin(Type(\"PluginSceneManager\")); \n SceneObject this_obj = se.GetSceneObjectByIndex(" + index.ToString() +
"); \n " + cls +
" this_eai = this_obj.GetObject(); \n " + script +
"\n}\n";
905 GetGame().ExecuteEnforceScript(wrapped_script,
"scMngMain");
914 if ( IsRulerActivated() )
916 m_RulerActivated =
false;
920 m_RulerActivated =
true;
923 SceneEditorMenuCmdRefresh();
929 bool IsRulerActivated()
931 return m_RulerActivated;
939 vector point_pos = GetMousePositionInScene();
941 m_RulerPoints.Insert( point_pos );
949 void RulerClearVisuals()
951 for (
int i = 0; i < m_RulerLines.Count(); ++i )
953 m_RulerLines.Get(i).Destroy();
955 m_RulerLines.Clear();
957 for (
int j = 0; j < m_RulerSpheres.Count(); ++j )
959 m_RulerSpheres.Get(j).Destroy();
961 m_RulerSpheres.Clear();
969 m_RulerPoints.Clear();
985 int GetSelectedSceneObjectIndex()
988 for (
int i = 0; i < scene_objects.Count(); i++ )
990 if ( GetSelectedSceneObject() == scene_objects.Get(i) )
1006 return m_SceneData.GetSceneObjects();
1019 return m_SceneData.GetScenePlayers();
1032 return m_SceneData.GetSceneObjectsAll();
1045 if ( scene_objects != NULL )
1047 if ( index > -1 && index < scene_objects.Count() )
1049 return scene_objects.Get( index );
1063 if ( scene_objects != NULL )
1065 for (
int i = 0; i <= scene_objects.Count(); ++i )
1085 return m_ModuleConfigScene.GetSceneList();
1099 if ( GetSelectedSceneObject() != NULL && GetSelectedSceneObject() == obj )
1104 m_SceneData.DeleteSceneObject(obj);
1108 SceneEditorMenuCmdPopup(
"You cant delete player!");
1117 protected PluginDeveloper m_ModuleDeveloper;
1118 protected PluginConfigScene m_ModuleConfigScene;
1123 protected float m_TimeLastClickRelease;
1124 protected float m_TimeLastClickPress;
1125 protected int m_PressedMouseID;
1131 protected string m_ClassBrowserSelected;
1132 protected bool m_IsOpen;
1137 private void DeselectObject()
1145 protected void EditorUpdate()
1147 if (
GetGame().IsMultiplayer() )
1155 for (
int i = 0; i < objects.Count(); ++i )
1164 obj.EditorShapeAdd();
1166 if ( GetSelectedSceneObject() && GetSelectedSceneObject() == obj )
1168 if ( GetDrawSelection() )
1170 obj.EditorShapeSelect();
1175 obj.EditorShapeDeselect();
1178 for ( j = 0; j < linked_scene_objects.Count(); j++ )
1180 obj.EditorLineAdd( linked_scene_objects.Get(j) );
1185 obj.EditorShapeRemove();
1187 if (linked_scene_objects)
1189 for ( j = 0; j < linked_scene_objects.Count(); j++ )
1191 obj.EditorLineRemove( linked_scene_objects.Get(j) );
1197 SceneEditorMenuCmdRefresh();
1203 private void SceneEditorMenuCmdRefresh()
1211 private void SceneEditorMenuCmdPopup(
string message)
1219 private void SceneEditorMenuCmdSave()
1227 private bool IsMouseInScene()
1231 if ( widget_under_mouse != NULL && widget_under_mouse.GetName() ==
"pnl_SceneControl" )
1242 private void EditorUpdateRuler()
1244 RulerClearVisuals();
1246 for (
int i = 0; i < m_RulerPoints.Count(); ++i )
1248 vector pos1 = m_RulerPoints.Get(i);
1250 m_RulerSpheres.Insert(
Debug.DrawSphere(pos1, 0.1));
1252 if ( i < m_RulerPoints.Count() - 1 )
1254 vector pos2 = m_RulerPoints.Get(i + 1);
1255 m_RulerLines.Insert(
Debug.DrawLine(pos1, pos2));
1263 private vector GetMousePositionInScene()
1266 vector from = FreeDebugCamera.GetInstance().GetPosition();
1267 vector to = from + ( dir * 10000 );
1270 int contact_component;
1272 if (
DayZPhysics.RaycastRV(from, to, contact_pos, contact_dir, contact_component) )