14 override bool _WB_GetCustomTitle(BaseContainer source, out
string title)
18 source.Get(
"m_sGroupTag", groupTag);
22 source.Get(
"m_sPropertyName", name);
26 source.Get(
"m_sClassTag", classTag);
31 if (!groupTag.IsEmpty())
32 title += groupTag +
": ";
39 if (!classTag.IsEmpty())
40 title +=
string.Format(
"(%1)", classTag);
50 protected string m_Label;
51 protected string m_PropertyName;
54 override bool _WB_GetCustomTitle(BaseContainer source, out
string title)
58 source.Get(
"m_Label", label);
62 source.Get(
"m_PropertyName", property);
65 title = label +
": " + property;
80 string m_sPropertyName;
84 if (m_sLabel.IsEmpty())
98 ref array<string> m_aInfo;
117 const string INVALID_VALUE =
"-invalid-";
119 [
Attribute(
"{0022F0B45ADBC5AC}UI/layouts/WidgetLibrary/EditBox/WLib_EditBox.layout", UIWidgets.ResourceNamePicker,
"What kind of widget should be generated for this value",
"layout")]
120 protected ResourceName m_sEntryLayout;
123 protected bool m_bShow;
125 [
Attribute(
"", UIWidgets.EditBox,
"Text for label")]
126 protected string m_sLabel;
128 [
Attribute(
"", UIWidgets.EditBox,
"Name of property that in json file")]
129 protected string m_sPropertyName;
131 [
Attribute(
"", UIWidgets.EditBox,
"Name of property that in json file")]
132 protected string m_sGroupTag;
134 [
Attribute(
"", UIWidgets.EditBox,
"Fallback value that will be prefilled at start")]
135 protected string m_sDefaultValue;
138 protected bool m_bRequired;
141 protected bool m_bInteractive;
145 protected string m_sClassTag;
147 protected Widget m_EntryRoot;
149 protected bool m_bValidInput =
true;
152 void CreateWidget(Widget parent)
155 Widget w =
GetGame().GetWorkspace().CreateWidgets(m_sEntryLayout, parent);
159 if (!m_ChangeableComponent)
162 m_ChangeableComponent.SetLabel(m_sLabel);
165 SetInteractive(m_bInteractive);
170 w.SetVisible(m_bShow);
175 protected void SetupHandlers();
179 string ValueAsString();
182 void SetValue(
string str){}
191 m_bValidInput =
true;
193 return m_bValidInput;
198 protected bool CanSkip()
200 return ValueAsString().IsEmpty() && !m_bRequired;
205 void SetInteractive(
bool interactive)
207 if (!m_ChangeableComponent)
210 m_ChangeableComponent.SetEnabled(interactive,
false);
218 ResourceName GetEntryLayout()
220 return m_sEntryLayout;
224 void SetEntryLayout(ResourceName
layout)
236 void SetLabel(
string label)
242 string GetPropertyName()
248 void SetPropertyName(
string propertyName)
260 void SetGroupTag(
string tag)
272 Widget GetEntryRoot()
280 return m_bValidInput;
288 [
Attribute(
"", UIWidgets.EditBox,
"Group tag for fast recongition")]
289 protected string m_sTag;
292 protected ref array<ref SCR_WidgetListEntry> m_aEntries;
308 protected float m_iOffsetTop;
311 protected float m_iOffsetBottom;
314 protected float m_iLeftBottom;
317 override void CreateWidget(Widget parent)
319 TextWidget wText = TextWidget.Cast(
GetGame().GetWorkspace().CreateWidgets(m_sEntryLayout, parent));
323 wText.SetText(m_sLabel);
324 VerticalLayoutSlot.SetPadding(wText, m_iLeftBottom, m_iOffsetTop, 0, m_iOffsetBottom);
326 m_sClassTag =
"label";
339 protected int m_CharLimit;
341 [
Attribute(
"5", UIWidgets.EditBox,
"In how many seconds should editbox error should be cleared after focus")]
342 protected int m_fClearErrorTimes;
348 protected string m_sPlaceholderText;
350 [
Attribute(
"0",
desc:
"When false - there will be used warning text below as default. Otherwise there might be hardcoded strings in format messages.")]
351 protected bool m_bUseFormatWarning;
354 protected string m_sWarningText;
357 protected string m_sObfuscation;
360 protected string m_sCharBlackList;
363 protected bool m_bShowWriteIcon;
369 override protected void SetupHandlers()
371 if (m_ChangeableComponent)
379 m_iType = m_iEditType;
380 m_sClassTag =
"edit";
383 m_EditBox.SetValue(m_sDefaultValue);
384 m_EditBox.SetPlaceholderText(m_sPlaceholderText);
385 m_EditBox.GetHint().SetMessage(m_sWarningText);
386 m_EditBox.ShowWriteIcon(m_bShowWriteIcon);
388 EditBoxWidget editBox = EditBoxWidget.Cast(m_EditBox.GetEditBoxWidget());
389 editBox.SetObfuscationChar(m_sObfuscation);
393 m_EditBox.m_OnConfirm.Insert(CheckValidity);
394 m_EditBox.m_OnChanged.Insert(CheckValidity);
395 m_EditBox.m_OnFocusChangedEditBox.Insert(OnFocusChange);
399 m_FormatCheck.SetEditBoxFilter(m_Filter);
402 GetGame().GetCallqueue().CallLater(SetCharLists);
411 m_Filter.SetNumbers(
true);
413 m_Filter.SetASCIIchars(
false);
414 m_Filter.SetUTFMultibyte(
false);
421 m_Filter.SetCharacterLimit(m_CharLimit);
422 m_Filter.m_OnInvalidInput.Insert(OnInvalidInput);
423 m_Filter.m_OnTextTooLong.Insert(OnInvalidInput);
426 m_Filter.SetCharBlacklist(m_sCharBlackList);
430 protected void SetCharLists()
432 m_Filter.SetCharBlacklist(m_sCharBlackList);
436 override string ValueAsString()
439 return INVALID_VALUE;
441 return m_EditBox.GetValue();
445 override void SetValue(
string str)
448 m_EditBox.SetValue(str);
452 override bool CheckValidity()
457 CheckEditBoxValidity(m_EditBox, m_EditBox.GetValue());
458 return m_bValidInput;
467 bool valid = CheckValidity();
470 GetGame().GetCallqueue().Remove(ClearInvalidInput);
477 m_bValidInput =
true;
489 m_bValidInput =
true;
493 m_bValidInput = m_FormatCheck.IsFormatValid(value);
496 if (m_Filter && !m_bValidInput)
500 GetGame().GetCallqueue().CallLater(InvokeInvalidInput);
504 if (m_bUseFormatWarning)
505 m_EditBox.GetHint().SetMessage(m_FormatCheck.GetFormatMessage());
509 protected void InvokeInvalidInput()
511 m_Filter.m_OnInvalidInput.Invoke();
515 protected void OnInvalidInput()
519 GetGame().GetCallqueue().CallLater(ClearInvalidInput, m_fClearErrorTimes * 1000);
523 void ClearInvalidInput()
526 m_EditBox.ClearInvalidInput();
538 return m_FormatCheck;
542 void SetWarningText(
string warning)
547 if (m_EditBox.GetHint())
548 m_EditBox.GetHint().SetMessage(warning);
557 protected SCR_WidgetEditFormatIP m_IPCheck;
560 override protected void SetupHandlers()
562 super.SetupHandlers();
563 m_IPCheck = SCR_WidgetEditFormatIP.Cast(m_FormatCheck);
567 override bool CheckValidity()
569 super.CheckValidity();
575 m_EditBox.ShowHint(
true);
578 return m_bValidInput;
588 protected string m_sPositive;
591 protected string m_sNegative;
598 if (m_ChangeableComponent)
602 m_sClassTag =
"check box";
605 if (!m_sNegative.IsEmpty() && m_Checkbox.m_aSelectionElements[0])
609 textComp.SetText(m_sNegative);
612 if (!m_sPositive.IsEmpty() && m_Checkbox.m_aSelectionElements[1])
616 textComp.SetText(m_sPositive);
629 m_Checkbox.SetChecked(checked);
633 override string ValueAsString()
636 return INVALID_VALUE;
638 return m_Checkbox.IsChecked().ToString();
654 protected ref array<ref SCR_LocalizedProperty> m_aOptions;
659 override protected void SetupHandlers()
661 if (m_ChangeableComponent)
668 for (
int i = 0, count = m_aOptions.Count(); i < count; i++)
670 m_Selection.AddItem(m_aOptions[i].m_sLabel);
674 if (!m_sDefaultValue.IsEmpty())
675 SelectOption(m_sDefaultValue.ToInt());
679 override string ValueAsString()
682 return INVALID_VALUE;
684 int id = m_Selection.m_iSelectedItem;
687 Print(
"option Id: " +
id +
"/" + m_aOptions.Count());
690 if (
id == -1 ||
id >= m_aOptions.Count())
691 return INVALID_VALUE;
693 if (m_aOptions[
id] ==
null)
694 return INVALID_VALUE;
696 return m_aOptions[id].m_sPropertyName;
704 return INVALID_VALUE;
706 return m_Selection.m_iSelectedItem;
717 m_Selection.SetCurrentItem(
id);
727 id = m_Selection.GetCurrentIndex();
732 return m_aOptions[id];
737 void SetOptions(array<ref SCR_LocalizedProperty> options)
739 m_aOptions = options;
745 m_Selection.ClearAll();
747 for (
int i = 0, count = m_aOptions.Count(); i < count; i++)
749 m_Selection.AddItem(m_aOptions[i].m_sLabel);
760 void GetOptions(out array<ref SCR_LocalizedProperty> options)
762 for (
int i = 0, count = m_aOptions.Count(); i < count; i++)
764 options.Insert(m_aOptions[i]);
775 protected bool m_bCycle;
780 override protected void SetupHandlers()
782 super.SetupHandlers();
792 override void SetValue(
string str)
810 protected bool m_bReversed;
815 if (m_ChangeableComponent)
824 for (
int i = m_aOptions.Count() - 1; i >= 0; i--)
826 m_Selection.AddItem(m_aOptions[i].m_sLabel);
831 for (
int i = 0, count = m_aOptions.Count(); i < count; i++)
833 m_Selection.AddItem(m_aOptions[i].m_sLabel);
838 if (!m_sDefaultValue.IsEmpty())
839 SelectOption(m_sDefaultValue.ToInt());
853 int value = str.ToInt();
882 protected string m_sFormatText;
889 if (m_ChangeableComponent)
895 m_Slider.SetFormatText(m_sFormatText);
897 m_Slider.SetValue(m_sDefaultValue.ToFloat());
906 m_Slider.SetValue(str.ToFloat());
910 override string ValueAsString()
913 return INVALID_VALUE;
915 return m_Slider.GetValue().ToString();
921 m_Slider.SetMin(min);
922 m_Slider.SetMax(max);