Ejemplo n.º 1
0
        public void UpdateMouseMode(MouseMode mouseMode)
        {
            _mouseMode = mouseMode;

            if (_mouseMode == MouseMode.NORMAL || _mouseMode == MouseMode.NORMAL_COVER)
            {
                _clickManager.Update();
            }
        }
Ejemplo n.º 2
0
        public void Update(MouseMode mouseMode)
        {
            _mouseMode = mouseMode;

            if (_mouseMode == MouseMode.normal)
            {
                _clickManager.Update();
            }
        }
Ejemplo n.º 3
0
        private void Update()
        {
            _selectionManager.UpdateMouseMode(CurMouseMode);

            switch (CurMouseMode)
            {
            case MouseMode.PURCHASING:
            {
                RaycastHit hit;
                if (Util.GetTerrainClickLocation(out hit))
                {
                    ShowGhostUnitsAndMaybePurchase(hit);
                }
                else
                {
                    _currentBuyTransaction.HidePreview();
                }

                MaybeExitPurchasingModeAndRefund();
                break;
            }

            case MouseMode.NORMAL:
            {
                ApplyHotkeys();
                _rightClickManager.Update();

                if (IsMouseOverCover())
                {
                    EnterNormalCoverMode();
                }

                break;
            }

            case MouseMode.NORMAL_COVER:
            {
                ApplyHotkeys();
                _rightClickManager.Update();

                if (!IsMouseOverCover())
                {
                    EnterNormalMode();
                }

                break;
            }

            case MouseMode.VISION_RULER:
            {
                ApplyHotkeys();

                // Show range and line of sight indicators
                RaycastHit hit;
                if (Util.GetTerrainClickLocation(out hit))
                {
                    _selectionManager.ToggleTargetingPreview(true);
                    int minDistance = _selectionManager.PlaceTargetingPreview(
                        hit.point, false);
                    _rangeTooltipText.text = minDistance.ToString() + "m";
                    _rangeTooltip.SetActive(true);
                    _rangeTooltip.transform.position = Input.mousePosition;
                }
                else
                {
                    _selectionManager.ToggleTargetingPreview(false);
                    _rangeTooltip.SetActive(false);
                }


                if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1))
                {
                    EnterNormalModeNaive();
                }
                break;
            }

            case MouseMode.FIRE_POS:
            {
                ApplyHotkeys();

                // Show range and line of sight indicators
                RaycastHit hit;
                if (Util.GetTerrainClickLocation(out hit))
                {
                    _selectionManager.ToggleTargetingPreview(true);
                    int minDistance = _selectionManager.PlaceTargetingPreview(
                        hit.point, true);
                    _rangeTooltipText.text = minDistance.ToString() + "m";
                    _rangeTooltip.SetActive(true);
                    _rangeTooltip.transform.position = Input.mousePosition;
                }
                else
                {
                    _selectionManager.ToggleTargetingPreview(false);
                    _rangeTooltip.SetActive(false);
                }

                // React to clicks
                if (Input.GetMouseButtonDown(0))
                {
                    _selectionManager.DispatchFirePosCommand();
                }

                if ((Input.GetMouseButtonDown(0) && !Input.GetKey(KeyCode.LeftShift)) ||
                    Input.GetMouseButtonDown(1))
                {
                    EnterNormalModeNaive();
                }

                break;
            }

            case MouseMode.REVERSE_MOVE:
                ApplyHotkeys();
                if (Input.GetMouseButtonDown(0))
                {
                    MoveGhostsToMouse();
                    _selectionManager.DispatchMoveCommand(
                        false, MoveCommandType.REVERSE);
                }

                if ((Input.GetMouseButtonDown(0) && !Input.GetKey(KeyCode.LeftShift)) ||
                    Input.GetMouseButtonDown(1))
                {
                    EnterNormalModeNaive();
                }
                break;

            case MouseMode.FAST_MOVE:
                ApplyHotkeys();
                if (Input.GetMouseButtonDown(0))
                {
                    MoveGhostsToMouse();
                    _selectionManager.DispatchMoveCommand(
                        false, MoveCommandType.FAST);
                }

                if ((Input.GetMouseButtonDown(0) && !Input.GetKey(KeyCode.LeftShift)) ||
                    Input.GetMouseButtonDown(1))
                {
                    EnterNormalModeNaive();
                }
                break;

            case MouseMode.SPLIT:
                ApplyHotkeys();
                if (Input.GetMouseButtonDown(0))
                {
                    _selectionManager.DispatchSplitCommand();
                }

                if ((Input.GetMouseButtonDown(0) && !Input.GetKey(KeyCode.LeftShift)) ||
                    Input.GetMouseButtonDown(1))
                {
                    EnterNormalModeNaive();
                }
                break;

            default:
                throw new Exception("impossible state");
            }
        }
    // Update is called once per frame
    void Update()
    {
        //////////////////////////////////////////////////////////////////////
        // Temporary : for testing health until units can damage each other //
        //////////////////////////////////////////////////////////////////////

        if (Input.GetKey(KeyCode.Space))
        {
            foreach (var x in selected)
            {
                foreach (var y in x.units)
                {
                    y.setHealth(y.getHealth() - 0.1f);
                    Debug.Log("hp : " + y.getHealth());
                }
            }
        }

        //////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////

        if (spawningUnits)
        {
            RaycastHit hit;
            if (Input.GetMouseButtonUp(0) && enteringSpawning)
            {
                enteringSpawning = false;
            }
            else if (getTerrainClickLocation(out hit) &&
                     hit.transform.gameObject.name.Equals("Terrain"))
            {
                arrangeToBeSpawned(hit.point);

                if (Input.GetMouseButtonUp(0) && !enteringSpawning)
                {
                    var spawnPoint   = getClosestSpawn(hit.point);
                    var realPlatoons = spawnList.ConvertAll(x => x.GetComponent <GhostPlatoonBehaviour>().getRealPlatoon());

                    spawnPoint.updateQueue(realPlatoons);
                    if (Input.GetKey(KeyCode.LeftShift))
                    {
                        replaceSpawnList();
                    }
                    else
                    {
                        spawnList.Clear();
                        spawningUnits = false;
                    }
                }
            }

            if (Input.GetMouseButton(1))
            {
                destroySpawning();
            }
        }
        else
        {
            if (!selectMode.IsActive)
            {
                orderMode.Update();
            }
            if (!orderMode.IsActive)
            {
                selectMode.Update();
            }
            processCommands();
        }
    }
Ejemplo n.º 5
0
        void Update()
        {
            _selectionManager.Update(CurMouseMode);

            switch (CurMouseMode)
            {
            case MouseMode.purchasing:

                RaycastHit hit;
                if (Util.GetTerrainClickLocation(out hit) &&
                    hit.transform.gameObject.name.Equals("Terrain"))
                {
                    ShowGhostUnitsAndMaybePurchase(hit);
                }

                MaybeExitPurchasingMode();
                break;

            case MouseMode.normal:
                ApplyHotkeys();
                _rightClickManager.Update();
                break;

            case MouseMode.firePos:
                ApplyHotkeys();

                if (Input.GetMouseButtonDown(0))
                {
                    _selectionManager.DispatchFirePosCommand();
                }

                if ((Input.GetMouseButtonDown(0) && !Input.GetKey(KeyCode.LeftShift)) ||
                    Input.GetMouseButtonDown(1))
                {
                    EnterNormalMode();
                }

                break;

            case MouseMode.reverseMove:
                ApplyHotkeys();
                if (Input.GetMouseButtonDown(0))
                {
                    MoveGhostsToMouse();
                    _selectionManager.DispatchMoveCommand(
                        false, MoveWaypoint.MoveMode.reverseMove);
                }

                if ((Input.GetMouseButtonDown(0) && !Input.GetKey(KeyCode.LeftShift)) ||
                    Input.GetMouseButtonDown(1))
                {
                    EnterNormalMode();
                }
                break;

            case MouseMode.fastMove:
                ApplyHotkeys();
                if (Input.GetMouseButtonDown(0))
                {
                    MoveGhostsToMouse();
                    _selectionManager.DispatchMoveCommand(
                        false, MoveWaypoint.MoveMode.fastMove);
                }

                if ((Input.GetMouseButtonDown(0) && !Input.GetKey(KeyCode.LeftShift)) ||
                    Input.GetMouseButtonDown(1))
                {
                    EnterNormalMode();
                }
                break;

            default:
                throw new Exception("impossible state");
            }
        }
Ejemplo n.º 6
0
        private void Update()
        {
            _selectionManager.UpdateMouseMode(CurMouseMode);

            switch (CurMouseMode)
            {
            case MouseMode.PURCHASING:
            {
                if (Util.GetTerrainClickLocation(out RaycastHit hit))
                {
                    ShowGhostUnitsAndMaybePurchase(hit);
                }
                else
                {
                    _currentBuyTransaction.HidePreview();
                }

                MaybeExitPurchasingModeAndRefund();
                break;
            }

            case MouseMode.FLARE:
            {
                if (Input.GetMouseButton(1))
                {
                    ExitFlareMode();
                }
                else if (Util.GetTerrainClickLocation(out RaycastHit hit))
                {
                    if (Input.GetMouseButton(0))
                    {
                        CommandConnection.Connection.CmdSpawnFlare(
                            _flare.Text,
                            MatchSession.Current.LocalPlayer.Data.Id,
                            hit.point);

                        ExitFlareMode();
                    }
                    else
                    {
                        _flare.transform.position = hit.point;
                        _flare.gameObject.SetActive(true);
                    }
                }
                else
                {
                    if (Input.GetMouseButton(0))
                    {
                        ExitFlareMode();
                    }
                    else
                    {
                        // We only hide the flare if the cursor is hovering somewhere bad
                        _flare.gameObject.SetActive(false);
                    }
                }

                break;
            }

            case MouseMode.NORMAL:
            {
                ApplyHotkeys();
                _rightClickManager.Update();

                if (IsMouseOverCover())
                {
                    EnterNormalCoverMode();
                }

                break;
            }

            case MouseMode.NORMAL_COVER:
            {
                ApplyHotkeys();
                _rightClickManager.Update();

                if (!IsMouseOverCover())
                {
                    EnterNormalMode();
                }

                break;
            }

            case MouseMode.VISION_RULER:
            {
                ApplyHotkeys();

                // Show range and line of sight indicators
                if (Util.GetTerrainClickLocation(out RaycastHit hit))
                {
                    _selectionManager.ToggleTargetingPreview(true);
                    int minDistance = _selectionManager.PlaceTargetingPreview(
                        hit.point, false);
                    _rangeTooltipText.text = minDistance.ToString() + "m";
                    _rangeTooltip.SetActive(true);
                    _rangeTooltip.transform.position = Input.mousePosition;
                }
                else
                {
                    _selectionManager.ToggleTargetingPreview(false);
                    _rangeTooltip.SetActive(false);
                }


                if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1))
                {
                    EnterNormalModeNaive();
                }
                break;
            }

            case MouseMode.FIRE_POS:
            {
                ApplyHotkeys();

                // Show range and line of sight indicators
                if (Util.GetTerrainClickLocation(out RaycastHit hit))
                {
                    _selectionManager.ToggleTargetingPreview(true);
                    int minDistance = _selectionManager.PlaceTargetingPreview(
                        hit.point, true);
                    _rangeTooltipText.text = minDistance.ToString() + "m";
                    _rangeTooltip.SetActive(true);
                    _rangeTooltip.transform.position = Input.mousePosition;
                }
                else
                {
                    _selectionManager.ToggleTargetingPreview(false);
                    _rangeTooltip.SetActive(false);
                }

                // React to clicks
                if (Input.GetMouseButtonDown(0))
                {
                    _selectionManager.DispatchFirePosCommand();
                }

                if ((Input.GetMouseButtonDown(0) && !Input.GetKey(KeyCode.LeftShift)) ||
                    Input.GetMouseButtonDown(1))
                {
                    EnterNormalModeNaive();
                }

                break;
            }

            case MouseMode.REVERSE_MOVE:
                ApplyHotkeys();
                if (Input.GetMouseButtonDown(0))
                {
                    MoveGhostsToMouse();
                    _selectionManager.DispatchMoveCommand(
                        false, MoveCommandType.REVERSE);
                }

                if ((Input.GetMouseButtonDown(0) && !Input.GetKey(KeyCode.LeftShift)) ||
                    Input.GetMouseButtonDown(1))
                {
                    EnterNormalModeNaive();
                }
                break;

            case MouseMode.FAST_MOVE:
                ApplyHotkeys();
                if (Input.GetMouseButtonDown(0))
                {
                    MoveGhostsToMouse();
                    _selectionManager.DispatchMoveCommand(
                        false, MoveCommandType.FAST);
                }

                if ((Input.GetMouseButtonDown(0) && !Input.GetKey(KeyCode.LeftShift)) ||
                    Input.GetMouseButtonDown(1))
                {
                    EnterNormalModeNaive();
                }
                break;

            case MouseMode.SPLIT:
                ApplyHotkeys();
                if (Input.GetMouseButtonDown(0))
                {
                    _selectionManager.DispatchSplitCommand();
                }

                if ((Input.GetMouseButtonDown(0) && !Input.GetKey(KeyCode.LeftShift)) ||
                    Input.GetMouseButtonDown(1))
                {
                    EnterNormalModeNaive();
                }
                break;

            case MouseMode.IN_MENU:
            {
                if (_commands.ToggleMenu)
                {
                    _minimap.enabled = true;
                    if (_lastCameraWasSliding)
                    {
                        _slidingCamera.enabled = true;
                    }
                    else
                    {
                        _orbitCamera.enabled = true;
                    }
                    _menu.SetActive(false);
                    EnterNormalModeNaive();
                }
                break;
            }

            default:
                throw new Exception("impossible state");
            }
        }