Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_EditBoxSearchComponent.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
3 {
4  [Attribute("1")]
5  protected bool m_bColorizeText;
6 
7  [Attribute(UIColors.GetColorAttribute(UIColors.NEUTRAL_ACTIVE_STANDBY), UIWidgets.ColorPicker)]
8  protected ref Color m_cDefault;
9 
10  [Attribute(UIColors.GetColorAttribute(UIColors.HIGHLIGHTED), UIWidgets.ColorPicker)]
11  protected ref Color m_cFocused;
12 
13  [Attribute(UIColors.GetColorAttribute(UIColors.CONTRAST_COLOR), UIWidgets.ColorPicker)]
14  protected ref Color m_cSearched;
15 
16  [Attribute()]
17  protected string m_sMessage;
18 
19  [Attribute("1", desc: "Should the message be hidden if there's text in the search bar")]
20  protected bool m_bHideMessageOnSearch;
21 
22  protected ref array<Widget> m_aColorizedElements = {};
23  protected SCR_ESearchBoxState m_eState;
24  protected bool m_bIsFilterActive;
25 
26  protected RichTextWidget m_wMessage;
27  protected SCR_ModularButtonComponent m_MessageButton;
28  protected string m_sLastSearch;
29 
30  //------------------------------------------------------------------------------------------------
31  override protected void HandlerAttached(Widget w)
32  {
33  super.HandlerAttached(w);
34 
35  m_wMessage = RichTextWidget.Cast(m_wRoot.FindAnyWidget("EditBoxMessage"));
36  if (m_wMessage)
37  m_aColorizedElements.Insert(m_wMessage);
38 
39  if (m_wImgWriteIcon)
40  m_aColorizedElements.Insert(m_wImgWriteIcon);
41 
42  if (m_bColorizeText && m_wEditBoxWidget)
43  m_aColorizedElements.Insert(m_wEditBoxWidget);
44 
45  // Message button
46  Widget messageButton = m_wRoot.FindAnyWidget("EditBoxMessageButton");
47  if (messageButton)
48  m_MessageButton = SCR_ModularButtonComponent.FindComponent(messageButton);
49 
50  if (m_MessageButton)
51  m_MessageButton.m_OnClicked.Insert(OnInternalButtonClicked);
52 
53  SetMessage(m_sMessage);
54 
55  m_wBorder.SetVisible(!m_bColorizeText);
56 
57  UpdateWidgets(false);
58  }
59 
60  //------------------------------------------------------------------------------------------------
61  override bool OnMouseEnter(Widget w, int x, int y)
62  {
63  // Moving from the write icon button to the edit field will trigger OnMouseEnter, which we don't want if we're in write mode already
64  if (IsInWriteMode())
65  return false;
66 
67  return super.OnMouseEnter(w, x, y);
68  }
69 
70  //------------------------------------------------------------------------------------------------
71  override void OnHandlerFocus()
72  {
73  super.OnHandlerFocus();
74 
75  m_eState = SCR_ESearchBoxState.FOCUSED;
76  UpdateWidgets();
77  }
78 
79  //------------------------------------------------------------------------------------------------
80  override void OnHandlerFocusLost()
81  {
82  // On PC, changing focus doubles as confirmation
83  if (!GetGame().IsPlatformGameConsole() && m_bIsInWriteMode && GetValue() != m_sLastSearch)
84  OnConfirm(m_wEditBox);
85 
86  super.OnHandlerFocusLost();
87 
88  if (m_bIsFilterActive)
89  m_eState = SCR_ESearchBoxState.SEARCHED;
90  else
91  m_eState = SCR_ESearchBoxState.DEFAULT;
92 
93  UpdateWidgets();
94  }
95 
96  //------------------------------------------------------------------------------------------------
97  override protected void OnConfirm(Widget w)
98  {
99  if (m_bIsInWriteMode)
100  super.OnConfirm(w);
101 
102  m_bIsFilterActive = GetValue() != string.Empty;
103  m_sLastSearch = GetValue();
104  }
105 
106  //------------------------------------------------------------------------------------------------
107  override void UpdateInteractionState(bool forceDisabled)
108  {
109  super.UpdateInteractionState(forceDisabled);
110 
111  if (!m_wMessage)
112  return;
113 
114  bool hideMessage = m_bHideMessageOnSearch && (m_bIsInWriteMode || !GetEditBoxText().IsEmpty());
115 
116  m_wMessage.SetVisible(!hideMessage);
117  }
118 
119  //------------------------------------------------------------------------------------------------
120  protected void UpdateWidgets(bool animate = true)
121  {
122  Color color;
123 
124  switch (m_eState)
125  {
126  case SCR_ESearchBoxState.FOCUSED:
127  color = m_cFocused;
128  break;
129 
130  case SCR_ESearchBoxState.SEARCHED:
131  color = m_cSearched;
132  break;
133 
134  default:
135  color = m_cDefault;
136  break;
137  }
138 
139  foreach (Widget element : m_aColorizedElements)
140  {
141  if (animate)
142  AnimateWidget.Color(element, color, m_fColorsAnimationTime);
143  else
144  element.SetColor(color);
145  }
146  }
147 
148  //------------------------------------------------------------------------------------------------
149  bool SetMessage(string message)
150  {
151  if (!m_wMessage || !m_MessageButton)
152  return false;
153 
154  m_MessageButton.SetVisible(!message.IsEmpty());
155 
156  if (!message.IsEmpty())
157  m_wMessage.SetTextFormat(message);
158 
159  return true;
160  }
161 
162  //------------------------------------------------------------------------------------------------
165  static SCR_EditBoxSearchComponent GetEditBoxSearchComponent(string name, Widget parent, bool searchAllChildren = true)
166  {
168  SCR_WLibComponentBase.GetComponent(SCR_EditBoxSearchComponent, name, parent, searchAllChildren)
169  );
170  return comp;
171  }
172 }
173 
174 //------------------------------------------------------------------------------------------------
175 enum SCR_ESearchBoxState
176 {
177  DEFAULT,
178  FOCUSED,
179  SEARCHED
180 }
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
SCR_WLibComponentBase
Base class for all final Reforger interactive elements.
Definition: SCR_WLibComponentBase.c:4
SEARCHED
SCR_EventHandlerComponent SEARCHED
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
IsPlatformGameConsole
bool IsPlatformGameConsole()
Definition: game.c:1393
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
m_wMessage
protected RichTextWidget m_wMessage
Definition: SCR_BrowserHoverTooltipComponent.c:24
DEFAULT
SCR_EditBoxSearchComponent DEFAULT
m_eState
EAITargetClusterState m_eState
Definition: SCR_AITargetClusterState.c:24
Attribute
typedef Attribute
Post-process effect of scripted camera.
UIColors
Definition: Constants.c:16
GetValue
override int GetValue()
Definition: SCR_VotingBase.c:69
FOCUSED
SCR_EditBoxSearchComponent FOCUSED
SCR_EditBoxComponent
Definition: SCR_EditBoxComponent.c:8
SCR_EditBoxSearchComponent
Definition: SCR_EditBoxSearchComponent.c:2