public void Construct(StarSystemController targetStarSystem, SignalDispatcher signalDispatcher, LocalPlayerManager localPlayerManager)
    {
        _targetStarSystem   = targetStarSystem;
        _signalDispatcher   = signalDispatcher;
        _localPlayerManager = localPlayerManager;

        GetComponentsInChildren <Text>()[0].text = _targetStarSystem.StarName;

        StarSystemData sysData = _targetStarSystem.GetComponent <StarSystemData>();

        GetComponentsInChildren <Text>()[1].text = sysData.OrigX + ", " + sysData.OrigY;
        GetComponentsInChildren <Text>()[2].text = "Harvard Class " + sysData.StarClass.Split('h')[1].ToUpper();
        if (sysData.IsDataKnown)
        {
            GetComponentsInChildren <Text>()[3].text  = "Planets: " + (sysData.PlanetsUnknown ? "More than " : "") + sysData.PlanetsKnown.ToString();
            GetComponentsInChildren <Text>()[4].text  = "Gravity: " + sysData.Gravity;
            GetComponentsInChildren <Text>()[5].text  = "Atmosphere: " + sysData.Atmosphere;
            GetComponentsInChildren <Text>()[6].text  = "Water: " + sysData.Water + "%";
            GetComponentsInChildren <Text>()[7].text  = "Climate: " + sysData.Climate;
            GetComponentsInChildren <Text>()[8].text  = "Terrain: " + sysData.Terrain;
            GetComponentsInChildren <Text>()[9].text  = "Development: " + sysData.Development;
            GetComponentsInChildren <Text>()[10].text = "Flag: " + sysData.HasFlag;
        }
        else
        {
            for (int x = 3; x <= 10; x++)
            {
                GetComponentsInChildren <Text>()[x].text = "";
            }
        }

        GetComponentInChildren <Button>().onClick.AddListener(() => CaptureSystem());
    }
示例#2
0
        void IGalaxyViewListener.SystemOpened(StarSystemController systemController)
        {
            if (this.InvokeRequired)
            {
                this.BeginInvoke(new Action <StarSystemController>(((IGalaxyViewListener)this).SystemOpened), systemController);
                return;
            }

            this.systemRenderer.SetStarSystem(systemController, this.currentPlayer);
            this.nextRenderer = systemRenderer;
        }
示例#3
0
        void IGalaxyViewListener.SystemSelected(StarSystemController systemController)
        {
            if (this.InvokeRequired)
            {
                this.BeginInvoke(new Action <StarSystemController>(((IGalaxyViewListener)this).SystemSelected), systemController);
                return;
            }

            this.fleetController    = null;
            this.fleetPanel.Visible = false;
        }
示例#4
0
    public void SystemSelected(StarSystemController system)
    {
        _systemUI = _systemHUDFactory.Create(system);

        if (_selectedRegiment != null && _regimentJumpable.Contains(system.StarName))
        {
            _selectedRegiment.LocationChange(system.StarName);
            _regimentMovedSignal.Fire(_selectedRegiment.gameObject, system.StarName);
        }

        _selectedRegiment = null;
    }
        public void PlayTurn()
        {
            this.playerController.RunAutomation();

            foreach (var stellaris in this.playerController.Stellarises())
            {
                StarSystemController starSystem = this.playerController.OpenStarSystem(stellaris.HostStar);
                manage(starSystem.StellarisController());
            }

            this.playerController.EndGalaxyPhase();
        }
示例#6
0
        void IGalaxyViewListener.SystemOpened(StarSystemController systemController)
        {
            if (this.InvokeRequired)
            {
                this.BeginInvoke(new Action <StarSystemController>(((IGalaxyViewListener)this).SystemOpened), systemController);
                return;
            }

            this.fleetController = null;

            this.empyPlanetView.Visible = false;
            this.fleetPanel.Visible     = false;
            this.returnButton.Visible   = true;

            this.systemRenderer.SetStarSystem(systemController, this.currentPlayer);
            this.nextRenderer = systemRenderer;
        }
示例#7
0
        public void SetStarSystem(StarSystemController controller, PlayerController playerController)
        {
            this.controller    = controller;
            this.currentPlayer = playerController;

            this.maxOffset = controller.Planets.Count() * OrbitStep + OrbitOffset + PlanetScale / 2;

            var bestColony = controller.Planets.
                             Select(x => controller.PlanetsColony(x)).
                             Aggregate(
                (ColonyInfo)null,
                (prev, next) => next == null || (prev != null && prev.Population >= next.Population) ? prev : next
                );

            this.originOffset = bestColony != null ? bestColony.Location.Position * OrbitStep + OrbitOffset : 0.5f;

            this.select(StarSystemController.StarIndex);
        }
        public void PlayTurn()
        {
            foreach (var stellaris in this.playerController.Stellarises())
            {
                StarSystemController starSystem = this.playerController.OpenStarSystem(stellaris.HostStar);
                manage(starSystem.StellarisController());

                foreach (var planet in starSystem.Planets)
                {
                    if (starSystem.BodyType(planet.Position) == BodyType.OwnColony)
                    {
                        manage(starSystem.ColonyController(planet.Position));
                    }
                }
            }

            this.playerController.EndGalaxyPhase();
        }
    public void OnEnable()
    {
        controller  = (StarSystemController)target;
        rootElement = new VisualElement();

        IMGUIContainer defaultInspector = new IMGUIContainer(() => DrawDefaultInspector());

        rootElement.Add(defaultInspector);

        #region Setup UXML and USS

        VisualTreeAsset visualTree = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>("Assets/Scripts/Editor/Star System Controller/StarSystemControllerInspector.uxml");
        visualTree.CloneTree(rootElement);

        StyleSheet stylesheet = AssetDatabase.LoadAssetAtPath <StyleSheet>("Assets/Scripts/Editor/Star System Controller/StarSystemControllerInspector.uss");
        rootElement.styleSheets.Add(stylesheet);

        #endregion
    }
    public override void Select()
    {
        StarSystemController currentSystem = transform.parent.GetComponent <StarSystemController>();

        Collider[] hits = Physics.OverlapSphere(transform.parent.position, 150f);
        for (int hit = 0; hit < hits.Length; hit++)
        {
            StarSystemController hitSystem = hits[hit].GetComponent <StarSystemController>();

            if (hitSystem == currentSystem)
            {
                continue;
            }

            if (hitSystem)
            {
                if (Vector3.Distance(transform.parent.position, hitSystem.transform.position) <= 150f)
                {
                    GameObject lineHolder = new GameObject();
                    _lineList.Add(lineHolder);
                    lineHolder.transform.parent = transform;
                    LineRenderer lineRenderer = lineHolder.AddComponent <LineRenderer>();
                    lineRenderer.material        = new Material(Shader.Find("Particles/Additive"));
                    lineRenderer.widthMultiplier = 1f;

                    if (hitSystem.GetComponent <FactionController>().CurrentFaction != currentSystem.GetComponent <FactionController>().CurrentFaction)
                    {
                        lineRenderer.startColor      = Color.red;
                        lineRenderer.endColor        = Color.red;
                        lineRenderer.widthMultiplier = 2f;
                    }

                    lineRenderer.SetPosition(0, transform.parent.position);
                    lineRenderer.SetPosition(1, hitSystem.transform.position);

                    _jumpable.Add(hitSystem.StarName);
                }
            }
        }

        _uiManager.RegimentSelected(GetComponent <RegimentChit>().Regiment, _jumpable);
    }
示例#11
0
        void IGalaxyViewListener.SystemSelected(StarSystemController systemController)
        {
            if (this.InvokeRequired)
            {
                this.BeginInvoke(new Action <StarSystemController>(((IGalaxyViewListener)this).SystemSelected), systemController);
                return;
            }

            //FIXME(later) update owner check when multiple stellarises can exist at the same star
            if (systemController.StarsAdministration() == null || systemController.StarsAdministration().Owner != this.currentPlayer.Info)
            {
                this.constructionManagement.Visible = false;
                return;
            }

            this.constructionManagement.SetView(systemController.StellarisController());
            this.constructionManagement.Visible = true;

            this.fleetController    = null;
            this.fleetPanel.Visible = false;
        }
示例#12
0
    void Update()
    {
        // Wait till the territory data is ready then create it
        // TODO: Get this out of the Update() function
        if (!_createdTerritory && Points.Count > 0)
        {
            StarSystemController starCtrl = GetComponent <StarSystemController>();

            // Pull the network synchronized points
            Vector2[] earlyPoints = new Vector2[Points.Count];
            Points.CopyTo(earlyPoints, 0);

            // Smooth those points out a bit
            List <Vector2> latePoints = new List <Vector2>();
            for (int i = 0; i < earlyPoints.Length; i++)
            {
                Vector2[] calcPoints = new Vector2[4];

                if (i == 0)
                {
                    calcPoints[0] = earlyPoints[earlyPoints.Length - 1];
                }
                else
                {
                    calcPoints[0] = earlyPoints[i - 1];
                }

                calcPoints[1] = earlyPoints[i];

                if ((i + 1) > (earlyPoints.Length - 1))
                {
                    calcPoints[2] = earlyPoints[0];
                }
                else
                {
                    calcPoints[2] = earlyPoints[i + 1];
                }

                SharedCurveTracker.PointPair pair = new SharedCurveTracker.PointPair();
                pair.p1 = calcPoints[1];
                pair.p2 = calcPoints[2];

                try
                {
                    List <Vector2> previouslyGenerated = _curveTracker.CurveLookup[pair];

                    if (previouslyGenerated != null)
                    {
                        latePoints.AddRange(previouslyGenerated);
                        continue;
                    }
                }
                catch (KeyNotFoundException) {}

                if ((i + 2) > earlyPoints.Length)
                {
                    calcPoints[3] = earlyPoints[1];
                }
                else if ((i + 2) > (earlyPoints.Length - 1))
                {
                    calcPoints[3] = earlyPoints[0];
                }
                else
                {
                    calcPoints[3] = earlyPoints[i + 2];
                }

                List <Vector2> smoothPoints = _splinulator.CatmulRom(calcPoints);
                smoothPoints.Remove(smoothPoints[smoothPoints.Count - 1]);               // remove duplicate first/last point
                latePoints.AddRange(smoothPoints);

                _curveTracker.CurveLookup[pair] = smoothPoints;
            }

            Vector2[] newPoints = new Vector2[latePoints.Count];
            latePoints.CopyTo(newPoints, 0);

            // Make triangles out of all those points
            Triangulator tr      = new Triangulator(newPoints);
            int[]        indices = tr.Triangulate();

            // Create the Vector3 vertices
            Vector3[] vertices = new Vector3[newPoints.Length];
            for (int i = 0; i < vertices.Length; i++)
            {
                vertices[i] = new Vector3(newPoints[i].x, -3, newPoints[i].y);
            }

            // Create the mesh
            Mesh msh = new Mesh();
            msh.vertices  = vertices;
            msh.triangles = indices;
            msh.RecalculateNormals();
            msh.RecalculateBounds();

            // Set up game object with mesh;
            TerritoryAttached      = new GameObject();
            TerritoryAttached.name = starCtrl.StarName + "_Territory";
            TerritoryAttached.AddComponent <MeshRenderer>();
            MeshFilter filter = TerritoryAttached.AddComponent <MeshFilter>();
            filter.mesh = msh;

            // Keep the scene hierarchy clean
            GameObject mgrParent = GameObject.Find("TerritoryList");
            TerritoryAttached.transform.parent = mgrParent.transform;

            // Too hacky: making sure the material gets assigned
            SendMessage("OnFactionChange");
            _createdTerritory = true;
        }
    }
示例#13
0
 private void Awake()
 {
     Instance = this;
 }
示例#14
0
 public void SystemDeselected(StarSystemController system)
 {
     GameObject.Destroy(_systemUI.gameObject);
 }
    private void createRegion(List <Vector2> regionPoints, StarSystem target, bool buildOnServer)
    {
        GameObject createdSystem = Container.InstantiatePrefab(_settings.StarSystemPrefab);

        createdSystem.transform.position = new Vector3(target.X, 0, target.Y);
        createdSystem.name = "Star_" + target.Name;

        // Might be building on the client in offline mode
        if (buildOnServer)
        {
            NetworkServer.Spawn(createdSystem.gameObject);
        }

        createdSystem.GetComponentsInChildren <Text>()[0].text = target.Name;

        TerritoryController tc = createdSystem.GetComponent <TerritoryController>();

        foreach (Vector2 point in regionPoints)
        {
            tc.Points.Add(point);
        }

        StarSystemController ssCon = createdSystem.gameObject.GetComponent <StarSystemController>();

        ssCon.StarName = target.Name;

        // Set the starting faction
        FactionController factCtrl = createdSystem.gameObject.GetComponent <FactionController>();

        switch (target.Faction)
        {
        case "s":
            factCtrl.CurrentFaction = Faction.Steiner;
            break;

        case "m":
            factCtrl.CurrentFaction = Faction.Marik;
            break;

        case "l":
            factCtrl.CurrentFaction = Faction.Liao;
            break;

        case "d":
            factCtrl.CurrentFaction = Faction.Davion;
            break;

        case "k":
            factCtrl.CurrentFaction = Faction.Kurita;
            break;

        case "c":
            factCtrl.CurrentFaction = Faction.Comstar;
            break;

        default:
            factCtrl.CurrentFaction = Faction.None;
            break;
        }

        StarSystemData sysData = createdSystem.gameObject.GetComponent <StarSystemData>();

        sysData.OrigX     = target.OrigX;
        sysData.OrigY     = target.OrigY;
        sysData.StarClass = target.StarClass;

        if (target.DataAvailable)
        {
            sysData.IsDataKnown    = true;
            sysData.PlanetsKnown   = target.PlanetsKnown;
            sysData.PlanetsUnknown = target.PlanetsUnknown;
            sysData.Gravity        = target.Gravity;
            sysData.Atmosphere     = target.Atmosphere;
            sysData.Water          = target.Water;
            sysData.Climate        = target.Climate;
            sysData.Terrain        = target.Terrain;
            sysData.Development    = target.Development;
            sysData.HasFlag        = target.HasFlag;
        }
    }
 public void DispatchSystemFactionChanged(StarSystemController system, string newFaction)
 {
     _systemFactionChangedSignal.Fire(system.gameObject, newFaction);
 }
示例#17
0
        public void SetStarSystem(StarSystemController controller, PlayerController playerController)
        {
            this.controller    = controller;
            this.currentPlayer = playerController;

            this.maxOffset = (controller.Planets.Count() + 1) * OrbitStep + OrbitOffset;

            var bestColony = controller.Planets.
                             Select(x => controller.PlanetsColony(x)).
                             Aggregate(
                (ColonyInfo)null,
                (prev, next) => next == null || (prev != null && prev.Population >= next.Population) ? prev : next
                );

            this.originOffset      = bestColony != null ? bestColony.Location.Position * OrbitStep + OrbitOffset : 0.5f;
            this.lastMousePosition = null;

            this.starSelector.ForgroundImageColor = controller.HostStar.Color;
            this.starSelector.Select();

            foreach (var anchor in this.planetAnchors)
            {
                this.RemoveAnchor(anchor);
            }
            this.planetAnchors.Clear();

            foreach (var element in this.planetSelectors.Values.Concat(this.colonizationMarkers.Values).Concat(this.otherPlanetElements))
            {
                this.RemoveElement(element);
            }
            this.planetSelectors.Clear();
            this.colonizationMarkers.Clear();
            this.otherPlanetElements.Clear();

            var traitGridBuilder = new GridPositionBuilder(2, 20, 20, 3);

            foreach (var trait in controller.HostStar.Traits)
            {
                var traitImage = new GuiImage
                {
                    Below   = this.starSelector,
                    Image   = GalaxyTextures.Get.Sprite(trait.ImagePath),
                    Tooltip = new SimpleTooltip("Traits", trait.LangCode)
                };
                traitImage.Position.FixedSize(20, 20).RelativeTo(this.starSelector, 0.8f, -0.8f, -1, 1).WithMargins(3, 0);
                traitGridBuilder.Add(traitImage.Position);
                this.addPlanetElement(traitImage);
            }

            foreach (var planet in this.controller.Planets)
            {
                var anchor = new GuiAnchor(planet.Position * OrbitStep + OrbitOffset, 0);
                this.AddAnchor(anchor);
                this.planetAnchors.Add(anchor);

                var planetSelector = new SelectableImage <int>(planet.Position)
                {
                    ForgroundImage = GalaxyTextures.Get.PlanetSprite(planet.Type),
                    SelectorImage  = GalaxyTextures.Get.SelectedStar,
                    SelectCallback = select,
                    Padding        = 16,
                };
                planetSelector.Position.FixedSize(100, 100).RelativeTo(anchor);
                planetSelector.GroupWith(starSelector);
                this.planetSelectors[planet.Position] = planetSelector;
                this.AddElement(planetSelector);

                var popInfo = new GuiText {
                    TextHeight = 20
                };
                popInfo.Position.WrapContent().Then.RelativeTo(planetSelector, 0, -1, 0, 1).WithMargins(0, 20);

                var formatter = new ThousandsFormatter();
                var colony    = this.controller.PlanetsColony(planet);
                if (colony != null)
                {
                    popInfo.Text      = formatter.Format(colony.Population) + " / " + formatter.Format(colony.PopulationMax);
                    popInfo.TextColor = colony.Owner.Color;
                }
                else
                {
                    popInfo.Text      = formatter.Format(planet.PopulationMax);
                    popInfo.TextColor = Color.Gray;
                }
                this.addPlanetElement(popInfo);

                traitGridBuilder = new GridPositionBuilder(4, 20, 20, 3);
                foreach (var trait in planet.Traits)
                {
                    var traitImage = new GuiImage
                    {
                        Image   = GalaxyTextures.Get.Sprite(trait.ImagePath),
                        Tooltip = new SimpleTooltip("Traits", trait.LangCode)
                    };
                    traitImage.Position.FixedSize(20, 20).RelativeTo(popInfo, 0, -1, 0, 1).WithMargins(0, 10).Offset(-40, 0);
                    traitGridBuilder.Add(traitImage.Position);
                    this.addPlanetElement(traitImage);
                }
            }

            this.setupColonizationMarkers();
        }
示例#18
0
        public void SetStarSystem(StarSystemController controller, PlayerController playerController)
        {
            this.setupSystem(controller.Planets.ToList(), controller.PlanetsColony);
            this.controller    = controller;
            this.currentPlayer = playerController;

            var colonies = controller.Planets.Select(x => controller.PlanetsColony(x)).Where(x => x != null);

            if (colonies.Any())
            {
                this.panTo(Methods.FindBest(colonies, x => x.Population).Location);
            }
            else
            {
                this.panToStar();
            }

            this.starSelector.ForgroundImageColor = controller.HostStar.Color;
            this.starSelector.Select();

            foreach (var element in this.planetSelectors.Values.Concat(this.colonizationMarkers.Values).Concat(this.otherPlanetElements))
            {
                this.RemoveElement(element);
            }
            this.planetSelectors.Clear();
            this.colonizationMarkers.Clear();
            this.otherPlanetElements.Clear();

            var traitGridBuilder = new GridPositionBuilder(2, 20, 20, 3);

            foreach (var trait in controller.HostStar.Traits)
            {
                var traitImage = new GuiImage
                {
                    Below   = this.starSelector,
                    Margins = new Vector2(3, 0),
                    Image   = GalaxyTextures.Get.Sprite(trait.ImagePath),
                    Tooltip = new SimpleTooltip("Traits", trait.LangCode)
                };
                traitImage.Position.FixedSize(20, 20).RelativeTo(this.starSelector, 0.8f, -0.8f, -1, 1).UseMargins();
                traitGridBuilder.Add(traitImage.Position);
                this.addPlanetElement(traitImage);
            }

            foreach (var planet in this.controller.Planets)
            {
                var planetSelector = new SelectableImage <int>(planet.Position)
                {
                    ForgroundImage = GalaxyTextures.Get.PlanetSprite(planet.Type),
                    SelectorImage  = GalaxyTextures.Get.SelectedStar,
                    SelectCallback = select,
                    Padding        = 16,
                };
                planetSelector.Position.FixedSize(100, 100).RelativeTo(this.planetAnchor(planet));
                planetSelector.GroupWith(starSelector);
                this.planetSelectors[planet.Position] = planetSelector;
                this.AddElement(planetSelector);

                var popInfo = new GuiText
                {
                    Margins    = new Vector2(0, 20),
                    TextHeight = 20
                };
                popInfo.Position.WrapContent().Then.RelativeTo(planetSelector, 0, -1, 0, 1).UseMargins();

                var formatter = new ThousandsFormatter();
                var colony    = this.controller.PlanetsColony(planet);
                if (colony != null)
                {
                    popInfo.Text      = formatter.Format(colony.Population) + " / " + formatter.Format(colony.PopulationMax);
                    popInfo.TextColor = colony.Owner.Color;
                }
                else
                {
                    popInfo.Text      = formatter.Format(planet.PopulationMax);
                    popInfo.TextColor = Color.Gray;
                }
                this.addPlanetElement(popInfo);

                traitGridBuilder = new GridPositionBuilder(4, 20, 20, 3);
                foreach (var trait in planet.Traits)
                {
                    var traitImage = new GuiImage
                    {
                        Margins = new Vector2(0, 10),
                        Image   = GalaxyTextures.Get.Sprite(trait.ImagePath),
                        Tooltip = new SimpleTooltip("Traits", trait.LangCode)
                    };
                    traitImage.Position.FixedSize(20, 20).RelativeTo(popInfo, 0, -1, 0, 1).UseMargins().Offset(-40, 0);
                    traitGridBuilder.Add(traitImage.Position);
                    this.addPlanetElement(traitImage);
                }
            }

            this.setupColonizationMarkers();
        }