Пример #1
0
        /// <summary>
        /// Remove the settings listeners matching the name and option parameters.
        /// </summary>
        /// <param name="name"> the name of the settings listener, or null to match any name </param>
        /// <param name="option"> the settings open, or null to match any settings option </param>
        public virtual void removeSettingsListener(string name, string option)
        {
//JAVA TO C# CONVERTER WARNING: Unlike Java's ListIterator, enumerators in .NET do not allow altering the collection:
            for (IEnumerator <SettingsListenerInfo> lit = allListeners.GetEnumerator(); lit.MoveNext();)
            {
                SettingsListenerInfo info = lit.Current;
                if (info.Equals(name, option))
                {
//JAVA TO C# CONVERTER TODO TASK: .NET enumerators are read-only:
                    lit.remove();
                    string key = info.Key;
                    IList <ISettingsListener> listenersForKey = listenersByKey[key];
                    listenersForKey.Remove(info.Listener);
                    if (listenersForKey.Count == 0)
                    {
                        listenersByKey.Remove(key);
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Register a settings listener for a specific option. The settings listener
        /// will be called as soon as the option value changes, e.g. when modifying
        /// the configuration through the GUI, or when loading a game having a patch
        /// file defined. The settings listener is also called immediately by this
        /// method while registering.
        ///
        /// Only one settings listener can be defined for each name/option
        /// combination. This allows to call this method for the same listener
        /// multiple times and have it registered only once.
        /// </summary>
        /// <param name="name"> the name of the settings listener </param>
        /// <param name="option"> the settings option </param>
        /// <param name="listener"> the listener to be called when the settings option value
        /// changes </param>
        public virtual void registerSettingsListener(string name, string option, ISettingsListener listener)
        {
            removeSettingsListener(name, option);

            SettingsListenerInfo info = new SettingsListenerInfo(name, option, listener);

            allListeners.Add(info);
            IList <ISettingsListener> listenersForKey = listenersByKey[option];

            if (listenersForKey == null)
            {
                listenersForKey        = new LinkedList <ISettingsListener>();
                listenersByKey[option] = listenersForKey;
            }
            listenersForKey.Add(listener);

            // Trigger the settings listener immediately if a value is defined
            string value = getProperty(option);

            if (!string.ReferenceEquals(value, null))
            {
                listener.settingsValueChanged(option, value);
            }
        }