Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_ActionMenuElementComponent.c
Go to the documentation of this file.
1//#define DEBUG_ACTIONICONS
3{
5
6 protected const float NEARBY_INTERACTION_OPACITY_DIVIDER = 3;
7 protected const float NEARBY_INTERACTION_OPACITY_MULTIPLIER = 0.9;
8 protected const float NEARBY_INTERACTION_OPACITY_CUTOFF = 0.1;
9
10 protected const int m_iFontSizeSelected = 24;
11 protected const int m_iFontSizeNotSelected = 20;
12
13 protected bool m_bIsSelected;
14 protected bool m_bIsDisabled;
15
16 //------------------------------------------------------------------------------------------------
17 override void HandlerAttached(Widget w)
18 {
19 super.HandlerAttached(w);
20
21 m_Widgets.Init(w);
22 }
23
24 //------------------------------------------------------------------------------------------------
26 {
27 return m_Widgets.m_IconOverlayComponent;
28 }
29
30 //------------------------------------------------------------------------------------------------
31 void SetVisible(bool state)
32 {
33 m_wRoot.SetVisible(state);
34 }
35
36 //------------------------------------------------------------------------------------------------
43 bool Set(notnull BaseUserAction userAction, bool isSelected, bool isAvailable, SCR_ActionUIInfo actionUIInfo)
44 {
45 m_bIsSelected = isSelected;
46 m_bIsDisabled = !isAvailable;
47
48 string sActionName = userAction.GetActionName();
49
50 array<string> actionStrings = {};
51 sActionName.Split("%CTX_HACK%", actionStrings, true);
52
53 int actionStringsCount = actionStrings.Count();
54
55 if (actionStringsCount == 0 || !actionStrings[0])
56 return false;
57
58 // Set string in widget and format it with provided ActionNameParams (if any)
59 m_Widgets.m_wActionText.SetTextFormat(
60 actionStrings[0],
61 userAction.ActionNameParams[0],
62 userAction.ActionNameParams[1],
63 userAction.ActionNameParams[2],
64 userAction.ActionNameParams[3],
65 userAction.ActionNameParams[4],
66 userAction.ActionNameParams[5],
67 userAction.ActionNameParams[6],
68 userAction.ActionNameParams[7],
69 userAction.ActionNameParams[8]
70 );
71
72 if (actionStringsCount > 1 && actionStrings[1])
73 {
74 m_Widgets.m_wActionContext.SetText(actionStrings[1]);
75 m_Widgets.m_wActionContext.SetVisible(true);
76 }
77 else
78 {
79 m_Widgets.m_wActionContext.SetText("");
80 m_Widgets.m_wActionContext.SetVisible(false);
81 }
82
83 SetIconFromAction(actionUIInfo, userAction);
84
85 m_Widgets.m_wIconOverlay.SetVisible(!isSelected);
86
87 if (isSelected)
88 {
89 m_Widgets.m_wActionText.SetExactFontSize(m_iFontSizeSelected);
90 m_Widgets.m_wActionContext.SetExactFontSize(m_iFontSizeSelected);
91 }
92 else
93 {
94 m_Widgets.m_wActionText.SetExactFontSize(m_iFontSizeNotSelected);
95 m_Widgets.m_wActionContext.SetExactFontSize(m_iFontSizeNotSelected);
96 }
97
99
100 return true;
101 }
102
103 //------------------------------------------------------------------------------------------------
105 protected void SetIconFromAction(SCR_ActionUIInfo info, BaseUserAction userAction)
106 {
107 if (userAction)
108 {
109 SCR_ActionUIInfo actionUIInfo = SCR_ActionUIInfo.Cast(userAction.GetUIInfo());
110
111 if (actionUIInfo && actionUIInfo.SetIconTo(m_Widgets.m_wIcon, m_Widgets.m_wIconGlow))
112 return;
113 }
114
115 if (info && info.SetIconTo(m_Widgets.m_wIcon, m_Widgets.m_wIconGlow))
116 return;
117
118 #ifdef DEBUG_ACTIONICONS
119 Print("DEBUG_ACTIONICONS:: No icons found for "+ userAction);
120 #endif
121
122 m_Widgets.m_wIcon.LoadImageFromSet(0, UIConstants.ICONS_IMAGE_SET, UIConstants.ICON_INTERACT_DEFAULT);
123 m_Widgets.m_wIconGlow.LoadImageFromSet(0, UIConstants.ICONS_GLOW_IMAGE_SET, UIConstants.ICON_INTERACT_DEFAULT);
124 }
125
126 //------------------------------------------------------------------------------------------------
128 {
129 Color textColor;
130 if (m_bIsDisabled)
131 {
132 textColor = GUIColors.DISABLED;
133
134 m_Widgets.m_wIcon.LoadImageFromSet(0, UIConstants.ICONS_IMAGE_SET, UIConstants.ICON_INTERACT_DISABLED);
135 m_Widgets.m_wIconGlow.LoadImageFromSet(0, UIConstants.ICONS_GLOW_IMAGE_SET, UIConstants.ICON_INTERACT_DISABLED);
136 m_Widgets.m_wIconGlow.SetOpacity(UIConstants.DISABLED_WIDGET_OPACITY);
137 m_Widgets.m_wIcon.SetColor(textColor);
138 }
139 else if (m_bIsSelected)
140 {
141 textColor = GUIColors.ENABLED;
142 }
143 else
144 {
145 textColor = UIColors.IDLE_ACTIVE;
146
147 m_Widgets.m_wIconGlow.SetOpacity(UIConstants.ENABLED_WIDGET_OPACITY);
148 m_Widgets.m_wIcon.SetColor(textColor);
149 }
150
151 m_Widgets.m_wActionText.SetColor(textColor);
152 m_Widgets.m_wActionContext.SetColor(textColor);
153 }
154
155 //------------------------------------------------------------------------------------------------
157 {
159 {
160 m_wRoot.SetOpacity(0.0);
161 return;
162 }
163
164 float opacity = UIConstants.ENABLED_WIDGET_OPACITY;
165 if (position != 0)
166 opacity = UIConstants.ENABLED_WIDGET_OPACITY * (NEARBY_INTERACTION_OPACITY_MULTIPLIER - (Math.AbsFloat(position) / NEARBY_INTERACTION_OPACITY_DIVIDER));
167
168 // if opacity is less then UIConstants.NEARBY_INTERACTION_OPACITY_CUTOFF (10%), just make it invisible
170 opacity = 0;
171
172 m_wRoot.SetOpacity(Math.Clamp(opacity, 0.0, UIConstants.ENABLED_WIDGET_OPACITY));
173 UpdateColors();
174 }
175}
vector position
proto external UIInfo GetUIInfo()
Returns the UIInfo set for this user action or null if none.
Definition Color.c:13
Definition Math.c:13
void SetIconFromAction(SCR_ActionUIInfo info, BaseUserAction userAction)
Try to set the Icon defined in the UIInfo from action first.
SCR_NearbyContextWidgetComponentInteract GetIconComponent()
ref SCR_ActionMenuElementWidgets m_Widgets
bool Set(notnull BaseUserAction userAction, bool isSelected, bool isAvailable, SCR_ActionUIInfo actionUIInfo)
bool SetIconTo(ImageWidget imageWidget, ImageWidget glowWidget=null)
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.