Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_MapEditorUIComponent.c
Go to the documentation of this file.
2 {
3  protected SCR_MapEntity m_MapEntity;
4  protected InputManager m_InputManager;
5 
6  protected SCR_ManualCamera m_EditorCamera;
7 
8  protected SCR_EditorManagerCore m_EditorCore;
9  protected SCR_EditorManagerEntity m_EditorManager;
10  protected SCR_MapEditorComponent m_EditorMapManager;
11 
12  protected ref Color m_CameraIconColor = Color.White;
13  protected Widget m_MapWidget;
14 
15  protected ResourceName m_EditorMapConfigPrefab;
16  protected ref MapConfiguration m_MapConfigEditor;
17  protected bool m_bIsFirstTimeOpened = true;
18 
19  //------------------------------------------------------------------------------------------------
23  void ToggleMap(bool show, ResourceName mapConfigPrefab)
24  {
25  if (mapConfigPrefab.IsEmpty())
26  return;
27 
28  if (show)
29  {
30  m_MapConfigEditor = m_MapEntity.SetupMapConfig(EMapEntityMode.EDITOR, mapConfigPrefab, m_MapWidget);
31  m_MapEntity.OpenMap(m_MapConfigEditor);
32  }
33  else if (m_MapEntity.IsOpen())
34  {
35  m_MapEntity.CloseMap();
36  }
37 
38  if (m_EditorCamera)
39  m_EditorCamera.SetInputEnabled(!show);
40  }
41 
42  //------------------------------------------------------------------------------------------------
43  protected void OnMapInit(MapConfiguration config)
44  {
45  if (IsConfigEditor(config))
46  {
47  m_MapWidget.SetVisible(true);
48  }
49  }
50 
51  //------------------------------------------------------------------------------------------------
52  protected void OnMapOpen(MapConfiguration config)
53  {
54  if (IsConfigEditor(config))
55  {
57  {
58  m_bIsFirstTimeOpened = false;
59  m_MapEntity.ZoomOut();
60  }
61  }
62  }
63 
64  //------------------------------------------------------------------------------------------------
65  protected void OnMapClose(MapConfiguration config)
66  {
67  if (IsConfigEditor(config))
68  m_MapWidget.SetVisible(false);
69  }
70 
71  //------------------------------------------------------------------------------------------------
74  bool IsEditorMapOpen()
75  {
76  return m_MapEntity && m_MapEntity.IsOpen() && IsConfigEditor(m_MapEntity.GetMapConfig());
77  }
78 
79  //------------------------------------------------------------------------------------------------
80  protected bool IsConfigEditor(MapConfiguration config)
81  {
82  return config && config.MapEntityMode == EMapEntityMode.EDITOR;
83  }
84 
85  //------------------------------------------------------------------------------------------------
86  protected void OnEditorModeChange(SCR_EditorModeEntity newModeEntity, SCR_EditorModeEntity oldModeEntity)
87  {
88  SCR_CameraEditorComponent cameraComponent;
89  if (oldModeEntity)
90  {
91  cameraComponent = SCR_CameraEditorComponent.Cast(oldModeEntity.FindComponent(SCR_CameraEditorComponent));
92  if (cameraComponent)
93  cameraComponent.GetOnCameraCreate().Remove(OnEditorCameraCreate);
94  }
95 
96  if (newModeEntity)
97  {
98  cameraComponent = SCR_CameraEditorComponent.Cast(newModeEntity.FindComponent(SCR_CameraEditorComponent));
99  if (cameraComponent)
100  {
101  cameraComponent.GetOnCameraCreate().Insert(OnEditorCameraCreate);
102  OnEditorCameraCreate(cameraComponent.GetCamera());
103  }
104 
105  SetCameraIconColor(newModeEntity.GetModeType());
106  }
107  }
108 
109  //------------------------------------------------------------------------------------------------
110  protected void SetCameraIconColor(EEditorMode mode)
111  {
112  if (!m_EditorCore)
113  return;
114 
115  SCR_EditorModeUIInfo modeUiInfo = m_EditorCore.GetDefaultModeInfo(mode);
116  if (modeUiInfo)
117  m_CameraIconColor = modeUiInfo.GetModeColor();
118  else if (m_EditorCore.GetDefaultModeInfo(EEditorMode.EDIT))
119  m_CameraIconColor = m_EditorCore.GetDefaultModeInfo(EEditorMode.EDIT).GetModeColor();
120  }
121 
122  //------------------------------------------------------------------------------------------------
123  protected void OnEditorCameraCreate(SCR_ManualCamera editorCamera)
124  {
125  if (!m_MapEntity || !editorCamera)
126  return;
127 
128  m_EditorCamera = editorCamera;
129 
130  if (m_EditorCamera)
131  m_EditorCamera.SetInputEnabled(!IsEditorMapOpen());
132  }
133 
134  //------------------------------------------------------------------------------------------------
135  protected void OnMenuUpdate()
136  {
137  if (IsEditorMapOpen())
138  m_InputManager.ActivateContext("MapContext");
139  }
140 
141  //------------------------------------------------------------------------------------------------
142  override void HandlerAttachedScripted(Widget w)
143  {
144  super.HandlerAttachedScripted(w);
145 
146  if (SCR_Global.IsEditMode())
147  return;
148 
149  m_InputManager = GetGame().GetInputManager();
150  if (!m_InputManager)
151  return;
152 
153  m_MapEntity = SCR_MapEntity.GetMapInstance();
154  if (!m_MapEntity)
155  return;
156 
157  m_MapEntity.GetOnMapInit().Insert(OnMapInit);
158  m_MapEntity.GetOnMapOpen().Insert(OnMapOpen);
159  m_MapEntity.GetOnMapClose().Insert(OnMapClose);
160 
162  if (!m_EditorManager)
163  return;
164 
165  m_EditorManager.GetOnModeChange().Insert(OnEditorModeChange);
166 
167  m_EditorMapManager = SCR_MapEditorComponent.Cast(SCR_MapEditorComponent.GetInstance(SCR_MapEditorComponent));
168  if (!m_EditorMapManager)
169  return;
170 
171  m_MapWidget = w;
172 
173  m_EditorMapManager.SetMapHandler(this);
174  m_EditorMapConfigPrefab = m_EditorMapManager.GetMapConfigPrefab();
175 
176  m_EditorCore = SCR_EditorManagerCore.Cast(SCR_EditorManagerCore.GetInstance(SCR_EditorManagerCore));
177 
178  GetMenu().GetOnMenuUpdate().Insert(OnMenuUpdate);
179 
180  OnEditorModeChange(m_EditorManager.GetCurrentModeEntity(), null);
181  }
182 
183  //------------------------------------------------------------------------------------------------
184  override void HandlerDeattached(Widget w)
185  {
186  if (SCR_Global.IsEditMode())
187  return;
188 
189  super.HandlerDeattached(w);
190 
191  if (IsEditorMapOpen())
192  ToggleMap(false, m_EditorMapConfigPrefab);
193 
194  if (GetMenu())
195  GetMenu().GetOnMenuUpdate().Remove(OnMenuUpdate);
196  }
197 }
SCR_ManualCamera
Definition: SCR_ManualCamera.c:16
m_MapEntity
protected SCR_MapEntity m_MapEntity
Definition: SCR_MapGadgetComponent.c:14
m_bIsFirstTimeOpened
protected bool m_bIsFirstTimeOpened
Definition: SCR_MapGadgetComponent.c:13
m_InputManager
protected InputManager m_InputManager
Definition: SCR_BaseManualCameraComponent.c:15
SCR_MapEditorUIComponent
Definition: SCR_MapEditorUIComponent.c:1
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_CameraEditorComponent
Definition: SCR_CameraEditorComponent.c:13
SCR_EditorModeEntity
Definition: SCR_EditorModeEntity.c:22
GetMenu
SCR_RadialMenu GetMenu()
Definition: SCR_RadialMenuGameModeComponent.c:41
SCR_MapEditorComponent
Definition: SCR_MapEditorComponent.c:9
SCR_EditorManagerCore
Core component to manage SCR_EditorManagerEntity.
Definition: SCR_EditorManagerCore.c:5
SCR_MapEntity
Map entity.
Definition: SCR_MapEntity.c:20
m_EditorManager
protected SCR_EditorManagerEntity m_EditorManager
Definition: SCR_VotingEditor.c:5
EEditorMode
EEditorMode
Editor mode that defines overall functionality.
Definition: EEditorMode.c:5
SCR_BaseEditorUIComponent
Definition: SCR_BaseEditorUIComponent.c:3
SCR_Global
Definition: Functions.c:6
EMapEntityMode
EMapEntityMode
Mode of the map.
Definition: SCR_MapConstants.c:28
SCR_EditorModeUIInfo
Definition: SCR_EditorModeUIInfo.c:2
SCR_EditorManagerEntity
Definition: SCR_EditorManagerEntity.c:26