コード例 #1
0
ファイル: KeybindSetting.cs プロジェクト: me22/TMPE
        /// <summary>
        /// Produce a keybind tooltip text, or two if alternate key is set. Prefixed if not empty.
        /// </summary>
        /// <param name="prefix">Prefix will be added if any key is not empty</param>
        /// <returns>String tooltip with the key shortcut or two</returns>
        public string ToLocalizedString(string prefix = "")
        {
            var result = default(string);

            if (!Keybind.IsEmpty(Key))
            {
                result += prefix + Keybind.ToLocalizedString(Key);
            }

            if (AlternateKey == null || Keybind.IsEmpty(AlternateKey))
            {
                return(result);
            }

            if (result.IsNullOrWhiteSpace())
            {
                result += prefix;
            }
            else
            {
                result += " | ";
            }

            return(result + Keybind.ToLocalizedString(AlternateKey));
        }
コード例 #2
0
ファイル: KeybindUI.cs プロジェクト: me22/TMPE
        /// <summary>
        /// For an inputkey, try find where possibly it is already used.
        /// This covers game Settings class, and self (OptionsKeymapping class).
        /// </summary>
        /// <param name="k">Key to search for the conflicts</param>
        /// <param name="sampleCategory">Check the same category keys if possible</param>
        /// <returns>Empty string for no conflict, or the conflicting key name</returns>
        private string FindConflict(KeybindSetting.Editable editedKeybind,
                                    InputKey sample,
                                    string sampleCategory)
        {
            if (Keybind.IsEmpty(sample))
            {
                // empty key never conflicts
                return(string.Empty);
            }

            var inGameSettings = FindConflictInGameSettings(sample);

            if (!string.IsNullOrEmpty(inGameSettings))
            {
                return(inGameSettings);
            }

            // Saves and null 'self.editingBinding_' to allow rebinding the key to itself.
            var saveEditingBinding = editedKeybind.TargetKey.value;

            editedKeybind.TargetKey.value = SavedInputKey.Empty;

            // Check in TMPE settings
            var tmpeSettingsType = typeof(KeybindSettingsBase);
            var tmpeFields       = tmpeSettingsType.GetFields(BindingFlags.Static | BindingFlags.Public);

            var inTmpe = FindConflictInTmpe(sample, sampleCategory, tmpeFields);

            editedKeybind.TargetKey.value = saveEditingBinding;
            return(inTmpe);
        }
コード例 #3
0
ファイル: KeybindSetting.cs プロジェクト: me22/TMPE
        /// <summary>
        /// Produce a keybind tooltip text, or two if alternate key is set. Prefixed if not empty.
        /// </summary>
        /// <param name="prefix">Prefix will be added if any key is not empty</param>
        /// <returns>String tooltip with the key shortcut or two</returns>
        public List <string> ToLocalizedStringList()
        {
            var result = new List <string>(capacity: 2);

            if (!Keybind.IsEmpty(Key))
            {
                result.Add(Keybind.ToLocalizedString(Key));;
            }

            if (AlternateKey != null && !Keybind.IsEmpty(AlternateKey))
            {
                result.Add(Keybind.ToLocalizedString(AlternateKey));
            }

            return(result);
        }