Beyond_Beyaan.Screens.SystemView.MouseUp C# (CSharp) Метод

MouseUp() публичный Метод

public MouseUp ( int x, int y ) : bool
x int
y int
Результат bool
        public override bool MouseUp(int x, int y)
        {
            if (!_isOwnedSystem)
            {
                return base.MouseUp(x, y);
            }
            if (IsTransferring)
            {
                if (_popTransferSlider.MouseUp(x, y))
                {
                    _transferLabel.SetText("Moving " + _popTransferSlider.TopIndex + " Population");
                    return true;
                }
                if (_transferToButton.MouseUp(x, y))
                {
                    if (TransferSystem != null && TransferSystem.IsValid)
                    {
                        if (TransferSystem.StarSystem == _currentSystem)
                        {
                            _currentSystem.Planets[0].TransferSystem = new KeyValuePair<TravelNode, int>(new TravelNode(), 0);
                        }
                        else
                        {
                            _currentSystem.Planets[0].TransferSystem = new KeyValuePair<TravelNode, int>(TransferSystem, _popTransferSlider.TopIndex);
                        }
                        _transferLabel.SetText("Moving " + _currentSystem.Planets[0].TransferSystem.Value + " Pop");
                        _transferLabel.MoveTo(_xPos + 10, _yPos + 440);
                        TransferSystem = null;
                        //Done setting transfer
                    }
                    IsTransferring = false;
                    return true;
                }
            }
            if (IsRelocating)
            {
                if (_relocateToButton.MouseUp(x, y))
                {
                    if (RelocateSystem.IsValid)
                    {
                        _currentSystem.Planets[0].RelocateToSystem = RelocateSystem;
                        IsRelocating = false;
                        RelocateSystem = null;
                    }
                }
            }
            if (_name.MouseUp(x, y))
            {
                return true;
            }
            if (_infrastructureSlider.MouseUp(x, y))
            {
                _currentSystem.Planets[0].SetOutputAmount(OUTPUT_TYPE.INFRASTRUCTURE, _infrastructureSlider.TopIndex, false);
                Refresh();
                return true;
            }
            if (_researchSlider.MouseUp(x, y))
            {
                _currentSystem.Planets[0].SetOutputAmount(OUTPUT_TYPE.RESEARCH, _researchSlider.TopIndex, false);
                Refresh();
                return true;
            }
            if (_environmentSlider.MouseUp(x, y))
            {
                _currentSystem.Planets[0].SetOutputAmount(OUTPUT_TYPE.ENVIRONMENT, _environmentSlider.TopIndex, false);
                Refresh();
                return true;
            }
            if (_defenseSlider.MouseUp(x, y))
            {
                _currentSystem.Planets[0].SetOutputAmount(OUTPUT_TYPE.DEFENSE, _defenseSlider.TopIndex, false);
                Refresh();
                return true;
            }
            if (_constructionSlider.MouseUp(x, y))
            {
                _currentSystem.Planets[0].SetOutputAmount(OUTPUT_TYPE.CONSTRUCTION, _constructionSlider.TopIndex, false);
                Refresh();
                return true;
            }
            if (_infrastructureLockButton.MouseUp(x, y))
            {
                _currentSystem.Planets[0].InfrastructureLocked = !_currentSystem.Planets[0].InfrastructureLocked;
                _infrastructureSlider.SetEnabledState(!_currentSystem.Planets[0].InfrastructureLocked);
                _infrastructureLockButton.Selected = _currentSystem.Planets[0].InfrastructureLocked;
                return true;
            }
            if (_researchLockButton.MouseUp(x, y))
            {
                _currentSystem.Planets[0].ResearchLocked = !_currentSystem.Planets[0].ResearchLocked;
                _researchSlider.SetEnabledState(!_currentSystem.Planets[0].ResearchLocked);
                _researchLockButton.Selected = _currentSystem.Planets[0].ResearchLocked;
                return true;
            }
            if (_environmentLockButton.MouseUp(x, y))
            {
                _currentSystem.Planets[0].EnvironmentLocked = !_currentSystem.Planets[0].EnvironmentLocked;
                _environmentSlider.SetEnabledState(!_currentSystem.Planets[0].EnvironmentLocked);
                _environmentLockButton.Selected = _currentSystem.Planets[0].EnvironmentLocked;
                return true;
            }
            if (_defenseLockButton.MouseUp(x, y))
            {
                _currentSystem.Planets[0].DefenseLocked = !_currentSystem.Planets[0].DefenseLocked;
                _defenseSlider.SetEnabledState(!_currentSystem.Planets[0].DefenseLocked);
                _defenseLockButton.Selected = _currentSystem.Planets[0].DefenseLocked;
                return true;
            }
            if (_constructionLockButton.MouseUp(x, y))
            {
                _currentSystem.Planets[0].ConstructionLocked = !_currentSystem.Planets[0].ConstructionLocked;
                _constructionSlider.SetEnabledState(!_currentSystem.Planets[0].ConstructionLocked);
                _constructionLockButton.Selected = _currentSystem.Planets[0].ConstructionLocked;
                return true;
            }
            if (_relocateToButton.MouseUp(x, y))
            {
                IsRelocating = true;
                _generalPurposeText.SetText("Select a friendly system to send newly built ships");
                _relocateToButton.Active = false;
                return true;
            }
            if (_transferToButton.MouseUp(x, y))
            {
                IsTransferring = true;
                _transferLabel.MoveTo(_xPos + 20, _yPos + 370);
                _transferLabel.SetText("Moving 0 Population");
                _popTransferSlider.SetAmountOfItems((int)(_currentSystem.Planets[0].TotalPopulation / 2));
                _generalPurposeText.SetText("Select a colonized planet to send population");
                return true;
            }
            if (_constructionProjectButton.MouseUp(x, y))
            {
                _currentSystem.Planets[0].ShipBeingBuilt = _currentEmpire.FleetManager.GetNextShipDesign(_currentSystem.Planets[0].ShipBeingBuilt);
                Refresh();
            }
            return base.MouseUp(x, y);
        }

Usage Example

Пример #1
0
        public void MouseUp(int x, int y, int whichButton)
        {
            if (whichButton == 1)
            {
                var currentEmpire = _gameMain.EmpireManager.CurrentEmpire;
                if (_taskBar.MouseUp(x, y, whichButton))
                {
                    //clear the fleet/planet window
                    currentEmpire.SelectedSystem     = null;
                    currentEmpire.SelectedFleetGroup = null;
                    return;
                }
                if (_windowShowing != null)
                {
                    _windowShowing.MouseUp(x, y);
                    return;
                }
                if (currentEmpire.SelectedSystem != null)
                {
                    if (_systemView.MouseUp(x, y))
                    {
                        return;
                    }
                    if (_systemView.IsTransferring)
                    {
                        Point point = new Point();

                        point.X = (int)((x / _camera.ZoomDistance) + _camera.CameraX);
                        point.Y = (int)((y / _camera.ZoomDistance) + _camera.CameraY);

                        StarSystem system = _gameMain.Galaxy.GetStarAtPoint(point);
                        if (system != null)
                        {
                            var path = _gameMain.Galaxy.GetPath(currentEmpire.SelectedSystem.X, currentEmpire.SelectedSystem.Y, null, system, false, currentEmpire);
                            if (path.Count > 0)
                            {
                                if (!path[0].StarSystem.IsThisSystemExploredByEmpire(currentEmpire) || path[0].StarSystem.Planets[0].Owner == null)
                                {
                                    path[0].IsValid = false;
                                }
                                _systemView.TransferSystem = path[0];
                            }
                        }
                        else
                        {
                            //Clicked to clear the option
                            _systemView.IsTransferring = false;
                            _systemView.TransferSystem = null;
                        }
                        return;
                    }
                    if (_systemView.IsRelocating)
                    {
                        Point point = new Point();

                        point.X = (int)((x / _camera.ZoomDistance) + _camera.CameraX);
                        point.Y = (int)((y / _camera.ZoomDistance) + _camera.CameraY);

                        StarSystem system = _gameMain.Galaxy.GetStarAtPoint(point);
                        if (system != null)
                        {
                            var path = _gameMain.Galaxy.GetPath(currentEmpire.SelectedSystem.X, currentEmpire.SelectedSystem.Y, null, system, false, currentEmpire);
                            if (path.Count > 0)
                            {
                                if (path[0].StarSystem.Planets[0].Owner != currentEmpire)
                                {
                                    path[0].IsValid = false;
                                }
                                _systemView.RelocateSystem = path[0];
                            }
                        }
                        else
                        {
                            //Clicked to clear the option
                            _systemView.IsRelocating   = false;
                            _systemView.RelocateSystem = null;
                        }
                        return;
                    }
                }
                if (_gameMain.EmpireManager.CurrentEmpire.SelectedFleetGroup != null)
                {
                    if (_fleetView.MouseUp(x, y))
                    {
                        RefreshETAText();
                        return;
                    }
                }
                //If a window is open, but the player didn't click on another system or fleet, the action is to close the current window
                bool  clearingUI   = _gameMain.EmpireManager.CurrentEmpire.SelectedSystem != null || _gameMain.EmpireManager.CurrentEmpire.SelectedFleetGroup != null;
                Point pointClicked = new Point();

                pointClicked.X = (int)((x / _camera.ZoomDistance) + _camera.CameraX);
                pointClicked.Y = (int)((y / _camera.ZoomDistance) + _camera.CameraY);

                StarSystem selectedSystem = _gameMain.Galaxy.GetStarAtPoint(pointClicked);
                if (selectedSystem != null && selectedSystem == _gameMain.EmpireManager.CurrentEmpire.SelectedSystem)
                {
                    return;
                }
                _gameMain.EmpireManager.CurrentEmpire.SelectedSystem = selectedSystem;

                if (selectedSystem != null)
                {
                    _gameMain.EmpireManager.CurrentEmpire.LastSelectedSystem = selectedSystem;
                    _gameMain.EmpireManager.CurrentEmpire.SelectedFleetGroup = null;
                    _systemView.LoadSystem();
                    return;
                }

                FleetGroup selectedFleetGroup = _gameMain.EmpireManager.GetFleetsAtPoint(pointClicked.X, pointClicked.Y);
                _gameMain.EmpireManager.CurrentEmpire.SelectedFleetGroup = selectedFleetGroup;

                if (selectedFleetGroup != null)
                {
                    _fleetView.LoadFleetGroup(selectedFleetGroup);
                    RefreshETAText();
                    return;
                }
                if (!clearingUI)
                {
                    _camera.ScrollToPosition(pointClicked.X, pointClicked.Y);
                }
            }
            else if (whichButton == 2)
            {
                if (_windowShowing != null)
                {
                    return;
                }
                var selectedFleetGroup = _gameMain.EmpireManager.CurrentEmpire.SelectedFleetGroup;
                if (selectedFleetGroup != null && selectedFleetGroup.FleetToSplit.Empire == _gameMain.EmpireManager.CurrentEmpire)
                {
                    bool isIdling       = selectedFleetGroup.SelectedFleet.AdjacentSystem != null;
                    bool hasDestination = selectedFleetGroup.SelectedFleet.TravelNodes != null;
                    if (selectedFleetGroup.FleetToSplit.ConfirmPath())
                    {
                        _gameMain.EmpireManager.CurrentEmpire.SelectedFleetGroup.SplitFleet(_gameMain.EmpireManager.CurrentEmpire);
                        _gameMain.EmpireManager.CurrentEmpire.FleetManager.MergeIdleFleets();
                        if (isIdling && !hasDestination)                         //Select the remaining idling ships on right of star
                        {
                            Point point = new Point((int)selectedFleetGroup.SelectedFleet.GalaxyX + 32, (int)selectedFleetGroup.SelectedFleet.GalaxyY);
                            selectedFleetGroup = _gameMain.EmpireManager.GetFleetsAtPoint(point.X, point.Y);
                            if (selectedFleetGroup == null)                             // No ships left, select the fleet on left of star
                            {
                                selectedFleetGroup = _gameMain.EmpireManager.GetFleetsAtPoint(point.X - 64, point.Y);
                            }
                        }
                        else if (isIdling)
                        {
                            if (selectedFleetGroup.SelectedFleet.TravelNodes == null)                             //cleared out movement order
                            {
                                selectedFleetGroup = _gameMain.EmpireManager.GetFleetsAtPoint((int)selectedFleetGroup.SelectedFleet.GalaxyX + 32, (int)selectedFleetGroup.SelectedFleet.GalaxyY);
                            }
                            else
                            {
                                selectedFleetGroup = _gameMain.EmpireManager.GetFleetsAtPoint((int)selectedFleetGroup.SelectedFleet.GalaxyX - 32, (int)selectedFleetGroup.SelectedFleet.GalaxyY);
                            }
                        }
                        else
                        {
                            selectedFleetGroup = _gameMain.EmpireManager.GetFleetsAtPoint((int)selectedFleetGroup.SelectedFleet.GalaxyX, (int)selectedFleetGroup.SelectedFleet.GalaxyY);
                        }
                        _gameMain.EmpireManager.CurrentEmpire.SelectedFleetGroup = selectedFleetGroup;
                        _fleetView.LoadFleetGroup(selectedFleetGroup);
                    }
                }
            }
        }