Ejemplo n.º 1
0
        private void RegisterKeyBindings()
        {
            int n = actions.Count;

            LogKeyBind("Registering {0:D} key bind(s) for mod {1}".F(n, Assembly.
                                                                     GetExecutingAssembly().GetNameSafe() ?? "?"));
            var currentBindings = new List <BindingEntry>(GameInputMapping.DefaultBindings);

            foreach (var action in actions)
            {
                var kAction = action.GetKAction();
                var binding = action.DefaultBinding;
                if (!FindKeyBinding(currentBindings, kAction))
                {
                    if (binding == null)
                    {
                        binding = new PKeyBinding();
                    }
                    // This constructor changes often enough to be worth detouring
                    currentBindings.Add(NEW_BINDING_ENTRY.Invoke(CATEGORY, binding.
                                                                 GamePadButton, binding.Key, binding.Modifiers, kAction));
                }
            }
            GameInputMapping.SetDefaultKeyBindings(currentBindings.ToArray());
            UpdateMaxAction();
        }
Ejemplo n.º 2
0
 internal PAction(int id, string identifier, LocString title, PKeyBinding binding)
 {
     if (id <= 0)
     {
         throw new ArgumentOutOfRangeException(nameof(id));
     }
     DefaultBinding = binding;
     Identifier     = identifier;
     this.id        = id;
     Title          = title;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Registers a PAction with the action manager.
        ///
        /// This call should occur after PUtil.InitLibrary() during the mod OnLoad(). If called
        /// earlier, it may fail with InvalidOperationException, and if called later, the
        /// user's custom key bind (if applicable) will be discarded.
        /// </summary>
        /// <param name="identifier">The identifier for this action.</param>
        /// <param name="title">The action's title. If null, the default value from
        /// STRINGS.INPUT_BINDINGS.PLIB.identifier will be used instead.</param>
        /// <param name="binding">The default key binding for this action. If null, no key will
        /// be bound by default, but the user can set a key bind.</param>
        /// <returns>The action thus registered.</returns>
        public PAction CreateAction(string identifier, LocString title,
                                    PKeyBinding binding = null)
        {
            PAction action;

            RegisterForForwarding();
            int curIndex = GetSharedData(1);

            action = new PAction(curIndex, identifier, title, binding);
            SetSharedData(curIndex + 1);
            actions.Add(action);
            return(action);
        }