Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_FieldManualPiece_ConfigEntry.c
Go to the documentation of this file.
1 [BaseContainerProps(), SCR_BaseContainerLocalizedTitleField("m_sDisplayName", "Config Entry: %1")]
3 {
4  [Attribute(uiwidget: UIWidgets.LocaleEditBox)]
5  protected string m_sDisplayName;
6 
7  [Attribute(desc: "Config or Entity to parse", params: "conf et")]
8  protected ResourceName m_ConfigPath;
9 
10  [Attribute(defvalue:"path/to/entry", desc: "in format \"level1/level2/level3/entryName\", entry name is CASE-SENSITIVE for an Entity (see SCR_ConfigHelper.GetChildBaseContainer for more information about the format)")]
11  protected string m_sEntryPath;
12 
13  [Attribute(desc: "Use %1 to display the entry's value")]
14  protected string m_sValueFormat;
15 
16  [Attribute(defvalue: "{671572B5C56766B3}UI/layouts/Menus/FieldManual/Pieces/FieldManual_Piece_ConfigEntry.layout", uiwidget: UIWidgets.EditBoxWithButton, params: "layout")]
17  protected ResourceName m_Layout;
18 
19  [Attribute(defvalue: "0", params: "-9 +9", desc: "move a number's decimal by # steps; -1 to the left, +1 to the right: -3 = divided by 1000, 6 = multiplied by one million, etc. Has no effects on other value types.")]
20  protected int m_iDecimalMove;
21 
22  [Attribute(defvalue: "-1", params: "-1 5", desc: "decides a number's decimals. -1 = no decimals limit, 0 = rounded")]
23  protected int m_iFixedDecimals;
24 
25  protected ref Resource m_Resource;
26  protected BaseContainer m_BaseContainer;
27 
28  //------------------------------------------------------------------------------------------------
29  protected void InitContainerAndPaths()
30  {
31  if (m_ConfigPath.IsEmpty() || m_sEntryPath.IsEmpty())
32  return;
33 
34  m_Resource = Resource.Load(m_ConfigPath);
35  if (!m_Resource.IsValid())
36  {
37  m_Resource = null;
38  return;
39  }
40 
41  m_BaseContainer = SCR_ConfigHelper.GetBaseContainerByPath(m_Resource, m_sEntryPath, true);
42 
43  array<string> paths = {};
44  m_sEntryPath = SCR_ConfigHelper.SplitConfigPath(m_sEntryPath, paths, true); // note, m_sEntryPath gets recycled here
45  if (!m_ConfigPath.EndsWith(".et")) // .et entries are case-sensitive -and- .conf ones need ToLower
46  m_sEntryPath.ToLower();
47  }
48 
49  //------------------------------------------------------------------------------------------------
50  override void CreateWidget(notnull Widget parent)
51  {
52  Widget createdWidget = GetGame().GetWorkspace().CreateWidgets(m_Layout, parent);
53  if (!createdWidget)
54  return;
55 
56  TextWidget descriptionWidget = TextWidget.Cast(createdWidget.FindAnyWidget("Description"));
57  if (descriptionWidget)
58  descriptionWidget.SetText(m_sDisplayName);
59 
60  TextWidget valueWidget = TextWidget.Cast(createdWidget.FindAnyWidget("Value"));
61  if (valueWidget)
62  SetConfigValue(valueWidget);
63  }
64 
65  //------------------------------------------------------------------------------------------------
66  protected void SetConfigValue(notnull TextWidget valueWidget)
67  {
68  if (!m_Resource || !m_BaseContainer)
69  InitContainerAndPaths();
70 
71  if (!m_Resource || !m_BaseContainer)
72  {
73  Print("Wrong config entry path | " + FilePath.StripPath(__FILE__) + ":" + __LINE__, LogLevel.WARNING);
74  valueWidget.SetText("-wrong config entry path provided-");
75  return;
76  }
77 
78  int index = m_BaseContainer.GetVarIndex(m_sEntryPath);
79  DataVarType dataVarType = m_BaseContainer.GetDataVarType(index);
80 
81  if (m_sValueFormat.Trim().IsEmpty())
82  m_sValueFormat = "%1";
83 
84  switch (dataVarType)
85  {
86  case DataVarType.BOOLEAN:
87  bool value;
88  m_BaseContainer.Get(m_sEntryPath, value);
89  valueWidget.SetTextFormat(m_sValueFormat, value);
90  break;
91 
92  case DataVarType.INTEGER:
93  case DataVarType.SCALAR:
94  float value;
95  m_BaseContainer.Get(m_sEntryPath, value);
96  if (m_iDecimalMove)
97  value /= Math.Pow(10, -m_iDecimalMove);
98 
99  valueWidget.SetTextFormat(m_sValueFormat, value.ToString(-1, m_iFixedDecimals));
100  break;
101 
102  case DataVarType.STRING:
103  string value;
104  m_BaseContainer.Get(m_sEntryPath, value);
105  valueWidget.SetTextFormat(m_sValueFormat, value);
106  break;
107 
108  case DataVarType.VECTOR3:
109  vector value;
110  m_BaseContainer.Get(m_sEntryPath, value);
111  valueWidget.SetTextFormat(m_sValueFormat, value);
112  break;
113 
114  default:
115  Print("Missing DataVarType type: " + dataVarType + " | " + FilePath.StripPath(__FILE__) + ":" + __LINE__, LogLevel.WARNING);
116  valueWidget.SetTextFormat(m_sValueFormat, "-");
117  break;
118  }
119 
120  if (m_sValueFormat == "%1")
121  m_sValueFormat = string.Empty;
122  }
123 }
m_sDisplayName
protected string m_sDisplayName
Definition: SCR_KeybindDialogs.c:39
SCR_FieldManualPiece
Definition: SCR_FieldManualPiece.c:2
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_BaseContainerLocalizedTitleField
SCR_TabViewComponent SCR_ScriptedWidgetComponent SCR_BaseContainerLocalizedTitleField("m_sTabButtonContent")
Definition: SCR_TabViewComponent.c:963
m_Layout
ResourceName m_Layout
Definition: SCR_ActionsToolbarEditorUIComponent.c:6
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
Attribute
typedef Attribute
Post-process effect of scripted camera.
index
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Definition: SCR_DestructionSynchronizationComponent.c:17
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
SCR_FieldManualPiece_ConfigEntry
Definition: SCR_FieldManualPiece_ConfigEntry.c:2
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
SCR_ConfigHelper
Definition: SCR_ConfigHelper.c:1