Exemplo n.º 1
0
 void Awake()
 {
     inControl   = true;
     canMove     = true;
     mouseTarget = new MouseTarget();
     target      = new Vector3();
 }
Exemplo n.º 2
0
        private void AddMouseAction(MouseChord chord, MouseTarget target)
        {
            MouseChord button = chord & ~(MouseChord.Alt | MouseChord.Ctrl | MouseChord.Shift);

            if (!MouseTargetButtons[target].Contains(button))
            {
                var dict = QTUtility.TextResourcesDic["Options_Page07_Mouse"];
                MessageBox.Show(
                    dict[18] + Environment.NewLine +
                    dict[19] + Environment.NewLine +
                    MouseTargetButtons[target].Select(k => "  " + dict[MouseButtonResx[k]])
                    .StringJoin(Environment.NewLine),
                    dict[20], MessageBoxButton.OK, MessageBoxImage.Hand);
                return;
            }
            MouseEntry entry = MouseBindings.FirstOrDefault(e => e.Chord == chord && e.Target == target);

            if (entry == null)
            {
                entry = new MouseEntry(target, chord, BindAction.Nothing);
                MouseBindings.Add(entry);
            }
            entry.IsSelected = true;
            lvwMouseBindings.UpdateLayout();
            lvwMouseBindings.ScrollIntoView(entry);
            // Need to wait for ScrollIntoView to finish, or the dropdown will open in the wrong place.
            Dispatcher.BeginInvoke(DispatcherPriority.Input, new Action(() => { entry.IsEditing = true; }));
        }
Exemplo n.º 3
0
 private void InitializeComponents()
 {
     cast        = GetComponent <Cast>();
     mover       = GetComponent <RootMover>();
     target      = GameObject.FindWithTag(Tags.GameController).GetComponent <Target>();
     mouseTarget = GameObject.FindWithTag(Tags.GameController).GetComponent <MouseTarget>();
     animator    = transform.root.GetComponentInChildren <Animator>();
 }
Exemplo n.º 4
0
 private void Click(object sender, MouseButtonEventArgs e)
 {
     if (e.Button == MouseButton.Left)
     {
         target = new MouseTarget(camera, map);
         timer.Restart();
         HandleTarget();
     }
 }
Exemplo n.º 5
0
        private void rctAddMouseAction_MouseDown(object sender, MouseButtonEventArgs e)
        {
            FrameworkElement control = ((FrameworkElement)sender);
            MouseChord       chord   = MouseChord.None;

            if ((Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift)
            {
                chord |= MouseChord.Shift;
            }
            if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
            {
                chord |= MouseChord.Ctrl;
            }
            if ((Keyboard.Modifiers & ModifierKeys.Alt) == ModifierKeys.Alt)
            {
                chord |= MouseChord.Alt;
            }
            // ugh.  wish there was a better way to do this, but I don't think there is one...
            MouseTarget target = MouseTargetResx.First(kv => kv.Value == (int)control.Tag).Key;

            // watch out for double clicks
            if (e.ChangedButton == MouseButton.Left)
            {
                if (mouseTimer == null || mouseTimer.Tag != control.Tag)
                {
                    mouseTimer = new DispatcherTimer {
                        Tag      = control.Tag,
                        Interval = TimeSpan.FromMilliseconds(
                            System.Windows.Forms.SystemInformation.DoubleClickTime)
                    };
                    mouseTimer.Tick += (sender2, e2) => {
                        mouseTimer.IsEnabled = false;
                        mouseTimer           = null;
                        chord |= MouseChord.Left;
                        AddMouseAction(chord, target);
                    };
                    mouseTimer.IsEnabled = true;
                }
                else
                {
                    mouseTimer.IsEnabled = false;
                    mouseTimer           = null;
                    chord |= MouseChord.Double;
                    AddMouseAction(chord, target);
                }
            }
            else
            {
                if (mouseTimer != null)
                {
                    mouseTimer.IsEnabled = false;
                    mouseTimer           = null;
                }
                chord |= MouseButtonMappings[e.ChangedButton];
                AddMouseAction(chord, target);
            }
        }
Exemplo n.º 6
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButton(0))
        {
            CurrentSpeed = Speed;

            Vector3 MouseHit = MouseTarget.GetWorldMousePos();

            MovePosition = MouseHit;

            Direction += MouseHit - transform.position;

            Direction.Normalize();

            //Player Rotations
            if (Vector3.Dot(transform.right, Direction) < 0.0f)
            {
                transform.Rotate(0.0f, -Vector3.Angle(transform.forward, Direction) * TurnRate, 0.0f);
            }
            if (Vector3.Dot(transform.right, Direction) > 0.0f)
            {
                transform.Rotate(0.0f, Vector3.Angle(transform.forward, Direction) * TurnRate, 0.0f);
            }
            //Move the player forward
            if (!Input.GetKey(KeyCode.LeftShift))
            {
                Animator.SetBool("Moving", true);
                if (Mathf.Abs(Vector3.Distance(transform.position, MouseHit)) > Deadzone)
                {
                    Rigid.MovePosition(transform.position + transform.forward * CurrentSpeed * Time.deltaTime);
                }
                DoMove = true;
            }
            //Stop the player when they press shift
            else
            {
                Animator.SetBool("Moving", false);
                MovePosition = transform.position;
            }
        }

        //Continue to move the player forward after mouse click
        if (Vector3.Distance(transform.position, MovePosition) > Deadzone && DoMove)
        {
            Direction += MovePosition - transform.position;

            Direction.Normalize();
            Rigid.MovePosition(transform.position + Direction * CurrentSpeed * Time.deltaTime);
        }
        else
        {
            Animator.SetBool("Moving", false);
            DoMove = false;
        }
        Debug.DrawLine(transform.position, MovePosition, Color.red);
    }
Exemplo n.º 7
0
    public override void OnPlayerCommand(MouseTarget _mouseTarget)
    {
        // Do what you need with the mouse target..

        /*
         *      Debug.Log ("Name to Layer: " + LayerMask.NameToLayer ("EnemyUnit"));
         *      Debug.Log ("Layer to Name: " + LayerMask.LayerToName (13));
         *
         *      if (MouseController.Instance.IsMouseOverLayer (LayerMask.NameToLayer ("EnemyUnit"))) {
         *              Debug.Log ("Attack the enemy!");
         *      }*/

        //string currentLayer = LayerMask.LayerToName (_mousearget.gameObject.layer);//MouseController.Instance.GetCurrentMouseOverLayerName ();
        //Debug.Log ("RIGHT CLICK TARGET IS: " + _target);
        playerSelectedTarget = _mouseTarget;

        switch (_mouseTarget.currentTargetType)
        {
        case TargetType.EnemyUnit:
            //playerSelectedTarget = _mouseTarget;
            UpdateTarget(null);
            //Debug.Log ("Hostile detected!");
            break;

        case TargetType.Walkable:
            //playerSelectedTarget = null;
            UpdateTarget(playerSelectedTarget.transform);
            //Debug.Log ("Move to position!");
            break;
        }

        /*switch (currentLayer) {
         * case "EnemyUnit":
         *      //canMove = false;
         *      //animationComponent.StopMovement ();
         *      //DisableSearch ();
         *      _target.tag = "RightClickTarget";
         *      attackModule.PlayerSelectedTarget = _target;
         *      break;
         * default:
         *      // Threat target from mouse event removed. If 'attackNearbyEnemies' is set, threatTarget is automatically updated for nearby enemies.
         *      //NOTE: This does not remove target from being reassigned as a nearby enemy. This is expected behavior.
         *      // Also note that setting the property to null does not affect targets added from RangedBounds. Only rightClickedTargets are removed.
         *      attackModule.PlayerSelectedTarget = null;
         *      break;
         * }
         */
        //throw new System.NotImplementedException ();
    }
Exemplo n.º 8
0
    //moves the indicator, aligned with the player
    void AlignIndicator()
    {
        //get position of mouse
        //mouseTarget.GetWorldMousePos();
        //set indicator to position of mouse
        transform.position = MouseTarget.GetWorldMousePos();
        //align rotation using direction from player
        Vector3    directionToFire   = MouseTarget.GetWorldMousePos() - player.transform.position;
        Quaternion rotationDirection = new Quaternion();

        rotationDirection   = Quaternion.LookRotation(directionToFire);
        rotationDirection.x = 0.0f;
        rotationDirection.z = 0.0f;
        transform.rotation  = rotationDirection;
    }
 //use spell four - lift and drop
 void UseGravityDrop()
 {
     player = PlayerManager.GetPlayer();
     if (player.GetComponent <ResourceManagement>().GetMana() >= GravityLift.GetComponent <GravityLiftSpell>().resourceCost)
     {
         player.GetComponent <ResourceManagement>().DamageMana(GravityLift.GetComponent <GravityLiftSpell>().resourceCost);
         player.GetComponent <PlayerMovement>().StopMovement();
         player.GetComponent <PlayerMovement>().FacePosition(transform.position);
         player.GetComponent <Animator>().SetTrigger("Attack");
         //create spell and fire it
         GameObject spellClone = GravityLift;
         //spawn into the world
         Instantiate(spellClone, MouseTarget.GetWorldMousePos(), Quaternion.identity);
     }
 }
Exemplo n.º 10
0
    // Update is called once per frame
    void Update()
    {
        if (TrackFloorOnly)
        {
            transform.position = MouseTarget.GetWorldMousePos();
        }
        else
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            RaycastHit hit;
            Physics.Raycast(ray, out hit, Mathf.Infinity);

            transform.position = hit.point;
        }
    }
Exemplo n.º 11
0
    // Update is called once per frame
    void Update()
    {
        curSpawnCoolDown -= Time.deltaTime;
        // some interval of time passed?
        if (curSpawnCoolDown <= 0)
        {
            curSpawnCoolDown = SPAWN_COOLDOWN;
            // Choose 1 random index i in spawns
            int i = Random.Range(0, spawns.Length);


            int count = 0;
            while (count != mouses.Length && mouses[i] != null)
            {
                i = (i + 1) % mouses.Length;
                count++;
            }

            if (mouses[i] == null)
            {
                //Debug.Log("Spawn occurred " + i);
                GameObject spawn = spawns[i];
                // Instantiate mouse object at spawns[i].transform.position
                mouses[i] = Instantiate(mouse, spawn.transform.position, Quaternion.identity);
            }
            else
            {
                //Debug.Log("full");
            }

            for (int j = 0; j < mouses.Length; j++)
            {
                MouseTarget mt = mouses[j];
                if (mt != null && mt.LifeSpan <= 0)
                {
                    Destroy(mt.gameObject);
                    //Destroy(mt);
                    //Debug.Log("destroyed: " + j);
                    mouses[j] = null;
                }
            }
        }
    }
    //fire basic shot in the direction of the mouse in world
    void FireBasicShot()
    {
        //get the direction of mouse from self
        //mouseTarget.GetWorldMousePos();
        Vector3    directionToFire   = MouseTarget.GetWorldMousePos() - transform.position;
        Quaternion rotationDirection = new Quaternion();

        rotationDirection = Quaternion.LookRotation(directionToFire);
        //rotationDirection.eulerAngles = directionToFire;
        player = PlayerManager.GetPlayer();
        player.GetComponent <ResourceManagement>().DamageMana(1f);
        player.GetComponent <PlayerMovement>().StopMovement();
        player.GetComponent <PlayerMovement>().FacePosition(transform.position + directionToFire);
        player.GetComponent <Animator>().SetTrigger("Attack");

        //create a shot and fire it
        GameObject bulletClone = basicBullet;

        Instantiate(bulletClone, transform.position + new Vector3(0f, 0.5f, 0f), rotationDirection);

        //play firing sound effect
        basicBulletFireSound.Play();
    }
Exemplo n.º 13
0
        private void OnMouseMove(Event e)
        {
#if DEBUG
            if (DebugMode)
            {
                Debug.Log("MouseEventDispatcher.OnMouseMove");
            }
#endif
            _mouseEvent = (MouseEvent)e;

            _pos  = _mouseEvent.GlobalPosition;
            _size = SystemManager.Instance.ScreenSize;

            if (_pos.X < 0 || _pos.Y < 0 || _pos.X > _size.X || _pos.Y > _size.Y)
            {
                if (!_isMouseLeave)
                {
                    /**
                     * 1) InvalidateDrawingList the event
                     * */
                    _mouseLeaveEvent = new MouseEvent(MouseEvent.MOUSE_LEAVE)
                    {
                        Target         = this,
                        GlobalPosition = _pos
                    };
                }
                _isMouseLeave = true;
            }
            else
            {
                _isMouseLeave = false;
            }

            //Debug.Log("..... will recalculate ..... ");

            /**
             * 1) Find (any) component under under mouse
             * */
            RecalculateMouseTarget();

            //RecalculateMouseWheelTargets();

            //Debug.Log("InspectMode: " + InspectMode);

            /**
             * 2) Handle inspector target under mouse
             * */
            if (PlayModeInspect || InspectMode)
            {
                RecalculateInspectorTarget();
            }

            if (null != MouseTarget)
            {
#if DEBUG
                if (DebugMode)
                {
                    Debug.Log("OnMouseMove component: " + MouseTarget);
                }
#endif
                MouseEventHelper.BuildAndDispatchMouseEvent(this, MouseTarget, MouseEvent.MOUSE_MOVE,
                                                            _mouseEvent.GlobalPosition, _mouseEvent.CurrentEvent);
            }

            if (MouseTarget != _previousMouseOveredComponent || _isMouseLeave)
            {
                if (null != _previousMouseOveredComponent)
                {
                    MouseEventHelper.BuildAndDispatchMouseEvent(this, _previousMouseOveredComponent,
                                                                MouseEvent.MOUSE_OUT, _mouseEvent.GlobalPosition, _mouseEvent.CurrentEvent);
                    //Debug.Log("MOUSE_OUT: " + _previousMouseOveredComponent);
                    _hasBeenMouseOut = true;

                    string cursorStyle = (string)_previousMouseOveredComponent.GetStyle("cursor");
                    if (!string.IsNullOrEmpty(cursorStyle))
                    {
                        CursorManager.Instance.RemoveCursor(_currentCursorId);
                    }
                }

                if (MouseTarget != null)
                {
                    /**
                     * MOUSE OVER
                     * */

                    if (!_hasBeenMouseDown && 0 != MouseTarget.HotControlId)
                    {
                        //GUIUtility.hotControl = MouseTarget.HotControlId;
                        //Debug.Log("GUIUtility.hotControl: " + GUIUtility.hotControl);
                    }

                    MouseEventHelper.BuildAndDispatchMouseEvent(this, MouseTarget, MouseEvent.MOUSE_OVER,
                                                                _mouseEvent.GlobalPosition, _mouseEvent.CurrentEvent);

                    string cursorStyle = (string)MouseTarget.GetStyle("cursor");
                    if (!string.IsNullOrEmpty(cursorStyle))
                    {
                        _currentCursorId = CursorManager.Instance.SetCursor(cursorStyle, CursorPriority.Low);
                    }

                    //Debug.Log("_previousMouseOveredComponent: " + _previousMouseOveredComponent);
                    //Debug.Log("_rollOveredComponents.Count: " + _rollOveredComponents.Count);

                    foreach (Component comp in _rollOveredComponents.Keys)
                    {
                        // this is the component subscribed to rollover events

                        _shouldDispatchRollOver = false;
                        _shouldDispatchRollOut  = false;

                        /**
                         * 1) Both components are the child of this parent
                         * From parent's point of view, there has been no rollover nor rollout
                         * */
                        if (comp.Contains(MouseTarget, true) &&
                            null != _previousMouseOveredComponent &&
                            comp.Contains(_previousMouseOveredComponent, true))
                        {
                            // do nothing
                            continue;
                        }

                        /**
                         * 2) Component child has been mouseovered.
                         * The component has not been in rollovered state.
                         * Dispatch ROLL_OVER.
                         * */
                        if (comp.Contains(MouseTarget, true) && !_rollOveredComponents[comp])
                        {
                            _shouldDispatchRollOver = true;
                            _rollOveredComponentsToChangeState.Add(comp);
                        }

                        /**
                         * 3) Component child has been mouseouted.
                         * New mouseovered component is not a child of this component, and component has been in rollovered state.
                         * Dispatch ROLL_OUT.
                         * */
                        else if (null != _previousMouseOveredComponent &&
                                 comp.Contains(_previousMouseOveredComponent, true) && _rollOveredComponents[comp])
                        {
                            _shouldDispatchRollOut = true;
                            _rollOveredComponentsToChangeState.Add(comp);
                        }

                        // rethink once again
                        // check if there has been a mouse out and no mouse in (blank Stage example)
                        //else if (_hasBeenMouseOut)// && !_shouldDispatchRollOut)
                        //{
                        //    Debug.Log("_hasBeenMouseOut");
                        //    _shouldDispatchRollOut = true;
                        //    _rollOveredComponentsToChangeState.Add(comp);
                        //}

                        if (_shouldDispatchRollOut)
                        {
#if DEBUG
                            if (DebugMode)
                            {
                                Debug.Log("Dispatching ROLL_OUT: " + comp);
                            }
#endif
                            MouseEventHelper.BuildAndDispatchMouseEvent(this, comp, MouseEvent.ROLL_OUT,
                                                                        _mouseEvent.GlobalPosition, _mouseEvent.CurrentEvent);
                        }
                        else if (_shouldDispatchRollOver)
                        {
#if DEBUG
                            if (DebugMode)
                            {
                                Debug.Log("Dispatching ROLL_OVER: " + comp);
                            }
#endif
                            MouseEventHelper.BuildAndDispatchMouseEvent(this, comp, MouseEvent.ROLL_OVER,
                                                                        _mouseEvent.GlobalPosition, _mouseEvent.CurrentEvent);
                        }
                    }
                }

                // new mouse target is null
                else if (_hasBeenMouseOut || _isMouseLeave)
                {
                    foreach (Component comp in _rollOveredComponents.Keys)
                    {
                        /**
                         *
                         * */
                        if (null != _previousMouseOveredComponent &&
                            comp.Contains(_previousMouseOveredComponent, true) &&
                            _rollOveredComponents[comp])
                        {
#if DEBUG
                            if (DebugMode)
                            {
                                Debug.Log("Dispatching ROLL_OUT (special): " + comp);
                            }
#endif
                            _rollOveredComponentsToChangeState.Add(comp);
                            MouseEventHelper.BuildAndDispatchMouseEvent(this, comp, MouseEvent.ROLL_OUT,
                                                                        _mouseEvent.GlobalPosition, _mouseEvent.CurrentEvent);
                        }
                    }
                }
            }

            _rollOveredComponentsToChangeState.ForEach(delegate(Component changing)
            {
                _rollOveredComponents[changing] =
                    !_rollOveredComponents[changing];
            });
            _rollOveredComponentsToChangeState.Clear();

            _previousMouseOveredComponent = MouseTarget;
            _hasBeenMouseOut = false;

            if (null != _mouseLeaveEvent)
            {
                /**
                 * 2) Dispatch from manager
                 * */
                DispatchEvent(_mouseLeaveEvent);
            }
        }
Exemplo n.º 14
0
 public override void OnPlayerCommand(MouseTarget _target)
 {
     //Do nothing.. for now.
 }
Exemplo n.º 15
0
 // Use this for initialization
 void Start()
 {
     mouseTarget = Camera.main.GetComponent <MouseTarget>();
 }
Exemplo n.º 16
0
 protected virtual void OnRightClick(MouseTarget _mouseTarget)
 {
     controllerUnit.OnPlayerCommand(_mouseTarget);
 }
Exemplo n.º 17
0
	// Use this for initialization
	void Start () {
		if (mInstance == null) {
			mInstance = this;
		}
	
	}
Exemplo n.º 18
0
 public MouseEntry(MouseTarget target, MouseChord chord, BindAction action) {
     Target = target;
     Action = action;
     Chord = chord;
 }
Exemplo n.º 19
0
 public MouseEntry(MouseTarget target, MouseChord chord, BindAction action)
 {
     Target = target;
     Action = action;
     Chord  = chord;
 }
Exemplo n.º 20
0
 protected override void OnRightClick(MouseTarget _mouseTarget)
 {
     controllerUnit.OnPlayerCommand(_mouseTarget);
 }
Exemplo n.º 21
0
 public abstract void OnPlayerCommand(MouseTarget mouseTarget);
Exemplo n.º 22
0
 private void Start()
 {
     mouseTarget = FindObjectOfType <MouseTarget>();
     itemSystem  = FindObjectOfType <ItemSystem>();
 }
Exemplo n.º 23
0
 // Use this for initialization
 void Awake()
 {
     mouseTarget = FindObjectOfType <MouseTarget> ();
     //rightClickableMask = mouseTarget.rightClickables;
 }
Exemplo n.º 24
0
 private void AddMouseAction(MouseChord chord, MouseTarget target) {
     MouseChord button = chord & ~(MouseChord.Alt | MouseChord.Ctrl | MouseChord.Shift);
     if(!MouseTargetButtons[target].Contains(button)) {
         var dict = QTUtility.TextResourcesDic["Options_Page07_Mouse"];
         MessageBox.Show(
                 dict[18] + Environment.NewLine +
                 dict[19] + Environment.NewLine +
                 MouseTargetButtons[target].Select(k => "  " + dict[MouseButtonResx[k]])
                     .StringJoin(Environment.NewLine),
                 dict[20], MessageBoxButton.OK, MessageBoxImage.Hand);
         return;
     }
     MouseEntry entry = MouseBindings.FirstOrDefault(e => e.Chord == chord && e.Target == target);
     if(entry == null) {
         entry = new MouseEntry(target, chord, BindAction.Nothing);
         MouseBindings.Add(entry);
     }
     entry.IsSelected = true;
     lvwMouseBindings.UpdateLayout();
     lvwMouseBindings.ScrollIntoView(entry);
     // Need to wait for ScrollIntoView to finish, or the dropdown will open in the wrong place.
     Dispatcher.BeginInvoke(DispatcherPriority.Input, new Action(() => { entry.IsEditing = true; }));
 }