Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_CompositionInfoHandlerComponent.c
Go to the documentation of this file.
1//#define COMPOSITION_INFO_EVERYWHERE
2
7
8class SCR_CompositionInfoHandlerComponent : ScriptComponent
9{
10 [Attribute("ToggleCompositionReporting")]
11 protected string m_sToggleInfoAction;
12
13 [Attribute("#AR-EditorToggle_LoadingText_Text")]
14 protected string m_sAuthorNameLoading;
15
16 [Attribute("#AR-CoreMenus_Tooltips_Unavailable")]
17 protected string m_sAuthorNameFailed;
18
19 [Attribute("ReportUser")]
20 protected string m_sReportUserAction;
21
22 [Attribute("CompositionInfoContext")]
23 protected string m_sActionContext;
24
25 [Attribute("20")]
26 protected float m_fTraceDistance;
27
28 protected bool m_ReportingActive;
29 protected bool m_IsInit;
30 protected bool m_bNameUpdateRequested;
31
32 protected ref SCR_CompositionInfoDisplay m_CompositionInfoDisplay;
33 protected ref SCR_CompositionDetails m_CurrentDetails;
34
35 //------------------------------------------------------------------------------------------------
36 SCR_CompositionDetails TraceEditableEntity()
37 {
38 CameraBase camera = GetGame().GetCameraManager().CurrentCamera();
39 vector transform[4];
40 camera.GetTransform(transform);
41
42 vector position = camera.GetOrigin();
43 vector direction = transform[2];
44 direction.Normalize();
45 TraceParam trace = MakeTraceParam(position, position + (direction * m_fTraceDistance), TraceFlags.ENTS);
46 array<IEntity> exludedEntities = {};
47
48 IEntity excEnt = GetOwner();
49 if (excEnt)
50 exludedEntities.Insert(excEnt);
51
52 excEnt = SCR_PlayerController.Cast(excEnt).GetControlledEntity();
53 if (excEnt)
54 exludedEntities.Insert(excEnt);
55
56 trace.ExcludeArray = exludedEntities;
57
58 GetGame().GetWorld().TraceMove(trace, null);
59
60 IEntity traceEntity = trace.TraceEnt;
61 if (!traceEntity)
62 {
63 m_CurrentDetails = null;
64 return null;
65 }
66
67 traceEntity = SCR_EntityHelper.GetMainParent(traceEntity, true);
68
69 SCR_EditableEntityComponent editableEntity = SCR_EditableEntityComponent.Cast(traceEntity.FindComponent(SCR_EditableEntityComponent));
70 if (!editableEntity)
71 {
72 m_CurrentDetails = null;
73 return null;
74 }
75
76 vector line[2];
77 line[0] = position;
78 line[1] = position + (transform[3] * m_fTraceDistance);
79 Shape.CreateLines(Color.RED, ShapeFlags.NOZBUFFER, line, 1);
80
81 SCR_EditableEntityAuthor author = editableEntity.GetAuthor();
82 if (!author || author.m_sAuthorUID.IsEmpty())
83 {
84 m_CurrentDetails = null;
85 return null;
86 }
87
88 string oldName;
89 if (m_CurrentDetails)
90 oldName = m_CurrentDetails.m_sAuthorName;
91
92 m_CurrentDetails = new SCR_CompositionDetails(oldName, author.m_iAuthorID, author.m_sAuthorUID, author.m_ePlatform, editableEntity.GetDisplayName(), editableEntity.GetAuthorLastUpdated(), editableEntity.GetOwner().GetOrigin());
93
94 if (!m_bNameUpdateRequested && m_CurrentDetails.m_sAuthorName.IsEmpty())
95 {
96 Print("CompositionInfoHandler - Name Cache Update Requested!", LogLevel.VERBOSE);
97
98 m_bNameUpdateRequested = true;
99 m_CompositionInfoDisplay.UpdateName(m_sAuthorNameLoading);
100
101 PlayerManager.s_OnPlayerNameCacheUpdateInvoker.Insert(OnNameCacheUpdated);
102 PlayerManager.RequestPlayerNameCacheUpdate({author.m_sAuthorUID});
103 }
104
105 return m_CurrentDetails;
106 }
107
108 //------------------------------------------------------------------------------------------------
109 protected void OnNameCacheUpdated(bool success)
110 {
111 if (success)
112 {
113 Print("CompositionInfoHandler - Name Cache Updated", LogLevel.VERBOSE);
114 }
115 else
116 {
117 Print("CompositionInfoHandler - Name Cache Update failed!", LogLevel.VERBOSE);
118 }
119
120 m_bNameUpdateRequested = false;
121 PlayerManager.s_OnPlayerNameCacheUpdateInvoker.Remove(OnNameCacheUpdated);
122
123 if (!m_CurrentDetails)
124 return;
125
126 PlayerManager pm = GetGame().GetPlayerManager();
127
128 if (!m_CurrentDetails.m_sAuthorUID.IsEmpty())
129 {
130 // Even if the request failed, we should try to do lookup by IdentityId first
131 m_CurrentDetails.m_sAuthorName = pm.GetPlayerNameByIdentity(m_CurrentDetails.m_sAuthorUID);
132 }
133 else
134 {
135 m_CurrentDetails.m_sAuthorName = pm.GetPlayerName(m_CurrentDetails.m_iAuthorID);
136 }
137
138 if (m_CurrentDetails.m_sAuthorName.IsEmpty())
139 {
140 m_CurrentDetails.m_sAuthorName = m_sAuthorNameFailed;
141 }
142
143 m_CompositionInfoDisplay.UpdateName(m_CurrentDetails.m_sAuthorName);
144 }
145
146 //--- EVENTS ---//
147 //------------------------------------------------------------------------------------------------
148 protected void OnReportingToggle()
149 {
150 if (!m_IsInit)
151 return;
152
153 m_ReportingActive = !m_ReportingActive;
154
155 // Disabled Reporting
156 //InputManager im = GetGame().GetInputManager();
157 //if (im && m_ReportingActive)
158 // im.AddActionListener(m_sReportUserAction, EActionTrigger.PRESSED, OnReportUser);
159 //else if (im)
160 // im.RemoveActionListener(m_sReportUserAction, EActionTrigger.PRESSED, OnReportUser);
161
162 if (m_CompositionInfoDisplay)
163 return;
164
166 if (!hudManager)
167 return;
168
169 SCR_InfoDisplay displayCandidate = hudManager.FindInfoDisplay(SCR_CompositionInfoDisplay);
170 if (!displayCandidate)
171 return;
172
173 m_CompositionInfoDisplay = SCR_CompositionInfoDisplay.Cast(displayCandidate);
174 }
175
176 //------------------------------------------------------------------------------------------------
177 protected void OnReportUser()
178 {
179 PlayerController pc = GetGame().GetPlayerController();
180 if (!pc)
181 return;
182
183 SocialComponent sc = SocialComponent.Cast(pc.FindComponent(SocialComponent));
184 if (!sc)
185 return;
186
187 if (!m_CurrentDetails.m_sAuthorName.IsEmpty() && !m_CurrentDetails.m_iAuthorID > -1)
188 {
189 sc.ReportPlayer(m_CurrentDetails.m_iAuthorID, SCR_EReportReason.NEGATIVE_ATTITUDE);
190 PrintFormat("Player: %1, with UID: %2. Was Reported", m_CurrentDetails.m_sAuthorName, m_CurrentDetails.m_iAuthorID, level: LogLevel.NORMAL);
191 m_CompositionInfoDisplay.ShowReported();
192 }
193 }
194
195 //------------------------------------------------------------------------------------------------
196 override protected void EOnFrame(IEntity owner, float timeSlice)
197 {
198 if (!m_IsInit)
199 return;
200
201 InputManager im = GetGame().GetInputManager();
202 if (!im)
203 return;
204
205 im.ActivateContext(m_sActionContext);
206
207 if (!m_CompositionInfoDisplay)
208 return;
209
210 m_CompositionInfoDisplay.Show(m_ReportingActive);
211
212 if (!m_ReportingActive)
213 return;
214
215 TraceEditableEntity();
216 m_CompositionInfoDisplay.UpdateCompositionDetails(m_CurrentDetails);
217 }
218
219 //------------------------------------------------------------------------------------------------
220 override protected void EOnInit(IEntity owner)
221 {
222#ifndef COMPOSITION_INFO_EVERYWHERE
223 PlatformService ps = GetGame().GetPlatformService();
224 if (!ps || ps.GetLocalPlatformKind() != PlatformKind.PSN)
225 return;
226#endif
227
228 InputManager im = GetGame().GetInputManager();
229 if (!im)
230 return;
231
232 im.AddActionListener(m_sToggleInfoAction, EActionTrigger.DOWN, OnReportingToggle);
233 m_IsInit = true;
234 }
235
236 //------------------------------------------------------------------------------------------------
237 override protected void OnPostInit(IEntity owner)
238 {
239 SetEventMask(owner, EntityEvent.INIT | EntityEvent.FRAME);
240 }
241
242 //------------------------------------------------------------------------------------------------
243 override protected void OnDelete(IEntity owner)
244 {
245 if (!m_IsInit)
246 return;
247
248 InputManager im = GetGame().GetInputManager();
249 if (!im)
250 return;
251
252 im.RemoveActionListener(m_sToggleInfoAction, EActionTrigger.DOWN, OnReportingToggle);
253 }
254}
255
256class SCR_CompositionDetails
257{
258 string m_sAuthorName;
259 int m_iAuthorID;
260 string m_sAuthorUID;
261 PlatformKind m_ePlatform;
262 string m_sEntityName;
263 int m_iLastUpdated;
264 vector m_vPosition;
265
266 //------------------------------------------------------------------------------------------------
267 void SCR_CompositionDetails(string authorName, int authorID, string authorUID, PlatformKind platform, string entityName, int lastUpdated, vector position = vector.Zero)
268 {
269 m_sAuthorName = authorName;
270 m_iAuthorID = authorID;
271 m_sAuthorUID = authorUID;
272 m_ePlatform = platform;
273 m_sEntityName = entityName;
274 m_iLastUpdated = lastUpdated;
275 m_vPosition = position;
276 }
277}
ArmaReforgerScripted GetGame()
Definition game.c:1398
PlatformKind
Definition PlatformKind.c:8
void OnNameCacheUpdated(bool success)
vector direction
vector position
enum EVehicleType IEntity
proto external int SetEventMask(notnull IEntity owner, int mask)
proto external Managed FindComponent(typename typeName)
Input management system for user interactions.
SCR_InfoDisplay FindInfoDisplay(typename type)
Return hud component of given type.
static SCR_HUDManagerComponent GetHUDManager()
void EOnFrame(IEntity owner, float timeSlice)
proto external GenericEntity GetOwner()
Get owner entity.
void EOnInit(IEntity owner)
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
ShapeFlags
Definition ShapeFlags.c:13
proto void PrintFormat(string fmt, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL, LogLevel level=LogLevel.NORMAL)
SCR_FieldOfViewSettings Attribute
EntityEvent
Various entity events.
Definition EntityEvent.c:14
EActionTrigger
SCR_EReportReason
Player report reason.
enum PostProcessEffectType MakeTraceParam(vector start, vector end, TraceFlags flags)
Definition EnWorld.c:52
TraceFlags
Definition TraceFlags.c:13