11 protected float m_fColorsAnimationTime;
14 protected bool m_bShowWriteIcon;
17 protected bool m_bShowInvalidInputWarning;
19 [
Attribute(
UIConstants.ICONS_IMAGE_SET, UIWidgets.ResourcePickerThumbnail,
"Image resource for icons")]
20 protected ResourceName m_sIconImageSet;
23 protected string m_sIconImageName;
26 protected string m_sWriteIconButtonName;
29 protected float m_fOpacityDefault;
32 protected float m_fOpacityFocused;
34 [
Attribute(
"0.022995 0.022995 0.022995 1.000000", UIWidgets.ColorPicker)]
35 protected ref Color m_BackgroundDefault;
37 [
Attribute(
"0.108995 0.108995 0.108995 1.000000", UIWidgets.ColorPicker)]
38 protected ref Color m_BackgroundInteracting;
40 [
Attribute(
"0.022995 0.022995 0.022995 1.000000", UIWidgets.ColorPicker)]
41 protected ref Color m_BackgroundFocused;
43 [
Attribute(
"", UIWidgets.EditBox,
"Text that should appear next to error warning on invalid input")]
44 protected string m_sWarningText;
47 Widget m_wColorOverlay;
48 Widget m_wEditBackground;
49 Widget m_wWarningIcon;
50 Widget m_wHorizontalLayout;
52 Widget m_wWriteIconScale;
53 ImageWidget m_wImgWriteIcon;
55 protected SCR_ModularButtonComponent m_WriteIconButton;
59 protected bool m_bValidInput =
true;
60 protected bool m_bIsTyping;
61 protected ref Color COLOR_INVALID_INPUT =
UIColors.WARNING;
62 protected ref Color COLOR_VALID_INPUT = Color.White;
65 ref ScriptInvoker m_OnConfirm =
new ScriptInvoker();
66 ref ScriptInvoker m_OnFocusChangedEditBox =
new ScriptInvoker();
68 protected MultilineEditBoxWidget m_wMultilineEditBoxWidget;
69 protected EditBoxWidget m_wEditBoxWidget;
72 protected const int INTERACTION_STATE_UPDATE_FREQUENCY = 50;
73 protected const int FOCUS_LOST_INTERACTION_STATE_UPDATE_DELAY = 1000 /
UIConstants.FADE_RATE_DEFAULT;
75 protected bool m_bIsFocused;
76 protected bool m_bIsInWriteMode;
77 protected bool m_bIsInWriteModePrevious;
78 protected ref Color m_BackgroundCurrent;
85 protected string m_sTextPrevious;
88 override void HandlerAttached(Widget w)
90 super.HandlerAttached(w);
91 m_wColorOverlay = w.FindAnyWidget(
"OverlayPanel");
93 m_wEditBox = w.FindAnyWidget(
"EditBox");
94 m_wWarningIcon = w.FindAnyWidget(
"ErrorIcon");
95 m_wEditBackground = w.FindAnyWidget(
"EditBackground");
96 m_wHorizontalLayout = w.FindAnyWidget(
"HorizontalLayout");
98 m_wWriteIconScale = w.FindAnyWidget(
"WriteIconScale");
99 m_wImgWriteIcon = ImageWidget.Cast(w.FindAnyWidget(
"WriteIcon"));
104 if (
GetGame().InPlayMode() && m_wWarningIcon)
107 m_wWarningIcon.SetOpacity(0);
109 m_wWarningIcon.SetOpacity(0);
114 m_Hint.SetMessage(m_sWarningText);
115 m_Hint.SetVisible(0);
122 if (m_fColorsAnimationTime <= 0)
123 m_fColorsAnimationTime = 1000;
125 m_fColorsAnimationTime = 1 / m_fColorsAnimationTime;
133 if (m_bShowInvalidInputWarning)
135 filter.m_OnInvalidInput.Insert(OnInvalidInput);
136 filter.m_OnTextTooLong.Insert(OnInvalidInput);
139 filter.m_OnValidInput.Insert(OnValueChanged);
145 m_EVHComponent.GetOnFocus().Insert(OnHandlerFocus);
146 m_EVHComponent.GetOnFocusLost().Insert(OnHandlerFocusLost);
147 m_EVHComponent.GetOnChangeFinal().Insert(OnConfirm);
150 if (m_wEditBackground)
152 m_wEditBackground.SetOpacity(m_fOpacityDefault);
153 m_wEditBackground.SetColor(m_BackgroundDefault);
154 m_BackgroundCurrent = m_BackgroundDefault;
158 if (m_wImgWriteIcon && m_wWriteIconScale)
160 bool hasResource = !m_sIconImageSet.IsEmpty() && !m_sIconImageName.IsEmpty();
161 m_wWriteIconScale.SetVisible(hasResource);
164 m_wImgWriteIcon.LoadImageFromSet(0, m_sIconImageSet, m_sIconImageName);
166 ShowWriteIcon(m_bShowWriteIcon && hasResource);
170 Widget iconButton =
m_wRoot.FindAnyWidget(m_sWriteIconButtonName);
172 m_WriteIconButton = SCR_ModularButtonComponent.FindComponent(iconButton);
174 if (m_WriteIconButton)
175 m_WriteIconButton.m_OnClicked.Insert(OnInternalButtonClicked);
178 m_wMultilineEditBoxWidget = MultilineEditBoxWidget.Cast(m_wEditBox);
179 m_wEditBoxWidget = EditBoxWidget.Cast(m_wEditBox);
181 if (m_wMultilineEditBoxWidget)
182 m_bIsInWriteMode = m_wMultilineEditBoxWidget.IsInWriteMode();
183 else if (m_wEditBoxWidget)
184 m_bIsInWriteMode = m_wEditBoxWidget.IsInWriteMode();
186 m_bIsInWriteModePrevious = m_bIsInWriteMode;
188 m_sTextPrevious = GetEditBoxText();
192 override void HandlerDeattached(Widget w)
194 super.HandlerDeattached(w);
196 ClearInteractionState();
200 override bool OnFocus(Widget w,
int x,
int y)
203 GetGame().GetWorkspace().SetFocusedWidget(m_wEditBox);
210 void OnValueChanged()
213 m_Hint.SetVisible(
false);
220 AnimateWidget.Opacity(m_wWarningIcon, 0, m_fColorsAnimationTime,
true);
222 AnimateWidget.Color(m_wColorOverlay, COLOR_VALID_INPUT, m_fColorsAnimationTime);
223 m_bValidInput =
true;
228 void OnHandlerFocus()
237 m_wRoot.SetFlags(WidgetFlags.NOFOCUS);
238 m_OnFocusChangedEditBox.Invoke(
this, m_wEditBox,
true);
240 UpdateBackgroundColor();
243 if(m_wMultilineEditBoxWidget || m_wEditBoxWidget)
244 GetGame().GetCallqueue().CallLater(UpdateInteractionState, INTERACTION_STATE_UPDATE_FREQUENCY,
true,
false);
248 void OnHandlerFocusLost()
251 super.OnFocusLost(
m_wRoot, 0, 0);
254 m_bIsFocused =
false;
258 m_wRoot.ClearFlags(WidgetFlags.NOFOCUS);
260 m_OnFocusChangedEditBox.Invoke(
this, m_wEditBox,
false);
262 ClearInteractionState();
266 void OnInvalidInput()
269 if (!m_Hint || m_Hint && m_Hint.GetMessage().IsEmpty())
270 AnimateWidget.Opacity(m_wWarningIcon, 1, m_fColorsAnimationTime,
true);
271 else if (m_Hint && !m_Hint.GetMessage().IsEmpty())
272 m_Hint.SetVisible(
true);
274 AnimateWidget.Color(m_wColorOverlay, COLOR_INVALID_INPUT, m_fColorsAnimationTime);
275 m_bValidInput =
false;
279 void ClearInvalidInput()
281 AnimateWidget.Opacity(m_wWarningIcon, 0, m_fColorsAnimationTime,
true);
283 m_Hint.SetVisible(
false);
285 AnimateWidget.Color(m_wColorOverlay, COLOR_VALID_INPUT, m_fColorsAnimationTime);
286 m_bValidInput =
false;
290 void ChangeOverlayColor(Color color)
292 m_wColorOverlay.SetColor(color);
296 void ResetOverlayColor()
298 AnimateWidget.Color(m_wColorOverlay, COLOR_VALID_INPUT, m_fColorsAnimationTime);
302 protected void OnConfirm(Widget w)
305 m_OnConfirm.Invoke(
this, GetValue());
309 protected void OnInternalButtonClicked()
311 ActivateWriteMode(
true);
315 protected string GetEditBoxText()
320 EditBoxWidget editBox = EditBoxWidget.Cast(m_wEditBox);
322 return editBox.GetText();
324 MultilineEditBoxWidget editMulti = MultilineEditBoxWidget.Cast(m_wEditBox);
326 return editMulti.GetText();
332 protected void SetEditBoxText(
string text)
337 EditBoxWidget editBox = EditBoxWidget.Cast(m_wEditBox);
340 editBox.SetText(text);
344 MultilineEditBoxWidget editMulti = MultilineEditBoxWidget.Cast(m_wEditBox);
346 editMulti.SetText(text);
350 protected string GetPlaceholderText()
352 EditBoxWidget editBox = EditBoxWidget.Cast(m_wEditBox);
354 return editBox.GetPlaceholderText();
359 void SetPlaceholderText(
string str)
361 EditBoxWidget editBox = EditBoxWidget.Cast(m_wEditBox);
363 editBox.SetPlaceholderText(str);
369 static SCR_EditBoxComponent GetEditBoxComponent(
string name, Widget parent,
bool searchAllChildren =
true)
371 if (!parent || name ==
string.Empty)
375 if (searchAllChildren)
376 w = parent.FindAnyWidget(name);
378 w = parent.FindWidget(name);
389 void ActivateWriteMode(
bool refocus =
false)
393 Widget target = m_wMultilineEditBoxWidget;
394 if (!m_wMultilineEditBoxWidget)
395 target = m_wEditBoxWidget;
397 GetGame().GetWorkspace().SetFocusedWidget(target);
400 if (m_wMultilineEditBoxWidget)
401 m_wMultilineEditBoxWidget.ActivateWriteMode();
404 if (m_wEditBoxWidget)
405 m_wEditBoxWidget.ActivateWriteMode();
409 void ShowHint(
bool show)
412 m_Hint.SetVisible(show);
416 void ShowWriteIcon(
bool show)
418 if (m_wWriteIconScale)
419 m_wWriteIconScale.SetVisible(show);
423 void UpdateInteractionState(
bool forceDisabled)
425 int interactionStateUpdateDelay;
428 m_bIsInWriteMode =
false;
429 interactionStateUpdateDelay = FOCUS_LOST_INTERACTION_STATE_UPDATE_DELAY;
434 if (m_wMultilineEditBoxWidget)
435 m_bIsInWriteMode = m_wMultilineEditBoxWidget.IsInWriteMode();
437 else if (m_wEditBoxWidget)
438 m_bIsInWriteMode = m_wEditBoxWidget.IsInWriteMode();
441 if (m_bIsInWriteMode != m_bIsInWriteModePrevious || forceDisabled)
443 SCR_MenuHelper.SetActiveWidgetInteractionState(m_bIsInWriteMode, interactionStateUpdateDelay);
445 UpdateBackgroundColor();
448 m_OnWriteModeEnter.Invoke();
450 m_OnWriteModeLeave.Invoke(GetEditBoxText());
453 m_bIsInWriteModePrevious = m_bIsInWriteMode;
455 if (GetEditBoxText() != m_sTextPrevious || forceDisabled)
457 m_sTextPrevious = GetEditBoxText();
458 m_OnTextChange.Invoke(m_sTextPrevious);
463 void ClearInteractionState()
465 GetGame().GetCallqueue().Remove(UpdateInteractionState);
466 UpdateInteractionState(
true);
470 protected void UpdateBackgroundColor()
472 if (!m_wEditBackground)
475 Color idleColor = m_BackgroundDefault;
477 idleColor = m_BackgroundFocused;
480 m_BackgroundCurrent = m_BackgroundInteracting;
482 m_BackgroundCurrent = idleColor;
484 AnimateWidget.Color(m_wEditBackground, m_BackgroundCurrent, m_fAnimationRate);
489 void SetValue(
string value) { SetEditBoxText(value); }
490 string GetValue() {
return GetEditBoxText(); }
491 string GetPlaceHolderText() {
return GetPlaceholderText(); }
492 Widget GetEditBoxWidget() {
return m_wEditBox; }
493 bool IsValidInput() {
return m_bValidInput; }
495 bool IsInWriteMode() {
return m_bIsInWriteMode; }
500 return m_EVHComponent;
505 void ConfirmValue(
string value)
507 SetEditBoxText(value);