Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_NTTextBase.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
5 {
6  [Attribute("14", UIWidgets.CheckBox, "Scaled text size at the beginning of the zone \n pixels")]
7  protected int m_fTextSizeMax;
8 
9  [Attribute("14", UIWidgets.CheckBox, "Scaled text size at the end of the zone \n pixels")]
10  protected int m_fTextSizeMin;
11 
12  [Attribute("{E2CBA6F76AAA42AF}UI/Fonts/Roboto/Roboto_Regular.fnt", UIWidgets.ResourceNamePicker, desc: "Font type", params: "fnt")]
13  protected ResourceName m_FontResource;
14 
15  //------------------------------------------------------------------------------------------------
20  protected void GetText(SCR_NameTagData data, out string name, out notnull array<string> nameParams)
21  {
22  return;
23  }
24 
25  //------------------------------------------------------------------------------------------------
28  protected void SetText(SCR_NameTagData data, string text, notnull array<string> nameParams, int index)
29  {
30  if (!data.m_aNametagElements[index])
31  return;
32 
33  int paramsCount = nameParams.Count();
34 
35  if (paramsCount == 0)
36  TextWidget.Cast( data.m_aNametagElements[index] ).SetText(text);
37  else if (paramsCount == 3)
38  TextWidget.Cast( data.m_aNametagElements[index] ).SetTextFormat(text, nameParams[0], nameParams[1], nameParams[2]);
39  else
40  {
41  Print(string.Format("'SCR_NTTextBase' does not support nameParams of count '%1'!", paramsCount), LogLevel.ERROR);
42  TextWidget.Cast( data.m_aNametagElements[index] ).SetText(text);
43  }
44 
45  }
46 
47  //------------------------------------------------------------------------------------------------
48  override protected void ScaleElement(SCR_NameTagData data, int index)
49  {
50  Widget widget = data.m_aNametagElements[index];
51  if (!widget)
52  return;
53 
54  //At least one zone always need to be defined
55  SCR_NameTagZone zone = SCR_NameTagDisplay.GetNametagZones().Get(data.m_iZoneID);
56  if (!zone)
57  return;
58 
59  float diff = m_fTextSizeMax - m_fTextSizeMin;
60 
61  // avoid 0 as a starting point
62  int zoneStart = zone.GetZoneStart();
63  if ( zoneStart < 1 )
64  zoneStart = 1;
65 
66  float lerp = Math.InverseLerp(zoneStart, zone.m_iZoneEnd, data.m_fDistance);
67  diff = diff * lerp;
68 
69  float x = FrameSlot.GetSizeX(widget);
70  float y = FrameSlot.GetSizeY(widget);
71  float ratio = x / y;
72 
73  float scaledY = m_fTextSizeMax - diff;
74 
75  FrameSlot.SetSizeY(widget, scaledY);
76  FrameSlot.SetSizeX(widget, scaledY * ratio);
77  }
78 
79  //------------------------------------------------------------------------------------------------
80  override void SetDefaults(SCR_NameTagData data, int index)
81  {
82  TextWidget tWidget = TextWidget.Cast( data.m_aNametagElements[index] );
83  if (!tWidget)
84  return;
85 
86  SCR_NTStateText stateConf = SCR_NTStateText.Cast( GetEntityStateConfig(data) );
87  if (!stateConf)
88  return;
89 
90  tWidget.SetFont(m_FontResource);
91 
92  if (!m_bScaleElement)
93  tWidget.SetExactFontSize(m_fTextSizeMax);
94 
95  tWidget.SetColor(stateConf.m_vColor);
96  tWidget.SetShadow( stateConf.m_fShadowSize, stateConf.m_vShadowColor.PackToInt(), stateConf.m_fShadowOpacity, 0, 0);
97 
98  data.SetVisibility(tWidget, stateConf.m_fOpacityDefault != 0, stateConf.m_fOpacityDefault, stateConf.m_bAnimateTransition); // transitions
99  }
100 };
101 
102 //------------------------------------------------------------------------------------------------
106 {
107  //------------------------------------------------------------------------------------------------
108  override void GetText(SCR_NameTagData data, out string name, out notnull array<string> nameParams)
109  {
110  data.GetName(name, nameParams);
111  }
112 
113  //------------------------------------------------------------------------------------------------
114  override void UpdateElement(SCR_NameTagData data, int index)
115  {
116  super.UpdateElement(data, index);
117 
118  if (data.m_Flags & ENameTagFlags.NAME_UPDATE)
119  {
120  if (data.m_Flags & ENameTagFlags.ENT_TYPE_UPDATE)
121  {
122  data.UpdateEntityType();
123  data.m_Flags &= ~ENameTagFlags.ENT_TYPE_UPDATE;
124  }
125 
126  string name;
127  array<string> nameParams = {};
128 
129  GetText(data, name, nameParams);
130 
131  if (name == string.Empty)
132  SetText(data, "GETNAME_ERROR", nameParams, index);
133  else
134  {
135  SetText(data, name, nameParams, index);
136  data.m_Flags &= ~ENameTagFlags.NAME_UPDATE;
137  }
138  }
139  }
140 };
141 
142 //------------------------------------------------------------------------------------------------
146 {
147  //------------------------------------------------------------------------------------------------
148  override void GetText(SCR_NameTagData data, out string name, out notnull array<string> nameParams)
149  {
150  name = Math.Round(Math.Sqrt(data.m_fDistance)).ToString();
151  }
152 
153  //------------------------------------------------------------------------------------------------
154  override void UpdateElement(SCR_NameTagData data, int index)
155  {
156  super.UpdateElement(data, index);
157 
158  string name;
159  array<string> nameParams = {};
160 
161  GetText(data, name, nameParams);
162  SetText(data, name, nameParams, index);
163  }
164 };
SCR_NameTagData
Nametag data.
Definition: SCR_NameTagData.c:54
SCR_NTElementBase
Nametag zone element base class, not for setup.
Definition: SCR_NTElementBase.c:18
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
SCR_NameTagZone
Nametag zone config setup.
Definition: SCR_NameTagConfig.c:109
ENameTagFlags
ENameTagFlags
Nametag flags.
Definition: SCR_NameTagData.c:17
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_NTTextDebug
Nametag element for distance debug text.
Definition: SCR_NTTextBase.c:145
SCR_NTName
Nametag element for name text.
Definition: SCR_NTTextBase.c:105
SCR_NameTagElementTitle
Custom names nametag element config.
Definition: SCR_NTElementBase.c:3
SCR_NameTagDisplay
Definition: SCR_NameTagDisplay.c:4
index
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Definition: SCR_DestructionSynchronizationComponent.c:17
SCR_NTStateText
Nametag text element state config.
Definition: SCR_NTElementBase.c:151
data
Get all prefabs that have the spawner data
Definition: SCR_EntityCatalogManagerComponent.c:305
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
SCR_NTTextBase
Base nametag element for text.
Definition: SCR_NTTextBase.c:4
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