4 protected Widget m_wRootWidget;
5 protected OverlayWidget m_wOverlayWidget;
7 protected ButtonWidget m_wButtonWidget;
10 protected const string BUTTON_WIDGET_NAME =
"NavigationButton1";
13 void SetText(
string text,
string name)
15 if (!m_NavigationButton)
18 m_NavigationButton.SetAction(text);
19 m_NavigationButton.SetLabel(name);
23 void SetSize(
int size)
25 if (m_NavigationButton)
26 m_NavigationButton.SetSize(size);
30 void SetVisible(
bool isVisible)
33 m_wRootWidget.SetVisible(isVisible);
37 void SetPadding(
float padding)
39 if (!m_wOverlayWidget)
42 float left, top, right, bottom;
43 OverlaySlot.GetPadding(m_wOverlayWidget, left, top, right, bottom);
44 OverlaySlot.SetPadding(m_wOverlayWidget, left, padding, right, padding);
51 return m_wRootWidget.IsVisible();
59 if (
layout ==
string.Empty)
69 Widget root =
GetGame().GetWorkspace().CreateWidgets(
layout, parent);
70 instance.m_wRootWidget = root;
73 instance.m_wButtonWidget = ButtonWidget.Cast(root.FindAnyWidget(instance.BUTTON_WIDGET_NAME));
76 if (instance.m_NavigationButton)
77 instance.m_NavigationButton.SetClickSoundDisabled(
true);
79 instance.SetText(text, name);
85 Widget GetRootWidget() {
return m_wRootWidget; }
94 m_wRootWidget.RemoveFromHierarchy();
102 override bool _WB_GetCustomTitle(BaseContainer source, out
string title)
105 int index = source.GetVarIndex(
"m_sAction");
111 source.Get(
"m_sTag", tag);
113 source.Get(
"m_sAction", title);
117 source.Get(
"m_bEnabled", enabled);
119 string enabledStr =
"x";
124 title =
"(" + title +
") " + tag +
" - " + enabledStr;
135 protected bool m_bEnabled;
137 [
Attribute(
"0", UIWidgets.EditBox,
"Amount of mili seconds to hide this hint, 0 and less means no hidding")]
138 protected int m_iTimeForHide;
141 protected ref array<ref SCR_AvailableActionCondition> m_aConditions;
143 [
Attribute(
"DefaultTag", UIWidgets.EditBox,
"Tag for quick search and recongnition. Change default tag to allow easier search.")]
144 protected string m_sTag;
146 [
Attribute(
"", UIWidgets.EditBox,
"Name of the action in action manager")]
147 protected string m_sAction;
149 [
Attribute(
"", UIWidgets.EditBox,
"Name of the action in to be displayed in UI")]
150 protected string m_sName;
152 protected const string MARKUP_FORMAT =
"<action name=\"%1\"/>";
154 protected bool m_bActivated =
false;
155 protected bool m_bHideTimeOver =
true;
158 string ToString(
bool forceText =
true)
162 text =
string.Format(MARKUP_FORMAT, m_sAction);
164 text =
string.Format(MARKUP_FORMAT, m_sAction);
166 return string.Format(
"%1", text);
170 string GetActionName()
193 foreach (
auto cond : m_aConditions)
195 if (!cond.IsEnabled())
198 if (!cond.IsAvailable(
data))
201 m_bActivated =
false;
203 GetGame().GetCallqueue().Remove(CountHideTime);
204 m_bHideTimeOver =
true;
211 if (m_iTimeForHide > 0 && m_bHideTimeOver && !m_bActivated)
213 m_bHideTimeOver =
false;
214 GetGame().GetCallqueue().Remove(CountHideTime);
215 GetGame().GetCallqueue().CallLater(CountHideTime, m_iTimeForHide,
false);
223 if (m_iTimeForHide > 0 && m_bHideTimeOver)
230 protected void CountHideTime()
232 m_bHideTimeOver =
true;
240 [
Attribute(
"", UIWidgets.Object,
"List of all actions to process at any given moment, these are filtered and available ones are displayed")]
241 protected ref array<ref SCR_AvailableActionContext> m_aActions;
243 [
Attribute(
"", UIWidgets.ResourceNamePicker,
"Layout used for individual action widgets",
params:
"layout")]
244 protected ResourceName m_sChildLayout;
247 protected float m_fDefaultOffsetY;
249 protected float m_fOffsetY;
250 protected float m_fAdditionalOffsetY = 0;
253 protected ref array<ref AvailableActionLayoutBehaviorBase> m_aBehaviors;
255 [
Attribute(
"40",
desc:
"Size of the small button which will be used when there are too many bigger buttons. (Height in px)")]
256 protected int m_iButtonSizeSmall;
258 [
Attribute(
"44",
desc:
"Size of the medium button which will be used when there are too many bigger buttons. (Height in px)")]
259 protected int m_iButtonSizeMedium;
261 [
Attribute(
"48",
desc:
"Size of the large button. This is the maximum size of the shown button. If there are too many one of the above will be used instead. (Height in px)")]
262 protected int m_iButtonSizeLarge;
265 protected const int PRELOADED_WIDGETS_COUNT = 16;
268 protected ref array<ref SCR_AvailableActionsWidget> m_aWidgets =
new array<ref SCR_AvailableActionsWidget>();
271 protected Widget m_wLayoutWidget;
274 protected int m_iLastCount;
277 protected bool m_bIsEnabledSettings;
285 protected float m_fDataFetchTimer;
288 protected int m_iMaxActionsBig = 5;
289 protected int m_iMaxActionsMedium = 7;
292 const int HEIGHT_DIVIDER_BIG = 70;
293 const int HEIGHT_DIVIDER_MEDIUM = 50;
295 const int HINT_SIZE_Y = 34;
296 const int DEFAULT_FONT_SIZE = 20;
297 const int MIN_FONT_SIZE = 16;
308 ArmaReforgerScripted game =
GetGame();
312 InputManager inputManager = game.GetInputManager();
318 foreach (
auto action : inActions)
320 auto actionName = action.GetActionName();
322 if (actionName ==
string.Empty)
325 if (inputManager.IsActionActive(actionName) && action.IsAvailable(
data))
327 outActions.Insert(action);
336 protected bool CanBeShown(IEntity controlledEntity)
341 ChimeraCharacter character = ChimeraCharacter.Cast(controlledEntity);
345 CharacterControllerComponent controller = character.GetCharacterController();
357 protected void UpdateIsEnabled()
360 m_bIsEnabledSettings =
true;
362 BaseContainer gameplaySettings =
GetGame().GetGameUserSettings().GetModule(
"SCR_GameplaySettings");
363 if (gameplaySettings)
364 gameplaySettings.Get(
"m_bControlHints", m_bIsEnabledSettings);
368 override event void DisplayUpdate(IEntity owner,
float timeSlice)
389 if (m_bIsEnabledSettings && CanBeShown(controlledEntity))
400 m_fDataFetchTimer += timeSlice;
402 if (m_fDataFetchTimer >= 0.25)
404 m_data.FetchData(controlledEntity, m_fDataFetchTimer);
405 DisplayWidgetsUpdate();
407 m_fDataFetchTimer = 0;
412 private void DisplayWidgetsUpdate()
414 array<SCR_AvailableActionContext> availableActions =
new array<SCR_AvailableActionContext>();
415 int actionsCount = GetAvailableActions(m_data,
m_aActions, availableActions);
418 if (actionsCount > m_iLastCount)
420 for (
int i = m_iLastCount; i < actionsCount; i++)
433 for (
int i = actionsCount; i < m_iLastCount; i++)
446 for (
int i = 0; i < actionsCount; i++)
455 if (actionsCount > m_iMaxActionsMedium)
459 else if (actionsCount > m_iMaxActionsBig)
470 m_iLastCount = actionsCount;
473 ApplyLayoutBehavior();
477 protected void DisplayHint(Widget widget,
float delayFade,
float delayShrink)
479 widget.SetOpacity(0);
480 VerticalLayoutSlot.SetPadding(widget, 0, -HINT_SIZE_Y, 0, 0);
481 widget.SetVisible(
true);
484 GetGame().GetCallqueue().Remove(HintShrink);
485 GetGame().GetCallqueue().Remove(HintHide);
488 float padding[4] = {0, 0, 0, 0};
489 AnimateWidget.Padding(widget, padding, delayShrink);
490 AnimateWidget.Opacity(widget, 1, delayFade);
495 protected void HintFadeOut(Widget widget,
float delayFade,
float delayShrink)
500 AnimateWidget.Opacity(widget, 0, delayFade);
501 GetGame().GetCallqueue().CallLater(HintShrink, 1000 / delayFade,
false, widget, delayShrink);
507 protected void HintShrink(Widget widget,
float delayShrink)
509 float padding[4] = {0, -HINT_SIZE_Y, 0, 0};
510 AnimateWidget.Padding(widget, padding, delayShrink);
511 GetGame().GetCallqueue().CallLater(HintHide, 1000 / delayShrink,
false, widget);
516 protected void HintHide(Widget widget)
518 widget.SetVisible(
false);
523 void SetOffsetY(
float offset = -1)
528 offset = m_fDefaultOffsetY;
537 void SetAdditionalOffsetY(
float offset)
540 m_fAdditionalOffsetY = offset;
545 protected void ApplyOffsets()
548 float sum = (-m_fOffsetY) + (-m_fAdditionalOffsetY);
551 FrameSlot.SetPosY(m_wLayoutWidget, sum);
555 override event void DisplayStartDraw(IEntity owner)
558 m_wLayoutWidget =
m_wRoot.FindAnyWidget(
"VerticalLayout");
564 int toGenerate = PRELOADED_WIDGETS_COUNT - count;
565 for (
int i = 0; i < toGenerate; i++)
571 widgetContainer.SetVisible(
false);
592 override event void DisplayStopDraw(IEntity owner)
595 m_wLayoutWidget =
null;
600 override event void DisplayInit(IEntity owner)
602 PlayerController playerController = PlayerController.Cast(owner);
603 if (!playerController)
605 Print(
"SCR_AvailableActionsDisplay is not an object in HUDManagerComponent attached onto a PlayerController entity! May result in undefined behaviour.", LogLevel.WARNING);
609 GetGame().OnUserSettingsChangedInvoker().Insert(UpdateIsEnabled);
613 protected void OnSlotUIResize()
622 m_iMaxActionsBig = (
int)height / HEIGHT_DIVIDER_BIG;
623 m_iMaxActionsMedium = (
int)height / HEIGHT_DIVIDER_MEDIUM;
624 if (m_iMaxActionsMedium < 1)
625 m_iMaxActionsMedium = 1;
629 protected void ApplyLayoutBehavior()
636 if (beh.ConditionsChecked(
this))
639 if (!selectedBehavior)
641 selectedBehavior = beh;
646 if (selectedBehavior.m_iPriority < beh.m_iPriority)
647 selectedBehavior = beh;
651 if (selectedBehavior)
652 selectedBehavior.ApplyBehavior(
this);
677 display.SetOffsetY(m_fOffsetY);
686 [
Attribute(
"", UIWidgets.ResourceNamePicker,
"Layout",
"layout")]
687 ResourceName m_sCheckHUD;
690 protected bool m_bOffsetFromDisplay;
693 protected float m_fAddOffset;
695 protected float m_fAutoOffset;
704 Widget hud = HUDManager.FindLayoutByResourceName(m_sCheckHUD);
709 if (m_bOffsetFromDisplay)
713 SCR_InfoDisplay hudCmp = HUDManager.FindInfoDisplayByResourceName(m_sCheckHUD);
715 hudCmp.GetDimensions(w, m_fAutoOffset);
726 if (!m_bOffsetFromDisplay)
728 super.ApplyBehavior(display);
733 display.SetOffsetY(m_fAutoOffset + m_fAddOffset);
747 return (
GetGame().GetMenuManager().FindMenuByPreset(m_ActiveMenu) !=
null);
755 [
Attribute(
"1", UIWidgets.ComboBox,
"In which mode should be this behavior applied",
"", ParamEnumArray.FromEnum(
EEditorMode))]
758 [
Attribute(
"0",
desc:
"Additional offset applied when editor is no legal in given scenario.")]
759 protected float m_fIllegalEditorOffset;
765 if (!editorManagerEntity)
768 EEditorMode mode = editorManagerEntity.GetCurrentMode();
774 float offset = m_fOffsetY;
776 if (m_fIllegalEditorOffset != 0)
782 if (editorSettings && !editorSettings.IsUnlimitedEditorLegal())
783 offset += m_fIllegalEditorOffset;
787 display.SetOffsetY(offset);