Beispiel #1
0
        public static IList <InputBindingViewModel> ToBindings <TAction>(
            LanguageTable languageTable,
            InputBindingGroup bindingGroup,
            EmptyBinding <TAction>[] mappableBindings,
            InputSourceMapping <TAction> inputMapping,
            Maybe <UnityInputDeviceProfile> currentControllerProfile)
        {
            // TODO Optimize for garbage collection, use object pool
            var l = languageTable.AsFunc;

            var bindings = new List <InputBindingViewModel>();

            for (int i = 0; i < mappableBindings.Length; i++)
            {
                var    mappableBinding = mappableBindings[i];
                var    inputSources    = inputMapping.Mappings.GetOrDefault(mappableBinding.Id, null) ?? ImmutableList <InputSource> .Empty;
                string binding;
                if (inputSources.Count > 0)
                {
                    binding = InputSource2String(languageTable, inputSources[0], currentControllerProfile);
                }
                else
                {
                    binding = null;
                }
                bindings.Add(new InputBindingViewModel(
                                 new InputBindingId(bindingGroup, mappableBinding.Id),
                                 l(bindingGroup.ToString().ToUnderscoreCase()),
                                 l(mappableBinding.Id.ToString().ToUnderscoreCase()),
                                 l(mappableBinding.BindingType.ToUnderscoreCase()),
                                 binding));
            }
            return(bindings);
        }
Beispiel #2
0
        /// <summary>
        /// Registers an input binding with the collection.
        /// </summary>
        /// <param name="binding">The input binding to register.</param>
        internal void RegisterBinding(InputBinding binding)
        {
            Contract.Require(binding, nameof(binding));
            Contract.EnsureNotDisposed(this, Disposed);

            foreach (var g in groups)
            {
                if (g.Add(binding))
                {
                    return;
                }
            }

            var group = new InputBindingGroup();

            group.Add(binding);
            groups.Add(group);
        }
Beispiel #3
0
 public InputBindingId(InputBindingGroup @group, object actionId)
 {
     Group    = @group;
     ActionId = actionId;
 }