private static void AddCharacterKeyBindingsTo(AdvancedDropdownItem parent, Keyboard keyboard) { foreach (var key in keyboard.children.OfType <KeyControl>()) { if (!key.keyCode.IsTextInputKey()) { continue; } // We can only bind to characters that can be printed. var displayName = key.displayName; if (!displayName.All(x => x.IsPrintable())) { continue; } if (displayName.Contains(')')) { displayName = string.Join("", displayName.Select(x => "\\" + x)); } ////TODO: should be searchable; when searching, needs different display name var item = new ControlDropdownItem(null, $"#({displayName})", "", keyboard.layout, "", false); item.name = key.displayName; parent.AddChild(item); } }
public ControlDropdownItem(ControlDropdownItem parent, string controlName, string displayName, string device, string usage, bool searchable) : base("") { m_Device = device; m_Usage = usage; if (parent != null) { m_ControlPath = $"{parent.controlPath}/{controlName}"; } else { m_ControlPath = controlName; } name = !string.IsNullOrEmpty(displayName) ? displayName : ObjectNames.NicifyVariableName(controlName); id = controlPathWithDevice.GetHashCode(); indent = parent?.indent + 1 ?? 0; if (searchable) { m_SearchableName = InputControlPath.ToHumanReadableString(controlPathWithDevice); } }
private void AddControlTreeItemsRecursive(InputControlLayout layout, DeviceDropdownItem parent, string device, string usage, bool searchable, ControlDropdownItem parentControl = null) { foreach (var control in layout.controls.OrderBy(a => a.name)) { if (control.isModifyingChildControlByPath) { continue; } // Skip variants except the default variant and variants dictated by the layout itself. if (!control.variants.IsEmpty() && control.variants != InputControlLayout.DefaultVariant && (layout.variants.IsEmpty() || !InputControlLayout.VariantsMatch(layout.variants, control.variants))) { continue; } var child = new ControlDropdownItem(parentControl, control.name, control.displayName, device, usage, searchable); child.icon = EditorInputControlLayoutCache.GetIconForLayout(control.layout); if (LayoutMatchesExpectedControlLayoutFilter(control.layout)) { parent.AddChild(child); } var controlLayout = EditorInputControlLayoutCache.TryGetLayout(control.layout); if (controlLayout != null) { AddControlTreeItemsRecursive(controlLayout, parent, device, usage, searchable, child); } } // Add optional controls for devices. var optionalControls = EditorInputControlLayoutCache.GetOptionalControlsForLayout(layout.name); if (optionalControls.Any() && layout.isDeviceLayout) { var optionalGroup = new AdvancedDropdownItem("Optional Controls"); foreach (var optionalControl in optionalControls) { if (LayoutMatchesExpectedControlLayoutFilter(optionalControl.layout)) { var child = new OptionalControlDropdownItem(optionalControl, device, usage); child.icon = EditorInputControlLayoutCache.GetIconForLayout(optionalControl.layout); optionalGroup.AddChild(child); } } if (optionalGroup.children.Any()) { var deviceName = EditorInputControlLayoutCache.TryGetLayout(device).m_DisplayName ?? ObjectNames.NicifyVariableName(device); parent.AddSeparator("Controls Present on More Specific " + deviceName.GetPlural()); parent.AddChild(optionalGroup); } } }
private static void AddPhysicalKeyBindingsTo(AdvancedDropdownItem parent, Keyboard keyboard, bool searchable) { foreach (var key in keyboard.children.OfType <KeyControl>()) { // If the key has a display name that differs from the key name, show it in the UI. var displayName = key.name; var keyDisplayName = key.displayName; if (keyDisplayName.All(x => x.IsPrintable()) && keyDisplayName != key.name) { displayName = $"{key.name} (Current Layout: {key.displayName})"; } var item = new ControlDropdownItem(null, key.name, displayName, keyboard.layout, "", searchable); parent.AddChild(item); } }