예제 #1
0
        protected void setupSystem(ICollection <PlanetInfo> planets, Func <PlanetInfo, ColonyInfo> colonies)
        {
            this.maxOffset         = (planets.Count + 1) * OrbitStep + OrbitOffset;
            this.lastMousePosition = null;

            this.UpdateScene(
                ref this.planetOrbits,
                planets.Select(
                    planet =>
            {
                var orbitR = planet.Position * OrbitStep + OrbitOffset;
                var colony = colonies(planet);
                var color  = colony != null ? Color.FromArgb(192, colony.Owner.Color) : Color.FromArgb(64, 64, 64);

                return(new SceneObject(new PolygonData(
                                           OrbitZ,
                                           new OrbitData(orbitR - OrbitWidth / 2, orbitR + OrbitWidth / 2, color, Matrix4.Identity, GalaxyTextures.Get.PathLine),
                                           OrbitHelpers.PlanetOrbit(orbitR, OrbitWidth, OrbitPieces).ToList()
                                           )));
            }
                    ).ToList()
                );

            foreach (var anchor in this.planetAnchors.Values)
            {
                this.RemoveAnchor(anchor);
            }
            this.planetAnchors = new Dictionary <PlanetInfo, GuiAnchor>();
            foreach (var planet in planets)
            {
                var anchor = new GuiAnchor(planet.Position * OrbitStep + OrbitOffset, 0);
                this.planetAnchors[planet] = anchor;
                this.AddAnchor(anchor);
            }
        }
예제 #2
0
        public void GuiAnchorConstructorVerification()
        {
            GuiAnchor testAnchor = new GuiAnchor(GuiAnchor.X.Center, GuiAnchor.Y.Bottom);

            Assert.AreEqual((int)GuiAnchor.X.Center, (int)testAnchor.Horizontal);
            Assert.AreEqual((int)GuiAnchor.Y.Bottom, (int)testAnchor.Vertical);
        }
예제 #3
0
        protected AStarSystemScene()
        {
            var context      = LocalizationManifest.Get.CurrentLanguage["FormMain"];
            var returnButton = new GuiButton
            {
                ClickCallback    = this.onReturn,
                BackgroundHover  = new BackgroundTexture(GalaxyTextures.Get.ButtonHover, 9),
                BackgroundNormal = new BackgroundTexture(GalaxyTextures.Get.ButtonNormal, 9),
                Padding          = 12,
                Margins          = new Vector2(10, 5),
                Text             = context["Return"].Text(),
                TextColor        = Color.Black,
                TextHeight       = 20
            };

            returnButton.Position.WrapContent().Then.ParentRelative(1, 1).UseMargins();
            this.AddElement(returnButton);

            this.StarAnchor = new GuiAnchor(0, 0);
            this.AddAnchor(this.StarAnchor);
        }
예제 #4
0
        public StarSystemScene(Action systemClosedHandler)
        {
            this.systemClosedHandler = systemClosedHandler;

            this.siteView = new ConstructionSiteView();
            this.siteView.Position.ParentRelative(0, -1);

            this.emptyPlanetView = new EmptyPlanetView(this.setupColonizationMarkers);
            this.emptyPlanetView.Position.ParentRelative(0, -1);

            var context      = LocalizationManifest.Get.CurrentLanguage["FormMain"];
            var returnButton = new GuiButton
            {
                ClickCallback    = systemClosedHandler,
                BackgroundHover  = new BackgroundTexture(GalaxyTextures.Get.ButtonHover, 9),
                BackgroundNormal = new BackgroundTexture(GalaxyTextures.Get.ButtonNormal, 9),
                Padding          = 12,
                Text             = context["Return"].Text(),
                TextColor        = Color.Black,
                TextHeight       = 20
            };

            returnButton.Position.WrapContent().Then.ParentRelative(1, 1).WithMargins(10, 5);
            this.AddElement(returnButton);

            var starAnchor = new GuiAnchor(0, 0);

            this.AddAnchor(starAnchor);

            this.starSelector = new SelectableImage <int>(StarSystemController.StarIndex)
            {
                ForgroundImage = GalaxyTextures.Get.SystemStar,
                SelectorImage  = GalaxyTextures.Get.SelectedStar,
                SelectCallback = select,
                Padding        = 24,
            };
            starSelector.Position.FixedSize(400, 400).RelativeTo(starAnchor);
            this.AddElement(starSelector);
        }
예제 #5
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();
        }
예제 #6
0
파일: AScene.cs 프로젝트: weshec/Stareater
 public void RemoveAnchor(GuiAnchor anchor)
 {
     this.anchors.Remove(anchor);
 }
예제 #7
0
파일: AScene.cs 프로젝트: weshec/Stareater
 public void AddAnchor(GuiAnchor anchor)
 {
     this.anchors.Add(anchor);
     anchor.Setup(this.projection, this.guiInvProjection);
 }
예제 #8
0
 public void AddAnchor(GuiAnchor anchor)
 {
     this.anchors.Add(anchor);
 }