Example #1
0
        // ------------------------------------------------------------------------------------------------------------------------------------------------
        static void AddListener <T>(EventDelegate <T> del, DelegateSet delegateSet) where T : GameEvent
        // ------------------------------------------------------------------------------------------------------------------------------------------------
        {
            // Early-out if we've already registered this delegate
            if (delegateSet.Lookup.ContainsKey(del))
            {
                return;
            }

            // Create a new non-generic delegate which calls our generic one.
            // This is the delegate we actually invoke.
            EventDelegate internalDelegate = (e) => del((T)e);

            delegateSet.Lookup[del] = internalDelegate;

            EventDelegate tempDel;

            if (delegateSet.Delegates.TryGetValue(typeof(T), out tempDel))
            {
                delegateSet.Delegates[typeof(T)] = tempDel += internalDelegate;
            }
            else
            {
                delegateSet.Delegates[typeof(T)] = internalDelegate;
            }
        }
Example #2
0
        public static DockableWidget createWindow(XmlNode node)
        {
            //Console.WriteLine("createWindow");
            ParameterSet ps = ParameterSet.CreateInstance(node);
            DelegateSet  ds = DelegateSet.CreateInstance(node);

            return(createWindow(ps, ds));
        }
Example #3
0
        // -----------------------------------------------------------------------------------
        static void ProcessEvent(GameEvent e, DelegateSet delegateSet)
        // -----------------------------------------------------------------------------------
        {
            EventDelegate del;

            if (delegateSet.Delegates.TryGetValue(e.GetType(), out del))
            {
                del.Invoke(e);
            }
        }
Example #4
0
        // -----------------------------------------------------------------------------------
        DelegateSet GetOrCreateDelegates(object obj)
        // -----------------------------------------------------------------------------------
        {
            DelegateSet delegateSet;

            if (_objectDelegates.TryGetValue(obj, out delegateSet) == false)
            {
                delegateSet = new DelegateSet();
                _objectDelegates.Add(obj, delegateSet);
            }
            return(delegateSet);
        }
Example #5
0
        // ---------------------------------------------------------------------------------------------------------
        /// <summary>
        ///  removes a function that listens for the given event when the event is sent to this object
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="del"></param>
        /// <param name="o"></param>
        public static void RemoveObjectListener <T>(Events.EventDelegate <T> del, object o) where T : GameEvent
        // ---------------------------------------------------------------------------------------------------------
        {
            DelegateSet delegateSet = Internal.GetDelegates(o);

            Dbg.Assert(delegateSet != null);   // odd otherwise
            RemoveListener(del, delegateSet);

            if (delegateSet.Lookup.Count == 0)
            {
                Internal.RemoveDelegates(o);
            }
        }
Example #6
0
        // ************************** QUEUE CALLBACKS - called from Trampoline/bounce ******************************************************************************


        // -----------------------------------------------------------------------------------
        static Bounce ProcessQueue(Queue <GameEvent> q, DelegateSet delegateSet)
        // -----------------------------------------------------------------------------------
        {
            if (q.Count == 0)
            {
                return(Bounce.End());
            }
            else
            {
                ProcessEvent(q.Peek(), delegateSet);
                q.Dequeue();
                return(Bounce.Continue(q));
            }
        }
Example #7
0
        // -----------------------------------------------------------------------------------
        static void Send(GameEvent e, DelegateSet delegateSet)
        // -----------------------------------------------------------------------------------
        {
            if (delegateSet == null)
            {
                return; // no one listening for this event, so ignore it
            }
            delegateSet.Queue.Enqueue(e);

            if (delegateSet.Queue.Count == 1)
            {
                Trampoline.Start(ProcessQueue, delegateSet);
            }
        }
Example #8
0
 /// <summary>
 ///     设置状态
 /// </summary>
 /// <param name="text"></param>
 public void SetStatusText(string text)
 {
     if (StatusLabel.GetCurrentParent().InvokeRequired)
     {
         DelegateSet set = DelegateSetStatusText;
         Invoke(set, new object[] { text });
     }
     else
     {
         if (string.IsNullOrEmpty(text))
         {
             return;
         }
         DelegateSetStatusText(text);
     }
 }
Example #9
0
        public static DockableWidget createWindow(ParameterSet param, DelegateSet delegates)
        {
            ConstructorInfo ci = param.BaseType.GetConstructor(param.Types);
            object          o  = ci.Invoke(param.Data);

            if (o != null)
            {
                DockableWidget wnd = (DockableWidget)o;
                wnd.Params    = param;
                wnd.Delegates = delegates;
                wnd.hookDelegates();
                wnd.afterInit();
                return(wnd);
            }
            return(null);
        }
Example #10
0
        protected override void doReadXml(XmlReader reader)
        {
            this.ID = reader["ID"];
            this.AllowMultipleWindows = Convert.ToBoolean(reader["AllowMultipleWindows"]);
            this.Startup = Convert.ToBoolean(reader["Startup"]);

            base.doReadXml(reader);

            reader.Read();

            Delegates = new DelegateSet();
            Delegates.ReadXml(reader);

            if (MainWindow.Instance != null)
            {
                MainWindow.Instance.WindowList.Add(this.ID, this);
            }
        }
Example #11
0
        // -----------------------------------------------------------------------------------
        static void RemoveListener <T>(EventDelegate <T> del, DelegateSet delegateSet) where T : GameEvent
        // -----------------------------------------------------------------------------------
        {
            EventDelegate internalDelegate;

            if (delegateSet.Lookup.TryGetValue(del, out internalDelegate))
            {
                EventDelegate tempDel;
                if (delegateSet.Delegates.TryGetValue(typeof(T), out tempDel))
                {
                    tempDel -= internalDelegate;
                    if (tempDel == null)
                    {
                        delegateSet.Delegates.Remove(typeof(T));
                    }
                    else
                    {
                        delegateSet.Delegates[typeof(T)] = tempDel;
                    }
                }

                delegateSet.Lookup.Remove(del);
            }
        }
Example #12
0
        /// <summary>
        ///     设置状态
        /// </summary>
        /// <param name="text"></param>
        public void SetStatusText(string text = null)
        {
            DelegateSet set = DelegateSetStatusText;

            Invoke(set, new object[] { text });
        }
Example #13
0
        /// <summary>
        ///     设置状态栏显示
        /// </summary>
        /// <param name="text"></param>
        public void SetToolTipText(string text)
        {
            DelegateSet set = DelegateSetToolTipText;

            Invoke(set, new object[] { text });
        }
Example #14
0
        protected override void doReadXml(XmlReader reader)
        {
            this.ID = reader["ID"];
            this.AllowMultipleWindows = Convert.ToBoolean(reader["AllowMultipleWindows"]);
            this.Startup = Convert.ToBoolean(reader["Startup"]);

            base.doReadXml (reader);

            reader.Read();

            Delegates = new DelegateSet();
            Delegates.ReadXml(reader);

            if (MainWindow.Instance != null)
            {
                MainWindow.Instance.WindowList.Add(this.ID,this);
            }
        }
Example #15
0
 public static DockableWidget createWindow(ParameterSet param, DelegateSet delegates)
 {
     ConstructorInfo ci = param.BaseType.GetConstructor(param.Types);
     object o = ci.Invoke(param.Data);
     if (o != null)
     {
         DockableWidget wnd = (DockableWidget)o;
         wnd.Params = param;
         wnd.Delegates = delegates;
         wnd.hookDelegates();
         wnd.afterInit();
         return wnd;
     }
     return null;
 }
Example #16
0
            public static void Start(Func <Queue <GameEvent>, DelegateSet, Bounce> action, DelegateSet delegateSet)

            {
                Bounce bounce = Bounce.Continue(delegateSet.Queue);

                while (true)
                {
                    if (bounce.HasResult)
                    {
                        break;
                    }

                    bounce = action(bounce.Queue, delegateSet);
                }
            }