9 [
Attribute(
"{A06BEA3AE2B878B9}UI/layouts/Menus/SettingsMenu/BindingMenu/KeybindActionDisplay.layout")]
10 ResourceName m_sLayout;
15 [
Attribute(
"1", UIWidgets.ComboBox,
"Horizontal layout container fill origin",
"", ParamEnumArray.FromEnum(HorizontalFillOrigin))]
16 HorizontalFillOrigin m_eRowFillOrigin;
19 bool m_bShowAdditionalKeybindsNumber;
22 string m_sAdditionalKeybindsMessage;
24 protected int m_iBindsLastIndex;
26 protected Widget m_wHorizontalScrollFrame;
27 protected HorizontalLayoutWidget m_wContainerWidget;
28 protected ref array<SCR_KeybindActionDisplayComponent> m_aDisplays = {};
30 protected RichTextWidget m_wAdditionalBindsText;
31 protected Widget m_wAdditionalBindsOverlay;
33 protected SCR_ModularButtonComponent m_AdditionalBindsButton;
36 protected const string ROOT_NAME =
"KeybindActionDisplayRow";
41 override void HandlerAttached(Widget w)
43 super.HandlerAttached(w);
45 m_wContainerWidget = HorizontalLayoutWidget.Cast(
m_wRoot.FindAnyWidget(
"ActionDisplaysHorizontalLayout"));
46 if (m_wContainerWidget)
47 m_wContainerWidget.SetFillOrigin(m_eRowFillOrigin);
49 m_wHorizontalScrollFrame =
m_wRoot.FindAnyWidget(
"HorizontalScrollFrame");
50 if (m_wHorizontalScrollFrame)
53 m_wAdditionalBindsText = RichTextWidget.Cast(
m_wRoot.FindAnyWidget(
"AdditionalBinds"));
54 m_wAdditionalBindsOverlay =
m_wRoot.FindAnyWidget(
"AdditionalBindsOverlay");
56 Widget root = w.FindAnyWidget(
"AdditionalBindsButton");
58 m_AdditionalBindsButton = SCR_ModularButtonComponent.FindComponent(root);
60 if (m_AdditionalBindsButton)
61 m_AdditionalBindsButton.m_OnClicked.Insert(OnAdditionalBindsButtonClicked);
67 CreateActionDisplays(
null,
null, EInputDeviceType.KEYBOARD);
71 protected void ResetScrolling()
73 if (!m_wContainerWidget || !m_HorizontalScrollComponent)
76 m_HorizontalScrollComponent.AnimationStop();
77 m_HorizontalScrollComponent.ResetPosition();
79 FrameSlot.SetAnchorMin(m_wContainerWidget, GetAlignment(), GetAlignment());
80 FrameSlot.SetAnchorMax(m_wContainerWidget, GetAlignment(), GetAlignment());
81 FrameSlot.SetAlignment(m_wContainerWidget, GetAlignment(), GetAlignment());
83 LayoutSlot.SetPadding(m_wHorizontalScrollFrame, 0, 0, 0, 0);
87 protected float GetAlignment()
89 switch (m_eRowFillOrigin)
91 case HorizontalFillOrigin.LEFT:
return 0;
92 case HorizontalFillOrigin.CENTER:
return 0.5;
93 case HorizontalFillOrigin.RIGHT:
return 1;
101 protected void UpdateScrollFrameSkip()
103 GetGame().GetCallqueue().Call(UpdateScrolling,
true);
107 protected void OnAdditionalBindsButtonClicked(SCR_ModularButtonComponent comp)
109 if (m_OnAdditionalBindsClicked)
110 m_OnAdditionalBindsClicked.Invoke();
115 void UpdateScrolling(
bool enable)
117 if (!m_wHorizontalScrollFrame || !m_wContainerWidget || !m_HorizontalScrollComponent || !m_wAdditionalBindsOverlay)
122 float frameX, frameY, textX, textY, additionalBindsX, additionalBindsY;
123 m_wHorizontalScrollFrame.GetScreenSize(frameX, frameY);
124 m_wContainerWidget.GetScreenSize(textX, textY);
125 m_wAdditionalBindsOverlay.GetScreenSize(additionalBindsX, additionalBindsY);
127 vector alignment = FrameSlot.GetAlignment(m_wContainerWidget);
129 bool move = enable && textX > frameX - additionalBindsX;
132 if ((move || m_eRowFillOrigin == HorizontalFillOrigin.RIGHT) && m_iBindsLastIndex + 1 > m_iMaxDisplays)
133 LayoutSlot.SetPadding(m_wHorizontalScrollFrame, 0, 0, additionalBindsX, 0);
138 FrameSlot.SetAnchorMin(m_wContainerWidget, 0, GetAlignment());
139 FrameSlot.SetAnchorMax(m_wContainerWidget, 0, GetAlignment());
140 FrameSlot.SetAlignment(m_wContainerWidget, 0, GetAlignment());
142 m_HorizontalScrollComponent.AnimationStart();
149 if (!m_wContainerWidget)
155 display.GetRootWidget().RemoveFromHierarchy();
161 int lastIndex = m_iMaxDisplays - 1;
162 m_iBindsLastIndex = 0;
164 if (entry && settingsKeybindModule)
167 string preset = entry.m_sPreset;;
169 if (device == EInputDeviceType.GAMEPAD)
171 if (!entry.m_sPresetGamepadOptional.IsEmpty())
172 preset = entry.m_sPresetGamepadOptional;
174 preset = entry.m_sPreset;
176 if (!preset.IsEmpty())
177 finalPreset = settingsKeybindModule.GetGamepadPresetPrefix() + preset;
180 else if (device == EInputDeviceType.KEYBOARD && !preset.IsEmpty())
182 finalPreset = settingsKeybindModule.GetPrimaryPresetPrefix() + preset;
185 m_iBindsLastIndex = settingsKeybindModule.GetActionBindCount(entry.m_sActionName, finalPreset, device) - 1;
187 if (m_iBindsLastIndex < lastIndex)
188 lastIndex = m_iBindsLastIndex;
192 lastIndex = Math.Clamp(lastIndex, 0, m_iMaxDisplays - 1);
198 Widget w =
GetGame().GetWorkspace().CreateWidgets(
m_sLayout, m_wContainerWidget);
206 m_aDisplays.Insert(comp);
214 if (m_eRowFillOrigin != HorizontalFillOrigin.RIGHT)
219 comp.UpdateActionDisplay(
data);
225 int remaining = m_iBindsLastIndex - lastIndex;
226 bool show = remaining > 0;
228 if (m_wAdditionalBindsOverlay)
229 m_wAdditionalBindsOverlay.SetVisible(show);
231 if (m_wAdditionalBindsText)
233 m_wAdditionalBindsText.SetVisible(show && m_bShowAdditionalKeybindsNumber);
234 m_wAdditionalBindsText.SetTextFormat(m_sAdditionalKeybindsMessage, remaining);
237 if (m_AdditionalBindsButton)
238 m_AdditionalBindsButton.SetVisible(show && !m_bShowAdditionalKeybindsNumber);
241 GetGame().GetCallqueue().Call(UpdateScrollFrameSkip);
245 void SetAllActionDisplayStates(SCR_EActionDisplayState state)
250 data = comp.GetActionDisplayData();
254 data.m_eState = state;
256 comp.UpdateActionDisplay(
data);
263 if (!m_OnAdditionalBindsClicked)
266 return m_OnAdditionalBindsClicked;
278 Widget actionRoot = w.FindAnyWidget(ROOT_NAME);