3 protected string m_sModule;
4 protected string m_sSubModule;
5 protected string m_sName;
6 protected string m_sWidgetName;
7 protected BaseContainer m_Setting;
9 protected bool m_bUseGameUserSettings;
11 protected ref ScriptInvoker m_OnEntryChanged;
14 protected float m_fMin, m_fMax, m_fStep, m_fCurrent;
15 protected ref array<string> m_aNames =
new array<string>();
16 protected ref array<int> m_aVals =
new array<int>();
17 protected bool m_bHasLimits =
false;
24 m_sWidgetName = widgetName;
25 m_sSubModule = subModule;
34 Widget w = parent.FindAnyWidget(name);
42 ScriptInvoker GetEntryChangedInvoker()
44 if (!m_OnEntryChanged)
45 m_OnEntryChanged =
new ScriptInvoker();
47 return m_OnEntryChanged;
51 string GetWidgetName()
57 void LoadEntry(Widget parent,
bool forceLoadSettings =
false,
bool addEntryChangedEventHandler =
true)
59 if ((forceLoadSettings || !m_Setting) && !SetBaseContainer())
62 if (!m_Setting || m_iItem < 0)
64 Print(
"Settings item not found: " +
m_sName, LogLevel.WARNING);
70 comp = GetComponent(m_sWidgetName, parent.GetParent());
74 Print(
"Settings widget not found: " + m_sWidgetName, LogLevel.WARNING);
78 if (InitSpinBox(comp, addEntryChangedEventHandler))
81 if (InitSlider(comp, addEntryChangedEventHandler))
84 if (InitCheckBox(comp, addEntryChangedEventHandler))
87 if (InitComboBox(comp, addEntryChangedEventHandler))
99 m_Setting.Get(
m_sName, current);
100 spin.SetCurrentItem(current);
101 m_Setting.GetEnumValues(m_iItem, m_aNames, m_aVals);
106 int intendedSize = Math.Max(m_aNames.Count(),
m_fMax + 1);
107 if (intendedSize != spin.GetNumItems())
108 Print(
string.Format(
"Settings: %1 has wrong number of items: %2/%3",
m_sName, spin.GetNumItems(), intendedSize), LogLevel.WARNING);
111 if (addEntryChangedEventHandler)
112 spin.m_OnChanged.Insert(OnSelectableChanged);
131 slider.SetValue(val);
133 if (addEntryChangedEventHandler)
134 slider.GetOnChangedFinal().Insert(OnSliderChanged);
147 m_Setting.Get(
m_sName, checked);
148 check.SetChecked(checked);
149 if (addEntryChangedEventHandler)
150 check.m_OnChanged.Insert(OnCheckboxChanged);
163 m_Setting.Get(
m_sName, current);
164 combo.SetCurrentItem(current);
167 m_Setting.GetEnumValues(m_iItem, m_aNames, m_aVals);
172 int intendedSize = Math.Max(m_aNames.Count(),
m_fMax);
173 if (intendedSize != combo.GetNumItems())
174 Print(
string.Format(
"Settings: %1 has wrong number of items: %2/%3",
m_sName, combo.GetNumItems(), intendedSize), LogLevel.WARNING);
177 if (addEntryChangedEventHandler)
178 combo.m_OnChanged.Insert(OnSelectableChanged);
184 protected BaseContainer SetBaseContainer()
186 UserSettings userSettings;
187 if (m_bUseGameUserSettings)
188 userSettings =
GetGame().GetGameUserSettings();
190 userSettings =
GetGame().GetEngineUserSettings();
195 if (m_sSubModule.IsEmpty())
196 m_Setting = userSettings.GetModule(m_sModule);
199 BaseContainer setting =
GetGame().GetEngineUserSettings().GetModule(m_sModule);
201 m_Setting = setting.GetObject(m_sSubModule);
210 if (!m_Setting && !SetBaseContainer())
213 if (i >= 0 && i < m_aVals.Count())
215 m_Setting.Set(
m_sName, m_aVals[i]);
217 else if (m_bHasLimits)
227 m_OnEntryChanged.Invoke(
this);
233 if (!m_Setting && !SetBaseContainer())
237 m_OnEntryChanged.Invoke(
this);
243 if (!m_Setting && !SetBaseContainer())
246 m_Setting.Set(
m_sName, checked);
247 m_OnEntryChanged.Invoke(
this);