4 [
Attribute(uiwidget: UIWidgets.LocaleEditBox)]
5 protected string m_sDisplayName;
8 protected ResourceName m_ConfigPath;
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;
14 protected string m_sValueFormat;
16 [
Attribute(defvalue:
"{671572B5C56766B3}UI/layouts/Menus/FieldManual/Pieces/FieldManual_Piece_ConfigEntry.layout", uiwidget: UIWidgets.EditBoxWithButton,
params:
"layout")]
17 protected ResourceName m_Layout;
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;
22 [
Attribute(defvalue:
"-1",
params:
"-1 5",
desc:
"decides a number's decimals. -1 = no decimals limit, 0 = rounded")]
23 protected int m_iFixedDecimals;
25 protected ref Resource m_Resource;
26 protected BaseContainer m_BaseContainer;
29 protected void InitContainerAndPaths()
31 if (m_ConfigPath.IsEmpty() || m_sEntryPath.IsEmpty())
34 m_Resource = Resource.Load(m_ConfigPath);
35 if (!m_Resource.IsValid())
41 m_BaseContainer =
SCR_ConfigHelper.GetBaseContainerByPath(m_Resource, m_sEntryPath,
true);
43 array<string> paths = {};
45 if (!m_ConfigPath.EndsWith(
".et"))
46 m_sEntryPath.ToLower();
50 override void CreateWidget(notnull Widget parent)
52 Widget createdWidget =
GetGame().GetWorkspace().CreateWidgets(
m_Layout, parent);
56 TextWidget descriptionWidget = TextWidget.Cast(createdWidget.FindAnyWidget(
"Description"));
57 if (descriptionWidget)
60 TextWidget valueWidget = TextWidget.Cast(createdWidget.FindAnyWidget(
"Value"));
62 SetConfigValue(valueWidget);
66 protected void SetConfigValue(notnull TextWidget valueWidget)
68 if (!m_Resource || !m_BaseContainer)
69 InitContainerAndPaths();
71 if (!m_Resource || !m_BaseContainer)
73 Print(
"Wrong config entry path | " + FilePath.StripPath(__FILE__) +
":" + __LINE__, LogLevel.WARNING);
74 valueWidget.SetText(
"-wrong config entry path provided-");
78 int index = m_BaseContainer.GetVarIndex(m_sEntryPath);
79 DataVarType dataVarType = m_BaseContainer.GetDataVarType(
index);
81 if (m_sValueFormat.Trim().IsEmpty())
82 m_sValueFormat =
"%1";
86 case DataVarType.BOOLEAN:
88 m_BaseContainer.Get(m_sEntryPath, value);
89 valueWidget.SetTextFormat(m_sValueFormat, value);
92 case DataVarType.INTEGER:
93 case DataVarType.SCALAR:
95 m_BaseContainer.Get(m_sEntryPath, value);
97 value /= Math.Pow(10, -m_iDecimalMove);
99 valueWidget.SetTextFormat(m_sValueFormat, value.ToString(-1, m_iFixedDecimals));
102 case DataVarType.STRING:
104 m_BaseContainer.Get(m_sEntryPath, value);
105 valueWidget.SetTextFormat(m_sValueFormat, value);
108 case DataVarType.VECTOR3:
110 m_BaseContainer.Get(m_sEntryPath, value);
111 valueWidget.SetTextFormat(m_sValueFormat, value);
115 Print(
"Missing DataVarType type: " + dataVarType +
" | " + FilePath.StripPath(__FILE__) +
":" + __LINE__, LogLevel.WARNING);
116 valueWidget.SetTextFormat(m_sValueFormat,
"-");
120 if (m_sValueFormat ==
"%1")
121 m_sValueFormat =
string.Empty;