7 #define DEBUG_CONFIGURABLE_DIALOGS
15 static const ResourceName NAVIGATION_BUTTON_LAYOUT =
"{87037226B1A2064B}UI/layouts/WidgetLibrary/Buttons/WLib_NavigationButtonSuperSmall.layout";
18 [
Attribute((1/
UIConstants.FADE_RATE_FAST).ToString(), UIWidgets.Auto,
"Duration of fade in and fade out animations")]
19 protected float m_fFadeInTime;
21 [
Attribute(NAVIGATION_BUTTON_LAYOUT, UIWidgets.ResourceNamePicker,
"Layout of the navigation button",
params:
"layout")]
22 protected ResourceName m_sNavigationButtonLayout;
24 [
Attribute(
"ButtonsLeft", UIWidgets.Auto,
"Widget name of left buttons layout")]
25 protected string m_sWidgetNameButtonsLeft;
27 [
Attribute(
"ButtonsRight", UIWidgets.Auto,
"Widget name of right buttons layout")]
28 protected string m_sWidgetNameButtonsRight;
30 [
Attribute(
"ButtonsCenter", UIWidgets.Auto,
"Widget name of center buttons layout")]
31 protected string m_sWidgetNameButtonsCenter;
34 ref ScriptInvoker m_OnConfirm =
new ScriptInvoker();
35 ref ScriptInvoker m_OnCancel =
new ScriptInvoker();
36 ref ScriptInvoker m_OnClose =
new ScriptInvoker();
37 ref ScriptInvoker m_OnCloseStart =
new ScriptInvoker();
38 ref ScriptInvoker m_OnButtonPressed =
new ScriptInvoker();
41 protected ImageWidget m_wImgTopLine;
42 protected ImageWidget m_wImgTitleIcon;
43 protected TextWidget m_wTitle;
44 protected TextWidget m_wMessage;
45 protected VerticalLayoutWidget m_wContentVerticalLayout;
48 protected ref map<string, SCR_InputButtonComponent> m_aButtonComponents =
new map<string, SCR_InputButtonComponent>;
49 protected Widget m_wRoot;
50 protected OverlayWidget m_wDialogBase;
55 protected MenuBase m_ProxyMenu;
61 protected string m_sLastPressedButtonTag;
64 protected bool m_bIsClosing;
68 static const string BUTTON_CONFIRM =
"confirm";
69 static const string BUTTON_CANCEL =
"cancel";
80 Resource rsc = BaseContainerTools.LoadContainer(presetsResourceName);
81 BaseContainer container = rsc.GetResource().ToBaseContainer();
90 Print(
string.Format(
"[SCR_ConfigurableDialogUi] Preset was not found: %1, %2", presets, tag), LogLevel.ERROR);
97 #ifdef DEBUG_CONFIGURABLE_DIALOGS
98 Print(
string.Format(
"[SCR_ConfigurableDialogUi] presetsResourceName: %1, tag: %2, customDialogObj: %3", presetsResourceName, tag, customDialogObj));
111 Widget internalWidget =
GetGame().GetWorkspace().CreateWidgets(preset.m_sLayout, proxyComp.GetRootWidget());
115 Print(
string.Format(
"[SCR_ConfigurableDialogUi] internalWidget wans't created"), LogLevel.ERROR);
120 if(!preset.m_sContentLayout.IsEmpty())
122 Widget contentContainer = GetContentWidget(internalWidget);
124 if(!contentContainer)
126 Print(
string.Format(
"[SCR_ConfigurableDialogUi] CreateByPreset() contentContainer wasn't found"), LogLevel.ERROR);
130 Widget contentWidget =
GetGame().GetWorkspace().CreateWidgets(preset.m_sContentLayout, contentContainer);
132 AlignableSlot.SetHorizontalAlign(contentWidget, LayoutHorizontalAlign.Stretch);
141 dialog = customDialogObj;
144 dialog.InitAttributedVariables();
145 internalWidget.AddHandler(dialog);
148 dialog.Init(internalWidget, preset, proxyComp);
149 proxyComp.Init(dialog);
152 if (!preset.m_sActionContext.IsEmpty())
153 proxyComp.SetActionContext(preset.m_sActionContext);
156 dialog.OnMenuOpen(preset);
158 m_CurrentDialog = dialog;
163 static void InitFromPreset(ResourceName presetsResourceName,
string tag, Widget widget)
166 Resource rsc = BaseContainerTools.LoadContainer(presetsResourceName);
167 BaseContainer container = rsc.GetResource().ToBaseContainer();
176 Print(
string.Format(
"[SCR_ConfigurableDialogUi] Preset was not found: %1, %2", presets, tag), LogLevel.ERROR);
180 InitByPreset(preset, widget);
187 Widget parent = widget;
190 menu = MenuBase.Cast(parent.FindHandler(MenuBase));
194 parent = parent.GetParent();
198 dialog.InitAttributedVariables();
199 dialog.Init(widget, preset, menu);
205 return m_CurrentDialog;
209 static string GetCurrentDialogTag()
212 return m_CurrentDialog.GetDialogPreset().m_sTag;
218 static bool IsPresetValid(ResourceName presetsResourceName,
string tag)
221 Resource rsc = BaseContainerTools.LoadContainer(presetsResourceName);
222 BaseContainer container = rsc.GetResource().ToBaseContainer();
226 return presets.FindPreset(tag);
239 m_OnCloseStart.Invoke(
this);
245 void SetTitle(
string text)
248 m_wTitle.SetText(text);
253 void SetMessage(
string text)
263 void SetMessageColor(Color color)
270 TextWidget GetMessageWidget() {
return m_wMessage; }
273 string GetMessageStr()
284 void SetTitleIcon(ResourceName image,
string imageName)
286 if (!m_wImgTitleIcon)
290 if (image.EndsWith(
"imageset"))
291 m_wImgTitleIcon.LoadImageFromSet(0, image, imageName);
293 m_wImgTitleIcon.LoadImageTexture(0, image);
298 void SetIconColor(Color color)
300 if (!m_wImgTitleIcon)
303 m_wImgTitleIcon.SetColor(color);
311 if (!m_wImgTopLine || !m_wImgTitleIcon)
315 Color color = Color.FromInt(Color.WHITE);
320 color = Color.FromInt(
UIColors.CONTRAST_COLOR.PackToInt());
324 color = Color.FromInt(
UIColors.WARNING.PackToInt());
328 color = Color.FromInt(
UIColors.CONFIRM.PackToInt());
332 color = Color.FromInt(
UIColors.ONLINE.PackToInt());
337 m_wImgTopLine.SetColor(color);
338 m_wImgTitleIcon.SetColor(color);
343 static Widget GetContentWidget(Widget baseWidget)
347 Print(
string.Format(
"[SCR_ConfigurableDialogUi] GetContentWidet(): invalid base Widget"), LogLevel.ERROR);
351 Widget contentContainer = baseWidget.FindAnyWidget(
"ContentLayoutContainer");
353 if(!contentContainer)
355 Print(
string.Format(
"[SCR_ConfigurableDialogUi] GetContentWidet(): couldn't find ContentLayoutContainer widget in base layout"), LogLevel.ERROR);
359 return contentContainer;
364 static Widget GetContentLayoutRoot(Widget baseWidget)
366 return GetContentWidget(baseWidget).GetChildren();
371 OverlayWidget GetDialogBaseOverlay()
373 return m_wDialogBase;
383 button.m_OnActivated.Insert(OnConfirm);
400 button.m_OnActivated.Insert(OnCancel);
417 button.m_OnActivated.Insert(OnButtonPressed);
420 Widget root = button.GetRootWidget();
421 string buttonTag = tag;
422 if (root && buttonTag.IsEmpty())
423 buttonTag = root.GetName();
438 protected void OnConfirm()
441 m_OnConfirm.Invoke(
this);
446 protected void OnCancel()
449 m_OnCancel.Invoke(
this);
456 m_sLastPressedButtonTag = GetButtonTag(button);
457 m_OnButtonPressed.Invoke(
this, m_sLastPressedButtonTag);
466 void OnMenuUpdate(
float tDelta);
469 void OnMenuFocusGained();
472 void OnMenuFocusLost();
486 HorizontalLayoutWidget wLayout;
487 float padding, paddingLeft, paddingRight;
488 switch (buttonPreset.m_eAlign)
491 wLayout = HorizontalLayoutWidget.Cast(GetRootWidget().FindAnyWidget(m_sWidgetNameButtonsLeft));
495 wLayout = HorizontalLayoutWidget.Cast(GetRootWidget().FindAnyWidget(m_sWidgetNameButtonsRight));
499 wLayout = HorizontalLayoutWidget.Cast(GetRootWidget().FindAnyWidget(m_sWidgetNameButtonsCenter));
break;
502 Widget wButton =
GetGame().GetWorkspace().CreateWidgets(m_sNavigationButtonLayout, wLayout);
505 float left, top, bottom;
506 AlignableSlot.GetPadding(wButton, left, top, padding, bottom);
507 switch (buttonPreset.m_eAlign)
510 paddingRight = padding;
514 paddingLeft = padding;
520 AlignableSlot.SetPadding(wButton, paddingLeft, 0.0, paddingRight, 0.0);
528 comp.SetVisible(buttonPreset.m_bShowButton,
false);
529 comp.SetLabel(buttonPreset.m_sLabel);
530 comp.SetAction(buttonPreset.m_sActionName);
532 comp.SetHoverSound(buttonPreset.m_sSoundHovered);
533 comp.SetClickedSound(buttonPreset.m_sSoundClicked);
535 comp.m_OnActivated.Insert(OnButtonPressed);
569 m_ProxyMenu = proxyMenu;
570 m_DialogPreset = preset;
576 SetTitle(preset.m_sTitle);
579 if (!preset.m_sMessage.IsEmpty())
581 SetMessage(preset.m_sMessage);
585 SetStyle(preset.m_eVisualStyle);
589 m_wImgTitleIcon.SetVisible(preset.m_bShowIcon);
591 if (!preset.m_sTitleIconTexture.IsEmpty())
593 SetTitleIcon(preset.m_sTitleIconTexture, preset.m_sTitleIconImageName);
600 HorizontalLayoutWidget wLeft = HorizontalLayoutWidget.Cast(GetRootWidget().FindAnyWidget(m_sWidgetNameButtonsLeft));
601 HorizontalLayoutWidget wRight = HorizontalLayoutWidget.Cast(GetRootWidget().FindAnyWidget(m_sWidgetNameButtonsRight));
602 HorizontalLayoutWidget wCenter = HorizontalLayoutWidget.Cast(GetRootWidget().FindAnyWidget(m_sWidgetNameButtonsCenter));
606 CreateButton(buttonPreset);
611 BindButtonConfirm(buttonConfirm);
614 BindButtonCancel(buttonCancel);
619 protected void InitWidgets()
624 m_wImgTopLine = ImageWidget.Cast(w.FindAnyWidget(
"Separator"));
625 m_wImgTitleIcon = ImageWidget.Cast(w.FindAnyWidget(
"ImgTitleIcon"));
628 m_wTitle = TextWidget.Cast(w.FindAnyWidget(
"Title"));
629 m_wMessage = TextWidget.Cast(w.FindAnyWidget(
"Message"));
632 m_wContentVerticalLayout = VerticalLayoutWidget.Cast(w.FindAnyWidget(
"ContentVerticalLayout"));
635 m_wDialogBase = OverlayWidget.Cast(w.FindAnyWidget(
"DialogBase"));
645 Widget GetRootWidget()
653 return m_DialogPreset;
657 protected void Internal_Close()
663 m_OnClose.Invoke(
this);
669 protected void InitAttributedVariables()
671 if (m_sNavigationButtonLayout.IsEmpty())
672 m_sNavigationButtonLayout = NAVIGATION_BUTTON_LAYOUT;
674 if (m_sWidgetNameButtonsLeft.IsEmpty())
675 m_sWidgetNameButtonsLeft =
"ButtonsLeft";
677 if (m_sWidgetNameButtonsRight.IsEmpty())
678 m_sWidgetNameButtonsRight =
"ButtonsRight";
680 if (m_sWidgetNameButtonsCenter.IsEmpty())
681 m_sWidgetNameButtonsCenter =
"ButtonsCenter";
683 if (m_fFadeInTime == 0)
701 override void OnMenuUpdate(
float tDelta)
703 super.OnMenuUpdate(tDelta);
704 m_Dlg.OnMenuUpdate(tDelta);
708 override void OnMenuFocusGained()
710 super.OnMenuFocusGained();
713 m_Dlg.OnMenuFocusGained();
717 override void OnMenuFocusLost()
719 super.OnMenuFocusLost();
722 m_Dlg.OnMenuFocusLost();
726 override void OnMenuShow()
735 override void OnMenuHide()
744 override void OnMenuClose()
784 [
Attribute(
"", UIWidgets.Auto,
"Custom tag, used for finding this button at run time")]
787 [
Attribute(
"", UIWidgets.Auto,
"Action name the button will listen to")]
788 string m_sActionName;
790 [
Attribute(
"", UIWidgets.Auto,
"Label of the button")]
797 string m_sSoundHovered;
800 string m_sSoundClicked;
811 [
Attribute(
"{E6B607B27BCC1477}UI/layouts/Menus/Dialogs/ConfigurableDialog.layout", UIWidgets.ResourceNamePicker,
".layout for the base of the dialog",
params:
"layout")]
812 ResourceName m_sLayout;
814 [
Attribute(
"", UIWidgets.ResourceNamePicker,
".layout for the content of the dialog",
params:
"layout")]
815 ResourceName m_sContentLayout;
817 [
Attribute(
"", UIWidgets.Auto,
"Custom tag, used for finding this preset at run time.")]
820 [
Attribute(
"0", UIWidgets.ComboBox,
"Visual style. Affects color of elements.",
"", ParamEnumArray.FromEnum(
EDialogType))]
823 [
Attribute(
UIConstants.ICONS_IMAGE_SET, UIWidgets.ResourcePickerThumbnail,
"Texture or imageset for title icon",
"edds imageset")]
824 ResourceName m_sTitleIconTexture;
830 string m_sTitleIconImageName;
832 [
Attribute(
"", UIWidgets.Auto,
"Message to be displayed inside, if messaage widget is present.")]
835 [
Attribute(
"", UIWidgets.Auto,
"Title of the dialog")]
839 ref array<ref SCR_ConfigurableDialogUiButtonPreset> m_aButtons;
841 [
Attribute(
string.Empty, UIWidgets.EditBox,
"Action context of the menu. If empty, MenuContext is used, same as in standard menu manager.")]
842 string m_sActionContext;
852 ref array<ref SCR_ConfigurableDialogUiPreset> m_aPresets;