Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_SliderEditorAttributeUIComponent.c
Go to the documentation of this file.
1 
4 {
5  protected SCR_SliderComponent m_SliderWidgetComponent;
6  protected ref SCR_BaseEditorAttributeEntrySlider m_SliderData;
7  protected float m_fMaxSliderValue;
8  protected float m_fDefaultValue = float.MAX;
9 
10  protected bool m_bIsTimeSlider;
11  //~ If value is 0 should it hide it or show it as 00. Eg if normally 23:05:19 (h:m:s) and s becomes 0 and is ticked here than it will be come 23:05
12  protected ETimeFormatParam m_eHideIfZero;
13  //~ If true than it will never show seconds even if seconds are not 0
14  protected bool m_bAlwaysHideSeconds;
15 
16  override void Init(Widget w, SCR_BaseEditorAttribute attribute)
17  {
18  //Set slider label
19  Widget sliderWidgetLibary = w.FindAnyWidget(m_sUiComponentName);
20  if (!sliderWidgetLibary) return;
21 
22  m_SliderWidgetComponent = SCR_SliderComponent.Cast(sliderWidgetLibary.FindHandler(SCR_SliderComponent));
23  if (!m_SliderWidgetComponent)
24  return;
25 
26  SCR_BaseEditorAttributeVar var = attribute.GetVariableOrCopy();
27  if (var)
28  {
29  array<ref SCR_BaseEditorAttributeEntry> entries = new array<ref SCR_BaseEditorAttributeEntry>;
30  attribute.GetEntries(entries);
31 
32  foreach (SCR_BaseEditorAttributeEntry entry: entries)
33  {
35  if (timeSlider)
36  {
37  m_bIsTimeSlider = true;
38  timeSlider.GetTimeSliderValues(m_eHideIfZero, m_bAlwaysHideSeconds);
39  continue;
40  }
41 
43  if (data)
44  {
45  m_SliderData = data;
46  SetSliderSettings(var, m_SliderData);
47  continue;
48  }
49 
51  if (defaultValue)
52  {
53  m_fDefaultValue = defaultValue.GetDefaultFloatValue();
54  }
55  }
56  }
57 
58  super.Init(w, attribute);
59  }
60 
61  //~ Is overridden in SCR_VectorSliderEditorAttributeUIComponent
62  protected void SetSliderSettings(SCR_BaseEditorAttributeVar var, SCR_BaseEditorAttributeEntrySlider sliderData)
63  {
64  m_SliderData = sliderData;
65 
66  float min, step;
67  m_SliderData.GetSliderMinMaxStep(min, m_fMaxSliderValue, step);
68  m_SliderWidgetComponent.SetSliderSettings(min, m_fMaxSliderValue, step, m_SliderData.GetSliderValueFormating());
69 
70  if (m_fDefaultValue == float.MAX)
71  m_fDefaultValue = m_fMaxSliderValue;
72  }
73 
74  //Sets a default state for the UI and var value if conflicting attribute
75  override void SetVariableToDefaultValue(SCR_BaseEditorAttributeVar var)
76  {
77  m_SliderWidgetComponent.SetValue(m_fDefaultValue);
78  m_SliderWidgetComponent.ShowCustomValue(GetSliderValueText(m_fDefaultValue));
79 
80  if (var)
81  var.SetFloat(m_fDefaultValue);
82  }
83 
84  override void SetFromVar(SCR_BaseEditorAttributeVar var)
85  {
86  super.SetFromVar(var);
87 
88  if (!var)
89  return;
90 
91  float value = var.GetFloat();
92 
93  m_SliderWidgetComponent.SetValue(value);
94  m_SliderWidgetComponent.ShowCustomValue(GetSliderValueText(value));
95  OnChange(null, 0, 0, false);
96 
97  if (value > m_fMaxSliderValue)
98  PrintFormat("%1 attribute slider is set to '%2' but can only support up to '%3'", GetAttribute().GetUIInfo().GetName(), value.ToString(), m_fMaxSliderValue.ToString());
99  }
100 
101 
102  override bool OnChange(Widget w, int x, int y, bool finished)
103  {
104  SCR_BaseEditorAttribute attribute = GetAttribute();
105  if (!attribute)
106  return false;
107 
108  SCR_BaseEditorAttributeVar var = attribute.GetVariable(true);
109  if (!var)
110  return false;
111 
112  float value = m_SliderWidgetComponent.GetValue();
113  m_SliderWidgetComponent.ShowCustomValue(GetSliderValueText(value));
114 
115  if (var.GetFloat() == value)
116  return false;
117 
118  var.SetFloat(value);
119  super.OnChange(w, x, y, finished);
120 
121  return false;
122  }
123 
124  protected string GetSliderValueText(float value)
125  {
126  if (m_SliderData)
127  {
128  if (!m_bIsTimeSlider)
129  {
130  return m_SliderData.GetText(value);
131  }
132  //~ Time slider
133  else
134  {
135  if (!m_bAlwaysHideSeconds)
136  return SCR_FormatHelper.GetTimeFormatting(value, m_eHideIfZero);
137  else
138  return SCR_FormatHelper.GetTimeFormattingHideSeconds(value, m_eHideIfZero);
139  }
140  }
141 
142  return "MISSING m_SliderData!";
143  }
144 };
GetName
string GetName()
Definition: SCR_ScenarioFrameworkLayerBase.c:85
SCR_FormatHelper
Definition: SCR_FormatHelper.c:1
SCR_SliderEditorAttributeUIComponent
Definition: SCR_SliderEditorAttributeUIComponent.c:3
SCR_SliderComponent
Definition: SCR_SliderComponent.c:2
GetUIInfo
SCR_UIInfo GetUIInfo()
Definition: SCR_EditableEntityCampaignBuildingModeLabelSetting.c:27
SCR_BaseEditorAttributeVar
Definition: SCR_BaseEditorAttributeVar.c:1
ETimeFormatParam
ETimeFormatParam
Definition: ETimeFormatParam.c:4
SCR_BaseEditorAttributeEntryTimeSlider
Definition: SCR_BaseEditorAttribute.c:597
SCR_BaseEditorAttribute
Base Attribute Script for other attributes to inherent from to get and set varriables in Editor Attri...
Definition: SCR_BaseEditorAttribute.c:3
SCR_BaseEditorAttributeDefaultFloatValue
void SCR_BaseEditorAttributeDefaultFloatValue(float floatValue)
Definition: SCR_BaseEditorAttribute.c:856
SCR_BaseEditorAttributeUIComponent
Definition: SCR_BaseEditorAttributeUIComponent.c:3
SCR_BaseEditorAttributeEntrySlider
void SCR_BaseEditorAttributeEntrySlider(SCR_EditorAttributeBaseValues sliderValues)
Definition: SCR_BaseEditorAttribute.c:581
data
Get all prefabs that have the spawner data
Definition: SCR_EntityCatalogManagerComponent.c:305