3 protected TabberUI m_Tabber;
4 protected ref DropdownPrefab m_KBDropdown;
5 protected ref OptionSelectorMultistate m_PresetSelector;
6 protected ref KeybindingsContainer m_GroupsContainer;
10 protected ButtonWidget m_Apply;
11 protected ButtonWidget
m_Back;
12 protected ButtonWidget m_Undo;
13 protected ButtonWidget m_Defaults;
14 protected ButtonWidget m_HardReset;
16 protected int m_CurrentSettingKeyIndex = -1;
17 protected int m_CurrentSettingAlternateKeyIndex = -1;
18 protected int m_OriginalPresetIndex;
19 protected int m_TargetPresetIndex;
22 const int MODAL_ID_BACK = 1337;
23 const int MODAL_ID_DEFAULT = 100;
24 const int MODAL_ID_DEFAULT_ALL = 101;
25 const int MODAL_ID_PRESET_CHANGE = 200;
26 const int MODAL_RESULT_DEFAULT_CURRENT = 0;
27 const int MODAL_RESULT_DEFAULT_ALL = 1;
32 layoutRoot =
GetGame().GetWorkspace().CreateWidgets(
"gui/layouts/new_ui/options/pc/keybinding_menu.layout",
null);
34 m_Version =
TextWidget.Cast(layoutRoot.FindAnyWidget(
"version"));
35 m_Apply = ButtonWidget.Cast(layoutRoot.FindAnyWidget(
"apply"));
36 m_Back = ButtonWidget.Cast(layoutRoot.FindAnyWidget(
"back"));
37 m_Undo = ButtonWidget.Cast(layoutRoot.FindAnyWidget(
"undo"));
38 m_Defaults = ButtonWidget.Cast(layoutRoot.FindAnyWidget(
"reset"));
39 m_HardReset = ButtonWidget.Cast(layoutRoot.FindAnyWidget(
"reset_all"));
41 layoutRoot.FindAnyWidget(
"Tabber").GetScript(m_Tabber);
45 #ifdef PLATFORM_CONSOLE
46 version =
"#main_menu_version" +
" " + version +
" (" +
g_Game.GetDatabaseID() +
")";
48 version =
"#main_menu_version" +
" " + version;
50 m_Version.SetText(version);
53 string back =
"circle";
57 ImageWidget toolbar_b = ImageWidget.Cast(layoutRoot.FindAnyWidget(
"BackIcon"));
58 toolbar_b.LoadImageFile(0,
"set:playstation_buttons image:" + back);
61 InitInputSortingMap();
63 CreateGroupContainer();
65 InitPresets(-1, layoutRoot.FindAnyWidget(
"group_header"), input);
66 m_Tabber.m_OnTabSwitch.Insert(UpdateTabContent);
67 m_Tabber.SelectTabControl(0);
68 m_Tabber.SelectTabPanel(0);
69 g_Game.SetKeyboardHandle(
this);
70 m_Tabber.RefreshTab(
true);
72 ColorDisabled(m_Apply);
74 ColorDisabled(m_Undo);
76 ColorWhite(m_Defaults,
null);
84 int sort_count =
InputUtils.GetInputActionSortingMap().Count();
85 for (
int i = 0; i < sort_count; i++)
87 if (
InputUtils.GetInputActionSortingMap().GetElement(i) &&
InputUtils.GetInputActionSortingMap().GetElement(i).Count() > 0)
89 string group_name =
GetUApi().SortingLocalization(
InputUtils.GetInputActionSortingMap().GetKey(i));
90 group_name =
Widget.TranslateString(
"#" + group_name);
91 m_Tabber.AddTab(group_name);
97 m_Tabber.AddTab(
Widget.TranslateString(
"#layout_pc_keybinding_unsorted"));
99 m_Tabber.DisableTabs(
true);
102 void CreateGroupContainer()
104 m_GroupsContainer =
new KeybindingsContainer(-1,
GetGame().
GetInput(),layoutRoot.FindAnyWidget(
"TabContentsHolder"),
this);
107 void UpdateTabContent(
int tab_index)
109 m_GroupsContainer.SwitchSubgroup(tab_index);
112 void ClearKeybind(
int key_index)
114 ColorWhite(m_Apply,
null);
116 ColorWhite(m_Undo,
null);
120 void ClearAlternativeKeybind(
int key_index)
122 ColorWhite(m_Apply,
null);
124 ColorWhite(m_Undo,
null);
128 void StartEnteringKeybind(
int key_index)
130 m_CurrentSettingAlternateKeyIndex = -1;
131 m_CurrentSettingKeyIndex = key_index;
134 void CancelEnteringKeybind()
136 m_GroupsContainer.CancelEnteringKeybind();
137 m_CurrentSettingKeyIndex = -1;
140 void StartEnteringAlternateKeybind(
int key_index)
142 m_CurrentSettingKeyIndex = -1;
143 m_CurrentSettingAlternateKeyIndex = key_index;
146 void CancelEnteringAlternateKeybind()
148 m_GroupsContainer.CancelEnteringAlternateKeybind();
149 m_CurrentSettingAlternateKeyIndex = -1;
152 void ConfirmKeybindEntry(
TIntArray new_keys)
154 m_CurrentSettingKeyIndex = -1;
155 ColorWhite(m_Apply,
null);
157 ColorWhite(m_Undo,
null);
161 void ConfirmAlternateKeybindEntry(
TIntArray new_keys)
163 m_CurrentSettingAlternateKeyIndex = -1;
164 ColorWhite(m_Apply,
null);
166 ColorWhite(m_Undo,
null);
170 override void Update(
float timeslice)
172 if (
GetUApi().GetInputByID(UAUIBack).LocalPress())
177 if (m_GroupsContainer)
179 m_GroupsContainer.Update(timeslice);
197 else if (w == m_Undo)
202 else if (w == m_Defaults)
207 else if (w == m_HardReset)
218 ColorDisabled(m_Apply);
220 ColorDisabled(m_Undo);
222 ColorWhite(m_Defaults,
null);
225 m_GroupsContainer.Apply();
233 if (m_CurrentSettingKeyIndex != -1)
235 CancelEnteringKeybind();
239 if (m_CurrentSettingAlternateKeyIndex != -1)
241 CancelEnteringAlternateKeybind();
245 bool changed = m_GroupsContainer.IsChanged();
249 g_Game.GetUIManager().ShowDialog(
"#main_menu_configure",
"#main_menu_configure_desc", MODAL_ID_BACK, DBT_YESNO, DBB_YES, DMT_QUESTION,
this);
253 GetGame().GetUIManager().Back();
260 ColorDisabled(m_Apply);
262 ColorDisabled(m_Undo);
265 m_GroupsContainer.Reset();
270 g_Game.GetUIManager().ShowDialog(
"#menu_default_cap",
"#menu_default_desc", MODAL_ID_DEFAULT, DBT_YESNO, DBB_YES, DMT_QUESTION,
this);
275 g_Game.GetUIManager().ShowDialog(
"#menu_default_cap",
"#menu_default_all_desc", MODAL_ID_DEFAULT_ALL, DBT_YESNO, DBB_YES, DMT_QUESTION,
this);
278 void PerformSetToDefaultsExt(
int mode)
282 case MODAL_RESULT_DEFAULT_CURRENT:
286 case MODAL_RESULT_DEFAULT_ALL:
291 ColorDisabled(m_Apply);
293 ColorDisabled(m_Undo);
296 m_GroupsContainer.Reset(
true);
299 override bool OnModalResult(
Widget w,
int x,
int y,
int code,
int result)
301 if (code == MODAL_ID_BACK)
303 if (result == DBB_YES)
306 GetGame().GetUIManager().Back();
310 else if (code == MODAL_ID_DEFAULT)
312 if (result == DBB_YES)
314 PerformSetToDefaultsExt(MODAL_RESULT_DEFAULT_CURRENT);
318 else if (code == MODAL_ID_DEFAULT_ALL)
320 if (result == DBB_YES)
322 PerformSetToDefaultsExt(MODAL_RESULT_DEFAULT_ALL);
325 else if (code == MODAL_ID_PRESET_CHANGE)
327 if (result == DBB_YES)
330 m_PresetSelector.PerformSetOption(m_TargetPresetIndex);
342 #ifdef PLATFORM_CONSOLE
343 version =
"#main_menu_version" +
" " + version +
" (" +
g_Game.GetDatabaseID() +
")";
345 version =
"#main_menu_version" +
" " + version;
347 m_Version.SetText(version);
370 ColorWhite(w, enterW);
377 override bool OnMouseWheel(
Widget w,
int x,
int y,
int wheel)
379 return super.OnMouseWheel(w,
x,
y, wheel);
413 return (w == m_Apply || w ==
m_Back || w == m_Undo || w == m_Defaults || w == m_HardReset);
423 ButtonWidget button = ButtonWidget.Cast(w);
424 if (button && button != m_Apply)
426 button.SetTextColor(
ARGB(255, 200, 0, 0));
432 #ifdef PLATFORM_WINDOWS
436 ButtonWidget button = ButtonWidget.Cast(w);
450 void ColorDisabled(
Widget w)
452 #ifdef PLATFORM_WINDOWS
456 ButtonWidget button = ButtonWidget.Cast(w);
463 protected void InitInputSortingMap()
468 void InitPresets(
int index,
Widget parent,
Input input)
470 Widget kb_root = parent.FindAnyWidget(
"keyboard_dropown");
479 for (
int i = 0; i < input.GetProfilesCount(); i++)
481 input.GetProfileName(i, profile_text);
482 opt1.Insert(profile_text);
485 int current_idx = input.GetCurrentProfile();
486 m_OriginalPresetIndex = current_idx;
487 m_PresetSelector =
new OptionSelectorMultistate(layoutRoot.FindAnyWidget(
"profile_setting_option"), current_idx,
null,
false, opt1);
488 m_PresetSelector.m_AttemptOptionChange.Insert(OnAttemptSelectPreset);
489 m_PresetSelector.m_OptionChanged.Insert(OnSelectKBPreset);
492 void OnAttemptSelectPreset(
int index)
494 bool changed = m_GroupsContainer.IsChanged() && m_OriginalPresetIndex != index;
495 m_TargetPresetIndex = index;
499 g_Game.GetUIManager().ShowDialog(
"#main_menu_configure",
"#main_menu_configure_desc", MODAL_ID_PRESET_CHANGE, DBT_YESNO, DBB_YES, DMT_QUESTION,
this);
502 m_PresetSelector.SetCanSwitch(!changed);
505 void OnSelectKBPreset(
int index)
507 m_OriginalPresetIndex = index;
508 m_GroupsContainer.OnSelectKBPreset(index);
510 GetGame().GetInput().GetProfileName(index, profile_text);
512 GetGame().GetMission().GetOnInputPresetChanged().Invoke();
518 KeybindingsContainer GetCurrentTab()
520 return m_GroupsContainer;
523 void AddGroup(
int index,
Input input)
528 void PerformSetToDefaults()
530 PerformSetToDefaultsExt(MODAL_RESULT_DEFAULT_ALL);
533 void DeferredDefaultsInit()