Example #1
0
    // Update is called once per frame
    void Update()
    {
        InputManager.Update();

        if(InputManager.ActiveDevice.MenuWasPressed)
        {
            bool newDevice = true;
            foreach(InputDevice inputDevice in device)
            {
                if(inputDevice == null || InputManager.ActiveDevice == null || inputDevice.Equals(InputManager.ActiveDevice))
                {
                    newDevice = false;
                }
            }

            if(newDevice && i < 4)
            {
                device.Add(InputManager.ActiveDevice);
                i++;
            }
        }

        int j=1;
        foreach(InputDevice inputDevice in device)
        {
            InputEvent e = new InputEvent(inputDevice, j);
            GameEvents.GameEventManager.post(e);
            j++;
        }
    }
 /// <summary>
 /// Function callback to process "EXIT_GAME" logic orders
 /// </summary>
 /// <param name="e">Event with the info of the order</param>
 public void onExitGameReceived(InputEvent e)
 {
     if (e.isOk)
     {
         GameMgr.Singleton.ChangeState("Menu");
     }
 }
Example #3
0
    void OnDoubleTap( InputEvent inputEvent )
    {
        if( inputEvent.hit==null ) return;
        Transform hitTransform = inputEvent.hit.transform;

        Lock( hitTransform );
    }
        public override void OnButtonDownEvent(InputEvent evt)
        {
            if (evt.IsRButtonDown())
            {
                this.Exit(1);
                return;
            }

            Vector3 pt = GetPointOnShape((int)evt.GetMousePosition().X, (int)evt.GetMousePosition().Y);
            if (pt == null)
                return;

            m_Points.Add(pt);

            if (m_Points.Count > 1)
            {
                TopoShape spline = GlobalInstance.BrepTools.MakeSpline(m_Points);
                if (spline != null)
                {
                    SceneNode node = GlobalInstance.TopoShapeConvert.ToEdgeNode(spline, 0.0f);

                    this.RemoveAllTempNodes();
                    this.ShowTempNode(node);
                    GetRenderer().RequestDraw(1);
                }
            }
        }
        public override void OnButtonDownEvent(InputEvent evt)
        {
            Renderer renderer = GetRenderer();
            m_Step += 1;
            if (m_Step == (int)EditStep.ES_Finish)
            {
                m_Step = (int)EditStep.ES_Init;

                LineNode lineNode = new LineNode();
                lineNode.Set(m_StartPos, ToWorldPoint(evt.GetMousePosition()));

                renderer.GetSceneManager().AddNode(lineNode);
                tempLineNode.SetVisible(false);

                renderer.RequestDraw(1);
                return;
            }

            if (evt.IsLButtonDown())
            {
                m_StartPos = ToWorldPoint(evt.GetMousePosition());
                tempLineNode.SetVisible(true);
                renderer.RequestDraw(1);
            }
        }
Example #6
0
    public InputEvent GetEvent()
    {
        var rect = new Rect(0, 0, Screen.width, Screen.height);
        bool currState = Input.GetMouseButton(0);
        Vector2 currPos = Input.mousePosition;

        InputEvent ret = new InputEvent() { Type = InputEventType.Idle, Origin = Vector2.zero };
        if(currState && !_trackClick) {
            _trackClick = true;
            _clickDuration = 0;
        }
        if(currState) {
            _clickDuration += Time.deltaTime;
        } else {

            if(_trackClick && _clickDuration < ClickConst && rect.Contains(currPos)) {
                _trackClick = false;
                _clickDuration = 0;

                ret = new InputEvent() { Type = InputEventType.Click, Origin = currPos };
                return ret;
            } else {
                _trackClick = false;
            }
        }
        return ret;
    }
 /// <summary>
 /// Function callback to process "START_GAME" logic orders
 /// </summary>
 /// <param name="e">Event with the info of the order</param>
 public void onStartGameReceived(InputEvent e)
 {
     if (e.isOk)
     {
         StartGame();
     }
 }
        public override void OnButtonDownEvent(InputEvent evt)
        {
            TopoShape shape = GetSelectedShape((int)evt.GetMousePosition().X, (int)evt.GetMousePosition().Y);
            if(shape == null)
                return;

            Renderer renderer = GetRenderer();
            m_Step += 1;
            if (m_Step == (int)EditStep.ES_Finish)
            {
                m_Step = (int)EditStep.ES_Init;

                MeasureTools mt = new MeasureTools();
                MeasureResult rt = mt.ComputeMinDistance(m_Shape1, shape);

                LineNode lineNode = new LineNode();
                lineNode.SetShowText(true);
                lineNode.Set(rt.GetPointOnShape1(), rt.GetPointOnShape2());

                renderer.GetSceneManager().AddNode(lineNode);
                renderer.RequestDraw(1);
                return;
            }

            if (evt.IsLButtonDown())
            {
                
                m_Shape1 = shape;
            }
        }
Example #9
0
    public void onMoveReceived(InputEvent e)
    {
        if (e.isOk)
        {

            Vector3 dir = Vector3.zero;
            if (e.Order == "MOVE_UP")
            {
                dir.y = 1.0f;
            }
            else if (e.Order == "MOVE_DOWN")
            {
                dir.y = -1.0f;
            }
            else if (e.Order == "MOVE_LEFT")
            {
                dir.x = -1.0f;
            }
            else if (e.Order == "MOVE_RIGHT")
            {
                dir.x = 1.0f;
            }

            m_controller.MovementDir = dir;
            m_controller.Speed = float.MaxValue;
        }
    }
Example #10
0
 /// <summary>
 /// Function callback to process "EXIT" logic orders
 /// </summary>
 /// <param name="e">Event with the info of the order</param>
 public void onExitReceived(InputEvent e)
 {
     if (e.isOk)
     {
         Application.Quit();
     }
 }
Example #11
0
 /// <summary>
 /// Function callback to process "START_GAME" logic orders
 /// </summary>
 /// <param name="e">Event with the info of the order</param>
 public void onStartGameReceived(InputEvent e)
 {
     if (e.isOk)
     {
         GameMgr.Singleton.ChangeState("Game");
     }
 }
Example #12
0
 public override void OnMouseMoveEvent(InputEvent evt)
 {
     if (m_Step == (int)EditStep.ES_Drawing)
     {
         Renderer renderer = GetRenderer();
         tempLineNode.Set(m_StartPos, ToWorldPoint(evt.GetMousePosition()));
         renderer.RequestDraw(1);
     }
 }
Example #13
0
    // Update is called once per frame
    void Update()
    {
        InputManager.Update();

        int i=1;
        foreach(InputDevice inputDevice in InputManager.Devices)
        {
            InputEvent e = new InputEvent(inputDevice, i);
            GameEvents.GameEventManager.post(e);
            i++;
        }
    }
Example #14
0
 void OnDrag( InputEvent inputEvent )
 {
     if( state != State.Drifting ) {
         state = State.Dragging;
         if( cameraTween != null )
             cameraTween.pause();
     }
     Vector3 deltaPos = ScreenPointToGroundPlanePoint( inputEvent.pos ) - ScreenPointToGroundPlanePoint( inputEvent.lastPos );
     deltaPos = -deltaPos.xz().AddY( 0 );
     speed = speed.LowPassFilter( deltaPos / Time.deltaTime, speedSmoothingFactor );
     speed.y = 0;
     log.Trace( "Drag by " + deltaPos );
     dragSnapCamera.transform.Translate( deltaPos, Space.World );
 }
Example #15
0
    private void OnMouseClick(InputEvent e)
    {
        if (e.isOk)
        {
            m_angryClicks++;

            if (m_angryClicks >= m_maxAngryCliks)
            {
                PoolMgr.Singleton.Instatiate(m_goatPrefab, m_transform.position, m_transform.rotation);
                m_angryClicks = 0;
                m_maxAngryCliks--;
            }
        }
    }
Example #16
0
        public override void OnMouseMoveEvent(InputEvent evt)
        {
            if (m_Step == EditStep.ES_PickNode)
            {
                Vector2 pt = evt.GetMousePosition();
                GetRenderer().Highlight((int)pt.X, (int)pt.Y);
            }
            else
            {
                Vector3 endPt = ToWorldPoint(evt.GetMousePosition());
                Matrix4 trf = GlobalInstance.MatrixBuilder.MakeTranslate(endPt - m_StartPos);
                m_TargetNode.SetTransform(GlobalInstance.MatrixBuilder.Multiply(m_InitTrf, trf));

                GetRenderer().RequestDraw(1);
            }
        }
Example #17
0
    private void DoSendMessage( string msgName, InputEvent inputEvent )
    {
        log.Trace( "Attempting to send message: " + msgName + " cam: " + currTouch.cam );
        inputEvent.hit = currTouch.hit;

        if( currTouch.receiver != null ) {
            log.Trace( "Sending message " + msgName + " to " + currTouch.receiver.name );
            currTouch.receiver.SendMessage( msgName, inputEvent, SendMessageOptions.DontRequireReceiver );
        }

        IEnumerable<InputReceiver> globalReceivers = inputReceivers.FindAll( ir => ir != null && ir.receiveAllInput == true );
        globalReceivers.ForEach( ir => {
            log.Trace( "Sending message " + msgName + " to " + ir.name );
            ir.SendMessage( msgName, inputEvent, SendMessageOptions.DontRequireReceiver );
        } );
    }
        public override void OnButtonDownEvent(InputEvent evt)
        {

            if (evt.IsRButtonDown())
            {
                this.Exit(1);
                return;
            }
            this.RemoveAllTempNodes();

            Renderer rv = GetRenderer();

            PickHelper pickHelper = new PickHelper();
            pickHelper.Initialize(rv);

            if (!pickHelper.Pick(evt.GetMousePosition()))
                return;


            TopoShape shape = pickHelper.GetGeometry();
            GeomSurface surface = new GeomSurface();
            if (!surface.Initialize(shape))
                return;

            IntersectionLineSurface intersector = new IntersectionLineSurface();
            intersector.SetSurface(shape);
            if (!intersector.Perform(rv.ComputeScreenRay(evt.GetMousePosition())))
            {
                return;
            }

            int nCount = intersector.GetPointCount();
            if(nCount < 1)
                return;

            float u = intersector.GetParameterU(1);
            float v = intersector.GetParameterV(1);

            Vector3 pt = surface.Value(u, v);
            Vector3 normal = surface.GetNormal(u, v);

            LineNode lineNode = new LineNode();
            lineNode.Set(pt, pt + normal);

            this.ShowTempNode(lineNode);
            rv.RequestDraw(1);
        }
		public InputEvent CreateAxisEvent(string name, string axisName)
		{
			if(!_eventLookup.ContainsKey(name))
			{
				InputEvent evt = new InputEvent(name);
				evt.axisName = axisName;
				evt.eventType = InputEventType.Axis;
				
				_inputEvents.Add(evt);
				_eventLookup.Add(name, evt);
				return evt;
			}
			else
			{
				Debug.LogError(string.Format("An input event named {0} already exists", name), this);
				return null;
			}
		}
		public InputEvent CreateButtonEvent(string name, string buttonName, InputState inputState)
		{
			if(!_eventLookup.ContainsKey(name))
			{
				InputEvent evt = new InputEvent(name);
				evt.buttonName = buttonName;
				evt.eventType = InputEventType.Button;
				evt.inputState = inputState;
				
				_inputEvents.Add(evt);
				_eventLookup.Add(name, evt);
				return evt;
			}
			else
			{
				Debug.LogError(string.Format("An input event named {0} already exists", name), this);
				return null;
			}
		}
Example #21
0
		public void update()
		{
			_previousState = _currentState;
			_currentState = GamePad.GetState( _playerIndex );

			// check for controller connects/disconnects
			if( _previousState.IsConnected != _currentState.IsConnected )
			{
				var data = new InputEvent {
					gamePadIndex = (int)_playerIndex
				};
				Input.emitter.emit( _currentState.IsConnected ? InputEventType.GamePadConnected : InputEventType.GamePadDisconnected, data );
			}

			if( _rumbleTime > 0f )
			{
				_rumbleTime -= Time.deltaTime;
				if( _rumbleTime <= 0f )
					GamePad.SetVibration( _playerIndex, 0, 0 );
			}
		}
Example #22
0
 public override void OnButtonDownEvent(InputEvent evt)
 {
     Renderer renderer = GetRenderer();
     if (m_Step == EditStep.ES_PickNode)
     {
         if (renderer.Select(true) > 0)
         {
             SelectedShapeQuery query = new SelectedShapeQuery();
             renderer.QuerySelection(query);
             m_TargetNode = query.GetRootNode();
             if (m_TargetNode != null)
             {
                 m_Step = EditStep.ES_BeginMove;
                 m_InitTrf = m_TargetNode.GetTransform();
             }
          }
     }
     else
     {
         m_StartPos = ToWorldPoint(evt.GetMousePosition());
     }
 }
        static int DelayedAndDraggableIntField(Rect rect, GUIContent label, int value, ref InputEvent inputEvent)
        {
            var dragSensitivity = NumericFieldDraggerUtility.CalculateIntDragSensitivity(value);

            return(DelayedAndDraggableIntField(rect, label, value, ref inputEvent, dragSensitivity));
        }
Example #24
0
 internal void Update(EventSystem eventSystem)
 {
     if (Input.GetMouseButtonDown(buttonId))
     {
         if (eventSystem != null && eventSystem.IsPointerOverGameObject())
         {
             return;
         }
         beginPos = Input.mousePosition;
         if (beginPos.x < 0 || beginPos.y < 0 || beginPos.x >= Screen.width || beginPos.y >= Screen.height)
         {
             return;
         }
         begin = true;
         var e = new InputEvent()
         {
             sequenceId = this.sequenceId,
             id         = this.id,
             type       = InputEventType.Begin,
             position   = Input.mousePosition,
             sender     = this
         };
         this.id++;
         beginStream.OnNext(e);
     }
     else if (Input.GetMouseButtonUp(buttonId))
     {
         if (!begin)
         {
             return;
         }
         begin = false;
         var e = new InputEvent()
         {
             sequenceId = this.sequenceId,
             id         = this.id,
             type       = InputEventType.End,
             position   = Input.mousePosition,
             sender     = this
         };
         this.id = 0;
         endStream.OnNext(e);
         this.sequenceId++;
     }
     else
     {
         if (begin && beginPos != (Vector2)Input.mousePosition)
         {
             beginPos = Input.mousePosition;
             var e = new InputEvent()
             {
                 sequenceId = this.sequenceId,
                 id         = this.id,
                 type       = InputEventType.Move,
                 position   = Input.mousePosition,
                 sender     = this
             };
             this.id++;
             moveStream.OnNext(e);
         }
     }
 }
Example #25
0
        private int KeyboardHookProc(int nCode, Int32 wParam, IntPtr lParam)
        {
            if (nCode == 0)
            {
                EventMsg msg = (EventMsg)Marshal.PtrToStructure(lParam, typeof(EventMsg));
                if (wParam == 0x100)                     //WM_KEYDOWN=0x100
                {
                    input.VirtKey  = msg.message & 0xff; //虚拟吗
                    input.ScanCode = msg.paramL & 0xff;  //扫描码
                    StringBuilder strKeyName = new StringBuilder(225);
                    if (GetKeyNameText(input.ScanCode * 65536, strKeyName, 255) > 0)
                    {
                        input.KeyName = strKeyName.ToString().Trim(new char[] { ' ', '\0' });
                    }
                    else
                    {
                        input.KeyName = "";
                    }
                    byte[] kbArray = new byte[256];
                    uint   uKey    = 0;
                    GetKeyboardState(kbArray);


                    if (ToAscii(input.VirtKey, input.ScanCode, kbArray, ref uKey, 0))
                    {
                        input.Ascii = uKey;
                        input.Chr   = Convert.ToChar(uKey);
                    }

                    TimeSpan ts = DateTime.Now.Subtract(input.Time);

                    if (ts.TotalMilliseconds > 50)
                    {
                        //时间戳,大于50 毫秒表示手动输入
                        //strBarCode = barCode.Chr.ToString();
                        sbBarCode.Remove(0, sbBarCode.Length);
                        sbBarCode.Append(input.Chr.ToString());
                        input.OriginalChrs    = " " + Convert.ToString(input.Chr);
                        input.OriginalAsciis  = " " + Convert.ToString(input.Ascii);
                        input.OriginalBarCode = Convert.ToString(input.Chr);
                    }
                    else
                    {
                        sbBarCode.Append(input.Chr.ToString());
                        if ((msg.message & 0xff) == 13 && sbBarCode.Length > 3)
                        {                                         //回车
                         //barCode.BarCode = strBarCode;
                            input.Barcode = sbBarCode.ToString(); // barCode.OriginalBarCode;
                            input.IsValid = true;
                            sbBarCode.Remove(0, sbBarCode.Length);
                        }
                        //strBarCode += barCode.Chr.ToString();
                    }
                    input.Time = DateTime.Now;
                    try
                    {
                        if (InputEvent != null &&
                            input.IsValid
                            )
                        {
                            AsyncCallback callback = new AsyncCallback(AsyncBack);
                            //object obj;
                            Delegate[] delArray = InputEvent.GetInvocationList();
                            //foreach (Delegate del in delArray)
                            foreach (BardCodeDeletegate del in delArray)
                            {
                                try
                                {
                                    //方法1
                                    //obj = del.DynamicInvoke(barCode);
                                    //方法2
                                    del.BeginInvoke(input, callback, del);//异步调用防止界面卡死
                                }
                                catch (Exception ex)
                                {
                                    throw ex;
                                }
                            }
                            //BarCodeEvent(barCode);//触发事件
                            input.Barcode         = "";
                            input.OriginalChrs    = "";
                            input.OriginalAsciis  = "";
                            input.OriginalBarCode = "";
                        }
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                    finally
                    {
                        input.IsValid = false; //最后一定要 设置barCode无效
                        input.Time    = DateTime.Now;
                    }
                }
            }
            return(CallNextHookEx(hKeyboardHook, nCode, wParam, lParam));
        }
        private float CalculateBackgroundHeight(InputEvent evt)
        {
            int fieldCount = evt.eventType == InputEventType.Axis ? 3 : 4;
            int eventCount = evt.eventType == InputEventType.Axis ? evt.onAxis.GetPersistentEventCount() : evt.onAction.GetPersistentEventCount();
            float fieldHeight = 18.0f;
            float eventBorderHeight = 95.0f;
            float eventHeight = 43.0f;

            return fieldCount * fieldHeight + eventBorderHeight + Math.Max(eventCount - 1, 0) * eventHeight;
        }
Example #27
0
        public override void _Input(InputEvent inputEvent)
        {
            if (this.controls == ControlMethod.REMOTE)
            {
                return;                                            //Do not check for inputs for remote objects
            }
            //No actions if the game hasn't started yet
            if (Lobby.state == Lobby.GameState.IN_GAME_NOT_PLAYING)
            {
                return;
            }

            //Check for actions
            foreach (Action action in this.actions)
            {
                if (action.IsPossible(this, inputEvent))
                {
                    if (Lobby.role == Lobby.MultiplayerRole.OFFLINE)
                    {
                        action.Start(this);
                    }
                    else
                    {
                        RpcMaybeReliable(nameof(this.ActionStart), new object[] { this.actions.IndexOf(action) });
                    }
                    //Mark input as dealt with
                    GetTree().SetInputAsHandled();
                    return;
                }
            }

            //Check for up / down calls
            if (this.state == State.ATTACK || this.state == State.PARRY || this.state == State.TRANS)
            {
                return;
            }

            if (inputEvent.IsActionPressed(this.ACTION_UP))
            {
                if (this.state == State.HIGH)
                {
                    this.ChangeState(State.LAX);
                }
                else
                {
                    this.ChangeState(State.HIGH);
                }
                GetTree().SetInputAsHandled();
            }
            else if (inputEvent.IsActionPressed(this.ACTION_DOWN))
            {
                if (this.state == State.LOW)
                {
                    this.ChangeState(State.LAX);
                }
                else
                {
                    this.ChangeState(State.LOW);
                }
                GetTree().SetInputAsHandled();
            }
        }
Example #28
0
    private void _on_TextureRect_gui_input(InputEvent @event, ItemSlot clickedSlot)
    {
        if (@event is InputEventMouseButton button && button.ButtonIndex == 1 && button.Pressed)
        {
            // If currently holding an item
            if (holdingItem != null)
            {
                // If you clicked into a valid slot and the item isn't null
                if (clickedSlot?.Item != null)
                {
                    // Check to see if it is trying to go into an equipment slot.
                    if (clickedSlot.ItemTypes.Count <= 2)
                    {
                        // If the slot already has a valid piece of equipment in it,
                        // check if the item going into it is a valid piece of equipment.
                        // If it's not a valid piece of equipment, don't let it go in.
                        // If the currently held item is a valid piece of equipment,
                        // let it go into that slot.
                        if (clickedSlot.ItemTypes.Contains(holdingItem.Item.Type))
                        {
                            if (clickedSlot.Name != "RightRing")
                            {
                                EquipAndSwap(clickedSlot);
                            }
                            else
                            {
                                EquipAndSwap(clickedSlot, RingHand.Right);
                            }
                        }
                    }

                    // If not going into an equipment slot
                    // check to see if the item came from an equipment slot.
                    // If it came from an equipment slot, make sure the item
                    // attempting to be swapped with is a valid piece of equipment for that slot.
                    // If it's not, unequip it and drop it in the first available slot.
                    else if (holdingItem.Slot.ItemTypes.Count <= 2)
                    {
                        if (holdingItem.Slot.ItemTypes.Contains(clickedSlot.Item.Item.Type))
                        {
                            EquipAndSwap(clickedSlot);
                        }
                        else
                        {
                            UnEquipAndPut(FindFirstEmptySlot());
                        }
                    }
                    // If the item didn't come from an equipment slot, swap the items.
                    else
                    {
                        SwapItems(clickedSlot);
                    }
                }
                // If you clicked into a valid slot and there's nothing there
                else if (clickedSlot != null)
                {
                    if (clickedSlot.ItemTypes.Count <= 2)
                    {
                        // If the slot already has a valid piece of equipment in it,
                        // check if the item going into it is a valid piece of equipment.
                        // If it's not a valid piece of equipment, don't let it go in.
                        // If the currently held item is a valid piece of equipment,
                        // let it go into that slot.
                        if (clickedSlot.ItemTypes.Contains(holdingItem.Item.Type))
                        {
                            if (clickedSlot.Name != "RightRing")
                            {
                                EquipAndPut(clickedSlot);
                            }
                            else
                            {
                                EquipAndPut(clickedSlot, RingHand.Right);
                            }
                        }
                    }
                    else if (holdingItem.Slot.ItemTypes.Count <= 2)
                    {
                        UnEquipAndPut(clickedSlot);
                    }
                    else
                    {
                        PutItem(clickedSlot);
                    }
                }
            }
            else if (clickedSlot?.Item != null)
            {
                holdingItem = clickedSlot.Item;
                clickedSlot.PickItem();
                holdingItem.RectGlobalPosition = new Vector2(button.GlobalPosition.x, button.GlobalPosition.y);
            }
        }
    }
Example #29
0
 public override void _GuiInput(InputEvent @event)
 {
 }
Example #30
0
        void HandleButton(string button, bool newState)
        {
            bool isModifier = IgnoreKeys.Contains(button);

            if (EnableIgnoreModifiers && isModifier)
            {
                return;
            }
            if (LastState[button] && newState)
            {
                return;
            }
            if (!LastState[button] && !newState)
            {
                return;
            }

            //apply
            //NOTE: this is not quite right. if someone held leftshift+rightshift it would be broken. seems unlikely, though.
            if (button == "LeftShift")
            {
                _Modifiers &= ~ModifierKey.Shift;
                if (newState)
                {
                    _Modifiers |= ModifierKey.Shift;
                }
            }
            if (button == "RightShift")
            {
                _Modifiers &= ~ModifierKey.Shift; if (newState)
                {
                    _Modifiers |= ModifierKey.Shift;
                }
            }
            if (button == "LeftControl")
            {
                _Modifiers &= ~ModifierKey.Control; if (newState)
                {
                    _Modifiers |= ModifierKey.Control;
                }
            }
            if (button == "RightControl")
            {
                _Modifiers &= ~ModifierKey.Control; if (newState)
                {
                    _Modifiers |= ModifierKey.Control;
                }
            }
            if (button == "LeftAlt")
            {
                _Modifiers &= ~ModifierKey.Alt; if (newState)
                {
                    _Modifiers |= ModifierKey.Alt;
                }
            }
            if (button == "RightAlt")
            {
                _Modifiers &= ~ModifierKey.Alt; if (newState)
                {
                    _Modifiers |= ModifierKey.Alt;
                }
            }

            if (UnpressState.ContainsKey(button))
            {
                if (newState)
                {
                    return;
                }
                Console.WriteLine("Removing Unpress {0} with newState {1}", button, newState);
                UnpressState.Remove(button);
                LastState[button] = false;
                return;
            }


            //dont generate events for things like Ctrl+LeftControl
            ModifierKey mods = _Modifiers;

            if (button == "LeftShift")
            {
                mods &= ~ModifierKey.Shift;
            }
            if (button == "RightShift")
            {
                mods &= ~ModifierKey.Shift;
            }
            if (button == "LeftControl")
            {
                mods &= ~ModifierKey.Control;
            }
            if (button == "RightControl")
            {
                mods &= ~ModifierKey.Control;
            }
            if (button == "LeftAlt")
            {
                mods &= ~ModifierKey.Alt;
            }
            if (button == "RightAlt")
            {
                mods &= ~ModifierKey.Alt;
            }

            var ie = new InputEvent
            {
                EventType     = newState ? InputEventType.Press : InputEventType.Release,
                LogicalButton = new LogicalButton(button, mods)
            };

            LastState[button] = newState;

            //track the pressed events with modifiers that we send so that we can send corresponding unpresses with modifiers
            //this is an interesting idea, which we may need later, but not yet.
            //for example, you may see this series of events: press:ctrl+c, release:ctrl, release:c
            //but you might would rather have press:ctr+c, release:ctrl+c
            //this code relates the releases to the original presses.
            //UPDATE - this is necessary for the frame advance key, which has a special meaning when it gets stuck down
            //so, i am adding it as of 11-sep-2011
            if (newState)
            {
                ModifierState[button] = ie.LogicalButton;
            }
            else
            {
                if (ModifierState[button] != null)
                {
                    LogicalButton alreadyReleased = ie.LogicalButton;
                    var           ieModified      = new InputEvent
                    {
                        LogicalButton = (LogicalButton)ModifierState[button],
                        EventType     = InputEventType.Release
                    };
                    if (ieModified.LogicalButton != alreadyReleased)
                    {
                        _NewEvents.Add(ieModified);
                    }
                }
                ModifierState[button] = null;
            }

            _NewEvents.Add(ie);
        }
 void OnDisable()
 {
     InputEvent.RemoveListener(touchOrMouseListener);
 }
Example #32
0
    /// Handles inputs for moving the tetromino
    public override void _Input(InputEvent input)
    {
        if (Board.CurrentTetromino != null && !GameIsPaused && !GameIsOver)
        {
            if (input.IsActionPressed("move_left"))
            {
                RemainingShiftDelay = AUTO_SHIFT_DELAY;
                AutoShiftDirection  = Vector2Int.Left;
                if (Board.CurrentTetromino.Translate(Vector2Int.Left))
                {
                    ResetLockDelay();
                }
            }
            if (input.IsActionPressed("move_right"))
            {
                RemainingShiftDelay = AUTO_SHIFT_DELAY;
                AutoShiftDirection  = Vector2Int.Right;
                if (Board.CurrentTetromino.Translate(Vector2Int.Right))
                {
                    ResetLockDelay();
                }
            }
            if (input.IsActionReleased("move_left"))
            {
                RemainingShiftDelay = AUTO_SHIFT_DELAY;
                if (Input.IsActionPressed("move_right"))
                {
                    AutoShiftDirection = Vector2Int.Right;
                }
                else
                {
                    AutoShiftDirection = Vector2Int.Zero;
                }
            }
            if (input.IsActionReleased("move_right"))
            {
                RemainingShiftDelay = AUTO_SHIFT_DELAY;
                if (Input.IsActionPressed("move_left"))
                {
                    AutoShiftDirection = Vector2Int.Left;
                }
                else
                {
                    AutoShiftDirection = Vector2Int.Zero;
                }
            }

            if (input.IsActionPressed("rotate_left"))
            {
                if (Board.CurrentTetromino.Rotate(Rotation.Left))
                {
                    ResetLockDelay();
                }
            }
            else if (input.IsActionPressed("rotate_right"))
            {
                if (Board.CurrentTetromino.Rotate(Rotation.Right))
                {
                    ResetLockDelay();
                }
            }
            if (input.IsActionPressed("hard_drop"))
            {
                Score += Math.Abs(2 * Board.CurrentTetromino.HardDrop().y);
                LockPiece(Board.CurrentTetromino);
                Board.CurrentTetromino = null;
            }
            if (input.IsActionPressed("swap"))
            {
                Board.Swap();
                Tetromino piece = Board.FrozenTetromino;
                if (piece != null)
                {
                    HashSet <int> modifiedRows = new HashSet <int>();
                    foreach (Vector2Int relativeMinoPos in piece.MinoTiles)
                    {
                        Vector2Int minoPosition = piece.Position + relativeMinoPos;
                        modifiedRows.Add(minoPosition.y);
                    }
                    CheckLineClears(modifiedRows);
                }
            }
        }
        if (input.IsActionPressed("soft_drop"))
        {
            SoftDropping = true;
        }
        if (input.IsActionReleased("soft_drop"))
        {
            SoftDropping = false;
        }
    }
Example #33
0
 /// <summary>
 /// Called by Canvas. Do not call directly.
 /// </summary>
 public override void OnKey(InputEvent e)
 {
     if (!_submitDesired)
     {
         if (e.KeyPressed(KeyId.Enter))
         {
             SetCursor(true);
             _submitDesired = true;
         }
         return;
     }
     if (e.KeyPressed(KeyId.Escape))
     {
         _text.Content = _contentBackup;
         PositionContent(true);
         SetCursor(false);
         _submitDesired = false;
     }
     else if (e.KeyPressed(KeyId.Home))
     {
         _cursorIndex = 0;
         SetCursor(true);
         PositionContent();
     }
     else if (e.KeyPressed(KeyId.End))
     {
         _cursorIndex = _text.Content.Length;
         SetCursor(true);
         PositionContent();
     }
     else if (e.KeyPressed(KeyId.Delete))
     {
         if (_cursorIndex < _text.Content.Length)
         {
             _text.Content = _text.Content.Substring(0, _cursorIndex) + _text.Content.Substring(_cursorIndex + 1);
         }
         SetCursor(true);
     }
     else if (e.KeyPressed(KeyId.Enter) || e.KeyPressed(KeyId.XI_A))
     {
         if (TrySubmit())
         {
             SetCursor(false);
             _contentBackup = _text.Content;
         }
     }
     else if (e.KeyPressed(KeyId.Backspace))
     {
         if (_cursorIndex > 0)
         {
             _text.Content = _text.Content.Substring(0, _cursorIndex - 1) + _text.Content.Substring(_cursorIndex);
             SetCursor(true);
             _cursorIndex--;
         }
         PositionContent(true);
     }
     else if (e.KeyPressed(KeyId.Left))
     {
         _cursorIndex = Math.Max(0, _cursorIndex - 1);
         SetCursor(true);
         PositionContent();
     }
     else if (e.KeyPressed(KeyId.Right))
     {
         _cursorIndex = Math.Min(_text.Content.Length, _cursorIndex + 1);
         SetCursor(true);
         PositionContent();
     }
     else if (e.State == InputState.Pressed)
     {
         _text.Content = _text.Content.Insert(_cursorIndex, e.KeyName);
         _cursorIndex += e.KeyName.Length;
         SetCursor(true);
         PositionContent(true);
     }
 }
Example #34
0
 private void SendTapUpMessage( InputEvent inputEvent )
 {
     DoSendMessage( "OnTapUp", inputEvent );
 }
Example #35
0
        // Pre-initiates all the required things in the game
        private void reqPreInit()
        {
            gdm=	new GraphicsDeviceManager(this);
            cameras=	new SelectionList<Camera>(new Camera(this));
            views=	new SelectionList<Viewport>();
            states=	new GameStateManager(this);
            registry=	new Registry();
            gui=	new GuiManager();

            clearColor=	getColor("royalblue");
            IsMouseVisible=	true;
            updateEvent=	delegate(GameTime time)	{};
            drawEvent=	delegate(GameTime time)	{};
            inputEvent=	delegate(InputArgs args)	{};

            effects=	new HashTable<Effect>(8);
            textures=	new HashTable<Texture2D>(8);
            fonts=	new HashTable<SpriteFont>(8);
            videos=	new HashTable<Video>(8);
            sounds=	new HashTable<SoundEffect>(8);
            songs=	new HashTable<Song>(8);
            models=	new HashTable<Model>(8);

            lastScrollData=	0;
            lastMousePosition=	Mouse.GetState().Position;
        }
Example #36
0
        public override void _GuiInput(InputEvent @event)
        {
            if (@event is InputEventMouseMotion eventMouseMotion)
            {
                /**
                 * we only want this to happen when the player is hovering over the inventory grid
                 * which is what _GuiInput implicitly does
                 */
                if (((App.Inventory.InventoryDragOverlay)GetNode("/root/InventoryDragOverlay")).hasPickedUpItem())
                {
                    var relativeMousePosition = eventMouseMotion.Position;
                    var targetCellPosition    = this.localToCellPosition(relativeMousePosition);
                    var item = ((App.Inventory.InventoryDragOverlay)GetNode("/root/InventoryDragOverlay")).getPickedUpItem();

                    this.dropzoneIndicator = new Rect2(this.cellPositionToLocal(targetCellPosition), item.getInventoryNode().GetCustomMinimumSize());
                    // this.AcceptEvent();
                }
                else
                {
                    if (this.dropzoneIndicator != null)
                    {
                        this.dropzoneIndicator = null;
                    }
                }

                /**
                 * when the mouse is moved while the user has something picked up then we will want to redraw the inventorybag UI
                 */
                if (((App.Inventory.InventoryDragOverlay)GetNode("/root/InventoryDragOverlay")).hasPickedUpItem())
                {
                    //this.AcceptEvent(); //handled in _GuiInput instead
                    this.Update();
                }
            }

            if (@event is InputEventMouseButton eventMouseButton)
            {
                if (eventMouseButton.ButtonIndex == 1)
                {
                    if (eventMouseButton.Pressed)
                    {
                        if (((App.Inventory.InventoryDragOverlay)GetNode("/root/InventoryDragOverlay")).hasPickedUpItem())
                        {
                            //if (!((App.Inventory.InventoryDragOverlay)GetNode("/root/InventoryDragOverlay")).justPickedUpItem) {

                            /**
                             * place the item down
                             */
                            this.AcceptEvent();
                            GD.Print("place the item down");
                            var item = ((App.Inventory.InventoryDragOverlay)GetNode("/root/InventoryDragOverlay")).getPickedUpItem();
                            ((App.Inventory.InventoryDragOverlay)GetNode("/root/InventoryDragOverlay")).setPickedUpItem(null);
                            this.addItem(item, this.localToCellPosition(this.GetLocalMousePosition()));
                            this.dropzoneIndicator = null;
                            this.Update();
                            //}
                        }
                    }
                }
            }
        }
Example #37
0
 public void OnDoubleTap( InputEvent inputEvent )
 {
     print( "Double tap: " + inputEvent );
 }
Example #38
0
 public InputMessageSpecialInputDevice(InputEvent inputEvent)
 {
     this.inputEvent = inputEvent;
 }
Example #39
0
 public abstract void HandleInput(InputEvent inputEvent);
        public override void OnButtonUpEvent(InputEvent evt)
        {

        }
Example #41
0
 protected abstract void ProcessKey(InputEvent e);
        public static void TimeField(SerializedProperty property, GUIContent label, bool readOnly, double frameRate, double minValue, double maxValue, ref InputEvent inputEvent)
        {
            var rect = EditorGUILayout.GetControlRect();

            TimeField(rect, property, label, readOnly, frameRate, minValue, maxValue, ref inputEvent);
        }
Example #43
0
 public override void _Input(InputEvent inputEvent)
 {
     HandlePauseInput(inputEvent);
 }
Example #44
0
 public override void UnhandledInput(InputEvent @event)
 {
 }
Example #45
0
 public virtual void HandleInput(InputEvent @event)
 {
 }
Example #46
0
 public ChatNextChannel(int id, string label, InputEvent eventMask) : base(id, label, eventMask, false)
 {
 }
        // Display Time related properties in frames and seconds
        public static void TimeField(Rect rect, SerializedProperty property, GUIContent label, bool readOnly, double frameRate, double minValue, double maxValue, ref InputEvent inputEvent)
        {
            GUIContent title = EditorGUI.BeginProperty(rect, label, property);

            rect = EditorGUI.PrefixLabel(rect, title);

            int   indentLevel = EditorGUI.indentLevel;
            float labelWidth  = EditorGUIUtility.labelWidth;

            EditorGUI.indentLevel       = 0;
            EditorGUIUtility.labelWidth = (int)EditorGUI.kMiniLabelW;
            using (new GUIMixedValueScope(property.hasMultipleDifferentValues))
            {
                var secondsRect = new Rect(rect.xMin, rect.yMin, rect.width / 2 - EditorGUI.kSpacingSubLabel, rect.height);
                var framesRect  = new Rect(rect.xMin + rect.width / 2, rect.yMin, rect.width / 2, rect.height);

                if (readOnly)
                {
                    EditorGUI.FloatField(secondsRect, Styles.SecondsPrefix, (float)property.doubleValue, EditorStyles.label);
                }
                else
                {
                    EditorGUI.BeginChangeCheck();
                    DelayedAndDraggableDoubleField(secondsRect, Styles.SecondsPrefix, property, ref inputEvent);
                    if (EditorGUI.EndChangeCheck())
                    {
                        property.doubleValue = Clamp(property.doubleValue, minValue, maxValue);
                    }
                }

                if (frameRate > TimeUtility.kTimeEpsilon)
                {
                    EditorGUI.BeginChangeCheck();

                    double time        = property.doubleValue;
                    int    frames      = TimeUtility.ToFrames(time, frameRate);
                    double exactFrames = TimeUtility.ToExactFrames(time, frameRate);
                    bool   useIntField = TimeUtility.OnFrameBoundary(time, frameRate);

                    if (readOnly)
                    {
                        if (useIntField)
                        {
                            EditorGUI.IntField(framesRect, Styles.FramesPrefix, frames, EditorStyles.label);
                        }
                        else
                        {
                            EditorGUI.DoubleField(framesRect, Styles.FramesPrefix, exactFrames, EditorStyles.label);
                        }
                    }
                    else
                    {
                        if (useIntField)
                        {
                            int newFrames = DelayedAndDraggableIntField(framesRect, Styles.FramesPrefix, frames, ref inputEvent);
                            time = Math.Max(0, TimeUtility.FromFrames(newFrames, frameRate));
                        }
                        else
                        {
                            double newExactFrames = DelayedAndDraggableDoubleField(framesRect, Styles.FramesPrefix, exactFrames, ref inputEvent);
                            time = Math.Max(0, TimeUtility.FromFrames((int)Math.Floor(newExactFrames), frameRate));
                        }
                    }

                    if (EditorGUI.EndChangeCheck())
                    {
                        property.doubleValue = Clamp(time, minValue, maxValue);
                    }
                }

                EditorGUI.indentLevel       = indentLevel;
                EditorGUIUtility.labelWidth = labelWidth;
                EditorGUI.EndProperty();
            }
        }
Example #48
0
 private static void Test(object __instance, InputEvent ev)
 {
     Info(__instance.GetType(), ev.InputType, ev.Name);
 }
Example #49
0
 private void SendTapDownMessage( InputEvent inputEvent )
 {
     DoSendMessage( "OnTapDown", inputEvent );
 }
Example #50
0
 public ChatMoveCursorEnd(int id, string label, InputEvent eventMask) : base(id, label, eventMask, false)
 {
 }
        static void DelayedAndDraggableDoubleField(Rect rect, GUIContent label, SerializedProperty property, ref InputEvent inputEvent)
        {
            EditorGUI.BeginChangeCheck();
            var newValue = DelayedAndDraggableDoubleField(rect, label, property.doubleValue, ref inputEvent);

            if (EditorGUI.EndChangeCheck())
            {
                property.doubleValue = newValue;
            }
        }
Example #52
0
 private static bool ShouldSwallow(AllowInput allowInput, InputEvent inputEvent)
 {
     return(allowInput == AllowInput.None || (allowInput == AllowInput.OnlyController && inputEvent.Source != InputFocus.Pad));
 }
        internal static double DelayedAndDraggableDoubleField(GUIContent label, double value, ref InputEvent action, double dragSensitivity)
        {
            var r = EditorGUILayout.s_LastRect = EditorGUILayout.GetControlRect(false, EditorGUI.kSingleLineHeight);

            return(DelayedAndDraggableDoubleField(r, label, value, ref action, dragSensitivity));
        }
Example #54
0
        void HandleButton(string button, bool newState, InputFocus source)
        {
            ModifierKey currentModifier = ButtonToModifierKey(button);

            if (EnableIgnoreModifiers && currentModifier != ModifierKey.None)
            {
                return;
            }
            if (LastState[button] == newState)
            {
                return;
            }

            //apply
            //NOTE: this is not quite right. if someone held leftshift+rightshift it would be broken. seems unlikely, though.
            if (currentModifier != ModifierKey.None)
            {
                if (newState)
                {
                    _Modifiers |= currentModifier;
                }
                else
                {
                    _Modifiers &= ~currentModifier;
                }
            }

            //dont generate events for things like Ctrl+LeftControl
            ModifierKey mods = _Modifiers;

            if (currentModifier != ModifierKey.None)
            {
                mods &= ~currentModifier;
            }

            var ie = new InputEvent
            {
                EventType     = newState ? InputEventType.Press : InputEventType.Release,
                LogicalButton = new LogicalButton(button, mods),
                Source        = source
            };

            LastState[button] = newState;

            //track the pressed events with modifiers that we send so that we can send corresponding unpresses with modifiers
            //this is an interesting idea, which we may need later, but not yet.
            //for example, you may see this series of events: press:ctrl+c, release:ctrl, release:c
            //but you might would rather have press:ctrl+c, release:ctrl+c
            //this code relates the releases to the original presses.
            //UPDATE - this is necessary for the frame advance key, which has a special meaning when it gets stuck down
            //so, i am adding it as of 11-sep-2011
            if (newState)
            {
                ModifierState[button] = ie.LogicalButton;
            }
            else
            {
                LogicalButton buttonModifierState;
                if (ModifierState.TryGetValue(button, out buttonModifierState))
                {
                    if (buttonModifierState != ie.LogicalButton && !IgnoreEventsNextPoll)
                    {
                        _NewEvents.Add(
                            new InputEvent
                        {
                            LogicalButton = buttonModifierState,
                            EventType     = InputEventType.Release,
                            Source        = source
                        });
                    }
                    ModifierState.Remove(button);
                }
            }

            if (!IgnoreEventsNextPoll)
            {
                _NewEvents.Add(ie);
            }
        }
Example #55
0
 public void OnSingleTap( InputEvent inputEvent )
 {
     print( "Single tap: " + inputEvent );
 }
Example #56
0
    // Update is called once per frame
    void Update()
    {
        play_audio();

        //Check if we are running either in the Unity editor or in a standalone build.
                #if UNITY_STANDALONE || UNITY_WEBPLAYER
        if (eh.isActivate())
        {
            InputEvent ie = eh.getEventData();
            switch (ie.keycode)
            {
            //Get input from the input manager, round it to an integer and store in horizontal to set x axis move direction
            case KeyCode.RightArrow:
                if (!at_confirm)
                {
                    GameMode.instance.gamemode = GameMode.Game_Mode.CONTINUE;
                    SoundManager.instance.PlayVoice(Database.instance.MainPreContinueGame, true);
                    SceneManager.LoadScene("Main");
                }
                //SoundManager.instance.PlaySingle(swipeRight);
                break;

            case KeyCode.LeftArrow:
                if (at_confirm)
                {
                    GameMode.instance.gamemode = GameMode.Game_Mode.MAIN;
                    SoundManager.instance.PlayVoice(Database.instance.MainPreNewGame, true);
                    SceneManager.LoadScene("Main");
                }
                //SoundManager.instance.PlaySingle(swipeLeft);
                break;

            case KeyCode.E:
                if (!at_confirm)
                {
                    at_confirm  = true;
                    cur_clip    = 0;
                    reset_audio = true;
                }
                else
                {
                    at_confirm  = false;
                    cur_clip    = 0;
                    reset_audio = true;
                }
                //SoundManager.instance.PlaySingle(swipeAhead);
                break;

            default:
                break;
            }
        }

        /*
         * //Get input from the input manager, round it to an integer and store in horizontal to set x axis move direction
         * if (Input.GetKeyUp(KeyCode.RightArrow)) {
         *      if(!at_confirm){
         *              GameMode.instance.gamemode = GameMode.Game_Mode.CONTINUE;
         *              SoundManager.instance.PlayVoice(continue_game, true);
         *              SceneManager.LoadScene("Main");
         *      }
         *      //SoundManager.instance.PlaySingle(swipeRight);
         * } else if (Input.GetKeyUp(KeyCode.LeftArrow)) {
         *      if(at_confirm){
         *              GameMode.instance.gamemode = GameMode.Game_Mode.MAIN;
         *              SoundManager.instance.PlayVoice(new_game, true);
         *              SceneManager.LoadScene("Main");
         *      }
         *      //SoundManager.instance.PlaySingle(swipeLeft);
         * } else if (Input.GetKeyUp("f")) {
         *      //SceneManager.LoadScene("Main");
         *      //SoundManager.instance.PlaySingle(swipeAhead);
         * } else if (Input.GetKeyUp("e")) {
         *      if(!at_confirm){
         *              at_confirm = true;
         *              cur_clip = 0;
         *              reset_audio = true;
         *      }
         *      else{
         *              at_confirm = false;
         *              cur_clip = 0;
         *              reset_audio = true;
         *      }
         *      //SoundManager.instance.PlaySingle(swipeAhead);
         * }
         */

        //Check if we are running on iOS, Android, Windows Phone 8 or Unity iPhone
                #elif UNITY_IOS || UNITY_ANDROID || UNITY_WP8 || UNITY_IPHONE
        Screen.sleepTimeout = SleepTimeout.NeverSleep;

        if (eh.isActivate())
        {
            InputEvent ie = eh.getEventData();

            if ((ie.touchNum == 1) && (!ie.isRotate))
            {
                if (ie.isRight)
                {
                    if (!at_confirm)
                    {
                        SoundManager.instance.PlaySingle(Database.instance.inputSFX);
                        GameMode.instance.gamemode = GameMode.Game_Mode.CONTINUE;
                        SceneManager.LoadScene("Main");
                        SoundManager.instance.PlayVoice(Database.instance.MainPreContinueGame, true);
                    }
                }
                else if (ie.isLeft)
                {
                    if (!at_confirm)
                    {
                        //nothing
                    }
                    else                      //at_confirm
                    {
                        at_confirm = false;
                        SoundManager.instance.PlaySingle(Database.instance.inputSFX);
                        GameMode.instance.gamemode = GameMode.Game_Mode.MAIN;
                        Utilities.write_save(0);
                        SceneManager.LoadScene("Main");
                        SoundManager.instance.PlayVoice(Database.instance.MainPreNewGame, true);
                    }
                }
            }
            else if ((ie.cumulativeTouchNum >= 2) && (!ie.hasDir()))
            {
                if (!at_confirm && TriggerStartNewGame.CDfinish())
                {
                    cur_clip    = 0;
                    reset_audio = true;
                    at_confirm  = true;
                    SoundManager.instance.PlaySingle(Database.instance.inputSFX);
                    TriggerStartNewGame.reset();
                }
                else if (TriggerStartNewGame.CDfinish())                  //at_confirm
                {
                    cur_clip    = 0;
                    reset_audio = true;
                    at_confirm  = false;
                    SoundManager.instance.PlaySingle(Database.instance.inputSFX);
                    TriggerStartNewGame.reset();
                }
            }
        }
                #endif //End of mobile platform dependendent compilation section started above with #elif
    }
Example #57
0
 public ChatDeletePrev(int id, string label, InputEvent eventMask) : base(id, label, eventMask, false)
 {
 }
Example #58
0
File: Dock.cs Project: g3gg0/rx-fft
 public virtual bool ProcessUserEvent(InputEvent evt)
 {
     return(false);
 }
        public override void OnMouseMoveEvent(InputEvent evt)
        {

        }
        static int DelayedAndDraggableIntField(Rect rect, GUIContent label, int value, ref InputEvent inputEvent, long dragSensitivity)
        {
            var id        = GUIUtility.GetControlID(FocusType.Keyboard);
            var fieldRect = EditorGUI.PrefixLabel(rect, id, label);

            rect.xMax = fieldRect.x;

            double dummy    = 0.0;
            long   refValue = value;

            inputEvent |= InputEventType(rect, id);

            EditorGUI.DragNumberValue(rect, id, false, ref dummy, ref refValue, dragSensitivity);

            EditorGUI.BeginChangeCheck();
            var result = EditorGUI.DelayedIntFieldInternal(fieldRect, GUIContent.none, (int)refValue, EditorStyles.numberField);

            if (EditorGUI.EndChangeCheck())
            {
                inputEvent |= InputEvent.KeyboardInput;
            }

            return(result);
        }