Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AdjustSpeedManualCameraComponent.c
Go to the documentation of this file.
1 
4 [BaseContainerProps(), SCR_BaseManualCameraComponentTitle()]
6 {
7  [Attribute("0.1")]
8  protected float m_fMinMultiplier;
9 
10  [Attribute("16")]
11  protected float m_fMaxMultiplier;
12 
13  [Attribute(params: "layout")]
14  protected ResourceName m_Layout;
15 
16  [Attribute("3")]
17  protected float m_fLayoutDuration;
18 
19  protected float m_fMultiplier = 1;
20  protected TextWidget m_Widget;
21  protected float m_fWidgetAlpha;
22  protected ref ScriptInvoker m_OnSpeedChange = new ScriptInvoker();
23 
24  //------------------------------------------------------------------------------------------------
27  ScriptInvoker GetOnSpeedChange()
28  {
29  return m_OnSpeedChange;
30  }
31 
32  //------------------------------------------------------------------------------------------------
33  protected void OnInputDeviceIsGamepad(bool isGamepad)
34  {
35  m_fMultiplier = 1;
36  m_OnSpeedChange.Invoke(m_fMultiplier, false);
37  m_Widget.SetVisible(false);
38  }
39 
40  //------------------------------------------------------------------------------------------------
41  protected void ManualCameraSpeedReset(float value, EActionTrigger trigger)
42  {
43  if (!IsEnabled() || !(GetCameraEntity().GetCameraParam().flag & EManualCameraFlag.ROTATE)) return;
44 
45  m_fMultiplier = 1;
46  m_OnSpeedChange.Invoke(m_fMultiplier, true);
47  UpdateWidget();
48  }
49 
50  //------------------------------------------------------------------------------------------------
51  protected void UpdateWidget()
52  {
53  if (!m_Widget) return;
54 
55 
56  // if min value is very low, e.g. 0.001, then the hardcoded decimal value will not display all data,
57  // so we dynamically adjust the displayed precision as we go below 1.0, based on min value
58  int dec = 10;
59  if (m_fMinMultiplier > 0 && m_fMultiplier < 1.0)
60  dec = Math.Round(1.0 / Math.Clamp(m_fMinMultiplier, 0.0, 1.0));
61 
62  m_Widget.SetTextFormat("#AR-ValueUnit_Short_Multiplier", Math.Round(m_fMultiplier * dec) / dec);
63  m_Widget.SetVisible(true);
64  m_fWidgetAlpha = 1 + m_fLayoutDuration;
65  }
66 
67  //------------------------------------------------------------------------------------------------
68  protected void FadeOutWidget(float timeSlice)
69  {
70  if (!m_Widget || !m_Widget.IsVisible()) return;
71 
72  m_fWidgetAlpha -= timeSlice;
73  if (m_fWidgetAlpha > 0)
74  {
75  m_Widget.SetOpacity(Math.Clamp(m_fWidgetAlpha, 0, 1));
76  }
77  else
78  {
79  m_Widget.SetVisible(false);
80  }
81  }
82 
83  //------------------------------------------------------------------------------------------------
84  override void EOnCameraSave(SCR_ManualCameraComponentSave data)
85  {
86  data.m_aValues = {m_fMultiplier};
87  }
88 
89  //------------------------------------------------------------------------------------------------
90  override void EOnCameraLoad(SCR_ManualCameraComponentSave data)
91  {
92  if (data.m_aValues && !data.m_aValues.IsEmpty())
93  {
94  m_fMultiplier = data.m_aValues[0];
95  m_OnSpeedChange.Invoke(m_fMultiplier, true);
96  }
97  }
98 
99  //------------------------------------------------------------------------------------------------
100  override void EOnCameraFrame(SCR_ManualCameraParam param)
101  {
102  if (!param.isManualInputEnabled)
103  {
104  if (m_Widget)
105  m_Widget.SetVisible(false);
106 
107  return;
108  }
109 
110  //--- Adjust
111  if (param.flag & EManualCameraFlag.ROTATE)
112  {
113  float inputValue = GetInputManager().GetActionValue("ManualCameraSpeedAdjust");
114  if (inputValue != 0)
115  {
116  inputValue = Math.Clamp(1 + inputValue * param.timeSlice, 0.5, 2);
117  m_fMultiplier = Math.Clamp(m_fMultiplier * inputValue, m_fMinMultiplier, m_fMaxMultiplier);
118  m_OnSpeedChange.Invoke(m_fMultiplier, true);
119  UpdateWidget();
120  }
121  }
122 
123  //--- Apply
124  param.multiplier *= m_fMultiplier;
125 
126  //--- Visualize
127  FadeOutWidget(param.timeSlice);
128  }
129 
130  //------------------------------------------------------------------------------------------------
131  override bool EOnCameraInit()
132  {
133  if (m_fMinMultiplier > 1 || m_fMaxMultiplier < 1)
134  {
135  Print("Value range in SCR_AdjustSpeedManualCameraComponent must contain 1!", LogLevel.ERROR);
136  }
137  GetGame().OnInputDeviceIsGamepadInvoker().Insert(OnInputDeviceIsGamepad);
138 
139  GetInputManager().AddActionListener("ManualCameraSpeedReset", EActionTrigger.DOWN, ManualCameraSpeedReset);
140 
141  m_Widget = TextWidget.Cast(GetCameraEntity().CreateCameraWidget(m_Layout, false));
142  return true;
143  }
144 
145  //------------------------------------------------------------------------------------------------
146  override void EOnCameraExit()
147  {
148  GetGame().OnInputDeviceIsGamepadInvoker().Remove(OnInputDeviceIsGamepad);
149 
150  GetInputManager().RemoveActionListener("ManualCameraSpeedReset", EActionTrigger.DOWN, ManualCameraSpeedReset);
151 
152  if (m_Widget) m_Widget.RemoveFromHierarchy();
153  }
154 }
SCR_BaseManualCameraComponent
Parent class from which all SCR_ManualCamera components inherit.
Definition: SCR_BaseManualCameraComponent.c:5
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
m_Layout
ResourceName m_Layout
Definition: SCR_ActionsToolbarEditorUIComponent.c:6
EManualCameraFlag
EManualCameraFlag
Definition: EManualCameraFlag.c:7
Attribute
typedef Attribute
Post-process effect of scripted camera.
IsEnabled
int IsEnabled()
Definition: SCR_BaseManualCameraComponent.c:99
SCR_ManualCameraComponentSave
Definition: SCR_ManualCameraSave.c:15
GetCameraEntity
protected SCR_ManualCamera GetCameraEntity()
Definition: SCR_BaseManualCameraComponent.c:59
SCR_ManualCameraParam
Parameter for carrying information between individual camera components.
Definition: SCR_ManualCameraParam.c:5
SCR_AdjustSpeedManualCameraComponent
Adjusting speed at small increments for manual camera.
Definition: SCR_AdjustSpeedManualCameraComponent.c:5
GetInputManager
protected InputManager GetInputManager()
Definition: SCR_BaseManualCameraComponent.c:65
m_fMultiplier
float m_fMultiplier
Definition: SCR_DamagePassRule.c:12
data
Get all prefabs that have the spawner data
Definition: SCR_EntityCatalogManagerComponent.c:305
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
BaseContainerProps
SCR_AIGoalReaction_Follow BaseContainerProps
Handles insects that are supposed to be spawned around selected prefabs defined in prefab names array...
Definition: SCR_AIGoalReaction.c:468