Ejemplo n.º 1
0
 /// <summary>
 /// 添加事件回调函数
 /// </summary>
 /// <param name="handler">回调处理函数</param>
 /// <param name="events">事件类型</param>
 public void AddHandler(GlobalEventHandler handler, params GlobalEventType[] events)
 {
     foreach (GlobalEventType type in events)
     {
         _globalHandler[(int)type].Add(handler);
     }
 }
Ejemplo n.º 2
0
 public ControlPanel(GlobalEventHandler globalEventHandler) : base(globalEventHandler)
 {
     InitializeComponent();
     DataContext   = this;
     Loaded       += onLoaded;
     PreviewKeyUp += onPreviewKeyUp;
 }
Ejemplo n.º 3
0
        public static void RemoveListener(EEvent type, GlobalEventHandler listener)
        {
            bool isTriggingEvent = EventHelper.IsTriggingEvent;

            if (isTriggingEvent)
            {
                EventHelper.allPendingListeners.Enqueue(new EventHelper.ListenerInfo(false, type, listener));
            }
            else
            {
                List <GlobalEventHandler> list;
                bool flag = EventHelper.allListeners.TryGetValue((int)type, out list);
                if (flag)
                {
                    bool flag2 = list.Remove(listener);
                    if (flag2)
                    {
                        bool flag3 = list.Count == 0;
                        if (flag3)
                        {
                            EventHelper.allListeners.Remove((int)type);
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
 public GenericAuditHandler(IBus bus, GlobalEventHandler broadcaster, IDocumentStore store, EventLogMappings mappings)
 {
     this.bus         = bus;
     this.broadcaster = broadcaster;
     this.store       = store;
     this.mappings    = mappings;
 }
    public static GlobalEventHandler GetInstance()
    {
        if( instance == null )
            instance = new GlobalEventHandler();

        return instance;
    }
Ejemplo n.º 6
0
        public static void RemoveListener(EEvent type, GlobalEventHandler listener)
        {
            if (IsTriggingEvent)
            {
                allPendingListeners.Enqueue(new ListenerInfo(false, type, listener));
                return;
            }

            var itype = (int)type;

            if (allListeners.TryGetValue(itype, out var tmplst))
            {
                if (tmplst.Remove(listener))
                {
                    if (tmplst.Count == 0)
                    {
                        allListeners.Remove(itype);
                    }

                    return;
                }
            }

            //Debug.LogError("Try remove a not exist listner " + type);
        }
Ejemplo n.º 7
0
 private void OnEnable()
 {
     cache = new Dictionary <int, object>();
     GlobalEventHandler.SubscribeEvent <int, object>(Events.ConsoleEvents.CacheEvent, CacheId);
     GlobalEventHandler.SubscribeEvent <int>(Events.ConsoleEvents.RemoveEvent, RemoveId);
     GlobalEventHandler.SubscribeEvent <int>(Events.ConsoleEvents.ShowIdEvent, DisplayCacheIds);
 }
Ejemplo n.º 8
0
 private void OnDisable()
 {
     cache.Clear();
     GlobalEventHandler.UnsubscribeEvent <int, object>(Events.ConsoleEvents.CacheEvent, CacheId);
     GlobalEventHandler.UnsubscribeEvent <int>(Events.ConsoleEvents.CacheEvent, RemoveId);
     GlobalEventHandler.UnsubscribeEvent <int>(Events.ConsoleEvents.ShowIdEvent, DisplayCacheIds);
 }
Ejemplo n.º 9
0
        public static GlobalEventHandler GetEventHandler(MyDefinitionId eventDefinitionId)
        {
            GlobalEventHandler handler = null;

            m_typesToHandlers.TryGetValue(eventDefinitionId, out handler);
            return(handler);
        }
        /// <summary>
        /// Executes a registered method within the event tables. If only one argument is parsed
        /// then the Global Event Table is executed.
        /// </summary>
        /// <param name="input">The user's input</param>
        public void TryExecuteCommand(string input)
        {
            // Trim the input of trailing white spaces and split the string into an array of strings.
            var args = input.Trim().Split(delimiter);

            if (args.Length > 1)
            {
                var parameters = argParser.ParseParameters(CopyArgs(args, 2));
                int intValue   = argParser.TryParseInt(args[1]);

                if (cache.IsIdCached(intValue))
                {
                    InvokeRelativeEvent(args[0], intValue, parameters);

                    var objectArg = cache[intValue];
                    GlobalEventHandler.InvokeEvent(args[0], System.Convert.ChangeType(objectArg, objectArg.GetType()));
                }
                else
                {
                    GlobalEventHandler.InvokeEvent(args[0], intValue);
                }
            }
            else
            {
                InvokeGlobalEvent(args[0]);
            }
        }
Ejemplo n.º 11
0
 public void AddListener(GlobalEventHandler eventHandler)
 {
     if (listeners.Contains(eventHandler))
     {
         return;
     }
     listeners.Add(eventHandler);
 }
Ejemplo n.º 12
0
 public void Register(string EventName, GlobalEventHandler Handler)
 {
     if (!HandlerChain.Contains(EventName))
     {
         HandlerChain.Add(EventName, new List <GlobalEventHandler>());
     }
     ((List <GlobalEventHandler>)HandlerChain[EventName]).Add(Handler);
 }
Ejemplo n.º 13
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.A) && !isCrushing)
        {
            isCrushing = true;
            // Nervous changes
            foreach (Collider2D coll in Physics2D.OverlapCircleAll(gameObject.transform.position, 3))
            {
                if (coll.tag == "Victim")
                {
                    coll.gameObject.GetComponent <VictimControls>().SetNervous();
                }
            }
            // Spook changes
            foreach (Collider2D coll in Physics2D.OverlapCircleAll(gameObject.transform.position, 1))
            {
                if (coll.tag == "Victim")
                {
                    coll.gameObject.GetComponent <VictimControls>().SetSpook();
                }
            }
        }
        if (isCrushing)
        {
            crushDuration  += Time.deltaTime;
            renderer.sprite = crushDuration > 0 && crushDuration <= 0.0625 ? Frame2
                            : crushDuration > 0.0625 && crushDuration <= 0.125 ? Frame3
                            : crushDuration > 0.125 && crushDuration <= 0.1875 ? Frame4
                            : crushDuration > 0.1875 && crushDuration <= 0.250 ? Frame5
                            : crushDuration > 0.250 && crushDuration <= 0.3125 ? Frame6
                            : crushDuration > 0.3125 && crushDuration <= 0.3750 ? Frame7
                            : crushDuration > 0.3750 && crushDuration <= 0.4375 ? Frame8 : Frame1;
            if (crushDuration > 0.0625 && crushDuration < 0.125)
            {
                foreach (Collider2D coll in Physics2D.OverlapCircleAll(gameObject.transform.position, 1f))
                {
                    if (coll.tag == "Victim")
                    {
                        foreach (AudioSource sound in GetComponents <AudioSource>())
                        {
                            sound.Play();
                        }
                        bloodGush.Stop();
                        bloodGush.Play();
                        Object.Destroy(coll.gameObject);
                        GlobalEventHandler.SendEvent(new GameEvents.VictimDied {
                        });
                    }
                }
            }

            if (crushDuration > 0.4375)
            {
                isCrushing    = false;
                crushDuration = 0;
            }
        }
    }
Ejemplo n.º 14
0
        public UnCloseableWindow(GlobalEventHandler globalEventHandler) : base()
        {
            IgnoreWindowPlacement = true;
            var minMouseMovePoints = 99;

            _GlobalEventHandler = globalEventHandler;

            PreviewMouseMove += async(s, e) => minMouseMovePoints = await ExitStrategy.CloseIfBigMoveBoforeGracePeriod(minMouseMovePoints, this, GetType().Name);

            //Closing += UnCloseableWindow_Closing;
            Closed += UnCloseableWindow_Closed;

            PreviewKeyUp += async(s, e) =>
            {
                e.Handled = await ExitStrategy.CloseBasedOnPCName(e.Key, this);

                if (e.Handled)
                {
                    //todo: is it redundant Application.Current.Shutdown(77);          Trace.WriteLine($"{DateTime.Now:yy.MM.dd HH:mm:ss.f} +{(DateTime.Now - App.StartedAt):mm\\:ss\\.ff}   App.Shutdown(77) in PreviewKeyUp(). ");
                }
                else
                {
                    switch (e.Key)
                    {
                    case Key.F1: _GlobalEventHandler.TglContainerVis("ContainerA"); break;

                    case Key.F2: _GlobalEventHandler.TglContainerVis("ContainerB"); break;

                    case Key.F3: _GlobalEventHandler.TglContainerVis("ContainerC"); break;

                    case Key.F4: _GlobalEventHandler.TglContainerVis("ContainerD"); break;

                    case Key.F5: _GlobalEventHandler.TglContainerVis("ContainerE"); break;

                    case Key.F6: _GlobalEventHandler.TglContainerVis("ContainerF"); break;

                    case Key.F7: _GlobalEventHandler.TglContainerVis("ContainerG"); break;

                    case Key.F8: _GlobalEventHandler.TglContainerVis("ContainerH"); break;

                    case Key.F9: _GlobalEventHandler.TglContainerVis("ContainerI"); break;

                    case Key.F10: _GlobalEventHandler.TglContainerVis("ContainerJ"); break;

                    case Key.F11: _GlobalEventHandler.TglContainerVis("ContainerK"); break;

                    case Key.F12: _GlobalEventHandler.TglContainerVis("ContainerL"); break;

                    default:
                        App.StopSpeakingAsync();
                        App.SpeakFaF($"{e.Key} not handled!"); return;
                    }
                }
            };
        }
    public static void UnregisterHandler(string evt, GlobalEventHandler handler)
    {
        if (string.IsNullOrEmpty(evt) || handler == null)
        {
            return;
        }

        if (immediateHandlersTable.ContainsKey(evt))
        {
            immediateHandlersTable[evt] -= handler;
        }
    }
Ejemplo n.º 16
0
 public GlobalEventArgs(bool isDelay, float delayTime, GlobalEventHandler initEventFunction,
                        bool isTimeLimitation, float limitTime, GlobalEventHandler finishEventFunction,
                        EventTransferArgs args)
 {
     IsDelay             = isDelay;
     DelayTime           = delayTime;
     InitEventFunction   = initEventFunction;
     IsTimeLimitation    = isTimeLimitation;
     LimitTime           = limitTime;
     FinishEventFunction = finishEventFunction;
     Args = args;
 }
Ejemplo n.º 17
0
        protected override void OnStartup(StartupEventArgs e)
        {
            System.AppContext.SetSwitch("Switch.System.Windows.Input.Stylus.EnablePointerSupport", true);

            CultureInfo culture = new CultureInfo("en");

            Thread.CurrentThread.CurrentCulture       = culture;
            Thread.CurrentThread.CurrentUICulture     = culture;
            CultureInfo.DefaultThreadCurrentCulture   = culture;
            CultureInfo.DefaultThreadCurrentUICulture = culture;

            string baseDir = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

            CrashHandler.Init(baseDir);

            // Check command line arguments
            var cmdLine = new CommandLine(e.Args);

            // Show Welcome Dialog while initializing
            bool bSkipWelcome = cmdLine.NoWelcomeDialog || cmdLine.HasPathToOpen || cmdLine.HasScriptToRun;

            if (!bSkipWelcome)
            {
                WelcomeDialog.ShowAsync();
            }

            // Set AppUserModelID for Shell-Features like JumpList, Taskbar-Grouping
            Win32Api.SetCurrentProcessExplicitAppUserModelID("Macad.1");

            CreateInstanceMutexes();

            // Init OCCT
#if DEBUG
            Environment.SetEnvironmentVariable(@"CSF_DEBUG", "1");
#endif
            // Init statics
            GlobalEventHandler.Init();
            WindowsClipboard.Init();

            // Init context
            AppContext.Initialize(cmdLine);

            // Start main window
            MainWindow = new MainWindow(new MainWindowModel());
            WelcomeDialog.Current?.SetMainWindow(MainWindow);
            MainWindow.Show();

            ShutdownMode = ShutdownMode.OnMainWindowClose;

            base.OnStartup(e);
        }
Ejemplo n.º 18
0
        public void AddListener(GlobalEventHandler eventHandler)
        {
            if (IsEmpty)
            {
                return;
            }

            if (!Value)
            {
                Debug.LogError($"Cannot add listener to event: {GetPath()}");
                return;
            }
            Value.AddListener(eventHandler);
        }
Ejemplo n.º 19
0
        public bool RemoveListener(GlobalEventHandler eventHandler)
        {
            if (IsEmpty)
            {
                return(false);
            }

            if (!Value)
            {
                Debug.LogError($"Cannot remove listener to event: {GetPath()}");
                return(false);
            }
            return(Value.RemoveListener(eventHandler));
        }
Ejemplo n.º 20
0
        public static void AddListener(EEvent type, GlobalEventHandler listener)
        {
            if (IsTriggingEvent)
            {
                allPendingListeners.Enqueue(new ListenerInfo(true, type, listener));
                return;
            }

            var itype = (int)type;

            if (allListeners.TryGetValue(itype, out var tmplst))
            {
                tmplst.Add(listener);
            }
            else
            {
                var lst = new List <GlobalEventHandler>();
                lst.Add(listener);
                allListeners.Add(itype, lst);
            }
        }
Ejemplo n.º 21
0
        public static void AddListener(EEvent type, GlobalEventHandler listener)
        {
#if _DEBUG_EVENT_TRIGGER
            if (IsTriggingEvent)
            {
                Debug.LogError("Error!!! can not modify allListeners when was Trigger Event");
            }
#endif

            var itype = (int)type;
            if (allListeners.TryGetValue(itype, out var tmplst))
            {
                tmplst.Add(listener);
            }
            else
            {
                var lst = new List <GlobalEventHandler>();
                lst.Add(listener);
                allListeners.Add(itype, lst);
            }
        }
Ejemplo n.º 22
0
        public static void RemoveListener(EEvent type, GlobalEventHandler listener)
        {
#if _DEBUG_EVENT_TRIGGER
            if (IsTriggingEvent)
            {
                Debug.LogError("Error!!! can not modify allListeners when was Trigger Event");
            }
#endif
            var itype = (int)type;
            if (allListeners.TryGetValue(itype, out var tmplst))
            {
                if (tmplst.Remove(listener))
                {
                    if (tmplst.Count == 0)
                    {
                        allListeners.Remove(itype);
                    }
                    return;
                }
            }
            Debug.LogError("Try remove a not exist listner " + type);
        }
Ejemplo n.º 23
0
        public static void AddListener(EEvent type, GlobalEventHandler listener)
        {
            bool isTriggingEvent = EventHelper.IsTriggingEvent;

            if (isTriggingEvent)
            {
                EventHelper.allPendingListeners.Enqueue(new EventHelper.ListenerInfo(true, type, listener));
            }
            else
            {
                List <GlobalEventHandler> list;
                bool flag = EventHelper.allListeners.TryGetValue((int)type, out list);
                if (flag)
                {
                    list.Add(listener);
                }
                else
                {
                    List <GlobalEventHandler> list2 = new List <GlobalEventHandler>();
                    list2.Add(listener);
                    EventHelper.allListeners.Add((int)type, list2);
                }
            }
        }
Ejemplo n.º 24
0
 // Use this for initialization
 void Start()
 {
     this.rounds = 0;
     this.eventHandler = GameObject.FindGameObjectWithTag("EventHandler").GetComponent<GlobalEventHandler> ();
 }
Ejemplo n.º 25
0
 public EventMonitor(NSEventMask[] mask, GlobalEventHandler handler)
 {
     this.mask    = mask;
     this.handler = handler;
 }
Ejemplo n.º 26
0
 public AuditEventLogWriter(GlobalEventHandler broadcaster, IDocumentStore store, EventLogMappings mappings)
 {
     this.broadcaster = broadcaster;
     this.store       = store;
     this.mappings    = mappings;
 }
Ejemplo n.º 27
0
 void Awake()
 {
     GlobalEventHandler.Register <NPCLeft>(OnNPCLeft);
 }
Ejemplo n.º 28
0
 void Awake()
 {
     instance = this;
 }
 public void Awake()
 {
     handler = this;
 }
 private void OnDisable()
 {
     GlobalEventHandler.UnsubscribeEvent <object>("ToggleAI", SwapAgentState);
 }
Ejemplo n.º 31
0
 public bool RemoveListener(GlobalEventHandler eventHandler)
 {
     return(listeners.Remove(eventHandler));
 }
Ejemplo n.º 32
0
        private static void RegisterHandler(MyDefinitionId eventDefinitionId, GlobalEventHandler handler)
        {
            Debug.Assert(!m_typesToHandlers.ContainsKey(eventDefinitionId), "One event definition id can only have one event handler!");

            m_typesToHandlers[eventDefinitionId] = handler;
        }