private void updateInfos()
        {
            var percentFormat   = new DecimalsFormatter(0, 1);
            var thousandsFormat = new ThousandsFormatter();

            double powerGenerated = this.controller.Reactor.Power;
            double powerUsed      = this.controller.PowerUsed;

            this.armorInfo.Text = this.context["armor"].Text(
                new TextVar("totalHp", thousandsFormat.Format(this.controller.HitPoints)).Get
                );
            this.mobilityInfo.Text = this.context["mobility"].Text(
                new TextVar("mobility", thousandsFormat.Format(this.controller.Evasion)).Get
                );
            this.powerInfo.Text = this.context["power"].Text(
                new TextVar("powerPercent", percentFormat.Format(Methods.Clamp(1 - powerUsed / powerGenerated, 0, 1) * 100)).Get
                );
            this.sensorInfo.Text = this.context["sensors"].Text(
                new TextVar("detection", this.controller.Detection.ToString("0.#")).Get
                );
            this.stealthInfo.Text = this.context["stealth"].Text(
                new TextVar("jamming", this.controller.Jamming.ToString("0.#")).
                And("cloaking", this.controller.Cloaking.ToString("0.#")).Get
                );
            this.costInfo.Text = this.context["cost"].Text(
                new TextVar("cost", thousandsFormat.Format(this.controller.Cost)).Get
                );

            this.spaceInfo.SetSpace(this.controller.SpaceUsed, this.controller.SpaceTotal);
        }
Esempio n. 2
0
        public void SetView(CombatantInfo unit, SpaceBattleController controller)
        {
            this.unit       = unit;
            this.controller = controller;

            var context       = LocalizationManifest.Get.CurrentLanguage["FormMain"];
            var formatter     = new ThousandsFormatter();
            var decimalFormat = new DecimalsFormatter(0, 0);

            shipCount.Text   = context["ShipCount"].Text() + ": " + formatter.Format(unit.Count);
            armorInfo.Text   = hpText("ArmorLabel", unit.ArmorHp, unit.ArmorHpMax);
            shieldsInfo.Text = hpText("ShieldLabel", unit.ShieldHp, unit.ShieldHpMax);

            if (unit.MovementEta > 0)
            {
                movementInfo.Text = context["MovementEta"].Text(
                    new Var("eta", unit.MovementEta).Get,
                    new TextVar("eta", unit.MovementEta.ToString()).Get
                    );
            }
            else
            {
                movementInfo.Text = context["MovementPoints"].Text() + " (" + decimalFormat.Format(unit.MovementPoints * 100) + " %)";
            }
        }
Esempio n. 3
0
        public void SetResults(ResultsController controller)
        {
            foreach (var cellText in this.tableCells)
            {
                this.RemoveElement(cellText);
            }

            //TODO(later) add table header

            var scores    = controller.Scores.OrderByDescending(x => x.VictoryPoints).ToList();
            var formatter = new DecimalsFormatter(0, 0);

            for (int i = 0; i < scores.Count; i++)
            {
                var score = new GuiText
                {
                    TextColor  = Color.White,
                    TextHeight = 30,
                    Text       = formatter.Format(scores[i].VictoryPoints)
                };
                score.Position.WrapContent().Then.RelativeTo(this.title, 0, -1, 1, 1).Then.Offset(-30, -20 + -40 * i);
                this.AddElement(score);
                this.tableCells.Add(score);

                var name = new GuiText
                {
                    TextColor  = Color.White,
                    TextHeight = 30,
                    Text       = scores[i].Player.Name
                };
                name.Position.WrapContent().Then.RelativeTo(this.title, 0, -1, -1, 1).Then.Offset(30, -20 + -40 * i);
                this.AddElement(name);
                this.tableCells.Add(name);
            }
        }
        public IkadnBaseObject Parse(IkadnParser parser)
        {
            parser.Reader.SkipWhiteSpaces();
            char   formatterType      = parser.Reader.Read();
            string formatterParameter = parser.Reader.ReadWhile(c => !char.IsWhiteSpace(c));

            Func <double, string> formatter;

            switch (formatterType)
            {
            case 'd':
            case 'D':
                formatter = new DecimalsFormatter(0,
                                                  formatterParameter.Length > 0 ? int.Parse(formatterParameter) : 0
                                                  ).Format;
                break;

            case 't':
            case 'T':
                formatter = (
                    (formatterParameter == AutomaticThousands) ?
                    new ThousandsFormatter() :
                    new ThousandsFormatter(formatterParameter)
                    ).Format;
                break;

            default:
                throw new FormatException("Unexpected expression formatter: " + formatterType);
            }

            parser.Reader.SkipWhiteSpaces();
            string expressionText = parser.Reader.ReadUntil(EndingChar);

            parser.Reader.Read();

            if (expressionText.Length == 0)
            {
                throw new FormatException("Expression at " + parser.Reader + " is empty (zero length)");
            }

            ExpressionParser expParser = new ExpressionParser(expressionText);

            expParser.Parse();

            if (expParser.errors.count > 0)
            {
                throw new FormatException("Expression at " + parser.Reader + " is invalid: " + expParser.errors.errorMessages);
            }

            //TODO(later) substitute subformulas
            return(new ExpressionText(expParser.ParsedFormula, formatter));
        }
Esempio n. 5
0
        private void updateEta()
        {
            var context   = LocalizationManifest.Get.CurrentLanguage["FormStareater"];
            var progress  = this.controller.EjectionProgress;
            var formatter = new DecimalsFormatter(0, 1);

            this.selectionInfo.Text =
                progress.CanProgress ?
                context["ejectionEta"].Text(
                    new Var("eta", Math.Ceiling(progress.Eta)).Get,
                    new TextVar("eta", formatter.Format(progress.Eta)).And("vp", formatter.Format(progress.VictoryPoints)).Get) :
                "";
        }
Esempio n. 6
0
        public FormStareater(StareaterController controller) : this()
        {
            this.controller = controller;

            var lang    = LocalizationManifest.Get.CurrentLanguage;
            var context = lang["FormStareater"];

            this.Text             = context["FormTitle"].Text();
            this.closeAction.Text = context["close"].Text();
            this.ejectLabel.Text  = context["eject"].Text() + ":";

            if (controller.HasControl)
            {
                this.whoControlsLabel.Text = context["controlledByYou"].Text();
            }
            else
            {
                this.whoControlsLabel.Text = context["notControlledByYou"].Text();
            }

            this.starSelector.Items.Add(new Tag <StarInfo>(null, context["noStar"].Text()));
            var ejectables = controller.EjectableStars.
                             Select(x => new Tag <StarInfo>(x, x.Name.ToText(lang))).
                             OrderBy(x => x.DisplayText).
                             ToList();

            foreach (var item in ejectables)
            {
                this.starSelector.Items.Add(item);
            }
            this.starSelector.SelectedIndex =
                controller.EjectTarget != null ?
                (ejectables.FindIndex(x => x.Value == controller.EjectTarget) + 1) :
                0;

            var progressText = context["progressHeading"].Text();
            var formatter    = new DecimalsFormatter(0, 1);

            foreach (var info in controller.GameProgress.OrderByDescending(x => x.VictoryPoints))
            {
                progressText += Environment.NewLine + context["playerProgress"].Text(
                    new TextVar("vp", formatter.Format(info.VictoryPoints)).
                    And("name", info.Player.Name).Get
                    );
            }

            this.gameProgressInfo.Text = progressText;

            updateEta();
        }
Esempio n. 7
0
        public void SetResults(ResultsController controller)
        {
            this.controller = controller;

            var scores    = controller.Scores.OrderByDescending(x => x.VictoryPoints).ToList();
            var formatter = new DecimalsFormatter(0, 0);

            this.UpdateScene(
                ref this.scoresText,
                new SceneObject(scores.Select(
                                    (x, i) => new PolygonData(
                                        TextZ,
                                        new SpriteData(
                                            Matrix4.CreateScale(TextSize, TextSize, 1) * Matrix4.CreateTranslation(-0.2f, -0.5f * i + 0.8f, 0),
                                            TextRenderUtil.Get.TextureId,
                                            Color.White,
                                            null, true
                                            ),
                                        TextRenderUtil.Get.BufferRaster(
                                            formatter.Format(x.VictoryPoints),
                                            -1f,
                                            Matrix4.Identity
                                            ).ToList()
                                        )))
                );

            this.UpdateScene(
                ref this.namesText,
                new SceneObject(scores.Select(
                                    (x, i) => new PolygonData(
                                        TextZ,
                                        new SpriteData(
                                            Matrix4.CreateScale(TextSize, TextSize, 1) * Matrix4.CreateTranslation(0, -0.5f * i + 0.8f, 0),
                                            TextRenderUtil.Get.TextureId,
                                            Color.White,
                                            null, true
                                            ),
                                        TextRenderUtil.Get.BufferRaster(
                                            x.Player.Name,
                                            0f,
                                            Matrix4.Identity
                                            ).ToList()
                                        )))
                );
        }
        public FormStellarisDetails(StellarisAdminController controller) : this()
        {
            this.controller = controller;
            this.setStarImage();

            Context context = LocalizationManifest.Get.CurrentLanguage["FormStellaris"];

            this.Text = this.controller.HostStar.Name.ToText(LocalizationManifest.Get.CurrentLanguage);
            this.Font = SettingsWinforms.Get.FormFont;

            buildingsGroup.Text    = context["buildingsGroup"].Text();
            coloniesInfoGroup.Text = context["coloniesGroup"].Text();
            outputInfoGroup.Text   = context["outputGroup"].Text();

            var prefixFormat  = new ThousandsFormatter();
            var percentFormat = new DecimalsFormatter(0, 1);
            Func <string, double, string> totalText = (label, x) => context[label].Text() + ": " + prefixFormat.Format(x);

            populationInfo.Text     = totalText("populationInfo", controller.PopulationTotal);
            infrastructureInfo.Text = context["infrastructureInfo"].Text() + ": " + percentFormat.Format(controller.OrganisationAverage * 100) + " %";

            industryInfo.Text    = totalText("industryInfo", controller.IndustryTotal);
            developmentInfo.Text = totalText("developmentInfo", controller.DevelopmentTotal);

            foreach (var trait in controller.Traits)
            {
                var thumbnail = new PictureBox();
                thumbnail.Size     = new Size(32, 32);
                thumbnail.SizeMode = PictureBoxSizeMode.Zoom;
                thumbnail.Image    = ImageCache.Get[trait.ImagePath];
                this.traitList.Controls.Add(thumbnail);
            }

            foreach (var data in controller.Buildings)
            {
                var itemView = new BuildingItem();
                itemView.Data = data;
                buildingsList.Controls.Add(itemView);
            }
        }
        private void hullSelector_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.hullPicker.SelectedItem == null)
            {
                return;
            }
            var hull = (this.hullPicker.SelectedItem as Tag <HullInfo>).Value;

            if (this.automaticName)
            {
                nameInput.Text = hull.Name;                 //TODO(later): get hull and organization specific name
            }
            this.hullImage.Image = ImageCache.Get[hull.ImagePaths[this.imageIndices[hull]]];

            this.controller.Hull       = hull;
            this.controller.ImageIndex = this.imageIndices[hull];

            this.hasIsDrive.Visible   = this.controller.AvailableIsDrive != null;
            this.hasIsDrive.Checked  &= this.hasIsDrive.Visible;
            this.isDriveImage.Visible = this.hasIsDrive.Checked;

            this.controller.HasIsDrive = this.hasIsDrive.Checked;

            if (this.controller.AvailableIsDrive != null)
            {
                var speedFormat = new DecimalsFormatter(0, 2);

                this.hasIsDrive.Text = this.context["isDrive"].Text(
                    new TextVar("name", this.controller.AvailableIsDrive.Name).
                    And("speed", speedFormat.Format(this.controller.AvailableIsDrive.Speed)).Get
                    );
                this.isDriveImage.Image = ImageCache.Get[this.controller.AvailableIsDrive.ImagePath];
            }

            this.checkValidity();
            this.updateInfos();
        }
Esempio n. 10
0
        public void PlayUnit(CombatantInfo unitInfo)
        {
            if (this.InvokeRequired)
            {
                this.BeginInvoke(new Action <CombatantInfo>(PlayUnit), unitInfo);
                return;
            }

            this.combatRenderer.OnUnitTurn(unitInfo);

            var context       = LocalizationManifest.Get.CurrentLanguage["FormMain"];
            var formatter     = new ThousandsFormatter();
            var decimalFormat = new DecimalsFormatter(0, 0);

            Func <string, double, double, string> hpText = (label, x, max) =>
            {
                var hpFormat = ThousandsFormatter.MaxMagnitudeFormat(x, max);
                return(context[label].Text() + ": " + hpFormat.Format(x) + " / " + hpFormat.Format(max));
            };

            shipCount.Text  = context["ShipCount"].Text() + ": " + formatter.Format(unitInfo.Count);
            armorInfo.Text  = hpText("ArmorLabel", unitInfo.ArmorHp, unitInfo.ArmorHpMax);
            shieldInfo.Text = hpText("ShieldLabel", unitInfo.ShieldHp, unitInfo.ShieldHpMax);

            if (unitInfo.MovementEta > 0)
            {
                movementInfo.Text = context["MovementEta"].Text(
                    new Var("eta", unitInfo.MovementEta).Get,
                    new TextVar("eta", unitInfo.MovementEta.ToString()).Get
                    );
            }
            else
            {
                movementInfo.Text = context["MovementPoints"].Text() + " (" + decimalFormat.Format(unitInfo.MovementPoints * 100) + " %)";
            }

            this.abilityList.Controls.Clear();
            Func <Image, string, object, Button> buttonMaker = (image, text, tag) =>
            {
                var button = new Button
                {
                    Image                   = image,
                    ImageAlign              = ContentAlignment.MiddleLeft,
                    Margin                  = new Padding(3, 3, 3, 0),
                    Size                    = new Size(80, 32),
                    Text                    = text,
                    TextImageRelation       = TextImageRelation.ImageBeforeText,
                    UseVisualStyleBackColor = true,
                    Tag = tag
                };
                button.Click += selectAbility_Click;

                return(button);
            };

            this.abilityList.Controls.Add(buttonMaker(
                                              null,
                                              context["MoveAction"].Text(),
                                              null
                                              ));

            foreach (var ability in unitInfo.Abilities)
            {
                this.abilityList.Controls.Add(buttonMaker(
                                                  ImageCache.Get.Resized(ability.ImagePath, new Size(24, 24)),
                                                  "x " + formatter.Format(ability.Quantity),
                                                  ability
                                                  ));
            }
        }
        public FormColonyDetails(ColonyController controller) : this()
        {
            this.controller = controller;

            switch (controller.PlanetBody.Type)
            {
            case PlanetType.Asteriod:
                this.planetImage.Image = Resources.asteroids;
                break;

            case PlanetType.GasGiant:
                this.planetImage.Image = Resources.gasGiant;
                break;

            case PlanetType.Rock:
                this.planetImage.Image = Resources.rockPlanet;
                break;
            }

            Context context = LocalizationManifest.Get.CurrentLanguage["FormColony"];

            this.Text = LocalizationMethods.PlanetName(controller.PlanetBody);
            this.Font = SettingsWinforms.Get.FormFont;

            var popFormat     = new ThousandsFormatter(controller.PopulationMax, controller.Population);
            var decimalFormat = new DecimalsFormatter(0, 1);
            var prefixFormat  = new ThousandsFormatter();

            Func <string, double, string> statText  = (label, x) => context[label].Text() + ": " + decimalFormat.Format(x);
            Func <string, double, string> perPop    = (label, x) => context[label].Text() + ": " + decimalFormat.Format(x) + " / " + context["perPop"].Text();
            Func <string, double, string> totalText = (label, x) => context[label].Text() + ": " + prefixFormat.Format(x);

            buildingsGroup.Text    = context["buildingsGroup"].Text();
            planetInfoGroup.Text   = context["planetGroup"].Text();
            popInfoGroup.Text      = context["popGroup"].Text();
            productivityGroup.Text = context["productivityGroup"].Text();

            populationInfo.Text     = popFormat.Format(controller.Population) + " / " + popFormat.Format(controller.PopulationMax);
            growthInfo.Text         = context["growthInfo"].Text() + ": " + DecimalsFormatter.Sign(controller.PopulationGrowth) + popFormat.Format(controller.PopulationGrowth);
            infrastructureInfo.Text = statText("infrastructureInfo", controller.Organization * 100) + "%";

            sizeInfo.Text        = statText("sizeInfo", controller.PlanetSize);
            environmentInfo.Text = statText("environmentInfo", controller.PlanetEnvironment * 100) + "%";

            foodInfo.Text             = perPop("foodInfo", controller.FoodPerPop);
            miningInfo.Text           = perPop("miningInfo", controller.OrePerPop);
            industryInfo.Text         = perPop("industryInfo", controller.IndustryPerPop);
            developmentInfo.Text      = perPop("developmentInfo", controller.DevelopmentPerPop);
            industryTotalInfo.Text    = totalText("industryTotalInfo", controller.IndustryTotal);
            developmentTotalInfo.Text = totalText("developmentTotalInfo", controller.DevelopmentTotal);

            foreach (var trait in controller.Traits)
            {
                var thumbnail = new PictureBox();
                thumbnail.Size     = new Size(32, 32);
                thumbnail.SizeMode = PictureBoxSizeMode.Zoom;
                thumbnail.Image    = ImageCache.Get[trait.ImagePath];
                this.traitList.Controls.Add(thumbnail);
            }

            foreach (var data in controller.Buildings)
            {
                var itemView = new BuildingItem();
                itemView.Data = data;
                buildingsList.Controls.Add(itemView);
            }
        }