Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_VehicleEditableEntityUIComponent.c
Go to the documentation of this file.
2 {
3  [Attribute(defvalue: "Name")]
4  protected string m_sNameTextWidgetName;
5 
6  [Attribute(defvalue: "#AR-Editor_PlayerVehicle_Name")]
7  protected string m_sVehicleNameText;
8 
9  protected RichTextWidget m_wNameTextWidget;
10 
11  protected SCR_EditableVehicleComponent m_VehicleComponent;
12  protected SCR_EditableCharacterComponent m_VehicleOwningPlayer;
13  protected BaseWorld m_World;
14 
15  protected SCR_RenderedEditableEntityFilter m_RenderFilter;
16 
17  //------------------------------------------------------------------------------------------------
19  void DetermineNameVisibility()
20  {
21  if (!m_World || !m_VehicleComponent || !m_VehicleOwningPlayer || !m_wNameTextWidget || !m_RenderFilter)
22  return;
23 
24  vector cameraMatrix[4];
25  vector playerPosition;
26  float playerMaxViewDistance = m_VehicleOwningPlayer.GetMaxDrawDistanceSq();
27 
28  m_VehicleOwningPlayer.GetPos(playerPosition);
29  m_World.GetCurrentCamera(cameraMatrix);
30 
31  float distanceSquared = vector.DistanceSq(playerPosition, cameraMatrix[3]);
32 
33  if (distanceSquared < playerMaxViewDistance * m_RenderFilter.GetCameraDisCoef())
34  m_wNameTextWidget.SetVisible(false);
35  else
36  m_wNameTextWidget.SetVisible(true);
37  }
38 
39  //------------------------------------------------------------------------------------------------
41  {
42  m_wNameTextWidget = RichTextWidget.Cast(GetWidget().FindAnyWidget(m_sNameTextWidgetName));
43  if (!m_wNameTextWidget)
44  {
45  Print("SCR_VehicleEditableEntityUIComponent: Failed to find Name Widget: " + m_sNameTextWidgetName, LogLevel.ERROR);
46  return;
47  }
48 
49  m_World = GetGame().GetWorld();
51  if (entitiesManager)
52  m_RenderFilter = SCR_RenderedEditableEntityFilter.Cast(entitiesManager.GetFilter(EEditableEntityState.RENDERED));
53 
54  OnRefresh(slot);
55  }
56 
57  //------------------------------------------------------------------------------------------------
58  override void OnRefresh(SCR_EditableEntityBaseSlotUIComponent slot)
59  {
60  if (!slot)
61  return;
62 
63  if (!m_VehicleComponent)
64  {
65  m_VehicleComponent = SCR_EditableVehicleComponent.Cast(slot.GetEntity());
66  if (!m_VehicleComponent)
67  return;
68  }
69 
70  int playerID = m_VehicleComponent.GetPlayerID();
71  if (playerID <= 0)
72  return;
73 
74  PlayerManager playerManager = GetGame().GetPlayerManager();
75  IEntity playerEntity = playerManager.GetPlayerControlledEntity(playerID);
76  if (playerEntity)
77  m_VehicleOwningPlayer = SCR_EditableCharacterComponent.Cast(playerEntity.FindComponent(SCR_EditableCharacterComponent));
78 
79  string playerName = playerManager.GetPlayerName(playerID);
80  int playerCount = m_VehicleComponent.GetPlayerCountInVehicle();
81 
82  if (playerCount > 1)
83  m_wNameTextWidget.SetTextFormat(m_sVehicleNameText, playerName, playerCount - 1);
84  else
85  m_wNameTextWidget.SetText(playerName);
86  }
87 
88  //------------------------------------------------------------------------------------------------
89  override bool OnUpdate(Widget w)
90  {
91  // Making changes to the Widget during OnUpdate() isn't advised by Peter Čimo.
92  GetGame().GetCallqueue().CallLater(DetermineNameVisibility, 0, false);
93 
94  return false;
95  }
96 }
EEditableEntityState
EEditableEntityState
Definition: EEditableEntityState.c:37
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_EntitiesManagerEditorComponent
Definition: SCR_EntitiesManagerEditorComponent.c:13
SCR_EditableEntityBaseSlotUIComponent
Definition: SCR_EditableEntityBaseSlotUIComponent.c:6
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_RenderedEditableEntityFilter
Definition: SCR_RenderedEditableEntityFilter.c:7
m_World
protected BaseWorld m_World
Definition: SCR_PreviewEntityEditorUIComponent.c:46
SCR_BaseEditableEntityUIComponent
Definition: SCR_BaseEditableEntityUIComponent.c:8
SCR_VehicleEditableEntityUIComponent
Definition: SCR_VehicleEditableEntityUIComponent.c:1
SCR_UIInfo
Definition: SCR_UIInfo.c:7
SCR_EditableEntityComponent
Definition: SCR_EditableEntityComponent.c:13
PlayerManager
Definition: PlayerManager.c:12
GetWidget
protected Widget GetWidget()
Definition: SCR_VonDisplay.c:155