Exemple #1
0
        void SetInputMode(InputModeEvent e)
        {
            if (e.Mode == null)
            {
                Raise(new LogEvent(LogEvent.Level.Info,
                                   $"InputMode: {InputMode} (Stack: {string.Join(", ", _inputModeStack)})"));
                return;
            }

            _inputModes.TryGetValue(e.Mode.Value, out var activeMode);
            if (_inputMode == e.Mode && activeMode?.IsActive == true)
            {
                return;
            }

            foreach (var mode in _inputModes.Values)
            {
                mode.IsActive = false;
            }

            if (activeMode != null)
            {
                activeMode.IsActive = true;
            }

            _inputMode = e.Mode.Value;
        }
Exemple #2
0
        public InputManager()
        {
            On <InputModeEvent>(SetInputMode);
            On <MouseModeEvent>(SetMouseMode);
            On <PushMouseModeEvent>(e =>
            {
                _mouseModeStack.Push(_mouseMode);
                var setEvent = new MouseModeEvent(e.Mode);
                SetMouseMode(setEvent);
                Raise(setEvent);
            });
            On <PopMouseModeEvent>(e =>
            {
                if (_mouseModeStack.Count == 0)
                {
                    return;
                }

                var setEvent = new MouseModeEvent(_mouseModeStack.Pop());
                SetMouseMode(setEvent);
                Raise(setEvent);
            });
            On <PushInputModeEvent>(e =>
            {
                _inputModeStack.Push(_inputMode);
                var setEvent = new InputModeEvent(e.Mode);
                SetInputMode(setEvent);
                Raise(setEvent);
            });
            On <PopInputModeEvent>(e =>
            {
                if (_inputModeStack.Count == 0)
                {
                    return;
                }

                var setEvent = new InputModeEvent(_inputModeStack.Pop());
                SetInputMode(setEvent);
                Raise(setEvent);
            });
        }