Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_VoiceoverSystem.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
3 {
4  protected ref ScriptInvokerVoid m_OnFinished;
5 
6  protected ref SCR_VoiceoverData m_Data;
7 
8  protected ref SCR_VoiceoverSubtitles m_SubtitlesDisplay;
9 
10  protected ref array<ref SCR_VoiceoverLine> m_aQueue = {};
11  protected ref array<IEntity> m_aActors = {};
12 
13  protected SCR_CommunicationSoundComponent m_PlayingSoundComponent;
14 
15  protected AudioHandle m_iAudioHandle;
16 
17  protected float m_fTimer;
18 
19  protected static const float PAUSE_BETWEEN_LINES = 0.5;
20 
21  //------------------------------------------------------------------------------------------------
22  override event protected void OnUpdate(ESystemPoint point)
23  {
24  if (!m_PlayingSoundComponent)
25  {
26  m_fTimer = 0;
27  Enable(false);
28  OnFinished();
29  return;
30  }
31 
32  if (!m_PlayingSoundComponent.IsFinishedPlaying(m_iAudioHandle))
33  return;
34 
35  if (m_aQueue.IsEmpty())
36  {
37  m_fTimer = 0;
38  Enable(false);
39  OnFinished();
40  }
41  else
42  {
43  m_fTimer += GetWorld().GetFixedTimeSlice();
44 
45  if (m_fTimer >= PAUSE_BETWEEN_LINES)
46  {
47  m_fTimer = 0;
48  PlayFromQueue();
49  }
50  }
51  }
52 
53  //------------------------------------------------------------------------------------------------
54  override event bool ShouldBePaused()
55  {
56  return true;
57  }
58 
59  //------------------------------------------------------------------------------------------------
60  static SCR_VoiceoverSystem GetInstance()
61  {
62  World world = GetGame().GetWorld();
63 
64  if (!world)
65  return null;
66 
67  return SCR_VoiceoverSystem.Cast(world.FindSystem(SCR_VoiceoverSystem));
68  }
69 
70  //------------------------------------------------------------------------------------------------
72  ScriptInvokerVoid GetOnFinished()
73  {
74  if (!m_OnFinished)
75  m_OnFinished = new ScriptInvokerVoid();
76 
77  return m_OnFinished;
78  }
79 
80  //------------------------------------------------------------------------------------------------
83  void SetData(ResourceName config)
84  {
85  Resource container = BaseContainerTools.LoadContainer(config);
86  m_Data = SCR_VoiceoverData.Cast(BaseContainerTools.CreateInstanceFromContainer(container.GetResource().ToBaseContainer()));
87  }
88 
89  //------------------------------------------------------------------------------------------------
90  bool IsPlaying()
91  {
92  return IsEnabled();
93  }
94 
95  //------------------------------------------------------------------------------------------------
97  // \param sequenceName Name of the sequence as defined in SCR_VoiceoverData
98  // \param actor1 Entity playing the voiceover as defined in SCR_VoiceoverData by ACTOR enum (default: player character)
99  void PlaySequence(string sequenceName, IEntity actor1 = null, IEntity actor2 = null, IEntity actor3 = null, IEntity actor4 = null, IEntity actor5 = null)
100  {
101  if (!m_Data)
102  return;
103 
104  SCR_VoiceoverSequence sequence = m_Data.GetSequenceByName(sequenceName);
105 
106  if (!sequence)
107  return;
108 
109  sequence.GetLines(m_aQueue);
110  m_aActors = {actor1, actor2, actor3, actor4, actor5};
111 
112  PlayFromQueue();
113  }
114 
115  //------------------------------------------------------------------------------------------------
117  // \param lineName Name of the line as defined in SCR_VoiceoverData
118  // \param actor1 Entity playing the voiceover as defined in SCR_VoiceoverData by ACTOR enum (default: player character)
119  void PlayLine(string lineName, IEntity actor1 = null, IEntity actor2 = null, IEntity actor3 = null, IEntity actor4 = null, IEntity actor5 = null)
120  {
121  if (!m_Data)
122  return;
123 
124  SCR_VoiceoverLineStandalone line = m_Data.GetLineByName(lineName);
125 
126  if (!line)
127  return;
128 
129  m_aQueue = {line};
130  m_aActors = {actor1, actor2, actor3, actor4, actor5};
131 
132  PlayFromQueue();
133  }
134 
135  //------------------------------------------------------------------------------------------------
137  // \param soundEventName Sound event name as defined in the appropriate .acp file in the actor's SCR_CommunicationSoundComponent
138  // \param actor Entity playing the voiceover (default: player character)
139  void PlayCustomLine(string soundEventName, string subtitle, IEntity actor = null)
140  {
141  PlayLine(soundEventName, subtitle, actor);
142  }
143 
144  //------------------------------------------------------------------------------------------------
145  void Stop()
146  {
147  if (m_PlayingSoundComponent && m_iAudioHandle != AudioHandle.Invalid)
148  m_PlayingSoundComponent.Terminate(m_iAudioHandle);
149 
150  m_iAudioHandle = AudioHandle.Invalid;
151  }
152 
153  //------------------------------------------------------------------------------------------------
154  protected void PlayFromQueue()
155  {
156  if (m_aQueue.IsEmpty())
157  return;
158 
159  SCR_VoiceoverLine line = m_aQueue[0];
160  m_aQueue.RemoveOrdered(0);
161 
162  PlayLine(line.GetSoundEventName(), line.GetSubtitleText(), m_aActors[line.GetActor()]);
163  }
164 
165  //------------------------------------------------------------------------------------------------
166  protected void PlayLine(string eventName, string subtitle, IEntity actor = null)
167  {
168  if (!actor)
169  actor = GetDefaultActor();
170 
171  if (!actor)
172  return;
173 
174  m_PlayingSoundComponent = SCR_CommunicationSoundComponent.Cast(actor.FindComponent(SCR_CommunicationSoundComponent));
175 
176  if (!m_PlayingSoundComponent)
177  return;
178 
179  if (m_iAudioHandle != AudioHandle.Invalid)
180  AudioSystem.TerminateSound(m_iAudioHandle);
181 
182  m_iAudioHandle = m_PlayingSoundComponent.SoundEvent(eventName);
183 
184  if (m_iAudioHandle != AudioHandle.Invalid)
185  {
186  ShowSubtitle(subtitle);
187  Enable(true);
188  }
189  }
190 
191  //------------------------------------------------------------------------------------------------
192  protected void ShowSubtitle(string subtitle)
193  {
194  if (!m_SubtitlesDisplay)
195  {
196  SCR_HUDManagerComponent hudManager = GetGame().GetHUDManager();
197 
198  if (!hudManager)
199  return;
200 
201  m_SubtitlesDisplay = SCR_VoiceoverSubtitles.Cast(hudManager.FindInfoDisplay(SCR_VoiceoverSubtitles));
202 
203  if (!m_SubtitlesDisplay)
204  return;
205  }
206 
207  GetGame().GetCallqueue().Remove(m_SubtitlesDisplay.Show);
208  m_SubtitlesDisplay.ShowSubtitle(subtitle);
209  }
210 
211  //------------------------------------------------------------------------------------------------
212  protected IEntity GetDefaultActor()
213  {
214  PlayerController pc = GetGame().GetPlayerController();
215 
216  if (!pc)
217  return null;
218 
219  return pc.GetControlledEntity();
220  }
221 
222  //------------------------------------------------------------------------------------------------
223  protected void OnFinished()
224  {
225  m_iAudioHandle = AudioHandle.Invalid;
226 
227  if (m_OnFinished)
228  m_OnFinished.Invoke();
229 
230  if (!m_SubtitlesDisplay)
231  return;
232 
233  GetGame().GetCallqueue().Remove(m_SubtitlesDisplay.Show);
234 
235  // Hide the subtitle after desired delay
236  GetGame().GetCallqueue().CallLater(m_SubtitlesDisplay.Show, SCR_VoiceoverSubtitles.GetLingerDuration() * 1000, false, false, UIConstants.FADE_RATE_INSTANT, EAnimationCurve.LINEAR);
237  }
238 }
SCR_HUDManagerComponent
Definition: SCR_HUDManagerComponent.c:23
UIConstants
Definition: Constants.c:130
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
m_fTimer
protected float m_fTimer
Definition: SCR_CampaignMilitaryBaseComponent.c:94
SCR_VoiceoverSubtitles
Definition: SCR_VoiceoverSubtitles.c:2
Enable
void Enable(bool enable)
Definition: SCR_TabViewComponent.c:806
GameSystem
Definition: GameSystem.c:12
IsEnabled
int IsEnabled()
Definition: SCR_BaseManualCameraComponent.c:99
SCR_VoiceoverData
Definition: SCR_VoiceoverData.c:3
SCR_VoiceoverLine
Definition: SCR_VoiceoverData.c:62
ScriptInvokerVoid
ScriptInvokerBase< ScriptInvokerVoidMethod > ScriptInvokerVoid
Definition: SCR_ScriptInvokerHelper.c:9
SCR_VoiceoverSystem
Definition: SCR_VoiceoverSystem.c:2