Example #1
0
		public void NoSubscribersTest ()
		{
			AGSEvent<AGSEventArgs> ev = new AGSEvent<AGSEventArgs> ();
			ev.Invoke (this, null);
			Assert.AreEqual (0, syncEvents);
			Assert.AreEqual (0, asyncEvents);
		}
		public AGSSliderComponent(IGameState state, IInput input, IGameEvents gameEvents)
		{
			_state = state;
			_input = input;
			_gameEvents = gameEvents;
			OnValueChanged = new AGSEvent<SliderValueEventArgs> ();
		}
Example #3
0
		public async Task NoSubscribersAsyncTest ()
		{
			AGSEvent<AGSEventArgs> ev = new AGSEvent<AGSEventArgs> ();
			await ev.InvokeAsync (this, null);
			Assert.AreEqual (0, syncEvents);
			Assert.AreEqual (0, asyncEvents);
		}
Example #4
0
        public void SubscribeUnsubscribeAsyncTest()
        {
            AGSEvent <MockEventArgs> ev = new AGSEvent <MockEventArgs> ();

            ev.SubscribeToAsync(onEventAsync);
            ev.UnsubscribeToAsync(onEventAsync);
            Assert.AreEqual(0, ev.SubscribersCount);
        }
Example #5
0
        public void NoSubscribersTest()
        {
            AGSEvent ev = new AGSEvent();

            ev.Invoke();
            Assert.AreEqual(0, syncEvents);
            Assert.AreEqual(0, asyncEvents);
        }
Example #6
0
        public void NoSubscribersTest()
        {
            AGSEvent <AGSEventArgs> ev = new AGSEvent <AGSEventArgs> ();

            ev.Invoke(this, null);
            Assert.AreEqual(0, syncEvents);
            Assert.AreEqual(0, asyncEvents);
        }
Example #7
0
        public async Task NoSubscribersAsyncTest()
        {
            AGSEvent ev = new AGSEvent();
            await ev.InvokeAsync();

            Assert.AreEqual(0, syncEvents);
            Assert.AreEqual(0, asyncEvents);
        }
Example #8
0
		public void SingleSubscriberTest ()
		{
			AGSEvent<MockEventArgs> ev = new AGSEvent<MockEventArgs> ();
			ev.Subscribe (onEvent);
			ev.Invoke (this, new MockEventArgs(x));
			Assert.AreEqual (1, syncEvents);
			Assert.AreEqual (0, asyncEvents);
		}
Example #9
0
		public async Task SingleAsyncSubscriberAsyncTest ()
		{
			AGSEvent<MockEventArgs> ev = new AGSEvent<MockEventArgs> ();
			ev.SubscribeToAsync (onEventAsync);
			await ev.InvokeAsync (this, new MockEventArgs(x));
			Assert.AreEqual (0, syncEvents);
			Assert.AreEqual (1, asyncEvents);
		}
Example #10
0
 public AndroidInput()
 {
     MouseDown = new AGSEvent<AGS.API.MouseButtonEventArgs>();
     MouseUp = new AGSEvent<AGS.API.MouseButtonEventArgs>();
     MouseMove = new AGSEvent<MousePositionEventArgs>();
     KeyDown = new AGSEvent<KeyboardEventArgs>();
     KeyUp = new AGSEvent<KeyboardEventArgs>();
 }
Example #11
0
        public void DuplicateSubscribersTest()
        {
            AGSEvent <MockEventArgs> ev = new AGSEvent <MockEventArgs>();

            ev.Subscribe(onEvent);
            ev.Subscribe(onEvent);
            Assert.AreEqual(1, ev.SubscribersCount);
        }
Example #12
0
        public async Task NoSubscribersAsyncTest()
        {
            AGSEvent <AGSEventArgs> ev = new AGSEvent <AGSEventArgs> ();
            await ev.InvokeAsync(this, null);

            Assert.AreEqual(0, syncEvents);
            Assert.AreEqual(0, asyncEvents);
        }
        public void TextBox_RespondsToKeys_Test(string expectedText, params Key[] keys)
        {                                    
            Mock<IInput> input = new Mock<IInput>();
            AGSEvent<KeyboardEventArgs> keyDown = new AGSEvent<KeyboardEventArgs>();
            AGSEvent<KeyboardEventArgs> keyUp = new AGSEvent<KeyboardEventArgs>();
            AGSEvent<MouseButtonEventArgs> mouseDown = new AGSEvent<MouseButtonEventArgs>();
            AGSEvent<MouseButtonEventArgs> mouseDownOutside = new AGSEvent<MouseButtonEventArgs>();
            AGSEvent<MouseButtonEventArgs> mouseUp = new AGSEvent<MouseButtonEventArgs>();
            input.Setup(i => i.KeyDown).Returns(keyDown);
            input.Setup(i => i.KeyUp).Returns(keyUp);            

            Mock<IObject> entity = new Mock<IObject>();
            Mock<ITextComponent> textComponent = new Mock<ITextComponent>();
            string actualText = "";
            textComponent.Setup(t => t.Text).Returns(() => actualText);
            textComponent.SetupSet(t => t.Text = It.IsAny<string>()).Callback<string>(text => actualText = text);
            Mock<IUIEvents> uiEvents = new Mock<IUIEvents>();
            uiEvents.Setup(i => i.MouseDown).Returns(mouseDown);
            uiEvents.Setup(i => i.MouseUp).Returns(mouseUp);
            uiEvents.Setup(i => i.LostFocus).Returns(mouseDownOutside);
            Mock<IInObjectTree> inTree = new Mock<IInObjectTree>();
            entity.Setup(e => e.GetComponent<ITextComponent>()).Returns(textComponent.Object);
            entity.Setup(e => e.GetComponent<IUIEvents>()).Returns(uiEvents.Object);
            entity.Setup(e => e.GetComponent<IInObjectTree>()).Returns(inTree.Object);
            Mock<IGame> game = new Mock<IGame>();
            Mock<IGameFactory> factory = new Mock<IGameFactory>();
            Mock<IUIFactory> uiFactory = new Mock<IUIFactory>();
            Mock<IGameEvents> gameEvents = new Mock<IGameEvents>();
            gameEvents.Setup(g => g.OnBeforeRender).Returns(new Mock<IBlockingEvent<AGSEventArgs>>().Object);
            game.Setup(g => g.Events).Returns(gameEvents.Object);
            game.Setup(g => g.Factory).Returns(factory.Object);
            factory.Setup(f => f.UI).Returns(uiFactory.Object);
            Mock<ILabel> label = new Mock<ILabel>();
            Mock<ITreeNode<IObject>> tree = new Mock<ITreeNode<IObject>>();
            label.Setup(l => l.TreeNode).Returns(tree.Object);
            uiFactory.Setup(u => u.GetLabel(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<float>(),
                It.IsAny<float>(), It.IsAny<float>(), It.IsAny<float>(), It.IsAny<ITextConfig>(), It.IsAny<bool>())).
                Returns(label.Object);
            

            AGSTextBoxComponent textbox = new AGSTextBoxComponent(new AGSEvent<AGSEventArgs>(), new AGSEvent<TextBoxKeyPressingEventArgs>(), 
                input.Object, game.Object);
            textbox.Init(entity.Object);
            textbox.IsFocused = true;
            bool isShiftDown = false;

            foreach (var key in keys)
            {
                if (key == Key.ShiftLeft || key == Key.ShiftRight)
                {
                    isShiftDown = !isShiftDown;
                    if (!isShiftDown) { keyUp.Invoke(this, new KeyboardEventArgs(key)); continue; }
                }
                keyDown.Invoke(this, new KeyboardEventArgs(key));
            }

            Assert.AreEqual(expectedText, actualText);
        }
Example #14
0
        public void SingleSubscriberTest()
        {
            AGSEvent <MockEventArgs> ev = new AGSEvent <MockEventArgs> ();

            ev.Subscribe(onEvent);
            ev.Invoke(new MockEventArgs(x));
            Assert.AreEqual(1, syncEvents);
            Assert.AreEqual(0, asyncEvents);
        }
Example #15
0
        public void Init()
        {
            _onRepeatedlyExecute = new AGSEvent <IRepeatedlyExecuteEventArgs>();
            startTicks();
            Mock <IGameEvents> gameEvents = new Mock <IGameEvents>();

            gameEvents.Setup(g => g.OnRepeatedlyExecute).Returns(_onRepeatedlyExecute);
            Tween.OverrideGameEvents = gameEvents.Object;
        }
Example #16
0
 public KeyboardBindings(IInput input)
 {
     OnKeyboardShortcutPressed = new AGSEvent <string>();
     _bindings    = new ConcurrentDictionary <KeyboardShortcut, string>();
     _pressedKeys = new List <Key>();
     applyDefaults();
     input.KeyDown.Subscribe(onKeyDown);
     input.KeyUp.Subscribe(onKeyUp);
 }
Example #17
0
        public void SingleAsyncSubscriberTest()
        {
            AGSEvent <MockEventArgs> ev = new AGSEvent <MockEventArgs> ();

            ev.SubscribeToAsync(onEventAsync);
            ev.Invoke(this, new MockEventArgs(x));
            Assert.AreEqual(0, syncEvents);
            Assert.AreEqual(1, asyncEvents);
        }
Example #18
0
		public void Init()
		{
			_onRepeatedlyExecute = new AGSEvent<AGSEventArgs>();
			startTicks();
			Mock<IGameEvents> gameEvents = new Mock<IGameEvents>();

			gameEvents.Setup(g => g.OnRepeatedlyExecute).Returns(_onRepeatedlyExecute);
			Tween.OverrideGameEvents = gameEvents.Object;
		}
Example #19
0
        public AndroidInput(AndroidSimpleGestures gestures, AGS.API.Size virtualResolution,
                            IGameState state, IShouldBlockInput shouldBlockInput, IGameWindowSize windowSize)
        {
            MousePosition     = new MousePosition(0f, 0f, state.Viewport);
            _shouldBlockInput = shouldBlockInput;
            _windowSize       = windowSize;
            _state            = state;
            API.MousePosition.VirtualResolution = virtualResolution;
            float density = Resources.System.DisplayMetrics.Density;

            API.MousePosition.GetWindowWidth  = () => (int)(_windowSize.GetWidth(null) - ((GLUtils.ScreenViewport.X * 2) / density));
            API.MousePosition.GetWindowHeight = () => (int)(_windowSize.GetHeight(null) - ((GLUtils.ScreenViewport.Y * 2) / density));
            MouseDown = new AGSEvent <AGS.API.MouseButtonEventArgs>();
            MouseUp   = new AGSEvent <AGS.API.MouseButtonEventArgs>();
            MouseMove = new AGSEvent <MousePositionEventArgs>();
            KeyDown   = new AGSEvent <KeyboardEventArgs>();
            KeyUp     = new AGSEvent <KeyboardEventArgs>();

            gestures.OnUserDrag += async(sender, e) =>
            {
                if (isInputBlocked())
                {
                    return;
                }
                DateTime now = DateTime.Now;
                _lastDrag   = now;
                IsTouchDrag = true;
                setMousePosition(e);
                await MouseMove.InvokeAsync(new MousePositionEventArgs(MousePosition));

                await Task.Delay(300);

                if (_lastDrag <= now)
                {
                    IsTouchDrag = false;
                }
            };
            gestures.OnUserSingleTap += async(sender, e) =>
            {
                if (isInputBlocked())
                {
                    return;
                }
                setMousePosition(e);
                LeftMouseButtonDown = true;
                await MouseDown.InvokeAsync(new MouseButtonEventArgs(null, MouseButton.Left, MousePosition));

                await Task.Delay(250);

                await MouseUp.InvokeAsync(new MouseButtonEventArgs(null, MouseButton.Left, MousePosition));

                LeftMouseButtonDown = false;
            };
            AndroidGameWindow.Instance.OnNewView += onViewChanged;
            onViewChanged(null, AndroidGameWindow.Instance.View);
        }
Example #20
0
        public void SubscribeUnsubscribeOnDifferentTargetAsyncTest()
        {
            AGSEvent <MockEventArgs> ev = new AGSEvent <MockEventArgs> ();

            ev.SubscribeToAsync(onEventAsync);
            EventTests target2 = new EventTests();

            ev.UnsubscribeToAsync(target2.onEventAsync);
            Assert.AreEqual(1, ev.SubscribersCount);
        }
Example #21
0
        public async Task SingleSubscriberAsyncTest()
        {
            AGSEvent <MockEventArgs> ev = new AGSEvent <MockEventArgs> ();

            ev.Subscribe(onEvent);
            await ev.InvokeAsync(this, new MockEventArgs(x));

            Assert.AreEqual(1, syncEvents);
            Assert.AreEqual(0, asyncEvents);
        }
Example #22
0
        public IOSInput(IOSGestures gestures, AGS.API.Size virtualResolution,
                        IGameState state, IShouldBlockInput shouldBlockInput, IGameWindow gameWindow)
        {
            MousePosition     = new MousePosition(0f, 0f, state.Viewport);
            _shouldBlockInput = shouldBlockInput;
            _gameWindow       = gameWindow;
            _state            = state;
            API.MousePosition.VirtualResolution = virtualResolution;
            updateWindowSizeFunctions();

            MouseDown = new AGSEvent <AGS.API.MouseButtonEventArgs>();
            MouseUp   = new AGSEvent <AGS.API.MouseButtonEventArgs>();
            MouseMove = new AGSEvent <MousePositionEventArgs>();
            KeyDown   = new AGSEvent <KeyboardEventArgs>();
            KeyUp     = new AGSEvent <KeyboardEventArgs>();

            IOSGameWindow.Instance.View.OnInsertText     += onInsertText;
            IOSGameWindow.Instance.View.OnDeleteBackward += onDeleteBackwards;

            gestures.OnUserDrag += async(sender, e) =>
            {
                if (isInputBlocked())
                {
                    return;
                }
                DateTime now = DateTime.Now;
                _lastDrag   = now;
                IsTouchDrag = true;
                setMousePosition(e);
                await MouseMove.InvokeAsync(new MousePositionEventArgs(MousePosition));

                await Task.Delay(300);

                if (_lastDrag <= now)
                {
                    IsTouchDrag = false;
                }
            };
            gestures.OnUserSingleTap += async(sender, e) =>
            {
                if (isInputBlocked())
                {
                    return;
                }
                setMousePosition(e);
                LeftMouseButtonDown = true;
                await MouseDown.InvokeAsync(new MouseButtonEventArgs(null, MouseButton.Left, MousePosition));

                await Task.Delay(250);

                await MouseUp.InvokeAsync(new MouseButtonEventArgs(null, MouseButton.Left, MousePosition));

                LeftMouseButtonDown = false;
            };
        }
Example #23
0
        public AGSInput(GameWindow game, AGS.API.Size virtualResolution, IGameState state, 
                        IAGSRoomTransitions roomTransitions, IGameWindowSize windowSize)
        {
            _windowSize = windowSize;
            this._roomTransitions = roomTransitions;
            this._virtualWidth = virtualResolution.Width;
            this._virtualHeight = virtualResolution.Height;
            this._state = state;
            this._keysDown = new AGSConcurrentHashSet<Key>();

            this._game = game;
            this._originalOSCursor = _game.Cursor;

            MouseDown = new AGSEvent<AGS.API.MouseButtonEventArgs>();
            MouseUp = new AGSEvent<AGS.API.MouseButtonEventArgs>();
            MouseMove = new AGSEvent<MousePositionEventArgs>();
            KeyDown = new AGSEvent<KeyboardEventArgs>();
            KeyUp = new AGSEvent<KeyboardEventArgs>();

            game.MouseDown += async (sender, e) =>
            {
                if (isInputBlocked()) return;
                var button = convert(e.Button);
                if (button == AGS.API.MouseButton.Left) LeftMouseButtonDown = true;
                else if (button == AGS.API.MouseButton.Right) RightMouseButtonDown = true;
                await MouseDown.InvokeAsync(sender, new AGS.API.MouseButtonEventArgs(button, convertX(e.X), convertY(e.Y)));
            };
            game.MouseUp += async (sender, e) =>
            {
                if (isInputBlocked()) return;
                var button = convert(e.Button);
                if (button == AGS.API.MouseButton.Left) LeftMouseButtonDown = false;
                else if (button == AGS.API.MouseButton.Right) RightMouseButtonDown = false;
                await MouseUp.InvokeAsync(sender, new AGS.API.MouseButtonEventArgs(button, convertX(e.X), convertY(e.Y)));
            };
            game.MouseMove += async (sender, e) =>
            {
                if (isInputBlocked()) return;
                await MouseMove.InvokeAsync(sender, new MousePositionEventArgs(convertX(e.X), convertY(e.Y)));
            };
            game.KeyDown += async (sender, e) =>
            {
                Key key = convert(e.Key);
                _keysDown.Add(key);
                if (isInputBlocked()) return;
                await KeyDown.InvokeAsync(sender, new KeyboardEventArgs(key));
            };
            game.KeyUp += async (sender, e) =>
            {
                Key key = convert(e.Key);
                _keysDown.Remove(key);
                if (isInputBlocked()) return;
                await KeyUp.InvokeAsync(sender, new KeyboardEventArgs(key));
            };
        }
Example #24
0
		public void MultipleSubscribersTest ()
		{
			AGSEvent<MockEventArgs> ev = new AGSEvent<MockEventArgs> ();
			ev.Subscribe (onEvent);
			ev.Subscribe ((sender, e) => onEvent(sender, e));
			ev.SubscribeToAsync (onEventAsync);
			ev.SubscribeToAsync (async (sender, e) => await onEventAsync(sender, e));
			ev.Invoke (this, new MockEventArgs(x));
			Assert.AreEqual (2, syncEvents);
			Assert.AreEqual (2, asyncEvents);
		}
Example #25
0
        public void MultipleSubscribersTest()
        {
            AGSEvent <MockEventArgs> ev = new AGSEvent <MockEventArgs> ();

            ev.Subscribe(onEvent);
            ev.Subscribe((sender, e) => onEvent(sender, e));
            ev.SubscribeToAsync(onEventAsync);
            ev.SubscribeToAsync(async(sender, e) => await onEventAsync(sender, e));
            ev.Invoke(this, new MockEventArgs(x));
            Assert.AreEqual(2, syncEvents);
            Assert.AreEqual(2, asyncEvents);
        }
Example #26
0
        public void MultipleSubscribersTest()
        {
            AGSEvent <MockEventArgs> ev = new AGSEvent <MockEventArgs> ();

            ev.Subscribe(onEvent);
            ev.Subscribe(e => onEvent(e));
            ev.SubscribeToAsync(onEventAsyncWithBlockingInvoke);
            ev.SubscribeToAsync(async e => await onEventAsyncWithBlockingInvoke(e));
            ev.Invoke(new MockEventArgs(x));
            Assert.AreEqual(2, syncEvents);
            Assert.AreEqual(2, asyncEvents);
        }
Example #27
0
        public IOSInput(IOSGestures gestures, IShouldBlockInput shouldBlockInput, ICoordinates coordinates, IAGSHitTest hitTest)
        {
            _gestures         = gestures;
            _hitTest          = hitTest;
            _coordinates      = coordinates;
            MousePosition     = new MousePosition(0f, 0f, _coordinates);
            _shouldBlockInput = shouldBlockInput;

            MouseDown = new AGSEvent <AGS.API.MouseButtonEventArgs>();
            MouseUp   = new AGSEvent <AGS.API.MouseButtonEventArgs>();
            MouseMove = new AGSEvent <MousePositionEventArgs>();
            KeyDown   = new AGSEvent <KeyboardEventArgs>();
            KeyUp     = new AGSEvent <KeyboardEventArgs>();

            IOSGameWindow.Instance.View.OnInsertText     += onInsertText;
            IOSGameWindow.Instance.View.OnDeleteBackward += onDeleteBackwards;

            gestures.OnUserDrag += async(sender, e) =>
            {
                if (isInputBlocked())
                {
                    return;
                }
                DateTime now = DateTime.Now;
                _lastDrag   = now;
                IsTouchDrag = true;
                setMousePosition(e);
                await MouseMove.InvokeAsync(new MousePositionEventArgs(MousePosition));

                await Task.Delay(300);

                if (_lastDrag <= now)
                {
                    IsTouchDrag = false;
                }
            };
            gestures.OnUserSingleTap += async(sender, e) =>
            {
                if (isInputBlocked())
                {
                    return;
                }
                setMousePosition(e);
                LeftMouseButtonDown = true;
                await MouseDown.InvokeAsync(new MouseButtonEventArgs(_hitTest.ObjectAtMousePosition, MouseButton.Left, MousePosition));

                await Task.Delay(250);

                await MouseUp.InvokeAsync(new MouseButtonEventArgs(_hitTest.ObjectAtMousePosition, MouseButton.Left, MousePosition));

                LeftMouseButtonDown = false;
            };
        }
Example #28
0
        public AndroidInput(AndroidSimpleGestures gestures, AGS.API.Size virtualResolution,
                            IGameState state, IShouldBlockInput shouldBlockInput, IGameWindowSize windowSize)
        {
            _shouldBlockInput   = shouldBlockInput;
            _windowSize         = windowSize;
            _state              = state;
            this._virtualWidth  = virtualResolution.Width;
            this._virtualHeight = virtualResolution.Height;
            MouseDown           = new AGSEvent <AGS.API.MouseButtonEventArgs>();
            MouseUp             = new AGSEvent <AGS.API.MouseButtonEventArgs>();
            MouseMove           = new AGSEvent <MousePositionEventArgs>();
            KeyDown             = new AGSEvent <KeyboardEventArgs>();
            KeyUp = new AGSEvent <KeyboardEventArgs>();

            gestures.OnUserDrag += async(sender, e) =>
            {
                if (isInputBlocked())
                {
                    return;
                }
                DateTime now = DateTime.Now;
                _lastDrag   = now;
                IsTouchDrag = true;
                setMousePosition(e);
                await MouseMove.InvokeAsync(sender, new MousePositionEventArgs(MouseX, MouseY));

                await Task.Delay(300);

                if (_lastDrag <= now)
                {
                    IsTouchDrag = false;
                }
            };
            gestures.OnUserSingleTap += async(sender, e) =>
            {
                if (isInputBlocked())
                {
                    return;
                }
                setMousePosition(e);
                LeftMouseButtonDown = true;
                await MouseDown.InvokeAsync(sender, new MouseButtonEventArgs(MouseButton.Left, MouseX, MouseY));

                await Task.Delay(250);

                await MouseUp.InvokeAsync(sender, new MouseButtonEventArgs(MouseButton.Left, MouseX, MouseY));

                LeftMouseButtonDown = false;
            };
            AndroidGameWindow.Instance.OnNewView += onViewChanged;
            onViewChanged(null, AndroidGameWindow.Instance.View);
        }
Example #29
0
        public void DontClaimEventTest()
        {
            AGSEvent <MockEventArgs> ev = new AGSEvent <MockEventArgs>();

            ev.Subscribe(onEventDontClaim);
            EventTests target2 = new EventTests();

            ev.Subscribe(target2.onEventDontClaim);
            ev.Invoke(new MockEventArgs(x));
            Assert.AreEqual(2, ev.SubscribersCount);
            Assert.AreEqual(1, syncEvents);
            Assert.AreEqual(1, target2.syncEvents);
        }
Example #30
0
        public async Task MultipleSubscribersAsyncTest()
        {
            AGSEvent <MockEventArgs> ev = new AGSEvent <MockEventArgs> ();

            ev.Subscribe(onEvent);
            ev.Subscribe(e => onEvent(e));
            ev.SubscribeToAsync(onEventAsync);
            ev.SubscribeToAsync(async e => await onEventAsync(e));
            await ev.InvokeAsync(new MockEventArgs(x));

            Assert.AreEqual(2, syncEvents);
            Assert.AreEqual(2, asyncEvents);
        }
Example #31
0
        public AndroidInput(AndroidSimpleGestures gestures, IShouldBlockInput shouldBlockInput, ICoordinates coordinates,
                            IAGSHitTest hitTest)
        {
            _hitTest          = hitTest;
            _coordinates      = coordinates;
            MousePosition     = new MousePosition(0f, 0f, coordinates);
            _shouldBlockInput = shouldBlockInput;
            MouseDown         = new AGSEvent <AGS.API.MouseButtonEventArgs>();
            MouseUp           = new AGSEvent <AGS.API.MouseButtonEventArgs>();
            MouseMove         = new AGSEvent <MousePositionEventArgs>();
            KeyDown           = new AGSEvent <KeyboardEventArgs>();
            KeyUp             = new AGSEvent <KeyboardEventArgs>();

            gestures.OnUserDrag += async(sender, e) =>
            {
                if (isInputBlocked())
                {
                    return;
                }
                DateTime now = DateTime.Now;
                _lastDrag   = now;
                IsTouchDrag = true;
                setMousePosition(e);
                await MouseMove.InvokeAsync(new MousePositionEventArgs(MousePosition));

                await Task.Delay(300);

                if (_lastDrag <= now)
                {
                    IsTouchDrag = false;
                }
            };
            gestures.OnUserSingleTap += async(sender, e) =>
            {
                if (isInputBlocked())
                {
                    return;
                }
                setMousePosition(e);
                LeftMouseButtonDown = true;
                await MouseDown.InvokeAsync(new MouseButtonEventArgs(hitTest.ObjectAtMousePosition, MouseButton.Left, MousePosition));

                await Task.Delay(250);

                await MouseUp.InvokeAsync(new MouseButtonEventArgs(hitTest.ObjectAtMousePosition, MouseButton.Left, MousePosition));

                LeftMouseButtonDown = false;
            };
            AndroidGameWindow.Instance.OnNewView += onViewChanged;
            onViewChanged(null, AndroidGameWindow.Instance.View);
        }
Example #32
0
		public AGSUIEvents(IInput input, IGameState state, IGameEvents gameEvents)
		{
			_input = input;
			_state = state;
			_gameEvents = gameEvents;

			MouseEnter = new AGSEvent<MousePositionEventArgs> ();
			MouseLeave = new AGSEvent<MousePositionEventArgs> ();
			MouseMove = new AGSEvent<MousePositionEventArgs> ();
			MouseClicked = new AGSEvent<MouseButtonEventArgs> ();
            MouseDoubleClicked = new AGSEvent<MouseButtonEventArgs>();
            MouseDown = new AGSEvent<MouseButtonEventArgs> ();
			MouseUp = new AGSEvent<MouseButtonEventArgs> ();
            LostFocus = new AGSEvent<MouseButtonEventArgs>();

			_leftMouseClickTimer = new Stopwatch ();
			_rightMouseClickTimer = new Stopwatch ();
            _leftMouseDoubleClickTimer = new Stopwatch();
            _rightMouseDoubleClickTimer = new Stopwatch();
        }
        public MenuItem(string text, Action onConfirm = null, Action onScrollLeft = null, Action onScrollRight = null)
        {
            Text          = text;
            OnConfirm     = new AGSEvent();
            OnScrollLeft  = new AGSEvent();
            OnScrollRight = new AGSEvent();

            if (onConfirm != null)
            {
                OnConfirm.Subscribe(onConfirm);
            }
            if (onScrollLeft != null)
            {
                OnScrollLeft.Subscribe(onScrollLeft);
            }
            if (onScrollRight != null)
            {
                OnScrollRight.Subscribe(onScrollRight);
            }
        }
Example #34
0
        private int _inUpdate; //For preventing re-entrancy

        public AGSInput(IGameState state, IGameEvents events,
                        IShouldBlockInput shouldBlockInput, IGameWindowSize windowSize)
        {
            _events                           = events;
            _actions                          = new ConcurrentQueue <Func <Task> >();
            _windowSize                       = windowSize;
            this._shouldBlockInput            = shouldBlockInput;
            API.MousePosition.GetWindowWidth  = () => _windowSize.GetWidth(_game);
            API.MousePosition.GetWindowHeight = () => _windowSize.GetHeight(_game);
            this._state                       = state;
            this._keysDown                    = new AGSConcurrentHashSet <API.Key>();

            MouseDown = new AGSEvent <AGS.API.MouseButtonEventArgs>();
            MouseUp   = new AGSEvent <AGS.API.MouseButtonEventArgs>();
            MouseMove = new AGSEvent <MousePositionEventArgs>();
            KeyDown   = new AGSEvent <KeyboardEventArgs>();
            KeyUp     = new AGSEvent <KeyboardEventArgs>();

            if (AGSGameWindow.GameWindow != null)
            {
                Init(AGSGameWindow.GameWindow);
            }
        }
Example #35
0
		public AGSEdge()
		{
			OnEdgeCrossed = new AGSEvent<AGSEventArgs> ();
            Enabled = true;
		}
Example #36
0
		public AGSInventory()
		{
			Items = new List<IInventoryItem> (20);
			_eventsMap = new ConcurrentDictionary<Tuple<IInventoryItem, IInventoryItem>, IEvent<InventoryCombinationEventArgs>> (2, 400);
			OnDefaultCombination = new AGSEvent<InventoryCombinationEventArgs> ();
		}
 public AGSCheckboxComponent()
 {
     OnCheckChanged = new AGSEvent<CheckBoxEventArgs>();
 }
Example #38
0
		public void Init()
		{
			_onRepeatedlyExecute = new AGSEvent<AGSEventArgs>();
			startTicks();
		}
        public void TextBox_RespondsToKeys_Test(string expectedText, params Key[] keys)
        {
            Mock <IInput> input = new Mock <IInput>();
            AGSEvent <KeyboardEventArgs>    keyDown          = new AGSEvent <KeyboardEventArgs>();
            AGSEvent <KeyboardEventArgs>    keyUp            = new AGSEvent <KeyboardEventArgs>();
            AGSEvent <MouseButtonEventArgs> mouseDown        = new AGSEvent <MouseButtonEventArgs>();
            AGSEvent <MouseButtonEventArgs> mouseDownOutside = new AGSEvent <MouseButtonEventArgs>();
            AGSEvent <MouseButtonEventArgs> mouseUp          = new AGSEvent <MouseButtonEventArgs>();

            input.Setup(i => i.KeyDown).Returns(keyDown);
            input.Setup(i => i.KeyUp).Returns(keyUp);

            Mock <IObject>        entity        = new Mock <IObject>();
            Mock <ITextComponent> textComponent = new Mock <ITextComponent>();
            string actualText = "";

            textComponent.Setup(t => t.Text).Returns(() => actualText);
            textComponent.SetupSet(t => t.Text = It.IsAny <string>()).Callback <string>(text => actualText = text);
            Mock <IUIEvents> uiEvents = new Mock <IUIEvents>();

            uiEvents.Setup(i => i.MouseDown).Returns(mouseDown);
            uiEvents.Setup(i => i.MouseUp).Returns(mouseUp);
            uiEvents.Setup(i => i.LostFocus).Returns(mouseDownOutside);
            Mock <IInObjectTree> inTree = new Mock <IInObjectTree>();

            entity.Setup(e => e.GetComponent <ITextComponent>()).Returns(textComponent.Object);
            entity.Setup(e => e.GetComponent <IUIEvents>()).Returns(uiEvents.Object);
            entity.Setup(e => e.GetComponent <IInObjectTree>()).Returns(inTree.Object);
            Mock <IGame>        game       = new Mock <IGame>();
            Mock <IGameFactory> factory    = new Mock <IGameFactory>();
            Mock <IUIFactory>   uiFactory  = new Mock <IUIFactory>();
            Mock <IGameEvents>  gameEvents = new Mock <IGameEvents>();

            gameEvents.Setup(g => g.OnBeforeRender).Returns(new Mock <IBlockingEvent <AGSEventArgs> >().Object);
            gameEvents.Setup(g => g.OnRepeatedlyExecute).Returns(new Mock <IEvent <AGSEventArgs> >().Object);
            game.Setup(g => g.Events).Returns(gameEvents.Object);
            game.Setup(g => g.Factory).Returns(factory.Object);
            factory.Setup(f => f.UI).Returns(uiFactory.Object);
            Mock <ILabel> label = new Mock <ILabel>();
            Mock <ITreeNode <IObject> > tree      = new Mock <ITreeNode <IObject> >();
            Mock <IFocusedUI>           focusedUi = new Mock <IFocusedUI>();

            label.Setup(l => l.TreeNode).Returns(tree.Object);
            uiFactory.Setup(u => u.GetLabel(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <float>(),
                                            It.IsAny <float>(), It.IsAny <float>(), It.IsAny <float>(), It.IsAny <ITextConfig>(), It.IsAny <bool>())).
            Returns(label.Object);


            AGSTextBoxComponent textbox = new AGSTextBoxComponent(new AGSEvent <AGSEventArgs>(), new AGSEvent <TextBoxKeyPressingEventArgs>(),
                                                                  input.Object, game.Object, new DesktopKeyboardState(), focusedUi.Object);

            textbox.Init(entity.Object);
            textbox.IsFocused = true;
            bool isShiftDown = false;

            foreach (var key in keys)
            {
                if (key == Key.ShiftLeft || key == Key.ShiftRight)
                {
                    isShiftDown = !isShiftDown;
                    if (!isShiftDown)
                    {
                        keyUp.Invoke(this, new KeyboardEventArgs(key)); continue;
                    }
                }
                keyDown.Invoke(this, new KeyboardEventArgs(key));
            }

            Assert.AreEqual(expectedText, actualText);
        }
Example #40
0
		public void SubscribeUnsubscribeOnDifferentTargetAsyncTest()
		{
			AGSEvent<MockEventArgs> ev = new AGSEvent<MockEventArgs> ();
			ev.SubscribeToAsync(onEventAsync);
			EventTests target2 = new EventTests ();
			ev.UnsubscribeToAsync(target2.onEventAsync);
			Assert.AreEqual(1, ev.SubscribersCount);
		}
Example #41
0
		public void SubscribeUnsubscribeAsyncTest()
		{
			AGSEvent<MockEventArgs> ev = new AGSEvent<MockEventArgs> ();
			ev.SubscribeToAsync(onEventAsync);
			ev.UnsubscribeToAsync(onEventAsync);
			Assert.AreEqual(0, ev.SubscribersCount);
		}
Example #42
0
 public FolderTree(IDevice device, IGameFactory factory)
 {
     _device          = device;
     _factory         = factory;
     OnFolderSelected = new AGSEvent <string>();
 }
Example #43
0
 public AGSHasImage()
 {
     OnImageChanged = new AGSEvent<AGSEventArgs>();
     Anchor = new PointF(0.5f, 0f);
     Tint = Colors.White;
 }
Example #44
0
 public DesktopKeyboardState()
 {
     OnSoftKeyboardHidden = new AGSEvent();
 }
Example #45
0
        public AGSInput(GameWindow game, AGS.API.Size virtualResolution, IGameState state,
                        IShouldBlockInput shouldBlockInput, IGameWindowSize windowSize)
        {
            _windowSize            = windowSize;
            this._shouldBlockInput = shouldBlockInput;
            this._virtualWidth     = virtualResolution.Width;
            this._virtualHeight    = virtualResolution.Height;
            this._state            = state;
            this._keysDown         = new AGSConcurrentHashSet <Key>();

            this._game             = game;
            this._originalOSCursor = _game.Cursor;

            MouseDown = new AGSEvent <AGS.API.MouseButtonEventArgs>();
            MouseUp   = new AGSEvent <AGS.API.MouseButtonEventArgs>();
            MouseMove = new AGSEvent <MousePositionEventArgs>();
            KeyDown   = new AGSEvent <KeyboardEventArgs>();
            KeyUp     = new AGSEvent <KeyboardEventArgs>();

            game.MouseDown += async(sender, e) =>
            {
                if (isInputBlocked())
                {
                    return;
                }
                var button = convert(e.Button);
                if (button == AGS.API.MouseButton.Left)
                {
                    LeftMouseButtonDown = true;
                }
                else if (button == AGS.API.MouseButton.Right)
                {
                    RightMouseButtonDown = true;
                }
                await MouseDown.InvokeAsync(sender, new AGS.API.MouseButtonEventArgs(button, convertX(e.X), convertY(e.Y)));
            };
            game.MouseUp += async(sender, e) =>
            {
                if (isInputBlocked())
                {
                    return;
                }
                var button = convert(e.Button);
                if (button == AGS.API.MouseButton.Left)
                {
                    LeftMouseButtonDown = false;
                }
                else if (button == AGS.API.MouseButton.Right)
                {
                    RightMouseButtonDown = false;
                }
                await MouseUp.InvokeAsync(sender, new AGS.API.MouseButtonEventArgs(button, convertX(e.X), convertY(e.Y)));
            };
            game.MouseMove += async(sender, e) =>
            {
                if (isInputBlocked())
                {
                    return;
                }
                await MouseMove.InvokeAsync(sender, new MousePositionEventArgs(convertX(e.X), convertY(e.Y)));
            };
            game.KeyDown += async(sender, e) =>
            {
                Key key = convert(e.Key);
                _keysDown.Add(key);
                if (isInputBlocked())
                {
                    return;
                }
                await KeyDown.InvokeAsync(sender, new KeyboardEventArgs(key));
            };
            game.KeyUp += async(sender, e) =>
            {
                Key key = convert(e.Key);
                _keysDown.Remove(key);
                if (isInputBlocked())
                {
                    return;
                }
                await KeyUp.InvokeAsync(sender, new KeyboardEventArgs(key));
            };
        }
Example #46
0
 public IOSKeyboardState()
 {
     OnSoftKeyboardHidden = new AGSEvent();
     NSNotificationCenter.DefaultCenter.AddObserver(UIKeyboard.WillHideNotification, onKeyboardHidden);
 }
Example #47
0
 public AGSCheckboxComponent()
 {
     OnCheckChanged = new AGSEvent <CheckBoxEventArgs>();
 }
		public AGSAnimationContainer()
		{
            OnAnimationStarted = new AGSEvent<AGSEventArgs>();
		}		
Example #49
0
 public void Init()
 {
     _onRepeatedlyExecute = new AGSEvent();
     startTicks();
 }