Пример #1
0
        public void SwitchPlayer(PlayerController player)
        {
            this.currentPlayer = player;

            //Assumes all players can see the same map size
            if (this.lastSelectedStars.Count == 0)
            {
                this.mapBoundsMin = new Vector2(
                    (float)this.currentPlayer.Stars.Min(star => star.Position.X) - StarMinClickRadius,
                    (float)this.currentPlayer.Stars.Min(star => star.Position.Y) - StarMinClickRadius
                    );
                this.mapBoundsMax = new Vector2(
                    (float)this.currentPlayer.Stars.Max(star => star.Position.X) + StarMinClickRadius,
                    (float)this.currentPlayer.Stars.Max(star => star.Position.Y) + StarMinClickRadius
                    );
            }

            if (!this.lastSelectedStars.ContainsKey(this.currentPlayer.PlayerIndex))
            {
                var bestStar = this.currentPlayer.Stellarises().Aggregate((a, b) => a.Population > b.Population ? a : b);

                this.lastSelectedStars.Add(this.currentPlayer.PlayerIndex, bestStar.HostStar.Position);
            }

            this.originOffset     = new Vector2((float)this.lastSelectedStar.Position.X, (float)this.lastSelectedStar.Position.Y);
            this.currentSelection = GalaxySelectionType.Star;
            this.galaxyViewListener.SystemSelected(this.currentPlayer.OpenStarSystem(this.lastSelectedStar));
            this.setupPerspective();
        }
Пример #2
0
        protected override void frameUpdate(double deltaTime)
        {
            if (this.refreshData.Check())
            {
                if (this.SelectedFleet != null && !this.SelectedFleet.Valid)
                {
                    this.SelectedFleet = null;
                }

                if (this.currentSelection == GalaxySelectionType.Fleet)
                {
                    this.currentSelection = GalaxySelectionType.None;
                }

                this.ResetLists();
            }
        }
Пример #3
0
        public void SwitchPlayer(PlayerController player)
        {
            player.RunAutomation();

            if (this.currentPlayer != null)
            {
                this.lastOffset[this.currentPlayer.PlayerIndex] = originOffset;
            }

            this.currentPlayer = player;

            //Assumes all players can see the same map size
            if (this.lastSelectedStars.Count == 0)
            {
                this.mapBoundsMin = new Vector2(
                    (float)this.currentPlayer.Stars.Min(star => star.Position.X) - StarMinClickRadius,
                    (float)this.currentPlayer.Stars.Min(star => star.Position.Y) - StarMinClickRadius
                    );
                this.mapBoundsMax = new Vector2(
                    (float)this.currentPlayer.Stars.Max(star => star.Position.X) + StarMinClickRadius,
                    (float)this.currentPlayer.Stars.Max(star => star.Position.Y) + StarMinClickRadius
                    );
            }

            if (!this.lastSelectedStars.ContainsKey(this.currentPlayer.PlayerIndex) ||
                !this.currentPlayer.Stars.Any(x => x.Position == this.lastSelectedStars[this.currentPlayer.PlayerIndex]))
            {
                this.selectDefaultStar();
            }

            this.originOffset     = this.lastOffset[this.currentPlayer.PlayerIndex];
            this.currentSelection = GalaxySelectionType.Star;
            this.updateStarInfo(this.lastSelectedStar);
            this.setupPerspective();
            this.setupFuelInfo();
        }
Пример #4
0
        protected override void onMouseClick(Vector2 mousePoint, Keys modiferKeys)
        {
            if (panAbsPath > PanClickTolerance)             //TODO(v0.8) maybe make AScene differentiate between click and drag
            {
                return;
            }

            var searchRadius = Math.Max(this.screenUnitScale * ClickRadius, StarMinClickRadius);
            var searchPoint  = convert(mousePoint);

            var allObjects = this.queryScene(searchPoint, searchRadius).
                             OrderBy(x => (x.PhysicalShape.Center - convert(searchPoint)).LengthSquared).
                             ToList();
            var starsFound = allObjects.Where(x => x.Data is StarInfo).Select(x => x.Data as StarInfo).ToList();
            var fleetFound = allObjects.Where(x => x.Data is FleetInfo).Select(x => x.Data as FleetInfo).ToList();

            var foundAny      = starsFound.Any() || fleetFound.Any();
            var isStarClosest =
                starsFound.Any() &&
                (
                    !fleetFound.Any() ||
                    (starsFound[0].Position - searchPoint).Length <= (fleetFound[0].Position - searchPoint).Length
                );

            if (this.SelectedFleet != null)
            {
                if (foundAny && isStarClosest)
                {
                    var destination = this.SelectedFleet.SimulationWaypoints().Any() ? this.SelectedFleet.SimulationWaypoints().Last() : starsFound[0];
                    this.SelectedFleet = modiferKeys.HasFlag(Keys.Control) ? this.SelectedFleet.SendDirectly(destination) : this.SelectedFleet.Send(destination);
                    this.lastSelectedIdleFleets[this.currentPlayer.PlayerIndex] = this.SelectedFleet.Fleet;
                    this.galaxyViewListener.FleetClicked(new FleetInfo[] { this.SelectedFleet.Fleet });
                    this.setupFleetMarkers();
                    this.setupFleetMovement();
                    this.setupSelectionMarkers();
                    this.setupFuelInfo();
                    return;
                }
                else
                {
                    this.galaxyViewListener.FleetDeselected();
                    this.SelectedFleet = null;
                    this.setupMovementEta();
                    this.setupMovementSimulation();
                    this.setupSelectionMarkers();
                }
            }


            if (!foundAny)
            {
                return;
            }

            if (isStarClosest)
            {
                this.currentSelection = GalaxySelectionType.Star;
                this.lastSelectedStars[this.currentPlayer.PlayerIndex] = starsFound[0].Position;
                this.updateStarInfo(this.lastSelectedStar);
                this.setupSelectionMarkers();
            }
            else
            {
                this.currentSelection = GalaxySelectionType.Fleet;
                this.lastSelectedIdleFleets[this.currentPlayer.PlayerIndex] = fleetFound[0];                 //TODO(v0.8) marks wrong fleet when there are multiple players
                this.galaxyViewListener.FleetClicked(fleetFound);
                this.setupSelectionMarkers();
            }
        }
Пример #5
0
        public override void OnMouseClick(MouseEventArgs e)
        {
            if (panAbsPath > PanClickTolerance)             //TODO(v0.6) maybe make AScene differentiate between click and drag
            {
                return;
            }

            Vector4 mousePoint   = Vector4.Transform(mouseToView(e.X, e.Y), invProjection);
            var     searchRadius = Math.Max(screenLength * ClickRadius, StarMinClickRadius);         //TODO(v0.6) doesn't scale with zoom
            var     searchPoint  = new NGenerics.DataStructures.Mathematical.Vector2D(mousePoint.X, mousePoint.Y);
            var     searchSize   = new NGenerics.DataStructures.Mathematical.Vector2D(searchRadius, searchRadius);

            var allObjects = this.QueryScene(searchPoint, searchRadius).
                             OrderBy(x => (x.PhysicalShape.Center - convert(searchPoint)).LengthSquared).
                             ToList();
            var starsFound = allObjects.Where(x => x.Data is StarData).Select(x => x.Data as StarData).ToList();
            var fleetFound = allObjects.Where(x => x.Data is FleetInfo).Select(x => x.Data as FleetInfo).ToList();

            var foundAny      = starsFound.Any() || fleetFound.Any();
            var isStarClosest =
                starsFound.Any() &&
                (
                    !fleetFound.Any() ||
                    (starsFound[0].Position - searchPoint).Magnitude() <= (fleetFound[0].Position - searchPoint).Magnitude()
                );

            if (this.SelectedFleet != null)
            {
                if (foundAny && isStarClosest)
                {
                    this.SelectedFleet = this.SelectedFleet.Send(this.SelectedFleet.SimulationWaypoints);
                    this.lastSelectedIdleFleets[this.currentPlayer.PlayerIndex] = this.SelectedFleet.Fleet;
                    this.galaxyViewListener.FleetClicked(new FleetInfo[] { this.SelectedFleet.Fleet });
                    this.setupFleetMarkers();
                    this.setupFleetMovement();
                    this.setupSelectionMarkers();
                    return;
                }
                else
                {
                    this.galaxyViewListener.FleetDeselected();
                    this.SelectedFleet = null;
                    this.setupMovementEta();
                    this.setupMovementSimulation();
                    this.setupSelectionMarkers();
                }
            }


            if (!foundAny)
            {
                return;
            }

            if (isStarClosest)
            {
                this.currentSelection = GalaxySelectionType.Star;
                this.lastSelectedStars[this.currentPlayer.PlayerIndex] = starsFound[0].Position;
                this.galaxyViewListener.SystemSelected(this.currentPlayer.OpenStarSystem(starsFound[0]));
                this.setupSelectionMarkers();
            }
            else
            {
                this.currentSelection = GalaxySelectionType.Fleet;
                this.lastSelectedIdleFleets[this.currentPlayer.PlayerIndex] = fleetFound[0];                 //TODO(v0.6) marks wrong fleet when there are multiple players
                this.galaxyViewListener.FleetClicked(fleetFound);
                this.setupSelectionMarkers();
            }
        }