Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ModesEditorUIComponent.c
Go to the documentation of this file.
1 
4 {
5  //Rename to active modes
6  protected ref array<EEditorMode> m_aActiveModes = {};
7  protected ref SCR_SortedArray<SCR_EditorModePrefab> m_aOrderedEditorModePrefabs = new SCR_SortedArray<SCR_EditorModePrefab>();
8  //Combobox
9  protected SCR_CustomDropdownEditorUIComponent m_DropdownWidget;
10 
11  protected SCR_EditorManagerEntity m_EditorManager;
12 
13 // //------------------------------------------------------------------------------------------------
14 // protected override bool IsUnique()
15 // {
16 // return false;
17 // }
18 
19  //------------------------------------------------------------------------------------------------
20  protected void OnModeAdd(SCR_EditorModeEntity modeEntity)
21  {
22  if (!modeEntity)
23  return;
24 
25  m_aActiveModes.Insert(modeEntity.GetModeType());
26  RefreshModes();
27  }
28 
29  //------------------------------------------------------------------------------------------------
30  protected void OnModeRemove(SCR_EditorModeEntity modeEntity)
31  {
32  if (!modeEntity)
33  return;
34 
35  int index = m_aActiveModes.Find(modeEntity.GetModeType());
36  if (index < 0)
37  return;
38 
39  m_aActiveModes.Remove(index);
40  RefreshModes();
41  }
42 
43  //------------------------------------------------------------------------------------------------
44  protected void CreateDropdown()
45  {
46  //m_DropdownWidget.ClearAll();
47  if (!m_EditorManager)
48  return;
49 
50  SCR_EditorModeEntity currentModeEntity = m_EditorManager.GetCurrentModeEntity();
51 
52  int count = m_aOrderedEditorModePrefabs.Count();
53 
54  for(int i = 0; i < count; ++i)
55  {
56  SCR_EditorModeUIInfo info = m_aOrderedEditorModePrefabs[i].GetInfo();
57 
58  if (info)
59  {
60  m_DropdownWidget.AddItem(info, info.GetModeColor());
61 
62  if (currentModeEntity && currentModeEntity.GetModeType() == m_aOrderedEditorModePrefabs[i].GetMode())
63  m_DropdownWidget.SetCurrentItem(i, false);
64  }
65 
66  }
67 
68  RefreshModes();
69  }
70 
71  //------------------------------------------------------------------------------------------------
72  protected void OnModeSelected(SCR_CustomDropdownEditorUIComponent dropdown, int index)
73  {
74  if (!m_EditorManager)
75  return;
76 
77  m_EditorManager.SetCurrentMode(m_aOrderedEditorModePrefabs[index].GetMode());
78  m_DropdownWidget.CloseDropdown();
79  }
80 
81  //------------------------------------------------------------------------------------------------
82  protected void OnModeChange(SCR_EditorModeEntity currentModeEntity, SCR_EditorModeEntity prevModeEntity)
83  {
84  //Close if dialog or close list if not (mainly for if mode is forced changed)
85  if (m_bIsInDialog)
86  CloseDialog();
87 
88  if (!m_EditorManager)
89  return;
90 
91  WorkspaceWidget workspace = GetGame().GetWorkspace();
92  if (workspace)
93  {
94  if (workspace.GetFocusedWidget() == m_DropdownWidget.GetRootWidget())
95  workspace.SetFocusedWidget(null);
96  }
97 
98  RefreshModes();
99  }
100 
101  //------------------------------------------------------------------------------------------------
102  protected void RefreshModes()
103  {
104  SCR_EditorModeEntity currentModeEntity = m_EditorManager.GetCurrentModeEntity();
105  if (!currentModeEntity)
106  return;
107 
108  int modeCount = 0;
109 
110  int count = m_aOrderedEditorModePrefabs.Count();
111  for(int i = 0; i < count; ++i)
112  {
113  m_DropdownWidget.SetItemVisible(i, m_aActiveModes.Contains(m_aOrderedEditorModePrefabs[i].GetMode()));
114 
115  if (!m_aActiveModes.Contains(m_aOrderedEditorModePrefabs[i].GetMode()))
116  continue;
117 
118  modeCount++;
119 
120  //Set combobox selected element
121  if (currentModeEntity.GetModeType() == m_aOrderedEditorModePrefabs[i].GetMode())
122  m_DropdownWidget.SetCurrentItem(i, false);
123  }
124 
125  //m_DropdownWidget.SetDropdownEnable(modeCount > 1);
126  }
127 
128  //------------------------------------------------------------------------------------------------
129  protected override void OnDialogOpened(SCR_DialogEditorUIComponent linkedComponent)
130  {
131  super.OnDialogOpened(linkedComponent);
132  //m_DropdownWidget.AllowFocus(true);
133 
134  int selected = 0;
135 
136  if (m_EditorManager)
137  {
138  EEditorMode currentMode = m_EditorManager.GetCurrentMode();
139  int count = m_aOrderedEditorModePrefabs.Count();
140 
141  for(int i = 0; i < count; ++i)
142  {
143  if (m_aOrderedEditorModePrefabs[i].GetMode() == currentMode)
144  {
145  selected = i;
146  break;
147  }
148  }
149 
150  }
151  }
152 
153  //------------------------------------------------------------------------------------------------
154  protected void SetSiblingMode(int relIndex)
155  {
156  if (!m_EditorManager || m_EditorManager.IsModeChangeRequested())
157  return;
158 
159  array<EEditorMode> modes = {};
160  int modesCount = m_EditorManager.GetModes(modes);
161  if (modesCount <= 1)
162  return;
163 
164  int index = modes.Find(m_EditorManager.GetCurrentMode()) + relIndex;
165  m_EditorManager.SetCurrentMode(modes[(index + modesCount) % modesCount])
166  }
167 
168  //------------------------------------------------------------------------------------------------
169  protected void OnEditorModePrev(float value, EActionTrigger reason)
170  {
171  SetSiblingMode(-1);
172  }
173 
174  //------------------------------------------------------------------------------------------------
175  protected void OnEditorModeNext(float value, EActionTrigger reason)
176  {
177  SetSiblingMode(1);
178  }
179 
180  //------------------------------------------------------------------------------------------------
181  override void OnRepeat()
182  {
183  if (m_EditorManager)
184  m_EditorManager.RestorePreviousMode();
185  }
186 
187  //------------------------------------------------------------------------------------------------
188  override void OnInputDeviceIsGamepad(bool isGamepad)
189  {
190  if (m_bIsInDialog)
191  CloseDialog();
192 
193  m_DropdownWidget.CloseDropdown();
194  }
195 
196  //------------------------------------------------------------------------------------------------
197  protected void OnDropdownOpen(SCR_CustomDropdownEditorUIComponent dropdown)
198  {
199  if (m_bIsInDialog)
200  m_CanCloseWithToggleAction = false;
201 
202  }
203 
204  //------------------------------------------------------------------------------------------------
205  protected void OnDropdownClosed(SCR_CustomDropdownEditorUIComponent dropdown)
206  {
207  if (m_bIsInDialog)
208  {
209  m_CanCloseWithToggleAction = true;
210  CloseDialog();
211  }
212  }
213 
214  //------------------------------------------------------------------------------------------------
215  override void HandlerAttachedScripted(Widget w)
216  {
217  super.HandlerAttachedScripted(w);
218 
220  if (!core)
221  return;
222 
224  if (!m_EditorManager)
225  return;
226 
227  m_DropdownWidget = SCR_CustomDropdownEditorUIComponent.Cast(w.FindHandler(SCR_CustomDropdownEditorUIComponent));
228  if (!m_DropdownWidget)
229  return;
230 
231  //~Hotfix for border always showing
232  Widget border = w.FindAnyWidget("Border");
233  if (border)
234  border.SetOpacity(0);
235 
236  m_DropdownWidget.GetOnChanged().Insert(OnModeSelected);
237  m_DropdownWidget.GetOnOpened().Insert(OnDropdownOpen);
238 
239  array<SCR_EditorModeEntity> modeEntities = {};
240  int modesCount = m_EditorManager.GetModeEntities(modeEntities);
241  for (int i = 0; i < modesCount; i++)
242  {
243  OnModeAdd(modeEntities[i]);
244  }
245 
246  //Create combobox
247  core.GetBaseModePrefabs(m_aOrderedEditorModePrefabs, -1, true);
248  CreateDropdown();
249 
250  SCR_EditorModeEntity currentModeEntity = m_EditorManager.GetCurrentModeEntity();
251 
252  m_EditorManager.GetOnModeAdd().Insert(OnModeAdd);
253  m_EditorManager.GetOnModeRemove().Insert(OnModeRemove);
254  m_EditorManager.GetOnModeChange().Insert(OnModeChange);
255 
256  InputManager inputManager = GetGame().GetInputManager();
257  if (inputManager)
258  {
259  inputManager.AddActionListener("EditorModePrev", EActionTrigger.PRESSED, OnEditorModePrev);
260  inputManager.AddActionListener("EditorModeNext", EActionTrigger.PRESSED, OnEditorModeNext);
261  }
262  }
263 
264  //------------------------------------------------------------------------------------------------
265  override void HandlerDeattached(Widget w)
266  {
267  super.HandlerDeattached(w);
268 
269  if (m_EditorManager)
270  {
271  m_EditorManager.GetOnModeAdd().Remove(OnModeAdd);
272  m_EditorManager.GetOnModeRemove().Remove(OnModeRemove);
273  m_EditorManager.GetOnModeChange().Remove(OnModeChange);
274  }
275 
276  InputManager inputManager = GetGame().GetInputManager();
277  if (inputManager)
278  {
279  inputManager.RemoveActionListener("EditorModePrev", EActionTrigger.PRESSED, OnEditorModePrev);
280  inputManager.RemoveActionListener("EditorModeNext", EActionTrigger.PRESSED, OnEditorModeNext);
281  }
282 
283  if (m_DropdownWidget)
284  {
285  m_DropdownWidget.GetOnChanged().Remove(OnModeSelected);
286  m_DropdownWidget.GetOnOpened().Remove(OnDropdownOpen);
287  m_DropdownWidget.GetOnClosed().Remove(OnDropdownClosed);
288  }
289  }
290 }
SCR_ModesEditorUIComponent
Definition: SCR_ModesEditorUIComponent.c:3
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_EditorModeEntity
Definition: SCR_EditorModeEntity.c:22
SCR_EditorManagerCore
Core component to manage SCR_EditorManagerEntity.
Definition: SCR_EditorManagerCore.c:5
SCR_CustomDropdownEditorUIComponent
Definition: SCR_CustomDropdownEditorUIComponent.c:1
m_EditorManager
protected SCR_EditorManagerEntity m_EditorManager
Definition: SCR_VotingEditor.c:5
EEditorMode
EEditorMode
Editor mode that defines overall functionality.
Definition: EEditorMode.c:5
index
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Definition: SCR_DestructionSynchronizationComponent.c:17
SCR_DialogEditorUIComponent
Definition: SCR_DialogEditorUIComponent.c:3
SCR_EditorModeUIInfo
Definition: SCR_EditorModeUIInfo.c:2
SCR_EditorManagerEntity
Definition: SCR_EditorManagerEntity.c:26