Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_VisualisedBallisticConfig.c
Go to the documentation of this file.
2{
3 [Attribute("{6E4CC0DD94FAB365}UI/layouts/Gadgets/BallisticTable/BallisticTable.layout", UIWidgets.ResourceNamePicker, "Layout name", "layout", category: "Layouts")]
5
6 [Attribute("{F75FE2331AF70BF8}UI/layouts/Gadgets/BallisticTable/ContentRowLayout.layout", UIWidgets.ResourceNamePicker, "Layout name", "layout", category: "Layouts")]
8
9 [Attribute("{801F5CED215A1CFF}UI/layouts/Gadgets/BallisticTable/Content.layout", UIWidgets.ResourceNamePicker, "Layout name", "layout", category: "Layouts")]
11
12 [Attribute(desc: "Lowest range for which data will be shown", params: "0 inf")]
13 protected int m_iMinRange;
14
15 [Attribute(desc: "Highest range for which data will be shown", params: "0 inf")]
16 protected int m_iMaxRange;
17
18 [Attribute(desc: "Change in elevation down range", params: "1 inf")]
20
21 [Attribute("0", desc: "Should value of 0 be replaced with '-' sign", category: "Layouts")]
23
24 [Attribute("0", desc: "Weights that will be applied to the grid of contents and thus impact how much space each cell will have in relation to other cells", category: "Layouts")]
25 protected ref array<float> m_aGridFillWeights;
26
27 [Attribute("%1 m", desc: "Format for displaying average dispersion.")]
29
31
32 const string EMPTY_CELL_TEXT = "-";
33 const string ROW_HOLDER_NAME = "BallisticContentLayout";
34 const string CONTENT_HOLDER_NAME = "ContentHolder";
35 const string CONTENT_LABEL_NAME = "Label";
36 const string TITLE_LABEL_NAME = "Title";
37 const string AMMO_TYPE_NAME = "AmmoTypeIcon";
38 const string DISPERSION_VALUE_CONTAINER_NAME = "DispersionValue";
39 const string STATIC_WIDGET_INDICATOR = "STATIC";
40
41 //------------------------------------------------------------------------------------------------
44 override bool GenerateBallisticData()
45 {
46 if (!super.GenerateBallisticData())
47 return false;
48
50 return true;
51
52 SCR_BallisticData ballisticData = SCR_BallisticData.s_aBallistics[m_iBallisticDataId];
53 if (!ballisticData)
54 return false;
55
56 int numberOfEntries = ballisticData.GetNumberOfEntries();
57 if (numberOfEntries < 1)
58 return false;
59
60 Resource resource = Resource.Load(m_sProjectilePrefab);
61 if (!resource.IsValid())
62 return false;
63
64 BaseResourceObject resourceObj = resource.GetResource();
65 if (!resourceObj)
66 return false;
67
68 IEntitySource entitySrc = resourceObj.ToEntitySource();
69 if (!entitySrc)
70 return false;
71
73 if (!windageData)
74 return false;
75
76 array<float> values;
77 array<float> windageValues;
78 float distance, travelTime, aimHeight, angle, angleRad;
79 for (int i; i < numberOfEntries; i++)
80 {
81 ballisticData.GetValues(i, values);
82 if (!values || values.IsEmpty())
83 continue;
84
85 distance = values[0] + m_iElevationChangeDownRange * 0.5;
86 aimHeight = BallisticTable.GetHeightFromProjectileSource(distance, travelTime, entitySrc, m_fProjectileInitSpeedCoef, m_bDirectFireMode);
87 angleRad = SCR_Math.ConvertToRadians(values[1], m_eUnitType);
88
89 if (travelTime > 0 && aimHeight > 0)
90 {
91 angle = Math.Atan2(aimHeight, distance); //radians
93 angle = Math.Round(Math.AbsFloat(angle - values[1]));
94 travelTime = Math.AbsFloat(travelTime - values[2]);
95 travelTime = travelTime.ToString(0,1).ToFloat();
96 }
97 else
98 {
99 angle = 0;
100 travelTime = 0;
101 }
102
103 values.Insert(angle);
104 values.Insert(travelTime);
105
106 windageValues = windageData.GetDataByAngle(angleRad, initSpeedCoef: m_fProjectileInitSpeedCoef);
107 if (windageValues && !windageValues.IsEmpty())
108 {
109 values.Insert(Math.Round(windageValues[2]));
110 values.Insert(Math.Round(windageValues[5] * 10) * 0.1);
111 values.Insert(Math.Round(SCR_Math.ConvertFromRadians(windageValues[3] * 0.001, m_eUnitType)));
112 values.Insert(Math.Round(windageValues[4]));
113 }
114
115 ballisticData.SetValues(i, values);
116 }
117
119 return true;
120 }
121
122 //------------------------------------------------------------------------------------------------
123 override void DrawPageData(notnull Widget root, notnull IEntity surfaceEntity, notnull SCR_DataDisplayGadgetComponent drawingGadget, int pageID)
124 {
125 ClearDataPage(root);
126 LoadDataPage(root, drawingGadget, pageID);
127 }
128
129 //------------------------------------------------------------------------------------------------
131 protected void LoadDataPage(notnull Widget root, notnull SCR_DataDisplayGadgetComponent drawingGadget, int pageID)
132 {
133 Widget rowHolder = root.FindAnyWidget(ROW_HOLDER_NAME);
134 if (!rowHolder)
135 return;
136
137 if (!IsGenerated())
139 return;
140
141 SCR_BallisticData ballisticData = SCR_BallisticData.s_aBallistics[m_iBallisticDataId];
142 if (!ballisticData)
143 return;
144
145 TextWidget title = TextWidget.Cast(root.FindAnyWidget(TITLE_LABEL_NAME));
146 if (title)
147 title.SetText(m_sDisplayedText);
148
149 ImageWidget ammoTypeIcon = ImageWidget.Cast(root.FindAnyWidget(AMMO_TYPE_NAME));
150 if (ammoTypeIcon)
151 {
152 if (m_sAmmoTypeQuadName.IsEmpty())
153 {
154 ammoTypeIcon.SetVisible(false);
155 }
156 else
157 {
158 ammoTypeIcon.SetVisible(true);
159 ammoTypeIcon.LoadImageFromSet(0, m_sAmmoTypeImageSet, m_sAmmoTypeQuadName);
160 ammoTypeIcon.SetSize(m_iAmmoTypeImageSize, m_iAmmoTypeImageSize);
161 }
162 }
163
164 HorizontalLayoutWidget dispersionContainer = HorizontalLayoutWidget.Cast(root.FindAnyWidget(DISPERSION_VALUE_CONTAINER_NAME));
165 if (dispersionContainer)
166 {
167 TextWidget dispersionValue = TextWidget.Cast(dispersionContainer.FindAnyWidget(CONTENT_LABEL_NAME));
168 if (dispersionValue)
169 dispersionValue.SetTextFormat(m_sAverageDispersionFormat, m_fStandardDispersion.ToString(0, 0));
170 }
171
172 Widget contentHolder;
173 array<float> values;
174 string cellText;
175 int id, lastEntry, numberOfValues, maxNumberOfColumns = m_aGridFillWeights.Count();
176 ballisticData.GetBallisticValuesForClosestRange(m_iMaxRange, lastEntry);
178
179 for (int i = id; i <= lastEntry; i++)
180 {
181 contentHolder = AddRow(rowHolder, i);
182 if (!contentHolder)
183 continue;
184
185 numberOfValues = ballisticData.GetValues(i, values);
186 if (numberOfValues < 1)
187 continue;
188
189 for (int valueId; valueId < maxNumberOfColumns; valueId++)
190 {
191 if (valueId >= numberOfValues || m_bReplaceZerosWithDash && float.AlmostEqual(values[valueId], 0))
192 cellText = EMPTY_CELL_TEXT;
193 else if (valueId == 2) //time of flight
194 cellText = values[valueId].ToString(0, 1);
195 else
196 cellText = values[valueId].ToString();
197
198 AddCell(contentHolder, cellText, valueId);
199 }
200 }
201
202 TextWidget pageNumber = TextWidget.Cast(root.FindAnyWidget(drawingGadget.PAGE_NUMBER_NAME));
203 if (pageNumber)
204 pageNumber.SetText(string.Format(drawingGadget.PAGE_NUMBER_FORMAT, (pageID + 1), drawingGadget.GetNumberOfPages()));
205 }
206
207 //------------------------------------------------------------------------------------------------
210 protected void ClearDataPage(notnull Widget root)
211 {
212 Widget rowHolder = root.FindAnyWidget(ROW_HOLDER_NAME);
213 if (!rowHolder)
214 {
215 Widget contentContaier = root.GetChildren();
216 if (contentContaier)
217 {
218 contentContaier.RemoveFromHierarchy();
219 delete contentContaier;
220 }
221
222 contentContaier = GetGame().GetWorkspace().CreateWidgets(m_sLayoutName, root);
223 if (!contentContaier)
224 return;
225
226 rowHolder = contentContaier.FindAnyWidget(ROW_HOLDER_NAME);
227 if (!rowHolder)
228 return;
229 }
230
231 Widget child = rowHolder.FindAnyWidgetById(0);
232 Widget nextChild;
233 while (child)
234 {
235 nextChild = child.GetSibling();
236 if (!child.GetName().Contains(STATIC_WIDGET_INDICATOR))
237 child.RemoveFromHierarchy();
238
239 child = nextChild;
240 }
241 }
242
243 //------------------------------------------------------------------------------------------------
245 protected Widget AddRow(notnull Widget parentWidget, int rowID = 0)
246 {
247 Widget layout = GetGame().GetWorkspace().CreateWidgets(m_sRowPrefab, parentWidget);
248 if (!layout)
249 return null;
250
251 layout.SetZOrder(rowID);
252 GridLayoutWidget contentHolder = GridLayoutWidget.Cast(layout.FindAnyWidget(CONTENT_HOLDER_NAME));
253 if (!contentHolder)
254 {
255 layout.RemoveFromHierarchy();
256 return null;
257 }
258
259 foreach (int i, float weight : m_aGridFillWeights)
260 {
261 contentHolder.SetColumnFillWeight(i, weight);
262 }
263
264 return contentHolder;
265 }
266
267 //------------------------------------------------------------------------------------------------
269 protected Widget AddCell(notnull Widget parentWidget, string text, int columnID = 0)
270 {
271 Widget layout = GetGame().GetWorkspace().CreateWidgets(m_sCellPrefab, parentWidget);
272 if (!layout)
273 return null;
274
275 GridSlot.SetColumn(layout, columnID);
276 TextWidget textWidget = TextWidget.Cast(layout.FindAnyWidget(CONTENT_LABEL_NAME));
277 if (!textWidget)
278 {
279 layout.RemoveFromHierarchy();
280 return null;
281 }
282
283 textWidget.SetText(text);
284 return textWidget;
285 }
286}
AddonBuildInfoTool id
ArmaReforgerScripted GetGame()
Definition game.c:1398
float distance
UI layouts Menus CleanSweep CleanSweepAreaSelection layout
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition Math.c:13
Object holding reference to resource. In destructor release the resource.
Definition Resource.c:25
int GetValues(int id, out array< float > values)
void SetValues(int id, notnull array< float > newValues)
array< float > GetBallisticValuesForClosestRange(int range, out int id=-1)
SCR_EOpticsAngleUnits m_eUnitType
static float ConvertFromRadians(float radianAngleFrom, SCR_EOpticsAngleUnits toUnitType)
Definition SCR_Math.c:290
static float ConvertToRadians(float angleFrom, SCR_EOpticsAngleUnits fromUnitType)
Definition SCR_Math.c:323
static SCR_ProjectileWindTable GetProjectileWindageData(notnull IEntity projectile)
array< float > GetDataByAngle(float angle, float windSpeed=10, float initSpeedCoef=1)
void LoadDataPage(notnull Widget root, notnull SCR_DataDisplayGadgetComponent drawingGadget, int pageID)
Method used to add widgets with ballistic data for currently selected page.
Widget AddCell(notnull Widget parentWidget, string text, int columnID=0)
Meant to add a single cell.
Widget AddRow(notnull Widget parentWidget, int rowID=0)
Meant to add a single row.
override void DrawPageData(notnull Widget root, notnull IEntity surfaceEntity, notnull SCR_DataDisplayGadgetComponent drawingGadget, int pageID)
SCR_FieldOfViewSettings Attribute